diff --git a/RsyncUI.pro b/RsyncUI.pro
index 7c53530..0b5fc16 100644
--- a/RsyncUI.pro
+++ b/RsyncUI.pro
@@ -27,10 +27,11 @@ HEADERS += \
tools.h
FORMS += \
+ configuration.ui \
mainwindow.ui
TRANSLATIONS += \
- languages/RsyncUI_fr_FR.ts
+ languages/fr/RsyncUI_fr_FR.ts
INCLUDEPATH += \
/usr/include/KF5
diff --git a/configuration.ui b/configuration.ui
new file mode 100644
index 0000000..a91fcbe
--- /dev/null
+++ b/configuration.ui
@@ -0,0 +1,122 @@
+
+
+ Configuration
+
+
+ Qt::WindowModal
+
+
+
+ 0
+ 0
+ 400
+ 300
+
+
+
+ Configuration
+
+
+
+
+ 9
+ 9
+ 381
+ 251
+
+
+
+ -
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+ 1024
+
+
+
+ -
+
+
+ Bandwidth limit
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+ -1
+
+
+ 5
+
+
+ 1024
+
+
+
+
+
+
+
+
+ 70
+ 260
+ 321
+ 34
+
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+
+
+
+ buttonBox
+ accepted()
+ Configuration
+ accept()
+
+
+ 248
+ 254
+
+
+ 157
+ 274
+
+
+
+
+ buttonBox
+ rejected()
+ Configuration
+ reject()
+
+
+ 316
+ 260
+
+
+ 286
+ 274
+
+
+
+
+
diff --git a/downloadfile.cpp b/downloadfile.cpp
index 785453b..57e6ca6 100644
--- a/downloadfile.cpp
+++ b/downloadfile.cpp
@@ -41,16 +41,24 @@ void downloadFile::download(MainWindow *mw)
vector v;
int value;
char buffer[4096];
+
argv[0] = "/usr/bin/rsync";
- argv[1] = "--bwlimit=" + mw->connexion.bandwidthLimit;
+ if (mw->connexion.bandwidthLimit == 0)
+ {
+ argv[1] = "--bwlimit=1000P";
+ }else
+ {
+ output << mw->connexion.bandwidthLimit;
+ argv[1] = "--bwlimit=" + output.str() + mw->connexion.bandwidthLimitUnit;
+ }
argv[2] = "--port=" + to_string(mw->connexion.port);
argv[3] = "-P";
argv[4] = mw->connexion.server + "::" + mw->downloading.service + "/" + mw->downloading.path;
argv[5] = mw->downloading.savePath + "/";
+ argv[6] = "";
- //unique_ptr pipe(popen(cmd "r"), pclose);
+ //launching downloading thread
FILE * fp = popen2(argv, "r", mw->downloading.pid);
-
if (!fp)
{
throw runtime_error("popen2() failed!");
@@ -64,7 +72,6 @@ void downloadFile::download(MainWindow *mw)
return;
}
line = buffer;
- //cout << line << endl;
pos = line.find('%');
if (pos != -1)
{
@@ -74,14 +81,14 @@ void downloadFile::download(MainWindow *mw)
{
line.erase(0, pos);
value = stoi(line);
- //cout << value << endl;
emit progressSignal(value);
}
}
}
pclose2(fp, mw->downloading.pid);
+
+ // ProgressBar to 100% and emit signal finished to main application
emit progressSignal(100);
emit finishedSignal(true);
- //cout << path << endl;
}
diff --git a/downloadfile.h b/downloadfile.h
index da0b1c0..1cfef71 100644
--- a/downloadfile.h
+++ b/downloadfile.h
@@ -2,7 +2,9 @@
#define DOWNLOADFILE_H
#include
-//#include "ui_mainwindow.h"
+#include
+#include
+#include
class MainWindow;
diff --git a/languages/fr/RsyncUI_fr_FR.qm b/languages/fr/RsyncUI_fr_FR.qm
index 3d78c29..68138d6 100644
Binary files a/languages/fr/RsyncUI_fr_FR.qm and b/languages/fr/RsyncUI_fr_FR.qm differ
diff --git a/languages/fr/RsyncUI_fr_FR.ts b/languages/fr/RsyncUI_fr_FR.ts
new file mode 100644
index 0000000..4b41b76
--- /dev/null
+++ b/languages/fr/RsyncUI_fr_FR.ts
@@ -0,0 +1,190 @@
+
+
+
+
+ Configuration
+
+
+
+ Configuration
+
+
+
+
+ Bandwidth limit
+ Limite de bande passante
+
+
+
+ MainWindow
+
+
+
+ Fenêtre principale
+
+
+
+
+ Serveur
+ Serveur
+
+
+
+
+ Port
+
+
+
+
+ Connexion
+
+
+
+
+ Retour
+
+
+
+
+ Downloading
+ Téléchargement
+
+
+
+
+
+ Menu
+
+
+
+
+ Aide
+
+
+
+
+
+ Changer le dossier de destination
+
+
+
+ Dossier d'enregistrement
+
+
+
+
+ Limite de bande passante
+
+
+
+
+ À propos
+
+
+
+
+ À propos de Qt
+
+
+
+
+ Paramètres
+
+
+
+ debug
+
+
+
+
+ Octet
+
+
+
+
+ Ko
+
+
+
+
+ Mo
+
+
+
+
+ Go
+
+
+
+
+ To
+
+
+
+
+
+ Po
+
+
+
+
+ Chemin
+
+
+
+
+ Taille
+
+
+
+
+ Soritr stoppera le téléchargement et effacera la file des téléchargements.
+Voulez-vous vraiment sortir du programme ?
+
+
+
+
+ Le serveur n'existe pas
+
+
+
+
+ License
+
+
+
+
+ Auteur
+
+
+
+
+ Courriel
+
+
+
+
+ Code source
+
+
+
+
+ Choisissez le dossier où enregistrer
+
+
+
+
+ Vouslez-vous arrêter le téléchargement et enlever ce fichier de la file de téléchargement ?
+
+
+
+ Client pour serveur rsync
+
+
+
+
+ Voulez-vous enlever ce fichier de la file de téléchargement ?
+
+
+
diff --git a/main.cpp b/main.cpp
index dd6c8c7..d149ea1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -4,21 +4,24 @@
#include
#include
#include
-#include
+#include
+#include
+
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
-
QTranslator myappTranslator;
+
QLocale localeName = QLocale::system();
- QString localeFile = "./RsyncUI_" + localeName.name() + ".qm";
+ QString localeFile = "usr/share/locale/" + localeName.name() + "LC_MESSAGES/RsyncUI_" + localeName.name() + ".qm";
if (myappTranslator.load(localeFile))
{
a.installTranslator(&myappTranslator);
}
MainWindow w;
+
w.show();
return a.exec();
}
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 9bfc6f0..e546a54 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -1,32 +1,10 @@
#include "mainwindow.h"
-#include "ui_mainwindow.h"
-#include "downloadfile.h"
-#include "tools.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
using namespace std;
bool display = false;
+extern QDialog Configuration;
+extern Ui::Configuration config;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
@@ -38,34 +16,50 @@ MainWindow::MainWindow(QWidget *parent)
QCoreApplication::setApplicationName("RsyncUI");
// init shortcut
-
- // QShortcut * shortcut = new QShortcut(QKeySequence("Return"), this);
loadSettings();
+ config.setupUi(&Configuration);
+ config.UnitCombobox->addItems({tr("Byte"), tr("KB"), tr("MB"), tr("GB"), tr("TB"), tr("PB")});
+
+ // init of About
+ this->about.description = tr(this->about.description.toStdString().c_str());
// connectors
connect(&downloadO, &downloadFile::progressSignal, ui->progressBar, &QProgressBar::setValue);
connect(&downloadO, &downloadFile::finishedSignal, this, &MainWindow::downloadFinished);
connect(this, &MainWindow::stopDownloading, &downloadO, &downloadFile::cancelled);
- //connect(shortcut, SIGNAL(activated()), this, SLOT(returnPressed()));
+ connect(config.buttonBox, SIGNAL(accepted()), this, SLOT(on_buttonBox_accepted()));
// init of widgets
ui->ktreewidgetsearchline->setTreeWidget(ui->treeWidget);
ui->ktreewidgetsearchline->setCaseSensitivity(Qt::CaseInsensitive);
ui->treeWidget->setHeaderLabels({tr("Path"), tr("Size")} );
+ if (this->settings.contains("connexion/lastServer"))
+ {
+ ui->portEdit->setText(this->settings.value("connexion/port").toString());
+ ui->khistorycombobox->setCurrentText(this->settings.value("connexion/lastServer").toString());
+ }else
+ {
+ ui->portEdit->text() = QString::number(this->connexion.port);
+ ui->khistorycombobox->clear();
+ }
+
+
ui->progressBar->hide();
populateList();
}
-void MainWindow::returnPressed()
-{
- populateList();
-}
-
MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+void MainWindow::closeEvent (QCloseEvent *event)
{
QMessageBox::StandardButton reply;
+ saveSettings();
+
if (ui->listDownload->count() != 0)
{
reply = QMessageBox::question(
@@ -74,17 +68,17 @@ MainWindow::~MainWindow()
tr("Exiting will stop downloading, and will clear the download queue.\n Do you want to exit ?"),
QMessageBox::Yes|QMessageBox::No,
QMessageBox::No);
- if (reply == QMessageBox::Yes)
+ if (reply == QMessageBox::No)
+ {
+ event->ignore();
+ return;
+ }else
{
emit (stopDownloading(this->downloading.pid));
+ waitpid(this->downloading.pid, NULL, WUNTRACED);
}
}
- saveSettings();
- if (this->downloading.pid != 0)
- {
- waitpid(this->downloading.pid, NULL, WUNTRACED);
- }
- delete ui;
+ event->accept();
}
void MainWindow::populateTree()
@@ -110,46 +104,49 @@ void MainWindow::populateList()
stringstream ss;
QString str;
QString server;
- QString port;
+ int port;
- ui->listWidget->clear();
server = ui->khistorycombobox->currentText();
- this->connexion.server.assign(server.toStdString());
- ss << ui->portEdit->text().toStdString();
- ss >> this->connexion.port;
-
- this->settings.beginGroup("connexion/server");
- if (this->settings.contains(server))
+ port = ui->portEdit->text().toUInt();
+ if ((server.toStdString() != this->connexion.server) or (port != this->connexion.port))
{
- port = this->settings.value(server).toString();
- ui->portEdit->setText(port);
- this->connexion.port = this->settings.value(server).toInt();
- }
+ ui->listWidget->clear();
+ this->connexion.server.assign(server.toStdString());
+ this->connexion.port = port;
- if (!server.isEmpty() and this->connexion.port > 0 and this->connexion.port < 65536)
- {
- if (validateServer(server.toStdString()))
+ this->settings.beginGroup("connexion/server");
+ if (this->settings.contains(server))
{
- //this->settings.beginGroup("connexion/server");
- if (!this->settings.contains(server))
- {
- cout << server.toStdString() << endl;
- // storing serverURL and port in settings
- this->settings.setValue(server, this->connexion.port);
- this->settings.sync();
-
- // storing in history of combobox
- ui->khistorycombobox->addToHistory(server);
- }
- // "waiting" cursor
- // load and display rsync services of the rsync server
- QGuiApplication::setOverrideCursor(Qt::WaitCursor);
- listServices();
- QGuiApplication::restoreOverrideCursor(); //setOverrideCursor(Qt::ArrowCursor);
+ port = this->settings.value(server).toUInt();
+ ui->portEdit->setText(QString::number(port));
+ this->connexion.port = port;
}
+
+ if (!server.isEmpty() and (port > 0 and port < 65536))
+ {
+ if (validateServer(server.toStdString()))
+ {
+ //this->settings.beginGroup("connexion/server");
+ if (!this->settings.contains(server))
+ {
+ cout << server.toStdString() << endl;
+ // storing serverURL and port in settings
+ this->settings.setValue(server, port);
+ this->settings.sync();
+
+ // storing in history of combobox
+ ui->khistorycombobox->addToHistory(server);
+ }
+ // "waiting" cursor
+ // load and display rsync services of the rsync server
+ QGuiApplication::setOverrideCursor(Qt::WaitCursor);
+ listServices();
+ QGuiApplication::restoreOverrideCursor(); //setOverrideCursor(Qt::ArrowCursor);
+ }
+ }
+ this->settings.endGroup();
+ QGuiApplication::restoreOverrideCursor(); //setOverrideCursor(Qt::ArrowCursor);
}
- this->settings.endGroup();
- QGuiApplication::restoreOverrideCursor(); //setOverrideCursor(Qt::ArrowCursor);
}
void MainWindow::listServices()
@@ -164,7 +161,6 @@ void MainWindow::listServices()
redi::ipstream in(cmd, redi::pstreams::pstdout | redi::pstreams::pstderr);
while (getline(in.out(), line))
{
- //cout << "stdout: " << line << endl;
boost::replace_all(line," ","");
boost::replace_all(line, "\t", " - ");
v = explode(line, ' ', 3 );
@@ -310,24 +306,14 @@ void MainWindow::displayTree()
}
-void MainWindow::on_khistorycombobox_returnPressed()
-{
- //populateList();
-}
-
void MainWindow::on_khistorycombobox_currentIndexChanged(int i)
{
- populateList();
-}
-
-void MainWindow::on_portEdit_returnPressed()
-{
- //populateList();
+ on_connectButton_clicked();
}
void MainWindow::on_connectButton_clicked()
{
- populateList();
+ populateList();
}
QTreeWidgetItem * MainWindow::addTreeRoot(QString name, QString fileSize)
@@ -363,7 +349,7 @@ void MainWindow::on_listWidget_clicked()
populateTree();
}
-void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item)
+void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item)
{
QFuture future;
QFileDialog dialog;
@@ -374,24 +360,15 @@ void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item)
{
item = item->parent();
this->downloading.path = item->text(0).toStdString() + "/" + this->downloading.path;
-
};
- //dirPath.append("/Vidéos/");
if (this->downloading.savePath.empty())
{
- if (this->downloading.dirPath.toStdString().empty())
- {
- this->downloading.dirPath = getenv("HOME");
- }
- if (this->downloading.savePath.empty())
- {
- on_DefaultSaveFolder_triggered();
- }
- if (!this->downloading.savePath.empty() && this->downloading.pid == 0)
- {
- startDownloading();
- }
+ on_DefaultSaveFolder_triggered();
+ }
+ if (!this->downloading.savePath.empty() && this->downloading.pid == 0)
+ {
+ startDownloading();
}
ui->listDownload->addItem(QString::fromStdString(this->downloading.path));
}
@@ -458,21 +435,29 @@ void MainWindow::on_listDownload_itemClicked(QListWidgetItem *item)
void MainWindow::loadSettings()
{
+ // restoring geometry and state of wondow and widgets
this->restoreGeometry(settings.value("window/geometry").toByteArray());
this->restoreState(settings.value("window/state").toByteArray());
ui->treeWidget->header()->restoreState(settings.value("treeView/state").toByteArray());
ui->splitter->restoreState(settings.value("splitter/state").toByteArray());
ui->splitter_2->restoreState(settings.value("splitter2/state").toByteArray());
+ // loading connexion settings
+ // loading servers history
this->settings.beginGroup("connexion/server");
-
QStringList servers = this->settings.allKeys();
this->settings.endGroup();
- this->downloading.dirPath = this->settings.value("Folder").toString();
for( const QString &server : servers )
{
ui->khistorycombobox->addToHistory(server);
}
+
+ // loading save path
+ this->downloading.savePath = this->settings.value("Folder").toString().toStdString();
+
+ // loading bandwidth limit
+ this->connexion.bandwidthLimit = this->settings.value("bandwidthlimit").toUInt();
+ this->connexion.bandwidthLimitUnit = this->settings.value("bandwidthlimitunit").toString().toStdString();
}
@@ -480,21 +465,21 @@ void MainWindow::saveSettings()
{
this->settings.setValue("window/geometry", saveGeometry());
this->settings.setValue("window/state", saveState());
- //ui->treeWidget->header()->saveState();
this->settings.setValue("treeView/state", ui->treeWidget->header()->saveState());
this->settings.setValue("splitter/state", ui->splitter->saveState());
this->settings.setValue("splitter2/state", ui->splitter_2->saveState());
-
+ this->settings.setValue("connexion/lastServer", QString::fromStdString(this->connexion.server));
+ this->settings.setValue("connexion/lastPort", QString::number(this->connexion.port));
this->settings.sync();
}
void MainWindow::on_actionAbout_triggered()
{
QString text = this->about.description + "\n\n" +
- "Licence: " + this->about.licence + "\n" +
- "Author: " + this->about.author + "\n" +
- "EMail : " + this->about.email + "\n" +
- "Source code: " + this->about.git;
+ tr("Licence" ) + ": " + this->about.licence + "\n" +
+ tr("Author") + ": " + this->about.author + "\n" +
+ tr("EMail") + ": " + this->about.email + "\n" +
+ tr("Source code") + ": " + this->about.git;
QMessageBox::about(this, this->about.title, text);
}
@@ -508,6 +493,34 @@ void MainWindow::on_DefaultSaveFolder_triggered()
QFileDialog dialog;
this->downloading.savePath = dialog.getExistingDirectory(this, tr("Choose directory to save file"), this->downloading.dirPath, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks).toStdString();
- this->downloading.dirPath = this->downloading.savePath.c_str();
- this->settings.setValue("Folder/", this->downloading.dirPath);
+ // this->downloading.dirPath = this->downloading.savePath.c_str();
+ this->settings.setValue("Folder/", this->downloading.savePath.c_str());
+ this->settings.sync();
+}
+
+void MainWindow::on_action_Settings_triggered()
+{
+ config.UnitCombobox->setCurrentText(QString::fromStdString(this->connexion.bandwidthLimitUnit));
+ config.spinBox->setValue(this->connexion.bandwidthLimit);
+ Configuration.show();
+}
+
+void MainWindow::on_buttonBox_accepted()
+{
+ QString unit;
+ QString bw;
+
+ bw = config.spinBox->text();
+ if (bw.toInt() == 0)
+ {
+ this->connexion.bandwidthLimit = 1000;
+ this->connexion.bandwidthLimitUnit = tr("PB").toStdString();
+ }else
+ {
+ this->connexion.bandwidthLimit = config.spinBox->value();
+ this->connexion.bandwidthLimitUnit = config.UnitCombobox->currentText().toStdString();
+ }
+ this->settings.setValue("bandwidthlimit", this->connexion.bandwidthLimit);
+ this->settings.setValue("bandwidthlimitunit", this->connexion.bandwidthLimitUnit.c_str());
+ this->settings.sync();
}
diff --git a/mainwindow.h b/mainwindow.h
index e50272e..d729934 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -1,15 +1,36 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
+#include "ui_mainwindow.h"
+#include "ui_configuration.h"
+#include "downloadfile.h"
#include "tools.h"
#include
#include
#include
#include
-#include "downloadfile.h"
#include
#include
#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
@@ -18,7 +39,8 @@ QT_END_NAMESPACE
class Connexion
{
public:
- std::string bandwidthLimit = "1M";
+ int bandwidthLimit = 0;
+ std::string bandwidthLimitUnit = "";
std::string server;
int port = 873;
};
@@ -66,27 +88,22 @@ class MainWindow : public QMainWindow
void startDownloading();
void loadSettings();
void saveSettings();
+ void closeEvent (QCloseEvent *event);
Connexion connexion;
Downloading downloading;
downloadFile downloadO;
QSettings settings;
About about;
-
+ QDialog Configuration;
+ Ui::Configuration config;
std::vector serversList;
private slots:
- void on_khistorycombobox_returnPressed();
-
- //void on_portEdit_userTextChanged();
-
- void on_portEdit_returnPressed();
-
- //void on_actionDownload_triggered();
void on_listWidget_clicked();
- void on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item);
+ void on_treeWidget_itemClicked(QTreeWidgetItem *item);
void downloadFinished();
@@ -102,15 +119,17 @@ class MainWindow : public QMainWindow
void on_DefaultSaveFolder_triggered();
- void returnPressed();
-
void on_connectButton_clicked();
-signals:
- void stopDownloading(int);
+ void on_action_Settings_triggered();
+
+ public slots:
+ void on_buttonBox_accepted();
+
+ signals:
+ void stopDownloading(int);
+ // void accepted();
};
-
-
#endif // MAINWINDOW_H
diff --git a/mainwindow.ui b/mainwindow.ui
index 50771de..ecab1a4 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -136,6 +136,9 @@
Qt::ImhPreferNumbers
+
+
+
@@ -199,19 +202,6 @@
- -
-
-
-
- 1
- 0
-
-
-
- Qt::ImhNoAutoUppercase
-
-
-
-
@@ -266,6 +256,19 @@
+ -
+
+
+
+ 1
+ 0
+
+
+
+ Qt::ImhNoAutoUppercase
+
+
+
@@ -308,6 +311,7 @@
Menu
+
diff --git a/tools.cpp b/tools.cpp
index 2bbcb25..9577d8f 100644
--- a/tools.cpp
+++ b/tools.cpp
@@ -59,7 +59,6 @@ FILE * popen2(array argv, string type, int & pid)
message);
}else
{
-
if((child_pid = fork()) == -1)
{
perror("fork");