This repository has been archived by the owner on Mar 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdaemon.cpp
87 lines (82 loc) · 2.27 KB
/
daemon.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "daemon.h"
Daemon* Daemon::daemon = nullptr;
Daemon::Daemon(QObject* parent)
: QObject(parent)
{
assert(daemon == nullptr);
if (daemon == nullptr)
daemon = this;
back = new ZBackend;
model = new ZListModel(this);
tray = new Systemtray(this);
tray->show();
addItems(back->getSavedDataList());
}
Daemon::~Daemon()
{
assert(daemon == this);
delete back; //back uses Daemon::instance & model, so destruct first
delete model;
delete tray;
if (daemon == this)
daemon = nullptr;
}
QList<ZNote> Daemon::exportNotes() const
{
return model->exportAll();
}
void Daemon::setAbstract(const InnerIndex& idx, const QString& Abstract)
{
model->setData(idx, QVariant::fromValue(Abstract), ZListModel::Abstract);
}
void Daemon::setHtml(const InnerIndex& idx, const QString& html)
{
model->setData(idx, QVariant::fromValue(html), ZListModel::Html);
}
InnerIndex Daemon::commitChange(const InnerIndex& idx) //优化逻辑,若通过save主动commit,后续setIndex时可能再次触发commit
{
// qDebug() << "commitChange(" << idx << ")";
return model->setData(idx, QVariant(), ZListModel::UpdateTime);
}
void Daemon::commitChange(const QModelIndex& index) //优化逻辑,若通过save主动commit,后续setIndex时可能再次触发commit
{
model->setData(index, QVariant(), ZListModel::UpdateTime);
}
void Daemon::save()
{
back->saveMainFile(model->exportAll());
back->saveMediaFile();
}
bool Daemon::eventFilter(QObject* obj, QEvent* e)
{
if (e->type() == QEvent::ActivationChange) {
emit activationChanged(obj);
if (auto i = qobject_cast<QWidget*>(obj)) {
i->isActiveWindow() ? emit gainActivation(i) : emit lostActivation(i);
}
return true;
} else {
return QObject::eventFilter(obj, e);
}
}
Daemon* Daemon::instance()
{
assert(daemon != nullptr);
return daemon;
}
QString Daemon::calcImageHash(const QUrl& fileUrl)
{
return back->insertImage(fileUrl);
}
QString Daemon::calcImageHash(const QByteArray& data)
{
return back->insertImage(data);
}
QByteArray Daemon::fetchImageData(const QString& hash)
{
return back->queryImage(hash);
}
QByteArray Daemon::fetchRemoteResource(const QString& url)
{
return back->download(url);
}