2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU Lesser General Public License as published by
4 * the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful, but
7 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 * David Trowbridge <trowbrds@cs.colorado.edu>
18 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
22 #include "evolution-config.h"
24 #include "url-editor-dialog.h"
27 #include <glib/gi18n.h>
29 #include <e-util/e-util.h>
30 #include <e-util/e-util-private.h>
32 #include <shell/e-shell.h>
40 create_uri (UrlEditorDialog
*dialog
)
46 if (uri
->service_type
== TYPE_URI
) {
48 g_free (uri
->location
);
49 uri
->location
= g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog
->server_entry
)));
51 const gchar
*method
= "file";
52 gchar
*server
, *file
, *port
, *username
, *password
;
54 server
= g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog
->server_entry
)));
55 file
= g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog
->file_entry
)));
56 port
= g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog
->port_entry
)));
57 username
= g_uri_escape_string (gtk_entry_get_text (GTK_ENTRY (dialog
->username_entry
)), "", FALSE
);
58 password
= g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog
->password_entry
)));
60 switch (uri
->service_type
) {
71 username
= g_strdup ("anonymous");
89 g_free (uri
->location
);
90 uri
->location
= g_strdup_printf (
91 "%s://%s%s%s%s%s%s%s",
93 username
, (username
[0] != '\0') ? "@" : "",
95 (port
[0] != '\0') ? ":" : "", port
,
96 (file
[0] != '/') ? "/" : "", file
);
105 uri
->fb_duration_value
= gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog
->fb_duration_spin
));
106 uri
->fb_duration_type
= gtk_combo_box_get_active (GTK_COMBO_BOX (dialog
->fb_duration_combo
));
110 check_input (UrlEditorDialog
*dialog
)
118 if (gtk_combo_box_get_active (GTK_COMBO_BOX (dialog
->type_selector
)) == URI_PUBLISH_AS_ICAL
) {
119 gtk_widget_hide (dialog
->fb_duration_label
);
120 gtk_widget_hide (dialog
->fb_duration_spin
);
121 gtk_widget_hide (dialog
->fb_duration_combo
);
123 gtk_widget_show (dialog
->fb_duration_label
);
124 gtk_widget_show (dialog
->fb_duration_spin
);
125 gtk_widget_show (dialog
->fb_duration_combo
);
128 if (gtk_widget_get_sensitive (dialog
->events_selector
)) {
129 sources
= e_source_selector_get_selection (
130 E_SOURCE_SELECTOR (dialog
->events_selector
));
131 n
+= g_list_length (sources
);
132 g_list_free_full (sources
, (GDestroyNotify
) g_object_unref
);
137 /* This should probably be more complex, since ' ' isn't a valid server name */
138 switch (uri
->service_type
) {
145 if (!strlen (gtk_entry_get_text (GTK_ENTRY (dialog
->server_entry
)))) goto fail
;
146 if (!strlen (gtk_entry_get_text (GTK_ENTRY (dialog
->file_entry
)))) goto fail
;
149 if (!strlen (gtk_entry_get_text (GTK_ENTRY (dialog
->server_entry
)))) goto fail
;
155 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog
), GTK_RESPONSE_OK
, TRUE
);
158 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog
), GTK_RESPONSE_OK
, FALSE
);
162 source_selection_changed (ESourceSelector
*selector
,
163 UrlEditorDialog
*dialog
)
165 check_input (dialog
);
169 publish_service_changed (GtkComboBox
*combo
,
170 UrlEditorDialog
*dialog
)
172 gint selected
= gtk_combo_box_get_active (combo
);
177 /* Big mess that switches around all the fields to match the source type
178 * the user has selected. Tries to keep field contents where possible */
181 gtk_label_set_text_with_mnemonic (GTK_LABEL (dialog
->server_label
), "_Server:");
182 gtk_label_set_text_with_mnemonic (GTK_LABEL (dialog
->port_label
), "_Port:");
183 gtk_label_set_text_with_mnemonic (GTK_LABEL (dialog
->port_label
), "S_hare:");
184 gtk_entry_set_text (GTK_ENTRY (dialog
->port_entry
), "");
185 gtk_widget_show (dialog
->file_hbox
);
186 gtk_widget_show (dialog
->optional_label
);
187 gtk_widget_show (dialog
->port_hbox
);
188 gtk_widget_show (dialog
->username_hbox
);
189 gtk_widget_show (dialog
->password_hbox
);
190 gtk_widget_show (dialog
->remember_pw
);
196 gtk_label_set_text_with_mnemonic (GTK_LABEL (dialog
->server_label
), "_Server:");
197 gtk_label_set_text_with_mnemonic (GTK_LABEL (dialog
->port_label
), "_Port:");
198 if (uri
->service_type
== TYPE_SMB
)
199 gtk_entry_set_text (GTK_ENTRY (dialog
->port_entry
), "");
200 else if (uri
->service_type
== TYPE_URI
)
201 gtk_entry_set_text (GTK_ENTRY (dialog
->server_entry
), "");
202 gtk_widget_show (dialog
->file_hbox
);
203 gtk_widget_show (dialog
->optional_label
);
204 gtk_widget_show (dialog
->port_hbox
);
205 gtk_widget_show (dialog
->username_hbox
);
206 gtk_widget_show (dialog
->password_hbox
);
207 gtk_widget_show (dialog
->remember_pw
);
210 gtk_label_set_text_with_mnemonic (GTK_LABEL (dialog
->server_label
), "_Server:");
211 gtk_label_set_text_with_mnemonic (GTK_LABEL (dialog
->port_label
), "_Port:");
212 if (uri
->service_type
== TYPE_SMB
)
213 gtk_entry_set_text (GTK_ENTRY (dialog
->port_entry
), "");
214 else if (uri
->service_type
== TYPE_URI
)
215 gtk_entry_set_text (GTK_ENTRY (dialog
->server_entry
), "");
216 gtk_widget_show (dialog
->file_hbox
);
217 gtk_widget_show (dialog
->optional_label
);
218 gtk_widget_show (dialog
->port_hbox
);
219 gtk_widget_hide (dialog
->username_hbox
);
220 gtk_widget_hide (dialog
->password_hbox
);
221 gtk_widget_hide (dialog
->remember_pw
);
224 gtk_label_set_text_with_mnemonic (GTK_LABEL (dialog
->server_label
), "_Location (URI):");
225 if (uri
->service_type
!= TYPE_URI
)
226 gtk_entry_set_text (GTK_ENTRY (dialog
->server_entry
), "");
227 gtk_widget_hide (dialog
->file_hbox
);
228 gtk_widget_hide (dialog
->optional_label
);
229 gtk_widget_hide (dialog
->port_hbox
);
230 gtk_widget_hide (dialog
->username_hbox
);
231 gtk_widget_hide (dialog
->password_hbox
);
232 gtk_widget_hide (dialog
->remember_pw
);
234 uri
->service_type
= selected
;
235 check_input (dialog
);
239 type_selector_changed (GtkComboBox
*combo
,
240 UrlEditorDialog
*dialog
)
242 gint selected
= gtk_combo_box_get_active (combo
);
246 uri
->publish_format
= selected
;
248 check_input (dialog
);
252 frequency_changed_cb (GtkComboBox
*combo
,
253 UrlEditorDialog
*dialog
)
255 gint selected
= gtk_combo_box_get_active (combo
);
260 uri
->publish_frequency
= selected
;
264 server_entry_changed (GtkEntry
*entry
,
265 UrlEditorDialog
*dialog
)
267 check_input (dialog
);
271 file_entry_changed (GtkEntry
*entry
,
272 UrlEditorDialog
*dialog
)
274 check_input (dialog
);
278 port_entry_changed (GtkEntry
*entry
,
279 UrlEditorDialog
*dialog
)
284 username_entry_changed (GtkEntry
*entry
,
285 UrlEditorDialog
*dialog
)
290 password_entry_changed (GtkEntry
*entry
,
291 UrlEditorDialog
*dialog
)
296 remember_pw_toggled (GtkToggleButton
*toggle
,
297 UrlEditorDialog
*dialog
)
302 set_from_uri (UrlEditorDialog
*dialog
)
314 soup_uri
= soup_uri_new (uri
->location
);
315 g_return_if_fail (soup_uri
!= NULL
);
317 /* determine our service type */
318 scheme
= soup_uri_get_scheme (soup_uri
);
319 g_return_if_fail (scheme
!= NULL
);
321 if (strcmp (scheme
, "smb") == 0)
322 uri
->service_type
= TYPE_SMB
;
323 else if (strcmp (scheme
, "sftp") == 0)
324 uri
->service_type
= TYPE_SFTP
;
325 else if (strcmp (scheme
, "ftp") == 0)
326 /* we set TYPE_FTP here for now. if we don't find a
327 * username later, we'll change it to TYPE_ANON_FTP */
328 uri
->service_type
= TYPE_FTP
;
329 else if (strcmp (scheme
, "dav") == 0)
330 uri
->service_type
= TYPE_DAV
;
331 else if (strcmp (scheme
, "davs") == 0)
332 uri
->service_type
= TYPE_DAVS
;
334 uri
->service_type
= TYPE_URI
;
336 user
= soup_uri_get_user (soup_uri
);
337 host
= soup_uri_get_host (soup_uri
);
338 port
= soup_uri_get_port (soup_uri
);
339 path
= soup_uri_get_path (soup_uri
);
342 gtk_entry_set_text (GTK_ENTRY (dialog
->username_entry
), user
);
345 gtk_entry_set_text (GTK_ENTRY (dialog
->server_entry
), host
);
349 port_str
= g_strdup_printf ("%d", port
);
350 gtk_entry_set_text (GTK_ENTRY (dialog
->port_entry
), port_str
);
355 gtk_entry_set_text (GTK_ENTRY (dialog
->file_entry
), path
);
357 if (uri
->service_type
== TYPE_URI
)
358 gtk_entry_set_text (GTK_ENTRY (dialog
->server_entry
), uri
->location
);
360 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog
->publish_service
), uri
->service_type
);
362 soup_uri_free (soup_uri
);
366 url_editor_dialog_construct (UrlEditorDialog
*dialog
)
370 GtkWidget
*content_area
;
373 ESourceRegistry
*registry
;
375 dialog
->builder
= gtk_builder_new ();
376 e_load_ui_builder_definition (dialog
->builder
, "publish-calendar.ui");
378 #define GW(name) ((dialog->name) = e_builder_get_widget (dialog->builder, #name))
380 GW (fb_duration_label
);
381 GW (fb_duration_spin
);
382 GW (fb_duration_combo
);
383 GW (publish_frequency
);
387 GW (publish_service
);
413 content_area
= gtk_dialog_get_content_area (GTK_DIALOG (dialog
));
414 toplevel
= e_builder_get_widget (dialog
->builder
, "publishing toplevel");
415 gtk_container_add (GTK_CONTAINER (content_area
), toplevel
);
417 gtk_container_set_border_width (GTK_CONTAINER (dialog
), 6);
419 dialog
->cancel
= gtk_dialog_add_button (GTK_DIALOG (dialog
), _("_Cancel"), GTK_RESPONSE_CANCEL
);
420 dialog
->ok
= gtk_dialog_add_button (GTK_DIALOG (dialog
), _("_OK"), GTK_RESPONSE_OK
);
421 gtk_dialog_set_default_response (GTK_DIALOG (dialog
), GTK_RESPONSE_OK
);
422 gtk_window_set_modal (GTK_WINDOW (dialog
), TRUE
);
423 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog
), GTK_RESPONSE_OK
, FALSE
);
425 shell
= e_shell_get_default ();
426 registry
= e_shell_get_registry (shell
);
427 dialog
->events_selector
= e_source_selector_new (
428 registry
, E_SOURCE_EXTENSION_CALENDAR
);
429 gtk_widget_show (dialog
->events_selector
);
430 gtk_container_add (GTK_CONTAINER (dialog
->events_swin
), dialog
->events_selector
);
432 group
= gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL
);
433 gtk_size_group_add_widget (group
, dialog
->type_selector
);
434 gtk_size_group_add_widget (group
, dialog
->publish_frequency
);
435 g_object_unref (group
);
437 group
= gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL
);
438 gtk_size_group_add_widget (group
, dialog
->publish_service
);
439 gtk_size_group_add_widget (group
, dialog
->server_entry
);
440 gtk_size_group_add_widget (group
, dialog
->file_entry
);
441 gtk_size_group_add_widget (group
, dialog
->port_entry
);
442 gtk_size_group_add_widget (group
, dialog
->username_entry
);
443 gtk_size_group_add_widget (group
, dialog
->password_entry
);
444 g_object_unref (group
);
447 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog
->publish_frequency
), 0);
448 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog
->type_selector
), 0);
449 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog
->publish_service
), 0);
451 dialog
->uri
= g_new0 (EPublishUri
, 1);
458 for (p
= uri
->events
; p
; p
= g_slist_next (p
)) {
459 const gchar
*uid
= p
->data
;
461 source
= e_source_registry_ref_source (
463 e_source_selector_select_source (
464 E_SOURCE_SELECTOR (dialog
->events_selector
),
466 g_object_unref (source
);
469 if (uri
->location
&& strlen (uri
->location
)) {
470 set_from_uri (dialog
);
473 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog
->publish_frequency
), uri
->publish_frequency
);
474 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog
->type_selector
), uri
->publish_format
);
476 uri
->password
= e_passwords_get_password (uri
->location
);
478 if (strlen (uri
->password
) != 0) {
479 gtk_entry_set_text (GTK_ENTRY (dialog
->password_entry
), uri
->password
);
480 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog
->remember_pw
), TRUE
);
482 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog
->remember_pw
), FALSE
);
487 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog
->fb_duration_spin
), uri
->fb_duration_value
);
488 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog
->fb_duration_combo
), uri
->fb_duration_type
);
490 type_selector_changed (GTK_COMBO_BOX (dialog
->type_selector
), dialog
);
491 frequency_changed_cb (GTK_COMBO_BOX (dialog
->publish_frequency
), dialog
);
492 publish_service_changed (GTK_COMBO_BOX (dialog
->publish_service
), dialog
);
495 dialog
->publish_service
, "changed",
496 G_CALLBACK (publish_service_changed
), dialog
);
498 dialog
->type_selector
, "changed",
499 G_CALLBACK (type_selector_changed
), dialog
);
501 dialog
->publish_frequency
, "changed",
502 G_CALLBACK (frequency_changed_cb
), dialog
);
504 dialog
->events_selector
, "selection_changed",
505 G_CALLBACK (source_selection_changed
), dialog
);
508 dialog
->server_entry
, "changed",
509 G_CALLBACK (server_entry_changed
), dialog
);
511 dialog
->file_entry
, "changed",
512 G_CALLBACK (file_entry_changed
), dialog
);
514 dialog
->port_entry
, "changed",
515 G_CALLBACK (port_entry_changed
), dialog
);
517 dialog
->username_entry
, "changed",
518 G_CALLBACK (username_entry_changed
), dialog
);
520 dialog
->password_entry
,"changed",
521 G_CALLBACK (password_entry_changed
), dialog
);
523 dialog
->remember_pw
, "toggled",
524 G_CALLBACK (remember_pw_toggled
), dialog
);
526 check_input (dialog
);
532 url_editor_dialog_new (GtkTreeModel
*url_list_model
,
535 UrlEditorDialog
*dialog
;
537 dialog
= (UrlEditorDialog
*) g_object_new (URL_EDITOR_DIALOG_TYPE
, NULL
);
538 dialog
->url_list_model
= g_object_ref (url_list_model
);
542 gtk_window_set_title (GTK_WINDOW (dialog
), _("New Location"));
544 gtk_window_set_title (GTK_WINDOW (dialog
), _("Edit Location"));
546 if (url_editor_dialog_construct (dialog
))
547 return GTK_WIDGET (dialog
);
549 g_object_unref (dialog
);
554 url_editor_dialog_dispose (GObject
*obj
)
556 UrlEditorDialog
*dialog
= (UrlEditorDialog
*) obj
;
558 if (dialog
->url_list_model
) {
559 g_object_unref (dialog
->url_list_model
);
560 dialog
->url_list_model
= NULL
;
562 if (dialog
->builder
) {
563 g_object_unref (dialog
->builder
);
564 dialog
->builder
= NULL
;
567 G_OBJECT_CLASS (url_editor_dialog_parent_class
)->dispose (obj
);
571 url_editor_dialog_class_init (UrlEditorDialogClass
*class)
573 GObjectClass
*object_class
;
575 object_class
= G_OBJECT_CLASS (class);
576 object_class
->dispose
= url_editor_dialog_dispose
;
580 url_editor_dialog_init (UrlEditorDialog
*dialog
)
585 url_editor_dialog_run (UrlEditorDialog
*dialog
)
589 response
= gtk_dialog_run (GTK_DIALOG (dialog
));
590 if (response
== GTK_RESPONSE_OK
) {
593 if (dialog
->uri
->password
)
594 g_free (dialog
->uri
->password
);
595 if (dialog
->uri
->events
) {
596 g_slist_foreach (dialog
->uri
->events
, (GFunc
) g_free
, NULL
);
597 dialog
->uri
->events
= NULL
;
602 dialog
->uri
->password
= g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog
->password_entry
)));
604 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog
->remember_pw
))) {
605 e_passwords_add_password (dialog
->uri
->location
, dialog
->uri
->password
);
606 e_passwords_remember_password (dialog
->uri
->location
);
608 e_passwords_forget_password (dialog
->uri
->location
);
611 list
= e_source_selector_get_selection (
612 E_SOURCE_SELECTOR (dialog
->events_selector
));
614 for (link
= list
; link
!= NULL
; link
= g_list_next (link
)) {
618 source
= E_SOURCE (link
->data
);
619 uid
= e_source_get_uid (source
);
620 dialog
->uri
->events
= g_slist_append (
621 dialog
->uri
->events
, g_strdup (uid
));
624 g_list_free_full (list
, (GDestroyNotify
) g_object_unref
);
626 gtk_widget_hide (GTK_WIDGET (dialog
));
628 return response
== GTK_RESPONSE_OK
;