Code

e67a3c88e999d034b13bdf516a28db2779cbb0bf
[inkscape.git] / src / jabber_whiteboard / new-inkboard-document.cpp
1 /**
2  * new-inkboard-document.h
3  * Functions to create new Inkboard documents, based off of sp_document_new /
4  * sp_file_new
5  *
6  * Authors:
7  * David Yip <yipdw@rose-hulman.edu>
8  *
9  * Copyright (c) 2006 Authors
10  *
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
14 #include <glib.h>
15 #include <glibmm.h>
16 #include <glibmm/i18n.h>
18 #include "document.h"
19 #include "document-private.h"
20 #include "desktop.h"
21 #include "desktop-handles.h"
22 #include "interface.h"
23 #include "sp-namedview.h"
24 #include "desktop-handles.h"
26 #include "gc-anchored.h"
28 #include "ui/view/view-widget.h"
30 #include "application/application.h"
31 #include "application/editor.h"
33 #include "util/ucompose.hpp"
35 #include "xml/node.h"
36 #include "xml/repr.h"
38 #include "jabber_whiteboard/inkboard-document.h"
39 #include "jabber_whiteboard/new-inkboard-document.h"
41 namespace Inkscape {
43 namespace Whiteboard {
45 SPDocument*
46 makeInkboardDocument(int code, gchar const* rootname, SessionType type, Glib::ustring const& to)
47 {
48         SPDocument* doc;
49         InkboardDocument* rdoc = new InkboardDocument(g_quark_from_static_string("xml"), type, to);
50         rdoc->setAttribute("version", "1.0");
51         rdoc->setAttribute("standalone", "no");
52         XML::Node *comment = sp_repr_new_comment(" Created with Inkscape (http://www.inkscape.org/) ");
53         rdoc->appendChild(comment);
54         GC::release(comment);
56         XML::Node* root = sp_repr_new(rootname);
57         rdoc->appendChild(root);
58         GC::release(root);
60         Glib::ustring name = String::ucompose(_("Inkboard session (%1 to %2)"), SessionManager::instance().getClient().getJid(), to);
62         doc = sp_document_create(rdoc, NULL, NULL, name.c_str(), TRUE);
63         return doc;
64 }
66 // TODO: When the switchover to the new GUI is complete, this function should go away
67 // and be replaced with a call to Inkscape::NSApplication::Editor::createDesktop.  
68 // It currently only exists to correctly mimic the desktop creation functionality
69 // in file.cpp.
70 //
71 // \see sp_file_new
72 SPDesktop*
73 makeInkboardDesktop(SPDocument* doc)
74 {
75         SPDesktop* dt;
77         if (NSApplication::Application::getNewGui()) {
78                 dt = NSApplication::Editor::createDesktop(doc);
79         } else {
80         SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL));
81         g_return_val_if_fail(dtw != NULL, NULL);
82         sp_document_unref(doc);
84         sp_create_window(dtw, TRUE);
85         dt = static_cast<SPDesktop*>(dtw->view);
86         sp_namedview_window_from_document(dt);
87         }
89         return dt;
90 }
92 }
94 }