Code

4c86b0dfac416dfac6e4af439e2eae254396ca20
[inkscape.git] / src / ui / dialog / whiteboard-sharewithchat.cpp
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 "jabber_whiteboard/typedefs.h"
24 #include "jabber_whiteboard/session-manager.h"
25 #include "jabber_whiteboard/buddy-list-manager.h"
27 #include "jabber_whiteboard/session-file-selector.h"
29 #include "ui/dialog/whiteboard-sharewithchat.h"
31 #include "util/ucompose.hpp"
33 namespace Inkscape {
35 namespace UI {
37 namespace Dialog {
39 WhiteboardShareWithChatroomDialog* 
40 WhiteboardShareWithChatroomDialog::create()
41 {
42         return new WhiteboardShareWithChatroomDialogImpl();
43 }
45 WhiteboardShareWithChatroomDialogImpl::WhiteboardShareWithChatroomDialogImpl() :
46         _layout(4, 2, false)
47 {
48         this->setSessionManager();
49         this->_construct();
50         this->get_vbox()->show_all_children();
51 }
53 WhiteboardShareWithChatroomDialogImpl::~WhiteboardShareWithChatroomDialogImpl()
54 {
56 }
58 void
59 WhiteboardShareWithChatroomDialogImpl::setSessionManager()
60 {
61         this->_desktop = SP_ACTIVE_DESKTOP;
62         this->_sm = SP_ACTIVE_DESKTOP->whiteboard_session_manager();
64 }
67 void
68 WhiteboardShareWithChatroomDialogImpl::_construct()
69 {
70         Gtk::VBox* main = this->get_vbox();
72         // Construct labels
73         this->_labels[0].set_markup_with_mnemonic(_("Chatroom _name:"));
74         this->_labels[1].set_markup_with_mnemonic(_("Chatroom _server:"));
75         this->_labels[2].set_markup_with_mnemonic(_("Chatroom _password:"));
76         this->_labels[3].set_markup_with_mnemonic(_("Chatroom _handle:"));
78         this->_labels[0].set_mnemonic_widget(this->_roomname);
79         this->_labels[1].set_mnemonic_widget(this->_confserver);
80         this->_labels[2].set_mnemonic_widget(this->_roompass);
81         this->_labels[3].set_mnemonic_widget(this->_handle);
83         // Pack table
84         this->_layout.attach(this->_labels[0], 0, 1, 0, 1);
85         this->_layout.attach(this->_labels[1], 0, 1, 1, 2);
86         this->_layout.attach(this->_labels[2], 0, 1, 2, 3);
87         this->_layout.attach(this->_labels[3], 0, 1, 3, 4);
89         this->_layout.attach(this->_roomname, 1, 2, 0, 1);
90         this->_layout.attach(this->_confserver, 1, 2, 1, 2);
91         this->_layout.attach(this->_roompass, 1, 2, 2, 3);
92         this->_layout.attach(this->_handle, 1, 2, 3, 4);
94         // Button setup and callback registration
95         this->_share.set_label(_("Connect to chatroom"));
96         this->_cancel.set_label(_("Cancel"));
97         this->_share.set_use_underline(true);
98         this->_cancel.set_use_underline(true);
100         this->_share.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &WhiteboardShareWithChatroomDialogImpl::_respCallback), WhiteboardShareWithChatroomDialogImpl::SHARE));
101         this->_cancel.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &WhiteboardShareWithChatroomDialogImpl::_respCallback), WhiteboardShareWithChatroomDialogImpl::CANCEL));
103         // Pack buttons
104         this->_buttonsbox.pack_start(this->_cancel);
105         this->_buttonsbox.pack_start(this->_share);
107         // Set default values
108         Glib::ustring jid = lm_connection_get_jid(this->_sm->session_data->connection);
109         Glib::ustring nick = jid.substr(0, jid.find_first_of('@'));
110         this->_handle.set_text(nick);
111         this->_roomname.set_text("inkboard");
113         // Pack into main box
114         main->pack_start(this->_layout);
115         main->pack_end(this->_buttonsbox);
118 void
119 WhiteboardShareWithChatroomDialogImpl::_respCallback(int resp)
121         switch (resp) {
122                 case SHARE:
123                 {
124                         Glib::ustring chatroom, server, handle, password;
125                         chatroom = this->_roomname.get_text();
126                         server = this->_confserver.get_text();
127                         password = this->_roompass.get_text();
128                         handle = this->_handle.get_text();
130                         Glib::ustring msg = String::ucompose(_("Synchronizing with chatroom <b>%1@%2</b> using the handle <b>%3</b>"), chatroom, server, handle);
132                         this->_desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, msg.data());
134                         this->_desktop->whiteboard_session_manager()->sendRequestToChatroom(server, chatroom, handle, password);
135                 }
136                 case CANCEL:
137                 default:
138                         this->hide();
139                         break;
140         }