1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 16:44:05 +02:00

Merge TomahawkSettings and TomahawkSettingsGui

This commit is contained in:
Uwe L. Korn
2014-06-05 21:40:33 +01:00
parent 68a225eeaa
commit 69530a4dd0
9 changed files with 77 additions and 193 deletions

View File

@@ -19,7 +19,7 @@
#include "AtticaManager.h" #include "AtticaManager.h"
#include "utils/TomahawkUtils.h" #include "utils/TomahawkUtils.h"
#include "TomahawkSettingsGui.h" #include "TomahawkSettings.h"
#include "Pipeline.h" #include "Pipeline.h"
#include "Source.h" #include "Source.h"
#include "config.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() ); PostJob* job = m_resolverProvider.voteForContent( c.id(), (uint)c.rating() );
connect( job, SIGNAL( finished( Attica::BaseJob* ) ), job, SLOT( deleteLater() ) ); connect( job, SIGNAL( finished( Attica::BaseJob* ) ), job, SLOT( deleteLater() ) );
@@ -330,7 +330,7 @@ AtticaManager::providerAdded( const Provider& provider )
m_resolverProvider = provider; m_resolverProvider = provider;
m_resolvers.clear(); m_resolvers.clear();
m_resolverStates = TomahawkSettingsGui::instanceGui()->atticaResolverStates(); m_resolverStates = TomahawkSettings::instance()->atticaResolverStates();
ListJob<Category>* job = m_resolverProvider.requestCategories(); ListJob<Category>* job = m_resolverProvider.requestCategories();
connect( job, SIGNAL( finished( Attica::BaseJob* ) ), this, SLOT( categoriesReturned( Attica::BaseJob* ) ) ); connect( job, SIGNAL( finished( Attica::BaseJob* ) ), this, SLOT( categoriesReturned( Attica::BaseJob* ) ) );
@@ -382,7 +382,7 @@ AtticaManager::resolversList( BaseJob* j )
// Uh oh // Uh oh
qWarning() << "Found attica resolver marked as installed that didn't exist on disk! Setting to uninstalled: " << rId << dir.absolutePath(); qWarning() << "Found attica resolver marked as installed that didn't exist on disk! Setting to uninstalled: " << rId << dir.absolutePath();
m_resolverStates[ rId ].state = Uninstalled; 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; tDebug( LOGVERBOSE ) << "Setting installed state to resolver:" << resolverId;
m_resolverStates[ resolverId ].state = Installed; m_resolverStates[ resolverId ].state = Installed;
TomahawkSettingsGui::instanceGui()->setAtticaResolverStates( m_resolverStates ); TomahawkSettings::instance()->setAtticaResolverStates( m_resolverStates );
emit resolverInstalled( resolverId ); emit resolverInstalled( resolverId );
emit resolverStateChanged( resolverId ); emit resolverStateChanged( resolverId );
} }
@@ -739,7 +739,7 @@ AtticaManager::uninstallResolver( const QString& pathToResolver )
m_resolverStates[ atticaId ].state = Uninstalled; m_resolverStates[ atticaId ].state = Uninstalled;
delete m_resolverStates[ resolver.id() ].pixmap; delete m_resolverStates[ resolver.id() ].pixmap;
m_resolverStates[ atticaId ].pixmap = 0; m_resolverStates[ atticaId ].pixmap = 0;
TomahawkSettingsGui::instanceGui()->setAtticaResolverState( atticaId, Uninstalled ); TomahawkSettings::instance()->setAtticaResolverState( atticaId, Uninstalled );
doResolverRemove( atticaId ); doResolverRemove( atticaId );
} }
@@ -757,7 +757,7 @@ AtticaManager::uninstallResolver( const Content& resolver )
emit resolverStateChanged( resolver.id() ); emit resolverStateChanged( resolver.id() );
m_resolverStates[ resolver.id() ].state = Uninstalled; m_resolverStates[ resolver.id() ].state = Uninstalled;
TomahawkSettingsGui::instanceGui()->setAtticaResolverState( resolver.id(), Uninstalled ); TomahawkSettings::instance()->setAtticaResolverState( resolver.id(), Uninstalled );
} }
delete m_resolverStates[ resolver.id() ].pixmap; delete m_resolverStates[ resolver.id() ].pixmap;

View File

@@ -22,7 +22,6 @@ set( libGuiSources
ViewPagePlugin.cpp ViewPagePlugin.cpp
ViewManager.cpp ViewManager.cpp
LatchManager.cpp LatchManager.cpp
TomahawkSettingsGui.cpp
context/ContextPage.cpp context/ContextPage.cpp
context/ContextWidget.cpp context/ContextWidget.cpp

View File

@@ -35,9 +35,12 @@
#if QT_VERSION < QT_VERSION_CHECK(5,0,0) #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
#include <qtkeychain/keychain.h> #include <qtkeychain/keychain.h>
#include <QDesktopServices>
#else #else
#include <qt5keychain/keychain.h> #include <qt5keychain/keychain.h>
#include <QStandardPaths>
#endif #endif
#include <QDir> #include <QDir>
using namespace Tomahawk; using namespace Tomahawk;
@@ -705,7 +708,11 @@ TomahawkSettings::infoSystemCacheVersion() const
QString QString
TomahawkSettings::storageCacheLocation() const 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; QString musicLocation;
#if defined(Q_OS_LINUX) #if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
musicLocation = QDir::homePath() + QLatin1String("/Music"); musicLocation = QStandardPaths::writableLocation( QStandardPaths::MusicLocation );
#else
musicLocation = QDesktopServices::storageLocation( QDesktopServices::MusicLocation );
#endif #endif
return value( "scanner/paths", musicLocation ).toStringList(); return value( "scanner/paths", musicLocation ).toStringList();
@@ -1597,3 +1606,40 @@ TomahawkSettings::registerCustomSettingsHandlers()
qRegisterMetaType< AtticaManager::StateHash >( "AtticaManager::StateHash" ); qRegisterMetaType< AtticaManager::StateHash >( "AtticaManager::StateHash" );
qRegisterMetaTypeStreamOperators< 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 ) );
}

View File

@@ -49,9 +49,9 @@ public:
void applyChanges() { emit changed(); } void applyChanges() { emit changed(); }
/// General settings /// 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 ); void setScannerPaths( const QStringList& paths );
bool hasScannerPaths() const; bool hasScannerPaths() const;
uint scannerTime() const; uint scannerTime() const;
@@ -226,6 +226,13 @@ public:
void setLastChartIds( const QMap<QString, QVariant>& ids ); void setLastChartIds( const QMap<QString, QVariant>& ids );
QMap<QString, QVariant> lastChartIds(); QMap<QString, QVariant> 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: signals:
void changed(); void changed();
void recentlyPlayedPlaylistAdded( const QString& playlistId, int sourceId ); void recentlyPlayedPlaylistAdded( const QString& playlistId, int sourceId );

View File

@@ -1,107 +0,0 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.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 "TomahawkSettingsGui.h"
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
#include <QStandardPaths>
#else
#include <QDesktopServices>
#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 ) );
}

View File

@@ -1,53 +0,0 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.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 TOMAHAWK_SETTINGS_GUI_H
#define TOMAHAWK_SETTINGS_GUI_H
#include "TomahawkSettings.h"
#include "AtticaManager.h"
#include <QSettings>
#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

View File

@@ -19,7 +19,7 @@
#include "BinaryInstallerHelper.h" #include "BinaryInstallerHelper.h"
#include "accounts/AccountManager.h" #include "accounts/AccountManager.h"
#include "TomahawkSettingsGui.h" #include "TomahawkSettings.h"
#include <QTemporaryFile> #include <QTemporaryFile>
BinaryInstallerHelper::BinaryInstallerHelper( QTemporaryFile* tempFile, const QString& resolverId, bool createAccount, AtticaManager* manager ) 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 ].scriptPath = path;
m_manager.data()->m_resolverStates[ m_resolverId ].state = AtticaManager::Installed; 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()->resolverInstalled( m_resolverId );
emit m_manager.data()->resolverStateChanged( m_resolverId ); emit m_manager.data()->resolverStateChanged( m_resolverId );

View File

@@ -71,17 +71,15 @@
#include "utils/TomahawkCache.h" #include "utils/TomahawkCache.h"
#include "widgets/SplashWidget.h" #include "widgets/SplashWidget.h"
#ifndef ENABLE_HEADLESS #include "resolvers/JSResolver.h"
#include "resolvers/JSResolver.h" #include "resolvers/ScriptResolver.h"
#include "resolvers/ScriptResolver.h" #include "utils/SpotifyParser.h"
#include "utils/SpotifyParser.h" #include "AtticaManager.h"
#include "AtticaManager.h" #include "TomahawkWindow.h"
#include "TomahawkWindow.h" #include "dialogs/SettingsDialog.h"
#include "dialogs/SettingsDialog.h" #include "ActionCollection.h"
#include "ActionCollection.h" #include "widgets/HeaderLabel.h"
#include "widgets/HeaderLabel.h" #include "TomahawkSettings.h"
#include "TomahawkSettingsGui.h"
#endif
#include "config.h" #include "config.h"

View File

@@ -34,7 +34,7 @@
static pascal OSErr appleEventHandler( const AppleEvent*, AppleEvent*, long ); static pascal OSErr appleEventHandler( const AppleEvent*, AppleEvent*, long );
#endif #endif
#include "TomahawkSettingsGui.h" #include "TomahawkSettings.h"
#ifdef WITH_CRASHREPORTER #ifdef WITH_CRASHREPORTER
#include "libcrashreporter-handler/Handler.h" #include "libcrashreporter-handler/Handler.h"
#endif #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 // MUST register StateHash ****before*** initing TomahawkSettingsGui as constructor of settings does upgrade before Gui subclass registers type
TomahawkSettings::registerCustomSettingsHandlers(); TomahawkSettings::registerCustomSettingsHandlers();
TomahawkSettingsGui::registerCustomSettingsHandlers();
#ifdef ENABLE_HEADLESS
new TomahawkSettings( &a ); new TomahawkSettings( &a );
#else
new TomahawkSettingsGui( &a );
#endif
#ifdef WITH_CRASHREPORTER #ifdef WITH_CRASHREPORTER
new CrashReporter::Handler( QDir::tempPath(), TomahawkSettings::instance()->crashReporterEnabled() && !TomahawkUtils::headless(), "tomahawk_crash_reporter" ); new CrashReporter::Handler( QDir::tempPath(), TomahawkSettings::instance()->crashReporterEnabled() && !TomahawkUtils::headless(), "tomahawk_crash_reporter" );