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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
|
/*
* Copyright (C) 2006-2007 Imendio AB
* Copyright (C) 2007-2011 Collabora Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authors: Martyn Russell <martyn@imendio.com>
* Xavier Claessens <xclaesse@gmail.com>
*/
#include <config.h>
#include <string.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <glib/gprintf.h>
#include <telepathy-glib/telepathy-glib.h>
#include <libempathy/empathy-chatroom.h>
#include <libempathy/empathy-utils.h>
#include <libempathy/empathy-request-util.h>
#include <libempathy/empathy-gsettings.h>
#include <libempathy-gtk/empathy-account-chooser.h>
#include <libempathy-gtk/empathy-ui-utils.h>
#include "empathy-new-chatroom-dialog.h"
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
#include <libempathy/empathy-debug.h>
G_DEFINE_TYPE (EmpathyNewChatroomDialog, empathy_new_chatroom_dialog,
GTK_TYPE_DIALOG)
struct _EmpathyNewChatroomDialogPriv
{
TpRoomList *room_list;
/* Currently selected account */
TpAccount *account;
/* Signal id of the "status-changed" signal connected on the currently
* selected account */
gulong status_changed_id;
GtkWidget *table_grid;
GtkWidget *label_account;
GtkWidget *account_chooser;
GtkWidget *label_server;
GtkWidget *entry_server;
GtkWidget *label_room;
GtkWidget *entry_room;
GtkWidget *expander_browse;
GtkWidget *hbox_expander;
GtkWidget *throbber;
GtkWidget *treeview;
GtkTreeModel *model;
GtkWidget *button_join;
GtkWidget *label_error_message;
GtkWidget *viewport_error;
GSettings *gsettings;
};
enum
{
COL_NEED_PASSWORD,
COL_INVITE_ONLY,
COL_NAME,
COL_ROOM,
COL_MEMBERS,
COL_MEMBERS_INT,
COL_TOOLTIP,
COL_COUNT
};
static EmpathyNewChatroomDialog *dialog_p = NULL;
static void
new_chatroom_dialog_store_last_account (GSettings *gsettings,
EmpathyAccountChooser *account_chooser)
{
TpAccount *account;
const char *account_path;
account = empathy_account_chooser_get_account (account_chooser);
if (account == NULL)
return;
account_path = tp_proxy_get_object_path (account);
DEBUG ("Storing account path '%s'", account_path);
g_settings_set (gsettings, EMPATHY_PREFS_CHAT_ROOM_LAST_ACCOUNT,
"o", account_path);
}
static void
new_chatroom_dialog_join (EmpathyNewChatroomDialog *self)
{
EmpathyAccountChooser *account_chooser;
TpAccount *account;
const gchar *room;
const gchar *server = NULL;
gchar *room_name = NULL;
room = gtk_entry_get_text (GTK_ENTRY (self->priv->entry_room));
server = gtk_entry_get_text (GTK_ENTRY (self->priv->entry_server));
account_chooser = EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser);
account = empathy_account_chooser_get_account (account_chooser);
if (!EMP_STR_EMPTY (server))
room_name = g_strconcat (room, "@", server, NULL);
else
room_name = g_strdup (room);
g_strstrip (room_name);
DEBUG ("Requesting channel for '%s'", room_name);
empathy_join_muc (account, room_name, empathy_get_current_action_time ());
g_free (room_name);
}
static void
empathy_new_chatroom_dialog_response (GtkDialog *dialog,
gint response)
{
EmpathyNewChatroomDialog *self = EMPATHY_NEW_CHATROOM_DIALOG (dialog);
if (response == GTK_RESPONSE_OK)
{
new_chatroom_dialog_join (self);
new_chatroom_dialog_store_last_account (self->priv->gsettings,
EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser));
}
gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
new_chatroom_dialog_model_add_columns (EmpathyNewChatroomDialog *self)
{
GtkTreeView *view;
GtkTreeViewColumn *column;
GtkCellRenderer *cell;
gint width, height;
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
view = GTK_TREE_VIEW (self->priv->treeview);
cell = gtk_cell_renderer_pixbuf_new ();
g_object_set (cell,
"width", width,
"height", height,
"stock-size", GTK_ICON_SIZE_MENU,
NULL);
column = gtk_tree_view_column_new_with_attributes (NULL, cell,
"stock-id", COL_INVITE_ONLY, NULL);
gtk_tree_view_column_set_sort_column_id (column, COL_INVITE_ONLY);
gtk_tree_view_append_column (view, column);
column = gtk_tree_view_column_new_with_attributes (NULL, cell,
"stock-id", COL_NEED_PASSWORD, NULL);
gtk_tree_view_column_set_sort_column_id (column, COL_NEED_PASSWORD);
gtk_tree_view_append_column (view, column);
cell = gtk_cell_renderer_text_new ();
g_object_set (cell,
"xpad", (guint) 4,
"ypad", (guint) 2,
"ellipsize", PANGO_ELLIPSIZE_END,
NULL);
column = gtk_tree_view_column_new_with_attributes (_("Chat Room"), cell,
"text", COL_NAME, NULL);
gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
gtk_tree_view_column_set_expand (column, TRUE);
gtk_tree_view_append_column (view, column);
cell = gtk_cell_renderer_text_new ();
g_object_set (cell,
"xpad", (guint) 4,
"ypad", (guint) 2,
"ellipsize", PANGO_ELLIPSIZE_END,
"alignment", PANGO_ALIGN_RIGHT,
NULL);
column = gtk_tree_view_column_new_with_attributes (_("Members"), cell,
"text", COL_MEMBERS, NULL);
gtk_tree_view_column_set_sort_column_id (column, COL_MEMBERS_INT);
gtk_tree_view_append_column (view, column);
}
static void
new_chatroom_dialog_model_row_activated_cb (GtkTreeView *tree_view,
GtkTreePath *path,
GtkTreeViewColumn *column,
EmpathyNewChatroomDialog *self)
{
gtk_widget_activate (self->priv->button_join);
}
static void
new_chatroom_dialog_model_selection_changed (GtkTreeSelection *selection,
EmpathyNewChatroomDialog *self)
{
GtkTreeModel *model;
GtkTreeIter iter;
gchar *room = NULL;
gchar *server = NULL;
if (!gtk_tree_selection_get_selected (selection, &model, &iter))
return;
gtk_tree_model_get (model, &iter, COL_ROOM, &room, -1);
server = strstr (room, "@");
if (server)
{
*server = '\0';
server++;
}
gtk_entry_set_text (GTK_ENTRY (self->priv->entry_server),
server ? server : "");
gtk_entry_set_text (GTK_ENTRY (self->priv->entry_room), room ? room : "");
g_free (room);
}
static void
new_chatroom_dialog_model_setup (EmpathyNewChatroomDialog *self)
{
GtkTreeView *view;
GtkListStore *store;
GtkTreeSelection *selection;
/* View */
view = GTK_TREE_VIEW (self->priv->treeview);
g_signal_connect (view, "row-activated",
G_CALLBACK (new_chatroom_dialog_model_row_activated_cb), self);
/* Store/Model */
store = gtk_list_store_new (COL_COUNT,
G_TYPE_STRING, /* Invite */
G_TYPE_STRING, /* Password */
G_TYPE_STRING, /* Name */
G_TYPE_STRING, /* Room */
G_TYPE_STRING, /* Member count */
G_TYPE_INT, /* Member count int */
G_TYPE_STRING); /* Tool tip */
self->priv->model = GTK_TREE_MODEL (store);
gtk_tree_view_set_model (view, self->priv->model);
gtk_tree_view_set_tooltip_column (view, COL_TOOLTIP);
gtk_tree_view_set_search_column (view, COL_NAME);
/* Selection */
selection = gtk_tree_view_get_selection (view);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
COL_NAME, GTK_SORT_ASCENDING);
g_signal_connect (selection, "changed",
G_CALLBACK (new_chatroom_dialog_model_selection_changed), self);
/* Columns */
new_chatroom_dialog_model_add_columns (self);
}
static void
update_join_button_sensitivity (EmpathyNewChatroomDialog *self)
{
const gchar *room;
const gchar *protocol;
gboolean sensitive = FALSE;
room = gtk_entry_get_text (GTK_ENTRY (self->priv->entry_room));
protocol = tp_account_get_protocol_name (self->priv->account);
if (EMP_STR_EMPTY (room))
goto out;
if (!tp_strdiff (protocol, "irc") &&
(!tp_strdiff (room, "#") || !tp_strdiff (room, "&")))
goto out;
if (self->priv->account == NULL)
goto out;
if (tp_account_get_connection_status (self->priv->account, NULL) !=
TP_CONNECTION_STATUS_CONNECTED)
goto out;
sensitive = TRUE;
out:
gtk_widget_set_sensitive (self->priv->button_join, sensitive);
}
static void
new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *self)
{
const gchar *protocol;
if (self->priv->account == NULL)
return;
protocol = tp_account_get_protocol_name (self->priv->account);
gtk_entry_set_text (GTK_ENTRY (self->priv->entry_server), "");
/* hardcode here known protocols */
if (strcmp (protocol, "jabber") == 0)
gtk_widget_set_sensitive (self->priv->entry_server, TRUE);
else if (strcmp (protocol, "local-xmpp") == 0)
gtk_widget_set_sensitive (self->priv->entry_server, FALSE);
else if (strcmp (protocol, "irc") == 0)
gtk_widget_set_sensitive (self->priv->entry_server, FALSE);
else
gtk_widget_set_sensitive (self->priv->entry_server, TRUE);
if (!tp_strdiff (protocol, "irc"))
gtk_entry_set_text (GTK_ENTRY (self->priv->entry_room), "#");
else
gtk_entry_set_text (GTK_ENTRY (self->priv->entry_room), "");
update_join_button_sensitivity (self);
/* Final set up of the dialog */
gtk_widget_grab_focus (self->priv->entry_room);
gtk_editable_set_position (GTK_EDITABLE (self->priv->entry_room), -1);
}
static void
account_status_changed_cb (TpAccount *account,
guint old_status,
guint new_status,
guint reason,
gchar *dbus_error_name,
GHashTable *details,
EmpathyNewChatroomDialog *self)
{
update_join_button_sensitivity (self);
}
static void
new_chatroom_dialog_select_last_account (GSettings *gsettings,
EmpathyAccountChooser *account_chooser)
{
const gchar *account_path;
TpAccountManager *manager;
TpSimpleClientFactory *factory;
TpAccount *account;
TpConnectionStatus status;
account_path = g_settings_get_string (gsettings,
EMPATHY_PREFS_CHAT_ROOM_LAST_ACCOUNT);
DEBUG ("Selecting account path '%s'", account_path);
manager = tp_account_manager_dup ();
factory = tp_proxy_get_factory (manager);
account = tp_simple_client_factory_ensure_account (factory, account_path,
NULL, NULL);
if (account != NULL)
{
status = tp_account_get_connection_status (account, NULL);
if (status == TP_CONNECTION_STATUS_CONNECTED)
empathy_account_chooser_set_account (account_chooser, account);
g_object_unref (account);
}
g_object_unref (manager);
}
static void
new_chatroom_dialog_account_ready_cb (EmpathyAccountChooser *combobox,
EmpathyNewChatroomDialog *self)
{
new_chatroom_dialog_select_last_account (self->priv->gsettings, combobox);
}
static void
listing_failed_cb (TpRoomList *room_list,
GError *error,
EmpathyNewChatroomDialog *self)
{
gtk_label_set_text (GTK_LABEL (self->priv->label_error_message),
_("Failed to list rooms"));
gtk_widget_show_all (self->priv->viewport_error);
gtk_widget_set_sensitive (self->priv->treeview, FALSE);
}
static void
new_chatroom_dialog_got_room_cb (TpRoomList *room_list,
TpRoomInfo *room,
EmpathyNewChatroomDialog *self)
{
GtkListStore *store;
gchar *members;
gchar *tooltip;
const gchar *need_password;
const gchar *invite_only;
gchar *tmp;
DEBUG ("New room listed: %s (%s)", tp_room_info_get_name (room),
tp_room_info_get_handle_name (room));
/* Add to model */
store = GTK_LIST_STORE (self->priv->model);
members = g_strdup_printf ("%d", tp_room_info_get_members_count (
room, NULL));
tmp = g_strdup_printf ("<b>%s</b>", tp_room_info_get_name (room));
/* Translators: Room/Join's roomlist tooltip. Parameters are a channel name,
yes/no, yes/no and a number. */
tooltip = g_strdup_printf (
_("%s\nInvite required: %s\nPassword required: %s\nMembers: %s"),
tmp,
tp_room_info_get_invite_only (room, NULL) ? _("Yes") : _("No"),
tp_room_info_get_requires_password (room, NULL) ? _("Yes") : _("No"),
members);
g_free (tmp);
invite_only = (tp_room_info_get_invite_only (room, NULL) ?
GTK_STOCK_INDEX : NULL);
need_password = (tp_room_info_get_requires_password (room, NULL) ?
GTK_STOCK_DIALOG_AUTHENTICATION : NULL);
gtk_list_store_insert_with_values (store, NULL, -1,
COL_NEED_PASSWORD, need_password,
COL_INVITE_ONLY, invite_only,
COL_NAME, tp_room_info_get_name (room),
COL_ROOM, tp_room_info_get_handle_name (room),
COL_MEMBERS, members,
COL_MEMBERS_INT, tp_room_info_get_members_count (room, NULL),
COL_TOOLTIP, tooltip,
-1);
g_free (members);
g_free (tooltip);
}
static void
new_chatroom_dialog_listing_cb (TpRoomList *room_list,
GParamSpec *spec,
EmpathyNewChatroomDialog *self)
{
/* Update the throbber */
if (tp_room_list_is_listing (room_list))
{
gtk_spinner_start (GTK_SPINNER (self->priv->throbber));
gtk_widget_show (self->priv->throbber);
}
else
{
gtk_spinner_stop (GTK_SPINNER (self->priv->throbber));
gtk_widget_hide (self->priv->throbber);
}
}
static void
new_chatroom_dialog_model_clear (EmpathyNewChatroomDialog *self)
{
GtkListStore *store;
store = GTK_LIST_STORE (self->priv->model);
gtk_list_store_clear (store);
}
static void
new_chatroom_dialog_browse_start (EmpathyNewChatroomDialog *self)
{
new_chatroom_dialog_model_clear (self);
if (self->priv->room_list != NULL)
tp_room_list_start (self->priv->room_list);
}
static void
new_room_list_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
EmpathyNewChatroomDialog *self = user_data;
GError *error = NULL;
self->priv->room_list = tp_room_list_new_finish (result, &error);
if (self->priv->room_list == NULL)
{
DEBUG ("Failed to create TpRoomList: %s\n", error->message);
g_error_free (error);
return;
}
g_signal_connect (self->priv->room_list, "got-room",
G_CALLBACK (new_chatroom_dialog_got_room_cb), self);
g_signal_connect (self->priv->room_list, "failed",
G_CALLBACK (listing_failed_cb), self);
g_signal_connect (self->priv->room_list, "notify::listing",
G_CALLBACK (new_chatroom_dialog_listing_cb), self);
if (gtk_expander_get_expanded (GTK_EXPANDER (self->priv->expander_browse)))
{
gtk_widget_hide (self->priv->viewport_error);
gtk_widget_set_sensitive (self->priv->treeview, TRUE);
new_chatroom_dialog_browse_start (self);
}
if (tp_room_list_is_listing (self->priv->room_list))
{
gtk_spinner_start (GTK_SPINNER (self->priv->throbber));
gtk_widget_show (self->priv->throbber);
}
gtk_widget_set_sensitive (self->priv->expander_browse, TRUE);
new_chatroom_dialog_update_widgets (self);
}
static void
new_chatroom_dialog_account_changed_cb (GtkComboBox *combobox,
EmpathyNewChatroomDialog *self)
{
EmpathyAccountChooser *account_chooser;
TpConnection *connection;
TpCapabilities *caps;
g_clear_object (&self->priv->room_list);
gtk_spinner_stop (GTK_SPINNER (self->priv->throbber));
gtk_widget_hide (self->priv->throbber);
new_chatroom_dialog_model_clear (self);
if (self->priv->account != NULL)
{
g_signal_handler_disconnect (self->priv->account,
self->priv->status_changed_id);
g_object_unref (self->priv->account);
}
account_chooser = EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser);
self->priv->account = empathy_account_chooser_dup_account (account_chooser);
connection = empathy_account_chooser_get_connection (account_chooser);
if (self->priv->account == NULL)
goto out;
self->priv->status_changed_id = g_signal_connect (self->priv->account,
"status-changed", G_CALLBACK (account_status_changed_cb), self);
/* empathy_account_chooser_filter_supports_chatrooms ensures that the
* account has a connection and CAPABILITIES has been prepared. */
g_assert (connection != NULL);
g_assert (tp_proxy_is_prepared (connection,
TP_CONNECTION_FEATURE_CAPABILITIES));
caps = tp_connection_get_capabilities (connection);
if (tp_capabilities_supports_room_list (caps, NULL))
{
/* Roomlist channels are supported */
tp_room_list_new_async (self->priv->account, NULL, new_room_list_cb,
self);
}
gtk_widget_set_sensitive (self->priv->expander_browse, FALSE);
out:
new_chatroom_dialog_update_widgets (self);
}
static void
new_chatroom_dialog_button_close_error_clicked_cb (GtkButton *button,
EmpathyNewChatroomDialog *self)
{
gtk_widget_hide (self->priv->viewport_error);
}
static void
new_chatroom_dialog_entry_changed_cb (GtkWidget *entry,
EmpathyNewChatroomDialog *self)
{
if (entry == self->priv->entry_room)
{
update_join_button_sensitivity (self);
/* FIXME: Select the room in the list */
}
}
static void
new_chatroom_dialog_entry_server_activate_cb (GtkWidget *widget,
EmpathyNewChatroomDialog *self)
{
new_chatroom_dialog_browse_start (self);
}
static void
new_chatroom_dialog_expander_browse_activate_cb (GtkWidget *widget,
EmpathyNewChatroomDialog *self)
{
gboolean expanded;
expanded = gtk_expander_get_expanded (GTK_EXPANDER (widget));
if (expanded)
{
gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
}
else
{
gtk_widget_hide (self->priv->viewport_error);
gtk_widget_set_sensitive (self->priv->treeview, TRUE);
new_chatroom_dialog_browse_start (self);
gtk_window_set_resizable (GTK_WINDOW (self), TRUE);
}
}
static gboolean
new_chatroom_dialog_entry_server_focus_out_cb (GtkWidget *widget,
GdkEventFocus *event,
EmpathyNewChatroomDialog *self)
{
gboolean expanded;
expanded = gtk_expander_get_expanded (
GTK_EXPANDER (self->priv->expander_browse));
if (expanded)
new_chatroom_dialog_browse_start (self);
return FALSE;
}
static GObject *
empathy_new_chatroom_dialog_constructor (GType type,
guint n_props,
GObjectConstructParam *props)
{
GObject *retval;
if (dialog_p)
{
retval = G_OBJECT (dialog_p);
g_object_ref (retval);
}
else
{
retval = G_OBJECT_CLASS (
empathy_new_chatroom_dialog_parent_class)->constructor (type,
n_props, props);
dialog_p = EMPATHY_NEW_CHATROOM_DIALOG (retval);
g_object_add_weak_pointer (retval, (gpointer) &dialog_p);
}
return retval;
}
GtkWidget *
empathy_new_chatroom_dialog_show (GtkWindow *parent)
{
GtkWidget *dialog;
dialog = g_object_new (EMPATHY_TYPE_NEW_CHATROOM_DIALOG, NULL);
if (parent != NULL)
{
gtk_window_set_transient_for (GTK_WINDOW (dialog),
GTK_WINDOW (parent));
}
gtk_window_present (GTK_WINDOW (dialog));
return dialog;
}
static void
empathy_new_chatroom_dialog_dispose (GObject *object)
{
EmpathyNewChatroomDialog *self = EMPATHY_NEW_CHATROOM_DIALOG (object);
void (*chain_up) (GObject *) =
((GObjectClass *) empathy_new_chatroom_dialog_parent_class)->dispose;
g_clear_object (&self->priv->room_list);
g_clear_object (&self->priv->model);
if (self->priv->account != NULL)
{
g_signal_handler_disconnect (self->priv->account,
self->priv->status_changed_id);
g_clear_object (&self->priv->account);
}
g_clear_object (&self->priv->gsettings);
if (chain_up != NULL)
chain_up (object);
}
static void
empathy_new_chatroom_dialog_class_init (EmpathyNewChatroomDialogClass *klass)
{
GObjectClass *oclass = G_OBJECT_CLASS (klass);
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
oclass->constructor = empathy_new_chatroom_dialog_constructor;
oclass->dispose = empathy_new_chatroom_dialog_dispose;
dialog_class->response = empathy_new_chatroom_dialog_response;
g_type_class_add_private (klass, sizeof (EmpathyNewChatroomDialogPriv));
}
static void
empathy_new_chatroom_dialog_init (EmpathyNewChatroomDialog *self)
{
GtkBuilder *gui;
GtkSizeGroup *size_group;
gchar *filename;
GtkWidget *vbox, *content;
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
EMPATHY_TYPE_NEW_CHATROOM_DIALOG, EmpathyNewChatroomDialogPriv);
filename = empathy_file_lookup ("empathy-new-chatroom-dialog.ui", "src");
gui = empathy_builder_get_file (filename,
"vbox_new_chatroom", &vbox,
"table_grid", &self->priv->table_grid,
"label_account", &self->priv->label_account,
"label_server", &self->priv->label_server,
"label_room", &self->priv->label_room,
"entry_server", &self->priv->entry_server,
"entry_room", &self->priv->entry_room,
"treeview", &self->priv->treeview,
"expander_browse", &self->priv->expander_browse,
"hbox_expander", &self->priv->hbox_expander,
"label_error_message", &self->priv->label_error_message,
"viewport_error", &self->priv->viewport_error,
NULL);
g_free (filename);
empathy_builder_connect (gui, self,
"entry_server", "changed", new_chatroom_dialog_entry_changed_cb,
"entry_server", "activate", new_chatroom_dialog_entry_server_activate_cb,
"entry_server", "focus-out-event",
new_chatroom_dialog_entry_server_focus_out_cb,
"entry_room", "changed", new_chatroom_dialog_entry_changed_cb,
"expander_browse", "activate",
new_chatroom_dialog_expander_browse_activate_cb,
"button_close_error", "clicked",
new_chatroom_dialog_button_close_error_clicked_cb,
NULL);
/* Create dialog */
content = gtk_dialog_get_content_area (GTK_DIALOG (self));
gtk_container_add (GTK_CONTAINER (content), vbox);
gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL);
self->priv->button_join = gtk_dialog_add_button (GTK_DIALOG (self),
_("Join"), GTK_RESPONSE_OK);
gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
gtk_window_set_title (GTK_WINDOW (self), _("Join Room"));
gtk_window_set_role (GTK_WINDOW (self), "join_new_chatroom");
g_object_unref (gui);
/* Label alignment */
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (size_group, self->priv->label_account);
gtk_size_group_add_widget (size_group, self->priv->label_server);
gtk_size_group_add_widget (size_group, self->priv->label_room);
g_object_unref (size_group);
/* Set up chatrooms treeview */
new_chatroom_dialog_model_setup (self);
/* Add throbber */
self->priv->throbber = gtk_spinner_new ();
gtk_box_pack_start (GTK_BOX (self->priv->hbox_expander), self->priv->throbber,
TRUE, TRUE, 0);
self->priv->gsettings = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
/* Account chooser for custom */
self->priv->account_chooser = empathy_account_chooser_new ();
empathy_account_chooser_set_filter (
EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser),
empathy_account_chooser_filter_supports_chatrooms, NULL);
gtk_grid_attach (GTK_GRID (self->priv->table_grid),
self->priv->account_chooser, 1, 0, 1, 1);
gtk_widget_show (self->priv->account_chooser);
g_signal_connect (EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser),
"ready", G_CALLBACK (new_chatroom_dialog_account_ready_cb), self);
g_signal_connect (GTK_COMBO_BOX (self->priv->account_chooser), "changed",
G_CALLBACK (new_chatroom_dialog_account_changed_cb), self);
new_chatroom_dialog_account_changed_cb (
GTK_COMBO_BOX (self->priv->account_chooser), self);
}
|