diff --git a/CMakeLists.txt b/CMakeLists.txt index 35909aafa..9c52db193 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,6 +263,11 @@ macro_log_feature(LIBLASTFM_FOUND "liblastfm" "Qt library for the Last.fm webser macro_optional_find_package(QtKeychain 0.1.0) macro_log_feature(QTKEYCHAIN_FOUND "QtKeychain" "Provides support for secure credentials storage" "https://github.com/frankosterfeld/qtkeychain" TRUE "" "") +if( UNIX AND NOT APPLE ) + macro_optional_find_package(TelepathyQt 0.9.3) + macro_log_feature(TelepathyQt4_FOUND "Telepathy-Qt" "Telepathy-Qt is a Qt high-level binding for Telepathy, a D-Bus framework for unifying real time communication." FALSE "" "Telepathy-Qt is needed for sharing Jabber/GTalk accounts with Telepathy.\n") +endif() + # we need pthreads too macro_optional_find_package(Threads) macro_log_feature(THREADS_FOUND "Threads" "Threading Library" "" TRUE "" "Platform specific library for threading") diff --git a/CMakeModules/FindTelepathyQt.cmake b/CMakeModules/FindTelepathyQt.cmake new file mode 100644 index 000000000..2b286856b --- /dev/null +++ b/CMakeModules/FindTelepathyQt.cmake @@ -0,0 +1,27 @@ +# Copyright (c) 2013, Teo Mrnjavac + +include(FindPackageHandleStandardArgs) + +if( NOT BUILD_WITH_QT4 ) + find_package(TelepathyQt5 NO_MODULE) + set(TelepathyQt_FOUND ${TelepathyQt5_FOUND}) + set(TELEPATHY_QT_VERSION ${TELEPATHY_QT5_VERSION}) + set(TELEPATHY_QT_INSTALL_DIR ${TELEPATHY_QT5_INSTALL_DIR}) + set(TELEPATHY_QT_INCLUDE_DIR ${TELEPATHY_QT5_INCLUDE_DIR}) + set(TELEPATHY_QT_LIB_DIR ${TELEPATHY_QT5_LIB_DIR}) + set(TELEPATHY_QT_SHARE_DIR ${TELEPATHY_QT5_SHARE_DIR}) + set(TELEPATHY_QT_LIBRARIES ${TELEPATHY_QT5_LIBRARIES}) +else() + find_package(TelepathyQt4 NO_MODULE) + set(TelepathyQt_FOUND ${TelepathyQt4_FOUND}) + set(TELEPATHY_QT_VERSION ${TELEPATHY_QT4_VERSION}) + set(TELEPATHY_QT_INSTALL_DIR ${TELEPATHY_QT4_INSTALL_DIR}) + set(TELEPATHY_QT_INCLUDE_DIR ${TELEPATHY_QT4_INCLUDE_DIR}) + set(TELEPATHY_QT_LIB_DIR ${TELEPATHY_QT4_LIB_DIR}) + set(TELEPATHY_QT_SHARE_DIR ${TELEPATHY_QT4_SHARE_DIR}) + set(TELEPATHY_QT_LIBRARIES ${TELEPATHY_QT4_LIBRARIES}) +endif() + +set(TELEPATHY_QT_FOUND ${TelepathyQt_FOUND}) + +find_package_handle_standard_args(TelepathyQt DEFAULT_MSG TELEPATHY_QT_INSTALL_DIR ) diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 277e92a9d..8dd9992db 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -365,6 +365,8 @@ list(APPEND libSources thirdparty/kdsingleapplicationguard/kdlockedsharedmemorypointer.cpp ) +add_subdirectory( accounts/configstorage ) + IF(LIBLASTFM_FOUND) include_directories( ${LIBLASTFM_INCLUDE_DIRS} ) list(APPEND LINK_LIBRARIES ${LIBLASTFM_LIBRARIES} ) diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index 88ec4c4e7..7b758e085 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -286,9 +286,10 @@ void AccountManager::loadFromConfig() { m_creds = new CredentialsManager( this ); - ConfigStorage* configStorage = new LocalConfigStorage( this ); //registers with CredentialsManager in the ctor - m_configStorageById.insert( configStorage->id(), configStorage ); + ConfigStorage* configStorage; + configStorage = new LocalConfigStorage( this ); //registers with CredentialsManager in the ctor + m_configStorageById.insert( configStorage->id(), configStorage ); QStringList accountIds; foreach ( ConfigStorage* cs, m_configStorageById ) diff --git a/src/libtomahawk/accounts/ConfigStorageDllMacro.h b/src/libtomahawk/accounts/ConfigStorageDllMacro.h new file mode 100644 index 000000000..4a1db7294 --- /dev/null +++ b/src/libtomahawk/accounts/ConfigStorageDllMacro.h @@ -0,0 +1,32 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 CONFIGSTORAGEDLLMACRO_H +#define CONFIGSTORAGEDLLMACRO_H + +#include + +#ifndef CONFIGSTORAGEDLLEXPORT +# if defined (CONFIGSTORAGEDLLEXPORT_PRO) +# define CONFIGSTORAGEDLLEXPORT Q_DECL_EXPORT +# else +# define CONFIGSTORAGEDLLEXPORT Q_DECL_IMPORT +# endif +#endif + +#endif // CONFIGSTORAGEDLLMACRO_H diff --git a/src/libtomahawk/accounts/CredentialsManager.h b/src/libtomahawk/accounts/CredentialsManager.h index aa000709e..eaf7b4f46 100644 --- a/src/libtomahawk/accounts/CredentialsManager.h +++ b/src/libtomahawk/accounts/CredentialsManager.h @@ -19,6 +19,8 @@ #ifndef CREDENTIALSMANAGER_H #define CREDENTIALSMANAGER_H +#include "DllMacro.h" + #include #include #include @@ -60,7 +62,7 @@ private: * This ensures an illusion of synchronous operations for Tomahawk's Account classes, even though all * QtKeychain jobs are async. */ -class CredentialsManager : public QObject +class DLLEXPORT CredentialsManager : public QObject { Q_OBJECT public: diff --git a/src/libtomahawk/accounts/configstorage/CMakeLists.txt b/src/libtomahawk/accounts/configstorage/CMakeLists.txt new file mode 100644 index 000000000..88ac22f2d --- /dev/null +++ b/src/libtomahawk/accounts/configstorage/CMakeLists.txt @@ -0,0 +1,14 @@ +include( ${CMAKE_CURRENT_LIST_DIR}/../../../../TomahawkAddPlugin.cmake ) + +file(GLOB SUBDIRECTORIES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*") +foreach(SUBDIRECTORY ${SUBDIRECTORIES}) + if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/CMakeLists.txt") + if(SUBDIRECTORY STREQUAL "telepathy") + if( TelepathyQt_FOUND ) + add_subdirectory( telepathy ) + endif() + else() + add_subdirectory(${SUBDIRECTORY}) + endif() + endif() +endforeach() diff --git a/src/libtomahawk/accounts/configstorage/telepathy/CMakeLists.txt b/src/libtomahawk/accounts/configstorage/telepathy/CMakeLists.txt new file mode 100644 index 000000000..25f64f7ea --- /dev/null +++ b/src/libtomahawk/accounts/configstorage/telepathy/CMakeLists.txt @@ -0,0 +1,11 @@ +include_directories(${TELEPATHY_QT_INCLUDE_DIR}) + +tomahawk_add_plugin(telepathy + TYPE configstorage + EXPORT_MACRO CONFIGSTORAGEDLLEXPORT_PRO + SOURCES + TelepathyConfigStorage.cpp + LINK_LIBRARIES + ${TOMAHAWK_LIBRARIES} + ${TELEPATHY_QT_LIBRARIES} +) diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp new file mode 100644 index 000000000..acf2cb582 --- /dev/null +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -0,0 +1,115 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 "TelepathyConfigStorage.h" + +#include "accounts/Account.h" +#include "accounts/AccountManager.h" +#include "accounts/CredentialsManager.h" +#include "utils/Logger.h" + + +namespace Tomahawk +{ + +namespace Accounts +{ + + +TelepathyConfigStorage::TelepathyConfigStorage( QObject* parent ) + : ConfigStorage( parent ) + , m_credentialsServiceName( "telepathy-kde" ) +{ + tDebug() << Q_FUNC_INFO; + + + // tell CredentialsManager which account ids it will be writing credentials for and in which svc + // so it can preload them when we call CM::loadCredentials() + AccountManager::instance()->credentialsManager()->addService( m_credentialsServiceName, + m_accountIds ); +} + + +QStringList +TelepathyConfigStorage::accountIds() const +{ + return m_accountIds; +} + + +void +TelepathyConfigStorage::save( const QString& accountId, const Account::Configuration& cfg ) +{ +// TomahawkSettings* s = TomahawkSettings::instance(); +// s->beginGroup( "accounts/" + accountId ); +// s->setValue( "accountfriendlyname", cfg.accountFriendlyName ); +// s->setValue( "enabled", cfg.enabled ); +// s->setValue( "configuration", cfg.configuration ); +// s->setValue( "acl", cfg.acl ); +// s->setValue( "types", cfg.types ); +// s->endGroup(); +// s->sync(); + + //CredentialsManager* c = AccountManager::instance()->credentialsManager(); + //c->setCredentials( m_credentialsServiceName, accountId, cfg.credentials ); + + if ( !m_accountIds.contains( accountId ) ) + m_accountIds.append( accountId ); +} + + +void +TelepathyConfigStorage::load( const QString& accountId, Account::Configuration& cfg ) +{ +// TomahawkSettings* s = TomahawkSettings::instance(); +// s->beginGroup( "accounts/" + accountId ); +// cfg.accountFriendlyName = s->value( "accountfriendlyname", QString() ).toString(); +// cfg.enabled = s->value( "enabled", false ).toBool(); +// cfg.configuration = s->value( "configuration", QVariantHash() ).toHash(); +// cfg.acl = s->value( "acl", QVariantMap() ).toMap(); +// cfg.types = s->value( "types", QStringList() ).toStringList(); +// s->endGroup(); + + CredentialsManager* c = AccountManager::instance()->credentialsManager(); + QString prefix( "tomahawkaccount_" ); + QString idInKeychain = accountId; + if ( idInKeychain.startsWith( prefix ) ) + idInKeychain.remove( 0, prefix.length() ); + cfg.credentials = c->credentials( m_credentialsServiceName, idInKeychain ); +} + + +void +TelepathyConfigStorage::remove( const QString& accountId ) +{ + TomahawkSettings* s = TomahawkSettings::instance(); + s->beginGroup( "accounts/" + accountId ); + s->remove( "accountfriendlyname" ); + s->remove( "enabled" ); + s->remove( "configuration" ); + s->remove( "acl" ); + s->remove( "types" ); + s->endGroup(); + s->remove( "accounts/" + accountId ); + + CredentialsManager* c = AccountManager::instance()->credentialsManager(); + c->setCredentials( m_credentialsServiceName, accountId, QVariantHash() ); +} + +} +} diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h new file mode 100644 index 000000000..c85df045c --- /dev/null +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h @@ -0,0 +1,56 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 TELEPATHYCONFIGSTORAGE_H +#define TELEPATHYCONFIGSTORAGE_H + +#include "accounts/ConfigStorageDllMacro.h" +#include "accounts/ConfigStorage.h" + +namespace Tomahawk +{ + +namespace Accounts +{ + +class CONFIGSTORAGEDLLEXPORT TelepathyConfigStorage : public ConfigStorage +{ + Q_OBJECT +public: + explicit TelepathyConfigStorage( QObject* parent = 0 ); + + QString id() const { return "telepathyconfigstorage"; } + + QStringList accountIds() const; + + virtual void save( const QString& accountId, const Account::Configuration& cfg ); + virtual void load( const QString& accountId, Account::Configuration& cfg ); + virtual void remove( const QString& accountId ); + +private: + const QString m_credentialsServiceName; + QStringList m_accountIds; + + static TelepathyConfigStorage* s_instance; +}; + +} //namespace Accounts + +} //namespace Tomahawk + +#endif // TELEPATHYCONFIGSTORAGE_H diff --git a/src/tomahawk/Config.h.in b/src/tomahawk/Config.h.in index 60e0c37ec..27500df65 100644 --- a/src/tomahawk/Config.h.in +++ b/src/tomahawk/Config.h.in @@ -19,7 +19,7 @@ #cmakedefine WITH_UPOWER #cmakedefine WITH_GNOMESHORTCUTHANDLER - +#cmakedefine TELEPATHY_QT_FOUND #cmakedefine LIBLASTFM_FOUND #cmakedefine QCA2_FOUND