From 37158a32ade94842c7110a8ec211820cedc0b282 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 7 Sep 2009 11:48:31 +0000 Subject: [PATCH] - Fix crash in torrent addition dialog when save path does not exist (closes #425227) - Fix downloading from URL (broken in v1.5.0) --- src/bittorrent.cpp | 6 ++++++ src/bittorrent.h | 1 + src/misc.h | 10 ++++++++-- src/torrentAddition.h | 7 ++++--- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 47fe6403c..eae00da87 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -1435,6 +1435,12 @@ void bittorrent::downloadFromUrl(QString url) { downloader->downloadUrl(url); } +void bittorrent::downloadFromURLList(const QStringList& urls) { + foreach(const QString &url, urls) { + downloadFromUrl(url); + } +} + void bittorrent::addMagnetSkipAddDlg(QString uri) { addMagnetUri(uri, false); } diff --git a/src/bittorrent.h b/src/bittorrent.h index 75648ea8b..7e753adf7 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -170,6 +170,7 @@ class bittorrent : public QObject { void processDownloadedFile(QString, QString); void saveTrackerFile(QString hash); void addMagnetSkipAddDlg(QString uri); + void downloadFromURLList(const QStringList& urls); protected slots: void scanDirectory(QString); diff --git a/src/misc.h b/src/misc.h index 7ab5bf4fd..e26ce6750 100644 --- a/src/misc.h +++ b/src/misc.h @@ -99,11 +99,17 @@ public: } - static unsigned long long freeDiskSpaceOnPath(QString path) { + static long long freeDiskSpaceOnPath(QString path) { + if(path.isEmpty()) return -1; + QDir dir_path(path); + if(!dir_path.exists()) { + if(!dir_path.cdUp()) return -1; + } + Q_ASSERT(dir_path.exists()); #ifndef Q_WS_WIN unsigned long long available; struct statfs stats; - int ret = statfs ((path+"/.").toLocal8Bit().data(), &stats) ; + int ret = statfs ((dir_path.path()+"/.").toLocal8Bit().data(), &stats) ; if(ret == 0) { available = ((unsigned long long)stats.f_bavail) * ((unsigned long long)stats.f_bsize) ; diff --git a/src/torrentAddition.h b/src/torrentAddition.h index e21e05f6b..fe295fd8a 100644 --- a/src/torrentAddition.h +++ b/src/torrentAddition.h @@ -90,6 +90,7 @@ public: connect(actionMaximum, SIGNAL(triggered()), this, SLOT(maximumSelection())); connect(collapseAllButton, SIGNAL(clicked()), torrentContentList, SLOT(collapseAll())); connect(expandAllButton, SIGNAL(clicked()), torrentContentList, SLOT(expandAll())); + torrentContentList->header()->resizeSection(0, 200); //torrentContentList->header()->setResizeMode(0, QHeaderView::Stretch); QString home = QDir::homePath(); @@ -148,6 +149,7 @@ public: delete arb; connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*))); //torrentContentList->expandAll(); + connect(savePathTxt, SIGNAL(textChanged(QString)), this, SLOT(updateDiskSpaceLabels())); updateDiskSpaceLabels(); show(); } @@ -278,7 +280,7 @@ public slots: } void updateDiskSpaceLabels() { - unsigned long long available = misc::freeDiskSpaceOnPath(savePathTxt->text()); + long long available = misc::freeDiskSpaceOnPath(savePathTxt->text()); lbl_disk_space->setText(misc::friendlyUnit(available)); // Determine torrent size @@ -293,7 +295,7 @@ public slots: lbl_torrent_size->setText(misc::friendlyUnit(torrent_size)); // Check if free space is sufficient if(available > 0) { - if(available > torrent_size) { + if((unsigned long long)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 { @@ -316,7 +318,6 @@ public slots: } if(!dir.isNull()){ savePathTxt->setText(dir); - updateDiskSpaceLabels(); } }