From a295f2792f2a80f10dd3214563aa71ad3562204f Mon Sep 17 00:00:00 2001 From: "tg(x)" <*@tg-x.net> Date: Thu, 12 May 2016 03:44:52 +0200 Subject: API changes: some UI improvements --- qml/PlaceCreate.qml | 9 +++-- qml/PlaceEnter.qml | 10 +++--- qml/PlaceThread.qml | 79 +++++++++++++++++++++++++++++++++++++++++ qml/main.qml | 1 + secushare.pro | 3 ++ src/gnunet/gnunet.cpp | 11 ++---- src/gnunet/gnunet.h | 6 ++-- src/gnunet/social/guest.cpp | 2 +- src/gnunet/social/host.cpp | 22 ++++-------- src/gnunet/social/host.h | 14 ++++---- src/gnunet/social/message.cpp | 35 +++++++++++++++--- src/gnunet/social/message.h | 50 +++++++++++++++++++++++--- src/gnunet/social/place.cpp | 37 +++++++++++-------- src/gnunet/social/place.h | 23 ++++++++---- src/gnunet/social/socialapp.cpp | 9 ++++- src/gnunet/social/socialapp.h | 2 ++ src/model/ThreadListModel.cpp | 20 +++++------ src/model/ThreadListModel.h | 4 +-- 18 files changed, 249 insertions(+), 88 deletions(-) diff --git a/qml/PlaceCreate.qml b/qml/PlaceCreate.qml index ce67caa..ad765ce 100644 --- a/qml/PlaceCreate.qml +++ b/qml/PlaceCreate.qml @@ -36,7 +36,7 @@ Rectangle { } Label { - text: "Create Home" + text: "Create Place" anchors.left: imageBanner.right anchors.leftMargin: 5 anchors.top: parent.top @@ -78,7 +78,8 @@ Rectangle { anchors.left: parent.left anchors.right: parent.right wrapMode : Text.Wrap - text: "Please enter the appropriate information about the place you would like to create." + text: "Please enter the appropriate information about the place you would like to create.\n" + + "The GNS label is added to the GNS zone of the selected ego, which then provides the address of the place." } } @@ -94,7 +95,7 @@ Rectangle { spacing: 2 Label { id: nameLabel - text: "Name:" + text: "GNS label:" width: 80 } @@ -107,6 +108,7 @@ Rectangle { } Row { + visible: false spacing: 2 Label { id: expirationLabel @@ -146,6 +148,7 @@ Rectangle { } Row { + visible: false spacing: 2 Label { id: passwordLabel diff --git a/qml/PlaceEnter.qml b/qml/PlaceEnter.qml index 6a0e8ac..82b0a6c 100644 --- a/qml/PlaceEnter.qml +++ b/qml/PlaceEnter.qml @@ -80,7 +80,7 @@ Rectangle { anchors.left: parent.left anchors.right: parent.right wrapMode : Text.Wrap - text: "Please enter the appropriate information about the chat you would like to join." + text: "Please enter the necessary information about the place you would like to enter." } @@ -120,7 +120,7 @@ Rectangle { } RadioButton { - text: qsTr("List of peers") + text: qsTr("Manual") exclusiveGroup: group } } @@ -154,7 +154,7 @@ Rectangle { spacing: 2 Label { id: publicKeyLabel - text: "Public Key:" + text: "Public key of place:" width: 100 } @@ -170,7 +170,7 @@ Rectangle { spacing: 2 Label { id: originLabel - text: "Origin (Empty will join local peer):" + text: "Origin (Empty will try local peer):" width: 100 } @@ -208,7 +208,7 @@ Rectangle { spacing: 2 Button { - text: "Join" + text: "Enter" width: 200 onClicked: { diff --git a/qml/PlaceThread.qml b/qml/PlaceThread.qml index ade60d2..ecca45c 100644 --- a/qml/PlaceThread.qml +++ b/qml/PlaceThread.qml @@ -8,6 +8,7 @@ import secushare 1.0 Rectangle { color: "white" + property var place: null property var thread: null property bool editable: false // FIXME @@ -100,6 +101,7 @@ Rectangle { clip: true model: messageListModel + //model: thread delegate: messageDelegate Component { @@ -284,5 +286,82 @@ Rectangle { } } } + + Item { + id: replyThread + height: 70 + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + + Rectangle { + id: userWrapper + width: 60 + height: 60 + color: "black" + opacity: 1.0 + + anchors.left: parent.left + anchors.leftMargin: 5 + anchors.top: parent.top + + Image { + id: messageMiniImage + source: "images/demo/lynX.jpg" + fillMode: Image.PreserveAspectCrop + height: 40 + width: 48 + anchors.left: parent.left + anchors.top: parent.top + anchors.margins: 3 + } + + Text { + anchors.top: messageMiniImage.bottom + id: contactText + text: "lynX" + font.pointSize: 10 + width: 55 + height: 15 + anchors.left: parent.left + anchors.leftMargin: 5 + + wrapMode : Text.Wrap + elide : Text.ElideRight + color: "white" + + font.family: ubuntuBIFont.name + font.letterSpacing : -1 + } + } + + TextArea { + anchors.left: userWrapper.right + anchors.right: parent.right + anchors.top: userWrapper.top + anchors.bottom: userWrapper.bottom + anchors.rightMargin: 10 + anchors.leftMargin: 10 + + Keys.onReturnPressed: { + if (Qt.ControlModifier & event.modifiers) + { + if (thread) { + thread.talk(text) + } + else + { + place.talk(text) + } + cursorPosition = 0 + text = "" + event.accepted = true + } + else event.accepted = false + } + } + + } + } } diff --git a/qml/main.qml b/qml/main.qml index 2bf9062..7920656 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -264,6 +264,7 @@ ApplicationWindow { Tab { PlaceThread { anchors.fill: parent + place: selectedPlace thread: selectedThread } } diff --git a/secushare.pro b/secushare.pro index 32d28d0..ac624a8 100644 --- a/secushare.pro +++ b/secushare.pro @@ -17,6 +17,9 @@ QT += qml quick widgets LIBS += -lgnunetutil -lgnunetcore -lgnunetidentity -lgnunetsocial -lgnunetpsycutil -lqrencode +QMAKE_CXXFLAGS += -O0 -g +QMAKE_CFLAGS += -O0 -g + #include(3rdParty/qzxing-master/QZXing.pro) SOURCES += src/main.cpp \ diff --git a/src/gnunet/gnunet.cpp b/src/gnunet/gnunet.cpp index b8b2a29..b5a6b51 100644 --- a/src/gnunet/gnunet.cpp +++ b/src/gnunet/gnunet.cpp @@ -142,11 +142,8 @@ GnuNet::mainLoopCallback (void *cls, char *const *args, const char *cfgfile, * Static function */ void -GnuNet::processQtEventsTask (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +GnuNet::processQtEventsTask (void *cls) { - Q_UNUSED (tc); - GnuNet *gnunet = (GnuNet *) cls; Q_ASSERT (NULL != gnunet); @@ -167,12 +164,8 @@ GnuNet::processQtEventsTask (void *cls, * Static function */ void -GnuNet::shutdownTask (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +GnuNet::shutdownTask (void *cls) { - Q_UNUSED (tc); - GnuNet *gnunet = (GnuNet *) cls; Q_ASSERT (NULL != gnunet); - } diff --git a/src/gnunet/gnunet.h b/src/gnunet/gnunet.h index 0de079b..0e42d8a 100644 --- a/src/gnunet/gnunet.h +++ b/src/gnunet/gnunet.h @@ -121,12 +121,10 @@ class GnuNet : public QObject const struct GNUNET_CONFIGURATION_Handle *cfg); static void - processQtEventsTask (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc); + processQtEventsTask (void *cls); static void - shutdownTask (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc); + shutdownTask (void *cls); SocialApp *m_social; diff --git a/src/gnunet/social/guest.cpp b/src/gnunet/social/guest.cpp index 0108598..cc41528 100644 --- a/src/gnunet/social/guest.cpp +++ b/src/gnunet/social/guest.cpp @@ -129,7 +129,7 @@ Guest::talkRequest (Message *msg) void Guest::talkRequest (QString text) { - Message msg ("_converse", QList(), text, 0); + Message msg (0, "_converse", QList(), text, 0); talkRequest (&msg); } diff --git a/src/gnunet/social/host.cpp b/src/gnunet/social/host.cpp index 94a8dee..fccc186 100644 --- a/src/gnunet/social/host.cpp +++ b/src/gnunet/social/host.cpp @@ -50,8 +50,8 @@ Host::~Host () void Host::connectSignals () { - connect (this, SIGNAL (announceSignal (QString)), - this, SLOT (announce (QString)), + connect (this, SIGNAL (talkSignal (QString, QString)), + this, SLOT (talk (QString, QString)), Qt::QueuedConnection); } @@ -68,7 +68,7 @@ Host::answerDoorCallback (void *cls, struct GNUNET_SOCIAL_Nym *nym, "%s\n%.*s\n", method_name, data_size, data); Host *host = (Host *) cls; - emit host->answerDoorSignal (new Message (method_name, env, data, data_size, + emit host->answerDoorSignal (new Message (0, method_name, env, data, data_size, 0, nym)); } @@ -112,7 +112,7 @@ Host::farewellCallback (void *cls, void -Host::announce (Message *msg) +Host::talk (Message *msg) { if (m_inTransmit) { @@ -134,20 +134,12 @@ Host::announce (Message *msg) } -void -Host::announce (QString text) -{ - qDebug () << "Host.announce: " << text; - Message msg ("_converse", QList(), text); - announce (&msg); -} - - void Host::talk (QString text) { - qDebug () << "Host.talk: " << text; - emit announceSignal (text); + qDebug () << "Host.announce: " << text; + Message msg (this, "_converse", QList(), text); + talk (&msg); } diff --git a/src/gnunet/social/host.h b/src/gnunet/social/host.h index ced0000..2e63793 100644 --- a/src/gnunet/social/host.h +++ b/src/gnunet/social/host.h @@ -27,24 +27,21 @@ class Host : public Place ~Host (); - Q_INVOKABLE void - talk (QString text); - int zoneAddPlace (QString name); public slots: - void - announce (Message *msg); + Q_INVOKABLE void + talk (Message *msg); - void - announce (QString text); + Q_INVOKABLE void + talk (QString text); signals: void - announceSignal (QString text); + talkSignal (QString body, QString title = ""); void answerDoorSignal (Message *msg); @@ -57,6 +54,7 @@ class Host : public Place void connectSignals (); + void entryDecision (GNUNET_SOCIAL_Nym *nym, bool isAdmitted, diff --git a/src/gnunet/social/message.cpp b/src/gnunet/social/message.cpp index abc3f9c..19d9109 100644 --- a/src/gnunet/social/message.cpp +++ b/src/gnunet/social/message.cpp @@ -2,7 +2,8 @@ #include "modifier.h" -Message::Message (QString method, +Message::Message (Place *place, + QString method, QList env, QByteArray data, uint64_t id, @@ -10,6 +11,7 @@ Message::Message (QString method, Message *parent) : QObject (parent) { + m_place = place; m_id = id; m_nym = nym; m_method = method; @@ -19,7 +21,8 @@ Message::Message (QString method, } -Message::Message (QString method, +Message::Message (Place *place, + QString method, QList env, QString text, uint64_t id, @@ -27,6 +30,7 @@ Message::Message (QString method, Message *parent) : QObject (parent) { + m_place = place; m_id = id; m_nym = nym; m_method = method; @@ -36,7 +40,8 @@ Message::Message (QString method, } -Message::Message (const char *method, +Message::Message (Place *place, + const char *method, GNUNET_PSYC_Environment *env, const void *data, size_t data_size, @@ -45,6 +50,7 @@ Message::Message (const char *method, Message *parent) : QObject (parent) { + m_place = place; m_id = id; m_nym = nym; m_method = QString::fromLatin1 (method); @@ -87,7 +93,7 @@ Message::appendData (char *data, size_t data_size) Modifier * -Message::findModifier (const QString name) +Message::findModifier (const QString name) const { QListIterator it (m_env); while (it.hasNext ()) @@ -221,6 +227,27 @@ Message::index () const : -1; } +/*** Signals ***/ + +void +Message::reply (QString body, QString title) +{ + QList env; + Modifier *id_thread = findModifier ("_id_thread"); + if (id_thread) + env += new Modifier (GNUNET_PSYC_OP_SET, "_id_thread", id_thread->text ()); + + Modifier *id_reply = findModifier ("_id_reply"); + if (id_reply) + env += new Modifier (GNUNET_PSYC_OP_SET, "_id_reply", id_reply->text ()); + + if (!title.isEmpty ()) + env += new Modifier (GNUNET_PSYC_OP_SET, "_title", title); + + Message *msg = new Message (m_place, "_converse"); + m_place->talk (msg); +} + /*** Operators ***/ diff --git a/src/gnunet/social/message.h b/src/gnunet/social/message.h index b3735ef..12269b5 100644 --- a/src/gnunet/social/message.h +++ b/src/gnunet/social/message.h @@ -4,8 +4,11 @@ #include #include #include "modifier.h" +#include "place.h" #include "gnunet.h" +class Place; + class Message : public QObject { @@ -14,6 +17,10 @@ class Message : public QObject Q_PROPERTY (uint64_t id READ id); + Q_PROPERTY (Place *place + READ place + WRITE setPlace); + Q_PROPERTY (QString method READ method WRITE setMethod); @@ -22,10 +29,14 @@ class Message : public QObject READ text WRITE setText); + Q_PROPERTY (QString title + READ title); + public: explicit - Message (QString method, + Message (Place *place, + QString method, QList env = QList(), QByteArray data = "", uint64_t id = 0, @@ -33,7 +44,8 @@ class Message : public QObject Message *parent = 0); explicit - Message (QString method, + Message (Place *place, + QString method, QList env, QString text, uint64_t id = 0, @@ -41,7 +53,8 @@ class Message : public QObject Message *parent = 0); explicit - Message (const char *method, + Message (Place *place, + const char *method, GNUNET_PSYC_Environment *env, const void *data = 0, size_t data_size = 0, @@ -63,7 +76,7 @@ class Message : public QObject appendData (char *data, size_t data_size); Modifier * - findModifier (const QString name); + findModifier (const QString name) const; GNUNET_PSYC_Message * toPsyc (); @@ -129,6 +142,19 @@ class Message : public QObject } + Place * + place () const + { + return m_place; + } + + void + setPlace (Place *place) + { + m_place = place; + } + + QString method () const { @@ -180,6 +206,21 @@ class Message : public QObject m_data = text.toUtf8 (); } + QString + title () const + { + Modifier *title = findModifier ("_title"); + if (title) { + return title->text (); + } + return QString (); + } + + public slots: + + void + reply (QString body, QString title = ""); + signals: @@ -194,6 +235,7 @@ class Message : public QObject private: + Place *m_place; uint64_t m_id; GNUNET_SOCIAL_Nym *m_nym; QString m_method; diff --git a/src/gnunet/social/place.cpp b/src/gnunet/social/place.cpp index 8b1f4f3..e160378 100644 --- a/src/gnunet/social/place.cpp +++ b/src/gnunet/social/place.cpp @@ -34,6 +34,9 @@ Place::init (const GNUNET_CRYPTO_EddsaPublicKey pubKey) setPubKey (pubKey); setName (pubKeyStr); + + // FIXME: request state and store it in a hash map + // GNUNET_SOCIAL_place_look_for (m_plc, "", ...); } /** @@ -50,22 +53,28 @@ Place::copyToClipboard () /** * Send a message to the place. * - * @param text + * @param msg * The message. */ void -Place::talk (QString text) +Place::talk (Message *msg) { -#if FIXME - if (m_isHost) - { - emit hostTalkSignal (this, text); - } - else - { - emit guestTalkSignal (this, text); - } -#endif + emit talkSignal (msg); +} + + +/** + * Send a message to the place. + * + * @param body + * Message body. + * @param title + * Message title. + */ +void +Place::talk (QString body, QString title) +{ + emit talkSignal (body, title); } @@ -106,7 +115,7 @@ Place::recvMethod (const struct GNUNET_PSYC_MessageHeader *msg, message_id, method_name); if (m_msg) delete m_msg; - m_msg = new Message (method_name); + m_msg = new Message (this, method_name); m_mod = 0; } @@ -248,7 +257,7 @@ Place::insertMessage (Message *msg) { // Create a placeholder message that will be replaced // when the missing message arrives (or not if it's not in a thread). - thread = new Message ("_INTERNAL_missing"); + thread = new Message (this, "_INTERNAL_missing"); // methods or variables of the _INTERNAL family must never be sent // over the wire! history replay must ensure that. -lynX diff --git a/src/gnunet/social/place.h b/src/gnunet/social/place.h index c5445be..7e7f168 100644 --- a/src/gnunet/social/place.h +++ b/src/gnunet/social/place.h @@ -5,6 +5,7 @@ #include "message.h" #include "gnunet.h" +class Message; class Place : public QObject { @@ -97,11 +98,20 @@ class Place : public QObject return m_threads; } - Q_INVOKABLE void + Q_INVOKABLE + void copyToClipboard (); - Q_INVOKABLE void - talk (QString text); +public slots: + + Q_INVOKABLE + void + talk (Message *msg); + + Q_INVOKABLE + void + talk (QString body, QString title); + protected: @@ -238,14 +248,13 @@ class Place : public QObject void threadAdded (Message *msg); -#if FIXME - void talkSignal (QString text); + void talkSignal (Message *msg); + void talkSignal (QString body, QString title); +#if FIXME void setTrayMessage (QString place, QString text); #endif -public slots: - }; #endif diff --git a/src/gnunet/social/socialapp.cpp b/src/gnunet/social/socialapp.cpp index e739574..144851b 100644 --- a/src/gnunet/social/socialapp.cpp +++ b/src/gnunet/social/socialapp.cpp @@ -15,13 +15,14 @@ SocialApp::SocialApp (struct GNUNET_CONFIGURATION_Handle *config, egoCallback, hostPlaceCallback, guestPlaceCallback, + appConnectedCallback, this); } SocialApp::~SocialApp () { - GNUNET_SOCIAL_app_disconnect (m_app); + GNUNET_SOCIAL_app_disconnect (m_app, NULL, NULL); } @@ -75,6 +76,12 @@ SocialApp::guestPlaceCallback (void *cls, } +void +SocialApp::appConnectedCallback (void *cls) +{ +} + + Ego * SocialApp::findEgo (const QString pubKeyStr) { diff --git a/src/gnunet/social/socialapp.h b/src/gnunet/social/socialapp.h index 36b4ee4..c8a32a7 100644 --- a/src/gnunet/social/socialapp.h +++ b/src/gnunet/social/socialapp.h @@ -90,6 +90,8 @@ class SocialApp : public QObject const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, enum GNUNET_SOCIAL_AppPlaceState placeState); + static void + appConnectedCallback (void *cls); }; #endif diff --git a/src/model/ThreadListModel.cpp b/src/model/ThreadListModel.cpp index aec692d..7c6ca0c 100644 --- a/src/model/ThreadListModel.cpp +++ b/src/model/ThreadListModel.cpp @@ -36,16 +36,14 @@ ThreadListModel::data (const QModelIndex &index, int role) const switch (role) { -#if FIXME - case NAME: - return msg->name (); + case METHOD: + return msg->method (); + case TEXT: + return msg->text (); + case TITLE: + return msg->title (); case PUBKEY: - return msg->pubKeyString (); - case TYPE: - return msg->type (); - case DESC: - return msg->desc (); -#endif + return msg->place ()->pubKeyString (); default: return QVariant(); } @@ -57,9 +55,9 @@ ThreadListModel::roleNames () const { QHash roles; - roles[TITLE] = "title"; + roles[METHOD] = "method"; roles[TEXT] = "text"; - roles[TYPE] = "type"; + roles[TITLE] = "title"; roles[PUBKEY] = "pubKey"; return roles; diff --git a/src/model/ThreadListModel.h b/src/model/ThreadListModel.h index 5c6d94c..57897a4 100644 --- a/src/model/ThreadListModel.h +++ b/src/model/ThreadListModel.h @@ -15,9 +15,9 @@ class ThreadListModel : public QAbstractListModel enum ThreadListRoles { - TITLE = Qt::UserRole + 1, - TYPE, + METHOD = Qt::UserRole + 1, TEXT, + TITLE, PUBKEY, THREADLIST_ROLE_COUNT }; -- cgit v1.2.3