File: syncthingapplet.h

package info (click to toggle)
syncthingtray 2.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,124 kB
  • sloc: cpp: 34,081; xml: 1,705; java: 1,258; sh: 97; javascript: 54; makefile: 25
file content (387 lines) | stat: -rw-r--r-- 14,214 bytes parent folder | download
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#ifndef SYNCTHINGAPPLET_H
#define SYNCTHINGAPPLET_H

#include <syncthingwidgets/misc/dbusstatusnotifier.h>
#include <syncthingwidgets/misc/statusinfo.h>
#include <syncthingwidgets/webview/webviewdefs.h>

#include <syncthingmodel/syncthingdevicemodel.h>
#include <syncthingmodel/syncthingdirectorymodel.h>
#include <syncthingmodel/syncthingdownloadmodel.h>
#include <syncthingmodel/syncthingrecentchangesmodel.h>
#include <syncthingmodel/syncthingsortfiltermodel.h>
#include <syncthingmodel/syncthingstatusselectionmodel.h>

#include <syncthingconnector/syncthingconnection.h>
#include <syncthingconnector/syncthingnotifier.h>
#include <syncthingconnector/syncthingservice.h>

#include <qtutilities/aboutdialog/aboutdialog.h>
#include <qtutilities/models/checklistmodel.h>

// ignore Plasma deprecation warnings because I'm not sure how to fix them considering Plasma's own applets
// haven't been ported yet
#define PLASMA_NO_DEPRECATED_WARNINGS 1

#include <Plasma/Applet>
#include <Plasma/Theme>

#include <QPalette>
#include <QSize>

namespace Data {
struct SyncthingConnectionSettings;
class IconManager;
} // namespace Data

namespace QtGui {
#ifdef SYNCTHINGWIDGETS_NO_WEBVIEW
using WebViewDialog = void;
#else
class WebViewDialog;
#endif
class Wizard;
} // namespace QtGui

namespace QtForkAwesome {
class QuickImageProvider;
}

namespace Plasmoid {

class SettingsDialog;

class SyncthingApplet : public Plasma::Applet {
    Q_OBJECT
    Q_PROPERTY(Data::SyncthingConnection *connection READ connection CONSTANT)
    Q_PROPERTY(Data::SyncthingDirectoryModel *dirModel READ dirModel CONSTANT)
    Q_PROPERTY(Data::SyncthingSortFilterModel *sortFilterDirModel READ sortFilterDirModel CONSTANT)
    Q_PROPERTY(Data::SyncthingDeviceModel *devModel READ devModel CONSTANT)
    Q_PROPERTY(Data::SyncthingSortFilterModel *sortFilterDevModel READ sortFilterDevModel CONSTANT)
    Q_PROPERTY(Data::SyncthingDownloadModel *downloadModel READ downloadModel CONSTANT)
    Q_PROPERTY(Data::SyncthingRecentChangesModel *recentChangesModel READ recentChangesModel CONSTANT)
    Q_PROPERTY(Data::SyncthingStatusSelectionModel *passiveSelectionModel READ passiveSelectionModel CONSTANT)
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
    Q_PROPERTY(Data::SyncthingService *service READ service CONSTANT)
#endif
    Q_PROPERTY(bool local READ isLocal NOTIFY localChanged)
    Q_PROPERTY(QString statusText READ statusText NOTIFY connectionStatusChanged)
    Q_PROPERTY(QString additionalStatusText READ additionalStatusText NOTIFY connectionStatusChanged)
    Q_PROPERTY(QIcon statusIcon READ statusIcon NOTIFY connectionStatusChanged)
    Q_PROPERTY(QString connectButtonState READ connectButtonState NOTIFY connectionStatusChanged)
    Q_PROPERTY(QString incomingTraffic READ incomingTraffic NOTIFY trafficChanged)
    Q_PROPERTY(bool hasIncomingTraffic READ hasIncomingTraffic NOTIFY trafficChanged)
    Q_PROPERTY(QString outgoingTraffic READ outgoingTraffic NOTIFY trafficChanged)
    Q_PROPERTY(bool hasOutgoingTraffic READ hasOutgoingTraffic NOTIFY trafficChanged)
    Q_PROPERTY(Data::SyncthingStatistics globalStatistics READ globalStatistics NOTIFY statisticsChanged)
    Q_PROPERTY(Data::SyncthingStatistics localStatistics READ localStatistics NOTIFY statisticsChanged)
    Q_PROPERTY(QStringList connectionConfigNames READ connectionConfigNames NOTIFY settingsChanged)
    Q_PROPERTY(QString currentConnectionConfigName READ currentConnectionConfigName NOTIFY currentConnectionConfigIndexChanged)
    Q_PROPERTY(int currentConnectionConfigIndex READ currentConnectionConfigIndex WRITE setCurrentConnectionConfigIndex NOTIFY
            currentConnectionConfigIndexChanged)
    Q_PROPERTY(int defaultTab READ defaultTab CONSTANT)
    Q_PROPERTY(bool startStopEnabled READ isStartStopEnabled NOTIFY settingsChanged)
    Q_PROPERTY(bool hasInternalErrors READ hasInternalErrors NOTIFY hasInternalErrorsChanged)
    Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY sizeChanged)
    Q_PROPERTY(bool showTabTexts READ isShowingTabTexts WRITE setShowingTabTexts NOTIFY showTabTextsChanged)
    Q_PROPERTY(bool showDownloads READ isShowingDownloads WRITE setShowingDownloads NOTIFY showDownloadsChanged)
    Q_PROPERTY(bool passive READ isPassive NOTIFY passiveChanged)
    Q_PROPERTY(QList<QtUtilities::ChecklistItem> passiveStates READ passiveStates WRITE setPassiveStates)
    Q_PROPERTY(QString faUrl READ faUrl NOTIFY faUrlChanged)
    Q_PROPERTY(bool wipFeaturesEnabled READ areWipFeaturesEnabled CONSTANT)

public:
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    SyncthingApplet(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
#else
    SyncthingApplet(QObject *parent, const QVariantList &data);
#endif
    ~SyncthingApplet() override;

public:
    Data::SyncthingConnection *connection() const;
    Data::SyncthingDirectoryModel *dirModel() const;
    Data::SyncthingSortFilterModel *sortFilterDirModel() const;
    Data::SyncthingDeviceModel *devModel() const;
    Data::SyncthingSortFilterModel *sortFilterDevModel() const;
    Data::SyncthingDownloadModel *downloadModel() const;
    Data::SyncthingRecentChangesModel *recentChangesModel() const;
    Data::SyncthingStatusSelectionModel *passiveSelectionModel() const;
    Data::SyncthingService *service() const;
    bool isLocal() const;
    QString statusText() const;
    QString additionalStatusText() const;
    QIcon statusIcon() const;
    QIcon syncthingIcon() const;
    QString connectButtonState() const;
    QString incomingTraffic() const;
    bool hasIncomingTraffic() const;
    QString outgoingTraffic() const;
    bool hasOutgoingTraffic() const;
    Data::SyncthingStatistics globalStatistics() const;
    Data::SyncthingStatistics localStatistics() const;
    QStringList connectionConfigNames() const;
    QString currentConnectionConfigName() const;
    int currentConnectionConfigIndex() const;
    int defaultTab() const;
    Data::SyncthingConnectionSettings *currentConnectionConfig();
    Data::SyncthingConnectionSettings *connectionConfig(int index);
    void setCurrentConnectionConfigIndex(int index);
    bool isStartStopEnabled() const;
    bool hasInternalErrors() const;
    QSize size() const;
    void setSize(const QSize &size);
    bool isShowingTabTexts() const;
    void setShowingTabTexts(bool showTabTexts);
    bool isShowingDownloads() const;
    void setShowingDownloads(bool showDownloads);
    bool isPassive() const;
    const QList<QtUtilities::ChecklistItem> &passiveStates() const;
    void setPassiveStates(const QList<QtUtilities::ChecklistItem> &passiveStates);
    QString faUrl();
    Q_INVOKABLE QIcon loadForkAwesomeIcon(const QString &name, int size = 32) const;
    Q_INVOKABLE QString formatFileSize(quint64 fileSizeInByte) const;
    Q_INVOKABLE QString substituteTilde(const QString &path) const;
    bool areWipFeaturesEnabled() const;

public Q_SLOTS:
    void init() override;
    void initEngine(QObject *object);
    void showSettingsDlg();
    void showWizard();
    void showWebUI();
    void showLog();
    void showOwnDeviceId();
    void showAboutDialog();
    void showNotificationsDialog();
    void showInternalErrorsDialog();
    void showDirectoryErrors(const QString &dirId);
    void browseRemoteFiles(const QString &dirId);
    void showIgnorePatterns(const QString &dirId);
    void copyToClipboard(const QString &text);
    void copyToClipboard(const QString &dirId, const QString &relativePath);
    void openLocalFileOrDir(const QString &dirId, const QString &relativePath);
    void updateStatusIconAndTooltip();
    void triggerConnectButtonAction();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    void handleRelevantControlsChanged(bool visible, int index);
#endif
    void saveSettings();

Q_SIGNALS:
    void localChanged();
    void connectionStatusChanged();
    void trafficChanged();
    void statisticsChanged();
    void settingsChanged();
    void currentConnectionConfigIndexChanged(int index);
    void hasInternalErrorsChanged(bool hasInternalErrors);
    void sizeChanged(const QSize &size);
    void showTabTextsChanged(bool isShowingTabTexts);
    void showDownloadsChanged(bool isShowingDownloads);
    void passiveChanged(bool passive);
    void faUrlChanged(const QString &faUrl);

private Q_SLOTS:
    void handleSettingsChanged();
    void handleConnectionStatusChanged(Data::SyncthingStatus previousStatus, Data::SyncthingStatus newStatus);
    void handleDevicesChanged();
    void handleInternalError(
        const QString &errorMsg, Data::SyncthingErrorCategory category, int networkError, const QNetworkRequest &request, const QByteArray &response);
    void handleDirStatisticsChanged();
    void handleErrorsCleared();
    void handleAboutDialogDeleted();
    void handleWebViewDeleted();
    void handleNotificationsDialogDeleted();
    void handleNewNotification(CppUtilities::DateTime when, const QString &msg);
    void handleSystemdServiceError(const QString &context, const QString &name, const QString &message);
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
    void handleSystemdStatusChanged();
#endif
    void handleImageProviderDestroyed();
    void handleThemeChanged();
    void setPassive(bool passive);
    void setBrightColors(bool brightColors);
    void applySettings(int changeConnectionIndex = -1);
    void applySettingsChangesFromWizard();
    void concludeWizard(const QString &errorMessage = QString());

private:
    void showCenteredDialog(QWidget *dlg);

    Plasma::Theme m_theme;
    QString m_faUrl;
    QPalette m_palette;
    Data::IconManager &m_iconManager;
    QtUtilities::AboutDialog *m_aboutDlg;
    Data::SyncthingConnection m_connection;
    Data::SyncthingOverallDirStatistics m_overallStats;
    Data::SyncthingNotifier m_notifier;
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
    Data::SyncthingService m_service;
#endif
    QtGui::StatusInfo m_statusInfo;
    Data::SyncthingDirectoryModel m_dirModel;
    Data::SyncthingSortFilterModel m_sortFilterDirModel;
    Data::SyncthingDeviceModel m_devModel;
    Data::SyncthingSortFilterModel m_sortFilterDevModel;
    Data::SyncthingDownloadModel m_downloadModel;
    Data::SyncthingRecentChangesModel m_recentChangesModel;
    Data::SyncthingStatusSelectionModel m_passiveSelectionModel;
    SettingsDialog *m_settingsDlg;
    QtGui::Wizard *m_wizard;
    QtGui::DBusStatusNotifier m_dbusNotifier;
    QtForkAwesome::QuickImageProvider *m_imageProvider;
    QtGui::WebViewDialog *m_webViewDlg;
    QDialog *m_notificationsDlg;
    int m_currentConnectionConfig;
    int m_defaultTab;
    int m_lastTab;
    bool m_hasInternalErrors;
    bool m_initialized;
    bool m_showTabTexts;
    bool m_showDownloads;
    bool m_applyingSettingsForWizard;
    QSize m_size;
};

inline Data::SyncthingConnection *SyncthingApplet::connection() const
{
    return const_cast<Data::SyncthingConnection *>(&m_connection);
}

inline Data::SyncthingDirectoryModel *SyncthingApplet::dirModel() const
{
    return const_cast<Data::SyncthingDirectoryModel *>(&m_dirModel);
}

inline Data::SyncthingSortFilterModel *SyncthingApplet::sortFilterDirModel() const
{
    return const_cast<Data::SyncthingSortFilterModel *>(&m_sortFilterDirModel);
}

inline Data::SyncthingDeviceModel *SyncthingApplet::devModel() const
{
    return const_cast<Data::SyncthingDeviceModel *>(&m_devModel);
}

inline Data::SyncthingSortFilterModel *SyncthingApplet::sortFilterDevModel() const
{
    return const_cast<Data::SyncthingSortFilterModel *>(&m_sortFilterDevModel);
}

inline Data::SyncthingDownloadModel *SyncthingApplet::downloadModel() const
{
    return const_cast<Data::SyncthingDownloadModel *>(&m_downloadModel);
}

inline Data::SyncthingRecentChangesModel *SyncthingApplet::recentChangesModel() const
{
    return const_cast<Data::SyncthingRecentChangesModel *>(&m_recentChangesModel);
}

inline Data::SyncthingStatusSelectionModel *SyncthingApplet::passiveSelectionModel() const
{
    return const_cast<Data::SyncthingStatusSelectionModel *>(&m_passiveSelectionModel);
}

inline Data::SyncthingService *SyncthingApplet::service() const
{
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
    return const_cast<Data::SyncthingService *>(&m_service);
#else
    return nullptr;
#endif
}

inline QString SyncthingApplet::statusText() const
{
    return m_statusInfo.statusText();
}

inline QString SyncthingApplet::additionalStatusText() const
{
    return m_statusInfo.additionalStatusText();
}

inline bool SyncthingApplet::isLocal() const
{
    return m_connection.isLocal();
}

inline int SyncthingApplet::currentConnectionConfigIndex() const
{
    return m_currentConnectionConfig;
}

inline int SyncthingApplet::defaultTab() const
{
    return m_defaultTab;
}

inline Data::SyncthingConnectionSettings *SyncthingApplet::currentConnectionConfig()
{
    return connectionConfig(m_currentConnectionConfig);
}

inline QSize SyncthingApplet::size() const
{
    return m_size;
}

inline void SyncthingApplet::setSize(const QSize &size)
{
    if (size != m_size) {
        emit sizeChanged(m_size = size);
    }
}

inline bool SyncthingApplet::isShowingTabTexts() const
{
    return m_showTabTexts;
}

inline void SyncthingApplet::setShowingTabTexts(bool showTabTexts)
{
    if (showTabTexts != m_showTabTexts) {
        emit showTabTextsChanged(m_showTabTexts = showTabTexts);
    }
}

inline bool SyncthingApplet::isShowingDownloads() const
{
    return m_showDownloads;
}

inline void SyncthingApplet::setShowingDownloads(bool showDownloads)
{
    if (showDownloads != m_showDownloads) {
        emit showDownloadsChanged(m_showDownloads = showDownloads);
    }
}

inline bool SyncthingApplet::isPassive() const
{
    return status() == Plasma::Types::PassiveStatus;
}

inline const QList<QtUtilities::ChecklistItem> &SyncthingApplet::passiveStates() const
{
    return m_passiveSelectionModel.items();
}

inline QString SyncthingApplet::faUrl()
{
    return m_faUrl;
}

inline void SyncthingApplet::setPassive(bool passive)
{
    if (passive != isPassive()) {
        setStatus(passive ? Plasma::Types::PassiveStatus : Plasma::Types::ActiveStatus);
        emit passiveChanged(passive);
    }
}
} // namespace Plasmoid

#endif // SYNCTHINGAPPLET_H