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,26 @@ bool SocExplorerSettings::loadSession(co 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(); 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,7 @@ 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 renameSession(const QString& session,const QString& newName); static bool deleteSession(); static bool deleteSession(const QString& session); signals: diff --git a/src/SocExplorerEngine/plugins/socexplorerplugin.cpp b/src/SocExplorerEngine/plugins/socexplorerplugin.cpp --- a/src/SocExplorerEngine/plugins/socexplorerplugin.cpp +++ b/src/SocExplorerEngine/plugins/socexplorerplugin.cpp @@ -108,6 +108,7 @@ void socexplorerplugin::setInstanceName( if(this->menu) this->menu->setTitle(this->_instanceName); this->setWindowTitle(newName); + this->setObjectName(newName); } bool socexplorerplugin::dumpMemory(unsigned int address, unsigned int count, QString file) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -56,6 +56,8 @@ void SocExplorerMainWindow::makeObjects( pluginsDockContainer->setObjectName("pluginsDockContainer"); pluginsDockContainer->setWindowFlags(Qt::Widget); pluginsDockContainer->setDockNestingEnabled(true); + this->sessionsActions = new QActionGroup(this); + this->sessionManagerAction =new QAction(tr("&Session manager"),this); this->mainWidget = new QSplitter(Qt::Vertical); this->appTranslator = new QTranslator; this->Quit = new QAction(tr("&Quit"),this); @@ -116,6 +118,7 @@ void SocExplorerMainWindow::makeConnecti connect(this->sessionManagerAction, SIGNAL(triggered(bool)),this,SLOT(showSessionManager(bool))); connect(this->p_SessionManagerDialog, SIGNAL(switchSession(QString)),this,SLOT(setActiveSession(QString))); + connect(this->sessionsActions,SIGNAL(triggered(QAction*)),this,SLOT(setActiveSession(QAction*))); 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))); @@ -160,7 +163,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->FileMenu->addAction(this->sessionManagerAction); this->SettingsMenu = menuBar()->addMenu(tr("&Settings")); SocExplorerGUI::registerMenuBar(menuBar(),this->FileMenu,this->SettingsMenu); this->PluginsMenu = menuBar()->addMenu(tr("&Plugins")); @@ -179,21 +182,23 @@ void SocExplorerMainWindow::makeMenu() void SocExplorerMainWindow::loadSessions() { p_Sessions=this->p_SessionManagerDialog->getSessionsList(); - sessionsActions_t* sact; + QAction* sact; QString stext; - foreach (sact, sessionsActions) + QList sessions=sessionsActions->actions(); + foreach (sact, sessions) { - sessionsActions.removeAll(sact); + sessionsActions->removeAction(sact); SessionsMenu->removeAction(sact); - disconnect(sact); delete sact; } foreach (stext, p_Sessions) { - sact = new sessionsActions_t(stext,this); + sact = new QAction(stext,this); sact->setCheckable(true); - connect(sact,SIGNAL(triggered(QString)),this,SLOT(setActiveSession(QString))); - sessionsActions.append(sact); + sact->setData(stext); + if(p_currentSession==stext) + sact->setChecked(true); + sessionsActions->addAction(sact); SessionsMenu->addAction(sact); } } @@ -211,6 +216,7 @@ void SocExplorerMainWindow::saveCurrentS } SocExplorerSettings::setValue("GLOBAL","LastModified",QDate::currentDate().toString(),SocExplorerSettings::Session); SocExplorerSettings::setValue(this,"DOCK_LOCATIONS",this->saveState(0),SocExplorerSettings::Session); + SocExplorerSettings::setValue(this,"PLUGINS_DOCK_LOCATIONS",this->pluginsDockContainer->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); @@ -224,6 +230,7 @@ void SocExplorerMainWindow::loadCurrentS 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()); + this->pluginsDockContainer->restoreState(SocExplorerSettings::value(this,"PLUGINS_DOCK_LOCATIONS",QVariant(),SocExplorerSettings::Session).toByteArray()); } @@ -294,16 +301,14 @@ void SocExplorerMainWindow::setActiveSes 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::setActiveSession(QAction *session) +{ + this->setActiveSession(session->text()); } void SocExplorerMainWindow::showSessionManager(bool) @@ -311,6 +316,12 @@ void SocExplorerMainWindow::showSessionM this->p_SessionManagerDialog->show(); } +//TODO handle rename +void SocExplorerMainWindow::sessionListChanged() +{ + +} + void SocExplorerMainWindow::closeEvent(QCloseEvent *event) diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -40,24 +40,6 @@ #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 { @@ -68,7 +50,7 @@ public: SocExplorerMainWindow(QString ScriptToEval,QWidget *parent = 0); ~SocExplorerMainWindow(); QAction* Quit,*LoadPlugin,*ManagePlugins,*help,*regsManager,*exploreRegs,*about,*translateAction,*sessionManagerAction; - QList sessionsActions; + QActionGroup*sessionsActions; QActionGroup*langActionGrp; QMenu* FileMenu,*SettingsMenu,*PluginsMenu,*ToolsMenu,*langMenu,*helpMenu,*SessionsMenu; QTranslator* appTranslator; @@ -87,7 +69,9 @@ public slots: void showAboutBox(); void pluginselected(const QString& instanceName); void setActiveSession(const QString & session); + void setActiveSession(QAction* session); void showSessionManager(bool); + void sessionListChanged(); signals: void translateSig(); void registerObject(QObject* object,const QString& instanceName); diff --git a/src/sessionmanagerdialog.cpp b/src/sessionmanagerdialog.cpp --- a/src/sessionmanagerdialog.cpp +++ b/src/sessionmanagerdialog.cpp @@ -109,6 +109,7 @@ void SessionManagerDialog::renameSession 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"), @@ -126,6 +127,9 @@ void SessionManagerDialog::renameSession if (ok && !text.isEmpty()) { item->setText(text); + SocExplorerSettings::renameSession(text,OldText); + updateSessionList(); + emit sessionListChanged(); } } diff --git a/src/sessionmanagerdialog.h b/src/sessionmanagerdialog.h --- a/src/sessionmanagerdialog.h +++ b/src/sessionmanagerdialog.h @@ -48,6 +48,7 @@ private slots: void switchSession(); signals: void switchSession(QString session); + void sessionListChanged(); private: void updateSessionList(); diff --git a/src/sessionmanagerdialog.ui b/src/sessionmanagerdialog.ui --- a/src/sessionmanagerdialog.ui +++ b/src/sessionmanagerdialog.ui @@ -2,6 +2,9 @@ SessionManagerDialog + + Qt::ApplicationModal + 0 @@ -13,6 +16,9 @@ SocExplorer Session Manager + + true +