- more work on refactoring
This commit is contained in:
parent
f7c4ecc63b
commit
a0e9d2e601
@ -142,7 +142,7 @@ target_include_directories(${EXE_NAME} SYSTEM BEFORE
|
|||||||
#PUBLIC ${UUID_INCLUDE}
|
#PUBLIC ${UUID_INCLUDE}
|
||||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/sqlitecpp/include
|
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/sqlitecpp/include
|
||||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/sqlitecpp/sqlite3/include
|
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/sqlitecpp/sqlite3/include
|
||||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../lib/openssl/include
|
PUBLIC ${OPENSSL_INCLUDE}
|
||||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../lib/uuid/include
|
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../lib/uuid/include
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -164,8 +164,7 @@ endif()
|
|||||||
target_link_libraries(${EXE_NAME}
|
target_link_libraries(${EXE_NAME}
|
||||||
SQLiteCpp
|
SQLiteCpp
|
||||||
qtkeychain
|
qtkeychain
|
||||||
#${UUID_LIB}
|
${UUID_LIB}
|
||||||
uuid
|
|
||||||
${OPENSSL_CRYPTO}
|
${OPENSSL_CRYPTO}
|
||||||
Qt5::Core Qt5::Widgets Qt5::PrintSupport Qt5::OpenGL # Qt
|
Qt5::Core Qt5::Widgets Qt5::PrintSupport Qt5::OpenGL # Qt
|
||||||
${PLATFORM_LIBS} # System specific libraries
|
${PLATFORM_LIBS} # System specific libraries
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
#include "browserwidget.h"
|
#include "browserwidget.h"
|
||||||
#include "ui_browserwidget.h"
|
#include "ui_browserwidget.h"
|
||||||
|
|
||||||
|
#include "tasktreemodel.h"
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
BrowserWidget::BrowserWidget(QWidget *parent) :
|
BrowserWidget::BrowserWidget(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::BrowserWidget)
|
ui(new Ui::BrowserWidget)
|
||||||
@ -13,7 +16,7 @@ BrowserWidget::~BrowserWidget()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWidget::newRootTask()
|
void BrowserWidget::onNewRootTask()
|
||||||
{
|
{
|
||||||
PTask rootTask = mTaskTreeModel->addTask(QModelIndex(), Storage::instance().topOfTaskTree().size());
|
PTask rootTask = mTaskTreeModel->addTask(QModelIndex(), Storage::instance().topOfTaskTree().size());
|
||||||
QModelIndex rootIndex = mTaskTreeModel->getIndex(rootTask);
|
QModelIndex rootIndex = mTaskTreeModel->getIndex(rootTask);
|
||||||
@ -21,7 +24,7 @@ void BrowserWidget::newRootTask()
|
|||||||
ui->mTaskTree->edit(rootIndex);
|
ui->mTaskTree->edit(rootIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWidget::newTask()
|
void BrowserWidget::onNewTask()
|
||||||
{
|
{
|
||||||
QModelIndex index = ui->mTaskTree->currentIndex();
|
QModelIndex index = ui->mTaskTree->currentIndex();
|
||||||
if (index.isValid())
|
if (index.isValid())
|
||||||
@ -39,7 +42,7 @@ void BrowserWidget::newTask()
|
|||||||
ui->mTaskTree->edit(childIndex);
|
ui->mTaskTree->edit(childIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWidget::newSibling()
|
void BrowserWidget::onNewSibling()
|
||||||
{
|
{
|
||||||
QModelIndex index = ui->mTaskTree->currentIndex();
|
QModelIndex index = ui->mTaskTree->currentIndex();
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
@ -55,7 +58,7 @@ void BrowserWidget::newSibling()
|
|||||||
ui->mTaskTree->edit(i);
|
ui->mTaskTree->edit(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWidget::moveUp()
|
void BrowserWidget::onMoveUp()
|
||||||
{
|
{
|
||||||
QModelIndex index = ui->mTaskTree->currentIndex();
|
QModelIndex index = ui->mTaskTree->currentIndex();
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
@ -72,7 +75,7 @@ void BrowserWidget::moveUp()
|
|||||||
ui->mTaskTree->setCurrentIndex(mTaskTreeModel->getIndex(currentTask));
|
ui->mTaskTree->setCurrentIndex(mTaskTreeModel->getIndex(currentTask));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWidget::moveDown()
|
void BrowserWidget::onMoveDown()
|
||||||
{
|
{
|
||||||
QModelIndex index = ui->mTaskTree->currentIndex();
|
QModelIndex index = ui->mTaskTree->currentIndex();
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
@ -95,14 +98,14 @@ void BrowserWidget::moveDown()
|
|||||||
ui->mTaskTree->setCurrentIndex(mTaskTreeModel->getIndex(currentTask));
|
ui->mTaskTree->setCurrentIndex(mTaskTreeModel->getIndex(currentTask));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWidget::renameTask()
|
void BrowserWidget::onRenameTask()
|
||||||
{
|
{
|
||||||
QModelIndex index = ui->mTaskTree->currentIndex();
|
QModelIndex index = ui->mTaskTree->currentIndex();
|
||||||
if (index.isValid())
|
if (index.isValid())
|
||||||
ui->mTaskTree->edit(index);
|
ui->mTaskTree->edit(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWidget::deleteTask()
|
void BrowserWidget::onDeleteTask()
|
||||||
{
|
{
|
||||||
QModelIndex index = ui->mTaskTree->currentIndex();
|
QModelIndex index = ui->mTaskTree->currentIndex();
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
@ -135,3 +138,22 @@ void BrowserWidget::deleteTask()
|
|||||||
mTaskTreeModel->deleteTask(ui->mTaskTree->currentIndex());
|
mTaskTreeModel->deleteTask(ui->mTaskTree->currentIndex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BrowserWidget::alertBox(const QString &title, const QString &text, AlertType alertType)
|
||||||
|
{
|
||||||
|
mAlertBox = new QMessageBox(alertType == AlertType_Critical ? QMessageBox::Critical : QMessageBox::Warning,
|
||||||
|
title, text, QMessageBox::Ok, this,
|
||||||
|
Qt::Sheet);
|
||||||
|
switch (alertType)
|
||||||
|
{
|
||||||
|
case AlertType_Critical:
|
||||||
|
connect(mAlertBox, SIGNAL(finished(int)), this, SLOT(criticalAlertFinished(int)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AlertType_Warning:
|
||||||
|
connect(mAlertBox, SIGNAL(finished(int)), this, SLOT(warningAlertFinished(int)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
mAlertBox->show();
|
||||||
|
}
|
||||||
|
|||||||
@ -3,10 +3,16 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "task.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class BrowserWidget;
|
class BrowserWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TaskTreeModel;
|
||||||
|
class QMessageBox;
|
||||||
|
|
||||||
class BrowserWidget : public QWidget
|
class BrowserWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -17,16 +23,40 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::BrowserWidget *ui;
|
Ui::BrowserWidget *ui;
|
||||||
|
TaskTreeModel* mTaskTreeModel = nullptr;
|
||||||
|
PTask mCurrentTask, mAutomaticTask;
|
||||||
|
QSharedPointer<Settings> mSettings;
|
||||||
|
QMessageBox* mAlertBox = nullptr;
|
||||||
|
|
||||||
|
enum AlertType
|
||||||
|
{
|
||||||
|
AlertType_Warning,
|
||||||
|
AlertType_Critical,
|
||||||
|
AlertType_CannotOpen
|
||||||
|
};
|
||||||
|
void alertBox(const QString &title, const QString &text, AlertType alertType);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
// Called when new root task has to be created. It will create both task in DB and UI.
|
||||||
void onNewRootTask();
|
void onNewRootTask();
|
||||||
void onNewTask();
|
|
||||||
void onNewSibling();
|
|
||||||
void onMoveUp();
|
|
||||||
void onMoveDown();
|
|
||||||
void onRenameTask();
|
|
||||||
void onDeleteTask();
|
|
||||||
|
|
||||||
|
// Called when new task has to be created.
|
||||||
|
void onNewTask();
|
||||||
|
|
||||||
|
// Called when new sibling is requested.
|
||||||
|
void onNewSibling();
|
||||||
|
|
||||||
|
// Called when node is moved up
|
||||||
|
void onMoveUp();
|
||||||
|
|
||||||
|
// Called when node is moved down
|
||||||
|
void onMoveDown();
|
||||||
|
|
||||||
|
// Called when node is to be renamed
|
||||||
|
void onRenameTask();
|
||||||
|
|
||||||
|
// Called when node has to be deleted
|
||||||
|
void onDeleteTask();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BROWSERWIDGET_H
|
#endif // BROWSERWIDGET_H
|
||||||
|
|||||||
@ -9,6 +9,47 @@ int main(int argc, char *argv[])
|
|||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
helper::theme::applyCurrent(Settings::instance());
|
helper::theme::applyCurrent(Settings::instance());
|
||||||
|
|
||||||
|
// Check if database / password are available
|
||||||
|
QString path = helper::path::pathToDatabase();
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// Check if file exists at all
|
||||||
|
if (!QFile::exists(path))
|
||||||
|
{
|
||||||
|
// Show dialog that requests database path
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Check if password is available
|
||||||
|
if (mSettings->data()[KEY_AUTOSAVE_PASSWORD].toBool())
|
||||||
|
{
|
||||||
|
QString password = helper::password::load();
|
||||||
|
if (password.isEmpty())
|
||||||
|
{
|
||||||
|
// Ask about password
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Storage::instance().setKey(password);
|
||||||
|
if (!Storage::instance().open())
|
||||||
|
{
|
||||||
|
askDbPassword(tr("Invalid password, please try again."));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
QApplication::postEvent(this, new UiInitEvent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
askDbPassword(QString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.layout()->invalidate();
|
w.layout()->invalidate();
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include "helper.h"
|
#include "helper.h"
|
||||||
#include "newpassworddlg.h"
|
#include "newpassworddlg.h"
|
||||||
#include "passworddlg.h"
|
#include "passworddlg.h"
|
||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QPrinter>
|
#include <QPrinter>
|
||||||
#include <QPrintDialog>
|
#include <QPrintDialog>
|
||||||
@ -13,6 +14,7 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "appevents.h"
|
#include "appevents.h"
|
||||||
#include "preferencesdlg.h"
|
#include "preferencesdlg.h"
|
||||||
@ -62,14 +64,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
|
|
||||||
loadGeometry();
|
loadGeometry();
|
||||||
|
|
||||||
// Now check if database is already configured
|
|
||||||
mStackedViews = new QStackedWidget(this);
|
|
||||||
setCentralWidget(mStackedViews);
|
|
||||||
mStackedViews->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
|
||||||
buildMainView();
|
|
||||||
buildOpenOrCreateView();
|
|
||||||
buildPasswordView();
|
|
||||||
|
|
||||||
// Find default database file exists
|
// Find default database file exists
|
||||||
QString path = helper::path::pathToDatabase();
|
QString path = helper::path::pathToDatabase();
|
||||||
|
|
||||||
@ -852,7 +846,7 @@ void MainWindow::buildPasswordView()
|
|||||||
{
|
{
|
||||||
if (!mConnectDbWidget)
|
if (!mConnectDbWidget)
|
||||||
{
|
{
|
||||||
mConnectDbWidget = new ConnectDbWidget(message, mStackedViews);
|
mConnectDbWidget = new ConnectDbWidget(QString(), mStackedViews);
|
||||||
connect(mConnectDbWidget, SIGNAL(passwordEntered(QString)), this, SLOT(onDbPasswordEntered(QString)));
|
connect(mConnectDbWidget, SIGNAL(passwordEntered(QString)), this, SLOT(onDbPasswordEntered(QString)));
|
||||||
connect(mConnectDbWidget, SIGNAL(cancelled()), this, SLOT(onDbPasswordCancelled()));
|
connect(mConnectDbWidget, SIGNAL(cancelled()), this, SLOT(onDbPasswordCancelled()));
|
||||||
int index = mStackedViews->addWidget(mConnectDbWidget);
|
int index = mStackedViews->addWidget(mConnectDbWidget);
|
||||||
@ -865,9 +859,9 @@ void MainWindow::buildOpenOrCreateView()
|
|||||||
if (!mOpenOrCreateDbWidget)
|
if (!mOpenOrCreateDbWidget)
|
||||||
{
|
{
|
||||||
mOpenOrCreateDbWidget = new OpenOrCreateDbWidget(mStackedViews);
|
mOpenOrCreateDbWidget = new OpenOrCreateDbWidget(mStackedViews);
|
||||||
connect(w, &OpenOrCreateDbWidget::databaseChanged,
|
connect(mOpenOrCreateDbWidget, &OpenOrCreateDbWidget::databaseChanged,
|
||||||
[this](const QString& path) { onDatabaseChanged(path); });
|
[this](const QString& path) { onDatabaseChanged(path); });
|
||||||
connect(w, &OpenOrCreateDbWidget::passwordEntered,
|
connect(mOpenOrCreateDbWidget, &OpenOrCreateDbWidget::passwordEntered,
|
||||||
[this](const QString& password) { onNewDbPasswordEntered(password); });
|
[this](const QString& password) { onNewDbPasswordEntered(password); });
|
||||||
int index = mStackedViews->addWidget(mOpenOrCreateDbWidget);
|
int index = mStackedViews->addWidget(mOpenOrCreateDbWidget);
|
||||||
assert (index == ViewIndex_OpenOrCreateDb);
|
assert (index == ViewIndex_OpenOrCreateDb);
|
||||||
|
|||||||
@ -96,6 +96,7 @@ private:
|
|||||||
QDialog* mTrayWindow = nullptr;
|
QDialog* mTrayWindow = nullptr;
|
||||||
QString mPassword = NOPASSWORDSTRING;
|
QString mPassword = NOPASSWORDSTRING;
|
||||||
ConnectDbWidget* mConnectDbWidget = nullptr;
|
ConnectDbWidget* mConnectDbWidget = nullptr;
|
||||||
|
OpenOrCreateDbWidget* mOpenOrCreateDbWidget = nullptr;
|
||||||
|
|
||||||
QStackedWidget* mStackedViews = nullptr;
|
QStackedWidget* mStackedViews = nullptr;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user