summaryrefslogtreecommitdiffstats
path: root/kscd/docking.cpp
blob: e6689b8dd91238e3f7cb8830e7897ffc04fc4465 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 *              KSCD -- a simpole cd player for the KDE project
 *
 * $Id$
 *
 *              Copyright (C) 1997 Bernd Johannes Wuebben
 *                      wuebben@math.cornell.edu
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library 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 "docking.h"
#include "kscd.h"

#include <tqhbox.h>
#include <tqtooltip.h>

#include <tdeaboutdata.h>
#include <tdeactioncollection.h>
#include <tdeapplication.h>
#include <tdelocale.h>
#include <tdeglobal.h>
#include <kiconloader.h>
#include <tdepopupmenu.h>
#include <kpassivepopup.h>

#include <kdebug.h>

DockWidget::DockWidget( KSCD* parent, const char *name)
    : KSystemTray( parent, name )
{
    m_popup = 0;
    setPixmap( loadIcon("cdsmall") );

    TDEActionCollection* actionCollection = parent->actionCollection();
    m_backAction = actionCollection->action("Previous");
    m_forwardAction = actionCollection->action("Next");
    m_backPix = loadIcon("media-skip-backward");
    m_forwardPix = loadIcon("media-skip-forward");

    // popup menu for right mouse button
    TQPopupMenu* popup = contextMenu();

    popup->insertItem(TDEGlobal::iconLoader()->loadIconSet("media-playback-start", TDEIcon::Small), i18n("Play/Pause"), parent, TQT_SLOT(playClicked()));
    popup->insertItem(TDEGlobal::iconLoader()->loadIconSet("media-playback-stop", TDEIcon::Small), i18n("Stop"), parent, TQT_SLOT(stopClicked()));
    popup->insertItem(TDEGlobal::iconLoader()->loadIconSet("media-skip-forward", TDEIcon::Small), i18n("Next"), parent, TQT_SLOT(nextClicked()));
    popup->insertItem(TDEGlobal::iconLoader()->loadIconSet("media-skip-backward", TDEIcon::Small), i18n("Previous"), parent, TQT_SLOT(prevClicked()));
    popup->insertItem(TDEGlobal::iconLoader()->loadIconSet("player_eject", TDEIcon::Small), i18n("Eject"), parent, TQT_SLOT(ejectClicked()));

    TQToolTip::add(this, kapp->aboutData()->programName());
}

DockWidget::~DockWidget()
{
}

void DockWidget::createPopup(const TQString &songName, bool addButtons)
{
    if (!Prefs::trackAnnouncement())
        return;

    delete m_popup;
    m_popup = new KPassivePopup(this);

    TQHBox* box = new TQHBox(m_popup);
    
    if (addButtons)
    {
        TQPushButton* backButton = new TQPushButton(m_backPix, 0, box, "popup_back");
        backButton->setFlat(true);
        connect(backButton, TQT_SIGNAL(clicked()), m_backAction, TQT_SLOT(activate()));
    }

    TQLabel* l = new TQLabel(songName, box);
    l->setMargin(3);

    if (addButtons)
    {
        TQPushButton* forwardButton = new TQPushButton(m_forwardPix, 0, box, "popup_forward");
        forwardButton->setFlat(true);
        connect(forwardButton, TQT_SIGNAL(clicked()), m_forwardAction, TQT_SLOT(activate()));
    }

    m_popup->setView(box);
    m_popup->setAutoDelete(false);
    m_popup->show();
}

void DockWidget::setToolTip(const TQString& text)
{
    if (tip == text)
    {
        return;
    }

    tip = text;
    TQToolTip::remove(this);

    if (text.isEmpty())
    {
        TQToolTip::add(this, kapp->aboutData()->programName());
    }
    else
    {
        TQToolTip::add(this, text);
    }
}

void DockWidget::wheelEvent(TQWheelEvent *e)
{
    if (e->orientation() ==Qt::Horizontal)
        return;

    KSCD* kscd = dynamic_cast<KSCD*>(parent());
    if (kscd == 0)
        return;

    switch (e->state())
    {
        case ShiftButton:
        {
            if (e->delta() > 0)
            {
                kscd->incVolume();
            }
            else
            {
                kscd->decVolume();
            }
            break;
        }
        default:
        {
            if (e->delta() > 0)
            {
                kscd->nextClicked();
            }
            else
            {
                kscd->prevClicked();
            }
        }
    }
}

#include "docking.moc"