From 56c75a13b083a1372d8328b5b4d645a06475c3c4 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Sun, 21 Dec 2014 23:46:31 +0000 Subject: [PATCH] Rework session dialog in Qt client to load from .ui --- qt/CMakeLists.txt | 1 + qt/qtr.pro | 1 + qt/session-dialog.cc | 101 +++++++++----------------- qt/session-dialog.h | 16 +---- qt/session-dialog.ui | 165 +++++++++++++++++++++++++++++++++++++++++++ qt/stats-dialog.cc | 1 - 6 files changed, 204 insertions(+), 81 deletions(-) create mode 100644 qt/session-dialog.ui diff --git a/qt/CMakeLists.txt b/qt/CMakeLists.txt index 2b61d1903..bf5129be8 100644 --- a/qt/CMakeLists.txt +++ b/qt/CMakeLists.txt @@ -103,6 +103,7 @@ set(${PROJECT_NAME}_HEADERS tr_qt_wrap_ui(${PROJECT_NAME}_UI_SOURCES details.ui mainwin.ui + session-dialog.ui stats-dialog.ui ) diff --git a/qt/qtr.pro b/qt/qtr.pro index 84f0f909e..208e3b061 100644 --- a/qt/qtr.pro +++ b/qt/qtr.pro @@ -48,6 +48,7 @@ TRANSLATIONS += translations/transmission_en.ts \ FORMS += details.ui \ mainwin.ui \ + session-dialog.ui \ stats-dialog.ui RESOURCES += application.qrc SOURCES += about.cc \ diff --git a/qt/session-dialog.cc b/qt/session-dialog.cc index 156c937b8..53991e985 100644 --- a/qt/session-dialog.cc +++ b/qt/session-dialog.cc @@ -7,15 +7,6 @@ * $Id$ */ -#include -#include -#include -#include -#include -#include -#include - -#include "hig.h" #include "prefs.h" #include "session.h" #include "session-dialog.h" @@ -27,12 +18,12 @@ void SessionDialog::onAccepted () { - myPrefs.set (Prefs::SESSION_IS_REMOTE, myRemoteRadioButton->isChecked ()); - myPrefs.set (Prefs::SESSION_REMOTE_HOST, myHostLineEdit->text ()); - myPrefs.set (Prefs::SESSION_REMOTE_PORT, myPortSpinBox->value ()); - myPrefs.set (Prefs::SESSION_REMOTE_AUTH, myAuthCheckBox->isChecked ()); - myPrefs.set (Prefs::SESSION_REMOTE_USERNAME, myUsernameLineEdit->text ()); - myPrefs.set (Prefs::SESSION_REMOTE_PASSWORD, myPasswordLineEdit->text ()); + myPrefs.set (Prefs::SESSION_IS_REMOTE, ui.remoteSessionRadio->isChecked ()); + myPrefs.set (Prefs::SESSION_REMOTE_HOST, ui.hostEdit->text ()); + myPrefs.set (Prefs::SESSION_REMOTE_PORT, ui.portSpin->value ()); + myPrefs.set (Prefs::SESSION_REMOTE_AUTH, ui.authCheck->isChecked ()); + myPrefs.set (Prefs::SESSION_REMOTE_USERNAME, ui.usernameEdit->text ()); + myPrefs.set (Prefs::SESSION_REMOTE_PASSWORD, ui.passwordEdit->text ()); mySession.restart (); hide (); } @@ -40,8 +31,8 @@ SessionDialog::onAccepted () void SessionDialog::resensitize () { - const bool isRemote = myRemoteRadioButton->isChecked(); - const bool useAuth = myAuthCheckBox->isChecked(); + const bool isRemote = ui.remoteSessionRadio->isChecked (); + const bool useAuth = ui.authCheck->isChecked (); foreach (QWidget * w, myRemoteWidgets) w->setEnabled (isRemote); @@ -59,56 +50,32 @@ SessionDialog::SessionDialog (Session& session, Prefs& prefs, QWidget * parent): mySession (session), myPrefs (prefs) { - QWidget * l; - QSpinBox * sb; - QCheckBox * cb; - QLineEdit * le; - QRadioButton * rb; - - setWindowTitle (tr ("Change Session")); - QVBoxLayout * top = new QVBoxLayout (this); - top->setSpacing (HIG::PAD); - - HIG * hig = new HIG; - hig->setContentsMargins (0, 0, 0, 0); - hig->addSectionTitle (tr ("Source")); - rb = new QRadioButton (tr ("Start &Local Session")); - rb->setChecked (!prefs.get(Prefs::SESSION_IS_REMOTE)); - connect (rb, SIGNAL(toggled(bool)), this, SLOT(resensitize())); - hig->addWideControl (rb); - rb = myRemoteRadioButton = new QRadioButton (tr ("Connect to &Remote Session")); - rb->setChecked (prefs.get(Prefs::SESSION_IS_REMOTE)); - connect (rb, SIGNAL(toggled(bool)), this, SLOT(resensitize())); - hig->addWideControl (rb); - le = myHostLineEdit = new QLineEdit (); - le->setText (prefs.get(Prefs::SESSION_REMOTE_HOST)); - l = hig->addRow (tr ("&Host:"), le); - myRemoteWidgets << l << le; - sb = myPortSpinBox = new QSpinBox; - sb->setRange (1, 65535); - sb->setValue (prefs.get(Prefs::SESSION_REMOTE_PORT)); - l = hig->addRow (tr ("&Port:"), sb); - myRemoteWidgets << l << sb; - cb = myAuthCheckBox = new QCheckBox (tr ("&Authentication required")); - cb->setChecked (prefs.get(Prefs::SESSION_REMOTE_AUTH)); - connect (cb, SIGNAL(toggled(bool)), this, SLOT(resensitize())); - myRemoteWidgets << cb; - hig->addWideControl (cb); - le = myUsernameLineEdit = new QLineEdit (); - le->setText (prefs.get(Prefs::SESSION_REMOTE_USERNAME)); - l = hig->addRow (tr ("&Username:"), le); - myAuthWidgets << l << le; - le = myPasswordLineEdit = new QLineEdit (); - le->setEchoMode (QLineEdit::Password); - le->setText (prefs.get(Prefs::SESSION_REMOTE_PASSWORD)); - l = hig->addRow (tr ("Pass&word:"), le); - myAuthWidgets << l << le; - hig->finish (); - top->addWidget (hig, 1); + ui.setupUi (this); + + ui.localSessionRadio->setChecked (!prefs.get (Prefs::SESSION_IS_REMOTE)); + connect (ui.localSessionRadio, SIGNAL (toggled (bool)), this, SLOT (resensitize ())); + + ui.remoteSessionRadio->setChecked (prefs.get (Prefs::SESSION_IS_REMOTE)); + connect (ui.remoteSessionRadio, SIGNAL (toggled (bool)), this, SLOT (resensitize ())); + + ui.hostEdit->setText (prefs.get (Prefs::SESSION_REMOTE_HOST)); + myRemoteWidgets << ui.hostLabel << ui.hostEdit; + + ui.portSpin->setValue (prefs.get (Prefs::SESSION_REMOTE_PORT)); + myRemoteWidgets << ui.portLabel << ui.portSpin; + + ui.authCheck->setChecked (prefs.get (Prefs::SESSION_REMOTE_AUTH)); + connect (ui.authCheck, SIGNAL (toggled (bool)), this, SLOT (resensitize ())); + myRemoteWidgets << ui.authCheck; + + ui.usernameEdit->setText (prefs.get (Prefs::SESSION_REMOTE_USERNAME)); + myAuthWidgets << ui.usernameLabel << ui.usernameEdit; + + ui.passwordEdit->setText (prefs.get (Prefs::SESSION_REMOTE_PASSWORD)); + myAuthWidgets << ui.passwordLabel << ui.passwordEdit; + resensitize (); - QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Cancel|QDialogButtonBox::Ok); - connect (buttons, SIGNAL(rejected()), this, SLOT(hide())); - connect (buttons, SIGNAL(accepted()), this, SLOT(onAccepted())); - top->addWidget (buttons, 0); + connect (ui.dialogButtons, SIGNAL (rejected ()), this, SLOT (hide ())); + connect (ui.dialogButtons, SIGNAL (accepted ()), this, SLOT (onAccepted ())); } diff --git a/qt/session-dialog.h b/qt/session-dialog.h index 2b50413b0..b266ccd07 100644 --- a/qt/session-dialog.h +++ b/qt/session-dialog.h @@ -13,12 +13,10 @@ #include #include +#include "ui_session-dialog.h" + class Prefs; class Session; -class QCheckBox; -class QLineEdit; -class QRadioButton; -class QSpinBox; class SessionDialog: public QDialog { @@ -32,18 +30,10 @@ class SessionDialog: public QDialog void onAccepted (); void resensitize (); - private: - QCheckBox * myAuthCheckBox; - QRadioButton * myRemoteRadioButton; - QLineEdit * myHostLineEdit; - QSpinBox * myPortSpinBox; - QLineEdit * myUsernameLineEdit; - QLineEdit * myPasswordLineEdit; - QCheckBox * myAutomaticCheckBox; - private: Session& mySession; Prefs& myPrefs; + Ui::SessionDialog ui; QWidgetList myRemoteWidgets; QWidgetList myAuthWidgets; }; diff --git a/qt/session-dialog.ui b/qt/session-dialog.ui new file mode 100644 index 000000000..1a42aa52d --- /dev/null +++ b/qt/session-dialog.ui @@ -0,0 +1,165 @@ + + + SessionDialog + + + + 0 + 0 + 248 + 263 + + + + Change Session + + + [tr-style~="form-section"] +{ + font-weight: bold; + margin-top: 12px; + margin-bottom: 1px; +} +[tr-style~="form-section"][tr-style~="first"] +{ + margin-top: 0; +} +[tr-style~="form-label"] +{ + margin-left: 18px; +} + + + + QLayout::SetFixedSize + + + + + Source + + + form-section first + + + + + + + Start &Local Session + + + form-label + + + + + + + Connect to &Remote Session + + + form-label + + + + + + + &Host: + + + hostEdit + + + form-label + + + + + + + + + + &Port: + + + portSpin + + + form-label + + + + + + + 1 + + + 65535 + + + + + + + &Authentication required + + + form-label + + + + + + + &Username: + + + usernameEdit + + + form-label + + + + + + + + + + Pass&word: + + + passwordEdit + + + form-label + + + + + + + QLineEdit::Password + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + diff --git a/qt/stats-dialog.cc b/qt/stats-dialog.cc index 50f867f81..80b4fba26 100644 --- a/qt/stats-dialog.cc +++ b/qt/stats-dialog.cc @@ -10,7 +10,6 @@ #include #include "formatter.h" -#include "hig.h" #include "session.h" #include "stats-dialog.h" -- 2.40.0