1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
/**
* Whiteboard connection establishment dialog
*
* Authors:
* David Yip <yipdw@rose-hulman.edu>
* Jason Segal, Jonas Collaros, Stephen Montgomery, Brandi Soggs, Matthew Weinstock (original C/Gtk version)
*
* Copyright (c) 2004-2005 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <glibmm/i18n.h>
#include <gtk/gtkdialog.h>
#include <gtkmm/entry.h>
#include <gtkmm/checkbutton.h>
#include <gtkmm/table.h>
#include "inkscape.h"
#include "desktop.h"
#include "message-stack.h"
#include "prefs-utils.h"
#include "jabber_whiteboard/session-manager.h"
#include "message-context.h"
#include "ui/dialog/whiteboard-connect.h"
#include "util/ucompose.hpp"
namespace Inkscape {
namespace UI {
namespace Dialog {
WhiteboardConnectDialog*
WhiteboardConnectDialog::create()
{
return new WhiteboardConnectDialogImpl();
}
WhiteboardConnectDialogImpl::WhiteboardConnectDialogImpl() :
_layout(4, 4, false), _usessl(_("_Use SSL"), true), _register(_("_Register"), true)
{
this->setSessionManager();
this->_construct();
//this->set_resize_mode(Gtk::RESIZE_IMMEDIATE);
this->set_resizable(false);
this->get_vbox()->show_all_children();
}
WhiteboardConnectDialogImpl::~WhiteboardConnectDialogImpl()
{
}
void WhiteboardConnectDialogImpl::present()
{
Dialog::present();
}
void
WhiteboardConnectDialogImpl::setSessionManager()
{
this->_desktop = this->getDesktop();
this->_sm = this->_desktop->whiteboard_session_manager();
}
void
WhiteboardConnectDialogImpl::_construct()
{
Gtk::VBox* main = this->get_vbox();
// Construct dialog interface
this->_labels[0].set_markup_with_mnemonic(_("_Server:"));
this->_labels[1].set_markup_with_mnemonic(_("_Username:"));
this->_labels[2].set_markup_with_mnemonic(_("_Password:"));
this->_labels[3].set_markup_with_mnemonic(_("P_ort:"));
this->_labels[0].set_mnemonic_widget(this->_server);
this->_labels[1].set_mnemonic_widget(this->_username);
this->_labels[2].set_mnemonic_widget(this->_password);
this->_labels[3].set_mnemonic_widget(this->_port);
this->_server.set_text(prefs_get_string_attribute("whiteboard.server", "name"));
this->_port.set_text(prefs_get_string_attribute("whiteboard.server", "port"));
this->_username.set_text(prefs_get_string_attribute("whiteboard.server", "username"));
this->_usessl.set_active((prefs_get_int_attribute("whiteboard.server", "ssl", 0) == 1) ? true : false);
this->_layout.attach(this->_labels[0], 0, 1, 0, 1);
this->_layout.attach(this->_labels[1], 0, 1, 1, 2);
this->_layout.attach(this->_labels[2], 0, 1, 2, 3);
this->_layout.attach(this->_labels[3], 2, 3, 0, 1);
this->_layout.attach(this->_server, 1, 2, 0, 1);
this->_layout.attach(this->_port, 3, 4, 0, 1);
this->_layout.attach(this->_username, 1, 4, 1, 2);
this->_layout.attach(this->_password, 1, 4, 2, 3);
this->_checkboxes.attach(this->_blank,0,1,0,1);
this->_checkboxes.attach(this->_blank,0,1,1,2);
this->_checkboxes.attach(this->_usessl, 1, 4, 0, 1);
this->_checkboxes.attach(this->_register, 1, 5, 1, 2);
this->_layout.set_col_spacings(1);
this->_layout.set_row_spacings(1);
this->_password.set_visibility(false);
this->_password.set_invisible_char('*');
// Buttons
this->_ok.set_label(_("Connect"));
this->_cancel.set_label(_("Cancel"));
this->_ok.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &WhiteboardConnectDialogImpl::_respCallback), GTK_RESPONSE_OK));
this->_cancel.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &WhiteboardConnectDialogImpl::_respCallback), GTK_RESPONSE_CANCEL));
this->_register.signal_clicked().connect(sigc::mem_fun(*this, &WhiteboardConnectDialogImpl::_registerCallback));
this->_usessl.signal_clicked().connect(sigc::mem_fun(*this, &WhiteboardConnectDialogImpl::_useSSLClickedCallback));
this->_buttons.pack_start(this->_cancel, true, true, 0);
this->_buttons.pack_end(this->_ok, true, true, 0);
// Pack widgets into main vbox
main->pack_start(this->_layout,Gtk::PACK_SHRINK);
main->pack_start(this->_checkboxes,Gtk::PACK_SHRINK);
main->pack_end(this->_buttons,Gtk::PACK_SHRINK);
}
void
WhiteboardConnectDialogImpl::_registerCallback()
{
if (this->_register.get_active())
{
Glib::ustring server, port;
bool usessl;
server = this->_server.get_text();
port = this->_port.get_text();
usessl = this->_usessl.get_active();
Glib::ustring msg = String::ucompose(_("Establishing connection to Jabber server <b>%1</b>"), server);
this->_desktop->messageStack()->flash(INFORMATION_MESSAGE, msg.data());
if(this->_sm->initializeConnection(server,port,usessl) == CONNECT_SUCCESS)
{
std::vector<Glib::ustring> entries = this->_sm->getRegistrationInfo();
for(unsigned i = 0; i<entries.size();i++)
{
Gtk::Entry *entry = manage (new Gtk::Entry);
Gtk::Label *label = manage (new Gtk::Label);
Glib::ustring::size_type zero=0,one=1;
Glib::ustring LabelText = entries[i].replace(zero,one,one,Glib::Unicode::toupper(entries[i].at(0)));
(*label).set_markup_with_mnemonic(LabelText.c_str());
(*label).set_mnemonic_widget(*entry);
this->_layout.attach (*label, 0, 1, i+3, i+4, Gtk::FILL|Gtk::EXPAND|Gtk::SHRINK, (Gtk::AttachOptions)0,0,0);
this->_layout.attach (*entry, 1, 4, i+3, i+4, Gtk::FILL|Gtk::EXPAND|Gtk::SHRINK, (Gtk::AttachOptions)0,0,0);
this->registerlabels.push_back(label);
this->registerentries.push_back(entry);
}
}else{
Glib::ustring msg = String::ucompose(_("Failed to establish connection to Jabber server <b>%1</b>"), server);
this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
this->_sm->connectionError(msg);
}
}else{
for(unsigned i = 0; i<registerlabels.size();i++)
{
this->_layout.remove(*registerlabels[i]);
this->_layout.remove(*registerentries[i]);
delete registerlabels[i];
delete registerentries[i];
}
registerentries.erase(registerentries.begin(), registerentries.end());
registerlabels.erase(registerlabels.begin(), registerlabels.end());
}
this->get_vbox()->show_all_children();
//this->reshow_with_initial_size();
}
void
WhiteboardConnectDialogImpl::_respCallback(int resp)
{
if (resp == GTK_RESPONSE_OK)
{
Glib::ustring server, port, username, password;
bool usessl;
server = this->_server.get_text();
port = this->_port.get_text();
username = this->_username.get_text();
password = this->_password.get_text();
usessl = this->_usessl.get_active();
Glib::ustring msg = String::ucompose(_("Establishing connection to Jabber server <b>%1</b> as user <b>%2</b>"), server, username);
this->_desktop->messageStack()->flash(INFORMATION_MESSAGE, msg.data());
if (!this->_register.get_active())
{
switch (this->_sm->connectToServer(server, port, username, password, usessl)) {
case FAILED_TO_CONNECT:
msg = String::ucompose(_("Failed to establish connection to Jabber server <b>%1</b>"), server);
this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
this->_sm->connectionError(msg);
break;
case INVALID_AUTH:
msg = String::ucompose(_("Authentication failed on Jabber server <b>%1</b> as <b>%2</b>"), server, username);
this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
this->_sm->connectionError(msg);
break;
case SSL_INITIALIZATION_ERROR:
msg = String::ucompose(_("SSL initialization failed when connecting to Jabber server <b>%1</b>"), server);
this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
this->_sm->connectionError(msg);
break;
case CONNECT_SUCCESS:
msg = String::ucompose(_("Connected to Jabber server <b>%1</b> as <b>%2</b>"), server, username);
this->_desktop->messageStack()->flash(INFORMATION_MESSAGE, msg.data());
// Save preferences
prefs_set_string_attribute(this->_prefs_path, "server", this->_server.get_text().c_str());
break;
default:
break;
}
}else{
std::vector<Glib::ustring> key,val;
for(unsigned i = 0; i<registerlabels.size();i++)
{
key.push_back((*registerlabels[i]).get_text());
val.push_back((*registerentries[i]).get_text());
}
switch (this->_sm->registerWithServer(username, password, key, val))
{
case FAILED_TO_CONNECT:
msg = String::ucompose(_("Failed to establish connection to Jabber server <b>%1</b>"), server);
this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
this->_sm->connectionError(msg);
break;
case INVALID_AUTH:
msg = String::ucompose(_("Registration failed on Jabber server <b>%1</b> as <b>%2</b>"), server, username);
this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
this->_sm->connectionError(msg);
break;
case SSL_INITIALIZATION_ERROR:
msg = String::ucompose(_("SSL initialization failed when connecting to Jabber server <b>%1</b>"), server);
this->_desktop->messageStack()->flash(WARNING_MESSAGE, msg.data());
this->_sm->connectionError(msg);
break;
case CONNECT_SUCCESS:
msg = String::ucompose(_("Connected to Jabber server <b>%1</b> as <b>%2</b>"), server, username);
this->_desktop->messageStack()->flash(INFORMATION_MESSAGE, msg.data());
// Save preferences
prefs_set_string_attribute(this->_prefs_path, "server", this->_server.get_text().c_str());
break;
default:
break;
}
}
}
this->_password.set_text("");
this->hide();
}
void
WhiteboardConnectDialogImpl::_useSSLClickedCallback()
{
if (this->_usessl.get_active()) {
this->_port.set_text("5223");
// String::ucompose seems to format numbers according to locale; unfortunately,
// I'm not yet sure how to turn that off
//this->_port.set_text(String::ucompose("%1", LM_CONNECTION_DEFAULT_PORT_SSL));
} else {
this->_port.set_text("5222");
}
}
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
|