File indexing completed on 2024-05-05 04:48:32
0001 /**************************************************************************************** 0002 * Copyright (c) 2013 Konrad Zemek <konrad.zemek@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "ImporterProvider.h" 0018 0019 #include "ImporterManager.h" 0020 #include "core/support/Debug.h" 0021 0022 #include <QRandomGenerator> 0023 0024 using namespace StatSyncing; 0025 0026 ImporterProvider::ImporterProvider( const QVariantMap &config, ImporterManager *manager ) 0027 : m_config( config ) 0028 , m_manager( manager ) 0029 { 0030 if( !m_config.contains( QStringLiteral("uid") ) ) 0031 m_config.insert( QStringLiteral("uid"), QRandomGenerator::global()->generate() ); 0032 0033 if( m_manager == nullptr ) 0034 warning() << __PRETTY_FUNCTION__ << "manager pointer is not set"; 0035 } 0036 0037 ImporterProvider::~ImporterProvider() 0038 { 0039 } 0040 0041 QString 0042 StatSyncing::ImporterProvider::id() const 0043 { 0044 return m_config.value( QStringLiteral("uid") ).toString(); 0045 } 0046 0047 QString 0048 ImporterProvider::description() const 0049 { 0050 return m_manager ? m_manager->description() : QString(); 0051 } 0052 0053 QIcon 0054 ImporterProvider::icon() const 0055 { 0056 return m_manager ? m_manager->icon() : QIcon(); 0057 } 0058 0059 QString 0060 ImporterProvider::prettyName() const 0061 { 0062 return m_config.value( QStringLiteral("name") ).toString(); 0063 } 0064 0065 bool 0066 ImporterProvider::isConfigurable() const 0067 { 0068 return true; 0069 } 0070 0071 ProviderConfigWidget* 0072 ImporterProvider::configWidget() 0073 { 0074 Q_ASSERT( m_manager ); 0075 return m_manager ? m_manager->configWidget( m_config ) : nullptr; 0076 } 0077 0078 void 0079 ImporterProvider::reconfigure( const QVariantMap &config ) 0080 { 0081 if( config.value( QStringLiteral("uid") ) == m_config.value( QStringLiteral("uid") ) ) 0082 Q_EMIT reconfigurationRequested( config ); 0083 else 0084 warning() << __PRETTY_FUNCTION__ << "reconfigure called with different provider" 0085 << "uid!"; 0086 } 0087 0088 Provider::Preference 0089 ImporterProvider::defaultPreference() 0090 { 0091 return NoByDefault; 0092 }