~nico-izo-ya/+junk/aaron2

« back to all changes in this revision

Viewing changes to buildtracker.h

  • Committer: Nicolay Izoderov
  • Date: 2015-08-29 22:17:38 UTC
  • Revision ID: nico-izo@ya.ru-20150829221738-38hi83l8ve0909q6
Added BuildTracker

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 * buildtracker.h
 
3
 *  Copyright © 2015, Nicolay Izoderov <nico-izo@ya.ru>.
 
4
 *  Licence: GPLv3 or later
 
5
 *
 
6
 ****************************************************************************
 
7
 *                                                                          *
 
8
 *   This library is free software; you can redistribute it and/or modify   *
 
9
 *   it under the terms of the GNU General Public License as published by   *
 
10
 *   the Free Software Foundation; either version 3 of the License, or      *
 
11
 *   (at your option) any later version.                                    *
 
12
 *                                                                          *
 
13
 ****************************************************************************/
 
14
 
 
15
#ifndef BUILDTRACKER_H
 
16
#define BUILDTRACKER_H
 
17
 
 
18
#include <QObject>
 
19
#include <QNetworkAccessManager>
 
20
#include <QTimer>
 
21
#include <QHash>
 
22
 
 
23
struct BuildInfo {
 
24
        /**
 
25
         * Datetime formatted as yyyy-MM-ddTHH:mm:ss.zzzQQQ+00:00, where QQQ is microseconds
 
26
         */
 
27
        QString datetime;
 
28
        /**
 
29
         * \see https://launchpad.net/+apidoc/1.0.html#build
 
30
         */
 
31
        QString webLink;
 
32
        /**
 
33
         * Can be "Successfully built", or "Failed to build", or many others
 
34
         * \see https://launchpad.net/+apidoc/1.0.html#build
 
35
         */
 
36
        QString status;
 
37
 
 
38
        QString toString() const {
 
39
                auto dt = QString(datetime);
 
40
                dt.truncate(19);
 
41
                return QString("[%1] \n Статус сборки: %2 \n Ссылка: %3")
 
42
                                .arg(dt)
 
43
                                .arg(status)
 
44
                                .arg(webLink);
 
45
        }
 
46
};
 
47
 
 
48
class BuildTracker : public QObject
 
49
{
 
50
        Q_OBJECT
 
51
 
 
52
public:
 
53
        explicit BuildTracker(QObject *parent = 0);
 
54
        ~BuildTracker();
 
55
 
 
56
signals:
 
57
        void newBuild(const QString&, const QString&);
 
58
public slots:
 
59
        QString getRepoMessage(const QString &repo);
 
60
private slots:
 
61
        void updateRepos();
 
62
        void onReplyFinished(QNetworkReply*);
 
63
private:
 
64
        QTimer updater;
 
65
        QNetworkAccessManager *netman;
 
66
        QHash<QString, QString> repos;
 
67
 
 
68
        QHash<QString, QDateTime> lastUpdated;
 
69
        QHash<QString, QList<BuildInfo>> builds;
 
70
        QList<BuildInfo> jsonToInfoList(const QByteArray &jsonstr);
 
71
};
 
72
 
 
73
#endif // BUILDTRACKER_H