From e2de64d6f1beb9e492daf5b886e19933c1fa41dd Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- noatun/modules/systray/Makefile.am | 16 ++ noatun/modules/systray/cmodule.cpp | 192 +++++++++++++ noatun/modules/systray/cmodule.h | 55 ++++ noatun/modules/systray/kitsystemtray.cpp | 131 +++++++++ noatun/modules/systray/kitsystemtray.h | 54 ++++ noatun/modules/systray/noatunui.cpp | 9 + noatun/modules/systray/systray.cpp | 467 +++++++++++++++++++++++++++++++ noatun/modules/systray/systray.h | 80 ++++++ noatun/modules/systray/systray.plugin | 100 +++++++ noatun/modules/systray/systrayui.rc | 20 ++ noatun/modules/systray/yhconfig.kcfg | 81 ++++++ noatun/modules/systray/yhconfig.kcfgc | 7 + noatun/modules/systray/yhconfigwidget.ui | 333 ++++++++++++++++++++++ 13 files changed, 1545 insertions(+) create mode 100644 noatun/modules/systray/Makefile.am create mode 100644 noatun/modules/systray/cmodule.cpp create mode 100644 noatun/modules/systray/cmodule.h create mode 100644 noatun/modules/systray/kitsystemtray.cpp create mode 100644 noatun/modules/systray/kitsystemtray.h create mode 100644 noatun/modules/systray/noatunui.cpp create mode 100644 noatun/modules/systray/systray.cpp create mode 100644 noatun/modules/systray/systray.h create mode 100644 noatun/modules/systray/systray.plugin create mode 100644 noatun/modules/systray/systrayui.rc create mode 100644 noatun/modules/systray/yhconfig.kcfg create mode 100644 noatun/modules/systray/yhconfig.kcfgc create mode 100644 noatun/modules/systray/yhconfigwidget.ui (limited to 'noatun/modules/systray') diff --git a/noatun/modules/systray/Makefile.am b/noatun/modules/systray/Makefile.am new file mode 100644 index 00000000..1dcfdd25 --- /dev/null +++ b/noatun/modules/systray/Makefile.am @@ -0,0 +1,16 @@ +INCLUDES= -I$(top_srcdir)/noatun/library $(all_includes) +kde_module_LTLIBRARIES = noatun_systray.la + +noatun_systray_la_SOURCES = systray.cpp noatunui.cpp kitsystemtray.cpp cmodule.cpp \ + yhconfig.kcfgc yhconfigwidget.ui + + +noatun_systray_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined +noatun_systray_la_LIBADD = $(LIB_KFILE) $(top_builddir)/noatun/library/libnoatun.la + +noatun_systray_la_METASOURCES = AUTO + +noinst_HEADERS = systray.h kitsystemtray.h cmodule.h + +noatun_modules_systray_DATA = systray.plugin systrayui.rc yhconfig.kcfg +noatun_modules_systraydir = $(kde_datadir)/noatun diff --git a/noatun/modules/systray/cmodule.cpp b/noatun/modules/systray/cmodule.cpp new file mode 100644 index 00000000..4adf7e44 --- /dev/null +++ b/noatun/modules/systray/cmodule.cpp @@ -0,0 +1,192 @@ +// cmodule.cpp +// +// Copyright (C) 2001 Neil Stevens +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name(s) of the author(s) shall not be +// used in advertising or otherwise to promote the sale, use or other dealings +// in this Software without prior written authorization from the author(s). + +#include "cmodule.h" +#include "yhconfig.h" +#include "yhconfigwidget.h" + +#include +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +YHModule::YHModule(QObject *_parent) + : CModule(i18n("System Tray Icon"), i18n("Configure System Tray Icon"), + "bottom", _parent) +{ + QVBoxLayout *top = new QVBoxLayout(this); + mWidget = new YHConfigWidget(this); + top->addWidget(mWidget); + + mWidget->cmbModifier->insertItem(i18n("None"), YHConfig::None); + mWidget->cmbModifier->insertItem(i18n("Shift"), YHConfig::Shift); + mWidget->cmbModifier->insertItem(i18n("Alt"), YHConfig::Alt); + mWidget->cmbModifier->insertItem(i18n("Ctrl"), YHConfig::Ctrl); + mWidget->cmbModifier->setCurrentItem(YHConfig::None); + + connect(mWidget->chkUsePopup, SIGNAL(toggled(bool)), this, SLOT(slotUsePopupToggled(bool))); + connect(mWidget->cmbModifier, SIGNAL(activated(int)), this, SLOT(slotModifierActivated(int))); + connect(mWidget->grpMwheel, SIGNAL(clicked(int)), this, SLOT(slotMwheelClicked(int))); + + reopen(); +} + + +void YHModule::reopen() +{ + kdDebug(66666) << k_funcinfo << endl; + YHConfig *c = YHConfig::self(); + + /** General TAB **/ + + mWidget->chkUseTooltip->setChecked(c->tip()); + mWidget->chkUseCovers->setChecked(c->passivePopupCovers()); + + mWidget->chkUsePopup->setChecked(c->passivePopup()); + mWidget->spinPopupTimeout->setValue(c->passivePopupTimeout()); + mWidget->chkPopupButtons->setChecked(c->passivePopupButtons()); + + switch(c->stateIconDisplay()) + { + case (YHConfig::Animation): + mWidget->rbStateAnim->setChecked(true); + break; + case (YHConfig::FlashingIcon): + mWidget->rbStateFlashing->setChecked(true); + break; + case (YHConfig::StaticIcon): + mWidget->rbStateStatic->setChecked(true); + break; + case (YHConfig::NoIcon): + mWidget->rbStateNone->setChecked(true); + break; + } + + /** Advanced TAB **/ + + if (c->middleMouseAction() == YHConfig::PlayPause) + mWidget->rbPlayPause->setChecked(true); + else + mWidget->rbHideShowPlaylist->setChecked(true); + + mActionMap[YHConfig::None] = YHConfig::self()->mouseWheelAction(YHConfig::None); + mActionMap[YHConfig::Shift] = YHConfig::self()->mouseWheelAction(YHConfig::Shift); + mActionMap[YHConfig::Alt] = YHConfig::self()->mouseWheelAction(YHConfig::Alt); + mActionMap[YHConfig::Ctrl] = YHConfig::self()->mouseWheelAction(YHConfig::Ctrl); + + slotModifierActivated(mWidget->cmbModifier->currentItem()); +} + + +void YHModule::save() +{ + kdDebug(66666) << k_funcinfo << endl; + + YHConfig *c = YHConfig::self(); + + /** General TAB **/ + + c->setTip(mWidget->chkUseTooltip->isChecked()); + c->setPassivePopupCovers(mWidget->chkUseCovers->isChecked()); + + c->setPassivePopup(mWidget->chkUsePopup->isChecked()); + c->setPassivePopupTimeout(mWidget->spinPopupTimeout->value()); + c->setPassivePopupButtons(mWidget->chkPopupButtons->isChecked()); + + if (mWidget->rbStateAnim->isChecked()) + c->setStateIconDisplay(YHConfig::Animation); + else if (mWidget->rbStateFlashing->isChecked()) + c->setStateIconDisplay(YHConfig::FlashingIcon); + else if (mWidget->rbStateStatic->isChecked()) + c->setStateIconDisplay(YHConfig::StaticIcon); + else + c->setStateIconDisplay(YHConfig::NoIcon); + + /** Advanced TAB **/ + + if (mWidget->rbPlayPause->isChecked()) + c->setMiddleMouseAction(YHConfig::PlayPause); + else + c->setMiddleMouseAction(YHConfig::HideShowPlaylist); + + c->setMouseWheelAction(YHConfig::None, mActionMap[YHConfig::None]); + c->setMouseWheelAction(YHConfig::Shift, mActionMap[YHConfig::Shift]); + c->setMouseWheelAction(YHConfig::Alt, mActionMap[YHConfig::Alt]); + c->setMouseWheelAction(YHConfig::Ctrl, mActionMap[YHConfig::Ctrl]); + + c->writeConfig(); + emit saved(); +} + + +void YHModule::slotUsePopupToggled(bool on) +{ + mWidget->lblPopupTimeout->setEnabled(on); + mWidget->spinPopupTimeout->setEnabled(on); + mWidget->chkPopupButtons->setEnabled(on); +} + + +void YHModule::slotModifierActivated(int index) +{ + kdDebug(66666) << k_funcinfo << endl; + switch(mActionMap[index]) + { + case (YHConfig::Nothing): + mWidget->rbActNothing->setChecked(true); + break; + case (YHConfig::ChangeVolume): + mWidget->rbActVolume->setChecked(true); + break; + case (YHConfig::ChangeTrack): + mWidget->rbActTrack->setChecked(true); + break; + } +} + +void YHModule::slotMwheelClicked(int index) +{ + kdDebug(66666) << k_funcinfo << endl; + if (index == 0) + mActionMap[mWidget->cmbModifier->currentItem()] = YHConfig::Nothing; + else if (index == 1) + mActionMap[mWidget->cmbModifier->currentItem()] = YHConfig::ChangeVolume; + else + mActionMap[mWidget->cmbModifier->currentItem()] = YHConfig::ChangeTrack; +} + +#include "cmodule.moc" diff --git a/noatun/modules/systray/cmodule.h b/noatun/modules/systray/cmodule.h new file mode 100644 index 00000000..fecc70e3 --- /dev/null +++ b/noatun/modules/systray/cmodule.h @@ -0,0 +1,55 @@ +// cmodule.h +// +// Copyright (C) 2001 Neil Stevens +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name(s) of the author(s) shall not be +// used in advertising or otherwise to promote the sale, use or other dealings +// in this Software without prior written authorization from the author(s). + +#ifndef CMODULE_H +#define CMODULE_H + +#include +#include + +class YHConfigWidget; + +class YHModule : public CModule +{ +Q_OBJECT + public: + YHModule(QObject *_parent); + virtual void save(); + virtual void reopen(); + + signals: + void saved(); + + private: + YHConfigWidget *mWidget; + QMap mActionMap; + + private slots: + void slotUsePopupToggled(bool on); + void slotModifierActivated(int index); + void slotMwheelClicked(int index); +}; + +#endif diff --git a/noatun/modules/systray/kitsystemtray.cpp b/noatun/modules/systray/kitsystemtray.cpp new file mode 100644 index 00000000..5847d7da --- /dev/null +++ b/noatun/modules/systray/kitsystemtray.cpp @@ -0,0 +1,131 @@ +// $Id$ +// +// Kit +// +// Copyright (C) 1999 Neil Stevens +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name(s) of the author(s) shall not be +// used in advertising or otherwise to promote the sale, use or other dealings +// in this Software without prior written authorization from the author(s). + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "yhconfig.h" + +#include +#include +#include + +#include "kitsystemtray.h" +#include +#include +#include +#include +#include + +#include + +KitSystemTray::KitSystemTray(const QString &contextMenu, KMainWindow *parent, const char *name) + : KSystemTray(parent, name) +{ + setAlignment(AlignHCenter | AlignVCenter); + menu = (KPopupMenu *)parent->guiFactory()->container(contextMenu, parent); + menu->insertTitle(SmallIcon("noatun"), QString::null, 0, 0); + setAcceptDrops(true); +} + +void KitSystemTray::changeTitle(const QPixmap &pixmap, const QString &title) +{ + menu->changeTitle(0, pixmap, title); +} + +void KitSystemTray::showEvent(QShowEvent *) +{ + // empty +} + +void KitSystemTray::mousePressEvent(QMouseEvent *event) +{ + switch(event->button()) + { + case LeftButton: + napp->toggleInterfaces(); + break; + case MidButton: + if (YHConfig::self()->middleMouseAction() == YHConfig::HideShowPlaylist) + napp->playlist()->toggleList(); + else // play or pause + napp->player()->playpause(); + break; + default: + menu->popup(event->globalPos()); + break; + } +} + +void KitSystemTray::dragEnterEvent(QDragEnterEvent * event) +{ + event->accept(KURLDrag::canDecode(event)); // accept uri drops only +} + +void KitSystemTray::dropEvent(QDropEvent * event) +{ + KURL::List uris; + if (KURLDrag::decode(event, uris)) + { + KURL::List::ConstIterator it; + for (it = uris.begin(); it != uris.end(); ++it) + napp->player()->openFile(*it, false); + } +} + +void KitSystemTray::wheelEvent(QWheelEvent *event) +{ + YHConfig *c = YHConfig::self(); + + int action = 0; + if (event->state() & Qt::ShiftButton) + action = c->mouseWheelAction(YHConfig::Shift); + else if (event->state() & Qt::ControlButton) + action = c->mouseWheelAction(YHConfig::Ctrl); + else if (event->state() & Qt::AltButton) + action = c->mouseWheelAction(YHConfig::Alt); + else + action = c->mouseWheelAction(YHConfig::None); + + switch(action) + { + case (YHConfig::ChangeVolume): + napp->player()->setVolume(napp->player()->volume()+event->delta()/24); + break; + case (YHConfig::ChangeTrack): + if (event->delta() > 0) + napp->player()->forward(true); + else + napp->player()->back(); + break; + default: + break; + } +} + +#include "kitsystemtray.moc" diff --git a/noatun/modules/systray/kitsystemtray.h b/noatun/modules/systray/kitsystemtray.h new file mode 100644 index 00000000..2f640adb --- /dev/null +++ b/noatun/modules/systray/kitsystemtray.h @@ -0,0 +1,54 @@ +// $Id$ +// +// Kit +// +// Copyright (C) 1999 Neil Stevens +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name(s) of the author(s) shall not be +// used in advertising or otherwise to promote the sale, use or other dealings +// in this Software without prior written authorization from the author(s). + +#ifndef KITSYSTEMTRAY_H +#define KITSYSTEMTRAY_H + +#include + +class KPopupMenu; +class KMainWindow; +class QPixmap; + +class KitSystemTray : public KSystemTray +{ +Q_OBJECT + +public: + KitSystemTray(const QString &contextMenu, KMainWindow *parent, const char *name = 0); + void changeTitle(const QPixmap &, const QString &); +protected: + virtual void showEvent(QShowEvent *); + virtual void mousePressEvent(QMouseEvent *); + virtual void dragEnterEvent(QDragEnterEvent *); + virtual void dropEvent(QDropEvent *); + virtual void wheelEvent(QWheelEvent *e); + + KPopupMenu *menu; +}; + +#endif diff --git a/noatun/modules/systray/noatunui.cpp b/noatun/modules/systray/noatunui.cpp new file mode 100644 index 00000000..76f9af25 --- /dev/null +++ b/noatun/modules/systray/noatunui.cpp @@ -0,0 +1,9 @@ +#include "systray.h" + +extern "C" +{ + KDE_EXPORT Plugin *create_plugin() + { + return new NoatunSystray(); + } +} diff --git a/noatun/modules/systray/systray.cpp b/noatun/modules/systray/systray.cpp new file mode 100644 index 00000000..c93080ca --- /dev/null +++ b/noatun/modules/systray/systray.cpp @@ -0,0 +1,467 @@ +// systray.h +// +// Copyright (C) 2000 Neil Stevens +// Copyright (C) 1999 Charles Samuels +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name(s) of the author(s) shall not be +// used in advertising or otherwise to promote the sale, use or other dealings +// in this Software without prior written authorization from the author(s). + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "systray.h" +#include "kitsystemtray.h" +#include "cmodule.h" +#include "yhconfig.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +// TODO: Maybe make this value configurable? +const int COVER_MAXW = 128; +const int COVER_MAXH = 128; +#define BASEICON "noatun" + +// From JuK +class PassivePopup : public KPassivePopup +{ +public: + PassivePopup(QWidget *parent = 0, const char *name = 0) : KPassivePopup(parent, name) {} + +protected: + virtual void enterEvent(QEvent *) + { + setTimeout(3000000); // Make timeout damn near infinite + } + + virtual void leaveEvent(QEvent *) + { + setTimeout(250); // Close quickly + } +}; + + +//NoatunSystray *NoatunSystray::self = 0; + + +NoatunSystray::NoatunSystray() : KMainWindow(0, "NoatunSystray"), Plugin(), + mTray(0), trayStatus(0), trayBase(0), mPassivePopup(0L) +{ + //self = this; + hide(); + + tmpCoverPath = locateLocal("tmp", "youngHickoryCover.png"); + + removeCover(); // make sure any old temp cover is gone + + KStdAction::quit(napp, SLOT(quit()), actionCollection()); + KStdAction::open(napp, SLOT(fileOpen()), actionCollection()); + KStdAction::preferences(napp, SLOT(preferences()), actionCollection()); + NoatunStdAction::back(actionCollection(), "back"); + NoatunStdAction::stop(actionCollection(), "stop"); + NoatunStdAction::playpause(actionCollection(), "play"); + NoatunStdAction::forward(actionCollection(), "forward"); + NoatunStdAction::playlist(actionCollection(), "show_playlist"); + NoatunStdAction::loop(actionCollection(), "loop_style"); + NoatunStdAction::effects(actionCollection(), "effects"); + NoatunStdAction::equalizer(actionCollection(), "equalizer"); + + createGUI("systrayui.rc"); + + mTray = new KitSystemTray("tray", this); + mTray->show(); + + trayBase = renderIcon(BASEICON, QString::null); + trayStatus = renderIcon(BASEICON, "player_stop"); + + mTray->changeTitle(*trayBase, i18n("Noatun")); + showingTrayStatus = false; + + mBlinkTimer = new QTimer(this); + connect(mBlinkTimer, SIGNAL(timeout()), this, SLOT(slotBlinkTimer())); + + connect(napp->player(), SIGNAL(playing()), this, SLOT(slotPlayPause())); + connect(napp->player(), SIGNAL(paused()), this, SLOT(slotPlayPause())); + connect(napp->player(), SIGNAL(stopped()), this, SLOT(slotStopped())); + //napp->player()->handleButtons(); +} + + +NoatunSystray::~NoatunSystray() +{ + //kdDebug(66666) << k_funcinfo << "Called." << endl; + removeCover(); + delete trayBase; + delete trayStatus; + napp->showInterfaces(); +} + + +void NoatunSystray::init() +{ + YHModule *cmod = new YHModule(this); + connect(cmod, SIGNAL(saved()), this, SLOT(slotLoadSettings())); + slotLoadSettings(); +} + + +void NoatunSystray::slotLoadSettings() +{ + kdDebug(66666) << k_funcinfo << endl; + + YHConfig *c = YHConfig::self(); + + if(c->stateIconDisplay() == YHConfig::FlashingIcon) + mBlinkTimer->start(1000); + else + mBlinkTimer->stop(); + slotBlinkTimer(); + + + if(c->tip()) + QToolTip::add(mTray, tipText); + else + QToolTip::remove(mTray); + + if (!c->passivePopupCovers()) + removeCover(); + + if(c->passivePopup()) + { + mPassivePopup = new PassivePopup(mTray, "NoatunPassivePopup"); + } + else + { + delete mPassivePopup; + mPassivePopup = 0L; + } +} + + +void NoatunSystray::closeEvent(QCloseEvent*) +{ + //kdDebug(66666) << k_funcinfo << "Called." << endl; + disconnect(napp->player(), 0, 0, 0); + unload(); +} + + +void NoatunSystray::slotPlayPause() +{ + QString status; + + if(napp->player()->isPaused()) + { + changeTray("player_pause"); + status = i18n("Noatun - Paused"); + } + else + { + changeTray("player_play"); + status = i18n("Noatun - Playing"); + } + + const PlaylistItem item = napp->player()->current(); + QString s; + + if(!item.isProperty("title")) + { + // No metadata + s = QString("%1").arg(item.title()); + } + else + { + s = QString("

%1

").arg(item.property("title")); + + if(item.isProperty("author")) + s += QString("%1
").arg(item.property("author")); + + if(item.isProperty("album")) + { + if(item.isProperty("date")) + s += QString("%1 (%2)
").arg(item.property("album")).arg(item.property("date")); + else + s += QString("%1
").arg(item.property("album")); + } + } + + // prepare cover image for display + if (YHConfig::self()->passivePopupCovers()) + updateCover(); + + if(YHConfig::self()->passivePopupCovers() && QFile::exists(tmpCoverPath)) + { + // QT always adds an empty line after the table so we add en empty line before the + // table to get equal spacing on top and bottom + setTipText(QString("
" \ + "" \ + "" \ + "

%1

%2
").arg(status).arg(s).arg(tmpCoverPath)); + } + else + { + setTipText(QString("

%1

%2
").arg(status).arg(s)); + } +} + + +void NoatunSystray::slotStopped() +{ + if(!napp->player()->current()) + return; + changeTray("player_stop"); + setTipText(QString("

%1

").arg(i18n("Noatun - Stopped"))); +} + + + +void NoatunSystray::changeTray(const QString &pm) +{ + delete trayStatus; + trayStatus = renderIcon(BASEICON, pm); + if(showingTrayStatus) + slotBlinkTimer(); +} + + +void NoatunSystray::slotBlinkTimer() +{ + switch(YHConfig::self()->stateIconDisplay()) + { + case (YHConfig::FlashingIcon): + showingTrayStatus ^= true; + break; + case (YHConfig::StaticIcon): + showingTrayStatus = true; + break; + case (YHConfig::NoIcon): + showingTrayStatus = false; + break; + } + + if(showingTrayStatus) + mTray->setPixmap(*trayStatus); + else + mTray->setPixmap(*trayBase); +} + + +// taken from patched karamba xmmssensor +// modified heavily to work in this place +void NoatunSystray::updateCover() +{ + //kdDebug(66666) << k_funcinfo << endl; + QString dir = napp->player()->current().url().directory(); + QString cover; + + // TODO: Maybe make these filenames configurable? + if(QFile::exists(dir + "/folder.png")) + cover = dir + "/folder.png"; + else if(QFile::exists(dir + "/.folder.png")) + cover = dir + "/.folder.png"; + else if(QFile::exists(dir + "/cover.png")) + cover = dir + "/cover.png"; + else if(QFile::exists(dir + "/cover.jpg")) + cover = dir + "/cover.jpg"; + else if(QFile::exists(dir + "/cover.jpeg")) + cover = dir + "/cover.jpeg"; + else // no cover + { + //kdDebug(66666) << k_funcinfo << "NO COVER" << endl; + removeCover(); + return; + } + + QString title = napp->player()->current().title(); + + QImage previmg; + previmg.load(tmpCoverPath); + + if(previmg.text("Title") != title) + { //Verify song change to limit CPU usage + /*kdDebug(66666) << k_funcinfo << "Creating new temp cover for '" << + cover << "'" << endl;*/ + + QImage src; + QImage tmpimg; + + if(src.load(cover)) + { + if(src.width() >= COVER_MAXW || src.height() >= COVER_MAXH) + tmpimg = src.scale(COVER_MAXW, COVER_MAXH, QImage::ScaleMin); + else + tmpimg = src; + + tmpimg.setText("Title", 0, title); //add Title in the image text for cache usage + tmpimg.save(tmpCoverPath, "PNG", 0); + } + else + { + removeCover(); + } + } +} + + +void NoatunSystray::removeCover() +{ + if(QFile::exists(tmpCoverPath)) + KIO::NetAccess::del(KURL(tmpCoverPath), this); +} + + +void NoatunSystray::setTipText(const QString& text) +{ + if(text == tipText) // save the planet, save cpu cycles ;) + return; + tipText = text; + + YHConfig *c = YHConfig::self(); + if(c->passivePopup()) + QTimer::singleShot(0, this, SLOT(showPassivePopup())); + + if(c->tip()) + QToolTip::add(mTray, tipText); +} + + +void NoatunSystray::showPassivePopup() +{ + if (!mPassivePopup) + { + kdDebug(66666) << k_funcinfo << "Called but no KPassivePopup created yet!" << endl; + return; + } + + mPassivePopup->reparent(0L, QPoint(0,0)); + + if (YHConfig::self()->passivePopupButtons() && !napp->player()->isStopped()) + { + QVBox *widget = mPassivePopup->standardView(QString::null, tipText, QPixmap()); + QHBox *box = new QHBox(mPassivePopup, "popupbox"); + + box->setSpacing(8); + + // Algorithm for determining popup location from kpassivepopup.cpp via JuK + NETWinInfo ni(qt_xdisplay(), mTray->winId(), qt_xrootwin(), + NET::WMIconGeometry | NET::WMKDESystemTrayWinFor); + NETRect frame, win; + ni.kdeGeometry(frame, win); + + QRect bounds = KGlobalSettings::desktopGeometry(QPoint(win.pos.x, win.pos.y)); + + if(win.pos.x < bounds.center().x()) + { + // Buttons to the left + + QVBox *buttonBox = new QVBox(box); + buttonBox->setSpacing(3); + + QPushButton *forwardButton = new QPushButton(action("forward")->iconSet(), 0, buttonBox, "popup_forward"); + forwardButton->setFlat(true); + connect(forwardButton, SIGNAL(clicked()), action("forward"), SLOT(activate())); + + QPushButton *backButton = new QPushButton(action("back")->iconSet(), 0, buttonBox, "popup_back"); + backButton->setFlat(true); + connect(backButton, SIGNAL(clicked()), action("back"), SLOT(activate())); + + QFrame *line = new QFrame(box); + line->setFrameShape(QFrame::VLine); + + widget->reparent(box, QPoint(0, 0)); + } + else + { + // Buttons to the right + widget->reparent(box, QPoint(0, 0)); + + QFrame *line = new QFrame(box); + line->setFrameShape(QFrame::VLine); + + QVBox *buttonBox = new QVBox(box); + buttonBox->setSpacing(3); + + QPushButton *forwardButton = new QPushButton(action("forward")->iconSet(), 0, buttonBox, "popup_forward"); + forwardButton->setFlat(true); + connect(forwardButton, SIGNAL(clicked()), action("forward"), SLOT(activate())); + + QPushButton *backButton = new QPushButton(action("back")->iconSet(), 0, buttonBox, "popup_back"); + backButton->setFlat(true); + connect(backButton, SIGNAL(clicked()), action("back"), SLOT(activate())); + } + mPassivePopup->setView(box); + } + else + { + mPassivePopup->setView(QString::null, tipText); + } + + mPassivePopup->setTimeout(YHConfig::self()->passivePopupTimeout()*1000); + mPassivePopup->show(); +} + + +QPixmap *NoatunSystray::renderIcon(const QString& baseIcon, const QString &overlayIcon) const +{ + QPixmap *base = new QPixmap(KSystemTray::loadIcon(baseIcon)); + + if(!(overlayIcon.isNull())) // otherwise leave the base as-is + { + QPixmap overlay = KSystemTray::loadIcon(overlayIcon); + if(!overlay.isNull()) + { + // draw the overlay on top of it + QPainter p(base); + p.drawPixmap(0, 0, overlay); + } + } + return base; +} + +#include "systray.moc" diff --git a/noatun/modules/systray/systray.h b/noatun/modules/systray/systray.h new file mode 100644 index 00000000..f602c4e3 --- /dev/null +++ b/noatun/modules/systray/systray.h @@ -0,0 +1,80 @@ +// systray.h +// +// Copyright (C) 2000 Neil Stevens +// Copyright (C) 1999 Charles Samuels +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name(s) of the author(s) shall not be +// used in advertising or otherwise to promote the sale, use or other dealings +// in this Software without prior written authorization from the author(s). + +#ifndef SYSTRAY_H +#define SYSTRAY_H + +#include +#include + +#include + +#include + +class KitSystemTray; +class QTimer; +class PassivePopup; + +class NoatunSystray : public KMainWindow, public Plugin +{ +Q_OBJECT +public: + NoatunSystray(); + virtual ~NoatunSystray(); + virtual void init(); + +protected: + virtual void closeEvent(QCloseEvent *); + +public slots: + void slotPlayPause(); + void slotStopped(); + +private slots: + void changeTray(const QString &); + void slotLoadSettings(); + void slotBlinkTimer(); + void showPassivePopup(); + QPixmap *renderIcon(const QString &, const QString &) const; + +private: + void setTipText(const QString&); + void updateCover(); + void removeCover(); + +private: + KitSystemTray *mTray; + QTimer *mBlinkTimer; + QPixmap *trayStatus; + QPixmap *trayBase; + PassivePopup *mPassivePopup; + + bool showingTrayStatus; + QString tipText; + QString tmpCoverPath; +}; + +#endif diff --git a/noatun/modules/systray/systray.plugin b/noatun/modules/systray/systray.plugin new file mode 100644 index 00000000..24af57f5 --- /dev/null +++ b/noatun/modules/systray/systray.plugin @@ -0,0 +1,100 @@ +Filename=noatun_systray.la +Author=Neil Stevens +Site=http://noatun.kde.org/plugins/yh/ +Email=neil@qualityassistant.com +Type=systray +License=X11-like +Name=Young Hickory +Name[af]=Jong Hickory +Name[ar]=شجرة الجوز الصغيرة +Name[az]=Gənc Hickory +Name[cs]=Mladý ořech +Name[eo]=Juna hikorio +Name[es]=Joven Nogal +Name[et]=Noor hikkor +Name[fa]=یانگ هیکوری +Name[fi]=Nuori Hickory +Name[fr]=Jeune Hickory +Name[hi]=यंग हिकॉरी +Name[is]=Ungi Hickory +Name[it]=Giovane nocciolina +Name[ko]=젊은 히코리 +Name[lt]=Jaunas Hickory +Name[lv]=Jaunais Hickorijs +Name[ne]=युवा हिक्कोरी +Name[pl]=Tacka systemowa +Name[ru]=Ветка гикори +Name[sk]=Mladý Hickory +Name[sl]=Mladi hikori +Name[sv]=Ung valnöt +Name[ta]=சின்ன ஒருவகை மரம் +Name[tr]=Genç Hickory +Name[ven]=Hickory mutuku +Name[xh]=iHickory encinane +Name[zh_CN]=小胡桃木 +Name[zh_HK]=小山胡桃 +Name[zh_TW]=小山胡桃 +Comment=A system tray interface +Comment[af]='n stelsel laai koppelvlak +Comment[ar]=واجهة للوحة النظام +Comment[az]=Sistem rəf paneli +Comment[bg]=Икона за управление от системния панел +Comment[bn]=একটি সিস্টেম ট্রে ইন্টারফেস +Comment[bs]=Interfejs za sistemski tray +Comment[ca]=Una interfície de la safata del sistema +Comment[cs]=Rozhraní systémové části panelu +Comment[cy]=Rhyngwyneb hambwrdd cysawd +Comment[da]=En statusfelt-grænseflade +Comment[de]=Oberfläche für den Systembereich der Kontrollleiste +Comment[el]=Μια διασύνδεση για το πλαίσιο συστήματος +Comment[eo]=Interfaco por la dokejo +Comment[es]=Una interfaz para la bandeja del sistema +Comment[et]=Süsteemse doki liides +Comment[eu]=Interfazea sistemaren bandejarentzat +Comment[fa]=یک واسط سینی سیستم +Comment[fi]=Järjestelmäikkunan rajapinta +Comment[fr]=Une interface intégrée dans la boîte à miniatures +Comment[gl]=Unha interface para a bandexa do sistema +Comment[he]=ממשק מגש מערכת +Comment[hi]=एक तंत्र तश्तरी इंटरफेस +Comment[hr]=Sučelje za sustavsku ladicu +Comment[hu]=A rendszertálca kezelői felülete +Comment[id]=interface tray sistem +Comment[is]=Aðgangur að kerfisbakka +Comment[it]=Un'interfaccia per il vassoio di sistema +Comment[ja]=システムトレイインターフェース +Comment[kk]=Жүйелік сөре интерфейсі +Comment[km]=ចំណុច​ប្រទាក់​ថាស​ប្រព័ន្ធ +Comment[ko]=시스템 트레이 인터페이스 +Comment[lt]=Sistemos dėklo sąsaja +Comment[lv]=Sistēmas teknes starpseja +Comment[mk]=Интерфејс за системската лента +Comment[ms]=Antaramuka dulang sistem +Comment[mt]=Interfaċċja għat-tray tas-sistema +Comment[nb]=Systemkurv grensesnitt +Comment[nds]=Systeemafsnitt-Koppelsteed +Comment[ne]=प्रणाली ट्रे इन्टरफेस +Comment[nl]=Een systeemvakinterface +Comment[nn]=Systemtrau-grensesnitt +Comment[pa]=ਇੱਕ ਸਿਸਟਮ ਟਰੇ ਇੰਟਰਫੇਸ +Comment[pl]=Interfejs tacki systemowej +Comment[pt]=Uma interface para a bandeja do sistema +Comment[pt_BR]=Uma interface para os ícones de sistema +Comment[ro]=O interfaţă pentru tava de sistem +Comment[ru]=Интерфейс панели системного лотка +Comment[sk]=Rozhranie pre systémovú lištu +Comment[sl]=Vmesnik za sistemsko vrstico v pultu +Comment[sr]=Интерфејс за системску касету +Comment[sr@Latn]=Interfejs za sistemsku kasetu +Comment[sv]=Gränssnitt för aktivitetsfältet +Comment[ta]=அமைப்பு தொகுதித் தட்டு இடைமுகம் +Comment[tg]=Интерфейси сабади системавӣ +Comment[th]=ส่วนติดต่อกับถาดระบบ +Comment[tr]=Sistem çekmecesi arayüzü +Comment[uk]=Інтерфейс системного лотка +Comment[ven]=Thirei ya sisitemu +Comment[xh]=Ujongano lwendlela yetreyi +Comment[zh_CN]=一个系统托盘界面 +Comment[zh_HK]=系統匣介面 +Comment[zh_TW]=System Tray的介面 +Comment[zu]=Isistimu yetreyi loxhumano olubhekene diff --git a/noatun/modules/systray/systrayui.rc b/noatun/modules/systray/systrayui.rc new file mode 100644 index 00000000..2b50654b --- /dev/null +++ b/noatun/modules/systray/systrayui.rc @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/noatun/modules/systray/yhconfig.kcfg b/noatun/modules/systray/yhconfig.kcfg new file mode 100644 index 00000000..9b017aec --- /dev/null +++ b/noatun/modules/systray/yhconfig.kcfg @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + FlashingIcon + + + + + 1 + + + + + true + + + + + true + + + + + 5 + + + + + true + + + + + true + + + + + + + + + + HideShowPlaylist + + + + + + None + Shift + Alt + Ctrl + + + + + + + + ChangeVolume + Nothing + Nothing + ChangeTrack + + + + diff --git a/noatun/modules/systray/yhconfig.kcfgc b/noatun/modules/systray/yhconfig.kcfgc new file mode 100644 index 00000000..5b4f99e4 --- /dev/null +++ b/noatun/modules/systray/yhconfig.kcfgc @@ -0,0 +1,7 @@ +# Code generation options for kconfig_compiler +File=yhconfig.kcfg +ClassName=YHConfig +Singleton=true +Mutators=true +MemberVariables=private +GlobalEnums=true diff --git a/noatun/modules/systray/yhconfigwidget.ui b/noatun/modules/systray/yhconfigwidget.ui new file mode 100644 index 00000000..48267c28 --- /dev/null +++ b/noatun/modules/systray/yhconfigwidget.ui @@ -0,0 +1,333 @@ + +YHConfigWidget + + + YHConfigWidget + + + + 0 + 0 + 371 + 379 + + + + + unnamed + + + 0 + + + + tabWidget2 + + + + tab + + + &General + + + + unnamed + + + + chkUseTooltip + + + Show a &tooltip for the current track + + + + + chkUseCovers + + + Show &covers in popup window and tooltip + + + + + groupBox1 + + + Popup Window + + + + unnamed + + + + lblPopupTimeout + + + Display popup window t&ime: + + + spinPopupTimeout + + + + + chkPopupButtons + + + Show &buttons in popup window + + + + + spinPopupTimeout + + + s + Seconds + + + 600 + + + 1 + + + 5 + + + + + chkUsePopup + + + Announce tracks with a &popup window + + + + + + + buttonGroup1 + + + State Icon Display + + + + unnamed + + + + rbStateAnim + + + false + + + &Animated + + + + + rbStateFlashing + + + &Flashing + + + + + rbStateStatic + + + &Static + + + false + + + + + rbStateNone + + + &None + + + + + + + spacer1 + + + Vertical + + + Expanding + + + + 20 + 81 + + + + + + + + tab + + + Ad&vanced + + + + unnamed + + + + grpMiddleMouse + + + Middle Mouse Button Action + + + + unnamed + + + + rbHideShowPlaylist + + + Hide / Show play&list + + + + + rbPlayPause + + + &Play / Pause + + + + + + + grpMwheel + + + Mouse &Wheel + + + + unnamed + + + + layout1 + + + + unnamed + + + + lblModifier + + + &Keyboard modifier: + + + cmbModifier + + + + + cmbModifier + + + + + + + lblAction + + + Action: + + + + + rbActNothing + + + &Nothing + + + + + rbActVolume + + + Change v&olume + + + + + rbActTrack + + + Switch &track + + + + + + + spacer6 + + + Vertical + + + Expanding + + + + 20 + 21 + + + + + + + + + + tabWidget2 + chkUseTooltip + chkUseCovers + chkUsePopup + spinPopupTimeout + chkPopupButtons + rbStateAnim + rbStateFlashing + rbStateStatic + rbStateNone + rbHideShowPlaylist + rbPlayPause + cmbModifier + rbActNothing + rbActVolume + rbActTrack + + + -- cgit v1.2.1