summaryrefslogtreecommitdiffstats
path: root/kicker-applets/mediacontrol/xmmsInterface.cpp
blob: 7d8e236df2cbc583eeda9ad34eb4aba7790d8944 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/***************************************************************************
                          Interface to access XMMS
                             -------------------
    begin                : Tue Apr 25 11:53:11 CEST 2000
    copyright            : (C) 2000-2002 by Stefan Gehn
    email                : metz {AT} gehn {DOT} net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef HAVE_XMMS // only use if there is xmms installed on compiletime

#include "xmmsInterface.h"
#include "xmmsInterface.moc"
#include <xmms/xmmsctrl.h>
#include <kdebug.h>

#define TIMER_SLOW 1000
#define TIMER_FAST  100
#define XMMS_SESSION 0

XmmsInterface::XmmsInterface() : PlayerInterface()
{
	timervalue = TIMER_FAST;
	bStartingXMMS = false;
	xmms_timer = new TQTimer ( this, "xmms_timer" );

	TQObject::connect( xmms_timer, TQT_SIGNAL(timeout()), TQT_SLOT(updateSlider()) );

	// Better start the timer as late as possible in initialization
	xmms_timer->start ( timervalue );
}

XmmsInterface::~XmmsInterface()
{
	delete xmms_timer;
}

void XmmsInterface::updateSlider ( void )
{
	if ( !xmms_remote_is_running(XMMS_SESSION) )
	{  // XMMS not running
		if (timervalue == TIMER_FAST)  // timer is running fast
		{
			emit playerStopped();
			timervalue = TIMER_SLOW;  // timer does not need to run fast if XMMS is not running
			xmms_timer->changeInterval(timervalue);
			emit newSliderPosition(0,0);
		}
		return;  // as XMMS is not running we can leave now
	}

	// huh, XMMS is running :)
	if (timervalue == TIMER_SLOW)  // what? Still running slow?
	{
		emit playerStarted();
		timervalue = TIMER_FAST;  // boost the timer to have better reaction-times for the applet
		xmms_timer->changeInterval(timervalue);
	}

	int len  = xmms_remote_get_playlist_time ( XMMS_SESSION, xmms_remote_get_playlist_pos(XMMS_SESSION) );
	int time = xmms_remote_get_output_time(XMMS_SESSION);

	if (len < 0)
	{
		len = 0;
		time = 0;
	}

	emit newSliderPosition(len,time);
	emit playingStatusChanged(playingStatus());
}


// Drag-n-Drop stuff =================================================================

void XmmsInterface::dragEnterEvent(TQDragEnterEvent* event)
{
	event->accept( TQTextDrag::canDecode(event) );
}

void XmmsInterface::dropEvent(TQDropEvent* event)
{
	TQString text;
//	kdDebug(90200) << "XmmsInterface::dropEvent()" << endl;
	if ( TQTextDrag::decode(event, text) )
	{
		xmms_remote_playlist_add_url_string(XMMS_SESSION,
			(gchar *)text.local8Bit().data());
	}
}

// ====================================================================================


void XmmsInterface::sliderStartDrag()
{
	xmms_timer->stop();
}

void XmmsInterface::sliderStopDrag()
{
	xmms_timer->start( timervalue );
}

void XmmsInterface::jumpToTime( int msec )
{
	xmms_remote_jump_to_time(XMMS_SESSION, msec);
}

void XmmsInterface::playpause()
{
	if (!xmms_remote_is_running(XMMS_SESSION))
	{
		if (bStartingXMMS)
			return;
		startPlayer("xmms");
		bStartingXMMS = true;
		TQTimer::singleShot(500, this, TQT_SLOT(playpause()));
	}
	else
	{
		bStartingXMMS = false;
		xmms_remote_play_pause(XMMS_SESSION);
	}
}

void XmmsInterface::stop()
{
	xmms_remote_stop(XMMS_SESSION);
}

void XmmsInterface::next()
{
	xmms_remote_playlist_next(XMMS_SESSION);
}

void XmmsInterface::prev()
{
	xmms_remote_playlist_prev(XMMS_SESSION);
}

void XmmsInterface::volumeUp()
{
	const int cur = xmms_remote_get_main_volume(XMMS_SESSION);
	xmms_remote_set_main_volume(XMMS_SESSION, cur+1);
}

void XmmsInterface::volumeDown()
{
	const int cur = xmms_remote_get_main_volume(XMMS_SESSION);
	xmms_remote_set_main_volume(XMMS_SESSION, cur-1);
}

int XmmsInterface::playingStatus()
{
	if (xmms_remote_is_paused(XMMS_SESSION))
		return Paused;

	if (xmms_remote_is_playing(XMMS_SESSION))
		return Playing;

	return Stopped;
}

const TQString XmmsInterface::getTrackTitle() const
{
	return TQString::fromLocal8Bit(
		xmms_remote_get_playlist_title(XMMS_SESSION,
			xmms_remote_get_playlist_pos(XMMS_SESSION)));
}
#endif // HAVE_XMMS