mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-02 18:36:49 +01:00
Notifications now provide API for invoking targets.
This commit is contained in:
parent
1d8c9a2545
commit
9447491ef7
@ -35,7 +35,8 @@
|
|||||||
|
|
||||||
|
|
||||||
Notification::Notification() : QWidget(0), m_title(QString()), m_text(QString()), m_icon(QPixmap()), m_screen(-1),
|
Notification::Notification() : QWidget(0), m_title(QString()), m_text(QString()), m_icon(QPixmap()), m_screen(-1),
|
||||||
m_width(-1), m_height(-1), m_padding(5), m_widgetMargin(2 * m_padding), m_timerId(0) {
|
m_width(-1), m_height(-1), m_padding(5), m_widgetMargin(2 * m_padding), m_timerId(0), m_clickTarget(NULL),
|
||||||
|
m_clickSlot(NULL) {
|
||||||
setupWidget();
|
setupWidget();
|
||||||
loadSettings();
|
loadSettings();
|
||||||
}
|
}
|
||||||
@ -48,14 +49,22 @@ bool Notification::areNotificationsActivated() {
|
|||||||
return qApp->settings()->value(GROUP(GUI), SETTING(GUI::UseFancyNotifications)).toBool();
|
return qApp->settings()->value(GROUP(GUI), SETTING(GUI::UseFancyNotifications)).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::notify(const QString &text, const QString &title, const QIcon &icon) {
|
void Notification::notify(const QString &text, const QString &title, const QIcon &icon,
|
||||||
|
QObject *invokation_target, const char *invokation_slot) {
|
||||||
cancel();
|
cancel();
|
||||||
|
|
||||||
// Set new values.
|
// Set new values.
|
||||||
|
m_clickTarget = invokation_target;
|
||||||
|
m_clickSlot = invokation_slot;
|
||||||
m_text = text;
|
m_text = text;
|
||||||
m_title = title;
|
m_title = title;
|
||||||
m_icon = icon.pixmap(NOTIFICATION_ICON_SIZE, NOTIFICATION_ICON_SIZE);
|
m_icon = icon.pixmap(NOTIFICATION_ICON_SIZE, NOTIFICATION_ICON_SIZE);
|
||||||
|
|
||||||
|
if (m_clickTarget != NULL && m_clickSlot != NULL) {
|
||||||
|
// Connect invokation target.
|
||||||
|
connect(this, SIGNAL(clicked()), m_clickTarget, m_clickSlot, Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
|
||||||
// Show it.
|
// Show it.
|
||||||
updateGeometries();
|
updateGeometries();
|
||||||
repaint();
|
repaint();
|
||||||
@ -64,13 +73,22 @@ void Notification::notify(const QString &text, const QString &title, const QIcon
|
|||||||
m_timerId = startTimer(10000);
|
m_timerId = startTimer(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::notify(const QString &text, const QString &title, QSystemTrayIcon::MessageIcon icon) {
|
void Notification::notify(const QString &text, const QString &title, QSystemTrayIcon::MessageIcon icon,
|
||||||
notify(text, title, MessageBox::iconForStatus((QMessageBox::Icon) icon));
|
QObject *invokation_target, const char *invokation_slot) {
|
||||||
|
notify(text, title, MessageBox::iconForStatus((QMessageBox::Icon) icon), invokation_target, invokation_slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::cancel() {
|
void Notification::cancel() {
|
||||||
hide();
|
hide();
|
||||||
|
|
||||||
|
if (m_clickTarget != NULL && m_clickSlot != NULL) {
|
||||||
|
// Disconnect previous bubble click signalling.
|
||||||
|
disconnect(this, SIGNAL(clicked()), m_clickTarget, m_clickSlot);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_clickSlot = NULL;
|
||||||
|
m_clickTarget = NULL;
|
||||||
|
|
||||||
if (m_timerId != 0) {
|
if (m_timerId != 0) {
|
||||||
killTimer(m_timerId);
|
killTimer(m_timerId);
|
||||||
}
|
}
|
||||||
@ -169,6 +187,7 @@ void Notification::paintEvent(QPaintEvent *event) {
|
|||||||
|
|
||||||
void Notification::mousePressEvent(QMouseEvent *event) {
|
void Notification::mousePressEvent(QMouseEvent *event) {
|
||||||
QWidget::mousePressEvent(event);
|
QWidget::mousePressEvent(event);
|
||||||
|
emit clicked();
|
||||||
cancel();
|
cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +34,11 @@ class Notification : public QWidget {
|
|||||||
static bool areNotificationsActivated();
|
static bool areNotificationsActivated();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void notify(const QString &text, const QString &title, const QIcon &icon);
|
// Main methods for using the netofication.
|
||||||
void notify(const QString &text, const QString &title, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
|
void notify(const QString &text, const QString &title, const QIcon &icon,
|
||||||
|
QObject *invokation_target = NULL, const char *invokation_slot = NULL);
|
||||||
|
void notify(const QString &text, const QString &title, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information,
|
||||||
|
QObject *invokation_target = NULL, const char *invokation_slot = NULL);
|
||||||
|
|
||||||
void cancel();
|
void cancel();
|
||||||
|
|
||||||
@ -46,6 +49,9 @@ class Notification : public QWidget {
|
|||||||
void leaveEvent(QEvent *event);
|
void leaveEvent(QEvent *event);
|
||||||
void timerEvent(QTimerEvent *event);
|
void timerEvent(QTimerEvent *event);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void setupWidget();
|
void setupWidget();
|
||||||
@ -65,6 +71,9 @@ class Notification : public QWidget {
|
|||||||
int m_padding;
|
int m_padding;
|
||||||
int m_widgetMargin;
|
int m_widgetMargin;
|
||||||
int m_timerId;
|
int m_timerId;
|
||||||
|
|
||||||
|
QObject *m_clickTarget;
|
||||||
|
const char *m_clickSlot;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NOTIFICATION_H
|
#endif // NOTIFICATION_H
|
||||||
|
@ -170,18 +170,19 @@ void Application::deleteTrayIcon() {
|
|||||||
|
|
||||||
void Application::showGuiMessage(const QString &title, const QString &message,
|
void Application::showGuiMessage(const QString &title, const QString &message,
|
||||||
QSystemTrayIcon::MessageIcon message_type, QWidget *parent,
|
QSystemTrayIcon::MessageIcon message_type, QWidget *parent,
|
||||||
bool show_at_least_msgbox, const QIcon &custom_icon) {
|
bool show_at_least_msgbox, const QIcon &custom_icon,
|
||||||
|
QObject *invokation_target, const char *invokation_slot) {
|
||||||
if (Notification::areNotificationsActivated()) {
|
if (Notification::areNotificationsActivated()) {
|
||||||
// Show OSD instead if tray icon bubble, depending on settings.
|
// Show OSD instead if tray icon bubble, depending on settings.
|
||||||
if (custom_icon.isNull()) {
|
if (custom_icon.isNull()) {
|
||||||
notification()->notify(message, title, message_type);
|
notification()->notify(message, title, message_type, invokation_target, invokation_slot);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
notification()->notify(message, title, custom_icon);
|
notification()->notify(message, title, custom_icon, invokation_target, invokation_slot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (SystemTrayIcon::isSystemTrayActivated()) {
|
else if (SystemTrayIcon::isSystemTrayActivated()) {
|
||||||
trayIcon()->showMessage(title, message, message_type, TRAY_ICON_BUBBLE_TIMEOUT);
|
trayIcon()->showMessage(title, message, message_type, TRAY_ICON_BUBBLE_TIMEOUT, invokation_target, invokation_slot);
|
||||||
}
|
}
|
||||||
else if (show_at_least_msgbox) {
|
else if (show_at_least_msgbox) {
|
||||||
// Tray icon or OSD is not available, display simple text box.
|
// Tray icon or OSD is not available, display simple text box.
|
||||||
|
@ -146,7 +146,8 @@ class Application : public QtSingleApplication {
|
|||||||
// Displays given simple message in tray icon bubble or OSD
|
// Displays given simple message in tray icon bubble or OSD
|
||||||
// or in message box if tray icon is disabled.
|
// or in message box if tray icon is disabled.
|
||||||
void showGuiMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon message_type,
|
void showGuiMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon message_type,
|
||||||
QWidget *parent = NULL, bool show_at_least_msgbox = false, const QIcon &custom_icon = QIcon());
|
QWidget *parent = NULL, bool show_at_least_msgbox = false, const QIcon &custom_icon = QIcon(),
|
||||||
|
QObject *invokation_target = NULL, const char *invokation_slot = NULL);
|
||||||
|
|
||||||
// Returns pointer to "GOD" application singleton.
|
// Returns pointer to "GOD" application singleton.
|
||||||
inline static Application *instance() {
|
inline static Application *instance() {
|
||||||
|
@ -195,7 +195,7 @@ bool SystemFactory::isUpdateNewer(const QString &update_version) {
|
|||||||
int current_number = current_version_tkn.takeFirst().toInt();
|
int current_number = current_version_tkn.takeFirst().toInt();
|
||||||
int new_number = new_version_tkn.takeFirst().toInt();
|
int new_number = new_version_tkn.takeFirst().toInt();
|
||||||
|
|
||||||
if (new_number > current_number) {
|
if (new_number != current_number) {
|
||||||
// New version is indeed higher thatn current version.
|
// New version is indeed higher thatn current version.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -255,12 +255,9 @@ void SystemFactory::checkForUpdatesOnStartup() {
|
|||||||
UpdateCheck updates = checkForUpdates();
|
UpdateCheck updates = checkForUpdates();
|
||||||
|
|
||||||
if (updates.second == QNetworkReply::NoError && isUpdateNewer(updates.first.m_availableVersion)) {
|
if (updates.second == QNetworkReply::NoError && isUpdateNewer(updates.first.m_availableVersion)) {
|
||||||
if (SystemTrayIcon::isSystemTrayActivated()) {
|
qApp->showGuiMessage(tr("New version available"),
|
||||||
qApp->trayIcon()->showMessage(tr("New version available"),
|
tr("Click the bubble for more information."),
|
||||||
tr("Click the bubble for more information."),
|
QSystemTrayIcon::Information,
|
||||||
QSystemTrayIcon::Information,
|
NULL, false, QIcon(), qApp->mainForm(), SLOT(showUpdates()));
|
||||||
TRAY_ICON_BUBBLE_TIMEOUT,
|
|
||||||
qApp->mainForm(), SLOT(showUpdates()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user