1 /****************************************************************************************
2  * Copyright (c) 2008 Casey Link <unnamedrambler@gmail.com>                             *
3  *                                                                                      *
4  * This program is free software; you can redistribute it and/or modify it under        *
5  * the terms of the GNU General Public License as published by the Free Software        *
6  * Foundation; either version 2 of the License, or (at your option) any later           *
7  * version.                                                                             *
8  *                                                                                      *
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
11  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
12  *                                                                                      *
13  * You should have received a copy of the GNU General Public License along with         *
14  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
15  ****************************************************************************************/
16 
17 #include "AmarokClient.h"
18 
19 #include <QDBusMessage>
20 #include <QDBusConnection>
21 #include <QtDebug>
22 
Mp3tunesAmarokClient()23 Mp3tunesAmarokClient::Mp3tunesAmarokClient() : Mp3tunesHarmonyClient()
24 {}
25 
dbusEmitMessage(const QString & message,const QString & param=QString ())26 void Mp3tunesAmarokClient::dbusEmitMessage( const QString &message, const QString &param = QString() )
27 {
28     QString name = "org.kde.amarok";
29     QDBusMessage m = QDBusMessage::createMethodCall( name,
30                                                "/Mp3tunesHarmonyHandler",
31                                                "",
32                                                message );
33     if( !param.isEmpty() )
34     {
35       QList<QVariant> args;
36       args.append( param );
37       m.setArguments(args);
38     }
39     QDBusMessage response = QDBusConnection::sessionBus().call( m );
40     if( response.type() == QDBusMessage::ErrorMessage )
41     {
42             qDebug() << "Got ERROR response " << message;
43             qDebug() << response.errorName() << ":  " << response.errorMessage();
44     }
45 }
46 
47 
48 /* SLOTS */
49 void
harmonyError(const QString & error)50 Mp3tunesAmarokClient::harmonyError( const QString &error )
51 {
52     qDebug() << "Received Error: " << error;
53 }
54 
55 void
harmonyWaitingForEmail(const QString & pin)56 Mp3tunesAmarokClient::harmonyWaitingForEmail( const QString &pin )
57 {
58     qDebug() << "Received HARMONY_WAITING_FOR_EMAIL " << pin;
59     dbusEmitMessage( "emitWaitingForEmail", pin );
60 }
61 
62 void
harmonyWaitingForPin()63 Mp3tunesAmarokClient::harmonyWaitingForPin()
64 {
65     qDebug() << "Received HARMONY_WAITING_FOR_PIN";
66     dbusEmitMessage( "emitWaitingForPin" );
67 }
68 
69 void
harmonyConnected()70 Mp3tunesAmarokClient::harmonyConnected()
71 {
72     qDebug() << "Apparently Harmony is connected";
73     dbusEmitMessage( "emitConnected" );
74 }
75 
76 void
harmonyDisconnected()77 Mp3tunesAmarokClient::harmonyDisconnected()
78 {
79     qDebug() << "Harmony said see ya later.";
80     dbusEmitMessage( "emitDisconnected" );
81 }
82 
83 void
harmonyDownloadReady(const Mp3tunesHarmonyDownload & download)84 Mp3tunesAmarokClient::harmonyDownloadReady( const Mp3tunesHarmonyDownload &download )
85 {
86     qDebug() << "Got message about ready: " << download.trackTitle() << " by " << download.artistName() << " on " << download. albumTitle();
87     QString name = "org.kde.amarok";
88     QDBusMessage m = QDBusMessage::createMethodCall( name,
89                                                "/Mp3tunesHarmonyHandler",
90                                                "",
91                                                "emitDownloadReady" );
92     QList<QVariant> args;
93     args.append( download.serialize() );
94     m.setArguments(args);
95     QDBusMessage response = QDBusConnection::sessionBus().call( m );
96     if( response.type() == QDBusMessage::ErrorMessage )
97     {
98             qDebug() << "Got ERROR response harmonyDownloadReady";
99             qDebug() << response.errorName() << ":  " << response.errorMessage();
100     }
101 }
102 
103 void
harmonyDownloadPending(const Mp3tunesHarmonyDownload & download)104 Mp3tunesAmarokClient::harmonyDownloadPending( const Mp3tunesHarmonyDownload &download )
105 {
106     qDebug() << "Got message about pending: " << download.trackTitle() << " by " << download.artistName() << " on " << download. albumTitle();
107     qDebug() << "Got message about ready: " << download.trackTitle() << " by " << download.artistName() << " on " << download. albumTitle();
108     QString name = "org.kde.amarok";
109     QDBusMessage m = QDBusMessage::createMethodCall( name,
110                                                "/Mp3tunesHarmonyHandler",
111                                                "",
112                                                "emitDownloadPending" );
113     QList<QVariant> args;
114     args.append( download.serialize() );
115     m.setArguments(args);
116     QDBusMessage response = QDBusConnection::sessionBus().call( m );
117     if( response.type() == QDBusMessage::ErrorMessage )
118     {
119             qDebug() << "Got ERROR response harmonyDownloadPending";
120             qDebug() << response.errorName() << ":  " << response.errorMessage();
121     }
122 }
123