mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-22 12:34:19 +00:00
- FEATURE: Display free disk space in torrent addition dialog
- Added some disambiguation for translators
This commit is contained in:
parent
c8e8306e0a
commit
6fcf25af52
@ -1,5 +1,6 @@
|
|||||||
* Unknown - Christophe Dumez <chris@qbittorrent.org> - v1.5.0
|
* Unknown - Christophe Dumez <chris@qbittorrent.org> - v1.5.0
|
||||||
- FEATURE: Added Magnet URI support
|
- FEATURE: Added Magnet URI support
|
||||||
|
- FEATURE: Display free disk space in torrent addition dialog
|
||||||
- BUGFIX: torrent resume code rewrited
|
- BUGFIX: torrent resume code rewrited
|
||||||
|
|
||||||
* Thu Aug 13 2009 - Christophe Dumez <chris@qbittorrent.org> - v1.4.0
|
* Thu Aug 13 2009 - Christophe Dumez <chris@qbittorrent.org> - v1.4.0
|
||||||
|
@ -1,68 +1,60 @@
|
|||||||
<ui version="4.0" >
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
<class>addTorrentDialog</class>
|
<class>addTorrentDialog</class>
|
||||||
<widget class="QDialog" name="addTorrentDialog" >
|
<widget class="QDialog" name="addTorrentDialog">
|
||||||
<property name="geometry" >
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>511</width>
|
<width>511</width>
|
||||||
<height>441</height>
|
<height>461</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle">
|
||||||
<string>Torrent addition dialog</string>
|
<string>Torrent addition dialog</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" >
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="fileNameLbl" >
|
<widget class="QLabel" name="fileNameLbl">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="Line" name="line" >
|
<widget class="Line" name="line">
|
||||||
<property name="orientation" >
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="savePathLbl" >
|
<widget class="QLabel" name="savePathLbl">
|
||||||
<property name="font" >
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<weight>75</weight>
|
<weight>75</weight>
|
||||||
<bold>true</bold>
|
<bold>true</bold>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>Save path:</string>
|
<string>Save path:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" >
|
<layout class="QHBoxLayout">
|
||||||
<property name="spacing" >
|
<property name="spacing">
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="leftMargin" >
|
<property name="margin">
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin" >
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin" >
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin" >
|
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="savePathTxt" />
|
<widget class="QLineEdit" name="savePathTxt"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="browseButton" >
|
<widget class="QToolButton" name="browseButton">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>...</string>
|
<string>...</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
@ -70,66 +62,27 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="torrentContentLbl" >
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<property name="font" >
|
|
||||||
<font>
|
|
||||||
<weight>75</weight>
|
|
||||||
<bold>true</bold>
|
|
||||||
</font>
|
|
||||||
</property>
|
|
||||||
<property name="text" >
|
|
||||||
<string>Torrent content:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QTreeView" name="torrentContentList" >
|
|
||||||
<property name="contextMenuPolicy" >
|
|
||||||
<enum>Qt::CustomContextMenu</enum>
|
|
||||||
</property>
|
|
||||||
<property name="editTriggers" >
|
|
||||||
<set>QAbstractItemView::AllEditTriggers</set>
|
|
||||||
</property>
|
|
||||||
<property name="selectionMode" >
|
|
||||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" >
|
|
||||||
<item>
|
<item>
|
||||||
<spacer>
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="orientation" >
|
<property name="text">
|
||||||
<enum>Qt::Horizontal</enum>
|
<string>Torrent size:</string>
|
||||||
</property>
|
|
||||||
<property name="sizeHint" >
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="collapseAllButton" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>Collapse all</string>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="expandAllButton" >
|
<widget class="QLabel" name="lbl_torrent_size">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>Expand all</string>
|
<string>Unknown</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer>
|
<spacer name="horizontalSpacer_2">
|
||||||
<property name="orientation" >
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" >
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>40</width>
|
<width>40</width>
|
||||||
<height>20</height>
|
<height>20</height>
|
||||||
@ -140,42 +93,77 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkIncrementalDL" >
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<property name="text" >
|
|
||||||
<string>Download in correct order (slower but good for previewing)</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="addInPause" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>Add to download list in paused state</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" >
|
|
||||||
<property name="spacing" >
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin" >
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin" >
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin" >
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin" >
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<spacer>
|
<widget class="QLabel" name="label">
|
||||||
<property name="orientation" >
|
<property name="text">
|
||||||
|
<string>Free disk space:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lbl_disk_space">
|
||||||
|
<property name="text">
|
||||||
|
<string>Unknown</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_space_msg">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" >
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="torrentContentLbl">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Torrent content:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeView" name="torrentContentList">
|
||||||
|
<property name="contextMenuPolicy">
|
||||||
|
<enum>Qt::CustomContextMenu</enum>
|
||||||
|
</property>
|
||||||
|
<property name="editTriggers">
|
||||||
|
<set>QAbstractItemView::AllEditTriggers</set>
|
||||||
|
</property>
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout">
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>40</width>
|
<width>40</width>
|
||||||
<height>20</height>
|
<height>20</height>
|
||||||
@ -184,25 +172,89 @@
|
|||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="OkButton" >
|
<widget class="QPushButton" name="collapseAllButton">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
|
<string>Collapse all</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="expandAllButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Expand all</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkIncrementalDL">
|
||||||
|
<property name="text">
|
||||||
|
<string>Download in sequential order (slower but good for previewing)</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="addInPause">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add to download list in paused state</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
<property name="margin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="OkButton">
|
||||||
|
<property name="text">
|
||||||
<string>Add</string>
|
<string>Add</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="CancelButton" >
|
<widget class="QPushButton" name="CancelButton">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>Cancel</string>
|
<string>Cancel</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer>
|
<spacer>
|
||||||
<property name="orientation" >
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" >
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>40</width>
|
<width>40</width>
|
||||||
<height>20</height>
|
<height>20</height>
|
||||||
@ -213,23 +265,23 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
<action name="actionIgnored" >
|
<action name="actionIgnored">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>Ignored</string>
|
<string>Ignored</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionNormal" >
|
<action name="actionNormal">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>Normal</string>
|
<string>Normal</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionHigh" >
|
<action name="actionHigh">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>High</string>
|
<string>High</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionMaximum" >
|
<action name="actionMaximum">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>Maximum</string>
|
<string>Maximum</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
22
src/misc.h
22
src/misc.h
@ -42,6 +42,10 @@
|
|||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
|
#ifndef Q_WS_WIN
|
||||||
|
#include <sys/vfs.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <libtorrent/torrent_info.hpp>
|
#include <libtorrent/torrent_info.hpp>
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
@ -92,6 +96,24 @@ public:
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static unsigned long long freeDiskSpaceOnPath(QString path) {
|
||||||
|
#ifndef Q_WS_WIN
|
||||||
|
unsigned long long available;
|
||||||
|
struct statfs stats;
|
||||||
|
int ret = statfs ((path+"/.").toUtf8().data(), &stats) ;
|
||||||
|
if(ret == 0) {
|
||||||
|
available = ((unsigned long long)stats.f_bavail) *
|
||||||
|
((unsigned long long)stats.f_bsize) ;
|
||||||
|
return available;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
return -1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// return best userfriendly storage unit (B, KiB, MiB, GiB, TiB)
|
// return best userfriendly storage unit (B, KiB, MiB, GiB, TiB)
|
||||||
// use Binary prefix standards from IEC 60027-2
|
// use Binary prefix standards from IEC 60027-2
|
||||||
// see http://en.wikipedia.org/wiki/Kilobyte
|
// see http://en.wikipedia.org/wiki/Kilobyte
|
||||||
|
@ -465,7 +465,7 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string comment="qBittorrent will watch a directory and automatically download torrents present in it">Transfer lists double-click</string>
|
<string comment="Action executed when doucle-clicking on an item in transfer (download/upload) list">Transfer lists double-click action</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
|
@ -55,366 +55,402 @@ using namespace libtorrent;
|
|||||||
class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
|
class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bittorrent *BTSession;
|
bittorrent *BTSession;
|
||||||
QString fileName;
|
QString fileName;
|
||||||
QString hash;
|
QString hash;
|
||||||
QString filePath;
|
QString filePath;
|
||||||
QString from_url;
|
QString from_url;
|
||||||
QStandardItemModel *PropListModel;
|
QStandardItemModel *PropListModel;
|
||||||
PropListDelegate *PropDelegate;
|
PropListDelegate *PropDelegate;
|
||||||
unsigned int nbFiles;
|
unsigned int nbFiles;
|
||||||
|
boost::intrusive_ptr<torrent_info> t;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
torrentAdditionDialog(QWidget *parent, bittorrent* _BTSession) : QDialog(parent) {
|
torrentAdditionDialog(QWidget *parent, bittorrent* _BTSession) : QDialog(parent) {
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
BTSession = _BTSession;
|
BTSession = _BTSession;
|
||||||
// Set Properties list model
|
// Set Properties list model
|
||||||
PropListModel = new QStandardItemModel(0,5);
|
PropListModel = new QStandardItemModel(0,5);
|
||||||
PropListModel->setHeaderData(NAME, Qt::Horizontal, tr("File name"));
|
PropListModel->setHeaderData(NAME, Qt::Horizontal, tr("File name"));
|
||||||
PropListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size"));
|
PropListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size"));
|
||||||
PropListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress"));
|
PropListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress"));
|
||||||
PropListModel->setHeaderData(PRIORITY, Qt::Horizontal, tr("Priority"));
|
PropListModel->setHeaderData(PRIORITY, Qt::Horizontal, tr("Priority"));
|
||||||
torrentContentList->setModel(PropListModel);
|
torrentContentList->setModel(PropListModel);
|
||||||
torrentContentList->hideColumn(PROGRESS);
|
torrentContentList->hideColumn(PROGRESS);
|
||||||
torrentContentList->hideColumn(INDEX);
|
torrentContentList->hideColumn(INDEX);
|
||||||
PropDelegate = new PropListDelegate();
|
PropDelegate = new PropListDelegate();
|
||||||
torrentContentList->setItemDelegate(PropDelegate);
|
torrentContentList->setItemDelegate(PropDelegate);
|
||||||
connect(torrentContentList, SIGNAL(clicked(const QModelIndex&)), torrentContentList, SLOT(edit(const QModelIndex&)));
|
connect(torrentContentList, SIGNAL(clicked(const QModelIndex&)), torrentContentList, SLOT(edit(const QModelIndex&)));
|
||||||
connect(torrentContentList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&)));
|
connect(torrentContentList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&)));
|
||||||
connect(actionIgnored, SIGNAL(triggered()), this, SLOT(ignoreSelection()));
|
connect(actionIgnored, SIGNAL(triggered()), this, SLOT(ignoreSelection()));
|
||||||
connect(actionNormal, SIGNAL(triggered()), this, SLOT(normalSelection()));
|
connect(actionNormal, SIGNAL(triggered()), this, SLOT(normalSelection()));
|
||||||
connect(actionHigh, SIGNAL(triggered()), this, SLOT(highSelection()));
|
connect(actionHigh, SIGNAL(triggered()), this, SLOT(highSelection()));
|
||||||
connect(actionMaximum, SIGNAL(triggered()), this, SLOT(maximumSelection()));
|
connect(actionMaximum, SIGNAL(triggered()), this, SLOT(maximumSelection()));
|
||||||
connect(collapseAllButton, SIGNAL(clicked()), torrentContentList, SLOT(collapseAll()));
|
connect(collapseAllButton, SIGNAL(clicked()), torrentContentList, SLOT(collapseAll()));
|
||||||
connect(expandAllButton, SIGNAL(clicked()), torrentContentList, SLOT(expandAll()));
|
connect(expandAllButton, SIGNAL(clicked()), torrentContentList, SLOT(expandAll()));
|
||||||
torrentContentList->header()->resizeSection(0, 200);
|
torrentContentList->header()->resizeSection(0, 200);
|
||||||
//torrentContentList->header()->setResizeMode(0, QHeaderView::Stretch);
|
//torrentContentList->header()->setResizeMode(0, QHeaderView::Stretch);
|
||||||
QString home = QDir::homePath();
|
QString home = QDir::homePath();
|
||||||
if(home[home.length()-1] != QDir::separator()){
|
if(home[home.length()-1] != QDir::separator()){
|
||||||
home += QDir::separator();
|
home += QDir::separator();
|
||||||
}
|
|
||||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
|
||||||
savePathTxt->setText(settings.value(QString::fromUtf8("LastDirTorrentAdd"), home+QString::fromUtf8("qBT_dir")).toString());
|
|
||||||
if(settings.value("Preferences/Downloads/StartInPause", false).toBool()) {
|
|
||||||
addInPause->setChecked(true);
|
|
||||||
addInPause->setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||||
~torrentAdditionDialog() {
|
savePathTxt->setText(settings.value(QString::fromUtf8("LastDirTorrentAdd"), home+QString::fromUtf8("qBT_dir")).toString());
|
||||||
delete PropDelegate;
|
if(settings.value("Preferences/Downloads/StartInPause", false).toBool()) {
|
||||||
delete PropListModel;
|
addInPause->setChecked(true);
|
||||||
|
addInPause->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void showLoad(QString filePath, QString from_url=QString::null){
|
~torrentAdditionDialog() {
|
||||||
if(!QFile::exists(filePath)) {
|
delete PropDelegate;
|
||||||
close();
|
delete PropListModel;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
this->filePath = filePath;
|
|
||||||
this->from_url = from_url;
|
|
||||||
// Getting torrent file informations
|
|
||||||
boost::intrusive_ptr<torrent_info> t;
|
|
||||||
try {
|
|
||||||
t = new torrent_info(filePath.toLocal8Bit().data());
|
|
||||||
} catch(std::exception&) {
|
|
||||||
qDebug("Caught error loading torrent");
|
|
||||||
if(!from_url.isNull()){
|
|
||||||
BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
|
|
||||||
QFile::remove(filePath);
|
|
||||||
}else{
|
|
||||||
BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red"));
|
|
||||||
}
|
|
||||||
close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
nbFiles = t->num_files();
|
|
||||||
// Setting file name
|
|
||||||
fileName = misc::toQString(t->name());
|
|
||||||
hash = misc::toQString(t->info_hash());
|
|
||||||
// Use left() to remove .old extension
|
|
||||||
QString newFileName;
|
|
||||||
if(fileName.endsWith(QString::fromUtf8(".old"))){
|
|
||||||
newFileName = fileName.left(fileName.size()-4);
|
|
||||||
}else{
|
|
||||||
newFileName = fileName;
|
|
||||||
}
|
|
||||||
fileNameLbl->setText(QString::fromUtf8("<center><b>")+newFileName+QString::fromUtf8("</b></center>"));
|
|
||||||
// List files in torrent
|
|
||||||
arborescence *arb = new arborescence(t);
|
|
||||||
addFilesToTree(arb->getRoot(), PropListModel->invisibleRootItem());
|
|
||||||
delete arb;
|
|
||||||
connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
|
|
||||||
torrentContentList->expandAll();
|
|
||||||
show();
|
|
||||||
}
|
|
||||||
|
|
||||||
void addFilesToTree(const torrent_file *root, QStandardItem *parent) {
|
void showLoad(QString filePath, QString from_url=QString::null){
|
||||||
QList<QStandardItem*> child;
|
if(!QFile::exists(filePath)) {
|
||||||
// Name
|
|
||||||
QStandardItem *first;
|
|
||||||
if(root->isDir()) {
|
|
||||||
first = new QStandardItem(QIcon(":/Icons/oxygen/folder.png"), root->name());
|
|
||||||
} else {
|
|
||||||
first = new QStandardItem(QIcon(":/Icons/oxygen/file.png"), root->name());
|
|
||||||
}
|
|
||||||
child << first;
|
|
||||||
// Size
|
|
||||||
child << new QStandardItem(misc::toQString(root->getSize()));
|
|
||||||
// Hidden progress
|
|
||||||
child << new QStandardItem("");
|
|
||||||
// Prio
|
|
||||||
child << new QStandardItem(misc::toQString(NORMAL));
|
|
||||||
// INDEX
|
|
||||||
child << new QStandardItem(misc::toQString(root->getIndex()));
|
|
||||||
// TODO: row Color?
|
|
||||||
// Add the child to the tree
|
|
||||||
parent->appendRow(child);
|
|
||||||
// Add children
|
|
||||||
QList<const torrent_file*> children = root->getChildren();
|
|
||||||
foreach(const torrent_file *child, children) {
|
|
||||||
addFilesToTree(child, first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
|
|
||||||
// priority is the new priority of given item
|
|
||||||
void updateParentsPriority(QStandardItem *item, int priority) {
|
|
||||||
QStandardItem *parent = item->parent();
|
|
||||||
if(!parent) return;
|
|
||||||
// Check if children have different priorities
|
|
||||||
// then folder must have NORMAL priority
|
|
||||||
unsigned int rowCount = parent->rowCount();
|
|
||||||
for(unsigned int i=0; i<rowCount; ++i) {
|
|
||||||
if(parent->child(i, PRIORITY)->text().toInt() != priority) {
|
|
||||||
QStandardItem *grandFather = parent->parent();
|
|
||||||
if(!grandFather) {
|
|
||||||
grandFather = PropListModel->invisibleRootItem();
|
|
||||||
}
|
|
||||||
QStandardItem *parentPrio = grandFather->child(parent->row(), PRIORITY);
|
|
||||||
if(parentPrio->text().toInt() != NORMAL) {
|
|
||||||
parentPrio->setText(misc::toQString(NORMAL));
|
|
||||||
// Recursively update ancesters of this parent too
|
|
||||||
updateParentsPriority(grandFather->child(parent->row()), priority);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// All the children have the same priority
|
|
||||||
// Parent folder should have the same priority too
|
|
||||||
QStandardItem *grandFather = parent->parent();
|
|
||||||
if(!grandFather) {
|
|
||||||
grandFather = PropListModel->invisibleRootItem();
|
|
||||||
}
|
|
||||||
QStandardItem *parentPrio = grandFather->child(parent->row(), PRIORITY);
|
|
||||||
if(parentPrio->text().toInt() != priority) {
|
|
||||||
parentPrio->setText(misc::toQString(priority));
|
|
||||||
// Recursively update ancesters of this parent too
|
|
||||||
updateParentsPriority(grandFather->child(parent->row()), priority);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateChildrenPriority(QStandardItem *item, int priority) {
|
|
||||||
QStandardItem *parent = item->parent();
|
|
||||||
if(!parent) {
|
|
||||||
parent = PropListModel->invisibleRootItem();
|
|
||||||
}
|
|
||||||
parent = parent->child(item->row());
|
|
||||||
unsigned int rowCount = parent->rowCount();
|
|
||||||
for(unsigned int i=0; i<rowCount; ++i) {
|
|
||||||
QStandardItem * childPrio = parent->child(i, PRIORITY);
|
|
||||||
if(childPrio->text().toInt() != priority) {
|
|
||||||
childPrio->setText(misc::toQString(priority));
|
|
||||||
// recursively update children of this child too
|
|
||||||
updateChildrenPriority(parent->child(i), priority);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void updatePriorities(QStandardItem *item) {
|
|
||||||
qDebug("Priority changed");
|
|
||||||
// First we disable the signal/slot on item edition
|
|
||||||
// temporarily so that it doesn't mess with our manual updates
|
|
||||||
disconnect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
|
|
||||||
QStandardItem *parent = item->parent();
|
|
||||||
if(!parent) {
|
|
||||||
parent = PropListModel->invisibleRootItem();
|
|
||||||
}
|
|
||||||
int priority = parent->child(item->row(), PRIORITY)->text().toInt();
|
|
||||||
// Update parents priorities
|
|
||||||
updateParentsPriority(item, priority);
|
|
||||||
// If this is not a directory, then there are
|
|
||||||
// no children to update
|
|
||||||
if(parent->child(item->row(), INDEX)->text().toInt() == -1) {
|
|
||||||
// Updating children
|
|
||||||
qDebug("Priority changed for a folder to %d", priority);
|
|
||||||
updateChildrenPriority(item, priority);
|
|
||||||
}
|
|
||||||
// Reconnect the signal/slot on item edition so that we
|
|
||||||
// get future updates
|
|
||||||
connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_browseButton_clicked(){
|
|
||||||
QString dir;
|
|
||||||
QDir saveDir(savePathTxt->text());
|
|
||||||
if(saveDir.exists()){
|
|
||||||
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), savePathTxt->text());
|
|
||||||
}else{
|
|
||||||
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
|
||||||
}
|
|
||||||
if(!dir.isNull()){
|
|
||||||
savePathTxt->setText(dir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_CancelButton_clicked(){
|
|
||||||
close();
|
close();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
this->filePath = filePath;
|
||||||
// Set the color of a row in data model
|
this->from_url = from_url;
|
||||||
void setRowColor(int row, QString color){
|
// Getting torrent file informations
|
||||||
for(int i=0; i<PropListModel->columnCount(); ++i){
|
try {
|
||||||
PropListModel->setData(PropListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole);
|
t = new torrent_info(filePath.toLocal8Bit().data());
|
||||||
|
} catch(std::exception&) {
|
||||||
|
qDebug("Caught error loading torrent");
|
||||||
|
if(!from_url.isNull()){
|
||||||
|
BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
|
||||||
|
QFile::remove(filePath);
|
||||||
|
}else{
|
||||||
|
BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red"));
|
||||||
}
|
}
|
||||||
|
close();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
nbFiles = t->num_files();
|
||||||
bool allFiltered() const {
|
// Setting file name
|
||||||
unsigned int nbRows = PropListModel->rowCount();
|
fileName = misc::toQString(t->name());
|
||||||
for(unsigned int i=0; i<nbRows; ++i){
|
hash = misc::toQString(t->info_hash());
|
||||||
if(PropListModel->data(PropListModel->index(i, PRIORITY)).toInt() != IGNORED)
|
// Use left() to remove .old extension
|
||||||
return false;
|
QString newFileName;
|
||||||
}
|
if(fileName.endsWith(QString::fromUtf8(".old"))){
|
||||||
return true;
|
newFileName = fileName.left(fileName.size()-4);
|
||||||
|
}else{
|
||||||
|
newFileName = fileName;
|
||||||
}
|
}
|
||||||
|
fileNameLbl->setText(QString::fromUtf8("<center><b>")+newFileName+QString::fromUtf8("</b></center>"));
|
||||||
|
// List files in torrent
|
||||||
|
arborescence *arb = new arborescence(t);
|
||||||
|
addFilesToTree(arb->getRoot(), PropListModel->invisibleRootItem());
|
||||||
|
delete arb;
|
||||||
|
connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
|
||||||
|
//torrentContentList->expandAll();
|
||||||
|
updateDiskSpaceLabels();
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
|
||||||
void displayFilesListMenu(const QPoint&){
|
void addFilesToTree(const torrent_file *root, QStandardItem *parent) {
|
||||||
if(nbFiles == 1) return;
|
QList<QStandardItem*> child;
|
||||||
QMenu myFilesLlistMenu(this);
|
// Name
|
||||||
QModelIndex index;
|
QStandardItem *first;
|
||||||
// Enable/disable pause/start action given the DL state
|
if(root->isDir()) {
|
||||||
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
first = new QStandardItem(QIcon(":/Icons/oxygen/folder.png"), root->name());
|
||||||
myFilesLlistMenu.setTitle(tr("Priority"));
|
} else {
|
||||||
myFilesLlistMenu.addAction(actionIgnored);
|
first = new QStandardItem(QIcon(":/Icons/oxygen/file.png"), root->name());
|
||||||
myFilesLlistMenu.addAction(actionNormal);
|
|
||||||
myFilesLlistMenu.addAction(actionHigh);
|
|
||||||
myFilesLlistMenu.addAction(actionMaximum);
|
|
||||||
// Call menu
|
|
||||||
myFilesLlistMenu.exec(QCursor::pos());
|
|
||||||
}
|
}
|
||||||
|
child << first;
|
||||||
void ignoreSelection(){
|
// Size
|
||||||
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
child << new QStandardItem(misc::toQString(root->getSize()));
|
||||||
foreach(const QModelIndex &index, selectedIndexes){
|
// Hidden progress
|
||||||
if(index.column() == PRIORITY){
|
child << new QStandardItem("");
|
||||||
PropListModel->setData(index, QVariant(IGNORED));
|
// Prio
|
||||||
}
|
child << new QStandardItem(misc::toQString(NORMAL));
|
||||||
for(int i=0; i<PropListModel->columnCount(); ++i){
|
// INDEX
|
||||||
PropListModel->setData(PropListModel->index(index.row(), i), QVariant(QColor(QString::fromUtf8("red"))), Qt::ForegroundRole);
|
child << new QStandardItem(misc::toQString(root->getIndex()));
|
||||||
}
|
// TODO: row Color?
|
||||||
}
|
// Add the child to the tree
|
||||||
|
parent->appendRow(child);
|
||||||
|
// Add children
|
||||||
|
QList<const torrent_file*> children = root->getChildren();
|
||||||
|
foreach(const torrent_file *child, children) {
|
||||||
|
addFilesToTree(child, first);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void normalSelection(){
|
public slots:
|
||||||
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
|
||||||
foreach(const QModelIndex &index, selectedIndexes){
|
|
||||||
if(index.column() == PRIORITY){
|
|
||||||
PropListModel->setData(index, QVariant(NORMAL));
|
|
||||||
}
|
|
||||||
for(int i=0; i<PropListModel->columnCount(); ++i){
|
|
||||||
PropListModel->setData(PropListModel->index(index.row(), i), QVariant(QColor(QString::fromUtf8("green"))), Qt::ForegroundRole);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void highSelection(){
|
// priority is the new priority of given item
|
||||||
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
void updateParentsPriority(QStandardItem *item, int priority) {
|
||||||
foreach(const QModelIndex &index, selectedIndexes){
|
QStandardItem *parent = item->parent();
|
||||||
if(index.column() == PRIORITY){
|
if(!parent) return;
|
||||||
PropListModel->setData(index, QVariant(HIGH));
|
// Check if children have different priorities
|
||||||
|
// then folder must have NORMAL priority
|
||||||
|
unsigned int rowCount = parent->rowCount();
|
||||||
|
for(unsigned int i=0; i<rowCount; ++i) {
|
||||||
|
if(parent->child(i, PRIORITY)->text().toInt() != priority) {
|
||||||
|
QStandardItem *grandFather = parent->parent();
|
||||||
|
if(!grandFather) {
|
||||||
|
grandFather = PropListModel->invisibleRootItem();
|
||||||
}
|
}
|
||||||
for(int i=0; i<PropListModel->columnCount(); ++i){
|
QStandardItem *parentPrio = grandFather->child(parent->row(), PRIORITY);
|
||||||
PropListModel->setData(PropListModel->index(index.row(), i), QVariant(QColor("green")), Qt::ForegroundRole);
|
if(parentPrio->text().toInt() != NORMAL) {
|
||||||
|
parentPrio->setText(misc::toQString(NORMAL));
|
||||||
|
// Recursively update ancesters of this parent too
|
||||||
|
updateParentsPriority(grandFather->child(parent->row()), priority);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void maximumSelection(){
|
|
||||||
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
|
||||||
foreach(const QModelIndex &index, selectedIndexes){
|
|
||||||
if(index.column() == PRIORITY){
|
|
||||||
PropListModel->setData(index, QVariant(MAXIMUM));
|
|
||||||
}
|
|
||||||
for(int i=0; i<PropListModel->columnCount(); ++i){
|
|
||||||
PropListModel->setData(PropListModel->index(index.row(), i), QVariant(QColor(QString::fromUtf8("green"))), Qt::ForegroundRole);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void getPriorities(QStandardItem *parent, int *priorities) {
|
|
||||||
unsigned int nbRows = parent->rowCount();
|
|
||||||
for(unsigned int i=0; i<nbRows; ++i){
|
|
||||||
QStandardItem *item = parent->child(i, INDEX);
|
|
||||||
int index = item->text().toInt();
|
|
||||||
if(index < 0) {
|
|
||||||
qDebug("getPriorities(), found a folder, checking its children");
|
|
||||||
getPriorities(parent->child(i), priorities);
|
|
||||||
} else {
|
|
||||||
item = parent->child(i, PRIORITY);
|
|
||||||
qDebug("getPriorities(), found priority %d for file at index %d", item->text().toInt(), index);
|
|
||||||
priorities[index] = item->text().toInt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void savePiecesPriorities(){
|
|
||||||
qDebug("Saving pieces priorities");
|
|
||||||
int *priorities = new int[nbFiles];
|
|
||||||
getPriorities(PropListModel->invisibleRootItem(), priorities);
|
|
||||||
std::vector<int> vect_prio;
|
|
||||||
for(unsigned int i=0; i<nbFiles; ++i) {
|
|
||||||
vect_prio.push_back(priorities[i]);
|
|
||||||
}
|
|
||||||
delete[] priorities;
|
|
||||||
TorrentTempData::setFilesPriority(hash, vect_prio);
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_OkButton_clicked(){
|
|
||||||
QDir savePath(savePathTxt->text());
|
|
||||||
if(savePathTxt->text().trimmed().isEmpty()){
|
|
||||||
QMessageBox::critical(0, tr("Empty save path"), tr("Please enter a save path"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check if savePath exists
|
|
||||||
if(!savePath.exists()){
|
|
||||||
if(!savePath.mkpath(savePath.path())){
|
|
||||||
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Save savepath
|
|
||||||
TorrentTempData::setSavePath(hash, savePath.path());
|
|
||||||
// Save last dir to remember it
|
|
||||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
|
||||||
settings.setValue(QString::fromUtf8("LastDirTorrentAdd"), savePathTxt->text());
|
|
||||||
// Create .incremental file if necessary
|
|
||||||
TorrentTempData::setSequential(hash, checkIncrementalDL->isChecked());
|
|
||||||
// Check if there is at least one selected file
|
|
||||||
if(allFiltered()){
|
|
||||||
QMessageBox::warning(0, tr("Invalid file selection"), tr("You must select at least one file in the torrent"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// save filtered files
|
|
||||||
savePiecesPriorities();
|
|
||||||
// Add to download list
|
|
||||||
QTorrentHandle h = BTSession->addTorrent(filePath, false, from_url);
|
|
||||||
if(addInPause->isChecked() && h.is_valid())
|
|
||||||
h.pause();
|
|
||||||
close();
|
|
||||||
}
|
}
|
||||||
|
// All the children have the same priority
|
||||||
|
// Parent folder should have the same priority too
|
||||||
|
QStandardItem *grandFather = parent->parent();
|
||||||
|
if(!grandFather) {
|
||||||
|
grandFather = PropListModel->invisibleRootItem();
|
||||||
|
}
|
||||||
|
QStandardItem *parentPrio = grandFather->child(parent->row(), PRIORITY);
|
||||||
|
if(parentPrio->text().toInt() != priority) {
|
||||||
|
parentPrio->setText(misc::toQString(priority));
|
||||||
|
// Recursively update ancesters of this parent too
|
||||||
|
updateParentsPriority(grandFather->child(parent->row()), priority);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateChildrenPriority(QStandardItem *item, int priority) {
|
||||||
|
QStandardItem *parent = item->parent();
|
||||||
|
if(!parent) {
|
||||||
|
parent = PropListModel->invisibleRootItem();
|
||||||
|
}
|
||||||
|
parent = parent->child(item->row());
|
||||||
|
unsigned int rowCount = parent->rowCount();
|
||||||
|
for(unsigned int i=0; i<rowCount; ++i) {
|
||||||
|
QStandardItem * childPrio = parent->child(i, PRIORITY);
|
||||||
|
if(childPrio->text().toInt() != priority) {
|
||||||
|
childPrio->setText(misc::toQString(priority));
|
||||||
|
// recursively update children of this child too
|
||||||
|
updateChildrenPriority(parent->child(i), priority);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void updatePriorities(QStandardItem *item) {
|
||||||
|
qDebug("Priority changed");
|
||||||
|
// First we disable the signal/slot on item edition
|
||||||
|
// temporarily so that it doesn't mess with our manual updates
|
||||||
|
disconnect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
|
||||||
|
QStandardItem *parent = item->parent();
|
||||||
|
if(!parent) {
|
||||||
|
parent = PropListModel->invisibleRootItem();
|
||||||
|
}
|
||||||
|
int priority = parent->child(item->row(), PRIORITY)->text().toInt();
|
||||||
|
// Update parents priorities
|
||||||
|
updateParentsPriority(item, priority);
|
||||||
|
// If this is not a directory, then there are
|
||||||
|
// no children to update
|
||||||
|
if(parent->child(item->row(), INDEX)->text().toInt() == -1) {
|
||||||
|
// Updating children
|
||||||
|
qDebug("Priority changed for a folder to %d", priority);
|
||||||
|
updateChildrenPriority(item, priority);
|
||||||
|
}
|
||||||
|
// Reconnect the signal/slot on item edition so that we
|
||||||
|
// get future updates
|
||||||
|
connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
|
||||||
|
// Update disk space labels
|
||||||
|
updateDiskSpaceLabels();
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateDiskSpaceLabels() {
|
||||||
|
unsigned long long available = misc::freeDiskSpaceOnPath(savePathTxt->text());
|
||||||
|
if (available > 0) {
|
||||||
|
lbl_disk_space->setText(misc::friendlyUnit(available));
|
||||||
|
} else {
|
||||||
|
lbl_disk_space->setText(tr("Unknown"));
|
||||||
|
}
|
||||||
|
// Determine torrent size
|
||||||
|
unsigned long long torrent_size = 0;
|
||||||
|
int nbFiles = t->num_files();
|
||||||
|
int *priorities = new int[nbFiles];
|
||||||
|
getPriorities(PropListModel->invisibleRootItem(), priorities);
|
||||||
|
for(int i=0; i<nbFiles; ++i) {
|
||||||
|
if(priorities[i] > 0)
|
||||||
|
torrent_size += t->file_at(i).size;
|
||||||
|
}
|
||||||
|
lbl_torrent_size->setText(misc::friendlyUnit(torrent_size));
|
||||||
|
// Check if free space is sufficient
|
||||||
|
if(available > 0) {
|
||||||
|
if(available > torrent_size) {
|
||||||
|
// Space is sufficient
|
||||||
|
label_space_msg->setText(tr("(%1 left after torrent download)", "e.g. (100MiB left after torrent download)").arg(misc::friendlyUnit(available-torrent_size)));
|
||||||
|
} else {
|
||||||
|
// Space is unsufficient
|
||||||
|
label_space_msg->setText("<font color=\"red\">"+tr("(%1 more are required to download)", "e.g. (100MiB more are required to download)").arg(misc::friendlyUnit(torrent_size-available))+"</font>");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Available disk space is unknown
|
||||||
|
label_space_msg->setText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_browseButton_clicked(){
|
||||||
|
QString dir;
|
||||||
|
QDir saveDir(savePathTxt->text());
|
||||||
|
if(saveDir.exists()){
|
||||||
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), savePathTxt->text());
|
||||||
|
}else{
|
||||||
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
||||||
|
}
|
||||||
|
if(!dir.isNull()){
|
||||||
|
savePathTxt->setText(dir);
|
||||||
|
updateDiskSpaceLabels();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_CancelButton_clicked(){
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the color of a row in data model
|
||||||
|
void setRowColor(int row, QString color){
|
||||||
|
for(int i=0; i<PropListModel->columnCount(); ++i){
|
||||||
|
PropListModel->setData(PropListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool allFiltered() const {
|
||||||
|
unsigned int nbRows = PropListModel->rowCount();
|
||||||
|
for(unsigned int i=0; i<nbRows; ++i){
|
||||||
|
if(PropListModel->data(PropListModel->index(i, PRIORITY)).toInt() != IGNORED)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayFilesListMenu(const QPoint&){
|
||||||
|
if(nbFiles == 1) return;
|
||||||
|
QMenu myFilesLlistMenu(this);
|
||||||
|
QModelIndex index;
|
||||||
|
// Enable/disable pause/start action given the DL state
|
||||||
|
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
||||||
|
myFilesLlistMenu.setTitle(tr("Priority"));
|
||||||
|
myFilesLlistMenu.addAction(actionIgnored);
|
||||||
|
myFilesLlistMenu.addAction(actionNormal);
|
||||||
|
myFilesLlistMenu.addAction(actionHigh);
|
||||||
|
myFilesLlistMenu.addAction(actionMaximum);
|
||||||
|
// Call menu
|
||||||
|
myFilesLlistMenu.exec(QCursor::pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ignoreSelection(){
|
||||||
|
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
||||||
|
foreach(const QModelIndex &index, selectedIndexes){
|
||||||
|
if(index.column() == PRIORITY){
|
||||||
|
PropListModel->setData(index, QVariant(IGNORED));
|
||||||
|
}
|
||||||
|
for(int i=0; i<PropListModel->columnCount(); ++i){
|
||||||
|
PropListModel->setData(PropListModel->index(index.row(), i), QVariant(QColor(QString::fromUtf8("red"))), Qt::ForegroundRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void normalSelection(){
|
||||||
|
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
||||||
|
foreach(const QModelIndex &index, selectedIndexes){
|
||||||
|
if(index.column() == PRIORITY){
|
||||||
|
PropListModel->setData(index, QVariant(NORMAL));
|
||||||
|
}
|
||||||
|
for(int i=0; i<PropListModel->columnCount(); ++i){
|
||||||
|
PropListModel->setData(PropListModel->index(index.row(), i), QVariant(QColor(QString::fromUtf8("green"))), Qt::ForegroundRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void highSelection(){
|
||||||
|
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
||||||
|
foreach(const QModelIndex &index, selectedIndexes){
|
||||||
|
if(index.column() == PRIORITY){
|
||||||
|
PropListModel->setData(index, QVariant(HIGH));
|
||||||
|
}
|
||||||
|
for(int i=0; i<PropListModel->columnCount(); ++i){
|
||||||
|
PropListModel->setData(PropListModel->index(index.row(), i), QVariant(QColor("green")), Qt::ForegroundRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void maximumSelection(){
|
||||||
|
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
||||||
|
foreach(const QModelIndex &index, selectedIndexes){
|
||||||
|
if(index.column() == PRIORITY){
|
||||||
|
PropListModel->setData(index, QVariant(MAXIMUM));
|
||||||
|
}
|
||||||
|
for(int i=0; i<PropListModel->columnCount(); ++i){
|
||||||
|
PropListModel->setData(PropListModel->index(index.row(), i), QVariant(QColor(QString::fromUtf8("green"))), Qt::ForegroundRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getPriorities(QStandardItem *parent, int *priorities) {
|
||||||
|
unsigned int nbRows = parent->rowCount();
|
||||||
|
for(unsigned int i=0; i<nbRows; ++i){
|
||||||
|
QStandardItem *item = parent->child(i, INDEX);
|
||||||
|
int index = item->text().toInt();
|
||||||
|
if(index < 0) {
|
||||||
|
qDebug("getPriorities(), found a folder, checking its children");
|
||||||
|
getPriorities(parent->child(i), priorities);
|
||||||
|
} else {
|
||||||
|
item = parent->child(i, PRIORITY);
|
||||||
|
qDebug("getPriorities(), found priority %d for file at index %d", item->text().toInt(), index);
|
||||||
|
priorities[index] = item->text().toInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void savePiecesPriorities(){
|
||||||
|
qDebug("Saving pieces priorities");
|
||||||
|
int *priorities = new int[nbFiles];
|
||||||
|
getPriorities(PropListModel->invisibleRootItem(), priorities);
|
||||||
|
std::vector<int> vect_prio;
|
||||||
|
for(unsigned int i=0; i<nbFiles; ++i) {
|
||||||
|
vect_prio.push_back(priorities[i]);
|
||||||
|
}
|
||||||
|
delete[] priorities;
|
||||||
|
TorrentTempData::setFilesPriority(hash, vect_prio);
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_OkButton_clicked(){
|
||||||
|
QDir savePath(savePathTxt->text());
|
||||||
|
if(savePathTxt->text().trimmed().isEmpty()){
|
||||||
|
QMessageBox::critical(0, tr("Empty save path"), tr("Please enter a save path"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Check if savePath exists
|
||||||
|
if(!savePath.exists()){
|
||||||
|
if(!savePath.mkpath(savePath.path())){
|
||||||
|
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Save savepath
|
||||||
|
TorrentTempData::setSavePath(hash, savePath.path());
|
||||||
|
// Save last dir to remember it
|
||||||
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||||
|
settings.setValue(QString::fromUtf8("LastDirTorrentAdd"), savePathTxt->text());
|
||||||
|
// Create .incremental file if necessary
|
||||||
|
TorrentTempData::setSequential(hash, checkIncrementalDL->isChecked());
|
||||||
|
// Check if there is at least one selected file
|
||||||
|
if(allFiltered()){
|
||||||
|
QMessageBox::warning(0, tr("Invalid file selection"), tr("You must select at least one file in the torrent"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// save filtered files
|
||||||
|
savePiecesPriorities();
|
||||||
|
// Add to download list
|
||||||
|
QTorrentHandle h = BTSession->addTorrent(filePath, false, from_url);
|
||||||
|
if(addInPause->isChecked() && h.is_valid())
|
||||||
|
h.pause();
|
||||||
|
close();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user