Code

working on session establishment
authordaleharvey <daleharvey@users.sourceforge.net>
Sun, 30 Jul 2006 13:29:30 +0000 (13:29 +0000)
committerdaleharvey <daleharvey@users.sourceforge.net>
Sun, 30 Jul 2006 13:29:30 +0000 (13:29 +0000)
src/jabber_whiteboard/defines.h
src/jabber_whiteboard/inkboard-document.cpp
src/jabber_whiteboard/inkboard-document.h
src/jabber_whiteboard/invitation-handlers.cpp
src/jabber_whiteboard/new-inkboard-document.cpp
src/jabber_whiteboard/new-inkboard-document.h
src/jabber_whiteboard/pedrogui.cpp
src/jabber_whiteboard/session-manager.cpp
src/jabber_whiteboard/session-manager.h

index cef369056e4a6ccdbb89a163e3f0a55f21974742..05e4b9b7651056bd585f853bd6957adcffae690a 100644 (file)
@@ -98,6 +98,7 @@ namespace State {
     extern SessionType WHITEBOARD_MUC; 
     extern SessionType WHITEBOARD_PEER;
 
+    typedef char const* SessionState;
 }
 
 // message types
index 9477399e5e5e2a0c237a720fb370115884c3ea0e..e53b7ec800b71b72856814535d087defd455c4cf 100644 (file)
@@ -23,7 +23,7 @@ namespace Inkscape {
 
 namespace Whiteboard {
 
-InkboardDocument::InkboardDocument(int code, SessionType type, Glib::ustring const& to) :
+InkboardDocument::InkboardDocument(int code, State::SessionType type, Glib::ustring const& to) :
        XML::SimpleNode(code), _type(type), _recipient(to)
 {
        _initBindings();
@@ -32,6 +32,7 @@ InkboardDocument::InkboardDocument(int code, SessionType type, Glib::ustring con
 void
 InkboardDocument::_initBindings()
 {
+    this->sm = &SessionManager::instance();
        _bindDocument(*this);
        _bindLogger(*(new XML::SimpleSession()));
 }
@@ -51,16 +52,7 @@ InkboardDocument::getRecipient() const
 void
 InkboardDocument::startSessionNegotiation()
 {
-       SessionManager& sm = SessionManager::instance();
-        switch (_type) {
-            case INKBOARD_MUC:
-                sm.sendGroup(_recipient, Message::PROTOCOL, " ");
-                break;
-            case INKBOARD_PRIVATE:
-            default:
-                sm.send(_recipient, Message::PROTOCOL," ");
-                break;
-        }
+    send(_recipient, Message::PROTOCOL,Message::CONNECT_REQUEST);
 }
 
 void
@@ -79,15 +71,17 @@ bool
 InkboardDocument::send(const Glib::ustring &destJid, Message::Wrapper wrapper, Message::Message message)
 {
     char *fmt=
-        "<message type='chat' from='%s' to='%s'>"
+        "<message type='%s' from='%s' to='%s'>"
             "<wb xmlns='%s'>"
                 "<protocol>"
                     "%s"
                 "</protocol>"
             "</wb>"
         "</message>";
-    //if (!getClient().write(fmt,getClient().getJid().c_str(),destJid.c_str(),Vars::INKBOARD_XMLNS,message))
-    //    return false;
+    if (!sm->getClient().write(
+        fmt,_type,sm->getClient().getJid().c_str(),
+        destJid.c_str(),Vars::INKBOARD_XMLNS,message))
+        return false;
 
     return true;
 }
index aa726b1f912751f262d331ad3537bb2b5545c4b2..1249c42f89f74ceb3e98aff05faffd93c69042d8 100644 (file)
@@ -27,16 +27,20 @@ namespace Whiteboard {
 class InkboardDocument : public XML::SimpleNode, public XML::Document {
 public:
        
-    explicit InkboardDocument(int code, SessionType type, Glib::ustring const& to);
+    explicit InkboardDocument(int code, State::SessionType type, Glib::ustring const& to);
 
     XML::NodeType type() const
     {
        return Inkscape::XML::DOCUMENT_NODE;
     }
 
+    SessionManager *sm;
+
     void setRecipient(Glib::ustring const& val);
     Glib::ustring getRecipient() const;
 
+    void setSession();
+
     void startSessionNegotiation();
     void terminateSession();
     void processInkboardEvent(Message::Wrapper mtype, unsigned int seqnum, Glib::ustring const& data);
@@ -66,7 +70,7 @@ private:
 
     void _initBindings();
 
-    SessionType _type;
+    State::SessionType _type;
     Glib::ustring _recipient;
 
     KeyNodeTable _tracker;
index 69d46f6d1c6400265e6677bf6d4afe162ad14d21..f304d095e04d9d976e9efb1e1c3855e799ad3a48 100644 (file)
@@ -56,7 +56,7 @@ SessionManager::_checkInvitationQueue()
                switch (resp) {
                        case ACCEPT_INVITATION:
                        {
-                               SPDesktop* dt = createInkboardDesktop(from, INKBOARD_PRIVATE);
+                               SPDesktop* dt = createInkboardDesktop(from, State::WHITEBOARD_PEER);
                                InkboardDocument* idoc = dynamic_cast< InkboardDocument* >(sp_desktop_document(dt)->rdoc);
                                send(from, Message::PROTOCOL, " ");
                                break;
index e67a3c88e999d034b13bdf516a28db2779cbb0bf..3e47554bb44e8317922174965c77b9f3beabab32 100644 (file)
@@ -43,7 +43,7 @@ namespace Inkscape {
 namespace Whiteboard {
 
 SPDocument*
-makeInkboardDocument(int code, gchar const* rootname, SessionType type, Glib::ustring const& to)
+makeInkboardDocument(int code, gchar const* rootname, State::SessionType type, Glib::ustring const& to)
 {
        SPDocument* doc;
        InkboardDocument* rdoc = new InkboardDocument(g_quark_from_static_string("xml"), type, to);
index d55cfe73da2254747c24de33b0e433a78da7d7a9..ead55ef709a6382172adbb5e9b40f44ab47a3bbc 100644 (file)
@@ -23,7 +23,7 @@ namespace Inkscape {
 
 namespace Whiteboard {
 
-SPDocument* makeInkboardDocument(int code, gchar const* rootname, SessionType type, Glib::ustring const& to);
+SPDocument* makeInkboardDocument(int code, gchar const* rootname, State::SessionType type, Glib::ustring const& to);
 SPDesktop* makeInkboardDesktop(SPDocument* doc);
 
 }
index 6aff31ccaf335d39948a6dc7d21f4b747db4f844..3b689b395ef393b1bafbf2c62b045a4025138a0b 100644 (file)
@@ -2470,16 +2470,18 @@ void PedroGui::doReceiveFile(
 
 void PedroGui::doShare(const DOMString &jid)
 {
-    Inkscape::Whiteboard::SessionManager& sm = Inkscape::Whiteboard::SessionManager::instance();
-    sm.doShare(jid, Inkscape::Whiteboard::INKBOARD_PRIVATE);
+    Inkscape::Whiteboard::SessionManager& sm =
+         Inkscape::Whiteboard::SessionManager::instance();
+    sm.doShare(jid, Inkscape::Whiteboard::State::WHITEBOARD_PEER);
 
 //  Inkscape::Whiteboard::SessionManager::instance().createInkboardDesktop(jid, Inkscape::Whiteboard::INKBOARD_PRIVATE);
 }
 
 void PedroGui::doGroupShare(const DOMString &groupJid)
 {
-    Inkscape::Whiteboard::SessionManager& sm = Inkscape::Whiteboard::SessionManager::instance();
-    sm.doShare(groupJid, Inkscape::Whiteboard::INKBOARD_MUC);
+    Inkscape::Whiteboard::SessionManager& sm =
+        Inkscape::Whiteboard::SessionManager::instance();
+    sm.doShare(groupJid, Inkscape::Whiteboard::State::WHITEBOARD_MUC);
 
 //  Inkscape::Whiteboard::SessionManager::instance().createInkboardDesktop(groupJid, Inkscape::Whiteboard::INKBOARD_MUC);
 }
index acb661cafd13d36afe0e2b5b0850cc3d003e44d4..daab6bcbe72c20146be99fdc1597d4c378de829f 100644 (file)
@@ -217,60 +217,57 @@ SessionManager::processXmppEvent(const Pedro::XmppEvent &event)
  * \param type Type of the session; i.e. private message or group chat.
  */
 void
-SessionManager::doShare(Glib::ustring const& to, SessionType type)
+SessionManager::doShare(Glib::ustring const& to, State::SessionType type)
 {
     InkboardDocument* doc;
     SPDesktop* dt;
 
-    switch (type) 
+    // Just create a new blank canvas for MUC sessions
+    if(type == State::WHITEBOARD_MUC) 
     {
-        // Just create a new blank canvas for MUC sessions
-        case INKBOARD_MUC:
+        dt = createInkboardDesktop(to, type);
 
-            dt = createInkboardDesktop(to, type);
+        if (dt != NULL) 
+        {
+            doc = dynamic_cast< InkboardDocument* >(sp_desktop_document(dt)->rdoc);
 
-            if (dt != NULL) 
+            if (doc != NULL) 
             {
-                doc = dynamic_cast< InkboardDocument* >(sp_desktop_document(dt)->rdoc);
-
-                if (doc != NULL) 
-                {
-                    doc->startSessionNegotiation();
-                }
+                doc->startSessionNegotiation();
             }
-            break;
+        }
+           
 
         // Let the user pick the document which to start a peer ro peer session
         // with, or a blank one, then create a blank document, copy over the contents
         // and initialise session
-        case INKBOARD_PRIVATE:
-        default:
+    } else if (type== State::WHITEBOARD_PEER) {
 
-            ChooseDesktop dialog;
-            int result = dialog.run();
+        ChooseDesktop dialog;
+        int result = dialog.run();
 
-            if(result == Gtk::RESPONSE_OK)
+        if(result == Gtk::RESPONSE_OK)
+        {
+            SPDesktop *desktop = dialog.getDesktop();
+            dt = createInkboardDesktop(to, type);
+
+            if (dt != NULL) 
             {
-                SPDesktop *desktop = dialog.getDesktop();
-                dt = createInkboardDesktop(to, type);
+                doc = dynamic_cast< InkboardDocument* >(sp_desktop_document(dt)->rdoc);
 
-                if (dt != NULL) 
+                if (doc != NULL) 
                 {
-                    doc = dynamic_cast< InkboardDocument* >(sp_desktop_document(dt)->rdoc);
-
-                    if (doc != NULL) 
+                    if(desktop != NULL)
                     {
-                        if(desktop != NULL)
-                        {
-                            Inkscape::XML::Document *old_doc = sp_desktop_document(desktop)->rdoc;
-                            doc->root()->mergeFrom(old_doc->root(),"id");
-                        }
-
-                        doc->startSessionNegotiation();
+                        Inkscape::XML::Document *old_doc =
+                            sp_desktop_document(desktop)->rdoc;
+                        doc->root()->mergeFrom(old_doc->root(),"id");
                     }
+
+                    doc->startSessionNegotiation();
                 }
             }
-        break;
+        }
     }
 }
 
@@ -282,7 +279,7 @@ SessionManager::doShare(Glib::ustring const& to, SessionType type)
  * \return A pointer to the created desktop, or NULL if a new desktop could not be created.
  */
 SPDesktop*
-SessionManager::createInkboardDesktop(Glib::ustring const& to, SessionType type)
+SessionManager::createInkboardDesktop(Glib::ustring const& to, State::SessionType type)
 {
 // Create document (sp_repr_document_new clone)
     SPDocument* doc = makeInkboardDocument(g_quark_from_static_string("xml"), "svg:svg", type, to);
index 49909a39b4f9925716e2aa3ee39de390a509bd57..d6e600fe448c108301ca9e113e58d179a39ccb1f 100644 (file)
@@ -127,7 +127,7 @@ public:
      * \param to The recipient to which this desktop will be linked, specified as a JID.
      * \param type Type of the session; i.e. private message or group chat.
      */
-    virtual void doShare(Glib::ustring const& to, SessionType type);
+    virtual void doShare(Glib::ustring const& to, State::SessionType type);
 
     /**
      * Creates a new desktop with an InkboardDocument.
@@ -141,7 +141,7 @@ public:
      * \param type Type of the session; i.e. private message or group chat.
      * \return A pointer to the created SPDesktop.
      */
-    virtual SPDesktop* createInkboardDesktop(Glib::ustring const& to, SessionType type);
+    virtual SPDesktop* createInkboardDesktop(Glib::ustring const& to, State::SessionType type);
 
     /**
      * Terminates an Inkboard session to a given recipient.  If the session to be