diff --git a/client/attachmentslist.cpp b/client/attachmentslist.cpp index 9f3fdc4..f95d6a6 100644 --- a/client/attachmentslist.cpp +++ b/client/attachmentslist.cpp @@ -7,253 +7,261 @@ #include AttachmentsListModel::AttachmentsListModel(PTask task, ChangesHistory& history, const AttachmentArray &items, QObject *parent) - :QAbstractListModel(parent), mTask(task), mHistory(history), mData(items) + :QAbstractListModel(parent), mTask(task), mHistory(history), mData(items) { } int AttachmentsListModel::rowCount(const QModelIndex &parent) const { - return mData.size(); + return mData.size(); } QVariant AttachmentsListModel::data(const QModelIndex& index, int role) const { - // Check that the index is valid and within the correct range first: - if (!index.isValid()) - return QVariant(); - if (index.row() >= mData.size()) - return QVariant(); + // Check that the index is valid and within the correct range first: + if (!index.isValid()) + return QVariant(); + if (index.row() >= mData.size()) + return QVariant(); - if (role == Qt::DisplayRole || role == Qt::EditRole) - { - // Only returns something for the roles you support (DisplayRole is a minimum) - return QVariant(mData.at(index.row())->filename()); - } - else - if (role == Qt::DecorationRole) - { - QFileInfo fi(mData.at(index.row())->filename()); - QIcon icon = mIconProvider.icon(fi); - return QVariant(icon); - } - else - return QVariant(); + if (role == Qt::DisplayRole || role == Qt::EditRole) + { + // Only returns something for the roles you support (DisplayRole is a minimum) + return QVariant(mData.at(index.row())->filename()); + } + else + if (role == Qt::DecorationRole) + { + QFileInfo fi(mData.at(index.row())->filename()); + QIcon icon = mIconProvider.icon(fi); + return QVariant(icon); + } + else + return QVariant(); } Qt::ItemFlags AttachmentsListModel::flags(const QModelIndex &index) const { - Qt::ItemFlags result = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;// | Qt::ItemIsDropEnabled; - //if (index.isValid()) - // result |= Qt::ItemIsDragEnabled; + Qt::ItemFlags result = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;// | Qt::ItemIsDropEnabled; + //if (index.isValid()) + // result |= Qt::ItemIsDragEnabled; - return result; + return result; } bool AttachmentsListModel::setData(const QModelIndex &index, const QVariant &value, int role /* = Qt::EditRole */) { - PAttachment att = itemAt(index.row()); - switch (role) - { - case Qt::DisplayRole: - case Qt::EditRole: - MAKE_ACTION(new RenameAttachmentAction(mTask, att, value.toString())); - break; - } - return true; + PAttachment att = itemAt(index.row()); + switch (role) + { + case Qt::DisplayRole: + case Qt::EditRole: + MAKE_ACTION(new RenameAttachmentAction(mTask, att, value.toString())); + break; + } + return true; } void AttachmentsListModel::addItem(PAttachment att, int index) { - if (index == -1) - { - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - mData.push_back(att); - endInsertRows(); - } - else - { - beginInsertRows(QModelIndex(), index, index); - mData.insert(mData.begin() + index, att); - endInsertRows(); - } + if (index == -1) + { + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + mData.push_back(att); + endInsertRows(); + } + else + { + beginInsertRows(QModelIndex(), index, index); + mData.insert(mData.begin() + index, att); + endInsertRows(); + } } void AttachmentsListModel::removeItem(int row) { - beginRemoveRows(QModelIndex(), row, row); - mData.erase(mData.begin() + row); - endRemoveRows(); + beginRemoveRows(QModelIndex(), row, row); + mData.erase(mData.begin() + row); + endRemoveRows(); } PAttachment AttachmentsListModel::itemAt(int row) const { - return mData[row]; + return mData[row]; } int AttachmentsListModel::findRow(PAttachment att) const { - return mData.indexOf(att); + return mData.indexOf(att); } AttachmentsList::AttachmentsList(QWidget *parent) : - QWidget(parent), - ui(new Ui::AttachmentsList) + QWidget(parent), + ui(new Ui::AttachmentsList) { - ui->setupUi(this); + ui->setupUi(this); } AttachmentsList::~AttachmentsList() { - delete ui; + delete ui; } -void AttachmentsList::setTask(PTask task) +void AttachmentsList::setTask(const PTask& task) { - mTask = task; - AttachmentArray aa; - Storage::instance().loadAttachments(mTask, aa); + if (mTask != task) + { + mTask = task; + AttachmentArray aa; + Storage::instance().loadAttachments(mTask, aa); - // Create model - mModel = new AttachmentsListModel(mTask, mHistory, aa); + // Create model + mModel = new AttachmentsListModel(mTask, mHistory, aa); - // Set model to history - mHistory.setAttachmentsModel(mModel); + // Set model to history + mHistory.setAttachmentsModel(mModel); - // Set model to list view - ui->mListView->setModel(mModel); + // Set model to list view + ui->mListView->setModel(mModel); + } +} + +PTask AttachmentsList::task() const +{ + return mTask; } void AttachmentsList::setParentWidget(QWidget *w) { - mParentWidget = w; + mParentWidget = w; } void AttachmentsList::updateActionsState() { - bool hasSelectedItem = ui->mListView->currentIndex().isValid(); - ui->mRenameAction->setEnabled(hasSelectedItem); - ui->mDeleteAction->setEnabled(hasSelectedItem); - ui->mExportAction->setEnabled(hasSelectedItem); + bool hasSelectedItem = ui->mListView->currentIndex().isValid(); + ui->mRenameAction->setEnabled(hasSelectedItem); + ui->mDeleteAction->setEnabled(hasSelectedItem); + ui->mExportAction->setEnabled(hasSelectedItem); } void AttachmentsList::contextualMenu(const QPoint& point) { - updateActionsState(); + updateActionsState(); - QMenu* menu = new QMenu(); - menu->addAction(ui->mRenameAction); - menu->addAction(ui->mDeleteAction); - menu->addAction(ui->mExportAction); - menu->addAction(ui->mImportAction); + QMenu* menu = new QMenu(); + menu->addAction(ui->mRenameAction); + menu->addAction(ui->mDeleteAction); + menu->addAction(ui->mExportAction); + menu->addAction(ui->mImportAction); - //menu->addAction(tr("Add 10 mins to timeline"), this, SLOT(add10Mins())); - menu->exec(this->window()->mapToGlobal(point)); + //menu->addAction(tr("Add 10 mins to timeline"), this, SLOT(add10Mins())); + menu->exec(this->window()->mapToGlobal(point)); } void AttachmentsList::importFile() { - // Prepare file open dialog - QFileDialog dlg(mParentWidget, Qt::Sheet); - dlg.setWindowTitle(tr("Select file(s) for import")); - dlg.setAcceptDrops(false); - dlg.setAcceptMode(QFileDialog::AcceptOpen); - dlg.setFileMode(QFileDialog::ExistingFiles); - if (!dlg.exec()) - return; + // Prepare file open dialog + QFileDialog dlg(mParentWidget, Qt::Sheet); + dlg.setWindowTitle(tr("Select file(s) for import")); + dlg.setAcceptDrops(false); + dlg.setAcceptMode(QFileDialog::AcceptOpen); + dlg.setFileMode(QFileDialog::ExistingFiles); + if (!dlg.exec()) + return; - // Iterate selected files - QStringList files = dlg.selectedFiles(); - for (QString filename: files) - { - QFile f(filename); - f.open(QFile::ReadOnly); - if (f.isOpen()) + // Iterate selected files + QStringList files = dlg.selectedFiles(); + for (QString filename: files) { - // Get data from file - QByteArray content = f.readAll(); + QFile f(filename); + f.open(QFile::ReadOnly); + if (f.isOpen()) + { + // Get data from file + QByteArray content = f.readAll(); - // Compress them - QByteArray compressed = qCompress(content); + // Compress them + QByteArray compressed = qCompress(content); - // Put it to Attachment instance - QFileInfo fi(filename); - PAttachment att(new Attachment()); - att->setTaskId(mTask->id()) - .setIndex(mModel->rowCount()) - .setFilename(fi.fileName()); + // Put it to Attachment instance + QFileInfo fi(filename); + PAttachment att(new Attachment()); + att->setTaskId(mTask->id()) + .setIndex(mModel->rowCount()) + .setFilename(fi.fileName()); - // Save everything - att->saveMetadata() - .saveContent(compressed); + // Save everything + att->saveMetadata() + .saveContent(compressed); - mModel->addItem(att); + mModel->addItem(att); + } + f.close(); } - f.close(); - } - // Refresh AttachmentsCount property on owner task - mTask->preloadAttachmentCount(); + // Refresh AttachmentsCount property on owner task + mTask->preloadAttachmentCount(); } void AttachmentsList::exportFile() { - QModelIndexList mil = ui->mListView->selectionModel()->selectedIndexes(); - foreach (const QModelIndex& index, mil) - { - if (!index.isValid()) - continue; + QModelIndexList mil = ui->mListView->selectionModel()->selectedIndexes(); + foreach (const QModelIndex& index, mil) + { + if (!index.isValid()) + continue; - QFileDialog dlg(mParentWidget, Qt::Sheet); - dlg.setWindowTitle(tr("Select file(s) for export")); - dlg.setAcceptDrops(false); - dlg.setAcceptMode(QFileDialog::AcceptSave); - PAttachment att = mModel->itemAt(index.row()); - dlg.selectFile(att->filename()); - if (!dlg.exec()) - continue; + QFileDialog dlg(mParentWidget, Qt::Sheet); + dlg.setWindowTitle(tr("Select file(s) for export")); + dlg.setAcceptDrops(false); + dlg.setAcceptMode(QFileDialog::AcceptSave); + PAttachment att = mModel->itemAt(index.row()); + dlg.selectFile(att->filename()); + if (!dlg.exec()) + continue; - QFile outputFile(dlg.selectedFiles().front()); - outputFile.open(QFile::WriteOnly); - outputFile.write(qUncompress(att->loadContent())); - outputFile.close(); - } + QFile outputFile(dlg.selectedFiles().front()); + outputFile.open(QFile::WriteOnly); + outputFile.write(qUncompress(att->loadContent())); + outputFile.close(); + } } void AttachmentsList::deleteFile() { - QModelIndexList mil = ui->mListView->selectionModel()->selectedIndexes(); - foreach (const QModelIndex& index, mil) - { - if (!index.isValid()) - continue; - PAttachment att = mModel->itemAt(index.row()); - - // Remove from DB - Storage::instance().deleteAttachment(att); - - // Remove from model - mModel->removeItem(index.row()); - - // Iterate other items and decrease their DB table's orderid field - for (int row = index.row() + 1; row < mModel->rowCount(); row++) + QModelIndexList mil = ui->mListView->selectionModel()->selectedIndexes(); + foreach (const QModelIndex& index, mil) { - Attachment& att = *mModel->itemAt(row); - att.setIndex(att.index() - 1) - .saveMetadata(); - } - } + if (!index.isValid()) + continue; + PAttachment att = mModel->itemAt(index.row()); - // Refresh hasAttachment property value on task - mTask->preloadAttachmentCount(); + // Remove from DB + Storage::instance().deleteAttachment(att); + + // Remove from model + mModel->removeItem(index.row()); + + // Iterate other items and decrease their DB table's orderid field + for (int row = index.row() + 1; row < mModel->rowCount(); row++) + { + Attachment& att = *mModel->itemAt(row); + att.setIndex(att.index() - 1) + .saveMetadata(); + } + } + + // Refresh hasAttachment property value on task + mTask->preloadAttachmentCount(); } void AttachmentsList::renameFile() { - QModelIndex index = ui->mListView->currentIndex(); - if (index.isValid()) - ui->mListView->edit(index); + QModelIndex index = ui->mListView->currentIndex(); + if (index.isValid()) + ui->mListView->edit(index); } diff --git a/client/attachmentslist.h b/client/attachmentslist.h index 63b5713..aaed4fb 100644 --- a/client/attachmentslist.h +++ b/client/attachmentslist.h @@ -42,7 +42,8 @@ class AttachmentsList : public QWidget public: explicit AttachmentsList(QWidget *parent = 0); ~AttachmentsList(); - void setTask(PTask task); + void setTask(const PTask& task); + PTask task() const; void setParentWidget(QWidget* w); private: diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp index e928896..60ab64e 100644 --- a/client/mainwindow.cpp +++ b/client/mainwindow.cpp @@ -41,8 +41,6 @@ #include #include -#define SETTINGS mSettings->data() - const int ViewIndex_Main = 0; const int ViewIndex_OpenOrCreateDb = 1; const int ViewIndex_DbPassword = 2; @@ -51,10 +49,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), mPasswordFailed(false), mFindInTasksDlg(this), mDockRecentMenu(nullptr) { - mSettings = QSharedPointer(new Settings()); - // Dark theme if needed - helper::theme::applyCurrent(*mSettings); + helper::theme::applyCurrent(SETTINGS); // Restore window size & position from last run setUpdatesEnabled(false); @@ -75,7 +71,7 @@ MainWindow::~MainWindow() void MainWindow::attachDatabase() { // Find default database file exists - QString path = mSettings->getDatabasePath(); + QString path = SETTINGS.getDatabasePath(); QString folder = QFileInfo(path).absoluteDir().path(); Storage::instance().setPath(path); @@ -84,7 +80,7 @@ void MainWindow::attachDatabase() askNewDbPassword(); else { - if (mSettings->data()[KEY_AUTOSAVE_PASSWORD].toBool()) + if (SETTINGS.data()[KEY_AUTOSAVE_PASSWORD].toBool()) { QString password = helper::password::loadFromKeychain(); if (password.isEmpty()) @@ -120,11 +116,11 @@ void MainWindow::connectUiToDatabase() if (mTaskTreeModel->hasChildren()) ui->mTaskTree->setCurrentIndex(mTaskTreeModel->index(0,0, QModelIndex())); - mTaskTreeModel->setExpandedState(mSettings->data()[KEY_EXPANDED_TASKS].toString(), *ui->mTaskTree); - mTaskTreeModel->setSelected(mSettings->data()[KEY_SELECTED_TASKS].toString(), *ui->mTaskTree); + mTaskTreeModel->setExpandedState(SETTINGS.data()[KEY_EXPANDED_TASKS].toString(), *ui->mTaskTree); + mTaskTreeModel->setSelected(SETTINGS.data()[KEY_SELECTED_TASKS].toString(), *ui->mTaskTree); // Load recent tasks - QString recent = mSettings->data()[KEY_RECENT_TASKS].toString(); + QString recent = SETTINGS.data()[KEY_RECENT_TASKS].toString(); QStringList recentList = recent.split(";", QString::SkipEmptyParts); for (QString& s: recentList) { @@ -182,7 +178,7 @@ void MainWindow::initClient() ui->mCheckForUpdatesAction->setMenuRole(QAction::ApplicationSpecificRole); // Build tray icon if system support this one - if (QSystemTrayIcon::isSystemTrayAvailable() && mSettings->data()[KEY_SHOW_TRAY_ICON].toBool()) + if (QSystemTrayIcon::isSystemTrayAvailable() && SETTINGS.data()[KEY_SHOW_TRAY_ICON].toBool()) initTrayIcon(); setWindowIcon(getAppIcon()); @@ -295,7 +291,7 @@ QSharedPointer MainWindow::getUndoStack() const void MainWindow::saveGeometry() { - AppGeometry g(*mSettings); + AppGeometry g(SETTINGS); g.setMaximized(isMaximized()); g.setWindowRect(this->geometry()); g.setSplitterPos(0, {ui->mSplitter->sizes().front(), ui->mSplitter->sizes().back()}); @@ -303,8 +299,8 @@ void MainWindow::saveGeometry() if (mTaskTreeModel) { - mSettings->data()[KEY_EXPANDED_TASKS] = this->mTaskTreeModel->getExpandedState(*ui->mTaskTree); - mSettings->data()[KEY_SELECTED_TASKS] = this->mTaskTreeModel->getSelected(*ui->mTaskTree); + SETTINGS.data()[KEY_EXPANDED_TASKS] = this->mTaskTreeModel->getExpandedState(*ui->mTaskTree); + SETTINGS.data()[KEY_SELECTED_TASKS] = this->mTaskTreeModel->getSelected(*ui->mTaskTree); } // Save recent list @@ -313,13 +309,13 @@ void MainWindow::saveGeometry() { recent += QString::number(t->id()) + ";"; } - mSettings->data()[KEY_RECENT_TASKS] = recent; - mSettings->save(); + SETTINGS.data()[KEY_RECENT_TASKS] = recent; + SETTINGS.save(); } void MainWindow::loadGeometry() { - auto g = AppGeometry(*mSettings); + auto g = AppGeometry(SETTINGS); if (g.isMaximized()) this->showMaximized(); @@ -415,7 +411,7 @@ void MainWindow::onDatabaseAvailable() void MainWindow::preferences() { - PreferencesDlg pref(this, *mSettings); + PreferencesDlg pref(this, SETTINGS); if (pref.exec() == QDialog::Accepted) { @@ -428,20 +424,20 @@ void MainWindow::preferences() emit onTimeFormatChanged(); // Delete autosaved password if needed - if (mSettings->data()[KEY_AUTOSAVE_PASSWORD].toBool() == false) + if (SETTINGS.data()[KEY_AUTOSAVE_PASSWORD].toBool() == false) { // Reset password in keychain helper::password::saveToKeychain(QString("")); //mSettings->data()[KEY_PASSWORD] = NOPASSWORDSTRING; - mSettings->save(); + SETTINGS.save(); } // Hide/Show tray icon if need - if (mSettings->data()[KEY_SHOW_TRAY_ICON].toBool() && !mTrayIcon && QSystemTrayIcon::isSystemTrayAvailable()) + if (SETTINGS.data()[KEY_SHOW_TRAY_ICON].toBool() && !mTrayIcon && QSystemTrayIcon::isSystemTrayAvailable()) initTrayIcon(); else - if (!mSettings->data()[KEY_SHOW_TRAY_ICON].toBool() && mTrayIcon) + if (!SETTINGS.data()[KEY_SHOW_TRAY_ICON].toBool() && mTrayIcon) removeTrayIcon(); updateData(); @@ -573,7 +569,7 @@ void MainWindow::deleteTask() } else { - if (mSettings->data()[KEY_ASK_BEFORE_DELETE].toBool()) + if (SETTINGS.data()[KEY_ASK_BEFORE_DELETE].toBool()) { auto reply = QMessageBox::question(this, tr("Are you sure?"), @@ -714,9 +710,9 @@ void MainWindow::idleDetected() mActivityTracker->acceptIdleState(); // Check if settings allow smart stop - if (SETTINGS[KEY_SMART_STOP].toBool() && SETTINGS[KEY_SMART_STOP_MINUTES].toInt() > 0) + if (SETTINGS.data()[KEY_SMART_STOP].toBool() && SETTINGS.data()[KEY_SMART_STOP_MINUTES].toInt() > 0) { - if (SETTINGS[KEY_ASK_STOP].toBool()) + if (SETTINGS.data()[KEY_ASK_STOP].toBool()) { // Stop activity tracker to not be confused with following user activity mActivityTracker->stop(); @@ -736,7 +732,7 @@ void MainWindow::activityDetected() mActivityTracker->acceptUserActiveState(); // Check if settings allow smart start - if (SETTINGS[KEY_SMART_START].toBool() && mStopReason == TSR_Automatic) + if (SETTINGS.data()[KEY_SMART_START].toBool() && mStopReason == TSR_Automatic) { /*if (SETTINGS[KEY_ASK_START].toBool()) { @@ -902,9 +898,9 @@ void MainWindow::startTracking(PTask t) updateTrayIcon(Tray_ShowMessage); // Start activity tracker if needed - if (mSettings->data()[KEY_SMART_STOP].toBool() && mSettings->data()[KEY_SMART_STOP_MINUTES].toInt() > 0) + if (SETTINGS.data()[KEY_SMART_STOP].toBool() && SETTINGS.data()[KEY_SMART_STOP_MINUTES].toInt() > 0) { - mActivityTracker->setInterval(mSettings->data()[KEY_SMART_STOP_MINUTES].toInt() * 60); + mActivityTracker->setInterval(SETTINGS.data()[KEY_SMART_STOP_MINUTES].toInt() * 60); mActivityTracker->start(); } } @@ -917,7 +913,7 @@ void MainWindow::startTracking() return; // Trigger permission dialog if needed - if (mSettings->data()[KEY_SMART_STOP].toBool()) + if (SETTINGS.data()[KEY_SMART_STOP].toBool()) { if (!helper::activityTracker::ensureSmartTrackingIsPossible()) mTrayIcon->showMessage(tr("No smart tracking stop/start"), tr("Problem with obtaining permissions"), QSystemTrayIcon::Warning); @@ -1296,26 +1292,14 @@ void MainWindow::timeFormatChanged() void MainWindow::showTimeForSelectedTask() { PTask t = mTaskTreeModel->getTask(ui->mTaskTree->currentIndex()); - bool showSeconds = mSettings->data()[KEY_SHOW_SECONDS].toBool(); - - // Show stats for current task - if (t) - { - if (!t->timeline()) - t->loadContent(); - - int spentSecondsToday = t->timeline()->today(); - int spentSecondsMonth = t->timeline()->month(); - ui->mTodaySpentTimeLabel->setText(QString::fromStdString(helper::chrono::secondsToDisplay(spentSecondsToday, showSeconds))); - ui->mThisMonthSpentTimeLabel->setText(QString::fromStdString(helper::chrono::secondsToDisplay(spentSecondsMonth, showSeconds))); - } + ui->mProperties->setTask(t); } void MainWindow::showTimeForTrackingTask() { if (mCurrentTask) { - bool showSeconds = mSettings->data()[KEY_SHOW_SECONDS].toBool(); + bool showSeconds = SETTINGS.data()[KEY_SHOW_SECONDS].toBool(); // Update status bar QString path; @@ -1369,7 +1353,7 @@ void MainWindow::updateTrayIcon(TrayShowMessage flag) QString tooltip; if (mCurrentTask) { - bool showSeconds = mSettings->data()[KEY_SHOW_SECONDS].toBool(); + bool showSeconds = SETTINGS.data()[KEY_SHOW_SECONDS].toBool(); int spentSecondsToday = mCurrentTask->timeline()->today(); QString timeString = QString::fromStdString(helper::chrono::secondsToDisplay(spentSecondsToday, showSeconds)); tooltip = tr("Noo is tracking ") + mCurrentTask->title() + ".\n" + @@ -1408,7 +1392,7 @@ void MainWindow::showTimeline() return; PTask t = mTaskTreeModel->getTask(ui->mTaskTree->currentIndex()); - TimeTreeDlg dlg(this, t->timeline(), *mSettings); + TimeTreeDlg dlg(this, t->timeline(), SETTINGS); dlg.exec(); // Refresh current timeline stats @@ -1417,7 +1401,7 @@ void MainWindow::showTimeline() void MainWindow::showTimeReport() { - TimeReportWizard trz(*mSettings, this); + TimeReportWizard trz(SETTINGS, this); trz.exec(); } @@ -1652,7 +1636,7 @@ void MainWindow::trayWindowDestroyed(QObject */*object*/) void MainWindow::onDbPasswordEntered(const QString& password) { // Save password to keychain if needed - if (mSettings->data()[KEY_AUTOSAVE_PASSWORD].toBool()) + if (SETTINGS.data()[KEY_AUTOSAVE_PASSWORD].toBool()) helper::password::saveToKeychain(password); // Try to open database @@ -1674,7 +1658,7 @@ void MainWindow::onDbPasswordCancelled() void MainWindow::onNewDbPasswordEntered(const QString& password) { // Save password to keychain if needed - if (mSettings->data()[KEY_AUTOSAVE_PASSWORD].toBool()) + if (SETTINGS.data()[KEY_AUTOSAVE_PASSWORD].toBool()) helper::password::saveToKeychain(password); // Configure storage @@ -1695,8 +1679,8 @@ void MainWindow::onNewDbPasswordEntered(const QString& password) void MainWindow::onDatabaseChanged(const QString& path) { // Bind to specific database - mSettings->data()[KEY_DB_FILENAME] = path; - mSettings->save(); + SETTINGS.data()[KEY_DB_FILENAME] = path; + SETTINGS.save(); Storage::instance().setPath(path); // Try to open database diff --git a/client/mainwindow.h b/client/mainwindow.h index dcb7926..091216e 100644 --- a/client/mainwindow.h +++ b/client/mainwindow.h @@ -63,7 +63,6 @@ private: QLabel* mCurrentIntervalLabel = nullptr; QLabel* mDuplicationSignalLabel = nullptr;; QSystemTrayIcon *mTrayIcon = nullptr; - QSharedPointer mSettings; bool mPasswordFailed = false; PasswordDlg* mPasswordDlg = nullptr; NewPasswordDlg* mNewPasswordDlg = nullptr; diff --git a/client/mainwindow.ui b/client/mainwindow.ui index f04a371..a99f347 100644 --- a/client/mainwindow.ui +++ b/client/mainwindow.ui @@ -81,36 +81,9 @@ QFrame::Raised - - - 2 - - - 0 - - - 2 - - - 0 - - + + - - - 0 - 0 - - - - - 16777215 - 4000 - - - - 0 - Qt::Horizontal @@ -210,59 +183,7 @@ - - - - 0 - 0 - - - - - 100 - 0 - - - - - 16777215 - 4000 - - - - QFrame::StyledPanel - - - - - - Today: - - - - - - - 0 hours 0 minutes - - - - - - - This month: - - - - - - - 0 hours 0 minutes - - - - - + @@ -771,6 +692,12 @@ QPlainTextEdit
qmarkdowntextedit/qmarkdowntextedit.h
+ + NodePropertiesWidget + QWidget +
nodepropertieswidget.h
+ 1 +
diff --git a/client/nodepropertieswidget.cpp b/client/nodepropertieswidget.cpp new file mode 100644 index 0000000..f3c73d4 --- /dev/null +++ b/client/nodepropertieswidget.cpp @@ -0,0 +1,52 @@ +#include "nodepropertieswidget.h" +#include "ui_nodepropertieswidget.h" +#include "settings.h" + +NodePropertiesWidget::NodePropertiesWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::NodePropertiesWidget) +{ + ui->setupUi(this); +} + +NodePropertiesWidget::~NodePropertiesWidget() +{ + delete ui; +} + +void NodePropertiesWidget::setTask(const PTask& task) +{ + if (mTask != task) + { + mTask = task; + update(); + } +} + + +PTask NodePropertiesWidget::task() const +{ + return mTask; +} + +void NodePropertiesWidget::refresh() +{ + bool showSeconds = SETTINGS.data()[KEY_SHOW_SECONDS].toBool(); + + if (mTask != nullptr) + { + ui->mFileListView->setTask(mTask); + if (!mTask->timeline()) + mTask->loadContent(); + + int spentSecondsToday = mTask->timeline()->today(); + int spentSecondsMonth = mTask->timeline()->month(); + ui->mTodaySpentTimeLabel->setText(QString::fromStdString(helper::chrono::secondsToDisplay(spentSecondsToday, showSeconds))); + ui->mThisMonthSpentTimeLabel->setText(QString::fromStdString(helper::chrono::secondsToDisplay(spentSecondsMonth, showSeconds))); + } + else + { + ui->mTimeFrame->setVisible(false); + ui->mFileListView->setTask(PTask()); + } +} diff --git a/client/nodepropertieswidget.h b/client/nodepropertieswidget.h new file mode 100644 index 0000000..219445a --- /dev/null +++ b/client/nodepropertieswidget.h @@ -0,0 +1,29 @@ +#ifndef NODEPROPERTIESWIDGET_H +#define NODEPROPERTIESWIDGET_H + +#include +#include "task.h" + +namespace Ui { +class NodePropertiesWidget; +} + +class NodePropertiesWidget : public QWidget +{ + Q_OBJECT + +public: + explicit NodePropertiesWidget(QWidget *parent = nullptr); + ~NodePropertiesWidget(); + + void setTask(const PTask& task); + PTask task() const; + +private: + Ui::NodePropertiesWidget *ui; + + void refresh(); + PTask mTask; +}; + +#endif // NODEPROPERTIESWIDGET_H diff --git a/client/nodepropertieswidget.ui b/client/nodepropertieswidget.ui new file mode 100644 index 0000000..1a02a83 --- /dev/null +++ b/client/nodepropertieswidget.ui @@ -0,0 +1,90 @@ + + + NodePropertiesWidget + + + + 0 + 0 + 449 + 470 + + + + Form + + + + + + Qt::Vertical + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 16777215 + 4000 + + + + QFrame::StyledPanel + + + + + + Today: + + + + + + + 0 hours 0 minutes + + + + + + + This month: + + + + + + + 0 hours 0 minutes + + + + + + + + + + + + + AttachmentsList + QWidget +
attachmentslist.h
+ 1 +
+
+ + +
diff --git a/client/noo.pro b/client/noo.pro index b0992e4..51ce325 100644 --- a/client/noo.pro +++ b/client/noo.pro @@ -52,6 +52,7 @@ INCLUDEPATH += $$PWD/../lib/include SOURCES += main.cpp \ mainwindow.cpp \ + nodepropertieswidget.cpp \ storage.cpp \ task.cpp \ tasktreemodel.cpp \ @@ -91,6 +92,7 @@ SOURCES += main.cpp \ HEADERS += mainwindow.h \ + nodepropertieswidget.h \ storage.h \ task.h \ tasktreemodel.h \ @@ -150,6 +152,7 @@ unix { FORMS += mainwindow.ui \ newpassworddlg.ui \ + nodepropertieswidget.ui \ passworddlg.ui \ preferencesdlg.ui \ timetreedlg.ui \ diff --git a/client/settings.h b/client/settings.h index 22b194c..5988e83 100644 --- a/client/settings.h +++ b/client/settings.h @@ -61,6 +61,8 @@ protected: QVariantMap mData; }; +#define SETTINGS Settings::instance() + class AppGeometry { public: