diff --git a/src/core/diaryholder.cpp b/src/core/diaryholder.cpp index 1ec2eb6..9486f08 100644 --- a/src/core/diaryholder.cpp +++ b/src/core/diaryholder.cpp @@ -22,14 +22,13 @@ #include "../util/zipper.h" #include "diaryholder.h" -int const CURRENT_SAVE_VERSION = 4; +int const CURRENT_SAVE_VERSION = 5; DiaryHolder *diary_holder_ptr; DiaryHolder::DiaryHolder() { diary_holder_ptr = this; - diary = td::Diary{ - td::DiaryLog(), td::Metadata{CURRENT_SAVE_VERSION, QDateTime::currentSecsSinceEpoch()}, td::Settings{}}; + m_diary = td::Diary{td::DiaryLog(), td::Metadata{CURRENT_SAVE_VERSION, QDateTime::currentSecsSinceEpoch()}}; } DiaryHolder::~DiaryHolder() {} @@ -42,8 +41,7 @@ DiaryHolder *DiaryHolder::instance() void DiaryHolder::init() { qDebug() << "Initialised diary."; - diary = td::Diary{ - td::DiaryLog(), td::Metadata{CURRENT_SAVE_VERSION, QDateTime::currentSecsSinceEpoch()}, td::Settings{}}; + m_diary = td::Diary{td::DiaryLog(), td::Metadata{CURRENT_SAVE_VERSION, QDateTime::currentSecsSinceEpoch()}}; } bool DiaryHolder::load(std::string &raw) @@ -54,12 +52,8 @@ bool DiaryHolder::load(std::string &raw) return false; } - // Here is where updating save versions will occur *if* I every actually get - // around to doing this which will probably never happen because I'm the only - // person using my own app :') - try { - diary = json.get(); + m_diary = json.get(); } catch (nlohmann::json::exception const &e) { qDebug() << "Exception while loading JSON diary."; @@ -89,15 +83,15 @@ bool DiaryHolder::save() } // Update last_updated. - diary.metadata.last_updated = QDateTime::currentSecsSinceEpoch(); - nlohmann::json const j = diary; + m_diary.metadata.last_updated = QDateTime::currentSecsSinceEpoch(); + nlohmann::json const j = m_diary; // Gzip JSON. std::string compressed, encrypted, decompressed = j.dump(); Zipper::zip(compressed, decompressed); // Encrypt if there is a password set. - auto const key_set = Encryptor::instance()->key_set; + auto const key_set = Encryptor::instance()->m_key_set; if (key_set) Encryptor::instance()->encrypt(compressed, encrypted); @@ -106,8 +100,8 @@ bool DiaryHolder::save() if (!ofs.fail()) { ofs << (key_set ? encrypted : compressed); - InternalManager::instance()->internal_diary_changed = false; - InternalManager::instance()->diary_file_changed = true; + InternalManager::instance()->m_internal_diary_changed = false; + InternalManager::instance()->m_diary_file_changed = true; qDebug() << "Saved diary to disk."; return true; } @@ -119,8 +113,8 @@ bool DiaryHolder::save() std::optional DiaryHolder::get_yearmap(QDate const &date) { - auto const &year_iter = diary.log.find(date.year()); - if (year_iter == diary.log.end()) + auto const &year_iter = m_diary.log.find(date.year()); + if (year_iter == m_diary.log.end()) return std::nullopt; return std::optional(year_iter); @@ -128,8 +122,8 @@ std::optional DiaryHolder::get_yearmap(QDate const &date std::optional DiaryHolder::get_monthmap(QDate const &date) { - auto const &year_iter = diary.log.find(date.year()); - if (year_iter == diary.log.end()) + auto const &year_iter = m_diary.log.find(date.year()); + if (year_iter == m_diary.log.end()) return std::nullopt; auto const &month_iter = year_iter->second.find(date.month()); @@ -141,8 +135,8 @@ std::optional DiaryHolder::get_monthmap(QDate const &date std::optional DiaryHolder::get_entry(QDate const &date) { - auto const &year_iter = diary.log.find(date.year()); - if (year_iter == diary.log.end()) + auto const &year_iter = m_diary.log.find(date.year()); + if (year_iter == m_diary.log.end()) return std::nullopt; auto const &month_iter = year_iter->second.find(date.month()); @@ -158,7 +152,7 @@ std::optional DiaryHolder::get_entry(QDate const &date) void DiaryHolder::create_entry(QDate const &date, td::Entry const &entry) { - auto &year_map = DiaryHolder::instance()->diary.log; + auto &year_map = DiaryHolder::instance()->m_diary.log; auto const &[year_iter, dummy] = year_map.try_emplace(date.year(), td::YearMap()); auto const &[month_iter, d2] = year_iter->second.try_emplace(date.month(), td::MonthMap()); diff --git a/src/core/diaryholder.h b/src/core/diaryholder.h index 37909de..94e111b 100644 --- a/src/core/diaryholder.h +++ b/src/core/diaryholder.h @@ -47,7 +47,7 @@ class DiaryHolder { void create_entry(QDate const &date, td::Entry const &entry); void delete_entry(QDate const &date); - td::Diary diary; + td::Diary m_diary; }; #endif // DIARYHOLDER_H diff --git a/src/core/googlewrapper.cpp b/src/core/googlewrapper.cpp index e180ba6..160501e 100644 --- a/src/core/googlewrapper.cpp +++ b/src/core/googlewrapper.cpp @@ -37,36 +37,36 @@ GoogleWrapper *google_wrapper_ptr; GoogleWrapper::GoogleWrapper(QObject *parent) : QObject(parent) { google_wrapper_ptr = this; - google = new O2Google(this); - google->setClientId(CLIENT_ID); - google->setClientSecret(CLIENT_SECRET); - google->setScope(SCOPE); - google->setLocalPort(PORT); - google->setReplyContent(REPLY_CONTENT); + m_o2g = new O2Google(this); + m_o2g->setClientId(CLIENT_ID); + m_o2g->setClientSecret(CLIENT_SECRET); + m_o2g->setScope(SCOPE); + m_o2g->setLocalPort(PORT); + m_o2g->setReplyContent(REPLY_CONTENT); QVariantMap params; params["access_type"] = QVariant("offline"); - google->setExtraRequestParams(params); + m_o2g->setExtraRequestParams(params); // To stop o2 from writing to the disk, a dummy read only file from the resource file is provided. // Don't want o2 to write to disk because a custom encryption method is already employed. auto settings = new QSettings(":/dummysettings", QSettings::IniFormat); auto settings_store = new O0SettingsStore(settings, QApplication::applicationName() /* Placeholder value */); - google->setStore(settings_store); + m_o2g->setStore(settings_store); - manager = new QNetworkAccessManager(this); - requestor = new O2Requestor(manager, qobject_cast(google), this); - requestor->setAddAccessTokenInQuery(false); - requestor->setAccessTokenInAuthenticationHTTPHeaderFormat("Bearer %1"); + m_man = new QNetworkAccessManager(this); + m_req = new O2Requestor(m_man, qobject_cast(m_o2g), this); + m_req->setAddAccessTokenInQuery(false); + m_req->setAccessTokenInAuthenticationHTTPHeaderFormat("Bearer %1"); - connect(google, &O2Google::openBrowser, [](QUrl const &url) { QDesktopServices::openUrl(url); }); + connect(m_o2g, &O2Google::openBrowser, [](QUrl const &url) { QDesktopServices::openUrl(url); }); } GoogleWrapper::~GoogleWrapper() { - delete google; - delete manager; - delete requestor; + delete m_o2g; + delete m_man; + delete m_req; } GoogleWrapper *GoogleWrapper::instance() @@ -76,14 +76,14 @@ GoogleWrapper *GoogleWrapper::instance() bool GoogleWrapper::encrypt_credentials() { - nlohmann::json const j = td::Credentials{google->token().toStdString(), google->refreshToken().toStdString()}; + nlohmann::json const j = td::Credentials{m_o2g->token().toStdString(), m_o2g->refreshToken().toStdString()}; // Gzip JSON. std::string compressed, encrypted, decompressed = j.dump(); Zipper::zip(compressed, decompressed); // Encrypt if there is a password set. - auto const key_set = Encryptor::instance()->key_set; + auto const key_set = Encryptor::instance()->m_key_set; if (key_set) Encryptor::instance()->encrypt(compressed, encrypted); @@ -145,9 +145,9 @@ bool GoogleWrapper::decrypt_credentials(bool const perform_decrypt) try { auto credentials = json.get(); - google->setToken(credentials.access_token.data()); - google->setRefreshToken(credentials.refresh_token.data()); - google->setLinked(true); + m_o2g->setToken(credentials.access_token.data()); + m_o2g->setRefreshToken(credentials.refresh_token.data()); + m_o2g->setLinked(true); qDebug() << "Decrypted tokens."; return true; @@ -160,14 +160,14 @@ bool GoogleWrapper::decrypt_credentials(bool const perform_decrypt) td::LinkingResponse GoogleWrapper::verify_auth() { - if (!google->linked()) { + if (!m_o2g->linked()) { qDebug() << "Linking failed."; return td::LinkingResponse::Fail; } // Confirm scopes. // Quite possibly the ONLY regular expression in the entire project :o - QStringList scope_list = google->scope().split(QRegularExpression("\\+|\\s")); + QStringList scope_list = m_o2g->scope().split(QRegularExpression("\\+|\\s")); QStringList required_list = QString(SCOPE).split(" "); std::sort(scope_list.begin(), scope_list.end()); std::sort(required_list.begin(), required_list.end()); @@ -185,12 +185,12 @@ td::LinkingResponse GoogleWrapper::verify_auth() td::NRO GoogleWrapper::revoke_access() { qDebug() << "Attempting to revoke access via Google."; - QUrl url(QString("https://oauth2.googleapis.com/revoke?token=%1").arg(google->token())); + QUrl url(QString("https://oauth2.googleapis.com/revoke?token=%1").arg(m_o2g->token())); QNetworkRequest req(url); req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); - auto observable = AsyncFuture::observe(requestor, qOverload(&O2Requestor::finished)); - requestor->post(req, ""); + auto observable = AsyncFuture::observe(m_req, qOverload(&O2Requestor::finished)); + m_req->post(req, ""); return observable; } @@ -200,8 +200,8 @@ td::NRO GoogleWrapper::list_files() QUrl url("https://www.googleapis.com/drive/v3/files?spaces=appDataFolder"); QNetworkRequest req(url); - auto observable = AsyncFuture::observe(requestor, qOverload(&O2Requestor::finished)); - requestor->get(req); + auto observable = AsyncFuture::observe(m_req, qOverload(&O2Requestor::finished)); + m_req->get(req); return observable; } @@ -226,9 +226,9 @@ td::NRO GoogleWrapper::upload_file(QFile *file, QString const &name) multi_part->append(metadata); multi_part->append(media); - auto observable = AsyncFuture::observe(requestor, qOverload(&O2Requestor::finished)); + auto observable = AsyncFuture::observe(m_req, qOverload(&O2Requestor::finished)); // The content type and content length headers are automatically set by Qt. - requestor->post(req, multi_part); + m_req->post(req, multi_part); return observable; } @@ -239,8 +239,8 @@ td::NRO GoogleWrapper::copy_file(QString const &id, QString const &new_name) QNetworkRequest req(url); req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - auto observable = AsyncFuture::observe(requestor, qOverload(&O2Requestor::finished)); - requestor->post(req, QString("{\"name\":\"%1\",\"parents\":[\"appDataFolder\"]}").arg(new_name).toUtf8()); + auto observable = AsyncFuture::observe(m_req, qOverload(&O2Requestor::finished)); + m_req->post(req, QString("{\"name\":\"%1\",\"parents\":[\"appDataFolder\"]}").arg(new_name).toUtf8()); return observable; } @@ -250,8 +250,8 @@ td::NRO GoogleWrapper::download_file(QString const &id) QUrl url(QString("https://www.googleapis.com/drive/v3/files/%1?alt=media").arg(id)); QNetworkRequest req(url); - auto observable = AsyncFuture::observe(requestor, qOverload(&O2Requestor::finished)); - requestor->get(req); + auto observable = AsyncFuture::observe(m_req, qOverload(&O2Requestor::finished)); + m_req->get(req); return observable; } @@ -261,8 +261,8 @@ td::NRO GoogleWrapper::delete_file(QString const &id) QUrl url(QString("https://www.googleapis.com/drive/v3/files/%1").arg(id)); QNetworkRequest req(url); - auto observable = AsyncFuture::observe(requestor, qOverload(&O2Requestor::finished)); - requestor->deleteResource(req); + auto observable = AsyncFuture::observe(m_req, qOverload(&O2Requestor::finished)); + m_req->deleteResource(req); return observable; } @@ -287,8 +287,8 @@ td::NRO GoogleWrapper::update_file(QFile *file, QString const &id) multi_part->append(metadata); multi_part->append(media); - auto observable = AsyncFuture::observe(requestor, qOverload(&O2Requestor::finished)); - requestor->customRequest(req, "PATCH", multi_part); + auto observable = AsyncFuture::observe(m_req, qOverload(&O2Requestor::finished)); + m_req->customRequest(req, "PATCH", multi_part); return observable; } diff --git a/src/core/googlewrapper.h b/src/core/googlewrapper.h index f11a8a3..4e0acd9 100644 --- a/src/core/googlewrapper.h +++ b/src/core/googlewrapper.h @@ -47,9 +47,9 @@ class GoogleWrapper : public QObject { ~GoogleWrapper(); static GoogleWrapper *instance(); - O2Google *google; - QNetworkAccessManager *manager; - O2Requestor *requestor; + O2Google *m_o2g; + QNetworkAccessManager *m_man; + O2Requestor *m_req; bool encrypt_credentials(); bool decrypt_credentials(bool const perform_decrypt); diff --git a/src/core/internalmanager.cpp b/src/core/internalmanager.cpp index 75c0ccb..21bf23d 100644 --- a/src/core/internalmanager.cpp +++ b/src/core/internalmanager.cpp @@ -25,23 +25,23 @@ InternalManager *i_m_ptr; InternalManager::InternalManager() { i_m_ptr = this; - app_busy = false; - internal_diary_changed = false; - diary_file_changed = false; + m_app_busy = false; + m_internal_diary_changed = false; + m_diary_file_changed = false; - settings = new QSettings(QString("%1/%2").arg(data_location(), "config.ini"), QSettings::IniFormat, this); + m_settings = new QSettings(QString("%1/%2").arg(data_location(), "config.ini"), QSettings::IniFormat, this); init_settings(false); - inactive_filter = new InactiveFilter(settings->value("lock_timeout").toLongLong(), this); - QApplication::instance()->installEventFilter(inactive_filter); + m_inactive_filter = new InactiveFilter(m_settings->value("lock_timeout").toLongLong(), this); + QApplication::instance()->installEventFilter(m_inactive_filter); start_update_theme(); } InternalManager::~InternalManager() { - delete settings; - delete inactive_filter; + delete m_settings; + delete m_inactive_filter; } InternalManager *InternalManager::instance() @@ -51,27 +51,27 @@ InternalManager *InternalManager::instance() void InternalManager::init_settings(const bool force_reset) { - if (!settings->contains("sync_enabled") || force_reset) - settings->setValue("sync_enabled", false); + if (!m_settings->contains("sync_enabled") || force_reset) + m_settings->setValue("sync_enabled", false); - if (!settings->contains("theme") || force_reset) - settings->setValue("theme", static_cast(td::Theme::Dark)); + if (!m_settings->contains("theme") || force_reset) + m_settings->setValue("theme", static_cast(td::Theme::Dark)); - if (!settings->contains("lock_timeout") || force_reset) - settings->setValue("lock_timeout", static_cast(300000 /* 5 minutes */)); + if (!m_settings->contains("lock_timeout") || force_reset) + m_settings->setValue("lock_timeout", static_cast(300000 /* 5 minutes */)); - if (!settings->contains("pie_slice_sorting") || force_reset) - settings->setValue("pie_slice_sorting", static_cast(td::settings::PieSliceSort::Days)); + if (!m_settings->contains("pie_slice_sorting") || force_reset) + m_settings->setValue("pie_slice_sorting", static_cast(td::settings::PieSliceSort::Days)); } td::Theme InternalManager::get_theme(bool const opposite) { if (opposite) { - return static_cast(settings->value("theme").toInt()) == td::Theme::Dark ? td::Theme::Light + return static_cast(m_settings->value("theme").toInt()) == td::Theme::Dark ? td::Theme::Light : td::Theme::Dark; } else { - return static_cast(settings->value("theme").toInt()); + return static_cast(m_settings->value("theme").toInt()); } } @@ -87,27 +87,33 @@ QString InternalManager::get_theme_str(bool const opposite) QString InternalManager::data_location() { + // Testing convenience +#ifdef QT_DEBUG + return QString("%1/%2-DEBUG") + .arg(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), QApplication::applicationName()); +#else return QString("%1/%2").arg( QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), QApplication::applicationName()); +#endif } void InternalManager::start_busy_mode() { - if (app_busy) + if (m_app_busy) return; - QApplication::instance()->installEventFilter(&busy_filter); - app_busy = true; + QApplication::instance()->installEventFilter(&m_busy_filter); + m_app_busy = true; QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); } void InternalManager::end_busy_mode() { - if (!app_busy) + if (!m_app_busy) return; - QApplication::instance()->removeEventFilter(&busy_filter); - app_busy = false; + QApplication::instance()->removeEventFilter(&m_busy_filter); + m_app_busy = false; QGuiApplication::restoreOverrideCursor(); } diff --git a/src/core/internalmanager.h b/src/core/internalmanager.h index 2cf0c47..7434149 100644 --- a/src/core/internalmanager.h +++ b/src/core/internalmanager.h @@ -36,21 +36,26 @@ enum class Rating { Unknown, VeryBad, Bad, Ok, Good, VeryGood }; struct Entry { bool important; Rating rating; - std::string message; + std::string general_message; + std::string emotions_message; + std::string gratitude_message; time_t last_updated; }; inline void to_json(nlohmann::json &j, Entry const &e) { - j = nlohmann::json{ - {"important", e.important}, {"rating", e.rating}, {"message", e.message}, {"last_updated", e.last_updated}}; + j = nlohmann::json{{"important", e.important}, {"rating", e.rating}, {"general_message", e.general_message}, + {"emotions_message", e.emotions_message}, {"gratitude_message", e.gratitude_message}, + {"last_updated", e.last_updated}}; } inline void from_json(nlohmann::json const &j, Entry &e) { j.at("important").get_to(e.important); j.at("rating").get_to(e.rating); - j.at("message").get_to(e.message); + j.at("general_message").get_to(e.general_message); + j.at("emotions_message").get_to(e.emotions_message); + j.at("gratitude_message").get_to(e.gratitude_message); j.at("last_updated").get_to(e.last_updated); } @@ -74,29 +79,20 @@ inline void from_json(nlohmann::json const &j, Metadata &m) j.at("last_updated").get_to(m.last_updated); } -struct Settings { -}; - -inline void to_json(nlohmann::json & /* j */, Settings const & /* s */) {} - -inline void from_json(nlohmann::json const & /* j */, Settings & /* s */) {} - struct Diary { DiaryLog log; Metadata metadata; - Settings settings; }; inline void to_json(nlohmann::json &j, Diary const &d) { - j = nlohmann::json{{"log", d.log}, {"metadata", d.metadata}, {"settings", d.settings}}; + j = nlohmann::json{{"log", d.log}, {"metadata", d.metadata}}; } inline void from_json(nlohmann::json const &j, Diary &d) { j.at("log").get_to(d.log); j.at("metadata").get_to(d.metadata); - j.at("settings").get_to(d.settings); } namespace OldVersions { @@ -181,21 +177,21 @@ class InternalManager : public QObject { inline void set_colour(td::ColourRole role, const QColor &colour) { - colourmap[static_cast(role)] = colour; + m_colourmap[static_cast(role)] = colour; } inline QColor colour(td::ColourRole role) const { - return colourmap.value(static_cast(role)); + return m_colourmap.value(static_cast(role)); } - QHash colourmap; - QSettings *settings; - InactiveFilter *inactive_filter; - BusyFilter busy_filter; - bool app_busy; - bool internal_diary_changed; - bool diary_file_changed; + QHash m_colourmap; + QSettings *m_settings; + InactiveFilter *m_inactive_filter; + BusyFilter m_busy_filter; + bool m_app_busy; + bool m_internal_diary_changed; + bool m_diary_file_changed; }; class AppBusyLock { @@ -203,12 +199,12 @@ class AppBusyLock { AppBusyLock(bool const p = false) { InternalManager::instance()->start_busy_mode(); - persist = p; + m_persist = p; } ~AppBusyLock() { - if (!persist) + if (!m_persist) InternalManager::instance()->end_busy_mode(); } @@ -217,7 +213,7 @@ class AppBusyLock { InternalManager::instance()->end_busy_mode(); } - bool persist; + bool m_persist; }; #endif // INTERNAL_MANAGER_H diff --git a/src/core/theoreticaldiary.cpp b/src/core/theoreticaldiary.cpp index 45cc9cb..39bb8a7 100644 --- a/src/core/theoreticaldiary.cpp +++ b/src/core/theoreticaldiary.cpp @@ -39,22 +39,22 @@ TheoreticalDiary::TheoreticalDiary(int &argc, char *argv[]) : QApplication(argc, setWindowIcon(QIcon(":/linux_icons/256x256/theoreticaldiary.png")); // Create app directory. - QDir dir(internal_manager->data_location()); + QDir dir(m_internal_manager->data_location()); if (!dir.exists()) dir.mkpath("."); - gwrapper = new GoogleWrapper(this); - diary_holder = new DiaryHolder(); - encryptor = new Encryptor(); - internal_manager = new InternalManager(); + m_gwrapper = new GoogleWrapper(this); + m_diary_holder = new DiaryHolder(); + m_encryptor = new Encryptor(); + m_internal_manager = new InternalManager(); } TheoreticalDiary::~TheoreticalDiary() { - delete gwrapper; - delete diary_holder; - delete encryptor; - delete internal_manager; + delete m_gwrapper; + delete m_diary_holder; + delete m_encryptor; + delete m_internal_manager; } TheoreticalDiary *TheoreticalDiary::instance() diff --git a/src/core/theoreticaldiary.h b/src/core/theoreticaldiary.h index bb898d7..4f4c435 100644 --- a/src/core/theoreticaldiary.h +++ b/src/core/theoreticaldiary.h @@ -40,11 +40,11 @@ class TheoreticalDiary : public QApplication { static TheoreticalDiary *instance(); // These have to be pointers in order to break cyclic dependencies. - GoogleWrapper *gwrapper; - QSettings *settings; - DiaryHolder *diary_holder; - Encryptor *encryptor; - InternalManager *internal_manager; + GoogleWrapper *m_gwrapper; + QSettings *m_settings; + DiaryHolder *m_diary_holder; + Encryptor *m_encryptor; + InternalManager *m_internal_manager; }; #endif // THOERETICALDIARY_H diff --git a/src/gui/aboutdialog.cpp b/src/gui/aboutdialog.cpp index adf9179..6b11443 100644 --- a/src/gui/aboutdialog.cpp +++ b/src/gui/aboutdialog.cpp @@ -56,29 +56,29 @@ QString const LIBRARIES = R"( )"; // clang-format on -AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDialog) +AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), m_ui(new Ui::AboutDialog) { - ui->setupUi(this); - ui->description->setText(QString(DESCRIPTION).replace("%APPNAME%", QApplication::applicationName())); - ui->contributors->setText(CONTRIBUTORS); - ui->licenses->setText(LIBRARIES); + m_ui->setupUi(this); + m_ui->description->setText(QString(DESCRIPTION).replace("%APPNAME%", QApplication::applicationName())); + m_ui->contributors->setText(CONTRIBUTORS); + m_ui->licenses->setText(LIBRARIES); QFile file(":/REVISION.txt"); file.open(QIODevice::ReadOnly); - ui->about->setText(QString(ABOUT) - .replace("%VERSION%", QApplication::applicationVersion()) - .replace("%REVISION%", file.readAll()) - .replace("%OS%", QSysInfo::prettyProductName()) - .replace("%CPU%", QSysInfo::currentCpuArchitecture()) - .replace("%KERNEL%", QSysInfo::kernelType() + " " + QSysInfo::kernelVersion())); + m_ui->about->setText(QString(ABOUT) + .replace("%VERSION%", QApplication::applicationVersion()) + .replace("%REVISION%", file.readAll()) + .replace("%OS%", QSysInfo::prettyProductName()) + .replace("%CPU%", QSysInfo::currentCpuArchitecture()) + .replace("%KERNEL%", QSysInfo::kernelType() + " " + QSysInfo::kernelVersion())); - connect(ui->ok_button, &QPushButton::clicked, this, &AboutDialog::accept, Qt::QueuedConnection); - connect(ui->clipboard, &QPushButton::clicked, - [this]() { QGuiApplication::clipboard()->setText(ui->about->toPlainText()); }); + connect(m_ui->ok_button, &QPushButton::clicked, this, &AboutDialog::accept, Qt::QueuedConnection); + connect(m_ui->clipboard, &QPushButton::clicked, + [this]() { QGuiApplication::clipboard()->setText(m_ui->about->toPlainText()); }); } AboutDialog::~AboutDialog() { - delete ui; + delete m_ui; } diff --git a/src/gui/aboutdialog.h b/src/gui/aboutdialog.h index 4f3e466..d2fc0ef 100644 --- a/src/gui/aboutdialog.h +++ b/src/gui/aboutdialog.h @@ -33,7 +33,7 @@ class AboutDialog : public QDialog { ~AboutDialog(); private: - Ui::AboutDialog *ui; + Ui::AboutDialog *m_ui; }; #endif // ABOUTDIALOG_H diff --git a/src/gui/aboutdialog.ui b/src/gui/aboutdialog.ui index 238f282..187e683 100644 --- a/src/gui/aboutdialog.ui +++ b/src/gui/aboutdialog.ui @@ -52,7 +52,7 @@ - 0 + 2 true @@ -70,9 +70,6 @@ true - - false - @@ -138,18 +135,15 @@ - - - 100 - 0 - - Close true + + true + diff --git a/src/gui/apiresponse.cpp b/src/gui/apiresponse.cpp index e5f7e91..9e48971 100644 --- a/src/gui/apiresponse.cpp +++ b/src/gui/apiresponse.cpp @@ -19,19 +19,19 @@ #include "apiresponse.h" #include "ui_apiresponse.h" -APIResponse::APIResponse(QByteArray const &res, QWidget *parent) : QDialog(parent), ui(new Ui::APIResponse) +APIResponse::APIResponse(QByteArray const &res, QWidget *parent) : QDialog(parent), m_ui(new Ui::APIResponse) { - ui->setupUi(this); - ui->res->setPlainText(res); + m_ui->setupUi(this); + m_ui->res->setPlainText(res); auto monospaced = QFontDatabase::systemFont(QFontDatabase::FixedFont); monospaced.setLetterSpacing(QFont::PercentageSpacing, 110); - ui->res->setFont(monospaced); + m_ui->res->setFont(monospaced); - connect(ui->ok_button, &QPushButton::clicked, this, &APIResponse::accept, Qt::QueuedConnection); + connect(m_ui->ok_button, &QPushButton::clicked, this, &APIResponse::accept, Qt::QueuedConnection); } APIResponse::~APIResponse() { - delete ui; + delete m_ui; } diff --git a/src/gui/apiresponse.h b/src/gui/apiresponse.h index 88a2cef..d5f6213 100644 --- a/src/gui/apiresponse.h +++ b/src/gui/apiresponse.h @@ -33,7 +33,7 @@ class APIResponse : public QDialog { ~APIResponse(); private: - Ui::APIResponse *ui; + Ui::APIResponse *m_ui; }; #endif // APIRESPONSE_H diff --git a/src/gui/apiresponse.ui b/src/gui/apiresponse.ui index 2cdce51..8d9455f 100644 --- a/src/gui/apiresponse.ui +++ b/src/gui/apiresponse.ui @@ -22,15 +22,12 @@ - - - 100 - 0 - - Close + + true + diff --git a/src/gui/diaryeditor.cpp b/src/gui/diaryeditor.cpp index 6a99cac..b537084 100644 --- a/src/gui/diaryeditor.cpp +++ b/src/gui/diaryeditor.cpp @@ -20,50 +20,79 @@ #include "../core/diaryholder.h" #include "../util/custommessageboxes.h" #include "../util/misc.h" +#include "emotionsreference.h" +#include "gratitudeguide.h" #include "mainwindow.h" +#include "rainguide.h" #include "ui_diaryeditor.h" -DiaryEditor::DiaryEditor(QDate const &date, QWidget *parent) : QWidget(parent), ui(new Ui::DiaryEditor) +DiaryEditor::DiaryEditor(QDate const &date, QWidget *parent) : QWidget(parent), m_ui(new Ui::DiaryEditor) { - ui->setupUi(this); - ui->alert_text->setText(""); - ui->alert_text->update(); + m_ui->setupUi(this); + m_ui->alert_text->setText(""); + m_ui->alert_text->update(); setup_buttons(); - current_month_offset = 0; - current_date = date; - last_entry_snapshot = td::Entry{false, td::Rating::Unknown, "", 0}; + m_current_month_offset = 0; + m_current_date = date; + m_last_entry_snapshot = td::Entry{false, td::Rating::Unknown, "", "", "", 0}; // Ctrl S to save the diary. - save_shortcut = new QShortcut(QKeySequence::Save, this); - save_shortcut->setAutoRepeat(false); + m_save_bind = new QShortcut(QKeySequence::Save, this); + m_save_bind->setAutoRepeat(false); connect( - save_shortcut, &QShortcut::activated, this, [&]() { update_day(false); }, Qt::QueuedConnection); + m_save_bind, &QShortcut::activated, this, [&]() { update_day(false); }, Qt::QueuedConnection); + + // Next and previous day/month shortcuts. + m_next_day_bind = new QShortcut(Qt::Key_Right, this); + m_next_day_bind->setAutoRepeat(true); + connect(m_next_day_bind, &QShortcut::activated, this, &DiaryEditor::next_day, Qt::QueuedConnection); + m_prev_day_bind = new QShortcut(Qt::Key_Left, this); + m_prev_day_bind->setAutoRepeat(true); + connect(m_prev_day_bind, &QShortcut::activated, this, &DiaryEditor::prev_day, Qt::QueuedConnection); + m_next_month_bind = new QShortcut(Qt::Key_Down, this); + m_next_month_bind->setAutoRepeat(true); + connect(m_next_month_bind, &QShortcut::activated, this, &DiaryEditor::next_month, Qt::QueuedConnection); + m_prev_month_bind = new QShortcut(Qt::Key_Up, this); + m_prev_month_bind->setAutoRepeat(true); + connect(m_prev_month_bind, &QShortcut::activated, this, &DiaryEditor::prev_month, Qt::QueuedConnection); // Calendar widget actions // See https://doc.qt.io/qt-5/qcombobox.html#currentIndexChanged for why QOverload is needed. - connect(ui->month_dropdown, QOverload::of(&QComboBox::currentIndexChanged), this, &DiaryEditor::month_changed, + connect(m_ui->month_dropdown, QOverload::of(&QComboBox::currentIndexChanged), this, + &DiaryEditor::month_changed, Qt::QueuedConnection); + connect(m_ui->year_edit, &QDateEdit::dateChanged, this, &DiaryEditor::year_changed, Qt::QueuedConnection); + connect(m_ui->next_month, &QPushButton::clicked, this, &DiaryEditor::next_month, Qt::QueuedConnection); + connect(m_ui->prev_month, &QPushButton::clicked, this, &DiaryEditor::prev_month, Qt::QueuedConnection); + + // Extra reference info buttons + connect(m_ui->emotion_list_button, &QPushButton::clicked, this, &DiaryEditor::emotions_list_button_clicked, + Qt::QueuedConnection); + connect(m_ui->rain_guide_button, &QPushButton::clicked, this, &DiaryEditor::rain_guide_button_clicked, + Qt::QueuedConnection); + connect(m_ui->gratitude_guide_button, &QPushButton::clicked, this, &DiaryEditor::gratitude_guide_button_clicked, Qt::QueuedConnection); - connect(ui->year_edit, &QDateEdit::dateChanged, this, &DiaryEditor::year_changed, Qt::QueuedConnection); - connect(ui->next_month, &QPushButton::clicked, this, &DiaryEditor::next_month, Qt::QueuedConnection); - connect(ui->prev_month, &QPushButton::clicked, this, &DiaryEditor::prev_month, Qt::QueuedConnection); // Info pane actions. connect(MainWindow::instance(), &MainWindow::sig_update_diary, this, &DiaryEditor::update_day); - connect(ui->update_button, &QPushButton::clicked, this, &DiaryEditor::update_day, Qt::QueuedConnection); - connect(ui->delete_button, &QPushButton::clicked, this, &DiaryEditor::delete_day, Qt::QueuedConnection); - connect(ui->reset_button, &QPushButton::clicked, this, &DiaryEditor::reset_day, Qt::QueuedConnection); + connect(m_ui->update_button, &QPushButton::clicked, this, &DiaryEditor::update_day, Qt::QueuedConnection); + connect(m_ui->delete_button, &QPushButton::clicked, this, &DiaryEditor::delete_day, Qt::QueuedConnection); + connect(m_ui->reset_button, &QPushButton::clicked, this, &DiaryEditor::reset_day, Qt::QueuedConnection); // Render current month. - change_month(current_date); + change_month(m_current_date); // The diary editor DOES NOT USE internal_diary_changed. It implements its own change detection system!!! } DiaryEditor::~DiaryEditor() { - delete ui; - delete save_shortcut; + delete m_ui; + delete m_save_bind; + delete m_next_day_bind; + delete m_prev_day_bind; + delete m_next_month_bind; + delete m_prev_month_bind; } void DiaryEditor::setup_buttons() @@ -73,7 +102,7 @@ void DiaryEditor::setup_buttons() auto ptr = new DiaryCalendarButton(td::CalendarButtonData{std::optional(-1), std::optional(false), std::optional(td::Rating::Unknown), std::optional(false), std::optional(false)}); connect(ptr, &DiaryCalendarButton::sig_clicked, this, &DiaryEditor::date_clicked, Qt::QueuedConnection); - ui->dates->addWidget(ptr, row, col, 1, 1, Qt::AlignCenter); + m_ui->dates->addWidget(ptr, row, col, 1, 1, Qt::AlignCenter); } } } @@ -86,13 +115,13 @@ void DiaryEditor::render_month(std::optional const &opt) if (!opt) { // Render the first row. for (int day = 0; day < 7; ++day) { - auto button = qobject_cast(ui->dates->itemAtPosition(0, day)->widget()); + auto button = qobject_cast(m_ui->dates->itemAtPosition(0, day)->widget()); - if (day < current_month_offset) { + if (day < m_current_month_offset) { button->setVisible(false); } else { - auto current_cond = irl_current_day == QDate(current_date.year(), current_date.month(), counter); + auto current_cond = irl_current_day == QDate(m_current_date.year(), m_current_date.month(), counter); button->render(td::CalendarButtonData{std::optional(counter++), std::optional(false), std::optional(td::Rating::Unknown), std::optional(false), std::optional(current_cond)}); button->setVisible(true); @@ -102,13 +131,14 @@ void DiaryEditor::render_month(std::optional const &opt) // Render the rest of the rows. for (int row = 1; row < 6; ++row) { for (int col = 0; col < 7; ++col) { - auto button = qobject_cast(ui->dates->itemAtPosition(row, col)->widget()); + auto button = qobject_cast(m_ui->dates->itemAtPosition(row, col)->widget()); - if (counter > current_date.daysInMonth()) { + if (counter > m_current_date.daysInMonth()) { button->setVisible(false); } else { - auto current_cond = irl_current_day == QDate(current_date.year(), current_date.month(), counter); + auto current_cond = + irl_current_day == QDate(m_current_date.year(), m_current_date.month(), counter); button->render(td::CalendarButtonData{std::optional(counter++), std::optional(false), std::optional(td::Rating::Unknown), std::optional(false), std::optional(current_cond)}); button->setVisible(true); @@ -123,21 +153,21 @@ void DiaryEditor::render_month(std::optional const &opt) // Render the first row. for (int day = 0; day < 7; ++day) { - auto button = qobject_cast(ui->dates->itemAtPosition(0, day)->widget()); + auto button = qobject_cast(m_ui->dates->itemAtPosition(0, day)->widget()); - if (day < current_month_offset) { + if (day < m_current_month_offset) { button->setVisible(false); } else { auto const &entry_iter = monthmap.find(counter); - auto current_cond = irl_current_day == QDate(current_date.year(), current_date.month(), counter); + auto current_cond = irl_current_day == QDate(m_current_date.year(), m_current_date.month(), counter); if (entry_iter == monthmap.end()) { button->render(td::CalendarButtonData{std::optional(counter++), std::optional(false), std::optional(td::Rating::Unknown), std::optional(false), std::optional(current_cond)}); } else { - auto const &[important, rating, dummy, d2] = entry_iter->second; + auto const &[important, rating, dummy, d2, d3, d4] = entry_iter->second; button->render(td::CalendarButtonData{std::optional(counter++), std::optional(important), std::optional(rating), std::optional(false), std::optional(current_cond)}); @@ -150,21 +180,21 @@ void DiaryEditor::render_month(std::optional const &opt) // Render the rest of the rows. for (int row = 1; row < 6; ++row) { for (int col = 0; col < 7; ++col) { - auto button = qobject_cast(ui->dates->itemAtPosition(row, col)->widget()); + auto button = qobject_cast(m_ui->dates->itemAtPosition(row, col)->widget()); - if (counter > current_date.daysInMonth()) { + if (counter > m_current_date.daysInMonth()) { button->setVisible(false); } else { auto const &entry_iter = monthmap.find(counter); - auto current_cond = irl_current_day == QDate(current_date.year(), current_date.month(), counter); + auto current_cond = irl_current_day == QDate(m_current_date.year(), m_current_date.month(), counter); if (entry_iter == monthmap.end()) { button->render(td::CalendarButtonData{std::optional(counter++), std::optional(false), std::optional(td::Rating::Unknown), std::optional(false), std::optional(current_cond)}); } else { - auto const &[important, rating, dummy, d2] = entry_iter->second; + auto const &[important, rating, dummy, d2, d3, d4] = entry_iter->second; button->render(td::CalendarButtonData{std::optional(counter++), std::optional(important), std::optional(rating), std::optional(false), std::optional(current_cond)}); @@ -175,16 +205,18 @@ void DiaryEditor::render_month(std::optional const &opt) } } - qDebug() << "Rendered month for current date:" << current_date; + qDebug() << "Rendered month for current date:" << m_current_date; } // Returns true if equal, false if not equal. bool DiaryEditor::compare_snapshots() { // Doesn't compare last edited timestamps. - return last_entry_snapshot.important == ui->special_box->isChecked() && - last_entry_snapshot.rating == static_cast(ui->rating_dropdown->currentIndex()) && - last_entry_snapshot.message == ui->entry_edit->toPlainText().toStdString(); + return m_last_entry_snapshot.important == m_ui->special_box->isChecked() && + m_last_entry_snapshot.rating == static_cast(m_ui->rating_dropdown->currentIndex()) && + m_last_entry_snapshot.general_message == m_ui->general_message->toPlainText().toStdString() && + m_last_entry_snapshot.emotions_message == m_ui->emotions_message->toPlainText().toStdString() && + m_last_entry_snapshot.gratitude_message == m_ui->gratitude_message->toPlainText().toStdString(); } void DiaryEditor::change_month(QDate const &date) @@ -196,20 +228,17 @@ void DiaryEditor::change_month(QDate const &date) if (QMessageBox::Save == res && !update_day()) return; - current_date = date; + m_current_date = date; QDate const first_day(date.year(), date.month(), 1); // dayOfWeek() returns a number from 1 to 7. - current_month_offset = first_day.dayOfWeek() - 1; + m_current_month_offset = first_day.dayOfWeek() - 1; // Set the calendar widget UI (not the info pane). - ui->month_dropdown->blockSignals(true); - ui->year_edit->blockSignals(true); + const QSignalBlocker b1(m_ui->month_dropdown); + const QSignalBlocker b2(m_ui->year_edit); - ui->month_dropdown->setCurrentIndex(date.month() - 1); - ui->year_edit->setDate(date); - - ui->month_dropdown->blockSignals(false); - ui->year_edit->blockSignals(false); + m_ui->month_dropdown->setCurrentIndex(date.month() - 1); + m_ui->year_edit->setDate(date); // Render current month. render_month(DiaryHolder::instance()->get_monthmap(date)); @@ -233,31 +262,36 @@ void DiaryEditor::change_month(QDate const &date) void DiaryEditor::render_day(td::CalendarButtonData const &d, bool const set_info_pane) { // Get x, y coords of button from 1-42. - int const x = (*d.day + current_month_offset - 1) % 7; - int const y = static_cast((*d.day + current_month_offset - 1) / 7); - - qobject_cast(ui->dates->itemAtPosition(y, x)->widget())->render(d); + int const x = (*d.day + m_current_month_offset - 1) % 7; + int const y = static_cast((*d.day + m_current_month_offset - 1) / 7); - if (!set_info_pane) - return; + auto button_ptr = qobject_cast(m_ui->dates->itemAtPosition(y, x)->widget()); + button_ptr->render(d); - auto const &new_date = QDate(current_date.year(), current_date.month(), *d.day); - auto const &opt = DiaryHolder::instance()->get_entry(new_date); + if (set_info_pane) { + auto const &new_date = QDate(m_current_date.year(), m_current_date.month(), *d.day); + auto const &opt = DiaryHolder::instance()->get_entry(new_date); - if (opt) { - last_entry_snapshot = (*opt)->second; - update_info_pane(new_date, (*opt)->second); - } - else { - auto default_entry = td::Entry{false, td::Rating::Unknown, "", 0}; - last_entry_snapshot = default_entry; - update_info_pane(new_date, default_entry); + if (opt) { + m_last_entry_snapshot = (*opt)->second; + update_info_pane(new_date, (*opt)->second); + } + else { + auto default_entry = td::Entry{false, td::Rating::Unknown, "", "", "", 0}; + m_last_entry_snapshot = default_entry; + update_info_pane(new_date, default_entry); + } } + + // Unfortunately this doesn't work for some reason + // TODO find a fix, although this is low priority + // button_ptr->activateWindow(); + // button_ptr->setFocus(Qt::OtherFocusReason); } void DiaryEditor::next_month() { - QDate &&next = current_date.addMonths(1); + QDate &&next = m_current_date.addMonths(1); next.setDate(next.year(), next.month(), 1); if (next.isValid()) change_month(next); @@ -265,7 +299,7 @@ void DiaryEditor::next_month() void DiaryEditor::prev_month() { - QDate &&prev = current_date.addMonths(-1); + QDate &&prev = m_current_date.addMonths(-1); prev.setDate(prev.year(), prev.month(), 1); if (prev.isValid()) change_month(prev); @@ -273,7 +307,7 @@ void DiaryEditor::prev_month() void DiaryEditor::month_changed(int const month) { - change_month(QDate(ui->year_edit->date().year(), month + 1, 1)); + change_month(QDate(m_ui->year_edit->date().year(), month + 1, 1)); } void DiaryEditor::year_changed(QDate const &date) @@ -285,11 +319,11 @@ void DiaryEditor::year_changed(QDate const &date) // Triggered when a calendar button is clicked. void DiaryEditor::date_clicked(int const day) { - ui->alert_text->setText(""); - ui->alert_text->update(); + m_ui->alert_text->setText(""); + m_ui->alert_text->update(); // Don't respond to spam clicks on same button. - if (day == current_date.day()) + if (day == m_current_date.day()) return; auto cb = [this, day](int const res) { @@ -300,7 +334,7 @@ void DiaryEditor::date_clicked(int const day) return; td::CalendarButtonData const old{ - std::optional(current_date.day()), std::nullopt, std::nullopt, std::optional(false), std::nullopt}; + std::optional(m_current_date.day()), std::nullopt, std::nullopt, std::optional(false), std::nullopt}; td::CalendarButtonData const n{ std::optional(day), std::nullopt, std::nullopt, std::optional(true), std::nullopt}; // Remove selected border from old calendar button. @@ -308,7 +342,7 @@ void DiaryEditor::date_clicked(int const day) // Add selected border to new calendar button. render_day(n, true); - current_date = QDate(current_date.year(), current_date.month(), day); + m_current_date = QDate(m_current_date.year(), m_current_date.month(), day); }; if (!compare_snapshots()) @@ -319,37 +353,35 @@ void DiaryEditor::date_clicked(int const day) void DiaryEditor::update_info_pane(QDate const &date, td::Entry const &entry) { - ui->date_label->setText(QString("%1 %2%3 %4") - .arg(date.toString("dddd"), QString::number(date.day()), - misc::get_day_suffix(date.day()), date.toString("MMMM"))); - ui->date_label->update(); - - ui->rating_dropdown->blockSignals(true); - ui->special_box->blockSignals(true); - ui->entry_edit->blockSignals(true); + m_ui->date_label->setText(QString("%1 %2%3 %4") + .arg(date.toString("dddd"), QString::number(date.day()), + misc::get_day_suffix(date.day()), date.toString("MMMM"))); + m_ui->date_label->update(); if (0 == entry.last_updated) { - ui->last_edited->setText(""); - ui->last_edited->setToolTip("Never edited before."); + m_ui->last_edited->setText(""); + m_ui->last_edited->setToolTip("Never edited before."); } else { QDateTime last_edited; last_edited.setTime_t(entry.last_updated); // Thanks stackoverflow ;) - ui->last_edited->setText("Last edited " + last_edited.toString("dd MMM ''yy 'at' h:mm ap")); - ui->last_edited->setToolTip( + m_ui->last_edited->setText("Last edited " + last_edited.toString("dd MMM ''yy 'at' h:mm ap")); + m_ui->last_edited->setToolTip( last_edited.toString("dddd MMMM d%1 yyyy 'at' h:mm:ss ap").arg(misc::get_day_suffix(date.day()))); } - ui->last_edited->update(); - ui->rating_dropdown->setCurrentIndex(static_cast(entry.rating)); - ui->special_box->setChecked(entry.important); - ui->entry_edit->setPlainText(entry.message.data()); - // ui->entry_edit->setPlainText("PLACEHOLDER"); + const QSignalBlocker b1(m_ui->rating_dropdown); + const QSignalBlocker b2(m_ui->special_box); + const QSignalBlocker b3(m_ui->general_message); + const QSignalBlocker b4(m_ui->emotions_message); + const QSignalBlocker b5(m_ui->gratitude_message); - ui->rating_dropdown->blockSignals(false); - ui->special_box->blockSignals(false); - ui->entry_edit->blockSignals(false); + m_ui->rating_dropdown->setCurrentIndex(static_cast(entry.rating)); + m_ui->special_box->setChecked(entry.important); + m_ui->general_message->setPlainText(entry.general_message.data()); + m_ui->emotions_message->setPlainText(entry.emotions_message.data()); + m_ui->gratitude_message->setPlainText(entry.gratitude_message.data()); qDebug() << "Updated info pane:" << date; } @@ -362,10 +394,11 @@ bool DiaryEditor::update_day(bool const suppress_error) AppBusyLock lock; // Add the entry to the in memory map. - td::Entry const e{ui->special_box->isChecked(), static_cast(ui->rating_dropdown->currentIndex()), - ui->entry_edit->toPlainText().toStdString(), QDateTime::currentSecsSinceEpoch()}; + td::Entry const e{m_ui->special_box->isChecked(), static_cast(m_ui->rating_dropdown->currentIndex()), + m_ui->general_message->toPlainText().toStdString(), m_ui->emotions_message->toPlainText().toStdString(), + m_ui->gratitude_message->toPlainText().toStdString(), QDateTime::currentSecsSinceEpoch()}; - DiaryHolder::instance()->create_entry(current_date, e); + DiaryHolder::instance()->create_entry(m_current_date, e); // Actually try and save the diary. if (!DiaryHolder::instance()->save() && suppress_error) { @@ -373,25 +406,26 @@ bool DiaryEditor::update_day(bool const suppress_error) return false; } - td::CalendarButtonData const d{std::optional(current_date.day()), std::optional(ui->special_box->isChecked()), - std::optional(static_cast(ui->rating_dropdown->currentIndex())), std::optional(true), std::nullopt}; + td::CalendarButtonData const d{std::optional(m_current_date.day()), std::optional(m_ui->special_box->isChecked()), + std::optional(static_cast(m_ui->rating_dropdown->currentIndex())), std::optional(true), + std::nullopt}; // This updates the day button in the calendar widget. render_day(d, false); - last_entry_snapshot = e; + m_last_entry_snapshot = e; // The last edited field is the only one that needs updating in this instance. QDateTime last_edited; last_edited.setTime_t(e.last_updated); // Thanks stackoverflow ;) - ui->last_edited->setText("Last edited " + last_edited.toString("dd MMM ''yy 'at' h:mm ap")); - ui->last_edited->setToolTip( - last_edited.toString("dddd MMMM d%1 yyyy 'at' h:mm:ss ap").arg(misc::get_day_suffix(current_date.day()))); - ui->last_edited->update(); - ui->alert_text->setText("Updated entry."); - ui->alert_text->update(); - - InternalManager::instance()->update_data(current_date); - qDebug() << "Updated entry and broadcasted update_data:" << current_date; + m_ui->last_edited->setText("Last edited " + last_edited.toString("dd MMM ''yy 'at' h:mm ap")); + m_ui->last_edited->setToolTip( + last_edited.toString("dddd MMMM d%1 yyyy 'at' h:mm:ss ap").arg(misc::get_day_suffix(m_current_date.day()))); + m_ui->last_edited->update(); + m_ui->alert_text->setText("Updated entry."); + m_ui->alert_text->update(); + + InternalManager::instance()->update_data(m_current_date); + qDebug() << "Updated entry and broadcasted update_data:" << m_current_date; return true; } @@ -404,24 +438,24 @@ void DiaryEditor::delete_day() AppBusyLock lock; // Remove the entry from the in memory map. - DiaryHolder::instance()->delete_entry(current_date); + DiaryHolder::instance()->delete_entry(m_current_date); // Actually try and save the diary. if (!DiaryHolder::instance()->save()) return cmb::display_local_diary_save_error(this); - ui->alert_text->setText("Deleted entry."); - ui->alert_text->update(); + m_ui->alert_text->setText("Deleted entry."); + m_ui->alert_text->update(); - render_day(td::CalendarButtonData{std::optional(current_date.day()), std::optional(false), + render_day(td::CalendarButtonData{std::optional(m_current_date.day()), std::optional(false), std::optional(td::Rating::Unknown), std::optional(true), std::nullopt}, false); - auto empty = td::Entry{false, td::Rating::Unknown, "", 0}; - update_info_pane(current_date, empty); - last_entry_snapshot = empty; + auto empty = td::Entry{false, td::Rating::Unknown, "", "", "", 0}; + update_info_pane(m_current_date, empty); + m_last_entry_snapshot = empty; - InternalManager::instance()->update_data(current_date); - qDebug() << "Deleted entry and broadcasted update_data:" << current_date; + InternalManager::instance()->update_data(m_current_date); + qDebug() << "Deleted entry and broadcasted update_data:" << m_current_date; }; // Shift click bypasses confirmation dialog. @@ -443,3 +477,56 @@ void DiaryEditor::reset_day() auto current_date = QDate::currentDate(); change_month(current_date); } + +void DiaryEditor::emotions_list_button_clicked() +{ + auto new_window = new EmotionsReference(); + new_window->setAttribute(Qt::WA_DeleteOnClose); + new_window->show(); +} + +void DiaryEditor::rain_guide_button_clicked() +{ + auto new_window = new RAINGuide(); + new_window->setAttribute(Qt::WA_DeleteOnClose); + new_window->show(); +} + +void DiaryEditor::gratitude_guide_button_clicked() +{ + auto new_window = new GratitudeGuide(); + new_window->setAttribute(Qt::WA_DeleteOnClose); + new_window->show(); +} + +void DiaryEditor::next_day() +{ + if (nullptr == qobject_cast(QApplication::focusWidget())) + return; + + if (m_current_date.daysInMonth() == m_current_date.day()) { + QDate &&next = m_current_date.addMonths(1); + next.setDate(next.year(), next.month(), 1); + if (next.isValid()) + change_month(next); + } + else { + date_clicked(m_current_date.day() + 1); + } +} + +void DiaryEditor::prev_day() +{ + if (nullptr == qobject_cast(QApplication::focusWidget())) + return; + + if (1 == m_current_date.day()) { + QDate &&prev = m_current_date.addMonths(-1); + prev.setDate(prev.year(), prev.month(), prev.daysInMonth()); + if (prev.isValid()) + change_month(prev); + } + else { + date_clicked(m_current_date.day() - 1); + } +} diff --git a/src/gui/diaryeditor.h b/src/gui/diaryeditor.h index 581daa5..8c10b30 100644 --- a/src/gui/diaryeditor.h +++ b/src/gui/diaryeditor.h @@ -37,11 +37,15 @@ class DiaryEditor : public QWidget { explicit DiaryEditor(QDate const &date, QWidget *parent = nullptr); ~DiaryEditor(); - QDate current_date; - int current_month_offset; - QShortcut *save_shortcut; + QDate m_current_date; + int m_current_month_offset; + QShortcut *m_save_bind; + QShortcut *m_next_day_bind; + QShortcut *m_prev_day_bind; + QShortcut *m_next_month_bind; + QShortcut *m_prev_month_bind; // Saves the state of the entry when it was first loaded. Used to decide if the save prompt needs showing. - td::Entry last_entry_snapshot; + td::Entry m_last_entry_snapshot; public slots: // Calendar widget. @@ -54,6 +58,13 @@ public slots: void month_changed(int const month); void year_changed(QDate const &date); void date_clicked(int const day); + void next_day(); + void prev_day(); + + // Reference info. + void emotions_list_button_clicked(); + void rain_guide_button_clicked(); + void gratitude_guide_button_clicked(); // Info pane. void update_info_pane(QDate const &date, td::Entry const &entry); @@ -62,7 +73,7 @@ public slots: void reset_day(); private: - Ui::DiaryEditor *ui; + Ui::DiaryEditor *m_ui; bool compare_snapshots(); }; diff --git a/src/gui/diaryeditor.ui b/src/gui/diaryeditor.ui index 435c789..7119f3d 100644 --- a/src/gui/diaryeditor.ui +++ b/src/gui/diaryeditor.ui @@ -64,76 +64,12 @@ 10 - - - - 8 + + + + Rating - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 100 - 0 - - - - Jump to today's entry. - - - Jump to today - - - - - - - - 100 - 0 - - - - Permanently delete the entry. - - - Delete - - - - - - - - 100 - 0 - - - - Update the entry and write the diary to the file system. - - - Update - - - true - - - - + @@ -145,21 +81,20 @@ - - + + + + + 9 + + - Entry + Placeholder text - - - 120 - 0 - - Determines the colour associated with this entry. @@ -195,255 +130,252 @@ - - - - - 9 - - - - Placeholder text - - - - - - - Message for this entry. - - - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Rating - - - - - - - - - 10 - - - - - - 24 - - - - Date placeholder - - - - - - - - 9 - - - - Last edited placeholder - - - - - - - - - - - 0 - - - 0 - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 15 - - - - - - - - 0 - - - - - - - 0 - - - - - - 50 - 0 - - - - - 16 - - - - Sun - - - Qt::AlignCenter - - - - - - - - 50 - 0 - - - - - 16 - - - - Thu - - - Qt::AlignCenter - - - - - - - - 50 - 0 - - - - - 16 - - - - Tue - - - Qt::AlignCenter - - - - - - - - 50 - 0 - - - - - 16 - - + + - Wed - - - Qt::AlignCenter + Entry - - - - - 50 - 0 - - - - - 16 - - - - Fri - - - Qt::AlignCenter + + + + 8 + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Jump to today's entry. + + + Jump to today + + + true + + + + + + + Permanently delete the entry. + + + Delete + + + true + + + + + + + Update the entry and write the diary to the file system. + + + Update + + + true + + + + + + + + + 0 + + + true + + + + General + + + + + + Message for this entry. + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + Write down things of significance and/or interest... + + + + + + + + Feelings and emotions + + + + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + Write down all the emotions you felt today... + + + + + + + + + Guide for managing emotions. + + + RAIN guide + + + true + + + + + + + List of emotions in case you have trouble describing any. + + + Reference table + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Gratitude + + + + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + Write down anything you're grateful for... + + + + + + + + + Guide on how to feel happier. + + + Guide + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + - - - - - 50 - 0 - - + + + + + + 10 + + + - 16 + 24 - Sat - - - Qt::AlignCenter + Date placeholder - - - - - 50 - 0 - - + + - 16 + 9 - Mon - - - Qt::AlignCenter + Last edited placeholder + + + + + + 0 + + + 0 + @@ -496,6 +428,9 @@ > + + true + @@ -517,6 +452,9 @@ < + + true + @@ -641,8 +579,8 @@ - - + + Qt::Vertical @@ -651,12 +589,166 @@ - 15 - 0 + 20 + 15 + + + + 0 + + + + + + 50 + 0 + + + + + 16 + + + + Sun + + + Qt::AlignCenter + + + + + + + + 50 + 0 + + + + + 16 + + + + Thu + + + Qt::AlignCenter + + + + + + + + 50 + 0 + + + + + 16 + + + + Tue + + + Qt::AlignCenter + + + + + + + + 50 + 0 + + + + + 16 + + + + Wed + + + Qt::AlignCenter + + + + + + + + 50 + 0 + + + + + 16 + + + + Fri + + + Qt::AlignCenter + + + + + + + + 50 + 0 + + + + + 16 + + + + Sat + + + Qt::AlignCenter + + + + + + + + 50 + 0 + + + + + 16 + + + + Mon + + + Qt::AlignCenter + + + + + @@ -673,6 +765,13 @@ + + + + 0 + + + @@ -686,6 +785,22 @@ + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 15 + 0 + + + + @@ -695,10 +810,18 @@ month_dropdown year_edit next_month - entry_edit update_button delete_button reset_button + rating_dropdown + special_box + entry_messages_widget + general_message + emotions_message + emotion_list_button + rain_guide_button + gratitude_message + gratitude_guide_button diff --git a/src/gui/diaryentryviewer.cpp b/src/gui/diaryentryviewer.cpp index 7bce78d..f37b62e 100644 --- a/src/gui/diaryentryviewer.cpp +++ b/src/gui/diaryentryviewer.cpp @@ -49,16 +49,24 @@ const QString HR_ROW(R"( char const *TABLE_END = ""; -DiaryEntryViewer::DiaryEntryViewer(QWidget *parent) : QWidget(parent), ui(new Ui::DiaryEntryViewer) +DiaryEntryViewer::DiaryEntryViewer(QWidget *parent) : QWidget(parent), m_ui(new Ui::DiaryEntryViewer) { - ui->setupUi(this); + m_ui->setupUi(this); // Navigator slots - connect(ui->month_dropdown, QOverload::of(&QComboBox::currentIndexChanged), this, + connect(m_ui->month_dropdown, QOverload::of(&QComboBox::currentIndexChanged), this, &DiaryEntryViewer::month_changed, Qt::QueuedConnection); - connect(ui->year_edit, &QDateEdit::dateChanged, this, &DiaryEntryViewer::year_changed, Qt::QueuedConnection); - connect(ui->next_month, &QPushButton::clicked, this, &DiaryEntryViewer::next_month, Qt::QueuedConnection); - connect(ui->prev_month, &QPushButton::clicked, this, &DiaryEntryViewer::prev_month, Qt::QueuedConnection); + connect(m_ui->year_edit, &QDateEdit::dateChanged, this, &DiaryEntryViewer::year_changed, Qt::QueuedConnection); + connect(m_ui->next_month, &QPushButton::clicked, this, &DiaryEntryViewer::next_month, Qt::QueuedConnection); + connect(m_ui->prev_month, &QPushButton::clicked, this, &DiaryEntryViewer::prev_month, Qt::QueuedConnection); + + // Next/prev month keyboard shortcuts + m_next_month_bind = new QShortcut(Qt::Key_Down, this); + m_next_month_bind->setAutoRepeat(true); + connect(m_next_month_bind, &QShortcut::activated, this, &DiaryEntryViewer::next_month, Qt::QueuedConnection); + m_prev_month_bind = new QShortcut(Qt::Key_Up, this); + m_prev_month_bind->setAutoRepeat(true); + connect(m_prev_month_bind, &QShortcut::activated, this, &DiaryEntryViewer::prev_month, Qt::QueuedConnection); connect(InternalManager::instance(), &InternalManager::update_data, this, &DiaryEntryViewer::change_month, Qt::QueuedConnection); @@ -70,7 +78,9 @@ DiaryEntryViewer::DiaryEntryViewer(QWidget *parent) : QWidget(parent), ui(new Ui DiaryEntryViewer::~DiaryEntryViewer() { - delete ui; + delete m_ui; + delete m_next_month_bind; + delete m_prev_month_bind; } void DiaryEntryViewer::update_theme() @@ -83,36 +93,33 @@ void DiaryEntryViewer::change_month(QDate const &date) qDebug() << "Changed diary entry viewer month:" << date; // Update the selector UI. - ui->month_dropdown->blockSignals(true); - ui->year_edit->blockSignals(true); + const QSignalBlocker b1(m_ui->month_dropdown); + const QSignalBlocker b2(m_ui->year_edit); if (date.isValid()) { - ui->month_dropdown->setCurrentIndex(date.month() - 1); - ui->year_edit->setDate(date); + m_ui->month_dropdown->setCurrentIndex(date.month() - 1); + m_ui->year_edit->setDate(date); } else { - ui->month_dropdown->setCurrentIndex(current_date.month() - 1); - ui->year_edit->setDate(current_date); + m_ui->month_dropdown->setCurrentIndex(m_current_date.month() - 1); + m_ui->year_edit->setDate(m_current_date); } - ui->month_dropdown->blockSignals(false); - ui->year_edit->blockSignals(false); - - auto const &opt = DiaryHolder::instance()->get_monthmap(date.isValid() ? date : current_date); + auto const &opt = DiaryHolder::instance()->get_monthmap(date.isValid() ? date : m_current_date); if (!opt) - return ui->entry_edit->setText(PLACEHOLDER_TEXT); + return m_ui->entry_edit->setText(PLACEHOLDER_TEXT); QString html(TABLE_START); auto row_counter = 0; for (auto const &i : (*opt)->second) { - auto const &[important, rating, message, le] = i.second; + auto const &[important, rating, general_message, dummy, d2, le] = i.second; - // Don't add any days that don't have text entries. - if (message.empty()) + // Don't add any days that don't have general_message's. + if (general_message.empty()) continue; - auto copy = message; + auto copy = general_message; QDateTime last_edited; last_edited.setTime_t(le); @@ -134,40 +141,40 @@ void DiaryEntryViewer::change_month(QDate const &date) } if (0 == row_counter) { - return ui->entry_edit->setText(PLACEHOLDER_TEXT); + return m_ui->entry_edit->setText(PLACEHOLDER_TEXT); } else { html.chop(HR_ROW.size()); html.append(TABLE_END); - ui->entry_edit->setText(html); + m_ui->entry_edit->setText(html); } - current_date = date; + m_current_date = date; } void DiaryEntryViewer::next_month() { - QDate const next = ui->year_edit->date().addMonths(1); + QDate const next = m_ui->year_edit->date().addMonths(1); if (next.isValid()) change_month(next); } void DiaryEntryViewer::prev_month() { - QDate const prev = ui->year_edit->date().addMonths(-1); + QDate const prev = m_ui->year_edit->date().addMonths(-1); if (prev.isValid()) change_month(prev); } void DiaryEntryViewer::month_changed(int) { - change_month(QDate(ui->year_edit->date().year(), ui->month_dropdown->currentIndex() + 1, 1)); + change_month(QDate(m_ui->year_edit->date().year(), m_ui->month_dropdown->currentIndex() + 1, 1)); } void DiaryEntryViewer::year_changed(QDate const &date) { if (date.isValid()) - change_month(QDate(ui->year_edit->date().year(), ui->month_dropdown->currentIndex() + 1, 1)); + change_month(QDate(m_ui->year_edit->date().year(), m_ui->month_dropdown->currentIndex() + 1, 1)); } QByteArray DiaryEntryViewer::generate_base64_icon(int const day, td::Rating const rating, bool const important) diff --git a/src/gui/diaryentryviewer.h b/src/gui/diaryentryviewer.h index 4b492e8..ad24b6e 100644 --- a/src/gui/diaryentryviewer.h +++ b/src/gui/diaryentryviewer.h @@ -39,7 +39,7 @@ class DiaryEntryViewer : public QWidget { explicit DiaryEntryViewer(QWidget *parent = nullptr); ~DiaryEntryViewer(); - QDate current_date; + QDate m_current_date; public slots: void update_theme(); @@ -50,7 +50,10 @@ public slots: void year_changed(QDate const &date); private: - Ui::DiaryEntryViewer *ui; + Ui::DiaryEntryViewer *m_ui; + + QShortcut *m_next_month_bind; + QShortcut *m_prev_month_bind; QByteArray generate_base64_icon(int const day, td::Rating const rating, bool const important); QPixmap generate_background(td::Rating const rating); diff --git a/src/gui/diaryentryviewer.ui b/src/gui/diaryentryviewer.ui index f492d9b..9ecd7b7 100644 --- a/src/gui/diaryentryviewer.ui +++ b/src/gui/diaryentryviewer.ui @@ -56,6 +56,9 @@ > + + true + @@ -89,6 +92,9 @@ < + + true + diff --git a/src/gui/diarymenu.cpp b/src/gui/diarymenu.cpp index fa0dbbf..d0051a4 100644 --- a/src/gui/diarymenu.cpp +++ b/src/gui/diarymenu.cpp @@ -24,30 +24,30 @@ #include "optionsmenu.h" #include "ui_diarymenu.h" -DiaryMenu::DiaryMenu(QWidget *parent) : QWidget(parent), ui(new Ui::DiaryMenu) +DiaryMenu::DiaryMenu(QWidget *parent) : QWidget(parent), m_ui(new Ui::DiaryMenu) { - ui->setupUi(this); + m_ui->setupUi(this); auto date = QDate::currentDate(); AppBusyLock lock; - ui->entries->layout()->addWidget(new DiaryEntryViewer(this)); - ui->statistics->layout()->addWidget(new DiaryStats(this)); - ui->pixels->layout()->addWidget(new DiaryPixels(this)); + m_ui->entries->layout()->addWidget(new DiaryEntryViewer(this)); + m_ui->statistics->layout()->addWidget(new DiaryStats(this)); + m_ui->pixels->layout()->addWidget(new DiaryPixels(this)); // DiaryEditor has to be initialised last because it tells all the other widgets to update. - ui->editor->layout()->addWidget(new DiaryEditor(date, this)); - ui->settings_tab->layout()->addWidget(new OptionsMenu(true, this)); + m_ui->editor->layout()->addWidget(new DiaryEditor(date, this)); + m_ui->settings_tab->layout()->addWidget(new OptionsMenu(true, this)); - connect(ui->diary_menu_tab, &QTabWidget::currentChanged, this, &DiaryMenu::tab_changed, Qt::QueuedConnection); + connect(m_ui->diary_menu_tab, &QTabWidget::currentChanged, this, &DiaryMenu::tab_changed, Qt::QueuedConnection); } DiaryMenu::~DiaryMenu() { - delete ui; + delete m_ui; } void DiaryMenu::tab_changed(int const) { - qDebug() << "Switched to tab:" << ui->diary_menu_tab->tabText(ui->diary_menu_tab->currentIndex()); + qDebug() << "Switched to tab:" << m_ui->diary_menu_tab->tabText(m_ui->diary_menu_tab->currentIndex()); } diff --git a/src/gui/diarymenu.h b/src/gui/diarymenu.h index 0121fa8..ef8004c 100644 --- a/src/gui/diarymenu.h +++ b/src/gui/diarymenu.h @@ -36,7 +36,7 @@ public slots: void tab_changed(int const); private: - Ui::DiaryMenu *ui; + Ui::DiaryMenu *m_ui; }; #endif // DIARYMENU_H diff --git a/src/gui/diarypixels.cpp b/src/gui/diarypixels.cpp index 79ea5bc..bf4483b 100644 --- a/src/gui/diarypixels.cpp +++ b/src/gui/diarypixels.cpp @@ -26,22 +26,22 @@ char const *MONTH_LETTERS = "JFMAMJJASOND"; int const LABEL_SIZE = 36; -DiaryPixels::DiaryPixels(QWidget *parent) : QWidget(parent), ui(new Ui::DiaryPixels) +DiaryPixels::DiaryPixels(QWidget *parent) : QWidget(parent), m_ui(new Ui::DiaryPixels) { - ui->setupUi(this); + m_ui->setupUi(this); setup_grid(); - ui->year_edit->setDate(QDate::currentDate()); + m_ui->year_edit->setDate(QDate::currentDate()); connect(InternalManager::instance(), &InternalManager::update_data, this, &DiaryPixels::render_grid, Qt::QueuedConnection); - connect(ui->year_edit, &QDateEdit::dateChanged, this, &DiaryPixels::render_grid, Qt::QueuedConnection); - connect(ui->export_img_button, &QPushButton::clicked, this, &DiaryPixels::export_image, Qt::QueuedConnection); + connect(m_ui->year_edit, &QDateEdit::dateChanged, this, &DiaryPixels::render_grid, Qt::QueuedConnection); + connect(m_ui->export_img_button, &QPushButton::clicked, this, &DiaryPixels::export_image, Qt::QueuedConnection); // current_date is initialised by &InternalManager::change_month signal. } DiaryPixels::~DiaryPixels() { - delete ui; + delete m_ui; } int DiaryPixels::calculate_size() @@ -53,15 +53,15 @@ int DiaryPixels::calculate_size() updateGeometry(); int gap = 0; - int w = ui->hidden_frame->width() - 18; // - 18 because the hidden_frame has margins of 9px on all sides. - int h = ui->hidden_frame->height() - 18; + int w = m_ui->hidden_frame->width() - 18; // - 18 because the hidden_frame has margins of 9px on all sides. + int h = m_ui->hidden_frame->height() - 18; int top = std::max({w, h, 1218}); // For every 500px width/height, increase gap by 1px. while ((top -= 500) > -1) gap++; - ui->grid->setSpacing(gap); + m_ui->grid->setSpacing(gap); // This approach is not entirely ideal but it's the most read friendly since there are no calculations of ratios and // all that stuff. @@ -81,7 +81,7 @@ int DiaryPixels::calculate_size() void DiaryPixels::render_button_clicked() { - render_grid(ui->year_edit->date()); + render_grid(m_ui->year_edit->date()); } void DiaryPixels::setup_grid() @@ -97,13 +97,13 @@ void DiaryPixels::setup_grid() label->setFixedHeight(LABEL_SIZE); label->setFixedWidth(LABEL_SIZE); label->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); - ui->grid->addWidget(label, month - 1, 0); + m_ui->grid->addWidget(label, month - 1, 0); for (int day = 1; day < 32; ++day) { auto ptr = new DiaryPixelLabel(td::Rating::Unknown, false, month, day, size, this); connect(this, &DiaryPixels::sig_changed_size, ptr, &DiaryPixelLabel::resize_slot, Qt::QueuedConnection); - ui->grid->addWidget(ptr, month - 1, day); + m_ui->grid->addWidget(ptr, month - 1, day); } } @@ -112,26 +112,26 @@ void DiaryPixels::setup_grid() void DiaryPixels::render_grid(QDate const &new_date) { - current_date = new_date; - ui->year_edit->blockSignals(true); - ui->year_edit->setDate(new_date); - ui->year_edit->blockSignals(false); - auto const &opt = DiaryHolder::instance()->get_yearmap(current_date); + const QSignalBlocker b1(m_ui->year_edit); + m_current_date = new_date; + m_ui->year_edit->setDate(new_date); + + auto const &opt = DiaryHolder::instance()->get_yearmap(m_current_date); for (int month = 1; month < 13; ++month) { - int days = QDate(current_date.year(), month, 1).daysInMonth(); + int days = QDate(m_current_date.year(), month, 1).daysInMonth(); auto placeholder = [this, month, days]() { for (int day = 1; day < 32; ++day) { - auto pixel = qobject_cast(ui->grid->itemAtPosition(month - 1, day)->widget()); + auto pixel = qobject_cast(m_ui->grid->itemAtPosition(month - 1, day)->widget()); if (day > days) pixel->setVisible(false); else pixel->setVisible(true); - pixel->rating = td::Rating::Unknown; - pixel->special = false; + pixel->m_rating = td::Rating::Unknown; + pixel->m_special = false; pixel->update(); } }; @@ -147,7 +147,7 @@ void DiaryPixels::render_grid(QDate const &new_date) auto const &entrymap = iter->second; for (int day = 1; day < 32; ++day) { - auto pixel = qobject_cast(ui->grid->itemAtPosition(month - 1, day)->widget()); + auto pixel = qobject_cast(m_ui->grid->itemAtPosition(month - 1, day)->widget()); auto const &iter2 = entrymap.find(day); if (day > days) @@ -156,13 +156,13 @@ void DiaryPixels::render_grid(QDate const &new_date) pixel->setVisible(true); if (iter2 == entrymap.end()) { - pixel->rating = td::Rating::Unknown; - pixel->special = false; + pixel->m_rating = td::Rating::Unknown; + pixel->m_special = false; } else { - auto const &[important, rating, dummy, d2] = iter2->second; - pixel->rating = rating; - pixel->special = important; + auto const &[important, rating, dummy, d2, d3, d4] = iter2->second; + pixel->m_rating = rating; + pixel->m_special = important; } pixel->update(); @@ -174,12 +174,12 @@ void DiaryPixels::render_grid(QDate const &new_date) } } - qDebug() << "Updated pixels grid" << current_date; + qDebug() << "Updated pixels grid" << m_current_date; } void DiaryPixels::export_image() { - auto year = QString::number(ui->year_edit->date().year()); + auto year = QString::number(m_ui->year_edit->date().year()); auto const &filename = QFileDialog::getSaveFileName( this, "Export image", QString("%1/%2.png").arg(QDir::homePath(), year), "Images (*.png);;All files"); @@ -189,8 +189,8 @@ void DiaryPixels::export_image() AppBusyLock lock; QPixmap pixmap; - if (ui->add_year_checkbox->isChecked()) { - auto frame = ui->hidden_frame->grab(); + if (m_ui->add_year_checkbox->isChecked()) { + auto frame = m_ui->hidden_frame->grab(); pixmap = QPixmap(frame.size().width(), frame.size().height() + 50); pixmap.fill(frame.toImage().pixel(0, 0)); @@ -211,7 +211,7 @@ void DiaryPixels::export_image() p.drawText(rect, Qt::AlignTop | Qt::AlignHCenter, year); } else { - pixmap = ui->hidden_frame->grab(); + pixmap = m_ui->hidden_frame->grab(); } if (pixmap.save(filename)) { diff --git a/src/gui/diarypixels.h b/src/gui/diarypixels.h index e565603..96bb298 100644 --- a/src/gui/diarypixels.h +++ b/src/gui/diarypixels.h @@ -42,7 +42,7 @@ class DiaryPixels : public QWidget { void setup_grid(); int calculate_size(); - QDate current_date; + QDate m_current_date; public slots: void render_button_clicked(); @@ -50,7 +50,7 @@ public slots: void export_image(); private: - Ui::DiaryPixels *ui; + Ui::DiaryPixels *m_ui; }; #endif // DIARYPIXELS_H diff --git a/src/gui/diarypixels.ui b/src/gui/diarypixels.ui index f596de0..4eec5df 100644 --- a/src/gui/diarypixels.ui +++ b/src/gui/diarypixels.ui @@ -100,6 +100,9 @@ Export image + + true + diff --git a/src/gui/diarystats.cpp b/src/gui/diarystats.cpp index 47b9e96..8e96be7 100644 --- a/src/gui/diarystats.cpp +++ b/src/gui/diarystats.cpp @@ -35,86 +35,86 @@ auto const light_background = QColor(230, 230, 230, 170); auto const dark_white = light_background.darker(); auto const light_black = dark_background.lighter(); -DiaryStats::DiaryStats(QWidget *parent) : QWidget(parent), ui(new Ui::DiaryStats) +DiaryStats::DiaryStats(QWidget *parent) : QWidget(parent), m_ui(new Ui::DiaryStats) { - ui->setupUi(this); + m_ui->setupUi(this); // Give DiaryComparisonLabels proper attributes. - ui->very_bad->rating = td::Rating::VeryBad; - ui->bad->rating = td::Rating::Bad; - ui->ok->rating = td::Rating::Ok; - ui->good->rating = td::Rating::Good; - ui->very_good->rating = td::Rating::VeryGood; - ui->unknown->rating = td::Rating::Unknown; - ui->starred->special = true; - - ui->very_bad_2->rating = td::Rating::VeryBad; - ui->bad_2->rating = td::Rating::Bad; - ui->ok_2->rating = td::Rating::Ok; - ui->good_2->rating = td::Rating::Good; - ui->very_good_2->rating = td::Rating::VeryGood; - ui->unknown_2->rating = td::Rating::Unknown; - ui->starred_2->special = true; - - ui->very_bad_3->rating = td::Rating::VeryBad; - ui->bad_3->rating = td::Rating::Bad; - ui->ok_3->rating = td::Rating::Ok; - ui->good_3->rating = td::Rating::Good; - ui->very_good_3->rating = td::Rating::VeryGood; - ui->unknown_3->rating = td::Rating::Unknown; - ui->starred_3->special = true; - - ui->very_bad->update_tooltip(); - ui->bad->update_tooltip(); - ui->ok->update_tooltip(); - ui->good->update_tooltip(); - ui->very_good->update_tooltip(); - ui->unknown->update_tooltip(); - ui->starred->update_tooltip(); - - ui->very_bad_2->update_tooltip(); - ui->bad_2->update_tooltip(); - ui->ok_2->update_tooltip(); - ui->good_2->update_tooltip(); - ui->very_good_2->update_tooltip(); - ui->unknown_2->update_tooltip(); - ui->starred_2->update_tooltip(); - - ui->very_bad_3->update_tooltip(); - ui->bad_3->update_tooltip(); - ui->ok_3->update_tooltip(); - ui->good_3->update_tooltip(); - ui->very_good_3->update_tooltip(); - ui->unknown_3->update_tooltip(); - ui->starred_3->update_tooltip(); + m_ui->very_bad->m_rating = td::Rating::VeryBad; + m_ui->bad->m_rating = td::Rating::Bad; + m_ui->ok->m_rating = td::Rating::Ok; + m_ui->good->m_rating = td::Rating::Good; + m_ui->very_good->m_rating = td::Rating::VeryGood; + m_ui->unknown->m_rating = td::Rating::Unknown; + m_ui->starred->m_special = true; + + m_ui->very_bad_2->m_rating = td::Rating::VeryBad; + m_ui->bad_2->m_rating = td::Rating::Bad; + m_ui->ok_2->m_rating = td::Rating::Ok; + m_ui->good_2->m_rating = td::Rating::Good; + m_ui->very_good_2->m_rating = td::Rating::VeryGood; + m_ui->unknown_2->m_rating = td::Rating::Unknown; + m_ui->starred_2->m_special = true; + + m_ui->very_bad_3->m_rating = td::Rating::VeryBad; + m_ui->bad_3->m_rating = td::Rating::Bad; + m_ui->ok_3->m_rating = td::Rating::Ok; + m_ui->good_3->m_rating = td::Rating::Good; + m_ui->very_good_3->m_rating = td::Rating::VeryGood; + m_ui->unknown_3->m_rating = td::Rating::Unknown; + m_ui->starred_3->m_special = true; + + m_ui->very_bad->update_tooltip(); + m_ui->bad->update_tooltip(); + m_ui->ok->update_tooltip(); + m_ui->good->update_tooltip(); + m_ui->very_good->update_tooltip(); + m_ui->unknown->update_tooltip(); + m_ui->starred->update_tooltip(); + + m_ui->very_bad_2->update_tooltip(); + m_ui->bad_2->update_tooltip(); + m_ui->ok_2->update_tooltip(); + m_ui->good_2->update_tooltip(); + m_ui->very_good_2->update_tooltip(); + m_ui->unknown_2->update_tooltip(); + m_ui->starred_2->update_tooltip(); + + m_ui->very_bad_3->update_tooltip(); + m_ui->bad_3->update_tooltip(); + m_ui->ok_3->update_tooltip(); + m_ui->good_3->update_tooltip(); + m_ui->very_good_3->update_tooltip(); + m_ui->unknown_3->update_tooltip(); + m_ui->starred_3->update_tooltip(); // Make the numbers display in a monospaced font. auto monospaced = QFontDatabase::systemFont(QFontDatabase::FixedFont); monospaced.setLetterSpacing(QFont::PercentageSpacing, 110); - ui->l0->setFont(monospaced); - ui->l1->setFont(monospaced); - ui->l2->setFont(monospaced); - ui->l3->setFont(monospaced); - ui->l4->setFont(monospaced); - ui->l5->setFont(monospaced); - ui->ls->setFont(monospaced); - - ui->t0->setFont(monospaced); - ui->t1->setFont(monospaced); - ui->t2->setFont(monospaced); - ui->t3->setFont(monospaced); - ui->t4->setFont(monospaced); - ui->t5->setFont(monospaced); - ui->ts->setFont(monospaced); - - ui->d0->setFont(monospaced); - ui->d1->setFont(monospaced); - ui->d2->setFont(monospaced); - ui->d3->setFont(monospaced); - ui->d4->setFont(monospaced); - ui->d5->setFont(monospaced); - ui->ds->setFont(monospaced); + m_ui->l0->setFont(monospaced); + m_ui->l1->setFont(monospaced); + m_ui->l2->setFont(monospaced); + m_ui->l3->setFont(monospaced); + m_ui->l4->setFont(monospaced); + m_ui->l5->setFont(monospaced); + m_ui->ls->setFont(monospaced); + + m_ui->t0->setFont(monospaced); + m_ui->t1->setFont(monospaced); + m_ui->t2->setFont(monospaced); + m_ui->t3->setFont(monospaced); + m_ui->t4->setFont(monospaced); + m_ui->t5->setFont(monospaced); + m_ui->ts->setFont(monospaced); + + m_ui->d0->setFont(monospaced); + m_ui->d1->setFont(monospaced); + m_ui->d2->setFont(monospaced); + m_ui->d3->setFont(monospaced); + m_ui->d4->setFont(monospaced); + m_ui->d5->setFont(monospaced); + m_ui->ds->setFont(monospaced); // Initilise pie chart. auto pie_chart = new QChart(); @@ -122,8 +122,8 @@ DiaryStats::DiaryStats(QWidget *parent) : QWidget(parent), ui(new Ui::DiaryStats pie_chart->setBackgroundVisible(false); pie_chart->legend()->hide(); pie_chart->setEnabled(false); // Disables scrolling (at the cost of what?). - ui->pie_chart_view->setRenderHint(QPainter::Antialiasing); - ui->pie_chart_view->setChart(pie_chart); + m_ui->pie_chart_view->setRenderHint(QPainter::Antialiasing); + m_ui->pie_chart_view->setChart(pie_chart); // Initialise polar chart. auto polar_chart = new QPolarChart(); @@ -131,8 +131,8 @@ DiaryStats::DiaryStats(QWidget *parent) : QWidget(parent), ui(new Ui::DiaryStats polar_chart->setBackgroundVisible(false); polar_chart->legend()->hide(); polar_chart->setEnabled(false); - ui->polar_chart_view->setRenderHint(QPainter::Antialiasing); - ui->polar_chart_view->setChart(polar_chart); + m_ui->polar_chart_view->setRenderHint(QPainter::Antialiasing); + m_ui->polar_chart_view->setChart(polar_chart); // Initialise spline chart. auto spline_chart = new QChart(); @@ -140,18 +140,26 @@ DiaryStats::DiaryStats(QWidget *parent) : QWidget(parent), ui(new Ui::DiaryStats spline_chart->setBackgroundVisible(false); spline_chart->legend()->hide(); spline_chart->setEnabled(false); - ui->spline_chart_view->setRenderHint(QPainter::Antialiasing); - ui->spline_chart_view->setChart(spline_chart); + m_ui->spline_chart_view->setRenderHint(QPainter::Antialiasing); + m_ui->spline_chart_view->setChart(spline_chart); connect(InternalManager::instance(), &InternalManager::update_data, this, &DiaryStats::render_stats, Qt::QueuedConnection); // Navigator slots. - connect(ui->month_dropdown, QOverload::of(&QComboBox::currentIndexChanged), this, &DiaryStats::month_changed, + connect(m_ui->month_dropdown, QOverload::of(&QComboBox::currentIndexChanged), this, &DiaryStats::month_changed, Qt::QueuedConnection); - connect(ui->year_edit, &QDateEdit::dateChanged, this, &DiaryStats::year_changed, Qt::QueuedConnection); - connect(ui->next_month, &QPushButton::clicked, this, &DiaryStats::next_month, Qt::QueuedConnection); - connect(ui->prev_month, &QPushButton::clicked, this, &DiaryStats::prev_month, Qt::QueuedConnection); + connect(m_ui->year_edit, &QDateEdit::dateChanged, this, &DiaryStats::year_changed, Qt::QueuedConnection); + connect(m_ui->next_month, &QPushButton::clicked, this, &DiaryStats::next_month, Qt::QueuedConnection); + connect(m_ui->prev_month, &QPushButton::clicked, this, &DiaryStats::prev_month, Qt::QueuedConnection); + + // Next/prev month keyboard shortcuts + m_next_month_bind = new QShortcut(Qt::Key_Down, this); + m_next_month_bind->setAutoRepeat(true); + connect(m_next_month_bind, &QShortcut::activated, this, &DiaryStats::next_month, Qt::QueuedConnection); + m_prev_month_bind = new QShortcut(Qt::Key_Up, this); + m_prev_month_bind->setAutoRepeat(true); + connect(m_prev_month_bind, &QShortcut::activated, this, &DiaryStats::prev_month, Qt::QueuedConnection); connect(InternalManager::instance(), &InternalManager::update_theme, this, &DiaryStats::update_theme, Qt::QueuedConnection); @@ -161,7 +169,9 @@ DiaryStats::DiaryStats(QWidget *parent) : QWidget(parent), ui(new Ui::DiaryStats DiaryStats::~DiaryStats() { - delete ui; + delete m_ui; + delete m_next_month_bind; + delete m_prev_month_bind; } void DiaryStats::update_theme() @@ -171,41 +181,41 @@ void DiaryStats::update_theme() void DiaryStats::next_month() { - auto const &&next = ui->year_edit->date().addMonths(1); + auto const &&next = m_ui->year_edit->date().addMonths(1); if (next.isValid()) render_stats(next); } void DiaryStats::prev_month() { - auto const &&prev = ui->year_edit->date().addMonths(-1); + auto const &&prev = m_ui->year_edit->date().addMonths(-1); if (prev.isValid()) render_stats(prev); } void DiaryStats::month_changed(int const) { - render_stats(QDate(ui->year_edit->date().year(), ui->month_dropdown->currentIndex() + 1, 1)); + render_stats(QDate(m_ui->year_edit->date().year(), m_ui->month_dropdown->currentIndex() + 1, 1)); } void DiaryStats::year_changed(QDate const &date) { if (date.isValid()) - render_stats(QDate(ui->year_edit->date().year(), ui->month_dropdown->currentIndex() + 1, 1)); + render_stats(QDate(m_ui->year_edit->date().year(), m_ui->month_dropdown->currentIndex() + 1, 1)); } void DiaryStats::render_pie_chart(std::vector const &rating_counts) { auto theme = InternalManager::instance()->get_theme(); // Clear all data from the chart so new values can be added. - ui->pie_chart_view->chart()->removeAllSeries(); + m_ui->pie_chart_view->chart()->removeAllSeries(); auto *pie_series = new QPieSeries(); pie_series->setPieEndAngle(330); - if (current_date.daysInMonth() == rating_counts[0]) { + if (m_current_date.daysInMonth() == rating_counts[0]) { // If there is no data for the current month, display an empty pie chart. - pie_series->append(ratings[0], current_date.daysInMonth()); + pie_series->append(ratings[0], m_current_date.daysInMonth()); auto slice = pie_series->slices().at(0); slice->setBrush(InternalManager::instance()->colour(td::ColourRole::Unknown)); slice->setLabelColor(InternalManager::instance()->colour(td::ColourRole::Text)); @@ -218,7 +228,7 @@ void DiaryStats::render_pie_chart(std::vector const &rating_counts) auto sorted = std::vector>(); switch (static_cast( - InternalManager::instance()->settings->value("pie_slice_sort").toInt())) { + InternalManager::instance()->m_settings->value("pie_slice_sort").toInt())) { case td::settings::PieSliceSort::Category: for (int i = 1; i < 6; ++i) if (0 != rating_counts[i]) @@ -249,16 +259,16 @@ void DiaryStats::render_pie_chart(std::vector const &rating_counts) } } - ui->pie_chart_view->chart()->addSeries(pie_series); - ui->pie_chart_view->update(); + m_ui->pie_chart_view->chart()->addSeries(pie_series); + m_ui->pie_chart_view->update(); qDebug() << "Rendered pie chart."; } void DiaryStats::render_polar_chart(std::optional const &opt) { auto theme = InternalManager::instance()->get_theme(); - auto chart = qobject_cast(ui->polar_chart_view->chart()); - auto const angular_max = current_date.daysInMonth(); + auto chart = qobject_cast(m_ui->polar_chart_view->chart()); + auto const angular_max = m_current_date.daysInMonth(); chart->removeAllSeries(); for (auto const &i : chart->axes()) @@ -281,7 +291,7 @@ void DiaryStats::render_polar_chart(std::optional const & if (opt) { for (auto const &[day, data] : (*opt)->second) { - auto const &[dummy, rating, d2, d3] = data; + auto const &[dummy, rating, d2, d3, d4, d5] = data; if (td::Rating::Unknown != rating) { auto upper = new QLineSeries(); @@ -312,7 +322,7 @@ void DiaryStats::render_polar_chart(std::optional const & void DiaryStats::render_spline_chart(std::optional const &opt) { auto theme = InternalManager::instance()->get_theme(); - auto chart = ui->spline_chart_view->chart(); + auto chart = m_ui->spline_chart_view->chart(); chart->removeAllSeries(); for (auto const &i : chart->axes()) @@ -321,27 +331,27 @@ void DiaryStats::render_spline_chart(std::optional const auto x_axis = new QValueAxis(); chart->addAxis(x_axis, Qt::AlignBottom); - switch (current_date.daysInMonth()) { + switch (m_current_date.daysInMonth()) { case 28: - x_axis->setRange(0, current_date.daysInMonth()); + x_axis->setRange(0, m_current_date.daysInMonth()); x_axis->setTickAnchor(0); x_axis->setTickInterval(2); x_axis->setTickCount(15); break; case 29: - x_axis->setRange(1, current_date.daysInMonth()); + x_axis->setRange(1, m_current_date.daysInMonth()); x_axis->setTickAnchor(1); x_axis->setTickInterval(2); x_axis->setTickCount(15); break; case 30: - x_axis->setRange(0, current_date.daysInMonth()); + x_axis->setRange(0, m_current_date.daysInMonth()); x_axis->setTickAnchor(0); x_axis->setTickInterval(2); x_axis->setTickCount(16); break; case 31: - x_axis->setRange(1, current_date.daysInMonth()); + x_axis->setRange(1, m_current_date.daysInMonth()); x_axis->setTickAnchor(1); x_axis->setTickInterval(2); x_axis->setTickCount(16); @@ -349,11 +359,11 @@ void DiaryStats::render_spline_chart(std::optional const default: // This will probably happen if somebody puts the year all the way back to 1700s when the calendar was reset or // something really obscure like that. - x_axis->setRange(1, current_date.daysInMonth()); + x_axis->setRange(1, m_current_date.daysInMonth()); x_axis->setTickAnchor(1); x_axis->setTickInterval(2); x_axis->setTickCount(15); - qDebug() << "This month has an invalid number of days in it:" << current_date; + qDebug() << "This month has an invalid number of days in it:" << m_current_date; break; } @@ -392,7 +402,7 @@ void DiaryStats::render_spline_chart(std::optional const current_spline_series->setColor(InternalManager::instance()->colour(td::ColourRole::Text)); for (auto const &[day, data] : (*opt)->second) { - auto const &[important, rating, dummy, d2] = data; + auto const &[important, rating, dummy, d2, d3, d4] = data; if (td::Rating::Unknown != rating) { // Each spline series covers a segment made from consecutive days with known ratings. This is done to // prevent the warping of the spline line if there are large gaps between days with ratings. Map @@ -426,52 +436,52 @@ void DiaryStats::render_spline_chart(std::optional const void DiaryStats::render_comparison(std::vector const &rating_counts) { - ui->t0->setText(QString::number(rating_counts[0])); - ui->t1->setText(QString::number(rating_counts[1])); - ui->t2->setText(QString::number(rating_counts[2])); - ui->t3->setText(QString::number(rating_counts[3])); - ui->t4->setText(QString::number(rating_counts[4])); - ui->t5->setText(QString::number(rating_counts[5])); - ui->ts->setText(QString::number(rating_counts[6])); - - auto const &prev_month = current_date.addMonths(-1); + m_ui->t0->setText(QString::number(rating_counts[0])); + m_ui->t1->setText(QString::number(rating_counts[1])); + m_ui->t2->setText(QString::number(rating_counts[2])); + m_ui->t3->setText(QString::number(rating_counts[3])); + m_ui->t4->setText(QString::number(rating_counts[4])); + m_ui->t5->setText(QString::number(rating_counts[5])); + m_ui->ts->setText(QString::number(rating_counts[6])); + + auto const &prev_month = m_current_date.addMonths(-1); if (!prev_month.isValid()) { - ui->l0->setText("N/A"); - ui->l1->setText("N/A"); - ui->l2->setText("N/A"); - ui->l3->setText("N/A"); - ui->l4->setText("N/A"); - ui->l5->setText("N/A"); - ui->ls->setText("N/A"); - - ui->d0->setText("N/A"); - ui->d1->setText("N/A"); - ui->d2->setText("N/A"); - ui->d3->setText("N/A"); - ui->d4->setText("N/A"); - ui->d5->setText("N/A"); - ui->ds->setText("N/A"); + m_ui->l0->setText("N/A"); + m_ui->l1->setText("N/A"); + m_ui->l2->setText("N/A"); + m_ui->l3->setText("N/A"); + m_ui->l4->setText("N/A"); + m_ui->l5->setText("N/A"); + m_ui->ls->setText("N/A"); + + m_ui->d0->setText("N/A"); + m_ui->d1->setText("N/A"); + m_ui->d2->setText("N/A"); + m_ui->d3->setText("N/A"); + m_ui->d4->setText("N/A"); + m_ui->d5->setText("N/A"); + m_ui->ds->setText("N/A"); return; } auto const &prev_stats = DiaryStats::get_rating_stats(DiaryHolder::instance()->get_monthmap(prev_month), prev_month.daysInMonth()); - ui->l0->setText(QString::number(prev_stats[0])); - ui->l1->setText(QString::number(prev_stats[1])); - ui->l2->setText(QString::number(prev_stats[2])); - ui->l3->setText(QString::number(prev_stats[3])); - ui->l4->setText(QString::number(prev_stats[4])); - ui->l5->setText(QString::number(prev_stats[5])); - ui->ls->setText(QString::number(prev_stats[6])); - - ui->d0->setText(QString::number(rating_counts[0] - prev_stats[0])); - ui->d1->setText(QString::number(rating_counts[1] - prev_stats[1])); - ui->d2->setText(QString::number(rating_counts[2] - prev_stats[2])); - ui->d3->setText(QString::number(rating_counts[3] - prev_stats[3])); - ui->d4->setText(QString::number(rating_counts[4] - prev_stats[4])); - ui->d5->setText(QString::number(rating_counts[5] - prev_stats[5])); - ui->ds->setText(QString::number(rating_counts[6] - prev_stats[6])); + m_ui->l0->setText(QString::number(prev_stats[0])); + m_ui->l1->setText(QString::number(prev_stats[1])); + m_ui->l2->setText(QString::number(prev_stats[2])); + m_ui->l3->setText(QString::number(prev_stats[3])); + m_ui->l4->setText(QString::number(prev_stats[4])); + m_ui->l5->setText(QString::number(prev_stats[5])); + m_ui->ls->setText(QString::number(prev_stats[6])); + + m_ui->d0->setText(QString::number(rating_counts[0] - prev_stats[0])); + m_ui->d1->setText(QString::number(rating_counts[1] - prev_stats[1])); + m_ui->d2->setText(QString::number(rating_counts[2] - prev_stats[2])); + m_ui->d3->setText(QString::number(rating_counts[3] - prev_stats[3])); + m_ui->d4->setText(QString::number(rating_counts[4] - prev_stats[4])); + m_ui->d5->setText(QString::number(rating_counts[5] - prev_stats[5])); + m_ui->ds->setText(QString::number(rating_counts[6] - prev_stats[6])); qDebug() << "Rendered stats table."; } @@ -482,7 +492,7 @@ std::vector DiaryStats::get_rating_stats(std::optionalsecond) { - auto const &[important, rating, dummy, d2] = data; + auto const &[important, rating, dummy, d2, d3, d4] = data; if (td::Rating::Unknown != rating) { --rating_counts[0]; ++rating_counts[static_cast(rating)]; @@ -498,26 +508,23 @@ std::vector DiaryStats::get_rating_stats(std::optionalmonth_dropdown->blockSignals(true); - ui->year_edit->blockSignals(true); + const QSignalBlocker b1(m_ui->month_dropdown); + const QSignalBlocker b2(m_ui->year_edit); if (date.isValid()) { - ui->month_dropdown->setCurrentIndex(date.month() - 1); - ui->year_edit->setDate(date); + m_ui->month_dropdown->setCurrentIndex(date.month() - 1); + m_ui->year_edit->setDate(date); } else { - ui->month_dropdown->setCurrentIndex(current_date.month() - 1); - ui->year_edit->setDate(current_date); + m_ui->month_dropdown->setCurrentIndex(m_current_date.month() - 1); + m_ui->year_edit->setDate(m_current_date); } - ui->month_dropdown->blockSignals(false); - ui->year_edit->blockSignals(false); - - auto const &opt = DiaryHolder::instance()->get_monthmap(current_date); - auto const &rating_counts = DiaryStats::get_rating_stats(opt, current_date.daysInMonth()); + auto const &opt = DiaryHolder::instance()->get_monthmap(m_current_date); + auto const &rating_counts = DiaryStats::get_rating_stats(opt, m_current_date.daysInMonth()); render_pie_chart(rating_counts); render_polar_chart(opt); diff --git a/src/gui/diarystats.h b/src/gui/diarystats.h index 7c1e17f..a0d61b3 100644 --- a/src/gui/diarystats.h +++ b/src/gui/diarystats.h @@ -43,7 +43,7 @@ class DiaryStats : public QWidget { void render_spline_chart(std::optional const &opt); void render_comparison(std::vector const &rating_counts); - QDate current_date; + QDate m_current_date; public slots: void update_theme(); @@ -54,7 +54,10 @@ public slots: void year_changed(QDate const &date); private: - Ui::DiaryStats *ui; + Ui::DiaryStats *m_ui; + + QShortcut *m_next_month_bind; + QShortcut *m_prev_month_bind; }; #endif // DIARYSTATS_H diff --git a/src/gui/diarystats.ui b/src/gui/diarystats.ui index bf200ad..352b4a2 100644 --- a/src/gui/diarystats.ui +++ b/src/gui/diarystats.ui @@ -583,6 +583,9 @@ < + + true + @@ -739,6 +742,9 @@ > + + true + diff --git a/src/gui/emotionsreference.cpp b/src/gui/emotionsreference.cpp new file mode 100644 index 0000000..91ab3e3 --- /dev/null +++ b/src/gui/emotionsreference.cpp @@ -0,0 +1,312 @@ +/* + * This file is part of Theoretical Diary. + * Copyright (C) 2022 someretical + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "emotionsreference.h" +#include "ui_emotionsreference.h" + +QString const TEXT = R"( +

Eight basic emotions (Robert Plutchik's theory)

+
    +
  1. Fear - feeling of being afraid, frightened, scared.
  2. +
  3. Anger - feeling angry. A stronger word for anger is rage.
  4. +
  5. Sadness - feeling sad. Other words are sorrow, grief (a stronger feeling, for example when someone has died).
  6. +
  7. Joy - the inward feeling of happiness that exists no matter the circumstance, whether good or bad.
  8. +
  9. Disgust - feeling something is wrong or nasty. Strong disapproval.
  10. +
  11. Surprise - being unprepared for something.
  12. +
  13. Trust - a positive emotion; admiration is stronger; acceptance is weaker.
  14. +
  15. Anticipation - in the sense of looking forward positively to something which is going to happen. Expectation is more neutral.
  16. +
+

Feelings

+

Feelings are what happens when these emotions are filtered through all of our memories, beliefs, experiences, and conscious awareness.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Fear + Anger + Sadness + Surprise + Joy + Love +
ScaredRageSufferingStunnedContentAffectionate
FrightenedHateAgonyShockedSatisfiedRomantic
HelplessHostileHurtDismayedPleasedFondness
      
TerrorExasperatedSadnessConfusedHappyLonging
PanicAgitatedDepressedDisillusionedAmusedSentimental
HystericalFustratedSorrowPerplexedDelightedAttracted
      
InsecureIrritableDisappointedAmazedCheerfulDesire
InferiorAnnoyedDismayedAstonishedJovialPassion
InadequateAggravatedDispleasedAwestruckBlissfulInfatuation
      
NervousEnvyShamefulOvercomeProudTenderness
WorriedResentfulRegretfulSpeechlessTriumphantCaring
AnxiousJealousGuiltyAstoundedIllustriousCompassionate
      
HorrorDisgustNeglectedMovedOptimisticPeaceful
MortifiedContemptIsolatedStimulatedEagerRelieved
DreadRevoltedLonelyTouchedHopefulSatisfied
      
  Despair Enthusiastic +  
  Grief Excited 
  Powerless Zeal 
      
    Elation 
    Euphoric 
    Jubilation 
      
    Enthralled 
    Enchanted 
    Rapture 
+

Sources

+ +)"; + +EmotionsReference::EmotionsReference(QWidget *parent) : QWidget(parent), m_ui(new Ui::EmotionsReference) +{ + m_ui->setupUi(this); + m_ui->text->setText(TEXT); + + connect(m_ui->ok_button, &QPushButton::clicked, this, &EmotionsReference::close, Qt::QueuedConnection); +} + +EmotionsReference::~EmotionsReference() +{ + delete m_ui; +} diff --git a/src/gui/emotionsreference.h b/src/gui/emotionsreference.h new file mode 100644 index 0000000..80029b3 --- /dev/null +++ b/src/gui/emotionsreference.h @@ -0,0 +1,39 @@ +/* + * This file is part of Theoretical Diary. + * Copyright (C) 2022 someretical + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef EMOTIONSREFERENCE_H +#define EMOTIONSREFERENCE_H + +#include + +namespace Ui { +class EmotionsReference; +} + +class EmotionsReference : public QWidget { + Q_OBJECT + +public: + explicit EmotionsReference(QWidget *parent = nullptr); + ~EmotionsReference(); + +private: + Ui::EmotionsReference *m_ui; +}; + +#endif // EMOTIONSREFERENCE_H diff --git a/src/gui/emotionsreference.ui b/src/gui/emotionsreference.ui new file mode 100644 index 0000000..ae08b6c --- /dev/null +++ b/src/gui/emotionsreference.ui @@ -0,0 +1,41 @@ + + + EmotionsReference + + + + 0 + 0 + 720 + 600 + + + + Emotions and feelings reference + + + + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + OK + + + true + + + true + + + + + + + + diff --git a/src/gui/gratitudeguide.cpp b/src/gui/gratitudeguide.cpp new file mode 100644 index 0000000..2ef8a21 --- /dev/null +++ b/src/gui/gratitudeguide.cpp @@ -0,0 +1,155 @@ +/* + * This file is part of Theoretical Diary. + * Copyright (C) 2022 someretical + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "gratitudeguide.h" +#include "ui_gratitudeguide.h" + +QString const TEXT = R"( +

Considerations

+
    +
  1. Be as specific as possible - specificity is key to fostering gratitude. "I'm grateful that my co-workers brought + me soup when I was sick on Tuesday" will be more effective than "I'm grateful for my co-workers."
  2. +
  3. Go for depth over breadth. Elaborating in detail about a particular person or thing for which you're grateful + carries more benefits than a superficial list of many things.
  4. +
  5. Get personal. Focusing on people to whom you are grateful has more of an impact than focusing on things for + which you are grateful.
  6. +
  7. Try subtraction, not just addition. Consider what your life would be like without certain people or things, + rather than just tallying up all the good stuff. Be grateful for the negative outcomes you avoided, escaped, + prevented, or turned into something positive - try not to take that good fortune for granted.
  8. +
  9. See good things as "gifts." Thinking of the good things in your life as gifts guards against taking them for + granted. Try to relish and savor the gifts you've received.
  10. +
  11. Savor surprises. Try to record events that were unexpected or surprising, as these tend to elicit stronger + levels of gratitude.
  12. +
  13. Revise if you repeat. Writing about some of the same people and things is OK, but zero in on a different aspect + in detail.
  14. +
  15. Write regularly. Whether you write daily or every other day, commit to a regular time to journal, then honor + that commitment.
  16. +
+

Resilience

+

To meet our need for safety, we can draw on:

+
    +
  • Compassion: Being sensitive to the burdens and suffering of others and ourselves, along with + the desire to help with these if we can.
  • +
  • Grit: Being doggedly tough and resourceful.
  • +
  • Calm: Emotional balance and a sense of capability in the face of threats.
  • +
  • Courage: Protecting and standing up for ourselves, including with others.
  • +
+

To meet our need for satisfaction, we can draw on:

+
    +
  • Mindfulness: Staying present in the moment as it is, rather than daydreaming, ruminating, or + being distracted.
  • +
  • Gratitude: Appreciating and feeling good about what already exists.
  • +
  • Motivation: Pursuing opportunities in the face of challenges.
  • +
  • Aspiration: Reaching for and achieving results that are important to us.
  • +
+

To meet our need for connection, we can draw on:

+
    +
  • Learning: Growing and developing, a process that allows us to cultivate all the other + strengths.
  • +
  • Confidence: Feeling a sense of being cared about, worthy, and self-assured.
  • +
  • Intimacy: Being open to knowing and being known by others.
  • +
  • Generosity: Giving to others through altruism, compassion, and forgiveness.
  • +
+

Considerations

+
    +
  • What, if it were more present in my mind these days, would really help?
  • +
  • What inner strengths could help me stay peaceful, content, and loving when I’m dealing with this + challenge?
  • +
  • If this challenge began in the past, what would have been really helpful to have experienced back then?
  • +
  • Deep down, what experience do I still very much long for?
  • +
+

The answers to these questions point to which resources you might need to get through your challenge.

+

Have a good experience

+

To have beneficial experiences in the first place, it helps to be alert to the good facts around you - for example, + fortunate circumstances, the beauty of nature, tasks you are completing, people who care about you, or your own + talents and skills. You can even find the good in hard times, such as seeing the kindness of others as you go + through a loss.

+

Besides simply noticing useful or pleasurable thoughts, feelings, or sensations that are already present in + your awareness, you could create beneficial experiences, such as by getting some exercise (to help build + the resource of grit) or deliberately recognizing your own good heart (for confidence). Or you could make something + good happen in a relationship, such as by listening carefully to someone (for intimacy).

+

Over time, you can learn to directly evoke a positive experience, such as relaxing at will, calling up a + sense of determination, or letting go of resentment. Because of experience-dependent neuroplasticity, repeatedly + having and internalizing a particular experience in the past makes it easier and easier to evoke it in the present. + It's like being able to push a button on your inner jukebox and quickly get the song of a useful experience playing + in your mind, since you’ve recorded it again and again.

+

Enrich it

+
    +
  • Lengthen it. Stay with it for five, ten, or more seconds. The longer that neurons fire + together, the more they tend to wire together. Protect the experience from distractions, focus on it, and come + back to it if your mind wanders.
  • +
  • Intensify it. Open to it and let it be big in your mind. Turn up the volume by breathing more + fully or getting a little excited.
  • +
  • Expand it. Notice other elements of the experience. For example, if you're having a useful + thought, look for related sensations or emotions.
  • +
  • Freshen it. The brain is a novelty detector, designed to learn from what's new or unexpected. + Look for what’s interesting or surprising about an experience. Imagine that you are having it for the very + first time.
  • +
  • Value it. We learn from what is personally relevant. Be aware of why the experience is + important to you, why it matters, and how it could help you.
  • +
+

Absorb it

+
    +
  • Intend to receive it. Consciously choose to take in the experience.
  • +
  • Sense it sinking into you. You could imagine that the experience is like a warm, soothing balm + or a jewel being placed in the treasure chest of your heart. Give over to it, allowing it to become a part of + you.
  • +
  • Reward yourself. Tune into whatever is pleasurable, reassuring, helpful, or hopeful about the + experience. Doing this will tend to increase the activity of two neurotransmitter systems - dopamine and + norepinephrine - that will flag the experience as a "keeper" for long-term storage.
  • +
+

Don't try and cling onto experiences in the stream of consciousness, rather gently encourage whatever is beneficial + to arise and stick around and sink in.

+

Link it

+

In Linking, you are simply conscious of both "negative" and "positive" material at the same time. For example, off to + the side of awareness could be old feelings of being left out and unwanted (perhaps from a rocky childhood) while in + the foreground of awareness are feelings of being liked and included by people at work. The brain naturally + associates things together, so if you keep the positive material more prominent and intense in awareness, it will + tend to soothe, ease, and even gradually replace the negative material.

+

For example, challenges to safety are often indicated by a sense of anxiety, anger, powerlessness, or trauma - and a + sense of calm or grit can really help with these. Challenges to our need for satisfaction are frequently experienced + as frustration, disappointment, drivenness, addiction, blahness, or boredom. Feeling thankful, awestruck, or already + contented are well-matched to these issues. Challenges to connection can be experienced as loneliness, resentment, + or inadequacy - and feeling either caring or cared about is a wonderful relief, since love is love whether it is + flowing in or out.

+

If you get pulled into the negative, drop it and focus only on the positive. And remember that this step is optional: + If the challenge you're facing is too powerful, you can grow mental resources for addressing it through the first + three HEAL steps alone.

+

Sources

+ +)"; + +GratitudeGuide::GratitudeGuide(QWidget *parent) : QWidget(parent), m_ui(new Ui::GratitudeGuide) +{ + m_ui->setupUi(this); + m_ui->text->setText(TEXT); + + connect(m_ui->ok_button, &QPushButton::clicked, this, &GratitudeGuide::close, Qt::QueuedConnection); +} + +GratitudeGuide::~GratitudeGuide() +{ + delete m_ui; +} diff --git a/src/gui/gratitudeguide.h b/src/gui/gratitudeguide.h new file mode 100644 index 0000000..bf75449 --- /dev/null +++ b/src/gui/gratitudeguide.h @@ -0,0 +1,39 @@ +/* + * This file is part of Theoretical Diary. + * Copyright (C) 2022 someretical + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GRATITUDEGUIDE_H +#define GRATITUDEGUIDE_H + +#include + +namespace Ui { +class GratitudeGuide; +} + +class GratitudeGuide : public QWidget { + Q_OBJECT + +public: + explicit GratitudeGuide(QWidget *parent = nullptr); + ~GratitudeGuide(); + +private: + Ui::GratitudeGuide *m_ui; +}; + +#endif // GRATITUDEGUIDE_H diff --git a/src/gui/gratitudeguide.ui b/src/gui/gratitudeguide.ui new file mode 100644 index 0000000..1afcdb6 --- /dev/null +++ b/src/gui/gratitudeguide.ui @@ -0,0 +1,41 @@ + + + GratitudeGuide + + + + 0 + 0 + 640 + 480 + + + + Gratitude and resilience guide + + + + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + OK + + + true + + + true + + + + + + + + diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp index c602e44..6000a92 100644 --- a/src/gui/mainmenu.cpp +++ b/src/gui/mainmenu.cpp @@ -31,35 +31,35 @@ #include "mainwindow.h" #include "ui_mainmenu.h" -MainMenu::MainMenu(bool const show_locked_message, QWidget *parent) : QWidget(parent), ui(new Ui::MainMenu) +MainMenu::MainMenu(bool const show_locked_message, QWidget *parent) : QWidget(parent), m_ui(new Ui::MainMenu) { - ui->setupUi(this); - ui->version->setText("Version " + QApplication::applicationVersion()); - ui->version->update(); - ui->app_name->setText(QApplication::applicationName()); - ui->app_name->update(); - ui->pwd_alert_text->set_text(show_locked_message ? "Diary locked due to inactivity." : ""); + m_ui->setupUi(this); + m_ui->version->setText("Version " + QApplication::applicationVersion()); + m_ui->version->update(); + m_ui->app_name->setText(QApplication::applicationName()); + m_ui->app_name->update(); + m_ui->pwd_alert_text->set_text(show_locked_message ? "Diary locked due to inactivity." : ""); - QTimer::singleShot(0, [&]() { ui->password_box->setFocus(); }); + QTimer::singleShot(0, [&]() { m_ui->password_box->setFocus(); }); // Pressing enter will try to decrypt - enter_shortcut = new QShortcut(QKeySequence(Qt::Key_Return), this); + m_enter_bind = new QShortcut(QKeySequence(Qt::Key_Return), this); connect( - enter_shortcut, &QShortcut::activated, this, - [&]() { QMetaObject::invokeMethod(ui->decrypt_button, "clicked"); }, Qt::QueuedConnection); - - connect(ui->decrypt_button, &QPushButton::clicked, this, &MainMenu::decrypt_diary, Qt::QueuedConnection); - connect(ui->new_button, &QPushButton::clicked, this, &MainMenu::new_diary, Qt::QueuedConnection); - connect(ui->import_button, &QPushButton::clicked, this, &MainMenu::import_diary, Qt::QueuedConnection); - connect(ui->options_button, &QPushButton::clicked, this, &MainMenu::open_options, Qt::QueuedConnection); - connect(ui->quit_button, &QPushButton::clicked, qobject_cast(parent), &MainWindow::close, + m_enter_bind, &QShortcut::activated, this, + [&]() { QMetaObject::invokeMethod(m_ui->decrypt_button, "clicked"); }, Qt::QueuedConnection); + + connect(m_ui->decrypt_button, &QPushButton::clicked, this, &MainMenu::decrypt_diary, Qt::QueuedConnection); + connect(m_ui->new_button, &QPushButton::clicked, this, &MainMenu::new_diary, Qt::QueuedConnection); + connect(m_ui->import_button, &QPushButton::clicked, this, &MainMenu::import_diary, Qt::QueuedConnection); + connect(m_ui->options_button, &QPushButton::clicked, this, &MainMenu::open_options, Qt::QueuedConnection); + connect(m_ui->quit_button, &QPushButton::clicked, qobject_cast(parent), &MainWindow::close, Qt::QueuedConnection); } MainMenu::~MainMenu() { - delete ui; - delete enter_shortcut; + delete m_ui; + delete m_enter_bind; } void MainMenu::open_options() @@ -91,7 +91,7 @@ bool MainMenu::get_diary_contents() } } - Encryptor::instance()->encrypted_str.assign(stream.str()); + Encryptor::instance()->m_encrypted_str.assign(stream.str()); return true; } @@ -100,10 +100,10 @@ void MainMenu::decrypt_diary() qDebug() << "Attempting to decrypt diary..."; AppBusyLock lock(true); - auto const &password = ui->password_box->text().toStdString(); - ui->password_box->setText(""); - ui->password_box->update(); - ui->pwd_alert_text->set_text(""); + auto const &password = m_ui->password_box->text().toStdString(); + m_ui->password_box->setText(""); + m_ui->password_box->update(); + m_ui->pwd_alert_text->set_text(""); auto const &opt = get_diary_contents(); if (!opt) { @@ -126,18 +126,18 @@ void MainMenu::decrypt_diary() auto decrypt_diary_cb = [this](bool const perform_decrypt) { std::string decrypted; if (perform_decrypt) { - auto const &res = Encryptor::instance()->decrypt(Encryptor::instance()->encrypted_str); + auto const &res = Encryptor::instance()->decrypt(Encryptor::instance()->m_encrypted_str); if (!res) return QTimer::singleShot(2000, [this]() { AppBusyLock lock; - ui->pwd_alert_text->set_text("Wrong password."); + m_ui->pwd_alert_text->set_text("Wrong password."); }); decrypted.assign(*res); } std::string decompressed; - if (Zipper::unzip((perform_decrypt ? decrypted : Encryptor::instance()->encrypted_str), decompressed) && + if (Zipper::unzip((perform_decrypt ? decrypted : Encryptor::instance()->m_encrypted_str), decompressed) && DiaryHolder::instance()->load(decompressed)) { GoogleWrapper::instance()->decrypt_credentials(perform_decrypt); @@ -149,11 +149,11 @@ void MainMenu::decrypt_diary() // 2000ms delay here to stop the app from getting spammed. QTimer::singleShot(2000, [this]() { AppBusyLock lock; - ui->pwd_alert_text->set_text("Unable to parse diary."); + m_ui->pwd_alert_text->set_text("Unable to parse diary."); }); }; - auto &str = Encryptor::instance()->encrypted_str; + auto &str = Encryptor::instance()->m_encrypted_str; // If the password box is empty, try to decompress immediately. // If the encrypted string length is too short, throw the same error. // This is the simplest way of letting a user know their file is scuffed. @@ -164,13 +164,13 @@ void MainMenu::decrypt_diary() else qDebug() << "No password to hash in decrypt_diary."; - ui->pwd_alert_text->set_text("Parsing diary...", false); + m_ui->pwd_alert_text->set_text("Parsing diary...", false); return decrypt_diary_cb(false); } Encryptor::instance()->parse_encrypted_string(str); - ui->pwd_alert_text->set_text("Decrypting...", false); + m_ui->pwd_alert_text->set_text("Decrypting...", false); auto hash_controller = new HashController(); connect(hash_controller, &HashController::sig_done, decrypt_diary_cb); @@ -187,7 +187,7 @@ void MainMenu::new_diary(bool const skip_overwrite_check) Encryptor::instance()->reset(); DiaryHolder::instance()->init(); - InternalManager::instance()->internal_diary_changed = true; + InternalManager::instance()->m_internal_diary_changed = true; qDebug() << "Showing diary menu from new diary."; MainWindow::instance()->show_diary_menu(); @@ -225,7 +225,7 @@ void MainMenu::import_diary() return msgbox->show(); } - InternalManager::instance()->internal_diary_changed = true; + InternalManager::instance()->m_internal_diary_changed = true; qDebug() << "Showing diary menu from import diary."; MainWindow::instance()->show_diary_menu(); }; diff --git a/src/gui/mainmenu.h b/src/gui/mainmenu.h index 86c5fd5..41a7812 100644 --- a/src/gui/mainmenu.h +++ b/src/gui/mainmenu.h @@ -40,8 +40,8 @@ public slots: bool get_diary_contents(); private: - Ui::MainMenu *ui; - QShortcut *enter_shortcut; + Ui::MainMenu *m_ui; + QShortcut *m_enter_bind; }; #endif // MAINMENU_H diff --git a/src/gui/mainmenu.ui b/src/gui/mainmenu.ui index 2185aab..ae699a6 100644 --- a/src/gui/mainmenu.ui +++ b/src/gui/mainmenu.ui @@ -153,34 +153,28 @@ - - - 100 - 0 - - Open the settings menu. Settings + + true + - - - 100 - 0 - - Exit the application. Quit + + true + @@ -329,18 +323,15 @@ - - - 100 - 0 - - Open local diary. Open + + true + true @@ -348,34 +339,28 @@ - - - 100 - 0 - - Import an unencrypted JSON diary. Import + + true + - - - 100 - 0 - - Create a new diary. New + + true + diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index ae712ba..2b29e4f 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -35,22 +35,22 @@ MainWindow *main_window_ptr; -MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow) { - ui->setupUi(this); + m_ui->setupUi(this); main_window_ptr = this; setWindowTitle(QApplication::applicationName()); restore_state(); show_main_menu(false); - connect(InternalManager::instance()->inactive_filter, &InactiveFilter::sig_inactive_timeout, this, + connect(InternalManager::instance()->m_inactive_filter, &InactiveFilter::sig_inactive_timeout, this, &MainWindow::lock_diary); } MainWindow::~MainWindow() { - delete ui; + delete m_ui; } MainWindow *MainWindow::instance() @@ -60,15 +60,15 @@ MainWindow *MainWindow::instance() void MainWindow::store_state() { - InternalManager::instance()->settings->setValue("geometry", saveGeometry()); - InternalManager::instance()->settings->setValue("window_state", saveState()); + InternalManager::instance()->m_settings->setValue("geometry", saveGeometry()); + InternalManager::instance()->m_settings->setValue("window_state", saveState()); qDebug() << "Stored window state."; } void MainWindow::restore_state() { - auto geo = InternalManager::instance()->settings->value("geometry", "").toByteArray(); - auto state = InternalManager::instance()->settings->value("window_state", "").toByteArray(); + auto geo = InternalManager::instance()->m_settings->value("geometry", "").toByteArray(); + auto state = InternalManager::instance()->m_settings->value("window_state", "").toByteArray(); restoreGeometry(geo); restoreState(state); qDebug() << "Restored window state."; @@ -84,11 +84,11 @@ void MainWindow::exit_diary_to_main_menu(bool const locked) auto encryptor = Encryptor::instance(); // Clean up. - intman->internal_diary_changed = false; + intman->m_internal_diary_changed = false; DiaryHolder::instance()->init(); // Backup on Google Drive. - if (intman->settings->value("sync_enabled").toBool() && intman->diary_file_changed) { + if (intman->m_settings->value("sync_enabled").toBool() && intman->m_diary_file_changed) { auto check_error = [this, locked](td::NR const &reply) { if (QNetworkReply::NoError != reply.error) { if (!locked) { @@ -108,9 +108,9 @@ void MainWindow::exit_diary_to_main_menu(bool const locked) if (!check_error(reply)) return; - intman->diary_file_changed = false; + intman->m_diary_file_changed = false; gwrapper->encrypt_credentials(); - gwrapper->google->unlink(); + gwrapper->m_o2g->unlink(); encryptor->reset(); if (!locked) @@ -179,18 +179,18 @@ void MainWindow::exit_diary_to_main_menu(bool const locked) cmb::display_google_drive_auth_error(this); break; case td::LinkingResponse::OK: - lock.persist = true; + lock.m_persist = true; gwrapper->list_files().subscribe(cb2); } }; - AsyncFuture::observe(gwrapper->google, &O2Google::linkingDone).subscribe(cb1); + AsyncFuture::observe(gwrapper->m_o2g, &O2Google::linkingDone).subscribe(cb1); AppBusyLock lock(true); - gwrapper->google->link(); + gwrapper->m_o2g->link(); } else { gwrapper->encrypt_credentials(); - gwrapper->google->unlink(); + gwrapper->m_o2g->unlink(); encryptor->reset(); } @@ -201,7 +201,7 @@ void MainWindow::exit_diary_to_main_menu(bool const locked) void MainWindow::lock_diary() { qDebug() << "Timeout detected."; - if (td::Window::Main == current_window || td::Window::Options == current_window) { + if (td::Window::Main == m_current_window || td::Window::Options == m_current_window) { // This isn't implemented because I don't believe it's a high risk for those tokens to be leaked? // In any case, if that ever DOES prove a threat, I can just uncomment the code below. // GoogleWrapper::instance()->google->unlink(); @@ -220,7 +220,7 @@ void MainWindow::clear_grid() misc::clear_message_boxes(); QLayoutItem *child; - while ((child = ui->central_grid->takeAt(0))) { + while ((child = m_ui->central_grid->takeAt(0))) { qDebug() << "Clearing grid of:" << child->widget() << child; child->widget()->deleteLater(); delete child; @@ -229,31 +229,31 @@ void MainWindow::clear_grid() void MainWindow::show_main_menu(bool const show_locked_message) { - current_window = td::Window::Main; + m_current_window = td::Window::Main; clear_grid(); - ui->central_grid->addWidget(new MainMenu(show_locked_message, this)); + m_ui->central_grid->addWidget(new MainMenu(show_locked_message, this)); } void MainWindow::show_options_menu() { - current_window = td::Window::Options; + m_current_window = td::Window::Options; clear_grid(); - ui->central_grid->addWidget(new StandaloneOptions(this)); + m_ui->central_grid->addWidget(new StandaloneOptions(this)); } void MainWindow::show_diary_menu() { - current_window = td::Window::Editor; + m_current_window = td::Window::Editor; clear_grid(); - ui->central_grid->addWidget(new DiaryMenu(this)); + m_ui->central_grid->addWidget(new DiaryMenu(this)); } void MainWindow::closeEvent(QCloseEvent *event) { - if (InternalManager::instance()->app_busy) { + if (InternalManager::instance()->m_app_busy) { event->ignore(); AppBusyLock lock; @@ -279,14 +279,14 @@ void MainWindow::closeEvent(QCloseEvent *event) QObject::connect(msgbox, &QMessageBox::finished, cb); msgbox->show(); } - else if (td::Window::Options == current_window) { + else if (td::Window::Options == m_current_window) { event->ignore(); // Don't close the main window, but exit to the main menu. show_main_menu(false); } - else if (td::Window::Editor == current_window) { + else if (td::Window::Editor == m_current_window) { event->ignore(); // Don't close the main window, but exit to the main menu. - if (InternalManager::instance()->internal_diary_changed) { + if (InternalManager::instance()->m_internal_diary_changed) { auto cb = [this](int const res) { if (QMessageBox::Cancel == res) return; diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 0163bf6..55c142f 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -44,7 +44,7 @@ class MainWindow : public QMainWindow { void restore_state(); void closeEvent(QCloseEvent *event); - td::Window current_window; + td::Window m_current_window; public slots: void lock_diary(); @@ -53,7 +53,7 @@ public slots: void show_options_menu(); private: - Ui::MainWindow *ui; + Ui::MainWindow *m_ui; }; #endif // MAINWINDOW_H diff --git a/src/gui/optionsmenu.cpp b/src/gui/optionsmenu.cpp index b7b9c43..c381853 100644 --- a/src/gui/optionsmenu.cpp +++ b/src/gui/optionsmenu.cpp @@ -32,39 +32,39 @@ #include "optionsmenu.h" #include "ui_optionsmenu.h" -OptionsMenu::OptionsMenu(bool const from_diary_editor, QWidget *parent) : QWidget(parent), ui(new Ui::OptionsMenu) +OptionsMenu::OptionsMenu(bool const from_diary_editor, QWidget *parent) : QWidget(parent), m_ui(new Ui::OptionsMenu) { - ui->setupUi(this); + m_ui->setupUi(this); - ui->pie_slice_sorting->setId(ui->pie_slice_sort1, static_cast(td::settings::PieSliceSort::Days)); - ui->pie_slice_sorting->setId(ui->pie_slice_sort2, static_cast(td::settings::PieSliceSort::Category)); + m_ui->pie_slice_sorting->setId(m_ui->pie_slice_sort1, static_cast(td::settings::PieSliceSort::Days)); + m_ui->pie_slice_sorting->setId(m_ui->pie_slice_sort2, static_cast(td::settings::PieSliceSort::Category)); - diary_editor_mode = from_diary_editor; + m_diary_editor_mode = from_diary_editor; - connect(ui->ok_button, &QPushButton::clicked, this, &OptionsMenu::back, Qt::QueuedConnection); - connect(ui->apply_button, &QPushButton::clicked, this, &OptionsMenu::save_settings, Qt::QueuedConnection); - connect(ui->export_button, &QPushButton::clicked, this, &OptionsMenu::export_diary, Qt::QueuedConnection); + connect(m_ui->ok_button, &QPushButton::clicked, this, &OptionsMenu::back, Qt::QueuedConnection); + connect(m_ui->apply_button, &QPushButton::clicked, this, &OptionsMenu::save_settings, Qt::QueuedConnection); + connect(m_ui->export_button, &QPushButton::clicked, this, &OptionsMenu::export_diary, Qt::QueuedConnection); connect( - ui->update_lock_timeout, &QPushButton::clicked, this, &OptionsMenu::update_lock_timeout, Qt::QueuedConnection); + m_ui->update_lock_timeout, &QPushButton::clicked, this, &OptionsMenu::update_lock_timeout, Qt::QueuedConnection); connect( - ui->change_password_button, &QPushButton::clicked, this, &OptionsMenu::change_password, Qt::QueuedConnection); - connect(ui->auth_button, &QPushButton::clicked, this, &OptionsMenu::complete_oauth, Qt::QueuedConnection); + m_ui->change_password_button, &QPushButton::clicked, this, &OptionsMenu::change_password, Qt::QueuedConnection); + connect(m_ui->auth_button, &QPushButton::clicked, this, &OptionsMenu::complete_oauth, Qt::QueuedConnection); connect( - ui->download_backup_button, &QPushButton::clicked, this, &OptionsMenu::download_backup, Qt::QueuedConnection); - connect(ui->upload_backup_button, &QPushButton::clicked, this, &OptionsMenu::upload_diary, Qt::QueuedConnection); - connect(ui->flush_oauth_button, &QPushButton::clicked, this, &OptionsMenu::flush_oauth, Qt::QueuedConnection); - connect(ui->dev_list_files_button, &QPushButton::clicked, this, &OptionsMenu::dev_list, Qt::QueuedConnection); - connect(ui->dev_upload_file_button, &QPushButton::clicked, this, &OptionsMenu::dev_upload, Qt::QueuedConnection); + m_ui->download_backup_button, &QPushButton::clicked, this, &OptionsMenu::download_backup, Qt::QueuedConnection); + connect(m_ui->upload_backup_button, &QPushButton::clicked, this, &OptionsMenu::upload_diary, Qt::QueuedConnection); + connect(m_ui->flush_oauth_button, &QPushButton::clicked, this, &OptionsMenu::flush_oauth, Qt::QueuedConnection); + connect(m_ui->dev_list_files_button, &QPushButton::clicked, this, &OptionsMenu::dev_list, Qt::QueuedConnection); + connect(m_ui->dev_upload_file_button, &QPushButton::clicked, this, &OptionsMenu::dev_upload, Qt::QueuedConnection); connect( - ui->dev_download_file_button, &QPushButton::clicked, this, &OptionsMenu::dev_download, Qt::QueuedConnection); - connect(ui->dev_update_file_button, &QPushButton::clicked, this, &OptionsMenu::dev_update, Qt::QueuedConnection); - connect(ui->dev_copy_file_button, &QPushButton::clicked, this, &OptionsMenu::dev_copy, Qt::QueuedConnection); - connect(ui->dev_delete_button, &QPushButton::clicked, this, &OptionsMenu::dev_delete, Qt::QueuedConnection); - connect(ui->about_button, &QPushButton::clicked, this, &OptionsMenu::show_about, Qt::QueuedConnection); - connect(ui->reset_button, &QPushButton::clicked, this, &OptionsMenu::reset_settings, Qt::QueuedConnection); - connect(ui->test_button, &QPushButton::clicked, this, &OptionsMenu::test, Qt::QueuedConnection); - - connect(GoogleWrapper::instance()->google, &O2Google::linkedChanged, this, &OptionsMenu::refresh_linked_checkbox, + m_ui->dev_download_file_button, &QPushButton::clicked, this, &OptionsMenu::dev_download, Qt::QueuedConnection); + connect(m_ui->dev_update_file_button, &QPushButton::clicked, this, &OptionsMenu::dev_update, Qt::QueuedConnection); + connect(m_ui->dev_copy_file_button, &QPushButton::clicked, this, &OptionsMenu::dev_copy, Qt::QueuedConnection); + connect(m_ui->dev_delete_button, &QPushButton::clicked, this, &OptionsMenu::dev_delete, Qt::QueuedConnection); + connect(m_ui->about_button, &QPushButton::clicked, this, &OptionsMenu::show_about, Qt::QueuedConnection); + connect(m_ui->reset_button, &QPushButton::clicked, this, &OptionsMenu::reset_settings, Qt::QueuedConnection); + connect(m_ui->test_button, &QPushButton::clicked, this, &OptionsMenu::test, Qt::QueuedConnection); + + connect(GoogleWrapper::instance()->m_o2g, &O2Google::linkedChanged, this, &OptionsMenu::refresh_linked_checkbox, Qt::QueuedConnection); setup_layout(); @@ -72,7 +72,7 @@ OptionsMenu::OptionsMenu(bool const from_diary_editor, QWidget *parent) : QWidge OptionsMenu::~OptionsMenu() { - delete ui; + delete m_ui; } void OptionsMenu::back() @@ -82,13 +82,13 @@ void OptionsMenu::back() void OptionsMenu::save_settings() { - auto settings = InternalManager::instance()->settings; + auto settings = InternalManager::instance()->m_settings; - settings->setValue("sync_enabled", ui->sync_checkbox->isChecked()); - settings->setValue("pie_slice_sort", ui->pie_slice_sorting->checkedId()); + settings->setValue("sync_enabled", m_ui->sync_checkbox->isChecked()); + settings->setValue("pie_slice_sort", m_ui->pie_slice_sorting->checkedId()); // auto original_theme = InternalManager::instance()->get_theme(); - auto new_theme = ui->theme_dropdown->currentIndex() == 0 ? td::Theme::Dark : td::Theme::Light; + auto new_theme = m_ui->theme_dropdown->currentIndex() == 0 ? td::Theme::Dark : td::Theme::Light; // if (original_theme != new_theme) { // settings->setValue("theme", static_cast(new_theme)); // InternalManager::instance()->start_update_theme(); @@ -97,8 +97,8 @@ void OptionsMenu::save_settings() // This workaround has to be put in place to make sure that the diary is uploaded if the user decrypts it, ticks the // backup option, and closes the diary without making any other changes. - if (ui->sync_checkbox->isChecked()) - InternalManager::instance()->diary_file_changed = true; + if (m_ui->sync_checkbox->isChecked()) + InternalManager::instance()->m_diary_file_changed = true; InternalManager::instance()->start_update_theme(); @@ -107,36 +107,36 @@ void OptionsMenu::save_settings() void OptionsMenu::setup_layout() { - ui->pwd_alert_text->set_text(""); - ui->lock_timeout_text->set_text(""); + m_ui->pwd_alert_text->set_text(""); + m_ui->lock_timeout_text->set_text(""); - auto const &settings = InternalManager::instance()->settings; + auto const &settings = InternalManager::instance()->m_settings; auto theme = static_cast(settings->value("theme").toInt()); - ui->theme_dropdown->setCurrentIndex(td::Theme::Dark == theme ? 0 : 1); + m_ui->theme_dropdown->setCurrentIndex(td::Theme::Dark == theme ? 0 : 1); - ui->oauth_checkbox->setEnabled(false); - ui->lock_timeout_textedit->setText(QString::number(settings->value("lock_timeout").toLongLong())); - ui->sync_checkbox->setChecked(settings->value("sync_enabled").toBool()); - qobject_cast(ui->pie_slice_sorting->button(settings->value("pie_slice_sort").toInt())) + m_ui->oauth_checkbox->setEnabled(false); + m_ui->lock_timeout_textedit->setText(QString::number(settings->value("lock_timeout").toLongLong())); + m_ui->sync_checkbox->setChecked(settings->value("sync_enabled").toBool()); + qobject_cast(m_ui->pie_slice_sorting->button(settings->value("pie_slice_sort").toInt())) ->setChecked(true); - if (!diary_editor_mode) { - ui->export_button->setEnabled(false); - ui->lock_timeout_textedit->setEnabled(false); - ui->update_lock_timeout->setEnabled(false); - ui->change_password_button->setEnabled(false); - ui->new_password->setEnabled(false); - ui->new_password_confirm->setEnabled(false); - ui->dev_list_files_button->setEnabled(false); - ui->dev_upload_file_button->setEnabled(false); - ui->dev_download_file_button->setEnabled(false); - ui->dev_update_file_button->setEnabled(false); - ui->dev_copy_file_button->setEnabled(false); - ui->dev_delete_button->setEnabled(false); + if (!m_diary_editor_mode) { + m_ui->export_button->setEnabled(false); + m_ui->lock_timeout_textedit->setEnabled(false); + m_ui->update_lock_timeout->setEnabled(false); + m_ui->change_password_button->setEnabled(false); + m_ui->new_password->setEnabled(false); + m_ui->new_password_confirm->setEnabled(false); + m_ui->dev_list_files_button->setEnabled(false); + m_ui->dev_upload_file_button->setEnabled(false); + m_ui->dev_download_file_button->setEnabled(false); + m_ui->dev_update_file_button->setEnabled(false); + m_ui->dev_copy_file_button->setEnabled(false); + m_ui->dev_delete_button->setEnabled(false); } else { - ui->ok_button->setVisible(false); + m_ui->ok_button->setVisible(false); } refresh_linked_checkbox(); @@ -144,24 +144,24 @@ void OptionsMenu::setup_layout() void OptionsMenu::refresh_linked_checkbox() { - if (GoogleWrapper::instance()->google->linked()) { - ui->oauth_checkbox->setCheckState(Qt::Checked); - ui->flush_oauth_button->setEnabled(true); + if (GoogleWrapper::instance()->m_o2g->linked()) { + m_ui->oauth_checkbox->setCheckState(Qt::Checked); + m_ui->flush_oauth_button->setEnabled(true); - if (diary_editor_mode) { - ui->upload_backup_button->setEnabled(true); - ui->download_backup_button->setEnabled(false); + if (m_diary_editor_mode) { + m_ui->upload_backup_button->setEnabled(true); + m_ui->download_backup_button->setEnabled(false); } else { - ui->upload_backup_button->setEnabled(false); - ui->download_backup_button->setEnabled(true); + m_ui->upload_backup_button->setEnabled(false); + m_ui->download_backup_button->setEnabled(true); } } else { - ui->oauth_checkbox->setCheckState(Qt::Unchecked); - ui->download_backup_button->setEnabled(false); - ui->upload_backup_button->setEnabled(false); - ui->flush_oauth_button->setEnabled(false); + m_ui->oauth_checkbox->setCheckState(Qt::Unchecked); + m_ui->download_backup_button->setEnabled(false); + m_ui->upload_backup_button->setEnabled(false); + m_ui->flush_oauth_button->setEnabled(false); } } @@ -179,7 +179,7 @@ void OptionsMenu::export_diary() if (dst.fail()) return cmb::display_local_io_error(this); - nlohmann::json const &j = DiaryHolder::instance()->diary; + nlohmann::json const &j = DiaryHolder::instance()->m_diary; dst << j.dump(4); auto msgbox = new QMessageBox(this); @@ -194,42 +194,42 @@ void OptionsMenu::update_lock_timeout() { AppBusyLock lock; bool ok = true; - qint64 const &ms = ui->lock_timeout_textedit->text().toLongLong(&ok, 10); + qint64 const &ms = m_ui->lock_timeout_textedit->text().toLongLong(&ok, 10); if (!ok || ms < 0) - return ui->lock_timeout_text->set_text("Please provide a positive integer."); + return m_ui->lock_timeout_text->set_text("Please provide a positive integer."); - InternalManager::instance()->settings->setValue("lock_timeout", ms); - InternalManager::instance()->inactive_filter->interval = ms; - InternalManager::instance()->inactive_filter->timer->start(); + InternalManager::instance()->m_settings->setValue("lock_timeout", ms); + InternalManager::instance()->m_inactive_filter->m_interval = ms; + InternalManager::instance()->m_inactive_filter->m_timer->start(); - ui->lock_timeout_text->set_text("Lock timeout updated."); + m_ui->lock_timeout_text->set_text("Lock timeout updated."); } void OptionsMenu::change_password() { AppBusyLock lock(true); - ui->pwd_alert_text->set_text(""); + m_ui->pwd_alert_text->set_text(""); - auto const &password = ui->new_password->text(); - if (password != ui->new_password_confirm->text()) { - ui->pwd_alert_text->set_text("The passwords do not match."); + auto const &password = m_ui->new_password->text(); + if (password != m_ui->new_password_confirm->text()) { + m_ui->pwd_alert_text->set_text("The passwords do not match."); return lock.release(); } auto cb = [this](bool const) { AppBusyLock lock; - InternalManager::instance()->internal_diary_changed = true; - ui->pwd_alert_text->set_text("Password updated."); + InternalManager::instance()->m_internal_diary_changed = true; + m_ui->pwd_alert_text->set_text("Password updated."); }; if (0 != password.length()) { - ui->pwd_alert_text->set_text("Changing password...", false); - ui->new_password->setText(""); - ui->new_password->update(); - ui->new_password_confirm->setText(""); - ui->new_password_confirm->update(); + m_ui->pwd_alert_text->set_text("Changing password...", false); + m_ui->new_password->setText(""); + m_ui->new_password->update(); + m_ui->new_password_confirm->setText(""); + m_ui->new_password_confirm->update(); auto hash_controller = new HashController(); connect(hash_controller, &HashController::sig_done, cb); @@ -270,9 +270,9 @@ void OptionsMenu::complete_oauth() } }; - AsyncFuture::observe(gwrapper->google, &O2Google::linkingDone).subscribe(cb1); + AsyncFuture::observe(gwrapper->m_o2g, &O2Google::linkingDone).subscribe(cb1); AppBusyLock lock(true); - gwrapper->google->link(); + gwrapper->m_o2g->link(); } void OptionsMenu::download_backup() @@ -329,7 +329,7 @@ void OptionsMenu::download_backup() cmb::display_google_drive_auth_error(this); break; case td::LinkingResponse::OK: - lock.persist = true; + lock.m_persist = true; gwrapper->list_files().subscribe(cb2); break; } @@ -339,9 +339,9 @@ void OptionsMenu::download_backup() if (QMessageBox::No == res) return; - AsyncFuture::observe(gwrapper->google, &O2Google::linkingDone).subscribe(cb1); + AsyncFuture::observe(gwrapper->m_o2g, &O2Google::linkingDone).subscribe(cb1); AppBusyLock lock(true); - gwrapper->google->link(); + gwrapper->m_o2g->link(); }; cmb::prompt_diary_overwrite(this, cb); @@ -427,15 +427,15 @@ void OptionsMenu::upload_diary() cmb::display_google_drive_auth_error(this); break; case td::LinkingResponse::OK: - lock.persist = true; + lock.m_persist = true; gwrapper->list_files().subscribe(cb2); break; } }; - AsyncFuture::observe(gwrapper->google, &O2Google::linkingDone).subscribe(cb1); + AsyncFuture::observe(gwrapper->m_o2g, &O2Google::linkingDone).subscribe(cb1); AppBusyLock lock(true); - gwrapper->google->link(); + gwrapper->m_o2g->link(); } void OptionsMenu::flush_oauth() @@ -445,7 +445,7 @@ void OptionsMenu::flush_oauth() auto cb = [this, gwrapper](td::NR const &) { AppBusyLock lock; - gwrapper->google->unlink(); + gwrapper->m_o2g->unlink(); auto msgbox = new QMessageBox(this); msgbox->setAttribute(Qt::WA_DeleteOnClose, true); @@ -482,15 +482,15 @@ void OptionsMenu::dev_list() cmb::display_google_drive_auth_error(this); break; case td::LinkingResponse::OK: - lock.persist = true; + lock.m_persist = true; gwrapper->list_files().subscribe(cb_final); break; } }; - AsyncFuture::observe(gwrapper->google, &O2Google::linkingDone).subscribe(cb1); + AsyncFuture::observe(gwrapper->m_o2g, &O2Google::linkingDone).subscribe(cb1); AppBusyLock lock(true); - gwrapper->google->link(); + gwrapper->m_o2g->link(); } void OptionsMenu::dev_upload() @@ -527,16 +527,16 @@ void OptionsMenu::dev_upload() if (!file_ptr->open(QIODevice::ReadOnly)) return cmb::display_local_io_error(this); - lock.persist = true; + lock.m_persist = true; QFileInfo fileinfo(file_ptr->fileName()); gwrapper->upload_file(file_ptr, fileinfo.fileName()).subscribe(cb_final); break; } }; - AsyncFuture::observe(gwrapper->google, &O2Google::linkingDone).subscribe(cb1); + AsyncFuture::observe(gwrapper->m_o2g, &O2Google::linkingDone).subscribe(cb1); AppBusyLock lock(true); - gwrapper->google->link(); + gwrapper->m_o2g->link(); } void OptionsMenu::dev_download() @@ -580,15 +580,15 @@ void OptionsMenu::dev_download() cmb::display_google_drive_auth_error(this); break; case td::LinkingResponse::OK: - lock.persist = true; - gwrapper->download_file(ui->dev_download_file_id->text()).subscribe(cb_final); + lock.m_persist = true; + gwrapper->download_file(m_ui->dev_download_file_id->text()).subscribe(cb_final); break; } }; - AsyncFuture::observe(gwrapper->google, &O2Google::linkingDone).subscribe(cb1); + AsyncFuture::observe(gwrapper->m_o2g, &O2Google::linkingDone).subscribe(cb1); AppBusyLock lock(true); - gwrapper->google->link(); + gwrapper->m_o2g->link(); } void OptionsMenu::dev_update() @@ -625,15 +625,15 @@ void OptionsMenu::dev_update() if (!file_ptr->open(QIODevice::ReadOnly)) return cmb::display_local_io_error(this); - lock.persist = true; - gwrapper->update_file(file_ptr, ui->dev_update_file_id->text()).subscribe(cb_final); + lock.m_persist = true; + gwrapper->update_file(file_ptr, m_ui->dev_update_file_id->text()).subscribe(cb_final); break; } }; - AsyncFuture::observe(gwrapper->google, &O2Google::linkingDone).subscribe(cb1); + AsyncFuture::observe(gwrapper->m_o2g, &O2Google::linkingDone).subscribe(cb1); AppBusyLock lock(true); - gwrapper->google->link(); + gwrapper->m_o2g->link(); } void OptionsMenu::dev_copy() @@ -660,15 +660,15 @@ void OptionsMenu::dev_copy() cmb::display_google_drive_auth_error(this); break; case td::LinkingResponse::OK: - lock.persist = true; - gwrapper->copy_file(ui->dev_copy_file_id->text(), ui->dev_copy_file_new_name->text()).subscribe(cb_final); + lock.m_persist = true; + gwrapper->copy_file(m_ui->dev_copy_file_id->text(), m_ui->dev_copy_file_new_name->text()).subscribe(cb_final); break; } }; - AsyncFuture::observe(gwrapper->google, &O2Google::linkingDone).subscribe(cb1); + AsyncFuture::observe(gwrapper->m_o2g, &O2Google::linkingDone).subscribe(cb1); AppBusyLock lock(true); - gwrapper->google->link(); + gwrapper->m_o2g->link(); } void OptionsMenu::dev_delete() @@ -696,15 +696,15 @@ void OptionsMenu::dev_delete() cmb::display_google_drive_auth_error(this); break; case td::LinkingResponse::OK: - lock.persist = true; - gwrapper->delete_file(ui->dev_delete_file_id->text()).subscribe(cb_final); + lock.m_persist = true; + gwrapper->delete_file(m_ui->dev_delete_file_id->text()).subscribe(cb_final); break; } }; - AsyncFuture::observe(gwrapper->google, &O2Google::linkingDone).subscribe(cb1); + AsyncFuture::observe(gwrapper->m_o2g, &O2Google::linkingDone).subscribe(cb1); AppBusyLock lock(true); - gwrapper->google->link(); + gwrapper->m_o2g->link(); } void OptionsMenu::show_about() diff --git a/src/gui/optionsmenu.h b/src/gui/optionsmenu.h index 3292fce..010be9b 100644 --- a/src/gui/optionsmenu.h +++ b/src/gui/optionsmenu.h @@ -55,8 +55,8 @@ public slots: void test(); private: - Ui::OptionsMenu *ui; - bool diary_editor_mode; + Ui::OptionsMenu *m_ui; + bool m_diary_editor_mode; }; #endif // OPTIONSMENU_H diff --git a/src/gui/optionsmenu.ui b/src/gui/optionsmenu.ui index aa656e2..29c964b 100644 --- a/src/gui/optionsmenu.ui +++ b/src/gui/optionsmenu.ui @@ -81,15 +81,12 @@ - - - 90 - 0 - - Apply + + true + true @@ -97,15 +94,12 @@ - - - 90 - 0 - - Close + + true + @@ -190,15 +184,12 @@ - - - 100 - 0 - - Upload backup + + true + @@ -206,32 +197,29 @@ Authorize + + true + - - - 100 - 0 - - Download backup + + true + - - - 100 - 0 - - Deauthorize + + true + @@ -359,12 +347,6 @@ - - - 100 - 0 - - Dark @@ -395,15 +377,12 @@ - - - 100 - 0 - - Reset + + true + @@ -420,15 +399,12 @@ - - - 100 - 0 - - View app information + + true + @@ -608,18 +584,15 @@ - - - 100 - 0 - - Update the password. Update + + true + @@ -633,18 +606,15 @@ - - - 100 - 0 - - Update the lock timeout. Update + + true + @@ -707,15 +677,12 @@ - - - 100 - 0 - - Export diary + + true + @@ -778,41 +745,32 @@ - - - 100 - 0 - - Upload + + true + - - - 100 - 0 - - Copy + + true + - - - 100 - 0 - - List + + true + @@ -824,15 +782,12 @@ - - - 100 - 0 - - Update + + true + @@ -900,28 +855,22 @@ - - - 100 - 0 - - Download + + true + - - - 100 - 0 - - Delete + + true + @@ -933,15 +882,12 @@ - - - 100 - 0 - - Test + + true + diff --git a/src/gui/rainguide.cpp b/src/gui/rainguide.cpp new file mode 100644 index 0000000..a64340f --- /dev/null +++ b/src/gui/rainguide.cpp @@ -0,0 +1,58 @@ +/* + * This file is part of Theoretical Diary. + * Copyright (C) 2022 someretical + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "rainguide.h" +#include "ui_rainguide.h" + +QString const TEXT = R"( +

Recognise

+

Name the emotions and feelings I am having.

+

Allow

+

Tell myself that it is okay to have these emotions and feelings.

+

Create a space for those emotions.

+

Investigate

+

What really wants my attention?

+

What am I believing right now?

+

What do I need right now?

+

Non-identify

+

Acknowledge that I am a whole person.

+

These negative emotions are just a tiny part of who I am so don't let them consume me.

+

Be kind to myself and offer myself what I need.

+

Sources:

+ +)"; + +RAINGuide::RAINGuide(QWidget *parent) : QWidget(parent), m_ui(new Ui::RAINGuide) +{ + m_ui->setupUi(this); + m_ui->text->setText(TEXT); + + connect(m_ui->ok_button, &QPushButton::clicked, this, &RAINGuide::close, Qt::QueuedConnection); +} + +RAINGuide::~RAINGuide() +{ + delete m_ui; +} diff --git a/src/gui/rainguide.h b/src/gui/rainguide.h new file mode 100644 index 0000000..3af434f --- /dev/null +++ b/src/gui/rainguide.h @@ -0,0 +1,39 @@ +/* + * This file is part of Theoretical Diary. + * Copyright (C) 2022 someretical + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef RAINGUIDE_H +#define RAINGUIDE_H + +#include + +namespace Ui { +class RAINGuide; +} + +class RAINGuide : public QWidget { + Q_OBJECT + +public: + explicit RAINGuide(QWidget *parent = nullptr); + ~RAINGuide(); + +private: + Ui::RAINGuide *m_ui; +}; + +#endif // RAINGUIDE_H diff --git a/src/gui/rainguide.ui b/src/gui/rainguide.ui new file mode 100644 index 0000000..18a101f --- /dev/null +++ b/src/gui/rainguide.ui @@ -0,0 +1,41 @@ + + + RAINGuide + + + + 0 + 0 + 640 + 480 + + + + Quick RAIN guide + + + + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + OK + + + true + + + true + + + + + + + + diff --git a/src/gui/standaloneoptions.cpp b/src/gui/standaloneoptions.cpp index dbbea90..0217564 100644 --- a/src/gui/standaloneoptions.cpp +++ b/src/gui/standaloneoptions.cpp @@ -20,15 +20,15 @@ #include "optionsmenu.h" #include "ui_standaloneoptions.h" -StandaloneOptions::StandaloneOptions(QWidget *parent) : QWidget(parent), ui(new Ui::StandaloneOptions) +StandaloneOptions::StandaloneOptions(QWidget *parent) : QWidget(parent), m_ui(new Ui::StandaloneOptions) { - ui->setupUi(this); - ui->settings_frame->layout()->addWidget(new OptionsMenu(false, this)); + m_ui->setupUi(this); + m_ui->settings_frame->layout()->addWidget(new OptionsMenu(false, this)); } StandaloneOptions::~StandaloneOptions() { - delete ui; + delete m_ui; } void StandaloneOptions::update_theme() {} diff --git a/src/gui/standaloneoptions.h b/src/gui/standaloneoptions.h index e01279f..b920455 100644 --- a/src/gui/standaloneoptions.h +++ b/src/gui/standaloneoptions.h @@ -36,7 +36,7 @@ public slots: void update_theme(); private: - Ui::StandaloneOptions *ui; + Ui::StandaloneOptions *m_ui; }; #endif // STANDALONEOPTIONS_H diff --git a/src/util/alertlabel.cpp b/src/util/alertlabel.cpp index a5a3a8a..fd041a0 100644 --- a/src/util/alertlabel.cpp +++ b/src/util/alertlabel.cpp @@ -20,10 +20,10 @@ AlertLabel::AlertLabel(QWidget *parent) : QLabel(parent) { - timer = new QTimer(this); - timer->setSingleShot(true); + m_timer = new QTimer(this); + m_timer->setSingleShot(true); - connect(timer, &QTimer::timeout, this, &AlertLabel::timeout); + connect(m_timer, &QTimer::timeout, this, &AlertLabel::timeout); } void AlertLabel::set_text(const QString &&t, bool const auto_hide) @@ -36,11 +36,11 @@ void AlertLabel::set_text(const QString &&t, bool const auto_hide) setVisible(true); if (auto_hide) { - timer->setInterval(5000); - timer->start(); + m_timer->setInterval(5000); + m_timer->start(); } else { - timer->stop(); + m_timer->stop(); } } diff --git a/src/util/alertlabel.h b/src/util/alertlabel.h index f704440..483c033 100644 --- a/src/util/alertlabel.h +++ b/src/util/alertlabel.h @@ -31,7 +31,7 @@ class AlertLabel : public QLabel { private: // The timer is used to auto hide the alert text after it has been shown for a while. - QTimer *timer; + QTimer *m_timer; private slots: void timeout(); diff --git a/src/util/diarycalendarbutton.h b/src/util/diarycalendarbutton.h index cf5e877..0f6904f 100644 --- a/src/util/diarycalendarbutton.h +++ b/src/util/diarycalendarbutton.h @@ -48,32 +48,32 @@ class DiaryCalendarButton : public QAbstractButton { { setText(QString::number(*d.day)); setFixedSize(QSize(override::SIZE, override::SIZE)); - data = d; - mouse_down = false; + m_data = d; + m_m_down = false; } ~DiaryCalendarButton() {} - td::CalendarButtonData data; - bool mouse_down; + td::CalendarButtonData m_data; + bool m_m_down; public slots: void render(td::CalendarButtonData const &d) { if (d.day) - data.day = d.day; + m_data.day = d.day; if (d.important) - data.important = d.important; + m_data.important = d.important; if (d.rating) - data.rating = d.rating; + m_data.rating = d.rating; if (d.selected) - data.selected = d.selected; + m_data.selected = d.selected; if (d.current_day) - data.current_day = d.current_day; + m_data.current_day = d.current_day; update(); } @@ -91,17 +91,17 @@ public slots: void mousePressEvent(QMouseEvent *) { - mouse_down = true; + m_m_down = true; update(); } void mouseReleaseEvent(QMouseEvent *e) { - mouse_down = false; + m_m_down = false; // Mouse move events are not broadcast when the mouse is held down. if (rect().contains(e->pos())) - emit sig_clicked(*data.day); + emit sig_clicked(*m_data.day); update(); } @@ -112,7 +112,7 @@ public slots: p.setRenderHint(QPainter::Antialiasing); p.drawPixmap(0, 0, generate_background()); - if (*data.important) + if (*m_data.important) p.drawPixmap(0, 0, generate_star()); p.drawPixmap(0, 0, generate_text()); @@ -122,7 +122,7 @@ public slots: QPixmap generate_background() { QString key = QString("calendarbutton:bkg:%1:%2:%3") - .arg(QString::number(static_cast(*data.rating)), + .arg(QString::number(static_cast(*m_data.rating)), QString::number(static_cast(InternalManager::instance()->get_theme())), QString::number(get_state())); QPixmap pixmap; @@ -144,8 +144,8 @@ public slots: // p.setOpacity(0.8); // Set background color. - QColor color = misc::rating_to_colour(*data.rating); - if (mouse_down) { + QColor color = misc::rating_to_colour(*m_data.rating); + if (m_m_down) { p.fillPath(path, QBrush(color.darker(120))); } // else if (underMouse()) { @@ -156,7 +156,7 @@ public slots: } // Set border color. - if (mouse_down || underMouse() || *data.selected) { + if (m_m_down || underMouse() || *m_data.selected) { if (InternalManager::instance()->get_theme() == td::Theme::Light) { p.strokePath(path, QPen(QBrush(color.lighter(110)), BORDER_WIDTH)); } @@ -177,10 +177,10 @@ public slots: QPixmap generate_text() { - QString day = QString::number(*data.day); + QString day = QString::number(*m_data.day); QPixmap pixmap; - if (*data.current_day) { + if (*m_data.current_day) { pixmap = QPixmap(override::SIZE, override::SIZE); pixmap.fill(Qt::transparent); @@ -198,13 +198,13 @@ public slots: rect = p.boundingRect(pixmap.rect(), Qt::AlignTop | Qt::AlignRight, day); rect.translate(-12, 8); - p.setPen(misc::theme_to_text(misc::rating_to_theme(*data.rating))); + p.setPen(misc::theme_to_text(misc::rating_to_theme(*m_data.rating))); p.drawText(rect, Qt::AlignTop | Qt::AlignRight, day); return pixmap; } - auto theme = QString::number(static_cast(misc::rating_to_theme(*data.rating))); + auto theme = QString::number(static_cast(misc::rating_to_theme(*m_data.rating))); QString key = QString("calendarbutton:text:%1:%2").arg(day, theme); if (!QPixmapCache::find(key, pixmap)) { @@ -223,7 +223,7 @@ public slots: rect = p.boundingRect(pixmap.rect(), Qt::AlignTop | Qt::AlignRight, day); rect.translate(-10, 8); - p.setPen(misc::theme_to_text(misc::rating_to_theme(*data.rating))); + p.setPen(misc::theme_to_text(misc::rating_to_theme(*m_data.rating))); p.drawText(rect, Qt::AlignTop | Qt::AlignRight, day); QPixmapCache::insert(key, pixmap); @@ -234,7 +234,7 @@ public slots: QPixmap generate_star() { - auto theme_str = misc::rating_to_theme(*data.rating) == td::Theme::Dark ? "dark" : "light"; + auto theme_str = misc::rating_to_theme(*m_data.rating) == td::Theme::Dark ? "dark" : "light"; QString key = QString("calendarbutton:star:%1:%2").arg(theme_str, QString::number(get_state())); QPixmap pixmap(override::SIZE, override::SIZE); @@ -244,7 +244,7 @@ public slots: QPainter p(&pixmap); p.setRenderHint(QPainter::Antialiasing); - if (mouse_down) { + if (m_m_down) { p.setOpacity(0.4); } else if (underMouse()) { @@ -278,10 +278,10 @@ public slots: // If the mouse IS hovering over but not clicking, state is 1. // If the mouse IS hovering over AND clicking, state is 2. - if (mouse_down) + if (m_m_down) return 2; - if (underMouse() || *data.selected) + if (underMouse() || *m_data.selected) return 1; return 0; diff --git a/src/util/diarycomparisonlabel.h b/src/util/diarycomparisonlabel.h index aa5e346..1c8901a 100644 --- a/src/util/diarycomparisonlabel.h +++ b/src/util/diarycomparisonlabel.h @@ -38,18 +38,18 @@ class DiaryComparisonLabel : public QLabel { DiaryComparisonLabel(QWidget *parent = nullptr) : QLabel(parent) { setFixedSize(QSize(50, 50)); - rating = td::Rating::Unknown; - special = false; + m_rating = td::Rating::Unknown; + m_special = false; } ~DiaryComparisonLabel() {} void update_tooltip() { - if (special) + if (m_special) return setToolTip("Starred days."); - switch (rating) { + switch (m_rating) { case td::Rating::Unknown: setToolTip("Days with unknown rating."); break; @@ -71,13 +71,13 @@ class DiaryComparisonLabel : public QLabel { } } - td::Rating rating; - bool special; + td::Rating m_rating; + bool m_special; private: QPixmap generate_pixmap() { - if (special) { + if (m_special) { auto theme_str = InternalManager::instance()->get_theme_str(true); QPixmap bkg(override::SIZE, override::SIZE); @@ -99,7 +99,7 @@ class DiaryComparisonLabel : public QLabel { QPixmap bkg(override::SIZE, override::SIZE); bkg.fill(Qt::transparent); - QColor bkg_color = misc::rating_to_colour(rating); + QColor bkg_color = misc::rating_to_colour(m_rating); QPainter p(&bkg); p.setRenderHint(QPainter::Antialiasing); @@ -119,8 +119,8 @@ class DiaryComparisonLabel : public QLabel { { QString key = QString("comparisonlabel:%1:%2") - .arg(QString::number(static_cast(rating)), - special ? "s" : QString::number(static_cast(InternalManager::instance()->get_theme()))); + .arg(QString::number(static_cast(m_rating)), + m_special ? "s" : QString::number(static_cast(InternalManager::instance()->get_theme()))); QPixmap pixmap; if (!QPixmapCache::find(key, pixmap)) { diff --git a/src/util/diarypixellabel.h b/src/util/diarypixellabel.h index fe39731..639dbc1 100644 --- a/src/util/diarypixellabel.h +++ b/src/util/diarypixellabel.h @@ -38,8 +38,8 @@ class DiaryPixelLabel : public QLabel { td::Rating const r, bool const s, int const month, int const day, int const size, QWidget *parent = nullptr) : QLabel(parent) { - special = s; - rating = r; + m_special = s; + m_rating = r; setFixedHeight(size); setFixedWidth(size); @@ -50,8 +50,8 @@ class DiaryPixelLabel : public QLabel { ~DiaryPixelLabel() {} - td::Rating rating; - bool special; + td::Rating m_rating; + bool m_special; public slots: void resize_slot(int const new_width) @@ -71,7 +71,7 @@ public slots: p.setRenderHint(QPainter::Antialiasing); p.drawPixmap(0, 0, generate_pixmap(size_)); - if (special) { + if (m_special) { p.setOpacity(0.5); p.drawPixmap(0, 0, generate_star(size_)); } @@ -82,12 +82,12 @@ public slots: { QPixmap pixmap(size_.width(), size_.width()); QString key = QString("pixellabel:%1:%2:%3") - .arg(QString::number(static_cast(rating)), QString::number(size_.width()), + .arg(QString::number(static_cast(m_rating)), QString::number(size_.width()), QString::number(static_cast(InternalManager::instance()->get_theme()))); if (!QPixmapCache::find(key, pixmap)) { pixmap.fill(Qt::transparent); - QColor bkg_colour = misc::rating_to_colour(rating); + QColor bkg_colour = misc::rating_to_colour(m_rating); QPainter p(&pixmap); p.setRenderHint(QPainter::Antialiasing); @@ -109,7 +109,7 @@ public slots: QPixmap pixmap(size_.width(), size_.width()); pixmap.fill(Qt::transparent); - auto theme_str = misc::rating_to_theme(rating) == td::Theme::Dark ? "dark" : "light"; + auto theme_str = misc::rating_to_theme(m_rating) == td::Theme::Dark ? "dark" : "light"; QSvgRenderer renderer(QString(":/themes/%1/star.svg").arg(theme_str)); QPainter painter(&pixmap); renderer.render(&painter); diff --git a/src/util/encryptor.cpp b/src/util/encryptor.cpp index 00d5636..f98d006 100644 --- a/src/util/encryptor.cpp +++ b/src/util/encryptor.cpp @@ -50,11 +50,11 @@ Encryptor *encryptor_ptr; Encryptor::Encryptor() { encryptor_ptr = this; - salt = CryptoPP::SecByteBlock(SALT_SIZE); - key = CryptoPP::SecByteBlock(KEY_SIZE); - key_set = false; - decrypt_iv = CryptoPP::SecByteBlock(IV_SIZE); - encrypted_str = std::string(); + m_salt = CryptoPP::SecByteBlock(SALT_SIZE); + m_key = CryptoPP::SecByteBlock(KEY_SIZE); + m_key_set = false; + m_decrypt_iv = CryptoPP::SecByteBlock(IV_SIZE); + m_encrypted_str = std::string(); } Encryptor::~Encryptor() {} @@ -66,18 +66,18 @@ Encryptor *Encryptor::instance() void Encryptor::reset() { - salt.Assign(CryptoPP::SecByteBlock(SALT_SIZE)); - key.Assign(CryptoPP::SecByteBlock(KEY_SIZE)); - key_set = false; - decrypt_iv.Assign(CryptoPP::SecByteBlock(IV_SIZE)); - encrypted_str.clear(); + m_salt.Assign(CryptoPP::SecByteBlock(SALT_SIZE)); + m_key.Assign(CryptoPP::SecByteBlock(KEY_SIZE)); + m_key_set = false; + m_decrypt_iv.Assign(CryptoPP::SecByteBlock(IV_SIZE)); + m_encrypted_str.clear(); qDebug() << "Encryptor reset."; } void Encryptor::regenerate_salt() { CryptoPP::AutoSeededRandomPool prng; - prng.GenerateBlock(salt.data(), SALT_SIZE); + prng.GenerateBlock(m_salt.data(), SALT_SIZE); qDebug() << "Salt regenerated."; } @@ -85,17 +85,17 @@ void Encryptor::set_key(std::string const &plaintext) { CryptoPP::SecByteBlock byte_block(reinterpret_cast(plaintext.data()), plaintext.size()); CryptoPP::Scrypt scrypt; - key_set = true; + m_key_set = true; // This is supposed to be computationally expensive to make it hard to brute force attack. It SHOULD take a // reasonable amount of time. Unfortunately it takes WAY longer on Windows compared with Linux. scrypt.DeriveKey( - key.data(), KEY_SIZE, byte_block.data(), byte_block.size(), salt.data(), SALT_SIZE, 1 << 15, 8, 16); + m_key.data(), KEY_SIZE, byte_block.data(), byte_block.size(), m_salt.data(), SALT_SIZE, 1 << 15, 8, 16); } void Encryptor::set_salt(std::string const &salt_str) { - salt.Assign(CryptoPP::SecByteBlock(reinterpret_cast(salt_str.data()), SALT_SIZE)); + m_salt.Assign(CryptoPP::SecByteBlock(reinterpret_cast(salt_str.data()), SALT_SIZE)); qDebug() << "New salt set."; } @@ -115,7 +115,7 @@ void Encryptor::encrypt(std::string const &plaintext, std::string &encrypted) CryptoPP::GCM::Encryption encryptor; prng.GenerateBlock(iv, IV_SIZE); - encryptor.SetKeyWithIV(key.data(), KEY_SIZE, iv, IV_SIZE); + encryptor.SetKeyWithIV(m_key.data(), KEY_SIZE, iv, IV_SIZE); // Put content to be encrypted in the encryption AND authentication channel. CryptoPP::AuthenticatedEncryptionFilter encryption_filter( @@ -128,13 +128,13 @@ void Encryptor::encrypt(std::string const &plaintext, std::string &encrypted) encrypted.insert(0, iv_str); // Prepend the salt. - std::string const salt_str(reinterpret_cast(salt.data()), SALT_SIZE); + std::string const salt_str(reinterpret_cast(m_salt.data()), SALT_SIZE); encrypted.insert(0, salt_str); } void Encryptor::set_decrypt_iv(std::string const &iv_str) { - decrypt_iv.Assign(CryptoPP::SecByteBlock(reinterpret_cast(iv_str.data()), IV_SIZE)); + m_decrypt_iv.Assign(CryptoPP::SecByteBlock(reinterpret_cast(iv_str.data()), IV_SIZE)); qDebug() << "New decrypt IV set."; } @@ -143,7 +143,7 @@ std::optional Encryptor::decrypt(std::string const &encrypted) { try { CryptoPP::GCM::Decryption decryptor; - decryptor.SetKeyWithIV(key.data(), KEY_SIZE, decrypt_iv, IV_SIZE); + decryptor.SetKeyWithIV(m_key.data(), KEY_SIZE, m_decrypt_iv, IV_SIZE); std::string encrypted_data = encrypted.substr(0, encrypted.size() - TAG_SIZE); std::string mac_value = encrypted.substr(encrypted.size() - TAG_SIZE); diff --git a/src/util/encryptor.h b/src/util/encryptor.h index fbe8fe2..f982903 100644 --- a/src/util/encryptor.h +++ b/src/util/encryptor.h @@ -47,15 +47,15 @@ class Encryptor { void encrypt(std::string const &plaintext, std::string &encrypted); std::optional decrypt(std::string const &encrypted); - bool key_set; + bool m_key_set; // This string exists as a cache of only the encrypted part of the string when trying to decrypt the diary. // The full diary string includes the salt and the IV. - std::string encrypted_str; + std::string m_encrypted_str; private: - CryptoPP::SecByteBlock salt; - CryptoPP::SecByteBlock key; - CryptoPP::SecByteBlock decrypt_iv; + CryptoPP::SecByteBlock m_salt; + CryptoPP::SecByteBlock m_key; + CryptoPP::SecByteBlock m_decrypt_iv; }; #endif // ENCRYPTOR_H diff --git a/src/util/eventfilters.cpp b/src/util/eventfilters.cpp index 19aa4c6..c3efa81 100644 --- a/src/util/eventfilters.cpp +++ b/src/util/eventfilters.cpp @@ -62,16 +62,16 @@ bool BusyFilter::eventFilter(QObject *, QEvent *event) */ InactiveFilter::InactiveFilter(qint64 const i, QObject *parent) : QObject(parent) { - interval = i; - timer = new QTimer(this); - timer->setSingleShot(false); - timer->start(interval); - connect(timer, &QTimer::timeout, this, &InactiveFilter::slot_inactive_timeout); + m_interval = i; + m_timer = new QTimer(this); + m_timer->setSingleShot(false); + m_timer->start(m_interval); + connect(m_timer, &QTimer::timeout, this, &InactiveFilter::slot_inactive_timeout); } InactiveFilter::~InactiveFilter() { - delete timer; + delete m_timer; } bool InactiveFilter::eventFilter(QObject *obj, QEvent *event) @@ -101,7 +101,7 @@ bool InactiveFilter::eventFilter(QObject *obj, QEvent *event) case QEvent::TouchCancel: case QEvent::TouchEnd: case QEvent::TouchUpdate: - timer->start(interval); + m_timer->start(m_interval); break; default: break; @@ -112,6 +112,6 @@ bool InactiveFilter::eventFilter(QObject *obj, QEvent *event) void InactiveFilter::slot_inactive_timeout() { - if (0 != interval) + if (0 != m_interval) emit sig_inactive_timeout(); } diff --git a/src/util/eventfilters.h b/src/util/eventfilters.h index 3334a9c..5df91be 100644 --- a/src/util/eventfilters.h +++ b/src/util/eventfilters.h @@ -42,8 +42,8 @@ class InactiveFilter : public QObject { InactiveFilter(qint64 const i, QObject *parent = nullptr); ~InactiveFilter(); - QTimer *timer; - qint64 interval; + QTimer *m_timer; + qint64 m_interval; public slots: void slot_inactive_timeout(); diff --git a/src/util/hashcontroller.h b/src/util/hashcontroller.h index 401b9ab..0265477 100644 --- a/src/util/hashcontroller.h +++ b/src/util/hashcontroller.h @@ -47,25 +47,25 @@ public slots: class HashController : public QObject { Q_OBJECT - QThread worker_thread; + QThread m_worker_thread; public: HashController() { auto *worker = new HashWorker; - worker->moveToThread(&worker_thread); + worker->moveToThread(&m_worker_thread); - connect(&worker_thread, &QThread::finished, worker, &QObject::deleteLater); + connect(&m_worker_thread, &QThread::finished, worker, &QObject::deleteLater); connect(this, &HashController::operate, worker, &HashWorker::hash); connect(worker, &HashWorker::done, this, &HashController::handle_results); - worker_thread.start(); + m_worker_thread.start(); } ~HashController() { - worker_thread.quit(); - worker_thread.wait(); + m_worker_thread.quit(); + m_worker_thread.wait(); } public slots: diff --git a/src/util/misc.cpp b/src/util/misc.cpp index e17afd7..c2cf0c6 100644 --- a/src/util/misc.cpp +++ b/src/util/misc.cpp @@ -45,35 +45,6 @@ bool is_not_space(int ch) return !std::isspace(ch); } -// Assumes trimmed input!!! -std::string get_trunc_first_line(std::string input, int max_line_len) -{ - std::string first_line; - auto newlines_exist = input.find('\n') != std::string::npos; - - if (newlines_exist) { - std::istringstream stream(input); - std::getline(stream, first_line); - } - else { - first_line = std::move(input); - } - - // Truncate line and append ... if it's too long. - // Cast max_line_len from 'int const' to 'long unsigned int'. - if (first_line.size() > static_cast::type>(max_line_len)) { - first_line.resize(max_line_len); - first_line.append("..."); - } - else if (newlines_exist) { - // There can be multiple lines in an entry where the first line does not have at least LONGEST_LINE_LENGTH - // characters. - first_line.append("..."); - } - - return first_line; -} - void extend_top_line(std::string &top, long unsigned int const max_line_len) { if (top.size() < max_line_len) diff --git a/src/util/misc.h b/src/util/misc.h index 2c09975..aeb5cef 100644 --- a/src/util/misc.h +++ b/src/util/misc.h @@ -27,7 +27,6 @@ namespace misc { QString get_day_suffix(int const day); -std::string get_trunc_first_line(std::string input, int const max_line_len); bool is_not_space(int ch); // Inline functions MUST be defined in header files if they are to be used in other files! diff --git a/src/util/passwordlineedit.h b/src/util/passwordlineedit.h index dd5cb9d..d45ec4e 100644 --- a/src/util/passwordlineedit.h +++ b/src/util/passwordlineedit.h @@ -38,10 +38,10 @@ class PasswordLineEdit : public QLineEdit { setFont(monospaced); QAction *action = addAction(QIcon(get_eye_icon(false)), QLineEdit::TrailingPosition); - button = qobject_cast(action->associatedWidgets().last()); - button->setCursor(QCursor(Qt::PointingHandCursor)); - connect(button, &QToolButton::pressed, this, &PasswordLineEdit::on_pressed, Qt::QueuedConnection); - connect(button, &QToolButton::released, this, &PasswordLineEdit::on_released, Qt::QueuedConnection); + m_eye_button = qobject_cast(action->associatedWidgets().last()); + m_eye_button->setCursor(QCursor(Qt::PointingHandCursor)); + connect(m_eye_button, &QToolButton::pressed, this, &PasswordLineEdit::on_pressed, Qt::QueuedConnection); + connect(m_eye_button, &QToolButton::released, this, &PasswordLineEdit::on_released, Qt::QueuedConnection); connect(InternalManager::instance(), &InternalManager::update_theme, this, &PasswordLineEdit::update_theme, Qt::QueuedConnection); @@ -50,7 +50,7 @@ class PasswordLineEdit : public QLineEdit { public slots: void update_theme() { - button->setIcon(QIcon(get_eye_icon(true))); + m_eye_button->setIcon(QIcon(get_eye_icon(true))); } private slots: @@ -69,7 +69,7 @@ private slots: } private: - QToolButton *button; + QToolButton *m_eye_button; QString get_eye_icon(bool const on) { diff --git a/src/util/runguard.cpp b/src/util/runguard.cpp index fa32e41..1053d3e 100644 --- a/src/util/runguard.cpp +++ b/src/util/runguard.cpp @@ -30,15 +30,15 @@ QString generate_key_hash(QString const &key, QString const &salt) } RunGuard::RunGuard(QString const &key) - : key(key), mem_lock_key(generate_key_hash(key, "_mem_lock_key")), - shared_mem_key(generate_key_hash(key, "_shared_mem_key")), shared_mem(shared_mem_key), mem_lock(mem_lock_key, 1) + : m_key(key), m_mem_lock_key(generate_key_hash(key, "_mem_lock_key")), + m_shared_mem_key(generate_key_hash(key, "_shared_mem_key")), m_shared_mem(m_shared_mem_key), m_mem_lock(m_mem_lock_key, 1) { - mem_lock.acquire(); + m_mem_lock.acquire(); { - QSharedMemory fix(shared_mem_key); // Fix for *nix: http://habrahabr.ru/post/173281/ + QSharedMemory fix(m_shared_mem_key); // Fix for *nix: http://habrahabr.ru/post/173281/ fix.attach(); } - mem_lock.release(); + m_mem_lock.release(); } RunGuard::~RunGuard() @@ -48,14 +48,14 @@ RunGuard::~RunGuard() bool RunGuard::is_another_running() { - if (shared_mem.isAttached()) + if (m_shared_mem.isAttached()) return false; - mem_lock.acquire(); - bool const isRunning = shared_mem.attach(); + m_mem_lock.acquire(); + bool const isRunning = m_shared_mem.attach(); if (isRunning) - shared_mem.detach(); - mem_lock.release(); + m_shared_mem.detach(); + m_mem_lock.release(); return isRunning; } @@ -65,9 +65,9 @@ bool RunGuard::try_to_run() if (is_another_running()) // Extra check. return false; - mem_lock.acquire(); - bool const result = shared_mem.create(sizeof(quint64)); - mem_lock.release(); + m_mem_lock.acquire(); + bool const result = m_shared_mem.create(sizeof(quint64)); + m_mem_lock.release(); if (!result) { release(); return false; @@ -78,8 +78,8 @@ bool RunGuard::try_to_run() void RunGuard::release() { - mem_lock.acquire(); - if (shared_mem.isAttached()) - shared_mem.detach(); - mem_lock.release(); + m_mem_lock.acquire(); + if (m_shared_mem.isAttached()) + m_shared_mem.detach(); + m_mem_lock.release(); } diff --git a/src/util/runguard.h b/src/util/runguard.h index 355f6d8..6df3891 100644 --- a/src/util/runguard.h +++ b/src/util/runguard.h @@ -23,7 +23,7 @@ class RunGuard { public: - RunGuard(QString const &key); + RunGuard(QString const &m_key); ~RunGuard(); bool is_another_running(); @@ -31,12 +31,12 @@ class RunGuard { void release(); private: - QString const key; - QString const mem_lock_key; - QString const shared_mem_key; + QString const m_key; + QString const m_mem_lock_key; + QString const m_shared_mem_key; - QSharedMemory shared_mem; - QSystemSemaphore mem_lock; + QSharedMemory m_shared_mem; + QSystemSemaphore m_mem_lock; Q_DISABLE_COPY(RunGuard) }; diff --git a/text/VERSION.txt b/text/VERSION.txt index b001d23..197c4d5 100644 --- a/text/VERSION.txt +++ b/text/VERSION.txt @@ -1 +1 @@ -2.3.12 +2.4.0 diff --git a/theoreticaldiary.pro b/theoreticaldiary.pro index 6b3800d..7cdd883 100644 --- a/theoreticaldiary.pro +++ b/theoreticaldiary.pro @@ -39,9 +39,12 @@ SOURCES += \ src/gui/diarymenu.cpp \ src/gui/diarypixels.cpp \ src/gui/diarystats.cpp \ + src/gui/emotionsreference.cpp \ + src/gui/gratitudeguide.cpp \ src/gui/mainmenu.cpp \ src/gui/mainwindow.cpp \ src/gui/optionsmenu.cpp \ + src/gui/rainguide.cpp \ src/gui/standaloneoptions.cpp \ src/gui/styles/base/basestyle.cpp \ src/gui/styles/base/phantomcolor.cpp \ @@ -68,9 +71,12 @@ HEADERS += \ src/gui/diarymenu.h \ src/gui/diarypixels.h \ src/gui/diarystats.h \ + src/gui/emotionsreference.h \ + src/gui/gratitudeguide.h \ src/gui/mainmenu.h \ src/gui/mainwindow.h \ src/gui/optionsmenu.h \ + src/gui/rainguide.h \ src/gui/standaloneoptions.h \ src/gui/styles/base/basestyle.h \ src/gui/styles/base/phantomcolor.h \ @@ -97,9 +103,12 @@ FORMS += \ src/gui/diarymenu.ui \ src/gui/diarypixels.ui \ src/gui/diarystats.ui \ + src/gui/emotionsreference.ui \ + src/gui/gratitudeguide.ui \ src/gui/mainmenu.ui \ src/gui/mainwindow.ui \ src/gui/optionsmenu.ui \ + src/gui/rainguide.ui \ src/gui/standaloneoptions.ui # Default rules for deployment. @@ -110,8 +119,8 @@ else: unix:!android: target.path = /usr/bin win32:RC_ICONS = images/windows_icons/icon.ico win32:VERSION = 1.0.0.0 win32:QMAKE_TARGET_COMPANY = someretical -win32:QMAKE_TARGET_PRODUCT = "TheoreticalDiary" -win32:QMAKE_TARGET_DESCRIPTION = "Digital diary." +win32:QMAKE_TARGET_PRODUCT = "Theoretical Diary" +win32:QMAKE_TARGET_DESCRIPTION = "Digital diary" win32:QMAKE_TARGET_COPYRIGHT = 2022 RESOURCES += \