Code

173e9a79417558148f2c579702b1046118e7b852
[inkscape.git] / src / ui / dialog / whiteboard-connect.cpp
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
56 WhiteboardConnectDialogImpl::setSessionManager()
57 {
58         this->_desktop = SP_ACTIVE_DESKTOP;
59         this->_sm = SP_ACTIVE_DESKTOP->whiteboard_session_manager();
61 }
63 void
64 WhiteboardConnectDialogImpl::_construct()
65 {
66         Gtk::VBox* main = this->get_vbox();
68         // Construct dialog interface
69         this->_labels[0].set_markup_with_mnemonic(_("_Server:"));
70         this->_labels[1].set_markup_with_mnemonic(_("_Username:"));
71         this->_labels[2].set_markup_with_mnemonic(_("_Password:"));
72         this->_labels[3].set_markup_with_mnemonic(_("P_ort:"));
74         this->_labels[0].set_mnemonic_widget(this->_server);
75         this->_labels[1].set_mnemonic_widget(this->_username);
76         this->_labels[2].set_mnemonic_widget(this->_password);
77         this->_labels[3].set_mnemonic_widget(this->_port);
79         this->_port.set_text("5222");
81         this->_layout.attach(this->_labels[0], 0, 1, 0, 1);
82         this->_layout.attach(this->_labels[3], 2, 3, 0, 1);
83         this->_layout.attach(this->_labels[1], 0, 1, 1, 2);
84         this->_layout.attach(this->_labels[2], 0, 1, 2, 3);
86         this->_layout.attach(this->_server, 1, 2, 0, 1);
87         this->_layout.attach(this->_port, 3, 4, 0, 1);
88         this->_layout.attach(this->_username, 1, 4, 1, 2);
89         this->_layout.attach(this->_password, 1, 4, 2, 3);
91         this->_layout.attach(this->_usessl, 1, 4, 3, 4);
93         this->_layout.set_col_spacings(1);
94         this->_layout.set_row_spacings(1);
96         this->_password.set_visibility(false);
97         this->_password.set_invisible_char('*');
99         // Buttons
100         this->_ok.set_label(_("Connect"));
101         this->_cancel.set_label(_("Cancel"));
102         this->_ok.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &WhiteboardConnectDialogImpl::_respCallback), GTK_RESPONSE_OK));
103         this->_cancel.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &WhiteboardConnectDialogImpl::_respCallback), GTK_RESPONSE_CANCEL));
104         this->_usessl.signal_clicked().connect(sigc::mem_fun(*this, &WhiteboardConnectDialogImpl::_useSSLClickedCallback));
106         this->_buttons.pack_start(this->_cancel, true, true, 0);
107         this->_buttons.pack_end(this->_ok, true, true, 0);
109         // Pack widgets into main vbox
110         main->pack_start(this->_layout);
111         main->pack_end(this->_buttons);
114 void
115 WhiteboardConnectDialogImpl::_respCallback(int resp)
117         if (resp == GTK_RESPONSE_OK) {
118                 Glib::ustring server, port, username, password;
119                 bool usessl;
121                 server = this->_server.get_text();
122                 port = this->_port.get_text();
123                 username = this->_username.get_text();
124                 password = this->_password.get_text();
125                 usessl = this->_usessl.get_active();
127                 Glib::ustring msg = String::ucompose(_("Establishing connection to Jabber server <b>%1</b> as user <b>%2</b>"), server, username);
128                 this->_desktop->messageStack()->flash(INFORMATION_MESSAGE, msg.data());
130                 switch (this->_sm->connectToServer(server, port, username, password, usessl)) {
131                         case FAILED_TO_CONNECT:
132                                 msg = String::ucompose(_("Failed to establish connection to Jabber server <b>%1</b>"), server);
133                                 this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
134                                 this->_sm->connectionError(msg);
135                                 break;
136                         case INVALID_AUTH:
137                                 msg = String::ucompose(_("Authentication failed on Jabber server <b>%1</b> as <b>%2</b>"), server, username);
138                                 this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
139                                 this->_sm->connectionError(msg);
140                                 break;
141                         case SSL_INITIALIZATION_ERROR:
142                                 msg = String::ucompose(_("SSL initialization failed when connecting to Jabber server <b>%1</b>"), server);
143                                 this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
144                                 this->_sm->connectionError(msg);
145                                 break;
146                                 
147                         case CONNECT_SUCCESS:
148                                 msg = String::ucompose(_("Connected to Jabber server <b>%1</b> as <b>%2</b>"), server, username);
149                                 this->_desktop->messageStack()->flash(INFORMATION_MESSAGE, msg.data());
151                                 // Save preferences
152                                 prefs_set_string_attribute(this->_prefs_path, "server", this->_server.get_text().c_str());
153                                 break;
154                         default:
155                                 break;
156                 }
157         }
159         this->_password.set_text("");
160         this->hide();
163 void
164 WhiteboardConnectDialogImpl::_useSSLClickedCallback()
166         if (this->_usessl.get_active()) {
167                 this->_port.set_text("5223");
168         
169                 // String::ucompose seems to format numbers according to locale; unfortunately,
170                 // I'm not yet sure how to turn that off
171                 //this->_port.set_text(String::ucompose("%1", LM_CONNECTION_DEFAULT_PORT_SSL));
172         } else {
173                 this->_port.set_text("5222");
174         }
183 /*
184   Local Variables:
185   mode:c++
186   c-file-style:"stroustrup"
187   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
188   indent-tabs-mode:nil
189   fill-column:99
190   End:
191 */
192 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :