From 6a73af8e23aabc594e7c72c96ec5733adbdc0c7a Mon Sep 17 00:00:00 2001 From: daleharvey Date: Sun, 30 Jul 2006 13:29:30 +0000 Subject: [PATCH] working on session establishment --- src/jabber_whiteboard/defines.h | 1 + src/jabber_whiteboard/inkboard-document.cpp | 22 +++---- src/jabber_whiteboard/inkboard-document.h | 8 ++- src/jabber_whiteboard/invitation-handlers.cpp | 2 +- .../new-inkboard-document.cpp | 2 +- src/jabber_whiteboard/new-inkboard-document.h | 2 +- src/jabber_whiteboard/pedrogui.cpp | 10 +-- src/jabber_whiteboard/session-manager.cpp | 63 +++++++++---------- src/jabber_whiteboard/session-manager.h | 4 +- 9 files changed, 56 insertions(+), 58 deletions(-) diff --git a/src/jabber_whiteboard/defines.h b/src/jabber_whiteboard/defines.h index cef369056..05e4b9b76 100644 --- a/src/jabber_whiteboard/defines.h +++ b/src/jabber_whiteboard/defines.h @@ -98,6 +98,7 @@ namespace State { extern SessionType WHITEBOARD_MUC; extern SessionType WHITEBOARD_PEER; + typedef char const* SessionState; } // message types diff --git a/src/jabber_whiteboard/inkboard-document.cpp b/src/jabber_whiteboard/inkboard-document.cpp index 9477399e5..e53b7ec80 100644 --- a/src/jabber_whiteboard/inkboard-document.cpp +++ b/src/jabber_whiteboard/inkboard-document.cpp @@ -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= - "" + "" "" "" "%s" "" "" ""; - //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; } diff --git a/src/jabber_whiteboard/inkboard-document.h b/src/jabber_whiteboard/inkboard-document.h index aa726b1f9..1249c42f8 100644 --- a/src/jabber_whiteboard/inkboard-document.h +++ b/src/jabber_whiteboard/inkboard-document.h @@ -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; diff --git a/src/jabber_whiteboard/invitation-handlers.cpp b/src/jabber_whiteboard/invitation-handlers.cpp index 69d46f6d1..f304d095e 100644 --- a/src/jabber_whiteboard/invitation-handlers.cpp +++ b/src/jabber_whiteboard/invitation-handlers.cpp @@ -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; diff --git a/src/jabber_whiteboard/new-inkboard-document.cpp b/src/jabber_whiteboard/new-inkboard-document.cpp index e67a3c88e..3e47554bb 100644 --- a/src/jabber_whiteboard/new-inkboard-document.cpp +++ b/src/jabber_whiteboard/new-inkboard-document.cpp @@ -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); diff --git a/src/jabber_whiteboard/new-inkboard-document.h b/src/jabber_whiteboard/new-inkboard-document.h index d55cfe73d..ead55ef70 100644 --- a/src/jabber_whiteboard/new-inkboard-document.h +++ b/src/jabber_whiteboard/new-inkboard-document.h @@ -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); } diff --git a/src/jabber_whiteboard/pedrogui.cpp b/src/jabber_whiteboard/pedrogui.cpp index 6aff31cca..3b689b395 100644 --- a/src/jabber_whiteboard/pedrogui.cpp +++ b/src/jabber_whiteboard/pedrogui.cpp @@ -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); } diff --git a/src/jabber_whiteboard/session-manager.cpp b/src/jabber_whiteboard/session-manager.cpp index acb661caf..daab6bcbe 100644 --- a/src/jabber_whiteboard/session-manager.cpp +++ b/src/jabber_whiteboard/session-manager.cpp @@ -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); diff --git a/src/jabber_whiteboard/session-manager.h b/src/jabber_whiteboard/session-manager.h index 49909a39b..d6e600fe4 100644 --- a/src/jabber_whiteboard/session-manager.h +++ b/src/jabber_whiteboard/session-manager.h @@ -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 -- 2.30.2