Basic libnotify OSD implementation

This commit is contained in:
David Sansome 2010-01-08 14:52:05 +00:00
parent 56b0d89261
commit d701e8e5ac
9 changed files with 119 additions and 3 deletions

1
TODO
View File

@ -6,6 +6,7 @@
- Edit tags in the playlist
- Global shortcut keys
- Make QSortFilterProxyModel on the library obey hasChildren()
- Database versioning
Long-term:
- iPod

View File

@ -8,6 +8,7 @@
#include "radiomodel.h"
#include "enginebase.h"
#include "lastfmservice.h"
#include "osd.h"
#include "qxtglobalshortcut.h"
@ -30,6 +31,7 @@ const char* MainWindow::kSettingsGroup = "MainWindow";
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
tray_icon_(new SystemTrayIcon(this)),
osd_(new OSD(tray_icon_, this)),
radio_model_(new RadioModel(this)),
playlist_(new Playlist(this)),
player_(new Player(playlist_, radio_model_->GetLastFMService(), this)),
@ -109,6 +111,10 @@ MainWindow::MainWindow(QWidget *parent)
connect(player_, SIGNAL(Playing()), ui_.playlist, SLOT(StartGlowing()));
connect(player_, SIGNAL(Stopped()), ui_.playlist, SLOT(StopGlowing()));
connect(player_, SIGNAL(Paused()), osd_, SLOT(Paused()));
connect(player_, SIGNAL(Stopped()), osd_, SLOT(Stopped()));
connect(playlist_, SIGNAL(CurrentSongChanged(Song)), osd_, SLOT(SongChanged(Song)));
connect(ui_.playlist, SIGNAL(doubleClicked(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
// Library connections

View File

@ -13,6 +13,7 @@ class LibraryConfig;
class RadioModel;
class Song;
class RadioItem;
class OSD;
class QSortFilterProxyModel;
class SystemTrayIcon;
@ -64,6 +65,7 @@ class MainWindow : public QMainWindow {
Ui::MainWindow ui_;
SystemTrayIcon* tray_icon_;
OSD* osd_;
RadioModel* radio_model_;
Playlist* playlist_;

30
src/osd.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "osd.h"
OSD::OSD(QSystemTrayIcon* tray_icon, QObject* parent)
: QObject(parent),
tray_icon_(tray_icon)
{
Init();
}
void OSD::SongChanged(const Song &song) {
QString summary(song.PrettyTitleWithArtist());
QStringList message_parts;
if (!song.album().isEmpty())
message_parts << song.album();
if (song.disc() > 0)
message_parts << QString("Disc %1").arg(song.disc());
if (song.track() > 0)
message_parts << QString("Track %1").arg(song.track());
ShowMessage(summary, message_parts.join(" "), "notification-audio-play");
}
void OSD::Paused() {
ShowMessage("Tangerine", "Paused");
}
void OSD::Stopped() {
ShowMessage("Tangerine", "Playlist finished");
}

30
src/osd.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef OSD_H
#define OSD_H
#include <QObject>
#include <QSystemTrayIcon>
#include "engine_fwd.h"
#include "song.h"
class OSD : public QObject {
Q_OBJECT
public:
OSD(QSystemTrayIcon* tray_icon, QObject* parent = 0);
void Init();
void ShowMessage(const QString& summary,
const QString& message = QString::null,
const QString& icon = QString::null);
public slots:
void SongChanged(const Song& song);
void Paused();
void Stopped();
private:
QSystemTrayIcon* tray_icon_;
};
#endif // OSD_H

35
src/osd_x11.cpp Normal file
View File

@ -0,0 +1,35 @@
// Libnotify headers need to go before Qt ones because they use "signals" as
// a variable name
#include <libnotify/notify.h>
#include <glib.h>
#include "osd.h"
#include <QtDebug>
void OSD::Init() {
notify_init("Tangerine");
}
void OSD::ShowMessage(const QString& summary, const QString& message,
const QString& icon) {
if (summary.isNull())
return;
NotifyNotification* notification = notify_notification_new(
summary.toUtf8().constData(),
message.isNull() ? NULL : message.toUtf8().constData(),
icon.isNull() ? NULL : icon.toUtf8().constData(), NULL);
notify_notification_set_urgency(notification, NOTIFY_URGENCY_LOW);
notify_notification_set_timeout(notification, 5000);
GError* error = NULL;
notify_notification_show(notification, &error);
if (error) {
qDebug() << "Error from notify_notification_show:" << error->message;
g_error_free(error);
}
g_object_unref(G_OBJECT(notification));
}

View File

@ -122,8 +122,11 @@ void Playlist::set_current_index(int i) {
if (old_current.isValid())
emit dataChanged(old_current, old_current.sibling(old_current.row(), ColumnCount));
if (current_item_.isValid())
if (current_item_.isValid()) {
emit dataChanged(current_item_, current_item_.sibling(current_item_.row(), ColumnCount));
emit CurrentSongChanged(current_item_metadata());
}
UpdateScrobblePoint();
}
@ -443,6 +446,7 @@ void Playlist::SetStreamMetadata(const QUrl& url, const Song& song) {
UpdateScrobblePoint();
emit dataChanged(index(current_item_.row(), 0), index(current_item_.row(), ColumnCount));
emit CurrentSongChanged(song);
}
void Playlist::ClearStreamMetadata() {

View File

@ -99,6 +99,9 @@ class Playlist : public QAbstractListModel {
void ClearStreamMetadata();
void SetStreamMetadata(const QUrl& url, const Song& song);
signals:
void CurrentSongChanged(const Song& metadata);
private:
void SetCurrentIsPaused(bool paused);
void UpdateScrobblePoint();

View File

@ -43,7 +43,9 @@ SOURCES += main.cpp \
radioplaylistitem.cpp \
radioloadingindicator.cpp \
radioview.cpp \
lastfmstationdialog.cpp
lastfmstationdialog.cpp \
osd.cpp \
osd_x11.cpp
HEADERS += mainwindow.h \
player.h \
library.h \
@ -87,7 +89,8 @@ HEADERS += mainwindow.h \
radioloadingindicator.h \
radioview.h \
lastfmstationdialog.h \
../3rdparty/qxt/keymapper_x11.h
../3rdparty/qxt/keymapper_x11.h \
osd.h
FORMS += mainwindow.ui \
libraryconfig.ui \
fileview.ui \
@ -103,6 +106,8 @@ LIBS += -llastfm
LIBS += $$system(taglib-config --libs)
QMAKE_CXXFLAGS += $$system(xine-config --cflags)
LIBS += $$system(xine-config --libs)
QMAKE_CXXFLAGS += $$system(pkg-config --cflags libnotify)
LIBS += $$system(pkg-config --libs libnotify)
}
win32 {
INCLUDEPATH += C:/msys/1.0/local/include \