config file is now ~/.config/RsyncUI.conf
This commit is contained in:
+42
-12
@@ -54,15 +54,18 @@ MainWindow::~MainWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
// Closing window has been clicked
|
||||
void MainWindow::closeEvent (QCloseEvent *event)
|
||||
{
|
||||
QMessageBox::StandardButton reply;
|
||||
|
||||
// saving settings
|
||||
saveSettings();
|
||||
|
||||
if (ui->listDownload->count() != 0)
|
||||
if (ui->listDownload->count() != 0) // some downloads waiting
|
||||
{
|
||||
reply = QMessageBox::question(
|
||||
// Asking for stopping or continuing
|
||||
reply = QMessageBox::question(
|
||||
this,
|
||||
"RsyncUI",
|
||||
tr("Exiting will stop downloading, and will clear the download queue.\n Do you want to exit ?"),
|
||||
@@ -70,10 +73,12 @@ void MainWindow::closeEvent (QCloseEvent *event)
|
||||
QMessageBox::No);
|
||||
if (reply == QMessageBox::No)
|
||||
{
|
||||
// continuing
|
||||
event->ignore();
|
||||
return;
|
||||
}else
|
||||
{
|
||||
// emission of signal to downloading thread and stopping
|
||||
emit (stopDownloading(this->downloading.pid));
|
||||
waitpid(this->downloading.pid, NULL, WUNTRACED);
|
||||
}
|
||||
@@ -81,24 +86,31 @@ void MainWindow::closeEvent (QCloseEvent *event)
|
||||
event->accept();
|
||||
}
|
||||
|
||||
// Populate treeview with list of files
|
||||
void MainWindow::populateTree()
|
||||
{
|
||||
stringstream ss;
|
||||
vector<string> path;
|
||||
|
||||
// Clear treewidget
|
||||
ui->treeWidget->clear();
|
||||
if (!this->connexion.server.empty() and this->connexion.port > 0 and this->connexion.port < 65536)
|
||||
{
|
||||
// setting cursor to "Wait"
|
||||
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
if (validateServer(this->connexion.server))
|
||||
{
|
||||
// server is validated
|
||||
path = explode(ui->listWidget->currentItem()->text().toStdString(), '\n', 2);
|
||||
scanDir(this->connexion.server, this->connexion.port, NULL, path[0].append("/") );
|
||||
}
|
||||
QGuiApplication::restoreOverrideCursor(); //setOverrideCursor(Qt::ArrowCursor);
|
||||
// Restoring cursor
|
||||
QGuiApplication::restoreOverrideCursor();
|
||||
}
|
||||
}
|
||||
|
||||
// Populate Listview with list of services
|
||||
void MainWindow::populateList()
|
||||
{
|
||||
stringstream ss;
|
||||
@@ -110,13 +122,16 @@ void MainWindow::populateList()
|
||||
port = ui->portEdit->text().toUInt();
|
||||
if ((server.toStdString() != this->connexion.server) or (port != this->connexion.port))
|
||||
{
|
||||
// clearing listwidget
|
||||
ui->listWidget->clear();
|
||||
this->connexion.server.assign(server.toStdString());
|
||||
this->connexion.port = port;
|
||||
|
||||
// verify if server is in history
|
||||
this->settings.beginGroup("connexion/server");
|
||||
if (this->settings.contains(server))
|
||||
{
|
||||
// server is in history and completing port value
|
||||
port = this->settings.value(server).toUInt();
|
||||
ui->portEdit->setText(QString::number(port));
|
||||
this->connexion.port = port;
|
||||
@@ -126,7 +141,7 @@ void MainWindow::populateList()
|
||||
{
|
||||
if (validateServer(server.toStdString()))
|
||||
{
|
||||
//this->settings.beginGroup("connexion/server");
|
||||
|
||||
if (!this->settings.contains(server))
|
||||
{
|
||||
cout << server.toStdString() << endl;
|
||||
@@ -149,6 +164,7 @@ void MainWindow::populateList()
|
||||
}
|
||||
}
|
||||
|
||||
//list services of the rsync server
|
||||
void MainWindow::listServices()
|
||||
{
|
||||
char cmd[4096];
|
||||
@@ -169,6 +185,7 @@ void MainWindow::listServices()
|
||||
}
|
||||
}
|
||||
|
||||
// connect to rsync server to get list of files
|
||||
void MainWindow::scanDir(string server, int portN, QTreeWidgetItem *parent, string path)
|
||||
{
|
||||
char cmd[4096];
|
||||
@@ -224,6 +241,7 @@ void MainWindow::scanDir(string server, int portN, QTreeWidgetItem *parent, stri
|
||||
|
||||
}
|
||||
|
||||
// Verify if server address is IP address
|
||||
bool MainWindow::isIpAddress(string server)
|
||||
{
|
||||
vector<string> r;
|
||||
@@ -249,6 +267,7 @@ bool MainWindow::isIpAddress(string server)
|
||||
}
|
||||
}
|
||||
|
||||
// validate address server
|
||||
bool MainWindow::validateServer(string server)
|
||||
{
|
||||
char cmd[512];
|
||||
@@ -300,22 +319,19 @@ bool MainWindow::validateServer(string server)
|
||||
return flag;
|
||||
}
|
||||
|
||||
void MainWindow::displayTree()
|
||||
{
|
||||
populateTree();
|
||||
|
||||
}
|
||||
|
||||
// slot activated when combobox is changed
|
||||
void MainWindow::on_khistorycombobox_currentIndexChanged(int i)
|
||||
{
|
||||
on_connectButton_clicked();
|
||||
}
|
||||
|
||||
// slot activated when button connection is clicked
|
||||
void MainWindow::on_connectButton_clicked()
|
||||
{
|
||||
populateList();
|
||||
}
|
||||
|
||||
// add a dir in treeview
|
||||
QTreeWidgetItem * MainWindow::addTreeRoot(QString name, QString fileSize)
|
||||
{
|
||||
// QTreeWidgetItem(QTreeWidget * parent, int type = Type)
|
||||
@@ -327,6 +343,7 @@ QTreeWidgetItem * MainWindow::addTreeRoot(QString name, QString fileSize)
|
||||
return treeItem;
|
||||
}
|
||||
|
||||
// add a file in treeview
|
||||
QTreeWidgetItem * MainWindow::addTreeChild(QTreeWidgetItem *parent, QString name, QString fileSize)
|
||||
{
|
||||
// QTreeWidgetItem(QTreeWidget * parent, int type = Type)
|
||||
@@ -341,6 +358,7 @@ QTreeWidgetItem * MainWindow::addTreeChild(QTreeWidgetItem *parent, QString name
|
||||
return treeItem;
|
||||
}
|
||||
|
||||
// Slot acivated when a service in the list is clicked
|
||||
void MainWindow::on_listWidget_clicked()
|
||||
{
|
||||
vector<string> v;
|
||||
@@ -349,6 +367,7 @@ void MainWindow::on_listWidget_clicked()
|
||||
populateTree();
|
||||
}
|
||||
|
||||
//Slot activated when a file is clicked in the treeview
|
||||
void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item)
|
||||
{
|
||||
QFuture<void> future;
|
||||
@@ -373,6 +392,7 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item)
|
||||
ui->listDownload->addItem(QString::fromStdString(this->downloading.path));
|
||||
}
|
||||
|
||||
// Launch the thread which download the file
|
||||
void MainWindow::startDownloading()
|
||||
{
|
||||
ui->progressBar->setValue(0);
|
||||
@@ -382,11 +402,13 @@ void MainWindow::startDownloading()
|
||||
|
||||
}
|
||||
|
||||
// Slot stopping download
|
||||
void MainWindow::stoppingDownload()
|
||||
{
|
||||
emit (stopDownloading(this->downloading.pid));
|
||||
}
|
||||
|
||||
// when download is finished, launch download of next file in queue
|
||||
void MainWindow::downloadFinished()
|
||||
{
|
||||
ui->progressBar->hide();
|
||||
@@ -399,6 +421,7 @@ void MainWindow::downloadFinished()
|
||||
}
|
||||
}
|
||||
|
||||
// Slot activated when a line is clicked in queue list
|
||||
void MainWindow::on_listDownload_itemClicked(QListWidgetItem *item)
|
||||
{
|
||||
QFileDialog dialog;
|
||||
@@ -433,6 +456,7 @@ void MainWindow::on_listDownload_itemClicked(QListWidgetItem *item)
|
||||
}
|
||||
}
|
||||
|
||||
// load settings
|
||||
void MainWindow::loadSettings()
|
||||
{
|
||||
// restoring geometry and state of wondow and widgets
|
||||
@@ -460,7 +484,7 @@ void MainWindow::loadSettings()
|
||||
this->connexion.bandwidthLimitUnit = this->settings.value("bandwidthlimitunit").toString().toStdString();
|
||||
}
|
||||
|
||||
|
||||
// save settings
|
||||
void MainWindow::saveSettings()
|
||||
{
|
||||
this->settings.setValue("window/geometry", saveGeometry());
|
||||
@@ -473,21 +497,25 @@ void MainWindow::saveSettings()
|
||||
this->settings.sync();
|
||||
}
|
||||
|
||||
// About
|
||||
void MainWindow::on_actionAbout_triggered()
|
||||
{
|
||||
QString text = this->about.description + "\n\n" +
|
||||
tr("Licence" ) + ": " + this->about.licence + "\n" +
|
||||
tr("Version") + ": " + this->about.version + "\n" +
|
||||
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);
|
||||
}
|
||||
|
||||
// About QT
|
||||
void MainWindow::on_actionAbout_Qt_triggered()
|
||||
{
|
||||
QMessageBox::aboutQt(this);
|
||||
}
|
||||
|
||||
// Activated when menu "change folder" is clicked
|
||||
void MainWindow::on_DefaultSaveFolder_triggered()
|
||||
{
|
||||
QFileDialog dialog;
|
||||
@@ -498,6 +526,7 @@ void MainWindow::on_DefaultSaveFolder_triggered()
|
||||
this->settings.sync();
|
||||
}
|
||||
|
||||
// Activated when menu "settings" is clicked
|
||||
void MainWindow::on_action_Settings_triggered()
|
||||
{
|
||||
config.UnitCombobox->setCurrentText(QString::fromStdString(this->connexion.bandwidthLimitUnit));
|
||||
@@ -505,6 +534,7 @@ void MainWindow::on_action_Settings_triggered()
|
||||
Configuration.show();
|
||||
}
|
||||
|
||||
// Acivated when "Ok" is clicked in Configuration window
|
||||
void MainWindow::on_buttonBox_accepted()
|
||||
{
|
||||
QString unit;
|
||||
|
||||
Reference in New Issue
Block a user