Changeset 14462


Ignore:
Timestamp:
Jan 25, 2015, 7:55:05 PM (6 years ago)
Author:
mikedld
Message:

Use TrPathButton? in preferences dialog

Location:
trunk/qt
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/path-button.cc

    r14418 r14462  
    7575{
    7676  return myPath;
     77}
     78
     79QSize
     80TrPathButton::sizeHint () const
     81{
     82  const QSize sh (QToolButton::sizeHint ());
     83  return QSize (qMin (sh.width (), 150), sh.height ());
    7784}
    7885
  • trunk/qt/path-button.h

    r14416 r14462  
    3434    const QString& path () const;
    3535
     36    virtual QSize sizeHint () const;
     37
    3638  signals:
    3739    void pathChanged (const QString& path);
  • trunk/qt/prefs-dialog.cc

    r14460 r14462  
    127127  else if (auto w = qobject_cast<QLineEdit*> (widget))
    128128    w->setText (myPrefs.getString (prefKey));
     129  else if (auto w = qobject_cast<TrPathButton*> (widget))
     130    w->setPath (myPrefs.getString (prefKey));
    129131  else
    130132    return false;
     
    146148  else if (widget->inherits ("QLineEdit"))
    147149    connect (widget, SIGNAL (editingFinished ()), SLOT (lineEditingFinished ()));
     150  else if (widget->inherits ("TrPathButton"))
     151    connect (widget, SIGNAL (pathChanged (QString)), SLOT (pathChanged (QString)));
    148152  else if (widget->inherits ("QAbstractSpinBox"))
    149153    connect (widget, SIGNAL (editingFinished ()), SLOT (spinBoxEditingFinished ()));
     
    184188        setPref (getPrefKey (e), e->text());
    185189    }
     190}
     191
     192void
     193PrefsDialog::pathChanged (const QString& path)
     194{
     195  if (auto b = qobject_cast<const TrPathButton*> (sender ()))
     196    setPref(getPrefKey (b), path);
    186197}
    187198
     
    422433
    423434void
    424 PrefsDialog::onScriptClicked ()
    425 {
    426   const QString title = tr ("Select \"Torrent Done\" Script");
    427   const QString myPath = myPrefs.getString (Prefs::SCRIPT_TORRENT_DONE_FILENAME);
    428   const QString path = Utils::remoteFileChooser (this, title, myPath, false, mySession.isServer());
    429 
    430   if (!path.isEmpty())
    431     onLocationSelected (path, Prefs::SCRIPT_TORRENT_DONE_FILENAME);
    432 }
    433 
    434 void
    435 PrefsDialog::onIncompleteClicked ()
    436 {
    437   const QString title = tr ("Select Incomplete Directory");
    438   const QString myPath = myPrefs.getString (Prefs::INCOMPLETE_DIR);
    439   const QString path = Utils::remoteFileChooser (this, title, myPath, true, mySession.isServer());
    440 
    441   if (!path.isEmpty())
    442     onLocationSelected (path, Prefs::INCOMPLETE_DIR);
    443 }
    444 
    445 void
    446 PrefsDialog::onWatchClicked ()
    447 {
    448   const QString title = tr ("Select Watch Directory");
    449   const QString myPath = myPrefs.getString (Prefs::DIR_WATCH);
    450   const QString path = Utils::remoteFileChooser (this, title, myPath, true, true);
    451 
    452   if (!path.isEmpty())
    453     onLocationSelected (path, Prefs::DIR_WATCH);
    454 }
    455 
    456 void
    457 PrefsDialog::onDestinationClicked ()
    458 {
    459   const QString title = tr ("Select Destination");
    460   const QString myPath = myPrefs.getString (Prefs::DOWNLOAD_DIR);
    461   const QString path = Utils::remoteFileChooser (this, title, myPath, true, mySession.isServer());
    462 
    463   if (!path.isEmpty())
    464     onLocationSelected (path, Prefs::DOWNLOAD_DIR);
    465 }
    466 
    467 void
    468 PrefsDialog::onLocationSelected (const QString& path, int key)
    469 {
    470   setPref (key, path);
    471 }
    472 
    473 void
    474435PrefsDialog::onIdleLimitChanged ()
    475436{
     
    505466PrefsDialog::initDownloadingTab ()
    506467{
    507   const QSize iconSize (QSize (1, 1) * style ()->pixelMetric (QStyle::PM_SmallIconSize));
    508   const QFileIconProvider iconProvider;
    509   const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
    510   const QIcon fileIcon = iconProvider.icon (QFileIconProvider::File);
    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);
     468  if (mySession.isLocal ())
     469    {
     470      ui.watchDirStack->setCurrentWidget (ui.watchDirButton);
     471      ui.downloadDirStack->setCurrentWidget (ui.downloadDirButton);
     472      ui.incompleteDirStack->setCurrentWidget (ui.incompleteDirButton);
     473      ui.completionScriptStack->setCurrentWidget (ui.completionScriptButton);
     474
     475      ui.watchDirButton->setMode (TrPathButton::DirectoryMode);
     476      ui.downloadDirButton->setMode (TrPathButton::DirectoryMode);
     477      ui.incompleteDirButton->setMode (TrPathButton::DirectoryMode);
     478      ui.completionScriptButton->setMode (TrPathButton::FileMode);
     479
     480      ui.watchDirButton->setTitle (tr ("Select Watch Directory"));
     481      ui.downloadDirButton->setTitle (tr ("Select Destination"));
     482      ui.incompleteDirButton->setTitle (tr ("Select Incomplete Directory"));
     483      ui.completionScriptButton->setTitle (tr ("Select \"Torrent Done\" Script"));
     484    }
     485  else
     486    {
     487      ui.watchDirStack->setCurrentWidget (ui.watchDirEdit);
     488      ui.downloadDirStack->setCurrentWidget (ui.downloadDirEdit);
     489      ui.incompleteDirStack->setCurrentWidget (ui.incompleteDirEdit);
     490      ui.completionScriptStack->setCurrentWidget (ui.completionScriptEdit);
     491    }
     492
     493  ui.watchDirStack->setFixedHeight (ui.watchDirStack->currentWidget ()->sizeHint ().height ());
     494  ui.downloadDirStack->setFixedHeight (ui.downloadDirStack->currentWidget ()->sizeHint ().height ());
     495  ui.incompleteDirStack->setFixedHeight (ui.incompleteDirStack->currentWidget ()->sizeHint ().height ());
     496  ui.completionScriptStack->setFixedHeight (ui.completionScriptStack->currentWidget ()->sizeHint ().height ());
     497
     498  ui.watchDirStack->setMinimumWidth (200);
     499
     500  ui.downloadDirLabel->setBuddy (ui.downloadDirStack->currentWidget ());
    520501
    521502  ui.downloadDirFreeSpaceLabel->setSession (mySession);
     
    523504
    524505  linkWidgetToPref (ui.watchDirCheck, Prefs::DIR_WATCH_ENABLED);
     506  linkWidgetToPref (ui.watchDirStack->currentWidget (), Prefs::DIR_WATCH);
    525507  linkWidgetToPref (ui.showTorrentOptionsDialogCheck, Prefs::OPTIONS_PROMPT);
    526508  linkWidgetToPref (ui.startAddedTorrentsCheck, Prefs::START);
    527509  linkWidgetToPref (ui.trashTorrentFileCheck, Prefs::TRASH_ORIGINAL);
     510  linkWidgetToPref (ui.downloadDirStack->currentWidget (), Prefs::DOWNLOAD_DIR);
    528511  linkWidgetToPref (ui.downloadQueueSizeSpin, Prefs::DOWNLOAD_QUEUE_SIZE);
    529512  linkWidgetToPref (ui.queueStalledMinutesSpin, Prefs::QUEUE_STALLED_MINUTES);
    530513  linkWidgetToPref (ui.renamePartialFilesCheck, Prefs::RENAME_PARTIAL_FILES);
    531514  linkWidgetToPref (ui.incompleteDirCheck, Prefs::INCOMPLETE_DIR_ENABLED);
     515  linkWidgetToPref (ui.incompleteDirStack->currentWidget (), Prefs::INCOMPLETE_DIR);
    532516  linkWidgetToPref (ui.completionScriptCheck, Prefs::SCRIPT_TORRENT_DONE_ENABLED);
     517  linkWidgetToPref (ui.completionScriptStack->currentWidget (), Prefs::SCRIPT_TORRENT_DONE_FILENAME);
    533518
    534519  ColumnResizer * cr (new ColumnResizer (this));
     
    538523  cr->update ();
    539524
    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 ()));
    544525  connect (ui.queueStalledMinutesSpin, SIGNAL (valueChanged (int)), SLOT (onQueueStalledMinutesChanged ()));
    545526
  • trunk/qt/prefs-dialog.h

    r14460 r14462  
    4646    void timeEditingFinished ();
    4747    void lineEditingFinished ();
     48    void pathChanged (const QString& path);
    4849    void refreshPref (int key);
    4950    void encryptionEdited (int);
    5051    void altSpeedDaysEdited (int);
    5152    void sessionUpdated ();
    52     void onWatchClicked ();
    53     void onScriptClicked ();
    54     void onIncompleteClicked ();
    55     void onDestinationClicked ();
    56     void onLocationSelected (const QString&, int key);
    5753    void onPortTested (bool);
    5854    void onPortTest ();
  • trunk/qt/prefs-dialog.ui

    r14461 r14462  
    285285         </item>
    286286         <item row="0" column="1">
    287           <widget class="QToolButton" name="watchDirButton">
     287          <widget class="QStackedWidget" name="watchDirStack">
    288288           <property name="sizePolicy">
    289             <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
     289            <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
    290290             <horstretch>0</horstretch>
    291291             <verstretch>0</verstretch>
    292292            </sizepolicy>
    293293           </property>
    294            <property name="toolButtonStyle">
    295             <enum>Qt::ToolButtonTextBesideIcon</enum>
    296            </property>
     294           <widget class="TrPathButton" name="watchDirButton"/>
     295           <widget class="QLineEdit" name="watchDirEdit"/>
    297296          </widget>
    298297         </item>
     
    323322            <string>Save to &amp;Location:</string>
    324323           </property>
    325            <property name="buddy">
    326             <cstring>downloadDirButton</cstring>
    327            </property>
    328324          </widget>
    329325         </item>
    330326         <item row="4" column="1">
    331           <widget class="QToolButton" name="downloadDirButton">
     327          <widget class="QStackedWidget" name="downloadDirStack">
    332328           <property name="sizePolicy">
    333             <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
     329            <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
    334330             <horstretch>0</horstretch>
    335331             <verstretch>0</verstretch>
    336332            </sizepolicy>
    337333           </property>
    338            <property name="toolButtonStyle">
    339             <enum>Qt::ToolButtonTextBesideIcon</enum>
    340            </property>
     334           <widget class="TrPathButton" name="downloadDirButton"/>
     335           <widget class="QLineEdit" name="downloadDirEdit"/>
    341336          </widget>
    342337         </item>
     
    395390         </item>
    396391         <item row="0" column="1">
    397           <widget class="QSpinBox" name="downloadQueueSizeSpin"/>
     392          <widget class="QSpinBox" name="downloadQueueSizeSpin">
     393           <property name="minimum">
     394            <number>1</number>
     395           </property>
     396           <property name="maximum">
     397            <number>999999999</number>
     398           </property>
     399          </widget>
    398400         </item>
    399401         <item row="1" column="0">
     
    411413           <property name="suffix">
    412414            <string notr="true"> minute(s) ago</string>
     415           </property>
     416           <property name="minimum">
     417            <number>1</number>
     418           </property>
     419           <property name="maximum">
     420            <number>9999</number>
     421           </property>
     422           <property name="singleStep">
     423            <number>5</number>
    413424           </property>
    414425          </widget>
     
    465476         </item>
    466477         <item row="1" column="1">
    467           <widget class="QToolButton" name="incompleteDirButton">
     478          <widget class="QStackedWidget" name="incompleteDirStack">
    468479           <property name="sizePolicy">
    469             <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
     480            <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
    470481             <horstretch>0</horstretch>
    471482             <verstretch>0</verstretch>
    472483            </sizepolicy>
    473484           </property>
    474            <property name="toolButtonStyle">
    475             <enum>Qt::ToolButtonTextBesideIcon</enum>
    476            </property>
     485           <widget class="TrPathButton" name="incompleteDirButton"/>
     486           <widget class="QLineEdit" name="incompleteDirEdit"/>
    477487          </widget>
    478488         </item>
     
    488498         </item>
    489499         <item row="2" column="1">
    490           <widget class="QToolButton" name="completionScriptButton">
     500          <widget class="QStackedWidget" name="completionScriptStack">
    491501           <property name="sizePolicy">
    492             <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
     502            <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
    493503             <horstretch>0</horstretch>
    494504             <verstretch>0</verstretch>
    495505            </sizepolicy>
    496506           </property>
    497            <property name="toolButtonStyle">
    498             <enum>Qt::ToolButtonTextBesideIcon</enum>
    499            </property>
     507           <widget class="TrPathButton" name="completionScriptButton"/>
     508           <widget class="QLineEdit" name="completionScriptEdit"/>
    500509          </widget>
    501510         </item>
     
    12201229 </widget>
    12211230 <customwidgets>
     1231  <customwidget>
     1232   <class>TrPathButton</class>
     1233   <extends>QToolButton</extends>
     1234   <header>path-button.h</header>
     1235  </customwidget>
    12221236  <customwidget>
    12231237   <class>FreespaceLabel</class>
     
    13131327   <sender>watchDirCheck</sender>
    13141328   <signal>toggled(bool)</signal>
    1315    <receiver>watchDirButton</receiver>
     1329   <receiver>watchDirStack</receiver>
    13161330   <slot>setEnabled(bool)</slot>
    13171331   <hints>
     
    13291343   <sender>incompleteDirCheck</sender>
    13301344   <signal>toggled(bool)</signal>
    1331    <receiver>incompleteDirButton</receiver>
     1345   <receiver>incompleteDirStack</receiver>
    13321346   <slot>setEnabled(bool)</slot>
    13331347   <hints>
     
    13451359   <sender>completionScriptCheck</sender>
    13461360   <signal>toggled(bool)</signal>
    1347    <receiver>completionScriptButton</receiver>
     1361   <receiver>completionScriptStack</receiver>
    13481362   <slot>setEnabled(bool)</slot>
    13491363   <hints>
  • trunk/qt/utils.cc

    r14428 r14462  
    4444extern QPixmap qt_pixmapFromWinHICON(HICON icon);
    4545#endif
    46 
    47 QString
    48 Utils::remoteFileChooser (QWidget * parent, const QString& title, const QString& myPath, bool dir, bool local)
    49 {
    50   QString path;
    51 
    52   if (local)
    53     {
    54       if (dir)
    55         path = QFileDialog::getExistingDirectory (parent, title, myPath);
    56       else
    57         path = QFileDialog::getOpenFileName (parent, title, myPath);
    58     }
    59   else
    60     {
    61       path = QInputDialog::getText (parent, title, tr ("Enter a location:"), QLineEdit::Normal, myPath, NULL);
    62     }
    63 
    64   return path;
    65 }
    6646
    6747void
  • trunk/qt/utils.h

    r14454 r14462  
    2929
    3030  public:
    31     static QString remoteFileChooser (QWidget * parent, const QString& title, const QString& myPath, bool dir, bool local);
    3231    static QIcon guessMimeIcon (const QString& filename);
    3332    // Test if string is UTF-8 or not
Note: See TracChangeset for help on using the changeset viewer.