~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to noatun/noatun/modules/systray/systray.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// systray.h
2
 
//
3
 
// Copyright (C) 2000 Neil Stevens <multivac@fcmail.com>
4
 
// Copyright (C) 1999 Charles Samuels <charles@kde.org>
5
 
//
6
 
// Permission is hereby granted, free of charge, to any person obtaining a copy
7
 
// of this software and associated documentation files (the "Software"), to deal
8
 
// in the Software without restriction, including without limitation the rights
9
 
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 
// copies of the Software, and to permit persons to whom the Software is
11
 
// furnished to do so, subject to the following conditions:
12
 
// 
13
 
// The above copyright notice and this permission notice shall be included in
14
 
// all copies or substantial portions of the Software.
15
 
// 
16
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
19
 
// THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
 
// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
 
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
 
// 
23
 
// Except as contained in this notice, the name(s) of the author(s) shall not be
24
 
// used in advertising or otherwise to promote the sale, use or other dealings
25
 
// in this Software without prior written authorization from the author(s).
26
 
 
27
 
#ifdef HAVE_CONFIG_H
28
 
#include <config.h>
29
 
#endif
30
 
 
31
 
#include <effects.h>
32
 
#include <noatunapp.h>
33
 
#include "noatunpref.h"
34
 
#include "player.h"
35
 
#include "systray.h"
36
 
#include "kitsystemtray.h"
37
 
#include "noatunstdaction.h"
38
 
#include "cmodule.h"
39
 
 
40
 
#include <kaction.h>
41
 
#include <kconfig.h>
42
 
#include <kfiledialog.h>
43
 
#include <kglobal.h>
44
 
#include <kiconloader.h>
45
 
#include <klocale.h>
46
 
#include <kpixmapeffect.h>
47
 
#include <kpopupmenu.h>
48
 
#include <kstdaction.h>
49
 
#include <qbitmap.h>
50
 
#include <qtimer.h>
51
 
#include <qtooltip.h>
52
 
 
53
 
NoatunSystray *NoatunSystray::jasonkb = 0;
54
 
 
55
 
NoatunSystray::NoatunSystray()
56
 
        : KMainWindow()
57
 
        , Plugin()
58
 
{
59
 
        hide();
60
 
        
61
 
        KStdAction::quit(napp, SLOT(quit()), actionCollection());
62
 
        KStdAction::open(napp, SLOT(fileOpen()), actionCollection());
63
 
        KStdAction::preferences(napp, SLOT(preferences()), actionCollection());
64
 
        mBack = NoatunStdAction::back(actionCollection(), "back");
65
 
        mStop = NoatunStdAction::stop(actionCollection(), "stop");
66
 
        mPlay = NoatunStdAction::playpause(actionCollection(), "play");
67
 
        mForward = NoatunStdAction::forward(actionCollection(), "forward");
68
 
        mPlaylist = NoatunStdAction::playlist(actionCollection(), "show_playlist");
69
 
        mLoop = new KAction(i18n("L&oop Style"), 0,napp->player(), SLOT(loop()), actionCollection(), "loop_style");
70
 
        NoatunStdAction::effects(actionCollection(), "effects");
71
 
        NoatunStdAction::equalizer(actionCollection(), "equalizer");
72
 
 
73
 
        createGUI("systrayui.rc");
74
 
 
75
 
        mTray = new KitSystemTray("tray", this);
76
 
        mTray->show();
77
 
        trayDefault = new QPixmap(SmallIcon("noatuntray"));
78
 
        trayStatus = new QPixmap(SmallIcon("noatuntraystop"));
79
 
        mTray->changeTitle(*trayDefault, "Noatun");
80
 
        showingTrayStatus = false;
81
 
 
82
 
        QTimer *t = new QTimer(this);
83
 
        connect(t, SIGNAL(timeout(void)), this, SLOT(blinkTimer(void)) );
84
 
        t->start(1000);
85
 
 
86
 
        connect(napp->player(), SIGNAL(playing()), this, SLOT(slotPlaying()));
87
 
        connect(napp->player(), SIGNAL(stopped()), this, SLOT(slotStopped()));
88
 
        connect(napp->player(), SIGNAL(paused()), this, SLOT(slotPaused()));
89
 
        connect(napp->player(), SIGNAL(loopTypeChange(int)), this, SLOT(changeLoopType(int)));
90
 
        napp->player()->handleButtons();
91
 
 
92
 
        changeLoopType(Player::None);
93
 
 
94
 
        jasonkb = this;
95
 
}
96
 
 
97
 
NoatunSystray::~NoatunSystray()
98
 
{
99
 
        delete trayStatus;
100
 
        delete trayDefault;
101
 
        napp->player()->showInterfaces();
102
 
}
103
 
 
104
 
void NoatunSystray::init(void)
105
 
{
106
 
        YHModule *module = new YHModule(this);
107
 
        blinkTimer();
108
 
}
109
 
 
110
 
void NoatunSystray::setBlink(Blink b)
111
 
{
112
 
        blink = b;
113
 
        blinkTimer();
114
 
}
115
 
 
116
 
void NoatunSystray::setTip(bool b)
117
 
{
118
 
        tip = b;
119
 
        if(tip)
120
 
                QToolTip::add(mTray, tipText);
121
 
        else
122
 
                QToolTip::remove(mTray);
123
 
}
124
 
 
125
 
void NoatunSystray::closeEvent(QCloseEvent*)
126
 
{
127
 
        unload();
128
 
}
129
 
 
130
 
void NoatunSystray::slotPlaying()
131
 
{
132
 
        mStop->setEnabled(true);
133
 
        changeTray(SmallIcon("noatuntrayplay"));
134
 
        setTipText(napp->player()->current()->title());
135
 
}
136
 
 
137
 
void NoatunSystray::slotStopped()
138
 
{
139
 
        if(!napp->player()->current()) return;
140
 
        changeTray(SmallIcon("noatuntraystop"));
141
 
        setTipText(i18n("Stopped"));
142
 
}
143
 
 
144
 
void NoatunSystray::slotPaused()
145
 
{
146
 
        changeTray(SmallIcon("noatuntraypause"));
147
 
        setTipText(i18n("%1 - Paused").arg(napp->player()->current()->title()));
148
 
}
149
 
 
150
 
void NoatunSystray::changeLoopType(int t)
151
 
{
152
 
        switch (t)
153
 
        {
154
 
        case Player::None:
155
 
                mLoop->setIconSet(QIconSet(SmallIcon("nloopnone")));
156
 
                mLoop->setText(i18n("No looping"));
157
 
                break;
158
 
        case Player::Song:
159
 
                mLoop->setIconSet(QIconSet(SmallIcon("nloopsong")));
160
 
                mLoop->setText(i18n("Song looping"));
161
 
                break;
162
 
        case Player::Playlist:
163
 
                mLoop->setIconSet(QIconSet(SmallIcon("nloopplaylist")));
164
 
                mLoop->setText(i18n("Playlist looping"));
165
 
        }
166
 
}
167
 
 
168
 
void NoatunSystray::changeTray(const QPixmap &pm)
169
 
{
170
 
        delete trayStatus;
171
 
        trayStatus = new QPixmap(pm);
172
 
        if(showingTrayStatus) blinkTimer();
173
 
}
174
 
 
175
 
void NoatunSystray::blinkTimer(void)
176
 
{
177
 
        switch((int)blink)
178
 
        {
179
 
        case 0:
180
 
                showingTrayStatus ^= true;
181
 
                break;
182
 
        case 1:
183
 
                showingTrayStatus = true;
184
 
                break;
185
 
        case 2:
186
 
                showingTrayStatus = false;
187
 
                break;
188
 
        }
189
 
 
190
 
        if(showingTrayStatus)
191
 
                mTray->setPixmap(*trayStatus);
192
 
        else
193
 
                mTray->setPixmap(*trayDefault);
194
 
}
195
 
 
196
 
void NoatunSystray::setTipText(QString text)
197
 
{
198
 
        tipText = text;
199
 
        if(tip) QToolTip::add(mTray, tipText);
200
 
}
201
 
 
202
 
#include "systray.moc"