Assamese translation updated
[platform/upstream/evolution-data-server.git] / libedataserverui / e-categories-dialog.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
4  *
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.
8  *
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.
13  *
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.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <string.h>
25 #include <gtk/gtk.h>
26 #include <gdk/gdkkeysyms.h>
27 #include <glib/gi18n-lib.h>
28
29 #include <libedataserver/libedataserver.h>
30 #include <libedataserver/libedataserver-private.h>
31
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"
37
38 #define E_CATEGORIES_DIALOG_GET_PRIVATE(obj) \
39         (G_TYPE_INSTANCE_GET_PRIVATE \
40         ((obj), E_TYPE_CATEGORIES_DIALOG, ECategoriesDialogPrivate))
41
42 G_DEFINE_TYPE (ECategoriesDialog, e_categories_dialog, GTK_TYPE_DIALOG)
43
44 struct _ECategoriesDialogPrivate {
45         GtkWidget *categories_editor;
46 };
47
48 static void
49 entry_changed_cb (GtkEntry *entry,
50                   ECategoriesDialog *dialog)
51 {
52         gtk_dialog_set_response_sensitive (
53                 GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
54 }
55
56 static void
57 e_categories_dialog_class_init (ECategoriesDialogClass *class)
58 {
59         g_type_class_add_private (class, sizeof (ECategoriesDialogPrivate));
60 }
61
62 static void
63 e_categories_dialog_init (ECategoriesDialog *dialog)
64 {
65         GtkWidget *dialog_content;
66         GtkWidget *categories_editor;
67
68         dialog->priv = E_CATEGORIES_DIALOG_GET_PRIVATE (dialog);
69
70         categories_editor = e_categories_editor_new ();
71         dialog->priv->categories_editor = categories_editor;
72
73         dialog_content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
74         gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
75         gtk_box_pack_start (
76                 GTK_BOX (dialog_content), categories_editor, TRUE, TRUE, 0);
77         gtk_box_set_spacing (GTK_BOX (dialog_content), 12);
78
79         g_signal_connect (
80                 categories_editor, "entry-changed",
81                 G_CALLBACK (entry_changed_cb), dialog);
82
83         gtk_dialog_add_buttons (
84                 GTK_DIALOG (dialog),
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"));
91
92         gtk_widget_show_all (categories_editor);
93 }
94
95 /**
96  * e_categories_dialog_new:
97  * @categories: Comma-separated list of categories
98  *
99  * Creates a new #ECategoriesDialog widget and sets the initial selection
100  * to @categories.
101  *
102  * Returns: a new #ECategoriesDialog
103  **/
104 GtkWidget *
105 e_categories_dialog_new (const gchar *categories)
106 {
107         ECategoriesDialog *dialog;
108
109         dialog = g_object_new (E_TYPE_CATEGORIES_DIALOG, NULL);
110
111         if (categories)
112                 e_categories_dialog_set_categories (dialog, categories);
113
114         return GTK_WIDGET (dialog);
115 }
116
117 /**
118  * e_categories_dialog_get_categories:
119  * @dialog: An #ECategoriesDialog
120  *
121  * Gets a comma-separated list of the categories currently selected
122  * in the dialog.
123  *
124  * Returns: a comma-separated list of categories. Free returned
125  * pointer with g_free().
126  **/
127 gchar *
128 e_categories_dialog_get_categories (ECategoriesDialog *dialog)
129 {
130         gchar *categories;
131
132         g_return_val_if_fail (E_IS_CATEGORIES_DIALOG (dialog), NULL);
133
134         categories = e_categories_editor_get_categories (
135                 E_CATEGORIES_EDITOR (dialog->priv->categories_editor));
136
137         return categories;
138 }
139
140 /**
141  * e_categories_dialog_set_categories:
142  * @dialog: An #ECategoriesDialog
143  * @categories: Comma-separated list of categories
144  *
145  * Sets the list of categories selected on the dialog.
146  **/
147 void
148 e_categories_dialog_set_categories (ECategoriesDialog *dialog,
149                                     const gchar *categories)
150 {
151         g_return_if_fail (E_IS_CATEGORIES_DIALOG (dialog));
152
153         e_categories_editor_set_categories (
154                 E_CATEGORIES_EDITOR (dialog->priv->categories_editor),
155                 categories);
156 }