Use TrPathButton in preferences dialog

This commit is contained in:
Mike Gelfand 2015-01-25 19:55:05 +00:00
parent cade70172e
commit 6b79473d9f
7 changed files with 98 additions and 119 deletions

View File

@ -76,6 +76,13 @@ TrPathButton::path () const
return myPath; return myPath;
} }
QSize
TrPathButton::sizeHint () const
{
const QSize sh (QToolButton::sizeHint ());
return QSize (qMin (sh.width (), 150), sh.height ());
}
void void
TrPathButton::paintEvent (QPaintEvent * /*event*/) TrPathButton::paintEvent (QPaintEvent * /*event*/)
{ {

View File

@ -33,6 +33,8 @@ class TrPathButton: public QToolButton
void setPath (const QString& path); void setPath (const QString& path);
const QString& path () const; const QString& path () const;
virtual QSize sizeHint () const;
signals: signals:
void pathChanged (const QString& path); void pathChanged (const QString& path);

View File

@ -126,6 +126,8 @@ PrefsDialog::updateWidgetValue (QWidget * widget, int prefKey)
w->setTime (QTime ().addSecs (myPrefs.getInt(prefKey) * 60)); w->setTime (QTime ().addSecs (myPrefs.getInt(prefKey) * 60));
else if (auto w = qobject_cast<QLineEdit*> (widget)) else if (auto w = qobject_cast<QLineEdit*> (widget))
w->setText (myPrefs.getString (prefKey)); w->setText (myPrefs.getString (prefKey));
else if (auto w = qobject_cast<TrPathButton*> (widget))
w->setPath (myPrefs.getString (prefKey));
else else
return false; return false;
@ -145,6 +147,8 @@ PrefsDialog::linkWidgetToPref (QWidget * widget, int prefKey)
connect (widget, SIGNAL (editingFinished ()), SLOT (timeEditingFinished ())); connect (widget, SIGNAL (editingFinished ()), SLOT (timeEditingFinished ()));
else if (widget->inherits ("QLineEdit")) else if (widget->inherits ("QLineEdit"))
connect (widget, SIGNAL (editingFinished ()), SLOT (lineEditingFinished ())); connect (widget, SIGNAL (editingFinished ()), SLOT (lineEditingFinished ()));
else if (widget->inherits ("TrPathButton"))
connect (widget, SIGNAL (pathChanged (QString)), SLOT (pathChanged (QString)));
else if (widget->inherits ("QAbstractSpinBox")) else if (widget->inherits ("QAbstractSpinBox"))
connect (widget, SIGNAL (editingFinished ()), SLOT (spinBoxEditingFinished ())); connect (widget, SIGNAL (editingFinished ()), SLOT (spinBoxEditingFinished ()));
} }
@ -185,6 +189,13 @@ PrefsDialog::lineEditingFinished ()
} }
} }
void
PrefsDialog::pathChanged (const QString& path)
{
if (auto b = qobject_cast<const TrPathButton*> (sender ()))
setPref(getPrefKey (b), path);
}
/*** /***
**** ****
***/ ***/
@ -420,56 +431,6 @@ PrefsDialog::initPrivacyTab ()
**** ****
***/ ***/
void
PrefsDialog::onScriptClicked ()
{
const QString title = tr ("Select \"Torrent Done\" Script");
const QString myPath = myPrefs.getString (Prefs::SCRIPT_TORRENT_DONE_FILENAME);
const QString path = Utils::remoteFileChooser (this, title, myPath, false, mySession.isServer());
if (!path.isEmpty())
onLocationSelected (path, Prefs::SCRIPT_TORRENT_DONE_FILENAME);
}
void
PrefsDialog::onIncompleteClicked ()
{
const QString title = tr ("Select Incomplete Directory");
const QString myPath = myPrefs.getString (Prefs::INCOMPLETE_DIR);
const QString path = Utils::remoteFileChooser (this, title, myPath, true, mySession.isServer());
if (!path.isEmpty())
onLocationSelected (path, Prefs::INCOMPLETE_DIR);
}
void
PrefsDialog::onWatchClicked ()
{
const QString title = tr ("Select Watch Directory");
const QString myPath = myPrefs.getString (Prefs::DIR_WATCH);
const QString path = Utils::remoteFileChooser (this, title, myPath, true, true);
if (!path.isEmpty())
onLocationSelected (path, Prefs::DIR_WATCH);
}
void
PrefsDialog::onDestinationClicked ()
{
const QString title = tr ("Select Destination");
const QString myPath = myPrefs.getString (Prefs::DOWNLOAD_DIR);
const QString path = Utils::remoteFileChooser (this, title, myPath, true, mySession.isServer());
if (!path.isEmpty())
onLocationSelected (path, Prefs::DOWNLOAD_DIR);
}
void
PrefsDialog::onLocationSelected (const QString& path, int key)
{
setPref (key, path);
}
void void
PrefsDialog::onIdleLimitChanged () PrefsDialog::onIdleLimitChanged ()
{ {
@ -504,32 +465,56 @@ PrefsDialog::onQueueStalledMinutesChanged ()
void void
PrefsDialog::initDownloadingTab () PrefsDialog::initDownloadingTab ()
{ {
const QSize iconSize (QSize (1, 1) * style ()->pixelMetric (QStyle::PM_SmallIconSize)); if (mySession.isLocal ())
const QFileIconProvider iconProvider; {
const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder); ui.watchDirStack->setCurrentWidget (ui.watchDirButton);
const QIcon fileIcon = iconProvider.icon (QFileIconProvider::File); ui.downloadDirStack->setCurrentWidget (ui.downloadDirButton);
ui.incompleteDirStack->setCurrentWidget (ui.incompleteDirButton);
ui.completionScriptStack->setCurrentWidget (ui.completionScriptButton);
ui.watchDirButton->setIcon (folderIcon); ui.watchDirButton->setMode (TrPathButton::DirectoryMode);
ui.watchDirButton->setIconSize (iconSize); ui.downloadDirButton->setMode (TrPathButton::DirectoryMode);
ui.downloadDirButton->setIcon (folderIcon); ui.incompleteDirButton->setMode (TrPathButton::DirectoryMode);
ui.downloadDirButton->setIconSize (iconSize); ui.completionScriptButton->setMode (TrPathButton::FileMode);
ui.incompleteDirButton->setIcon (folderIcon);
ui.incompleteDirButton->setIconSize (iconSize); ui.watchDirButton->setTitle (tr ("Select Watch Directory"));
ui.completionScriptButton->setIcon (fileIcon); ui.downloadDirButton->setTitle (tr ("Select Destination"));
ui.completionScriptButton->setIconSize (iconSize); ui.incompleteDirButton->setTitle (tr ("Select Incomplete Directory"));
ui.completionScriptButton->setTitle (tr ("Select \"Torrent Done\" Script"));
}
else
{
ui.watchDirStack->setCurrentWidget (ui.watchDirEdit);
ui.downloadDirStack->setCurrentWidget (ui.downloadDirEdit);
ui.incompleteDirStack->setCurrentWidget (ui.incompleteDirEdit);
ui.completionScriptStack->setCurrentWidget (ui.completionScriptEdit);
}
ui.watchDirStack->setFixedHeight (ui.watchDirStack->currentWidget ()->sizeHint ().height ());
ui.downloadDirStack->setFixedHeight (ui.downloadDirStack->currentWidget ()->sizeHint ().height ());
ui.incompleteDirStack->setFixedHeight (ui.incompleteDirStack->currentWidget ()->sizeHint ().height ());
ui.completionScriptStack->setFixedHeight (ui.completionScriptStack->currentWidget ()->sizeHint ().height ());
ui.watchDirStack->setMinimumWidth (200);
ui.downloadDirLabel->setBuddy (ui.downloadDirStack->currentWidget ());
ui.downloadDirFreeSpaceLabel->setSession (mySession); ui.downloadDirFreeSpaceLabel->setSession (mySession);
ui.downloadDirFreeSpaceLabel->setPath (myPrefs.getString (Prefs::DOWNLOAD_DIR)); ui.downloadDirFreeSpaceLabel->setPath (myPrefs.getString (Prefs::DOWNLOAD_DIR));
linkWidgetToPref (ui.watchDirCheck, Prefs::DIR_WATCH_ENABLED); linkWidgetToPref (ui.watchDirCheck, Prefs::DIR_WATCH_ENABLED);
linkWidgetToPref (ui.watchDirStack->currentWidget (), Prefs::DIR_WATCH);
linkWidgetToPref (ui.showTorrentOptionsDialogCheck, Prefs::OPTIONS_PROMPT); linkWidgetToPref (ui.showTorrentOptionsDialogCheck, Prefs::OPTIONS_PROMPT);
linkWidgetToPref (ui.startAddedTorrentsCheck, Prefs::START); linkWidgetToPref (ui.startAddedTorrentsCheck, Prefs::START);
linkWidgetToPref (ui.trashTorrentFileCheck, Prefs::TRASH_ORIGINAL); linkWidgetToPref (ui.trashTorrentFileCheck, Prefs::TRASH_ORIGINAL);
linkWidgetToPref (ui.downloadDirStack->currentWidget (), Prefs::DOWNLOAD_DIR);
linkWidgetToPref (ui.downloadQueueSizeSpin, Prefs::DOWNLOAD_QUEUE_SIZE); linkWidgetToPref (ui.downloadQueueSizeSpin, Prefs::DOWNLOAD_QUEUE_SIZE);
linkWidgetToPref (ui.queueStalledMinutesSpin, Prefs::QUEUE_STALLED_MINUTES); linkWidgetToPref (ui.queueStalledMinutesSpin, Prefs::QUEUE_STALLED_MINUTES);
linkWidgetToPref (ui.renamePartialFilesCheck, Prefs::RENAME_PARTIAL_FILES); linkWidgetToPref (ui.renamePartialFilesCheck, Prefs::RENAME_PARTIAL_FILES);
linkWidgetToPref (ui.incompleteDirCheck, Prefs::INCOMPLETE_DIR_ENABLED); linkWidgetToPref (ui.incompleteDirCheck, Prefs::INCOMPLETE_DIR_ENABLED);
linkWidgetToPref (ui.incompleteDirStack->currentWidget (), Prefs::INCOMPLETE_DIR);
linkWidgetToPref (ui.completionScriptCheck, Prefs::SCRIPT_TORRENT_DONE_ENABLED); linkWidgetToPref (ui.completionScriptCheck, Prefs::SCRIPT_TORRENT_DONE_ENABLED);
linkWidgetToPref (ui.completionScriptStack->currentWidget (), Prefs::SCRIPT_TORRENT_DONE_FILENAME);
ColumnResizer * cr (new ColumnResizer (this)); ColumnResizer * cr (new ColumnResizer (this));
cr->addLayout (ui.addingSectionLayout); cr->addLayout (ui.addingSectionLayout);
@ -537,10 +522,6 @@ PrefsDialog::initDownloadingTab ()
cr->addLayout (ui.incompleteSectionLayout); cr->addLayout (ui.incompleteSectionLayout);
cr->update (); 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 ())); connect (ui.queueStalledMinutesSpin, SIGNAL (valueChanged (int)), SLOT (onQueueStalledMinutesChanged ()));
onQueueStalledMinutesChanged (); onQueueStalledMinutesChanged ();

View File

@ -45,15 +45,11 @@ class PrefsDialog: public QDialog
void spinBoxEditingFinished (); void spinBoxEditingFinished ();
void timeEditingFinished (); void timeEditingFinished ();
void lineEditingFinished (); void lineEditingFinished ();
void pathChanged (const QString& path);
void refreshPref (int key); void refreshPref (int key);
void encryptionEdited (int); void encryptionEdited (int);
void altSpeedDaysEdited (int); void altSpeedDaysEdited (int);
void sessionUpdated (); void sessionUpdated ();
void onWatchClicked ();
void onScriptClicked ();
void onIncompleteClicked ();
void onDestinationClicked ();
void onLocationSelected (const QString&, int key);
void onPortTested (bool); void onPortTested (bool);
void onPortTest (); void onPortTest ();
void onIdleLimitChanged (); void onIdleLimitChanged ();

View File

@ -284,16 +284,15 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QToolButton" name="watchDirButton"> <widget class="QStackedWidget" name="watchDirStack">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolButtonStyle"> <widget class="TrPathButton" name="watchDirButton"/>
<enum>Qt::ToolButtonTextBesideIcon</enum> <widget class="QLineEdit" name="watchDirEdit"/>
</property>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="2"> <item row="1" column="0" colspan="2">
@ -322,22 +321,18 @@
<property name="text"> <property name="text">
<string>Save to &amp;Location:</string> <string>Save to &amp;Location:</string>
</property> </property>
<property name="buddy">
<cstring>downloadDirButton</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="4" column="1">
<widget class="QToolButton" name="downloadDirButton"> <widget class="QStackedWidget" name="downloadDirStack">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolButtonStyle"> <widget class="TrPathButton" name="downloadDirButton"/>
<enum>Qt::ToolButtonTextBesideIcon</enum> <widget class="QLineEdit" name="downloadDirEdit"/>
</property>
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="5" column="1">
@ -394,7 +389,14 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QSpinBox" name="downloadQueueSizeSpin"/> <widget class="QSpinBox" name="downloadQueueSizeSpin">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999999999</number>
</property>
</widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="queueStalledMinutesLabel"> <widget class="QLabel" name="queueStalledMinutesLabel">
@ -411,6 +413,15 @@
<property name="suffix"> <property name="suffix">
<string notr="true"> minute(s) ago</string> <string notr="true"> minute(s) ago</string>
</property> </property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
<property name="singleStep">
<number>5</number>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -464,16 +475,15 @@
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QToolButton" name="incompleteDirButton"> <widget class="QStackedWidget" name="incompleteDirStack">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolButtonStyle"> <widget class="TrPathButton" name="incompleteDirButton"/>
<enum>Qt::ToolButtonTextBesideIcon</enum> <widget class="QLineEdit" name="incompleteDirEdit"/>
</property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
@ -487,16 +497,15 @@
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QToolButton" name="completionScriptButton"> <widget class="QStackedWidget" name="completionScriptStack">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolButtonStyle"> <widget class="TrPathButton" name="completionScriptButton"/>
<enum>Qt::ToolButtonTextBesideIcon</enum> <widget class="QLineEdit" name="completionScriptEdit"/>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -1219,6 +1228,11 @@
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget>
<class>TrPathButton</class>
<extends>QToolButton</extends>
<header>path-button.h</header>
</customwidget>
<customwidget> <customwidget>
<class>FreespaceLabel</class> <class>FreespaceLabel</class>
<extends>QLabel</extends> <extends>QLabel</extends>
@ -1312,7 +1326,7 @@
<connection> <connection>
<sender>watchDirCheck</sender> <sender>watchDirCheck</sender>
<signal>toggled(bool)</signal> <signal>toggled(bool)</signal>
<receiver>watchDirButton</receiver> <receiver>watchDirStack</receiver>
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
@ -1328,7 +1342,7 @@
<connection> <connection>
<sender>incompleteDirCheck</sender> <sender>incompleteDirCheck</sender>
<signal>toggled(bool)</signal> <signal>toggled(bool)</signal>
<receiver>incompleteDirButton</receiver> <receiver>incompleteDirStack</receiver>
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
@ -1344,7 +1358,7 @@
<connection> <connection>
<sender>completionScriptCheck</sender> <sender>completionScriptCheck</sender>
<signal>toggled(bool)</signal> <signal>toggled(bool)</signal>
<receiver>completionScriptButton</receiver> <receiver>completionScriptStack</receiver>
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">

View File

@ -44,26 +44,6 @@
extern QPixmap qt_pixmapFromWinHICON(HICON icon); extern QPixmap qt_pixmapFromWinHICON(HICON icon);
#endif #endif
QString
Utils::remoteFileChooser (QWidget * parent, const QString& title, const QString& myPath, bool dir, bool local)
{
QString path;
if (local)
{
if (dir)
path = QFileDialog::getExistingDirectory (parent, title, myPath);
else
path = QFileDialog::getOpenFileName (parent, title, myPath);
}
else
{
path = QInputDialog::getText (parent, title, tr ("Enter a location:"), QLineEdit::Normal, myPath, NULL);
}
return path;
}
void void
Utils::toStderr (const QString& str) Utils::toStderr (const QString& str)
{ {

View File

@ -28,7 +28,6 @@ class Utils: public QObject
virtual ~Utils () {} virtual ~Utils () {}
public: public:
static QString remoteFileChooser (QWidget * parent, const QString& title, const QString& myPath, bool dir, bool local);
static QIcon guessMimeIcon (const QString& filename); static QIcon guessMimeIcon (const QString& filename);
// Test if string is UTF-8 or not // Test if string is UTF-8 or not
static bool isValidUtf8 (const char *s); static bool isValidUtf8 (const char *s);