Ignore:
Timestamp:
Dec 21, 2014, 11:46:31 PM (8 years ago)
Author:
mikedld
Message:

Rework session dialog in Qt client to load from .ui

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/session-dialog.cc

    r14377 r14393  
    88 */
    99
    10 #include <QCheckBox>
    11 #include <QDialogButtonBox>
    12 #include <QLabel>
    13 #include <QLineEdit>
    14 #include <QRadioButton>
    15 #include <QSpinBox>
    16 #include <QVBoxLayout>
    17 
    18 #include "hig.h"
    1910#include "prefs.h"
    2011#include "session.h"
     
    2819SessionDialog::onAccepted ()
    2920{
    30   myPrefs.set (Prefs::SESSION_IS_REMOTE, myRemoteRadioButton->isChecked ());
    31   myPrefs.set (Prefs::SESSION_REMOTE_HOST, myHostLineEdit->text ());
    32   myPrefs.set (Prefs::SESSION_REMOTE_PORT, myPortSpinBox->value ());
    33   myPrefs.set (Prefs::SESSION_REMOTE_AUTH, myAuthCheckBox->isChecked ());
    34   myPrefs.set (Prefs::SESSION_REMOTE_USERNAME, myUsernameLineEdit->text ());
    35   myPrefs.set (Prefs::SESSION_REMOTE_PASSWORD, myPasswordLineEdit->text ());
     21  myPrefs.set (Prefs::SESSION_IS_REMOTE, ui.remoteSessionRadio->isChecked ());
     22  myPrefs.set (Prefs::SESSION_REMOTE_HOST, ui.hostEdit->text ());
     23  myPrefs.set (Prefs::SESSION_REMOTE_PORT, ui.portSpin->value ());
     24  myPrefs.set (Prefs::SESSION_REMOTE_AUTH, ui.authCheck->isChecked ());
     25  myPrefs.set (Prefs::SESSION_REMOTE_USERNAME, ui.usernameEdit->text ());
     26  myPrefs.set (Prefs::SESSION_REMOTE_PASSWORD, ui.passwordEdit->text ());
    3627  mySession.restart ();
    3728  hide ();
     
    4132SessionDialog::resensitize ()
    4233{
    43   const bool isRemote = myRemoteRadioButton->isChecked();
    44   const bool useAuth = myAuthCheckBox->isChecked();
     34  const bool isRemote = ui.remoteSessionRadio->isChecked ();
     35  const bool useAuth = ui.authCheck->isChecked ();
    4536
    4637  foreach (QWidget * w, myRemoteWidgets)
     
    6051  myPrefs (prefs)
    6152{
    62   QWidget * l;
    63   QSpinBox * sb;
    64   QCheckBox * cb;
    65   QLineEdit * le;
    66   QRadioButton * rb;
     53  ui.setupUi (this);
    6754
    68   setWindowTitle (tr ("Change Session"));
    69   QVBoxLayout * top = new QVBoxLayout (this);
    70   top->setSpacing (HIG::PAD);
     55  ui.localSessionRadio->setChecked (!prefs.get<bool> (Prefs::SESSION_IS_REMOTE));
     56  connect (ui.localSessionRadio, SIGNAL (toggled (bool)), this, SLOT (resensitize ()));
    7157
    72   HIG * hig = new HIG;
    73   hig->setContentsMargins (0, 0, 0, 0);
    74   hig->addSectionTitle (tr ("Source"));
    75   rb = new QRadioButton (tr ("Start &Local Session"));
    76   rb->setChecked (!prefs.get<bool>(Prefs::SESSION_IS_REMOTE));
    77   connect (rb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
    78   hig->addWideControl (rb);
    79   rb = myRemoteRadioButton = new QRadioButton (tr ("Connect to &Remote Session"));
    80   rb->setChecked (prefs.get<bool>(Prefs::SESSION_IS_REMOTE));
    81   connect (rb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
    82   hig->addWideControl (rb);
    83   le = myHostLineEdit = new QLineEdit ();
    84   le->setText (prefs.get<QString>(Prefs::SESSION_REMOTE_HOST));
    85   l = hig->addRow (tr ("&Host:"), le);
    86   myRemoteWidgets << l << le;
    87   sb = myPortSpinBox = new QSpinBox;
    88   sb->setRange (1, 65535);
    89   sb->setValue (prefs.get<int>(Prefs::SESSION_REMOTE_PORT));
    90   l = hig->addRow (tr ("&Port:"), sb);
    91   myRemoteWidgets << l << sb;
    92   cb = myAuthCheckBox = new QCheckBox (tr ("&Authentication required"));
    93   cb->setChecked (prefs.get<bool>(Prefs::SESSION_REMOTE_AUTH));
    94   connect (cb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
    95   myRemoteWidgets << cb;
    96   hig->addWideControl (cb);
    97   le = myUsernameLineEdit = new QLineEdit ();
    98   le->setText (prefs.get<QString>(Prefs::SESSION_REMOTE_USERNAME));
    99   l = hig->addRow (tr ("&Username:"), le);
    100   myAuthWidgets << l << le;
    101   le = myPasswordLineEdit = new QLineEdit ();
    102   le->setEchoMode (QLineEdit::Password);
    103   le->setText (prefs.get<QString>(Prefs::SESSION_REMOTE_PASSWORD));
    104   l = hig->addRow (tr ("Pass&word:"), le);
    105   myAuthWidgets << l << le;
    106   hig->finish ();
    107   top->addWidget (hig, 1);
     58  ui.remoteSessionRadio->setChecked (prefs.get<bool> (Prefs::SESSION_IS_REMOTE));
     59  connect (ui.remoteSessionRadio, SIGNAL (toggled (bool)), this, SLOT (resensitize ()));
     60
     61  ui.hostEdit->setText (prefs.get<QString> (Prefs::SESSION_REMOTE_HOST));
     62  myRemoteWidgets << ui.hostLabel << ui.hostEdit;
     63
     64  ui.portSpin->setValue (prefs.get<int> (Prefs::SESSION_REMOTE_PORT));
     65  myRemoteWidgets << ui.portLabel << ui.portSpin;
     66
     67  ui.authCheck->setChecked (prefs.get<bool> (Prefs::SESSION_REMOTE_AUTH));
     68  connect (ui.authCheck, SIGNAL (toggled (bool)), this, SLOT (resensitize ()));
     69  myRemoteWidgets << ui.authCheck;
     70
     71  ui.usernameEdit->setText (prefs.get<QString> (Prefs::SESSION_REMOTE_USERNAME));
     72  myAuthWidgets << ui.usernameLabel << ui.usernameEdit;
     73
     74  ui.passwordEdit->setText (prefs.get<QString> (Prefs::SESSION_REMOTE_PASSWORD));
     75  myAuthWidgets << ui.passwordLabel << ui.passwordEdit;
     76
    10877  resensitize ();
    10978
    110   QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
    111   connect (buttons, SIGNAL(rejected()), this, SLOT(hide()));
    112   connect (buttons, SIGNAL(accepted()), this, SLOT(onAccepted()));
    113   top->addWidget (buttons, 0);
     79  connect (ui.dialogButtons, SIGNAL (rejected ()), this, SLOT (hide ()));
     80  connect (ui.dialogButtons, SIGNAL (accepted ()), this, SLOT (onAccepted ()));
    11481}
Note: See TracChangeset for help on using the changeset viewer.