diff --git a/settingsdialog.cpp b/settingsdialog.cpp index ca785ee..490f5a5 100644 --- a/settingsdialog.cpp +++ b/settingsdialog.cpp @@ -20,7 +20,6 @@ SettingsDialog::SettingsDialog(QWidget *parent) : ui->cmb_theme->addItem("Light Theme"); ui->cmb_theme->addItem("Dark Theme"); - } SettingsDialog::~SettingsDialog() @@ -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; } diff --git a/settingsdialog.h b/settingsdialog.h index 58d6b31..bfd508e 100644 --- a/settingsdialog.h +++ b/settingsdialog.h @@ -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." @@ -35,6 +37,7 @@ private slots: void executeFolderDialog(); public slots: void syntaxColorUpdateHandler(HighlightColor &colors); + void show(); private: Ui::SettingsDialog *ui; HighlightColor previewColors;