Show now playing in the dock menu somewhat like iTunes.

This commit is contained in:
John Maguire 2010-09-08 11:53:35 +00:00
parent 977dd916b0
commit effa826abb
17 changed files with 89 additions and 0 deletions

View File

@ -14,6 +14,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: ar\n"
"X-Launchpad-Export-Date: 2010-05-22 04:09+0000\n"
"X-Generator: Launchpad (build Unknown)\n"

View File

@ -14,6 +14,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: bg\n"
"X-Launchpad-Export-Date: 2010-07-25 04:25+0000\n"
"X-Generator: Launchpad (build Unknown)\n"
"Language: bg\n"

View File

@ -15,6 +15,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: da\n"
"X-Launchpad-Export-Date: 2010-07-25 04:25+0000\n"
"X-Generator: Launchpad (build Unknown)\n"
"Language: da\n"

View File

@ -14,6 +14,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"X-Launchpad-Export-Date: 2010-06-18 03:42+0000\n"
"X-Generator: Launchpad (build Unknown)\n"

View File

@ -14,6 +14,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"X-Launchpad-Export-Date: 2010-06-18 03:42+0000\n"
"X-Generator: Launchpad (build Unknown)\n"

View File

@ -14,6 +14,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: gl\n"
"X-Launchpad-Export-Date: 2010-04-28 03:53+0000\n"
"X-Generator: Launchpad (build Unknown)\n"

View File

@ -14,6 +14,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: kk\n"
"X-Launchpad-Export-Date: 2010-04-28 03:53+0000\n"
"X-Generator: Launchpad (build Unknown)\n"

View File

@ -14,6 +14,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: lt\n"
"X-Launchpad-Export-Date: 2010-07-25 04:26+0000\n"
"X-Generator: Launchpad (build Unknown)\n"
"Language: lt\n"

View File

@ -14,6 +14,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"X-Launchpad-Export-Date: 2010-05-22 04:09+0000\n"
"X-Generator: Launchpad (build Unknown)\n"

View File

@ -14,6 +14,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: ro\n"
"X-Launchpad-Export-Date: 2010-05-04 03:52+0000\n"
"X-Generator: Launchpad (build Unknown)\n"

View File

@ -14,6 +14,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: sr\n"
"X-Launchpad-Export-Date: 2010-07-25 04:26+0000\n"
"X-Generator: Launchpad (build Unknown)\n"
"Language: sr\n"

View File

@ -1198,6 +1198,9 @@ msgstr ""
msgid "Notifications"
msgstr ""
msgid "Now Playing"
msgstr ""
msgid "OSD Preview"
msgstr ""

View File

@ -14,6 +14,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"X-Launchpad-Export-Date: 2010-06-08 03:51+0000\n"
"X-Generator: Launchpad (build Unknown)\n"

View File

@ -35,6 +35,9 @@ public:
QAction* stop_after, QAction* next, QAction* love,
QAction* ban, QAction* quit);
void SetNowPlaying(const Song& song);
void ClearNowPlaying();
private:
void SetupMenuItem(QAction* action);

View File

@ -16,6 +16,8 @@
#include "macsystemtrayicon.h"
#include "core/song.h"
#include <QAction>
#include <QApplication>
#include <QIcon>
@ -57,9 +59,32 @@ class MacSystemTrayIconPrivate : boost::noncopyable {
MacSystemTrayIconPrivate() {
dock_menu_ = [[NSMenu alloc] initWithTitle:@"DockMenu"];
QString title = QT_TR_NOOP("Now Playing");
NSString* t = [[NSString alloc] initWithUTF8String:title.toUtf8().constData()];
now_playing_ = [[NSMenuItem alloc]
initWithTitle:t
action:NULL
keyEquivalent:@""];
now_playing_artist_ = [[NSMenuItem alloc]
initWithTitle:@"Nothing to see here"
action:NULL
keyEquivalent:@""];
now_playing_title_ = [[NSMenuItem alloc]
initWithTitle:@"Nothing to see here"
action:NULL
keyEquivalent:@""];
[dock_menu_ insertItem:now_playing_title_ atIndex:0];
[dock_menu_ insertItem:now_playing_artist_ atIndex:0];
[dock_menu_ insertItem:now_playing_ atIndex:0];
// Don't look now.
// This must be called after our custom NSApplicationDelegate has been set.
[[NSApp delegate] setDockMenu:dock_menu_];
ClearNowPlaying();
}
void AddMenuItem(QAction* action) {
@ -89,10 +114,43 @@ class MacSystemTrayIconPrivate : boost::noncopyable {
[dock_menu_ addItem:separator];
}
void ShowNowPlaying(const QString& artist, const QString& title) {
ClearNowPlaying(); // Makes sure the order is consistent.
[now_playing_artist_ setTitle:
[[NSString alloc] initWithUTF8String: artist.toUtf8().constData()]];
[now_playing_title_ setTitle:
[[NSString alloc] initWithUTF8String: title.toUtf8().constData()]];
title.isEmpty() ? HideItem(now_playing_title_) : ShowItem(now_playing_title_);
artist.isEmpty() ? HideItem(now_playing_artist_) : ShowItem(now_playing_artist_);
artist.isEmpty() && title.isEmpty() ? HideItem(now_playing_) : ShowItem(now_playing_);
}
void ClearNowPlaying() {
// Hiding doesn't seem to work in the dock menu.
HideItem(now_playing_);
HideItem(now_playing_artist_);
HideItem(now_playing_title_);
}
private:
void HideItem(NSMenuItem* item) {
if ([dock_menu_ indexOfItem:item] != -1) {
[dock_menu_ removeItem:item];
}
}
void ShowItem(NSMenuItem* item, int index = 0) {
if ([dock_menu_ indexOfItem:item] == -1) {
[dock_menu_ insertItem:item atIndex:index];
}
}
QMap<QAction*, NSMenuItem*> actions_;
NSMenu* dock_menu_;
NSMenuItem* now_playing_;
NSMenuItem* now_playing_artist_;
NSMenuItem* now_playing_title_;
};
MacSystemTrayIcon::MacSystemTrayIcon(QObject* parent)
@ -135,3 +193,11 @@ void MacSystemTrayIcon::ActionChanged() {
QAction* action = qobject_cast<QAction*>(sender());
p_->ActionChanged(action);
}
void MacSystemTrayIcon::ClearNowPlaying() {
p_->ClearNowPlaying();
}
void MacSystemTrayIcon::SetNowPlaying(const Song& song) {
p_->ShowNowPlaying(song.artist(), song.PrettyTitle());
}

View File

@ -21,6 +21,7 @@
#include <QPixmap>
class QAction;
class Song;
class SystemTrayIcon : public QObject {
Q_OBJECT
@ -39,6 +40,8 @@ class SystemTrayIcon : public QObject {
// Called by the OSD
virtual void ShowPopup(const QString& summary, const QString& message,
int timeout) {}
virtual void SetNowPlaying(const Song& song) {}
virtual void ClearNowPlaying() {}
static SystemTrayIcon* CreateSystemTrayIcon(QObject* parent = 0);

View File

@ -79,6 +79,7 @@ void OSD::ReloadSettings() {
}
void OSD::SongChanged(const Song &song) {
tray_icon_->SetNowPlaying(song);
QString summary(song.PrettyTitle());
if (!song.artist().isEmpty())
summary = QString("%1 - %2").arg(song.artist(), summary);
@ -120,6 +121,7 @@ void OSD::Paused() {
}
void OSD::Stopped() {
tray_icon_->ClearNowPlaying();
if (ignore_next_stopped_) {
ignore_next_stopped_ = false;
return;