forked from gyunaev/birdtray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunreadmonitor.h
103 lines (82 loc) · 3.19 KB
/
unreadmonitor.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
#ifndef UNREAD_MONITOR_H
#define UNREAD_MONITOR_H
#include <QThread>
#include <QString>
#include <QColor>
#include <QMap>
#include <QTimer>
#include <QStringList>
#include <QFileSystemWatcher>
class TrayIcon;
class UnreadMonitor : public QThread
{
Q_OBJECT
public:
UnreadMonitor( TrayIcon * parent );
// Thread run function
virtual void run() override;
/**
* Get the current warnings for the watched paths.
* The null-string key can contain a warning for all paths.
*
* @return A path to warnings mapping.
*/
const QMap<QString, QString> &getWarnings() const;
signals:
// Unread counter changed
void unreadUpdated( unsigned int total, QColor color );
/**
* A warning was added or removed for the given watched path.
*
* @param path The watched path or null-string for a global warning.
*/
void warningChanged(const QString &path);
public slots:
void slotSettingsChanged();
void watchedFileChanges( const QString& filechanged );
void updateUnread();
// This one forces rereading Mork files
void forceUpdateUnread();
private:
void getUnreadCount_Mork( int & count, QColor& color );
int getMorkUnreadCount( const QString& path );
/**
* Set a warning for a given path or for all paths, if no path is given.
* Overwrites any previous warning.
*
* @param message The warning message.
* @param path The watched path.
*/
void setWarning(const QString &message, const QString &path = QString());
/**
* Reset the warning if there was one for the given watched path.
* Or reset the global warning for all paths, if no path is given.
*
* @param path The path to the watched mork file.
*/
void clearWarning(const QString &path = QString());
private:
// Maps the Mork files to unread counts
QMap< QString, quint32 > mMorkUnreadCounts;
// Watches the files for changes
QFileSystemWatcher mDBWatcher;
// Thunderbird tends to do lots of modifications to the MSF file
// each time a new email arrives. This results in lots of notifications,
// and thus lots of unread calls. To avoid this, we set up the timer each
// time a new notification is issued, and reset it for each further notification.
// We only read the file(s) if the timer expires.
QTimer mChangedMSFtimer;
// List of changed files (for MSF monitoring)
QList<QString> mChangedMSFfiles;
// This timer is used when force update is set, triggering such update
QTimer mForceUpdateTimer;
// Last reported unread
int mLastReportedUnread;
QColor mLastColor;
/**
* This contains mappings from watched paths to warning messages for that path.
* If there is a warning in the null-string key, it applies to all paths.
*/
QMap<QString, QString> warnings;
};
#endif /* UNREAD_MONITOR_H */