gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r34142 - in gnunet-qt/SecureShare: core/social qml


From: gnunet
Subject: [GNUnet-SVN] r34142 - in gnunet-qt/SecureShare: core/social qml
Date: Mon, 11 Aug 2014 18:37:40 +0200

Author: bratao
Date: 2014-08-11 18:37:40 +0200 (Mon, 11 Aug 2014)
New Revision: 34142

Modified:
   gnunet-qt/SecureShare/core/social/place.cpp
   gnunet-qt/SecureShare/core/social/place.h
   gnunet-qt/SecureShare/core/social/socialservice.cpp
   gnunet-qt/SecureShare/core/social/socialservice.h
   gnunet-qt/SecureShare/qml/GroupConversation.qml
   gnunet-qt/SecureShare/qml/main.qml
Log:
Implement conversation

Modified: gnunet-qt/SecureShare/core/social/place.cpp
===================================================================
--- gnunet-qt/SecureShare/core/social/place.cpp 2014-08-11 15:29:49 UTC (rev 
34141)
+++ gnunet-qt/SecureShare/core/social/place.cpp 2014-08-11 16:37:40 UTC (rev 
34142)
@@ -10,6 +10,9 @@
     m_status = "No status";
     m_name = "No name";
     m_type = "group";//thread;group;contact
+
+    connect(this,&Place::addConversationSignal,
+            this,&Place::addConversationSlot, Qt::QueuedConnection);
 }
 
 
@@ -19,3 +22,22 @@
 
     clipboard->setText(m_key);
 }
+
+void Place::talk(QString text)
+{
+    emit talkSignal(this,text);
+}
+
+
+void Place::addConversation(QString text)
+{
+    emit addConversationSignal(text);
+}
+
+void Place::addConversationSlot(QString text)
+{
+
+    m_content += text + "<br/>";
+
+    emit contentChanged(m_content);
+}

Modified: gnunet-qt/SecureShare/core/social/place.h
===================================================================
--- gnunet-qt/SecureShare/core/social/place.h   2014-08-11 15:29:49 UTC (rev 
34141)
+++ gnunet-qt/SecureShare/core/social/place.h   2014-08-11 16:37:40 UTC (rev 
34142)
@@ -7,6 +7,7 @@
 {
     Q_OBJECT
     Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
+    Q_PROPERTY(QString content READ content NOTIFY contentChanged)
 public:
     explicit Place(QString key, QObject *parent = 0);
 
@@ -45,23 +46,101 @@
         emit statusChanged(status);
     }
 
+    //Social Guest
+    struct GNUNET_SOCIAL_Guest* socialGuest() const
+    { return m_gst; }
+    void setSocialGuest(struct GNUNET_SOCIAL_Guest* guest)
+    {
+        m_gst = guest;
+    }
+
+    //Content
+    QString content() const
+    { return m_content; }
+
+
+    //Slicer
+    struct GNUNET_SOCIAL_Slicer* slicer() const
+    { return m_slicer; }
+    void setSlicer(struct GNUNET_SOCIAL_Slicer* slicer)
+    {
+        m_slicer = slicer;
+    }
+
+    //Host
+    struct GNUNET_SOCIAL_Host* host() const
+    { return m_hst; }
+    void setHost(struct GNUNET_SOCIAL_Host* host)
+    {
+        m_hst = host;
+        m_isHost = true;
+    }
+
+    //Private Key
+    struct GNUNET_CRYPTO_EddsaPrivateKey* privateKey() const
+    { return m_placeKey; }
+    void setPrivateKey(struct GNUNET_CRYPTO_EddsaPrivateKey* key)
+    {
+        m_placeKey = key;
+    }
+
+    //Public Key
+    struct GNUNET_CRYPTO_EddsaPublicKey* publicKey() const
+    { return m_placePubKey; }
+    void setPublicKey(struct GNUNET_CRYPTO_EddsaPublicKey* key)
+    {
+        m_placePubKey = key;
+    }
+
+
+
     Q_INVOKABLE void copyToClipboard();
+    Q_INVOKABLE void talk(QString text);
+
+    void addConversation(QString text);
+
 private:
     int m_index;
     QString m_name;
     QString m_type;
     QString m_status;
+
+
+    QString m_content;
+
+    struct GNUNET_CRYPTO_EddsaPrivateKey *m_placeKey;
     QString m_key;
+    //For guests
+    struct GNUNET_SOCIAL_Guest * m_gst;
 
+    //For hosts
+    bool m_isHost;
+    struct GNUNET_SOCIAL_Slicer* m_slicer;
+    struct GNUNET_SOCIAL_Host *m_hst;
+
+
+    struct GNUNET_CRYPTO_EddsaPublicKey* m_placePubKey;
+
+    //The peer got his inscrition approved ?
+    bool m_approved;
+
 signals:
     void modifiedSignal(int index);
     void nameChanged(QString name);
     void typeChanged(QString type);
     void statusChanged(QString status);
 
+    void contentChanged(QString content);
 
+    void talkSignal (Place* place, QString text);
+
+    void addConversationSignal(QString text);
+
+
 public slots:
 
+    void addConversationSlot(QString text);
+
 };
 
 #endif // PLACE_H

Modified: gnunet-qt/SecureShare/core/social/socialservice.cpp
===================================================================
--- gnunet-qt/SecureShare/core/social/socialservice.cpp 2014-08-11 15:29:49 UTC 
(rev 34141)
+++ gnunet-qt/SecureShare/core/social/socialservice.cpp 2014-08-11 16:37:40 UTC 
(rev 34142)
@@ -43,20 +43,8 @@
     m_hostEgo = iden->ego();
 
 
-    m_placeKey = GNUNET_CRYPTO_eddsa_key_create ();
-
-    createSlice();
-
-    enterPlaceAsHost();
 }
 
-void SocialService::createSlice()
-{
-    m_hostSlicer = GNUNET_SOCIAL_slicer_create ();
-    GNUNET_SOCIAL_slicer_add (m_hostSlicer, "",
-                              &hostRecvMethodCallback, 
&hostRecvModifierCallback,
-                              &hostRecvDataCallback, &hostRecvEomCallback, 
NULL);
-}
 
 
 void SocialService::createPlace()
@@ -70,11 +58,11 @@
 
 
     GNUNET_CRYPTO_EddsaPrivateKey *placeKey = GNUNET_CRYPTO_eddsa_key_create 
();
-    GNUNET_CRYPTO_EddsaPublicKey placePubKey;
+    GNUNET_CRYPTO_EddsaPublicKey *placePubKey= new 
GNUNET_CRYPTO_EddsaPublicKey;
 
-    GNUNET_CRYPTO_eddsa_key_get_public (placeKey, &placePubKey);
+    GNUNET_CRYPTO_eddsa_key_get_public (placeKey, placePubKey);
 
-    char* id = GNUNET_CRYPTO_eddsa_public_key_to_string (&placePubKey);
+    char* id = GNUNET_CRYPTO_eddsa_public_key_to_string (placePubKey);
     QString strId = QString::fromLatin1(id);
 
 
@@ -82,41 +70,29 @@
     Place* newPlace = theApp->models()->placesModel()->add(strId);
 
     newPlace->setName(strId);
+    newPlace->setPrivateKey(placeKey);
+    newPlace->setPublicKey(placePubKey);
 
+    GNUNET_SOCIAL_Slicer* slicer = GNUNET_SOCIAL_slicer_create ();
+    GNUNET_SOCIAL_slicer_add (slicer, "",
+                              &hostRecvMethodCallback, 
&hostRecvModifierCallback,
+                              &hostRecvDataCallback, &hostRecvEomCallback, 
newPlace);
 
+    newPlace->setSlicer(slicer);
 
+
+
     GNUNET_SOCIAL_Host * host = GNUNET_SOCIAL_host_enter (m_config, m_hostEgo, 
placeKey,
-                                                          
GNUNET_PSYC_CHANNEL_PRIVATE, m_hostSlicer,
+                                                          
GNUNET_PSYC_CHANNEL_PRIVATE, slicer,
                                                           
&hostEnteredCallback, &hostAnswerDoorCallback,
                                                           
&hostFarewellCallback, newPlace);
+
+    newPlace->setHost(host);
 }
 
 
-void SocialService::enterPlaceAsHost()
-{
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering to place as host.\n");
 
 
-    GNUNET_CRYPTO_eddsa_key_get_public (m_placeKey, &m_placePubKey);
-
-    char* id = GNUNET_CRYPTO_eddsa_public_key_to_string (&m_placePubKey);
-    QString strId = QString::fromLatin1(id);
-
-
-
-    Place* newPlace = theApp->models()->placesModel()->add(strId);
-
-    newPlace->setName("My Room");
-
-
-
-    m_hst = GNUNET_SOCIAL_host_enter (m_config, m_hostEgo, m_placeKey,
-                                      GNUNET_PSYC_CHANNEL_PRIVATE, 
m_hostSlicer,
-                                      &hostEnteredCallback, 
&hostAnswerDoorCallback,
-                                      &hostFarewellCallback, newPlace);
-}
-
-
 void
 SocialService::hostRecvMethodCallback (void *cls,
                                        const struct GNUNET_PSYC_MessageMethod 
*meth,
@@ -142,10 +118,16 @@
                                          const void *value,
                                          uint16_t value_size)
 {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+    /* GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Test #: Host received modifier for message ID %i:\n"
-                "%c%s: %.*s\n",
+                "%i %s: %i %s\n",
                 message_id, oper, name, value_size, value);
+    */
+
+
+    QString str = QString::fromLatin1((char *)value);
+
+    qWarning() << "Host received modifier for message ID" << message_id << 
oper << name << value_size << str;
 }
 
 
@@ -157,10 +139,18 @@
                                      const void *data,
                                      uint16_t data_size)
 {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+    /*GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Test #: Host received data for message ID %i:\n"
                 "%.*s\n",
-                message_id, data_size, data);
+                message_id, data_size, data);*/
+
+    QString str = QString::fromLatin1((char *)data);
+
+    Place* place = (Place*)cls;
+
+    qWarning() << "Host received data for message ID" << message_id << 
data_size << str;
+
+    place->addConversation(str);
 }
 
 
@@ -222,16 +212,18 @@
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Host received entry request from guest .\n"
                 );
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "%s\n%.*s\n",
                 method_name, data_size, data);
 
+    Place* place = (Place*)cls;
 
+
     //TODO: Give option to deny
 
     GNUNET_PSYC_Message *join_resp = GNUNET_PSYC_message_create ("_admit_nym", 
env,
                                                                  DATA2ARG 
("Welcome, nym!"));
-    GNUNET_SOCIAL_host_entry_decision (m_hst, nym, GNUNET_YES, join_resp);
+    GNUNET_SOCIAL_host_entry_decision (place->host(), nym, GNUNET_YES, 
join_resp);
 
 
     /*
@@ -290,8 +282,18 @@
 void
 SocialService::guestRecvLocalEnterCallback (void *cls, int result, uint64_t 
max_message_id)
 {
+
+    theApp->gnunet()->social()->guestRecvLocalEnter(cls,result,max_message_id);
+
+}
+
+void
+SocialService::guestRecvLocalEnter (void *cls, int result, uint64_t 
max_message_id)
+{
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Guest entered to local place, 
result : %i.\n",result);
 
+
+
 }
 
 void
@@ -361,18 +363,120 @@
     emsg.msg = GNUNET_PSYC_message_create (emsg.method_name, emsg.env,
                                            emsg.data, emsg.data_size);
 
-    GNUNET_CRYPTO_EddsaPublicKey convertedRoomKey;
+    GNUNET_CRYPTO_EddsaPublicKey* convertedRoomKey = new 
GNUNET_CRYPTO_EddsaPublicKey;
 
-    GNUNET_CRYPTO_eddsa_public_key_from_string (pubKey.toStdString().c_str(),
-                                                pubKey.length(),
-                                                &convertedRoomKey);
+    int result = GNUNET_CRYPTO_eddsa_public_key_from_string 
(pubKey.toStdString().c_str(),
+                                                             pubKey.length(),
+                                                             convertedRoomKey);
 
 
 
+    if(result != GNUNET_OK) // Failed conversion
+        return;
 
+
+    Place* newPlace = theApp->models()->placesModel()->add(pubKey);
+
+    newPlace->setName(pubKey);
+    newPlace->setPublicKey(convertedRoomKey);
+
+    GNUNET_SOCIAL_Slicer* slicer = GNUNET_SOCIAL_slicer_create ();
+    newPlace->setSlicer(slicer);
+
+
     //TODO change place pub key to arbitrary value
-    GNUNET_SOCIAL_Guest *gst = GNUNET_SOCIAL_guest_enter (m_config, m_hostEgo, 
&convertedRoomKey,
+    GNUNET_SOCIAL_Guest *gst = GNUNET_SOCIAL_guest_enter (m_config, m_hostEgo, 
convertedRoomKey,
                                                           
theApp->gnunet()->myPeer(), 0, NULL, emsg.msg,
-                                                          m_hostSlicer, 
&guestRecvLocalEnterCallback,
-                                                          
&guestRecvEntryDecisionCallback, NULL);
+                                                          slicer, 
&guestRecvLocalEnterCallback,
+                                                          
&guestRecvEntryDecisionCallback, newPlace);
+    newPlace->setSocialGuest(gst);
+
+    connect(newPlace,&Place::talkSignal,
+            this,&SocialService::guestTalk, Qt::QueuedConnection);
+
+
 }
+
+static void
+transmit_resume (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission resumed.\n");
+    TransmitClosure *tmit = (TransmitClosure *)cls;
+    if (NULL != tmit->host_ann)
+        GNUNET_SOCIAL_host_announce_resume (tmit->host_ann);
+    else
+        GNUNET_SOCIAL_guest_talk_resume (tmit->guest_talk);
+}
+
+
+int
+notify_data (void *cls, uint16_t *data_size, void *data)
+{
+    struct TransmitClosure *tmit = (TransmitClosure *)cls;
+    if (NULL != tmit->env)
+    {
+        GNUNET_ENV_environment_destroy (tmit->env);
+        tmit->env = NULL;
+    }
+    if (0 == tmit->data_count)
+    {
+        *data_size = 0;
+        return GNUNET_YES;
+    }
+
+    uint16_t size = strlen (tmit->data[tmit->n]) + 1;
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Transmit notify data: %u bytes available, "
+                "processing fragment %u/%u (size %u).\n",
+                *data_size, tmit->n + 1, tmit->data_count, size);
+    if (*data_size < size)
+    {
+        *data_size = 0;
+        //GNUNET_assert (0);
+        return GNUNET_SYSERR;
+    }
+
+    if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n])
+    {
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission paused.\n");
+        tmit->paused = GNUNET_YES;
+        GNUNET_SCHEDULER_add_delayed (
+                    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+                                                   tmit->data_delay[tmit->n]),
+                &transmit_resume, tmit);
+        *data_size = 0;
+        return GNUNET_NO;
+    }
+    tmit->paused = GNUNET_NO;
+
+    *data_size = size;
+    memcpy (data, tmit->data[tmit->n], size);
+
+    return ++tmit->n < tmit->data_count ? GNUNET_NO : GNUNET_YES;
+}
+
+void
+SocialService::guestTalk (Place* place, QString text)
+{
+
+    TransmitClosure tmit = (struct TransmitClosure) {};
+    tmit.env = GNUNET_ENV_environment_create ();
+
+
+
+    tmit.data[0] = "zzz xxx yyy";
+    tmit.data[1] = "zyx wvu tsr qpo";
+    tmit.data[2] = "testing ten nine eight";
+    tmit.data_count = 3;
+
+/*
+    tmit.data[0] = (char *)text.toStdString().c_str();
+    tmit.data_count = 1;*/
+
+
+
+    tmit.guest_talk
+            = GNUNET_SOCIAL_guest_talk (place->socialGuest(), 
"_message_guest", tmit.env,
+                                        &notify_data, &tmit,
+                                        GNUNET_SOCIAL_TALK_NONE);
+}

Modified: gnunet-qt/SecureShare/core/social/socialservice.h
===================================================================
--- gnunet-qt/SecureShare/core/social/socialservice.h   2014-08-11 15:29:49 UTC 
(rev 34141)
+++ gnunet-qt/SecureShare/core/social/socialservice.h   2014-08-11 16:37:40 UTC 
(rev 34142)
@@ -14,6 +14,20 @@
   uint16_t data_size;
 }GuestEnterMessage;
 
+
+typedef struct TransmitClosure
+{
+  struct GNUNET_SOCIAL_Announcement *host_ann;
+  struct GNUNET_SOCIAL_TalkRequest *guest_talk;
+  struct GNUNET_ENV_Environment *env;
+  char *data[16];
+  uint8_t data_delay[16];
+  uint8_t data_count;
+  uint8_t paused;
+  uint8_t n;
+} TransmitClosure;
+
+class Place;
 class SocialService : public QObject
 {
     Q_OBJECT
@@ -79,6 +93,8 @@
 
     static void
     guestRecvLocalEnterCallback (void *cls, int result, uint64_t 
max_message_id);
+    void
+    guestRecvLocalEnter(void *cls, int result, uint64_t max_message_id);
 
 
 
@@ -86,22 +102,19 @@
     Q_INVOKABLE void createPlace();
     void createPlaceSlot();
     Q_INVOKABLE void enterRoom(QString pubKey, QString peerIdentity);
+
 signals:
     void createPlaceSignal();
     void enterRoomSignal(QString pubKey, QString peerIdentity);
 public slots:
 
     void enterRoomSlot(QString pubKey, QString peerIdentity);
+    void guestTalk(Place *place, QString text);
 private:
     GNUNET_IDENTITY_Ego* m_hostEgo;
-    GNUNET_SOCIAL_Slicer* m_hostSlicer;
-    GNUNET_SOCIAL_Host *m_hst;
-    GNUNET_CRYPTO_EddsaPrivateKey *m_placeKey;
-    GNUNET_CRYPTO_EddsaPublicKey m_placePubKey;
+
     GNUNET_CONFIGURATION_Handle *m_config;
-    
-    void createSlice();
-    void enterPlaceAsHost();
+
 };
 
 #endif // SOCIALSERVICE_H

Modified: gnunet-qt/SecureShare/qml/GroupConversation.qml
===================================================================
--- gnunet-qt/SecureShare/qml/GroupConversation.qml     2014-08-11 15:29:49 UTC 
(rev 34141)
+++ gnunet-qt/SecureShare/qml/GroupConversation.qml     2014-08-11 16:37:40 UTC 
(rev 34142)
@@ -10,6 +10,8 @@
     anchors.fill: parent
     color: "steelblue"
 
+    property var place: null
+
     FontLoader { id: ubuntuFont; source: "fonts/Ubuntu-R.ttf" }
 
     Rectangle{
@@ -35,7 +37,7 @@
 
         Label{
             id:name
-            text: "lynX Group"
+            text: place.name
             anchors.left: imageBanner.right
             anchors.leftMargin: 5
             anchors.top: parent.top
@@ -89,9 +91,7 @@
                     textFormat: TextEdit.RichText
                     readOnly: true
                     frameVisible: false
-                    text: "
-(12:23:22 PM) <b>lynX:</b> like me<br/>"+
-"(12:23:26 PM) <b>tg:</b> if you know qml it's easier to do it directly in qml"
+                    text: place.content
                 }
 
 
@@ -130,11 +130,20 @@
         }
 
         TextArea{
+            id: textField
             Layout.fillWidth: true
             Layout.minimumHeight: 70
             Layout.preferredHeight: 70
 
         }
+        Button{
+            height: 40
+            width: 40
+            text: "Send"
+            onClicked: {
+                place.talk("oi")
+            }
+        }
 
     }
 }

Modified: gnunet-qt/SecureShare/qml/main.qml
===================================================================
--- gnunet-qt/SecureShare/qml/main.qml  2014-08-11 15:29:49 UTC (rev 34141)
+++ gnunet-qt/SecureShare/qml/main.qml  2014-08-11 16:37:40 UTC (rev 34142)
@@ -67,7 +67,25 @@
                 }
             }
 
+            MenuItem {
+                text: qsTr("Single Chat")
+                onTriggered: {
+                    var single = 
Qt.createComponent("qrc:///qml/SingleConversation.qml");
+                    var singleWnd = single.createObject();
+                    singleWnd.show();
+                }
+            }
 
+            MenuItem {
+                text: qsTr("Threaded Chat")
+                onTriggered: {
+                    var threaded = 
Qt.createComponent("qrc:///qml/TreadChat.qml");
+                    var threadedWnd = threaded.createObject();
+                    threadedWnd.show();
+                }
+            }
+
+
         }
     }
 
@@ -299,7 +317,8 @@
                                     id: contactName
                                     anchors.left: contactPic.right
                                     anchors.top: contactPic.top
-                                    width: contactBackground.width
+                                    width: 175
+                                    height: 15
                                     anchors.leftMargin: 5
                                     text: name
                                     font.family: ubuntuFont.name
@@ -490,6 +509,31 @@
 
 
 
+        Repeater
+        {
+            id: repeater
+            model : Psyc.models.placesModel
+            Item
+            {
+                property string title: "My Title"
+
+            }
+            onItemAdded: {
+                var component = Qt.createComponent("GroupConversation.qml");
+                var tab = main.addTab(item.title, component)
+                tab.active = true
+                tab.item.place = Psyc.models.placesModel.get(index)
+
+            }
+            onItemRemoved: {
+                var component = main.getTab(index).item
+                //component.searchResultModel = null
+                main.removeTab(index)
+
+            }
+        }
+
+
         TabView {
             id: main
             anchors.left: sidebar.right
@@ -525,6 +569,8 @@
                 }
             }
 
+
+/*
             Tab{
                 title: "TreadChat"
                 ThreadChat{
@@ -546,11 +592,11 @@
                 }
             }
 
+*/
 
 
 
 
-
         }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]