- refactor task properties to dedicated widget
This commit is contained in:
parent
37e70ab252
commit
6bc7985b44
@ -7,253 +7,261 @@
|
||||
#include <QFileDialog>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -41,8 +41,6 @@
|
||||
#include <QDebug>
|
||||
#include <iostream>
|
||||
|
||||
#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<Settings>(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<QByteArray> 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
|
||||
|
||||
@ -63,7 +63,6 @@ private:
|
||||
QLabel* mCurrentIntervalLabel = nullptr;
|
||||
QLabel* mDuplicationSignalLabel = nullptr;;
|
||||
QSystemTrayIcon *mTrayIcon = nullptr;
|
||||
QSharedPointer<Settings> mSettings;
|
||||
bool mPasswordFailed = false;
|
||||
PasswordDlg* mPasswordDlg = nullptr;
|
||||
NewPasswordDlg* mNewPasswordDlg = nullptr;
|
||||
|
||||
@ -81,36 +81,9 @@
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QSplitter" name="mTimeSplitter">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>4000</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
@ -210,59 +183,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QFrame" name="mTimeFrame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>4000</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="mTodayTextLabel">
|
||||
<property name="text">
|
||||
<string>Today:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="mTodaySpentTimeLabel">
|
||||
<property name="text">
|
||||
<string>0 hours 0 minutes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="mThisMonthTextLabel">
|
||||
<property name="text">
|
||||
<string>This month:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="mThisMonthSpentTimeLabel">
|
||||
<property name="text">
|
||||
<string>0 hours 0 minutes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="NodePropertiesWidget" name="mProperties" native="true"/>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@ -771,6 +692,12 @@
|
||||
<extends>QPlainTextEdit</extends>
|
||||
<header>qmarkdowntextedit/qmarkdowntextedit.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>NodePropertiesWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>nodepropertieswidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="mainwindow.qrc"/>
|
||||
|
||||
52
client/nodepropertieswidget.cpp
Normal file
52
client/nodepropertieswidget.cpp
Normal file
@ -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());
|
||||
}
|
||||
}
|
||||
29
client/nodepropertieswidget.h
Normal file
29
client/nodepropertieswidget.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef NODEPROPERTIESWIDGET_H
|
||||
#define NODEPROPERTIESWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#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
|
||||
90
client/nodepropertieswidget.ui
Normal file
90
client/nodepropertieswidget.ui
Normal file
@ -0,0 +1,90 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NodePropertiesWidget</class>
|
||||
<widget class="QWidget" name="NodePropertiesWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>449</width>
|
||||
<height>470</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<widget class="QFrame" name="mTimeFrame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>4000</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="mTodayTextLabel">
|
||||
<property name="text">
|
||||
<string>Today:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="mTodaySpentTimeLabel">
|
||||
<property name="text">
|
||||
<string>0 hours 0 minutes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="mThisMonthTextLabel">
|
||||
<property name="text">
|
||||
<string>This month:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="mThisMonthSpentTimeLabel">
|
||||
<property name="text">
|
||||
<string>0 hours 0 minutes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="AttachmentsList" name="mFileListView" native="true"/>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>AttachmentsList</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>attachmentslist.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@ -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 \
|
||||
|
||||
@ -61,6 +61,8 @@ protected:
|
||||
QVariantMap mData;
|
||||
};
|
||||
|
||||
#define SETTINGS Settings::instance()
|
||||
|
||||
class AppGeometry
|
||||
{
|
||||
public:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user