From 69530a4dd0c530c9f740aea248c6e858b9d9d631 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Thu, 5 Jun 2014 21:40:33 +0100 Subject: [PATCH] Merge TomahawkSettings and TomahawkSettingsGui --- src/libtomahawk/AtticaManager.cpp | 14 +-- src/libtomahawk/CMakeLists.txt | 1 - src/libtomahawk/TomahawkSettings.cpp | 52 ++++++++- src/libtomahawk/TomahawkSettings.h | 11 +- src/libtomahawk/TomahawkSettingsGui.cpp | 107 ------------------ src/libtomahawk/TomahawkSettingsGui.h | 53 --------- .../utils/BinaryInstallerHelper.cpp | 4 +- src/tomahawk/TomahawkApp.cpp | 20 ++-- src/tomahawk/main.cpp | 8 +- 9 files changed, 77 insertions(+), 193 deletions(-) delete mode 100644 src/libtomahawk/TomahawkSettingsGui.cpp delete mode 100644 src/libtomahawk/TomahawkSettingsGui.h diff --git a/src/libtomahawk/AtticaManager.cpp b/src/libtomahawk/AtticaManager.cpp index a27978e75..891ce928a 100644 --- a/src/libtomahawk/AtticaManager.cpp +++ b/src/libtomahawk/AtticaManager.cpp @@ -19,7 +19,7 @@ #include "AtticaManager.h" #include "utils/TomahawkUtils.h" -#include "TomahawkSettingsGui.h" +#include "TomahawkSettings.h" #include "Pipeline.h" #include "Source.h" #include "config.h" @@ -255,7 +255,7 @@ AtticaManager::uploadRating( const Content& c ) } } - TomahawkSettingsGui::instanceGui()->setAtticaResolverStates( m_resolverStates ); + TomahawkSettings::instance()->setAtticaResolverStates( m_resolverStates ); PostJob* job = m_resolverProvider.voteForContent( c.id(), (uint)c.rating() ); connect( job, SIGNAL( finished( Attica::BaseJob* ) ), job, SLOT( deleteLater() ) ); @@ -330,7 +330,7 @@ AtticaManager::providerAdded( const Provider& provider ) m_resolverProvider = provider; m_resolvers.clear(); - m_resolverStates = TomahawkSettingsGui::instanceGui()->atticaResolverStates(); + m_resolverStates = TomahawkSettings::instance()->atticaResolverStates(); ListJob* job = m_resolverProvider.requestCategories(); connect( job, SIGNAL( finished( Attica::BaseJob* ) ), this, SLOT( categoriesReturned( Attica::BaseJob* ) ) ); @@ -382,7 +382,7 @@ AtticaManager::resolversList( BaseJob* j ) // Uh oh qWarning() << "Found attica resolver marked as installed that didn't exist on disk! Setting to uninstalled: " << rId << dir.absolutePath(); m_resolverStates[ rId ].state = Uninstalled; - TomahawkSettingsGui::instanceGui()->setAtticaResolverState( rId, Uninstalled ); + TomahawkSettings::instance()->setAtticaResolverState( rId, Uninstalled ); } } } @@ -708,7 +708,7 @@ AtticaManager::payloadFetched() { tDebug( LOGVERBOSE ) << "Setting installed state to resolver:" << resolverId; m_resolverStates[ resolverId ].state = Installed; - TomahawkSettingsGui::instanceGui()->setAtticaResolverStates( m_resolverStates ); + TomahawkSettings::instance()->setAtticaResolverStates( m_resolverStates ); emit resolverInstalled( resolverId ); emit resolverStateChanged( resolverId ); } @@ -739,7 +739,7 @@ AtticaManager::uninstallResolver( const QString& pathToResolver ) m_resolverStates[ atticaId ].state = Uninstalled; delete m_resolverStates[ resolver.id() ].pixmap; m_resolverStates[ atticaId ].pixmap = 0; - TomahawkSettingsGui::instanceGui()->setAtticaResolverState( atticaId, Uninstalled ); + TomahawkSettings::instance()->setAtticaResolverState( atticaId, Uninstalled ); doResolverRemove( atticaId ); } @@ -757,7 +757,7 @@ AtticaManager::uninstallResolver( const Content& resolver ) emit resolverStateChanged( resolver.id() ); m_resolverStates[ resolver.id() ].state = Uninstalled; - TomahawkSettingsGui::instanceGui()->setAtticaResolverState( resolver.id(), Uninstalled ); + TomahawkSettings::instance()->setAtticaResolverState( resolver.id(), Uninstalled ); } delete m_resolverStates[ resolver.id() ].pixmap; diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 98fe51401..2159e9403 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -22,7 +22,6 @@ set( libGuiSources ViewPagePlugin.cpp ViewManager.cpp LatchManager.cpp - TomahawkSettingsGui.cpp context/ContextPage.cpp context/ContextWidget.cpp diff --git a/src/libtomahawk/TomahawkSettings.cpp b/src/libtomahawk/TomahawkSettings.cpp index 0b9540fdb..109e5ea25 100644 --- a/src/libtomahawk/TomahawkSettings.cpp +++ b/src/libtomahawk/TomahawkSettings.cpp @@ -35,9 +35,12 @@ #if QT_VERSION < QT_VERSION_CHECK(5,0,0) #include + #include #else #include + #include #endif + #include using namespace Tomahawk; @@ -705,7 +708,11 @@ TomahawkSettings::infoSystemCacheVersion() const QString TomahawkSettings::storageCacheLocation() const { - return QDir::tempPath() + "/tomahawk/"; +#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) + return QStandardPaths::writableLocation( QStandardPaths::CacheLocation ); +#else + return QDesktopServices::storageLocation( QDesktopServices::CacheLocation ); +#endif } @@ -714,8 +721,10 @@ TomahawkSettings::scannerPaths() const { QString musicLocation; -#if defined(Q_OS_LINUX) - musicLocation = QDir::homePath() + QLatin1String("/Music"); +#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) + musicLocation = QStandardPaths::writableLocation( QStandardPaths::MusicLocation ); +#else + musicLocation = QDesktopServices::storageLocation( QDesktopServices::MusicLocation ); #endif return value( "scanner/paths", musicLocation ).toStringList(); @@ -1597,3 +1606,40 @@ TomahawkSettings::registerCustomSettingsHandlers() qRegisterMetaType< AtticaManager::StateHash >( "AtticaManager::StateHash" ); qRegisterMetaTypeStreamOperators< AtticaManager::StateHash >( "AtticaManager::StateHash" ); } + + +void +TomahawkSettings::setAtticaResolverState( const QString& resolver, AtticaManager::ResolverState state ) +{ + AtticaManager::StateHash resolvers = value( "script/atticaresolverstates" ).value< AtticaManager::StateHash >(); + AtticaManager::Resolver r = resolvers.value( resolver ); + r.state = state; + resolvers.insert( resolver, r ); + setValue( "script/atticaresolverstates", QVariant::fromValue< AtticaManager::StateHash >( resolvers ) ); + + sync(); +} + + +AtticaManager::StateHash +TomahawkSettings::atticaResolverStates() const +{ + return value( "script/atticaresolverstates" ).value< AtticaManager::StateHash >(); +} + + +void +TomahawkSettings::setAtticaResolverStates( const AtticaManager::StateHash states ) +{ + setValue( "script/atticaresolverstates", QVariant::fromValue< AtticaManager::StateHash >( states ) ); +} + + +void +TomahawkSettings::removeAtticaResolverState ( const QString& resolver ) +{ + AtticaManager::StateHash resolvers = value( "script/atticaresolverstates" ).value< AtticaManager::StateHash >(); + resolvers.remove( resolver ); + setValue( "script/atticaresolverstates", QVariant::fromValue< AtticaManager::StateHash >( resolvers ) ); +} + diff --git a/src/libtomahawk/TomahawkSettings.h b/src/libtomahawk/TomahawkSettings.h index d74ea4891..af1aaeb42 100644 --- a/src/libtomahawk/TomahawkSettings.h +++ b/src/libtomahawk/TomahawkSettings.h @@ -49,9 +49,9 @@ public: void applyChanges() { emit changed(); } /// General settings - virtual QString storageCacheLocation() const; + QString storageCacheLocation() const; - virtual QStringList scannerPaths() const; /// QDesktopServices::MusicLocation in TomahawkSettingsGui + QStringList scannerPaths() const; /// QDesktopServices::MusicLocation in TomahawkSettingsGui void setScannerPaths( const QStringList& paths ); bool hasScannerPaths() const; uint scannerTime() const; @@ -226,6 +226,13 @@ public: void setLastChartIds( const QMap& ids ); QMap lastChartIds(); + AtticaManager::StateHash atticaResolverStates() const; + void setAtticaResolverStates( const AtticaManager::StateHash states ); + + void setAtticaResolverState( const QString& resolver, AtticaManager::ResolverState state ); + void removeAtticaResolverState( const QString& resolver ); + + signals: void changed(); void recentlyPlayedPlaylistAdded( const QString& playlistId, int sourceId ); diff --git a/src/libtomahawk/TomahawkSettingsGui.cpp b/src/libtomahawk/TomahawkSettingsGui.cpp deleted file mode 100644 index 6ee3b9831..000000000 --- a/src/libtomahawk/TomahawkSettingsGui.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* === 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 "TomahawkSettingsGui.h" - -#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) -#include -#else -#include -#endif - -using namespace Tomahawk; - - -TomahawkSettingsGui* -TomahawkSettingsGui::instanceGui() -{ - return qobject_cast< TomahawkSettingsGui* >(TomahawkSettings::instance()); -} - - -TomahawkSettingsGui::TomahawkSettingsGui( QObject* parent ) - : TomahawkSettings( parent ) -{ -} - - -TomahawkSettingsGui::~TomahawkSettingsGui() -{ -} - - -QString -TomahawkSettingsGui::storageCacheLocation() const -{ -#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) - return QStandardPaths::writableLocation( QStandardPaths::CacheLocation ); -#else - return QDesktopServices::storageLocation( QDesktopServices::CacheLocation ); -#endif -} - - -QStringList -TomahawkSettingsGui::scannerPaths() const -{ - QString musicLocation; - -#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) - musicLocation = QStandardPaths::writableLocation( QStandardPaths::MusicLocation ); -#else - musicLocation = QDesktopServices::storageLocation( QDesktopServices::MusicLocation ); -#endif - - return value( "scanner/paths", musicLocation ).toStringList(); -} - - -void -TomahawkSettingsGui::setAtticaResolverState( const QString& resolver, AtticaManager::ResolverState state ) -{ - AtticaManager::StateHash resolvers = value( "script/atticaresolverstates" ).value< AtticaManager::StateHash >(); - AtticaManager::Resolver r = resolvers.value( resolver ); - r.state = state; - resolvers.insert( resolver, r ); - setValue( "script/atticaresolverstates", QVariant::fromValue< AtticaManager::StateHash >( resolvers ) ); - - sync(); -} - - -AtticaManager::StateHash -TomahawkSettingsGui::atticaResolverStates() const -{ - return value( "script/atticaresolverstates" ).value< AtticaManager::StateHash >(); -} - - -void -TomahawkSettingsGui::setAtticaResolverStates( const AtticaManager::StateHash states ) -{ - setValue( "script/atticaresolverstates", QVariant::fromValue< AtticaManager::StateHash >( states ) ); -} - - -void -TomahawkSettingsGui::removeAtticaResolverState ( const QString& resolver ) -{ - AtticaManager::StateHash resolvers = value( "script/atticaresolverstates" ).value< AtticaManager::StateHash >(); - resolvers.remove( resolver ); - setValue( "script/atticaresolverstates", QVariant::fromValue< AtticaManager::StateHash >( resolvers ) ); -} diff --git a/src/libtomahawk/TomahawkSettingsGui.h b/src/libtomahawk/TomahawkSettingsGui.h deleted file mode 100644 index ce704ccc8..000000000 --- a/src/libtomahawk/TomahawkSettingsGui.h +++ /dev/null @@ -1,53 +0,0 @@ -/* === 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 TOMAHAWK_SETTINGS_GUI_H -#define TOMAHAWK_SETTINGS_GUI_H - -#include "TomahawkSettings.h" -#include "AtticaManager.h" - -#include - -#include "DllMacro.h" - -/** - * Convenience wrapper around QSettings for tomahawk-specific config - */ -class DLLEXPORT TomahawkSettingsGui : public TomahawkSettings -{ -Q_OBJECT - -public: - static TomahawkSettingsGui* instanceGui(); - - explicit TomahawkSettingsGui( QObject* parent = 0 ); - virtual ~TomahawkSettingsGui(); - - virtual QString storageCacheLocation() const; - virtual QStringList scannerPaths() const; - - AtticaManager::StateHash atticaResolverStates() const; - void setAtticaResolverStates( const AtticaManager::StateHash states ); - - void setAtticaResolverState( const QString& resolver, AtticaManager::ResolverState state ); - void removeAtticaResolverState( const QString& resolver ); -}; - - -#endif diff --git a/src/libtomahawk/utils/BinaryInstallerHelper.cpp b/src/libtomahawk/utils/BinaryInstallerHelper.cpp index 23bbcd5aa..b5c55c30f 100644 --- a/src/libtomahawk/utils/BinaryInstallerHelper.cpp +++ b/src/libtomahawk/utils/BinaryInstallerHelper.cpp @@ -19,7 +19,7 @@ #include "BinaryInstallerHelper.h" #include "accounts/AccountManager.h" -#include "TomahawkSettingsGui.h" +#include "TomahawkSettings.h" #include BinaryInstallerHelper::BinaryInstallerHelper( QTemporaryFile* tempFile, const QString& resolverId, bool createAccount, AtticaManager* manager ) @@ -64,7 +64,7 @@ BinaryInstallerHelper::installSucceeded( const QString& path ) m_manager.data()->m_resolverStates[ m_resolverId ].scriptPath = path; m_manager.data()->m_resolverStates[ m_resolverId ].state = AtticaManager::Installed; - TomahawkSettingsGui::instanceGui()->setAtticaResolverStates( m_manager.data()->m_resolverStates ); + TomahawkSettings::instance()->setAtticaResolverStates( m_manager.data()->m_resolverStates ); emit m_manager.data()->resolverInstalled( m_resolverId ); emit m_manager.data()->resolverStateChanged( m_resolverId ); diff --git a/src/tomahawk/TomahawkApp.cpp b/src/tomahawk/TomahawkApp.cpp index a1000c071..675f849b5 100644 --- a/src/tomahawk/TomahawkApp.cpp +++ b/src/tomahawk/TomahawkApp.cpp @@ -71,17 +71,15 @@ #include "utils/TomahawkCache.h" #include "widgets/SplashWidget.h" -#ifndef ENABLE_HEADLESS - #include "resolvers/JSResolver.h" - #include "resolvers/ScriptResolver.h" - #include "utils/SpotifyParser.h" - #include "AtticaManager.h" - #include "TomahawkWindow.h" - #include "dialogs/SettingsDialog.h" - #include "ActionCollection.h" - #include "widgets/HeaderLabel.h" - #include "TomahawkSettingsGui.h" -#endif +#include "resolvers/JSResolver.h" +#include "resolvers/ScriptResolver.h" +#include "utils/SpotifyParser.h" +#include "AtticaManager.h" +#include "TomahawkWindow.h" +#include "dialogs/SettingsDialog.h" +#include "ActionCollection.h" +#include "widgets/HeaderLabel.h" +#include "TomahawkSettings.h" #include "config.h" diff --git a/src/tomahawk/main.cpp b/src/tomahawk/main.cpp index 02c0e10e1..24132b3bd 100644 --- a/src/tomahawk/main.cpp +++ b/src/tomahawk/main.cpp @@ -34,7 +34,7 @@ static pascal OSErr appleEventHandler( const AppleEvent*, AppleEvent*, long ); #endif -#include "TomahawkSettingsGui.h" +#include "TomahawkSettings.h" #ifdef WITH_CRASHREPORTER #include "libcrashreporter-handler/Handler.h" #endif @@ -156,13 +156,7 @@ main( int argc, char *argv[] ) // MUST register StateHash ****before*** initing TomahawkSettingsGui as constructor of settings does upgrade before Gui subclass registers type TomahawkSettings::registerCustomSettingsHandlers(); - TomahawkSettingsGui::registerCustomSettingsHandlers(); - -#ifdef ENABLE_HEADLESS new TomahawkSettings( &a ); -#else - new TomahawkSettingsGui( &a ); -#endif #ifdef WITH_CRASHREPORTER new CrashReporter::Handler( QDir::tempPath(), TomahawkSettings::instance()->crashReporterEnabled() && !TomahawkUtils::headless(), "tomahawk_crash_reporter" );