2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-01-08 15:52:05 +01:00
|
|
|
#include "osd.h"
|
2010-03-25 20:30:10 +01:00
|
|
|
#include "osdpretty.h"
|
2010-01-08 15:52:05 +01:00
|
|
|
|
2010-01-08 17:21:22 +01:00
|
|
|
#include <QCoreApplication>
|
2010-01-08 20:50:29 +01:00
|
|
|
#include <QtDebug>
|
2010-02-03 18:21:25 +01:00
|
|
|
#include <QSettings>
|
|
|
|
|
|
|
|
const char* OSD::kSettingsGroup = "OSD";
|
2010-01-08 17:21:22 +01:00
|
|
|
|
2010-01-08 15:52:05 +01:00
|
|
|
OSD::OSD(QSystemTrayIcon* tray_icon, QObject* parent)
|
|
|
|
: QObject(parent),
|
2010-01-08 16:37:35 +01:00
|
|
|
tray_icon_(tray_icon),
|
2010-03-30 02:08:16 +02:00
|
|
|
timeout_msec_(5000),
|
2010-02-27 01:48:27 +01:00
|
|
|
behaviour_(Native),
|
2010-02-28 02:08:18 +01:00
|
|
|
show_on_volume_change_(false),
|
2010-03-25 20:30:10 +01:00
|
|
|
show_art_(true),
|
|
|
|
pretty_popup_(new OSDPretty)
|
2010-01-08 15:52:05 +01:00
|
|
|
{
|
2010-02-03 18:21:25 +01:00
|
|
|
ReloadSettings();
|
2010-01-08 15:52:05 +01:00
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
2010-03-25 20:30:10 +01:00
|
|
|
OSD::~OSD() {
|
|
|
|
delete pretty_popup_;
|
|
|
|
}
|
|
|
|
|
2010-02-03 18:21:25 +01:00
|
|
|
void OSD::ReloadSettings() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
behaviour_ = OSD::Behaviour(s.value("Behaviour", Native).toInt());
|
2010-03-30 02:08:16 +02:00
|
|
|
timeout_msec_ = s.value("Timeout", 5000).toInt();
|
2010-02-27 01:48:27 +01:00
|
|
|
show_on_volume_change_ = s.value("ShowOnVolumeChange", false).toBool();
|
2010-02-28 02:08:18 +01:00
|
|
|
show_art_ = s.value("ShowArt", true).toBool();
|
2010-02-03 18:21:25 +01:00
|
|
|
|
2010-02-26 23:37:48 +01:00
|
|
|
if (!SupportsNativeNotifications() && behaviour_ == Native)
|
2010-03-25 22:29:17 +01:00
|
|
|
behaviour_ = Pretty;
|
2010-02-26 23:37:48 +01:00
|
|
|
if (!SupportsTrayPopups() && behaviour_ == TrayPopup)
|
|
|
|
behaviour_ = Disabled;
|
2010-03-25 20:30:10 +01:00
|
|
|
|
2010-03-30 02:08:16 +02:00
|
|
|
pretty_popup_->set_popup_duration(timeout_msec_);
|
2010-03-25 20:30:10 +01:00
|
|
|
pretty_popup_->ReloadSettings();
|
2010-02-03 18:21:25 +01:00
|
|
|
}
|
|
|
|
|
2010-01-08 15:52:05 +01:00
|
|
|
void OSD::SongChanged(const Song &song) {
|
2010-01-08 17:40:34 +01:00
|
|
|
QString summary(song.PrettyTitle());
|
2010-02-26 23:13:13 +01:00
|
|
|
if (!song.artist().isEmpty())
|
2010-01-08 17:40:34 +01:00
|
|
|
summary = QString("%1 - %2").arg(song.artist(), summary);
|
2010-01-08 15:52:05 +01:00
|
|
|
|
2010-01-08 17:40:34 +01:00
|
|
|
QStringList message_parts;
|
2010-01-08 15:52:05 +01:00
|
|
|
if (!song.album().isEmpty())
|
|
|
|
message_parts << song.album();
|
|
|
|
if (song.disc() > 0)
|
2010-03-29 12:24:36 +02:00
|
|
|
message_parts << tr("disc %1").arg(song.disc());
|
2010-01-08 15:52:05 +01:00
|
|
|
if (song.track() > 0)
|
2010-03-29 12:24:36 +02:00
|
|
|
message_parts << tr("track %1").arg(song.track());
|
2010-01-08 15:52:05 +01:00
|
|
|
|
2010-02-28 02:08:18 +01:00
|
|
|
ShowMessage(summary, message_parts.join(", "), "notification-audio-play",
|
|
|
|
show_art_ ? song.GetBestImage() : QImage());
|
2010-01-08 15:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSD::Paused() {
|
2010-02-23 19:33:09 +01:00
|
|
|
ShowMessage(QCoreApplication::applicationName(), tr("Paused"));
|
2010-01-08 15:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSD::Stopped() {
|
2010-02-23 19:33:09 +01:00
|
|
|
ShowMessage(QCoreApplication::applicationName(), tr("Playlist finished"));
|
2010-01-08 15:52:05 +01:00
|
|
|
}
|
2010-01-08 17:40:34 +01:00
|
|
|
|
|
|
|
void OSD::VolumeChanged(int value) {
|
2010-02-27 01:48:27 +01:00
|
|
|
if (!show_on_volume_change_)
|
|
|
|
return;
|
|
|
|
|
2010-02-23 19:33:09 +01:00
|
|
|
ShowMessage(QCoreApplication::applicationName(), tr("Volume %1%").arg(value));
|
2010-01-08 17:40:34 +01:00
|
|
|
}
|
2010-02-03 18:21:25 +01:00
|
|
|
|
|
|
|
void OSD::ShowMessage(const QString& summary,
|
|
|
|
const QString& message,
|
2010-02-25 01:18:32 +01:00
|
|
|
const QString& icon,
|
|
|
|
const QImage& image) {
|
2010-02-03 18:21:25 +01:00
|
|
|
switch (behaviour_) {
|
|
|
|
case Native:
|
2010-02-25 01:18:32 +01:00
|
|
|
if (image.isNull()) {
|
2010-03-30 02:08:16 +02:00
|
|
|
ShowMessageNative(summary, message, icon, QImage());
|
2010-02-25 01:18:32 +01:00
|
|
|
} else {
|
2010-03-30 02:08:16 +02:00
|
|
|
ShowMessageNative(summary, message, QString(), image);
|
2010-02-25 01:18:32 +01:00
|
|
|
}
|
2010-02-03 18:21:25 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TrayPopup:
|
2010-03-30 02:08:16 +02:00
|
|
|
tray_icon_->showMessage(summary, message, QSystemTrayIcon::NoIcon, timeout_msec_);
|
2010-02-03 18:21:25 +01:00
|
|
|
break;
|
|
|
|
|
2010-03-25 20:30:10 +01:00
|
|
|
case Pretty:
|
|
|
|
pretty_popup_->SetMessage(summary, message, image);
|
|
|
|
pretty_popup_->show();
|
|
|
|
break;
|
|
|
|
|
2010-02-03 18:21:25 +01:00
|
|
|
case Disabled:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-03-26 00:03:28 +01:00
|
|
|
|
|
|
|
#ifndef Q_WS_X11
|
|
|
|
void OSD::CallFinished(QDBusPendingCallWatcher*) {}
|
|
|
|
#endif
|