-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
wakatimeplugin.h
115 lines (96 loc) · 3.22 KB
/
wakatimeplugin.h
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* This file is part of kate-wakatime.
* Copyright 2014 Andrew Udvare <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version
* 3, or (at your option) any later version, as published by the Free
* Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with the kdelibs library; see the file COPYING.LIB. If
* not, write to the Free Software Foundation, Inc., 51 Franklin Street,
* Fifth Floor, Boston, MA 02110-1301, USA. or see
* <http://www.gnu.org/licenses/>.
*/
#ifndef WAKATIMEPLUGIN_H
#define WAKATIMEPLUGIN_H
#include <KTextEditor/Plugin>
#include <KTextEditor/View>
#include <QtCore/QDateTime>
#include <QtCore/QLoggingCategory>
#include <QtCore/QSettings>
#include "ui_configdialog.h"
#define kWakaTimePluginVersion "1.3.10"
Q_DECLARE_LOGGING_CATEGORY(gLogWakaTime)
namespace KTextEditor {
class Document;
class MainWindow;
class View;
} // namespace KTextEditor
class QDateTime;
class QFile;
class QNetworkAccessManager;
class QNetworkReply;
class OfflineQueue;
class WakaTimeView;
class WakaTimePlugin : public KTextEditor::Plugin {
public:
explicit WakaTimePlugin(QObject *parent = nullptr,
const QList<QVariant> & = QList<QVariant>());
virtual ~WakaTimePlugin();
QObject *createView(KTextEditor::MainWindow *mainWindow) override;
private:
QList<WakaTimeView *> m_views;
};
class WakaTimeView : public QObject, public KXMLGUIClient {
Q_OBJECT
public:
enum WakaTimeApiHttpHeaders {
AuthorizationHeader,
TimeZoneHeader,
XIgnoreHeader,
XMachineName,
};
WakaTimeView(KTextEditor::MainWindow *);
~WakaTimeView();
private Q_SLOTS:
void slotConfigureWakaTime();
void slotDocumentModifiedChanged(KTextEditor::Document *);
void slotDocumentWrittenToDisk(KTextEditor::Document *);
void slotNetworkReplyFinished(QNetworkReply *);
void viewCreated(KTextEditor::View *);
void viewDestroyed(QObject *);
private:
QByteArray apiAuthBytes();
bool documentIsConnected(KTextEditor::Document *);
void connectDocumentSignals(KTextEditor::Document *);
void disconnectDocumentSignals(KTextEditor::Document *);
QString getBinPath(QString);
void readConfig();
void sendAction(KTextEditor::Document *, bool);
void sendHeartbeat(const QVariantMap &, bool, bool saveToQueue = true);
void sendQueuedHeartbeats();
void writeConfig();
private:
KTextEditor::MainWindow *m_mainWindow;
QString apiKey;
QString apiUrl;
QMap<QString, QString> binPathCache;
bool hasSent;
bool hideFilenames;
// Initialised in constructor definition
QList<KTextEditor::Document *> connectedDocuments;
QSettings *config;
QString lastFileSent;
QDateTime lastTimeSent;
QNetworkAccessManager *nam;
OfflineQueue *queue;
QByteArray userAgent;
};
#endif