diff options
author | tg(x) <*@tg-x.net> | 2016-03-11 01:15:05 +0100 |
---|---|---|
committer | tg(x) <*@tg-x.net> | 2016-03-11 01:15:05 +0100 |
commit | 9f6335f6360473c85330b9cd22deb5fc1d7697b5 (patch) | |
tree | 4a5c3442882cd2e3db6d57c300b54e15ef71c924 | |
parent | 83f2395605f5ab34d1ee9003a49f0d0b5d4144f7 (diff) | |
download | secushare-9f6335f6360473c85330b9cd22deb5fc1d7697b5.tar.gz secushare-9f6335f6360473c85330b9cd22deb5fc1d7697b5.zip |
ego & place models
-rw-r--r-- | src/app.cpp | 16 | ||||
-rw-r--r-- | src/app.h | 1 | ||||
-rw-r--r-- | src/model/EgoListModel.cpp | 135 | ||||
-rw-r--r-- | src/model/EgoListModel.h | 39 | ||||
-rw-r--r-- | src/model/PlaceListModel.cpp | 128 | ||||
-rw-r--r-- | src/model/PlaceListModel.h | 38 | ||||
-rw-r--r-- | src/model/models.cpp | 12 | ||||
-rw-r--r-- | src/model/models.h | 34 | ||||
-rw-r--r-- | src/nym/nym.h | 2 | ||||
-rw-r--r-- | src/social/place.cpp | 2 | ||||
-rw-r--r-- | src/social/place.h | 11 | ||||
-rw-r--r-- | src/social/socialapp.cpp | 3 |
12 files changed, 179 insertions, 242 deletions
diff --git a/src/app.cpp b/src/app.cpp index 15063cb..bb703da 100644 --- a/src/app.cpp +++ b/src/app.cpp | |||
@@ -78,11 +78,17 @@ App::startGnuNet () | |||
78 | void | 78 | void |
79 | App::setConnected (bool connected) | 79 | App::setConnected (bool connected) |
80 | { | 80 | { |
81 | #if FIXME | 81 | qDebug () << "setConnected: " << connected; |
82 | m_models->egos ()->setData (m_gnunet->social ()->egos ()); | 82 | if (connected) |
83 | connect (m_gnunet->social (), SIGNAL (egoAdded ()), | 83 | { |
84 | m_models->egos (), SLOT (add ())); | 84 | m_models->setEgos (new EgoListModel (m_gnunet->social ()->egos (), this)); |
85 | #endif | 85 | connect (m_gnunet->social (), &SocialApp::egoAddedSignal, |
86 | m_models->egos (), &EgoListModel::rowAddedSlot); | ||
87 | |||
88 | m_models->setPlaces (new PlaceListModel (m_gnunet->social ()->places (), this)); | ||
89 | connect (m_gnunet->social (), &SocialApp::placeAddedSignal, | ||
90 | m_models->places (), &PlaceListModel::rowAddedSlot); | ||
91 | } | ||
86 | 92 | ||
87 | m_connected = connected; | 93 | m_connected = connected; |
88 | emit connectedChanged (m_connected); | 94 | emit connectedChanged (m_connected); |
@@ -37,7 +37,6 @@ class App : public QObject | |||
37 | 37 | ||
38 | Q_PROPERTY (bool connected | 38 | Q_PROPERTY (bool connected |
39 | READ isConnected | 39 | READ isConnected |
40 | WRITE setConnected | ||
41 | NOTIFY connectedChanged); | 40 | NOTIFY connectedChanged); |
42 | 41 | ||
43 | public: | 42 | public: |
diff --git a/src/model/EgoListModel.cpp b/src/model/EgoListModel.cpp index 3ffe6bd..0e279bb 100644 --- a/src/model/EgoListModel.cpp +++ b/src/model/EgoListModel.cpp | |||
@@ -25,33 +25,18 @@ | |||
25 | #include "EgoListModel.h" | 25 | #include "EgoListModel.h" |
26 | 26 | ||
27 | 27 | ||
28 | EgoListModel::EgoListModel (QObject * parent) | 28 | EgoListModel::EgoListModel (const QList<Ego *> &data, QObject * parent) |
29 | : QAbstractListModel (parent) | 29 | : QAbstractListModel (parent), |
30 | m_data (data) | ||
30 | { | 31 | { |
31 | connect (this, &EgoListModel::addEgoSignal, | ||
32 | this, &EgoListModel::addEgoSlot, Qt::BlockingQueuedConnection); | ||
33 | } | ||
34 | |||
35 | |||
36 | void | ||
37 | EgoListModel::setData (const QList<Ego *> &data) | ||
38 | { | ||
39 | m_data = data; | ||
40 | } | 32 | } |
41 | 33 | ||
42 | 34 | ||
43 | int | 35 | int |
44 | EgoListModel::rowCount (const QModelIndex & parent) const | 36 | EgoListModel::rowCount (const QModelIndex &parent) const |
45 | { | 37 | { |
46 | Q_UNUSED (parent); | 38 | Q_UNUSED (parent); |
47 | return m_data.size (); | 39 | return m_data.count (); |
48 | } | ||
49 | |||
50 | |||
51 | bool | ||
52 | EgoListModel::contains (QString pubKey) | ||
53 | { | ||
54 | return m_lookupIndex.contains (pubKey); | ||
55 | } | 40 | } |
56 | 41 | ||
57 | 42 | ||
@@ -65,12 +50,12 @@ EgoListModel::data (const QModelIndex &index, int role) const | |||
65 | 50 | ||
66 | switch (role) | 51 | switch (role) |
67 | { | 52 | { |
68 | case NAME: | ||
69 | return ego->name (); | ||
70 | break; | ||
71 | case PUBKEY: | 53 | case PUBKEY: |
72 | return ego->pubKeyString (); | 54 | return ego->pubKeyString (); |
73 | break; | 55 | |
56 | case NAME: | ||
57 | return ego->name (); | ||
58 | |||
74 | default: | 59 | default: |
75 | return QVariant::Invalid; | 60 | return QVariant::Invalid; |
76 | } | 61 | } |
@@ -91,71 +76,51 @@ EgoListModel::roleNames () const | |||
91 | } | 76 | } |
92 | 77 | ||
93 | 78 | ||
79 | /** | ||
80 | * An ego was added to the source data. | ||
81 | */ | ||
94 | void | 82 | void |
95 | EgoListModel::modifiedSlot (int indexRow) | 83 | EgoListModel::rowAddedSlot (Ego *ego) |
96 | { | 84 | { |
97 | QModelIndex modelIndex = this->index (indexRow); | 85 | int index = m_data.count (); |
86 | beginInsertRows (QModelIndex (), index, index); | ||
87 | ego->setIndex (index); | ||
98 | 88 | ||
99 | emit dataChanged (modelIndex, modelIndex); | 89 | connect (ego, &Ego::modifiedSignal, |
90 | this, &EgoListModel::rowModifiedSlot); | ||
91 | |||
92 | //m_lookupIndex[pubKey] = index; | ||
93 | endInsertRows (); | ||
100 | } | 94 | } |
101 | 95 | ||
102 | 96 | ||
103 | /** | ||
104 | * @brief EgoListModel::add, add a new ego to the model. | ||
105 | * @param key | ||
106 | * @param name | ||
107 | * @return Return the newly created ego | ||
108 | */ | ||
109 | void | 97 | void |
110 | EgoListModel::add (Ego *ego) | 98 | EgoListModel::rowModifiedSlot (int index) |
111 | { | 99 | { |
112 | emit addEgoSignal (ego, ego->pubKeyString ()); | 100 | QModelIndex modelIndex = this->index (index); |
101 | emit dataChanged (modelIndex, modelIndex); | ||
113 | } | 102 | } |
114 | 103 | ||
115 | 104 | ||
116 | /** | 105 | int |
117 | * @brief EgoListModel::addEgoSlot | 106 | EgoListModel::getCount () |
118 | * @param key, the ego key. | ||
119 | * @return return the same place as item | ||
120 | */ | ||
121 | Ego * | ||
122 | EgoListModel::addEgoSlot (Ego *item, QString pubKey) | ||
123 | { | 107 | { |
124 | 108 | return m_data.count (); | |
125 | //Search if already exists | ||
126 | if (m_lookupIndex.contains (pubKey)) | ||
127 | { | ||
128 | return NULL; | ||
129 | } | ||
130 | else | ||
131 | { | ||
132 | int index = m_data.count (); | ||
133 | |||
134 | beginInsertRows (QModelIndex (), index, index); | ||
135 | m_data.append (item); | ||
136 | item->setIndex (index); | ||
137 | |||
138 | //Notify modifications | ||
139 | connect (item, &Ego::modifiedSignal, | ||
140 | this, &EgoListModel::modifiedSlot); | ||
141 | |||
142 | m_lookupIndex[pubKey] = index; | ||
143 | endInsertRows (); | ||
144 | return item; | ||
145 | } | ||
146 | } | 109 | } |
147 | 110 | ||
148 | 111 | ||
149 | Ego * | 112 | Ego * |
150 | EgoListModel::get (QString key) | 113 | EgoListModel::get (int index) |
151 | { | 114 | { |
152 | if (m_lookupIndex.contains (key)) | 115 | if (index < 0 || m_data.count () <= index) |
153 | { | ||
154 | Ego *ego = m_data[m_lookupIndex[key]]; | ||
155 | return ego; | ||
156 | } | ||
157 | else | ||
158 | return NULL; | 116 | return NULL; |
117 | |||
118 | Ego *ego = m_data[index]; | ||
119 | |||
120 | //Set the ownership so QML don't delete it. | ||
121 | QQmlEngine::setObjectOwnership (ego, QQmlEngine::CppOwnership); | ||
122 | |||
123 | return ego; | ||
159 | } | 124 | } |
160 | 125 | ||
161 | 126 | ||
@@ -169,23 +134,23 @@ EgoListModel::get (QModelIndex index) | |||
169 | } | 134 | } |
170 | 135 | ||
171 | 136 | ||
172 | Ego * | 137 | #if FIXME |
173 | EgoListModel::get (int index) | 138 | bool |
139 | EgoListModel::contains (QString pubKey) | ||
174 | { | 140 | { |
175 | if (index < 0 || m_data.count () <= index) | 141 | return m_lookupIndex.contains (pubKey); |
176 | return NULL; | ||
177 | |||
178 | Ego *ego = m_data[index]; | ||
179 | |||
180 | //Set he ownership so QML don't delete it. | ||
181 | QQmlEngine::setObjectOwnership (ego, QQmlEngine::CppOwnership); | ||
182 | |||
183 | return ego; | ||
184 | } | 142 | } |
185 | 143 | ||
186 | 144 | ||
187 | int | 145 | Ego * |
188 | EgoListModel::getCount () | 146 | EgoListModel::get (QString key) |
189 | { | 147 | { |
190 | return m_data.count (); | 148 | if (m_lookupIndex.contains (key)) |
149 | { | ||
150 | Ego *ego = m_data[m_lookupIndex[key]]; | ||
151 | return ego; | ||
152 | } | ||
153 | else | ||
154 | return NULL; | ||
191 | } | 155 | } |
156 | #endif | ||
diff --git a/src/model/EgoListModel.h b/src/model/EgoListModel.h index 33a9cbe..dbc4147 100644 --- a/src/model/EgoListModel.h +++ b/src/model/EgoListModel.h | |||
@@ -35,47 +35,41 @@ class EgoListModel : public QAbstractListModel | |||
35 | public: | 35 | public: |
36 | enum EgoRoles | 36 | enum EgoRoles |
37 | { | 37 | { |
38 | NAME = Qt::UserRole + 1, | 38 | PUBKEY = Qt::UserRole + 1, |
39 | PUBKEY, | 39 | NAME, |
40 | NB_PLACE_COLUMNS | 40 | NB_PLACE_COLUMNS |
41 | }; | 41 | }; |
42 | 42 | ||
43 | explicit | 43 | explicit |
44 | EgoListModel (QObject *parent = 0); | 44 | EgoListModel (const QList<Ego *> &data, QObject *parent = 0); |
45 | |||
46 | void | ||
47 | setData (const QList<Ego *> &data); | ||
48 | |||
49 | void | ||
50 | add (Ego *ego); | ||
51 | 45 | ||
52 | Q_INVOKABLE int | 46 | Q_INVOKABLE int |
53 | getCount (); | 47 | getCount (); |
54 | 48 | ||
55 | bool | ||
56 | contains (QString id); | ||
57 | |||
58 | Q_INVOKABLE Ego * | 49 | Q_INVOKABLE Ego * |
59 | get (int index); | 50 | get (int index); |
51 | |||
60 | Ego * | 52 | Ego * |
61 | get (QModelIndex index); | 53 | get (QModelIndex index); |
54 | |||
55 | #if FIXME | ||
56 | bool | ||
57 | contains (QString id); | ||
58 | |||
62 | Ego * | 59 | Ego * |
63 | get (QString key); | 60 | get (QString key); |
64 | 61 | ||
65 | signals: | 62 | #endif |
66 | |||
67 | void | ||
68 | addEgoSignal (Ego *item, QString pubKey); | ||
69 | 63 | ||
70 | public slots: | 64 | public slots: |
71 | 65 | ||
72 | void | 66 | void |
73 | modifiedSlot (int indexRow); | 67 | rowAddedSlot (Ego *ego); |
74 | 68 | ||
75 | private slots: | 69 | void |
70 | rowModifiedSlot (int index); | ||
76 | 71 | ||
77 | Ego * | 72 | private slots: |
78 | addEgoSlot (Ego *item, QString name); | ||
79 | 73 | ||
80 | private: | 74 | private: |
81 | 75 | ||
@@ -88,8 +82,11 @@ private: | |||
88 | QHash<int, QByteArray> | 82 | QHash<int, QByteArray> |
89 | roleNames () const; | 83 | roleNames () const; |
90 | 84 | ||
85 | const QList<Ego *> &m_data; | ||
86 | |||
87 | #if FIXME | ||
91 | QHash<QString, int> m_lookupIndex; | 88 | QHash<QString, int> m_lookupIndex; |
92 | QList<Ego *> m_data; | 89 | #endif |
93 | }; | 90 | }; |
94 | 91 | ||
95 | #endif | 92 | #endif |
diff --git a/src/model/PlaceListModel.cpp b/src/model/PlaceListModel.cpp index 1116679..896fa22 100644 --- a/src/model/PlaceListModel.cpp +++ b/src/model/PlaceListModel.cpp | |||
@@ -21,21 +21,15 @@ | |||
21 | 21 | ||
22 | #include <sstream> | 22 | #include <sstream> |
23 | #include <QQmlEngine> | 23 | #include <QQmlEngine> |
24 | #include <QDebug> | ||
24 | 25 | ||
25 | #include "PlaceListModel.h" | 26 | #include "PlaceListModel.h" |
26 | 27 | ||
27 | 28 | ||
28 | PlaceListModel::PlaceListModel (QObject * parent) | 29 | PlaceListModel::PlaceListModel (const QList<Place *> &data, QObject * parent) |
29 | : QAbstractListModel (parent) | 30 | : QAbstractListModel (parent), |
31 | m_data (data) | ||
30 | { | 32 | { |
31 | connect (this, &PlaceListModel::addPlaceSignal, | ||
32 | this, &PlaceListModel::addPlaceSlot); | ||
33 | } | ||
34 | |||
35 | |||
36 | PlaceListModel::~PlaceListModel () | ||
37 | { | ||
38 | |||
39 | } | 33 | } |
40 | 34 | ||
41 | 35 | ||
@@ -47,13 +41,6 @@ PlaceListModel::rowCount (const QModelIndex & parent) const | |||
47 | } | 41 | } |
48 | 42 | ||
49 | 43 | ||
50 | bool | ||
51 | PlaceListModel::contains (QString id) | ||
52 | { | ||
53 | return m_lookupIndex.contains (id); | ||
54 | } | ||
55 | |||
56 | |||
57 | QVariant | 44 | QVariant |
58 | PlaceListModel::data (const QModelIndex & index, int role) const | 45 | PlaceListModel::data (const QModelIndex & index, int role) const |
59 | { | 46 | { |
@@ -98,74 +85,53 @@ PlaceListModel::roleNames () const | |||
98 | } | 85 | } |
99 | 86 | ||
100 | 87 | ||
88 | /** | ||
89 | * A place was added to the source data. | ||
90 | */ | ||
101 | void | 91 | void |
102 | PlaceListModel::modifiedSlot (int indexRow) | 92 | PlaceListModel::rowAddedSlot (Place *place) |
103 | { | 93 | { |
104 | QModelIndex modelIndex = this->index (indexRow); | 94 | int index = m_data.count () - 1; |
95 | qDebug () << "PlaceListModel::rowAddedSlot: " << index; | ||
105 | 96 | ||
106 | emit dataChanged (modelIndex, modelIndex); | 97 | beginInsertRows (QModelIndex (), index, index); |
98 | place->setIndex (index); | ||
99 | |||
100 | connect (place, &Place::modifiedSignal, | ||
101 | this, &PlaceListModel::rowModifiedSlot); | ||
102 | |||
103 | //m_lookupIndex[pubKey] = index; | ||
104 | endInsertRows (); | ||
107 | } | 105 | } |
108 | 106 | ||
109 | 107 | ||
110 | /** | ||
111 | * @brief PlaceListModel::add, add a new place to the model. | ||
112 | * @param key | ||
113 | * @return Return the new created place | ||
114 | */ | ||
115 | void | 108 | void |
116 | PlaceListModel::add (Place *place) | 109 | PlaceListModel::rowModifiedSlot (int index) |
117 | { | 110 | { |
118 | emit addPlaceSignal (place, place->pubKeyString ()); | 111 | QModelIndex modelIndex = this->index (index); |
112 | emit dataChanged (modelIndex, modelIndex); | ||
119 | } | 113 | } |
120 | 114 | ||
121 | 115 | ||
122 | /** | 116 | int |
123 | * @brief PlaceListModel::addPlaceSlot | 117 | PlaceListModel::getCount () |
124 | * @param key, the place ID. | ||
125 | * @return return the same place as item | ||
126 | */ | ||
127 | Place * | ||
128 | PlaceListModel::addPlaceSlot (Place *item, QString pubKey) | ||
129 | { | 118 | { |
130 | 119 | return m_data.count (); | |
131 | //Search if already exists | ||
132 | if (m_lookupIndex.contains (pubKey)) | ||
133 | { | ||
134 | return NULL; | ||
135 | } | ||
136 | else | ||
137 | { | ||
138 | int index = m_data.count (); | ||
139 | |||
140 | beginInsertRows (QModelIndex (), index, index); | ||
141 | m_data.append (item); | ||
142 | item->setIndex (index); | ||
143 | |||
144 | //Notify modifications | ||
145 | connect (item, &Place::modifiedSignal, | ||
146 | this, &PlaceListModel::modifiedSlot); | ||
147 | |||
148 | m_lookupIndex[pubKey] = index; | ||
149 | endInsertRows (); | ||
150 | return item; | ||
151 | } | ||
152 | |||
153 | |||
154 | } | 120 | } |
155 | 121 | ||
156 | 122 | ||
157 | Place * | 123 | Place * |
158 | PlaceListModel::get (QString key) | 124 | PlaceListModel::get (int index) |
159 | { | 125 | { |
160 | if (m_lookupIndex.contains (key)) | 126 | if (index < 0 || getCount () < index) |
161 | { | 127 | return NULL; |
162 | Place *place = m_data[m_lookupIndex[key]]; | ||
163 | 128 | ||
164 | return place; | 129 | Place *place = m_data[index]; |
165 | 130 | ||
166 | } | 131 | //Set the ownership so QML don't delete it. |
167 | else | 132 | QQmlEngine::setObjectOwnership (place, QQmlEngine::CppOwnership); |
168 | return NULL; | 133 | |
134 | return place; | ||
169 | } | 135 | } |
170 | 136 | ||
171 | 137 | ||
@@ -179,23 +145,25 @@ PlaceListModel::get (QModelIndex index) | |||
179 | } | 145 | } |
180 | 146 | ||
181 | 147 | ||
182 | Place * | 148 | #if FIXME |
183 | PlaceListModel::get (int index) | 149 | bool |
150 | PlaceListModel::contains (QString id) | ||
184 | { | 151 | { |
185 | if (index < 0 || getCount () < index) | 152 | return m_lookupIndex.contains (id); |
186 | return NULL; | ||
187 | |||
188 | Place *place = m_data[index]; | ||
189 | |||
190 | //Set he ownership so QML don't delete it. | ||
191 | QQmlEngine::setObjectOwnership (place, QQmlEngine::CppOwnership); | ||
192 | |||
193 | return place; | ||
194 | } | 153 | } |
195 | 154 | ||
196 | 155 | ||
197 | int | 156 | Place * |
198 | PlaceListModel::getCount () | 157 | PlaceListModel::get (QString key) |
199 | { | 158 | { |
200 | return m_data.count (); | 159 | if (m_lookupIndex.contains (key)) |
160 | { | ||
161 | Place *place = m_data[m_lookupIndex[key]]; | ||
162 | |||
163 | return place; | ||
164 | |||
165 | } | ||
166 | else | ||
167 | return NULL; | ||
201 | } | 168 | } |
169 | #endif | ||
diff --git a/src/model/PlaceListModel.h b/src/model/PlaceListModel.h index b66044d..d93a3f4 100644 --- a/src/model/PlaceListModel.h +++ b/src/model/PlaceListModel.h | |||
@@ -42,42 +42,32 @@ class PlaceListModel : public QAbstractListModel | |||
42 | }; | 42 | }; |
43 | 43 | ||
44 | explicit | 44 | explicit |
45 | PlaceListModel (QObject *parent = 0); | 45 | PlaceListModel (const QList<Place *> &data, QObject *parent = 0); |
46 | ~PlaceListModel (); | ||
47 | 46 | ||
48 | void | 47 | Q_INVOKABLE int |
49 | add (Place *place); | ||
50 | int | ||
51 | getCount (); | 48 | getCount (); |
52 | bool | ||
53 | contains (QString id); | ||
54 | 49 | ||
55 | Q_INVOKABLE Place * | 50 | Q_INVOKABLE Place * |
56 | get (int index); | 51 | get (int index); |
52 | |||
57 | Place * | 53 | Place * |
58 | get (QModelIndex index); | 54 | get (QModelIndex index); |
59 | Place * | ||
60 | get (QString key); | ||
61 | |||
62 | void | ||
63 | save (); | ||
64 | void | ||
65 | load (); | ||
66 | 55 | ||
67 | signals: | 56 | #if FIXME |
57 | bool | ||
58 | contains (QString id); | ||
68 | 59 | ||
69 | void | 60 | Place * |
70 | addPlaceSignal (Place *item, QString key); | 61 | get (QString key); |
62 | #endif | ||
71 | 63 | ||
72 | public slots: | 64 | public slots: |
73 | 65 | ||
74 | void | 66 | void |
75 | modifiedSlot (int indexRow); | 67 | rowAddedSlot (Place *place); |
76 | 68 | ||
77 | private slots: | 69 | void |
78 | 70 | rowModifiedSlot (int index); | |
79 | Place * | ||
80 | addPlaceSlot (Place *item, QString name); | ||
81 | 71 | ||
82 | private: | 72 | private: |
83 | 73 | ||
@@ -88,8 +78,8 @@ class PlaceListModel : public QAbstractListModel | |||
88 | QHash<int, QByteArray> | 78 | QHash<int, QByteArray> |
89 | roleNames () const; | 79 | roleNames () const; |
90 | 80 | ||
91 | QHash<QString, int> m_lookupIndex; | 81 | const QList<Place *> &m_data; |
92 | QList<Place *> m_data; | 82 | //QHash<QString, int> m_lookupIndex; |
93 | }; | 83 | }; |
94 | 84 | ||
95 | #endif | 85 | #endif |
diff --git a/src/model/models.cpp b/src/model/models.cpp index cdac395..4472b51 100644 --- a/src/model/models.cpp +++ b/src/model/models.cpp | |||
@@ -25,16 +25,4 @@ | |||
25 | Models::Models (QObject *parent) | 25 | Models::Models (QObject *parent) |
26 | : QObject (parent) | 26 | : QObject (parent) |
27 | { | 27 | { |
28 | m_egos = new EgoListModel (this); | ||
29 | m_places = new PlaceListModel (this); | ||
30 | } | ||
31 | |||
32 | |||
33 | Models::~Models () | ||
34 | { | ||
35 | delete m_egos; | ||
36 | m_egos = NULL; | ||
37 | |||
38 | delete m_places; | ||
39 | m_places = NULL; | ||
40 | } | 28 | } |
diff --git a/src/model/models.h b/src/model/models.h index 11449b5..246d18e 100644 --- a/src/model/models.h +++ b/src/model/models.h | |||
@@ -26,7 +26,7 @@ | |||
26 | #include "model/EgoListModel.h" | 26 | #include "model/EgoListModel.h" |
27 | #include "model/PlaceListModel.h" | 27 | #include "model/PlaceListModel.h" |
28 | 28 | ||
29 | class Models:public QObject | 29 | class Models : public QObject |
30 | { | 30 | { |
31 | Q_OBJECT; | 31 | Q_OBJECT; |
32 | 32 | ||
@@ -38,26 +38,46 @@ class Models:public QObject | |||
38 | READ places | 38 | READ places |
39 | NOTIFY placesChanged); | 39 | NOTIFY placesChanged); |
40 | 40 | ||
41 | |||
41 | public: | 42 | public: |
42 | 43 | ||
43 | explicit Models (QObject * parent = 0); | 44 | explicit |
44 | ~Models (); | 45 | Models (QObject *parent = 0); |
45 | 46 | ||
46 | EgoListModel *egos () const | 47 | EgoListModel * |
48 | egos () const | ||
47 | { | 49 | { |
48 | return m_egos; | 50 | return m_egos; |
49 | } | 51 | } |
50 | 52 | ||
51 | PlaceListModel *places () const | 53 | PlaceListModel |
54 | *places () const | ||
52 | { | 55 | { |
53 | return m_places; | 56 | return m_places; |
54 | } | 57 | } |
55 | 58 | ||
59 | void | ||
60 | setEgos (EgoListModel *egos) | ||
61 | { | ||
62 | m_egos = egos; | ||
63 | emit egosChanged (egos); | ||
64 | } | ||
65 | |||
66 | void | ||
67 | setPlaces (PlaceListModel *places) | ||
68 | { | ||
69 | m_places = places; | ||
70 | emit placesChanged (places); | ||
71 | } | ||
72 | |||
56 | 73 | ||
57 | signals: | 74 | signals: |
58 | 75 | ||
59 | void egosChanged (EgoListModel *); | 76 | void |
60 | void placesChanged (PlaceListModel *); | 77 | egosChanged (EgoListModel *); |
78 | |||
79 | void | ||
80 | placesChanged (PlaceListModel *); | ||
61 | 81 | ||
62 | 82 | ||
63 | private: | 83 | private: |
diff --git a/src/nym/nym.h b/src/nym/nym.h index bddf91d..d961c69 100644 --- a/src/nym/nym.h +++ b/src/nym/nym.h | |||
@@ -21,7 +21,7 @@ class Nym : public QObject | |||
21 | QObject *parent = 0); | 21 | QObject *parent = 0); |
22 | 22 | ||
23 | int | 23 | int |
24 | getIndex () const | 24 | index () const |
25 | { | 25 | { |
26 | return m_index; | 26 | return m_index; |
27 | } | 27 | } |
diff --git a/src/social/place.cpp b/src/social/place.cpp index ddfa100..06e9c35 100644 --- a/src/social/place.cpp +++ b/src/social/place.cpp | |||
@@ -32,8 +32,6 @@ Place::init (const GNUNET_CRYPTO_EddsaPublicKey pubKey) | |||
32 | 32 | ||
33 | setPubKey (pubKey); | 33 | setPubKey (pubKey); |
34 | setName (pubKeyStr); | 34 | setName (pubKeyStr); |
35 | |||
36 | theApp->models()->places()->add (this); | ||
37 | } | 35 | } |
38 | 36 | ||
39 | /** | 37 | /** |
diff --git a/src/social/place.h b/src/social/place.h index e0d4788..f59c444 100644 --- a/src/social/place.h +++ b/src/social/place.h | |||
@@ -12,7 +12,7 @@ class Place : public QObject | |||
12 | { | 12 | { |
13 | 13 | ||
14 | Q_OBJECT; | 14 | Q_OBJECT; |
15 | Q_PROPERTY (QString pubkey READ pubKeyString); | 15 | Q_PROPERTY (QString pubkey READ pubKeyString NOTIFY pubKeyStringChanged); |
16 | Q_PROPERTY (QString name READ name WRITE setName NOTIFY nameChanged); | 16 | Q_PROPERTY (QString name READ name WRITE setName NOTIFY nameChanged); |
17 | Q_PROPERTY (QString desc READ desc WRITE setDesc NOTIFY descChanged); | 17 | Q_PROPERTY (QString desc READ desc WRITE setDesc NOTIFY descChanged); |
18 | 18 | ||
@@ -21,7 +21,7 @@ class Place : public QObject | |||
21 | explicit Place (QObject *parent = 0); | 21 | explicit Place (QObject *parent = 0); |
22 | 22 | ||
23 | //Index | 23 | //Index |
24 | int getIndex () const | 24 | int index () const |
25 | { | 25 | { |
26 | return m_index; | 26 | return m_index; |
27 | } | 27 | } |
@@ -39,6 +39,7 @@ class Place : public QObject | |||
39 | { | 39 | { |
40 | m_name = name; | 40 | m_name = name; |
41 | emit nameChanged (name); | 41 | emit nameChanged (name); |
42 | emit modifiedSignal (m_index); | ||
42 | } | 43 | } |
43 | 44 | ||
44 | // Desc | 45 | // Desc |
@@ -50,6 +51,7 @@ class Place : public QObject | |||
50 | { | 51 | { |
51 | m_desc = desc; | 52 | m_desc = desc; |
52 | emit descChanged (desc); | 53 | emit descChanged (desc); |
54 | emit modifiedSignal (m_index); | ||
53 | } | 55 | } |
54 | 56 | ||
55 | //Type | 57 | //Type |
@@ -61,6 +63,7 @@ class Place : public QObject | |||
61 | { | 63 | { |
62 | m_type = type; | 64 | m_type = type; |
63 | emit typeChanged (type); | 65 | emit typeChanged (type); |
66 | emit modifiedSignal (m_index); | ||
64 | } | 67 | } |
65 | 68 | ||
66 | //Is Host ? | 69 | //Is Host ? |
@@ -86,6 +89,8 @@ class Place : public QObject | |||
86 | char *pubKeyChr = GNUNET_CRYPTO_eddsa_public_key_to_string (&pubKey); | 89 | char *pubKeyChr = GNUNET_CRYPTO_eddsa_public_key_to_string (&pubKey); |
87 | m_pubKeyStr = QString::fromLatin1 (pubKeyChr); | 90 | m_pubKeyStr = QString::fromLatin1 (pubKeyChr); |
88 | GNUNET_free (pubKeyChr); | 91 | GNUNET_free (pubKeyChr); |
92 | emit pubKeyStringChanged (m_pubKeyStr); | ||
93 | emit modifiedSignal (m_index); | ||
89 | } | 94 | } |
90 | 95 | ||
91 | Q_INVOKABLE void | 96 | Q_INVOKABLE void |
@@ -217,6 +222,8 @@ class Place : public QObject | |||
217 | 222 | ||
218 | void modifiedSignal (int index); | 223 | void modifiedSignal (int index); |
219 | 224 | ||
225 | void pubKeyStringChanged (QString pubKeyString); | ||
226 | |||
220 | void nameChanged (QString name); | 227 | void nameChanged (QString name); |
221 | 228 | ||
222 | void descChanged (QString desc); | 229 | void descChanged (QString desc); |
diff --git a/src/social/socialapp.cpp b/src/social/socialapp.cpp index c789e7e..b6f5d7c 100644 --- a/src/social/socialapp.cpp +++ b/src/social/socialapp.cpp | |||
@@ -50,7 +50,6 @@ SocialApp::addEgo (Ego *ego) | |||
50 | { | 50 | { |
51 | m_egos += ego; | 51 | m_egos += ego; |
52 | emit egoAddedSignal (ego); | 52 | emit egoAddedSignal (ego); |
53 | theApp->models ()->egos ()->add (ego); // FIXME | ||
54 | } | 53 | } |
55 | 54 | ||
56 | void | 55 | void |
@@ -101,7 +100,7 @@ SocialApp::findEgo (const QString pubKeyStr) | |||
101 | void | 100 | void |
102 | SocialApp::placeCreate (GNUNET_SOCIAL_Ego *ego) | 101 | SocialApp::placeCreate (GNUNET_SOCIAL_Ego *ego) |
103 | { | 102 | { |
104 | addPlace (new Host (m_app, ego, GNUNET_PSYC_CHANNEL_PRIVATE, this)); // FIXME: ego | 103 | addPlace (new Host (m_app, ego, GNUNET_PSYC_CHANNEL_PRIVATE, this)); |
105 | } | 104 | } |
106 | 105 | ||
107 | 106 | ||