-
Notifications
You must be signed in to change notification settings - Fork 288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initialise DBus notifications in another thread #152
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,9 @@ | |
|
||
#include <QIcon> | ||
#include <QObject> | ||
#include <QThread> | ||
|
||
#include <atomic> | ||
|
||
QT_BEGIN_NAMESPACE | ||
class QSystemTrayIcon; | ||
|
@@ -20,6 +23,23 @@ class QDBusInterface; | |
#endif | ||
QT_END_NAMESPACE | ||
|
||
class Notificator; | ||
|
||
#ifdef USE_DBUS | ||
class DBusInitThread : public QThread | ||
{ | ||
Q_OBJECT | ||
|
||
Notificator& m_notificator; | ||
|
||
public: | ||
DBusInitThread(Notificator& notificator) : m_notificator(notificator) {}; | ||
|
||
protected: | ||
void run() override; | ||
}; | ||
#endif | ||
|
||
/** Cross-platform desktop notification client. */ | ||
class Notificator: public QObject | ||
{ | ||
|
@@ -63,11 +83,15 @@ public slots: | |
UserNotificationCenter /**< Use the 10.8+ User Notification Center (Mac only) */ | ||
}; | ||
QString programName; | ||
Mode mode; | ||
std::atomic<Mode> mode; | ||
QSystemTrayIcon *trayIcon; | ||
#ifdef USE_DBUS | ||
QThread *m_dbus_init_thread{nullptr}; | ||
protected: | ||
QDBusInterface *interface; | ||
friend class DBusInitThread; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Signal can be invoked from within
In the result,
..would be performed on thread
Also, adding |
||
|
||
private: | ||
void notifyDBus(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout); | ||
#endif | ||
void notifySystray(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emit finished here and clean up instead of keeping the thread for the
Notificator
lifecycle?DBusInitThread
name implies it's disposable as soon as init is done.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that supposed to be an automatic part of Qt? The docs say the user can't emit it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I think it used to be public signal but seems that is no longer the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say move
m_dbus_init_thread->wait();
call into~DBusInitThread()
, so it no longer can be possible to misuse (forget). Also, connectingfinished()
signal could perform cleanup: