~ubuntu-branches/debian/lenny/network-manager/lenny

« back to all changes in this revision

Viewing changes to gnome/vpn-properties/nm-vpn-properties.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2008-07-05 15:11:33 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080705151133-rnwi7uuhda2iulug
Tags: 0.6.6-2
* debian/control
  - Add Build-Depends on pkg-config.
  - Drop obsolete Depends on iputils-arping. (Closes: #487794)
* debian/patches/09-nm_dbus_get_ap_from_object_path-mem_leak_fix.patch 
  - Fix memory leak in src/nm-dbus-net.c. (Closes: #488604)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
 * CVSID: $Id: nm-vpn-properties.c,v 1.13.2.11 2006/05/29 14:57:55 rml Exp $
 
2
 * CVSID: $Id: nm-vpn-properties.c 3173 2007-12-14 20:37:00Z dcbw $
3
3
 *
4
4
 * nm-vpn-properties.c : GNOME UI dialogs for manipulating VPN connections
5
5
 *
122
122
add_vpn_connection (const char *conn_name, const char *service_name, GSList *conn_data, GSList *routes)
123
123
{
124
124
        char *gconf_key;
 
125
        GtkTreeSelection *selection;
125
126
        GtkTreeIter iter;
126
127
        char conn_gconf_path[PATH_MAX];
127
128
        char *escaped_conn_name;
139
140
 
140
141
        if (gconf_client_dir_exists (gconf_client, conn_gconf_path, NULL))
141
142
                goto out;
142
 
               
 
143
 
 
144
        if ((selection = gtk_tree_view_get_selection (vpn_conn_view)) == NULL)
 
145
                goto out;
 
146
 
143
147
        /* User-visible name of connection */
144
148
        gconf_key = g_strdup_printf ("%s/name", conn_gconf_path);
145
149
        gconf_client_set_string (gconf_client, gconf_key, conn_name, NULL);
181
185
                            VPNCONN_GCONF_COLUMN, conn_gconf_path,
182
186
                            VPNCONN_USER_CAN_EDIT_COLUMN, &conn_user_can_edit,
183
187
                            -1);
 
188
        gtk_tree_selection_select_iter (selection, &iter);
184
189
 
185
190
        ret = TRUE;
186
191
 
189
194
        return ret;
190
195
}
191
196
 
 
197
static void
 
198
remove_vpn_connection (const char *gconf_path, GtkTreeIter *iter)
 
199
{
 
200
        char key[PATH_MAX];
 
201
 
 
202
        g_snprintf (key, sizeof (key), "%s/name", gconf_path);
 
203
        gconf_client_unset (gconf_client, key, NULL);
 
204
        g_snprintf (key, sizeof (key), "%s/service_name", gconf_path);
 
205
        gconf_client_unset (gconf_client, key, NULL);
 
206
        g_snprintf (key, sizeof (key), "%s/vpn_data", gconf_path);
 
207
        gconf_client_unset (gconf_client, key, NULL);
 
208
        g_snprintf (key, sizeof (key), "%s/routes", gconf_path);
 
209
        gconf_client_unset (gconf_client, key, NULL);
 
210
        g_snprintf (key, sizeof (key), "%s/user_name", gconf_path);
 
211
        gconf_client_unset (gconf_client, key, NULL);
 
212
 
 
213
        g_snprintf (key, sizeof (key), "%s/last_attempt_success", gconf_path);
 
214
        gconf_client_unset (gconf_client, key, NULL);
 
215
 
 
216
        gconf_client_unset (gconf_client, gconf_path, NULL);
 
217
        gconf_client_suggest_sync (gconf_client, NULL);
 
218
 
 
219
        if (gtk_list_store_remove (vpn_conn_list, iter)) {
 
220
                GtkTreeSelection *selection;
 
221
 
 
222
                selection = gtk_tree_view_get_selection (vpn_conn_view);
 
223
                gtk_tree_selection_select_iter (selection, iter);
 
224
        }
 
225
}
 
226
 
192
227
static void 
193
228
vpn_druid_vpn_validity_changed (NetworkManagerVpnUI *vpn_ui,
194
229
                                gboolean is_valid, 
197
232
        char *conn_name;
198
233
        GtkTreeIter iter;
199
234
 
200
 
        /*printf ("vpn_druid_vpn_validity_changed %d!\n", is_valid);*/
201
 
 
202
235
        conn_name = vpn_ui->get_connection_name (vpn_ui);
203
236
 
204
237
        /* get list of existing connection names */
213
246
                                            -1);
214
247
                        
215
248
                        if (strcmp (name, conn_name) == 0) {
216
 
                                /*printf ("name '%s' is already in use\n", conn_name);*/
217
249
                                is_valid = FALSE;
218
250
                                break;
219
251
                        }
238
270
        GtkWidget *w;
239
271
        NetworkManagerVpnUI *vpn_ui;
240
272
 
241
 
        /*printf ("vpn_type_next!\n");*/
242
 
 
243
273
        /* first hide existing child */
244
274
        w = g_list_nth_data (gtk_container_children (GTK_CONTAINER (vpn_type_details)), 0);
245
275
        if (w)
280
310
 
281
311
        is_valid = FALSE;
282
312
 
283
 
        /*printf ("vpn_druid_von_details_page_prepare!\n");*/
284
 
 
285
313
        /* validate input, in case we are coming in via 'Back' */
286
314
        vpn_ui = (NetworkManagerVpnUI *) g_slist_nth_data (vpn_types, gtk_combo_box_get_active (vpn_type_combo_box));
287
315
        if (vpn_ui != NULL)
299
327
 
300
328
        is_valid = FALSE;
301
329
 
302
 
        /*printf ("vpn_details_next!\n");*/
303
 
 
304
330
        /* validate input */
305
331
        vpn_ui = (NetworkManagerVpnUI *) g_slist_nth_data (vpn_types, gtk_combo_box_get_active (vpn_type_combo_box));
306
332
        if (vpn_ui != NULL)
315
341
{
316
342
        NetworkManagerVpnUI *vpn_ui;
317
343
 
318
 
        /*printf ("vpn_confirm_prepare!\n");*/
319
 
 
320
344
        vpn_ui = (NetworkManagerVpnUI *) g_slist_nth_data (vpn_types, gtk_combo_box_get_active (vpn_type_combo_box));
321
345
        if (vpn_ui != NULL) {
322
346
                gchar *confirm_text;
339
363
        char *conn_name;
340
364
        NetworkManagerVpnUI *vpn_ui;
341
365
 
342
 
        /*printf ("vpn_confirm_finish!\n");*/
343
 
 
344
366
        vpn_ui = (NetworkManagerVpnUI *) g_slist_nth_data (vpn_types, gtk_combo_box_get_active (vpn_type_combo_box));
345
367
        conn_name   = vpn_ui->get_connection_name (vpn_ui);
346
368
        conn_data   = vpn_ui->get_properties (vpn_ui);
419
441
        GList *children;
420
442
        NetworkManagerVpnUI *vpn_ui;
421
443
 
422
 
        /*printf ("import_settings svc_name='%s', name='%s' vpn-ui-=\n", svc_name, name);*/
423
 
 
424
444
        vpn_ui = find_vpn_ui_by_service_name (svc_name);
425
445
 
426
446
        /* Bail out if we don't have the requested VPN implementation on our system */
494
514
 
495
515
        orig_conn_name = (const char *) user_data;
496
516
 
497
 
        /*printf ("vpn_edit_vpn_validity_changed %d!\n", is_valid);*/
498
 
 
499
517
        conn_name = vpn_ui->get_connection_name (vpn_ui);
500
518
 
501
519
        /* get list of existing connection names */
512
530
                        /* Can override the original name (stored in user_data, see edit_cb()) */
513
531
                        if (strcmp (name, orig_conn_name) != 0) {                       
514
532
                                if (strcmp (name, conn_name) == 0) {
515
 
                                        /*printf ("name '%s' is already in use\n", conn_name);*/
516
533
                                        is_valid = FALSE;
517
534
                                        break;
518
535
                                }
631
648
        const char *conn_name;
632
649
        char key[PATH_MAX];
633
650
        char *conn_gconf_path;
 
651
        GtkTreeSelection *selection;
634
652
        GtkTreeIter iter;
635
653
 
636
 
        printf ("edit_cb\n");
637
 
 
638
654
        if (!retrieve_data_from_selected_connection (&vpn_ui, &conn_vpn_data, &conn_routes, &conn_name, &conn_gconf_path))
639
655
                goto out;
640
656
 
 
657
        if ((selection = gtk_tree_view_get_selection (vpn_conn_view)) == NULL)
 
658
                goto out;
 
659
 
 
660
        if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
 
661
                goto out;
 
662
 
641
663
        vpn_edit_widget = vpn_ui->get_widget (vpn_ui, conn_vpn_data, conn_routes, conn_name);
642
664
 
643
665
        g_slist_free (conn_vpn_data);
675
697
 
676
698
                        gconf_client_suggest_sync (gconf_client, NULL);
677
699
                } else {
678
 
                        /* remove old entry */
679
 
                        g_snprintf (key, sizeof (key), "%s/name", conn_gconf_path);
680
 
                        gconf_client_unset (gconf_client, key, NULL);
681
 
                        g_snprintf (key, sizeof (key), "%s/service_name", conn_gconf_path);
682
 
                        gconf_client_unset (gconf_client, key, NULL);
683
 
                        g_snprintf (key, sizeof (key), "%s/vpn_data", conn_gconf_path);
684
 
                        gconf_client_unset (gconf_client, key, NULL);
685
 
                        /* TODO: at some point remove routes and user_name */
686
 
                        g_snprintf (key, sizeof (key), "%s/routes", conn_gconf_path);
687
 
                        gconf_client_unset (gconf_client, key, NULL);
688
 
                        g_snprintf (key, sizeof (key), "%s/user_name", conn_gconf_path);
689
 
                        gconf_client_unset (gconf_client, key, NULL);
690
 
                        gconf_client_unset (gconf_client, conn_gconf_path, NULL);
691
 
                        gconf_client_suggest_sync (gconf_client, NULL);
692
 
                        gtk_list_store_remove (vpn_conn_list, &iter);
 
700
                        selection = gtk_tree_view_get_selection (vpn_conn_view);
 
701
                        gtk_tree_selection_get_selected (selection, NULL, &iter);
 
702
                        remove_vpn_connection (conn_gconf_path, &iter);
693
703
 
694
 
                        /* add new entry */
695
704
                        add_vpn_connection (new_conn_name, vpn_ui->get_service_name (vpn_ui), 
696
 
                                            new_conn_data, new_conn_routes);
 
705
                                                                new_conn_data, new_conn_routes);
697
706
                }
698
707
 
699
708
                if (new_conn_data != NULL) {
723
732
        GtkWidget *confirm_dialog;
724
733
        int response;
725
734
 
726
 
        /*printf ("delete\n");*/
727
 
 
728
735
        if ((selection = gtk_tree_view_get_selection (vpn_conn_view)) == NULL)
729
736
                goto out;
730
737
 
748
755
 
749
756
        gtk_tree_model_get (GTK_TREE_MODEL (vpn_conn_list), &iter, VPNCONN_GCONF_COLUMN, &conn_gconf_path, -1);
750
757
 
751
 
        if (conn_gconf_path != NULL) {
752
 
                char key[PATH_MAX];
753
 
                
754
 
                g_snprintf (key, sizeof (key), "%s/name", conn_gconf_path);
755
 
                gconf_client_unset (gconf_client, key, NULL);
756
 
                g_snprintf (key, sizeof (key), "%s/service_name", conn_gconf_path);
757
 
                gconf_client_unset (gconf_client, key, NULL);
758
 
                g_snprintf (key, sizeof (key), "%s/vpn_data", conn_gconf_path);
759
 
                gconf_client_unset (gconf_client, key, NULL);
760
 
                g_snprintf (key, sizeof (key), "%s/routes", conn_gconf_path);
761
 
                gconf_client_unset (gconf_client, key, NULL);
762
 
                /* TODO: remove user_name */
763
 
                g_snprintf (key, sizeof (key), "%s/user_name", conn_gconf_path);
764
 
                gconf_client_unset (gconf_client, key, NULL);
765
 
                g_snprintf (key, sizeof (key), "%s/last_attempt_success", conn_gconf_path);
766
 
                gconf_client_unset (gconf_client, key, NULL);
767
 
 
768
 
                gconf_client_unset (gconf_client, conn_gconf_path, NULL);
769
 
 
770
 
                gconf_client_suggest_sync (gconf_client, NULL);
771
 
 
772
 
                if (gtk_list_store_remove (vpn_conn_list, &iter))
773
 
                        gtk_tree_selection_select_iter (selection, &iter);
774
 
        }
 
758
        if (conn_gconf_path != NULL)
 
759
                remove_vpn_connection (conn_gconf_path, &iter);
775
760
 
776
761
        update_edit_del_sensitivity ();
777
762
 
802
787
        const char *conn_name;
803
788
        char *conn_gconf_path;
804
789
 
805
 
        /*printf ("export_cb\n");*/
806
 
 
807
790
        if (!retrieve_data_from_selected_connection (&vpn_ui, &conn_vpn_data, &conn_routes, &conn_name, &conn_gconf_path))
808
791
                goto out;
809
792
 
882
865
vpn_list_cursor_changed_cb (GtkTreeView *treeview,
883
866
                            gpointer user_data)
884
867
{
885
 
        /*printf ("*** vpn_list_cursor_changed_cb\n");*/
886
 
 
887
868
        update_edit_del_sensitivity ();
888
869
}
889
870
 
 
871
static void
 
872
vpn_list_row_activated_cb (GtkTreeView *treeview,
 
873
                           GtkTreePath *path,
 
874
                           GtkTreeViewColumn *column,
 
875
                           gpointer user_data)
 
876
{
 
877
        edit_cb (NULL, NULL);
 
878
}
 
879
 
890
880
/* TODO: remove these once we get the GModule thing going */
891
881
//extern NetworkManagerVpnUI* vpn_ui_factory_vpnc (void);
892
882
extern NetworkManagerVpnUI* vpn_ui_factory_dummy (void);
927
917
 
928
918
#define VPN_NAME_FILES_DIR SYSCONFDIR"/NetworkManager/VPN"
929
919
 
 
920
static gint
 
921
vpn_list_sorter(GtkTreeModel *model,
 
922
                GtkTreeIter *a,
 
923
                GtkTreeIter *b,
 
924
                gpointer user_data)
 
925
{
 
926
        GValue aval = {0};
 
927
        GValue bval = {0};
 
928
        const char *aname;
 
929
        const char *bname;
 
930
        gint res;
 
931
 
 
932
        gtk_tree_model_get_value(model, a, VPNCONN_NAME_COLUMN, &aval);
 
933
        gtk_tree_model_get_value(model, b, VPNCONN_NAME_COLUMN, &bval);
 
934
        aname = g_value_get_string(&aval);
 
935
        bname = g_value_get_string(&bval);
 
936
        res = strcasecmp(aname, bname);
 
937
        g_value_unset(&aval);
 
938
        g_value_unset(&bval);
 
939
        return res;
 
940
}
 
941
 
 
942
 
930
943
static gboolean
931
944
init_app (void)
932
945
{
938
951
        GtkHBox *vpn_type_hbox1;
939
952
        GtkWidget *toplevel;
940
953
        GDir *dir;
 
954
    GtkTreeIter tree_iter;
941
955
 
942
956
        if (!vpn_get_clipboard ())
943
957
                return FALSE;
1001
1015
        vpn_type_details = GTK_VBOX (glade_xml_get_widget (xml, "vpn-connection-druid-details-box"));
1002
1016
 
1003
1017
        w = glade_xml_get_widget (xml, "add");
1004
 
        gtk_signal_connect (GTK_OBJECT (w), "clicked", GTK_SIGNAL_FUNC (add_cb), NULL);
 
1018
        g_signal_connect (G_OBJECT (w), "clicked", GTK_SIGNAL_FUNC (add_cb), NULL);
1005
1019
        vpn_edit = glade_xml_get_widget (xml, "edit");
1006
 
        gtk_signal_connect (GTK_OBJECT (vpn_edit), "clicked", GTK_SIGNAL_FUNC (edit_cb), NULL);
 
1020
        g_signal_connect (G_OBJECT (vpn_edit), "clicked", GTK_SIGNAL_FUNC (edit_cb), NULL);
1007
1021
        vpn_export = glade_xml_get_widget (xml, "export");
1008
 
        gtk_signal_connect (GTK_OBJECT (vpn_export), "clicked", GTK_SIGNAL_FUNC (export_cb), NULL);
 
1022
        g_signal_connect (G_OBJECT (vpn_export), "clicked", GTK_SIGNAL_FUNC (export_cb), NULL);
1009
1023
        vpn_delete = glade_xml_get_widget (xml, "delete");
1010
 
        gtk_signal_connect (GTK_OBJECT (vpn_delete), "clicked", GTK_SIGNAL_FUNC (delete_cb), NULL);
 
1024
        g_signal_connect (G_OBJECT (vpn_delete), "clicked", GTK_SIGNAL_FUNC (delete_cb), NULL);
1011
1025
        g_signal_connect (dialog, "response",
1012
1026
                          G_CALLBACK (response_cb), NULL);
1013
1027
        g_signal_connect (dialog, "delete_event",
1016
1030
        vpn_conn_view = GTK_TREE_VIEW (glade_xml_get_widget (xml, "vpnlist"));
1017
1031
        vpn_conn_list = gtk_list_store_new (VPNCONN_N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
1018
1032
 
1019
 
        gtk_signal_connect_after (GTK_OBJECT (vpn_conn_view), "cursor-changed",
 
1033
        gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(vpn_conn_list),
 
1034
                                        VPNCONN_NAME_COLUMN,
 
1035
                                        vpn_list_sorter,
 
1036
                                        NULL,
 
1037
                                        NULL);
 
1038
        gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(vpn_conn_list),
 
1039
                                             VPNCONN_NAME_COLUMN,
 
1040
                                             GTK_SORT_ASCENDING);
 
1041
 
 
1042
        g_signal_connect_after (G_OBJECT (vpn_conn_view), "cursor-changed",
1020
1043
                                  GTK_SIGNAL_FUNC (vpn_list_cursor_changed_cb), NULL);
1021
1044
 
 
1045
        g_signal_connect (G_OBJECT (vpn_conn_view), "row-activated",
 
1046
                                  GTK_SIGNAL_FUNC (vpn_list_row_activated_cb), NULL);
 
1047
 
1022
1048
        get_all_vpn_connections ();
1023
1049
 
1024
1050
        column = gtk_tree_view_column_new ();
1032
1058
        gtk_tree_view_set_model (vpn_conn_view, GTK_TREE_MODEL (vpn_conn_list));
1033
1059
        gtk_tree_view_expand_all (vpn_conn_view);
1034
1060
 
 
1061
        if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (vpn_conn_list), &tree_iter)) {
 
1062
                GtkTreeSelection *selection = gtk_tree_view_get_selection (vpn_conn_view);
 
1063
 
 
1064
                gtk_tree_selection_select_iter (selection, &tree_iter);
 
1065
        }
 
1066
 
1035
1067
        gtk_widget_show_all (dialog);
1036
1068
 
1037
1069
        /* fill in possibly choices in the druid when adding a connection */
1046
1078
 
1047
1079
        /* Druid */
1048
1080
        druid = GNOME_DRUID (glade_xml_get_widget (xml, "vpn-create-connection-druid"));
1049
 
        gtk_signal_connect (GTK_OBJECT (druid), "cancel", GTK_SIGNAL_FUNC (vpn_druid_cancel), NULL);
 
1081
        g_signal_connect (GTK_OBJECT (druid), "cancel", GTK_SIGNAL_FUNC (vpn_druid_cancel), NULL);
1050
1082
        druid_confirm_page = GNOME_DRUID_PAGE_EDGE (glade_xml_get_widget (xml, "vpn-druid-vpn-confirm-page"));
1051
1083
        /* use connect_after, otherwise gnome_druid_set_buttons_sensitive() won't work in prepare handlers */
1052
1084
        w = glade_xml_get_widget (xml, "vpn-druid-vpn-type-page");
1053
 
        gtk_signal_connect_after (GTK_OBJECT (w), "next", GTK_SIGNAL_FUNC (vpn_druid_vpn_type_page_next), NULL);
 
1085
        g_signal_connect_after (G_OBJECT (w), "next", GTK_SIGNAL_FUNC (vpn_druid_vpn_type_page_next), NULL);
1054
1086
        w = glade_xml_get_widget (xml, "vpn-druid-vpn-details-page");
1055
 
        gtk_signal_connect_after (GTK_OBJECT (w), "prepare", GTK_SIGNAL_FUNC (vpn_druid_vpn_details_page_prepare), NULL);
1056
 
        gtk_signal_connect_after (GTK_OBJECT (w), "next", GTK_SIGNAL_FUNC (vpn_druid_vpn_details_page_next), NULL);
 
1087
        g_signal_connect_after (G_OBJECT (w), "prepare", GTK_SIGNAL_FUNC (vpn_druid_vpn_details_page_prepare), NULL);
 
1088
        g_signal_connect_after (G_OBJECT (w), "next", GTK_SIGNAL_FUNC (vpn_druid_vpn_details_page_next), NULL);
1057
1089
        w = glade_xml_get_widget (xml, "vpn-druid-vpn-confirm-page");
1058
 
        gtk_signal_connect_after (GTK_OBJECT (w), "prepare", GTK_SIGNAL_FUNC (vpn_druid_vpn_confirm_page_prepare), NULL);
1059
 
        gtk_signal_connect_after (GTK_OBJECT (w), "finish", GTK_SIGNAL_FUNC (vpn_druid_vpn_confirm_page_finish), NULL);
 
1090
        g_signal_connect_after (G_OBJECT (w), "prepare", GTK_SIGNAL_FUNC (vpn_druid_vpn_confirm_page_prepare), NULL);
 
1091
        g_signal_connect_after (G_OBJECT (w), "finish", GTK_SIGNAL_FUNC (vpn_druid_vpn_confirm_page_finish), NULL);
1060
1092
 
1061
1093
        toplevel = gtk_widget_get_toplevel (GTK_WIDGET (druid));
1062
 
        gtk_signal_connect (GTK_OBJECT (toplevel), "delete_event", GTK_SIGNAL_FUNC (vpn_window_close), NULL);
 
1094
        g_signal_connect (G_OBJECT (toplevel), "delete_event", GTK_SIGNAL_FUNC (vpn_window_close), NULL);
1063
1095
 
1064
1096
        druid_window = GTK_WINDOW (glade_xml_get_widget (xml, "vpn-create-connection"));
1065
1097