[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [Amarok] Initial commit for KNotify support in Amarok.
From: Kevin Funk <krf () electrostorm ! net>
Date: 2009-09-28 21:45:37
Message-ID: 200909282145.n8SLjbjV017796 () Wurst ! kollide ! net
[Download RAW message or body]
commit 9134a2b7fbe186f3e7352f631839ee1f4c94285a
Author: Kevin Funk <krf@electrostorm.net>
AuthorDate: Fri Sep 11 12:05:06 2009 +0200
Commit: Kevin Funk <krf@electrostorm.net>
CommitDate: Mon Sep 28 23:31:07 2009 +0200
Initial commit for KNotify support in Amarok.
diff --git a/src/App.cpp b/src/App.cpp
index fd57096..68e19e0 100644
--- a/src/App.cpp
+++ b/src/App.cpp
@@ -26,6 +26,7 @@
#include "Debug.h"
#include "EngineController.h"
#include "firstruntutorial/FirstRunTutorial.h"
+#include "KNotificationBackend.h"
#include "Meta.h"
#include "meta/MetaConstants.h"
#include "MountPointManager.h"
@@ -57,6 +58,7 @@
#include <KJob>
#include <KJobUiDelegate>
#include <KLocale>
+#include <KNotifyConfigWidget> //slotConfigNotifications()
#include <KShortcutsDialog> //slotConfigShortcuts()
#include <KSplashScreen>
#include <KStandardDirs>
@@ -663,6 +665,7 @@ App::continueInit()
PERF_LOG( "Done creating MainWindow" )
m_tray = new Amarok::TrayIcon( mainWindow() );
+ new Amarok::KNotificationBackend();
PERF_LOG( "Creating DBus handlers" )
new Amarok::RootDBusHandler();
@@ -750,6 +753,11 @@ void App::slotConfigShortcuts()
AmarokConfig::self()->writeConfig();
}
+void App::slotConfigNotifications()
+{
+ KNotifyConfigWidget::configure( mainWindow() );
+}
+
KIO::Job *App::trashFiles( const KUrl::List &files )
{
KIO::Job *job = KIO::trash( files );
diff --git a/src/App.h b/src/App.h
index 8a61a96..3360d39 100644
--- a/src/App.h
+++ b/src/App.h
@@ -83,6 +83,7 @@ class AMAROK_EXPORT App : public KUniqueApplication
#endif // DEBUG
void slotConfigAmarok( const QString& page = QString() );
void slotConfigShortcuts();
+ void slotConfigNotifications();
void slotConfigEqualizer();
KIO::Job *trashFiles( const KUrl::List &files );
void quit();
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7cb6d07..8d4fb77 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -573,6 +573,7 @@ set(amaroklib_LIB_SRCS
EngineController.cpp
EngineObserver.cpp
Expression.cpp
+ KNotificationBackend.cpp
MainWindow.cpp
MediaDeviceCache.cpp
MediaDeviceMonitor.cpp
@@ -702,6 +703,7 @@ target_link_libraries(amaroklib
${KDE4_KFILE_LIBS}
${KDE4_THREADWEAVER_LIBRARIES}
${KDE4_KNEWSTUFF2_LIBS}
+ ${KDE4_KNOTIFYCONFIG_LIBS}
${KDE4_PHONON_LIBRARY}
${KDE4_PLASMA_LIBS}
${KDE4_SOLID_LIBRARY}
@@ -801,6 +803,7 @@ install(FILES data/DefaultPlaylistLayouts.xml
DESTINATION ${DATA_INSTALL_DIR}/amarok/data)
install( FILES data/amarok_homerc DESTINATION ${CONFIG_INSTALL_DIR} )
+install( FILES data/amarok.notifyrc DESTINATION ${DATA_INSTALL_DIR}/amarok )
kde4_install_icons( ${ICON_INSTALL_DIR} )
diff --git a/src/KNotificationBackend.cpp b/src/KNotificationBackend.cpp
new file mode 100644
index 0000000..5bb380a
--- /dev/null
+++ b/src/KNotificationBackend.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************************
+ * Copyright (c) 2009 Kevin Funk <krf@electrostorm.net> \
* + * \
* + * This program 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 2 of the License, or (at your option) any later \
* + * version. \
* + * \
* + * This program 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 \
* + * this program. If not, see <http://www.gnu.org/licenses/>. \
* + ****************************************************************************************/
+
+#include "KNotificationBackend.h"
+
+#include "Amarok.h"
+#include "Debug.h"
+#include "EngineController.h"
+#include "meta/Meta.h"
+
+#include <KStandardDirs>
+
+#include <QTextDocument> // for Qt::escape()
+#include <QTimer>
+
+Amarok::KNotificationBackend::KNotificationBackend()
+ : EngineObserver( The::engineController() )
+{
+ DEBUG_BLOCK
+
+ m_timer = new QTimer( this );
+ m_timer->setSingleShot( true );
+ connect( m_timer, SIGNAL( timeout() ), this, SLOT( slotShowCurrentTrack() ) );
+}
+
+Amarok::KNotificationBackend::~KNotificationBackend()
+{
+ DEBUG_BLOCK
+}
+
+// TODO: Implement
+void
+Amarok::KNotificationBackend::engineStateChanged( Phonon::State state, Phonon::State \
/*oldState*/ ) +{
+ switch( state )
+ {
+ case Phonon::PlayingState:
+ case Phonon::StoppedState:
+ case Phonon::PausedState:
+ case Phonon::LoadingState:
+ case Phonon::ErrorState:
+ case Phonon::BufferingState:
+ break;
+ }
+}
+
+void
+Amarok::KNotificationBackend::engineNewTrackPlaying()
+{
+ DEBUG_BLOCK
+
+ m_timer->start( 3000 ); // Wait some time to display the correct cover
+}
+
+void
+Amarok::KNotificationBackend::slotShowCurrentTrack()
+{
+ DEBUG_BLOCK
+
+ Meta::TrackPtr track = The::engineController()->currentTrack();
+
+ if( track )
+ {
+ QString text;
+
+ text = "<b>" + Qt::escape( track->prettyName() ) + "</b>";
+ if( track->artist() )
+ {
+ const QString artist = Qt::escape( track->artist()->prettyName() );
+ if( !artist.isEmpty() )
+ text += i18n( " by <b>%1</b>", artist );
+ }
+ if( track->album() )
+ {
+ const QString album = Qt::escape( track->album()->prettyName() );
+ if( !album.isEmpty() )
+ text += i18n( " on <b>%1</b>", album );
+ }
+
+ KNotification::event( "trackChange", text, track->album()->image( 80 ) \
)->setTitle( i18n( "Now playing" ) ); + }
+}
+
+#include "KNotificationBackend.moc"
diff --git a/src/KNotificationBackend.h b/src/KNotificationBackend.h
new file mode 100644
index 0000000..725f2df
--- /dev/null
+++ b/src/KNotificationBackend.h
@@ -0,0 +1,55 @@
+/****************************************************************************************
+ * Copyright (c) 2009 Kevin Funk <krf@electrostorm.net> \
* + * \
* + * This program 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 2 of the License, or (at your option) any later \
* + * version. \
* + * \
* + * This program 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 \
* + * this program. If not, see <http://www.gnu.org/licenses/>. \
* + ****************************************************************************************/
+
+#ifndef AMAROK_KNOTIFICATIONBACKEND_H
+#define AMAROK_KNOTIFICATIONBACKEND_H
+
+#include "EngineObserver.h"
+
+#include <KNotification>
+
+namespace Amarok {
+
+/**
+ * A class for accessing knotify in KDE
+ *
+ **/
+class KNotificationBackend : public QObject, public EngineObserver
+{
+ Q_OBJECT
+
+public:
+ KNotificationBackend();
+ ~KNotificationBackend();
+
+public Q_SLOTS:
+
+protected:
+ // Reimplemented from engineobserver
+ virtual void engineStateChanged( Phonon::State state, Phonon::State oldState = \
Phonon::StoppedState ); + virtual void engineNewTrackPlaying();
+
+private Q_SLOTS:
+ void slotShowCurrentTrack();
+
+private:
+ QTimer *m_timer;
+
+};
+
+}
+
+#endif
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index 65e356a..e05d360 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -638,8 +638,10 @@ MainWindow::createActions()
const Playlist::Controller* const pc = The::playlistController();
KStandardAction::keyBindings( kapp, SLOT( slotConfigShortcuts() ), ac );
+ KStandardAction::configureNotifications( kapp, SLOT( slotConfigNotifications() \
), ac ); KStandardAction::preferences( kapp, SLOT( slotConfigAmarok() ), ac );
ac->action(KStandardAction::name(KStandardAction::KeyBindings))->setIcon( KIcon( \
"configure-shortcuts-amarok" ) ); + \
ac->action(KStandardAction::name(KStandardAction::ConfigureNotifications) \
);
ac->action(KStandardAction::name(KStandardAction::Preferences))->setIcon( KIcon( \
"configure-amarok" ) ); \
ac->action(KStandardAction::name(KStandardAction::Preferences))->setMenuRole(QAction::PreferencesRole); \
// Define OS X Prefs menu here, removes need for ifdef later
@@ -910,6 +912,7 @@ MainWindow::createMenus()
m_settingsMenu->addAction( Amarok::actionCollection()->action("equalizer_mode") \
); m_settingsMenu->addSeparator();
+ m_settingsMenu->addAction( \
Amarok::actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureNotifications)) \
);
m_settingsMenu->addAction( \
Amarok::actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings)) \
);
m_settingsMenu->addAction( \
Amarok::actionCollection()->action(KStandardAction::name(KStandardAction::Preferences)) \
); //END Settings menu
diff --git a/src/MainWindow.h b/src/MainWindow.h
index 9969c67..aa93dbe 100644
--- a/src/MainWindow.h
+++ b/src/MainWindow.h
@@ -74,7 +74,7 @@ class AMAROK_EXPORT MainWindow : public KMainWindow, public \
EngineObserver, publ
public:
MainWindow();
- ~MainWindow();
+ ~MainWindow();
//allows us to switch browsers from within other browsers etc
void showBrowser( const QString& name );
diff --git a/src/data/amarok.notifyrc b/src/data/amarok.notifyrc
new file mode 100644
index 0000000..75d37ae
--- /dev/null
+++ b/src/data/amarok.notifyrc
@@ -0,0 +1,7 @@
+[Global]
+Comment=Amarok
+
+[Event/trackChange]
+Name=Track Change
+Comment=Amarok changed to a new track
+Action=Popup
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic