2 * This file Copyright (C) 2009-2014 Mnemosyne LLC
4 * It may be used under the GNU Public License v2 or v3 licenses,
5 * or any future license endorsed by Mnemosyne LLC.
7 * $Id: relocate.cc 14225 2014-01-19 01:09:44Z jordan $
10 #include <QApplication>
11 #include <QDialogButtonBox>
13 #include <QFileIconProvider>
15 #include <QPushButton>
16 #include <QRadioButton>
19 #include <QVBoxLayout>
26 #include "torrent-model.h"
29 bool RelocateDialog :: myMoveFlag
= true;
32 RelocateDialog :: onSetLocation ()
34 mySession
.torrentSetLocation (myIds
, myPath
, myMoveFlag
);
39 RelocateDialog :: onFileSelected (const QString
& path
)
42 myDirButton
->setText (myPath
);
46 RelocateDialog :: onDirButtonClicked ()
48 const QString title
= tr ("Select Location");
49 const QString path
= Utils::remoteFileChooser (this, title
, myPath
, true, mySession
.isServer ());
52 onFileSelected (path
);
56 RelocateDialog :: onMoveToggled (bool b
)
61 RelocateDialog :: RelocateDialog (Session
& session
,
63 const QSet
<int> & ids
,
70 const int iconSize (style ()->pixelMetric (QStyle :: PM_SmallIconSize
));
71 const QFileIconProvider iconProvider
;
72 const QIcon folderIcon
= iconProvider
.icon (QFileIconProvider::Folder
);
73 const QPixmap folderPixmap
= folderIcon
.pixmap (iconSize
);
75 QRadioButton
* find_rb
;
76 setWindowTitle (tr ("Set Torrent Location"));
78 foreach (int id
, myIds
)
80 const Torrent
* tor
= myModel
.getTorrentFromId (id
);
82 if (myPath
.isEmpty ())
84 myPath
= tor
->getPath ();
86 else if (myPath
!= tor
->getPath ())
88 if (mySession
.isServer ())
89 myPath
= QDir::homePath ();
91 myPath
= QDir::rootPath ();
95 HIG
* hig
= new HIG ();
96 hig
->addSectionTitle (tr ("Set Location"));
97 hig
->addRow (tr ("New &location:"), myDirButton
= new QPushButton (folderPixmap
, myPath
));
98 hig
->addWideControl (myMoveRadio
= new QRadioButton (tr ("&Move from the current folder"), this));
99 hig
->addWideControl (find_rb
= new QRadioButton (tr ("Local data is &already there"), this));
103 myMoveRadio
->setChecked (true);
105 find_rb
->setChecked (true);
107 connect (myMoveRadio
, SIGNAL (toggled (bool)), this, SLOT (onMoveToggled (bool)));
108 connect (myDirButton
, SIGNAL (clicked (bool)), this, SLOT (onDirButtonClicked ()));
110 QLayout
* layout
= new QVBoxLayout (this);
111 layout
->addWidget (hig
);
112 QDialogButtonBox
* buttons
= new QDialogButtonBox (QDialogButtonBox::Ok
|QDialogButtonBox::Cancel
);
113 connect (buttons
, SIGNAL (rejected ()), this, SLOT (deleteLater ()));
114 connect (buttons
, SIGNAL (accepted ()), this, SLOT (onSetLocation ()));
115 layout
->addWidget (buttons
);
116 QWidget::setAttribute (Qt::WA_DeleteOnClose
, true);