From 8419f8ad9039f3678a5b187cadb0f03337f024c2 Mon Sep 17 00:00:00 2001 From: Daniel Tartavel Date: Wed, 15 Feb 2023 13:49:31 +0100 Subject: [PATCH] - 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 --- RsyncUI.pro.user | 2 +- RsyncUI_fr_FR.ts | 127 ++++++------ downloadfile.cpp | 13 ++ languages/fr_FR/LC_MESSAGES/RsyncUI_fr_FR.qm | Bin 19198 -> 19610 bytes main.cpp | 1 + mainwindow.cpp | 201 ++++++++++++------- mainwindow.ui | 9 +- 7 files changed, 217 insertions(+), 136 deletions(-) diff --git a/RsyncUI.pro.user b/RsyncUI.pro.user index 7f059d0..1404cf4 100644 --- a/RsyncUI.pro.user +++ b/RsyncUI.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/RsyncUI_fr_FR.ts b/RsyncUI_fr_FR.ts index 729be00..33ea27f 100644 --- a/RsyncUI_fr_FR.ts +++ b/RsyncUI_fr_FR.ts @@ -74,141 +74,141 @@ Fenêtre principale - + Server Serveur Serveur - + Enter server's URL Entrez l'adresse du serveur - + Port Port - + Enter rsync port on server Entrez le port du serveur rsync - + Press button to connect to rsync server Connect to server Cliquez pour se connecter au serveur rsync - + Connection Connexion - + Return Retour - + Click to view the list of files of this folder Cliquez pour afficher la liste des documents - + Click to add to download queue Cliquez pour ajouter à la file de téléchargement - + Click on file to stop downloading Cliquez sur le document pour arrêter le téléchargement et l'enlever de la file - + %p% Downloading Téléchargement - + toolBar Barre d'outils - + Download Télécharger - + Click on menu button to download the entire folder Cliquer sur le bouton droit de la souris pour télécharger le dossier entier - + Exit Quitter - + Terminate the program Terminer le programme - + Ctrl+Q Ctrl+Q - - + + Change save folder Changer le dossier de destination - + About À propos - + About Qt À propos de Qt - + Settings Paramètres - + KB Ko - + MB Mo - + GB Go - + TB To - + PB Po - + You click on file to enqueue it, and RyncUI Download one file a time Client for rsync server<br><br>You click on file to enqueue it, and RyncUI Download one file a time <h3>Utilisation</h3> @@ -241,150 +241,159 @@ Cliquez sur un fichier pour le supprimer de la file et une fenêtre de confirmat Permet de quitter le programme - <h2>Client for rsync server<2><br><br> - <h2>Client pour serveur rsync<2><br><br>éaa + <h2>Client pour serveur rsync<2><br><br>éaa - + Path Chemin - + Size Taille - + Type Type - + A list of interrupted downloads exists, do you want to continue downloading ? if not the list will be cleared Une liste de téléchargement existe, voulez-vous utiliser cette liste ? si non, elle sera effacée - + &Quit &Quitter - + Clicking Save button, You can save the list of downloads Vous pouvez enregistrer la liste des téléchargements en cliquant sur "enregister" - + Exiting will stop downloading, and will clear the download queue. Do you want to exit ? Si vous sortez, les téléchargements seront arrêter. Voulez-vous vraiment sortir ? - + The program will keep running in the system tray. To terminate the program, choose <b>Quit</b> in the context menu of the system tray entry. Le programme continue dans la boîte à miniatures. Pour quitter le programme cliquez sur l'icône <b>Quitter</b> ou dans les menu contextuel. - + server does not exists Le serveur n'existe pas - - + + Dir dossier - - + + File Doc - + + File is partially downloaded. Do you want to resume download ? if no, the file will be deleted from destination directory + Le document est déjà partiellement téléchargé. Voulez vous continuer le téléchargemnt ? Si non, il sera supprimer du dossier de destination + + + File is already downloaded. Do you want to reload it ? The old file will be deleted Le document est déjà téléchargé. Voulez-vous le télécharger à nouveau ? L'ancien fichier sera effacé - + File is already downloading Le document est déjà en téléchargement - + Starting downloading Démarrage du téléchargement - + finished Terminé - + Rsync process crashed Le processus rsync à planté - + stopped by user stoppé par l'utilisateur - + Download Téléchargement - + Version Version - + + <h2>Client for rsync server</h2> + <h2>Client pour serveur rsync</h2> + + + Licence License - + Author Auteur - + EMail Courriel - + Source code Code source - + Since the save path is linked to service, you need to select a service before you can select a folder Vous devez sélectionnez un service pour pouvoir sélectionnez un dossier par défaut - + Choose folder where to save file Choisissez un dossier où enregistrer le document - + Do you want to stop downloading and delete this file from download queue ? Voulez-vous arrêter le téléchargement et enlever ce fichier de la file de téléchargement ? - + Do you want to delete this file from download queue ? Voulez-vous enlever ce fichier de la file de téléchargement ? diff --git a/downloadfile.cpp b/downloadfile.cpp index e8edec5..43cba48 100644 --- a/downloadfile.cpp +++ b/downloadfile.cpp @@ -27,7 +27,14 @@ downloadFile::downloadFile() //Slot activated when download is cancelled void MainWindow::cancelled(QProcess * process) { + bool n = 0; + process->terminate(); + n = process->waitForFinished(30000); + if (n == false) + { + process->kill(); + } } // launch a rsync processus downloading a file @@ -83,6 +90,12 @@ void MainWindow::readRsyncOutput() // sending progress to Main window emit progressSignal(value); } + }else + { + if (!line.contains("receiving")) + { + emit fileName(line.remove(QChar('\n'), Qt::CaseInsensitive) + " %p%"); + } } } } diff --git a/languages/fr_FR/LC_MESSAGES/RsyncUI_fr_FR.qm b/languages/fr_FR/LC_MESSAGES/RsyncUI_fr_FR.qm index 47131d00019c5ae705b348ca30abafa6690ecf6a..406a6730c0f3077fd7eda7118617f14da10a557a 100644 GIT binary patch delta 1062 zcmX|9e{2(F7=Et3yWXuoj*YH!-PT^2%cAT@*vd8+R&Zl1ps9=*5{XV*dR-5%SLk(v zX+m{DjmZR)6BWx4e@so#7@2WV$=JvUTGag@B#Mb9CMNz-G3X*LA=9`2_{Vq8_r3SL z&-1?T_pO~|-Z;g)?92WJu;&49gz!(o=K-#a@MpqqpsJs64DgQt4Ry4C40yl-lrDi? zV1e>y!7ftVlLwdhfcPWeMqVMD1osvP_;TQ86`*bhJnbRi{yA(Mr#vo)zE|ggtnCbT zwci2UDeQhd2DIjJsOvUxS0i(CR0lS%SOz~I1bQbe-wnMB@Ov!RYy4z<-m*G>nF>8; z4G1L6eq;S%IZTDFT7NW#r~sCI^zEa7y@DP8I0`rd?70&R6@Hfe@L@9c{Kd|cxR6Du z!e09JaiEN0SEgSi<0;OvOoE+PxYiBD#68>*#}&XC2dWQnr%zu3YB+A1q0Xgx z?jnB^xNnBHHJk!0S^kl$>#31{`F;5`;M&F?yEX%aa{RBG$asB$FGSV=<|KdTh@J)d zmTe`54+!+wqF=axu4P-Ijj(OncHuyQI`!I?KBfN~1cANxC?J#zUEMTN$7MnPMv)5i<;CD8G8FfUT4V*VEsJ9+<=0J$3pLp!jVxF4 zv@u2<8TN`3t<=G+z3t6?6fd#I1$q;~S$koL1lzAUswM^j>!Rby+jQm@9A7d9<#jl| zKIdYRek?#z; z2C9kfzQ+~y5yAbA>yQ4sX+%M(zJmldTcn4060Utt>My6qRh^TD{Ht{5FGl6O^82hRnY~~oD-FHSk%sx1wP$L;dW>VX zo8Joo^O>4TH@2V|3A7+26r12_$!4cm%{C`mLgptG?x~FUM45&0n7gYsRvtuzbTUw( zkg7)CBrP2oGvuwWlre%7hG9U)e%eu-m^y~dtLtj(izgXdX$??Rrg)LjKs%L`WXe)V zJ7R_#E16-lsj12Pe?_A^R85gpLp~TuXVi$MnSXozyNuzaBF9pPbuAT%$y;SLF6*fV xIg?Q2c#(ft)igOu6h%`qN=%NYQ%O1)8C8#D)RZpA)U>iclS+?H%~f?Z{|EN-2W0>N delta 818 zcmYjPTS!z<6kRiO&wV(L+t{d;&X{Qm<^yMJG}9@kQpm8Rh>|iL@>MqZ2(bbOtRG1< zn5;}C3yGjY(x5V5iBXwvF{mg->O-0gE2u!MZC`zC*5#bN*V=2{bFD$KRIj*ba?Jo- zJFse)@Eai&^9EL@5!wm639A6(ED*7tz7GRwNQTUKMM=_6S|n95 zf7%JeW-GHEX93&w%8~q5fG<)`83RdpNcnr<843ESfRnkrofmV5 zZdL;77_O$x0cbXJcj^?hcqeyv9|`+uxgIYaT+q9?{^28lw?9)(5YZ+Jv#eVlC}Qbh zM94;2h2}Y+tz>;aMl{!VQO>P+%q87%X%h^N`b6 zVf+EzuRSGl;gx_GEhgD1Qq8pJoSg!2OI+}z0|^(zrCmuiSdIp~E3%dv_EY!=wKK3AMu> diff --git a/main.cpp b/main.cpp index fc6da0f..54d6085 100644 --- a/main.cpp +++ b/main.cpp @@ -23,5 +23,6 @@ int main(int argc, char *argv[]) MainWindow w; w.show(); + w.init(); return a.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index aa4177b..0e7c371 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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 diff --git a/mainwindow.ui b/mainwindow.ui index e87d43b..f3efe40 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -21,7 +21,8 @@ MainWindow - + + .. Qt::ToolButtonTextUnderIcon @@ -356,6 +357,9 @@ 0 + + Qt::AlignCenter + %p% @@ -449,7 +453,8 @@ - + + .. Exit