Skip to content

Commit

Permalink
src:add functions related to saving settings
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoming <2014500726@smail.xtu.edu.cn>
  • Loading branch information
QQxiaoming committed Oct 23, 2023
1 parent 5c541d3 commit 7cd555c
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 4 deletions.
11 changes: 11 additions & 0 deletions dpkg/quardCRT/usr/share/applications/open-with-quardCRT.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Icon=/opt/quardCRT/quardCRT.png
NoDisplay=true
Exec=/usr/bin/quardCRT -m true -s %U %f
Name=quardCRT
Comment=open with quardCRT
MimeType=x-scheme-handler/file;x-scheme-handler/dir;

16 changes: 16 additions & 0 deletions src/globalsetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@ GlobalSetting::GlobalSetting(QObject *parent)
QApplication::applicationName(),QApplication::applicationName(),parent)
{
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
void GlobalSetting::setValue(QAnyStringView key, const QVariant &value)
#else
void GlobalSetting::setValue(const QString &key, const QVariant &value)
#endif
{
QSettings::setValue(key, value);
if(realtime)
sync();
}

void GlobalSetting::setRealtimeSave(bool realtime)
{
this->realtime = realtime;
}
11 changes: 11 additions & 0 deletions src/globalsetting.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ class GlobalSetting : public QSettings
Q_OBJECT
public:
explicit GlobalSetting(QObject *parent = nullptr);

#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
void setValue(QAnyStringView key, const QVariant &value);
#else
void setValue(const QString &key, const QVariant &value);
#endif
void setRealtimeSave(bool realtime);
bool isRealtimeSave() const { return realtime;}

private:
bool realtime = false;
};

#endif // GLOBALSETTING_H
16 changes: 15 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QLibraryInfo>
#include <QStyleFactory>
#include <QRegularExpression>
#include <QFileInfo>

#include "qfonticon.h"

Expand Down Expand Up @@ -164,12 +165,21 @@ int main(int argc, char *argv[])

AppComLineParser->process(application);

GlobalSetting settings;
bool debugMode = settings.value("Debug/DebugMode",false).toBool();
if(debugMode) {
uint32_t debugLevel = settings.value("Debug/DebugLevel",0).toUInt();
QString debugLogFile = settings.value("Debug/DebugLogFile","").toString();
qDebug() << "DebugMode: " << debugMode;
qDebug() << "DebugLevel: " << debugLevel;
qDebug() << "DebugLogFile: " << debugLogFile;
}

QString dark_theme = "true";
QString app_lang;
bool isMiniUI = false;
QString dir;

GlobalSetting settings;
settings.beginGroup("Global/Startup");
if(settings.contains("dark_theme"))
dark_theme = settings.value("dark_theme").toString();
Expand All @@ -192,6 +202,10 @@ int main(int argc, char *argv[])
isMiniUI = AppComLineParser->getOpt("miniui") == "true"?true:false;
if(AppComLineParser->isSetOpt("start_dir"))
dir = AppComLineParser->getOpt("start_dir");
QFileInfo start_dir(dir);
if(start_dir.isFile()) {
dir = start_dir.absolutePath();
}

settings.endGroup();

Expand Down
14 changes: 13 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,8 @@ void MainWindow::menuAndToolBarRetranslateUi(void) {
}

void MainWindow::menuAndToolBarInit(void) {
GlobalSetting settings;

ui->toolBar->setIconSize(QSize(16,16));
ui->toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);

Expand Down Expand Up @@ -834,6 +836,8 @@ void MainWindow::menuAndToolBarInit(void) {
ui->toolBar->addSeparator();
autoSaveOptionsAction = new QAction(this);
autoSaveOptionsAction->setCheckable(true);
bool checked = settings.value("Global/Options/AutoSaveOptions",false).toBool();
autoSaveOptionsAction->setChecked(checked);
optionsMenu->addAction(autoSaveOptionsAction);
saveSettingsNowAction = new QAction(this);
optionsMenu->addAction(saveSettingsNowAction);
Expand Down Expand Up @@ -885,7 +889,6 @@ void MainWindow::menuAndToolBarInit(void) {
cleanAllBookmarkAction = new QAction(this);
bookmarkMenu->addAction(cleanAllBookmarkAction);
bookmarkMenu->addSeparator();
GlobalSetting settings;
int size = settings.beginReadArray("Global/Bookmark");
for(int i=0;i<size;i++) {
settings.setArrayIndex(i);
Expand Down Expand Up @@ -1159,6 +1162,15 @@ void MainWindow::menuAndToolBarConnectSignals(void) {
windowTransparency = (100-transparency)/100.0;
setWindowOpacity(windowTransparencyEnabled?windowTransparency:1.0);
});
connect(autoSaveOptionsAction,&QAction::triggered,this,[=](bool checked){
GlobalSetting settings;
settings.setValue("Global/Options/AutoSaveOptions",checked);
settings.setRealtimeSave(checked);
});
connect(saveSettingsNowAction,&QAction::triggered,this,[=](){
GlobalSetting settings;
settings.sync();
});
connect(keyMapManagerWindow,&keyMapManager::keyBindingChanged,this,[=](QString keyBinding){
foreach(SessionsWindow *sessionsWindow, sessionList) {
sessionsWindow->getTermWidget()->setKeyBindings(keyBinding);
Expand Down
2 changes: 1 addition & 1 deletion theme/dark/darkstyle.qss
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ QTabWidget::pane:selected {
}

QTabWidget::tab-bar {
alignment: left;
alignment: left;
}

/* QTabBar ----------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion theme/light/lightstyle.qss
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ QTabWidget::pane:selected {
}

QTabWidget::tab-bar {
alignment: left;
alignment: left;
}

/* QTabBar ----------------------------------------------------------------
Expand Down

0 comments on commit 7cd555c

Please sign in to comment.