1 /**
2 * Whiteboard share with chatroom dialog
3 *
4 * Authors:
5 * David Yip <yipdw@rose-hulman.edu>
6 * Jason Segal, Jonas Collaros, Stephen Montgomery, Brandi Soggs, Matthew Weinstock (original C/Gtk version)
7 *
8 * Copyright (c) 2004-2005 Authors
9 *
10 * Released under GNU GPL, read the file 'COPYING' for more information
11 */
13 #include <glibmm/i18n.h>
15 #include <sigc++/sigc++.h>
16 #include <gtk/gtkdialog.h>
18 #include "message-stack.h"
19 #include "message-context.h"
20 #include "inkscape.h"
21 #include "desktop.h"
23 #include "prefs-utils.h"
25 #include "jabber_whiteboard/typedefs.h"
26 #include "jabber_whiteboard/session-manager.h"
27 #include "jabber_whiteboard/buddy-list-manager.h"
29 #include "jabber_whiteboard/session-file-selector.h"
31 #include "ui/dialog/whiteboard-sharewithchat.h"
33 #include "util/ucompose.hpp"
35 namespace Inkscape {
37 namespace UI {
39 namespace Dialog {
41 WhiteboardShareWithChatroomDialog*
42 WhiteboardShareWithChatroomDialog::create()
43 {
44 return new WhiteboardShareWithChatroomDialogImpl();
45 }
47 WhiteboardShareWithChatroomDialogImpl::WhiteboardShareWithChatroomDialogImpl() :
48 _layout(4, 2, false)
49 {
50 this->setSessionManager();
51 this->_construct();
52 this->get_vbox()->show_all_children();
53 }
55 WhiteboardShareWithChatroomDialogImpl::~WhiteboardShareWithChatroomDialogImpl()
56 {
58 }
60 void
61 WhiteboardShareWithChatroomDialogImpl::setSessionManager()
62 {
63 this->_desktop = SP_ACTIVE_DESKTOP;
64 this->_sm = SP_ACTIVE_DESKTOP->whiteboard_session_manager();
66 }
69 void
70 WhiteboardShareWithChatroomDialogImpl::_construct()
71 {
72 Gtk::VBox* main = this->get_vbox();
74 // Construct labels
75 this->_labels[0].set_markup_with_mnemonic(_("Chatroom _name:"));
76 this->_labels[1].set_markup_with_mnemonic(_("Chatroom _server:"));
77 this->_labels[2].set_markup_with_mnemonic(_("Chatroom _password:"));
78 this->_labels[3].set_markup_with_mnemonic(_("Chatroom _handle:"));
80 this->_labels[0].set_mnemonic_widget(this->_roomname);
81 this->_labels[1].set_mnemonic_widget(this->_confserver);
82 this->_labels[2].set_mnemonic_widget(this->_roompass);
83 this->_labels[3].set_mnemonic_widget(this->_handle);
86 this->_roomname.set_text(prefs_get_string_attribute("whiteboard.room", "name"));
87 this->_confserver.set_text(prefs_get_string_attribute("whiteboard.room", "server"));
88 this->_handle.set_text(prefs_get_string_attribute("whiteboard.server", "username"));
90 // Pack table
91 this->_layout.attach(this->_labels[0], 0, 1, 0, 1);
92 this->_layout.attach(this->_labels[1], 0, 1, 1, 2);
93 this->_layout.attach(this->_labels[2], 0, 1, 2, 3);
94 this->_layout.attach(this->_labels[3], 0, 1, 3, 4);
96 this->_layout.attach(this->_roomname, 1, 2, 0, 1);
97 this->_layout.attach(this->_confserver, 1, 2, 1, 2);
98 this->_layout.attach(this->_roompass, 1, 2, 2, 3);
99 this->_layout.attach(this->_handle, 1, 2, 3, 4);
101 // Button setup and callback registration
102 this->_share.set_label(_("Connect to chatroom"));
103 this->_cancel.set_label(_("Cancel"));
104 this->_share.set_use_underline(true);
105 this->_cancel.set_use_underline(true);
107 this->_share.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &WhiteboardShareWithChatroomDialogImpl::_respCallback), WhiteboardShareWithChatroomDialogImpl::SHARE));
108 this->_cancel.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &WhiteboardShareWithChatroomDialogImpl::_respCallback), WhiteboardShareWithChatroomDialogImpl::CANCEL));
110 // Pack buttons
111 this->_buttonsbox.pack_start(this->_cancel);
112 this->_buttonsbox.pack_start(this->_share);
114 // Set default values
115 Glib::ustring jid = this->_sm->session_data->jid;
116 Glib::ustring nick = jid.substr(0, jid.find_first_of('@'));
117 this->_handle.set_text(nick);
118 this->_roomname.set_text("inkboard");
120 // Pack into main box
121 main->pack_start(this->_layout);
122 main->pack_end(this->_buttonsbox);
123 }
125 void
126 WhiteboardShareWithChatroomDialogImpl::_respCallback(int resp)
127 {
128 switch (resp) {
129 case SHARE:
130 {
131 Glib::ustring chatroom, server, handle, password;
132 chatroom = this->_roomname.get_text();
133 server = this->_confserver.get_text();
134 password = this->_roompass.get_text();
135 handle = this->_handle.get_text();
137 Glib::ustring msg = String::ucompose(_("Synchronizing with chatroom <b>%1@%2</b> using the handle <b>%3</b>"), chatroom, server, handle);
139 this->_desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, msg.data());
141 this->_desktop->whiteboard_session_manager()->sendRequestToChatroom(server, chatroom, handle, password);
142 }
143 case CANCEL:
144 default:
145 this->hide();
146 break;
147 }
148 }
150 }
152 }
154 }