# HG changeset patch # User Jeandet Alexis # Date 2015-06-11 18:41:49 # Node ID 9652b437323fc7fd1cab5b37ed077e276ac967ca # Parent 0dab228f7441476b8003169deb4123408a5dd52a Session manager almost complete. diff --git a/src/SocExplorerEngine/engine/socexplorersettings.cpp b/src/SocExplorerEngine/engine/socexplorersettings.cpp --- a/src/SocExplorerEngine/engine/socexplorersettings.cpp +++ b/src/SocExplorerEngine/engine/socexplorersettings.cpp @@ -197,6 +197,59 @@ bool SocExplorerSettings::loadSession(co return false; } +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); diff --git a/src/SocExplorerEngine/engine/socexplorersettings.h b/src/SocExplorerEngine/engine/socexplorersettings.h --- a/src/SocExplorerEngine/engine/socexplorersettings.h +++ b/src/SocExplorerEngine/engine/socexplorersettings.h @@ -56,6 +56,8 @@ public: //! \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 deleteSession(); + static bool deleteSession(const QString& session); signals: public slots: diff --git a/src/SocExplorerEngine/plugins/socexplorerplugin.h b/src/SocExplorerEngine/plugins/socexplorerplugin.h --- a/src/SocExplorerEngine/plugins/socexplorerplugin.h +++ b/src/SocExplorerEngine/plugins/socexplorerplugin.h @@ -85,6 +85,7 @@ public: //! Default plugin constructor, any plugin should call this constructor. socexplorerplugin(QWidget *parent = 0,bool createPyObject=true):QDockWidget(parent) { + Q_UNUSED(createPyObject) closeAction=NULL; menu=NULL; ChildsMenu=NULL; diff --git a/src/SocExplorerEngine/proxy/socexplorerproxy.cpp b/src/SocExplorerEngine/proxy/socexplorerproxy.cpp --- a/src/SocExplorerEngine/proxy/socexplorerproxy.cpp +++ b/src/SocExplorerEngine/proxy/socexplorerproxy.cpp @@ -32,6 +32,7 @@ QList* socexplorerpr socexplorerplugin* socexplorerproxy::root=NULL; socexplorerplugin* socexplorerproxy::parent=NULL; PluginsCache* socexplorerproxy::cache=NULL; +QStringList* socexplorerproxy::linearDriverPathList=NULL; socexplorerproxy::socexplorerproxy(QObject *parent) : QObject(parent) @@ -39,6 +40,7 @@ socexplorerproxy::socexplorerproxy(QObje cache = new PluginsCache; drivers = new QList; linearDriverList=new QList; + linearDriverPathList=new QStringList; root = NULL; } @@ -50,6 +52,7 @@ socexplorerproxy::socexplorerproxy(QMain cache = new PluginsCache; drivers = new QList; linearDriverList=new QList; + linearDriverPathList=new QStringList; root = NULL; } @@ -77,7 +80,7 @@ void socexplorerproxy::loadSysDriver(con { socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name); QString driverName = _self->getinstanceName(driver->baseName()); - loadSysDriver(driver,driverName); + loadSysDriver(driver,driverName,name); } } @@ -87,18 +90,22 @@ void socexplorerproxy::loadSysDriver(con if(pluginloader::libcanberoot(name) && !_self->instanceExists(instanceName)) { socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name); - loadSysDriver(driver,instanceName); + loadSysDriver(driver,instanceName,name); } } -void socexplorerproxy::loadSysDriver(socexplorerplugin *driver, const QString instanceName) +void socexplorerproxy::loadSysDriver(socexplorerplugin *driver, const QString instanceName, const QString path) { if(!_self)init(); driver->setInstanceName(instanceName); driver->parent = NULL; drivers->append(driver); linearDriverList->append(driver); + if(path.isEmpty()) + linearDriverPathList->append(driver->baseName()); + else + linearDriverPathList->append(path); connectChildToProxy(driver); emit _self->addPluginGUI(driver); emit _self->clearMenu(); @@ -117,7 +124,7 @@ void socexplorerproxy::loadChildSysDrive bool ok=true; if(ok) { - if(parent!=NULL)_self->loadSysDriverToParent(driver,parent,driverName); + if(parent!=NULL)_self->loadSysDriverToParent(driver,parent,driverName,child); } } } @@ -133,7 +140,7 @@ void socexplorerproxy::loadSysDriverToPa if(ok) { socexplorerplugin* parent=_self->getSysDriver(ParentInst); - if(parent!=NULL)loadSysDriverToParent(driver,parent,driverName); + if(parent!=NULL)loadSysDriverToParent(driver,parent,driverName,name); } } } @@ -149,15 +156,19 @@ void socexplorerproxy::loadSysDriverToPa if(ok) { socexplorerplugin* parent=_self->getSysDriver(ParentInst); - if(parent!=NULL)loadSysDriverToParent(driver,parent,instanceName); + if(parent!=NULL)loadSysDriverToParent(driver,parent,instanceName,name); } } } -void socexplorerproxy::loadSysDriverToParent(socexplorerplugin *driver,socexplorerplugin *parent, const QString instanceName) +void socexplorerproxy::loadSysDriverToParent(socexplorerplugin *driver,socexplorerplugin *parent, const QString instanceName,const QString path) { if(!_self)init(); linearDriverList->append(driver); + if(path.isEmpty()) + linearDriverPathList->append(driver->baseName()); + else + linearDriverPathList->append(path); driver->parent = parent; driver->setInstanceName(instanceName); parent->childs.append(driver); @@ -264,6 +275,57 @@ socexplorerplugin *socexplorerproxy::fin return NULL; } +QStringList socexplorerproxy::getPluginsList() +{ + if(!_self)init(); + QStringList result; + socexplorerplugin* plugin; + for(int i=0; icount();i++) + { + QString parent=""; + plugin=linearDriverList->at(i); + if(plugin->parent)parent=plugin->parent->instanceName(); + result.append(linearDriverList->at(i)->instanceName()+":"+parent+":"+linearDriverPathList->at(i)); + } + return result; +} + +bool socexplorerproxy::loadPluginsList(QStringList plugins) +{ + if(!_self)init(); + QString plugin; + int lastLoadedPlugins=-1; + QStringList loadedPlugins; + while(plugins.count() && lastLoadedPlugins!=loadedPlugins.count()) + { + lastLoadedPlugins=loadedPlugins.count(); + for (int i = 0; i < plugins.count(); i++) + { + plugin=plugins[i]; + QStringList args=plugin.split(':',QString::KeepEmptyParts); + if(args.count()==3) + { + if(args[1].isEmpty()) + { + _self->loadSysDriver(args[2],args[0]); + loadedPlugins.append(args[0]); + plugins.removeAt(i); + } + else if(loadedPlugins.contains(args[1])) + { + _self->loadSysDriverToParent(args[2],args[0],args[1]); + loadedPlugins.append(args[0]); + plugins.removeAt(i); + } + } + else + { + plugins.removeAt(i); + } + } + } +} + bool socexplorerproxy::instanceExists(const QString &instanceName) { return !socexplorerproxy::instanceNameIsValid(instanceName); @@ -312,6 +374,7 @@ void socexplorerproxy::closeSysDriver(so emit _self->removePluginGUI(driver); if(driver->parent==NULL)SocExplorerEngine::removeSOC(driver); while(driver->childs.count()!=0)closeSysDriver(driver->childs.first()); + linearDriverPathList->removeAt(linearDriverList->indexOf(driver)); linearDriverList->removeOne(driver); if(driver->parent!= NULL) { diff --git a/src/SocExplorerEngine/proxy/socexplorerproxy.h b/src/SocExplorerEngine/proxy/socexplorerproxy.h --- a/src/SocExplorerEngine/proxy/socexplorerproxy.h +++ b/src/SocExplorerEngine/proxy/socexplorerproxy.h @@ -54,6 +54,8 @@ public: static void disconnectChildToProxy(socexplorerplugin* child); static bool instanceNameIsValid(const QString& instanceName); static socexplorerplugin* findPlugin(const QString &instanceName); + static QStringList getPluginsList(); + static bool loadPluginsList( QStringList plugins); QT_ENSURE_STACK_ALIGNED_FOR_SSE static void loadChildSysDriver(socexplorerplugin* parent,const QString child); @@ -72,10 +74,10 @@ signals: public slots: QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriver(const QString name); QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriver(const QString name,const QString instanceName); - QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriver(socexplorerplugin* driver,const QString instanceName); + QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriver(socexplorerplugin* driver,const QString instanceName,const QString path=""); QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriverToParent(const QString name,const QString ParentInst); QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriverToParent(const QString name,const QString instanceName,const QString ParentInst); - QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriverToParent(socexplorerplugin *driver,socexplorerplugin *parent, const QString instanceName); + QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadSysDriverToParent(socexplorerplugin *driver,socexplorerplugin *parent, const QString instanceName,const QString path=""); QT_ENSURE_STACK_ALIGNED_FOR_SSE void changeSysDriverInstName(const QString instanceName); QT_ENSURE_STACK_ALIGNED_FOR_SSE void changeSysDriverInstName(const QString newinstanceName,const QString previnstanceName); // QT_ENSURE_STACK_ALIGNED_FOR_SSE void loadChild(socexplorerplugin* parent); @@ -95,6 +97,7 @@ private: static QMainWindow* mainWindow; static QList* drivers; static QList* linearDriverList; + static QStringList* linearDriverPathList; static socexplorerplugin* root; static socexplorerplugin* parent; static PluginsCache* cache; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -34,7 +34,6 @@ SocExplorerMainWindow::SocExplorerMainWi this->makeLayout(); this->makeMenu(); SocExplorerSettings::init(); - SocExplorerSettings::loadSession("Session1"); this->makeConnections(); this->setWindowIcon(QIcon(":/images/icon.png")); this->setAcceptDrops(true); @@ -54,6 +53,7 @@ void SocExplorerMainWindow::makeObjects( Q_UNUSED(ScriptToEval) this->p_pluginGUIlist = new QList(); pluginsDockContainer = new QMainWindow; + pluginsDockContainer->setObjectName("pluginsDockContainer"); pluginsDockContainer->setWindowFlags(Qt::Widget); pluginsDockContainer->setDockNestingEnabled(true); this->mainWidget = new QSplitter(Qt::Vertical); @@ -73,11 +73,13 @@ void SocExplorerMainWindow::makeObjects( SocExplorerEngine::xmlModel()->scanXmlFiles(); this->regExplorer = new RegsExplorer(); this->regExplorer->setAllowedAreas(Qt::AllDockWidgetAreas); + this->regExplorer->setObjectName("regExplorer"); this->addPluginInterface(this->regExplorer); this->PythonConsoleInst = new PythonConsole(socexplorerproxy::self()); this->PythonConsoleInst->addObject("SocExplorerEngine",SocExplorerEngine::self()); this->pluginManager = new dockablePluginManager(); this->toolpane = new toolBar; + this->toolpane->setObjectName("toolpane"); this->p_about = new aboutsocexplorer(); } @@ -112,7 +114,8 @@ void SocExplorerMainWindow::makeConnecti connect(this->about,SIGNAL(triggered()),this,SLOT(showAboutBox())); connect(this->exploreRegs,SIGNAL(triggered()),this->regExplorer,SLOT(show())); - connect(this->sessionManagerAction, SIGNAL(triggered(bool)),this->p_SessionManagerDialog,SLOT(show())); + connect(this->sessionManagerAction, SIGNAL(triggered(bool)),this,SLOT(showSessionManager(bool))); + connect(this->p_SessionManagerDialog, SIGNAL(switchSession(QString)),this,SLOT(setActiveSession(QString))); this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDrviver(QString)),socexplorerproxy::self(),SLOT(loadSysDriver(QString))); this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDriverToParent(QString,QString)),socexplorerproxy::self(),SLOT(loadSysDriverToParent(QString,QString))); @@ -122,12 +125,10 @@ void SocExplorerMainWindow::makeConnecti void SocExplorerMainWindow::launchPluginManager() { - if(this->pluginManager->isHidden()) { this->pluginManager->setHidden(false); } - } @@ -158,6 +159,7 @@ void SocExplorerMainWindow::makeMenu() { this->FileMenu = menuBar()->addMenu(tr("&File")); this->SessionsMenu = this->FileMenu->addMenu(tr("&Sessions")); + this->loadSessions(); this->sessionManagerAction = this->FileMenu->addAction(tr("&Session manager...")); this->SettingsMenu = menuBar()->addMenu(tr("&Settings")); SocExplorerGUI::registerMenuBar(menuBar(),this->FileMenu,this->SettingsMenu); @@ -177,13 +179,57 @@ void SocExplorerMainWindow::makeMenu() void SocExplorerMainWindow::loadSessions() { p_Sessions=this->p_SessionManagerDialog->getSessionsList(); + sessionsActions_t* sact; + QString stext; + foreach (sact, sessionsActions) + { + sessionsActions.removeAll(sact); + SessionsMenu->removeAction(sact); + disconnect(sact); + delete sact; + } + foreach (stext, p_Sessions) + { + sact = new sessionsActions_t(stext,this); + sact->setCheckable(true); + connect(sact,SIGNAL(triggered(QString)),this,SLOT(setActiveSession(QString))); + sessionsActions.append(sact); + SessionsMenu->addAction(sact); + } +} + +void SocExplorerMainWindow::savePlugins() +{ + +} + +void SocExplorerMainWindow::saveCurrentSession() +{ + if(p_currentSession.isEmpty()) + { + SocExplorerSettings::loadSession("default"); + } + SocExplorerSettings::setValue("GLOBAL","LastModified",QDate::currentDate().toString(),SocExplorerSettings::Session); + SocExplorerSettings::setValue(this,"DOCK_LOCATIONS",this->saveState(0),SocExplorerSettings::Session); + SocExplorerSettings::setValue(this,"MAIN_WINDOW_GEOMETRY",this->saveGeometry(),SocExplorerSettings::Session); + QStringList plugins = socexplorerproxy::getPluginsList(); + SocExplorerSettings::setValue(this,"LOADED_PLUGINS",QVariant(plugins),SocExplorerSettings::Session); + SocExplorerSettings::sync(); +} + +void SocExplorerMainWindow::loadCurrentSession() +{ + + QStringList plugins = SocExplorerSettings::value(this,"LOADED_PLUGINS",QVariant(),SocExplorerSettings::Session).toStringList(); + socexplorerproxy::loadPluginsList(plugins); + this->restoreGeometry(SocExplorerSettings::value(this,"MAIN_WINDOW_GEOMETRY",QVariant(),SocExplorerSettings::Session).toByteArray()); + this->restoreState(SocExplorerSettings::value(this,"DOCK_LOCATIONS",QVariant(),SocExplorerSettings::Session).toByteArray()); } SocExplorerMainWindow::~SocExplorerMainWindow() { - SocExplorerSettings::setValue("GLOBAL","LastModified",QDate::currentDate().toString(),SocExplorerSettings::Session); - SocExplorerSettings::sync(); + } @@ -242,10 +288,34 @@ void SocExplorerMainWindow::pluginselect drv->raise(); } +void SocExplorerMainWindow::setActiveSession(const QString &session) +{ + if(!(p_currentSession.isNull() && session=="default")) + saveCurrentSession(); + socexplorerproxy::self()->close(); + this->p_currentSession = session; + sessionsActions_t* sact; + SocExplorerSettings::loadSession(session); + loadCurrentSession(); + foreach (sact, sessionsActions) + { + if(sact->text().compare(session)) + sact->setChecked(false); + else + sact->setChecked(true); + } +} + +void SocExplorerMainWindow::showSessionManager(bool) +{ + this->p_SessionManagerDialog->show(); +} + void SocExplorerMainWindow::closeEvent(QCloseEvent *event) { + saveCurrentSession(); socexplorerproxy::self()->close(); qApp->closeAllWindows(); event->accept(); diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -40,15 +40,35 @@ #include "regsExplorer/regsexplorer.h" #include "socexplorergui.h" #include "sessionmanagerdialog.h" +class sessionsActions_t: public QAction +{ + Q_OBJECT +public: + sessionsActions_t(const QString &text, QObject* parent) + : QAction(text,parent) + { + connect(this,SIGNAL(triggered(bool)),this,SLOT(p_triggered(bool))); + } +signals: + void triggered(const QString & session); +private slots: + void p_triggered(bool checked = false) + { + Q_UNUSED(checked) + emit triggered(this->text()); + } +}; class SocExplorerMainWindow : public QMainWindow { Q_OBJECT + public: SocExplorerMainWindow(QString ScriptToEval,QWidget *parent = 0); ~SocExplorerMainWindow(); QAction* Quit,*LoadPlugin,*ManagePlugins,*help,*regsManager,*exploreRegs,*about,*translateAction,*sessionManagerAction; + QList sessionsActions; QActionGroup*langActionGrp; QMenu* FileMenu,*SettingsMenu,*PluginsMenu,*ToolsMenu,*langMenu,*helpMenu,*SessionsMenu; QTranslator* appTranslator; @@ -66,7 +86,8 @@ public slots: void setLangage(QAction* action); void showAboutBox(); void pluginselected(const QString& instanceName); - + void setActiveSession(const QString & session); + void showSessionManager(bool); signals: void translateSig(); void registerObject(QObject* object,const QString& instanceName); @@ -77,6 +98,9 @@ private: void makeConnections(); void makeMenu(); void loadSessions(); + void savePlugins(); + void saveCurrentSession(); + void loadCurrentSession(); QMainWindow* pluginsDockContainer; QSplitter* mainWidget; PythonConsole* PythonConsoleInst; @@ -85,6 +109,7 @@ private: aboutsocexplorer* p_about; QList* p_pluginGUIlist; QStringList p_Sessions; + QString p_currentSession; SessionManagerDialog* p_SessionManagerDialog; }; diff --git a/src/sessionmanagerdialog.cpp b/src/sessionmanagerdialog.cpp --- a/src/sessionmanagerdialog.cpp +++ b/src/sessionmanagerdialog.cpp @@ -33,6 +33,8 @@ SessionManagerDialog::SessionManagerDial 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() @@ -63,6 +65,7 @@ QStringList SessionManagerDialog::getSes void SessionManagerDialog::show() { QStringList sessions = getSessionsList(); + this->ui->listWidget->clear(); this->ui->listWidget->addItems(sessions); QDialog::show(); } @@ -73,7 +76,7 @@ void SessionManagerDialog::newSession() QString text; do { - text = QInputDialog::getText(this, tr("QInputDialog::getText()"), + text = QInputDialog::getText(this, tr("SocExplorer Session Manager"), tr("Session name:"), QLineEdit::Normal, "New Session", &ok); exists = sessionExists(text); @@ -83,7 +86,7 @@ void SessionManagerDialog::newSession() tr("The session ")+text+tr(" already exists."), QMessageBox::Ok); } - }while(ok && !text.isEmpty() && exists); + }while(ok && (text.isEmpty() || exists)); if (ok && !text.isEmpty()) { @@ -102,7 +105,28 @@ void SessionManagerDialog::newSession(QS void SessionManagerDialog::renameSession() { + bool ok=true; + int exists=0; + QListWidgetItem* item = this->ui->listWidget->currentItem(); + QString text= 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); + } } void SessionManagerDialog::deleteSession() @@ -113,21 +137,28 @@ void SessionManagerDialog::deleteSession if(item && item->text().compare("default")) { this->ui->listWidget->removeItemWidget(item); - //TODO delete session FILE! + SocExplorerSettings::deleteSession(item->text()); delete item; updateSessionList(); } } } -bool SessionManagerDialog::sessionExists(QString session) +void SessionManagerDialog::switchSession() { - bool diff=true; + 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++) { - diff &= (this->ui->listWidget->item(i)->text().compare(session)!=0); + exists += (this->ui->listWidget->item(i)->text().compare(session)==0); } - return !diff; + return exists; } void SessionManagerDialog::updateSessionList() diff --git a/src/sessionmanagerdialog.h b/src/sessionmanagerdialog.h --- a/src/sessionmanagerdialog.h +++ b/src/sessionmanagerdialog.h @@ -39,11 +39,15 @@ public: QStringList getSessionsList(); public slots: void show(); + void newSession(QString session); + int sessionExists(QString session); +private slots: void newSession(); - void newSession(QString session); void renameSession(); void deleteSession(); - bool sessionExists(QString session); + void switchSession(); +signals: + void switchSession(QString session); private: void updateSessionList(); diff --git a/src/sessionmanagerdialog.ui b/src/sessionmanagerdialog.ui --- a/src/sessionmanagerdialog.ui +++ b/src/sessionmanagerdialog.ui @@ -11,7 +11,7 @@ - Dialog + SocExplorer Session Manager