mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
- Still optimizing
This commit is contained in:
parent
4bc043146d
commit
7bd0dff802
@ -133,9 +133,8 @@ void FinishedTorrents::setRowColor(int row, QString color){
|
|||||||
|
|
||||||
QStringList FinishedTorrents::getSelectedTorrents(bool only_one) const{
|
QStringList FinishedTorrents::getSelectedTorrents(bool only_one) const{
|
||||||
QStringList res;
|
QStringList res;
|
||||||
QModelIndex index;
|
|
||||||
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes();
|
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes();
|
||||||
foreach(index, selectedIndexes) {
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||||||
if(index.column() == F_NAME) {
|
if(index.column() == F_NAME) {
|
||||||
// Get the file hash
|
// Get the file hash
|
||||||
QString hash = finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString();
|
QString hash = finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString();
|
||||||
@ -218,9 +217,8 @@ void FinishedTorrents::saveColWidthFinishedList() const{
|
|||||||
|
|
||||||
void FinishedTorrents::on_actionSet_upload_limit_triggered(){
|
void FinishedTorrents::on_actionSet_upload_limit_triggered(){
|
||||||
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes();
|
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes();
|
||||||
QModelIndex index;
|
|
||||||
QStringList hashes;
|
QStringList hashes;
|
||||||
foreach(index, selectedIndexes){
|
foreach(const QModelIndex &index, selectedIndexes){
|
||||||
if(index.column() == F_NAME){
|
if(index.column() == F_NAME){
|
||||||
// Get the file hash
|
// Get the file hash
|
||||||
hashes << finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString();
|
hashes << finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString();
|
||||||
@ -330,8 +328,7 @@ void FinishedTorrents::updateFileSize(QString hash){
|
|||||||
// display properties of selected items
|
// display properties of selected items
|
||||||
void FinishedTorrents::propertiesSelection(){
|
void FinishedTorrents::propertiesSelection(){
|
||||||
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes();
|
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes();
|
||||||
QModelIndex index;
|
foreach(const QModelIndex &index, selectedIndexes){
|
||||||
foreach(index, selectedIndexes){
|
|
||||||
if(index.column() == F_NAME){
|
if(index.column() == F_NAME){
|
||||||
showProperties(index);
|
showProperties(index);
|
||||||
}
|
}
|
||||||
@ -340,8 +337,7 @@ void FinishedTorrents::propertiesSelection(){
|
|||||||
|
|
||||||
void FinishedTorrents::forceRecheck(){
|
void FinishedTorrents::forceRecheck(){
|
||||||
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes();
|
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes();
|
||||||
QModelIndex index;
|
foreach(const QModelIndex &index, selectedIndexes){
|
||||||
foreach(index, selectedIndexes){
|
|
||||||
if(index.column() == F_NAME){
|
if(index.column() == F_NAME){
|
||||||
QString hash = finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString();
|
QString hash = finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString();
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||||
@ -352,11 +348,10 @@ void FinishedTorrents::forceRecheck(){
|
|||||||
|
|
||||||
void FinishedTorrents::displayFinishedListMenu(const QPoint& pos){
|
void FinishedTorrents::displayFinishedListMenu(const QPoint& pos){
|
||||||
QMenu myFinishedListMenu(this);
|
QMenu myFinishedListMenu(this);
|
||||||
QModelIndex index;
|
|
||||||
// Enable/disable pause/start action given the DL state
|
// Enable/disable pause/start action given the DL state
|
||||||
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes();
|
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes();
|
||||||
bool has_pause = false, has_start = false, has_preview = false;
|
bool has_pause = false, has_start = false, has_preview = false;
|
||||||
foreach(index, selectedIndexes) {
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||||||
if(index.column() == F_NAME) {
|
if(index.column() == F_NAME) {
|
||||||
// Get the file name
|
// Get the file name
|
||||||
QString hash = finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString();
|
QString hash = finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString();
|
||||||
|
@ -32,7 +32,7 @@ class torrent_file {
|
|||||||
torrent_file *parent;
|
torrent_file *parent;
|
||||||
bool is_dir;
|
bool is_dir;
|
||||||
QString rel_path;
|
QString rel_path;
|
||||||
QList<torrent_file*> children;
|
QList<const torrent_file*> children;
|
||||||
size_type size;
|
size_type size;
|
||||||
float progress;
|
float progress;
|
||||||
int priority;
|
int priority;
|
||||||
@ -68,8 +68,7 @@ class torrent_file {
|
|||||||
}
|
}
|
||||||
float wanted = 0.;
|
float wanted = 0.;
|
||||||
float done = 0.;
|
float done = 0.;
|
||||||
torrent_file *child;
|
foreach(const torrent_file *child, children) {
|
||||||
foreach(child, children) {
|
|
||||||
wanted += child->getSize();
|
wanted += child->getSize();
|
||||||
done += child->getSize()*child->getProgress();
|
done += child->getSize()*child->getProgress();
|
||||||
}
|
}
|
||||||
@ -80,8 +79,7 @@ class torrent_file {
|
|||||||
|
|
||||||
void updatePriority(int prio) {
|
void updatePriority(int prio) {
|
||||||
Q_ASSERT(is_dir);
|
Q_ASSERT(is_dir);
|
||||||
torrent_file *child;
|
foreach(const torrent_file *child, children) {
|
||||||
foreach(child, children) {
|
|
||||||
if(child->getPriority() != prio) return;
|
if(child->getPriority() != prio) return;
|
||||||
}
|
}
|
||||||
priority = prio;
|
priority = prio;
|
||||||
@ -111,14 +109,13 @@ class torrent_file {
|
|||||||
return (!children.isEmpty());
|
return (!children.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<torrent_file*> getChildren() const {
|
QList<const torrent_file*> getChildren() const {
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent_file* getChild(QString fileName) const {
|
const torrent_file* getChild(QString fileName) const {
|
||||||
Q_ASSERT(is_dir);
|
Q_ASSERT(is_dir);
|
||||||
torrent_file* f;
|
foreach(const torrent_file *f, children) {
|
||||||
foreach(f, children) {
|
|
||||||
if(f->name() == fileName) return f;
|
if(f->name() == fileName) return f;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -141,16 +138,15 @@ class torrent_file {
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool removeFromFS(QString saveDir) {
|
bool removeFromFS(QString saveDir) const {
|
||||||
QString full_path = saveDir + QDir::separator() + rel_path;
|
QString full_path = saveDir + QDir::separator() + rel_path;
|
||||||
if(!QFile::exists(full_path)) {
|
if(!QFile::exists(full_path)) {
|
||||||
qDebug("%s does not exist, no need to remove it", full_path.toUtf8().data());
|
qDebug("%s does not exist, no need to remove it", full_path.toUtf8().data());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool success = true;
|
bool success = true;
|
||||||
torrent_file *f;
|
|
||||||
qDebug("We have %d children", children.size());
|
qDebug("We have %d children", children.size());
|
||||||
foreach(f, children) {
|
foreach(const torrent_file *f, children) {
|
||||||
bool s = f->removeFromFS(saveDir);
|
bool s = f->removeFromFS(saveDir);
|
||||||
success = s && success;
|
success = s && success;
|
||||||
}
|
}
|
||||||
@ -239,14 +235,13 @@ class arborescence {
|
|||||||
if(relative_path.at(0) ==QDir::separator())
|
if(relative_path.at(0) ==QDir::separator())
|
||||||
relative_path.remove(0, 1);
|
relative_path.remove(0, 1);
|
||||||
QStringList fileNames = relative_path.split(QDir::separator());
|
QStringList fileNames = relative_path.split(QDir::separator());
|
||||||
QString fileName;
|
|
||||||
torrent_file *dad = root;
|
torrent_file *dad = root;
|
||||||
unsigned int nb_i = 0;
|
unsigned int nb_i = 0;
|
||||||
unsigned int size = fileNames.size();
|
unsigned int size = fileNames.size();
|
||||||
foreach(fileName, fileNames) {
|
foreach(const QString &fileName, fileNames) {
|
||||||
++nb_i;
|
++nb_i;
|
||||||
if(fileName == ".") continue;
|
if(fileName == ".") continue;
|
||||||
torrent_file* child = dad->getChild(fileName);
|
const torrent_file* child = dad->getChild(fileName);
|
||||||
if(!child) {
|
if(!child) {
|
||||||
if(nb_i != size) {
|
if(nb_i != size) {
|
||||||
// Folder
|
// Folder
|
||||||
@ -256,7 +251,7 @@ class arborescence {
|
|||||||
child = dad->addChild(fileName, false, file_size, index, progress, priority);
|
child = dad->addChild(fileName, false, file_size, index, progress, priority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dad = child;
|
dad = (torrent_file*)child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -146,7 +146,7 @@ properties::~properties(){
|
|||||||
delete progressBar;
|
delete progressBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
void properties::addFilesToTree(torrent_file *root, QStandardItem *parent) {
|
void properties::addFilesToTree(const torrent_file *root, QStandardItem *parent) {
|
||||||
QList<QStandardItem*> child;
|
QList<QStandardItem*> child;
|
||||||
// Name
|
// Name
|
||||||
QStandardItem *first;
|
QStandardItem *first;
|
||||||
@ -168,8 +168,7 @@ void properties::addFilesToTree(torrent_file *root, QStandardItem *parent) {
|
|||||||
// Add the child to the tree
|
// Add the child to the tree
|
||||||
parent->appendRow(child);
|
parent->appendRow(child);
|
||||||
// Add childs
|
// Add childs
|
||||||
torrent_file *childFile;
|
foreach(const torrent_file *childFile, root->getChildren()) {
|
||||||
foreach(childFile, root->getChildren()) {
|
|
||||||
addFilesToTree(childFile, first);
|
addFilesToTree(childFile, first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ class properties : public QDialog, private Ui::properties{
|
|||||||
void saveWebSeeds();
|
void saveWebSeeds();
|
||||||
void loadWebSeedsFromFile();
|
void loadWebSeedsFromFile();
|
||||||
void deleteSelectedUrlSeeds();
|
void deleteSelectedUrlSeeds();
|
||||||
void addFilesToTree(torrent_file *root, QStandardItem *parent);
|
void addFilesToTree(const torrent_file *root, QStandardItem *parent);
|
||||||
void updateChildrenPriority(QStandardItem *item, int priority);
|
void updateChildrenPriority(QStandardItem *item, int priority);
|
||||||
void updateParentsPriority(QStandardItem *item, int priority);
|
void updateParentsPriority(QStandardItem *item, int priority);
|
||||||
void updatePriorities(QStandardItem *item);
|
void updatePriorities(QStandardItem *item);
|
||||||
|
@ -3,7 +3,7 @@ LANG_PATH = lang
|
|||||||
ICONS_PATH = Icons
|
ICONS_PATH = Icons
|
||||||
|
|
||||||
# Set the following variable to 1 to enable debug
|
# Set the following variable to 1 to enable debug
|
||||||
DEBUG_MODE = 0
|
DEBUG_MODE = 1
|
||||||
|
|
||||||
# Global
|
# Global
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
@ -141,7 +141,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
|
|||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void addFilesToTree(torrent_file *root, QStandardItem *parent) {
|
void addFilesToTree(const torrent_file *root, QStandardItem *parent) {
|
||||||
QList<QStandardItem*> child;
|
QList<QStandardItem*> child;
|
||||||
// Name
|
// Name
|
||||||
QStandardItem *first;
|
QStandardItem *first;
|
||||||
@ -163,10 +163,9 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
|
|||||||
// Add the child to the tree
|
// Add the child to the tree
|
||||||
parent->appendRow(child);
|
parent->appendRow(child);
|
||||||
// Add children
|
// Add children
|
||||||
QList<torrent_file*> children = root->getChildren();
|
QList<const torrent_file*> children = root->getChildren();
|
||||||
unsigned int nbChildren = children.size();
|
foreach(const torrent_file *child, children) {
|
||||||
for(unsigned int i=0; i < nbChildren; ++i) {
|
addFilesToTree(child, first);
|
||||||
addFilesToTree(children.at(i), first);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user