~neon/juk/master

« back to all changes in this revision

Viewing changes to systemtray.cpp

  • Committer: Michael Pyne
  • Date: 2009-11-24 23:14:58 UTC
  • Revision ID: git-v1:b932c0483e4a59a489134e1b866bed25cef9cf56
Use shared-mime-info-compliant MP4 mimetype, and add mimetype for MP4 audiobooks (which
is in a Kubuntu patch on JuK as well).

svn path=/trunk/KDE/kdemultimedia/juk/; revision=1053883

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <kwindowsystem.h>
32
32
 
33
33
#include <QTimer>
34
 
#include <QWheelEvent>
35
34
#include <QColor>
36
35
#include <QPushButton>
37
36
#include <QPalette>
62
61
    connect(m_timer, SIGNAL(timeout()), SLOT(timerExpired()));
63
62
    setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
64
63
 
65
 
    // Workaround transparent background in Oxygen when (ab-)using Qt::ToolTip
66
 
    setAutoFillBackground(true);
67
 
 
68
 
    setFrameStyle(StyledPanel | Plain);
69
 
    setLineWidth(2);
 
64
    // I'd like StyledPanel but it doesn't work in the default KDE style...
 
65
    setFrameStyle(Box | Plain);
 
66
    setLineWidth(3);
70
67
}
71
68
 
72
69
void PassiveInfo::startTimer(int delay)
120
117
{
121
118
}
122
119
 
123
 
void PassiveInfo::wheelEvent(QWheelEvent *e)
124
 
{
125
 
    if(e->delta() >= 0) {
126
 
        emit nextSong();
127
 
    }
128
 
    else {
129
 
        emit previousSong();
130
 
    }
131
 
 
132
 
    e->accept();
133
 
}
134
 
 
135
120
void PassiveInfo::positionSelf()
136
121
{
137
122
    // Start with a QRect of our size, move it to the right spot.
151
136
// public methods
152
137
////////////////////////////////////////////////////////////////////////////////
153
138
 
154
 
SystemTray::SystemTray(PlayerManager *player, QWidget *parent) :
155
 
    KStatusNotifierItem(parent),
156
 
    m_popup(0),
157
 
    m_player(player),
158
 
    m_fadeTimer(0),
159
 
    m_fade(true),
160
 
    m_hasCompositionManager(false)
 
139
SystemTray::SystemTray(QWidget *parent) : KStatusNotifierItem(parent),
 
140
                                          m_popup(0),
 
141
                                          m_fadeTimer(0),
 
142
                                          m_fade(true),
 
143
                                          m_hasCompositionManager(false)
 
144
 
161
145
{
162
146
    // This should be initialized to the number of labels that are used.
163
147
    m_labels.fill(0, 3);
178
162
 
179
163
    KMenu *cm = contextMenu();
180
164
 
181
 
    connect(m_player, SIGNAL(signalPlay()), this, SLOT(slotPlay()));
182
 
    connect(m_player, SIGNAL(signalPause()), this, SLOT(slotPause()));
183
 
    connect(m_player, SIGNAL(signalStop()), this, SLOT(slotStop()));
 
165
    connect(PlayerManager::instance(), SIGNAL(signalPlay()), this, SLOT(slotPlay()));
 
166
    connect(PlayerManager::instance(), SIGNAL(signalPause()), this, SLOT(slotPause()));
 
167
    connect(PlayerManager::instance(), SIGNAL(signalStop()), this, SLOT(slotStop()));
184
168
 
185
169
    cm->addAction( action("play") );
186
170
    cm->addAction( action("pause") );
202
186
    cm->addAction( action("togglePopups") );
203
187
 
204
188
    m_fadeTimer = new QTimer(this);
205
 
    m_fadeTimer->setObjectName( QLatin1String("systrayFadeTimer" ));
 
189
    m_fadeTimer->setObjectName("systrayFadeTimer");
206
190
    connect(m_fadeTimer, SIGNAL(timeout()), SLOT(slotNextStep()));
207
191
 
208
192
    // Handle wheel events
212
196
    connect(this, SIGNAL(secondaryActivateRequested(const QPoint &)),
213
197
            action("playPause"), SLOT(trigger()));
214
198
 
215
 
    if(m_player->playing())
 
199
    if(PlayerManager::instance()->playing())
216
200
        slotPlay();
217
 
    else if(m_player->paused())
 
201
    else if(PlayerManager::instance()->paused())
218
202
        slotPause();
219
203
}
220
204
 
224
208
 
225
209
void SystemTray::slotPlay()
226
210
{
227
 
    if(!m_player->playing())
 
211
    if(!PlayerManager::instance()->playing())
228
212
        return;
229
213
 
230
 
    QPixmap cover = m_player->playingFile().coverInfo()->pixmap(CoverInfo::FullSize);
 
214
    QPixmap cover = PlayerManager::instance()->playingFile().coverInfo()->pixmap(CoverInfo::Thumbnail);
231
215
 
232
216
    setOverlayIconByName("media-playback-start");
233
 
    setToolTip(m_player->playingString(), cover);
 
217
    setToolTip(PlayerManager::instance()->playingString(), cover);
234
218
    createPopup();
235
219
}
236
220
 
249
233
 
250
234
void SystemTray::slotPopupLargeCover()
251
235
{
252
 
    if(!m_player->playing())
 
236
    if(!PlayerManager::instance()->playing())
253
237
        return;
254
238
 
255
 
    FileHandle playingFile = m_player->playingFile();
 
239
    FileHandle playingFile = PlayerManager::instance()->playingFile();
256
240
    playingFile.coverInfo()->popup();
257
241
}
258
242
 
359
343
 
360
344
void SystemTray::createPopup()
361
345
{
362
 
    FileHandle playingFile = m_player->playingFile();
 
346
    FileHandle playingFile = PlayerManager::instance()->playingFile();
363
347
    Tag *playingInfo = playingFile.tag();
364
348
 
365
349
    // If the action exists and it's checked, do our stuff
379
363
    m_popup = new PassiveInfo(this);
380
364
    connect(m_popup, SIGNAL(destroyed()), SLOT(slotPopupDestroyed()));
381
365
    connect(m_popup, SIGNAL(timeExpired()), SLOT(slotFadeOut()));
382
 
    connect(m_popup, SIGNAL(nextSong()), SLOT(slotForward()));
383
 
    connect(m_popup, SIGNAL(previousSong()), SLOT(slotBack()));
384
366
 
385
367
    KHBox *box = new KHBox(m_popup);
386
368
    box->setSpacing(15); // Add space between text and buttons
424
406
    buttonBox->setSpacing(3);
425
407
 
426
408
    QPushButton *forwardButton = new QPushButton(m_forwardPix, 0, buttonBox);
427
 
    forwardButton->setObjectName( QLatin1String("popup_forward" ));
 
409
    forwardButton->setObjectName("popup_forward");
428
410
    connect(forwardButton, SIGNAL(clicked()), SLOT(slotForward()));
429
411
 
430
412
    QPushButton *backButton = new QPushButton(m_backPix, 0, buttonBox);
431
 
    backButton->setObjectName( QLatin1String("popup_back" ));
 
413
    backButton->setObjectName("popup_back");
432
414
    connect(backButton, SIGNAL(clicked()), SLOT(slotBack()));
433
415
}
434
416
 
494
476
    if(tip.isEmpty())
495
477
        KStatusNotifierItem::setToolTip("juk", i18n("JuK"), QString());
496
478
    else {
497
 
        QPixmap myCover;
498
 
        if(cover.isNull()) {
 
479
        QPixmap myCover = cover;
 
480
        if(cover.isNull())
499
481
            myCover = DesktopIcon("juk");
500
 
        } else {
501
 
            //Scale to proper icon size, otherwise KStatusNotifierItem will show an unknown icon
502
 
            int iconSize = KIconLoader::global()->currentSize(KIconLoader::Desktop);
503
 
            myCover = cover.scaled(iconSize, iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
504
 
        }
505
482
 
506
 
        KStatusNotifierItem::setToolTip(QIcon(myCover), i18n("JuK"), tip);
 
483
        QString html = QString("%1").arg(tip);
 
484
        html.replace(" ", "&nbsp;");
 
485
        KStatusNotifierItem::setToolTip(QIcon(myCover), i18n("JuK"), html);
507
486
    }
508
487
}
509
488