1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-12 09:04:33 +02:00

Create TelepathyConfigStorage as plugin, and link against TelepathyQt.

This commit is contained in:
Teo Mrnjavac
2013-06-10 19:08:51 +02:00
parent 63f9168b4a
commit e4fbe9bffb
11 changed files with 269 additions and 4 deletions

View File

@@ -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")

View File

@@ -0,0 +1,27 @@
# Copyright (c) 2013, Teo Mrnjavac <teo@kde.org>
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 )

View File

@@ -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} )

View File

@@ -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 )

View File

@@ -0,0 +1,32 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef CONFIGSTORAGEDLLMACRO_H
#define CONFIGSTORAGEDLLMACRO_H
#include <QtCore/qglobal.h>
#ifndef CONFIGSTORAGEDLLEXPORT
# if defined (CONFIGSTORAGEDLLEXPORT_PRO)
# define CONFIGSTORAGEDLLEXPORT Q_DECL_EXPORT
# else
# define CONFIGSTORAGEDLLEXPORT Q_DECL_IMPORT
# endif
#endif
#endif // CONFIGSTORAGEDLLMACRO_H

View File

@@ -19,6 +19,8 @@
#ifndef CREDENTIALSMANAGER_H
#define CREDENTIALSMANAGER_H
#include "DllMacro.h"
#include <QObject>
#include <QVariantHash>
#include <QMutex>
@@ -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:

View File

@@ -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()

View File

@@ -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}
)

View File

@@ -0,0 +1,115 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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() );
}
}
}

View File

@@ -0,0 +1,56 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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

View File

@@ -19,7 +19,7 @@
#cmakedefine WITH_UPOWER
#cmakedefine WITH_GNOMESHORTCUTHANDLER
#cmakedefine TELEPATHY_QT_FOUND
#cmakedefine LIBLASTFM_FOUND
#cmakedefine QCA2_FOUND