From 55e9c607f0bac0a0333552885d97d45c5122bd59 Mon Sep 17 00:00:00 2001 From: Hans Petter Jansson Date: Sun, 9 Nov 2003 05:41:00 +0000 Subject: Add new-addressbook.[ch]. (glade_DATA): Add new-addressbook.glade. 2003-11-08 Hans Petter Jansson * gui/component/Makefile.am (libevolution_addressbook_la_SOURCES): Add new-addressbook.[ch]. (glade_DATA): Add new-addressbook.glade. * gui/component/addressbook-component.c (add_popup_menu_item): Implement. (new_addressbook_cb): Implement. (delete_addressbook_cb): Implement (skeletal). (fill_popup_menu_callback): Implement. (impl_createControls): Hook up fill_popup_menu_callback(). * gui/component/new-addressbook.[ch]: New files. * gui/component/new-addressbook.glade: New file. svn path=/trunk/; revision=23238 --- addressbook/ChangeLog | 17 ++ addressbook/gui/component/Makefile.am | 6 +- addressbook/gui/component/addressbook-component.c | 56 +++++++ addressbook/gui/component/new-addressbook.c | 158 ++++++++++++++++++ addressbook/gui/component/new-addressbook.glade | 192 ++++++++++++++++++++++ addressbook/gui/component/new-addressbook.h | 30 ++++ 6 files changed, 458 insertions(+), 1 deletion(-) create mode 100644 addressbook/gui/component/new-addressbook.c create mode 100644 addressbook/gui/component/new-addressbook.glade create mode 100644 addressbook/gui/component/new-addressbook.h (limited to 'addressbook') diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 954628b562..86998148a2 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,20 @@ +2003-11-08 Hans Petter Jansson + + * gui/component/Makefile.am (libevolution_addressbook_la_SOURCES): + Add new-addressbook.[ch]. + (glade_DATA): Add new-addressbook.glade. + + * gui/component/addressbook-component.c (add_popup_menu_item): + Implement. + (new_addressbook_cb): Implement. + (delete_addressbook_cb): Implement (skeletal). + (fill_popup_menu_callback): Implement. + (impl_createControls): Hook up fill_popup_menu_callback(). + + * gui/component/new-addressbook.[ch]: New files. + + * gui/component/new-addressbook.glade: New file. + 2003-11-07 Dan Winship * util/Makefile.am (INCLUDES): Remove some includes of directories diff --git a/addressbook/gui/component/Makefile.am b/addressbook/gui/component/Makefile.am index 0d6b6e2461..6071aa9a8a 100644 --- a/addressbook/gui/component/Makefile.am +++ b/addressbook/gui/component/Makefile.am @@ -37,6 +37,8 @@ libevolution_addressbook_la_SOURCES = \ addressbook-storage.h \ addressbook.c \ addressbook.h \ + new-addressbook.c \ + new-addressbook.h \ component-factory.c # $(top_builddir)/addressbook/printing/libecontactprint.la @@ -82,7 +84,9 @@ server_DATA = $(server_in_files:.server.in.in=_$(BASE_VERSION).server) @EVO_NAME_SERVER_RULE@ @INTLTOOL_SERVER_RULE@ -glade_DATA = ldap-config.glade +glade_DATA = \ + ldap-config.glade \ + new-addressbook.glade BUILT_SOURCES = $(server_DATA) CLEANFILES = $(BUILT_SOURCES) diff --git a/addressbook/gui/component/addressbook-component.c b/addressbook/gui/component/addressbook-component.c index 25d94f1f6c..7f0ca913ed 100644 --- a/addressbook/gui/component/addressbook-component.c +++ b/addressbook/gui/component/addressbook-component.c @@ -28,10 +28,17 @@ #include "addressbook-component.h" #include "addressbook.h" +#include "new-addressbook.h" #include "widgets/misc/e-source-selector.h" +#include #include +#include +#include +#include +#include +#include #include @@ -59,6 +66,45 @@ load_uri_for_selection (ESourceSelector *selector, } } +static void +add_popup_menu_item (GtkMenu *menu, const char *label, const char *pixmap, + GCallback callback, gpointer user_data) +{ + GtkWidget *item, *image; + + if (pixmap) { + item = gtk_image_menu_item_new_with_label (label); + + /* load the image */ + image = gtk_image_new_from_file (pixmap); + if (!image) + image = gtk_image_new_from_stock (pixmap, GTK_ICON_SIZE_MENU); + + if (image) + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); + } else { + item = gtk_menu_item_new_with_label (label); + } + + if (callback) + g_signal_connect (G_OBJECT (item), "activate", callback, user_data); + + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show (item); +} + +/* Folder popup menu callbacks */ + +static void +new_addressbook_cb (GtkWidget *widget, ESourceSelector *selector) +{ + new_addressbook_dialog (GTK_WINDOW (gtk_widget_get_toplevel (widget))); +} + +static void +delete_addressbook_cb (GtkWidget *widget, AddressbookComponent *comp) +{ +} /* Callbacks. */ @@ -69,6 +115,13 @@ primary_source_selection_changed_callback (ESourceSelector *selector, load_uri_for_selection (selector, view_control); } +static void +fill_popup_menu_callback (ESourceSelector *selector, GtkMenu *menu, AddressbookComponent *comp) +{ + add_popup_menu_item (menu, _("New Addressbook"), NULL, G_CALLBACK (new_addressbook_cb), comp); + add_popup_menu_item (menu, _("Delete"), GTK_STOCK_DELETE, G_CALLBACK (delete_addressbook_cb), comp); + add_popup_menu_item (menu, _("Rename"), NULL, NULL, NULL); +} /* Evolution::Component CORBA methods. */ @@ -101,6 +154,9 @@ impl_createControls (PortableServer_Servant servant, g_signal_connect_object (selector, "primary_selection_changed", G_CALLBACK (primary_source_selection_changed_callback), G_OBJECT (view_control), 0); + g_signal_connect_object (selector, "fill_popup_menu", + G_CALLBACK (fill_popup_menu_callback), + G_OBJECT (addressbook_component), 0); load_uri_for_selection (E_SOURCE_SELECTOR (selector), view_control); *corba_sidebar_control = CORBA_Object_duplicate (BONOBO_OBJREF (sidebar_control), ev); diff --git a/addressbook/gui/component/new-addressbook.c b/addressbook/gui/component/new-addressbook.c new file mode 100644 index 0000000000..c06c84bc84 --- /dev/null +++ b/addressbook/gui/component/new-addressbook.c @@ -0,0 +1,158 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* new-addressbook.c - Create a new addressbook + * + * Copyright (C) 2003 Novell, Inc. + * + * Author: Hans Petter Jansson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "new-addressbook.h" + +static gboolean +create_new_source_with_group (GtkWindow *parent, + ESourceGroup *group, + const char *source_name, + const char *source_location) +{ + ESource *source; + char *new_dir; + + if (e_source_group_peek_source_by_name (group, source_name)) { + e_notice (parent, GTK_MESSAGE_ERROR, + _("Source with name '%s' already exists in the selected group"), + source_name); + return FALSE; + } + + /* Local source */ + + new_dir = g_build_filename (e_source_group_peek_base_uri (group), + source_name, NULL); + if (e_mkdir_hier (new_dir, 0700)) { + g_free (new_dir); + e_notice (parent, GTK_MESSAGE_ERROR, + _("Could not create directory for new calendar")); + return FALSE; + } + + source = e_source_new (source_name, source_name); + g_free (new_dir); + + e_source_group_add_source (group, source, -1); + return TRUE; +} + +/** + * new_calendar_dialog + * + * Displays a dialog that allows the user to create a new calendar. + */ +gboolean +new_addressbook_dialog (GtkWindow *parent) +{ + GtkWidget *dialog, *ab_group, *ab_name, *ab_location; + GladeXML *xml; + ESourceList *source_list; + GConfClient *gconf_client; + GSList *groups, *sl; + gboolean result = FALSE, retry = TRUE; + + /* load the Glade file */ + xml = glade_xml_new (EVOLUTION_GLADEDIR "/new-addressbook.glade", "new-addressbook-dialog", NULL); + if (!xml) { + g_warning (G_STRLOC ": cannot load Glade file"); + return FALSE; + } + + dialog = glade_xml_get_widget (xml, "new-addressbook-dialog"); + ab_group = glade_xml_get_widget (xml, "addressbook-group"); + ab_name = glade_xml_get_widget (xml, "addressbook-name"); + + /* set up widgets */ + gconf_client = gconf_client_get_default (); + source_list = e_source_list_new_for_gconf (gconf_client, "/apps/evolution/addressbook/sources"); + + groups = e_source_list_peek_groups (source_list); + for (sl = groups; sl != NULL; sl = sl->next) { + GtkWidget *menu_item, *menu; + ESourceGroup *group = sl->data; + + menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (ab_group)); + if (!GTK_IS_MENU (menu)) { + menu = gtk_menu_new (); + gtk_option_menu_set_menu (GTK_OPTION_MENU (ab_group), menu); + gtk_widget_show (menu); + } + + menu_item = gtk_menu_item_new_with_label (e_source_group_peek_name (group)); + gtk_widget_show (menu_item); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + } + + if (groups) + gtk_option_menu_set_history (GTK_OPTION_MENU (ab_group), 0); + + /* run the dialog */ + do { + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) { + const char *name; + const char *location; + + name = gtk_entry_get_text (GTK_ENTRY (ab_name)); + location = gtk_entry_get_text (GTK_ENTRY (ab_location)); + sl = g_slist_nth (groups, gtk_option_menu_get_history (GTK_OPTION_MENU (ab_group))); + if (sl) { + if (create_new_source_with_group (GTK_WINDOW (dialog), + sl->data, + name, + location)) + retry = FALSE; + } else { + e_notice (dialog, GTK_MESSAGE_ERROR, + _("A group must be selected")); + continue; + } + } else + retry = FALSE; /* user pressed Cancel */ + } while (retry); + + /* free memory */ + g_object_unref (gconf_client); + g_object_unref (source_list); + gtk_widget_destroy (dialog); + + /* free memory */ + g_object_unref (xml); + + return result; +} diff --git a/addressbook/gui/component/new-addressbook.glade b/addressbook/gui/component/new-addressbook.glade new file mode 100644 index 0000000000..2bac58c325 --- /dev/null +++ b/addressbook/gui/component/new-addressbook.glade @@ -0,0 +1,192 @@ + + + + + + + 12 + True + Add New Addressbook + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + False + False + False + True + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + -6 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + 3 + 3 + False + 6 + 6 + + + + True + Addressbook Group + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 1 + 2 + 1 + 2 + 6 + fill + + + + + + + True + True + -1 + + + 2 + 3 + 1 + 2 + 6 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 2 + 3 + 2 + 3 + 6 + + + + + + + True + <b>Addressbook options</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + 3 + 0 + 1 + 6 + + + + + + + True + Addressbook Name + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 1 + 2 + 2 + 3 + 6 + fill + + + + + + 4 + True + True + + + + + + + diff --git a/addressbook/gui/component/new-addressbook.h b/addressbook/gui/component/new-addressbook.h new file mode 100644 index 0000000000..9860872a00 --- /dev/null +++ b/addressbook/gui/component/new-addressbook.h @@ -0,0 +1,30 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* new-addressbook.h - Create a new addressbook + * + * Copyright (C) 2003 Novell, Inc. + * + * Author: Hans Petter Jansson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef NEW_ADDRESSBOOK_H +#define NEW_ADDRESSBOOK_H + +#include + +gboolean new_addressbook_dialog (GtkWindow *parent); + +#endif -- cgit v1.2.3