~ubuntu-branches/ubuntu/hoary/kvirc/hoary

« back to all changes in this revision

Viewing changes to src/plugins/xmms/kvi_xmms_widget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Robin Verduijn
  • Date: 2004-12-14 15:32:19 UTC
  • mfrom: (0.2.1 upstream) (1.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20041214153219-fdink3gyp2s20b6g
Tags: 2:2.1.3.1-2
* Change Recommends on xmms to a Suggests.
* Rebuild against KDE 3.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// =============================================================================
 
2
//
 
3
//   Copyright (C) 1999-2000 Szymon Stefanek
 
4
//
 
5
//   This program is FREE software. You can redistribute it and/or
 
6
//   modify it under the terms of the GNU General Public License
 
7
//   as published by the Free Software Foundation; either version 2
 
8
//   of the License, or (at your opinion) any later version.
 
9
//
 
10
//   This program is distributed in the HOPE that it will be USEFUL,
 
11
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
13
//   See the GNU General Public License for more details.
 
14
//
 
15
//   You should have received a copy of the GNU General Public License
 
16
//   along with this program. If not, write to the Free Software Foundation,
 
17
//   Inc, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
//
 
19
// =============================================================================
 
20
 
 
21
#define _KVI_DEBUG_CHECK_RANGE_
 
22
#define _KVI_DEBUG_CLASS_NAME_ "KviXmmsWidget"
 
23
 
 
24
#include <qpainter.h>
 
25
 
 
26
#define __KVIRC_PLUGIN__
 
27
 
 
28
#include "kvi_process.h"
 
29
#include "kvi_xmms.h"
 
30
#include "kvi_xmms_widget.h"
 
31
#include "kvirc_plugin.h"
 
32
 
 
33
KviXmmsWidget::KviXmmsWidget(void *handle, KviStatusBar *parent, KviFrame *frame)
 
34
        : KviDockableWidget(handle, parent)
 
35
{
 
36
        m_pFrm = frame;
 
37
        setMaximumWidth(146);
 
38
        setMinimumWidth(146);
 
39
        setMinimumHeight(16);
 
40
        setMaximumHeight(16);
 
41
        m_mousePressX = -1;
 
42
        setBackgroundMode(NoBackground);
 
43
        m_timer = startTimer(KVI_XMMS_UPDATE_TIME);
 
44
}
 
45
 
 
46
KviXmmsWidget::~KviXmmsWidget()
 
47
{
 
48
        // Nothing here
 
49
}
 
50
 
 
51
void KviXmmsWidget::processExited(KviProcess *proc)
 
52
{
 
53
        if( proc ) delete proc;
 
54
}
 
55
 
 
56
void KviXmmsWidget::mousePressEvent(QMouseEvent *e)
 
57
{
 
58
        m_mousePressX = e->pos().x();
 
59
        if( !libxmms_remote_is_running(0) ) {
 
60
                KviProcess *proc = new KviProcess();
 
61
                connect(proc, SIGNAL(processExited(KviProcess *)), this, SLOT(processExited(KviProcess *)));
 
62
                if( !proc->run("xmms") )
 
63
                        delete proc;
 
64
        }
 
65
        if( m_mousePressX > 50 ) {
 
66
                if( m_mousePressX < 66 ) {
 
67
                        libxmms_remote_playlist_prev(0);
 
68
                        sayWhatIsPlayed();
 
69
                } else if( m_mousePressX < 82 ) {
 
70
                        libxmms_remote_play(0);
 
71
                        sayWhatIsPlayed();
 
72
                } else if( m_mousePressX < 98 ) {
 
73
                        libxmms_remote_pause(0);
 
74
                } else if( m_mousePressX < 114 ) {
 
75
                        libxmms_remote_stop(0);
 
76
                } else if( m_mousePressX < 130 ) {
 
77
                        libxmms_remote_playlist_next(0);
 
78
                        sayWhatIsPlayed();
 
79
                } else {
 
80
                        libxmms_remote_eject(0);
 
81
                }
 
82
        } else {
 
83
                if( libxmms_remote_is_playing(0) )
 
84
                        sayWhatIsPlayed();
 
85
                else
 
86
                        kvirc_plugin_statusbar_message(m_pFrm, "[XMMS]: stopped", 5000);
 
87
        }
 
88
        repaint();
 
89
}
 
90
 
 
91
void KviXmmsWidget::sayWhatIsPlayed()
 
92
{
 
93
        const char *song = libxmms_remote_get_playlist_title(0, libxmms_remote_get_playlist_pos(0));
 
94
        KviStr tmp(KviStr::Format, "[XMMS]: playing \"%s\"", song);
 
95
        kvirc_plugin_statusbar_message(m_pFrm, tmp.ptr(), 5000);
 
96
}
 
97
 
 
98
void KviXmmsWidget::mouseReleaseEvent(QMouseEvent *e)
 
99
{
 
100
        m_mousePressX = -1;
 
101
        repaint();
 
102
}
 
103
 
 
104
void KviXmmsWidget::paintEvent(QPaintEvent *)
 
105
{
 
106
        m_bIsPlaying   = libxmms_remote_is_playing(0);
 
107
        m_bIsRunning   = libxmms_remote_is_running(0);
 
108
        m_iPlaylistPos = libxmms_remote_get_playlist_pos(0);
 
109
        m_iPlaylistLen = libxmms_remote_get_playlist_length(0);
 
110
 
 
111
        QPainter p(this);
 
112
        p.drawPixmap(0, 0, *g_pXmmsLogo, 0, 0, 50, 16);
 
113
        QColor clr(140, 120, 255);
 
114
        p.setPen(clr);
 
115
 
 
116
        QFont f = KviConfig::getFixedFont();
 
117
        f.setPointSize(9);
 
118
        p.setFont(f);
 
119
 
 
120
        if( m_bIsPlaying ) {
 
121
                KviStr tmp(KviStr::Format, "%d of %d", m_iPlaylistPos + 1, m_iPlaylistLen);
 
122
                p.drawText(1, 1, 48, 14, AlignCenter, tmp.ptr());
 
123
        } else {
 
124
                if( m_bIsRunning ) {
 
125
                        KviStr tmp(KviStr::Format, "0 of %d", m_iPlaylistLen);
 
126
                        p.drawText(1, 1, 48, 14, AlignCenter, tmp.ptr());
 
127
                } else
 
128
                        p.drawText(1, 1, 48, 14, AlignCenter, "---");
 
129
        }
 
130
        // Prev
 
131
        p.drawPixmap(50, 0, ((m_mousePressX >= 50) && (m_mousePressX < 66)) ?
 
132
                *g_pXmmsButtonsPressed : *g_pXmmsButtonsNormal, 0, 0, 16, 16);
 
133
        // Play
 
134
        p.drawPixmap(66, 0, ((m_mousePressX >= 66) && (m_mousePressX < 82)) ?
 
135
                *g_pXmmsButtonsPressed : (m_bIsPlaying ? *g_pXmmsButtonsActive : *g_pXmmsButtonsNormal), 16, 0, 16, 16);
 
136
        // Pause
 
137
        p.drawPixmap(82, 0, ((m_mousePressX >= 82) && (m_mousePressX < 98)) ?
 
138
                *g_pXmmsButtonsPressed : (libxmms_remote_is_paused(0) ? *g_pXmmsButtonsActive : *g_pXmmsButtonsNormal), 32, 0, 16, 16);
 
139
        // Stop
 
140
        p.drawPixmap(98, 0, ((m_mousePressX >= 98) && (m_mousePressX < 114)) ?
 
141
                *g_pXmmsButtonsPressed : ((m_bIsPlaying || (!m_bIsRunning)) ? *g_pXmmsButtonsNormal : *g_pXmmsButtonsActive), 48, 0, 16, 16);
 
142
        // Next
 
143
        p.drawPixmap(114, 0, ((m_mousePressX >= 114) && (m_mousePressX < 130)) ?
 
144
                *g_pXmmsButtonsPressed : *g_pXmmsButtonsNormal, 64, 0, 16, 16);
 
145
        // Eject
 
146
        p.drawPixmap(130, 0, ((m_mousePressX >= 130) && (m_mousePressX < 146)) ?
 
147
                *g_pXmmsButtonsPressed : *g_pXmmsButtonsNormal, 80, 0, 16, 16);
 
148
}
 
149
 
 
150
void KviXmmsWidget::timerEvent(QTimerEvent *e)
 
151
{
 
152
        if( e->timerId() == m_timer ) {
 
153
                     if( m_bIsRunning   != libxmms_remote_is_running(0)          ) repaint();
 
154
                else if( m_bIsPlaying   != libxmms_remote_is_playing(0)          ) repaint();
 
155
                else if( m_iPlaylistPos != libxmms_remote_get_playlist_pos(0)    ) repaint();
 
156
                else if( m_iPlaylistLen != libxmms_remote_get_playlist_length(0) ) repaint();
 
157
        }
 
158
        KviDockableWidget::timerEvent(e);
 
159
}
 
160
 
 
161
#include "m_kvi_xmms_widget.moc"