1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU Lesser General Public
7 * License as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
26 #include <gdk/gdkkeysyms.h>
27 #include <glib/gi18n-lib.h>
29 #include <libedataserver/libedataserver.h>
30 #include <libedataserver/libedataserver-private.h>
32 #include "e-categories-dialog.h"
33 #include "e-categories-editor.h"
34 #include "e-categories-selector.h"
35 #include "e-category-completion.h"
36 #include "e-category-editor.h"
38 #define E_CATEGORIES_DIALOG_GET_PRIVATE(obj) \
39 (G_TYPE_INSTANCE_GET_PRIVATE \
40 ((obj), E_TYPE_CATEGORIES_DIALOG, ECategoriesDialogPrivate))
42 G_DEFINE_TYPE (ECategoriesDialog, e_categories_dialog, GTK_TYPE_DIALOG)
44 struct _ECategoriesDialogPrivate {
45 GtkWidget *categories_editor;
49 entry_changed_cb (GtkEntry *entry,
50 ECategoriesDialog *dialog)
52 gtk_dialog_set_response_sensitive (
53 GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
57 e_categories_dialog_class_init (ECategoriesDialogClass *class)
59 g_type_class_add_private (class, sizeof (ECategoriesDialogPrivate));
63 e_categories_dialog_init (ECategoriesDialog *dialog)
65 GtkWidget *dialog_content;
66 GtkWidget *categories_editor;
68 dialog->priv = E_CATEGORIES_DIALOG_GET_PRIVATE (dialog);
70 categories_editor = e_categories_editor_new ();
71 dialog->priv->categories_editor = categories_editor;
73 dialog_content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
74 gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
76 GTK_BOX (dialog_content), categories_editor, TRUE, TRUE, 0);
77 gtk_box_set_spacing (GTK_BOX (dialog_content), 12);
80 categories_editor, "entry-changed",
81 G_CALLBACK (entry_changed_cb), dialog);
83 gtk_dialog_add_buttons (
85 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
86 GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
87 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
88 gtk_dialog_set_response_sensitive (
89 GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
90 gtk_window_set_title (GTK_WINDOW (dialog), _("Categories"));
92 gtk_widget_show_all (categories_editor);
96 * e_categories_dialog_new:
97 * @categories: Comma-separated list of categories
99 * Creates a new #ECategoriesDialog widget and sets the initial selection
102 * Returns: a new #ECategoriesDialog
105 e_categories_dialog_new (const gchar *categories)
107 ECategoriesDialog *dialog;
109 dialog = g_object_new (E_TYPE_CATEGORIES_DIALOG, NULL);
112 e_categories_dialog_set_categories (dialog, categories);
114 return GTK_WIDGET (dialog);
118 * e_categories_dialog_get_categories:
119 * @dialog: An #ECategoriesDialog
121 * Gets a comma-separated list of the categories currently selected
124 * Returns: a comma-separated list of categories. Free returned
125 * pointer with g_free().
128 e_categories_dialog_get_categories (ECategoriesDialog *dialog)
132 g_return_val_if_fail (E_IS_CATEGORIES_DIALOG (dialog), NULL);
134 categories = e_categories_editor_get_categories (
135 E_CATEGORIES_EDITOR (dialog->priv->categories_editor));
141 * e_categories_dialog_set_categories:
142 * @dialog: An #ECategoriesDialog
143 * @categories: Comma-separated list of categories
145 * Sets the list of categories selected on the dialog.
148 e_categories_dialog_set_categories (ECategoriesDialog *dialog,
149 const gchar *categories)
151 g_return_if_fail (E_IS_CATEGORIES_DIALOG (dialog));
153 e_categories_editor_set_categories (
154 E_CATEGORIES_EDITOR (dialog->priv->categories_editor),