summaryrefslogtreecommitdiffstats
path: root/framework/src
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-07-04 09:59:58 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-07-04 10:02:33 +0200
commita69789502feb0235bddad0cf3cb9ed9ca7554632 (patch)
treedd9f02fc5f87eb4152cbf42b49bfd17f243d56af /framework/src
parent9d196fecae23a1f1d2f7922a180e3122547f9e4c (diff)
downloadkube-a69789502feb0235bddad0cf3cb9ed9ca7554632.tar.gz
kube-a69789502feb0235bddad0cf3cb9ed9ca7554632.zip
Introduced a logmodel
To get rid of weird problems of lists converting to qmllistmodels. I'm relatively sure some crashes I've seen were related to this.
Diffstat (limited to 'framework/src')
-rw-r--r--framework/src/CMakeLists.txt1
-rw-r--r--framework/src/domain/maillistmodel.cpp9
-rw-r--r--framework/src/frameworkplugin.cpp2
-rw-r--r--framework/src/logmodel.cpp76
-rw-r--r--framework/src/logmodel.h41
5 files changed, 129 insertions, 0 deletions
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt
index 5ad5e910..901ec4a3 100644
--- a/framework/src/CMakeLists.txt
+++ b/framework/src/CMakeLists.txt
@@ -54,6 +54,7 @@ add_library(kubeframework SHARED
54 extensionmodel.cpp 54 extensionmodel.cpp
55 viewhighlighter.cpp 55 viewhighlighter.cpp
56 file.cpp 56 file.cpp
57 logmodel.cpp
57 ) 58 )
58generate_export_header(kubeframework BASE_NAME Kube EXPORT_FILE_NAME kube_export.h) 59generate_export_header(kubeframework BASE_NAME Kube EXPORT_FILE_NAME kube_export.h)
59set_target_properties(kubeframework PROPERTIES 60set_target_properties(kubeframework PROPERTIES
diff --git a/framework/src/domain/maillistmodel.cpp b/framework/src/domain/maillistmodel.cpp
index 5936c792..152b4f23 100644
--- a/framework/src/domain/maillistmodel.cpp
+++ b/framework/src/domain/maillistmodel.cpp
@@ -406,6 +406,15 @@ bool MailListModel::showInbox() const
406void MailListModel::setEntityId(const QString &id) 406void MailListModel::setEntityId(const QString &id)
407{ 407{
408 qDebug() << "Running mail query for mail with ID:" << id; 408 qDebug() << "Running mail query for mail with ID:" << id;
409 if (id.isEmpty()) {
410 mCurrentQueryItem.clear();
411 setSourceModel(nullptr);
412 return;
413 }
414 if (mCurrentQueryItem == id) {
415 return;
416 }
417 mCurrentQueryItem = id.toLatin1();
409 using namespace Sink::ApplicationDomain; 418 using namespace Sink::ApplicationDomain;
410 Sink::Query query; 419 Sink::Query query;
411 query.setFlags(Sink::Query::LiveQuery); 420 query.setFlags(Sink::Query::LiveQuery);
diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp
index b5635733..9c81b7e1 100644
--- a/framework/src/frameworkplugin.cpp
+++ b/framework/src/frameworkplugin.cpp
@@ -46,6 +46,7 @@
46#include "extensionmodel.h" 46#include "extensionmodel.h"
47#include "viewhighlighter.h" 47#include "viewhighlighter.h"
48#include "file.h" 48#include "file.h"
49#include "logmodel.h"
49 50
50#include <QtQml> 51#include <QtQml>
51#include <QQuickImageProvider> 52#include <QQuickImageProvider>
@@ -178,6 +179,7 @@ void FrameworkPlugin::registerTypes (const char *uri)
178 qmlRegisterType<ContactController>(uri, 1, 0,"ContactController"); 179 qmlRegisterType<ContactController>(uri, 1, 0,"ContactController");
179 qmlRegisterType<PeopleModel>(uri, 1, 0,"PeopleModel"); 180 qmlRegisterType<PeopleModel>(uri, 1, 0,"PeopleModel");
180 qmlRegisterType<TextDocumentHandler>(uri, 1, 0, "TextDocumentHandler"); 181 qmlRegisterType<TextDocumentHandler>(uri, 1, 0, "TextDocumentHandler");
182 qmlRegisterType<LogModel>(uri, 1, 0, "LogModel");
181 183
182 qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory"); 184 qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory");
183 qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel"); 185 qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel");
diff --git a/framework/src/logmodel.cpp b/framework/src/logmodel.cpp
new file mode 100644
index 00000000..c3a692dc
--- /dev/null
+++ b/framework/src/logmodel.cpp
@@ -0,0 +1,76 @@
1/*
2 Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "logmodel.h"
21
22#include <QDebug>
23#include <QDateTime>
24#include <QStandardItem>
25
26LogModel::LogModel(QObject *parent)
27 : QStandardItemModel(parent)
28{
29 QByteArrayList roles{"type", "subtype", "timestamp", "message", "details", "entities", "resource"};
30
31 int role = Qt::UserRole + 1;
32 mRoles.insert("id", role);
33 role++;
34 for (const auto &r : roles) {
35 mRoles.insert(r, role);
36 role++;
37 }
38
39 QHash<int, QByteArray> roleNames;
40 for (const auto r : mRoles.keys()) {
41 roleNames.insert(mRoles[r], r);
42 }
43 setItemRoleNames(roleNames);
44}
45
46LogModel::~LogModel()
47{
48
49}
50
51void LogModel::insert(const QVariantMap &message)
52{
53
54 if (rowCount() > 0) {
55 auto i = item(0);
56 const auto subtype = i->data(mRoles["subtype"]).toString();
57 if (!subtype.isEmpty() && (subtype == message.value("subtype").toString())) {
58 //TODO merge message into this entry
59 return;
60 }
61 }
62
63 auto item = new QStandardItem;
64 auto addProperty = [&] (const QByteArray &key) {
65 item->setData(message.value(key), mRoles[key]);
66 };
67 item->setData(QDateTime::currentDateTime(), mRoles["timestamp"]);
68 addProperty("type");
69 addProperty("subtype");
70 addProperty("message");
71 addProperty("details");
72 addProperty("resource");
73 addProperty("entities");
74 insertRow(0, item);
75}
76
diff --git a/framework/src/logmodel.h b/framework/src/logmodel.h
new file mode 100644
index 00000000..73909e87
--- /dev/null
+++ b/framework/src/logmodel.h
@@ -0,0 +1,41 @@
1/*
2 Copyright (c) 2016 Michael Bohlender <michael.bohlender@kdemail.net>
3 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
4
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
9
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
19*/
20
21#pragma once
22#include "kube_export.h"
23
24#include <QStandardItemModel>
25#include <QVariantMap>
26#include <fabric.h>
27
28class KUBE_EXPORT LogModel : public QStandardItemModel
29{
30 Q_OBJECT
31
32public:
33 LogModel(QObject *parent = Q_NULLPTR);
34 ~LogModel();
35
36 Q_INVOKABLE void insert(const QVariantMap &);
37
38private:
39 // QSharedPointer<Kube::Fabric::Listener> mListener;
40 QHash<QByteArray, int> mRoles;
41};