1/* 2 * This file Copyright (C) Mnemosyne LLC 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License version 2 6 * as published by the Free Software Foundation. 7 * 8 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 9 * 10 * $Id: session-dialog.cc 11092 2010-08-01 20:36:13Z charles $ 11 */ 12 13#include <QCheckBox> 14#include <QDialogButtonBox> 15#include <QLabel> 16#include <QLineEdit> 17#include <QRadioButton> 18#include <QSpinBox> 19#include <QVBoxLayout> 20 21#include "hig.h" 22#include "prefs.h" 23#include "session.h" 24#include "session-dialog.h" 25 26/*** 27**** 28***/ 29 30void 31SessionDialog :: onAccepted( ) 32{ 33 myPrefs.set( Prefs::SESSION_IS_REMOTE, myRemoteRadioButton->isChecked( ) ); 34 myPrefs.set( Prefs::SESSION_REMOTE_HOST, myHostLineEdit->text( ) ); 35 myPrefs.set( Prefs::SESSION_REMOTE_PORT, myPortSpinBox->value( ) ); 36 myPrefs.set( Prefs::SESSION_REMOTE_AUTH, myAuthCheckBox->isChecked( ) ); 37 myPrefs.set( Prefs::SESSION_REMOTE_USERNAME, myUsernameLineEdit->text( ) ); 38 myPrefs.set( Prefs::SESSION_REMOTE_PASSWORD, myPasswordLineEdit->text( ) ); 39 mySession.restart( ); 40 hide( ); 41} 42 43void 44SessionDialog :: resensitize( ) 45{ 46 const bool isRemote = myRemoteRadioButton->isChecked(); 47 const bool useAuth = myAuthCheckBox->isChecked(); 48 49 foreach( QWidget * w, myRemoteWidgets ) 50 w->setEnabled( isRemote ); 51 52 foreach( QWidget * w, myAuthWidgets ) 53 w->setEnabled( isRemote && useAuth ); 54} 55 56/*** 57**** 58***/ 59 60SessionDialog :: SessionDialog( Session& session, Prefs& prefs, QWidget * parent ): 61 QDialog( parent ), 62 mySession( session ), 63 myPrefs( prefs ) 64{ 65 QWidget * l; 66 QSpinBox * sb; 67 QCheckBox * cb; 68 QLineEdit * le; 69 QRadioButton * rb; 70 71 setWindowTitle( tr( "Change Session" ) ); 72 QVBoxLayout * top = new QVBoxLayout( this ); 73 top->setSpacing( HIG :: PAD ); 74 75 HIG * hig = new HIG; 76 hig->setContentsMargins( 0, 0, 0, 0 ); 77 hig->addSectionTitle( tr( "Source" ) ); 78 rb = new QRadioButton( tr( "Start &Local Session" ) ); 79 rb->setChecked( !prefs.get<bool>(Prefs::SESSION_IS_REMOTE) ); 80 connect( rb, SIGNAL(toggled(bool)), this, SLOT(resensitize())); 81 hig->addWideControl( rb ); 82 rb = myRemoteRadioButton = new QRadioButton( tr( "Connect to &Remote Session" ) ); 83 rb->setChecked( prefs.get<bool>(Prefs::SESSION_IS_REMOTE) ); 84 connect( rb, SIGNAL(toggled(bool)), this, SLOT(resensitize())); 85 hig->addWideControl( rb ); 86 le = myHostLineEdit = new QLineEdit( ); 87 le->setText( prefs.get<QString>(Prefs::SESSION_REMOTE_HOST) ); 88 l = hig->addRow( tr( "&Host:" ), le ); 89 myRemoteWidgets << l << le; 90 sb = myPortSpinBox = new QSpinBox; 91 sb->setRange( 1, 65535 ); 92 sb->setValue( prefs.get<int>(Prefs::SESSION_REMOTE_PORT) ); 93 l = hig->addRow( tr( "&Port:" ), sb ); 94 myRemoteWidgets << l << sb; 95 cb = myAuthCheckBox = new QCheckBox( tr( "&Authentication required" ) ); 96 cb->setChecked( prefs.get<bool>(Prefs::SESSION_REMOTE_AUTH) ); 97 connect( cb, SIGNAL(toggled(bool)), this, SLOT(resensitize())); 98 myRemoteWidgets << cb; 99 hig->addWideControl( cb ); 100 le = myUsernameLineEdit = new QLineEdit( ); 101 le->setText( prefs.get<QString>(Prefs::SESSION_REMOTE_USERNAME) ); 102 l = hig->addRow( tr( "&Username:" ), le ); 103 myAuthWidgets << l << le; 104 le = myPasswordLineEdit = new QLineEdit( ); 105 le->setEchoMode( QLineEdit::Password ); 106 le->setText( prefs.get<QString>(Prefs::SESSION_REMOTE_PASSWORD) ); 107 l = hig->addRow( tr( "Pass&word:" ), le ); 108 myAuthWidgets << l << le; 109 hig->finish( ); 110 top->addWidget( hig, 1 ); 111 resensitize( ); 112 113 QDialogButtonBox * buttons = new QDialogButtonBox( QDialogButtonBox::Cancel|QDialogButtonBox::Ok ); 114 connect( buttons, SIGNAL(rejected()), this, SLOT(hide())); 115 connect( buttons, SIGNAL(accepted()), this, SLOT(onAccepted())); 116 top->addWidget( buttons, 0 ); 117} 118