TrMainWindow::setLocation ()
{
QDialog * d = new RelocateDialog (mySession, myModel, getSelectedTorrents (), this);
+ d->setAttribute (Qt::WA_DeleteOnClose, true);
d->show ();
}
</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">
<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">
<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>
myPath ()
{
setSizePolicy(QSizePolicy (QSizePolicy::Preferred, QSizePolicy::Fixed));
+ setToolButtonStyle (Qt::ToolButtonTextBesideIcon);
setText (tr ("(None)")); // for minimum width
updateAppearance ();
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)));
*/
#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)
{
{
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);
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 ();
}
#include <QDialog>
#include <QSet>
-#include <QString>
#include "ui_relocate.h"
~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;
};
<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~="form-label"]
{
margin-left: 18px;
+}
+#newLocationStack
+{
+ min-width: 15em;
}</string>
</property>
<layout class="QGridLayout" name="dialogLayout">
<property name="text">
<string>New &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>