Add (experimental) Qt settings
This commit is contained in:
parent
544126373c
commit
77284da073
|
@ -8,6 +8,7 @@ set(META_APP_CATEGORIES "Utility")
|
|||
set(META_APP_AUTHOR "Martchus")
|
||||
set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
|
||||
set(META_APP_DESCRIPTION "A simple password store using AES-256-CBC encryption via OpenSSL")
|
||||
set(META_GUI_OPTIONAL true)
|
||||
set(META_VERSION_MAJOR 2)
|
||||
set(META_VERSION_MINOR 1)
|
||||
set(META_VERSION_PATCH 1)
|
||||
|
@ -113,11 +114,13 @@ set(REQUIRED_ICONS
|
|||
go-next
|
||||
qtcreator
|
||||
document-export
|
||||
password-generate
|
||||
)
|
||||
|
||||
# find c++utilities
|
||||
find_package(c++utilities 4.0.0 REQUIRED)
|
||||
use_cpp_utilities()
|
||||
include(BasicConfig)
|
||||
|
||||
# find qtutilities
|
||||
if(WIDGETS_GUI OR QUICK_GUI)
|
||||
|
@ -130,7 +133,6 @@ find_package(passwordfile 3.1.0 REQUIRED)
|
|||
use_password_file()
|
||||
|
||||
# include modules to apply configuration
|
||||
include(BasicConfig)
|
||||
if(WIDGETS_GUI OR QUICK_GUI)
|
||||
include(QtGuiConfig)
|
||||
include(QtConfig)
|
||||
|
|
|
@ -6,12 +6,13 @@
|
|||
|
||||
#include <qtutilities/resources/qtconfigarguments.h>
|
||||
#include <qtutilities/resources/resources.h>
|
||||
#include <qtutilities/settingsdialog/qtsettings.h>
|
||||
|
||||
#include <QTextCodec>
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#include <QSettings>
|
||||
|
||||
using namespace ApplicationUtilities;
|
||||
using namespace Dialogs;
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
|
@ -20,14 +21,18 @@ int runWidgetsGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs,
|
|||
SET_QT_APPLICATION_INFO;
|
||||
// init application
|
||||
QApplication a(argc, argv);
|
||||
// restore Qt settings
|
||||
QtSettings qtSettings;
|
||||
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName());
|
||||
qtSettings.restore(settings);
|
||||
qtSettings.apply();
|
||||
// load resources needed by classes of qtutilities
|
||||
QtUtilitiesResources::init();
|
||||
// apply settings specified via command line args
|
||||
qtConfigArgs.applySettings();
|
||||
LOAD_QT_TRANSLATIONS;
|
||||
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
|
||||
// init widgets GUI
|
||||
QtGui::MainWindow w;
|
||||
MainWindow w(settings, &qtSettings);
|
||||
w.show();
|
||||
if(!file.isEmpty()) {
|
||||
w.openFile(file);
|
||||
|
@ -36,6 +41,8 @@ int runWidgetsGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs,
|
|||
int res = a.exec();
|
||||
// cleanup resources
|
||||
QtUtilitiesResources::cleanup();
|
||||
// save Qt settings
|
||||
qtSettings.save(settings);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
#include <qtutilities/misc/desktoputils.h>
|
||||
#include <qtutilities/misc/recentmenumanager.h>
|
||||
#include <qtutilities/aboutdialog/aboutdialog.h>
|
||||
#include <qtutilities/settingsdialog/settingsdialog.h>
|
||||
#include <qtutilities/settingsdialog/optioncategorymodel.h>
|
||||
#include <qtutilities/settingsdialog/qtsettings.h>
|
||||
|
||||
#include <c++utilities/io/path.h>
|
||||
#include <c++utilities/io/catchiofailure.h>
|
||||
|
@ -107,11 +110,14 @@ void MainWindow::setSomethingChanged(bool somethingChanged)
|
|||
/*!
|
||||
* \brief Constructs a new main window.
|
||||
*/
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
MainWindow::MainWindow(QSettings &settings, Dialogs::QtSettings *qtSettings, QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
m_ui(new Ui::MainWindow),
|
||||
m_clearClipboardTimer(0),
|
||||
m_aboutDlg(nullptr)
|
||||
m_aboutDlg(nullptr),
|
||||
m_settings(settings),
|
||||
m_qtSettings(qtSettings),
|
||||
m_settingsDlg(nullptr)
|
||||
{
|
||||
// setup ui
|
||||
m_ui->setupUi(this);
|
||||
|
@ -123,7 +129,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
m_dontUpdateSelection = false;
|
||||
updateUiStatus();
|
||||
// load settings
|
||||
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName());
|
||||
settings.beginGroup(QStringLiteral("mainwindow"));
|
||||
// init recent menu manager
|
||||
m_recentMgr = new RecentMenuManager(m_ui->menuRecent, this);
|
||||
|
@ -170,7 +175,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
pwVisibilityAction->setChecked(true);
|
||||
setPasswordVisibility(pwVisibilityAction);
|
||||
// connect signals and slots
|
||||
// file related actions
|
||||
// -> file related actions
|
||||
connect(m_ui->actionSave, &QAction::triggered, this, &MainWindow::saveFile);
|
||||
connect(m_ui->actionExport, &QAction::triggered, this, &MainWindow::exportFile);
|
||||
connect(m_ui->actionShowContainingDirectory, &QAction::triggered, this, &MainWindow::showContainingDirectory);
|
||||
|
@ -178,34 +183,35 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
connect(m_ui->actionCreate, &QAction::triggered, this, static_cast<bool (MainWindow::*)(void)>(&MainWindow::createFile));
|
||||
connect(m_ui->actionQuit, &QAction::triggered, this, &MainWindow::close);
|
||||
connect(m_ui->actionChangepassword, &QAction::triggered, this, &MainWindow::changePassword);
|
||||
// showing dialogs
|
||||
// -> showing dialogs
|
||||
connect(m_ui->actionPasswordGenerator, &QAction::triggered, this, &MainWindow::showPassowrdGeneratorDialog);
|
||||
connect(m_ui->actionAbout, &QAction::triggered, this, &MainWindow::showAboutDialog);
|
||||
connect(m_ui->actionOpen, &QAction::triggered, this, &MainWindow::showOpenFileDialog);
|
||||
connect(m_ui->actionSaveAs, &QAction::triggered, this, &MainWindow::showSaveFileDialog);
|
||||
// add/remove account
|
||||
connect(m_ui->actionQtSettings, &QAction::triggered, this, &MainWindow::showSettingsDialog);
|
||||
// -> add/remove account
|
||||
connect(m_ui->actionAddAccount, &QAction::triggered, this, &MainWindow::addAccount);
|
||||
connect(m_ui->actionAddCategory, &QAction::triggered, this, &MainWindow::addCategory);
|
||||
connect(m_ui->actionRemoveRows, &QAction::triggered, this, &MainWindow::removeEntry);
|
||||
// insert/remove fields
|
||||
// -> insert/remove fields
|
||||
connect(m_ui->actionInsertRow, &QAction::triggered, this, &MainWindow::insertRow);
|
||||
connect(m_ui->actionRemoveAccount, &QAction::triggered, this, &MainWindow::removeRows);
|
||||
// undo/redo
|
||||
// -> undo/redo
|
||||
connect(m_ui->actionUndo, &QAction::triggered, m_undoStack, &QUndoStack::undo);
|
||||
connect(m_ui->actionRedo, &QAction::triggered, m_undoStack, &QUndoStack::redo);
|
||||
connect(m_undoStack, &QUndoStack::canUndoChanged, m_ui->actionUndo, &QAction::setEnabled);
|
||||
connect(m_undoStack, &QUndoStack::canRedoChanged, m_ui->actionRedo, &QAction::setEnabled);
|
||||
// view
|
||||
// -> view
|
||||
connect(passwordVisibilityGroup, &QActionGroup::triggered, this, &MainWindow::setPasswordVisibility);
|
||||
connect(m_ui->actionShowUndoStack, &QAction::triggered, this, &MainWindow::showUndoView);
|
||||
// models
|
||||
// -> models
|
||||
connect(m_ui->treeView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &MainWindow::accountSelected);
|
||||
connect(m_entryModel, &QAbstractItemModel::dataChanged, this, static_cast<void (MainWindow::*)(void)>(&MainWindow::setSomethingChanged));
|
||||
connect(m_fieldModel, &QAbstractItemModel::dataChanged, this, static_cast<void (MainWindow::*)(void)>(&MainWindow::setSomethingChanged));
|
||||
// context menus
|
||||
// -> context menus
|
||||
connect(m_ui->treeView, &QTableView::customContextMenuRequested, this, &MainWindow::showTreeViewContextMenu);
|
||||
connect(m_ui->tableView, &QTableView::customContextMenuRequested, this, &MainWindow::showTableViewContextMenu);
|
||||
// filter
|
||||
// -> filter
|
||||
//connect(m_ui->accountFilterLineEdit, &QLineEdit::textChanged, m_entryFilterModel, &QSortFilterProxyModel::setFilterFixedString);
|
||||
connect(m_ui->accountFilterLineEdit, &QLineEdit::textChanged, this, &MainWindow::applyFilter);
|
||||
// setup other controls
|
||||
|
@ -275,13 +281,12 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
|||
m_undoView->close();
|
||||
}
|
||||
// save settings
|
||||
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName());
|
||||
settings.beginGroup(QStringLiteral("mainwindow"));
|
||||
settings.setValue(QStringLiteral("geometry"), saveGeometry());
|
||||
settings.setValue(QStringLiteral("state"), saveState());
|
||||
settings.setValue(QStringLiteral("recententries"), m_recentMgr->save());
|
||||
settings.setValue(QStringLiteral("accountfilter"), m_ui->accountFilterLineEdit->text());
|
||||
settings.setValue(QStringLiteral("alwayscreatebackup"), m_ui->actionAlwaysCreateBackup->isChecked());
|
||||
m_settings.beginGroup(QStringLiteral("mainwindow"));
|
||||
m_settings.setValue(QStringLiteral("geometry"), saveGeometry());
|
||||
m_settings.setValue(QStringLiteral("state"), saveState());
|
||||
m_settings.setValue(QStringLiteral("recententries"), m_recentMgr->save());
|
||||
m_settings.setValue(QStringLiteral("accountfilter"), m_ui->accountFilterLineEdit->text());
|
||||
m_settings.setValue(QStringLiteral("alwayscreatebackup"), m_ui->actionAlwaysCreateBackup->isChecked());
|
||||
QString pwVisibility;
|
||||
if(m_ui->actionShowAlways->isChecked()) {
|
||||
pwVisibility = QStringLiteral("always");
|
||||
|
@ -290,8 +295,8 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
|||
} else {
|
||||
pwVisibility = QStringLiteral("editing");
|
||||
}
|
||||
settings.setValue(QStringLiteral("pwvisibility"), pwVisibility);
|
||||
settings.endGroup();
|
||||
m_settings.setValue(QStringLiteral("pwvisibility"), pwVisibility);
|
||||
m_settings.endGroup();
|
||||
}
|
||||
|
||||
void MainWindow::timerEvent(QTimerEvent *event)
|
||||
|
@ -302,6 +307,26 @@ void MainWindow::timerEvent(QTimerEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Shows the settings dialog (which currently only consists of the Qt settings category).
|
||||
*/
|
||||
void MainWindow::showSettingsDialog()
|
||||
{
|
||||
if(!m_settingsDlg) {
|
||||
m_settingsDlg = new SettingsDialog(this);
|
||||
if(m_qtSettings) {
|
||||
m_settingsDlg->setWindowTitle(tr("Qt settings"));
|
||||
m_settingsDlg->setSingleCategory(m_qtSettings->category());
|
||||
}
|
||||
//connect(m_settingsDlg, &SettingsDialog::applied, this, &MainWindow::settingsAccepted);
|
||||
}
|
||||
if(m_settingsDlg->isHidden()) {
|
||||
m_settingsDlg->showNormal();
|
||||
} else {
|
||||
m_settingsDlg->activateWindow();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Shows the about dialog.
|
||||
*/
|
||||
|
|
|
@ -17,6 +17,7 @@ QT_FORWARD_DECLARE_CLASS(QCloseEvent)
|
|||
QT_FORWARD_DECLARE_CLASS(QTreeWidgetItem)
|
||||
QT_FORWARD_DECLARE_CLASS(QUndoStack)
|
||||
QT_FORWARD_DECLARE_CLASS(QUndoView)
|
||||
QT_FORWARD_DECLARE_CLASS(QSettings)
|
||||
|
||||
namespace Io {
|
||||
DECLARE_ENUM_CLASS(EntryType, int);
|
||||
|
@ -29,6 +30,8 @@ class RecentMenuManager;
|
|||
|
||||
namespace Dialogs {
|
||||
class AboutDialog;
|
||||
class SettingsDialog;
|
||||
class QtSettings;
|
||||
}
|
||||
|
||||
namespace QtGui {
|
||||
|
@ -46,7 +49,7 @@ class MainWindow : public QMainWindow
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
explicit MainWindow(QSettings &settings, Dialogs::QtSettings *qtSettings = nullptr, QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
public slots:
|
||||
|
@ -59,6 +62,13 @@ public slots:
|
|||
bool saveFile();
|
||||
void exportFile();
|
||||
bool closeFile();
|
||||
// show dialogs
|
||||
void showOpenFileDialog();
|
||||
void showSaveFileDialog();
|
||||
void showSettingsDialog();
|
||||
void showAboutDialog();
|
||||
void showPassowrdGeneratorDialog();
|
||||
void showUndoView();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
@ -66,12 +76,6 @@ protected:
|
|||
void timerEvent(QTimerEvent *event);
|
||||
|
||||
private slots:
|
||||
// showing dialogs
|
||||
void showAboutDialog();
|
||||
void showPassowrdGeneratorDialog();
|
||||
void showOpenFileDialog();
|
||||
void showSaveFileDialog();
|
||||
void showUndoView();
|
||||
// file management
|
||||
bool showFile();
|
||||
// account/categories management
|
||||
|
@ -124,6 +128,9 @@ private:
|
|||
int m_clearClipboardTimer;
|
||||
MiscUtils::RecentMenuManager *m_recentMgr;
|
||||
Dialogs::AboutDialog *m_aboutDlg;
|
||||
QSettings &m_settings;
|
||||
Dialogs::QtSettings *m_qtSettings;
|
||||
Dialogs::SettingsDialog *m_settingsDlg;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -194,6 +194,9 @@
|
|||
<property name="toolTip">
|
||||
<string>Recently opened files</string>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<addaction name="actionCreate"/>
|
||||
<addaction name="actionOpen"/>
|
||||
|
@ -234,6 +237,7 @@
|
|||
<string>&Tools</string>
|
||||
</property>
|
||||
<addaction name="actionPasswordGenerator"/>
|
||||
<addaction name="actionQtSettings"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuView">
|
||||
<property name="title">
|
||||
|
@ -397,6 +401,9 @@
|
|||
</property>
|
||||
</action>
|
||||
<action name="actionPasswordGenerator">
|
||||
<property name="icon">
|
||||
<iconset theme="password-generate"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Password generator</string>
|
||||
</property>
|
||||
|
@ -498,6 +505,14 @@
|
|||
<string>&hide always</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionQtSettings">
|
||||
<property name="icon">
|
||||
<iconset theme="qtcreator"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Qt settings</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
|
|
Loading…
Reference in New Issue