Location | Tool | Test ID | Function | Issue |
---|---|---|---|---|
nautilus-connect-server-dialog.c:289:66 | clang-analyzer | Access to field 'message' results in a dereference of a null pointer (loaded from variable 'error') |
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /*
3 * Nautilus
4 *
5 * Copyright (C) 2003 Red Hat, Inc.
6 * Copyright (C) 2010 Cosimo Cecchi <cosimoc@gnome.org>
7 *
8 * Nautilus is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * Nautilus is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; see the file COPYING. If not,
20 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 */
23
24 #include <config.h>
25
26 #include "nautilus-connect-server-dialog.h"
27
28 #include <string.h>
29 #include <eel/eel-stock-dialogs.h>
30 #include <eel/eel-gtk-extensions.h>
31 #include <glib/gi18n.h>
32 #include <gio/gio.h>
33 #include <gtk/gtk.h>
34
35 #include "nautilus-window.h"
36
37 struct _NautilusConnectServerDialogDetails {
38 GtkTreeView *view;
39 GtkListStore *store;
40 GtkWidget *primary_grid;
41
42 GtkWidget *uri_entry;
43 GtkWidget *error_label;
44
45 GtkWidget *menu;
46 GtkWidget *remove_menu_item;
47 GtkWidget *clear_menu_item;
48 GtkWidget *browse_button;
49
50 char **supported;
51 };
52
53 enum {
54 COLUMN_NAME,
55 COLUMN_URI,
56 NUM_COLUMNS
57 };
58
59
60 G_DEFINE_TYPE (NautilusConnectServerDialog, nautilus_connect_server_dialog,
61 GTK_TYPE_DIALOG)
62
63 void
64 nautilus_connect_server_dialog_set_show_browse (NautilusConnectServerDialog *dialog,
65 gboolean show)
66 {
67 gtk_widget_set_visible (dialog->details->browse_button, show);
68 }
69
70 GFile *
71 nautilus_connect_server_dialog_get_location (NautilusConnectServerDialog *dialog)
72 {
73 const char *uri;
74 GFile *file = NULL;
75
76 uri = gtk_entry_get_text (GTK_ENTRY (dialog->details->uri_entry));
77 if (uri != NULL && uri[0] != '\0') {
78 file = g_file_new_for_commandline_arg (uri);
79 }
80
81 return file;
82 }
83
84 static void
85 nautilus_connect_server_dialog_response (GtkDialog *dialog,
86 int response_id,
87 gpointer data)
88 {
89 GError *error;
90 NautilusConnectServerDialog *cs_dialog = NAUTILUS_CONNECT_SERVER_DIALOG (dialog);
91
92 switch (response_id) {
93 case GTK_RESPONSE_ACCEPT:
94 g_signal_stop_emission_by_name (dialog, "response");
95 gtk_entry_set_text (GTK_ENTRY (cs_dialog->details->uri_entry), "network:///");
96 gtk_dialog_response (dialog, GTK_RESPONSE_OK);
97 break;
98 case GTK_RESPONSE_HELP:
99 error = NULL;
100 gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (dialog)),
101 "help:gnome-help/nautilus-connect",
102 gtk_get_current_event_time (), &error);
103 if (error) {
104 eel_show_error_dialog (_("There was an error displaying help."), error->message,
105 GTK_WINDOW (dialog));
106 g_error_free (error);
107 }
108 g_signal_stop_emission_by_name (dialog, "response");
109 break;
110 default :
111 break;
112 }
113 }
114
115 static gboolean
116 is_scheme_supported (NautilusConnectServerDialog *dialog,
117 const char *scheme)
118 {
119 int i;
120
121 if (dialog->details->supported == NULL) {
122 return FALSE;
123 }
124
125 for (i = 0; dialog->details->supported[i] != NULL; i++) {
126 if (strcmp (scheme, dialog->details->supported[i]) == 0) {
127 return TRUE;
128 }
129 }
130
131 return FALSE;
132 }
133
134 static gboolean
135 validate_uri (NautilusConnectServerDialog *dialog,
136 const char *uri,
137 GError **error)
138 {
139 gboolean valid = FALSE;
140 char *scheme;
141
142 scheme = g_uri_parse_scheme (uri);
143 if (scheme != NULL) {
144 valid = is_scheme_supported (dialog, scheme);
145 if (! valid) {
146 g_set_error_literal (error,
147 G_IO_ERROR,
148 G_IO_ERROR_NOT_SUPPORTED,
149 _("Don't recognize this file server type."));
150 }
151 g_free (scheme);
152 } else {
153 g_set_error_literal (error,
154 G_IO_ERROR,
155 G_IO_ERROR_INVALID_ARGUMENT,
156 _("This doesn't look like an address."));
157
158 }
159
160 return valid;
161 }
162
163 static void
164 on_uri_entry_clear (GtkEntry *entry,
165 NautilusConnectServerDialog *dialog)
166 {
167 gtk_entry_set_text (entry, "");
168 }
169
170 static const char *
171 get_default_schema (NautilusConnectServerDialog *dialog)
172 {
173 if (dialog->details->supported == NULL) {
174 return NULL;
175 }
176
177 return dialog->details->supported[0];
178 }
179
180 static int
181 get_index (const char **names,
182 const char *needle)
183 {
184 int i;
185 int index = G_MAXINT;
186 for (i = 0; names[i] != NULL; i++) {
187 if (strcmp (needle, names[i]) == 0) {
188 index = i;
189 break;
190 }
191 }
192
193 return index;
194 }
195
196 static int
197 sort_supported (gconstpointer a,
198 gconstpointer b,
199 gpointer user_data)
200 {
201 const char **preferred = user_data;
202 const char *s_a = *((char **)a);
203 const char *s_b = *((char **)b);
204 int i_a;
205 int i_b;
206
207 i_a = get_index (preferred, s_a);
208 i_b = get_index (preferred, s_b);
209
210 if (i_b == i_a) {
211 return 0;
212 } else if (i_a > i_b) {
213 return 1;
214 } else {
215 return -1;
216 }
217 }
218
219 static void
220 populate_supported_list (NautilusConnectServerDialog *dialog)
221 {
222 const char * const *supported;
223 GPtrArray *good;
224 int i;
225 int j;
226 const char * unsupported[] = { "file", "afc", "obex", "http", "trash", "burn", "computer", "archive", "recent", "localtest", NULL };
227 const char * preferred[] = { "smb", "afp", "sftp", "ssh", "davs", "dav", "ftp", NULL };
228
229 supported = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
230 if (supported == NULL) {
231 return;
232 }
233
234 good = g_ptr_array_new ();
235 for (i = 0; supported[i] != NULL; i++) {
236 gboolean support = TRUE;
237 for (j = 0; unsupported[j] != NULL; j++) {
238 if (strcmp (supported[i], unsupported[j]) == 0) {
239 support = FALSE;
240 break;
241 }
242 }
243 if (support) {
244 g_ptr_array_add (good, g_strdup (supported[i]));
245 }
246 }
247 g_ptr_array_sort_with_data (good, sort_supported, preferred);
248
249 g_ptr_array_add (good, NULL);
250
251 dialog->details->supported = (char **)g_ptr_array_free (good, FALSE);
252 }
253
254 static void
255 reset_example_label (NautilusConnectServerDialog *dialog)
256 {
257 char *text;
258 char *uri;
259 const char *schema;
260
261 schema = get_default_schema (dialog);
262 if (schema != NULL) {
263 uri = g_strdup_printf ("%s://foo.example.org", schema);
264 /* Translators: %s is a URI of the form "smb://foo.example.com" */
265 text = g_strdup_printf (_("For example, %s"), uri);
266 g_free (uri);
267 } else {
268 text = g_strdup ("");
269 }
270 gtk_label_set_text (GTK_LABEL (dialog->details->error_label), text);
271 g_free (text);
272 }
273
274 static void
275 check_uri_entry (NautilusConnectServerDialog *dialog)
276 {
277 guint length;
278 gboolean button_active = FALSE;
279 gboolean icon_active = FALSE;
280 const char *text = NULL;
281
282 length = gtk_entry_get_text_length (GTK_ENTRY (dialog->details->uri_entry));
283 if (length > 0) {
284 GError *error = NULL;
285
286 text = gtk_entry_get_text (GTK_ENTRY (dialog->details->uri_entry));
287 button_active = validate_uri (dialog, text, &error);
288 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) {
289 gtk_label_set_text (GTK_LABEL (dialog->details->error_label), error->message);
(emitted by clang-analyzer)TODO: a detailed trace is available in the data model (not yet rendered in this report)
290 } else {
291 reset_example_label (dialog);
292 }
293 g_clear_error (&error);
294 icon_active = TRUE;
295 }
296
297 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, button_active);
298
299 g_object_set (dialog->details->uri_entry,
300 "secondary-icon-name", icon_active ? "edit-clear-symbolic" : NULL,
301 "secondary-icon-activatable", icon_active,
302 "secondary-icon-sensitive", icon_active,
303 NULL);
304 }
305
306 static void
307 on_uri_entry_changed (GtkEditable *editable,
308 NautilusConnectServerDialog *dialog)
309 {
310 GtkTreeSelection *selection;
311
312 /* if the uri is changed at all it isn't the selected on anymore */
313 selection = gtk_tree_view_get_selection (dialog->details->view);
314 gtk_tree_selection_unselect_all (selection);
315
316 check_uri_entry (dialog);
317 }
318
319 static char *
320 get_selected (NautilusConnectServerDialog *dialog,
321 GtkTreeIter *iter_out)
322 {
323 GtkTreeSelection *selection;
324 GtkTreeIter iter;
325 char *uri = NULL;
326
327 selection = gtk_tree_view_get_selection (dialog->details->view);
328 if (gtk_tree_selection_get_selected (selection, NULL, &iter)) {
329 gtk_tree_model_get (GTK_TREE_MODEL (dialog->details->store),
330 &iter,
331 COLUMN_URI, &uri,
332 -1);
333 if (iter_out) {
334 *iter_out = iter;
335 }
336 }
337
338 return uri;
339 }
340
341 static void
342 on_selection_changed (GtkTreeSelection *selection,
343 NautilusConnectServerDialog *dialog)
344 {
345 char *uri;
346
347 uri = get_selected (dialog, NULL);
348 if (uri != NULL) {
349 g_signal_handlers_block_by_func (dialog->details->uri_entry, on_uri_entry_changed, dialog);
350 gtk_entry_set_text (GTK_ENTRY (dialog->details->uri_entry), uri);
351 g_signal_handlers_unblock_by_func (dialog->details->uri_entry, on_uri_entry_changed, dialog);
352 check_uri_entry (dialog);
353 g_free (uri);
354 gtk_widget_set_sensitive (dialog->details->remove_menu_item, TRUE);
355 } else {
356 gtk_widget_set_sensitive (dialog->details->remove_menu_item, FALSE);
357 }
358 }
359
360 static GBookmarkFile *
361 server_list_load (NautilusConnectServerDialog *dialog)
362 {
363 GBookmarkFile *bookmarks;
364 GError *error = NULL;
365 char *datadir;
366 char *filename;
367
368 bookmarks = g_bookmark_file_new ();
369 datadir = g_build_filename (g_get_user_config_dir (), "nautilus", NULL);
370 filename = g_build_filename (datadir, "servers", NULL);
371 g_mkdir_with_parents (datadir, 0700);
372 g_free (datadir);
373 g_bookmark_file_load_from_file (bookmarks,
374 filename,
375 &error);
376 g_free (filename);
377 if (error != NULL) {
378 if (! g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
379 /* only warn if the file exists */
380 g_warning ("Unable to open server bookmarks: %s", error->message);
381 }
382 g_error_free (error);
383 g_bookmark_file_free (bookmarks);
384 bookmarks = NULL;
385 }
386
387 return bookmarks;
388 }
389
390 static void
391 server_list_save (NautilusConnectServerDialog *dialog,
392 GBookmarkFile *bookmarks)
393 {
394 char *filename;
395
396 filename = g_build_filename (g_get_user_config_dir (), "nautilus", "servers", NULL);
397 g_bookmark_file_to_file (bookmarks, filename, NULL);
398 }
399
400 static void
401 populate_server_list (NautilusConnectServerDialog *dialog)
402 {
403 GBookmarkFile *bookmarks;
404 GtkTreeIter iter;
405 char **uris;
406 int i;
407
408 bookmarks = server_list_load (dialog);
409 if (bookmarks == NULL) {
410 return;
411 }
412 uris = g_bookmark_file_get_uris (bookmarks, NULL);
413 if (uris != NULL) {
414 for (i = 0; uris[i] != NULL; i++) {
415 char *name;
416
417 name = g_bookmark_file_get_title (bookmarks, uris[i], NULL);
418 gtk_list_store_append (dialog->details->store, &iter);
419 gtk_list_store_set (dialog->details->store, &iter,
420 COLUMN_URI, uris[i],
421 COLUMN_NAME, name,
422 -1);
423 g_free (name);
424 }
425 g_strfreev (uris);
426 gtk_widget_set_sensitive (dialog->details->clear_menu_item, TRUE);
427 } else {
428 gtk_widget_set_sensitive (dialog->details->clear_menu_item, FALSE);
429 }
430
431 g_bookmark_file_free (bookmarks);
432 }
433
434 static void
435 server_list_remove (NautilusConnectServerDialog *dialog,
436 const char *uri)
437 {
438 GBookmarkFile *bookmarks;
439
440 bookmarks = server_list_load (dialog);
441 if (bookmarks == NULL) {
442 return;
443 }
444
445 g_bookmark_file_remove_item (bookmarks, uri, NULL);
446 server_list_save (dialog, bookmarks);
447 g_bookmark_file_free (bookmarks);
448 }
449
450 static void
451 server_list_remove_all (NautilusConnectServerDialog *dialog)
452 {
453 GBookmarkFile *bookmarks;
454
455 bookmarks = g_bookmark_file_new ();
456 if (bookmarks == NULL) {
457 return;
458 }
459 server_list_save (dialog, bookmarks);
460 g_bookmark_file_free (bookmarks);
461 }
462
463 static void
464 boldify_label (GtkLabel *label)
465 {
466 PangoAttrList *attrs;
467 attrs = pango_attr_list_new ();
468 pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
469 gtk_label_set_attributes (label, attrs);
470 pango_attr_list_unref (attrs);
471 }
472
473 static void
474 on_clear_item_activated (GtkMenuItem *item,
475 NautilusConnectServerDialog *dialog)
476 {
477 server_list_remove_all (dialog);
478 gtk_list_store_clear (dialog->details->store);
479 gtk_widget_set_sensitive (dialog->details->clear_menu_item, FALSE);
480 }
481
482 static void
483 on_remove_item_activated (GtkMenuItem *item,
484 NautilusConnectServerDialog *dialog)
485 {
486 char *uri;
487 GtkTreeIter iter;
488
489 uri = get_selected (dialog, &iter);
490 if (uri != NULL) {
491 server_list_remove (dialog, uri);
492 gtk_list_store_remove (dialog->details->store, &iter);
493 g_free (uri);
494 }
495 }
496
497 static void
498 on_row_activated (GtkTreeView *tree_view,
499 GtkTreePath *path,
500 GtkTreeViewColumn *column,
501 NautilusConnectServerDialog *dialog)
502 {
503 gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
504 }
505
506 static void
507 on_popup_menu_detach (GtkWidget *attach_widget,
508 GtkMenu *menu)
509 {
510 NautilusConnectServerDialog *dialog = NAUTILUS_CONNECT_SERVER_DIALOG (attach_widget);
511
512 dialog->details->menu = NULL;
513 dialog->details->remove_menu_item = NULL;
514 dialog->details->clear_menu_item = NULL;
515 }
516
517 static void
518 create_popup_menu (NautilusConnectServerDialog *dialog)
519 {
520 GtkWidget *menu;
521 GtkWidget *item;
522
523 if (dialog->details->menu != NULL) {
524 return;
525 }
526
527 menu = gtk_menu_new ();
528 dialog->details->menu = menu;
529 gtk_menu_attach_to_widget (GTK_MENU (menu),
530 GTK_WIDGET (dialog),
531 on_popup_menu_detach);
532
533 item = gtk_menu_item_new_with_mnemonic (_("_Remove"));
534 dialog->details->remove_menu_item = item;
535 g_signal_connect (item, "activate",
536 G_CALLBACK (on_remove_item_activated), dialog);
537 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
538 gtk_widget_show (item);
539
540 eel_gtk_menu_append_separator (GTK_MENU (menu));
541
542 item = gtk_menu_item_new_with_mnemonic (_("_Clear All"));
543 dialog->details->clear_menu_item = item;
544 g_signal_connect (item, "activate",
545 G_CALLBACK (on_clear_item_activated), dialog);
546 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
547 gtk_widget_show (item);
548 }
549
550 static void
551 history_popup_menu (NautilusConnectServerDialog *dialog)
552 {
553 create_popup_menu (dialog);
554 eel_pop_up_context_menu (GTK_MENU (dialog->details->menu), NULL);
555 }
556
557 static gboolean
558 on_popup_menu (GtkWidget *widget,
559 NautilusConnectServerDialog *dialog)
560 {
561 history_popup_menu (dialog);
562 return TRUE;
563 }
564
565 static void
566 nautilus_connect_server_dialog_init (NautilusConnectServerDialog *dialog)
567 {
568 GtkWidget *label;
569 GtkWidget *button;
570 GtkWidget *sw;
571 GtkWidget *view;
572 GtkWidget *box;
573 GtkWidget *content_area;
574 GtkWidget *grid;
575 int row;
576 GtkCellRenderer *cell;
577 GtkTreeSelection *selection;
578 GtkListStore *store;
579
580 dialog->details = G_TYPE_INSTANCE_GET_PRIVATE (dialog, NAUTILUS_TYPE_CONNECT_SERVER_DIALOG,
581 NautilusConnectServerDialogDetails);
582
583 populate_supported_list (dialog);
584
585 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
586
587 /* set dialog properties */
588 gtk_window_set_title (GTK_WINDOW (dialog), _("Connect to Server"));
589 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
590
591 grid = gtk_grid_new ();
592 gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
593 gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
594 gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
595 gtk_widget_set_margin_bottom (grid, 12);
596 gtk_container_set_border_width (GTK_CONTAINER (grid), 5);
597 gtk_container_add (GTK_CONTAINER (content_area), grid);
598 gtk_widget_show (grid);
599
600 dialog->details->primary_grid = grid;
601
602 row = 0;
603
604 label = gtk_label_new_with_mnemonic (_("_Server Address"));
605 boldify_label (GTK_LABEL (label));
606 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
607 gtk_grid_attach (GTK_GRID (grid), label, 0, row++, 1, 1);
608 gtk_widget_show (label);
609
610 dialog->details->uri_entry = gtk_entry_new ();
611
612 gtk_widget_set_hexpand (dialog->details->uri_entry, TRUE);
613 gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->uri_entry), TRUE);
614 gtk_grid_attach (GTK_GRID (grid), dialog->details->uri_entry, 0, row++, 1, 1);
615
616 gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->details->uri_entry);
617 gtk_widget_show (dialog->details->uri_entry);
618
619 label = gtk_label_new (NULL);
620 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
621 gtk_grid_attach (GTK_GRID (grid), label, 0, row++, 1, 1);
622 gtk_widget_show (label);
623 dialog->details->error_label = label;
624 reset_example_label (dialog);
625 gtk_widget_set_margin_bottom (label, 12);
626 gtk_style_context_add_class (gtk_widget_get_style_context (label), "dim-label");
627
628 label = gtk_label_new_with_mnemonic (_("_Recent Servers"));
629 boldify_label (GTK_LABEL (label));
630 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
631 gtk_grid_attach (GTK_GRID (grid), label, 0, row++, 1, 1);
632 gtk_widget_show (label);
633
634 box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
635 gtk_widget_set_hexpand (box, TRUE);
636 gtk_widget_set_vexpand (box, TRUE);
637 gtk_grid_attach (GTK_GRID (grid), box, 0, row++, 1, 1);
638 gtk_widget_show (box);
639
640 sw = gtk_scrolled_window_new (NULL, NULL);
641 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
642 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
643 GTK_POLICY_NEVER,
644 GTK_POLICY_AUTOMATIC);
645 gtk_widget_set_size_request (sw, 400, 150);
646 gtk_widget_show (sw);
647 gtk_widget_set_hexpand (sw, TRUE);
648 gtk_widget_set_vexpand (sw, TRUE);
649 gtk_container_add (GTK_CONTAINER (box), sw);
650
651 view = gtk_tree_view_new ();
652 gtk_widget_show (view);
653 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
654 gtk_container_add (GTK_CONTAINER (sw), view);
655
656 g_signal_connect (view, "row-activated",
657 G_CALLBACK (on_row_activated),
658 dialog);
659 g_signal_connect (view, "popup-menu",
660 G_CALLBACK (on_popup_menu),
661 dialog);
662
663 store = gtk_list_store_new (NUM_COLUMNS,
664 G_TYPE_STRING,
665 G_TYPE_STRING);
666
667 gtk_tree_view_set_model (GTK_TREE_VIEW (view),
668 GTK_TREE_MODEL (store));
669 g_object_unref (store);
670
671 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
672 g_signal_connect (selection, "changed",
673 G_CALLBACK (on_selection_changed),
674 dialog);
675
676 cell = gtk_cell_renderer_text_new ();
677 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
678 -1,
679 NULL,
680 cell,
681 "text", COLUMN_NAME,
682 NULL);
683 cell = gtk_cell_renderer_text_new ();
684 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
685 -1,
686 NULL,
687 cell,
688 "text", COLUMN_URI,
689 NULL);
690 dialog->details->view = GTK_TREE_VIEW (view);
691 dialog->details->store = store;
692
693 button = gtk_dialog_add_button (GTK_DIALOG (dialog),
694 _("_Browse"),
695 GTK_RESPONSE_ACCEPT);
696 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))),
697 button, TRUE);
698 dialog->details->browse_button = button;
699
700 gtk_dialog_add_button (GTK_DIALOG (dialog),
701 GTK_STOCK_CANCEL,
702 GTK_RESPONSE_CANCEL);
703 gtk_dialog_add_button (GTK_DIALOG (dialog),
704 _("C_onnect"),
705 GTK_RESPONSE_OK);
706 gtk_dialog_set_default_response (GTK_DIALOG (dialog),
707 GTK_RESPONSE_OK);
708 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
709 GTK_RESPONSE_OK,
710 FALSE);
711
712 g_signal_connect (dialog->details->uri_entry, "changed",
713 G_CALLBACK (on_uri_entry_changed),
714 dialog);
715 g_signal_connect (dialog->details->uri_entry, "icon-release",
716 G_CALLBACK (on_uri_entry_clear),
717 dialog);
718
719 g_signal_connect (dialog, "response",
720 G_CALLBACK (nautilus_connect_server_dialog_response),
721 NULL);
722
723 create_popup_menu (dialog);
724 populate_server_list (dialog);
725 }
726
727 static void
728 nautilus_connect_server_dialog_finalize (GObject *object)
729 {
730 NautilusConnectServerDialog *dialog;
731
732 dialog = NAUTILUS_CONNECT_SERVER_DIALOG (object);
733
734 g_strfreev (dialog->details->supported);
735
736 G_OBJECT_CLASS (nautilus_connect_server_dialog_parent_class)->finalize (object);
737 }
738
739 static void
740 nautilus_connect_server_dialog_class_init (NautilusConnectServerDialogClass *class)
741 {
742 GObjectClass *oclass;
743
744 oclass = G_OBJECT_CLASS (class);
745 oclass->finalize = nautilus_connect_server_dialog_finalize;
746
747 g_type_class_add_private (class, sizeof (NautilusConnectServerDialogDetails));
748 }
749
750 GtkWidget *
751 nautilus_connect_server_dialog_new (NautilusWindow *window)
752 {
753 GtkWidget *dialog;
754
755 dialog = gtk_widget_new (NAUTILUS_TYPE_CONNECT_SERVER_DIALOG, NULL);
756
757 if (window) {
758 gtk_window_set_screen (GTK_WINDOW (dialog),
759 gtk_window_get_screen (GTK_WINDOW (window)));
760 }
761
762 return dialog;
763 }