Use TrPathButton in preferences dialog
This commit is contained in:
parent
cade70172e
commit
6b79473d9f
|
@ -76,6 +76,13 @@ TrPathButton::path () const
|
|||
return myPath;
|
||||
}
|
||||
|
||||
QSize
|
||||
TrPathButton::sizeHint () const
|
||||
{
|
||||
const QSize sh (QToolButton::sizeHint ());
|
||||
return QSize (qMin (sh.width (), 150), sh.height ());
|
||||
}
|
||||
|
||||
void
|
||||
TrPathButton::paintEvent (QPaintEvent * /*event*/)
|
||||
{
|
||||
|
|
|
@ -33,6 +33,8 @@ class TrPathButton: public QToolButton
|
|||
void setPath (const QString& path);
|
||||
const QString& path () const;
|
||||
|
||||
virtual QSize sizeHint () const;
|
||||
|
||||
signals:
|
||||
void pathChanged (const QString& path);
|
||||
|
||||
|
|
|
@ -126,6 +126,8 @@ PrefsDialog::updateWidgetValue (QWidget * widget, int prefKey)
|
|||
w->setTime (QTime ().addSecs (myPrefs.getInt(prefKey) * 60));
|
||||
else if (auto w = qobject_cast<QLineEdit*> (widget))
|
||||
w->setText (myPrefs.getString (prefKey));
|
||||
else if (auto w = qobject_cast<TrPathButton*> (widget))
|
||||
w->setPath (myPrefs.getString (prefKey));
|
||||
else
|
||||
return false;
|
||||
|
||||
|
@ -145,6 +147,8 @@ PrefsDialog::linkWidgetToPref (QWidget * widget, int prefKey)
|
|||
connect (widget, SIGNAL (editingFinished ()), SLOT (timeEditingFinished ()));
|
||||
else if (widget->inherits ("QLineEdit"))
|
||||
connect (widget, SIGNAL (editingFinished ()), SLOT (lineEditingFinished ()));
|
||||
else if (widget->inherits ("TrPathButton"))
|
||||
connect (widget, SIGNAL (pathChanged (QString)), SLOT (pathChanged (QString)));
|
||||
else if (widget->inherits ("QAbstractSpinBox"))
|
||||
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
|
||||
PrefsDialog::onIdleLimitChanged ()
|
||||
{
|
||||
|
@ -504,32 +465,56 @@ PrefsDialog::onQueueStalledMinutesChanged ()
|
|||
void
|
||||
PrefsDialog::initDownloadingTab ()
|
||||
{
|
||||
const QSize iconSize (QSize (1, 1) * style ()->pixelMetric (QStyle::PM_SmallIconSize));
|
||||
const QFileIconProvider iconProvider;
|
||||
const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
|
||||
const QIcon fileIcon = iconProvider.icon (QFileIconProvider::File);
|
||||
if (mySession.isLocal ())
|
||||
{
|
||||
ui.watchDirStack->setCurrentWidget (ui.watchDirButton);
|
||||
ui.downloadDirStack->setCurrentWidget (ui.downloadDirButton);
|
||||
ui.incompleteDirStack->setCurrentWidget (ui.incompleteDirButton);
|
||||
ui.completionScriptStack->setCurrentWidget (ui.completionScriptButton);
|
||||
|
||||
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.watchDirButton->setMode (TrPathButton::DirectoryMode);
|
||||
ui.downloadDirButton->setMode (TrPathButton::DirectoryMode);
|
||||
ui.incompleteDirButton->setMode (TrPathButton::DirectoryMode);
|
||||
ui.completionScriptButton->setMode (TrPathButton::FileMode);
|
||||
|
||||
ui.watchDirButton->setTitle (tr ("Select Watch Directory"));
|
||||
ui.downloadDirButton->setTitle (tr ("Select Destination"));
|
||||
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->setPath (myPrefs.getString (Prefs::DOWNLOAD_DIR));
|
||||
|
||||
linkWidgetToPref (ui.watchDirCheck, Prefs::DIR_WATCH_ENABLED);
|
||||
linkWidgetToPref (ui.watchDirStack->currentWidget (), Prefs::DIR_WATCH);
|
||||
linkWidgetToPref (ui.showTorrentOptionsDialogCheck, Prefs::OPTIONS_PROMPT);
|
||||
linkWidgetToPref (ui.startAddedTorrentsCheck, Prefs::START);
|
||||
linkWidgetToPref (ui.trashTorrentFileCheck, Prefs::TRASH_ORIGINAL);
|
||||
linkWidgetToPref (ui.downloadDirStack->currentWidget (), Prefs::DOWNLOAD_DIR);
|
||||
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.incompleteDirStack->currentWidget (), Prefs::INCOMPLETE_DIR);
|
||||
linkWidgetToPref (ui.completionScriptCheck, Prefs::SCRIPT_TORRENT_DONE_ENABLED);
|
||||
linkWidgetToPref (ui.completionScriptStack->currentWidget (), Prefs::SCRIPT_TORRENT_DONE_FILENAME);
|
||||
|
||||
ColumnResizer * cr (new ColumnResizer (this));
|
||||
cr->addLayout (ui.addingSectionLayout);
|
||||
|
@ -537,10 +522,6 @@ PrefsDialog::initDownloadingTab ()
|
|||
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 ();
|
||||
|
|
|
@ -45,15 +45,11 @@ class PrefsDialog: public QDialog
|
|||
void spinBoxEditingFinished ();
|
||||
void timeEditingFinished ();
|
||||
void lineEditingFinished ();
|
||||
void pathChanged (const QString& path);
|
||||
void refreshPref (int key);
|
||||
void encryptionEdited (int);
|
||||
void altSpeedDaysEdited (int);
|
||||
void sessionUpdated ();
|
||||
void onWatchClicked ();
|
||||
void onScriptClicked ();
|
||||
void onIncompleteClicked ();
|
||||
void onDestinationClicked ();
|
||||
void onLocationSelected (const QString&, int key);
|
||||
void onPortTested (bool);
|
||||
void onPortTest ();
|
||||
void onIdleLimitChanged ();
|
||||
|
|
|
@ -284,16 +284,15 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QToolButton" name="watchDirButton">
|
||||
<widget class="QStackedWidget" name="watchDirStack">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextBesideIcon</enum>
|
||||
</property>
|
||||
<widget class="TrPathButton" name="watchDirButton"/>
|
||||
<widget class="QLineEdit" name="watchDirEdit"/>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
|
@ -322,22 +321,18 @@
|
|||
<property name="text">
|
||||
<string>Save to &Location:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>downloadDirButton</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QToolButton" name="downloadDirButton">
|
||||
<widget class="QStackedWidget" name="downloadDirStack">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextBesideIcon</enum>
|
||||
</property>
|
||||
<widget class="TrPathButton" name="downloadDirButton"/>
|
||||
<widget class="QLineEdit" name="downloadDirEdit"/>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
|
@ -394,7 +389,14 @@
|
|||
</widget>
|
||||
</item>
|
||||
<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 row="1" column="0">
|
||||
<widget class="QLabel" name="queueStalledMinutesLabel">
|
||||
|
@ -411,6 +413,15 @@
|
|||
<property name="suffix">
|
||||
<string notr="true"> minute(s) ago</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>9999</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -464,16 +475,15 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QToolButton" name="incompleteDirButton">
|
||||
<widget class="QStackedWidget" name="incompleteDirStack">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextBesideIcon</enum>
|
||||
</property>
|
||||
<widget class="TrPathButton" name="incompleteDirButton"/>
|
||||
<widget class="QLineEdit" name="incompleteDirEdit"/>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
|
@ -487,16 +497,15 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QToolButton" name="completionScriptButton">
|
||||
<widget class="QStackedWidget" name="completionScriptStack">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextBesideIcon</enum>
|
||||
</property>
|
||||
<widget class="TrPathButton" name="completionScriptButton"/>
|
||||
<widget class="QLineEdit" name="completionScriptEdit"/>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -1219,6 +1228,11 @@
|
|||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>TrPathButton</class>
|
||||
<extends>QToolButton</extends>
|
||||
<header>path-button.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>FreespaceLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
|
@ -1312,7 +1326,7 @@
|
|||
<connection>
|
||||
<sender>watchDirCheck</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>watchDirButton</receiver>
|
||||
<receiver>watchDirStack</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
|
@ -1328,7 +1342,7 @@
|
|||
<connection>
|
||||
<sender>incompleteDirCheck</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>incompleteDirButton</receiver>
|
||||
<receiver>incompleteDirStack</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
|
@ -1344,7 +1358,7 @@
|
|||
<connection>
|
||||
<sender>completionScriptCheck</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>completionScriptButton</receiver>
|
||||
<receiver>completionScriptStack</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
|
|
20
qt/utils.cc
20
qt/utils.cc
|
@ -44,26 +44,6 @@
|
|||
extern QPixmap qt_pixmapFromWinHICON(HICON icon);
|
||||
#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
|
||||
Utils::toStderr (const QString& str)
|
||||
{
|
||||
|
|
|
@ -28,7 +28,6 @@ class Utils: public QObject
|
|||
virtual ~Utils () {}
|
||||
|
||||
public:
|
||||
static QString remoteFileChooser (QWidget * parent, const QString& title, const QString& myPath, bool dir, bool local);
|
||||
static QIcon guessMimeIcon (const QString& filename);
|
||||
// Test if string is UTF-8 or not
|
||||
static bool isValidUtf8 (const char *s);
|
||||
|
|
Loading…
Reference in New Issue