aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/dialogs/comp-editor.c
diff options
context:
space:
mode:
authorJP Rosevear <jpr@ximian.com>2001-06-02 07:54:43 +0800
committerJP Rosevear <jpr@src.gnome.org>2001-06-02 07:54:43 +0800
commitf4e8698fdd4c48422f217f409e92ec7a2d26c443 (patch)
tree52e697a2a46e790a2d8059680c7a3bff252e97ad /calendar/gui/dialogs/comp-editor.c
parent58d8f86e64d42782ac80ec4ed40b5269a3493454 (diff)
downloadgsoc2013-evolution-f4e8698fdd4c48422f217f409e92ec7a2d26c443.tar
gsoc2013-evolution-f4e8698fdd4c48422f217f409e92ec7a2d26c443.tar.gz
gsoc2013-evolution-f4e8698fdd4c48422f217f409e92ec7a2d26c443.tar.bz2
gsoc2013-evolution-f4e8698fdd4c48422f217f409e92ec7a2d26c443.tar.lz
gsoc2013-evolution-f4e8698fdd4c48422f217f409e92ec7a2d26c443.tar.xz
gsoc2013-evolution-f4e8698fdd4c48422f217f409e92ec7a2d26c443.tar.zst
gsoc2013-evolution-f4e8698fdd4c48422f217f409e92ec7a2d26c443.zip
renamed from editor-page for consistency, more complete implementation
2001-06-01 JP Rosevear <jpr@ximian.com> * gui/dialogs/comp-editor-page.[hc]: renamed from editor-page for consistency, more complete implementation * gui/dialogs/comp-editor.[hc]: More complete implementation * gui/dialogs/*-page.*: The various pages needed to construct the event and task dialogs * gui/dialogs/comp-editor-util.[hc]: useful utility functions for the component editor pages to use * gui/dialogs/Makefile.am: Build and install new files * gui/event-editor*: Remove, obsoleted by the new comp-editor stuff * gui/dialogs/task-editor-dialog.glade: ditto * gui/e-calendar-table.c (open_task): update to use comp editor stuff * gui/e-tasks.c (e_tasks_new_task): ditto * gui/gnome-cal.c (gnome_calendar_edit_object): ditto * gui/Makefile.am: don't build non-existent files nor try to install them svn path=/trunk/; revision=10088
Diffstat (limited to 'calendar/gui/dialogs/comp-editor.c')
-rw-r--r--calendar/gui/dialogs/comp-editor.c385
1 files changed, 373 insertions, 12 deletions
diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c
index f101bfa15a..ddf9f9a9ae 100644
--- a/calendar/gui/dialogs/comp-editor.c
+++ b/calendar/gui/dialogs/comp-editor.c
@@ -23,12 +23,21 @@
#include <config.h>
#endif
+#include <gnome.h>
+#include <gal/widgets/e-unicode.h>
+#include "save-comp.h"
#include "comp-editor.h"
/* Private part of the CompEditor structure */
struct _CompEditorPrivate {
+ /* Client to use */
+ CalClient *client;
+
+ /* Calendar object/uid we are editing; this is an internal copy */
+ CalComponent *comp;
+
/* The pages we have */
GList *pages;
@@ -37,6 +46,8 @@ struct _CompEditorPrivate {
/* Notebook to hold the pages */
GtkNotebook *notebook;
+
+ gboolean changed;
};
@@ -45,6 +56,15 @@ static void comp_editor_class_init (CompEditorClass *class);
static void comp_editor_init (CompEditor *editor);
static void comp_editor_destroy (GtkObject *object);
+static void page_summary_changed_cb (GtkWidget *widget, const char *summary, gpointer data);
+static void page_dates_changed_cb (GtkWidget *widget, CompEditorPageDates *dates, gpointer data);
+static void page_changed_cb (GtkWidget *widget, gpointer data);
+
+static void save_clicked_cb (GtkWidget *widget, gpointer data);
+static void close_clicked_cb (GtkWidget *widget, gpointer data);
+static void help_clicked_cb (GtkWidget *widget, gpointer data);
+static gint delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data);
+
static GtkObjectClass *parent_class;
@@ -52,21 +72,22 @@ static GtkObjectClass *parent_class;
GtkType
comp_editor_get_type (void)
{
- static GtkType comp_editor_type;
+ static GtkType comp_editor_type = 0;
if (!comp_editor_type) {
- static const GtkTypeInfo comp_editor_info = {
+ GtkTypeInfo comp_editor_info = {
"CompEditor",
sizeof (CompEditor),
sizeof (CompEditorClass),
(GtkClassInitFunc) comp_editor_class_init,
- (GtkObjectInitfunc) comp_editor_init,
+ (GtkObjectInitFunc) comp_editor_init,
NULL, /* reserved_1 */
NULL, /* reserved_2 */
(GtkClassInitFunc) NULL
- }
+ };
- comp_editor_type = gtk_type_unique (GTK_TYPE_OBJECT, &comp_editor_info);
+ comp_editor_type = gtk_type_unique (GTK_TYPE_OBJECT,
+ &comp_editor_info);
}
return comp_editor_type;
@@ -110,23 +131,30 @@ setup_widgets (CompEditor *editor)
/* Notebook */
priv->notebook = GTK_NOTEBOOK (gtk_notebook_new ());
- gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (priv->notebook),
+ TRUE, TRUE, 0);
/* Buttons */
bbox = gtk_hbutton_box_new ();
- gtk_hbutton_box_set_layout_default (GTK_HBUTTON_BOX (bbox), GTK_BUTTONBOX_END);
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
pixmap = gnome_stock_pixmap_widget (NULL, GNOME_STOCK_PIXMAP_SAVE);
button = gnome_pixmap_button (pixmap, _("Save"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
-
+ gtk_signal_connect (GTK_OBJECT (button), "clicked",
+ GTK_SIGNAL_FUNC (save_clicked_cb), editor);
+
button = gnome_stock_button (GNOME_STOCK_BUTTON_CLOSE);
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
+ gtk_signal_connect (GTK_OBJECT (button), "clicked",
+ GTK_SIGNAL_FUNC (close_clicked_cb), editor);
button = gnome_stock_button (GNOME_STOCK_BUTTON_HELP);
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
+ gtk_signal_connect (GTK_OBJECT (button), "clicked",
+ GTK_SIGNAL_FUNC (help_clicked_cb), editor);
}
/* Object initialization function for the calendar component editor */
@@ -141,6 +169,7 @@ comp_editor_init (CompEditor *editor)
setup_widgets (editor);
priv->pages = NULL;
+ priv->changed = FALSE;
}
/* Destroy handler for the calendar component editor */
@@ -167,8 +196,18 @@ comp_editor_destroy (GtkObject *object)
+/**
+ * comp_editor_append_page:
+ * @editor: A component editor
+ * @page: Top level widget of the page
+ * @label: Label of the page
+ *
+ * Appends a page to the editor notebook with the given label
+ **/
void
-comp_editor_append_page (CompEditor *editor, EditorPage *page, const char *label)
+comp_editor_append_page (CompEditor *editor,
+ CompEditorPage *page,
+ const char *label)
{
CompEditorPrivate *priv;
GtkWidget *page_widget;
@@ -177,7 +216,7 @@ comp_editor_append_page (CompEditor *editor, EditorPage *page, const char *label
g_return_if_fail (editor != NULL);
g_return_if_fail (IS_COMP_EDITOR (editor));
g_return_if_fail (page != NULL);
- g_return_if_fail (IS_EDITOR_PAGE (page));
+ g_return_if_fail (IS_COMP_EDITOR_PAGE (page));
g_return_if_fail (label != NULL);
priv = editor->priv;
@@ -185,11 +224,333 @@ comp_editor_append_page (CompEditor *editor, EditorPage *page, const char *label
/* Only allow adding the pages while a component has not been set */
g_return_if_fail (priv->comp == NULL);
- page_widget = editor_page_get_widget (page);
+ page_widget = comp_editor_page_get_widget (page);
g_assert (page_widget != NULL);
-
+
label_widget = gtk_label_new (label);
priv->pages = g_list_append (priv->pages, page);
gtk_notebook_append_page (priv->notebook, page_widget, label_widget);
+
+ /* Listen for things happening on the page */
+ gtk_signal_connect (GTK_OBJECT (page), "summary_changed",
+ GTK_SIGNAL_FUNC (page_summary_changed_cb), editor);
+ gtk_signal_connect (GTK_OBJECT (page), "dates_changed",
+ GTK_SIGNAL_FUNC (page_dates_changed_cb), editor);
+ gtk_signal_connect (GTK_OBJECT (page), "changed",
+ GTK_SIGNAL_FUNC (page_changed_cb), editor);
+}
+
+/**
+ * comp_editor_set_cal_client:
+ * @editor: A component editor
+ * @client: The calendar client to use
+ *
+ * Sets the calendar client used by the editor to update components
+ **/
+void
+comp_editor_set_cal_client (CompEditor *editor, CalClient *client)
+{
+ CompEditorPrivate *priv;
+
+ g_return_if_fail (editor != NULL);
+ g_return_if_fail (IS_COMP_EDITOR (editor));
+
+ priv = editor->priv;
+
+ if (client == priv->client)
+ return;
+
+ if (client) {
+ g_return_if_fail (IS_CAL_CLIENT (client));
+ g_return_if_fail (cal_client_get_load_state (client) ==
+ CAL_CLIENT_LOAD_LOADED);
+ gtk_object_ref (GTK_OBJECT (client));
+ }
+
+ if (priv->client) {
+ gtk_signal_disconnect_by_data (GTK_OBJECT (priv->client),
+ editor);
+ gtk_object_unref (GTK_OBJECT (priv->client));
+ }
+
+ priv->client = client;
+}
+
+/**
+ * comp_editor_get_cal_client:
+ * @editor: A component editor
+ *
+ * Returns the calendar client of the editor
+ *
+ * Return value: The calendar client of the editor
+ **/
+CalClient *
+comp_editor_get_cal_client (CompEditor *editor)
+{
+ CompEditorPrivate *priv;
+
+ g_return_val_if_fail (editor != NULL, NULL);
+ g_return_val_if_fail (IS_COMP_EDITOR (editor), NULL);
+
+ priv = editor->priv;
+
+ return priv->client;
+}
+
+/* Creates an appropriate title for the event editor dialog */
+static char *
+make_title_from_comp (CalComponent *comp)
+{
+ char *title;
+ const char *type_string;
+ CalComponentVType type;
+ CalComponentText text;
+
+ if (!comp)
+ return g_strdup (_("Edit Appointment"));
+
+ type = cal_component_get_vtype (comp);
+ switch (type) {
+ case CAL_COMPONENT_EVENT:
+ type_string = _("Appointment - %s");
+ break;
+ case CAL_COMPONENT_TODO:
+ type_string = _("Task - %s");
+ break;
+ case CAL_COMPONENT_JOURNAL:
+ type_string = _("Journal entry - %s");
+ break;
+ default:
+ g_message ("make_title_from_comp(): Cannot handle object of type %d", type);
+ return NULL;
+ }
+
+ cal_component_get_summary (comp, &text);
+ if (text.value) {
+ char *summary;
+ summary = e_utf8_to_locale_string (text.value);
+ title = g_strdup_printf (type_string, summary);
+ g_free (summary);
+ } else
+ title = g_strdup_printf (type_string, _("No summary"));
+
+ return title;
+}
+
+/* Sets the event editor's window title from a calendar component */
+static void
+set_title_from_comp (CompEditor *editor)
+{
+ CompEditorPrivate *priv;
+ char *title;
+
+ priv = editor->priv;
+ title = make_title_from_comp (priv->comp);
+ gtk_window_set_title (GTK_WINDOW (priv->window), title);
+ g_free (title);
+}
+
+static void
+fill_widgets (CompEditor *editor)
+{
+ CompEditorPrivate *priv;
+ GList *l;
+
+ priv = editor->priv;
+
+ for (l = priv->pages; l != NULL; l = l->next)
+ comp_editor_page_fill_widgets (l->data, priv->comp);
+}
+
+/**
+ * comp_editor_edit_comp:
+ * @editor: A component editor
+ * @comp: A calendar component
+ *
+ * Starts the editor editing the given component
+ **/
+void
+comp_editor_edit_comp (CompEditor *editor, CalComponent *comp)
+{
+ CompEditorPrivate *priv;
+
+ g_return_if_fail (editor != NULL);
+ g_return_if_fail (IS_COMP_EDITOR (editor));
+
+ priv = editor->priv;
+
+ if (priv->comp) {
+ gtk_object_unref (GTK_OBJECT (priv->comp));
+ priv->comp = NULL;
+ }
+
+ if (comp)
+ priv->comp = cal_component_clone (comp);
+
+ set_title_from_comp (editor);
+ fill_widgets (editor);
+}
+
+
+/* Brings attention to a window by raising it and giving it focus */
+static void
+raise_and_focus (GtkWidget *widget)
+{
+ g_assert (GTK_WIDGET_REALIZED (widget));
+ gdk_window_show (widget->window);
+ gtk_widget_grab_focus (widget);
+}
+
+/**
+ * comp_editor_focus:
+ * @editor: A component editor
+ *
+ * Brings the editor window to the front and gives it focus
+ **/
+void
+comp_editor_focus (CompEditor *editor)
+{
+ CompEditorPrivate *priv;
+
+ g_return_if_fail (editor != NULL);
+ g_return_if_fail (IS_COMP_EDITOR (editor));
+
+ priv = editor->priv;
+
+ gtk_widget_show_all (priv->window);
+ raise_and_focus (priv->window);
+}
+
+static void
+save_comp (CompEditor *editor)
+{
+ CompEditorPrivate *priv;
+ GList *l;
+
+ priv = editor->priv;
+
+ for (l = priv->pages; l != NULL; l = l->next)
+ comp_editor_page_fill_component (l->data, priv->comp);
+
+ if (!cal_client_update_object (priv->client, priv->comp))
+ g_message ("save_comp (): Could not update the object!");
+ else
+ priv->changed = FALSE;
+}
+
+static gboolean
+prompt_to_save_changes (CompEditor *editor)
+{
+ CompEditorPrivate *priv;
+
+ priv = editor->priv;
+
+ if (!priv->changed)
+ return TRUE;
+
+ switch (save_component_dialog (GTK_WINDOW (priv->window))) {
+ case 0: /* Save */
+ /* FIXME: If an error occurs here, we should popup a dialog
+ and then return FALSE. */
+ save_comp (editor);
+ return TRUE;
+ case 1: /* Discard */
+ return TRUE;
+ case 2: /* Cancel */
+ default:
+ return FALSE;
+ break;
+ }
+}
+
+/* Closes the dialog box and emits the appropriate signals */
+static void
+close_dialog (CompEditor *editor)
+{
+ CompEditorPrivate *priv;
+
+ priv = editor->priv;
+
+ g_assert (priv->window != NULL);
+
+ gtk_object_destroy (GTK_OBJECT (editor));
+}
+
+static void
+save_clicked_cb (GtkWidget *widget, gpointer data)
+{
+ CompEditor *editor = COMP_EDITOR (data);
+
+ save_comp (editor);
+ close_dialog (editor);
+}
+
+static void
+close_clicked_cb (GtkWidget *widget, gpointer data)
+{
+ CompEditor *editor = COMP_EDITOR (data);
+
+ if (prompt_to_save_changes (editor))
+ close_dialog (editor);
+}
+
+static void
+help_clicked_cb (GtkWidget *widget, gpointer data)
+{
+}
+
+static void
+page_summary_changed_cb (GtkWidget *widget, const char *summary, gpointer data)
+{
+ CompEditor *editor = COMP_EDITOR (data);
+ CompEditorPrivate *priv;
+ GList *l;
+
+ priv = editor->priv;
+
+ for (l = priv->pages; l != NULL; l = l->next)
+ comp_editor_page_set_summary (l->data, summary);
+
+ priv->changed = TRUE;
+}
+
+static void
+page_dates_changed_cb (GtkWidget *widget,
+ CompEditorPageDates *dates,
+ gpointer data)
+{
+ CompEditor *editor = COMP_EDITOR (data);
+ CompEditorPrivate *priv;
+ GList *l;
+
+ priv = editor->priv;
+
+ for (l = priv->pages; l != NULL; l = l->next)
+ comp_editor_page_set_dates (l->data, dates);
+
+ priv->changed = TRUE;
+}
+
+
+static void
+page_changed_cb (GtkWidget *widget, gpointer data)
+{
+ CompEditor *editor = COMP_EDITOR (data);
+ CompEditorPrivate *priv;
+
+ priv = editor->priv;
+
+ priv->changed = TRUE;
+}
+
+static gint
+delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+ CompEditor *editor = COMP_EDITOR (data);
+
+ if (prompt_to_save_changes (editor))
+ close_dialog (editor);
+
+ return TRUE;
}