# HG changeset patch # User Alexis Jeandet # Date 2016-04-18 21:13:47 # Node ID c459540a6dbdcbb4e17f204685fce02c070ba971 # Parent 7598f3bdb8ba583e819d1b2a5c9254a8268645f9 # Parent 11a895cff789ec536c7cd9e33f0c194465880649 Pre-0.7 merged diff --git a/src/SocExplorerEngine/engine/socexplorerconfigkeys.h b/src/SocExplorerEngine/engine/socexplorerconfigkeys.h new file mode 100644 --- /dev/null +++ b/src/SocExplorerEngine/engine/socexplorerconfigkeys.h @@ -0,0 +1,34 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2012, 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@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ +#ifndef SOCEXPLORERCONFIGKEYS +#define SOCEXPLORERCONFIGKEYS + +#define SOCEXPLORERENGINE_SETTINGS_SCOPE "SocExplorerEngine" +#define SOCEXPLORERENGINE_SETTINGS_PLUGINS_LOOKUP_PATH "plugins-lookup-path" +#define SOCEXPLORERENGINE_SETTINGS_SOC_REGS_LOOKUP_PATH "soc-registers-lookup-path" + +#define SOCEXPLORERGLOBAL_SETTINGS_SCOPE "GLOBAL" +#define SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE "SESSIONS" +#define SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME "NAME" + +#endif // SOCEXPLORERCONFIGKEYS + diff --git a/src/SocExplorerEngine/engine/socexplorergui.cpp b/src/SocExplorerEngine/engine/socexplorergui.cpp new file mode 100644 --- /dev/null +++ b/src/SocExplorerEngine/engine/socexplorergui.cpp @@ -0,0 +1,93 @@ +#include "socexplorergui.h" + +SocExplorerGUI* SocExplorerGUI::_self=NULL; +QMenuBar* SocExplorerGUI::m_mainMenuBar=NULL; +QMenu* SocExplorerGUI::m_fileMenu=NULL; +QMenu* SocExplorerGUI::m_SettingsMenu=NULL; +QList* SocExplorerGUI::m_queuedSettingActions=NULL; +QList* SocExplorerGUI::m_queuedFileMenuActions=NULL; + +#define INIT() \ + if(Q_UNLIKELY(_self==NULL))\ + {\ + init();\ + } + +SocExplorerGUI::SocExplorerGUI(QObject *parent) : QObject(parent) +{ + m_queuedFileMenuActions = new QList(); + m_queuedSettingActions = new QList(); +} + +void SocExplorerGUI::init() +{ + _self=new SocExplorerGUI(); +} + +void SocExplorerGUI::registerMenuBar(QMenuBar *menuBar, QMenu *fileMenu, QMenu *SettingsMenu) +{ + INIT(); + m_mainMenuBar = menuBar; + if(m_mainMenuBar) + { + if(fileMenu==NULL) + m_fileMenu = m_mainMenuBar->addMenu(tr("File")); + else + m_fileMenu = fileMenu; + if(SettingsMenu==NULL) + m_SettingsMenu = m_mainMenuBar->addMenu(tr("Settings")); + else + m_SettingsMenu = SettingsMenu; + } + + QAction* action; + foreach (action, *m_queuedSettingActions) + { + m_SettingsMenu->addAction(action); + } + foreach (action, *m_queuedFileMenuActions) + { + m_fileMenu->addAction(action); + } +} + +QMenu *SocExplorerGUI::addMenu(const QString &title) +{ + INIT(); + if(m_mainMenuBar) + { + return m_mainMenuBar->addMenu(title); + } + return NULL; +} + +bool SocExplorerGUI::addFileAction(QAction *action) +{ + INIT(); + if(m_fileMenu) + { + m_fileMenu->addAction(action); + return true; + } + else + { + m_queuedFileMenuActions->append(action); + } + return false; +} + +bool SocExplorerGUI::addSettingsAction(QAction *action) +{ + INIT(); + if(m_SettingsMenu) + { + m_SettingsMenu->addAction(action); + return true; + } + else + { + m_queuedSettingActions->append(action); + } + return false; +} + diff --git a/src/SocExplorerEngine/engine/socexplorergui.h b/src/SocExplorerEngine/engine/socexplorergui.h new file mode 100644 --- /dev/null +++ b/src/SocExplorerEngine/engine/socexplorergui.h @@ -0,0 +1,32 @@ +#ifndef SOCEXPLORERGUI_H +#define SOCEXPLORERGUI_H + +#include +#include +#include +#include +#include + +class SocExplorerGUI : public QObject +{ + Q_OBJECT + static SocExplorerGUI* _self; + static QMenuBar* m_mainMenuBar; + static QMenu* m_fileMenu; + static QMenu* m_SettingsMenu; + static QList* m_queuedSettingActions; + static QList* m_queuedFileMenuActions; + SocExplorerGUI(QObject *parent = 0); + static void init(); +public: + static SocExplorerGUI* self(){ if(!_self){_self= new SocExplorerGUI;}return _self;} + static void registerMenuBar(QMenuBar* menuBar, QMenu* fileMenu=NULL, QMenu* SettingsMenu=NULL); + static QMenu* addMenu(const QString & title); + static bool addFileAction(QAction * action); + static bool addSettingsAction(QAction * action); +signals: + +public slots: +}; + +#endif // SOCEXPLORERGUI_H diff --git a/src/SocExplorerEngine/engine/socexplorersettings.cpp b/src/SocExplorerEngine/engine/socexplorersettings.cpp new file mode 100644 --- /dev/null +++ b/src/SocExplorerEngine/engine/socexplorersettings.cpp @@ -0,0 +1,321 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer 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@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ +#include "socexplorersettings.h" + +SocExplorerSettings* SocExplorerSettings::_self=NULL; +QSettings* SocExplorerSettings::m_settings=NULL; +QSettings* SocExplorerSettings::m_sessionSettings=NULL; +SocExplorerSettingsDialog* SocExplorerSettings::m_configDialog = NULL; +#include +#include +#include +#include +#include + +#define INIT() \ + if(Q_UNLIKELY(_self==NULL))\ +{\ + init();\ + } + + +SocExplorerSettings::SocExplorerSettings(QObject *parent) : QObject(parent) +{ + m_settings = new QSettings(); + m_configDialog = new SocExplorerSettingsDialog(); + QAction* trigerGUI = new QAction(tr("Settings"),this); + connect(trigerGUI,SIGNAL(triggered()),this,SLOT(popConfigDialog())); + SocExplorerGUI::addSettingsAction(trigerGUI); +} + +SocExplorerSettings::~SocExplorerSettings() +{ + if(m_settings) + { + m_settings->sync(); + delete m_settings; + } + if(m_sessionSettings) + { + m_sessionSettings->sync(); + delete m_sessionSettings; + } +} + +void SocExplorerSettings::init() +{ + if(!_self) + { + _self= new SocExplorerSettings(); + } +} + +void SocExplorerSettings::setValue(QObject *object, const QString &key, const QVariant &value, SettingScope Sscope) +{ + INIT(); + setValue(object->metaObject()->className(),key,value,Sscope); +} + +QVariant SocExplorerSettings::value(QObject *object, const QString &key, const QVariant &defaultValue, SettingScope Sscope) +{ + INIT(); + return value(object->metaObject()->className(),key,defaultValue,Sscope); +} + +void SocExplorerSettings::setValue(const QString scope, const QString &key, const QVariant &value, SettingScope Sscope) +{ + INIT(); + switch (Sscope) + { + case SystemWide: + if(m_settings) + m_settings->setValue(scope+"/"+key,value); + break; + case Session: + if(m_sessionSettings) + m_sessionSettings->setValue(scope+"/"+key,value); + break; + default: + break; + } +} + +QVariant SocExplorerSettings::value(const QString scope, const QString &key, const QVariant &defaultValue, SettingScope Sscope) +{ + INIT(); + switch (Sscope) + { + case SystemWide: + if(m_settings) + return m_settings->value(scope+"/"+key,defaultValue); + break; + case Session: + if(m_sessionSettings) + return m_sessionSettings->value(scope+"/"+key,defaultValue); + break; + default: + break; + } + return defaultValue; +} + +QList > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, SocExplorerSettings::SettingScope Sscope) +{ + INIT(); + QList > defaultValue; + switch (Sscope) + { + case SystemWide: + if(m_settings) + return arrays(prefix,keys,m_settings); + break; + case Session: + if(m_sessionSettings) + return arrays(prefix,keys,m_sessionSettings); + break; + default: + break; + } + return defaultValue; +} + +void SocExplorerSettings::setArrays(const QString &prefix, QStringList keys, QList > values, SocExplorerSettings::SettingScope Sscope) +{ + INIT(); + switch (Sscope) + { + case SystemWide: + if(m_settings) + return setArrays(prefix,keys,values,m_settings); + break; + case Session: + if(m_sessionSettings) + return setArrays(prefix,keys,values,m_sessionSettings); + break; + default: + break; + } + +} + +void SocExplorerSettings::sync() +{ + INIT(); + if(m_settings) + { + m_settings->sync(); + } + if(m_sessionSettings) + { + m_sessionSettings->sync(); + } +} + +bool SocExplorerSettings::registerConfigEntry(SocExplorerSettingsItem *configEntry, QIcon icon, QString text) +{ + INIT(); + return m_configDialog->registerConfigEntry(configEntry,icon,text); +} + +bool SocExplorerSettings::loadSession(const QString &session) +{ + INIT(); + QFileInfo sessionInfo(m_settings->fileName()); + QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf"; + if(m_sessionSettings) + { + delete m_sessionSettings; + m_sessionSettings = NULL; + } + m_sessionSettings = new QSettings(fullpath,QSettings::NativeFormat,self()); + qDebug()<< m_sessionSettings->fileName(); + if(m_sessionSettings->status()==QSettings::NoError) + { + return true; + } + delete m_sessionSettings; + m_sessionSettings = NULL; + return false; +} + +bool SocExplorerSettings::renameSession(const QString &session, const QString &newName) +{ + INIT(); + sync(); + QFileInfo sessionInfo(m_settings->fileName()); + QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf"; + QString newFullpath=sessionInfo.absoluteDir().absolutePath() +"/"+newName+".conf"; + if(m_sessionSettings && m_sessionSettings->fileName()==fullpath) + { + delete m_sessionSettings; + QFile::rename(fullpath,newFullpath); + m_sessionSettings = new QSettings(newFullpath,QSettings::NativeFormat,self()); + } + else + { + QFile::rename(fullpath,newFullpath); + } + return true; +} + +bool SocExplorerSettings::deleteSession() +{ + INIT(); + if(m_sessionSettings) + { + m_sessionSettings->clear(); + QString filename= m_sessionSettings->fileName(); + if(QFile::exists(filename)) + { + delete m_sessionSettings; + QFile::remove(filename); + } + else + delete m_sessionSettings; + m_sessionSettings = NULL; + return true; + } + return false; +} + +bool SocExplorerSettings::deleteSession(const QString &session) +{ + QFileInfo sessionInfo(m_settings->fileName()); + QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf"; + if(m_sessionSettings) + { + if(m_sessionSettings->fileName()==fullpath) + { + deleteSession(); + return true; + } + } + QSettings* sessionSettings = new QSettings(fullpath,QSettings::NativeFormat,self()); + if(sessionSettings) + { + if(sessionSettings->status()==QSettings::NoError) + { + sessionSettings->clear(); + QString filename= m_sessionSettings->fileName(); + if(QFile::exists(filename)) + { + delete sessionSettings; + QFile::remove(filename); + } + else + delete sessionSettings; + return true; + } + delete sessionSettings; + } + return false; +} + +void SocExplorerSettings::popConfigDialog() +{ + m_configDialog->popConfigDialog(NULL); +} + +QList > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, QSettings *settings) +{ + QList > result; + if(settings) + { + int size = settings->beginReadArray(prefix); + for (int i = 0; i < size; ++i) + { + result.append(QList()); + settings->setArrayIndex(i); + for(int l=0;lvalue(keys.at(l))); + } + } + settings->endArray(); + } + return result; +} + +void SocExplorerSettings::setArrays(const QString &prefix, QStringList keys, QList > values, QSettings *settings) +{ + if(settings) + { + QString key; + foreach (key, keys) + { + + settings->remove(prefix+"/"+key); + } + settings->beginWriteArray(prefix); + for (int i = 0; i < values.size(); ++i) + { + settings->setArrayIndex(i); + for(int l=0;lsetValue(keys[l], values.at(i).at(l)); + } + } + settings->endArray(); + + } +} + diff --git a/src/SocExplorerEngine/engine/socexplorersettings.h b/src/SocExplorerEngine/engine/socexplorersettings.h new file mode 100644 --- /dev/null +++ b/src/SocExplorerEngine/engine/socexplorersettings.h @@ -0,0 +1,71 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2012, 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@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ +#ifndef SOCEXPLORERSETTINGS_H +#define SOCEXPLORERSETTINGS_H + +#include +#include +#include +#include + +class SocExplorerSettings : public QObject +{ + Q_OBJECT +private: + static SocExplorerSettings* _self; + static QSettings* m_settings; + static QSettings* m_sessionSettings; + static SocExplorerSettingsDialog* m_configDialog; + SocExplorerSettings(QObject *parent = 0); + ~SocExplorerSettings(); +public: + enum SettingScope { + SystemWide = 0, + Session + }; + static void init(); + static SocExplorerSettings* self(){ if(!_self){_self= new SocExplorerSettings;}return _self;} + static void setValue(QObject* object,const QString & key, const QVariant & value,SettingScope Sscope =SystemWide); + static QVariant value(QObject* object, const QString & key, const QVariant & defaultValue = QVariant(),SettingScope Sscope=SystemWide); + static void setValue(const QString scope,const QString & key, const QVariant & value,SettingScope Sscope= SystemWide); + static QVariant value(const QString scope, const QString & key, const QVariant & defaultValue = QVariant(),SettingScope Sscope =SystemWide); + static QList > arrays(const QString & prefix, QStringList keys,SettingScope Sscope =SystemWide); + static void setArrays(const QString & prefix, QStringList keys,QList > values,SettingScope Sscope =SystemWide); + static void sync(); + static bool registerConfigEntry(SocExplorerSettingsItem* configEntry,QIcon icon, QString text); + //! Loads the given session, or sreate it if doesn't exists. + //! \param session Session name. + //! \return true if success or false if fails to create session config file. + static bool loadSession(const QString& session); + static bool renameSession(const QString& session,const QString& newName); + static bool deleteSession(); + static bool deleteSession(const QString& session); +signals: + +public slots: + void popConfigDialog(); +private: + static QList > arrays(const QString & prefix, QStringList keys,QSettings* settings); + static void setArrays(const QString & prefix, QStringList keys,QList > values,QSettings* settings); +}; + +#endif // SOCEXPLORERSETTINGS_H diff --git a/src/SocExplorerEngine/engine/socexplorersettingsdialog.cpp b/src/SocExplorerEngine/engine/socexplorersettingsdialog.cpp new file mode 100644 --- /dev/null +++ b/src/SocExplorerEngine/engine/socexplorersettingsdialog.cpp @@ -0,0 +1,69 @@ +#include "socexplorersettingsdialog.h" +#include "ui_socexplorersettingsdialog.h" + +SocExplorerSettingsDialog::SocExplorerSettingsDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SocExplorerSettingsDialog) +{ + ui->setupUi(this); + connect(ui->contentsWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),this, SLOT(changePage(QListWidgetItem*,QListWidgetItem*))); + ui->contentsWidget->setViewMode(QListView::IconMode); + ui->contentsWidget->setIconSize(QSize(96, 84)); + ui->contentsWidget->setMovement(QListView::Static); + ui->contentsWidget->setSpacing(12); +} + +SocExplorerSettingsDialog::~SocExplorerSettingsDialog() +{ + delete ui; +} + +void SocExplorerSettingsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous) +{ + if (!current) + current = previous; + ui->pagesWidget->setCurrentIndex(ui->contentsWidget->row(current)); +} + +bool SocExplorerSettingsDialog::registerConfigEntry(SocExplorerSettingsItem *configEntry, QIcon icon, QString text) +{ + if(configEntry!=NULL) + { + ui->pagesWidget->addWidget(configEntry); + QListWidgetItem *configButton = new QListWidgetItem(ui->contentsWidget); + configButton->setIcon(icon); + configButton->setText(text); + configButton->setTextAlignment(Qt::AlignHCenter); + configButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + connect(this,SIGNAL(accepted()),configEntry,SLOT(accept())); + return true; + } + return false; +} + +void SocExplorerSettingsDialog::popConfigDialog(SocExplorerSettingsItem *selectedConfigEntry) +{ + if(selectedConfigEntry!=NULL) + { + for(int i=0;ipagesWidget->count();i++) + { + if(ui->pagesWidget->widget(i)==selectedConfigEntry) + { + ui->pagesWidget->setCurrentIndex(i); + } + } + } + this->show(); +} + +void SocExplorerSettingsDialog::changeEvent(QEvent *e) +{ + QDialog::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} diff --git a/src/SocExplorerEngine/engine/socexplorersettingsdialog.h b/src/SocExplorerEngine/engine/socexplorersettingsdialog.h new file mode 100644 --- /dev/null +++ b/src/SocExplorerEngine/engine/socexplorersettingsdialog.h @@ -0,0 +1,41 @@ +#ifndef SOCEXPLORERSETTINGSDIALOG_H +#define SOCEXPLORERSETTINGSDIALOG_H + +#include + +namespace Ui { +class SocExplorerSettingsDialog; +} +#include + +class SocExplorerSettingsItem : public QWidget +{ + Q_OBJECT +public: + SocExplorerSettingsItem(QWidget *parent = 0):QWidget(parent) {} + ~SocExplorerSettingsItem() {} +public slots: + virtual void accept()=0; +}; + +class SocExplorerSettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SocExplorerSettingsDialog(QWidget *parent = 0); + ~SocExplorerSettingsDialog(); + +public slots: + void changePage(QListWidgetItem *current, QListWidgetItem *previous); + bool registerConfigEntry(SocExplorerSettingsItem* configEntry, QIcon icon, QString text); + void popConfigDialog(SocExplorerSettingsItem* selectedConfigEntry=0); + +protected: + void changeEvent(QEvent *e); + +private: + Ui::SocExplorerSettingsDialog *ui; +}; + +#endif // SOCEXPLORERSETTINGSDIALOG_H diff --git a/src/SocExplorerEngine/engine/socexplorersettingsdialog.ui b/src/SocExplorerEngine/engine/socexplorersettingsdialog.ui new file mode 100644 --- /dev/null +++ b/src/SocExplorerEngine/engine/socexplorersettingsdialog.ui @@ -0,0 +1,102 @@ + + + SocExplorerSettingsDialog + + + + 0 + 0 + 555 + 329 + + + + Dialog + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 16777215 + 16777215 + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + SocExplorerSettingsDialog + accept() + + + 277 + 304 + + + 277 + 164 + + + + + buttonBox + rejected() + SocExplorerSettingsDialog + reject() + + + 277 + 304 + + + 277 + 164 + + + + + diff --git a/src/sessionmanagerdialog.cpp b/src/sessionmanagerdialog.cpp new file mode 100644 --- /dev/null +++ b/src/sessionmanagerdialog.cpp @@ -0,0 +1,181 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer 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@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ +#include "sessionmanagerdialog.h" +#include "ui_sessionmanagerdialog.h" +#include +#include +#include +#include + +SessionManagerDialog::SessionManagerDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SessionManagerDialog) +{ + ui->setupUi(this); + connect(this->ui->NewQPB,SIGNAL(clicked(bool)),this,SLOT(newSession())); + connect(this->ui->DeleteQPB,SIGNAL(clicked(bool)),this,SLOT(deleteSession())); + connect(this->ui->RenameQPB,SIGNAL(clicked(bool)),this,SLOT(renameSession())); + connect(this->ui->SwitchToQPB,SIGNAL(clicked(bool)),this,SLOT(switchSession())); +} + +SessionManagerDialog::~SessionManagerDialog() +{ + delete ui; +} + + +QStringList SessionManagerDialog::getSessionsList() +{ + QStringList result; + QList > sessions = SocExplorerSettings::arrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<=1) + { + result.append(sessions.at(i).at(0).toString()); + } + } + // May always return at least default session + if(result.count()==0) + { + result.append("default"); + } + return result; +} + +void SessionManagerDialog::show() +{ + QStringList sessions = getSessionsList(); + this->ui->listWidget->clear(); + this->ui->listWidget->addItems(sessions); + QDialog::show(); +} + +void SessionManagerDialog::newSession() +{ + bool ok=true,exists=false; + QString text; + do + { + text = QInputDialog::getText(this, tr("SocExplorer Session Manager"), + tr("Session name:"), QLineEdit::Normal, + "New Session", &ok); + exists = sessionExists(text); + if(exists && ok) + { + QMessageBox::warning(this, tr("SocExplorer Session Manager"), + tr("The session ")+text+tr(" already exists."), + QMessageBox::Ok); + } + }while(ok && (text.isEmpty() || exists)); + + if (ok && !text.isEmpty()) + { + this->newSession(text); + } +} + +void SessionManagerDialog::newSession(QString session) +{ + if (!session.isEmpty()) + { + this->ui->listWidget->addItem(session); + updateSessionList(); + emit sessionAdded(session); + } +} + +void SessionManagerDialog::renameSession() +{ + bool ok=true; + int exists=0; + QListWidgetItem* item = this->ui->listWidget->currentItem(); + QString text= item->text(); + QString OldText= item->text(); + do + { + text = QInputDialog::getText(this, tr("SocExplorer Session Manager"), + tr("New session name:"), QLineEdit::Normal, + text, &ok); + exists = sessionExists(text); + if(exists&& ok) + { + QMessageBox::warning(this, tr("SocExplorer Session Manager"), + tr("The session ")+text+tr(" already exists."), + QMessageBox::Ok); + } + }while(ok && text.isEmpty()); + + if (ok && !text.isEmpty()) + { + item->setText(text); + SocExplorerSettings::renameSession(OldText,text); + emit sessionRenamed(OldText,text); + updateSessionList(); + emit sessionListChanged(); + } +} + +void SessionManagerDialog::deleteSession() +{ + if(this->ui->listWidget->selectedItems().count()) + { + QListWidgetItem* item = this->ui->listWidget->currentItem(); + if(item && item->text().compare("default")) + { + this->ui->listWidget->removeItemWidget(item); + SocExplorerSettings::deleteSession(item->text()); + emit sessionRemoved(item->text()); + delete item; + updateSessionList(); + } + } +} + +void SessionManagerDialog::switchSession() +{ + QListWidgetItem* item = this->ui->listWidget->currentItem(); + if(item) + emit switchSession(item->text()); +} + +int SessionManagerDialog::sessionExists(QString session) +{ + int exists=0; + for(int i=0;i< this->ui->listWidget->count();i++) + { + exists += (this->ui->listWidget->item(i)->text().compare(session)==0); + } + return exists; +} + +void SessionManagerDialog::updateSessionList() +{ + QList > sessions; + for(int i=0;i< this->ui->listWidget->count();i++) + { + QList sess; + sess.append(this->ui->listWidget->item(i)->text()); + sessions.append(sess); + } + SocExplorerSettings::setArrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()< + +namespace Ui { +class SessionManagerDialog; +} + +class SessionManagerDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SessionManagerDialog(QWidget *parent = 0); + ~SessionManagerDialog(); + + QStringList getSessionsList(); +public slots: + void show(); + void newSession(QString session); + int sessionExists(QString session); +private slots: + void newSession(); + void renameSession(); + void deleteSession(); + void switchSession(); +signals: + void switchSession(QString session); + void sessionListChanged(); + void sessionRenamed(const QString& oldName,const QString& newName); + void sessionRemoved(const QString& session); + void sessionAdded(const QString& newSession); +private: + void updateSessionList(); + Ui::SessionManagerDialog *ui; +}; + +#endif // SESSIONMANAGERDIALOG_H diff --git a/src/sessionmanagerdialog.ui b/src/sessionmanagerdialog.ui new file mode 100644 --- /dev/null +++ b/src/sessionmanagerdialog.ui @@ -0,0 +1,127 @@ + + + SessionManagerDialog + + + Qt::ApplicationModal + + + + 0 + 0 + 553 + 275 + + + + SocExplorer Session Manager + + + true + + + + + + + + + + + + New + + + + + + + Rename + + + + + + + Clone + + + + + + + Delete + + + + + + + Switch to + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + buttonBox + accepted() + SessionManagerDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SessionManagerDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/socexplorercoresettingsgui.cpp b/src/socexplorercoresettingsgui.cpp new file mode 100644 --- /dev/null +++ b/src/socexplorercoresettingsgui.cpp @@ -0,0 +1,37 @@ +#include "socexplorercoresettingsgui.h" +#include "ui_socexplorercoresettingsgui.h" +#include +#include +#include + +SocExplorerCoreSettingsGUI::SocExplorerCoreSettingsGUI(QWidget *parent) : + SocExplorerSettingsItem(parent), + ui(new Ui::SocExplorerCoreSettingsGUI) +{ + ui->setupUi(this); + this->ui->PluginsLookupPath->setText(SocExplorerSettings::value(SOCEXPLORERENGINE_SETTINGS_SCOPE,SOCEXPLORERENGINE_SETTINGS_PLUGINS_LOOKUP_PATH,"").toString()); + this->ui->SOCregsLookupPath->setText(SocExplorerSettings::value(SOCEXPLORERENGINE_SETTINGS_SCOPE,SOCEXPLORERENGINE_SETTINGS_SOC_REGS_LOOKUP_PATH,"").toString()); +} + +SocExplorerCoreSettingsGUI::~SocExplorerCoreSettingsGUI() +{ + delete ui; +} + +void SocExplorerCoreSettingsGUI::changeEvent(QEvent *e) +{ + QWidget::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +void SocExplorerCoreSettingsGUI::accept() +{ + SocExplorerSettings::setValue(SOCEXPLORERENGINE_SETTINGS_SCOPE,SOCEXPLORERENGINE_SETTINGS_PLUGINS_LOOKUP_PATH,this->ui->PluginsLookupPath->text()); + SocExplorerSettings::setValue(SOCEXPLORERENGINE_SETTINGS_SCOPE,SOCEXPLORERENGINE_SETTINGS_SOC_REGS_LOOKUP_PATH,this->ui->SOCregsLookupPath->text()); +} diff --git a/src/socexplorercoresettingsgui.h b/src/socexplorercoresettingsgui.h new file mode 100644 --- /dev/null +++ b/src/socexplorercoresettingsgui.h @@ -0,0 +1,27 @@ +#ifndef SOCEXPLORERCORESETTINGSGUI_H +#define SOCEXPLORERCORESETTINGSGUI_H + +#include +#include + +namespace Ui { +class SocExplorerCoreSettingsGUI; +} + +class SocExplorerCoreSettingsGUI : public SocExplorerSettingsItem +{ + Q_OBJECT + +public: + explicit SocExplorerCoreSettingsGUI(QWidget *parent = 0); + ~SocExplorerCoreSettingsGUI(); + +protected: + void changeEvent(QEvent *e); +public slots: + void accept(); +private: + Ui::SocExplorerCoreSettingsGUI *ui; +}; + +#endif // SOCEXPLORERCORESETTINGSGUI_H diff --git a/src/socexplorercoresettingsgui.ui b/src/socexplorercoresettingsgui.ui new file mode 100644 --- /dev/null +++ b/src/socexplorercoresettingsgui.ui @@ -0,0 +1,80 @@ + + + SocExplorerCoreSettingsGUI + + + + 0 + 0 + 573 + 274 + + + + Form + + + + + + Plugins + + + + + + Lookup path + + + + + + + <html><head/><body><p><span style=" font-weight:600;">Semicolon </span>separated list of path.</p></body></html> + + + + + + + + + + SOC registers description + + + + + + Lookup path + + + + + + + <html><head/><body><p><span style=" font-weight:600;">Semicolon </span>separated list of path.</p></body></html> + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/unixcfg/socexplorer.desktop b/unixcfg/socexplorer.desktop --- a/unixcfg/socexplorer.desktop +++ b/unixcfg/socexplorer.desktop @@ -12,6 +12,6 @@ Exec=socexplorer %U Icon=/usr/share/SocExplorer/icon.png Terminal=false -Categories=Electronics;Engineering; +Categories=Development;Engineering; MimeType=text/x-python;