Downloads folder now is movable

This commit is contained in:
Blue 2022-02-19 21:31:49 +03:00
parent d8b5ccb2da
commit 73b1b58a96
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
16 changed files with 141 additions and 12 deletions

View file

@ -125,6 +125,7 @@ void Squawk::onPreferences()
preferences = new Settings();
preferences->setAttribute(Qt::WA_DeleteOnClose);
connect(preferences, &Settings::destroyed, this, &Squawk::onPreferencesClosed);
connect(preferences, &Settings::changeDownloadsPath, this, &Squawk::changeDownloadsPath);
preferences->show();
} else {

View file

@ -80,6 +80,7 @@ signals:
void uploadVCard(const QString& account, const Shared::VCard& card);
void responsePassword(const QString& account, const QString& password);
void localPathInvalid(const QString& path);
void changeDownloadsPath(const QString& path);
public slots:
void writeSettings();

View file

@ -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;
}

View file

@ -5,6 +5,7 @@
#include <QScopedPointer>
#include <QVariant>
#include <QSettings>
#include <QFileDialog>
namespace Ui
{
@ -24,8 +25,14 @@ public:
signals:
void variableModified(const QString& key, const QVariant& value);
private slots:
void onBrowseButtonClicked();
void onDialogAccepted();
void onDialogDestroyed();
private:
QScopedPointer<Ui::PageGeneral> m_ui;
QFileDialog* dialog;
};
#endif // PAGEGENERAL_H

View file

@ -33,7 +33,7 @@
<item>
<widget class="QPushButton" name="downloadsPathButton">
<property name="text">
<string>PushButton</string>
<string>Browse</string>
</property>
</widget>
</item>

View file

@ -42,11 +42,21 @@ void Settings::apply()
for (const std::pair<const QString, QVariant>& pair: modifiedSettings) {
if (pair.first == "style") {
Shared::Global::setStyle(pair.second.toString());
settings.setValue(pair.first, pair.second);
} else if (pair.first == "theme") {
Shared::Global::setTheme(pair.second.toString());
settings.setValue(pair.first, pair.second);
} else if (pair.first == "downloadsPath") {
QString path = pair.second.toString();
if (!Shared::isSubdirectoryOfSettings(path)) {
path = Shared::getAbsoluteWritablePath(path);
if (path.size() > 0) {
settings.setValue(pair.first, path);
emit changeDownloadsPath(path);
}
}
}
settings.setValue(pair.first, pair.second);
}
modifiedSettings.clear();

View file

@ -5,8 +5,10 @@
#include <QListWidgetItem>
#include <QScopedPointer>
#include <QSettings>
#include <QDir>
#include "shared/global.h"
#include "shared/pathcheck.h"
namespace Ui
{
@ -23,6 +25,9 @@ public:
Settings(QWidget* parent = nullptr);
~Settings();
signals:
void changeDownloadsPath(const QString& path);
public slots:
void apply();
void confirm();

View file

@ -10,6 +10,9 @@
<height>363</height>
</rect>
</property>
<property name="windowTitle">
<string>Preferences</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
@ -183,10 +186,23 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="PageGeneral" name="General" native="true"/>
<widget class="PageAppearance" name="Appearance" native="true"/>
<widget class="PageGeneral" name="General"/>
<widget class="PageAppearance" name="Appearance"/>
</widget>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>