1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-18 20:34:39 +01:00

OS X dock icon updates to show current status.

Somewhat less (but still quite) hacky system tray code.
This commit is contained in:
John Maguire 2010-04-19 20:59:05 +00:00
parent 8ffe7f64b2
commit ff06207732
5 changed files with 21 additions and 17 deletions

View File

@ -18,6 +18,8 @@
<file>volumeslider-gradient.png</file>
<file>logo.png</file>
<file>icon.png</file>
<file>icon_large.png</file>
<file>icon_large_grey.png</file>
<file>currenttrack_bar_left.png</file>
<file>currenttrack_bar_mid.png</file>
<file>currenttrack_bar_right.png</file>

BIN
data/icon_large_grey.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 KiB

View File

@ -78,7 +78,6 @@ GSTREAMER_PLUGINS=[
'libgstmpegaudioparse.so',
'libgstmusepack.so',
'libgstogg.so',
'libgstpnm.so',
'libgstvorbis.so',
# HTTP src support

View File

@ -77,11 +77,7 @@ const char* MainWindow::kMediaFilterSpec =
MainWindow::MainWindow(QNetworkAccessManager* network, Engine::Type engine, QWidget *parent)
: QMainWindow(parent),
#ifdef Q_OS_DARWIN
tray_icon_(NULL),
#else
tray_icon_(new SystemTrayIcon(this)),
#endif
osd_(new OSD(tray_icon_, this)),
track_slider_(new TrackSlider(this)),
playlist_sequence_(new PlaylistSequence(this)),
@ -105,10 +101,8 @@ MainWindow::MainWindow(QNetworkAccessManager* network, Engine::Type engine, QWid
was_maximized_(false)
{
ui_.setupUi(this);
#ifndef Q_OS_DARWIN
tray_icon_->setIcon(windowIcon());
tray_icon_->setToolTip(QCoreApplication::applicationName());
#endif
ui_.volume->setValue(player_->GetVolume());
@ -501,10 +495,8 @@ void MainWindow::MediaStopped() {
track_position_timer_->stop();
track_slider_->SetStopped();
#ifndef Q_OS_DARWIN
tray_icon_->SetProgress(0);
tray_icon_->SetStopped();
#endif
}
void MainWindow::MediaPaused() {
@ -517,9 +509,7 @@ void MainWindow::MediaPaused() {
track_position_timer_->stop();
#ifndef Q_OS_DARWIN
tray_icon_->SetPaused();
#endif
}
void MainWindow::MediaPlaying() {
@ -542,9 +532,7 @@ void MainWindow::MediaPlaying() {
track_position_timer_->start();
UpdateTrackPosition();
#ifndef Q_OS_DARWIN
tray_icon_->SetPlaying();
#endif
}
void MainWindow::ScrobblingEnabledChanged(bool value) {
@ -668,9 +656,7 @@ void MainWindow::UpdateTrackPosition() {
if (length <= 0) {
// Probably a stream that we don't know the length of
track_slider_->SetStopped();
#ifndef Q_OS_DARWIN
tray_icon_->SetProgress(0);
#endif
return;
}
@ -686,12 +672,10 @@ void MainWindow::UpdateTrackPosition() {
// Update the slider
track_slider_->SetValue(position, length);
#ifndef Q_OS_DARWIN
// Update the tray icon every 10 seconds
if (position % 10 == 1) {
tray_icon_->SetProgress(double(position) / length * 100);
}
#endif
}
void MainWindow::Love() {

View File

@ -16,9 +16,11 @@
#include "systemtrayicon.h"
#include <QApplication>
#include <QEvent>
#include <QWheelEvent>
#include <QPainter>
#include <QWidget>
#include <QtDebug>
#include <cmath>
@ -29,6 +31,9 @@ SystemTrayIcon::SystemTrayIcon(QObject* parent)
paused_icon_(":/tiny-pause.png"),
percentage_(0)
{
#ifdef Q_OS_DARWIN
hide();
#endif
}
SystemTrayIcon::~SystemTrayIcon() {}
@ -48,8 +53,16 @@ void SystemTrayIcon::SetProgress(int percentage) {
void SystemTrayIcon::Update() {
if (icon_.isNull()) {
#ifdef Q_OS_DARWIN
QIcon big_icon(":icon_large.png");
icon_ = big_icon.pixmap(128, 128, QIcon::Normal);
QIcon big_grey_icon(":icon_large_grey.png");
grey_icon_ = big_grey_icon.pixmap(128, 128, QIcon::Normal);
grey_icon_.save("grey.png");
#else
icon_ = icon().pixmap(geometry().size(), QIcon::Normal);
grey_icon_ = icon().pixmap(geometry().size(), QIcon::Disabled);
#endif
if (icon_.isNull())
return;
@ -93,7 +106,13 @@ void SystemTrayIcon::Update() {
p.end();
#ifdef Q_OS_DARWIN
// Setting main window icon.
QApplication::setWindowIcon(icon);
icon.save("icon.png");
#else
setIcon(icon);
#endif
}
void SystemTrayIcon::SetPaused() {