From 3945ea6537a8f1c23c74c65b008a8d6079e873ab Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 16 Mar 2011 10:59:59 +0100 Subject: DM now appends download index to filename in case file already exists --- src/downloadManager.cpp | 22 ++++++++++++++++------ src/main.cpp | 3 ++- src/testApp.sh | 6 ++---- 3 files changed, 20 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/downloadManager.cpp b/src/downloadManager.cpp index 0262efe..9b44a3d 100644 --- a/src/downloadManager.cpp +++ b/src/downloadManager.cpp @@ -74,13 +74,21 @@ void downloadManager::startNextDownload() tmp.remove(0, tmp.lastIndexOf(QChar('/')) + 1); if (debug) qDebug() << "Extracted " << tmp << "from " << url.toString(); - outfile.setFileName(downloadPath + "/" + tmp); - if (!outfile.open(QIODevice::WriteOnly)) - { + /* check if filename exists on target file system */ + QFileInfo fi(downloadPath + "/" + tmp); + if (fi.exists()){ + QString qs = QString(fi.absoluteFilePath() + ".\%1").arg(downloaded); + outfile.setFileName(qs); + } + else + outfile.setFileName(downloadPath + "/" + tmp); + + if (!outfile.open(QIODevice::WriteOnly)){ if (debug) qDebug() << "Couldn't open file! Skipping..."; return; } - + QString qs = QString(fi.absoluteFilePath() + ".\%1").arg(downloaded); + qDebug() << "TEST:" << qs; /* send the request for the file */ QNetworkRequest request(url); currentDownload = qnam->get(request); @@ -121,10 +129,12 @@ void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) QString unit; if (speed < 1024) { unit = "bytes/sec"; - } else if (speed < 1024*1024) { + } + else if (speed < 1024*1024) { speed /= 1024; unit = "KB/s"; - } else { + } + else { speed /= 1024*1024; unit = "MB/s"; } diff --git a/src/main.cpp b/src/main.cpp index 3138838..689b3e4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,7 +12,8 @@ void printHelp() qout << QObject::tr("Usage: ./fbgui [OPTIONS]") << endl; qout << QObject::tr("Options:") << endl; qout << "-u , --url= " << QObject::tr("Set which URL to load.") << endl; - qout << "-d , --downloaddir= " << QObject::tr("Specifiy the download directory.") << endl; + qout << "-d , --download= " << QObject::tr("Specify the download directory.") << endl; + qout << "-c , --config= " << QObject::tr("Path to config file.") << endl; qout << "-D, --debug " << QObject::tr("Activate debug mode.") << endl; qout << "-h, --help " << QObject::tr("Prints usage information.") << endl; qout.flush(); diff --git a/src/testApp.sh b/src/testApp.sh index 4e80f5a..444636b 100755 --- a/src/testApp.sh +++ b/src/testApp.sh @@ -3,19 +3,17 @@ # Use: ./testApp.sh [OPTIONS] # OPTIONS: -D, --debug # -u , --url= -# -d , --downloaddir= (dir relative) +# -d , --download= absolute dir for downloads. +# -c , --config= path to config file. # script_path="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")" - # to get the path only - not the script name - add working_path=`dirname "$script_path"` display_id=$(grep -n $(whoami) /etc/passwd| head -n 1|awk -F : '{print $1}') - # Start QT's virtual framebuffer with proper displayID /usr/local/Trolltech/Qt-4.7.1/bin/qvfb -width 800 -height 600 -qwsdisplay :$display_id & sleep 0.1 # Start fbgui. -echo "$working_path/fbgui -display QVFb:$display_id $@" $working_path/fbgui -display QVFb:$display_id $@ # Check if fbbrowser is not running, if so kill the qvfb. if [ $(ps aux | grep -v grep | grep -c fbgui) -eq 1 ] -- cgit v1.2.3-55-g7522