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->_server.set_text(prefs_get_string_attribute("whiteboard.server", "name"));
85 this->_port.set_text(prefs_get_string_attribute("whiteboard.server", "port"));
86 this->_username.set_text(prefs_get_string_attribute("whiteboard.server", "username"));
87 this->_usessl.set_active((prefs_get_int_attribute("whiteboard.server", "ssl", 0) == 1) ? true : false);
89 this->_layout.attach(this->_labels[0], 0, 1, 0, 1);
90 this->_layout.attach(this->_labels[3], 2, 3, 0, 1);
91 this->_layout.attach(this->_labels[1], 0, 1, 1, 2);
92 this->_layout.attach(this->_labels[2], 0, 1, 2, 3);
94 this->_layout.attach(this->_server, 1, 2, 0, 1);
95 this->_layout.attach(this->_port, 3, 4, 0, 1);
96 this->_layout.attach(this->_username, 1, 4, 1, 2);
97 this->_layout.attach(this->_password, 1, 4, 2, 3);
99 this->_layout.attach(this->_usessl, 1, 4, 3, 4);
101 this->_layout.set_col_spacings(1);
102 this->_layout.set_row_spacings(1);
104 this->_password.set_visibility(false);
105 this->_password.set_invisible_char('*');
107 // Buttons
108 this->_ok.set_label(_("Connect"));
109 this->_cancel.set_label(_("Cancel"));
110 this->_ok.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &WhiteboardConnectDialogImpl::_respCallback), GTK_RESPONSE_OK));
111 this->_cancel.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &WhiteboardConnectDialogImpl::_respCallback), GTK_RESPONSE_CANCEL));
112 this->_usessl.signal_clicked().connect(sigc::mem_fun(*this, &WhiteboardConnectDialogImpl::_useSSLClickedCallback));
114 this->_buttons.pack_start(this->_cancel, true, true, 0);
115 this->_buttons.pack_end(this->_ok, true, true, 0);
117 // Pack widgets into main vbox
118 main->pack_start(this->_layout);
119 main->pack_end(this->_buttons);
120 }
122 void
123 WhiteboardConnectDialogImpl::_respCallback(int resp)
124 {
125 if (resp == GTK_RESPONSE_OK) {
126 Glib::ustring server, port, username, password;
127 bool usessl;
129 server = this->_server.get_text();
130 port = this->_port.get_text();
131 username = this->_username.get_text();
132 password = this->_password.get_text();
133 usessl = this->_usessl.get_active();
135 Glib::ustring msg = String::ucompose(_("Establishing connection to Jabber server <b>%1</b> as user <b>%2</b>"), server, username);
136 this->_desktop->messageStack()->flash(INFORMATION_MESSAGE, msg.data());
138 switch (this->_sm->connectToServer(server, port, username, password, usessl)) {
139 case FAILED_TO_CONNECT:
140 msg = String::ucompose(_("Failed to establish connection to Jabber server <b>%1</b>"), server);
141 this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
142 this->_sm->connectionError(msg);
143 break;
144 case INVALID_AUTH:
145 msg = String::ucompose(_("Authentication failed on Jabber server <b>%1</b> as <b>%2</b>"), server, username);
146 this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
147 this->_sm->connectionError(msg);
148 break;
149 case SSL_INITIALIZATION_ERROR:
150 msg = String::ucompose(_("SSL initialization failed when connecting to Jabber server <b>%1</b>"), server);
151 this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
152 this->_sm->connectionError(msg);
153 break;
155 case CONNECT_SUCCESS:
156 msg = String::ucompose(_("Connected to Jabber server <b>%1</b> as <b>%2</b>"), server, username);
157 this->_desktop->messageStack()->flash(INFORMATION_MESSAGE, msg.data());
159 // Save preferences
160 prefs_set_string_attribute(this->_prefs_path, "server", this->_server.get_text().c_str());
161 break;
162 default:
163 break;
164 }
165 }
167 this->_password.set_text("");
168 this->hide();
169 }
171 void
172 WhiteboardConnectDialogImpl::_useSSLClickedCallback()
173 {
174 if (this->_usessl.get_active()) {
175 this->_port.set_text("5223");
177 // String::ucompose seems to format numbers according to locale; unfortunately,
178 // I'm not yet sure how to turn that off
179 //this->_port.set_text(String::ucompose("%1", LM_CONNECTION_DEFAULT_PORT_SSL));
180 } else {
181 this->_port.set_text("5222");
182 }
183 }
185 }
187 }
189 }
191 /*
192 Local Variables:
193 mode:c++
194 c-file-style:"stroustrup"
195 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
196 indent-tabs-mode:nil
197 fill-column:99
198 End:
199 */
200 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :