From: Mike Gelfand Date: Sun, 25 Jan 2015 15:47:03 +0000 (+0000) Subject: Rework preferences dialog in Qt client to load from .ui X-Git-Tag: 2.90~232 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a18d818882912b656534912b5838a9907c48d5b0;p=transmission Rework preferences dialog in Qt client to load from .ui --- diff --git a/qt/CMakeLists.txt b/qt/CMakeLists.txt index d099d571d..209e6528f 100644 --- a/qt/CMakeLists.txt +++ b/qt/CMakeLists.txt @@ -113,6 +113,7 @@ tr_qt_wrap_ui(${PROJECT_NAME}_UI_SOURCES make-dialog.ui make-progress-dialog.ui options.ui + prefs-dialog.ui relocate.ui session-dialog.ui stats-dialog.ui diff --git a/qt/details.ui b/qt/details.ui index 2ed0e516f..bffa2138e 100644 --- a/qt/details.ui +++ b/qt/details.ui @@ -19,6 +19,12 @@ 0 + + Qt::ElideNone + + + false + Information @@ -701,12 +707,12 @@ - - 0.500000000000000 - 999999999.000000000000000 + + 0.500000000000000 + diff --git a/qt/mainwin.cc b/qt/mainwin.cc index 383b57328..e17b7a683 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -82,7 +82,7 @@ TrMainWindow::getStockIcon (const QString& name, int fallback) TrMainWindow::TrMainWindow (Session& session, Prefs& prefs, TorrentModel& model, bool minimized): myLastFullUpdateTime (0), mySessionDialog (new SessionDialog (session, prefs, this)), - myPrefsDialog (0), + myPrefsDialog (), myAboutDialog (new AboutDialog (this)), myStatsDialog (new StatsDialog (session, this)), myDetailsDialog (0), @@ -513,22 +513,20 @@ TrMainWindow::hideEvent (QHideEvent * event) ***** ****/ -void -TrMainWindow::onPrefsDestroyed () -{ - myPrefsDialog = 0; -} - void TrMainWindow::openPreferences () { - if (myPrefsDialog == 0) + if (myPrefsDialog.isNull ()) { myPrefsDialog = new PrefsDialog (mySession, myPrefs, this); - connect (myPrefsDialog, SIGNAL (destroyed (QObject*)), this, SLOT (onPrefsDestroyed ())); + myPrefsDialog->setAttribute (Qt::WA_DeleteOnClose); + myPrefsDialog->show (); + } + else + { + myPrefsDialog->raise (); + myPrefsDialog->activateWindow (); } - - myPrefsDialog->show (); } void diff --git a/qt/mainwin.h b/qt/mainwin.h index da51f5859..01d7b4af5 100644 --- a/qt/mainwin.h +++ b/qt/mainwin.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -57,7 +58,7 @@ class TrMainWindow: public QMainWindow private: time_t myLastFullUpdateTime; QDialog * mySessionDialog; - QDialog * myPrefsDialog; + QPointer myPrefsDialog; QDialog * myAboutDialog; QDialog * myStatsDialog; Details * myDetailsDialog; @@ -91,7 +92,6 @@ class TrMainWindow: public QMainWindow QWidgetList myHidden; private slots: - void onPrefsDestroyed (); void openPreferences (); void onDetailsDestroyed (); void showTotalRatio (); diff --git a/qt/prefs-dialog.cc b/qt/prefs-dialog.cc index 0aceaef58..f11bcc2ab 100644 --- a/qt/prefs-dialog.cc +++ b/qt/prefs-dialog.cc @@ -33,6 +33,7 @@ #include #include +#include "column-resizer.h" #include "freespace-label.h" #include "formatter.h" #include "hig.h" @@ -48,154 +49,177 @@ namespace { const char * PREF_KEY ("pref-key"); + + void + setPrefKey (QObject * object, int key) + { + object->setProperty (PREF_KEY, key); + } + + int + getPrefKey (const QObject * object) + { + return object->property (PREF_KEY).toInt (); + } + + int + qtDayToTrDay (int day) + { + switch (day) + { + case Qt::Monday: + return TR_SCHED_MON; + case Qt::Tuesday: + return TR_SCHED_TUES; + case Qt::Wednesday: + return TR_SCHED_WED; + case Qt::Thursday: + return TR_SCHED_THURS; + case Qt::Friday: + return TR_SCHED_FRI; + case Qt::Saturday: + return TR_SCHED_SAT; + case Qt::Sunday: + return TR_SCHED_SUN; + default: + assert (0 && "Invalid day of week"); + return 0; + } + } + + QString + qtDayName (int day) + { + switch (day) + { + case Qt::Monday: + return PrefsDialog::tr ("Monday"); + case Qt::Tuesday: + return PrefsDialog::tr ("Tuesday"); + case Qt::Wednesday: + return PrefsDialog::tr ("Wednesday"); + case Qt::Thursday: + return PrefsDialog::tr ("Thursday"); + case Qt::Friday: + return PrefsDialog::tr ("Friday"); + case Qt::Saturday: + return PrefsDialog::tr ("Saturday"); + case Qt::Sunday: + return PrefsDialog::tr ("Sunday"); + default: + assert (0 && "Invalid day of week"); + return QString (); + } + } }; -void -PrefsDialog::checkBoxToggled (bool checked) -{ - const int key (sender ()->property (PREF_KEY).toInt ()); - setPref (key, checked); +bool +PrefsDialog::updateWidgetValue (QWidget * widget, int prefKey) +{ + if (auto w = qobject_cast (widget)) + w->setChecked (myPrefs.getBool (prefKey)); + else if (auto w = qobject_cast (widget)) + w->setValue (myPrefs.getInt (prefKey)); + else if (auto w = qobject_cast (widget)) + w->setValue (myPrefs.getDouble (prefKey)); + else if (auto w = qobject_cast (widget)) + w->setTime (QTime ().addSecs (myPrefs.getInt(prefKey) * 60)); + else if (auto w = qobject_cast (widget)) + w->setText (myPrefs.getString (prefKey)); + else + return false; + + return true; } -QCheckBox * -PrefsDialog::checkBoxNew (const QString& text, int key) +void +PrefsDialog::linkWidgetToPref (QWidget * widget, int prefKey) { - QCheckBox * box = new QCheckBox (text); - box->setChecked (myPrefs.getBool (key)); - box->setProperty (PREF_KEY, key); - connect (box, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled(bool))); - myWidgets.insert (key, box); - return box; + setPrefKey (widget, prefKey); + updateWidgetValue (widget, prefKey); + myWidgets.insert (prefKey, widget); + + if (widget->inherits ("QCheckBox")) + connect (widget, SIGNAL (toggled (bool)), SLOT (checkBoxToggled (bool))); + else if (widget->inherits ("QTimeEdit")) + connect (widget, SIGNAL (editingFinished ()), SLOT (timeEditingFinished ())); + else if (widget->inherits ("QLineEdit")) + connect (widget, SIGNAL (editingFinished ()), SLOT (lineEditingFinished ())); + else if (widget->inherits ("QAbstractSpinBox")) + connect (widget, SIGNAL (editingFinished ()), SLOT (spinBoxEditingFinished ())); } void -PrefsDialog::enableBuddyWhenChecked (QCheckBox * box, QWidget * buddy) +PrefsDialog::checkBoxToggled (bool checked) { - connect (box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool))); - buddy->setEnabled (box->isChecked ()); + if (auto c = qobject_cast (sender ())) + setPref (getPrefKey (c), checked); } void PrefsDialog::spinBoxEditingFinished () { const QObject * spin = sender(); - const int key = spin->property (PREF_KEY).toInt (); - const QDoubleSpinBox * d = qobject_cast (spin); + const int key = getPrefKey (spin); - if (d) - setPref (key, d->value ()); - else - setPref (key, qobject_cast(spin)->value ()); -} - -QSpinBox * -PrefsDialog::spinBoxNew (int key, int low, int high, int step) -{ - QSpinBox * spin = new QSpinBox (); - spin->setRange (low, high); - spin->setSingleStep (step); - spin->setValue (myPrefs.getInt (key)); - spin->setProperty (PREF_KEY, key); - connect (spin, SIGNAL(editingFinished()), this, SLOT(spinBoxEditingFinished())); - myWidgets.insert (key, spin); - return spin; -} - -QDoubleSpinBox * -PrefsDialog::doubleSpinBoxNew (int key, double low, double high, double step, int decimals) -{ - QDoubleSpinBox * spin = new QDoubleSpinBox (); - spin->setRange (low, high); - spin->setSingleStep (step); - spin->setDecimals (decimals); - spin->setValue (myPrefs.getDouble (key)); - spin->setProperty (PREF_KEY, key); - connect (spin, SIGNAL(editingFinished()), this, SLOT(spinBoxEditingFinished())); - myWidgets.insert (key, spin); - return spin; + if (auto e = qobject_cast (spin)) + setPref (key, e->value ()); + else if (auto e = qobject_cast (spin)) + setPref (key, e->value ()); } void -PrefsDialog::timeEditingFinished() -{ - auto e = qobject_cast(sender()); - if (e != nullptr) - { - const int key {e->property(PREF_KEY).toInt()}; - const QTime t {e->time()}; - const int minutes_after_midnight {t.hour()*60 + t.minute()}; - setPref(key, minutes_after_midnight); - } -} - -QTimeEdit* -PrefsDialog::timeEditNew (int key) +PrefsDialog::timeEditingFinished () { - const int minutes {myPrefs.getInt(key)}; - auto e = new QTimeEdit{}; - e->setDisplayFormat(QString::fromUtf8("hh:mm")); - e->setProperty(PREF_KEY, key); - e->setTime(QTime{minutes/60, minutes%60}); - myWidgets.insert(key, e); - connect(e, SIGNAL(editingFinished()), this, SLOT(timeEditingFinished())); - return e; + if (auto e = qobject_cast (sender ())) + setPref(getPrefKey (e), QTime ().secsTo (e->time()) / 60); } void PrefsDialog::lineEditingFinished () { - QLineEdit * e = qobject_cast(sender()); - if (e && e->isModified ()) + if (auto e = qobject_cast (sender ())) { - const int key (e->property (PREF_KEY).toInt ()); - const QString text (e->text()); - setPref (key, text); + if (e->isModified ()) + setPref (getPrefKey (e), e->text()); } } -QLineEdit* -PrefsDialog::lineEditNew (int key, int echoMode) -{ - QLineEdit * e = new QLineEdit (myPrefs.getString (key)); - e->setProperty (PREF_KEY, key); - e->setEchoMode (QLineEdit::EchoMode (echoMode)); - myWidgets.insert (key, e); - connect (e, SIGNAL(editingFinished()), this, SLOT(lineEditingFinished())); - return e; -} - /*** **** ***/ -QWidget * -PrefsDialog::createRemoteTab (Session& session) -{ - HIG * hig = new HIG (this); - hig->addSectionTitle (tr ("Remote Control")); - QWidget * w; - QHBoxLayout * h = new QHBoxLayout (); - QPushButton * b = new QPushButton (tr ("&Open web client")); - connect (b, SIGNAL(clicked()), &session, SLOT(launchWebInterface())); - h->addWidget (b, 0, Qt::AlignRight); - QWidget * l = checkBoxNew (tr ("Allow &remote access"), Prefs::RPC_ENABLED); - myUnsupportedWhenRemote << l; - hig->addRow (l, h, 0); - l = hig->addRow (tr ("HTTP &port:"), w = spinBoxNew (Prefs::RPC_PORT, 0, 65535, 1)); - myWebWidgets << l << w; - hig->addWideControl (w = checkBoxNew (tr ("Use &authentication"), Prefs::RPC_AUTH_REQUIRED)); - myWebWidgets << w; - l = hig->addRow (tr ("&Username:"), w = lineEditNew (Prefs::RPC_USERNAME)); - myWebAuthWidgets << l << w; - l = hig->addRow (tr ("Pass&word:"), w = lineEditNew (Prefs::RPC_PASSWORD, QLineEdit::Password)); - myWebAuthWidgets << l << w; - hig->addWideControl (w = checkBoxNew (tr ("Only allow these IP a&ddresses:"), Prefs::RPC_WHITELIST_ENABLED)); - myWebWidgets << w; - l = hig->addRow (tr ("Addresses:"), w = lineEditNew (Prefs::RPC_WHITELIST)); - myWebWhitelistWidgets << l << w; - myUnsupportedWhenRemote << myWebWidgets << myWebAuthWidgets << myWebWhitelistWidgets; - hig->finish (); - return hig; +void +PrefsDialog::initRemoteTab () +{ + linkWidgetToPref (ui.enableRpcCheck, Prefs::RPC_ENABLED); + linkWidgetToPref (ui.rpcPortSpin, Prefs::RPC_PORT); + linkWidgetToPref (ui.requireRpcAuthCheck, Prefs::RPC_AUTH_REQUIRED); + linkWidgetToPref (ui.rpcUsernameEdit, Prefs::RPC_USERNAME); + linkWidgetToPref (ui.rpcPasswordEdit, Prefs::RPC_PASSWORD); + linkWidgetToPref (ui.enableRpcWhitelistCheck, Prefs::RPC_WHITELIST_ENABLED); + linkWidgetToPref (ui.rpcWhitelistEdit, Prefs::RPC_WHITELIST); + + myWebWidgets << + ui.rpcPortLabel << + ui.rpcPortSpin << + ui.requireRpcAuthCheck << + ui.enableRpcWhitelistCheck; + myWebAuthWidgets << + ui.rpcUsernameLabel << + ui.rpcUsernameEdit << + ui.rpcPasswordLabel << + ui.rpcPasswordEdit; + myWebWhitelistWidgets << + ui.rpcWhitelistLabel << + ui.rpcWhitelistEdit; + myUnsupportedWhenRemote << + ui.enableRpcCheck << + myWebWidgets << + myWebAuthWidgets << + myWebWhitelistWidgets; + + connect (ui.openWebClientButton, SIGNAL (clicked ()), &mySession, SLOT (launchWebInterface ())); } /*** @@ -209,113 +233,64 @@ PrefsDialog::altSpeedDaysEdited (int i) setPref (Prefs::ALT_SPEED_LIMIT_TIME_DAY, value); } - -QWidget * -PrefsDialog::createSpeedTab () +void +PrefsDialog::initSpeedTab () { - QWidget * l; - QSpinBox * r; - HIG * hig = new HIG (this); - hig->addSectionTitle (tr ("Speed Limits")); const QString speed_K_str = Formatter::unitStr (Formatter::SPEED, Formatter::KB); - - l = checkBoxNew (tr ("&Upload:"), Prefs::USPEED_ENABLED); - r = spinBoxNew (Prefs::USPEED, 0, INT_MAX, 5); - r->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str)); - hig->addRow (l, r); - enableBuddyWhenChecked (qobject_cast(l), r); - - l = checkBoxNew (tr ("&Download:"), Prefs::DSPEED_ENABLED); - r = spinBoxNew (Prefs::DSPEED, 0, INT_MAX, 5); - r->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str)); - hig->addRow (l, r); - enableBuddyWhenChecked (qobject_cast(l), r); - - hig->addSectionDivider (); - QHBoxLayout * h = new QHBoxLayout; - h->setSpacing (HIG::PAD); - QLabel * label = new QLabel; - label->setPixmap (QPixmap (QString::fromUtf8 (":/icons/alt-limit-off.png"))); - label->setAlignment (Qt::AlignLeft|Qt::AlignVCenter); - h->addWidget (label); - label = new QLabel (tr ("Alternative Speed Limits")); - label->setStyleSheet (QString::fromUtf8 ("font: bold")); - label->setAlignment (Qt::AlignLeft|Qt::AlignVCenter); - h->addWidget (label); - hig->addSectionTitle (h); - - QString s = tr ("Override normal speed limits manually or at scheduled times"); - hig->addWideControl (new QLabel (s)); - - s = tr ("U&pload:"); - r = spinBoxNew (Prefs::ALT_SPEED_LIMIT_UP, 0, INT_MAX, 5); - r->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str)); - hig->addRow (s, r); - - s = tr ("Do&wnload:"); - r = spinBoxNew (Prefs::ALT_SPEED_LIMIT_DOWN, 0, INT_MAX, 5); - r->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str)); - hig->addRow (s, r); - - QCheckBox * c = checkBoxNew (tr ("&Scheduled times:"), Prefs::ALT_SPEED_LIMIT_TIME_ENABLED); - h = new QHBoxLayout (); - h->setSpacing (HIG::PAD); - QWidget * w = timeEditNew (Prefs::ALT_SPEED_LIMIT_TIME_BEGIN); - h->addWidget (w, 1); - mySchedWidgets << w; - QLabel * nd = new QLabel (tr("&to")); - h->addWidget (nd); - mySchedWidgets << nd; - w = timeEditNew (Prefs::ALT_SPEED_LIMIT_TIME_END); - nd->setBuddy (w); - h->addWidget (w, 1); - mySchedWidgets << w; - hig->addRow (c, h, 0); - - s = tr ("&On days:"); - QComboBox * box = new QComboBox; - const QIcon noIcon; - box->addItem (noIcon, tr ("Every Day"), QVariant (TR_SCHED_ALL)); - box->addItem (noIcon, tr ("Weekdays"), QVariant (TR_SCHED_WEEKDAY)); - box->addItem (noIcon, tr ("Weekends"), QVariant (TR_SCHED_WEEKEND)); - box->addItem (noIcon, tr ("Sunday"), QVariant (TR_SCHED_SUN)); - box->addItem (noIcon, tr ("Monday"), QVariant (TR_SCHED_MON)); - box->addItem (noIcon, tr ("Tuesday"), QVariant (TR_SCHED_TUES)); - box->addItem (noIcon, tr ("Wednesday"), QVariant (TR_SCHED_WED)); - box->addItem (noIcon, tr ("Thursday"), QVariant (TR_SCHED_THURS)); - box->addItem (noIcon, tr ("Friday"), QVariant (TR_SCHED_FRI)); - box->addItem (noIcon, tr ("Saturday"), QVariant (TR_SCHED_SAT)); - box->setCurrentIndex (box->findData (myPrefs.getInt (Prefs::ALT_SPEED_LIMIT_TIME_DAY))); - connect (box, SIGNAL(activated(int)), this, SLOT(altSpeedDaysEdited(int))); - w = hig->addRow (s, box); - mySchedWidgets << w << box; - - hig->finish (); - return hig; + const QLocale locale; + + ui.uploadSpeedLimitSpin->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str)); + ui.downloadSpeedLimitSpin->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str)); + ui.altUploadSpeedLimitSpin->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str)); + ui.altDownloadSpeedLimitSpin->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str)); + + ui.altSpeedLimitDaysCombo->addItem (tr ("Every Day"), QVariant (TR_SCHED_ALL)); + ui.altSpeedLimitDaysCombo->addItem (tr ("Weekdays"), QVariant (TR_SCHED_WEEKDAY)); + ui.altSpeedLimitDaysCombo->addItem (tr ("Weekends"), QVariant (TR_SCHED_WEEKEND)); + ui.altSpeedLimitDaysCombo->insertSeparator (ui.altSpeedLimitDaysCombo->count ()); + for (int i = locale.firstDayOfWeek (); i <= Qt::Sunday; ++i) + ui.altSpeedLimitDaysCombo->addItem (qtDayName (i), qtDayToTrDay (i)); + for (int i = Qt::Monday; i < locale.firstDayOfWeek (); ++i) + ui.altSpeedLimitDaysCombo->addItem (qtDayName (i), qtDayToTrDay (i)); + ui.altSpeedLimitDaysCombo->setCurrentIndex (ui.altSpeedLimitDaysCombo->findData (myPrefs.getInt (Prefs::ALT_SPEED_LIMIT_TIME_DAY))); + + linkWidgetToPref (ui.uploadSpeedLimitCheck, Prefs::USPEED_ENABLED); + linkWidgetToPref (ui.uploadSpeedLimitSpin, Prefs::USPEED); + linkWidgetToPref (ui.downloadSpeedLimitCheck, Prefs::DSPEED_ENABLED); + linkWidgetToPref (ui.downloadSpeedLimitSpin, Prefs::DSPEED); + linkWidgetToPref (ui.altUploadSpeedLimitSpin, Prefs::ALT_SPEED_LIMIT_UP); + linkWidgetToPref (ui.altDownloadSpeedLimitSpin, Prefs::ALT_SPEED_LIMIT_DOWN); + linkWidgetToPref (ui.altSpeedLimitScheduleCheck, Prefs::ALT_SPEED_LIMIT_TIME_ENABLED); + linkWidgetToPref (ui.altSpeedLimitStartTimeEdit, Prefs::ALT_SPEED_LIMIT_TIME_BEGIN); + linkWidgetToPref (ui.altSpeedLimitEndTimeEdit, Prefs::ALT_SPEED_LIMIT_TIME_END); + + mySchedWidgets << + ui.altSpeedLimitStartTimeEdit << + ui.altSpeedLimitToLabel << + ui.altSpeedLimitEndTimeEdit << + ui.altSpeedLimitDaysLabel << + ui.altSpeedLimitDaysCombo; + + ColumnResizer * cr (new ColumnResizer (this)); + cr->addLayout (ui.speedLimitsSectionLayout); + cr->addLayout (ui.altSpeedLimitsSectionLayout); + cr->update (); + + connect (ui.altSpeedLimitDaysCombo, SIGNAL (activated (int)), SLOT (altSpeedDaysEdited (int))); } /*** **** ***/ -QWidget * -PrefsDialog::createDesktopTab () +void +PrefsDialog::initDesktopTab () { - HIG * hig = new HIG (this); - hig->addSectionTitle (tr ("Desktop")); - - hig->addWideControl (checkBoxNew (tr ("Show Transmission icon in the ¬ification area"), Prefs::SHOW_TRAY_ICON)); - hig->addWideControl (checkBoxNew (tr ("Start &minimized in notification area"), Prefs::START_MINIMIZED)); - - hig->addSectionDivider (); - hig->addSectionTitle (tr ("Notification")); - - hig->addWideControl (checkBoxNew (tr ("Show a notification when torrents are a&dded"), Prefs::SHOW_NOTIFICATION_ON_ADD)); - hig->addWideControl (checkBoxNew (tr ("Show a notification when torrents &finish"), Prefs::SHOW_NOTIFICATION_ON_COMPLETE)); - hig->addWideControl (checkBoxNew (tr ("Play a &sound when torrents finish"), Prefs::COMPLETE_SOUND_ENABLED)); - - hig->finish (); - return hig; + linkWidgetToPref (ui.showTrayIconCheck, Prefs::SHOW_TRAY_ICON); + linkWidgetToPref (ui.startMinimizedCheck, Prefs::START_MINIMIZED); + linkWidgetToPref (ui.notifyOnTorrentAddedCheck, Prefs::SHOW_NOTIFICATION_ON_ADD); + linkWidgetToPref (ui.notifyOnTorrentCompletedCheck, Prefs::SHOW_NOTIFICATION_ON_COMPLETE); + linkWidgetToPref (ui.playSoundOnTorrentCompletedCheck, Prefs::COMPLETE_SOUND_ENABLED); } /*** @@ -325,63 +300,44 @@ PrefsDialog::createDesktopTab () void PrefsDialog::onPortTested (bool isOpen) { - myPortButton->setEnabled (true); + ui.testPeerPortButton->setEnabled (true); myWidgets[Prefs::PEER_PORT]->setEnabled (true); - myPortLabel->setText (isOpen ? tr ("Port is open") - : tr ("Port is closed")); + ui.peerPortStatusLabel->setText (isOpen ? tr ("Port is open") + : tr ("Port is closed")); } void PrefsDialog::onPortTest () { - myPortLabel->setText (tr ("Testing TCP Port...")); - myPortButton->setEnabled (false); + ui.peerPortStatusLabel->setText (tr ("Testing TCP Port...")); + ui.testPeerPortButton->setEnabled (false); myWidgets[Prefs::PEER_PORT]->setEnabled (false); mySession.portTest (); } -QWidget * -PrefsDialog::createNetworkTab () +void +PrefsDialog::initNetworkTab () { - HIG * hig = new HIG (this); - hig->addSectionTitle (tr ("Incoming Peers")); - - QSpinBox * s = spinBoxNew (Prefs::PEER_PORT, 1, 65535, 1); - QHBoxLayout * h = new QHBoxLayout (); - QPushButton * b = myPortButton = new QPushButton (tr ("Te&st Port")); - QLabel * l = myPortLabel = new QLabel (tr ("Status unknown")); - h->addWidget (l); - h->addSpacing (HIG::PAD_BIG); - h->addWidget (b); - h->setStretchFactor (l, 1); - connect (b, SIGNAL(clicked(bool)), this, SLOT(onPortTest())); - connect (&mySession, SIGNAL(portTested(bool)), this, SLOT(onPortTested(bool))); - - hig->addRow (tr ("&Port for incoming connections:"), s); - hig->addRow (QString(), h, 0); - hig->addWideControl (checkBoxNew (tr ("Pick a &random port every time Transmission is started"), Prefs::PEER_PORT_RANDOM_ON_START)); - hig->addWideControl (checkBoxNew (tr ("Use UPnP or NAT-PMP port &forwarding from my router"), Prefs::PORT_FORWARDING)); - - hig->addSectionDivider (); - hig->addSectionTitle (tr ("Peer Limits")); - hig->addRow (tr ("Maximum peers per &torrent:"), spinBoxNew (Prefs::PEER_LIMIT_TORRENT, 1, FD_SETSIZE, 5)); - hig->addRow (tr ("Maximum peers &overall:"), spinBoxNew (Prefs::PEER_LIMIT_GLOBAL, 1, FD_SETSIZE, 5)); + ui.torrentPeerLimitSpin->setRange (1, FD_SETSIZE); + ui.globalPeerLimitSpin->setRange (1, FD_SETSIZE); - hig->addSectionDivider (); - hig->addSectionTitle (tr ("Options")); + linkWidgetToPref (ui.peerPortSpin, Prefs::PEER_PORT); + linkWidgetToPref (ui.randomPeerPortCheck, Prefs::PEER_PORT_RANDOM_ON_START); + linkWidgetToPref (ui.enablePortForwardingCheck, Prefs::PORT_FORWARDING); + linkWidgetToPref (ui.torrentPeerLimitSpin, Prefs::PEER_LIMIT_TORRENT); + linkWidgetToPref (ui.globalPeerLimitSpin, Prefs::PEER_LIMIT_GLOBAL); + linkWidgetToPref (ui.enableUtpCheck, Prefs::UTP_ENABLED); + linkWidgetToPref (ui.enablePexCheck, Prefs::PEX_ENABLED); + linkWidgetToPref (ui.enableDhtCheck, Prefs::DHT_ENABLED); + linkWidgetToPref (ui.enableLpdCheck, Prefs::LPD_ENABLED); - QWidget * w; - hig->addWideControl (w = checkBoxNew (tr ("Enable &uTP for peer connections"), Prefs::UTP_ENABLED)); - w->setToolTip (tr ("uTP is a tool for reducing network congestion.")); - hig->addWideControl (w = checkBoxNew (tr ("Use PE&X to find more peers"), Prefs::PEX_ENABLED)); - w->setToolTip (tr ("PEX is a tool for exchanging peer lists with the peers you're connected to.")); - hig->addWideControl (w = checkBoxNew (tr ("Use &DHT to find more peers"), Prefs::DHT_ENABLED)); - w->setToolTip (tr ("DHT is a tool for finding peers without a tracker.")); - hig->addWideControl (w = checkBoxNew (tr ("Use &Local Peer Discovery to find more peers"), Prefs::LPD_ENABLED)); - w->setToolTip (tr ("LPD is a tool for finding peers on your local network.")); + ColumnResizer * cr (new ColumnResizer (this)); + cr->addLayout (ui.incomingPeersSectionLayout); + cr->addLayout (ui.peerLimitsSectionLayout); + cr->update (); - hig->finish (); - return hig; + connect (ui.testPeerPortButton, SIGNAL (clicked ()), SLOT (onPortTest ())); + connect (&mySession, SIGNAL (portTested (bool)), SLOT (onPortTested (bool))); } /*** @@ -431,49 +387,33 @@ PrefsDialog::encryptionEdited (int i) setPref (Prefs::ENCRYPTION, value); } -QWidget * -PrefsDialog::createPrivacyTab () +void +PrefsDialog::initPrivacyTab () { - QWidget * w; - HIG * hig = new HIG (this); - - hig->addSectionTitle (tr ("Encryption")); - - QComboBox * box = new QComboBox (); - box->addItem (tr ("Allow encryption"), 0); - box->addItem (tr ("Prefer encryption"), 1); - box->addItem (tr ("Require encryption"), 2); - myWidgets.insert (Prefs::ENCRYPTION, box); - connect (box, SIGNAL(activated(int)), this, SLOT(encryptionEdited(int))); + ui.encryptionModeCombo->addItem (tr ("Allow encryption"), 0); + ui.encryptionModeCombo->addItem (tr ("Prefer encryption"), 1); + ui.encryptionModeCombo->addItem (tr ("Require encryption"), 2); - hig->addRow (tr ("&Encryption mode:"), box); + linkWidgetToPref (ui.encryptionModeCombo, Prefs::ENCRYPTION); + linkWidgetToPref (ui.blocklistCheck, Prefs::BLOCKLIST_ENABLED); + linkWidgetToPref (ui.blocklistEdit, Prefs::BLOCKLIST_URL); + linkWidgetToPref (ui.autoUpdateBlocklistCheck, Prefs::BLOCKLIST_UPDATES_ENABLED); - hig->addSectionDivider (); - hig->addSectionTitle (tr ("Blocklist")); + myBlockWidgets << + ui.blocklistEdit << + ui.blocklistStatusLabel << + ui.updateBlocklistButton << + ui.autoUpdateBlocklistCheck; - QWidget * l = checkBoxNew (tr("Enable &blocklist:"), Prefs::BLOCKLIST_ENABLED); - QWidget * e = lineEditNew (Prefs::BLOCKLIST_URL); - myBlockWidgets << e; - hig->addRow (l, e); + ColumnResizer * cr (new ColumnResizer (this)); + cr->addLayout (ui.encryptionSectionLayout); + cr->addLayout (ui.blocklistSectionLayout); + cr->update (); - l = myBlocklistLabel = new QLabel (); - myBlockWidgets << l; - w = new QPushButton (tr ("&Update")); - connect (w, SIGNAL(clicked(bool)), this, SLOT(onUpdateBlocklistClicked())); - myBlockWidgets << w; - QHBoxLayout * h = new QHBoxLayout (); - h->addWidget (l); - h->addStretch (1); - h->addWidget (w); - hig->addWideControl (h); + connect (ui.encryptionModeCombo, SIGNAL (activated (int)), SLOT (encryptionEdited (int))); + connect (ui.updateBlocklistButton, SIGNAL (clicked ()), SLOT (onUpdateBlocklistClicked ())); - l = checkBoxNew (tr ("Enable &automatic updates"), Prefs::BLOCKLIST_UPDATES_ENABLED); - myBlockWidgets << l; - hig->addWideControl (l); - - hig->finish (); updateBlocklistLabel (); - return hig; } /*** @@ -534,127 +474,76 @@ void PrefsDialog::onIdleLimitChanged () { //: Spin box suffix, "Stop seeding if idle for: [ 5 minutes ]" (includes leading space after the number, if needed) - const QString unitsSuffix = tr (" minute(s)", 0, myIdleLimitSpin->value ()); - if (myIdleLimitSpin->suffix () != unitsSuffix) - myIdleLimitSpin->setSuffix (unitsSuffix); + const QString unitsSuffix = tr (" minute(s)", 0, ui.idleLimitSpin->value ()); + if (ui.idleLimitSpin->suffix () != unitsSuffix) + ui.idleLimitSpin->setSuffix (unitsSuffix); } -QWidget * -PrefsDialog::createSeedingTab () +void +PrefsDialog::initSeedingTab () { - const int iconSize (style ()->pixelMetric (QStyle::PM_SmallIconSize)); - const QFileIconProvider iconProvider; - const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder); - const QPixmap folderPixmap = folderIcon.pixmap (iconSize); - const QIcon fileIcon = iconProvider.icon (QFileIconProvider::File); - const QPixmap filePixmap = fileIcon.pixmap (iconSize); - - QWidget *l, *r; - HIG * hig = new HIG (this); - hig->addSectionTitle (tr ("Limits")); - - l = checkBoxNew (tr ("Stop seeding at &ratio:"), Prefs::RATIO_ENABLED); - r = doubleSpinBoxNew (Prefs::RATIO, 0, INT_MAX, 0.5, 2); - hig->addRow (l, r); - enableBuddyWhenChecked (qobject_cast(l), r); + linkWidgetToPref (ui.ratioLimitCheck, Prefs::RATIO_ENABLED); + linkWidgetToPref (ui.ratioLimitSpin, Prefs::RATIO); + linkWidgetToPref (ui.idleLimitCheck, Prefs::IDLE_LIMIT_ENABLED); + linkWidgetToPref (ui.idleLimitSpin, Prefs::IDLE_LIMIT); - l = checkBoxNew (tr ("Stop seedi&ng if idle for:"), Prefs::IDLE_LIMIT_ENABLED); - r = myIdleLimitSpin = spinBoxNew (Prefs::IDLE_LIMIT, 1, INT_MAX, 5); - connect (r, SIGNAL (valueChanged (int)), this, SLOT (onIdleLimitChanged ())); - hig->addRow (l, r); - enableBuddyWhenChecked (qobject_cast(l), r); - onIdleLimitChanged (); + connect (ui.idleLimitSpin, SIGNAL (valueChanged (int)), SLOT (onIdleLimitChanged ())); - hig->finish (); - return hig; + onIdleLimitChanged (); } void PrefsDialog::onQueueStalledMinutesChanged () { //: Spin box suffix, "Download is inactive if data sharing stopped: [ 5 minutes ago ]" (includes leading space after the number, if needed) - const QString unitsSuffix = tr (" minute(s) ago", 0, myQueueStalledMinutesSpin->value ()); - if (myQueueStalledMinutesSpin->suffix () != unitsSuffix) - myQueueStalledMinutesSpin->setSuffix (unitsSuffix); + const QString unitsSuffix = tr (" minute(s) ago", 0, ui.queueStalledMinutesSpin->value ()); + if (ui.queueStalledMinutesSpin->suffix () != unitsSuffix) + ui.queueStalledMinutesSpin->setSuffix (unitsSuffix); } -QWidget * -PrefsDialog::createDownloadingTab () +void +PrefsDialog::initDownloadingTab () { - const int iconSize (style ()->pixelMetric (QStyle::PM_SmallIconSize)); + const QSize iconSize (QSize (1, 1) * style ()->pixelMetric (QStyle::PM_SmallIconSize)); const QFileIconProvider iconProvider; const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder); - const QPixmap folderPixmap = folderIcon.pixmap (iconSize); const QIcon fileIcon = iconProvider.icon (QFileIconProvider::File); - const QPixmap filePixmap = fileIcon.pixmap (iconSize); - - QWidget * l; - QPushButton * b; - HIG * hig = new HIG (this); - hig->addSectionTitle (tr ("Adding")); - - l = checkBoxNew (tr ("Automatically add .torrent files &from:"), Prefs::DIR_WATCH_ENABLED); - b = myWatchButton = new QPushButton; - b->setIcon (folderPixmap); - b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5")); - connect (b, SIGNAL(clicked(bool)), this, SLOT(onWatchClicked())); - hig->addRow (l, b); - enableBuddyWhenChecked (qobject_cast(l), b); - - hig->addWideControl (checkBoxNew (tr ("Show the Torrent Options &dialog"), Prefs::OPTIONS_PROMPT)); - - hig->addWideControl (checkBoxNew (tr ("&Start added torrents"), Prefs::START)); - - hig->addWideControl (checkBoxNew (tr ("Mo&ve the .torrent file to the trash"), Prefs::TRASH_ORIGINAL)); - - b = myDestinationButton = new QPushButton; - b->setIcon (folderPixmap); - b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5")); - connect (b, SIGNAL(clicked(bool)), this, SLOT(onDestinationClicked())); - hig->addRow (tr ("Save to &Location:"), b); - - const QString downloadDir (myPrefs.getString(Prefs::DOWNLOAD_DIR)); - l = myFreespaceLabel = new FreespaceLabel (this); - myFreespaceLabel->setSession (mySession); - myFreespaceLabel->setPath (downloadDir); - QHBoxLayout * h = new QHBoxLayout (); - h->addStretch (1); - h->addWidget (l); - hig->addWideControl (h); - - hig->addSectionDivider (); - hig->addSectionTitle (tr ("Download Queue")); - - hig->addRow (tr ("Ma&ximum active downloads:"), spinBoxNew (Prefs::DOWNLOAD_QUEUE_SIZE, 1, INT_MAX, 1)); - QSpinBox * sb = myQueueStalledMinutesSpin = spinBoxNew (Prefs::QUEUE_STALLED_MINUTES, 1, INT_MAX, 10); - connect (sb, SIGNAL (valueChanged (int)), this, SLOT (onQueueStalledMinutesChanged ())); - //: Please keep this phrase as short as possible, it's curently the longest and influences dialog width - hig->addRow (tr ("Download is i&nactive if data sharing stopped:"), sb); - onQueueStalledMinutesChanged (); - - hig->addSectionDivider (); - hig->addSectionTitle (tr ("Incomplete")); - - hig->addWideControl (checkBoxNew (tr ("Append \".&part\" to incomplete files' names"), Prefs::RENAME_PARTIAL_FILES)); - - l = myIncompleteCheckbox = checkBoxNew (tr ("Keep &incomplete files in:"), Prefs::INCOMPLETE_DIR_ENABLED); - b = myIncompleteButton = new QPushButton; - b->setIcon (folderPixmap); - b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5")); - connect (b, SIGNAL(clicked(bool)), this, SLOT(onIncompleteClicked())); - hig->addRow (myIncompleteCheckbox, b); - enableBuddyWhenChecked (qobject_cast(l), b); - - l = myTorrentDoneScriptCheckbox = checkBoxNew (tr ("Call scrip&t when torrent is completed:"), Prefs::SCRIPT_TORRENT_DONE_ENABLED); - b = myTorrentDoneScriptButton = new QPushButton; - b->setIcon (filePixmap); - b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5")); - connect (b, SIGNAL(clicked(bool)), this, SLOT(onScriptClicked())); - hig->addRow (myTorrentDoneScriptCheckbox, b); - enableBuddyWhenChecked (qobject_cast(l), b); - - hig->finish (); - return hig; + + ui.watchDirButton->setIcon (folderIcon); + ui.watchDirButton->setIconSize (iconSize); + ui.downloadDirButton->setIcon (folderIcon); + ui.downloadDirButton->setIconSize (iconSize); + ui.incompleteDirButton->setIcon (folderIcon); + ui.incompleteDirButton->setIconSize (iconSize); + ui.completionScriptButton->setIcon (fileIcon); + ui.completionScriptButton->setIconSize (iconSize); + + ui.downloadDirFreeSpaceLabel->setSession (mySession); + ui.downloadDirFreeSpaceLabel->setPath (myPrefs.getString (Prefs::DOWNLOAD_DIR)); + + linkWidgetToPref (ui.watchDirCheck, Prefs::DIR_WATCH_ENABLED); + linkWidgetToPref (ui.showTorrentOptionsDialogCheck, Prefs::OPTIONS_PROMPT); + linkWidgetToPref (ui.startAddedTorrentsCheck, Prefs::START); + linkWidgetToPref (ui.trashTorrentFileCheck, Prefs::TRASH_ORIGINAL); + linkWidgetToPref (ui.downloadQueueSizeSpin, Prefs::DOWNLOAD_QUEUE_SIZE); + linkWidgetToPref (ui.queueStalledMinutesSpin, Prefs::QUEUE_STALLED_MINUTES); + linkWidgetToPref (ui.renamePartialFilesCheck, Prefs::RENAME_PARTIAL_FILES); + linkWidgetToPref (ui.incompleteDirCheck, Prefs::INCOMPLETE_DIR_ENABLED); + linkWidgetToPref (ui.completionScriptCheck, Prefs::SCRIPT_TORRENT_DONE_ENABLED); + + ColumnResizer * cr (new ColumnResizer (this)); + cr->addLayout (ui.addingSectionLayout); + cr->addLayout (ui.downloadQueueSectionLayout); + cr->addLayout (ui.incompleteSectionLayout); + cr->update (); + + connect (ui.watchDirButton, SIGNAL (clicked ()), SLOT (onWatchClicked ())); + connect (ui.downloadDirButton, SIGNAL (clicked ()), SLOT (onDestinationClicked ())); + connect (ui.incompleteDirButton, SIGNAL (clicked ()), SLOT (onIncompleteClicked ())); + connect (ui.completionScriptButton, SIGNAL (clicked ()), SLOT (onScriptClicked ())); + connect (ui.queueStalledMinutesSpin, SIGNAL (valueChanged (int)), SLOT (onQueueStalledMinutesChanged ())); + + onQueueStalledMinutesChanged (); } /*** @@ -665,27 +554,19 @@ PrefsDialog::PrefsDialog (Session& session, Prefs& prefs, QWidget * parent): QDialog (parent), myIsServer (session.isServer ()), mySession (session), - myPrefs (prefs), - myLayout (new QVBoxLayout (this)) + myPrefs (prefs) { - setWindowTitle (tr ("Transmission Preferences")); - - QTabWidget * t = new QTabWidget (this); - t->addTab (createSpeedTab (), tr ("Speed")); - t->addTab (createDownloadingTab (), tr ("Downloading")); - t->addTab (createSeedingTab (), tr ("Seeding")); - t->addTab (createPrivacyTab (), tr ("Privacy")); - t->addTab (createNetworkTab (), tr ("Network")); - t->addTab (createDesktopTab (), tr ("Desktop")); - t->addTab (createRemoteTab(session), tr ("Remote")); - myLayout->addWidget (t); + ui.setupUi (this); - QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Close, Qt::Horizontal, this); - connect (buttons, SIGNAL(rejected()), this, SLOT(close())); // "close" triggers rejected - myLayout->addWidget (buttons); - QWidget::setAttribute (Qt::WA_DeleteOnClose, true); + initSpeedTab (); + initDownloadingTab (); + initSeedingTab (); + initPrivacyTab (); + initNetworkTab (); + initDesktopTab (); + initRemoteTab (); - connect (&mySession, SIGNAL(sessionUpdated()), this, SLOT(sessionUpdated())); + connect (&mySession, SIGNAL (sessionUpdated ()), SLOT (sessionUpdated ())); QList keys; keys << Prefs::RPC_ENABLED @@ -711,6 +592,8 @@ PrefsDialog::PrefsDialog (Session& session, Prefs& prefs, QWidget * parent): w->setEnabled (false); } } + + adjustSize (); } PrefsDialog::~PrefsDialog () @@ -738,7 +621,7 @@ void PrefsDialog::updateBlocklistLabel () { const int n = mySession.blocklistSize (); - myBlocklistLabel->setText (tr ("Blocklist contains %Ln rule(s)", 0, n)); + ui.blocklistStatusLabel->setText (tr ("Blocklist contains %Ln rule(s)", 0, n)); } void @@ -753,61 +636,59 @@ PrefsDialog::refreshPref (int key) const bool enabled (myPrefs.getBool (Prefs::RPC_ENABLED)); const bool whitelist (myPrefs.getBool (Prefs::RPC_WHITELIST_ENABLED)); const bool auth (myPrefs.getBool (Prefs::RPC_AUTH_REQUIRED)); - foreach (QWidget * w, myWebWhitelistWidgets)w->setEnabled (enabled && whitelist); - foreach (QWidget * w, myWebAuthWidgets)w->setEnabled (enabled && auth); - foreach (QWidget * w, myWebWidgets)w->setEnabled (enabled); + foreach (QWidget * w, myWebWhitelistWidgets) + w->setEnabled (enabled && whitelist); + foreach (QWidget * w, myWebAuthWidgets) + w->setEnabled (enabled && auth); + foreach (QWidget * w, myWebWidgets) + w->setEnabled (enabled); break; } case Prefs::ALT_SPEED_LIMIT_TIME_ENABLED: { const bool enabled = myPrefs.getBool (key); - foreach (QWidget * w, mySchedWidgets)w->setEnabled (enabled); + foreach (QWidget * w, mySchedWidgets) + w->setEnabled (enabled); break; } case Prefs::BLOCKLIST_ENABLED: { const bool enabled = myPrefs.getBool (key); - foreach (QWidget * w, myBlockWidgets)w->setEnabled (enabled); + foreach (QWidget * w, myBlockWidgets) + w->setEnabled (enabled); break; } case Prefs::DIR_WATCH: - myWatchButton->setText (QFileInfo(myPrefs.getString(Prefs::DIR_WATCH)).fileName()); + ui.watchDirButton->setText (QFileInfo (myPrefs.getString (Prefs::DIR_WATCH)).fileName ()); break; case Prefs::SCRIPT_TORRENT_DONE_FILENAME: { const QString path (myPrefs.getString (key)); - myTorrentDoneScriptButton->setText (QFileInfo(path).fileName()); + ui.completionScriptButton->setText (QFileInfo (path).fileName ()); break; } case Prefs::PEER_PORT: - myPortLabel->setText (tr ("Status unknown")); - myPortButton->setEnabled (true); + ui.peerPortStatusLabel->setText (tr ("Status unknown")); + ui.testPeerPortButton->setEnabled (true); break; case Prefs::DOWNLOAD_DIR: { const QString path (myPrefs.getString (key)); - myDestinationButton->setText (QFileInfo(path).fileName()); - myFreespaceLabel->setPath (path); + ui.downloadDirButton->setText (QFileInfo (path).fileName ()); + ui.downloadDirFreeSpaceLabel->setPath (path); break; } case Prefs::INCOMPLETE_DIR: { QString path (myPrefs.getString (key)); - myIncompleteButton->setText (QFileInfo(path).fileName()); - break; - } - - case Prefs::INCOMPLETE_DIR_ENABLED: - { - const bool enabled = myPrefs.getBool (key); - myIncompleteButton->setEnabled (enabled); + ui.incompleteDirButton->setText (QFileInfo (path).fileName ()); break; } @@ -819,46 +700,15 @@ PrefsDialog::refreshPref (int key) if (it != myWidgets.end ()) { QWidget * w (it.value ()); - QCheckBox * checkBox; - QSpinBox * spin; - QDoubleSpinBox * doubleSpin; - QTimeEdit * timeEdit; - QLineEdit * lineEdit; - if ((checkBox = qobject_cast(w))) - { - checkBox->setChecked (myPrefs.getBool (key)); - } - else if ((spin = qobject_cast(w))) - { - spin->setValue (myPrefs.getInt (key)); - } - else if ((doubleSpin = qobject_cast(w))) - { - doubleSpin->setValue (myPrefs.getDouble (key)); - } - else if ((timeEdit = qobject_cast(w))) + if (!updateWidgetValue (w, key)) { - const int minutes (myPrefs.getInt (key)); - timeEdit->setTime (QTime().addSecs (minutes * 60)); - } - else if ((lineEdit = qobject_cast(w))) - { - lineEdit->setText (myPrefs.getString (key)); - } - else if (key == Prefs::ENCRYPTION) - { - QComboBox * comboBox (qobject_cast (w)); - const int index = comboBox->findData (myPrefs.getInt (key)); - comboBox->setCurrentIndex (index); + if (key == Prefs::ENCRYPTION) + { + QComboBox * comboBox (qobject_cast (w)); + const int index = comboBox->findData (myPrefs.getInt (key)); + comboBox->setCurrentIndex (index); + } } } } - -bool -PrefsDialog::isAllowed (int key) const -{ - Q_UNUSED (key); - - return true; -} diff --git a/qt/prefs-dialog.h b/qt/prefs-dialog.h index 6f16a34f0..8c1cfb688 100644 --- a/qt/prefs-dialog.h +++ b/qt/prefs-dialog.h @@ -11,8 +11,11 @@ #define PREFS_DIALOG_H #include +#include #include + #include "prefs.h" +#include "ui_prefs-dialog.h" class QAbstractButton; class QCheckBox; @@ -62,12 +65,8 @@ class PrefsDialog: public QDialog void onBlocklistUpdated (int n); private: - QDoubleSpinBox * doubleSpinBoxNew (int key, double low, double high, double step, int decimals); - QCheckBox * checkBoxNew (const QString& text, int key); - QSpinBox * spinBoxNew (int key, int low, int high, int step); - QTimeEdit * timeEditNew (int key); - QLineEdit * lineEditNew (int key, int mode = 0); - void enableBuddyWhenChecked (QCheckBox *, QWidget *); + bool updateWidgetValue (QWidget * widget, int prefKey); + void linkWidgetToPref (QWidget * widget, int prefKey); void updateBlocklistLabel (); public: @@ -76,14 +75,14 @@ class PrefsDialog: public QDialog private: void setPref (int key, const QVariant& v); - bool isAllowed (int key) const; - QWidget * createDownloadingTab (); - QWidget * createSeedingTab (); - QWidget * createSpeedTab (); - QWidget * createPrivacyTab (); - QWidget * createNetworkTab (); - QWidget * createDesktopTab (); - QWidget * createRemoteTab (Session&); + + void initDownloadingTab (); + void initSeedingTab (); + void initSpeedTab (); + void initPrivacyTab (); + void initNetworkTab (); + void initDesktopTab (); + void initRemoteTab (); private: typedef QMap key2widget_t; @@ -91,15 +90,6 @@ class PrefsDialog: public QDialog const bool myIsServer; Session& mySession; Prefs& myPrefs; - QVBoxLayout * myLayout; - QLabel * myPortLabel; - QPushButton * myPortButton; - QPushButton * myWatchButton; - QPushButton * myTorrentDoneScriptButton; - QCheckBox * myTorrentDoneScriptCheckbox; - QCheckBox * myIncompleteCheckbox; - QPushButton * myIncompleteButton; - QPushButton * myDestinationButton; QWidgetList myWebWidgets; QWidgetList myWebAuthWidgets; QWidgetList myWebWhitelistWidgets; @@ -108,14 +98,11 @@ class PrefsDialog: public QDialog QWidgetList mySchedWidgets; QWidgetList myBlockWidgets; QWidgetList myUnsupportedWhenRemote; - FreespaceLabel * myFreespaceLabel; - QSpinBox * myIdleLimitSpin; - QSpinBox * myQueueStalledMinutesSpin; + Ui::PrefsDialog ui; int myBlocklistHttpTag; QHttp * myBlocklistHttp; QMessageBox * myBlocklistDialog; - QLabel * myBlocklistLabel; }; #endif diff --git a/qt/prefs-dialog.ui b/qt/prefs-dialog.ui new file mode 100644 index 000000000..47de509bd --- /dev/null +++ b/qt/prefs-dialog.ui @@ -0,0 +1,1361 @@ + + + PrefsDialog + + + + 0 + 0 + 545 + 547 + + + + Transmission Preferences + + + + + + 0 + + + Qt::ElideNone + + + false + + + + Speed + + + + + + font-weight:bold + + + Speed Limits + + + + + + + 18 + + + + + &Upload: + + + true + + + + + + + 999999999 + + + 5 + + + + + + + &Download: + + + true + + + + + + + 999999999 + + + 5 + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 1 + 10 + + + + + + + + 2 + + + + + :/icons/alt-limit-off.png + + + + + + + font-weight:bold + + + Alternative Speed Limits + + + + + + + + + 18 + + + + + Do&wnload: + + + altDownloadSpeedLimitSpin + + + + + + + 999999999 + + + 5 + + + + + + + <small>Override normal speed limits manually or at scheduled times</small> + + + + + + + 999999999 + + + 5 + + + + + + + + + hh:mm + + + + + + + + 0 + 0 + + + + &to + + + altSpeedLimitEndTimeEdit + + + + + + + hh:mm + + + + + + + + + U&pload: + + + altUploadSpeedLimitSpin + + + + + + + &Scheduled times: + + + true + + + + + + + &On days: + + + altSpeedLimitDaysCombo + + + + + + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + Downloading + + + + + + font-weight:bold + + + Adding + + + + + + + 18 + + + + + Show the Torrent Options &dialog + + + + + + + Mo&ve the .torrent file to the trash + + + + + + + Automatically add .torrent files &from: + + + true + + + + + + + &Start added torrents + + + + + + + Save to &Location: + + + downloadDirButton + + + + + + + + 0 + 0 + + + + Qt::ToolButtonTextBesideIcon + + + + + + + + 0 + 0 + + + + Qt::ToolButtonTextBesideIcon + + + + + + + ... + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 1 + 10 + + + + + + + + font-weight:bold + + + Download Queue + + + + + + + 18 + + + + + Ma&ximum active downloads: + + + downloadQueueSizeSpin + + + + + + + + + + Download is i&nactive if data sharing stopped: + + + queueStalledMinutesSpin + + + + + + + minute(s) ago + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 1 + 10 + + + + + + + + font-weight:bold + + + Incomplete + + + + + + + 18 + + + + + Append ".&part" to incomplete files' names + + + + + + + + 0 + 0 + + + + Qt::ToolButtonTextBesideIcon + + + + + + + Keep &incomplete files in: + + + true + + + + + + + Call scrip&t when torrent is completed: + + + true + + + + + + + + 0 + 0 + + + + Qt::ToolButtonTextBesideIcon + + + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + Seeding + + + + + + font-weight:bold + + + Limits + + + + + + + 18 + + + + + Stop seeding at &ratio: + + + true + + + + + + + 999999999.000000000000000 + + + 0.500000000000000 + + + + + + + Stop seedi&ng if idle for: + + + true + + + + + + + minute(s) + + + 1 + + + 9999 + + + 5 + + + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + Privacy + + + + + + font-weight:bold + + + Encryption + + + + + + + 18 + + + + + &Encryption mode: + + + encryptionModeCombo + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 1 + 10 + + + + + + + + font-weight:bold + + + Blocklist + + + + + + + 18 + + + + + + + + &Update + + + false + + + + + + + Enable &blocklist: + + + true + + + + + + + Enable &automatic updates + + + + + + + ... + + + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + Network + + + + + + font-weight:bold + + + Incoming Peers + + + + + + + 18 + + + + + Te&st Port + + + false + + + + + + + Pick a &random port every time Transmission is started + + + + + + + &Port for incoming connections: + + + peerPortSpin + + + + + + + 1 + + + 65535 + + + + + + + Status unknown + + + + + + + Use UPnP or NAT-PMP port &forwarding from my router + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 1 + 10 + + + + + + + + font-weight:bold + + + Peer Limits + + + + + + + 18 + + + + + Maximum peers per &torrent: + + + torrentPeerLimitSpin + + + + + + + 1 + + + 1024 + + + 5 + + + + + + + Maximum peers &overall: + + + globalPeerLimitSpin + + + + + + + 1 + + + 1024 + + + 5 + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 1 + 10 + + + + + + + + font-weight:bold + + + Options + + + + + + + 18 + + + + + uTP is a tool for reducing network congestion. + + + Enable &uTP for peer connections + + + + + + + PEX is a tool for exchanging peer lists with the peers you're connected to. + + + Use PE&X to find more peers + + + + + + + DHT is a tool for finding peers without a tracker. + + + Use &DHT to find more peers + + + + + + + LPD is a tool for finding peers on your local network. + + + Use &Local Peer Discovery to find more peers + + + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + Desktop + + + + + + font-weight:bold + + + Desktop + + + + + + + 18 + + + + + Show Transmission icon in the &notification area + + + + + + + Start &minimized in notification area + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 1 + 10 + + + + + + + + font-weight:bold + + + Notification + + + + + + + 18 + + + + + Show a notification when torrents are a&dded + + + + + + + Show a notification when torrents &finish + + + + + + + Play a &sound when torrents finish + + + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + Remote + + + + + + font-weight:bold + + + Remote Control + + + + + + + 18 + + + + + &Username: + + + rpcUsernameEdit + + + + + + + Only allow these IP a&ddresses: + + + true + + + + + + + &Open web client + + + false + + + + + + + 1 + + + 65535 + + + + + + + Use &authentication + + + true + + + + + + + Pass&word: + + + rpcPasswordEdit + + + + + + + Allow &remote access + + + true + + + + + + + + + + QLineEdit::Password + + + + + + + HTTP &port: + + + rpcPortSpin + + + + + + + Addresses: + + + rpcWhitelistEdit + + + + + + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + FreespaceLabel + QLabel +
freespace-label.h
+
+
+ + + + + + dialogButtons + rejected() + PrefsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + uploadSpeedLimitCheck + toggled(bool) + uploadSpeedLimitSpin + setEnabled(bool) + + + 94 + 79 + + + 323 + 79 + + + + + downloadSpeedLimitCheck + toggled(bool) + downloadSpeedLimitSpin + setEnabled(bool) + + + 94 + 113 + + + 323 + 113 + + + + + ratioLimitCheck + toggled(bool) + ratioLimitSpin + setEnabled(bool) + + + 129 + 79 + + + 359 + 79 + + + + + idleLimitCheck + toggled(bool) + idleLimitSpin + setEnabled(bool) + + + 129 + 113 + + + 359 + 113 + + + + + watchDirCheck + toggled(bool) + watchDirButton + setEnabled(bool) + + + 167 + 80 + + + 392 + 80 + + + + + incompleteDirCheck + toggled(bool) + incompleteDirButton + setEnabled(bool) + + + 169 + 411 + + + 395 + 411 + + + + + completionScriptCheck + toggled(bool) + completionScriptButton + setEnabled(bool) + + + 169 + 447 + + + 395 + 447 + + + + +
diff --git a/qt/qtr.pro b/qt/qtr.pro index 92a3c8a94..2c0d81e03 100644 --- a/qt/qtr.pro +++ b/qt/qtr.pro @@ -55,6 +55,7 @@ FORMS += about.ui \ make-dialog.ui \ make-progress-dialog.ui \ options.ui \ + prefs-dialog.ui \ relocate.ui \ session-dialog.ui \ stats-dialog.ui