]> granicus.if.org Git - transmission/commitdiff
Make use of path button in relocate dialog (Qt client)
authorMike Gelfand <mikedld@mikedld.com>
Thu, 1 Jan 2015 05:02:13 +0000 (05:02 +0000)
committerMike Gelfand <mikedld@mikedld.com>
Thu, 1 Jan 2015 05:02:13 +0000 (05:02 +0000)
qt/mainwin.cc
qt/make-dialog.ui
qt/options.ui
qt/path-button.cc
qt/relocate.cc
qt/relocate.h
qt/relocate.ui

index 68fe94b725c1c9516b758074c04128ec9a4094e7..52050c8ce8e489cca362ce8b254ce01f93d12eae 100644 (file)
@@ -554,6 +554,7 @@ void
 TrMainWindow::setLocation ()
 {
   QDialog * d = new RelocateDialog (mySession, myModel, getSelectedTorrents (), this);
+  d->setAttribute (Qt::WA_DeleteOnClose, true);
   d->show ();
 }
 
index ad86571e6cd3f913d5bb69950de1fe6f087b5a78..a2b24a676114147c69a9e3490cbc564df98c745f 100644 (file)
     </widget>
    </item>
    <item row="1" column="1">
-    <widget class="TrPathButton" name="destinationButton">
-     <property name="toolButtonStyle">
-      <enum>Qt::ToolButtonTextBesideIcon</enum>
-     </property>
-    </widget>
+    <widget class="TrPathButton" name="destinationButton"/>
    </item>
    <item row="2" column="0">
     <widget class="QRadioButton" name="sourceFolderRadio">
@@ -78,9 +74,6 @@
      <property name="enabled">
       <bool>false</bool>
      </property>
-     <property name="toolButtonStyle">
-      <enum>Qt::ToolButtonTextBesideIcon</enum>
-     </property>
     </widget>
    </item>
    <item row="3" column="0">
     </widget>
    </item>
    <item row="3" column="1">
-    <widget class="TrPathButton" name="sourceFileButton">
-     <property name="toolButtonStyle">
-      <enum>Qt::ToolButtonTextBesideIcon</enum>
-     </property>
-    </widget>
+    <widget class="TrPathButton" name="sourceFileButton"/>
    </item>
    <item row="4" column="1">
     <widget class="QLabel" name="sourceSizeLabel">
index 4f2d061053f26496fd9ef6c931f6c466fae2cdc0..03b88bd136001cdeccc87b196024619a4bd011b7 100644 (file)
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
-     <widget class="TrPathButton" name="sourceButton">
-      <property name="toolButtonStyle">
-       <enum>Qt::ToolButtonTextBesideIcon</enum>
-      </property>
-     </widget>
+     <widget class="TrPathButton" name="sourceButton"/>
      <widget class="QLineEdit" name="sourceEdit"/>
     </widget>
    </item>
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
-     <widget class="TrPathButton" name="destinationButton">
-      <property name="toolButtonStyle">
-       <enum>Qt::ToolButtonTextBesideIcon</enum>
-      </property>
-     </widget>
+     <widget class="TrPathButton" name="destinationButton"/>
      <widget class="QLineEdit" name="destinationEdit"/>
     </widget>
    </item>
index 38995c6a12bd1d7b3a1c17bce72823919cf598ad..fe91e6d0828ca5abe7db83e7ded57cd94cf4e7a3 100644 (file)
@@ -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)));
index 3b97031cee75cc8d0e3647f9c9c865ddcc81c1ac..fd5ab75d74ec9a9544163987e7ff49564cb56c85 100644 (file)
@@ -8,53 +8,21 @@
  */
 
 #include <QDir>
-#include <QFileIconProvider>
-#include <QFileInfo>
 
 #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 ();
 }
index de68577f7b55ac2bccd7a365348da25374b7f99c..ec43e32bfc442876d75417feef79c779a29c49f2 100644 (file)
@@ -12,7 +12,6 @@
 
 #include <QDialog>
 #include <QSet>
-#include <QString>
 
 #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<int> myIds;
     Ui::RelocateDialog ui;
-    QString myPath;
 
     static bool myMoveFlag;
 };
index adfb379b75d88c8bf2bc109c61c6e8006bfbdf26..63227d17c305cbad257975967ee51ca1ac343088 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>225</width>
-    <height>155</height>
+    <width>339</width>
+    <height>151</height>
    </rect>
   </property>
   <property name="windowTitle">
 [tr-style~=&quot;form-label&quot;]
 {
   margin-left: 18px;
+}
+#newLocationStack
+{
+  min-width: 15em;
 }</string>
   </property>
   <layout class="QGridLayout" name="dialogLayout">
      <property name="text">
       <string>New &amp;location:</string>
      </property>
-     <property name="buddy">
-      <cstring>newLocationButton</cstring>
-     </property>
      <property name="tr-style" stdset="0">
       <string notr="true">form-label</string>
      </property>
     </widget>
    </item>
    <item row="1" column="1">
-    <widget class="QToolButton" name="newLocationButton">
-     <property name="sizePolicy">
-      <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
-     <property name="styleSheet">
-      <string notr="true">text-align:left</string>
-     </property>
-     <property name="toolButtonStyle">
-      <enum>Qt::ToolButtonTextBesideIcon</enum>
-     </property>
+    <widget class="QStackedWidget" name="newLocationStack">
+     <widget class="TrPathButton" name="newLocationButton"/>
+     <widget class="QLineEdit" name="newLocationEdit"/>
     </widget>
    </item>
    <item row="2" column="0" colspan="2">
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>TrPathButton</class>
+   <extends>QToolButton</extends>
+   <header>path-button.h</header>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>