- now saving state of widgets

This commit is contained in:
Daniel Tartavel 2023-01-15 15:25:22 +01:00
parent cb384e1c51
commit 13c5c3788f
2 changed files with 36 additions and 10 deletions

View File

@ -33,10 +33,16 @@ MainWindow::MainWindow(QWidget *parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
QCoreApplication::setOrganizationName("RsyncUI");
QCoreApplication::setApplicationName("RsyncUI");
// 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);
// 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")} );
@ -86,7 +92,7 @@ void MainWindow::populateTree()
path = explode(ui->listWidget->currentItem()->text().toStdString(), '\n', 2); path = explode(ui->listWidget->currentItem()->text().toStdString(), '\n', 2);
scanDir(this->connexion.server, this->connexion.port, NULL, path[0].append("/") ); scanDir(this->connexion.server, this->connexion.port, NULL, path[0].append("/") );
} }
QGuiApplication::setOverrideCursor(Qt::ArrowCursor); QGuiApplication::restoreOverrideCursor(); //setOverrideCursor(Qt::ArrowCursor);
} }
} }
@ -132,7 +138,7 @@ void MainWindow::populateList()
} }
} }
this->settings.endGroup(); this->settings.endGroup();
QGuiApplication::setOverrideCursor(Qt::ArrowCursor); QGuiApplication::restoreOverrideCursor(); //setOverrideCursor(Qt::ArrowCursor);
} }
void MainWindow::listServices() void MainWindow::listServices()
@ -298,11 +304,7 @@ void MainWindow::on_khistorycombobox_returnPressed()
void MainWindow::on_khistorycombobox_currentIndexChanged(int i) void MainWindow::on_khistorycombobox_currentIndexChanged(int i)
{ {
/*QString server = ui->khistorycombobox->currentText(); this->populateList();
this->settings.beginGroup("connexion/server");
ui->portEdit->setText(this->settings.value(server).toString());
this->settings.endGroup();*/
this->populateList();
} }
void MainWindow::on_portEdit_returnPressed() void MainWindow::on_portEdit_returnPressed()
@ -370,8 +372,10 @@ void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int colu
{ {
this->downloading.dirPath = getenv("HOME"); this->downloading.dirPath = getenv("HOME");
} }
if (this->downloading.savePath.empty())
this->downloading.savePath = dialog.getExistingDirectory(this, tr("Choose directory to save file"), this->downloading.dirPath, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks).toStdString(); {
on_DefaultSaveFolder_triggered();
}
if (!this->downloading.savePath.empty() && this->downloading.pid == 0) if (!this->downloading.savePath.empty() && this->downloading.pid == 0)
{ {
startDownloading(); startDownloading();
@ -443,11 +447,16 @@ void MainWindow::on_listDownload_itemClicked(QListWidgetItem *item)
void MainWindow::loadSettings() void MainWindow::loadSettings()
{ {
this->restoreGeometry(settings.value("window/geometry").toByteArray()); 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());
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);
@ -458,6 +467,12 @@ void MainWindow::loadSettings()
void MainWindow::saveSettings() void MainWindow::saveSettings()
{ {
this->settings.setValue("window/geometry", saveGeometry()); 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.sync(); this->settings.sync();
} }
@ -475,3 +490,12 @@ void MainWindow::on_actionAbout_Qt_triggered()
{ {
QMessageBox::aboutQt(this); QMessageBox::aboutQt(this);
} }
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);
}

View File

@ -99,6 +99,8 @@ class MainWindow : public QMainWindow
void on_khistorycombobox_currentIndexChanged(int i); void on_khistorycombobox_currentIndexChanged(int i);
void on_DefaultSaveFolder_triggered();
signals: signals:
void stopDownloading(int); void stopDownloading(int);