Compare commits

...

2 Commits
1.2 ... 1.4

Author SHA1 Message Date
d1e45b8ba8 debug 2023-01-23 10:04:54 +01:00
7546aedec2 version Ok 2023-01-22 14:33:23 +01:00
13 changed files with 613 additions and 178 deletions

View File

@ -27,10 +27,11 @@ HEADERS += \
tools.h tools.h
FORMS += \ FORMS += \
configuration.ui \
mainwindow.ui mainwindow.ui
TRANSLATIONS += \ TRANSLATIONS += \
languages/RsyncUI_fr_FR.ts languages/fr_FR/RsyncUI_fr_FR.ts
INCLUDEPATH += \ INCLUDEPATH += \
/usr/include/KF5 /usr/include/KF5
@ -40,6 +41,6 @@ qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /usr/bin/ else: unix:!android: target.path = /usr/bin/
!isEmpty(target.path): INSTALLS += target !isEmpty(target.path): INSTALLS += target
lang.path = /languages lang.path = /languages/fr_FR/
lang.files = languages/* lang.files = languages/fr_FR/*
INSTALLS += lang INSTALLS += lang

131
configuration.ui Normal file
View File

@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Configuration</class>
<widget class="QDialog" name="Configuration">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>127</height>
</rect>
</property>
<property name="windowTitle">
<string>Configuration</string>
</property>
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
<x>9</x>
<y>9</y>
<width>381</width>
<height>61</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QSpinBox" name="spinBox">
<property name="toolTip">
<string>Enter the bandwidth limit</string>
</property>
<property name="toolTipDuration">
<number>5000</number>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="maximum">
<number>1024</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label1">
<property name="text">
<string extracomment="Bandwidth limit">Bandwidth limit</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="UnitCombobox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string extracomment="Unit of bandwidth">Select th unit of bandwidth limit in Bytes, KiloBytes, MegaBytes, GigaBytes or PetaBytes</string>
</property>
<property name="toolTipDuration">
<number>5000</number>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
<property name="maxVisibleItems">
<number>5</number>
</property>
<property name="maxCount">
<number>1024</number>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>70</x>
<y>80</y>
<width>321</width>
<height>34</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Configuration</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Configuration</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -41,16 +41,24 @@ void downloadFile::download(MainWindow *mw)
vector<string> v; vector<string> v;
int value; int value;
char buffer[4096]; char buffer[4096];
argv[0] = "/usr/bin/rsync"; 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[2] = "--port=" + to_string(mw->connexion.port);
argv[3] = "-P"; argv[3] = "-P";
argv[4] = mw->connexion.server + "::" + mw->downloading.service + "/" + mw->downloading.path; argv[4] = mw->connexion.server + "::" + mw->downloading.service + "/" + mw->downloading.path;
argv[5] = mw->downloading.savePath + "/"; argv[5] = mw->downloading.savePath + "/";
argv[6] = "";
//unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd "r"), pclose); //launching downloading thread
FILE * fp = popen2(argv, "r", mw->downloading.pid); FILE * fp = popen2(argv, "r", mw->downloading.pid);
if (!fp) if (!fp)
{ {
throw runtime_error("popen2() failed!"); throw runtime_error("popen2() failed!");
@ -64,7 +72,6 @@ void downloadFile::download(MainWindow *mw)
return; return;
} }
line = buffer; line = buffer;
//cout << line << endl;
pos = line.find('%'); pos = line.find('%');
if (pos != -1) if (pos != -1)
{ {
@ -74,14 +81,14 @@ void downloadFile::download(MainWindow *mw)
{ {
line.erase(0, pos); line.erase(0, pos);
value = stoi(line); value = stoi(line);
//cout << value << endl;
emit progressSignal(value); emit progressSignal(value);
} }
} }
} }
pclose2(fp, mw->downloading.pid); pclose2(fp, mw->downloading.pid);
// ProgressBar to 100% and emit signal finished to main application
emit progressSignal(100); emit progressSignal(100);
emit finishedSignal(true); emit finishedSignal(true);
//cout << path << endl;
} }

View File

@ -2,7 +2,9 @@
#define DOWNLOADFILE_H #define DOWNLOADFILE_H
#include <QObject> #include <QObject>
//#include "ui_mainwindow.h" #include <stdio.h>
#include <stdlib.h>
#include <cstdlib>
class MainWindow; class MainWindow;

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,233 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="fr_FR">
<context>
<name>Configuration</name>
<message>
<location filename="../../configuration.ui" line="17"/>
<source>Configuration</source>
<translation>Configuration</translation>
</message>
<message>
<location filename="../../configuration.ui" line="32"/>
<source>Enter the bandwidth limit</source>
<translation>Entrez la limite de bande passante
</translation>
</message>
<message>
<location filename="../../configuration.ui" line="48"/>
<source>Bandwidth limit</source>
<extracomment>Bandwidth limit</extracomment>
<translation>Limite de bande passante</translation>
</message>
<message>
<location filename="../../configuration.ui" line="61"/>
<source>Select th unit of bandwidth limit in Bytes, KiloBytes, MegaBytes, GigaBytes or PetaBytes</source>
<extracomment>Unit of bandwidth</extracomment>
<translation>Sélectionnez l&apos;unité de limite de bande passante en otctets, Ko, Mo, Go, Po</translation>
</message>
</context>
<context>
<name>MainWindow</name>
<message>
<location filename="../../mainwindow.ui" line="21"/>
<source>MainWindow</source>
<translation>Fenêtre principale</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="80"/>
<source>Server</source>
<oldsource>Serveur</oldsource>
<translation>Serveur</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="102"/>
<source>Enter server&apos;s URL</source>
<translation>Entrez l&apos;adresse du serveur</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="118"/>
<source>Port</source>
<translation>Port</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="143"/>
<source>Enter rsync port on server</source>
<translation>Entrez le port du servuer rsync</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="177"/>
<source>Press button to connect to rsync server</source>
<extracomment>Connect to server</extracomment>
<translation>Cliquez pour se connecter au serveur rsync</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="183"/>
<source>Connection</source>
<translation>Connexion</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="186"/>
<source>Return</source>
<translation>Retour</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="209"/>
<source>Click to view the list of files of this folder</source>
<translation>Cliquez pour afficher la liste des documents</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="238"/>
<source>Click to add to download queue</source>
<translation>Cliquez pour ajouter à la file de téléchargement</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="307"/>
<source>Click on file to stop downloading</source>
<translation>Cliquez sur le document pour arrêter le téléchargement et l&apos;enleveer de la file</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="327"/>
<source>%p%</source>
<extracomment>Downloading</extracomment>
<translation>Téléchargement</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="344"/>
<location filename="../../mainwindow.ui" line="362"/>
<source>Menu</source>
<translation>Menu</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="351"/>
<source>help</source>
<translation>Aide</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="367"/>
<location filename="../../mainwindow.ui" line="370"/>
<source>Change save folder</source>
<translation>Changer le dossier de destination</translation>
</message>
<message>
<source>Default save folder</source>
<translation type="vanished">Dossier d&apos;enregistrement</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="375"/>
<source>Bandwidth limit</source>
<translation>Limite de bande passante</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="380"/>
<source>About</source>
<translation>À propos</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="385"/>
<source>About Qt</source>
<translation>À propos de Qt</translation>
</message>
<message>
<location filename="../../mainwindow.ui" line="390"/>
<source>Settings</source>
<translation>Paramètres</translation>
</message>
<message>
<source>debug</source>
<translation type="vanished">debug</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="21"/>
<source>Byte</source>
<translation>Octet</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="21"/>
<source>KB</source>
<translation>Ko</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="21"/>
<source>MB</source>
<translation>Mo</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="21"/>
<source>GB</source>
<translation>Go</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="21"/>
<source>TB</source>
<translation>To</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="21"/>
<location filename="../../mainwindow.cpp" line="517"/>
<source>PB</source>
<translation>Po</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="35"/>
<source>Path</source>
<translation>Chemin</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="35"/>
<source>Size</source>
<translation>Taille</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="68"/>
<source>Exiting will stop downloading, and will clear the download queue.
Do you want to exit ?</source>
<translation>Soritr stoppera le téléchargement et effacera la file des téléchargements.
Voulez-vous vraiment sortir du programme ?</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="297"/>
<source>server does not exists</source>
<translation>Le serveur n&apos;existe pas</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="479"/>
<source>Licence</source>
<translation>License</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="480"/>
<source>Author</source>
<translation>Auteur</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="481"/>
<source>EMail</source>
<translation>Courriel</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="482"/>
<source>Source code</source>
<translation>Code source</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="495"/>
<source>Choose directory to save file</source>
<translation>Choisissez le dossier enregistrer</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="413"/>
<source>Do you want to stop downloading and delete this file from download queue ?</source>
<translation>Vouslez-vous arrêter le téléchargement et enlever ce fichier de la file de téléchargement ?</translation>
</message>
<message>
<source>Client for rsync server</source>
<translation type="vanished">Client pour serveur rsync</translation>
</message>
<message>
<location filename="../../mainwindow.cpp" line="425"/>
<source>Do you want to delete this file from download queue ?</source>
<translation>Voulez-vous enlever ce fichier de la file de téléchargement ?</translation>
</message>
</context>
</TS>

View File

@ -1,18 +1,15 @@
#include "mainwindow.h" #include "mainwindow.h"
#include <QApplication>
#include <QSettings> #include <QTranslator>
#include <KAboutData>
#include <KDBusService>
#include <QCommandLineParser>
#include<QTranslator>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
QTranslator myappTranslator; QTranslator myappTranslator;
QLocale localeName = QLocale::system(); 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)) if (myappTranslator.load(localeFile))
{ {
a.installTranslator(&myappTranslator); a.installTranslator(&myappTranslator);

View File

@ -1,32 +1,10 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h"
#include "downloadfile.h"
#include "tools.h"
#include <iostream>
#include <KTreeWidgetSearchLineWidget>
#include <pstreams/pstream.h>
#include <sstream>
#include <string>
#include <cstring>
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <QMessageBox>
#include <vector>
#include <boost/algorithm/string/replace.hpp>
#include <QFuture>
#include <QtConcurrent>
#include <qtconcurrentrun.h>
#include <QFileDialog>
#include <QThread>
#include <QProgressDialog>
#include <sys/wait.h>
#include <QGuiApplication>
#include <QShortcut>
using namespace std; using namespace std;
bool display = false; bool display = false;
extern QDialog Configuration;
extern Ui::Configuration config;
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
@ -38,34 +16,50 @@ MainWindow::MainWindow(QWidget *parent)
QCoreApplication::setApplicationName("RsyncUI"); QCoreApplication::setApplicationName("RsyncUI");
// init shortcut // init shortcut
// QShortcut * shortcut = new QShortcut(QKeySequence("Return"), this);
loadSettings(); 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 // connectors
connect(&downloadO, &downloadFile::progressSignal, ui->progressBar, &QProgressBar::setValue); connect(&downloadO, &downloadFile::progressSignal, ui->progressBar, &QProgressBar::setValue);
connect(&downloadO, &downloadFile::finishedSignal, this, &MainWindow::downloadFinished); connect(&downloadO, &downloadFile::finishedSignal, this, &MainWindow::downloadFinished);
connect(this, &MainWindow::stopDownloading, &downloadO, &downloadFile::cancelled); 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 // init of widgets
ui->ktreewidgetsearchline->setTreeWidget(ui->treeWidget); ui->ktreewidgetsearchline->setTreeWidget(ui->treeWidget);
ui->ktreewidgetsearchline->setCaseSensitivity(Qt::CaseInsensitive); ui->ktreewidgetsearchline->setCaseSensitivity(Qt::CaseInsensitive);
ui->treeWidget->setHeaderLabels({tr("Path"), tr("Size")} ); 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(); ui->progressBar->hide();
populateList(); populateList();
} }
void MainWindow::returnPressed()
{
populateList();
}
MainWindow::~MainWindow() MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::closeEvent (QCloseEvent *event)
{ {
QMessageBox::StandardButton reply; QMessageBox::StandardButton reply;
saveSettings();
if (ui->listDownload->count() != 0) if (ui->listDownload->count() != 0)
{ {
reply = QMessageBox::question( 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 ?"), tr("Exiting will stop downloading, and will clear the download queue.\n Do you want to exit ?"),
QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes|QMessageBox::No,
QMessageBox::No); QMessageBox::No);
if (reply == QMessageBox::Yes) if (reply == QMessageBox::No)
{
event->ignore();
return;
}else
{ {
emit (stopDownloading(this->downloading.pid)); emit (stopDownloading(this->downloading.pid));
}
}
saveSettings();
if (this->downloading.pid != 0)
{
waitpid(this->downloading.pid, NULL, WUNTRACED); waitpid(this->downloading.pid, NULL, WUNTRACED);
} }
delete ui; }
event->accept();
} }
void MainWindow::populateTree() void MainWindow::populateTree()
@ -110,23 +104,25 @@ void MainWindow::populateList()
stringstream ss; stringstream ss;
QString str; QString str;
QString server; QString server;
QString port; int port;
ui->listWidget->clear();
server = ui->khistorycombobox->currentText(); server = ui->khistorycombobox->currentText();
port = ui->portEdit->text().toUInt();
if ((server.toStdString() != this->connexion.server) or (port != this->connexion.port))
{
ui->listWidget->clear();
this->connexion.server.assign(server.toStdString()); this->connexion.server.assign(server.toStdString());
ss << ui->portEdit->text().toStdString(); this->connexion.port = port;
ss >> this->connexion.port;
this->settings.beginGroup("connexion/server"); this->settings.beginGroup("connexion/server");
if (this->settings.contains(server)) if (this->settings.contains(server))
{ {
port = this->settings.value(server).toString(); port = this->settings.value(server).toUInt();
ui->portEdit->setText(port); ui->portEdit->setText(QString::number(port));
this->connexion.port = this->settings.value(server).toInt(); this->connexion.port = port;
} }
if (!server.isEmpty() and this->connexion.port > 0 and this->connexion.port < 65536) if (!server.isEmpty() and (port > 0 and port < 65536))
{ {
if (validateServer(server.toStdString())) if (validateServer(server.toStdString()))
{ {
@ -135,7 +131,7 @@ void MainWindow::populateList()
{ {
cout << server.toStdString() << endl; cout << server.toStdString() << endl;
// storing serverURL and port in settings // storing serverURL and port in settings
this->settings.setValue(server, this->connexion.port); this->settings.setValue(server, port);
this->settings.sync(); this->settings.sync();
// storing in history of combobox // storing in history of combobox
@ -150,6 +146,7 @@ void MainWindow::populateList()
} }
this->settings.endGroup(); this->settings.endGroup();
QGuiApplication::restoreOverrideCursor(); //setOverrideCursor(Qt::ArrowCursor); QGuiApplication::restoreOverrideCursor(); //setOverrideCursor(Qt::ArrowCursor);
}
} }
void MainWindow::listServices() void MainWindow::listServices()
@ -164,7 +161,6 @@ void MainWindow::listServices()
redi::ipstream in(cmd, redi::pstreams::pstdout | redi::pstreams::pstderr); redi::ipstream in(cmd, redi::pstreams::pstdout | redi::pstreams::pstderr);
while (getline(in.out(), line)) while (getline(in.out(), line))
{ {
//cout << "stdout: " << line << endl;
boost::replace_all(line," ",""); boost::replace_all(line," ","");
boost::replace_all(line, "\t", " - "); boost::replace_all(line, "\t", " - ");
v = explode(line, ' ', 3 ); v = explode(line, ' ', 3 );
@ -310,19 +306,9 @@ void MainWindow::displayTree()
} }
void MainWindow::on_khistorycombobox_returnPressed()
{
//populateList();
}
void MainWindow::on_khistorycombobox_currentIndexChanged(int i) void MainWindow::on_khistorycombobox_currentIndexChanged(int i)
{ {
populateList(); on_connectButton_clicked();
}
void MainWindow::on_portEdit_returnPressed()
{
//populateList();
} }
void MainWindow::on_connectButton_clicked() void MainWindow::on_connectButton_clicked()
@ -363,7 +349,7 @@ void MainWindow::on_listWidget_clicked()
populateTree(); populateTree();
} }
void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item) void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item)
{ {
QFuture<void> future; QFuture<void> future;
QFileDialog dialog; QFileDialog dialog;
@ -374,16 +360,8 @@ void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item)
{ {
item = item->parent(); item = item->parent();
this->downloading.path = item->text(0).toStdString() + "/" + this->downloading.path; 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()) if (this->downloading.savePath.empty())
{ {
on_DefaultSaveFolder_triggered(); on_DefaultSaveFolder_triggered();
@ -392,7 +370,6 @@ void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item)
{ {
startDownloading(); startDownloading();
} }
}
ui->listDownload->addItem(QString::fromStdString(this->downloading.path)); ui->listDownload->addItem(QString::fromStdString(this->downloading.path));
} }
@ -458,21 +435,29 @@ void MainWindow::on_listDownload_itemClicked(QListWidgetItem *item)
void MainWindow::loadSettings() void MainWindow::loadSettings()
{ {
// restoring geometry and state of wondow and widgets
this->restoreGeometry(settings.value("window/geometry").toByteArray()); this->restoreGeometry(settings.value("window/geometry").toByteArray());
this->restoreState(settings.value("window/state").toByteArray()); this->restoreState(settings.value("window/state").toByteArray());
ui->treeWidget->header()->restoreState(settings.value("treeView/state").toByteArray()); ui->treeWidget->header()->restoreState(settings.value("treeView/state").toByteArray());
ui->splitter->restoreState(settings.value("splitter/state").toByteArray()); ui->splitter->restoreState(settings.value("splitter/state").toByteArray());
ui->splitter_2->restoreState(settings.value("splitter2/state").toByteArray()); ui->splitter_2->restoreState(settings.value("splitter2/state").toByteArray());
// loading connexion settings
// loading servers history
this->settings.beginGroup("connexion/server"); this->settings.beginGroup("connexion/server");
QStringList servers = this->settings.allKeys(); QStringList servers = this->settings.allKeys();
this->settings.endGroup(); this->settings.endGroup();
this->downloading.dirPath = this->settings.value("Folder").toString();
for( const QString &server : servers ) for( const QString &server : servers )
{ {
ui->khistorycombobox->addToHistory(server); 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/geometry", saveGeometry());
this->settings.setValue("window/state", saveState()); this->settings.setValue("window/state", saveState());
//ui->treeWidget->header()->saveState();
this->settings.setValue("treeView/state", ui->treeWidget->header()->saveState()); this->settings.setValue("treeView/state", ui->treeWidget->header()->saveState());
this->settings.setValue("splitter/state", ui->splitter->saveState()); this->settings.setValue("splitter/state", ui->splitter->saveState());
this->settings.setValue("splitter2/state", ui->splitter_2->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(); this->settings.sync();
} }
void MainWindow::on_actionAbout_triggered() void MainWindow::on_actionAbout_triggered()
{ {
QString text = this->about.description + "\n\n" + QString text = this->about.description + "\n\n" +
"Licence: " + this->about.licence + "\n" + tr("Licence" ) + ": " + this->about.licence + "\n" +
"Author: " + this->about.author + "\n" + tr("Author") + ": " + this->about.author + "\n" +
"EMail : " + this->about.email + "\n" + tr("EMail") + ": " + this->about.email + "\n" +
"Source code: " + this->about.git; tr("Source code") + ": " + this->about.git;
QMessageBox::about(this, this->about.title, text); QMessageBox::about(this, this->about.title, text);
} }
@ -508,6 +493,34 @@ void MainWindow::on_DefaultSaveFolder_triggered()
QFileDialog dialog; QFileDialog dialog;
this->downloading.savePath = dialog.getExistingDirectory(this, tr("Choose directory to save file"), this->downloading.dirPath, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks).toStdString(); 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->downloading.dirPath = this->downloading.savePath.c_str();
this->settings.setValue("Folder/", this->downloading.dirPath); 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();
} }

View File

@ -1,15 +1,36 @@
#ifndef MAINWINDOW_H #ifndef MAINWINDOW_H
#define MAINWINDOW_H #define MAINWINDOW_H
#include "ui_mainwindow.h"
#include "ui_configuration.h"
#include "downloadfile.h"
#include "tools.h" #include "tools.h"
#include <QMainWindow> #include <QMainWindow>
#include <string> #include <string>
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
#include <QListWidgetItem> #include <QListWidgetItem>
#include "downloadfile.h"
#include <QProgressDialog> #include <QProgressDialog>
#include <QSettings> #include <QSettings>
#include <vector> #include <vector>
#include <iostream>
#include <KTreeWidgetSearchLineWidget>
#include <pstreams/pstream.h>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <cstdio>
#include <QMessageBox>
#include <boost/algorithm/string/replace.hpp>
#include <QFuture>
#include <qtconcurrentrun.h>
#include <QFileDialog>
#include <QThread>
#include <QProgressDialog>
#include <sys/wait.h>
#include <QGuiApplication>
#include <QShortcut>
#include <QCloseEvent>
#include <unistd.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; } namespace Ui { class MainWindow; }
@ -18,7 +39,8 @@ QT_END_NAMESPACE
class Connexion class Connexion
{ {
public: public:
std::string bandwidthLimit = "1M"; int bandwidthLimit = 0;
std::string bandwidthLimitUnit = "";
std::string server; std::string server;
int port = 873; int port = 873;
}; };
@ -40,7 +62,7 @@ class About
QString title = "RsyncUI"; QString title = "RsyncUI";
QString author = "Daniel TARTAVEL-JEANNOT"; QString author = "Daniel TARTAVEL-JEANNOT";
QString licence = "GPL_V3"; QString licence = "GPL_V3";
QString description = "Client for rsync server"; QString description = "Client for rsync server\n\nYou click on file to enqueue it, and RyncUI Download one file a time";
QString email = "dtux@free.fr"; QString email = "dtux@free.fr";
QString git = "https://git.labolyon.fr/dtux/RsyncUI/issues"; QString git = "https://git.labolyon.fr/dtux/RsyncUI/issues";
}; };
@ -66,27 +88,22 @@ class MainWindow : public QMainWindow
void startDownloading(); void startDownloading();
void loadSettings(); void loadSettings();
void saveSettings(); void saveSettings();
void closeEvent (QCloseEvent *event);
Connexion connexion; Connexion connexion;
Downloading downloading; Downloading downloading;
downloadFile downloadO; downloadFile downloadO;
QSettings settings; QSettings settings;
About about; About about;
QDialog Configuration;
Ui::Configuration config;
std::vector <QString> serversList; std::vector <QString> serversList;
private slots: private slots:
void on_khistorycombobox_returnPressed();
//void on_portEdit_userTextChanged();
void on_portEdit_returnPressed();
//void on_actionDownload_triggered();
void on_listWidget_clicked(); void on_listWidget_clicked();
void on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item); void on_treeWidget_itemClicked(QTreeWidgetItem *item);
void downloadFinished(); void downloadFinished();
@ -102,15 +119,17 @@ class MainWindow : public QMainWindow
void on_DefaultSaveFolder_triggered(); void on_DefaultSaveFolder_triggered();
void returnPressed();
void on_connectButton_clicked(); void on_connectButton_clicked();
signals: void on_action_Settings_triggered();
void stopDownloading(int);
public slots:
void on_buttonBox_accepted();
signals:
void stopDownloading(int);
// void accepted();
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -98,6 +98,12 @@
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="toolTip">
<string>Enter server's URL</string>
</property>
<property name="toolTipDuration">
<number>5000</number>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -133,9 +139,18 @@
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<property name="toolTip">
<string>Enter rsync port on server</string>
</property>
<property name="toolTipDuration">
<number>5000</number>
</property>
<property name="inputMethodHints"> <property name="inputMethodHints">
<set>Qt::ImhPreferNumbers</set> <set>Qt::ImhPreferNumbers</set>
</property> </property>
<property name="inputMask">
<string/>
</property>
<property name="text"> <property name="text">
<string comment="numéro"/> <string comment="numéro"/>
</property> </property>
@ -159,7 +174,10 @@
<item> <item>
<widget class="QPushButton" name="connectButton"> <widget class="QPushButton" name="connectButton">
<property name="toolTip"> <property name="toolTip">
<string extracomment="Connect to server"/> <string extracomment="Connect to server">Press button to connect to rsync server</string>
</property>
<property name="toolTipDuration">
<number>5000</number>
</property> </property>
<property name="text"> <property name="text">
<string>Connection</string> <string>Connection</string>
@ -187,6 +205,12 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip">
<string>Click to view the list of files of this folder</string>
</property>
<property name="toolTipDuration">
<number>5000</number>
</property>
<property name="editTriggers"> <property name="editTriggers">
<set>QAbstractItemView::SelectedClicked</set> <set>QAbstractItemView::SelectedClicked</set>
</property> </property>
@ -199,19 +223,6 @@
</widget> </widget>
<widget class="QWidget" name="layoutWidget"> <widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="KTreeWidgetSearchLine" name="ktreewidgetsearchline">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="inputMethodHints">
<set>Qt::ImhNoAutoUppercase</set>
</property>
</widget>
</item>
<item> <item>
<widget class="QTreeWidget" name="treeWidget"> <widget class="QTreeWidget" name="treeWidget">
<property name="sizePolicy"> <property name="sizePolicy">
@ -221,7 +232,16 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="contextMenuPolicy"> <property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum> <enum>Qt::NoContextMenu</enum>
</property>
<property name="toolTip">
<string>Click to add to download queue</string>
</property>
<property name="toolTipDuration">
<number>5000</number>
</property>
<property name="whatsThis">
<string extracomment="Click to add to download queue"/>
</property> </property>
<property name="editTriggers"> <property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set> <set>QAbstractItemView::NoEditTriggers</set>
@ -266,10 +286,26 @@
</column> </column>
</widget> </widget>
</item> </item>
<item>
<widget class="KTreeWidgetSearchLine" name="ktreewidgetsearchline">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="inputMethodHints">
<set>Qt::ImhNoAutoUppercase</set>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
<widget class="QListWidget" name="listDownload"> <widget class="QListWidget" name="listDownload">
<property name="toolTip">
<string>Click on file to stop downloading</string>
</property>
<property name="dragEnabled"> <property name="dragEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
@ -308,6 +344,7 @@
<string>Menu</string> <string>Menu</string>
</property> </property>
<addaction name="DefaultSaveFolder"/> <addaction name="DefaultSaveFolder"/>
<addaction name="action_Settings"/>
</widget> </widget>
<widget class="QMenu" name="menuhelp"> <widget class="QMenu" name="menuhelp">
<property name="title"> <property name="title">
@ -327,10 +364,10 @@
</action> </action>
<action name="DefaultSaveFolder"> <action name="DefaultSaveFolder">
<property name="text"> <property name="text">
<string>Default save folder</string> <string>Change save folder</string>
</property> </property>
<property name="iconText"> <property name="iconText">
<string>Default save folder</string> <string>Change save folder</string>
</property> </property>
</action> </action>
<action name="actionBandwidth_limit"> <action name="actionBandwidth_limit">
@ -348,6 +385,11 @@
<string>About Qt</string> <string>About Qt</string>
</property> </property>
</action> </action>
<action name="action_Settings">
<property name="text">
<string>Settings</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -1,11 +1,4 @@
#include "mainwindow.h" #include "mainwindow.h"
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <pstreams/pstream.h>
#include <QMessageBox>
#include <ctype.h>
using namespace std; using namespace std;
@ -44,11 +37,12 @@ const vector<string> explode(const string& s, const char& c, int n = 0)
return v; return v;
} }
FILE * popen2(array<string, 7> argv, string type, int & pid) FILE * popen2(char * const argv, string type, int & pid)
{ {
pid_t child_pid; pid_t child_pid;
int fd[2]; int fd[2];
QString message; QString message;
string command;
if (pipe(fd) == -1) if (pipe(fd) == -1)
{ {
@ -59,7 +53,6 @@ FILE * popen2(array<string, 7> argv, string type, int & pid)
message); message);
}else }else
{ {
if((child_pid = fork()) == -1) if((child_pid = fork()) == -1)
{ {
perror("fork"); perror("fork");
@ -81,7 +74,8 @@ FILE * popen2(array<string, 7> argv, string type, int & pid)
} }
setpgid(child_pid, child_pid); //Needed so negative PIDs can kill children of /bin/sh setpgid(child_pid, child_pid); //Needed so negative PIDs can kill children of /bin/sh
if (execl(argv[0].c_str(), argv[0].c_str(), argv[1].c_str(), argv[2].c_str(), argv[3].c_str(), argv[4].c_str(), argv[5].c_str(), NULL ) == -1) //if (execlp(argv[0].c_str(), argv[0].c_str(), argv[1].c_str(), argv[2].c_str(), argv[3].c_str(), argv[4].c_str(), argv[5].c_str(), NULL ) == -1)
if (execvp(command.c_str(), &argv))
{ {
perror("execl error => "); perror("execl error => ");
} }
@ -99,14 +93,11 @@ FILE * popen2(array<string, 7> argv, string type, int & pid)
} }
} }
pid = child_pid; pid = child_pid;
if (type == "r") if (type == "r")
{ {
return fdopen(fd[READ], "r"); return fdopen(fd[READ], "r");
} }
return fdopen(fd[WRITE], "w"); return fdopen(fd[WRITE], "w");
} }
return 0; return 0;
@ -125,7 +116,6 @@ int pclose2(FILE * fp, pid_t pid)
break; break;
} }
} }
return stat; return stat;
} }

View File

@ -9,7 +9,7 @@ using namespace std;
const vector<string> explode(const string& s, const char& c, int n); const vector<string> explode(const string& s, const char& c, int n);
FILE * popen2(array<string, 7> argv, string type, int & pid); FILE * popen2(char * const argv, string type, int & pid);
int pclose2(FILE * fp, pid_t pid); int pclose2(FILE * fp, pid_t pid);