Browse Source

- Added a right click menu to (un)select files in torrent addition dialog

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
64369b60b7
  1. 13
      src/addTorrentDialog.ui
  2. 35
      src/torrentAddition.h

13
src/addTorrentDialog.ui

@ -69,6 +69,9 @@
</item> </item>
<item> <item>
<widget class="QTreeWidget" name="torrentContentList" > <widget class="QTreeWidget" name="torrentContentList" >
<property name="contextMenuPolicy" >
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="selectionMode" > <property name="selectionMode" >
<enum>QAbstractItemView::ExtendedSelection</enum> <enum>QAbstractItemView::ExtendedSelection</enum>
</property> </property>
@ -157,6 +160,16 @@
</layout> </layout>
</item> </item>
</layout> </layout>
<action name="actionSelect" >
<property name="text" >
<string>select</string>
</property>
</action>
<action name="actionUnselect" >
<property name="text" >
<string>Unselect</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>

35
src/torrentAddition.h

@ -27,6 +27,7 @@
#include <QFile> #include <QFile>
#include <fstream> #include <fstream>
#include <QMessageBox> #include <QMessageBox>
#include <QMenu>
#include <libtorrent/session.hpp> #include <libtorrent/session.hpp>
#include <libtorrent/bencode.hpp> #include <libtorrent/bencode.hpp>
@ -54,6 +55,10 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
torrentAdditionDialog(QWidget *parent, QString filePath, bool fromScanDir=false, QString from_url=QString::null) : QDialog(parent), filePath(filePath), fromScanDir(fromScanDir), from_url(from_url){ torrentAdditionDialog(QWidget *parent, QString filePath, bool fromScanDir=false, QString from_url=QString::null) : QDialog(parent), filePath(filePath), fromScanDir(fromScanDir), from_url(from_url){
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
actionSelect->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/add.png")));
actionUnselect->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/remove.png")));
connect(actionSelect, SIGNAL(triggered()), this, SLOT(selectItems()));
connect(actionUnselect, SIGNAL(triggered()), this, SLOT(unselectItems()));
//TODO: Remember last entered path //TODO: Remember last entered path
QString home = QDir::homePath(); QString home = QDir::homePath();
if(home[home.length()-1] != QDir::separator()){ if(home[home.length()-1] != QDir::separator()){
@ -96,6 +101,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
} }
//Connects //Connects
connect(torrentContentList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(toggleSelection(QTreeWidgetItem*, int))); connect(torrentContentList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(toggleSelection(QTreeWidgetItem*, int)));
connect(torrentContentList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displaySelectionMenu(const QPoint&)));
show(); show();
} }
@ -111,6 +117,28 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
close(); close();
} }
void selectItems(){
QList<QTreeWidgetItem *> selectedItems = torrentContentList->selectedItems();
QTreeWidgetItem *item;
foreach(item, selectedItems){
int row = torrentContentList->indexOfTopLevelItem(item);
setLineColor(row, "green");
item->setText(SELECTED, tr("True"));
selection.replace(row, true);
}
}
void unselectItems(){
QList<QTreeWidgetItem *> selectedItems = torrentContentList->selectedItems();
QTreeWidgetItem *item;
foreach(item, selectedItems){
int row = torrentContentList->indexOfTopLevelItem(item);
setLineColor(row, "red");
item->setText(SELECTED, tr("False"));
selection.replace(row, false);
}
}
void toggleSelection(QTreeWidgetItem *item, int){ void toggleSelection(QTreeWidgetItem *item, int){
int row = torrentContentList->indexOfTopLevelItem(item); int row = torrentContentList->indexOfTopLevelItem(item);
if(row == -1){ if(row == -1){
@ -127,6 +155,13 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
} }
} }
void displaySelectionMenu(const QPoint& pos){
QMenu mySelectionMenu(this);
mySelectionMenu.addAction(actionSelect);
mySelectionMenu.addAction(actionUnselect);
mySelectionMenu.exec(mapToGlobal(pos)+QPoint(10, 150));
}
void saveFilteredFiles(){ void saveFilteredFiles(){
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces"); QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces");
// First, remove old file // First, remove old file

Loading…
Cancel
Save