/
trayicon.cpp
executable file
·75 lines (67 loc) · 3.02 KB
/
trayicon.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/***************************************************************************
* Copyright (C) 2008 by Michał Pilch <mpilhoo@gmail.com> *
* *
* 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, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include "trayicon.h"
// #include <QDebug>
UrsusTrayIcon::UrsusTrayIcon(const QString &icon, KXmlGuiWindow *parent, UrsusPlayer *player_) : KSystemTrayIcon(icon, parent){
// qDebug() << this << "constructor()";
player=player_;
QMenu *cm=contextMenu();
cm->addAction(parent->actionCollection()->action("mute"));
cm->addSeparator();
cm->addAction(parent->actionCollection()->action("previous"));
cm->addAction(parent->actionCollection()->action("play"));
cm->addAction(parent->actionCollection()->action("pause"));
cm->addAction(parent->actionCollection()->action("stop"));
cm->addAction(parent->actionCollection()->action("next"));
setToolTip("Ursus Music Player");
connect(
player->Object(), SIGNAL(stateChanged(Phonon::State, Phonon::State)),
this, SLOT(setStateIcon(Phonon::State, Phonon::State))
);
}
UrsusTrayIcon::~UrsusTrayIcon() {
// qDebug() << this << "destructor()";
disconnect(
player->Object(), SIGNAL(stateChanged(Phonon::State, Phonon::State)),
this, SLOT(setStateIcon(Phonon::State, Phonon::State))
);
}
void UrsusTrayIcon::setStateIcon(Phonon::State newState, Phonon::State /*oldState*/){
// qDebug() << this << "setStateIcon()";
switch(actualState=newState){
case Phonon::PlayingState:
setIcon(KIcon("ursusplaying"));
setToolTip(m_trackString);
break;
case Phonon::PausedState:
setIcon(KIcon("ursuspaused"));
setToolTip(m_trackString);
break;
default:
setIcon(KIcon("ursus"));
setToolTip("Ursus Music Player");
break;
}
}
void UrsusTrayIcon::setTrackString(QString trackString){
// qDebug() << this << "setTrackString()";
m_trackString=trackString;
if(actualState==Phonon::PlayingState)
setToolTip(m_trackString);
}