summaryrefslogtreecommitdiffstats
path: root/kopete/plugins/nowlistening/nlkscd.cpp
blob: bd9b9b6b355ea39f4551389131dd684da00d77bd (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
/*
    nlkscd.cpp

    Kopete Now Listening To plugin

    Copyright (c) 2002,2003,2004 by Will Stephenson <will@stevello.free-online.co.uk>

    Kopete    (c) 2002,2003,2004 by the Kopete developers  <kopete-devel@kde.org>
	
	Purpose: 
	This class abstracts the interface to KsCD by
	implementing NLMediaPlayer

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

#include <kdebug.h>
#include <tqstringlist.h>

#include "nlmediaplayer.h"

#include "nlkscd.h"

NLKscd::NLKscd( DCOPClient *client ) : NLMediaPlayer()
{
	m_client = client;
	m_type = Audio;
	m_name = "KsCD";
}

void NLKscd::update()
{
	m_playing = false;
	TQString newTrack;
	// see if it's registered with DCOP
	if ( m_client->isApplicationRegistered( "kscd" ) )
	{
		// see if it's playing
		TQByteArray data, replyData;
		TQCString replyType;
		if ( !m_client->call( "kscd", "CDPlayer", "playing()", data,
					replyType, replyData ) )
		{
			// we're talking to a KsCD without the playing() method
			m_playing = true;
//			kdDebug( 14307 ) << "NLKscd::update() - KsCD without playing()"
//				<< endl;
		}
		else
		{
			TQDataStream reply( replyData, IO_ReadOnly );
			if ( replyType == "bool" ) {
				reply >> m_playing;
//				kdDebug( 14307 ) << "NLKscd::update() - KsCD is " <<
//					( m_playing ? "" : "not " ) << "playing!" << endl;
			}
		}
		// poll it for its current artist 
		if ( !m_client->call( "kscd", "CDPlayer",
					"currentArtist()", data, replyType, replyData ) )
			kdDebug( 14307 ) <<  "NLKscd::update() DCOP error"
				<< endl;
		else {
			TQDataStream reply( replyData, IO_ReadOnly );
			if ( replyType == TQSTRING_OBJECT_NAME_STRING )
				reply >> m_artist;
			else
				kdDebug( 14307 ) << "NLKscd::update() trackList returned unexpected reply type!" << endl;
		}

		//album
		if ( !m_client->call( "kscd", "CDPlayer",
					"currentAlbum()", data, replyType, replyData ) )
			kdDebug( 14307 ) <<  "NLKscd::update() DCOP error"
				<< endl;
		else {
			TQDataStream reply( replyData, IO_ReadOnly );
			if ( replyType == TQSTRING_OBJECT_NAME_STRING )
				reply >> m_album;
			else
				kdDebug( 14307 ) << "NLKscd::update() trackList returned unexpected reply type!" << endl;
		}

		// Get the current track title
		if ( !m_client->call( "kscd", "CDPlayer",
					"currentTrackTitle()", data, replyType, replyData ) )
			kdDebug( 14307 ) << "NLKscd::update() - there was some error using DCOP." << endl;
		else {
			TQDataStream reply( replyData, IO_ReadOnly );
			if ( replyType == TQSTRING_OBJECT_NAME_STRING ) {
				reply >> newTrack;
				//kdDebug( 14307 ) << "the result is: " << newTrack.latin1()
				//	<< endl;
			} else
				kdDebug( 14307 ) << "NLKscd::update()-  currentTrackTitle "
					<< "returned unexpected reply type!" << endl;
		}
		// if the current track title has changed
		if ( newTrack != m_track )
		{
			m_newTrack = true;
			m_track = newTrack;
		}
		else
			m_newTrack = false;
//		kdDebug( 14307 ) << "NLKscd::update() - found kscd - "
//			<< m_track << endl;

	}
//	else
//		kdDebug( 14307 ) << "NLKscd::update() - kscd not found" << endl;
}

// vim: set noet ts=4 sts=4 sw=4: