/*------------------------------------------------------------------------------ -- This file is a part of the QLop Software -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS -- -- This program 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 2 of the License, or -- (at your option) any later version. -- -- This program 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 this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -------------------------------------------------------------------------------*/ /*-- Author : Alexis Jeandet -- Mail : alexis.jeandet@member.fsf.org ----------------------------------------------------------------------------*/ #include "qlopsettings.h" #include #include #include QLopSettings* QLopSettings::_self=NULL; QDockWidget* QLopSettings::m_gui=NULL; QSettings* QLopSettings::m_settings=NULL; QLopSettingsDialog* QLopSettings::m_configDialog=NULL; #define INIT() \ if(Q_UNLIKELY(_self==NULL))\ {\ init();\ } QLopSettings::QLopSettings(bool noGUI,QObject *parent) : QLopService(parent) { m_serviceName="QLopSettings"; m_settings = new QSettings(); m_noGui=noGUI; m_configDialog = new QLopSettingsDialog(); QAction* trigerGUI = new QAction(tr("Settings"),this); connect(trigerGUI,SIGNAL(triggered()),this,SLOT(popConfigDialog())); QLopGUI::addSettingsAction(trigerGUI); } QLopSettings::~QLopSettings() { delete m_configDialog; delete m_settings; } QDockWidget *QLopSettings::getGUI() { if(!m_noGui && (m_gui==NULL)) { // m_gui=new QLopDataBaseViewer(); // m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); } return m_gui; } void QLopSettings::init(bool noGUI, QObject *parent) { _self=new QLopSettings(noGUI,parent); } const QString &QLopSettings::serviceName() { INIT(); return m_serviceName; } QLopSettings *QLopSettings::self() { INIT(); return _self; } void QLopSettings::popConfigDialog(QLopSettingsItem *selectedConfigEntry) { INIT(); m_configDialog->popConfigDialog(selectedConfigEntry); } void QLopSettings::popConfigDialog() { m_configDialog->popConfigDialog(NULL); } bool QLopSettings::registerConfigEntry(QLopSettingsItem *configEntry, QIcon icon, QString text) { INIT(); return m_configDialog->registerConfigEntry(configEntry, icon, text); } void QLopSettings::setValue(QLopService* service, const QString &key, const QVariant &value) { INIT(); m_settings->setValue(service->serviceName()+"/"+key,value); } QVariant QLopSettings::value(QLopService* service, const QString &key, const QVariant &defaultValue) { INIT(); return m_settings->value(service->serviceName()+"/"+key,defaultValue); }