Skip to content

Commit

Permalink
Github Issue #39: config file is checked if it exists or not. If yes …
Browse files Browse the repository at this point in the history
…vault root path is loaded into the QLineEdit of the Settings Dialog. If not then new config file is created with the current directory set as the vault root path
  • Loading branch information
AngryFender committed Oct 13, 2023
1 parent 1e27339 commit ebace2c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
27 changes: 25 additions & 2 deletions settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ SettingsDialog::SettingsDialog(QWidget *parent) :

ui->cmb_theme->addItem("Light Theme");
ui->cmb_theme->addItem("Dark Theme");

}

SettingsDialog::~SettingsDialog()
Expand All @@ -46,9 +45,33 @@ void SettingsDialog::syntaxColorUpdateHandler(HighlightColor &colors)
emit syntaxColorUpdate(previewColors);
}

void SettingsDialog::show()
{
ui->edit_vaultRootPath->setText(getVaultRootPath());
QDialog::show();
}

const QString SettingsDialog::getVaultRootPath()
{
QString currentPath = QDir::currentPath();
QString filePath = currentPath + CONFIG_FILE_NAME;
QFile file(filePath);

QString vaultRootPath;
//todo

if(file.exists()){
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream stream(&file);
vaultRootPath = stream.readAll();
}
}else{
if (file.open(QIODevice::WriteOnly)){
QTextStream stream(&file);
stream << currentPath;
vaultRootPath = currentPath;
}
}
file.close();
return vaultRootPath;
}
3 changes: 3 additions & 0 deletions settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "mktextdocument.h"
#include "highlighter.h"

#define CONFIG_FILE_NAME "/config.txt"

const QString previewText = QStringLiteral("The header file declares several type definitions that guarantee a specified bit-size on all platforms supported by Qt for various basic types, for example qint8 which is a signed char guaranteed to be 8-bit on all platforms supported by Qt. The header file also declares the qlonglong type definition for long long int ( __int64 on Windows). "
"Several convenience type definitions are declared: qreal for double or float, uchar for unsigned char, uint for unsigned int, ulong for unsigned long and ushort for unsigned short.\n"
"\"Finally, the QtMsgType definition identifies the various messages that can be generated and sent to a Qt message handler; \"QtMessageHandler is a type definition for a pointer to a function with the signature void myMessageHandler(QtMsgType, const QMessageLogContext &, const char *). QMessageLogContext class contains the line, file, and function the message was logged at. This information is created by the QMessageLogger class. initialize the new thread before starting its event loop, or to run parallel code without an event loop."
Expand Down Expand Up @@ -35,6 +37,7 @@ private slots:
void executeFolderDialog();
public slots:
void syntaxColorUpdateHandler(HighlightColor &colors);
void show();
private:
Ui::SettingsDialog *ui;
HighlightColor previewColors;
Expand Down

0 comments on commit ebace2c

Please sign in to comment.