Notifications settings
This commit is contained in:
parent
b0cad6cee9
commit
4aa1cdfa52
@ -55,5 +55,6 @@
|
|||||||
<file>web.png</file>
|
<file>web.png</file>
|
||||||
<file>library.png</file>
|
<file>library.png</file>
|
||||||
<file>media-playback-start-32.png</file>
|
<file>media-playback-start-32.png</file>
|
||||||
|
<file>lightbulb.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
BIN
data/lightbulb.png
Normal file
BIN
data/lightbulb.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
@ -228,6 +228,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
connect(settings_dialog_, SIGNAL(accepted()), player_, SLOT(ReloadSettings()));
|
connect(settings_dialog_, SIGNAL(accepted()), player_, SLOT(ReloadSettings()));
|
||||||
|
connect(settings_dialog_, SIGNAL(accepted()), osd_, SLOT(ReloadSettings()));
|
||||||
|
|
||||||
// Analyzer
|
// Analyzer
|
||||||
ui_.analyzer->set_engine(player_->GetEngine());
|
ui_.analyzer->set_engine(player_->GetEngine());
|
||||||
|
35
src/osd.cpp
35
src/osd.cpp
@ -2,15 +2,30 @@
|
|||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
const char* OSD::kSettingsGroup = "OSD";
|
||||||
|
|
||||||
OSD::OSD(QSystemTrayIcon* tray_icon, QObject* parent)
|
OSD::OSD(QSystemTrayIcon* tray_icon, QObject* parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
tray_icon_(tray_icon),
|
tray_icon_(tray_icon),
|
||||||
timeout_(5000)
|
timeout_(5000),
|
||||||
|
behaviour_(Native)
|
||||||
{
|
{
|
||||||
|
ReloadSettings();
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
void OSD::SongChanged(const Song &song) {
|
void OSD::SongChanged(const Song &song) {
|
||||||
QString summary(song.PrettyTitle());
|
QString summary(song.PrettyTitle());
|
||||||
if (!song.artist().isNull())
|
if (!song.artist().isNull())
|
||||||
@ -38,3 +53,21 @@ void OSD::Stopped() {
|
|||||||
void OSD::VolumeChanged(int value) {
|
void OSD::VolumeChanged(int value) {
|
||||||
ShowMessage(QCoreApplication::applicationName(), QString("Volume %1%").arg(value));
|
ShowMessage(QCoreApplication::applicationName(), QString("Volume %1%").arg(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
26
src/osd.h
26
src/osd.h
@ -19,20 +19,38 @@ class OSD : public QObject {
|
|||||||
public:
|
public:
|
||||||
OSD(QSystemTrayIcon* tray_icon, QObject* parent = 0);
|
OSD(QSystemTrayIcon* tray_icon, QObject* parent = 0);
|
||||||
|
|
||||||
void Init();
|
static const char* kSettingsGroup;
|
||||||
void ShowMessage(const QString& summary,
|
|
||||||
const QString& message = QString::null,
|
enum Behaviour {
|
||||||
const QString& icon = QString::null);
|
Disabled = 0,
|
||||||
|
Native,
|
||||||
|
TrayPopup,
|
||||||
|
};
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void ReloadSettings();
|
||||||
|
|
||||||
void SongChanged(const Song& song);
|
void SongChanged(const Song& song);
|
||||||
void Paused();
|
void Paused();
|
||||||
void Stopped();
|
void Stopped();
|
||||||
void VolumeChanged(int value);
|
void VolumeChanged(int value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void ShowMessage(const QString& summary,
|
||||||
|
const QString& message = QString::null,
|
||||||
|
const QString& icon = QString::null);
|
||||||
|
|
||||||
|
// These are implemented in the OS-specific files
|
||||||
|
void Init();
|
||||||
|
bool CanShowNativeMessages() const;
|
||||||
|
void ShowMessageNative(const QString& summary,
|
||||||
|
const QString& message = QString::null,
|
||||||
|
const QString& icon = QString::null);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSystemTrayIcon* tray_icon_;
|
QSystemTrayIcon* tray_icon_;
|
||||||
int timeout_;
|
int timeout_;
|
||||||
|
Behaviour behaviour_;
|
||||||
|
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
NotifyNotification* notification_;
|
NotifyNotification* notification_;
|
||||||
|
@ -5,7 +5,12 @@
|
|||||||
void OSD::Init() {
|
void OSD::Init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSD::ShowMessage(const QString& summary, const QString& message,
|
bool OSD::CanShowNativeMessages() const {
|
||||||
const QString& icon) {
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSD::ShowMessageNative(const QString& summary, const QString& message,
|
||||||
|
const QString& icon) {
|
||||||
|
// This should use growl
|
||||||
tray_icon_->showMessage(summary, message, QSystemTrayIcon::NoIcon, timeout_);
|
tray_icon_->showMessage(summary, message, QSystemTrayIcon::NoIcon, timeout_);
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,12 @@ void OSD::Init() {
|
|||||||
notify_init(QCoreApplication::applicationName().toUtf8().constData());
|
notify_init(QCoreApplication::applicationName().toUtf8().constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSD::ShowMessage(const QString& summary, const QString& message,
|
bool OSD::CanShowNativeMessages() const {
|
||||||
const QString& icon) {
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSD::ShowMessageNative(const QString& summary, const QString& message,
|
||||||
|
const QString& icon) {
|
||||||
if (summary.isNull())
|
if (summary.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "settingsdialog.h"
|
#include "settingsdialog.h"
|
||||||
#include "enginebase.h"
|
#include "enginebase.h"
|
||||||
|
#include "osd.h"
|
||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
@ -8,8 +9,19 @@ SettingsDialog::SettingsDialog(QWidget* parent)
|
|||||||
{
|
{
|
||||||
ui_.setupUi(this);
|
ui_.setupUi(this);
|
||||||
|
|
||||||
|
// List box
|
||||||
connect(ui_.list, SIGNAL(currentTextChanged(QString)), SLOT(CurrentTextChanged(QString)));
|
connect(ui_.list, SIGNAL(currentTextChanged(QString)), SLOT(CurrentTextChanged(QString)));
|
||||||
ui_.list->setCurrentRow(0);
|
ui_.list->setCurrentRow(0);
|
||||||
|
|
||||||
|
// Notifications
|
||||||
|
connect(ui_.notifications_none, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
|
||||||
|
connect(ui_.notifications_native, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
|
||||||
|
connect(ui_.notifications_tray, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
|
||||||
|
|
||||||
|
#ifdef Q_WS_WIN
|
||||||
|
// Sucks to be a windows user
|
||||||
|
ui_.notifications_native->setEnabled(false);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::CurrentTextChanged(const QString &text) {
|
void SettingsDialog::CurrentTextChanged(const QString &text) {
|
||||||
@ -29,6 +41,17 @@ void SettingsDialog::accept() {
|
|||||||
s.setValue("FadeoutDuration", ui_.fadeout_duration->value());
|
s.setValue("FadeoutDuration", ui_.fadeout_duration->value());
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
|
// Notifications
|
||||||
|
OSD::Behaviour osd_behaviour;
|
||||||
|
if (ui_.notifications_none->isChecked()) osd_behaviour = OSD::Disabled;
|
||||||
|
else if (ui_.notifications_native->isChecked()) osd_behaviour = OSD::Native;
|
||||||
|
else if (ui_.notifications_tray->isChecked()) osd_behaviour = OSD::TrayPopup;
|
||||||
|
|
||||||
|
s.beginGroup(OSD::kSettingsGroup);
|
||||||
|
s.setValue("Behaviour", int(osd_behaviour));
|
||||||
|
s.setValue("Timeout", ui_.notifications_duration->value() * 1000);
|
||||||
|
s.endGroup();
|
||||||
|
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,4 +66,20 @@ void SettingsDialog::showEvent(QShowEvent*) {
|
|||||||
ui_.no_fadeout->setChecked(true);
|
ui_.no_fadeout->setChecked(true);
|
||||||
ui_.fadeout_duration->setValue(s.value("FadeoutDuration", 2000).toInt());
|
ui_.fadeout_duration->setValue(s.value("FadeoutDuration", 2000).toInt());
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
|
// Notifications
|
||||||
|
s.beginGroup(OSD::kSettingsGroup);
|
||||||
|
OSD::Behaviour osd_behaviour = OSD::Behaviour(s.value("Behaviour", OSD::Native).toInt());
|
||||||
|
switch (osd_behaviour) {
|
||||||
|
case OSD::Native: ui_.notifications_native->setChecked(true); break;
|
||||||
|
case OSD::TrayPopup: ui_.notifications_tray->setChecked(true); break;
|
||||||
|
case OSD::Disabled:
|
||||||
|
default: ui_.notifications_none->setChecked(true); break;
|
||||||
|
}
|
||||||
|
ui_.notifications_duration->setValue(s.value("Timeout", 5000).toInt() / 1000);
|
||||||
|
s.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsDialog::NotificationTypeChanged() {
|
||||||
|
ui_.notifications_options->setEnabled(!ui_.notifications_none->isChecked());
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ class SettingsDialog : public QDialog {
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void CurrentTextChanged(const QString& text);
|
void CurrentTextChanged(const QString& text);
|
||||||
|
void NotificationTypeChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::SettingsDialog ui_;
|
Ui::SettingsDialog ui_;
|
||||||
|
@ -51,16 +51,25 @@
|
|||||||
<string>Playback</string>
|
<string>Playback</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../data/data.qrc">
|
<iconset>
|
||||||
<normaloff>:/media-playback-start-32.png</normaloff>:/media-playback-start-32.png</iconset>
|
<normaloff>:/media-playback-start-32.png</normaloff>:/media-playback-start-32.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Notifications</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset>
|
||||||
|
<normaloff>:/lightbulb.png</normaloff>:/lightbulb.png</iconset>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Music Library</string>
|
<string>Music Library</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../data/data.qrc">
|
<iconset>
|
||||||
<normaloff>:/library.png</normaloff>:/library.png</iconset>
|
<normaloff>:/library.png</normaloff>:/library.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
@ -69,7 +78,7 @@
|
|||||||
<string>Last.fm</string>
|
<string>Last.fm</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../data/data.qrc">
|
<iconset>
|
||||||
<normaloff>:/last.fm/as.png</normaloff>:/last.fm/as.png</iconset>
|
<normaloff>:/last.fm/as.png</normaloff>:/last.fm/as.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
@ -90,7 +99,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QStackedWidget" name="stackedWidget">
|
<widget class="QStackedWidget" name="stackedWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="page">
|
<widget class="QWidget" name="page">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
@ -186,6 +195,99 @@
|
|||||||
<zorder>groupBox</zorder>
|
<zorder>groupBox</zorder>
|
||||||
<zorder>verticalSpacer</zorder>
|
<zorder>verticalSpacer</zorder>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QWidget" name="page_4">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
|
<property name="margin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Clementine can show a message when the track changes.</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="notifications_none">
|
||||||
|
<property name="text">
|
||||||
|
<string>Don't show notifications</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="notifications_native">
|
||||||
|
<property name="text">
|
||||||
|
<string>Show a native desktop notification</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="notifications_tray">
|
||||||
|
<property name="text">
|
||||||
|
<string>Show a popup from the system tray</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Fixed</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>4</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="notifications_options" native="true">
|
||||||
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Popup duration</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QSpinBox" name="notifications_duration">
|
||||||
|
<property name="suffix">
|
||||||
|
<string> seconds</string>
|
||||||
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>20</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>5</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>286</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
<widget class="QWidget" name="page_2">
|
<widget class="QWidget" name="page_2">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
<property name="margin">
|
<property name="margin">
|
||||||
@ -232,9 +334,7 @@
|
|||||||
<tabstop>fadeout_duration</tabstop>
|
<tabstop>fadeout_duration</tabstop>
|
||||||
<tabstop>buttonBox</tabstop>
|
<tabstop>buttonBox</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources>
|
<resources/>
|
||||||
<include location="../data/data.qrc"/>
|
|
||||||
</resources>
|
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
<sender>list</sender>
|
<sender>list</sender>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user