From 873b67f010d427b16ce575ef77b9ef7873a6d44a Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Fri, 26 Dec 2008 18:14:26 +0000 Subject: notification plugin: volume change notification, transparency settings git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@712 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/notifier/notifier.cpp | 36 ++++-- src/plugins/General/notifier/notifier.h | 4 +- src/plugins/General/notifier/popupwidget.cpp | 111 +++++++++++++------ src/plugins/General/notifier/popupwidget.h | 16 ++- src/plugins/General/notifier/settingsdialog.cpp | 8 +- src/plugins/General/notifier/settingsdialog.ui | 121 ++++++++++++++++----- .../notifier/translations/notifier_plugin_cs.ts | 39 ++++--- .../notifier/translations/notifier_plugin_de.ts | 53 +++++---- .../notifier/translations/notifier_plugin_ru.ts | 40 ++++--- .../notifier/translations/notifier_plugin_uk_UA.ts | 40 ++++--- .../notifier/translations/notifier_plugin_zh_CN.ts | 53 +++++---- .../notifier/translations/notifier_plugin_zh_TW.ts | 53 +++++---- 12 files changed, 392 insertions(+), 182 deletions(-) (limited to 'src/plugins/General/notifier') diff --git a/src/plugins/General/notifier/notifier.cpp b/src/plugins/General/notifier/notifier.cpp index 1340c0d5a..5bdba1595 100644 --- a/src/plugins/General/notifier/notifier.cpp +++ b/src/plugins/General/notifier/notifier.cpp @@ -31,15 +31,19 @@ Notifier::Notifier(QObject *parent) : General(parent) { m_popupWidget = 0; + m_l = -1; + m_r = -1; QFile::remove(QDir::homePath()+"/.psi/tune"); QSettings settings(Qmmp::configFile(), QSettings::IniFormat); settings.beginGroup("Notifier"); - m_desktop = settings.value("desktop_notification", TRUE).toBool(); + m_desktop = settings.value("song_notification", TRUE).toBool(); + m_showVolume = settings.value("volume_notification", TRUE).toBool(); m_psi = settings.value("psi_notification", FALSE).toBool(); settings.endGroup(); m_core = SoundCore::instance(); connect (m_core, SIGNAL(metaDataChanged ()), SLOT(showMetaData())); connect (m_core, SIGNAL(stateChanged (Qmmp::State)), SLOT(setState(Qmmp::State))); + connect (m_core, SIGNAL(volumeChanged(int, int)), SLOT(showVolume(int, int))); } Notifier::~Notifier() @@ -47,7 +51,7 @@ Notifier::~Notifier() void Notifier::setState(Qmmp::State state) { - switch ((uint) state) + switch ((uint) state) { case Qmmp::Playing: { @@ -67,11 +71,14 @@ void Notifier::setState(Qmmp::State state) void Notifier::showMetaData() { - if (m_popupWidget) - delete m_popupWidget; - if(m_desktop) - m_popupWidget = new PopupWidget(); - if(!m_psi) + if (m_desktop) + { + if (!m_popupWidget) + m_popupWidget = new PopupWidget(); + m_popupWidget->showMetaData(); + } + + if (!m_psi) return; QFile file(QDir::homePath()+"/.psi/tune"); //psi file file.open(QIODevice::WriteOnly | QIODevice::Text); @@ -82,3 +89,18 @@ void Notifier::showMetaData() file.write(QString("%1").arg(m_core->length()).toUtf8()+"\n"); file.close(); } + +void Notifier::showVolume(int l, int r) +{ + if (((m_l != l) || (m_r != r)) && m_showVolume) + { + if (m_l >= 0) + { + if (!m_popupWidget) + m_popupWidget = new PopupWidget(); + m_popupWidget->showVolume(qMax(l,r)); + } + m_l = l; + m_r = r; + } +} diff --git a/src/plugins/General/notifier/notifier.h b/src/plugins/General/notifier/notifier.h index a6702a26a..d9cbb7faf 100644 --- a/src/plugins/General/notifier/notifier.h +++ b/src/plugins/General/notifier/notifier.h @@ -42,12 +42,14 @@ public: private slots: void showMetaData(); + void showVolume(int, int); void setState(Qmmp::State state); private: QPointer m_popupWidget; - bool m_desktop; + bool m_desktop, m_showVolume; bool m_psi; + int m_l, m_r; SoundCore *m_core; }; diff --git a/src/plugins/General/notifier/popupwidget.cpp b/src/plugins/General/notifier/popupwidget.cpp index 98c4e3462..9e7c3cc53 100644 --- a/src/plugins/General/notifier/popupwidget.cpp +++ b/src/plugins/General/notifier/popupwidget.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "popupwidget.h" @@ -36,6 +37,48 @@ PopupWidget::PopupWidget(QWidget *parent) setWindowFlags(Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint | Qt::Window); setFrameStyle(QFrame::Box | QFrame::Plain); + + QHBoxLayout *hlayout = new QHBoxLayout(this); + QLabel *pixlabel = new QLabel(this); + pixlabel->setPixmap(QPixmap(":/notifier_icon.png")); + pixlabel->setFixedSize(32,32); + hlayout->addWidget(pixlabel); + //layout + QVBoxLayout *vlayout = new QVBoxLayout(); + hlayout->addLayout (vlayout); + setLayout(hlayout); + //first line + m_label1 = new QLabel(this); + vlayout->addWidget(m_label1); + //second line + m_label2 = new QLabel(this); + vlayout->addWidget(m_label2); + //resize(sizeHint()); //update size hint + //settings + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + settings.beginGroup("Notifier"); + int delay = settings.value("message_delay", 2000).toInt(); + m_pos = settings.value("message_pos", PopupWidget::BOTTOMLEFT).toUInt(); + setWindowOpacity(settings.value("opacity", 1.0).toDouble()); + settings.endGroup(); + //timer + m_timer = new QTimer(this); + m_timer->setInterval(delay); + m_timer->setSingleShot (TRUE); + connect(m_timer, SIGNAL(timeout ()), SLOT(deleteLater())); +} + +PopupWidget::~PopupWidget() +{} + +void PopupWidget::mousePressEvent (QMouseEvent *) +{ + deleteLater(); +} + +void PopupWidget::showMetaData() +{ + m_timer->stop(); SoundCore *core = SoundCore::instance(); QString title = core->metaData(Qmmp::TITLE); if (title.isEmpty()) @@ -45,56 +88,54 @@ PopupWidget::PopupWidget(QWidget *parent) title.append(" "); title.append(QString("(%1:%2)").arg(core->length()/60).arg(core->length()%60, 2, 10, QChar('0'))); } - - QHBoxLayout *hlayout = new QHBoxLayout(this); - QLabel *pixlabel = new QLabel(this); - pixlabel->setPixmap(QPixmap(":/notifier_icon.png")); - pixlabel->setFixedSize(32,32); - hlayout->addWidget(pixlabel); - - QVBoxLayout *vlayout = new QVBoxLayout(); - QLabel *label1 = new QLabel(""+title+"", this); - vlayout->addWidget(label1); + m_label1->setText("" + title + ""); QString info = core->metaData(Qmmp::ARTIST); if (!info.isEmpty() && !core->metaData(Qmmp::ALBUM).isEmpty()) info.append(" - " + core->metaData(Qmmp::ALBUM)); if (!info.isEmpty()) { - QLabel *label2 = new QLabel(info, this); - vlayout->addWidget(label2); + m_label2->setText(info); + m_label2->show(); } + else + m_label2->hide(); + qApp->processEvents(); + resize(sizeHint()); + qApp->processEvents(); + updatePosition(); + qApp->processEvents(); + show(); + m_timer->start(); +} - hlayout->addLayout (vlayout); - setLayout(hlayout); +void PopupWidget::showVolume(int v) +{ + m_timer->stop(); + m_label1->setText("" + tr("Volume:") + QString (" %1\%").arg(v)+ + ""); + + m_label2->hide(); + qApp->processEvents(); resize(sizeHint()); - QSettings settings(Qmmp::configFile(), QSettings::IniFormat); - settings.beginGroup("Notifier"); - int delay = settings.value("message_delay", 2000).toInt(); - uint pos = settings.value("message_pos", PopupWidget::BOTTOMLEFT).toUInt(); - settings.endGroup(); + qApp->processEvents(); + updatePosition(); + qApp->processEvents(); + show(); + m_timer->start(); +} + +void PopupWidget::updatePosition() +{ //calculate widget position int x = 5, y = 5; QSize desktopSize = QApplication::desktop()->size(); - if (pos == LEFT || pos == RIGHT || pos == CENTER) + if (m_pos == LEFT || m_pos == RIGHT || m_pos == CENTER) y = desktopSize.height()/2 - height()/2; - else if (pos == BOTTOMLEFT || pos == BOTTOM || pos == BOTTOMRIGHT) + else if (m_pos == BOTTOMLEFT || m_pos == BOTTOM || m_pos == BOTTOMRIGHT) y = desktopSize.height() - height() - 5; - if (pos == TOP || pos == BOTTOM || pos == CENTER) + if (m_pos == TOP || m_pos == BOTTOM || m_pos == CENTER) x = desktopSize.width()/2 - width()/2; - else if (pos == TOPRIGHT || pos == RIGHT || pos == BOTTOMRIGHT) + else if (m_pos == TOPRIGHT || m_pos == RIGHT || m_pos == BOTTOMRIGHT) x = desktopSize.width() - width() - 5; - move (x,y); - QTimer::singleShot(delay, this, SLOT(deleteLater())); - show(); -} - -PopupWidget::~PopupWidget() -{} - -void PopupWidget::mousePressEvent (QMouseEvent *) -{ - deleteLater(); } - diff --git a/src/plugins/General/notifier/popupwidget.h b/src/plugins/General/notifier/popupwidget.h index cfda202a5..989b37bd7 100644 --- a/src/plugins/General/notifier/popupwidget.h +++ b/src/plugins/General/notifier/popupwidget.h @@ -23,6 +23,9 @@ #include #include +class QTimer; +class QLabel; + /** @author Ilya Kotov */ @@ -47,7 +50,18 @@ public: CENTER }; -virtual void mousePressEvent (QMouseEvent *); + void showMetaData(); + void showVolume(int); + +protected: + virtual void mousePressEvent (QMouseEvent *); + +private: + void updatePosition(); + QTimer *m_timer; + QLabel *m_label1; + QLabel *m_label2; + uint m_pos; }; diff --git a/src/plugins/General/notifier/settingsdialog.cpp b/src/plugins/General/notifier/settingsdialog.cpp index d7f2e2660..6bb582e04 100644 --- a/src/plugins/General/notifier/settingsdialog.cpp +++ b/src/plugins/General/notifier/settingsdialog.cpp @@ -46,7 +46,9 @@ SettingsDialog::SettingsDialog(QWidget *parent) uint pos = settings.value("message_pos", PopupWidget::BOTTOMLEFT).toUInt(); m_buttons.value(pos)->setChecked(TRUE); ui.psiCheckBox->setChecked(settings.value("psi_notification", FALSE).toBool()); - ui.desktopCheckBox->setChecked(settings.value("desktop_notification", TRUE).toBool()); + ui.songCheckBox->setChecked(settings.value("song_notification", TRUE).toBool()); + ui.volumeCheckBox->setChecked(settings.value("volume_notification", TRUE).toBool()); + ui.transparencySlider->setValue(100 - settings.value("opacity", 1.0).toDouble()*100); settings.endGroup(); } @@ -67,7 +69,9 @@ void SettingsDialog::accept() } settings.setValue("message_pos", pos); settings.setValue("psi_notification", ui.psiCheckBox->isChecked()); - settings.setValue("desktop_notification", ui.desktopCheckBox->isChecked()); + settings.setValue("song_notification", ui.songCheckBox->isChecked()); + settings.setValue("volume_notification", ui.volumeCheckBox->isChecked()); + settings.setValue ("opacity", 1.0 - (double)ui.transparencySlider->value()/100); settings.endGroup(); QDialog::accept(); } diff --git a/src/plugins/General/notifier/settingsdialog.ui b/src/plugins/General/notifier/settingsdialog.ui index b64a389e1..b321bccf1 100644 --- a/src/plugins/General/notifier/settingsdialog.ui +++ b/src/plugins/General/notifier/settingsdialog.ui @@ -5,20 +5,20 @@ 0 0 - 278 - 330 + 244 + 349 Notifier Plugin Settings - + Psi Notification - + @@ -34,25 +34,32 @@ Desktop Notification - + - + - Enable desktop notification + Song change notification - + + + + Volume change notification + + + + - Message delay, ms: + Delay, ms: Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - + 100 @@ -68,15 +75,54 @@ - - + + - Position + Transparency - - + + + + 90 + + + Qt::Horizontal + + + + + + + + 18 + 0 + + + + 0 + + + + + + + Qt::Vertical + + + + 20 + 32 + + + + + + + + 3 + @@ -196,15 +242,22 @@ - - + + + + Position + + + + + - Qt::Horizontal + Qt::Vertical - 40 - 20 + 20 + 30 @@ -212,7 +265,7 @@ - + Qt::Horizontal @@ -225,7 +278,7 @@ - + @@ -249,8 +302,8 @@ accept() - 183 - 303 + 257 + 341 62 @@ -265,8 +318,8 @@ reject() - 249 - 298 + 257 + 341 95 @@ -274,5 +327,21 @@ + + transparencySlider + valueChanged(int) + trasparencyLabel + setNum(int) + + + 183 + 187 + + + 233 + 184 + + + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_cs.ts b/src/plugins/General/notifier/translations/notifier_plugin_cs.ts index 3e485ac54..56b78381a 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_cs.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_cs.ts @@ -23,6 +23,14 @@ Autor: Ilja Kotov <forkotov02@hotmail.ru> + + PopupWidget + + + Volume: + + + SettingsDialog @@ -45,30 +53,35 @@ Desktop Notification Notifikace na pracovní ploše + + + Position + Umístění + - Enable desktop notification - Povolit notifikaci na pracovní ploše + Song change notification + - Message delay, ms: - Prodleva zprávy, ms: + Volume change notification + - - Position - Umístění + + Delay, ms: + - - OK - OK + + Transparency + - - Cancel - Zrušit + + 0 + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_de.ts b/src/plugins/General/notifier/translations/notifier_plugin_de.ts index f0a844b5b..579d51174 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_de.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_de.ts @@ -1,6 +1,5 @@ - NotifierFactory @@ -25,12 +24,15 @@ - SettingsDialog + PopupWidget - - Status Icon Plugin Settings - Status Icon Plugin Einstellungen + + Volume: + + + + SettingsDialog Psi Notification @@ -47,34 +49,39 @@ Desktop-Benachrichtigungen - - Enable desktop notification - Einschalten + + Position + Position - - Message delay, ms: - Verzögerung, ms: + + Notifier Plugin Settings + Einstellungen des Benachrichtigungs-Plugins - - Position - Position + + Song change notification + - - OK - OK + + Volume change notification + - - Cancel - Abbrechen + + Delay, ms: + - - Notifier Plugin Settings - Einstellungen des Benachrichtigungs-Plugins + + Transparency + + + + + 0 + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_ru.ts b/src/plugins/General/notifier/translations/notifier_plugin_ru.ts index e07e74a52..fe4ec5027 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_ru.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_ru.ts @@ -1,6 +1,5 @@ - NotifierFactory @@ -24,6 +23,14 @@ Разработчик: Илья Котов <forkotov02@hotmail.ru> + + PopupWidget + + + Volume: + + + SettingsDialog @@ -46,30 +53,35 @@ Desktop Notification Сообщение на рабочем столе + + + Position + Позциция + - Enable desktop notification - Показывать сообщение на рабочем столе + Song change notification + - Message delay, ms: - Задержка сообщения, мс: + Volume change notification + - - Position - Позциция + + Delay, ms: + - - OK - OK + + Transparency + - - Cancel - Отмена + + 0 + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_uk_UA.ts b/src/plugins/General/notifier/translations/notifier_plugin_uk_UA.ts index e39437e8b..08550ca14 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_uk_UA.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_uk_UA.ts @@ -1,6 +1,5 @@ - NotifierFactory @@ -24,6 +23,14 @@ Розробник: Ілля Котов <forkotov02@hotmail.ru> + + PopupWidget + + + Volume: + + + SettingsDialog @@ -46,30 +53,35 @@ Desktop Notification Повідомлення на робочому столі + + + Position + Позиція + - Enable desktop notification - Відображати повідомлення на робочому столі + Song change notification + - Message delay, ms: - Затримка повідомлення, мс: + Volume change notification + - - Position - Позиція + + Delay, ms: + - - OK - Застосувати + + Transparency + - - Cancel - Відміна + + 0 + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_zh_CN.ts b/src/plugins/General/notifier/translations/notifier_plugin_zh_CN.ts index 630855f4b..c75aecaf3 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_zh_CN.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_zh_CN.ts @@ -1,6 +1,5 @@ - NotifierFactory @@ -25,12 +24,15 @@ - SettingsDialog + PopupWidget - - Status Icon Plugin Settings - 状态图标插件设置 + + Volume: + + + + SettingsDialog Psi Notification @@ -47,34 +49,39 @@ 桌面通知 - - Enable desktop notification - 启用桌面通知 + + Position + 位置 - - Message delay, ms: - 消息延时(ms): + + Notifier Plugin Settings + 通知插件设置 - - Position - 位置 + + Song change notification + - - OK - 确定 + + Volume change notification + - - Cancel - 取消 + + Delay, ms: + - - Notifier Plugin Settings - 通知插件设置 + + Transparency + + + + + 0 + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_zh_TW.ts b/src/plugins/General/notifier/translations/notifier_plugin_zh_TW.ts index d89f8b425..ac72b47b7 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_zh_TW.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_zh_TW.ts @@ -1,6 +1,5 @@ - NotifierFactory @@ -25,12 +24,15 @@ - SettingsDialog + PopupWidget - - Status Icon Plugin Settings - 狀態圖像插件設定 + + Volume: + + + + SettingsDialog Psi Notification @@ -47,34 +49,39 @@ 桌面通知 - - Enable desktop notification - 啟用桌面通知 + + Position + 位置 - - Message delay, ms: - 訊息延時(ms): + + Notifier Plugin Settings + 通知插件設定 - - Position - 位置 + + Song change notification + - - OK - 確定 + + Volume change notification + - - Cancel - 取消 + + Delay, ms: + - - Notifier Plugin Settings - 通知插件設定 + + Transparency + + + + + 0 + -- cgit v1.2.3-13-gbd6f