From 5a328a75181fb9488ff9a71a48aff33b78613886 Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Thu, 18 Feb 2021 21:44:13 +0200 Subject: [PATCH] - fixes --- client/build-number/build_number.h | 2 +- client/connectdb_widget.cpp | 3 ++ client/connectdb_widget.ui | 34 ++++++++++-- client/helper.cpp | 4 ++ client/main.cpp | 7 +-- client/mainwindow.cpp | 86 +++++++++++++++--------------- client/mainwindow.ui | 24 +++++++-- client/preferencesdlg.cpp | 7 +-- client/preferencesdlg.ui | 7 --- client/settings.cpp | 15 ++++++ client/settings.h | 16 +++--- client/timetreemodel.cpp | 3 ++ 12 files changed, 128 insertions(+), 80 deletions(-) diff --git a/client/build-number/build_number.h b/client/build-number/build_number.h index 4951fd1..08382f1 100644 --- a/client/build-number/build_number.h +++ b/client/build-number/build_number.h @@ -1,2 +1,2 @@ // Auto generated file ! Please do not edit ! -#define APP_BUILD_NUMBER 113 \ No newline at end of file +#define APP_BUILD_NUMBER 154 \ No newline at end of file diff --git a/client/connectdb_widget.cpp b/client/connectdb_widget.cpp index 804cf64..d906599 100644 --- a/client/connectdb_widget.cpp +++ b/client/connectdb_widget.cpp @@ -1,5 +1,6 @@ #include "connectdb_widget.h" #include "ui_connectdb_widget.h" +#include ConnectDbWidget::ConnectDbWidget(const QString& message, QWidget *parent) : QWidget(parent), @@ -10,6 +11,8 @@ ConnectDbWidget::ConnectDbWidget(const QString& message, QWidget *parent) : connect(ui->mButtonBox, SIGNAL(accepted()), this, SLOT(onOk())); connect(ui->mButtonBox, SIGNAL(rejected()), this, SLOT(onCancel())); connect(ui->mPasswordEdit, SIGNAL(returnPressed()), this, SLOT(onOk())); + + this->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum); } ConnectDbWidget::~ConnectDbWidget() diff --git a/client/connectdb_widget.ui b/client/connectdb_widget.ui index 55fa31f..911c17f 100644 --- a/client/connectdb_widget.ui +++ b/client/connectdb_widget.ui @@ -6,10 +6,16 @@ 0 0 - 277 - 114 + 400 + 150 + + + 0 + 0 + + 200 @@ -18,8 +24,8 @@ - 400 - 150 + 160000 + 250 @@ -49,8 +55,26 @@ - + + + + 0 + 0 + + + + + 180 + 0 + + + + + 500 + 16777215 + + QLineEdit::Password diff --git a/client/helper.cpp b/client/helper.cpp index 0b3789b..5c692dd 100644 --- a/client/helper.cpp +++ b/client/helper.cpp @@ -245,6 +245,10 @@ QString path::pathToDatabaseTemplate() #ifdef TARGET_OSX return QCoreApplication::applicationDirPath() + "/../Resources/" + DATABASENAME; #endif + +#ifdef TARGET_LINUX + return QCoreApplication::applicationDirPath() + "/" + DATABASENAME; +#endif } QString path::pathToLog() diff --git a/client/main.cpp b/client/main.cpp index 6532792..7cb3586 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -11,12 +11,9 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); helper::theme::applyCurrent(Settings::instance()); - // Check if database / password are available - QString path = helper::path::pathToDatabase(); + // Path to database. + QString path = Settings::instance().getDatabasePath(); - // Find optional custom path to database - if (Settings::instance().data()[KEY_DB_FILENAME_SPECIFIED].toBool()) - path = Settings::instance().data()[KEY_DB_FILENAME].toString(); QString folder = QFileInfo(path).absoluteDir().path(); Storage::instance().setPath(path); diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp index 458ea17..cdc2c06 100644 --- a/client/mainwindow.cpp +++ b/client/mainwindow.cpp @@ -39,9 +39,9 @@ #define SETTINGS mSettings->data() -const int ViewIndex_Main = 0; -const int ViewIndex_OpenOrCreateDb = 1; -const int ViewIndex_DbPassword = 2; +const int ViewIndex_Main = 0; +const int ViewIndex_OpenOrCreateDb = 1; +const int ViewIndex_DbPassword = 2; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -80,15 +80,7 @@ MainWindow::~MainWindow() void MainWindow::attachDatabase() { // Find default database file exists - QString path = helper::path::pathToDatabase(); - - // Find optional custom path to database - if (mSettings->data()[KEY_DB_FILENAME_SPECIFIED].toBool()) - { - path = mSettings->data()[KEY_DB_FILENAME].toString(); - if (path.contains("~")) - path.replace("~", QDir::homePath()); - } + QString path = mSettings->getDatabasePath(); QString folder = QFileInfo(path).absoluteDir().path(); Storage::instance().setPath(path); @@ -173,6 +165,9 @@ void MainWindow::alertBox(const QString &title, const QString &text, AlertType a case AlertType_Warning: connect(mAlertBox, SIGNAL(finished(int)), this, SLOT(warningAlertFinished(int))); break; + + case AlertType_CannotOpen: + break; } mAlertBox->show(); @@ -181,7 +176,7 @@ void MainWindow::alertBox(const QString &title, const QString &text, AlertType a void MainWindow::initClient() { // Avoid double initialization - if (!mStackedViews->children().empty()) + if (mStackedViews->children().size() > 2) return; mFindStartIndex = 0; @@ -226,35 +221,39 @@ void MainWindow::initClient() connect(mActivityTracker.data(), SIGNAL(activityDetected()), this, SLOT(activityDetected())); // Configure toolbar - connect(ui->mMainToolbar, SIGNAL(visibilityChanged(bool)), this, SLOT(toolbarVisibilityChanged(bool))); - QWidget *spacerWidget = new QWidget(this); - spacerWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - spacerWidget->setVisible(true); - ui->mMainToolbar->addWidget(spacerWidget); + if (nullptr == mAttachmentsAction) + { + connect(ui->mMainToolbar, SIGNAL(visibilityChanged(bool)), this, SLOT(toolbarVisibilityChanged(bool))); + QWidget *spacerWidget = new QWidget(this); + spacerWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + spacerWidget->setVisible(true); + ui->mMainToolbar->addWidget(spacerWidget); - mAttachmentsAction = new QAction(this); - mAttachmentsAction->setIcon(QIcon(":/icons/icons/mail-attachment.png")); - mAttachmentsAction->setText(tr("Attachments")); - //ui->mMainToolbar->addAction(mAttachmentsAction); - connect(mAttachmentsAction, SIGNAL(triggered()), this, SLOT(showAttachments())); + mAttachmentsAction = new QAction(this); + mAttachmentsAction->setIcon(QIcon(":/icons/icons/mail-attachment.png")); + mAttachmentsAction->setText(tr("Attachments")); + //ui->mMainToolbar->addAction(mAttachmentsAction); + connect(mAttachmentsAction, SIGNAL(triggered()), this, SLOT(showAttachments())); - mAttachmentsLabel = new QLabel(this); - mAttachmentsLabel->setMargin(5); - mAttachmentsLabel->setOpenExternalLinks(false); - QFont f = mAttachmentsLabel->font(); - f.setUnderline(true); - mAttachmentsLabel->setFont(f); - mAttachmentsLabel->setTextFormat(Qt::RichText); - //mAttachmentsLabel->setStyleSheet("QLabel { color:rgb(142,178,218); }"); + mAttachmentsLabel = new QLabel(this); + mAttachmentsLabel->setMargin(5); + mAttachmentsLabel->setOpenExternalLinks(false); - QPalette newPal(palette()); - newPal.setColor(QPalette::Link, QColor(0x100, 0x100, 0x100)); - newPal.setColor(QPalette::LinkVisited, QColor(0x100, 0x100, 0x100)); - mAttachmentsLabel->setPalette(newPal); + QFont f = mAttachmentsLabel->font(); + f.setUnderline(true); + mAttachmentsLabel->setFont(f); + mAttachmentsLabel->setTextFormat(Qt::RichText); + //mAttachmentsLabel->setStyleSheet("QLabel { color:rgb(142,178,218); }"); - ui->mMainToolbar->addWidget(mAttachmentsLabel); - connect(mAttachmentsLabel, SIGNAL(linkActivated(QString)), this, SLOT(showAttachments())); - updateAttachmentsLabel(PTask()); + QPalette newPal(palette()); + newPal.setColor(QPalette::Link, QColor(0x100, 0x100, 0x100)); + newPal.setColor(QPalette::LinkVisited, QColor(0x100, 0x100, 0x100)); + mAttachmentsLabel->setPalette(newPal); + + ui->mMainToolbar->addWidget(mAttachmentsLabel); + connect(mAttachmentsLabel, SIGNAL(linkActivated(QString)), this, SLOT(showAttachments())); + updateAttachmentsLabel(PTask()); + } #ifdef TARGET_OSX mSleepTracker.install(); @@ -724,9 +723,9 @@ void MainWindow::taskIndexChanged(const QModelIndex& current, const QModelIndex& emit onTimeChanged(); // Set new timeline tree model - /*int w = ui->mTaskTimeTree->columnWidth(0); - ui->mTaskTimeTree->setModel(new TimeTreeModel(task->timeline(), *mSettings)); - ui->mTaskTimeTree->setColumnWidth(0, w);*/ + /* int w = ui->mTaskTimeTree->columnWidth(0); + ui->mTaskTimeTree->setModel(new TimeTreeModel(task->timeline(), *mSettings)); + ui->mTaskTimeTree->setColumnWidth(0, w); */ // Show or hide time table depending on type of loaded task handleTrackableState(task); @@ -876,7 +875,7 @@ void MainWindow::buildOpenOrCreateView() } // Ask password -void MainWindow::askDbPassword(const QString& message) +void MainWindow::askDbPassword(const QString& /*message*/) { if (mStackedViews) mStackedViews->setCurrentIndex(ViewIndex_DbPassword); @@ -1656,7 +1655,7 @@ void MainWindow::stopOnActivity() stopTracking(TSR_Manual); } -void MainWindow::trayWindowDestroyed(QObject *object) +void MainWindow::trayWindowDestroyed(QObject */*object*/) { mTrayWindow = nullptr; } @@ -1707,7 +1706,6 @@ void MainWindow::onNewDbPasswordEntered(const QString& password) void MainWindow::onDatabaseChanged(const QString& path) { // Bind to specific database - mSettings->data()[KEY_DB_FILENAME_SPECIFIED] = true; mSettings->data()[KEY_DB_FILENAME] = path; mSettings->save(); Storage::instance().setPath(path); diff --git a/client/mainwindow.ui b/client/mainwindow.ui index ea90a47..a3c8d6b 100644 --- a/client/mainwindow.ui +++ b/client/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 647 - 508 + 1206 + 522 @@ -253,8 +253,8 @@ 0 0 - 647 - 29 + 1206 + 22 @@ -1280,6 +1280,22 @@ + + mPreferencesAction + triggered() + MainWindow + preferences() + + + -1 + -1 + + + 323 + 253 + + + save() diff --git a/client/preferencesdlg.cpp b/client/preferencesdlg.cpp index 3cccc7c..85b3563 100644 --- a/client/preferencesdlg.cpp +++ b/client/preferencesdlg.cpp @@ -35,11 +35,7 @@ PreferencesDlg::PreferencesDlg(QWidget *parent, Settings& settings) : ui->mDarkThemeCheckbox->setChecked(settings.data().value(KEY_DARK_THEME).toBool()); // Use custom database path ? - ui->mCustomDatabaseFileCheckbox->setChecked(settings.data().value(KEY_DB_FILENAME_SPECIFIED).toBool()); - if (settings.data().value(KEY_DB_FILENAME_SPECIFIED).toBool()) - ui->mDatabaseLocation->setText(settings.data().value(KEY_DB_FILENAME).toString()); - else - ui->mDatabaseLocation->setText(helper::path::pathToDatabase()); + ui->mDatabaseLocation->setText(settings.data().value(KEY_DB_FILENAME).toString()); // Use stop on idle ? ui->mSmartStopTracking->setChecked(GET_BOOL(KEY_SMART_STOP)); @@ -83,7 +79,6 @@ void PreferencesDlg::accepted() mSettings.data()[KEY_SHOW_SECONDS] = ui->mShowSecondsCheckbox->isChecked(); mSettings.data()[KEY_ASK_BEFORE_DELETE] = ui->mAskBeforeDeleteCheckbox->isChecked(); - mSettings.data()[KEY_DB_FILENAME_SPECIFIED] = ui->mCustomDatabaseFileCheckbox->isChecked(); mSettings.data()[KEY_DB_FILENAME] = ui->mDatabaseLocation->text(); mSettings.data()[KEY_SMART_STOP] = ui->mSmartStopTracking->isChecked(); mSettings.data()[KEY_SMART_STOP_MINUTES] = ui->mSmartStopIntervalInMinutes->text().toInt(); diff --git a/client/preferencesdlg.ui b/client/preferencesdlg.ui index 55e57d4..7f9773d 100644 --- a/client/preferencesdlg.ui +++ b/client/preferencesdlg.ui @@ -58,13 +58,6 @@ - - - - Use database at custom location (requires app restart) - - - diff --git a/client/settings.cpp b/client/settings.cpp index 7699520..85b858b 100644 --- a/client/settings.cpp +++ b/client/settings.cpp @@ -56,6 +56,21 @@ void Settings::load() mData[KEY_SHOW_SECONDS] = true; } +QString Settings::getDatabasePath() +{ + // Path to settings file + QString path = helper::path::pathToSettings(); + + QString stored_path = data()[KEY_DB_FILENAME].toString(); + if (!stored_path.isEmpty()) + path = stored_path; + + if (path.contains("~")) + path.replace("~", QDir::homePath()); + + return path; +} + static Settings* GInstance = nullptr; Settings& Settings::instance() { diff --git a/client/settings.h b/client/settings.h index d59b290..adb1261 100644 --- a/client/settings.h +++ b/client/settings.h @@ -10,7 +10,6 @@ #define KEY_PASSWORD "Password" #define KEY_SHOW_SECONDS "ShowSeconds" #define KEY_DB_FILENAME "DbFilename" -#define KEY_DB_FILENAME_SPECIFIED "DbFilenameSpecified" #define KEY_TIMECOUNTER_TYPE "TimecounterType" #define KEY_LEFT "Left" @@ -47,17 +46,18 @@ class Settings { public: - Settings(); - ~Settings(); + Settings(); + ~Settings(); - void load(); - void save(); - QVariantMap& data(); + void load(); + void save(); + QVariantMap& data(); - static Settings& instance(); + QString getDatabasePath(); + static Settings& instance(); protected: - QVariantMap mData; + QVariantMap mData; }; #endif // SETTINGS_H diff --git a/client/timetreemodel.cpp b/client/timetreemodel.cpp index 8495175..2375726 100644 --- a/client/timetreemodel.cpp +++ b/client/timetreemodel.cpp @@ -372,6 +372,9 @@ TimeRecord TimeTreeModel::findInterval(const QModelIndex &index) case Level_Time: mTimeLine->getTime(year, month, day, &intervals); return intervals[index.row()]; + + default: + return TimeRecord(); } }