1 /**
2 * Whiteboard connection establishment 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>
14 #include <gtk/gtkdialog.h>
15 #include <gtkmm/entry.h>
16 #include <gtkmm/checkbutton.h>
17 #include <gtkmm/table.h>
19 #include "inkscape.h"
20 #include "desktop.h"
21 #include "message-stack.h"
22 #include "prefs-utils.h"
24 #include "jabber_whiteboard/session-manager.h"
26 #include "message-context.h"
27 #include "ui/dialog/whiteboard-connect.h"
29 #include "util/ucompose.hpp"
31 namespace Inkscape {
33 namespace UI {
35 namespace Dialog {
37 WhiteboardConnectDialog*
38 WhiteboardConnectDialog::create()
39 {
40 return new WhiteboardConnectDialogImpl();
41 }
43 WhiteboardConnectDialogImpl::WhiteboardConnectDialogImpl() :
44 _layout(4, 4, false), _usessl(_("_Use SSL"), true)
45 {
46 this->setSessionManager();
47 this->_construct();
48 this->get_vbox()->show_all_children();
49 }
51 WhiteboardConnectDialogImpl::~WhiteboardConnectDialogImpl()
52 {
53 }
55 void WhiteboardConnectDialogImpl::present()
56 {
57 Dialog::present();
58 }
60 void
61 WhiteboardConnectDialogImpl::setSessionManager()
62 {
63 this->_desktop = SP_ACTIVE_DESKTOP;
64 this->_sm = SP_ACTIVE_DESKTOP->whiteboard_session_manager();
66 }
68 void
69 WhiteboardConnectDialogImpl::_construct()
70 {
71 Gtk::VBox* main = this->get_vbox();
73 // Construct dialog interface
74 this->_labels[0].set_markup_with_mnemonic(_("_Server:"));
75 this->_labels[1].set_markup_with_mnemonic(_("_Username:"));
76 this->_labels[2].set_markup_with_mnemonic(_("_Password:"));
77 this->_labels[3].set_markup_with_mnemonic(_("P_ort:"));
79 this->_labels[0].set_mnemonic_widget(this->_server);
80 this->_labels[1].set_mnemonic_widget(this->_username);
81 this->_labels[2].set_mnemonic_widget(this->_password);
82 this->_labels[3].set_mnemonic_widget(this->_port);
84 this->_port.set_text("5222");
86 this->_layout.attach(this->_labels[0], 0, 1, 0, 1);
87 this->_layout.attach(this->_labels[3], 2, 3, 0, 1);
88 this->_layout.attach(this->_labels[1], 0, 1, 1, 2);
89 this->_layout.attach(this->_labels[2], 0, 1, 2, 3);
91 this->_layout.attach(this->_server, 1, 2, 0, 1);
92 this->_layout.attach(this->_port, 3, 4, 0, 1);
93 this->_layout.attach(this->_username, 1, 4, 1, 2);
94 this->_layout.attach(this->_password, 1, 4, 2, 3);
96 this->_layout.attach(this->_usessl, 1, 4, 3, 4);
98 this->_layout.set_col_spacings(1);
99 this->_layout.set_row_spacings(1);
101 this->_password.set_visibility(false);
102 this->_password.set_invisible_char('*');
104 // Buttons
105 this->_ok.set_label(_("Connect"));
106 this->_cancel.set_label(_("Cancel"));
107 this->_ok.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &WhiteboardConnectDialogImpl::_respCallback), GTK_RESPONSE_OK));
108 this->_cancel.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &WhiteboardConnectDialogImpl::_respCallback), GTK_RESPONSE_CANCEL));
109 this->_usessl.signal_clicked().connect(sigc::mem_fun(*this, &WhiteboardConnectDialogImpl::_useSSLClickedCallback));
111 this->_buttons.pack_start(this->_cancel, true, true, 0);
112 this->_buttons.pack_end(this->_ok, true, true, 0);
114 // Pack widgets into main vbox
115 main->pack_start(this->_layout);
116 main->pack_end(this->_buttons);
117 }
119 void
120 WhiteboardConnectDialogImpl::_respCallback(int resp)
121 {
122 if (resp == GTK_RESPONSE_OK) {
123 Glib::ustring server, port, username, password;
124 bool usessl;
126 server = this->_server.get_text();
127 port = this->_port.get_text();
128 username = this->_username.get_text();
129 password = this->_password.get_text();
130 usessl = this->_usessl.get_active();
132 Glib::ustring msg = String::ucompose(_("Establishing connection to Jabber server <b>%1</b> as user <b>%2</b>"), server, username);
133 this->_desktop->messageStack()->flash(INFORMATION_MESSAGE, msg.data());
135 switch (this->_sm->connectToServer(server, port, username, password, usessl)) {
136 case FAILED_TO_CONNECT:
137 msg = String::ucompose(_("Failed to establish connection to Jabber server <b>%1</b>"), server);
138 this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
139 this->_sm->connectionError(msg);
140 break;
141 case INVALID_AUTH:
142 msg = String::ucompose(_("Authentication failed on Jabber server <b>%1</b> as <b>%2</b>"), server, username);
143 this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
144 this->_sm->connectionError(msg);
145 break;
146 case SSL_INITIALIZATION_ERROR:
147 msg = String::ucompose(_("SSL initialization failed when connecting to Jabber server <b>%1</b>"), server);
148 this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
149 this->_sm->connectionError(msg);
150 break;
152 case CONNECT_SUCCESS:
153 msg = String::ucompose(_("Connected to Jabber server <b>%1</b> as <b>%2</b>"), server, username);
154 this->_desktop->messageStack()->flash(INFORMATION_MESSAGE, msg.data());
156 // Save preferences
157 prefs_set_string_attribute(this->_prefs_path, "server", this->_server.get_text().c_str());
158 break;
159 default:
160 break;
161 }
162 }
164 this->_password.set_text("");
165 this->hide();
166 }
168 void
169 WhiteboardConnectDialogImpl::_useSSLClickedCallback()
170 {
171 if (this->_usessl.get_active()) {
172 this->_port.set_text("5223");
174 // String::ucompose seems to format numbers according to locale; unfortunately,
175 // I'm not yet sure how to turn that off
176 //this->_port.set_text(String::ucompose("%1", LM_CONNECTION_DEFAULT_PORT_SSL));
177 } else {
178 this->_port.set_text("5222");
179 }
180 }
182 }
184 }
186 }
188 /*
189 Local Variables:
190 mode:c++
191 c-file-style:"stroustrup"
192 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
193 indent-tabs-mode:nil
194 fill-column:99
195 End:
196 */
197 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :