forked from blue/squawk
Downloads folder now is movable
This commit is contained in:
parent
d8b5ccb2da
commit
73b1b58a96
16 changed files with 141 additions and 12 deletions
|
@ -3,14 +3,58 @@
|
|||
|
||||
PageGeneral::PageGeneral(QWidget* parent):
|
||||
QWidget(parent),
|
||||
m_ui(new Ui::PageGeneral())
|
||||
m_ui(new Ui::PageGeneral()),
|
||||
dialog(nullptr)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
QSettings settings;
|
||||
m_ui->downloadsPathInput->setText(settings.value("downloadsPath").toString());
|
||||
connect(m_ui->downloadsPathButton, &QPushButton::clicked, this, &PageGeneral::onBrowseButtonClicked);
|
||||
}
|
||||
|
||||
PageGeneral::~PageGeneral()
|
||||
{
|
||||
if (dialog != nullptr) {
|
||||
dialog->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void PageGeneral::onBrowseButtonClicked()
|
||||
{
|
||||
if (dialog == nullptr) {
|
||||
QSettings settings;
|
||||
dialog = new QFileDialog(this, tr("Select where downloads folder is going to be"), settings.value("downloadsPath").toString());
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dialog->setAcceptMode(QFileDialog::AcceptSave); //I find it the most convinient way
|
||||
dialog->setFileMode(QFileDialog::AnyFile); //Otherwise the directory is supposed to be
|
||||
dialog->setOption(QFileDialog::ShowDirsOnly, true); //selected and not to be navigated
|
||||
dialog->setOption(QFileDialog::DontConfirmOverwrite, true);
|
||||
dialog->setModal(true);
|
||||
connect(dialog, &QFileDialog::accepted, this, &PageGeneral::onDialogAccepted);
|
||||
connect(dialog, &QFileDialog::destroyed, this, &PageGeneral::onDialogDestroyed);
|
||||
dialog->show();
|
||||
} else {
|
||||
dialog->show();
|
||||
dialog->raise();
|
||||
dialog->activateWindow();
|
||||
}
|
||||
}
|
||||
|
||||
void PageGeneral::onDialogAccepted()
|
||||
{
|
||||
QStringList files = dialog->selectedFiles();
|
||||
QString path;
|
||||
if (files.size() > 0) {
|
||||
path = files[0];
|
||||
} else {
|
||||
path = dialog->directory().canonicalPath();
|
||||
}
|
||||
m_ui->downloadsPathInput->setText(path);
|
||||
emit variableModified("downloadsPath", path);
|
||||
}
|
||||
|
||||
void PageGeneral::onDialogDestroyed()
|
||||
{
|
||||
dialog = nullptr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue