summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortg(x) <*@tg-x.net>2016-03-18 00:53:30 +0100
committertg(x) <*@tg-x.net>2016-03-18 00:53:30 +0100
commitfdd50e49e8e7598984700872bd7720f9daec7f58 (patch)
tree744a530f0fb1c7a95056bfce4f85c06e75c518e8
parente8a36ec5b3315b5f73bc75f7e7938e159f8cfaa6 (diff)
downloadsecushare-fdd50e49e8e7598984700872bd7720f9daec7f58.tar.gz
secushare-fdd50e49e8e7598984700872bd7720f9daec7f58.zip
models
-rw-r--r--secushare.pro2
-rw-r--r--src/app.cpp30
-rw-r--r--src/app.h26
-rw-r--r--src/model/EgoListModel.cpp8
-rw-r--r--src/model/EgoListModel.h4
-rw-r--r--src/model/NymListModel.cpp8
-rw-r--r--src/model/NymListModel.h6
-rw-r--r--src/model/PlaceListModel.cpp60
-rw-r--r--src/model/PlaceListModel.h15
-rw-r--r--src/model/ThreadListModel.cpp153
-rw-r--r--src/model/ThreadListModel.h69
-rw-r--r--src/model/ThreadModel.cpp31
-rw-r--r--src/model/ThreadModel.h8
-rw-r--r--src/social/message.cpp2
-rw-r--r--src/social/message.h5
-rw-r--r--src/social/nym.h5
-rw-r--r--src/social/place.cpp17
-rw-r--r--src/social/place.h34
-rw-r--r--src/social/socialapp.cpp37
-rw-r--r--src/social/socialapp.h22
20 files changed, 423 insertions, 119 deletions
diff --git a/secushare.pro b/secushare.pro
index bea042b..05da98d 100644
--- a/secushare.pro
+++ b/secushare.pro
@@ -25,6 +25,7 @@ SOURCES += src/main.cpp \
25 src/model/EgoListModel.cpp \ 25 src/model/EgoListModel.cpp \
26 src/model/NymListModel.cpp \ 26 src/model/NymListModel.cpp \
27 src/model/PlaceListModel.cpp \ 27 src/model/PlaceListModel.cpp \
28 src/model/ThreadListModel.cpp \
28 src/model/ThreadModel.cpp \ 29 src/model/ThreadModel.cpp \
29 src/gnunet/gnunet.cpp \ 30 src/gnunet/gnunet.cpp \
30 src/social/socialapp.cpp \ 31 src/social/socialapp.cpp \
@@ -55,6 +56,7 @@ HEADERS += \
55 src/model/EgoListModel.h \ 56 src/model/EgoListModel.h \
56 src/model/NymListModel.h \ 57 src/model/NymListModel.h \
57 src/model/PlaceListModel.h \ 58 src/model/PlaceListModel.h \
59 src/model/ThreadListModel.h \
58 src/model/ThreadModel.h \ 60 src/model/ThreadModel.h \
59 src/social/socialapp.h \ 61 src/social/socialapp.h \
60 src/social/nym.h \ 62 src/social/nym.h \
diff --git a/src/app.cpp b/src/app.cpp
index 91d3af7..c59856b 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -82,12 +82,20 @@ App::setConnected (bool connected)
82 if (connected) 82 if (connected)
83 { 83 {
84 m_models->setEgos (new EgoListModel (m_gnunet->social ()->egos (), this)); 84 m_models->setEgos (new EgoListModel (m_gnunet->social ()->egos (), this));
85 connect (m_gnunet->social (), &SocialApp::egoAddedSignal, 85 connect (m_gnunet->social (), &SocialApp::egoAdded,
86 m_models->egos (), &EgoListModel::rowAddedSlot); 86 m_models->egos (), &EgoListModel::rowAdded);
87 87
88 m_models->setPlaces (new PlaceListModel (m_gnunet->social ()->places (), this)); 88 m_models->setPlaces (new PlaceListModel (m_gnunet->social ()->places (), this));
89 connect (m_gnunet->social (), &SocialApp::placeAddedSignal, 89 connect (m_gnunet->social (), &SocialApp::placeAdded,
90 m_models->places (), &PlaceListModel::rowAddedSlot); 90 m_models->places (), &PlaceListModel::rowAdded);
91
92 // FIXME: threads
93
94 connect (this, &App::createPlaceSignal,
95 m_gnunet->social (), &SocialApp::createPlaceSlot, Qt::QueuedConnection);
96
97 connect (this, &App::enterPlaceSignal,
98 m_gnunet->social (), &SocialApp::enterPlaceSlot, Qt::QueuedConnection);
91 } 99 }
92 100
93 m_connected = connected; 101 m_connected = connected;
@@ -95,6 +103,20 @@ App::setConnected (bool connected)
95} 103}
96 104
97 105
106void
107App::createPlace (QString egoPubKeyStr)
108{
109 emit createPlaceSignal (egoPubKeyStr);
110}
111
112
113void
114App::enterPlace (QString egoPubKeyStr, QString pubKeyStr, QString peerIdStr)
115{
116 emit enterPlaceSignal (egoPubKeyStr, pubKeyStr, peerIdStr);
117}
118
119
98// theApp singleton type provider 120// theApp singleton type provider
99static QObject * 121static QObject *
100theApp_provider (QQmlEngine * engine, QJSEngine * scriptEngine) 122theApp_provider (QQmlEngine * engine, QJSEngine * scriptEngine)
diff --git a/src/app.h b/src/app.h
index d187806..eca9460 100644
--- a/src/app.h
+++ b/src/app.h
@@ -67,9 +67,20 @@ public:
67 return m_gnunet ? m_gnunet->social () : NULL; 67 return m_gnunet ? m_gnunet->social () : NULL;
68 } 68 }
69 69
70 void setupTray (); 70 void
71 Q_INVOKABLE void hide (); 71 setupTray ();
72 Q_INVOKABLE void close (); 72
73 Q_INVOKABLE void
74 hide ();
75
76 Q_INVOKABLE void
77 close ();
78
79 Q_INVOKABLE void
80 createPlace (QString egoPubKeyStr);
81
82 Q_INVOKABLE void
83 enterPlace (QString egoPubKeyStr, QString pubKeyStr, QString peerIdStr);
73 84
74 void setConnected (bool connected); 85 void setConnected (bool connected);
75 86
@@ -99,7 +110,14 @@ private:
99 110
100 signals: 111 signals:
101 112
102 void connectedChanged (bool connected); 113 void
114 connectedChanged (bool connected);
115
116 void
117 createPlaceSignal (QString egoPubKeyStr);
118
119 void
120 enterPlaceSignal (QString egoPubKeyStr, QString pubKey, QString peerId);
103 121
104 public slots: 122 public slots:
105 123
diff --git a/src/model/EgoListModel.cpp b/src/model/EgoListModel.cpp
index 0e279bb..0cef0d4 100644
--- a/src/model/EgoListModel.cpp
+++ b/src/model/EgoListModel.cpp
@@ -80,14 +80,14 @@ EgoListModel::roleNames () const
80 * An ego was added to the source data. 80 * An ego was added to the source data.
81 */ 81 */
82void 82void
83EgoListModel::rowAddedSlot (Ego *ego) 83EgoListModel::rowAdded (Ego *ego)
84{ 84{
85 int index = m_data.count (); 85 int index = m_data.count ();
86 beginInsertRows (QModelIndex (), index, index); 86 beginInsertRows (QModelIndex (), index, index);
87 ego->setIndex (index); 87 ego->setIndex (index);
88 88
89 connect (ego, &Ego::modifiedSignal, 89 connect (ego, &Ego::modified,
90 this, &EgoListModel::rowModifiedSlot); 90 this, &EgoListModel::rowModified);
91 91
92 //m_lookupIndex[pubKey] = index; 92 //m_lookupIndex[pubKey] = index;
93 endInsertRows (); 93 endInsertRows ();
@@ -95,7 +95,7 @@ EgoListModel::rowAddedSlot (Ego *ego)
95 95
96 96
97void 97void
98EgoListModel::rowModifiedSlot (int index) 98EgoListModel::rowModified (int index)
99{ 99{
100 QModelIndex modelIndex = this->index (index); 100 QModelIndex modelIndex = this->index (index);
101 emit dataChanged (modelIndex, modelIndex); 101 emit dataChanged (modelIndex, modelIndex);
diff --git a/src/model/EgoListModel.h b/src/model/EgoListModel.h
index c75aa07..bb2d94b 100644
--- a/src/model/EgoListModel.h
+++ b/src/model/EgoListModel.h
@@ -64,10 +64,10 @@ public:
64public slots: 64public slots:
65 65
66 void 66 void
67 rowAddedSlot (Ego *ego); 67 rowAdded (Ego *ego);
68 68
69 void 69 void
70 rowModifiedSlot (int index); 70 rowModified (int index);
71 71
72private slots: 72private slots:
73 73
diff --git a/src/model/NymListModel.cpp b/src/model/NymListModel.cpp
index da5ab17..76fa9a4 100644
--- a/src/model/NymListModel.cpp
+++ b/src/model/NymListModel.cpp
@@ -80,14 +80,14 @@ NymListModel::roleNames () const
80 * An nym was added to the source data. 80 * An nym was added to the source data.
81 */ 81 */
82void 82void
83NymListModel::rowAddedSlot (Nym *nym) 83NymListModel::rowAdded (Nym *nym)
84{ 84{
85 int index = m_data.count (); 85 int index = m_data.count ();
86 beginInsertRows (QModelIndex (), index, index); 86 beginInsertRows (QModelIndex (), index, index);
87 nym->setIndex (index); 87 nym->setIndex (index);
88 88
89 connect (nym, &Nym::modifiedSignal, 89 connect (nym, &Nym::modified,
90 this, &NymListModel::rowModifiedSlot); 90 this, &NymListModel::rowModified);
91 91
92 //m_lookupIndex[pubKey] = index; 92 //m_lookupIndex[pubKey] = index;
93 endInsertRows (); 93 endInsertRows ();
@@ -95,7 +95,7 @@ NymListModel::rowAddedSlot (Nym *nym)
95 95
96 96
97void 97void
98NymListModel::rowModifiedSlot (int index) 98NymListModel::rowModified (int index)
99{ 99{
100 QModelIndex modelIndex = this->index (index); 100 QModelIndex modelIndex = this->index (index);
101 emit dataChanged (modelIndex, modelIndex); 101 emit dataChanged (modelIndex, modelIndex);
diff --git a/src/model/NymListModel.h b/src/model/NymListModel.h
index 01f8095..c680d98 100644
--- a/src/model/NymListModel.h
+++ b/src/model/NymListModel.h
@@ -64,12 +64,10 @@ public:
64public slots: 64public slots:
65 65
66 void 66 void
67 rowAddedSlot (Nym *ego); 67 rowAdded (Nym *ego);
68 68
69 void 69 void
70 rowModifiedSlot (int index); 70 rowModified (int index);
71
72private slots:
73 71
74private: 72private:
75 73
diff --git a/src/model/PlaceListModel.cpp b/src/model/PlaceListModel.cpp
index 896fa22..d14ac60 100644
--- a/src/model/PlaceListModel.cpp
+++ b/src/model/PlaceListModel.cpp
@@ -1,5 +1,6 @@
1/* 1/*
2 This file is part of SecureShare 2 This file is part of SecureShare
3
3 (C) 2013 Bruno Cabral (and other contributing authors) 4 (C) 2013 Bruno Cabral (and other contributing authors)
4 5
5 SecureShare is free software; you can redistribute it and/or modify 6 SecureShare is free software; you can redistribute it and/or modify
@@ -26,15 +27,20 @@
26#include "PlaceListModel.h" 27#include "PlaceListModel.h"
27 28
28 29
29PlaceListModel::PlaceListModel (const QList<Place *> &data, QObject * parent) 30PlaceListModel::PlaceListModel (const QList<Place *> &data, QObject *parent)
30 : QAbstractListModel (parent), 31 : QAbstractListModel (parent),
31 m_data (data) 32 m_data (data)
32{ 33{
34 QListIterator<Place *> it (m_data);
35 while (it.hasNext ())
36 {
37 rowAdded (it.next ());
38 }
33} 39}
34 40
35 41
36int 42int
37PlaceListModel::rowCount (const QModelIndex & parent) const 43PlaceListModel::rowCount (const QModelIndex &parent) const
38{ 44{
39 Q_UNUSED (parent); 45 Q_UNUSED (parent);
40 return m_data.size (); 46 return m_data.size ();
@@ -42,32 +48,29 @@ PlaceListModel::rowCount (const QModelIndex & parent) const
42 48
43 49
44QVariant 50QVariant
45PlaceListModel::data (const QModelIndex & index, int role) const 51PlaceListModel::data (const QModelIndex &index, int role) const
46{ 52{
47 if (index.row () < 0 || index.row () >= m_data.count ()) 53 int idx = index.row ();
48 return QVariant (); 54 if (idx < 0 || m_data.count () <= idx)
55 return QVariant::Invalid;
49 56
50 Place *place = m_data[index.row ()]; 57 Place *place = m_data[idx];
51 58
52 switch (role) 59 switch (role)
53 { 60 {
54 case NAME: 61 case NAME:
55 return place->name (); 62 return place->name ();
56 break;
57 case PUBKEY: 63 case PUBKEY:
58 return place->pubKeyString (); 64 return place->pubKeyString ();
59 break;
60 case TYPE: 65 case TYPE:
61 return place->type (); 66 return place->type ();
62 break;
63 case DESC: 67 case DESC:
64 return place->desc (); 68 return place->desc ();
65 break; 69 case THREADS:
70 return &m_threads[idx];
66 default: 71 default:
67 return QVariant::Invalid; 72 return QVariant::Invalid;
68 } 73 }
69
70 return QVariant::Invalid;
71} 74}
72 75
73 76
@@ -76,6 +79,7 @@ PlaceListModel::roleNames () const
76{ 79{
77 QHash<int, QByteArray> roles; 80 QHash<int, QByteArray> roles;
78 81
82 // FIXME: roles[PLACE] = "place";
79 roles[NAME] = "name"; 83 roles[NAME] = "name";
80 roles[PUBKEY] = "pubKey"; 84 roles[PUBKEY] = "pubKey";
81 roles[TYPE] = "type"; 85 roles[TYPE] = "type";
@@ -89,32 +93,34 @@ PlaceListModel::roleNames () const
89 * A place was added to the source data. 93 * A place was added to the source data.
90 */ 94 */
91void 95void
92PlaceListModel::rowAddedSlot (Place *place) 96PlaceListModel::rowAdded (Place *place)
93{ 97{
94 int index = m_data.count () - 1; 98 int idx = m_data.count () - 1;
95 qDebug () << "PlaceListModel::rowAddedSlot: " << index; 99 qDebug () << "PlaceListModel::rowAdded: " << idx;
96
97 beginInsertRows (QModelIndex (), index, index);
98 place->setIndex (index);
99 100
100 connect (place, &Place::modifiedSignal, 101 m_threads += new ThreadListModel (place->threads (), this);
101 this, &PlaceListModel::rowModifiedSlot);
102 102
103 //m_lookupIndex[pubKey] = index; 103 beginInsertRows (QModelIndex (), idx, idx);
104 endInsertRows (); 104 endInsertRows ();
105
106 connect (place, &Place::modified,
107 this, &PlaceListModel::rowModified);
108
109 connect (place, &Place::threadAdded,
110 m_threads[idx], &ThreadListModel::rowAdded);
105} 111}
106 112
107 113
108void 114void
109PlaceListModel::rowModifiedSlot (int index) 115PlaceListModel::rowModified (Place *place)
110{ 116{
111 QModelIndex modelIndex = this->index (index); 117 QModelIndex index = this->index (place->index ());
112 emit dataChanged (modelIndex, modelIndex); 118 emit dataChanged (index, index);
113} 119}
114 120
115 121
116int 122int
117PlaceListModel::getCount () 123PlaceListModel::count ()
118{ 124{
119 return m_data.count (); 125 return m_data.count ();
120} 126}
@@ -123,7 +129,7 @@ PlaceListModel::getCount ()
123Place * 129Place *
124PlaceListModel::get (int index) 130PlaceListModel::get (int index)
125{ 131{
126 if (index < 0 || getCount () < index) 132 if (index < 0 || count () < index)
127 return NULL; 133 return NULL;
128 134
129 Place *place = m_data[index]; 135 Place *place = m_data[index];
@@ -138,7 +144,7 @@ PlaceListModel::get (int index)
138Place * 144Place *
139PlaceListModel::get (QModelIndex index) 145PlaceListModel::get (QModelIndex index)
140{ 146{
141 if (getCount () < index.row ()) 147 if (count () < index.row ())
142 return NULL; 148 return NULL;
143 149
144 return m_data[index.row ()]; 150 return m_data[index.row ()];
diff --git a/src/model/PlaceListModel.h b/src/model/PlaceListModel.h
index d93a3f4..b3c9941 100644
--- a/src/model/PlaceListModel.h
+++ b/src/model/PlaceListModel.h
@@ -23,6 +23,7 @@
23 23
24#include <QAbstractListModel> 24#include <QAbstractListModel>
25 25
26#include "ThreadListModel.h"
26#include "social/place.h" 27#include "social/place.h"
27 28
28 29
@@ -38,6 +39,7 @@ class PlaceListModel : public QAbstractListModel
38 PUBKEY, 39 PUBKEY,
39 TYPE, 40 TYPE,
40 DESC, 41 DESC,
42 THREADS,
41 PLACELIST_ROLE_COUNT 43 PLACELIST_ROLE_COUNT
42 }; 44 };
43 45
@@ -45,7 +47,7 @@ class PlaceListModel : public QAbstractListModel
45 PlaceListModel (const QList<Place *> &data, QObject *parent = 0); 47 PlaceListModel (const QList<Place *> &data, QObject *parent = 0);
46 48
47 Q_INVOKABLE int 49 Q_INVOKABLE int
48 getCount (); 50 count ();
49 51
50 Q_INVOKABLE Place * 52 Q_INVOKABLE Place *
51 get (int index); 53 get (int index);
@@ -64,22 +66,25 @@ class PlaceListModel : public QAbstractListModel
64 public slots: 66 public slots:
65 67
66 void 68 void
67 rowAddedSlot (Place *place); 69 rowAdded (Place *place);
68 70
69 void 71 void
70 rowModifiedSlot (int index); 72 rowModified (Place *place);
71 73
72 private: 74 private:
73 75
74 int 76 int
75 rowCount (const QModelIndex & parent) const; 77 rowCount (const QModelIndex &parent) const;
78
76 QVariant 79 QVariant
77 data (const QModelIndex &index, int role) const; 80 data (const QModelIndex &index, int role) const;
81
78 QHash<int, QByteArray> 82 QHash<int, QByteArray>
79 roleNames () const; 83 roleNames () const;
80 84
81 const QList<Place *> &m_data; 85 const QList<Place *> &m_data;
82 //QHash<QString, int> m_lookupIndex; 86
87 QList<ThreadListModel *> m_threads;
83}; 88};
84 89
85#endif 90#endif
diff --git a/src/model/ThreadListModel.cpp b/src/model/ThreadListModel.cpp
new file mode 100644
index 0000000..02f0092
--- /dev/null
+++ b/src/model/ThreadListModel.cpp
@@ -0,0 +1,153 @@
1#include <sstream>
2#include <QQmlEngine>
3#include <QDebug>
4
5#include "ThreadListModel.h"
6
7
8ThreadListModel::ThreadListModel (const QList<Message *> &data, QObject * parent)
9 : QAbstractListModel (parent),
10 m_data (data)
11{
12 QListIterator<Message *> it (m_data);
13 while (it.hasNext ())
14 {
15 rowAdded (it.next ());
16 }
17}
18
19
20int
21ThreadListModel::rowCount (const QModelIndex & parent) const
22{
23 Q_UNUSED (parent);
24 return m_data.size ();
25}
26
27
28QVariant
29ThreadListModel::data (const QModelIndex & index, int role) const
30{
31 int idx = index.row ();
32 if (idx < 0 || m_data.count () <= idx)
33 return QVariant::Invalid;
34
35 Message *msg = m_data[idx];
36
37 switch (role)
38 {
39#if FIXME
40 case NAME:
41 return msg->name ();
42 case PUBKEY:
43 return msg->pubKeyString ();
44 case TYPE:
45 return msg->type ();
46 case DESC:
47 return msg->desc ();
48#endif
49 default:
50 return QVariant::Invalid;
51 }
52}
53
54
55QHash<int, QByteArray>
56ThreadListModel::roleNames () const
57{
58 QHash<int, QByteArray> roles;
59
60 roles[TITLE] = "title";
61 roles[TEXT] = "text";
62 roles[TYPE] = "type";
63 roles[PUBKEY] = "pubKey";
64
65 return roles;
66}
67
68
69/**
70 * A message was added to the source data.
71 */
72void
73ThreadListModel::rowAdded (Message *msg)
74{
75 int idx = m_data.count () - 1;
76 qDebug () << "ThreadListModel::rowAdded: " << idx;
77
78 m_thread += new ThreadModel (msg, this);
79
80 beginInsertRows (QModelIndex (), idx, idx);
81 endInsertRows ();
82
83 connect (msg, &Message::modified,
84 this, &ThreadListModel::rowModified);
85
86 connect (msg, &Message::childAdded,
87 m_thread[idx], &ThreadModel::rowAdded);
88
89}
90
91
92void
93ThreadListModel::rowModified (Message *msg)
94{
95 QModelIndex index = this->index (msg->index ());
96 emit dataChanged (index, index);
97}
98
99
100int
101ThreadListModel::count ()
102{
103 return m_data.count ();
104}
105
106
107Message *
108ThreadListModel::get (int index)
109{
110 if (index < 0 || count () < index)
111 return NULL;
112
113 Message *msg = m_data[index];
114
115 //Set the ownership so QML don't delete it.
116 QQmlEngine::setObjectOwnership (msg, QQmlEngine::CppOwnership);
117
118 return msg;
119}
120
121
122Message *
123ThreadListModel::get (QModelIndex index)
124{
125 if (count () < index.row ())
126 return NULL;
127
128 return m_data[index.row ()];
129}
130
131
132#if FIXME
133bool
134ThreadListModel::contains (QString id)
135{
136 return m_lookupIndex.contains (id);
137}
138
139
140Message *
141ThreadListModel::get (QString key)
142{
143 if (m_lookupIndex.contains (key))
144 {
145 Message *msg = m_data[m_lookupIndex[key]];
146
147 return msg;
148
149 }
150 else
151 return NULL;
152}
153#endif
diff --git a/src/model/ThreadListModel.h b/src/model/ThreadListModel.h
new file mode 100644
index 0000000..d5a664d
--- /dev/null
+++ b/src/model/ThreadListModel.h
@@ -0,0 +1,69 @@
1#ifndef THREADLISTMODEL_H
2#define THREADLISTMODEL_H
3
4#include <QAbstractListModel>
5
6#include "ThreadModel.h"
7#include "social/place.h"
8
9
10class ThreadListModel : public QAbstractListModel
11{
12 Q_OBJECT;
13
14 public:
15
16 enum ThreadListRoles
17 {
18 TITLE = Qt::UserRole + 1,
19 TYPE,
20 TEXT,
21 PUBKEY,
22 THREADLIST_ROLE_COUNT
23 };
24
25 explicit
26 ThreadListModel (const QList<Message *> &data, QObject *parent = 0);
27
28 Q_INVOKABLE int
29 count ();
30
31 Q_INVOKABLE Message *
32 get (int index);
33
34 Message *
35 get (QModelIndex index);
36
37#if FIXME
38 bool
39 contains (QString id);
40
41 Message *
42 get (QString key);
43#endif
44
45 public slots:
46
47 void
48 rowAdded (Message *msg);
49
50 void
51 rowModified (Message *msg);
52
53 private:
54
55 int
56 rowCount (const QModelIndex &parent) const;
57
58 QVariant
59 data (const QModelIndex &index, int role) const;
60
61 QHash<int, QByteArray>
62 roleNames () const;
63
64 const QList<Message *> &m_data;
65
66 QList<ThreadModel *> m_thread;
67};
68
69#endif
diff --git a/src/model/ThreadModel.cpp b/src/model/ThreadModel.cpp
index a41b6a2..e72d2e6 100644
--- a/src/model/ThreadModel.cpp
+++ b/src/model/ThreadModel.cpp
@@ -93,3 +93,34 @@ ThreadModel::rowCount (const QModelIndex &parent) const
93 93
94 return msg->childrenCount (); 94 return msg->childrenCount ();
95} 95}
96
97
98/**
99 * A message was added to the source data.
100 */
101void
102ThreadModel::rowAdded (Message *msg)
103{
104#if FIXME
105 int idx = m_data.count () - 1;
106
107 beginInsertRows (QModelIndex (), idx, idx);
108 endInsertRows ();
109
110 connect (msg, &Message::modified,
111 this, &ThreadModel::rowModified);
112
113 connect (msg, &Message::childAdded,
114 this, &ThreadModel::rowAdded);
115#endif
116}
117
118
119void
120ThreadModel::rowModified (Message *msg)
121{
122#if FIXME
123 QModelIndex index = this->index (msg->index ());
124 emit dataChanged (index, index);
125#endif
126}
diff --git a/src/model/ThreadModel.h b/src/model/ThreadModel.h
index 7d48afc..656373b 100644
--- a/src/model/ThreadModel.h
+++ b/src/model/ThreadModel.h
@@ -45,6 +45,14 @@ 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 public slots:
49
50 void
51 rowAdded (Message *msg);
52
53 void
54 rowModified (Message *msg);
55
48 private: 56 private:
49 57
50 Message *m_root; 58 Message *m_root;
diff --git a/src/social/message.cpp b/src/social/message.cpp
index db5bf7b..41b1d3a 100644
--- a/src/social/message.cpp
+++ b/src/social/message.cpp
@@ -155,7 +155,7 @@ Message::appendChild (Message *msg)
155{ 155{
156 m_children.append (msg); 156 m_children.append (msg);
157 msg->setParent (this); 157 msg->setParent (this);
158 emit messageAdded (msg); 158 emit childAdded (msg);
159} 159}
160 160
161 161
diff --git a/src/social/message.h b/src/social/message.h
index f45395a..5e36477 100644
--- a/src/social/message.h
+++ b/src/social/message.h
@@ -181,7 +181,10 @@ class Message : public QObject
181 signals: 181 signals:
182 182
183 void 183 void
184 messageAdded (Message *msg); 184 modified (Message *msg);
185
186 void
187 childAdded (Message *msg);
185 188
186 private: 189 private:
187 190
diff --git a/src/social/nym.h b/src/social/nym.h
index d961c69..9c7b88b 100644
--- a/src/social/nym.h
+++ b/src/social/nym.h
@@ -44,7 +44,7 @@ class Nym : public QObject
44 { 44 {
45 m_name = name; 45 m_name = name;
46 emit nameChanged (name); 46 emit nameChanged (name);
47 emit modifiedSignal (m_index); 47 emit modified (m_index);
48 } 48 }
49 49
50 50
@@ -72,6 +72,7 @@ class Nym : public QObject
72 { 72 {
73 m_name = m_pubKeyStr.left (8); 73 m_name = m_pubKeyStr.left (8);
74 } 74 }
75 emit modified (m_index);
75 } 76 }
76 77
77 QString 78 QString
@@ -104,7 +105,7 @@ class Nym : public QObject
104 105
105 signals: 106 signals:
106 107
107 void modifiedSignal (int index); 108 void modified (int index);
108 void nameChanged (QString name); 109 void nameChanged (QString name);
109 110
110}; 111};
diff --git a/src/social/place.cpp b/src/social/place.cpp
index b7e5179..8b1f4f3 100644
--- a/src/social/place.cpp
+++ b/src/social/place.cpp
@@ -20,8 +20,10 @@ Place::Place (QObject *parent) : QObject (parent)
20 m_msg = 0; 20 m_msg = 0;
21 m_mod = 0; 21 m_mod = 0;
22 22
23 connect (this, &Place::setTrayMessageSignal, 23 #if FIXME
24 connect (this, &Place::setTrayMessage,
24 theApp, &App::setTrayMessage, Qt::QueuedConnection); 25 theApp, &App::setTrayMessage, Qt::QueuedConnection);
26 #endif
25} 27}
26 28
27void 29void
@@ -229,6 +231,7 @@ Place::insertMessage (Message *msg)
229 231
230 // Find thread 232 // Find thread
231 233
234 bool newThread = false;
232 uint64_t threadId = 0; 235 uint64_t threadId = 0;
233 Modifier *mod = msg->findModifier ("_id_thread"); 236 Modifier *mod = msg->findModifier ("_id_thread");
234 if (mod) 237 if (mod)
@@ -256,8 +259,9 @@ Place::insertMessage (Message *msg)
256 } 259 }
257 } 260 }
258 261
262 m_threads += thread;
259 m_threadHash.insert (threadId, thread); 263 m_threadHash.insert (threadId, thread);
260 m_threadList.append (thread); 264 newThread = true;
261 } 265 }
262 266
263 // Find parent message 267 // Find parent message
@@ -276,6 +280,13 @@ Place::insertMessage (Message *msg)
276 280
277 if (parent) 281 if (parent)
278 parent->appendChild (msg); 282 parent->appendChild (msg);
283
284 emit messageReceived (msg, parent, thread);
285
286 if (newThread)
287 {
288 emit threadAdded (msg);
289 }
279} 290}
280 291
281 292
@@ -303,6 +314,6 @@ Place::notifyData (uint16_t *data_size, void *data)
303 return GNUNET_NO; 314 return GNUNET_NO;
304 315
305 m_inTransmit = false; 316 m_inTransmit = false;
306 emit dataSentSignal (); 317 emit dataSent ();
307 return GNUNET_YES; 318 return GNUNET_YES;
308} 319}
diff --git a/src/social/place.h b/src/social/place.h
index f59c444..c5445be 100644
--- a/src/social/place.h
+++ b/src/social/place.h
@@ -5,8 +5,6 @@
5#include "message.h" 5#include "message.h"
6#include "gnunet.h" 6#include "gnunet.h"
7 7
8#define DATA2ARG(data) data, sizeof (data)
9
10 8
11class Place : public QObject 9class Place : public QObject
12{ 10{
@@ -39,7 +37,7 @@ class Place : public QObject
39 { 37 {
40 m_name = name; 38 m_name = name;
41 emit nameChanged (name); 39 emit nameChanged (name);
42 emit modifiedSignal (m_index); 40 emit modified (this);
43 } 41 }
44 42
45 // Desc 43 // Desc
@@ -51,7 +49,7 @@ class Place : public QObject
51 { 49 {
52 m_desc = desc; 50 m_desc = desc;
53 emit descChanged (desc); 51 emit descChanged (desc);
54 emit modifiedSignal (m_index); 52 emit modified (this);
55 } 53 }
56 54
57 //Type 55 //Type
@@ -63,7 +61,7 @@ class Place : public QObject
63 { 61 {
64 m_type = type; 62 m_type = type;
65 emit typeChanged (type); 63 emit typeChanged (type);
66 emit modifiedSignal (m_index); 64 emit modified (this);
67 } 65 }
68 66
69 //Is Host ? 67 //Is Host ?
@@ -90,7 +88,13 @@ class Place : public QObject
90 m_pubKeyStr = QString::fromLatin1 (pubKeyChr); 88 m_pubKeyStr = QString::fromLatin1 (pubKeyChr);
91 GNUNET_free (pubKeyChr); 89 GNUNET_free (pubKeyChr);
92 emit pubKeyStringChanged (m_pubKeyStr); 90 emit pubKeyStringChanged (m_pubKeyStr);
93 emit modifiedSignal (m_index); 91 emit modified (this);
92 }
93
94 const QList<Message *> &
95 threads ()
96 {
97 return m_threads;
94 } 98 }
95 99
96 Q_INVOKABLE void 100 Q_INVOKABLE void
@@ -116,7 +120,7 @@ class Place : public QObject
116 Modifier *m_mod; 120 Modifier *m_mod;
117 121
118 /// List of top-level, thread-starting messages. 122 /// List of top-level, thread-starting messages.
119 QList<Message *> m_threadList; 123 QList<Message *> m_threads;
120 124
121 /// _thread_id -> thread starter Message 125 /// _thread_id -> thread starter Message
122 QHash<uint64_t, Message *> m_threadHash; 126 QHash<uint64_t, Message *> m_threadHash;
@@ -124,8 +128,6 @@ class Place : public QObject
124 /// _message_id -> Message 128 /// _message_id -> Message
125 QHash<uint64_t, Message *> m_msgHash; 129 QHash<uint64_t, Message *> m_msgHash;
126 130
127 // FIXME: ThreadListModel m_threads;
128
129 QString m_pubKeyStr; 131 QString m_pubKeyStr;
130 132
131 GNUNET_CRYPTO_EddsaPublicKey m_pubKey; 133 GNUNET_CRYPTO_EddsaPublicKey m_pubKey;
@@ -220,7 +222,7 @@ class Place : public QObject
220 222
221 signals: 223 signals:
222 224
223 void modifiedSignal (int index); 225 void modified (Place *place);
224 226
225 void pubKeyStringChanged (QString pubKeyString); 227 void pubKeyStringChanged (QString pubKeyString);
226 228
@@ -230,11 +232,17 @@ class Place : public QObject
230 232
231 void typeChanged (QString type); 233 void typeChanged (QString type);
232 234
233 void talkSignal (QString text); 235 void dataSent ();
236
237 void messageReceived (Message *msg, Message *parent, Message *thread);
234 238
235 void dataSentSignal (); 239 void threadAdded (Message *msg);
236 240
237 void setTrayMessageSignal (QString place, QString text); 241#if FIXME
242 void talkSignal (QString text);
243
244 void setTrayMessage (QString place, QString text);
245#endif
238 246
239public slots: 247public slots:
240 248
diff --git a/src/social/socialapp.cpp b/src/social/socialapp.cpp
index 027f650..75279fd 100644
--- a/src/social/socialapp.cpp
+++ b/src/social/socialapp.cpp
@@ -16,12 +16,6 @@ SocialApp::SocialApp (struct GNUNET_CONFIGURATION_Handle *config,
16 hostPlaceCallback, 16 hostPlaceCallback,
17 guestPlaceCallback, 17 guestPlaceCallback,
18 this); 18 this);
19
20 connect (this, &SocialApp::createPlaceSignal,
21 this, &SocialApp::createPlaceSlot, Qt::QueuedConnection);
22
23 connect (this, &SocialApp::enterPlaceSignal,
24 this, &SocialApp::enterPlaceSlot, Qt::QueuedConnection);
25} 19}
26 20
27 21
@@ -46,14 +40,15 @@ void
46SocialApp::addEgo (Ego *ego) 40SocialApp::addEgo (Ego *ego)
47{ 41{
48 m_egos += ego; 42 m_egos += ego;
49 emit egoAddedSignal (ego); 43 emit egoAdded (ego);
50} 44}
51 45
52void 46void
53SocialApp::addPlace (Place *place) 47SocialApp::addPlace (Place *place)
54{ 48{
55 m_places += place; 49 m_places += place;
56 emit placeAddedSignal (place); 50 place->setIndex (m_places.count () - 1);
51 emit placeAdded (place);
57} 52}
58 53
59void 54void
@@ -95,7 +90,7 @@ SocialApp::findEgo (const QString pubKeyStr)
95 90
96 91
97void 92void
98SocialApp::placeCreate (GNUNET_SOCIAL_Ego *ego) 93SocialApp::createPlace (GNUNET_SOCIAL_Ego *ego)
99{ 94{
100 addPlace (new Host (m_app, ego, GNUNET_PSYC_CHANNEL_PRIVATE, this)); 95 addPlace (new Host (m_app, ego, GNUNET_PSYC_CHANNEL_PRIVATE, this));
101} 96}
@@ -113,21 +108,14 @@ SocialApp::createPlaceSlot (QString egoPubKeyStr)
113 ego = m_egos.last (); 108 ego = m_egos.last ();
114 } 109 }
115 110
116 placeCreate (ego->ego ()); 111 createPlace (ego->ego ());
117}
118
119
120void
121SocialApp::createPlace (QString egoPubKeyStr)
122{
123 emit createPlaceSignal (egoPubKeyStr);
124} 112}
125 113
126 114
127void 115void
128SocialApp::placeEnter (GNUNET_SOCIAL_Ego *ego, 116SocialApp::enterPlace (GNUNET_SOCIAL_Ego *ego,
129 GNUNET_CRYPTO_EddsaPublicKey *pubKey, 117 GNUNET_CRYPTO_EddsaPublicKey *pubKey,
130 GNUNET_PeerIdentity *peerId) 118 GNUNET_PeerIdentity *peerId)
131{ 119{
132 addPlace (new Guest (m_app, ego, pubKey, peerId, 0, NULL, NULL, this)); 120 addPlace (new Guest (m_app, ego, pubKey, peerId, 0, NULL, NULL, this));
133} 121}
@@ -159,12 +147,5 @@ SocialApp::enterPlaceSlot (QString egoPubKeyStr, QString pubKeyStr, QString peer
159 ego = m_egos.last (); 147 ego = m_egos.last ();
160 } 148 }
161 149
162 placeEnter (ego->ego (), &pubKey, &peerId); 150 enterPlace (ego->ego (), &pubKey, &peerId);
163}
164
165
166void
167SocialApp::enterPlace (QString egoPubKeyStr, QString pubKeyStr, QString peerIdStr)
168{
169 emit enterPlaceSignal (egoPubKeyStr, pubKeyStr, peerIdStr);
170} 151}
diff --git a/src/social/socialapp.h b/src/social/socialapp.h
index 0800b14..7bb7219 100644
--- a/src/social/socialapp.h
+++ b/src/social/socialapp.h
@@ -22,19 +22,13 @@ class SocialApp : public QObject
22 findEgo (const QString pubKeyStr); 22 findEgo (const QString pubKeyStr);
23 23
24 void 24 void
25 placeCreate (GNUNET_SOCIAL_Ego *ego); 25 createPlace (GNUNET_SOCIAL_Ego *ego);
26 26
27 void 27 void
28 placeEnter (GNUNET_SOCIAL_Ego *ego, 28 enterPlace (GNUNET_SOCIAL_Ego *ego,
29 GNUNET_CRYPTO_EddsaPublicKey *pubKey, 29 GNUNET_CRYPTO_EddsaPublicKey *pubKey,
30 GNUNET_PeerIdentity *peerId); 30 GNUNET_PeerIdentity *peerId);
31 31
32 Q_INVOKABLE void
33 createPlace (QString egoPubKeyStr);
34
35 Q_INVOKABLE void
36 enterPlace (QString egoPubKeyStr, QString pubKeyStr, QString peerIdStr);
37
38 const QList<Ego *> & 32 const QList<Ego *> &
39 egos () 33 egos ()
40 { 34 {
@@ -50,16 +44,10 @@ class SocialApp : public QObject
50 signals: 44 signals:
51 45
52 void 46 void
53 createPlaceSignal (QString egoPubKeyStr); 47 egoAdded (Ego *ego);
54
55 void
56 enterPlaceSignal (QString egoPubKeyStr, QString pubKey, QString peerId);
57
58 void
59 egoAddedSignal (Ego *ego);
60 48
61 void 49 void
62 placeAddedSignal (Place *place); 50 placeAdded (Place *place);
63 51
64 public slots: 52 public slots:
65 53
@@ -67,7 +55,7 @@ class SocialApp : public QObject
67 createPlaceSlot (QString egoPubKeyStr); 55 createPlaceSlot (QString egoPubKeyStr);
68 56
69 void 57 void
70 enterPlaceSlot (QString egoPubKeyStr, QString pubKey, QString peerId); 58 enterPlaceSlot (QString egoPubKeyStr, QString pubKeyStr, QString peerIdStr);
71 59
72 private: 60 private:
73 61