added: - history in combobox\n - settings in application
This commit is contained in:
+79
-29
@@ -41,6 +41,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
ui->ktreewidgetsearchline->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
ui->treeWidget->setHeaderLabels({tr("Path"), tr("Size")} );
|
||||
ui->progressBar->hide();
|
||||
|
||||
loadSettings();
|
||||
|
||||
populateList();
|
||||
@@ -51,7 +52,6 @@ MainWindow::~MainWindow()
|
||||
{
|
||||
QMessageBox::StandardButton reply;
|
||||
|
||||
|
||||
if (ui->listDownload->count() != 0)
|
||||
{
|
||||
reply = QMessageBox::question(
|
||||
@@ -64,7 +64,8 @@ MainWindow::~MainWindow()
|
||||
{
|
||||
emit (stopDownloading(this->downloading.pid));
|
||||
}
|
||||
}
|
||||
}
|
||||
saveSettings();
|
||||
if (this->downloading.pid != 0)
|
||||
{
|
||||
waitpid(this->downloading.pid, NULL, WUNTRACED);
|
||||
@@ -79,36 +80,59 @@ void MainWindow::populateTree()
|
||||
|
||||
if (!this->connexion.server.empty() and this->connexion.port > 0 and this->connexion.port < 65536)
|
||||
{
|
||||
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
if (validateServer(this->connexion.server))
|
||||
{
|
||||
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
path = explode(ui->listWidget->currentItem()->text().toStdString(), '\n', 2);
|
||||
scanDir(this->connexion.server, this->connexion.port, NULL, path[0].append("/") );
|
||||
this->unsetCursor();
|
||||
QGuiApplication::setOverrideCursor(Qt::ArrowCursor);
|
||||
}
|
||||
QGuiApplication::setOverrideCursor(Qt::ArrowCursor);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::populateList()
|
||||
{
|
||||
stringstream ss;
|
||||
QString str;
|
||||
QString server;
|
||||
QString port;
|
||||
|
||||
this->connexion.server.assign(ui->khistorycombobox->currentText().toStdString());
|
||||
server = ui->khistorycombobox->currentText();
|
||||
this->connexion.server.assign(server.toStdString());
|
||||
ss << ui->portEdit->text().toStdString();
|
||||
ss >> this->connexion.port;
|
||||
if (!this->connexion.server.empty() and this->connexion.port > 0 and this->connexion.port < 65536)
|
||||
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
this->settings.beginGroup("connexion/server");
|
||||
if (this->settings.contains(server))
|
||||
{
|
||||
if (validateServer(this->connexion.server))
|
||||
port = this->settings.value(server).toString();
|
||||
ui->portEdit->setText(port);
|
||||
this->connexion.port = this->settings.value(server).toInt();
|
||||
}
|
||||
|
||||
if (!server.isEmpty() and this->connexion.port > 0 and this->connexion.port < 65536)
|
||||
{
|
||||
if (validateServer(server.toStdString()))
|
||||
{
|
||||
ui->khistorycombobox->addItem(this->connexion.server.c_str());
|
||||
ui->centralwidget->cursor().setShape(Qt::WaitCursor);
|
||||
//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
|
||||
listServices();
|
||||
ui->centralwidget->cursor().setShape(Qt::ArrowCursor);
|
||||
QStringList test = ui->khistorycombobox->historyItems();
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
this->settings.endGroup();
|
||||
QGuiApplication::setOverrideCursor(Qt::ArrowCursor);
|
||||
}
|
||||
|
||||
void MainWindow::listServices()
|
||||
@@ -119,11 +143,12 @@ void MainWindow::listServices()
|
||||
vector<string> v;
|
||||
char service[4096];
|
||||
|
||||
ui->listWidget->clear();
|
||||
sprintf(cmd, "rsync --contimeout=10 -P \"%s::\" --port %d ", this->connexion.server.c_str(), this->connexion.port );
|
||||
redi::ipstream in(cmd, redi::pstreams::pstdout | redi::pstreams::pstderr);
|
||||
while (getline(in.out(), line))
|
||||
{
|
||||
cout << "stdout: " << line << endl;
|
||||
//cout << "stdout: " << line << endl;
|
||||
boost::replace_all(line," ","");
|
||||
boost::replace_all(line, "\t", " - ");
|
||||
v = explode(line, ' ', 3 );
|
||||
@@ -221,7 +246,7 @@ bool MainWindow::validateServer(string server)
|
||||
|
||||
while (getline(in.out(), line))
|
||||
{
|
||||
cout << "stdout: " << line << '\n';
|
||||
//cout << "stdout: " << line << '\n';
|
||||
if (line.find(";; ANSWER SECTION:") != string::npos)
|
||||
{
|
||||
flag = true;
|
||||
@@ -268,7 +293,16 @@ void MainWindow::displayTree()
|
||||
|
||||
void MainWindow::on_khistorycombobox_returnPressed()
|
||||
{
|
||||
populateList();
|
||||
//populateList();
|
||||
}
|
||||
|
||||
void MainWindow::on_khistorycombobox_currentIndexChanged(int i)
|
||||
{
|
||||
/*QString server = ui->khistorycombobox->currentText();
|
||||
this->settings.beginGroup("connexion/server");
|
||||
ui->portEdit->setText(this->settings.value(server).toString());
|
||||
this->settings.endGroup();*/
|
||||
this->populateList();
|
||||
}
|
||||
|
||||
void MainWindow::on_portEdit_returnPressed()
|
||||
@@ -276,16 +310,6 @@ void MainWindow::on_portEdit_returnPressed()
|
||||
populateList();
|
||||
}
|
||||
|
||||
void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::on_treeWidget_customContextMenuRequested()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::on_actionDownload_triggered()
|
||||
{
|
||||
|
||||
@@ -387,7 +411,7 @@ void MainWindow::on_listDownload_itemClicked(QListWidgetItem *item)
|
||||
QFileDialog dialog;
|
||||
QMessageBox::StandardButton reply;
|
||||
|
||||
cout << item->text().toStdString() << endl;
|
||||
//cout << item->text().toStdString() << endl;
|
||||
if (item->listWidget()->row(item) == 0)
|
||||
{
|
||||
reply = QMessageBox::question(
|
||||
@@ -418,10 +442,36 @@ void MainWindow::on_listDownload_itemClicked(QListWidgetItem *item)
|
||||
|
||||
void MainWindow::loadSettings()
|
||||
{
|
||||
this->settings.value("serverlist");
|
||||
this->restoreGeometry(settings.value("window/geometry").toByteArray());
|
||||
this->settings.beginGroup("connexion/server");
|
||||
|
||||
QStringList servers = this->settings.allKeys();
|
||||
this->settings.endGroup();
|
||||
|
||||
for( const QString &server : servers )
|
||||
{
|
||||
ui->khistorycombobox->addToHistory(server);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::saveSettings()
|
||||
{
|
||||
//ui->khistorycombobox->
|
||||
this->settings.setValue("window/geometry", saveGeometry());
|
||||
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;
|
||||
QMessageBox::about(this, this->about.title, text);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAbout_Qt_triggered()
|
||||
{
|
||||
QMessageBox::aboutQt(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user