diff --git a/src/libtomahawk/infosystem/infoplugins/adium.h b/src/libtomahawk/infosystem/infoplugins/adium.h new file mode 100644 index 000000000..9833fe82b --- /dev/null +++ b/src/libtomahawk/infosystem/infoplugins/adium.h @@ -0,0 +1,25 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk 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 3 of the License, or + * (at your option) any later version. + * + * Tomahawk 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef ADIUM_TOMAHAWK_H +#define ADIUM_TOMAHAWK_H +#include + +void script( const char* status ); + +#endif ADIUM_TOMAHAWK_H diff --git a/src/libtomahawk/infosystem/infoplugins/adium.mm b/src/libtomahawk/infosystem/infoplugins/adium.mm new file mode 100644 index 000000000..576bc0624 --- /dev/null +++ b/src/libtomahawk/infosystem/infoplugins/adium.mm @@ -0,0 +1,30 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk 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 3 of the License, or + * (at your option) any later version. + * + * Tomahawk 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#import +#import +#import "adium.h" + +void script( const char* status ) +{ + NSString *stat = [NSString stringWithUTF8String:status]; + NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:stat]; + NSDictionary *errorDictionary; + NSAppleEventDescriptor *eventDescriptor = [appleScript executeAndReturnError:&errorDictionary]; + [appleScript release]; +} diff --git a/src/libtomahawk/infosystem/infoplugins/adiumplugin.cpp b/src/libtomahawk/infosystem/infoplugins/adiumplugin.cpp new file mode 100644 index 000000000..acb36d30e --- /dev/null +++ b/src/libtomahawk/infosystem/infoplugins/adiumplugin.cpp @@ -0,0 +1,121 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk 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 3 of the License, or + * (at your option) any later version. + * + * Tomahawk 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include + +#include "artist.h" +#include "result.h" + +#include "adiumplugin.h" +#include "adium.h" + +static void setStatus(const QString &status) +{ + QString adiumStatus = "tell application \"Adium\"\n"; + adiumStatus.append("set the status message of every account to \""); + adiumStatus.append(status); + adiumStatus.append("\"\nend tell\n"); + const char* scriptstr = adiumStatus.toUtf8(); + script( scriptstr ); + +} + +using namespace Tomahawk::InfoSystem; + +AdiumPlugin::AdiumPlugin(QObject *parent) + : InfoPlugin(parent) +{ + /** No supported types since the plugin pushes info, doesn't get any */ + qDebug() << Q_FUNC_INFO; + QSet< InfoType > supportedTypes; + InfoSystem *system = qobject_cast< InfoSystem* >(parent); + system->registerInfoTypes(this, supportedTypes); + + /** Connect to audio state signals. + TODO: Move this into InfoSystem? There could end up being many plugins + connected to audio state signals. */ + + connect( system, SIGNAL( audioStarted( const Tomahawk::result_ptr& ) ), + SLOT( audioStarted( const Tomahawk::result_ptr& ) ) ); + connect( system, SIGNAL( audioFinished( const Tomahawk::result_ptr& ) ), + SLOT( audioFinished( const Tomahawk::result_ptr& ) ) ); + connect( system, SIGNAL( audioStopped() ), + SLOT( audioStopped() ) ); + connect( system, SIGNAL( audioPaused() ), + SLOT( audioPaused() ) ); + connect( system, SIGNAL( audioResumed( const Tomahawk::result_ptr& ) ), + SLOT( audioResumed( const Tomahawk::result_ptr& ) ) ); + +} + +AdiumPlugin::~AdiumPlugin() +{ + qDebug() << Q_FUNC_INFO; + setStatus( "" ); +} + +void AdiumPlugin::getInfo(const QString &caller, const InfoType type, const QVariant& data, InfoCustomData customData) +{ + switch (type) + { + default: + { + emit info(caller, Tomahawk::InfoSystem::InfoNoInfo, QVariant(), QVariant(), customData); + return; + } + } +} + +/** Audio state slots */ + +void AdiumPlugin::audioStarted( const Tomahawk::result_ptr& track ) +{ + qDebug() << Q_FUNC_INFO; + QString nowPlaying = ""; + nowPlaying.append( track->track() ); + nowPlaying.append(" - "); + nowPlaying.append(track->artist()->name()); + setStatus( nowPlaying ); +} + +void AdiumPlugin::audioFinished( const Tomahawk::result_ptr& track ) +{ + //qDebug() << Q_FUNC_INFO; +} + +void AdiumPlugin::audioStopped() +{ + qDebug() << Q_FUNC_INFO; + // TODO: audio stopped, so push update status to Adium that says "stopped" + setStatus( "Stopped" ); +} + +void AdiumPlugin::audioPaused() +{ + qDebug() << Q_FUNC_INFO; + // TODO: audio paused, so push update status to Adium that says "paused" + setStatus( "Paused" ); +} + +void AdiumPlugin::audioResumed( const Tomahawk::result_ptr& track ) +{ + qDebug() << Q_FUNC_INFO; + // TODO: audio resumed, so push update status to Adium with playing track + this->audioStarted( track ); +} + diff --git a/src/libtomahawk/infosystem/infoplugins/adiumplugin.h b/src/libtomahawk/infosystem/infoplugins/adiumplugin.h new file mode 100644 index 000000000..604432ab1 --- /dev/null +++ b/src/libtomahawk/infosystem/infoplugins/adiumplugin.h @@ -0,0 +1,54 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk 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 3 of the License, or + * (at your option) any later version. + * + * Tomahawk 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef ADIUMPLUGIN_H +#define ADIUMPLUGIN_H + +#include "infosystem/infosystem.h" + +#include + +namespace Tomahawk { + +namespace InfoSystem { + +class AdiumPlugin : public InfoPlugin +{ + Q_OBJECT + +public: + AdiumPlugin( QObject *parent ); + virtual ~AdiumPlugin(); + + void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData ); + +public slots: + void audioStarted( const Tomahawk::result_ptr& track ); + void audioFinished( const Tomahawk::result_ptr& track ); + void audioStopped(); + void audioPaused(); + void audioResumed( const Tomahawk::result_ptr& track ); + +}; + + +} + +} + +#endif // ADIUMPLUGIN_H