- better UI
This commit is contained in:
parent
13e00590b1
commit
7cc4ce2b94
@ -1,14 +1,28 @@
|
||||
#include "connectdb_widget.h"
|
||||
#include "ui_connectdb_widget.h"
|
||||
|
||||
ConnectDbWidget::ConnectDbWidget(QWidget *parent) :
|
||||
ConnectDbWidget::ConnectDbWidget(const QString& message, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ConnectDbWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->mMessageLabel->setText(message);
|
||||
connect(ui->mButtonBox, SIGNAL(accepted()), this, SLOT(onOk()));
|
||||
connect(ui->mButtonBox, SIGNAL(rejected()), this, SLOT(onCancel()));
|
||||
connect(ui->mPasswordEdit, SIGNAL(returnPressed()), this, SLOT(onOk()));
|
||||
}
|
||||
|
||||
ConnectDbWidget::~ConnectDbWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ConnectDbWidget::onOk()
|
||||
{
|
||||
emit passwordEntered(ui->mPasswordEdit->text());
|
||||
}
|
||||
|
||||
void ConnectDbWidget::onCancel()
|
||||
{
|
||||
emit cancelled();
|
||||
}
|
||||
|
||||
@ -12,11 +12,19 @@ class ConnectDbWidget : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConnectDbWidget(QWidget *parent = nullptr);
|
||||
explicit ConnectDbWidget(const QString& msg = QString(), QWidget *parent = nullptr);
|
||||
~ConnectDbWidget();
|
||||
|
||||
private:
|
||||
Ui::ConnectDbWidget *ui;
|
||||
|
||||
public slots:
|
||||
void onOk();
|
||||
void onCancel();
|
||||
|
||||
signals:
|
||||
void passwordEntered(const QString& password);
|
||||
void cancelled();
|
||||
};
|
||||
|
||||
#endif // CONNECTDB_WIDGET_H
|
||||
|
||||
@ -10,10 +10,35 @@
|
||||
<height>114</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>400</width>
|
||||
<height>150</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="mMessageLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="mPasswordLabel">
|
||||
<property name="text">
|
||||
@ -25,7 +50,14 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="mPasswordEdit"/>
|
||||
<widget class="QLineEdit" name="mPasswordEdit">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="mButtonBox">
|
||||
|
||||
@ -26,13 +26,17 @@
|
||||
#include "finddialog.h"
|
||||
#include "startworkdialog.h"
|
||||
#include "stopworkdialog.h"
|
||||
#include "connectdb_widget.h"
|
||||
#include "openorcreatedb_widget.h"
|
||||
|
||||
#include <QDesktopWidget>
|
||||
#include <iostream>
|
||||
|
||||
#define SETTINGS mSettings->data()
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow), mPasswordFailed(false), mFindInTasksDlg(this), mDockRecentMenu(nullptr)
|
||||
mPasswordFailed(false), mFindInTasksDlg(this), mDockRecentMenu(nullptr)
|
||||
{
|
||||
mSettings = QSharedPointer<Settings>(new Settings());
|
||||
|
||||
@ -47,21 +51,30 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
mCurrentIntervalLabel = nullptr;
|
||||
mTrayIcon = nullptr;
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
// Hide Find line edit for now
|
||||
ui->mFindFrame->setVisible(false);
|
||||
helper::EscapeKeyEventFilter* eventFilter = new helper::EscapeKeyEventFilter(ui->mFindEdit);
|
||||
connect(eventFilter, SIGNAL(escapePressed(QObject*)), this, SLOT(findRejected(QObject*)));
|
||||
ui->mFindEdit->installEventFilter(eventFilter);
|
||||
|
||||
QCoreApplication::setApplicationName(APPNAME);
|
||||
//QCoreApplication::setOrganizationName(COMPANY);
|
||||
// Set this to your own appcast URL, of course
|
||||
FvUpdater::sharedUpdater()->SetFeedURL("http://satorilight.com/LittAppCast.xml");
|
||||
|
||||
initClient();
|
||||
QApplication::postEvent(this, new AttachDatabaseEvent());
|
||||
loadGeometry();
|
||||
|
||||
// Now check if database is already configured
|
||||
QWidget* centralWidget = new QWidget(this);
|
||||
setCentralWidget(centralWidget);
|
||||
centralWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
|
||||
// Check if database file exists
|
||||
QString path = helper::path::pathToDatabase();
|
||||
|
||||
if (mSettings->data()[KEY_DB_FILENAME_SPECIFIED].toBool())
|
||||
path = mSettings->data()[KEY_DB_FILENAME].toString();
|
||||
|
||||
QString folder = QFileInfo(path).absoluteDir().path();
|
||||
Storage::instance().setPath(path);
|
||||
|
||||
if (!QFile::exists(path))
|
||||
askNewDbPassword();
|
||||
else
|
||||
askDbPassword(QString());
|
||||
|
||||
this->setUpdatesEnabled(true);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -75,12 +88,14 @@ void MainWindow::attachDatabase()
|
||||
{
|
||||
// Open database
|
||||
QString path = helper::path::pathToDatabase();
|
||||
|
||||
if (mSettings->data()[KEY_DB_FILENAME_SPECIFIED].toBool())
|
||||
path = mSettings->data()[KEY_DB_FILENAME].toString();
|
||||
|
||||
QString folder = QFileInfo(path).absoluteDir().path();
|
||||
Storage::instance().setPath(path);
|
||||
|
||||
/*
|
||||
if (!QFile::exists(path))
|
||||
{
|
||||
QDir().mkpath(folder);
|
||||
@ -93,7 +108,6 @@ void MainWindow::attachDatabase()
|
||||
else
|
||||
{
|
||||
// See if there is stored password
|
||||
QString password;
|
||||
if (mSettings->data()[KEY_AUTOSAVE_PASSWORD].toBool() && mSettings->data()[KEY_PASSWORD].toString() != NOPASSWORDSTRING)
|
||||
password = mSettings->data()[KEY_PASSWORD].toString();
|
||||
else
|
||||
@ -102,26 +116,10 @@ void MainWindow::attachDatabase()
|
||||
connect(mPasswordDlg, SIGNAL(finished(int)), this, SLOT(passwordDialogFinished(int)));
|
||||
mPasswordDlg->show();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
this->setUpdatesEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::openDatabase(const QString &password)
|
||||
{
|
||||
Storage::instance().setKey(password);
|
||||
if (!Storage::instance().open())
|
||||
{
|
||||
mPasswordFailed = true;
|
||||
alertBox(tr("Error"), tr("Failed to open database"), AlertType_CannotOpen);
|
||||
}
|
||||
else
|
||||
if (mSettings->data()[KEY_AUTOSAVE_PASSWORD].toBool())
|
||||
{
|
||||
mSettings->data()[KEY_PASSWORD] = password;
|
||||
mSettings->save();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::connectUiToDatabase()
|
||||
{
|
||||
ui->mTaskTree->setModel(mTaskTreeModel = new TaskTreeModel(false));
|
||||
@ -172,10 +170,6 @@ void MainWindow::alertBox(const QString &title, const QString &text, AlertType a
|
||||
connect(mAlertBox, SIGNAL(finished(int)), this, SLOT(criticalAlertFinished(int)));
|
||||
break;
|
||||
|
||||
case AlertType_CannotOpen:
|
||||
connect(mAlertBox, SIGNAL(finished(int)), this, SLOT(openAlertFinished(int)));
|
||||
break;
|
||||
|
||||
case AlertType_Warning:
|
||||
connect(mAlertBox, SIGNAL(finished(int)), this, SLOT(warningAlertFinished(int)));
|
||||
break;
|
||||
@ -293,7 +287,7 @@ void MainWindow::save()
|
||||
|
||||
QSharedPointer<QByteArray> MainWindow::getUndoStack() const
|
||||
{
|
||||
QTextDocument* doc = ui->mNoteEdit->document();
|
||||
//QTextDocument* doc = ui->mNoteEdit->document();
|
||||
|
||||
return QSharedPointer<QByteArray>(new QByteArray());
|
||||
}
|
||||
@ -356,7 +350,7 @@ void MainWindow::loadGeometry()
|
||||
}
|
||||
|
||||
// Set splitter position
|
||||
if (settings.contains(KEY_SPLITTEROFFSET1) && settings.contains(KEY_SPLITTEROFFSET2))
|
||||
if (settings.contains(KEY_SPLITTEROFFSET1) && settings.contains(KEY_SPLITTEROFFSET2) && ui)
|
||||
{
|
||||
QList<int> sizes = ui->mSplitter->sizes();
|
||||
sizes[0] = settings.value(KEY_SPLITTEROFFSET1).toInt();
|
||||
@ -364,7 +358,7 @@ void MainWindow::loadGeometry()
|
||||
ui->mSplitter->setSizes(sizes);
|
||||
}
|
||||
|
||||
if (settings.contains(KEY_TIMESPLITTER_OFFSET1) && settings.contains(KEY_TIMESPLITTER_OFFSET2))
|
||||
if (settings.contains(KEY_TIMESPLITTER_OFFSET1) && settings.contains(KEY_TIMESPLITTER_OFFSET2) && ui)
|
||||
{
|
||||
QList<int> sizes = ui->mTimeSplitter->sizes();
|
||||
sizes[0] = settings.value(KEY_TIMESPLITTER_OFFSET1).toInt();
|
||||
@ -380,22 +374,24 @@ void MainWindow::sync()
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent * ev)
|
||||
{
|
||||
// Update DB if document was modified
|
||||
if (ui->mNoteEdit->document()->isModified())
|
||||
if (ui)
|
||||
{
|
||||
// See if there is active selection
|
||||
QModelIndex index = ui->mTaskTree->currentIndex();
|
||||
if (index.isValid())
|
||||
// Update DB if document was modified
|
||||
if (ui->mNoteEdit->document()->isModified())
|
||||
{
|
||||
PTask task = mTaskTreeModel->getTask(index);
|
||||
task->setHtml(ui->mNoteEdit->document()->toPlainText());
|
||||
task->save();
|
||||
// See if there is active selection
|
||||
QModelIndex index = ui->mTaskTree->currentIndex();
|
||||
if (index.isValid())
|
||||
{
|
||||
PTask task = mTaskTreeModel->getTask(index);
|
||||
task->setHtml(ui->mNoteEdit->document()->toPlainText());
|
||||
task->save();
|
||||
}
|
||||
}
|
||||
|
||||
if (!mPasswordFailed)
|
||||
save();
|
||||
}
|
||||
|
||||
if (!mPasswordFailed)
|
||||
save();
|
||||
|
||||
ev->accept();
|
||||
}
|
||||
|
||||
@ -804,6 +800,56 @@ void MainWindow::updateAttachmentsLabel(PTask t)
|
||||
mAttachmentsLabel->setText(text);
|
||||
}
|
||||
|
||||
void MainWindow::setupMainUi()
|
||||
{
|
||||
// Detach old widget
|
||||
setCentralWidget(nullptr);
|
||||
|
||||
// Construct main UI
|
||||
ui = new Ui::MainWindow();
|
||||
ui->setupUi(this);
|
||||
|
||||
// Hide Find line edit for now
|
||||
ui->mFindFrame->setVisible(false);
|
||||
helper::EscapeKeyEventFilter* eventFilter = new helper::EscapeKeyEventFilter(ui->mFindEdit);
|
||||
connect(eventFilter, SIGNAL(escapePressed(QObject*)), this, SLOT(findRejected(QObject*)));
|
||||
ui->mFindEdit->installEventFilter(eventFilter);
|
||||
|
||||
//QCoreApplication::setOrganizationName(COMPANY);
|
||||
// Set this to your own appcast URL, of course
|
||||
FvUpdater::sharedUpdater()->SetFeedURL("http://satorilight.com/LittAppCast.xml");
|
||||
|
||||
initClient();
|
||||
QApplication::postEvent(this, new AttachDatabaseEvent());
|
||||
}
|
||||
|
||||
// Ask password
|
||||
void MainWindow::askDbPassword(const QString& message)
|
||||
{
|
||||
setCentralWidget(nullptr); setCentralWidget(new QWidget(this));
|
||||
auto cdw = new ConnectDbWidget(message, centralWidget());
|
||||
connect(cdw, SIGNAL(passwordEntered(QString)), this, SLOT(onDbPasswordEntered(QString)));
|
||||
connect(cdw, SIGNAL(cancelled()), this, SLOT(onDbPasswordCancelled()));
|
||||
|
||||
QVBoxLayout* l = new QVBoxLayout(centralWidget());
|
||||
l->addWidget(cdw);
|
||||
l->setAlignment(Qt::AlignCenter);
|
||||
centralWidget()->setLayout(l);
|
||||
}
|
||||
|
||||
void MainWindow::askNewDbPassword()
|
||||
{
|
||||
setCentralWidget(nullptr); setCentralWidget(new QWidget(this));
|
||||
auto w = new OpenOrCreateDbWidget(centralWidget());
|
||||
connect(w, &OpenOrCreateDbWidget::databaseChanged, [this](const QString& path) { onDatabaseChanged(path); });
|
||||
connect(w, &OpenOrCreateDbWidget::passwordEntered, [this](const QString& password) { onNewDbPasswordEntered(password); });
|
||||
|
||||
auto l = new QVBoxLayout(centralWidget());
|
||||
l->addWidget(w);
|
||||
l->setAlignment(Qt::AlignCenter);
|
||||
centralWidget()->setLayout(l);
|
||||
}
|
||||
|
||||
void MainWindow::startOrStopTracking()
|
||||
{
|
||||
if (!mCurrentTask)
|
||||
@ -1351,61 +1397,12 @@ void MainWindow::showTimeReport()
|
||||
trz.exec();
|
||||
}
|
||||
|
||||
void MainWindow::newPasswordDialogFinished(int status)
|
||||
{
|
||||
if (status == QDialog::Accepted)
|
||||
{
|
||||
Storage::instance().setKey(mNewPasswordDlg->password());
|
||||
if (!Storage::instance().create())
|
||||
{
|
||||
// Quit application
|
||||
mPasswordFailed = true;
|
||||
alertBox(tr("Error"), tr("Failed to initialize database"), AlertType_Critical);
|
||||
}
|
||||
|
||||
// Remember password if it is specified in settings
|
||||
if (mSettings->data()[KEY_AUTOSAVE_PASSWORD].toBool())
|
||||
mSettings->data()[KEY_PASSWORD] = mNewPasswordDlg->password();
|
||||
else
|
||||
mSettings->data()[KEY_PASSWORD] = NOPASSWORDSTRING;
|
||||
|
||||
// Flush settings
|
||||
mSettings->save();
|
||||
|
||||
connectUiToDatabase();
|
||||
}
|
||||
else
|
||||
close();
|
||||
}
|
||||
|
||||
void MainWindow::passwordDialogFinished(int status)
|
||||
{
|
||||
QString password;
|
||||
if (status == QDialog::Accepted)
|
||||
{
|
||||
password = mPasswordDlg->password();
|
||||
openDatabase(password);
|
||||
connectUiToDatabase();
|
||||
}
|
||||
else
|
||||
{
|
||||
mPasswordFailed = false;
|
||||
QApplication::postEvent(this, new ClientCloseEvent());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::criticalAlertFinished(int /*status*/)
|
||||
{
|
||||
QApplication::postEvent(this, new ClientCloseEvent());
|
||||
}
|
||||
|
||||
void MainWindow::openAlertFinished(int /*status*/)
|
||||
{
|
||||
mPasswordDlg = new PasswordDlg(this);
|
||||
connect(mPasswordDlg, SIGNAL(finished(int)), this, SLOT(passwordDialogFinished(int)));
|
||||
mPasswordDlg->show();
|
||||
}
|
||||
|
||||
void MainWindow::warningAlertFinished(int /*status*/)
|
||||
{
|
||||
}
|
||||
@ -1618,3 +1615,72 @@ void MainWindow::trayWindowDestroyed(QObject *object)
|
||||
{
|
||||
mTrayWindow = nullptr;
|
||||
}
|
||||
|
||||
void MainWindow::onDbPasswordEntered(const QString& password)
|
||||
{
|
||||
if (mSettings->data()[KEY_AUTOSAVE_PASSWORD].toBool())
|
||||
{
|
||||
mSettings->data()[KEY_PASSWORD] = password;
|
||||
mSettings->save();
|
||||
}
|
||||
|
||||
Storage::instance().setKey(password);
|
||||
if (!Storage::instance().open())
|
||||
{
|
||||
askDbPassword(tr("Invalid password, please try again."));
|
||||
}
|
||||
else
|
||||
{
|
||||
setupMainUi();
|
||||
connectUiToDatabase();
|
||||
loadGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onDbPasswordCancelled()
|
||||
{
|
||||
askNewDbPassword();
|
||||
}
|
||||
|
||||
void MainWindow::onNewDbPasswordEntered(const QString& password)
|
||||
{
|
||||
if (mSettings->data()[KEY_AUTOSAVE_PASSWORD].toBool())
|
||||
{
|
||||
mSettings->data()[KEY_PASSWORD] = password;
|
||||
mSettings->save();
|
||||
}
|
||||
|
||||
Storage::instance().setKey(password);
|
||||
|
||||
// Remove old database
|
||||
::remove(Storage::instance().path().toStdString().c_str());
|
||||
|
||||
// Try to create new one
|
||||
if (!Storage::instance().create())
|
||||
{
|
||||
showFatal(tr("Failed to create new database. Exiting."));
|
||||
}
|
||||
else
|
||||
{
|
||||
setupMainUi();
|
||||
connectUiToDatabase();
|
||||
loadGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
askDbPassword();
|
||||
}
|
||||
|
||||
void MainWindow::showFatal(const QString& message)
|
||||
{
|
||||
std::cerr << message.toStdString() << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@ -28,185 +28,201 @@ class MainWindow;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *);
|
||||
void customEvent(QEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
void customEvent(QEvent *);
|
||||
|
||||
private:
|
||||
enum TrackingStopReason
|
||||
{
|
||||
TSR_None, // Used to init only
|
||||
TSR_Manual,
|
||||
TSR_Automatic
|
||||
};
|
||||
enum TrackingStopReason
|
||||
{
|
||||
TSR_None, // Used to init only
|
||||
TSR_Manual,
|
||||
TSR_Automatic
|
||||
};
|
||||
|
||||
QSharedPointer<Logger> mLogger;
|
||||
QSharedPointer<HIDActivityTracker> mActivityTracker;
|
||||
TrackingStopReason mStopReason;
|
||||
QSharedPointer<Logger> mLogger;
|
||||
QSharedPointer<HIDActivityTracker> mActivityTracker;
|
||||
TrackingStopReason mStopReason;
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
TaskTreeModel* mTaskTreeModel;
|
||||
PTask mCurrentTask, mAutomaticTask;
|
||||
QTimer* mUpdateTimer;
|
||||
QLabel* mModifiedLabel;
|
||||
QLabel* mCurrentIntervalLabel;
|
||||
QLabel* mDuplicationSignalLabel;
|
||||
QSystemTrayIcon *mTrayIcon;
|
||||
QSharedPointer<Settings> mSettings;
|
||||
bool mPasswordFailed;
|
||||
PasswordDlg* mPasswordDlg;
|
||||
NewPasswordDlg* mNewPasswordDlg;
|
||||
QMessageBox* mAlertBox;
|
||||
Ui::MainWindow *ui = nullptr;
|
||||
TaskTreeModel* mTaskTreeModel;
|
||||
PTask mCurrentTask, mAutomaticTask;
|
||||
QTimer* mUpdateTimer;
|
||||
QLabel* mModifiedLabel;
|
||||
QLabel* mCurrentIntervalLabel;
|
||||
QLabel* mDuplicationSignalLabel;
|
||||
QSystemTrayIcon *mTrayIcon;
|
||||
QSharedPointer<Settings> mSettings;
|
||||
bool mPasswordFailed;
|
||||
PasswordDlg* mPasswordDlg;
|
||||
NewPasswordDlg* mNewPasswordDlg;
|
||||
QMessageBox* mAlertBox;
|
||||
|
||||
// Time when current note was saved to DB last time
|
||||
QDateTime mLastTimelineFlush;
|
||||
// Time when current note was saved to DB last time
|
||||
QDateTime mLastTimelineFlush;
|
||||
|
||||
// Attachments action
|
||||
QAction* mAttachmentsAction;
|
||||
// Attachments action
|
||||
QAction* mAttachmentsAction;
|
||||
|
||||
// Attachments label
|
||||
QLabel* mAttachmentsLabel;
|
||||
// Attachments label
|
||||
QLabel* mAttachmentsLabel;
|
||||
|
||||
// Delegate to draw task items in custom way
|
||||
TaskItemDelegate mTaskItemDelegate;
|
||||
// Delegate to draw task items in custom way
|
||||
TaskItemDelegate mTaskItemDelegate;
|
||||
|
||||
// Find text in document start index
|
||||
int mFindStartIndex;
|
||||
QString mFindPattern;
|
||||
FindInTasksDialog mFindInTasksDlg;
|
||||
// Find text in document start index
|
||||
int mFindStartIndex;
|
||||
QString mFindPattern;
|
||||
FindInTasksDialog mFindInTasksDlg;
|
||||
|
||||
#ifdef TARGET_OSX
|
||||
SleepTracker mSleepTracker;
|
||||
SleepTracker mSleepTracker;
|
||||
#endif
|
||||
QSharedPointer<QByteArray> getUndoStack() const;
|
||||
int mTimeFrameHeight;
|
||||
QSharedPointer<QByteArray> getUndoStack() const;
|
||||
int mTimeFrameHeight;
|
||||
|
||||
QDateTime mTextModificationTime;
|
||||
std::deque<PTask> mRecentTrackingTasks;
|
||||
QMenu* mDockRecentMenu;
|
||||
QDialog* mTrayWindow = nullptr;
|
||||
QDateTime mTextModificationTime;
|
||||
std::deque<PTask> mRecentTrackingTasks;
|
||||
QMenu* mDockRecentMenu;
|
||||
QDialog* mTrayWindow = nullptr;
|
||||
QString mPassword = NOPASSWORDSTRING;
|
||||
|
||||
void saveGeometry();
|
||||
void loadGeometry();
|
||||
void applyTextFormat(const QTextCharFormat& fmt);
|
||||
void initClient();
|
||||
|
||||
// Checks if database exists, requests passwords etc.
|
||||
void attachDatabase();
|
||||
void saveGeometry();
|
||||
void loadGeometry();
|
||||
void applyTextFormat(const QTextCharFormat& fmt);
|
||||
void initClient();
|
||||
|
||||
// Just open database via Storage::instance()
|
||||
void openDatabase(const QString& password);
|
||||
// Checks if database exists, requests passwords etc.
|
||||
void attachDatabase();
|
||||
|
||||
// Creates task tree model, adjusts UI
|
||||
void connectUiToDatabase();
|
||||
// Just open database via Storage::instance()
|
||||
void openDatabase(const QString& password);
|
||||
|
||||
// Shows window with alert text and button OK
|
||||
enum AlertType
|
||||
{
|
||||
AlertType_Warning,
|
||||
AlertType_Critical,
|
||||
AlertType_CannotOpen
|
||||
};
|
||||
// Creates task tree model, adjusts UI
|
||||
void connectUiToDatabase();
|
||||
|
||||
void alertBox(const QString& title, const QString& text, AlertType alertType);
|
||||
// Shows window with alert text and button OK
|
||||
enum AlertType
|
||||
{
|
||||
AlertType_Warning,
|
||||
AlertType_Critical,
|
||||
AlertType_CannotOpen
|
||||
};
|
||||
|
||||
void showTimeForSelectedTask();
|
||||
void showTimeForTrackingTask();
|
||||
void initTrayIcon();
|
||||
void removeTrayIcon();
|
||||
void alertBox(const QString& title, const QString& text, AlertType alertType);
|
||||
|
||||
enum TrayShowMessage
|
||||
{
|
||||
Tray_ShowMessage = 0,
|
||||
Tray_SkipMessage = 1
|
||||
};
|
||||
void updateTrayIcon(TrayShowMessage flag);
|
||||
void handleTrackableState(PTask task);
|
||||
void trayContextualMenu();
|
||||
int showTrayWindow(QDialog* dlg);
|
||||
void installDockMenu();
|
||||
void startTracking(PTask t);
|
||||
void prepareRecentTasksMenu(QMenu* submenu);
|
||||
void updateAttachmentsLabel(PTask t);
|
||||
void showTimeForSelectedTask();
|
||||
void showTimeForTrackingTask();
|
||||
void initTrayIcon();
|
||||
void removeTrayIcon();
|
||||
|
||||
enum TrayShowMessage
|
||||
{
|
||||
Tray_ShowMessage = 0,
|
||||
Tray_SkipMessage = 1
|
||||
};
|
||||
void updateTrayIcon(TrayShowMessage flag);
|
||||
void handleTrackableState(PTask task);
|
||||
void trayContextualMenu();
|
||||
int showTrayWindow(QDialog* dlg);
|
||||
void installDockMenu();
|
||||
void startTracking(PTask t);
|
||||
void prepareRecentTasksMenu(QMenu* submenu);
|
||||
void updateAttachmentsLabel(PTask t);
|
||||
|
||||
// Builds main UI layut
|
||||
void setupMainUi();
|
||||
|
||||
// Show UI to ask password for existing DB
|
||||
void askDbPassword(const QString& message = QString(""));
|
||||
|
||||
// Show UI to ask password for new database (or select existing database file)
|
||||
void askNewDbPassword();
|
||||
|
||||
// Show UI about fatal alert & button to quit app
|
||||
void showFatal(const QString& message);
|
||||
|
||||
signals:
|
||||
void onTimeFormatChanged();
|
||||
void onTimeChanged();
|
||||
void onTimeFormatChanged();
|
||||
void onTimeChanged();
|
||||
|
||||
public slots:
|
||||
void save();
|
||||
void sync();
|
||||
void about();
|
||||
void preferences();
|
||||
void print();
|
||||
void quit();
|
||||
void newRootTask();
|
||||
void newTask();
|
||||
void newSibling();
|
||||
void moveUp();
|
||||
void moveDown();
|
||||
void renameTask();
|
||||
void deleteTask();
|
||||
void taskTreeContextualMenu(const QPoint& point);
|
||||
void taskIndexChanged(const QModelIndex&, const QModelIndex&);
|
||||
void idleDetected();
|
||||
void activityDetected();
|
||||
void startOrStopTracking();
|
||||
void startTracking();
|
||||
void startTrackingRecent();
|
||||
void save();
|
||||
void sync();
|
||||
void about();
|
||||
void preferences();
|
||||
void print();
|
||||
void quit();
|
||||
void newRootTask();
|
||||
void newTask();
|
||||
void newSibling();
|
||||
void moveUp();
|
||||
void moveDown();
|
||||
void renameTask();
|
||||
void deleteTask();
|
||||
void taskTreeContextualMenu(const QPoint& point);
|
||||
void taskIndexChanged(const QModelIndex&, const QModelIndex&);
|
||||
void idleDetected();
|
||||
void activityDetected();
|
||||
void startOrStopTracking();
|
||||
void startTracking();
|
||||
void startTrackingRecent();
|
||||
|
||||
void stopTracking(TrackingStopReason reason, time_t current_utc = time(nullptr));
|
||||
void updateData();
|
||||
void add10Mins();
|
||||
void stopTracking(TrackingStopReason reason, time_t current_utc = time(nullptr));
|
||||
void updateData();
|
||||
void add10Mins();
|
||||
|
||||
void editSelectionChanged();
|
||||
void editPositionChanged();
|
||||
void editFormatChanged(const QTextCharFormat& fmt);
|
||||
void editSelectionChanged();
|
||||
void editPositionChanged();
|
||||
void editFormatChanged(const QTextCharFormat& fmt);
|
||||
|
||||
void editUndo();
|
||||
void editRedo();
|
||||
void editCut();
|
||||
void editCopy();
|
||||
void editPaste();
|
||||
void editDelete();
|
||||
void editSelectAll();
|
||||
void editUndo();
|
||||
void editRedo();
|
||||
void editCut();
|
||||
void editCopy();
|
||||
void editPaste();
|
||||
void editDelete();
|
||||
void editSelectAll();
|
||||
|
||||
void iconActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
void timeFormatChanged();
|
||||
void showTimeline();
|
||||
void showTimeReport();
|
||||
void iconActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
void timeFormatChanged();
|
||||
void showTimeline();
|
||||
void showTimeReport();
|
||||
|
||||
void newPasswordDialogFinished(int status);
|
||||
void passwordDialogFinished(int status);
|
||||
void criticalAlertFinished(int status);
|
||||
void openAlertFinished(int status);
|
||||
void warningAlertFinished(int status);
|
||||
void toolbarVisibilityChanged(bool visible);
|
||||
void showHideToolbar();
|
||||
void showAttachments();
|
||||
void checkForUpdates();
|
||||
void systemSleep();
|
||||
void systemResume();
|
||||
void changeTimeTrackableFlag(bool trackable);
|
||||
void find();
|
||||
void findInTasks();
|
||||
void findRequested();
|
||||
void findRejected(QObject* obj);
|
||||
void taskTextChanged();
|
||||
void taskMoved(PTask task);
|
||||
void focusTaskTree();
|
||||
void focusTaskText();
|
||||
void showMainWindow();
|
||||
void continueOnIdle();
|
||||
void breakOnIdle(const QDateTime& stopTime);
|
||||
void startOnActivity();
|
||||
void stopOnActivity();
|
||||
void trayWindowDestroyed(QObject* object);
|
||||
void criticalAlertFinished(int status);
|
||||
void warningAlertFinished(int status);
|
||||
void toolbarVisibilityChanged(bool visible);
|
||||
void showHideToolbar();
|
||||
void showAttachments();
|
||||
void checkForUpdates();
|
||||
void systemSleep();
|
||||
void systemResume();
|
||||
void changeTimeTrackableFlag(bool trackable);
|
||||
void find();
|
||||
void findInTasks();
|
||||
void findRequested();
|
||||
void findRejected(QObject* obj);
|
||||
void taskTextChanged();
|
||||
void taskMoved(PTask task);
|
||||
void focusTaskTree();
|
||||
void focusTaskText();
|
||||
void showMainWindow();
|
||||
void continueOnIdle();
|
||||
void breakOnIdle(const QDateTime& stopTime);
|
||||
void startOnActivity();
|
||||
void stopOnActivity();
|
||||
void trayWindowDestroyed(QObject* object);
|
||||
|
||||
void onDbPasswordEntered(const QString& password);
|
||||
void onDbPasswordCancelled();
|
||||
void onNewDbPasswordEntered(const QString& password);
|
||||
void onDatabaseChanged(const QString& path);
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
@ -1,14 +1,55 @@
|
||||
#include "openorcreatedb_widget.h"
|
||||
#include "ui_openorcreatedb_widget.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
OpenOrCreateDbWidget::OpenOrCreateDbWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::OpenOrCreateDbWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->mNewPasswordEdit1, &QLineEdit::returnPressed, [this]() { ui->mNewPasswordEdit2->setFocus(); });
|
||||
connect(ui->mNewPasswordEdit2, &QLineEdit::returnPressed, [this]() { handleEnteredPasswords(); });
|
||||
connect(ui->mSelectDatabaseButton, &QPushButton::clicked, [this]() { askForDatabase(); });
|
||||
connect(ui->mDialogButtonBox, &QDialogButtonBox::accepted, [this]()
|
||||
{
|
||||
if (mDbPath.isEmpty())
|
||||
handleEnteredPasswords();
|
||||
else
|
||||
emit databaseChanged(ui->mSelectedDbLabel->text());
|
||||
});
|
||||
}
|
||||
|
||||
OpenOrCreateDbWidget::~OpenOrCreateDbWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void OpenOrCreateDbWidget::handleEnteredPasswords()
|
||||
{
|
||||
if (ui->mNewPasswordEdit1->text().isEmpty() && ui->mNewPasswordEdit2->text().isEmpty())
|
||||
{
|
||||
ui->mMessageLabel->setText("Password can't be empty. Please try again!");
|
||||
}
|
||||
if (ui->mNewPasswordEdit1->text() == ui->mNewPasswordEdit2->text())
|
||||
emit passwordEntered(ui->mNewPasswordEdit1->text());
|
||||
else
|
||||
{
|
||||
ui->mNewPasswordEdit1->setText("");
|
||||
ui->mNewPasswordEdit2->setText("");
|
||||
ui->mNewPasswordEdit1->setFocus();
|
||||
ui->mMessageLabel->setText("Passwords are not the same. Please try again!");
|
||||
}
|
||||
}
|
||||
|
||||
void OpenOrCreateDbWidget::askForDatabase()
|
||||
{
|
||||
QString path = QFileDialog::getOpenFileName(this, "Please select existing database", QString(), "*.litt");
|
||||
if (path.size())
|
||||
{
|
||||
mDbPath = path;
|
||||
ui->mSelectedDbLabel->setText(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,14 @@ public:
|
||||
|
||||
private:
|
||||
Ui::OpenOrCreateDbWidget *ui;
|
||||
|
||||
QString mDbPath;
|
||||
void handleEnteredPasswords();
|
||||
void askForDatabase();
|
||||
|
||||
signals:
|
||||
void databaseChanged(const QString& path);
|
||||
void passwordEntered(const QString& password);
|
||||
};
|
||||
|
||||
#endif // OPENORCREATEDB_WIDGET_H
|
||||
|
||||
@ -6,10 +6,22 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>549</width>
|
||||
<height>384</height>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>400</width>
|
||||
<height>400</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
@ -59,6 +71,16 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="mMessageLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
@ -106,7 +128,7 @@
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::Ok|QDialogButtonBox::Reset</set>
|
||||
</property>
|
||||
<property name="centerButtons">
|
||||
<bool>true</bool>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user