- resolved a bug in filelist: when clicking again on a directory add
again files - resolved bug: at startup relaoding download do not start downloading - added downloading filename in progress bar
This commit is contained in:
+127
-74
@@ -33,8 +33,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
QAbstractButton * reply;
|
||||
QMessageBox msgBox;
|
||||
ui->setupUi(this);
|
||||
|
||||
QCoreApplication::setOrganizationName("RsyncUI");
|
||||
@@ -61,6 +59,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
AboutW.TextAbout->setHtml(aboutText);
|
||||
|
||||
// connectors
|
||||
connect(this, &MainWindow::fileName, ui->progressBar, &QProgressBar::setFormat);
|
||||
connect(this, &MainWindow::progressSignal, ui->progressBar, &QProgressBar::setValue);
|
||||
//connect(this, &MainWindow::errorSignal, this, &MainWindow::downloadingErrorSlot);
|
||||
connect(this, &MainWindow::stopDownloading, this, &MainWindow::cancelled);
|
||||
@@ -100,6 +99,16 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
//setting unit of bandwidth limit
|
||||
config.UnitCombobox->addItems({tr("KB"), tr("MB"), tr("GB"), tr("TB"), tr("PB")});
|
||||
|
||||
initSystemTrayIcon();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::init()
|
||||
{
|
||||
QAbstractButton * reply;
|
||||
QMessageBox msgBox;
|
||||
|
||||
//if exists list of donwloads in saved settings
|
||||
if (this->settings.value("Downloads/rows").toInt() != 0)
|
||||
{
|
||||
@@ -122,7 +131,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
}
|
||||
// load list of services
|
||||
populateList();
|
||||
initSystemTrayIcon();
|
||||
}
|
||||
|
||||
void MainWindow::initSystemTrayIcon()
|
||||
@@ -192,23 +200,34 @@ void MainWindow::quitApp()
|
||||
param |= QMessageBox::Save;
|
||||
displayText = tr("Clicking Save button, You can save the list of downloads\n");
|
||||
}
|
||||
|
||||
reply = QMessageBox::question(
|
||||
this,
|
||||
"RsyncUI",
|
||||
tr("Exiting will stop downloading, and will clear the download queue.\nDo you want to exit ?") + displayText,
|
||||
param,
|
||||
QMessageBox::No);
|
||||
|
||||
this->downloading.quit = true;
|
||||
if(reply == QMessageBox::Yes)
|
||||
{
|
||||
// emission of signal to downloading thread and stopping
|
||||
emit (stopDownloading(this->downloading.process));
|
||||
}else
|
||||
if (this->downloading.process->state() != QProcess::NotRunning)
|
||||
{
|
||||
// emission of signal to downloading thread and stopping
|
||||
emit (stopDownloading(this->downloading.process));
|
||||
}
|
||||
}else if (reply == QMessageBox::Save)
|
||||
{
|
||||
saveDownloadList();
|
||||
if (config.autosaveCheckbox->checkState() == Qt::Unchecked)
|
||||
{
|
||||
|
||||
//saveDownloadList();
|
||||
emit (stopDownloading(this->downloading.process));
|
||||
}
|
||||
}else if (reply == QMessageBox::No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
//delete ui;
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
|
||||
@@ -385,54 +404,62 @@ void MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt
|
||||
QProcess * myProcess;
|
||||
bool isDir = false;
|
||||
bool flag = false;
|
||||
int nChild = 0;
|
||||
|
||||
cmd = "rsync";
|
||||
param << "--contimeout=10" << "--port=" + QString::number(portN) << server + "::" + path;
|
||||
|
||||
myProcess = new QProcess(this);
|
||||
myProcess->start(cmd, param);
|
||||
|
||||
// waiting for responsiteme of the server with a timeout of 10 seconds
|
||||
while(myProcess->waitForReadyRead(100000))
|
||||
if (parent != NULL)
|
||||
{
|
||||
while (!flag)
|
||||
{
|
||||
line = QString::fromUtf8(myProcess->readLine());
|
||||
// line empty then buffer is empty so returning to wait new datas
|
||||
if (line.isEmpty())
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
// extracting name, size and is dir/file
|
||||
line = line.simplified();
|
||||
size = line.section(" ", 1, 1);
|
||||
filename = line.section(" ", 4);
|
||||
if (filename != '.')
|
||||
{
|
||||
if (line[0] == "d")
|
||||
{
|
||||
isDir = true;
|
||||
}else
|
||||
{
|
||||
isDir = false;
|
||||
}
|
||||
if (parent != NULL)
|
||||
{
|
||||
//adding item to tree
|
||||
addTreeChild(parent, filename, size, isDir);
|
||||
}else
|
||||
{
|
||||
//adding item to tree (as directory)
|
||||
addTreeRoot(filename, size, isDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flag = false;
|
||||
nChild = parent->childCount();
|
||||
}
|
||||
if (nChild == 0)
|
||||
{
|
||||
cmd = "rsync";
|
||||
param << "--contimeout=10" << "--port=" + QString::number(portN) << server + "::" + path;
|
||||
|
||||
myProcess = new QProcess(this);
|
||||
myProcess->start(cmd, param);
|
||||
|
||||
// waiting for responsiteme of the server with a timeout of 10 seconds
|
||||
while(myProcess->waitForReadyRead(100000))
|
||||
{
|
||||
while (!flag)
|
||||
{
|
||||
line = QString::fromUtf8(myProcess->readLine());
|
||||
// line empty then buffer is empty so returning to wait new datas
|
||||
if (line.isEmpty())
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
// extracting name, size and is dir/file
|
||||
line = line.simplified();
|
||||
size = line.section(" ", 1, 1);
|
||||
filename = line.section(" ", 4);
|
||||
if (filename != '.')
|
||||
{
|
||||
if (line[0] == "d")
|
||||
{
|
||||
isDir = true;
|
||||
}else
|
||||
{
|
||||
isDir = false;
|
||||
}
|
||||
if (parent != NULL)
|
||||
{
|
||||
//adding item to tree
|
||||
addTreeChild(parent, filename, size, isDir);
|
||||
}else
|
||||
{
|
||||
//adding item to tree (as directory)
|
||||
addTreeRoot(filename, size, isDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flag = false;
|
||||
}
|
||||
// buffer empty go to waiting new datas
|
||||
testRsyncReturn(myProcess);
|
||||
}
|
||||
// buffer empty go to waiting new datas
|
||||
testRsyncReturn(myProcess);
|
||||
}
|
||||
|
||||
// Verify if server address is IP address
|
||||
@@ -594,6 +621,7 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD
|
||||
QString path;
|
||||
QString str;
|
||||
QMessageBox::StandardButton reply;
|
||||
int sizeFromRsync;
|
||||
|
||||
itemR = item;
|
||||
|
||||
@@ -621,27 +649,48 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD
|
||||
itemR = itemR->parent();
|
||||
// concatening parent to path
|
||||
path.prepend(itemR->text(0) + "/");
|
||||
sizeFromRsync = itemR->text(1).toUInt();
|
||||
};
|
||||
|
||||
QFileInfo info(path);
|
||||
if (item->text(1) == tr("File") or downloadDir == true)
|
||||
{
|
||||
// Item is a file
|
||||
// searching if file exists in savepath
|
||||
if (QFile::exists(this->downloading.savePath + "/" + path))
|
||||
{
|
||||
reply = QMessageBox::question(
|
||||
this,
|
||||
"RsyncUI",
|
||||
tr("File is already downloaded. Do you want to reload it ? The old file will be deleted"),
|
||||
QMessageBox::Yes|QMessageBox::No,
|
||||
QMessageBox::No);
|
||||
|
||||
if (reply == QMessageBox::No)
|
||||
if (info.size() >= sizeFromRsync)
|
||||
{
|
||||
return;
|
||||
reply = QMessageBox::question(
|
||||
this,
|
||||
"RsyncUI",
|
||||
tr("File is partially downloaded. Do you want to resume download ? if no, the file will be deleted from destination directory"),
|
||||
QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel,
|
||||
QMessageBox::Cancel);
|
||||
|
||||
if (reply == QMessageBox::Cancel)
|
||||
{
|
||||
return;
|
||||
}else if(reply == QMessageBox::No)
|
||||
{
|
||||
QFile::remove(this->downloading.savePath + "/" + path);
|
||||
return;
|
||||
}
|
||||
}else
|
||||
{
|
||||
QFile::remove(this->downloading.savePath + "/" + path);
|
||||
reply = QMessageBox::question(
|
||||
this,
|
||||
"RsyncUI",
|
||||
tr("File is already downloaded. Do you want to reload it ? The old file will be deleted"),
|
||||
QMessageBox::Yes|QMessageBox::No,
|
||||
QMessageBox::No);
|
||||
|
||||
if (reply == QMessageBox::No)
|
||||
{
|
||||
return;
|
||||
}else
|
||||
{
|
||||
QFile::remove(this->downloading.savePath + "/" + path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -689,7 +738,7 @@ void MainWindow::startDownloading()
|
||||
ui->progressBar->show();
|
||||
|
||||
//QtConcurrent::run(&this->downloadO, &downloadFile::download, this);
|
||||
download();
|
||||
this->download();
|
||||
this->trayIcon->showMessage("RsyncUI", tr("Starting downloading\n") + this->downloading.path, QSystemTrayIcon::Information);
|
||||
}
|
||||
|
||||
@@ -744,11 +793,11 @@ void MainWindow::downloadFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
if (ui->listDownload->count() != 0)
|
||||
{
|
||||
// autosave is activated
|
||||
if (config.autosaveCheckbox->checkState() == Qt::Checked)
|
||||
/*if (config.autosaveCheckbox->checkState() == Qt::Checked)
|
||||
{
|
||||
// saving download list
|
||||
saveDownloadList();
|
||||
}
|
||||
}*/
|
||||
|
||||
// initializing download
|
||||
path = ui->listDownload->item(0)->text();
|
||||
@@ -778,7 +827,10 @@ void MainWindow::downloadFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
saveDownloadList();
|
||||
if(config.autosaveCheckbox->checkState() == Qt::Checked and this->downloading.quit == false)
|
||||
{
|
||||
saveDownloadList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -815,13 +867,14 @@ void MainWindow::on_listDownload_itemClicked(QListWidgetItem *item)
|
||||
// removing line from download list
|
||||
ui->listDownload->removeItemWidget(item);
|
||||
delete item;
|
||||
if (config.autosaveCheckbox->checkState() == Qt::Checked)
|
||||
{
|
||||
// autosave acivated,so saving download list
|
||||
saveDownloadList();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (config.autosaveCheckbox->checkState() == Qt::Checked)
|
||||
{
|
||||
// autosave acivated,so saving download list
|
||||
saveDownloadList();
|
||||
}
|
||||
}
|
||||
|
||||
// load settings
|
||||
|
||||
Reference in New Issue
Block a user