Skip to content

Commit

Permalink
feat(file_dialog): save history folder.
Browse files Browse the repository at this point in the history
Change-Id: Ia8a5992adf80f700419396a59222140c311a50bc
  • Loading branch information
reionwong committed Sep 7, 2018
1 parent 9e82a5d commit 9116f16
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 15 additions & 2 deletions filechoosewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
DWIDGET_USE_NAMESPACE

FileChooseWidget::FileChooseWidget(QWidget *parent)
: QWidget(parent)
: QWidget(parent),
m_settings("deepin", "deepin-deb-install")
{
const auto ratio = devicePixelRatioF();
QPixmap iconPix = Utils::renderSVG(":/images/icon.svg", QSize(140, 140));
Expand Down Expand Up @@ -96,11 +97,23 @@ FileChooseWidget::FileChooseWidget(QWidget *parent)

void FileChooseWidget::chooseFiles()
{
QString historyDir = m_settings.value("history_dir").toString();

if (historyDir.isEmpty()) {
historyDir = QDir::homePath();
}

QFileDialog dialog;
dialog.setFileMode(QFileDialog::ExistingFiles);
dialog.setNameFilter("Debian Pakcage Files (*.deb)");
dialog.setDirectory(historyDir);

const int mode = dialog.exec();

// save the directory string to config file.
m_settings.setValue("history_dir", dialog.directoryUrl().toLocalFile());

if (dialog.exec() != QDialog::Accepted)
if (mode != QDialog::Accepted)
return;

const QStringList selected_files = dialog.selectedFiles();
Expand Down
2 changes: 2 additions & 0 deletions filechoosewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define FILECHOOSEWIDGET_H

#include <QWidget>
#include <QSettings>

#include <dlinkbutton.h>

Expand All @@ -42,6 +43,7 @@ private slots:

private:
Dtk::Widget::DLinkButton *m_fileChooseBtn;
QSettings m_settings;
};

#endif // FILECHOOSEWIDGET_H

0 comments on commit 9116f16

Please sign in to comment.