Code

added choose desktop dialog during intialising a whiteboard session
authordaleharvey <daleharvey@users.sourceforge.net>
Thu, 20 Jul 2006 01:19:09 +0000 (01:19 +0000)
committerdaleharvey <daleharvey@users.sourceforge.net>
Thu, 20 Jul 2006 01:19:09 +0000 (01:19 +0000)
src/jabber_whiteboard/Makefile_insert
src/jabber_whiteboard/dialog/choose-desktop.cpp [new file with mode: 0644]
src/jabber_whiteboard/dialog/choose-desktop.h [new file with mode: 0644]
src/jabber_whiteboard/session-manager.cpp

index b5d1941edd5e2b479bd618657a7ab9553462dc5f..e3966086e358b4cae53568725e51b0a43f3675c8 100644 (file)
@@ -34,6 +34,8 @@ jabber_whiteboard_SOURCES = \
        jabber_whiteboard/session-file-selector.cpp \
        jabber_whiteboard/session-file-selector.h \
        jabber_whiteboard/session-manager.cpp \
+       jabber_whiteboard/dialog/choose-desktop.cpp \
+       jabber_whiteboard/dialog/choose-desktop.h \
        jabber_whiteboard/session-manager.h \
        jabber_whiteboard/tracker-node.h \
        jabber_whiteboard/pedrogui.cpp \
diff --git a/src/jabber_whiteboard/dialog/choose-desktop.cpp b/src/jabber_whiteboard/dialog/choose-desktop.cpp
new file mode 100644 (file)
index 0000000..862b6cb
--- /dev/null
@@ -0,0 +1,107 @@
+/**
+ * \brief Choose Desktop dialog
+ *
+ * Authors:
+ *   Dale Harvey <harveyd@gmail.com>
+ *
+ * Copyright (C) 2006 Authors
+ *
+ * Released under GNU GPL.  Read the file 'COPYING' for more information.
+ */
+
+#include "choose-desktop.h"
+
+#include "document.h"
+#include "desktop-handles.h"
+#include "inkscape.h"
+
+namespace Inkscape {
+namespace Whiteboard {
+
+void ChooseDesktop::okCallback()
+{
+    response(Gtk::RESPONSE_OK);
+    hide();
+}
+
+void ChooseDesktop::cancelCallback()
+{
+    response(Gtk::RESPONSE_CANCEL);
+    hide();
+}
+
+void ChooseDesktop::doubleClickCallback(
+                   const Gtk::TreeModel::Path &path,
+                   Gtk::TreeViewColumn *col)
+{
+    response(Gtk::RESPONSE_OK);
+    hide();
+}
+
+
+SPDesktop* ChooseDesktop::getDesktop()
+{
+    Glib::RefPtr<Gtk::TreeModel> model = desktopView.get_model();
+    Glib::RefPtr<Gtk::TreeSelection> sel = desktopView.get_selection();
+    Gtk::TreeModel::iterator iter = sel->get_selected();
+    return iter->get_value(desktopColumns.desktopColumn);
+}
+
+
+bool ChooseDesktop::doSetup()
+{
+    set_title("Choose Desktop");
+    set_size_request(300,400);
+
+    add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+    add_button(Gtk::Stock::OPEN,   Gtk::RESPONSE_OK);
+
+    desktopView.signal_row_activated().connect(
+        sigc::mem_fun(*this, &ChooseDesktop::doubleClickCallback) );
+
+    std::list< SPDesktop* > desktops;
+    inkscape_get_all_desktops(desktops);
+
+    desktopListStore = Gtk::ListStore::create(desktopColumns);
+    desktopView.set_model(desktopListStore);
+
+    std::list< SPDesktop* >::iterator p = desktops.begin();
+    while(p != desktops.end())
+    {
+        SPDesktop *desktop = (SPDesktop *)*p;
+
+        Gtk::TreeModel::Row row = *(desktopListStore->append());
+        row[desktopColumns.nameColumn] = (desktop->doc())->name;
+        row[desktopColumns.desktopColumn] = (SPDesktop *)*p;
+        p++;
+    }
+
+    Gtk::TreeModel::Row row = *(desktopListStore->append());
+    row[desktopColumns.nameColumn] = "Blank Document";
+    row[desktopColumns.desktopColumn] = NULL;
+
+    desktopView.append_column("Desktop", desktopColumns.nameColumn);
+
+    desktopScroll.add(desktopView);
+    desktopScroll.set_policy(Gtk::POLICY_ALWAYS, Gtk::POLICY_ALWAYS);
+
+    get_vbox()->pack_start(desktopScroll);
+
+    show_all_children();
+
+    return true;
+}
+
+}
+}
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/jabber_whiteboard/dialog/choose-desktop.h b/src/jabber_whiteboard/dialog/choose-desktop.h
new file mode 100644 (file)
index 0000000..8b26a55
--- /dev/null
@@ -0,0 +1,66 @@
+/**
+ * \brief Choose Desktop dialog
+ *
+ * Authors:
+ *   Dale Harvey <harveyd@gmail.com>
+ *
+ * Copyright (C) 2006 Authors
+ *
+ * Released under GNU GPL.  Read the file 'COPYING' for more information.
+ */
+
+#include <gtkmm.h>
+
+#include "desktop.h"
+
+namespace Inkscape {
+namespace Whiteboard {
+
+class ChooseDesktop : public Gtk::Dialog
+{
+public:
+
+    ChooseDesktop()
+        { doSetup(); }
+
+    virtual ~ChooseDesktop()
+        {}
+
+    SPDesktop* getDesktop();
+
+private:
+
+    void okCallback();
+    void cancelCallback();
+
+    void doubleClickCallback(
+                   const Gtk::TreeModel::Path &path,
+                   Gtk::TreeViewColumn *col);
+
+    bool doSetup();
+
+    class DesktopColumns : public Gtk::TreeModel::ColumnRecord
+        {
+        public:
+            DesktopColumns()
+                {
+                add(nameColumn);
+                add(desktopColumn);
+                }
+
+            Gtk::TreeModelColumn<Glib::ustring> nameColumn;
+            Gtk::TreeModelColumn<SPDesktop*> desktopColumn;
+        };
+
+    DesktopColumns desktopColumns;
+
+    Gtk::ScrolledWindow desktopScroll;
+    Gtk::TreeView desktopView;
+
+    Glib::RefPtr<Gtk::ListStore> desktopListStore;
+
+};
+
+}
+}
+
index f8ca94612fcb80e99d798fcf72243104da4a4aea..c8b2420e620223bedd231e621831d83692ec47a6 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "xml/node-observer.h"
 
+#include "pedro/pedrodom.h"
+
 #include "document.h"
 #include "desktop.h"
 #include "desktop-handles.h"
@@ -28,6 +30,8 @@
 #include "jabber_whiteboard/inkboard-document.h"
 #include "jabber_whiteboard/new-inkboard-document.h"
 
+#include "jabber_whiteboard/dialog/choose-desktop.h"
+
 #define INKBOARD_XMLNS "http://inkscape.org/inkboard"
 
 namespace Inkscape {
@@ -81,7 +85,7 @@ SessionManager::send(const Glib::ustring &destJid,
     Pedro::DOMString xmlData = Pedro::Parser::encode(data);
     char *fmt=
     "<message type='chat' from='%s' to='%s' id='ink_%d'>"
-    "<inkboard xmlns='%s' "
+    "<w xmlns='%s' "
     "protocol='%d' type='%d' seq='%d'><x:inkboard-data>%s</x:inkboard-data></inkboard>"
     "<body></body>"
     "</message>";
@@ -214,13 +218,31 @@ SessionManager::processXmppEvent(const Pedro::XmppEvent &event)
 void
 SessionManager::doShare(Glib::ustring const& to, SessionType type)
 {
-    SPDesktop* dt = createInkboardDesktop(to, type);
-       if (dt != NULL) {
-               InkboardDocument* doc = dynamic_cast< InkboardDocument* >(sp_desktop_document(dt)->rdoc);
-               if (doc != NULL) {
-                       doc->startSessionNegotiation();
-               }
-       }
+    ChooseDesktop dialog;
+    int result = dialog.run();
+
+    if(result == Gtk::RESPONSE_OK)
+    {
+        InkboardDocument* doc;
+        SPDesktop *desktop = dialog.getDesktop();
+
+        if(desktop == NULL)
+        {
+            SPDesktop* dt = createInkboardDesktop(to, type);
+            if (dt != NULL) 
+            {
+                 doc = dynamic_cast< InkboardDocument* >(sp_desktop_document(dt)->rdoc);
+            }
+        }else 
+        {
+            doc = dynamic_cast< InkboardDocument* >(sp_desktop_document(desktop)->rdoc);
+        }
+
+        if (doc != NULL) 
+        {
+            doc->startSessionNegotiation();
+        }
+    }
 }
 
 /**