From: Mike Gelfand Date: Thu, 1 Jan 2015 05:02:13 +0000 (+0000) Subject: Make use of path button in relocate dialog (Qt client) X-Git-Tag: 2.90~274 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=424c79a5da9f5d46957506762fe35747462fc99e;p=transmission Make use of path button in relocate dialog (Qt client) --- diff --git a/qt/mainwin.cc b/qt/mainwin.cc index 68fe94b72..52050c8ce 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -554,6 +554,7 @@ void TrMainWindow::setLocation () { QDialog * d = new RelocateDialog (mySession, myModel, getSelectedTorrents (), this); + d->setAttribute (Qt::WA_DeleteOnClose, true); d->show (); } diff --git a/qt/make-dialog.ui b/qt/make-dialog.ui index ad86571e6..a2b24a676 100644 --- a/qt/make-dialog.ui +++ b/qt/make-dialog.ui @@ -57,11 +57,7 @@ - - - Qt::ToolButtonTextBesideIcon - - + @@ -78,9 +74,6 @@ false - - Qt::ToolButtonTextBesideIcon - @@ -97,11 +90,7 @@ - - - Qt::ToolButtonTextBesideIcon - - + diff --git a/qt/options.ui b/qt/options.ui index 4f2d06105..03b88bd13 100644 --- a/qt/options.ui +++ b/qt/options.ui @@ -29,11 +29,7 @@ 0 - - - Qt::ToolButtonTextBesideIcon - - + @@ -55,11 +51,7 @@ 0 - - - Qt::ToolButtonTextBesideIcon - - + diff --git a/qt/path-button.cc b/qt/path-button.cc index 38995c6a1..fe91e6d08 100644 --- a/qt/path-button.cc +++ b/qt/path-button.cc @@ -26,6 +26,7 @@ TrPathButton::TrPathButton (QWidget * parent): myPath () { setSizePolicy(QSizePolicy (QSizePolicy::Preferred, QSizePolicy::Fixed)); + setToolButtonStyle (Qt::ToolButtonTextBesideIcon); setText (tr ("(None)")); // for minimum width updateAppearance (); @@ -104,7 +105,8 @@ TrPathButton::onClicked () dialog->setFileMode (isDirMode () ? QFileDialog::Directory : QFileDialog::ExistingFile); if (isDirMode ()) dialog->setOption (QFileDialog::ShowDirsOnly); - dialog->setNameFilter (myNameFilter); + if (!myNameFilter.isEmpty ()) + dialog->setNameFilter (myNameFilter); dialog->selectFile (myPath); connect (dialog, SIGNAL (fileSelected (QString)), this, SLOT (onFileSelected (QString))); diff --git a/qt/relocate.cc b/qt/relocate.cc index 3b97031ce..fd5ab75d7 100644 --- a/qt/relocate.cc +++ b/qt/relocate.cc @@ -8,53 +8,21 @@ */ #include -#include -#include #include "relocate.h" #include "session.h" #include "torrent.h" #include "torrent-model.h" -#include "utils.h" bool RelocateDialog::myMoveFlag = true; void RelocateDialog::onSetLocation () { - mySession.torrentSetLocation (myIds, myPath, myMoveFlag); + mySession.torrentSetLocation (myIds, newLocation (), myMoveFlag); close (); } -void -RelocateDialog::onFileSelected (const QString& path) -{ - myPath = path; - - const int iconSize = style ()->pixelMetric (QStyle::PM_SmallIconSize); - - const QFileInfo pathInfo (path); - const QString absolutePath = pathInfo.absoluteFilePath (); - const QFileIconProvider iconProvider; - - ui.newLocationButton->setIcon (mySession.isLocal () ? - iconProvider.icon (pathInfo) : - iconProvider.icon (QFileIconProvider::Folder)); - ui.newLocationButton->setIconSize (QSize (iconSize, iconSize)); - ui.newLocationButton->setText (pathInfo.fileName ().isEmpty () ? absolutePath : pathInfo.fileName ()); - ui.newLocationButton->setToolTip (absolutePath); -} - -void -RelocateDialog::onDirButtonClicked () -{ - const QString title = tr ("Select Location"); - const QString path = Utils::remoteFileChooser (this, title, myPath, true, mySession.isServer ()); - - if (!path.isEmpty ()) - onFileSelected (path); -} - void RelocateDialog::onMoveToggled (bool b) { @@ -71,25 +39,41 @@ RelocateDialog::RelocateDialog (Session & session, { ui.setupUi (this); + QString path; foreach (int id, myIds) { const Torrent * tor = model.getTorrentFromId (id); - if (myPath.isEmpty ()) + if (path.isEmpty ()) { - myPath = tor->getPath (); + path = tor->getPath (); } - else if (myPath != tor->getPath ()) + else if (path != tor->getPath ()) { if (mySession.isServer ()) - myPath = QDir::homePath (); + path = QDir::homePath (); else - myPath = QDir::rootPath (); + path = QDir::rootPath (); break; } } - onFileSelected (myPath); + if (mySession.isServer ()) + { + ui.newLocationStack->setCurrentWidget (ui.newLocationButton); + ui.newLocationButton->setMode (TrPathButton::DirectoryMode); + ui.newLocationButton->setTitle (tr ("Select Location")); + ui.newLocationButton->setPath (path); + } + else + { + ui.newLocationStack->setCurrentWidget (ui.newLocationEdit); + ui.newLocationEdit->setText (path); + ui.newLocationEdit->selectAll (); + } + + ui.newLocationStack->setFixedHeight (ui.newLocationStack->currentWidget ()->sizeHint ().height ()); + ui.newLocationLabel->setBuddy (ui.newLocationStack->currentWidget ()); if (myMoveFlag) ui.moveDataRadio->setChecked (true); @@ -97,9 +81,13 @@ RelocateDialog::RelocateDialog (Session & session, ui.findDataRadio->setChecked (true); connect (ui.moveDataRadio, SIGNAL (toggled (bool)), this, SLOT (onMoveToggled (bool))); - connect (ui.newLocationButton, SIGNAL (clicked ()), this, SLOT (onDirButtonClicked ())); connect (ui.dialogButtons, SIGNAL (rejected ()), this, SLOT (close ())); connect (ui.dialogButtons, SIGNAL (accepted ()), this, SLOT (onSetLocation ())); +} - setAttribute (Qt::WA_DeleteOnClose, true); +QString +RelocateDialog::newLocation () const +{ + return ui.newLocationStack->currentWidget () == ui.newLocationButton ? + ui.newLocationButton->path () : ui.newLocationEdit->text (); } diff --git a/qt/relocate.h b/qt/relocate.h index de68577f7..ec43e32bf 100644 --- a/qt/relocate.h +++ b/qt/relocate.h @@ -12,7 +12,6 @@ #include #include -#include #include "ui_relocate.h" @@ -28,16 +27,16 @@ class RelocateDialog: public QDialog ~RelocateDialog () {} private slots: - void onFileSelected (const QString& path); - void onDirButtonClicked (); void onSetLocation (); void onMoveToggled (bool); + private: + QString newLocation () const; + private: Session& mySession; const QSet myIds; Ui::RelocateDialog ui; - QString myPath; static bool myMoveFlag; }; diff --git a/qt/relocate.ui b/qt/relocate.ui index adfb379b7..63227d17c 100644 --- a/qt/relocate.ui +++ b/qt/relocate.ui @@ -6,8 +6,8 @@ 0 0 - 225 - 155 + 339 + 151 @@ -27,6 +27,10 @@ [tr-style~="form-label"] { margin-left: 18px; +} +#newLocationStack +{ + min-width: 15em; } @@ -48,28 +52,15 @@ New &location: - - newLocationButton - form-label - - - - 0 - 0 - - - - text-align:left - - - Qt::ToolButtonTextBesideIcon - + + + @@ -104,6 +95,13 @@ + + + TrPathButton + QToolButton +
path-button.h
+
+