On linux, don't reuse the notification if it's already probably closed. Fixes nastyness on KDE4. Fixes issue #118.

Also merge the two ShowMessageNative functions to cut down on copypasta.
This commit is contained in:
David Sansome 2010-03-30 00:08:16 +00:00
parent 3a33d220f6
commit 4e5218a189
5 changed files with 27 additions and 46 deletions

View File

@ -26,7 +26,7 @@ const char* OSD::kSettingsGroup = "OSD";
OSD::OSD(QSystemTrayIcon* tray_icon, QObject* parent)
: QObject(parent),
tray_icon_(tray_icon),
timeout_(5000),
timeout_msec_(5000),
behaviour_(Native),
show_on_volume_change_(false),
show_art_(true),
@ -44,7 +44,7 @@ void OSD::ReloadSettings() {
QSettings s;
s.beginGroup(kSettingsGroup);
behaviour_ = OSD::Behaviour(s.value("Behaviour", Native).toInt());
timeout_ = s.value("Timeout", 5000).toInt();
timeout_msec_ = s.value("Timeout", 5000).toInt();
show_on_volume_change_ = s.value("ShowOnVolumeChange", false).toBool();
show_art_ = s.value("ShowArt", true).toBool();
@ -53,7 +53,7 @@ void OSD::ReloadSettings() {
if (!SupportsTrayPopups() && behaviour_ == TrayPopup)
behaviour_ = Disabled;
pretty_popup_->set_popup_duration(timeout_);
pretty_popup_->set_popup_duration(timeout_msec_);
pretty_popup_->ReloadSettings();
}
@ -96,14 +96,14 @@ void OSD::ShowMessage(const QString& summary,
switch (behaviour_) {
case Native:
if (image.isNull()) {
ShowMessageNative(summary, message, icon);
ShowMessageNative(summary, message, icon, QImage());
} else {
ShowMessageNative(summary, message, image);
ShowMessageNative(summary, message, QString(), image);
}
break;
case TrayPopup:
tray_icon_->showMessage(summary, message, QSystemTrayIcon::NoIcon, timeout_);
tray_icon_->showMessage(summary, message, QSystemTrayIcon::NoIcon, timeout_msec_);
break;
case Pretty:

View File

@ -73,16 +73,14 @@ class OSD : public QObject {
// These are implemented in the OS-specific files
void Init();
void ShowMessageNative(const QString& summary,
const QString& message = QString(),
const QString& icon = QString());
void ShowMessageNative(const QString& summary,
const QString& message,
const QImage& image);
const QString& icon = QString(),
const QImage& image = QImage());
private:
QSystemTrayIcon* tray_icon_;
int timeout_;
int timeout_msec_;
Behaviour behaviour_;
bool show_on_volume_change_;
bool show_art_;
@ -97,6 +95,7 @@ class OSD : public QObject {
#ifdef Q_WS_X11
boost::scoped_ptr<org::freedesktop::Notifications> interface_;
uint notification_id_;
QDateTime last_notification_time_;
#endif
private slots:
void CallFinished(QDBusPendingCallWatcher* watcher);

View File

@ -119,15 +119,7 @@ bool OSD::SupportsTrayPopups() {
}
void OSD::ShowMessageNative(const QString& summary, const QString& message,
const QString& icon) {
const QString& icon, const QImage& image) {
Q_UNUSED(icon);
wrapper_->ShowMessage(summary, message, QImage());
}
void OSD::ShowMessageNative(const QString& summary,
const QString& message,
const QImage& image) {
wrapper_->ShowMessage(summary, message, image);
}

View File

@ -30,11 +30,6 @@ bool OSD::SupportsTrayPopups() {
}
void OSD::ShowMessageNative(const QString&, const QString&,
const QString&) {
qWarning() << __PRETTY_FUNCTION__ << ": NOT IMPLEMENTED";
}
void OSD::ShowMessageNative(const QString& summary, const QString& message,
const QImage& image) {
const QString&, const QImage&) {
qWarning() << __PRETTY_FUNCTION__ << ": NOT IMPLEMENTED";
}

View File

@ -72,36 +72,30 @@ bool OSD::SupportsTrayPopups() {
}
void OSD::ShowMessageNative(const QString& summary, const QString& message,
const QString& icon) {
QDBusPendingReply<uint> reply = interface_->Notify(
QCoreApplication::applicationName(),
notification_id_,
icon,
summary,
message,
QStringList(),
QVariantMap(),
timeout_);
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
SLOT(CallFinished(QDBusPendingCallWatcher*)));
}
void OSD::ShowMessageNative(const QString& summary, const QString& message,
const QImage& image) {
const QString& icon, const QImage& image) {
QVariantMap hints;
if (!image.isNull()) {
hints["image_data"] = QVariant(image);
}
int id = 0;
if (last_notification_time_.secsTo(QDateTime::currentDateTime()) * 1000
< timeout_msec_) {
// Reuse the existing popup if it's still open. The reason we don't always
// reuse the popup is because the notification daemon on KDE4 won't re-show
// the bubble if it's already gone to the tray. See issue #118
id = notification_id_;
}
QDBusPendingReply<uint> reply = interface_->Notify(
QCoreApplication::applicationName(),
notification_id_,
QString(),
id,
icon,
summary,
message,
QStringList(),
hints,
timeout_);
timeout_msec_);
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
SLOT(CallFinished(QDBusPendingCallWatcher*)));
@ -119,5 +113,6 @@ void OSD::CallFinished(QDBusPendingCallWatcher* watcher) {
uint id = reply.value();
if (id != 0) {
notification_id_ = id;
last_notification_time_ = QDateTime::currentDateTime();
}
}