transmission 2.83
[tomato.git] / release / src-rt-6.x.4708 / router / transmission / qt / relocate.cc
blob809070c553280e4f80ec60cea9dc6c5e67092c1a
1 /*
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 $
8 */
10 #include <QApplication>
11 #include <QDialogButtonBox>
12 #include <QDir>
13 #include <QFileIconProvider>
14 #include <QLabel>
15 #include <QPushButton>
16 #include <QRadioButton>
17 #include <QSet>
18 #include <QStyle>
19 #include <QVBoxLayout>
20 #include <QWidget>
22 #include "hig.h"
23 #include "relocate.h"
24 #include "session.h"
25 #include "torrent.h"
26 #include "torrent-model.h"
27 #include "utils.h"
29 bool RelocateDialog :: myMoveFlag = true;
31 void
32 RelocateDialog :: onSetLocation ()
34 mySession.torrentSetLocation (myIds, myPath, myMoveFlag);
35 deleteLater ();
38 void
39 RelocateDialog :: onFileSelected (const QString& path)
41 myPath = path;
42 myDirButton->setText (myPath);
45 void
46 RelocateDialog :: onDirButtonClicked ()
48 const QString title = tr ("Select Location");
49 const QString path = Utils::remoteFileChooser (this, title, myPath, true, mySession.isServer ());
51 if (!path.isEmpty ())
52 onFileSelected (path);
55 void
56 RelocateDialog :: onMoveToggled (bool b)
58 myMoveFlag = b;
61 RelocateDialog :: RelocateDialog (Session & session,
62 TorrentModel & model,
63 const QSet<int> & ids,
64 QWidget * parent):
65 QDialog (parent),
66 mySession (session),
67 myModel (model),
68 myIds (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 ();
90 else
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));
100 hig->finish ();
102 if (myMoveFlag)
103 myMoveRadio->setChecked (true);
104 else
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);