Clementine-audio-player-Mac.../src/osd.cpp

74 lines
1.8 KiB
C++
Raw Normal View History

2010-01-08 15:52:05 +01:00
#include "osd.h"
2010-01-08 17:21:22 +01:00
#include <QCoreApplication>
#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-02-03 18:21:25 +01:00
timeout_(5000),
behaviour_(Native)
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-02-03 18:21:25 +01:00
void OSD::ReloadSettings() {
QSettings s;
s.beginGroup(kSettingsGroup);
behaviour_ = OSD::Behaviour(s.value("Behaviour", Native).toInt());
timeout_ = s.value("Timeout", 5000).toInt();
if (!CanShowNativeMessages() && behaviour_ == Native)
behaviour_ = TrayPopup;
}
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());
if (!song.artist().isNull())
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)
message_parts << QString("disc %1").arg(song.disc());
2010-01-08 15:52:05 +01:00
if (song.track() > 0)
message_parts << QString("track %1").arg(song.track());
2010-01-08 15:52:05 +01:00
ShowMessage(summary, message_parts.join(", "), "notification-audio-play");
2010-01-08 15:52:05 +01:00
}
void OSD::Paused() {
2010-01-08 17:21:22 +01:00
ShowMessage(QCoreApplication::applicationName(), "Paused");
2010-01-08 15:52:05 +01:00
}
void OSD::Stopped() {
2010-01-08 17:21:22 +01:00
ShowMessage(QCoreApplication::applicationName(), "Playlist finished");
2010-01-08 15:52:05 +01:00
}
2010-01-08 17:40:34 +01:00
void OSD::VolumeChanged(int value) {
ShowMessage(QCoreApplication::applicationName(), QString("Volume %1%").arg(value));
}
2010-02-03 18:21:25 +01:00
void OSD::ShowMessage(const QString& summary,
const QString& message,
const QString& icon) {
switch (behaviour_) {
case Native:
ShowMessageNative(summary, message, icon);
break;
case TrayPopup:
tray_icon_->showMessage(summary, message, QSystemTrayIcon::NoIcon, timeout_);
break;
case Disabled:
default:
break;
}
}