~nico-izo-ya/+junk/aaron2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/****************************************************************************
 * buildtracker.h
 *  Copyright © 2015, Nicolay Izoderov <nico-izo@ya.ru>.
 *  Licence: GPLv3 or later
 *
 ****************************************************************************
 *                                                                          *
 *   This library is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by   *
 *   the Free Software Foundation; either version 3 of the License, or      *
 *   (at your option) any later version.                                    *
 *                                                                          *
 ****************************************************************************/

#ifndef BUILDTRACKER_H
#define BUILDTRACKER_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QTimer>
#include <QHash>

struct BuildInfo {
	/**
	 * Datetime formatted as yyyy-MM-ddTHH:mm:ss.zzzQQQ+00:00, where QQQ is microseconds
	 */
	QString datetime;
	/**
	 * \see https://launchpad.net/+apidoc/1.0.html#build
	 */
	QString webLink;
	/**
	 * Can be "Successfully built", or "Failed to build", or many others
	 * \see https://launchpad.net/+apidoc/1.0.html#build
	 */
	QString status;

	QString toString() const {
		auto dt = QString(datetime);
		dt.truncate(19);
		return QString("[%1] \n Статус сборки: %2 \n Ссылка: %3")
				.arg(dt)
				.arg(status)
				.arg(webLink);
	}
};

class BuildTracker : public QObject
{
	Q_OBJECT

public:
	explicit BuildTracker(QObject *parent = 0);
	~BuildTracker();

signals:
	void newBuild(const QString&, const QString&);
public slots:
	QString getRepoMessage(const QString &repo);
private slots:
	void updateRepos();
	void onReplyFinished(QNetworkReply*);
private:
	QTimer updater;
	QNetworkAccessManager *netman;
	QHash<QString, QString> repos;

	QHash<QString, QDateTime> lastUpdated;
	QHash<QString, QList<BuildInfo>> builds;
	QList<BuildInfo> jsonToInfoList(const QByteArray &jsonstr);
};

#endif // BUILDTRACKER_H