diff options
author | tg(x) <*@tg-x.net> | 2016-03-23 03:13:11 +0100 |
---|---|---|
committer | tg(x) <*@tg-x.net> | 2016-03-23 03:13:11 +0100 |
commit | 507939ec2cc128b794177ec04689b43d7d84ba4c (patch) | |
tree | c16ad0df2ad630e46df9f0d199fd4c5d0d933397 | |
parent | 5936b06d6c5e1515770258ff1a944a709a336f7f (diff) | |
download | secushare-507939ec2cc128b794177ec04689b43d7d84ba4c.tar.gz secushare-507939ec2cc128b794177ec04689b43d7d84ba4c.zip |
models
-rw-r--r-- | src/model/EgoListModel.cpp | 4 | ||||
-rw-r--r-- | src/model/NymListModel.cpp | 4 | ||||
-rw-r--r-- | src/model/PlaceListModel.cpp | 5 | ||||
-rw-r--r-- | src/model/ThreadListModel.cpp | 37 | ||||
-rw-r--r-- | src/model/ThreadListModel.h | 8 | ||||
-rw-r--r-- | src/model/ThreadModel.cpp | 84 | ||||
-rw-r--r-- | src/model/ThreadModel.h | 5 | ||||
-rw-r--r-- | src/social/message.cpp | 7 | ||||
-rw-r--r-- | src/social/message.h | 8 | ||||
-rw-r--r-- | src/social/socialapp.cpp | 6 | ||||
-rw-r--r-- | src/social/socialapp.h | 4 |
11 files changed, 123 insertions, 49 deletions
diff --git a/src/model/EgoListModel.cpp b/src/model/EgoListModel.cpp index 8327274..7fd9029 100644 --- a/src/model/EgoListModel.cpp +++ b/src/model/EgoListModel.cpp | |||
@@ -62,10 +62,10 @@ EgoListModel::data (const QModelIndex &index, int role) const | |||
62 | return ego->name (); | 62 | return ego->name (); |
63 | 63 | ||
64 | default: | 64 | default: |
65 | return QVariant::Invalid; | 65 | return QVariant(); |
66 | } | 66 | } |
67 | 67 | ||
68 | return QVariant::Invalid; | 68 | return QVariant(); |
69 | } | 69 | } |
70 | 70 | ||
71 | 71 | ||
diff --git a/src/model/NymListModel.cpp b/src/model/NymListModel.cpp index 1277800..2ca6c70 100644 --- a/src/model/NymListModel.cpp +++ b/src/model/NymListModel.cpp | |||
@@ -62,10 +62,10 @@ NymListModel::data (const QModelIndex &index, int role) const | |||
62 | return nym->name (); | 62 | return nym->name (); |
63 | 63 | ||
64 | default: | 64 | default: |
65 | return QVariant::Invalid; | 65 | return QVariant(); |
66 | } | 66 | } |
67 | 67 | ||
68 | return QVariant::Invalid; | 68 | return QVariant(); |
69 | } | 69 | } |
70 | 70 | ||
71 | 71 | ||
diff --git a/src/model/PlaceListModel.cpp b/src/model/PlaceListModel.cpp index f1b8c29..aaaf4ed 100644 --- a/src/model/PlaceListModel.cpp +++ b/src/model/PlaceListModel.cpp | |||
@@ -52,7 +52,7 @@ PlaceListModel::data (const QModelIndex &index, int role) const | |||
52 | { | 52 | { |
53 | int idx = index.row (); | 53 | int idx = index.row (); |
54 | if (idx < 0 || m_data.count () <= idx) | 54 | if (idx < 0 || m_data.count () <= idx) |
55 | return QVariant::Invalid; | 55 | return QVariant(); |
56 | 56 | ||
57 | Place *place = m_data[idx]; | 57 | Place *place = m_data[idx]; |
58 | 58 | ||
@@ -69,7 +69,7 @@ PlaceListModel::data (const QModelIndex &index, int role) const | |||
69 | case THREADS: | 69 | case THREADS: |
70 | return &m_threads[idx]; | 70 | return &m_threads[idx]; |
71 | default: | 71 | default: |
72 | return QVariant::Invalid; | 72 | return QVariant(); |
73 | } | 73 | } |
74 | } | 74 | } |
75 | 75 | ||
@@ -84,6 +84,7 @@ PlaceListModel::roleNames () const | |||
84 | roles[PUBKEY] = "pubKey"; | 84 | roles[PUBKEY] = "pubKey"; |
85 | roles[TYPE] = "type"; | 85 | roles[TYPE] = "type"; |
86 | roles[DESC] = "description"; | 86 | roles[DESC] = "description"; |
87 | roles[THREADS] = "threadListModel"; | ||
87 | 88 | ||
88 | return roles; | 89 | return roles; |
89 | } | 90 | } |
diff --git a/src/model/ThreadListModel.cpp b/src/model/ThreadListModel.cpp index cb310f4..aec692d 100644 --- a/src/model/ThreadListModel.cpp +++ b/src/model/ThreadListModel.cpp | |||
@@ -26,11 +26,11 @@ ThreadListModel::rowCount (const QModelIndex & parent) const | |||
26 | 26 | ||
27 | 27 | ||
28 | QVariant | 28 | QVariant |
29 | ThreadListModel::data (const QModelIndex & index, int role) const | 29 | ThreadListModel::data (const QModelIndex &index, int role) const |
30 | { | 30 | { |
31 | int idx = index.row (); | 31 | int idx = index.row (); |
32 | if (idx < 0 || m_data.count () <= idx) | 32 | if (idx < 0 || m_data.count () <= idx) |
33 | return QVariant::Invalid; | 33 | return QVariant(); |
34 | 34 | ||
35 | Message *msg = m_data[idx]; | 35 | Message *msg = m_data[idx]; |
36 | 36 | ||
@@ -47,7 +47,7 @@ ThreadListModel::data (const QModelIndex & index, int role) const | |||
47 | return msg->desc (); | 47 | return msg->desc (); |
48 | #endif | 48 | #endif |
49 | default: | 49 | default: |
50 | return QVariant::Invalid; | 50 | return QVariant(); |
51 | } | 51 | } |
52 | } | 52 | } |
53 | 53 | ||
@@ -105,12 +105,12 @@ ThreadListModel::count () | |||
105 | 105 | ||
106 | 106 | ||
107 | Message * | 107 | Message * |
108 | ThreadListModel::get (int index) | 108 | ThreadListModel::get (int idx) |
109 | { | 109 | { |
110 | if (index < 0 || count () < index) | 110 | if (idx < 0 || count () < idx) |
111 | return NULL; | 111 | return NULL; |
112 | 112 | ||
113 | Message *msg = m_data[index]; | 113 | Message *msg = m_data[idx]; |
114 | 114 | ||
115 | //Set the ownership so QML don't delete it. | 115 | //Set the ownership so QML don't delete it. |
116 | QQmlEngine::setObjectOwnership (msg, QQmlEngine::CppOwnership); | 116 | QQmlEngine::setObjectOwnership (msg, QQmlEngine::CppOwnership); |
@@ -129,6 +129,31 @@ ThreadListModel::get (QModelIndex index) | |||
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
132 | ThreadModel * | ||
133 | ThreadListModel::threadModel (int idx) | ||
134 | { | ||
135 | if (idx < 0 || count () < idx) | ||
136 | return NULL; | ||
137 | |||
138 | ThreadModel *thread = m_thread[idx]; | ||
139 | |||
140 | //Set the ownership so QML don't delete it. | ||
141 | QQmlEngine::setObjectOwnership (thread, QQmlEngine::CppOwnership); | ||
142 | |||
143 | return thread; | ||
144 | } | ||
145 | |||
146 | |||
147 | ThreadModel * | ||
148 | ThreadListModel::threadModel (QModelIndex index) | ||
149 | { | ||
150 | if (count () < index.row ()) | ||
151 | return NULL; | ||
152 | |||
153 | return m_thread[index.row ()]; | ||
154 | } | ||
155 | |||
156 | |||
132 | #if FIXME | 157 | #if FIXME |
133 | bool | 158 | bool |
134 | ThreadListModel::contains (QString id) | 159 | ThreadListModel::contains (QString id) |
diff --git a/src/model/ThreadListModel.h b/src/model/ThreadListModel.h index d31e2e2..0d67b88 100644 --- a/src/model/ThreadListModel.h +++ b/src/model/ThreadListModel.h | |||
@@ -29,11 +29,17 @@ class ThreadListModel : public QAbstractListModel | |||
29 | count (); | 29 | count (); |
30 | 30 | ||
31 | Q_INVOKABLE Message * | 31 | Q_INVOKABLE Message * |
32 | get (int index); | 32 | get (int idx); |
33 | 33 | ||
34 | Message * | 34 | Message * |
35 | get (QModelIndex index); | 35 | get (QModelIndex index); |
36 | 36 | ||
37 | Q_INVOKABLE ThreadModel * | ||
38 | threadModel (int idx); | ||
39 | |||
40 | ThreadModel * | ||
41 | threadModel (QModelIndex index); | ||
42 | |||
37 | #if FIXME | 43 | #if FIXME |
38 | bool | 44 | bool |
39 | contains (QString id); | 45 | contains (QString id); |
diff --git a/src/model/ThreadModel.cpp b/src/model/ThreadModel.cpp index e72d2e6..4f5b2f6 100644 --- a/src/model/ThreadModel.cpp +++ b/src/model/ThreadModel.cpp | |||
@@ -1,5 +1,7 @@ | |||
1 | |||
1 | #include "ThreadModel.h" | 2 | #include "ThreadModel.h" |
2 | 3 | ||
4 | #include <QDebug> | ||
3 | 5 | ||
4 | ThreadModel::ThreadModel (Message *root, QObject *parent) | 6 | ThreadModel::ThreadModel (Message *root, QObject *parent) |
5 | : QAbstractItemModel (parent) | 7 | : QAbstractItemModel (parent) |
@@ -20,13 +22,6 @@ ThreadModel::setRoot (Message *root) | |||
20 | } | 22 | } |
21 | 23 | ||
22 | 24 | ||
23 | int | ||
24 | ThreadModel::columnCount (const QModelIndex &parent) const | ||
25 | { | ||
26 | return 1; | ||
27 | } | ||
28 | |||
29 | |||
30 | Qt::ItemFlags | 25 | Qt::ItemFlags |
31 | ThreadModel::flags (const QModelIndex &index) const | 26 | ThreadModel::flags (const QModelIndex &index) const |
32 | { | 27 | { |
@@ -34,15 +29,25 @@ ThreadModel::flags (const QModelIndex &index) const | |||
34 | } | 29 | } |
35 | 30 | ||
36 | 31 | ||
37 | QVariant | 32 | int |
38 | ThreadModel::data (const QModelIndex &index, | 33 | ThreadModel::rowCount (const QModelIndex &parent) const |
39 | int role) const | ||
40 | { | 34 | { |
41 | if (role != Qt::DisplayRole || !index.isValid()) | 35 | if (0 != parent.column ()) |
42 | return QVariant (); | 36 | return 0; |
43 | 37 | ||
44 | Message *msg = static_cast<Message *> (index.internalPointer()); | 38 | Message * |
45 | return QVariant::fromValue (msg); | 39 | msg = (parent.isValid ()) |
40 | ? static_cast<Message *> (parent.internalPointer()) | ||
41 | : m_root; | ||
42 | |||
43 | return msg->childrenCount (); | ||
44 | } | ||
45 | |||
46 | |||
47 | int | ||
48 | ThreadModel::columnCount (const QModelIndex &parent) const | ||
49 | { | ||
50 | return 1; | ||
46 | } | 51 | } |
47 | 52 | ||
48 | 53 | ||
@@ -74,24 +79,34 @@ ThreadModel::parent (const QModelIndex &index) const | |||
74 | Message *child = static_cast<Message *> (index.internalPointer()); | 79 | Message *child = static_cast<Message *> (index.internalPointer()); |
75 | Message *parent = child->parent (); | 80 | Message *parent = child->parent (); |
76 | 81 | ||
77 | return (parent == m_root) | 82 | return (parent == m_root || parent == 0) |
78 | ? QModelIndex () | 83 | ? QModelIndex () |
79 | : createIndex (parent->index(), 0, parent); | 84 | : createIndex (parent->index(), 0, parent); |
80 | } | 85 | } |
81 | 86 | ||
82 | 87 | ||
83 | int | 88 | QVariant |
84 | ThreadModel::rowCount (const QModelIndex &parent) const | 89 | ThreadModel::data (const QModelIndex &index, int role) const |
85 | { | 90 | { |
86 | if (0 != parent.column ()) | 91 | if (role != Qt::DisplayRole || !index.isValid()) |
87 | return 0; | 92 | return QVariant (); |
88 | 93 | ||
89 | Message * | 94 | Message *msg = static_cast<Message *> (index.internalPointer()); |
90 | msg = (parent.isValid ()) | 95 | return QVariant::fromValue (msg); |
91 | ? static_cast<Message *> (parent.internalPointer()) | 96 | } |
92 | : m_root; | ||
93 | 97 | ||
94 | return msg->childrenCount (); | 98 | |
99 | QModelIndex | ||
100 | ThreadModel::index (Message *msg) | ||
101 | { | ||
102 | if (m_index.contains (msg)) | ||
103 | { | ||
104 | return m_index[msg]; | ||
105 | } | ||
106 | else | ||
107 | { | ||
108 | return QModelIndex (); | ||
109 | } | ||
95 | } | 110 | } |
96 | 111 | ||
97 | 112 | ||
@@ -101,10 +116,20 @@ ThreadModel::rowCount (const QModelIndex &parent) const | |||
101 | void | 116 | void |
102 | ThreadModel::rowAdded (Message *msg) | 117 | ThreadModel::rowAdded (Message *msg) |
103 | { | 118 | { |
104 | #if FIXME | 119 | int idx = msg->index (); |
105 | int idx = m_data.count () - 1; | 120 | qDebug () << "ThreadModel::rowAdded: " << idx; |
121 | |||
122 | if (!msg->parent ()) | ||
123 | { | ||
124 | qDebug () << "ThreadModel::rowAdded: no parent found"; | ||
125 | Q_ASSERT (0); | ||
126 | return; | ||
127 | } | ||
128 | |||
129 | QModelIndex parent = index (msg->parent ()); | ||
130 | m_index[msg] = createIndex (idx, 0, msg); | ||
106 | 131 | ||
107 | beginInsertRows (QModelIndex (), idx, idx); | 132 | beginInsertRows (parent, idx, idx); |
108 | endInsertRows (); | 133 | endInsertRows (); |
109 | 134 | ||
110 | connect (msg, &Message::modified, | 135 | connect (msg, &Message::modified, |
@@ -112,15 +137,12 @@ ThreadModel::rowAdded (Message *msg) | |||
112 | 137 | ||
113 | connect (msg, &Message::childAdded, | 138 | connect (msg, &Message::childAdded, |
114 | this, &ThreadModel::rowAdded); | 139 | this, &ThreadModel::rowAdded); |
115 | #endif | ||
116 | } | 140 | } |
117 | 141 | ||
118 | 142 | ||
119 | void | 143 | void |
120 | ThreadModel::rowModified (Message *msg) | 144 | ThreadModel::rowModified (Message *msg) |
121 | { | 145 | { |
122 | #if FIXME | 146 | QModelIndex index = m_index[msg]; |
123 | QModelIndex index = this->index (msg->index ()); | ||
124 | emit dataChanged (index, index); | 147 | emit dataChanged (index, index); |
125 | #endif | ||
126 | } | 148 | } |
diff --git a/src/model/ThreadModel.h b/src/model/ThreadModel.h index 656373b..ff1111f 100644 --- a/src/model/ThreadModel.h +++ b/src/model/ThreadModel.h | |||
@@ -45,6 +45,10 @@ class ThreadModel : public QAbstractItemModel | |||
45 | columnCount (const QModelIndex &parent = QModelIndex()) | 45 | columnCount (const QModelIndex &parent = QModelIndex()) |
46 | const Q_DECL_OVERRIDE; | 46 | const Q_DECL_OVERRIDE; |
47 | 47 | ||
48 | QModelIndex | ||
49 | index (Message *msg); | ||
50 | |||
51 | |||
48 | public slots: | 52 | public slots: |
49 | 53 | ||
50 | void | 54 | void |
@@ -56,6 +60,7 @@ class ThreadModel : public QAbstractItemModel | |||
56 | private: | 60 | private: |
57 | 61 | ||
58 | Message *m_root; | 62 | Message *m_root; |
63 | QHash<Message *, QModelIndex> m_index; | ||
59 | }; | 64 | }; |
60 | 65 | ||
61 | #endif | 66 | #endif |
diff --git a/src/social/message.cpp b/src/social/message.cpp index 41b1d3a..abc3f9c 100644 --- a/src/social/message.cpp +++ b/src/social/message.cpp | |||
@@ -55,6 +55,13 @@ Message::Message (const char *method, | |||
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | Message::~Message () | ||
59 | { | ||
60 | // FIXME: delete children? | ||
61 | emit deleted (this); | ||
62 | } | ||
63 | |||
64 | |||
58 | /*** PSYC ***/ | 65 | /*** PSYC ***/ |
59 | 66 | ||
60 | 67 | ||
diff --git a/src/social/message.h b/src/social/message.h index 5e36477..b3735ef 100644 --- a/src/social/message.h +++ b/src/social/message.h | |||
@@ -49,6 +49,8 @@ class Message : public QObject | |||
49 | GNUNET_SOCIAL_Nym *nym = 0, | 49 | GNUNET_SOCIAL_Nym *nym = 0, |
50 | Message *parent = 0); | 50 | Message *parent = 0); |
51 | 51 | ||
52 | ~Message (); | ||
53 | |||
52 | /*** PSYC ***/ | 54 | /*** PSYC ***/ |
53 | 55 | ||
54 | void | 56 | void |
@@ -178,6 +180,7 @@ class Message : public QObject | |||
178 | m_data = text.toUtf8 (); | 180 | m_data = text.toUtf8 (); |
179 | } | 181 | } |
180 | 182 | ||
183 | |||
181 | signals: | 184 | signals: |
182 | 185 | ||
183 | void | 186 | void |
@@ -186,6 +189,9 @@ class Message : public QObject | |||
186 | void | 189 | void |
187 | childAdded (Message *msg); | 190 | childAdded (Message *msg); |
188 | 191 | ||
192 | void | ||
193 | deleted (Message *msg); | ||
194 | |||
189 | private: | 195 | private: |
190 | 196 | ||
191 | uint64_t m_id; | 197 | uint64_t m_id; |
@@ -197,6 +203,8 @@ class Message : public QObject | |||
197 | QList<Message *> m_children; | 203 | QList<Message *> m_children; |
198 | Message *m_parent; | 204 | Message *m_parent; |
199 | 205 | ||
206 | void *m_ptr; | ||
207 | |||
200 | static int | 208 | static int |
201 | iterateEnv (void *cls, GNUNET_PSYC_Operator oper, | 209 | iterateEnv (void *cls, GNUNET_PSYC_Operator oper, |
202 | const char *name, const char *value, | 210 | const char *name, const char *value, |
diff --git a/src/social/socialapp.cpp b/src/social/socialapp.cpp index 75279fd..e739574 100644 --- a/src/social/socialapp.cpp +++ b/src/social/socialapp.cpp | |||
@@ -1,8 +1,8 @@ | |||
1 | #include "social/socialapp.h" | 1 | #include "socialapp.h" |
2 | #include "app.h" | 2 | #include "app.h" |
3 | 3 | ||
4 | #include "social/host.h" | 4 | #include "host.h" |
5 | #include "social/guest.h" | 5 | #include "guest.h" |
6 | 6 | ||
7 | 7 | ||
8 | SocialApp::SocialApp (struct GNUNET_CONFIGURATION_Handle *config, | 8 | SocialApp::SocialApp (struct GNUNET_CONFIGURATION_Handle *config, |
diff --git a/src/social/socialapp.h b/src/social/socialapp.h index 7bb7219..36b4ee4 100644 --- a/src/social/socialapp.h +++ b/src/social/socialapp.h | |||
@@ -4,8 +4,8 @@ | |||
4 | #include <QObject> | 4 | #include <QObject> |
5 | #include <QDebug> | 5 | #include <QDebug> |
6 | 6 | ||
7 | #include "social/ego.h" | 7 | #include "ego.h" |
8 | #include "social/place.h" | 8 | #include "place.h" |
9 | #include "gnunet.h" | 9 | #include "gnunet.h" |
10 | 10 | ||
11 | class SocialApp : public QObject | 11 | class SocialApp : public QObject |