##// END OF EJS Templates
New Plugin Manager and interface to remove all the previous crap!...
New Plugin Manager and interface to remove all the previous crap! Let's use Qt plugin API and make it much simpler.

File last commit:

r97:9f8fee223cb9 default
r118:de85e8465e67 tip 1.0
Show More
sessionmanagerdialog.cpp
181 lines | 5.8 KiB | text/x-c | CppLexer
/ src / sessionmanagerdialog.cpp
Jeandet Alexis
Working on session manager.
r93 /*------------------------------------------------------------------------------
-- 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
----------------------------------------------------------------------------*/
Jeandet Alexis
Working on session manager.
r92 #include "sessionmanagerdialog.h"
#include "ui_sessionmanagerdialog.h"
Jeandet Alexis
Working on session manager.
r93 #include <socexplorersettings.h>
#include <socexplorerconfigkeys.h>
#include <QInputDialog>
#include <QMessageBox>
Jeandet Alexis
Working on session manager.
r92
SessionManagerDialog::SessionManagerDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SessionManagerDialog)
{
ui->setupUi(this);
Jeandet Alexis
Working on session manager.
r93 connect(this->ui->NewQPB,SIGNAL(clicked(bool)),this,SLOT(newSession()));
connect(this->ui->DeleteQPB,SIGNAL(clicked(bool)),this,SLOT(deleteSession()));
Jeandet Alexis
Session manager almost complete.
r94 connect(this->ui->RenameQPB,SIGNAL(clicked(bool)),this,SLOT(renameSession()));
connect(this->ui->SwitchToQPB,SIGNAL(clicked(bool)),this,SLOT(switchSession()));
Jeandet Alexis
Working on session manager.
r92 }
SessionManagerDialog::~SessionManagerDialog()
{
delete ui;
}
Jeandet Alexis
Working on session manager.
r93
QStringList SessionManagerDialog::getSessionsList()
{
QStringList result;
QList<QList<QVariant> > sessions = SocExplorerSettings::arrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME);
for(int i=0;i<sessions.count();i++)
{
if(sessions.at(i).count()>=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();
Jeandet Alexis
Session manager almost complete.
r94 this->ui->listWidget->clear();
Jeandet Alexis
Working on session manager.
r93 this->ui->listWidget->addItems(sessions);
QDialog::show();
}
void SessionManagerDialog::newSession()
{
bool ok=true,exists=false;
QString text;
do
{
Jeandet Alexis
Session manager almost complete.
r94 text = QInputDialog::getText(this, tr("SocExplorer Session Manager"),
Jeandet Alexis
Working on session manager.
r93 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);
}
Jeandet Alexis
Session manager almost complete.
r94 }while(ok && (text.isEmpty() || exists));
Jeandet Alexis
Working on session manager.
r93
if (ok && !text.isEmpty())
{
this->newSession(text);
}
}
void SessionManagerDialog::newSession(QString session)
{
if (!session.isEmpty())
{
this->ui->listWidget->addItem(session);
updateSessionList();
Session manager ready for release.
r97 emit sessionAdded(session);
Jeandet Alexis
Working on session manager.
r93 }
}
void SessionManagerDialog::renameSession()
{
Jeandet Alexis
Session manager almost complete.
r94 bool ok=true;
int exists=0;
QListWidgetItem* item = this->ui->listWidget->currentItem();
QString text= item->text();
Jeandet Alexis
Sync
r95 QString OldText= item->text();
Jeandet Alexis
Session manager almost complete.
r94 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());
Jeandet Alexis
Working on session manager.
r93
Jeandet Alexis
Session manager almost complete.
r94 if (ok && !text.isEmpty())
{
item->setText(text);
Session manager ready for release.
r97 SocExplorerSettings::renameSession(OldText,text);
emit sessionRenamed(OldText,text);
Jeandet Alexis
Sync
r95 updateSessionList();
emit sessionListChanged();
Jeandet Alexis
Session manager almost complete.
r94 }
Jeandet Alexis
Working on session manager.
r93 }
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);
Jeandet Alexis
Session manager almost complete.
r94 SocExplorerSettings::deleteSession(item->text());
Session manager ready for release.
r97 emit sessionRemoved(item->text());
Jeandet Alexis
Working on session manager.
r93 delete item;
updateSessionList();
}
}
}
Jeandet Alexis
Session manager almost complete.
r94 void SessionManagerDialog::switchSession()
Jeandet Alexis
Working on session manager.
r93 {
Jeandet Alexis
Session manager almost complete.
r94 QListWidgetItem* item = this->ui->listWidget->currentItem();
if(item)
emit switchSession(item->text());
}
int SessionManagerDialog::sessionExists(QString session)
{
int exists=0;
Jeandet Alexis
Working on session manager.
r93 for(int i=0;i< this->ui->listWidget->count();i++)
{
Jeandet Alexis
Session manager almost complete.
r94 exists += (this->ui->listWidget->item(i)->text().compare(session)==0);
Jeandet Alexis
Working on session manager.
r93 }
Jeandet Alexis
Session manager almost complete.
r94 return exists;
Jeandet Alexis
Working on session manager.
r93 }
void SessionManagerDialog::updateSessionList()
{
QList<QList<QVariant> > sessions;
for(int i=0;i< this->ui->listWidget->count();i++)
{
QList<QVariant> sess;
sess.append(this->ui->listWidget->item(i)->text());
sessions.append(sess);
}
SocExplorerSettings::setArrays(SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_SCOPE,QStringList()<<SOCEXPLORERGLOBAL_SETTINGS_SESSIONS_NAME,sessions);
}