diff --git a/src/libtomahawk/TomahawkSettingsGui.cpp b/src/libtomahawk/TomahawkSettingsGui.cpp new file mode 100644 index 000000000..e91025237 --- /dev/null +++ b/src/libtomahawk/TomahawkSettingsGui.cpp @@ -0,0 +1,133 @@ +/* === 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" + +#include +#include "settingsdialog.h" + +// #include +// +// #include "sip/SipHandler.h" +// #include "playlistinterface.h" +// +// #include "utils/logger.h" +// #include "utils/tomahawkutils.h" +// +// #include "database/databasecommand_updatesearchindex.h" +// #include "database/database.h" + +#define VERSION 5 + +using namespace Tomahawk; + +inline QDataStream& operator<<(QDataStream& out, const AtticaManager::StateHash& states) +{ + out << VERSION; + out << (quint32)states.count(); + foreach( const QString& key, states.keys() ) + { + AtticaManager::Resolver resolver = states[ key ]; + out << key << resolver.version << resolver.scriptPath << (qint32)resolver.state << resolver.userRating; + } + return out; +} + + +inline QDataStream& operator>>(QDataStream& in, AtticaManager::StateHash& states) +{ + quint32 count = 0, version = 0; + in >> version; + in >> count; + for ( uint i = 0; i < count; i++ ) + { + QString key, version, scriptPath; + qint32 state, userRating; + in >> key; + in >> version; + in >> scriptPath; + in >> state; + in >> userRating; + states[ key ] = AtticaManager::Resolver( version, scriptPath, userRating, (AtticaManager::ResolverState)state ); + } + return in; +} + +TomahawkSettingsGui* +TomahawkSettingsGui::instanceGui() +{ + return qobject_cast< TomahawkSettingsGui* >(TomahawkSettings::instance()); +} + + +TomahawkSettingsGui::TomahawkSettingsGui( QObject* parent ) + : TomahawkSettings( parent ) +{ + qRegisterMetaType< AtticaManager::StateHash >( "AtticaManager::StateHash" ); + qRegisterMetaTypeStreamOperators("AtticaManager::StateHash"); +} + + +TomahawkSettingsGui::~TomahawkSettingsGui() +{ +} + + +QStringList +TomahawkSettingsGui::scannerPaths() const +{ + QString musicLocation; + + musicLocation = QDesktopServices::storageLocation( QDesktopServices::MusicLocation ); + + 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 new file mode 100644 index 000000000..bac2cddd4 --- /dev/null +++ b/src/libtomahawk/TomahawkSettingsGui.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 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 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 ); +}; + +Q_DECLARE_METATYPE(AtticaManager::StateHash); + + +#endif