1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
//
// C++ Implementation: sessionmanagedialog
//
// Description:
//
//
// Author: Oleksandr Shneyder <oleksandr.shneyder@obviously-nice.de>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "x2goclientconfig.h"
#include "sessionmanagedialog.h"
#include "onmainwindow.h"
#include <QPushButton>
#include <QDir>
#include <QFrame>
#include <QBoxLayout>
#include <QListView>
#include <QStringListModel>
#include <QShortcut>
#include "sessionbutton.h"
SessionManageDialog::SessionManageDialog ( QWidget * parent,
bool onlyCreateIcon, Qt::WFlags f )
: QDialog ( parent, f )
{
QVBoxLayout* ml=new QVBoxLayout ( this );
QFrame *fr=new QFrame ( this );
QHBoxLayout* frLay=new QHBoxLayout ( fr );
QPushButton* ok=new QPushButton ( tr ( "E&xit" ),this );
QHBoxLayout* bLay=new QHBoxLayout();
sessions=new QListView ( fr );
frLay->addWidget ( sessions );
QPushButton* newSession=new QPushButton ( tr ( "&New session" ),fr );
editSession=new QPushButton ( tr ( "&Session preferences" ),fr );
removeSession=new QPushButton ( tr ( "&Delete session" ),fr );
#if (!defined Q_WS_HILDON) && (!defined Q_OS_DARWIN)
if ( !ONMainWindow::getPortable() )
createSessionIcon=new QPushButton (
tr ( "&Create session icon on desktop..." ),fr );
#endif
par= ( ONMainWindow* ) parent;
newSession->setIcon ( QIcon (
par->iconsPath ( "/16x16/new_file.png" ) ) );
editSession->setIcon ( QIcon (
par->iconsPath ( "/16x16/edit.png" ) ) );
#if (!defined Q_WS_HILDON) && (!defined Q_OS_DARWIN)
if ( !ONMainWindow::getPortable() )
createSessionIcon->setIcon (
QIcon ( par->iconsPath ( "/16x16/create_file.png" ) ) );
#endif
removeSession->setIcon (
QIcon ( par->iconsPath ( "/16x16/delete.png" ) ) );
QVBoxLayout* actLay=new QVBoxLayout();
actLay->addWidget ( newSession );
actLay->addWidget ( editSession );
actLay->addWidget ( removeSession );
#if (!defined Q_WS_HILDON) && (!defined Q_OS_DARWIN)
if ( !ONMainWindow::getPortable() )
actLay->addWidget ( createSessionIcon );
#endif
actLay->addStretch();
frLay->addLayout ( actLay );
if ( onlyCreateIcon )
{
newSession->hide();
editSession->hide();
removeSession->hide();
}
QShortcut* sc=new QShortcut (
QKeySequence ( tr ( "Delete","Delete" ) ),this );
connect ( ok,SIGNAL ( clicked() ),this,SLOT ( close() ) );
connect (
sc,SIGNAL ( activated() ),removeSession,SIGNAL ( clicked() ) );
connect (
removeSession,SIGNAL ( clicked() ),this,SLOT ( slot_delete() ) );
connect ( editSession,SIGNAL ( clicked() ),this,SLOT ( slot_edit() ) );
#if (!defined Q_WS_HILDON) && (!defined Q_OS_DARWIN)
if ( !ONMainWindow::getPortable() )
connect ( createSessionIcon,SIGNAL ( clicked() ),
this,SLOT ( slot_createSessionIcon() ) );
#endif
connect ( newSession,SIGNAL ( clicked() ),this,SLOT ( slotNew() ) );
bLay->setSpacing ( 5 );
bLay->addStretch();
bLay->addWidget ( ok );
ml->addWidget ( fr );
ml->addLayout ( bLay );
fr->setFrameStyle ( QFrame::StyledPanel | QFrame::Raised );
fr->setLineWidth ( 2 );
setSizeGripEnabled ( true );
setWindowIcon (
QIcon (
( ( ONMainWindow* ) parent )->iconsPath (
"/32x32/edit.png" ) ) );
setWindowTitle ( tr ( "Session management" ) );
loadSessions();
connect ( sessions,SIGNAL ( clicked ( const QModelIndex& ) ),
this,SLOT ( slot_activated ( const QModelIndex& ) ) );
connect ( sessions,SIGNAL ( doubleClicked ( const QModelIndex& ) ),
this,SLOT ( slot_dclicked ( const QModelIndex& ) ) );
}
SessionManageDialog::~SessionManageDialog()
{}
void SessionManageDialog::loadSessions()
{
QStringListModel *model= ( QStringListModel* ) sessions->model();
if ( !model )
model=new QStringListModel();
sessions->setModel ( model );
QStringList lst;
model->setStringList ( lst );
const QList<SessionButton*> *sess=par->getSessionsList();
for ( int i=0;i<sess->size();++i )
lst<<sess->at ( i )->name();
model->setStringList ( lst );
removeSession->setEnabled ( false );
editSession->setEnabled ( false );
#if (!defined Q_WS_HILDON) && (!defined Q_OS_DARWIN)
if ( !ONMainWindow::getPortable() )
createSessionIcon->setEnabled ( false );
#endif
sessions->setEditTriggers ( QAbstractItemView::NoEditTriggers );
}
void SessionManageDialog::slot_activated ( const QModelIndex& )
{
removeSession->setEnabled ( true );
editSession->setEnabled ( true );
#if (!defined Q_WS_HILDON) && (!defined Q_OS_DARWIN)
if ( !ONMainWindow::getPortable() )
createSessionIcon->setEnabled ( true );
#endif
}
void SessionManageDialog::slot_dclicked ( const QModelIndex& )
{
slot_edit();
}
void SessionManageDialog::slotNew()
{
par->slotNewSession();
loadSessions();
}
void SessionManageDialog::slot_edit()
{
int ind=sessions->currentIndex().row();
if ( ind<0 )
return;
par->slotEdit ( par->getSessionsList()->at ( ind ) );
loadSessions();
}
void SessionManageDialog::slot_createSessionIcon()
{
int ind=sessions->currentIndex().row();
if ( ind<0 )
return;
par->slotCreateDesktopIcon ( par->getSessionsList()->at ( ind ) );
}
void SessionManageDialog::slot_delete()
{
int ind=sessions->currentIndex().row();
if ( ind<0 )
return;
par->slotDeleteButton ( par->getSessionsList()->at ( ind ) );
loadSessions();
}
|