Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / jabber_whiteboard / session-manager.cpp
index 3dcb8e217bdf08a9aef87406f18e25d4df1ba8bf..60d0b73781a47d1bbb7d4247af9496a4f70dfbe3 100644 (file)
@@ -4,6 +4,7 @@
  * Authors:
  * David Yip <yipdw@rose-hulman.edu>
  * Bob Jamison (Pedro port)
+ *   Abhishek Sharma
  *
  * Copyright (c) 2005 Authors
  *
@@ -29,9 +30,6 @@
 
 #include "ui/view/view-widget.h"
 
-#include "application/application.h"
-#include "application/editor.h"
-
 #include "document-private.h"
 #include "interface.h"
 #include "sp-namedview.h"
@@ -59,15 +57,15 @@ SessionManager *sessionManagerInstance = NULL;
 
 void SessionManager::showClient()
 {
-       SessionManager::instance().gui.show();
+    SessionManager::instance().gui.show();
 }
 
-SessionManager&
-SessionManager::instance()
+SessionManager &SessionManager::instance()
 {
-    if (!sessionManagerInstance)
+    if (!sessionManagerInstance) {
         sessionManagerInstance = new SessionManager();
-       return *sessionManagerInstance;
+    }
+    return *sessionManagerInstance;
 }
 
 SessionManager::SessionManager() 
@@ -229,12 +227,12 @@ SessionManager::processWhiteboardEvent(Pedro::XmppEvent const& event)
 {
     Pedro::Element* root = event.getDOM();
     if (root == NULL) {
-       g_warning("Received null DOM; ignoring message.");
-       return;
+        g_warning("Received null DOM; ignoring message.");
+        return;
     }
 
     Pedro::DOMString session = root->getTagAttribute("wb", "session");
-    Pedro::DOMString type = root->getTagAttribute("session", "type");
+    Pedro::DOMString type = root->getTagAttribute("message", "type");
     Pedro::DOMString domwrapper = root->getFirstChild()->getFirstChild()->getFirstChild()->getName();
 
     if (session.empty()) {
@@ -250,9 +248,10 @@ SessionManager::processWhiteboardEvent(Pedro::XmppEvent const& event)
     { 
         Message::Wrapper wrapper = static_cast< Message::Wrapper >(domwrapper);
         InkboardDocument* doc = getInkboardSession(session);
-        doc->processInkboardEvent(wrapper, root->getFirstChild());
-    }
 
+        if(doc != NULL)
+            doc->recieve(wrapper, root->getFirstChild());
+    }
 }
 
 char*
@@ -298,11 +297,11 @@ SessionManager::checkInvitationQueue()
     if (invitations.size() > 0) 
     {
         // There's an invitation to process; process it.
-       Invitation invitation = invitations.front();
+        Invitation invitation = invitations.front();
         Glib::ustring from = invitation.first;
         Glib::ustring sessionId = invitation.second;
 
-       Glib::ustring primary = 
+        Glib::ustring primary = 
             "<span weight=\"bold\" size=\"larger\">" + 
             String::ucompose(_("<b>%1</b> has invited you to a whiteboard session."), from) + 
             "</span>\n\n" + 
@@ -328,12 +327,12 @@ SessionManager::checkInvitationQueue()
         switch (reply) {
 
             case Dialog::ACCEPT_INVITATION:{
-                inkdoc->sendProtocol(from, Message::PROTOCOL,Message::ACCEPT_INVITATION);
+                inkdoc->send(from, Message::PROTOCOL,Message::ACCEPT_INVITATION);
                 makeInkboardDesktop(doc);
                 break; }
 
             case Dialog::DECLINE_INVITATION: default: {
-                inkdoc->sendProtocol(from, Message::PROTOCOL,Message::DECLINE_INVITATION);
+                inkdoc->send(from, Message::PROTOCOL,Message::DECLINE_INVITATION);
                 terminateSession(sessionId);
                 break; }
         }
@@ -357,18 +356,18 @@ makeInkboardDocument(int code, gchar const* rootname, State::SessionType type, G
     InkboardDocument* rdoc = new InkboardDocument(g_quark_from_static_string("xml"), type, to);
     rdoc->setAttribute("version", "1.0");
     rdoc->setAttribute("standalone", "no");
-    XML::Node *comment = sp_repr_new_comment(" Created with Inkscape (http://www.inkscape.org/) ");
+    XML::Node *comment = rdoc->createComment(" Created with Inkscape (http://www.inkscape.org/) ");
     rdoc->appendChild(comment);
     GC::release(comment);
 
-    XML::Node* root = sp_repr_new(rootname);
+    XML::Node* root = rdoc->createElement(rootname);
     rdoc->appendChild(root);
     GC::release(root);
 
     Glib::ustring name = String::ucompose(
         _("Inkboard session (%1 to %2)"), SessionManager::instance().getClient().getJid(), to);
 
-    doc = sp_document_create(rdoc, NULL, NULL, name.c_str(), TRUE);
+    doc = SPDocument::createDoc(rdoc, NULL, NULL, name.c_str(), TRUE);
     g_return_val_if_fail(doc != NULL, NULL);
 
     return doc;
@@ -380,24 +379,16 @@ makeInkboardDocument(int code, gchar const* rootname, State::SessionType type, G
 // in file.cpp.
 //
 // \see sp_file_new
-SPDesktop*
-makeInkboardDesktop(SPDocument* doc)
+SPDesktop *makeInkboardDesktop(SPDocument* doc)
 {
-    SPDesktop* dt;
+    SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL));
+    g_return_val_if_fail(dtw != NULL, NULL);
+    doc->doUnref();
 
-    if (NSApplication::Application::getNewGui()) 
-        dt = NSApplication::Editor::createDesktop(doc);
-
-    else 
-    {
-        SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL));
-        g_return_val_if_fail(dtw != NULL, NULL);
-        sp_document_unref(doc);
-
-        sp_create_window(dtw, TRUE);
-        dt = static_cast<SPDesktop*>(dtw->view);
-        sp_namedview_window_from_document(dt);
-    }
+    sp_create_window(dtw, TRUE);
+    SPDesktop *dt = static_cast<SPDesktop*>(dtw->view);
+    sp_namedview_window_from_document(dt);
+    sp_namedview_update_layers_from_document(dt);
 
     return dt;
 }
@@ -416,4 +407,4 @@ makeInkboardDesktop(SPDocument* doc)
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :