Changeset 14460


Ignore:
Timestamp:
Jan 25, 2015, 3:47:03 PM (6 years ago)
Author:
mikedld
Message:

Rework preferences dialog in Qt client to load from .ui

Location:
trunk/qt
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/CMakeLists.txt

    r14458 r14460  
    114114    make-progress-dialog.ui
    115115    options.ui
     116    prefs-dialog.ui
    116117    relocate.ui
    117118    session-dialog.ui
  • trunk/qt/column-resizer.cc

    • Property svn:keywords set to Date Rev Author Id
  • trunk/qt/column-resizer.h

    • Property svn:keywords set to Date Rev Author Id
  • trunk/qt/details.ui

    r14458 r14460  
    2020      <number>0</number>
    2121     </property>
     22     <property name="elideMode">
     23      <enum>Qt::ElideNone</enum>
     24     </property>
     25     <property name="usesScrollButtons">
     26      <bool>false</bool>
     27     </property>
    2228     <widget class="QWidget" name="infoTab">
    2329      <attribute name="title">
     
    702708         <item row="0" column="2">
    703709          <widget class="QDoubleSpinBox" name="ratioSpin">
    704            <property name="minimum">
    705             <double>0.500000000000000</double>
    706            </property>
    707710           <property name="maximum">
    708711            <double>999999999.000000000000000</double>
     712           </property>
     713           <property name="singleStep">
     714            <double>0.500000000000000</double>
    709715           </property>
    710716          </widget>
  • trunk/qt/mainwin.cc

    r14455 r14460  
    8383  myLastFullUpdateTime (0),
    8484  mySessionDialog (new SessionDialog (session, prefs, this)),
    85   myPrefsDialog (0),
     85  myPrefsDialog (),
    8686  myAboutDialog (new AboutDialog (this)),
    8787  myStatsDialog (new StatsDialog (session, this)),
     
    515515
    516516void
    517 TrMainWindow::onPrefsDestroyed ()
    518 {
    519   myPrefsDialog = 0;
    520 }
    521 
    522 void
    523517TrMainWindow::openPreferences ()
    524518{
    525   if (myPrefsDialog == 0)
     519  if (myPrefsDialog.isNull ())
    526520    {
    527521      myPrefsDialog = new PrefsDialog (mySession, myPrefs, this);
    528       connect (myPrefsDialog, SIGNAL (destroyed (QObject*)), this, SLOT (onPrefsDestroyed ()));
    529     }
    530 
    531   myPrefsDialog->show ();
     522      myPrefsDialog->setAttribute (Qt::WA_DeleteOnClose);
     523      myPrefsDialog->show ();
     524    }
     525  else
     526    {
     527      myPrefsDialog->raise ();
     528      myPrefsDialog->activateWindow ();
     529    }
    532530}
    533531
  • trunk/qt/mainwin.h

    r14389 r14460  
    1616#include <QMainWindow>
    1717#include <QMap>
     18#include <QPointer>
    1819#include <QPushButton>
    1920#include <QSet>
     
    5859    time_t myLastFullUpdateTime;
    5960    QDialog * mySessionDialog;
    60     QDialog * myPrefsDialog;
     61    QPointer<QDialog> myPrefsDialog;
    6162    QDialog * myAboutDialog;
    6263    QDialog * myStatsDialog;
     
    9293
    9394  private slots:
    94     void onPrefsDestroyed ();
    9595    void openPreferences ();
    9696    void onDetailsDestroyed ();
  • trunk/qt/prefs-dialog.cc

    r14455 r14460  
    3434#include <QVBoxLayout>
    3535
     36#include "column-resizer.h"
    3637#include "freespace-label.h"
    3738#include "formatter.h"
     
    4950{
    5051  const char * PREF_KEY ("pref-key");
     52
     53  void
     54  setPrefKey (QObject * object, int key)
     55  {
     56    object->setProperty (PREF_KEY, key);
     57  }
     58
     59  int
     60  getPrefKey (const QObject * object)
     61  {
     62    return object->property (PREF_KEY).toInt ();
     63  }
     64
     65  int
     66  qtDayToTrDay (int day)
     67  {
     68    switch (day)
     69    {
     70      case Qt::Monday:
     71        return TR_SCHED_MON;
     72      case Qt::Tuesday:
     73        return TR_SCHED_TUES;
     74      case Qt::Wednesday:
     75        return TR_SCHED_WED;
     76      case Qt::Thursday:
     77        return TR_SCHED_THURS;
     78      case Qt::Friday:
     79        return TR_SCHED_FRI;
     80      case Qt::Saturday:
     81        return TR_SCHED_SAT;
     82      case Qt::Sunday:
     83        return TR_SCHED_SUN;
     84      default:
     85        assert (0 && "Invalid day of week");
     86        return 0;
     87    }
     88  }
     89
     90  QString
     91  qtDayName (int day)
     92  {
     93    switch (day)
     94    {
     95      case Qt::Monday:
     96        return PrefsDialog::tr ("Monday");
     97      case Qt::Tuesday:
     98        return PrefsDialog::tr ("Tuesday");
     99      case Qt::Wednesday:
     100        return PrefsDialog::tr ("Wednesday");
     101      case Qt::Thursday:
     102        return PrefsDialog::tr ("Thursday");
     103      case Qt::Friday:
     104        return PrefsDialog::tr ("Friday");
     105      case Qt::Saturday:
     106        return PrefsDialog::tr ("Saturday");
     107      case Qt::Sunday:
     108        return PrefsDialog::tr ("Sunday");
     109      default:
     110        assert (0 && "Invalid day of week");
     111        return QString ();
     112    }
     113  }
    51114};
    52115
     116bool
     117PrefsDialog::updateWidgetValue (QWidget * widget, int prefKey)
     118{
     119  if (auto w = qobject_cast<QCheckBox*> (widget))
     120    w->setChecked (myPrefs.getBool (prefKey));
     121  else if (auto w = qobject_cast<QSpinBox*> (widget))
     122    w->setValue (myPrefs.getInt (prefKey));
     123  else if (auto w = qobject_cast<QDoubleSpinBox*> (widget))
     124    w->setValue (myPrefs.getDouble (prefKey));
     125  else if (auto w = qobject_cast<QTimeEdit*> (widget))
     126    w->setTime (QTime ().addSecs (myPrefs.getInt(prefKey) * 60));
     127  else if (auto w = qobject_cast<QLineEdit*> (widget))
     128    w->setText (myPrefs.getString (prefKey));
     129  else
     130    return false;
     131
     132  return true;
     133}
     134
     135void
     136PrefsDialog::linkWidgetToPref (QWidget * widget, int prefKey)
     137{
     138  setPrefKey (widget, prefKey);
     139  updateWidgetValue (widget, prefKey);
     140  myWidgets.insert (prefKey, widget);
     141
     142  if (widget->inherits ("QCheckBox"))
     143    connect (widget, SIGNAL (toggled (bool)), SLOT (checkBoxToggled (bool)));
     144  else if (widget->inherits ("QTimeEdit"))
     145    connect (widget, SIGNAL (editingFinished ()), SLOT (timeEditingFinished ()));
     146  else if (widget->inherits ("QLineEdit"))
     147    connect (widget, SIGNAL (editingFinished ()), SLOT (lineEditingFinished ()));
     148  else if (widget->inherits ("QAbstractSpinBox"))
     149    connect (widget, SIGNAL (editingFinished ()), SLOT (spinBoxEditingFinished ()));
     150}
     151
    53152void
    54153PrefsDialog::checkBoxToggled (bool checked)
    55154{
    56   const int key (sender ()->property (PREF_KEY).toInt ());
    57   setPref (key, checked);
    58 }
    59 
    60 QCheckBox *
    61 PrefsDialog::checkBoxNew (const QString& text, int key)
    62 {
    63   QCheckBox * box = new QCheckBox (text);
    64   box->setChecked (myPrefs.getBool (key));
    65   box->setProperty (PREF_KEY, key);
    66   connect (box, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled(bool)));
    67   myWidgets.insert (key, box);
    68   return box;
    69 }
    70 
    71 void
    72 PrefsDialog::enableBuddyWhenChecked (QCheckBox * box, QWidget * buddy)
    73 {
    74   connect (box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)));
    75   buddy->setEnabled (box->isChecked ());
     155  if (auto c = qobject_cast<QCheckBox*> (sender ()))
     156    setPref (getPrefKey (c), checked);
    76157}
    77158
     
    80161{
    81162  const QObject * spin = sender();
    82   const int key = spin->property (PREF_KEY).toInt ();
    83   const QDoubleSpinBox * d = qobject_cast<const QDoubleSpinBox*> (spin);
    84 
    85   if (d)
    86     setPref (key, d->value ());
    87   else
    88     setPref (key, qobject_cast<const QSpinBox*>(spin)->value ());
    89 }
    90 
    91 QSpinBox *
    92 PrefsDialog::spinBoxNew (int key, int low, int high, int step)
    93 {
    94   QSpinBox * spin = new QSpinBox ();
    95   spin->setRange (low, high);
    96   spin->setSingleStep (step);
    97   spin->setValue (myPrefs.getInt (key));
    98   spin->setProperty (PREF_KEY, key);
    99   connect (spin, SIGNAL(editingFinished()), this, SLOT(spinBoxEditingFinished()));
    100   myWidgets.insert (key, spin);
    101   return spin;
    102 }
    103 
    104 QDoubleSpinBox *
    105 PrefsDialog::doubleSpinBoxNew (int key, double low, double high, double step, int decimals)
    106 {
    107   QDoubleSpinBox * spin = new QDoubleSpinBox ();
    108   spin->setRange (low, high);
    109   spin->setSingleStep (step);
    110   spin->setDecimals (decimals);
    111   spin->setValue (myPrefs.getDouble (key));
    112   spin->setProperty (PREF_KEY, key);
    113   connect (spin, SIGNAL(editingFinished()), this, SLOT(spinBoxEditingFinished()));
    114   myWidgets.insert (key, spin);
    115   return spin;
    116 }
    117 
    118 void
    119 PrefsDialog::timeEditingFinished()
    120 {
    121   auto e = qobject_cast<QTimeEdit*>(sender());
    122   if (e != nullptr)
     163  const int key = getPrefKey (spin);
     164
     165  if (auto e = qobject_cast<const QDoubleSpinBox*> (spin))
     166    setPref (key, e->value ());
     167  else if (auto e = qobject_cast<const QSpinBox*> (spin))
     168    setPref (key, e->value ());
     169}
     170
     171void
     172PrefsDialog::timeEditingFinished ()
     173{
     174  if (auto e = qobject_cast<const QTimeEdit*> (sender ()))
     175    setPref(getPrefKey (e), QTime ().secsTo (e->time()) / 60);
     176}
     177
     178void
     179PrefsDialog::lineEditingFinished ()
     180{
     181  if (auto e = qobject_cast<const QLineEdit*> (sender ()))
    123182    {
    124       const int key {e->property(PREF_KEY).toInt()};
    125       const QTime t {e->time()};
    126       const int minutes_after_midnight {t.hour()*60 + t.minute()};
    127       setPref(key, minutes_after_midnight);
     183      if (e->isModified ())
     184        setPref (getPrefKey (e), e->text());
    128185    }
    129186}
    130187
    131 QTimeEdit*
    132 PrefsDialog::timeEditNew (int key)
    133 {
    134   const int minutes {myPrefs.getInt(key)};
    135   auto e = new QTimeEdit{};
    136   e->setDisplayFormat(QString::fromUtf8("hh:mm"));
    137   e->setProperty(PREF_KEY, key);
    138   e->setTime(QTime{minutes/60, minutes%60});
    139   myWidgets.insert(key, e);
    140   connect(e, SIGNAL(editingFinished()), this, SLOT(timeEditingFinished()));
    141   return e;
    142 }
    143 
    144 void
    145 PrefsDialog::lineEditingFinished ()
    146 {
    147   QLineEdit * e = qobject_cast<QLineEdit*>(sender());
    148   if (e && e->isModified ())
    149     {
    150       const int key (e->property (PREF_KEY).toInt ());
    151       const QString text (e->text());
    152       setPref (key, text);
    153     }
    154 }
    155 
    156 QLineEdit*
    157 PrefsDialog::lineEditNew (int key, int echoMode)
    158 {
    159   QLineEdit * e = new QLineEdit (myPrefs.getString (key));
    160   e->setProperty (PREF_KEY, key);
    161   e->setEchoMode (QLineEdit::EchoMode (echoMode));
    162   myWidgets.insert (key, e);
    163   connect (e, SIGNAL(editingFinished()), this, SLOT(lineEditingFinished()));
    164   return e;
    165 }
    166 
    167 /***
    168 ****
    169 ***/
    170 
    171 QWidget *
    172 PrefsDialog::createRemoteTab (Session& session)
    173 {
    174   HIG * hig = new HIG (this);
    175   hig->addSectionTitle (tr ("Remote Control"));
    176   QWidget * w;
    177   QHBoxLayout * h = new QHBoxLayout ();
    178   QPushButton * b = new QPushButton (tr ("&Open web client"));
    179   connect (b, SIGNAL(clicked()), &session, SLOT(launchWebInterface()));
    180   h->addWidget (b, 0, Qt::AlignRight);
    181   QWidget * l = checkBoxNew (tr ("Allow &remote access"), Prefs::RPC_ENABLED);
    182   myUnsupportedWhenRemote << l;
    183   hig->addRow (l, h, 0);
    184   l = hig->addRow (tr ("HTTP &port:"), w = spinBoxNew (Prefs::RPC_PORT, 0, 65535, 1));
    185   myWebWidgets << l << w;
    186   hig->addWideControl (w = checkBoxNew (tr ("Use &authentication"), Prefs::RPC_AUTH_REQUIRED));
    187   myWebWidgets << w;
    188   l = hig->addRow (tr ("&Username:"), w = lineEditNew (Prefs::RPC_USERNAME));
    189   myWebAuthWidgets << l << w;
    190   l = hig->addRow (tr ("Pass&word:"), w = lineEditNew (Prefs::RPC_PASSWORD, QLineEdit::Password));
    191   myWebAuthWidgets << l << w;
    192   hig->addWideControl (w = checkBoxNew (tr ("Only allow these IP a&ddresses:"), Prefs::RPC_WHITELIST_ENABLED));
    193   myWebWidgets << w;
    194   l = hig->addRow (tr ("Addresses:"), w = lineEditNew (Prefs::RPC_WHITELIST));
    195   myWebWhitelistWidgets << l << w;
    196   myUnsupportedWhenRemote << myWebWidgets << myWebAuthWidgets << myWebWhitelistWidgets;
    197   hig->finish ();
    198   return hig;
     188/***
     189****
     190***/
     191
     192void
     193PrefsDialog::initRemoteTab ()
     194{
     195  linkWidgetToPref (ui.enableRpcCheck, Prefs::RPC_ENABLED);
     196  linkWidgetToPref (ui.rpcPortSpin, Prefs::RPC_PORT);
     197  linkWidgetToPref (ui.requireRpcAuthCheck, Prefs::RPC_AUTH_REQUIRED);
     198  linkWidgetToPref (ui.rpcUsernameEdit, Prefs::RPC_USERNAME);
     199  linkWidgetToPref (ui.rpcPasswordEdit, Prefs::RPC_PASSWORD);
     200  linkWidgetToPref (ui.enableRpcWhitelistCheck, Prefs::RPC_WHITELIST_ENABLED);
     201  linkWidgetToPref (ui.rpcWhitelistEdit, Prefs::RPC_WHITELIST);
     202
     203  myWebWidgets <<
     204    ui.rpcPortLabel <<
     205    ui.rpcPortSpin <<
     206    ui.requireRpcAuthCheck <<
     207    ui.enableRpcWhitelistCheck;
     208  myWebAuthWidgets <<
     209    ui.rpcUsernameLabel <<
     210    ui.rpcUsernameEdit <<
     211    ui.rpcPasswordLabel <<
     212    ui.rpcPasswordEdit;
     213  myWebWhitelistWidgets <<
     214    ui.rpcWhitelistLabel <<
     215    ui.rpcWhitelistEdit;
     216  myUnsupportedWhenRemote <<
     217    ui.enableRpcCheck <<
     218    myWebWidgets <<
     219    myWebAuthWidgets <<
     220    myWebWhitelistWidgets;
     221
     222  connect (ui.openWebClientButton, SIGNAL (clicked ()), &mySession, SLOT (launchWebInterface ()));
    199223}
    200224
     
    210234}
    211235
    212 
    213 QWidget *
    214 PrefsDialog::createSpeedTab ()
    215 {
    216   QWidget * l;
    217   QSpinBox * r;
    218   HIG * hig = new HIG (this);
    219   hig->addSectionTitle (tr ("Speed Limits"));
     236void
     237PrefsDialog::initSpeedTab ()
     238{
    220239  const QString speed_K_str = Formatter::unitStr (Formatter::SPEED, Formatter::KB);
    221 
    222     l = checkBoxNew (tr ("&Upload:"), Prefs::USPEED_ENABLED);
    223     r = spinBoxNew (Prefs::USPEED, 0, INT_MAX, 5);
    224     r->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
    225     hig->addRow (l, r);
    226     enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), r);
    227 
    228     l = checkBoxNew (tr ("&Download:"), Prefs::DSPEED_ENABLED);
    229     r = spinBoxNew (Prefs::DSPEED, 0, INT_MAX, 5);
    230     r->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
    231     hig->addRow (l, r);
    232     enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), r);
    233 
    234   hig->addSectionDivider ();
    235   QHBoxLayout * h = new QHBoxLayout;
    236   h->setSpacing (HIG::PAD);
    237   QLabel * label = new QLabel;
    238   label->setPixmap (QPixmap (QString::fromUtf8 (":/icons/alt-limit-off.png")));
    239   label->setAlignment (Qt::AlignLeft|Qt::AlignVCenter);
    240   h->addWidget (label);
    241   label = new QLabel (tr ("Alternative Speed Limits"));
    242   label->setStyleSheet (QString::fromUtf8 ("font: bold"));
    243   label->setAlignment (Qt::AlignLeft|Qt::AlignVCenter);
    244   h->addWidget (label);
    245   hig->addSectionTitle (h);
    246 
    247     QString s = tr ("<small>Override normal speed limits manually or at scheduled times</small>");
    248     hig->addWideControl (new QLabel (s));
    249 
    250     s = tr ("U&pload:");
    251     r = spinBoxNew (Prefs::ALT_SPEED_LIMIT_UP, 0, INT_MAX, 5);
    252     r->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
    253     hig->addRow (s, r);
    254 
    255     s = tr ("Do&wnload:");
    256     r = spinBoxNew (Prefs::ALT_SPEED_LIMIT_DOWN, 0, INT_MAX, 5);
    257     r->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
    258     hig->addRow (s, r);
    259 
    260     QCheckBox * c = checkBoxNew (tr ("&Scheduled times:"), Prefs::ALT_SPEED_LIMIT_TIME_ENABLED);
    261     h = new QHBoxLayout ();
    262     h->setSpacing (HIG::PAD);
    263     QWidget * w = timeEditNew (Prefs::ALT_SPEED_LIMIT_TIME_BEGIN);
    264     h->addWidget (w, 1);
    265     mySchedWidgets << w;
    266     QLabel * nd = new QLabel (tr("&to"));
    267     h->addWidget (nd);
    268     mySchedWidgets << nd;
    269     w = timeEditNew (Prefs::ALT_SPEED_LIMIT_TIME_END);
    270     nd->setBuddy (w);
    271     h->addWidget (w, 1);
    272     mySchedWidgets << w;
    273     hig->addRow (c, h, 0);
    274 
    275     s = tr ("&On days:");
    276     QComboBox * box = new QComboBox;
    277     const QIcon noIcon;
    278     box->addItem (noIcon, tr ("Every Day"), QVariant (TR_SCHED_ALL));
    279     box->addItem (noIcon, tr ("Weekdays"),  QVariant (TR_SCHED_WEEKDAY));
    280     box->addItem (noIcon, tr ("Weekends"),  QVariant (TR_SCHED_WEEKEND));
    281     box->addItem (noIcon, tr ("Sunday"),    QVariant (TR_SCHED_SUN));
    282     box->addItem (noIcon, tr ("Monday"),    QVariant (TR_SCHED_MON));
    283     box->addItem (noIcon, tr ("Tuesday"),   QVariant (TR_SCHED_TUES));
    284     box->addItem (noIcon, tr ("Wednesday"), QVariant (TR_SCHED_WED));
    285     box->addItem (noIcon, tr ("Thursday"),  QVariant (TR_SCHED_THURS));
    286     box->addItem (noIcon, tr ("Friday"),    QVariant (TR_SCHED_FRI));
    287     box->addItem (noIcon, tr ("Saturday"),  QVariant (TR_SCHED_SAT));
    288     box->setCurrentIndex (box->findData (myPrefs.getInt (Prefs::ALT_SPEED_LIMIT_TIME_DAY)));
    289     connect (box, SIGNAL(activated(int)), this, SLOT(altSpeedDaysEdited(int)));
    290     w = hig->addRow (s, box);
    291     mySchedWidgets << w << box;
    292 
    293   hig->finish ();
    294   return hig;
    295 }
    296 
    297 /***
    298 ****
    299 ***/
    300 
    301 QWidget *
    302 PrefsDialog::createDesktopTab ()
    303 {
    304   HIG * hig = new HIG (this);
    305   hig->addSectionTitle (tr ("Desktop"));
    306 
    307     hig->addWideControl (checkBoxNew (tr ("Show Transmission icon in the &notification area"), Prefs::SHOW_TRAY_ICON));
    308     hig->addWideControl (checkBoxNew (tr ("Start &minimized in notification area"), Prefs::START_MINIMIZED));
    309 
    310   hig->addSectionDivider ();
    311   hig->addSectionTitle (tr ("Notification"));
    312 
    313     hig->addWideControl (checkBoxNew (tr ("Show a notification when torrents are a&dded"), Prefs::SHOW_NOTIFICATION_ON_ADD));
    314     hig->addWideControl (checkBoxNew (tr ("Show a notification when torrents &finish"), Prefs::SHOW_NOTIFICATION_ON_COMPLETE));
    315     hig->addWideControl (checkBoxNew (tr ("Play a &sound when torrents finish"), Prefs::COMPLETE_SOUND_ENABLED));
    316 
    317   hig->finish ();
    318   return hig;
     240  const QLocale locale;
     241
     242  ui.uploadSpeedLimitSpin->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
     243  ui.downloadSpeedLimitSpin->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
     244  ui.altUploadSpeedLimitSpin->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
     245  ui.altDownloadSpeedLimitSpin->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
     246
     247  ui.altSpeedLimitDaysCombo->addItem (tr ("Every Day"), QVariant (TR_SCHED_ALL));
     248  ui.altSpeedLimitDaysCombo->addItem (tr ("Weekdays"),  QVariant (TR_SCHED_WEEKDAY));
     249  ui.altSpeedLimitDaysCombo->addItem (tr ("Weekends"),  QVariant (TR_SCHED_WEEKEND));
     250  ui.altSpeedLimitDaysCombo->insertSeparator (ui.altSpeedLimitDaysCombo->count ());
     251  for (int i = locale.firstDayOfWeek (); i <= Qt::Sunday; ++i)
     252    ui.altSpeedLimitDaysCombo->addItem (qtDayName (i), qtDayToTrDay (i));
     253  for (int i = Qt::Monday; i < locale.firstDayOfWeek (); ++i)
     254    ui.altSpeedLimitDaysCombo->addItem (qtDayName (i), qtDayToTrDay (i));
     255  ui.altSpeedLimitDaysCombo->setCurrentIndex (ui.altSpeedLimitDaysCombo->findData (myPrefs.getInt (Prefs::ALT_SPEED_LIMIT_TIME_DAY)));
     256
     257  linkWidgetToPref (ui.uploadSpeedLimitCheck, Prefs::USPEED_ENABLED);
     258  linkWidgetToPref (ui.uploadSpeedLimitSpin, Prefs::USPEED);
     259  linkWidgetToPref (ui.downloadSpeedLimitCheck, Prefs::DSPEED_ENABLED);
     260  linkWidgetToPref (ui.downloadSpeedLimitSpin, Prefs::DSPEED);
     261  linkWidgetToPref (ui.altUploadSpeedLimitSpin, Prefs::ALT_SPEED_LIMIT_UP);
     262  linkWidgetToPref (ui.altDownloadSpeedLimitSpin, Prefs::ALT_SPEED_LIMIT_DOWN);
     263  linkWidgetToPref (ui.altSpeedLimitScheduleCheck, Prefs::ALT_SPEED_LIMIT_TIME_ENABLED);
     264  linkWidgetToPref (ui.altSpeedLimitStartTimeEdit, Prefs::ALT_SPEED_LIMIT_TIME_BEGIN);
     265  linkWidgetToPref (ui.altSpeedLimitEndTimeEdit, Prefs::ALT_SPEED_LIMIT_TIME_END);
     266
     267  mySchedWidgets <<
     268    ui.altSpeedLimitStartTimeEdit <<
     269    ui.altSpeedLimitToLabel <<
     270    ui.altSpeedLimitEndTimeEdit <<
     271    ui.altSpeedLimitDaysLabel <<
     272    ui.altSpeedLimitDaysCombo;
     273
     274  ColumnResizer * cr (new ColumnResizer (this));
     275  cr->addLayout (ui.speedLimitsSectionLayout);
     276  cr->addLayout (ui.altSpeedLimitsSectionLayout);
     277  cr->update ();
     278
     279  connect (ui.altSpeedLimitDaysCombo, SIGNAL (activated (int)), SLOT (altSpeedDaysEdited (int)));
     280}
     281
     282/***
     283****
     284***/
     285
     286void
     287PrefsDialog::initDesktopTab ()
     288{
     289  linkWidgetToPref (ui.showTrayIconCheck, Prefs::SHOW_TRAY_ICON);
     290  linkWidgetToPref (ui.startMinimizedCheck, Prefs::START_MINIMIZED);
     291  linkWidgetToPref (ui.notifyOnTorrentAddedCheck, Prefs::SHOW_NOTIFICATION_ON_ADD);
     292  linkWidgetToPref (ui.notifyOnTorrentCompletedCheck, Prefs::SHOW_NOTIFICATION_ON_COMPLETE);
     293  linkWidgetToPref (ui.playSoundOnTorrentCompletedCheck, Prefs::COMPLETE_SOUND_ENABLED);
    319294}
    320295
     
    326301PrefsDialog::onPortTested (bool isOpen)
    327302{
    328   myPortButton->setEnabled (true);
     303  ui.testPeerPortButton->setEnabled (true);
    329304  myWidgets[Prefs::PEER_PORT]->setEnabled (true);
    330   myPortLabel->setText (isOpen ? tr ("Port is <b>open</b>")
    331                                : tr ("Port is <b>closed</b>"));
     305  ui.peerPortStatusLabel->setText (isOpen ? tr ("Port is <b>open</b>")
     306                                          : tr ("Port is <b>closed</b>"));
    332307}
    333308
     
    335310PrefsDialog::onPortTest ()
    336311{
    337   myPortLabel->setText (tr ("Testing TCP Port..."));
    338   myPortButton->setEnabled (false);
     312  ui.peerPortStatusLabel->setText (tr ("Testing TCP Port..."));
     313  ui.testPeerPortButton->setEnabled (false);
    339314  myWidgets[Prefs::PEER_PORT]->setEnabled (false);
    340315  mySession.portTest ();
    341316}
    342317
    343 QWidget *
    344 PrefsDialog::createNetworkTab ()
    345 {
    346   HIG * hig = new HIG (this);
    347   hig->addSectionTitle (tr ("Incoming Peers"));
    348 
    349   QSpinBox * s = spinBoxNew (Prefs::PEER_PORT, 1, 65535, 1);
    350   QHBoxLayout * h = new QHBoxLayout ();
    351   QPushButton * b = myPortButton = new QPushButton (tr ("Te&st Port"));
    352   QLabel * l = myPortLabel = new QLabel (tr ("Status unknown"));
    353   h->addWidget (l);
    354   h->addSpacing (HIG::PAD_BIG);
    355   h->addWidget (b);
    356   h->setStretchFactor (l, 1);
    357   connect (b, SIGNAL(clicked(bool)), this, SLOT(onPortTest()));
    358   connect (&mySession, SIGNAL(portTested(bool)), this, SLOT(onPortTested(bool)));
    359 
    360   hig->addRow (tr ("&Port for incoming connections:"), s);
    361   hig->addRow (QString(), h, 0);
    362   hig->addWideControl (checkBoxNew (tr ("Pick a &random port every time Transmission is started"), Prefs::PEER_PORT_RANDOM_ON_START));
    363   hig->addWideControl (checkBoxNew (tr ("Use UPnP or NAT-PMP port &forwarding from my router"), Prefs::PORT_FORWARDING));
    364 
    365   hig->addSectionDivider ();
    366   hig->addSectionTitle (tr ("Peer Limits"));
    367   hig->addRow (tr ("Maximum peers per &torrent:"), spinBoxNew (Prefs::PEER_LIMIT_TORRENT, 1, FD_SETSIZE, 5));
    368   hig->addRow (tr ("Maximum peers &overall:"), spinBoxNew (Prefs::PEER_LIMIT_GLOBAL, 1, FD_SETSIZE, 5));
    369 
    370   hig->addSectionDivider ();
    371   hig->addSectionTitle (tr ("Options"));
    372 
    373   QWidget * w;
    374   hig->addWideControl (w = checkBoxNew (tr ("Enable &uTP for peer connections"), Prefs::UTP_ENABLED));
    375   w->setToolTip (tr ("uTP is a tool for reducing network congestion."));
    376   hig->addWideControl (w = checkBoxNew (tr ("Use PE&X to find more peers"), Prefs::PEX_ENABLED));
    377   w->setToolTip (tr ("PEX is a tool for exchanging peer lists with the peers you're connected to."));
    378   hig->addWideControl (w = checkBoxNew (tr ("Use &DHT to find more peers"), Prefs::DHT_ENABLED));
    379   w->setToolTip (tr ("DHT is a tool for finding peers without a tracker."));
    380   hig->addWideControl (w = checkBoxNew (tr ("Use &Local Peer Discovery to find more peers"), Prefs::LPD_ENABLED));
    381   w->setToolTip (tr ("LPD is a tool for finding peers on your local network."));
    382 
    383   hig->finish ();
    384   return hig;
     318void
     319PrefsDialog::initNetworkTab ()
     320{
     321  ui.torrentPeerLimitSpin->setRange (1, FD_SETSIZE);
     322  ui.globalPeerLimitSpin->setRange (1, FD_SETSIZE);
     323
     324  linkWidgetToPref (ui.peerPortSpin, Prefs::PEER_PORT);
     325  linkWidgetToPref (ui.randomPeerPortCheck, Prefs::PEER_PORT_RANDOM_ON_START);
     326  linkWidgetToPref (ui.enablePortForwardingCheck, Prefs::PORT_FORWARDING);
     327  linkWidgetToPref (ui.torrentPeerLimitSpin, Prefs::PEER_LIMIT_TORRENT);
     328  linkWidgetToPref (ui.globalPeerLimitSpin, Prefs::PEER_LIMIT_GLOBAL);
     329  linkWidgetToPref (ui.enableUtpCheck, Prefs::UTP_ENABLED);
     330  linkWidgetToPref (ui.enablePexCheck, Prefs::PEX_ENABLED);
     331  linkWidgetToPref (ui.enableDhtCheck, Prefs::DHT_ENABLED);
     332  linkWidgetToPref (ui.enableLpdCheck, Prefs::LPD_ENABLED);
     333
     334  ColumnResizer * cr (new ColumnResizer (this));
     335  cr->addLayout (ui.incomingPeersSectionLayout);
     336  cr->addLayout (ui.peerLimitsSectionLayout);
     337  cr->update ();
     338
     339  connect (ui.testPeerPortButton, SIGNAL (clicked ()), SLOT (onPortTest ()));
     340  connect (&mySession, SIGNAL (portTested (bool)), SLOT (onPortTested (bool)));
    385341}
    386342
     
    432388}
    433389
    434 QWidget *
    435 PrefsDialog::createPrivacyTab ()
    436 {
    437   QWidget * w;
    438   HIG * hig = new HIG (this);
    439 
    440   hig->addSectionTitle (tr ("Encryption"));
    441 
    442   QComboBox * box = new QComboBox ();
    443   box->addItem (tr ("Allow encryption"), 0);
    444   box->addItem (tr ("Prefer encryption"), 1);
    445   box->addItem (tr ("Require encryption"), 2);
    446   myWidgets.insert (Prefs::ENCRYPTION, box);
    447   connect (box, SIGNAL(activated(int)), this, SLOT(encryptionEdited(int)));
    448 
    449   hig->addRow (tr ("&Encryption mode:"), box);
    450 
    451   hig->addSectionDivider ();
    452   hig->addSectionTitle (tr ("Blocklist"));
    453 
    454   QWidget * l = checkBoxNew (tr("Enable &blocklist:"), Prefs::BLOCKLIST_ENABLED);
    455   QWidget * e = lineEditNew (Prefs::BLOCKLIST_URL);
    456   myBlockWidgets << e;
    457   hig->addRow (l, e);
    458 
    459   l = myBlocklistLabel = new QLabel ();
    460   myBlockWidgets << l;
    461   w = new QPushButton (tr ("&Update"));
    462   connect (w, SIGNAL(clicked(bool)), this, SLOT(onUpdateBlocklistClicked()));
    463   myBlockWidgets << w;
    464   QHBoxLayout * h = new QHBoxLayout ();
    465   h->addWidget (l);
    466   h->addStretch (1);
    467   h->addWidget (w);
    468   hig->addWideControl (h);
    469 
    470   l = checkBoxNew (tr ("Enable &automatic updates"), Prefs::BLOCKLIST_UPDATES_ENABLED);
    471   myBlockWidgets << l;
    472   hig->addWideControl (l);
    473 
    474   hig->finish ();
     390void
     391PrefsDialog::initPrivacyTab ()
     392{
     393  ui.encryptionModeCombo->addItem (tr ("Allow encryption"), 0);
     394  ui.encryptionModeCombo->addItem (tr ("Prefer encryption"), 1);
     395  ui.encryptionModeCombo->addItem (tr ("Require encryption"), 2);
     396
     397  linkWidgetToPref (ui.encryptionModeCombo, Prefs::ENCRYPTION);
     398  linkWidgetToPref (ui.blocklistCheck, Prefs::BLOCKLIST_ENABLED);
     399  linkWidgetToPref (ui.blocklistEdit, Prefs::BLOCKLIST_URL);
     400  linkWidgetToPref (ui.autoUpdateBlocklistCheck, Prefs::BLOCKLIST_UPDATES_ENABLED);
     401
     402  myBlockWidgets <<
     403    ui.blocklistEdit <<
     404    ui.blocklistStatusLabel <<
     405    ui.updateBlocklistButton <<
     406    ui.autoUpdateBlocklistCheck;
     407
     408  ColumnResizer * cr (new ColumnResizer (this));
     409  cr->addLayout (ui.encryptionSectionLayout);
     410  cr->addLayout (ui.blocklistSectionLayout);
     411  cr->update ();
     412
     413  connect (ui.encryptionModeCombo, SIGNAL (activated (int)), SLOT (encryptionEdited (int)));
     414  connect (ui.updateBlocklistButton, SIGNAL (clicked ()), SLOT (onUpdateBlocklistClicked ()));
     415
    475416  updateBlocklistLabel ();
    476   return hig;
    477417}
    478418
     
    535475{
    536476  //: Spin box suffix, "Stop seeding if idle for: [ 5 minutes ]" (includes leading space after the number, if needed)
    537   const QString unitsSuffix = tr (" minute(s)", 0, myIdleLimitSpin->value ());
    538   if (myIdleLimitSpin->suffix () != unitsSuffix)
    539     myIdleLimitSpin->setSuffix (unitsSuffix);
    540 }
    541 
    542 QWidget *
    543 PrefsDialog::createSeedingTab ()
    544 {
    545   const int iconSize (style ()->pixelMetric (QStyle::PM_SmallIconSize));
     477  const QString unitsSuffix = tr (" minute(s)", 0, ui.idleLimitSpin->value ());
     478  if (ui.idleLimitSpin->suffix () != unitsSuffix)
     479    ui.idleLimitSpin->setSuffix (unitsSuffix);
     480}
     481
     482void
     483PrefsDialog::initSeedingTab ()
     484{
     485  linkWidgetToPref (ui.ratioLimitCheck, Prefs::RATIO_ENABLED);
     486  linkWidgetToPref (ui.ratioLimitSpin, Prefs::RATIO);
     487  linkWidgetToPref (ui.idleLimitCheck, Prefs::IDLE_LIMIT_ENABLED);
     488  linkWidgetToPref (ui.idleLimitSpin, Prefs::IDLE_LIMIT);
     489
     490  connect (ui.idleLimitSpin, SIGNAL (valueChanged (int)), SLOT (onIdleLimitChanged ()));
     491
     492  onIdleLimitChanged ();
     493}
     494
     495void
     496PrefsDialog::onQueueStalledMinutesChanged ()
     497{
     498  //: Spin box suffix, "Download is inactive if data sharing stopped: [ 5 minutes ago ]" (includes leading space after the number, if needed)
     499  const QString unitsSuffix = tr (" minute(s) ago", 0, ui.queueStalledMinutesSpin->value ());
     500  if (ui.queueStalledMinutesSpin->suffix () != unitsSuffix)
     501    ui.queueStalledMinutesSpin->setSuffix (unitsSuffix);
     502}
     503
     504void
     505PrefsDialog::initDownloadingTab ()
     506{
     507  const QSize iconSize (QSize (1, 1) * style ()->pixelMetric (QStyle::PM_SmallIconSize));
    546508  const QFileIconProvider iconProvider;
    547509  const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
    548   const QPixmap folderPixmap = folderIcon.pixmap (iconSize);
    549510  const QIcon fileIcon = iconProvider.icon (QFileIconProvider::File);
    550   const QPixmap filePixmap = fileIcon.pixmap (iconSize);
    551 
    552   QWidget *l, *r;
    553   HIG * hig = new HIG (this);
    554   hig->addSectionTitle (tr ("Limits"));
    555 
    556     l = checkBoxNew (tr ("Stop seeding at &ratio:"), Prefs::RATIO_ENABLED);
    557     r = doubleSpinBoxNew (Prefs::RATIO, 0, INT_MAX, 0.5, 2);
    558     hig->addRow (l, r);
    559     enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), r);
    560 
    561     l = checkBoxNew (tr ("Stop seedi&ng if idle for:"), Prefs::IDLE_LIMIT_ENABLED);
    562     r = myIdleLimitSpin = spinBoxNew (Prefs::IDLE_LIMIT, 1, INT_MAX, 5);
    563     connect (r, SIGNAL (valueChanged (int)), this, SLOT (onIdleLimitChanged ()));
    564     hig->addRow (l, r);
    565     enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), r);
    566     onIdleLimitChanged ();
    567 
    568   hig->finish ();
    569   return hig;
    570 }
    571 
    572 void
    573 PrefsDialog::onQueueStalledMinutesChanged ()
    574 {
    575   //: Spin box suffix, "Download is inactive if data sharing stopped: [ 5 minutes ago ]" (includes leading space after the number, if needed)
    576   const QString unitsSuffix = tr (" minute(s) ago", 0, myQueueStalledMinutesSpin->value ());
    577   if (myQueueStalledMinutesSpin->suffix () != unitsSuffix)
    578     myQueueStalledMinutesSpin->setSuffix (unitsSuffix);
    579 }
    580 
    581 QWidget *
    582 PrefsDialog::createDownloadingTab ()
    583 {
    584   const int iconSize (style ()->pixelMetric (QStyle::PM_SmallIconSize));
    585   const QFileIconProvider iconProvider;
    586   const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
    587   const QPixmap folderPixmap = folderIcon.pixmap (iconSize);
    588   const QIcon fileIcon = iconProvider.icon (QFileIconProvider::File);
    589   const QPixmap filePixmap = fileIcon.pixmap (iconSize);
    590 
    591   QWidget * l;
    592   QPushButton * b;
    593   HIG * hig = new HIG (this);
    594   hig->addSectionTitle (tr ("Adding"));
    595 
    596     l = checkBoxNew (tr ("Automatically add .torrent files &from:"), Prefs::DIR_WATCH_ENABLED);
    597     b = myWatchButton = new QPushButton;
    598     b->setIcon (folderPixmap);
    599     b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
    600     connect (b, SIGNAL(clicked(bool)), this, SLOT(onWatchClicked()));
    601     hig->addRow (l, b);
    602     enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), b);
    603 
    604     hig->addWideControl (checkBoxNew (tr ("Show the Torrent Options &dialog"), Prefs::OPTIONS_PROMPT));
    605 
    606     hig->addWideControl (checkBoxNew (tr ("&Start added torrents"), Prefs::START));
    607 
    608     hig->addWideControl (checkBoxNew (tr ("Mo&ve the .torrent file to the trash"), Prefs::TRASH_ORIGINAL));
    609 
    610     b = myDestinationButton = new QPushButton;
    611     b->setIcon (folderPixmap);
    612     b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
    613     connect (b, SIGNAL(clicked(bool)), this, SLOT(onDestinationClicked()));
    614     hig->addRow (tr ("Save to &Location:"), b);
    615 
    616     const QString downloadDir (myPrefs.getString(Prefs::DOWNLOAD_DIR));
    617     l = myFreespaceLabel = new FreespaceLabel (this);
    618     myFreespaceLabel->setSession (mySession);
    619     myFreespaceLabel->setPath (downloadDir);
    620     QHBoxLayout * h = new QHBoxLayout ();
    621     h->addStretch (1);
    622     h->addWidget (l);
    623     hig->addWideControl (h);
    624 
    625   hig->addSectionDivider ();
    626   hig->addSectionTitle (tr ("Download Queue"));
    627 
    628     hig->addRow (tr ("Ma&ximum active downloads:"), spinBoxNew (Prefs::DOWNLOAD_QUEUE_SIZE, 1, INT_MAX, 1));
    629     QSpinBox * sb = myQueueStalledMinutesSpin = spinBoxNew (Prefs::QUEUE_STALLED_MINUTES, 1, INT_MAX, 10);
    630     connect (sb, SIGNAL (valueChanged (int)), this, SLOT (onQueueStalledMinutesChanged ()));
    631     //: Please keep this phrase as short as possible, it's curently the longest and influences dialog width
    632     hig->addRow (tr ("Download is i&nactive if data sharing stopped:"), sb);
    633     onQueueStalledMinutesChanged ();
    634 
    635   hig->addSectionDivider ();
    636   hig->addSectionTitle (tr ("Incomplete"));
    637 
    638     hig->addWideControl (checkBoxNew (tr ("Append \".&part\" to incomplete files' names"), Prefs::RENAME_PARTIAL_FILES));
    639 
    640     l = myIncompleteCheckbox = checkBoxNew (tr ("Keep &incomplete files in:"), Prefs::INCOMPLETE_DIR_ENABLED);
    641     b = myIncompleteButton = new QPushButton;
    642     b->setIcon (folderPixmap);
    643     b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
    644     connect (b, SIGNAL(clicked(bool)), this, SLOT(onIncompleteClicked()));
    645     hig->addRow (myIncompleteCheckbox, b);
    646     enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), b);
    647 
    648     l = myTorrentDoneScriptCheckbox = checkBoxNew (tr ("Call scrip&t when torrent is completed:"), Prefs::SCRIPT_TORRENT_DONE_ENABLED);
    649     b = myTorrentDoneScriptButton = new QPushButton;
    650     b->setIcon (filePixmap);
    651     b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
    652     connect (b, SIGNAL(clicked(bool)), this, SLOT(onScriptClicked()));
    653     hig->addRow (myTorrentDoneScriptCheckbox, b);
    654     enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), b);
    655 
    656   hig->finish ();
    657   return hig;
     511
     512  ui.watchDirButton->setIcon (folderIcon);
     513  ui.watchDirButton->setIconSize (iconSize);
     514  ui.downloadDirButton->setIcon (folderIcon);
     515  ui.downloadDirButton->setIconSize (iconSize);
     516  ui.incompleteDirButton->setIcon (folderIcon);
     517  ui.incompleteDirButton->setIconSize (iconSize);
     518  ui.completionScriptButton->setIcon (fileIcon);
     519  ui.completionScriptButton->setIconSize (iconSize);
     520
     521  ui.downloadDirFreeSpaceLabel->setSession (mySession);
     522  ui.downloadDirFreeSpaceLabel->setPath (myPrefs.getString (Prefs::DOWNLOAD_DIR));
     523
     524  linkWidgetToPref (ui.watchDirCheck, Prefs::DIR_WATCH_ENABLED);
     525  linkWidgetToPref (ui.showTorrentOptionsDialogCheck, Prefs::OPTIONS_PROMPT);
     526  linkWidgetToPref (ui.startAddedTorrentsCheck, Prefs::START);
     527  linkWidgetToPref (ui.trashTorrentFileCheck, Prefs::TRASH_ORIGINAL);
     528  linkWidgetToPref (ui.downloadQueueSizeSpin, Prefs::DOWNLOAD_QUEUE_SIZE);
     529  linkWidgetToPref (ui.queueStalledMinutesSpin, Prefs::QUEUE_STALLED_MINUTES);
     530  linkWidgetToPref (ui.renamePartialFilesCheck, Prefs::RENAME_PARTIAL_FILES);
     531  linkWidgetToPref (ui.incompleteDirCheck, Prefs::INCOMPLETE_DIR_ENABLED);
     532  linkWidgetToPref (ui.completionScriptCheck, Prefs::SCRIPT_TORRENT_DONE_ENABLED);
     533
     534  ColumnResizer * cr (new ColumnResizer (this));
     535  cr->addLayout (ui.addingSectionLayout);
     536  cr->addLayout (ui.downloadQueueSectionLayout);
     537  cr->addLayout (ui.incompleteSectionLayout);
     538  cr->update ();
     539
     540  connect (ui.watchDirButton, SIGNAL (clicked ()), SLOT (onWatchClicked ()));
     541  connect (ui.downloadDirButton, SIGNAL (clicked ()), SLOT (onDestinationClicked ()));
     542  connect (ui.incompleteDirButton, SIGNAL (clicked ()), SLOT (onIncompleteClicked ()));
     543  connect (ui.completionScriptButton, SIGNAL (clicked ()), SLOT (onScriptClicked ()));
     544  connect (ui.queueStalledMinutesSpin, SIGNAL (valueChanged (int)), SLOT (onQueueStalledMinutesChanged ()));
     545
     546  onQueueStalledMinutesChanged ();
    658547}
    659548
     
    666555  myIsServer (session.isServer ()),
    667556  mySession (session),
    668   myPrefs (prefs),
    669   myLayout (new QVBoxLayout (this))
    670 {
    671   setWindowTitle (tr ("Transmission Preferences"));
    672 
    673   QTabWidget * t = new QTabWidget (this);
    674   t->addTab (createSpeedTab (),        tr ("Speed"));
    675   t->addTab (createDownloadingTab (),  tr ("Downloading"));
    676   t->addTab (createSeedingTab (),      tr ("Seeding"));
    677   t->addTab (createPrivacyTab (),      tr ("Privacy"));
    678   t->addTab (createNetworkTab (),      tr ("Network"));
    679   t->addTab (createDesktopTab (),      tr ("Desktop"));
    680   t->addTab (createRemoteTab(session), tr ("Remote"));
    681   myLayout->addWidget (t);
    682 
    683   QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Close, Qt::Horizontal, this);
    684   connect (buttons, SIGNAL(rejected()), this, SLOT(close())); // "close" triggers rejected
    685   myLayout->addWidget (buttons);
    686   QWidget::setAttribute (Qt::WA_DeleteOnClose, true);
    687 
    688   connect (&mySession, SIGNAL(sessionUpdated()), this, SLOT(sessionUpdated()));
     557  myPrefs (prefs)
     558{
     559  ui.setupUi (this);
     560
     561  initSpeedTab ();
     562  initDownloadingTab ();
     563  initSeedingTab ();
     564  initPrivacyTab ();
     565  initNetworkTab ();
     566  initDesktopTab ();
     567  initRemoteTab ();
     568
     569  connect (&mySession, SIGNAL (sessionUpdated ()), SLOT (sessionUpdated ()));
    689570
    690571  QList<int> keys;
     
    712593        }
    713594    }
     595
     596  adjustSize ();
    714597}
    715598
     
    739622{
    740623  const int n = mySession.blocklistSize ();
    741   myBlocklistLabel->setText (tr ("<i>Blocklist contains %Ln rule(s)</i>", 0, n));
     624  ui.blocklistStatusLabel->setText (tr ("<i>Blocklist contains %Ln rule(s)</i>", 0, n));
    742625}
    743626
     
    754637          const bool whitelist (myPrefs.getBool (Prefs::RPC_WHITELIST_ENABLED));
    755638          const bool auth (myPrefs.getBool (Prefs::RPC_AUTH_REQUIRED));
    756           foreach (QWidget * w, myWebWhitelistWidgets)w->setEnabled (enabled && whitelist);
    757           foreach (QWidget * w, myWebAuthWidgets)w->setEnabled (enabled && auth);
    758           foreach (QWidget * w, myWebWidgets)w->setEnabled (enabled);
     639          foreach (QWidget * w, myWebWhitelistWidgets)
     640            w->setEnabled (enabled && whitelist);
     641          foreach (QWidget * w, myWebAuthWidgets)
     642            w->setEnabled (enabled && auth);
     643          foreach (QWidget * w, myWebWidgets)
     644            w->setEnabled (enabled);
    759645          break;
    760646        }
     
    763649        {
    764650          const bool enabled = myPrefs.getBool (key);
    765           foreach (QWidget * w, mySchedWidgets)w->setEnabled (enabled);
     651          foreach (QWidget * w, mySchedWidgets)
     652            w->setEnabled (enabled);
    766653          break;
    767654        }
     
    770657        {
    771658          const bool enabled = myPrefs.getBool (key);
    772           foreach (QWidget * w, myBlockWidgets)w->setEnabled (enabled);
     659          foreach (QWidget * w, myBlockWidgets)
     660            w->setEnabled (enabled);
    773661          break;
    774662        }
    775663
    776664      case Prefs::DIR_WATCH:
    777         myWatchButton->setText (QFileInfo(myPrefs.getString(Prefs::DIR_WATCH)).fileName());
     665        ui.watchDirButton->setText (QFileInfo (myPrefs.getString (Prefs::DIR_WATCH)).fileName ());
    778666        break;
    779667
     
    781669        {
    782670          const QString path (myPrefs.getString (key));
    783           myTorrentDoneScriptButton->setText (QFileInfo(path).fileName());
     671          ui.completionScriptButton->setText (QFileInfo (path).fileName ());
    784672          break;
    785673        }
    786674
    787675      case Prefs::PEER_PORT:
    788         myPortLabel->setText (tr ("Status unknown"));
    789         myPortButton->setEnabled (true);
     676        ui.peerPortStatusLabel->setText (tr ("Status unknown"));
     677        ui.testPeerPortButton->setEnabled (true);
    790678        break;
    791679
     
    793681        {
    794682          const QString path (myPrefs.getString (key));
    795           myDestinationButton->setText (QFileInfo(path).fileName());
    796           myFreespaceLabel->setPath (path);
     683          ui.downloadDirButton->setText (QFileInfo (path).fileName ());
     684          ui.downloadDirFreeSpaceLabel->setPath (path);
    797685          break;
    798686        }
     
    801689        {
    802690          QString path (myPrefs.getString (key));
    803           myIncompleteButton->setText (QFileInfo(path).fileName());
    804           break;
    805         }
    806 
    807       case Prefs::INCOMPLETE_DIR_ENABLED:
    808         {
    809           const bool enabled = myPrefs.getBool (key);
    810           myIncompleteButton->setEnabled (enabled);
     691          ui.incompleteDirButton->setText (QFileInfo (path).fileName ());
    811692          break;
    812693        }
     
    820701    {
    821702      QWidget * w (it.value ());
    822       QCheckBox * checkBox;
    823       QSpinBox * spin;
    824       QDoubleSpinBox * doubleSpin;
    825       QTimeEdit * timeEdit;
    826       QLineEdit * lineEdit;
    827 
    828       if ((checkBox = qobject_cast<QCheckBox*>(w)))
     703
     704      if (!updateWidgetValue (w, key))
    829705        {
    830           checkBox->setChecked (myPrefs.getBool (key));
    831         }
    832       else if ((spin = qobject_cast<QSpinBox*>(w)))
    833         {
    834           spin->setValue (myPrefs.getInt (key));
    835         }
    836       else if ((doubleSpin = qobject_cast<QDoubleSpinBox*>(w)))
    837         {
    838           doubleSpin->setValue (myPrefs.getDouble (key));
    839         }
    840       else if ((timeEdit = qobject_cast<QTimeEdit*>(w)))
    841         {
    842           const int minutes (myPrefs.getInt (key));
    843           timeEdit->setTime (QTime().addSecs (minutes * 60));
    844         }
    845       else if ((lineEdit = qobject_cast<QLineEdit*>(w)))
    846         {
    847           lineEdit->setText (myPrefs.getString (key));
    848         }
    849       else if (key == Prefs::ENCRYPTION)
    850         {
    851           QComboBox * comboBox (qobject_cast<QComboBox*> (w));
    852           const int index = comboBox->findData (myPrefs.getInt (key));
    853           comboBox->setCurrentIndex (index);
     706          if (key == Prefs::ENCRYPTION)
     707            {
     708              QComboBox * comboBox (qobject_cast<QComboBox*> (w));
     709              const int index = comboBox->findData (myPrefs.getInt (key));
     710              comboBox->setCurrentIndex (index);
     711            }
    854712        }
    855713    }
    856714}
    857 
    858 bool
    859 PrefsDialog::isAllowed (int key) const
    860 {
    861   Q_UNUSED (key);
    862 
    863   return true;
    864 }
  • trunk/qt/prefs-dialog.h

    r14446 r14460  
    1212
    1313#include <QDialog>
     14#include <QMap>
    1415#include <QSet>
     16
    1517#include "prefs.h"
     18#include "ui_prefs-dialog.h"
    1619
    1720class QAbstractButton;
     
    6366
    6467  private:
    65     QDoubleSpinBox * doubleSpinBoxNew (int key, double low, double high, double step, int decimals);
    66     QCheckBox * checkBoxNew (const QString& text, int key);
    67     QSpinBox * spinBoxNew (int key, int low, int high, int step);
    68     QTimeEdit * timeEditNew (int key);
    69     QLineEdit * lineEditNew (int key, int mode = 0);
    70     void enableBuddyWhenChecked (QCheckBox *, QWidget *);
     68    bool updateWidgetValue (QWidget * widget, int prefKey);
     69    void linkWidgetToPref (QWidget * widget, int prefKey);
    7170    void updateBlocklistLabel ();
    7271
     
    7776  private:
    7877    void setPref (int key, const QVariant& v);
    79     bool isAllowed (int key) const;
    80     QWidget * createDownloadingTab ();
    81     QWidget * createSeedingTab ();
    82     QWidget * createSpeedTab ();
    83     QWidget * createPrivacyTab ();
    84     QWidget * createNetworkTab ();
    85     QWidget * createDesktopTab ();
    86     QWidget * createRemoteTab (Session&);
     78
     79    void initDownloadingTab ();
     80    void initSeedingTab ();
     81    void initSpeedTab ();
     82    void initPrivacyTab ();
     83    void initNetworkTab ();
     84    void initDesktopTab ();
     85    void initRemoteTab ();
    8786
    8887  private:
     
    9291    Session& mySession;
    9392    Prefs& myPrefs;
    94     QVBoxLayout * myLayout;
    95     QLabel * myPortLabel;
    96     QPushButton * myPortButton;
    97     QPushButton * myWatchButton;
    98     QPushButton * myTorrentDoneScriptButton;
    99     QCheckBox * myTorrentDoneScriptCheckbox;
    100     QCheckBox * myIncompleteCheckbox;
    101     QPushButton * myIncompleteButton;
    102     QPushButton * myDestinationButton;
    10393    QWidgetList myWebWidgets;
    10494    QWidgetList myWebAuthWidgets;
     
    10999    QWidgetList myBlockWidgets;
    110100    QWidgetList myUnsupportedWhenRemote;
    111     FreespaceLabel * myFreespaceLabel;
    112     QSpinBox * myIdleLimitSpin;
    113     QSpinBox * myQueueStalledMinutesSpin;
     101    Ui::PrefsDialog ui;
    114102
    115103    int myBlocklistHttpTag;
    116104    QHttp * myBlocklistHttp;
    117105    QMessageBox * myBlocklistDialog;
    118     QLabel * myBlocklistLabel;
    119106};
    120107
  • trunk/qt/qtr.pro

    r14458 r14460  
    5656         make-progress-dialog.ui \
    5757         options.ui \
     58         prefs-dialog.ui \
    5859         relocate.ui \
    5960         session-dialog.ui \
Note: See TracChangeset for help on using the changeset viewer.