[gnome-calendar] Added a new bunch of editable widgets.
- From: Erick PÃrez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] Added a new bunch of editable widgets.
- Date: Tue, 3 Jul 2012 19:53:19 +0000 (UTC)
commit 8b7265d5da6d9133a654e608b3f0b3a2e0e52d67
Author: Erick PÃrez Castellanos <erick red gmail com>
Date: Thu Jun 21 08:13:22 2012 -0400
Added a new bunch of editable widgets.
Just one or two left.
TODO | 1 +
src/gcal-editable-combo.c | 242 ++++++++++++++++++++++++++++++++++++
src/gcal-editable-combo.h | 64 ++++++++++
src/gcal-editable-date.c | 275 +++++++++++++++++++++++++++++++++++++++++
src/gcal-editable-date.h | 61 +++++++++
src/gcal-editable-entry.c | 144 ++++++++++++++--------
src/gcal-editable-entry.h | 7 +-
src/gcal-editable-text.c | 190 +++++++++++++++++++++++++++++
src/gcal-editable-text.h | 61 +++++++++
src/gcal-editable.c | 99 +++++++++++-----
src/gcal-editable.h | 26 +++--
src/gcal-event-view.c | 296 +++++++++++++++++++++++++++++++++++++--------
src/gcal-event-view.h | 11 ++-
13 files changed, 1330 insertions(+), 147 deletions(-)
---
diff --git a/TODO b/TODO
index edd79a5..8bdd4aa 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,6 @@
TODO
+ - Review size/resize of GcalEventView widget
- Rethink signals from GcalManager
- Order events for starting hour in GcalMonthView, and the others
- Review static modifiers
diff --git a/src/gcal-editable-combo.c b/src/gcal-editable-combo.c
new file mode 100644
index 0000000..bf06315
--- /dev/null
+++ b/src/gcal-editable-combo.c
@@ -0,0 +1,242 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 2 -*- */
+/*
+ * gcal-editable-combo.c
+ *
+ * Copyright (C) 2012 - Erick PÃrez Castellanos
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gcal-editable-combo.h"
+
+struct _GcalEditableComboPrivate
+{
+ GtkWidget *view_widget;
+ GtkWidget *edit_widget;
+};
+
+static void gcal_editable_combo_constructed (GObject *object);
+
+static void gcal_editable_combo_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+
+static void gcal_editable_combo_enter_edit_mode (GcalEditable *editable);
+
+static void gcal_editable_combo_leave_edit_mode (GcalEditable *editable);
+
+static void gcal_editable_combo_clear (GcalEditable *editable);
+
+G_DEFINE_TYPE (GcalEditableCombo, gcal_editable_combo, GCAL_TYPE_EDITABLE);
+
+static void gcal_editable_combo_class_init (GcalEditableComboClass *klass)
+{
+ GcalEditableClass *editable_class;
+ GtkWidgetClass *widget_class;
+ GObjectClass *object_class;
+
+ editable_class = GCAL_EDITABLE_CLASS (klass);
+ editable_class->enter_edit_mode = gcal_editable_combo_enter_edit_mode;
+ editable_class->leave_edit_mode = gcal_editable_combo_leave_edit_mode;
+ editable_class->clear = gcal_editable_combo_clear;
+
+ widget_class = GTK_WIDGET_CLASS (klass);
+ widget_class->size_allocate = gcal_editable_combo_size_allocate;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->constructed = gcal_editable_combo_constructed;
+
+ g_type_class_add_private ((gpointer)klass, sizeof (GcalEditableComboPrivate));
+}
+
+
+
+static void gcal_editable_combo_init (GcalEditableCombo *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ GCAL_TYPE_EDITABLE_COMBO,
+ GcalEditableComboPrivate);
+}
+
+static void
+gcal_editable_combo_constructed (GObject *object)
+{
+ GcalEditableComboPrivate *priv;
+
+ priv = GCAL_EDITABLE_COMBO (object)->priv;
+
+ if (G_OBJECT_CLASS (gcal_editable_combo_parent_class)->constructed != NULL)
+ G_OBJECT_CLASS (gcal_editable_combo_parent_class)->constructed (object);
+
+ priv->view_widget = gtk_label_new (NULL);
+ gtk_label_set_ellipsize (GTK_LABEL (priv->view_widget),
+ PANGO_ELLIPSIZE_END);
+ gtk_widget_show (priv->view_widget);
+ gtk_widget_set_valign (priv->view_widget, GTK_ALIGN_CENTER);
+ gtk_widget_set_halign (priv->view_widget, GTK_ALIGN_START);
+ gcal_editable_set_view_widget (GCAL_EDITABLE (object), priv->view_widget);
+
+ priv->edit_widget = gtk_combo_box_new ();
+ gtk_widget_show (priv->edit_widget);
+ gcal_editable_set_edit_widget (GCAL_EDITABLE (object), priv->edit_widget);
+}
+
+static void
+gcal_editable_combo_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ GcalEditableComboPrivate *priv;
+ GtkAllocation view_allocation;
+ gint minimum;
+ gint natural;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_COMBO (widget));
+ priv = GCAL_EDITABLE_COMBO (widget)->priv;
+
+ if (GTK_WIDGET_CLASS (gcal_editable_combo_parent_class)->size_allocate != NULL)
+ GTK_WIDGET_CLASS (gcal_editable_combo_parent_class)->size_allocate (widget, allocation);
+
+ //FIXME: hack to keep the label thin
+ gtk_widget_get_preferred_height (priv->view_widget, &minimum, &natural);
+ gtk_widget_get_allocation (priv->view_widget, &view_allocation);
+ view_allocation.height = minimum;
+ gtk_widget_size_allocate (priv->view_widget, &view_allocation);
+}
+
+static void
+gcal_editable_combo_enter_edit_mode (GcalEditable *editable)
+{
+ GcalEditableComboPrivate *priv;
+ gchar *uid;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_COMBO (editable));
+ priv = GCAL_EDITABLE_COMBO (editable)->priv;
+
+ if (gtk_combo_box_get_model (GTK_COMBO_BOX (priv->edit_widget)) != NULL)
+ {
+ uid = gcal_get_source_uid (
+ gtk_combo_box_get_model (GTK_COMBO_BOX (priv->edit_widget)),
+ gtk_label_get_text (GTK_LABEL (priv->view_widget)));
+
+ gtk_combo_box_set_active_id (GTK_COMBO_BOX (priv->edit_widget), uid);
+ g_free (uid);
+
+ gtk_widget_grab_focus (priv->edit_widget);
+ }
+}
+
+static void
+gcal_editable_combo_leave_edit_mode (GcalEditable *editable)
+{
+ GcalEditableComboPrivate *priv;
+ gchar *name;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_COMBO (editable));
+ priv = GCAL_EDITABLE_COMBO (editable)->priv;
+
+ if (gtk_combo_box_get_model (GTK_COMBO_BOX (priv->edit_widget)) == NULL)
+ {
+ gtk_label_set_text (GTK_LABEL (priv->view_widget), NULL);
+ }
+ else
+ {
+ name = gcal_get_source_name (
+ gtk_combo_box_get_model (GTK_COMBO_BOX (priv->edit_widget)),
+ gtk_combo_box_get_active_id (GTK_COMBO_BOX (priv->edit_widget)));
+
+ gtk_label_set_text (GTK_LABEL (priv->view_widget), name);
+ g_free (name);
+ }
+}
+
+static void
+gcal_editable_combo_clear (GcalEditable *editable)
+{
+ GcalEditableComboPrivate *priv;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_COMBO (editable));
+ priv = GCAL_EDITABLE_COMBO (editable)->priv;
+
+ gtk_label_set_text (GTK_LABEL (priv->view_widget), NULL);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (priv->edit_widget), -1);
+}
+
+/**
+ * gcal_editable_combo_new:
+ *
+ * Init the combo in EDIT_MODE
+ *
+ * Since: 0.1
+ * Returns: (transfer full):
+ **/
+GtkWidget*
+gcal_editable_combo_new (void)
+{
+ GtkWidget *combo = g_object_new (GCAL_TYPE_EDITABLE_COMBO, NULL);
+ gcal_editable_enter_edit_mode (GCAL_EDITABLE (combo));
+ return combo;
+}
+
+/**
+ * gcal_editable_combo_new_with_content:
+ *
+ * Init the combo in VIEW_MODE
+ *
+ * Since 0.2
+ * Returns: (transfer full)
+ */
+GtkWidget*
+gcal_editable_combo_new_with_content (const gchar* content)
+{
+ GtkWidget *combo;
+ combo = g_object_new (GCAL_TYPE_EDITABLE_COMBO, NULL);
+ gcal_editable_combo_set_content (GCAL_EDITABLE_COMBO (combo), content);
+ gcal_editable_leave_edit_mode (GCAL_EDITABLE (combo));
+ return combo;
+}
+
+void
+gcal_editable_combo_set_model (GcalEditableCombo *combo,
+ GtkTreeModel *model)
+{
+ GcalEditableComboPrivate *priv;
+ GtkCellRenderer *renderer;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_COMBO (combo));
+ priv = combo->priv;
+
+ gtk_combo_box_set_model (GTK_COMBO_BOX (priv->edit_widget), model);
+ gtk_combo_box_set_id_column (GTK_COMBO_BOX (priv->edit_widget), 0);
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->edit_widget),
+ renderer,
+ TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->edit_widget),
+ renderer,
+ "text",
+ 1,
+ NULL);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (priv->edit_widget), 0);
+}
+
+void
+gcal_editable_combo_set_content (GcalEditableCombo *combo,
+ const gchar *content)
+{
+ GcalEditableComboPrivate *priv;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_COMBO (combo));
+ priv = combo->priv;
+
+ gtk_label_set_text (GTK_LABEL (priv->view_widget), content);
+}
diff --git a/src/gcal-editable-combo.h b/src/gcal-editable-combo.h
new file mode 100644
index 0000000..c951179
--- /dev/null
+++ b/src/gcal-editable-combo.h
@@ -0,0 +1,64 @@
+/*
+ * gcal-editable-combo.h
+ *
+ * Copyright (C) 2012 - Erick PÃrez Castellanos
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GCAL_EDITABLE_COMBO_H__
+#define __GCAL_EDITABLE_COMBO_H__
+
+#include "gcal-editable.h"
+
+G_BEGIN_DECLS
+
+#define GCAL_TYPE_EDITABLE_COMBO (gcal_editable_combo_get_type ())
+#define GCAL_EDITABLE_COMBO(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_EDITABLE_COMBO, GcalEditableCombo))
+#define GCAL_EDITABLE_COMBO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_EDITABLE_COMBO, GcalEditableComboClass))
+#define GCAL_IS_EDITABLE_COMBO(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_EDITABLE_COMBO))
+#define GCAL_IS_EDITABLE_COMBO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_EDITABLE_COMBO))
+#define GCAL_EDITABLE_COMBO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_EDITABLE_COMBO, GcalEditableComboClass))
+
+typedef struct _GcalEditableCombo GcalEditableCombo;
+typedef struct _GcalEditableComboClass GcalEditableComboClass;
+typedef struct _GcalEditableComboPrivate GcalEditableComboPrivate;
+
+struct _GcalEditableCombo
+{
+ GcalEditable parent;
+
+ /* add your public declarations here */
+ GcalEditableComboPrivate *priv;
+};
+
+struct _GcalEditableComboClass
+{
+ GcalEditableClass parent_class;
+};
+
+GType gcal_editable_combo_get_type (void);
+
+GtkWidget* gcal_editable_combo_new (void);
+
+GtkWidget* gcal_editable_combo_new_with_content (const gchar *content);
+
+void gcal_editable_combo_set_model (GcalEditableCombo *combo,
+ GtkTreeModel *model);
+
+void gcal_editable_combo_set_content (GcalEditableCombo *entry,
+ const gchar *content);
+G_END_DECLS
+
+#endif /* __GCAL_EDITABLE_COMBO_H__ */
diff --git a/src/gcal-editable-date.c b/src/gcal-editable-date.c
new file mode 100644
index 0000000..eb50b2d
--- /dev/null
+++ b/src/gcal-editable-date.c
@@ -0,0 +1,275 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 2 -*- */
+/*
+ * gcal-editable-date.c
+ *
+ * Copyright (C) 2012 - Erick PÃrez Castellanos
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gcal-editable-date.h"
+
+#include <glib/gi18n.h>
+
+struct _GcalEditableDatePrivate
+{
+ GtkWidget *view_widget;
+
+ GtkWidget *edit_widget;
+ GtkWidget *since_entry;
+ GtkWidget *until_entry;
+ GtkWidget *all_day_check;
+};
+
+static void gcal_editable_date_constructed (GObject *object);
+
+static void gcal_editable_date_enter_edit_mode (GcalEditable *editable);
+
+static void gcal_editable_date_leave_edit_mode (GcalEditable *editable);
+
+static void gcal_editable_date_clear (GcalEditable *editable);
+
+static void gcal_editable_date_split_set (GcalEditable *editable);
+
+G_DEFINE_TYPE (GcalEditableDate, gcal_editable_date, GCAL_TYPE_EDITABLE);
+
+static void gcal_editable_date_class_init (GcalEditableDateClass *klass)
+{
+ GcalEditableClass *editable_class;
+ GObjectClass *object_class;
+
+ editable_class = GCAL_EDITABLE_CLASS (klass);
+ editable_class->enter_edit_mode = gcal_editable_date_enter_edit_mode;
+ editable_class->leave_edit_mode = gcal_editable_date_leave_edit_mode;
+ editable_class->clear = gcal_editable_date_clear;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->constructed = gcal_editable_date_constructed;
+
+ g_type_class_add_private ((gpointer)klass, sizeof (GcalEditableDatePrivate));
+}
+
+
+
+static void gcal_editable_date_init (GcalEditableDate *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ GCAL_TYPE_EDITABLE_DATE,
+ GcalEditableDatePrivate);
+}
+
+static void
+gcal_editable_date_constructed (GObject *object)
+{
+ GcalEditableDatePrivate *priv;
+
+ priv = GCAL_EDITABLE_DATE (object)->priv;
+
+ if (G_OBJECT_CLASS (gcal_editable_date_parent_class)->constructed != NULL)
+ G_OBJECT_CLASS (gcal_editable_date_parent_class)->constructed (object);
+
+ priv->view_widget = gtk_label_new (NULL);
+ gtk_widget_show (priv->view_widget);
+ gtk_widget_set_valign (priv->view_widget, GTK_ALIGN_START);
+ gtk_widget_set_halign (priv->view_widget, GTK_ALIGN_START);
+ gcal_editable_set_view_widget (GCAL_EDITABLE (object), priv->view_widget);
+
+ priv->edit_widget = gtk_grid_new ();
+
+ priv->since_entry = gtk_entry_new ();
+ priv->until_entry = gtk_entry_new ();
+ priv->all_day_check = gtk_check_button_new_with_label (_("All day"));
+
+ gtk_grid_attach (GTK_GRID (priv->edit_widget),
+ priv->since_entry,
+ 0, 0, 1, 1);
+ gtk_grid_attach (GTK_GRID (priv->edit_widget),
+ gtk_label_new (_("to")),
+ 1, 0, 1, 1);
+ gtk_grid_attach (GTK_GRID (priv->edit_widget),
+ priv->until_entry,
+ 2, 0, 1, 1);
+ gtk_grid_attach (GTK_GRID (priv->edit_widget),
+ priv->all_day_check,
+ 0, 1, 3, 1);
+
+ gtk_grid_set_column_spacing (GTK_GRID (priv->edit_widget), 6);
+ gtk_widget_show_all (priv->edit_widget);
+
+ gcal_editable_set_edit_widget (GCAL_EDITABLE (object), priv->edit_widget);
+}
+
+static void
+gcal_editable_date_enter_edit_mode (GcalEditable *editable)
+{
+ GcalEditableDatePrivate *priv;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_DATE (editable));
+ priv = GCAL_EDITABLE_DATE (editable)->priv;
+
+ gcal_editable_date_split_set (editable);
+ gtk_widget_grab_focus (priv->since_entry);
+}
+
+static void
+gcal_editable_date_leave_edit_mode (GcalEditable *editable)
+{
+ GcalEditableDatePrivate *priv;
+ gchar *built;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_DATE (editable));
+ priv = GCAL_EDITABLE_DATE (editable)->priv;
+ built = NULL;
+
+ if (g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (priv->since_entry)), "") != 0)
+ built = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->since_entry)));
+
+ if (g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (priv->until_entry)), "") != 0)
+ {
+ if (built != NULL)
+ {
+ gchar *c;
+ c = built;
+ built = g_strconcat (c,
+ " - ",
+ gtk_entry_get_text (GTK_ENTRY (priv->until_entry)),
+ NULL);
+ g_free (c);
+ }
+ else
+ {
+ built = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->until_entry)));
+ }
+ }
+
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->all_day_check))
+ && built != NULL)
+ {
+ gchar *c;
+ c = built;
+ built = g_strconcat (c, _(" (All day)"), NULL);
+ g_free (c);
+ }
+
+ gtk_label_set_text (GTK_LABEL (priv->view_widget), built);
+ g_free (built);
+}
+
+static void
+gcal_editable_date_clear (GcalEditable *editable)
+{
+ GcalEditableDatePrivate *priv;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_DATE (editable));
+ priv = GCAL_EDITABLE_DATE (editable)->priv;
+
+ gtk_label_set_text (GTK_LABEL (priv->view_widget), NULL);
+ gtk_entry_set_text (GTK_ENTRY (priv->since_entry), NULL);
+ gtk_entry_set_text (GTK_ENTRY (priv->until_entry), NULL);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->all_day_check), FALSE);
+}
+
+static void
+gcal_editable_date_split_set (GcalEditable *editable)
+{
+ GcalEditableDatePrivate *priv;
+ gchar **tokens;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_DATE (editable));
+ priv = GCAL_EDITABLE_DATE (editable)->priv;
+
+ if (g_strcmp0 (gtk_label_get_text (GTK_LABEL (priv->view_widget)), "") != 0)
+ {
+ gchar *label_text;
+ if (g_str_has_suffix (
+ gtk_label_get_text (GTK_LABEL (priv->view_widget)),
+ _(" (All day)")))
+ {
+ const gchar *c;
+ c = gtk_label_get_text (GTK_LABEL (priv->view_widget));
+ label_text = g_strndup (c, g_strrstr (c, _(" (All day)")) - c);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->all_day_check),
+ TRUE);
+ }
+ else
+ {
+ label_text =
+ g_strdup (gtk_label_get_text (GTK_LABEL (priv->view_widget)));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->all_day_check),
+ FALSE);
+ }
+
+ tokens = g_strsplit (label_text, "-", -1);
+
+ if (tokens[0] != NULL)
+ {
+ tokens[0] = g_strstrip (tokens[0]);
+ gtk_entry_set_text (GTK_ENTRY (priv->since_entry), tokens[0]);
+ }
+ if (tokens[1] != NULL)
+ {
+ tokens[1] = g_strstrip (tokens[1]);
+ gtk_entry_set_text (GTK_ENTRY (priv->until_entry), tokens[1]);
+ }
+
+ g_strfreev (tokens);
+ }
+}
+
+/**
+ * gcal_editable_date_new:
+ *
+ * Init the date widget in EDIT_MODE
+ *
+ * Since: 0.1
+ * Returns: (transfer full):
+ **/
+GtkWidget*
+gcal_editable_date_new (void)
+{
+ GtkWidget *date = g_object_new (GCAL_TYPE_EDITABLE_DATE, NULL);
+ gcal_editable_enter_edit_mode (GCAL_EDITABLE (date));
+ return date;
+}
+
+/**
+ * gcal_editable_date_new_with_content:
+ *
+ * Init the date widget in VIEW_MODE
+ *
+ * Since 0.2
+ * Returns: (transfer full)
+ */
+GtkWidget*
+gcal_editable_date_new_with_content (const gchar* content)
+{
+ GtkWidget *date;
+ date = g_object_new (GCAL_TYPE_EDITABLE_DATE, NULL);
+ gcal_editable_date_set_content (GCAL_EDITABLE_DATE (date), content);
+ gcal_editable_leave_edit_mode (GCAL_EDITABLE (date));
+ return date;
+}
+
+void
+gcal_editable_date_set_content (GcalEditableDate *date,
+ const gchar *content)
+{
+ GcalEditableDatePrivate *priv;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_DATE (date));
+ priv = date->priv;
+
+ gtk_label_set_text (GTK_LABEL (priv->view_widget), content);
+}
diff --git a/src/gcal-editable-date.h b/src/gcal-editable-date.h
new file mode 100644
index 0000000..f589b95
--- /dev/null
+++ b/src/gcal-editable-date.h
@@ -0,0 +1,61 @@
+/*
+ * gcal-editable-date.h
+ *
+ * Copyright (C) 2012 - Erick PÃrez Castellanos
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GCAL_EDITABLE_DATE_H__
+#define __GCAL_EDITABLE_DATE_H__
+
+#include "gcal-editable.h"
+
+G_BEGIN_DECLS
+
+#define GCAL_TYPE_EDITABLE_DATE (gcal_editable_date_get_type ())
+#define GCAL_EDITABLE_DATE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_EDITABLE_DATE, GcalEditableDate))
+#define GCAL_EDITABLE_DATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_EDITABLE_DATE, GcalEditableDateClass))
+#define GCAL_IS_EDITABLE_DATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_EDITABLE_DATE))
+#define GCAL_IS_EDITABLE_DATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_EDITABLE_DATE))
+#define GCAL_EDITABLE_DATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_EDITABLE_DATE, GcalEditableDateClass))
+
+typedef struct _GcalEditableDate GcalEditableDate;
+typedef struct _GcalEditableDateClass GcalEditableDateClass;
+typedef struct _GcalEditableDatePrivate GcalEditableDatePrivate;
+
+struct _GcalEditableDate
+{
+ GcalEditable parent;
+
+ /* add your public declarations here */
+ GcalEditableDatePrivate *priv;
+};
+
+struct _GcalEditableDateClass
+{
+ GcalEditableClass parent_class;
+};
+
+GType gcal_editable_date_get_type (void);
+
+GtkWidget* gcal_editable_date_new (void);
+
+GtkWidget* gcal_editable_date_new_with_content (const gchar *content);
+
+void gcal_editable_date_set_content (GcalEditableDate *entry,
+ const gchar *content);
+G_END_DECLS
+
+#endif /* __GCAL_EDITABLE_DATE_H__ */
diff --git a/src/gcal-editable-entry.c b/src/gcal-editable-entry.c
index 874e852..1e83b82 100644
--- a/src/gcal-editable-entry.c
+++ b/src/gcal-editable-entry.c
@@ -22,35 +22,36 @@
struct _GcalEditableEntryPrivate
{
+ GtkWidget *view_widget;
GtkWidget *edit_widget;
-
- gboolean update_view;
};
static void gcal_editable_entry_constructed (GObject *object);
-static gchar* gcal_editable_entry_update_view_widget (GcalEditable *editable);
+static void gcal_editable_entry_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
static void gcal_editable_entry_enter_edit_mode (GcalEditable *editable);
-static gboolean gcal_editable_entry_key_pressed (GtkWidget *widget,
- GdkEventKey *event,
- gpointer user_data);
+static void gcal_editable_entry_leave_edit_mode (GcalEditable *editable);
-static void gcal_editable_entry_activated (GtkEntry *entry,
- gpointer user_data);
+static void gcal_editable_entry_clear (GcalEditable *editable);
G_DEFINE_TYPE (GcalEditableEntry, gcal_editable_entry, GCAL_TYPE_EDITABLE);
static void gcal_editable_entry_class_init (GcalEditableEntryClass *klass)
{
GcalEditableClass *editable_class;
+ GtkWidgetClass *widget_class;
GObjectClass *object_class;
editable_class = GCAL_EDITABLE_CLASS (klass);
- editable_class->update_view_widget = gcal_editable_entry_update_view_widget;
editable_class->enter_edit_mode = gcal_editable_entry_enter_edit_mode;
- editable_class->leave_edit_mode = NULL;
+ editable_class->leave_edit_mode = gcal_editable_entry_leave_edit_mode;
+ editable_class->clear = gcal_editable_entry_clear;
+
+ widget_class = GTK_WIDGET_CLASS (klass);
+ widget_class->size_allocate = gcal_editable_entry_size_allocate;
object_class = G_OBJECT_CLASS (klass);
object_class->constructed = gcal_editable_entry_constructed;
@@ -68,7 +69,7 @@ static void gcal_editable_entry_init (GcalEditableEntry *self)
}
static void
-gcal_editable_entry_constructed (GObject *object)
+gcal_editable_entry_constructed (GObject *object)
{
GcalEditableEntryPrivate *priv;
@@ -77,82 +78,83 @@ gcal_editable_entry_constructed (GObject *object)
if (G_OBJECT_CLASS (gcal_editable_entry_parent_class)->constructed != NULL)
G_OBJECT_CLASS (gcal_editable_entry_parent_class)->constructed (object);
+ priv->view_widget = gtk_label_new (NULL);
+ gtk_label_set_ellipsize (GTK_LABEL (priv->view_widget),
+ PANGO_ELLIPSIZE_END);
+ gtk_widget_show (priv->view_widget);
+ gtk_widget_set_valign (priv->view_widget, GTK_ALIGN_CENTER);
+ gtk_widget_set_halign (priv->view_widget, GTK_ALIGN_START);
+ gcal_editable_set_view_widget (GCAL_EDITABLE (object), priv->view_widget);
priv->edit_widget = gtk_entry_new ();
gtk_widget_show (priv->edit_widget);
gcal_editable_set_edit_widget (GCAL_EDITABLE (object), priv->edit_widget);
-
- g_signal_connect (priv->edit_widget,
- "key-press-event",
- G_CALLBACK (gcal_editable_entry_key_pressed),
- object);
- g_signal_connect (priv->edit_widget,
- "activate",
- G_CALLBACK (gcal_editable_entry_activated),
- object);
-
- priv->update_view = TRUE;
}
-static gchar*
-gcal_editable_entry_update_view_widget (GcalEditable *editable)
+static void
+gcal_editable_entry_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
{
GcalEditableEntryPrivate *priv;
- gchar *contents;
+ GtkAllocation view_allocation;
+ gint minimum;
+ gint natural;
- g_return_val_if_fail (GCAL_IS_EDITABLE_ENTRY (editable), NULL);
- priv = GCAL_EDITABLE_ENTRY (editable)->priv;
- contents = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->edit_widget)));
- return priv->update_view ? contents : NULL;
+ g_return_if_fail (GCAL_IS_EDITABLE_ENTRY (widget));
+ priv = GCAL_EDITABLE_ENTRY (widget)->priv;
+
+ if (GTK_WIDGET_CLASS (gcal_editable_entry_parent_class)->size_allocate != NULL)
+ GTK_WIDGET_CLASS (gcal_editable_entry_parent_class)->size_allocate (widget, allocation);
+
+ //FIXME: hack to keep the label thin
+ gtk_widget_get_preferred_height (priv->view_widget, &minimum, &natural);
+ gtk_widget_get_allocation (priv->view_widget, &view_allocation);
+ view_allocation.height = minimum;
+ gtk_widget_size_allocate (priv->view_widget, &view_allocation);
}
static void
gcal_editable_entry_enter_edit_mode (GcalEditable *editable)
{
GcalEditableEntryPrivate *priv;
- const gchar *contents;
g_return_if_fail (GCAL_IS_EDITABLE_ENTRY (editable));
priv = GCAL_EDITABLE_ENTRY (editable)->priv;
- contents = gcal_editable_get_view_contents (editable);
- gtk_entry_set_text (GTK_ENTRY (priv->edit_widget), contents);
+ gtk_entry_set_text (GTK_ENTRY (priv->edit_widget),
+ gtk_label_get_text (GTK_LABEL (priv->view_widget)));
gtk_editable_select_region (GTK_EDITABLE (priv->edit_widget), 0, -1);
gtk_widget_grab_focus (priv->edit_widget);
}
-static gboolean
-gcal_editable_entry_key_pressed (GtkWidget *widget,
- GdkEventKey *event,
- gpointer user_data)
+static void
+gcal_editable_entry_leave_edit_mode (GcalEditable *editable)
{
GcalEditableEntryPrivate *priv;
- g_return_val_if_fail (GCAL_IS_EDITABLE_ENTRY (user_data), FALSE);
- priv = GCAL_EDITABLE_ENTRY (user_data)->priv;
+ g_return_if_fail (GCAL_IS_EDITABLE_ENTRY (editable));
+ priv = GCAL_EDITABLE_ENTRY (editable)->priv;
- if (event->keyval == GDK_KEY_Escape)
- {
- priv->update_view = FALSE;
- gcal_editable_leave_edit_mode (GCAL_EDITABLE (user_data));
- return TRUE;
- }
- return FALSE;
+ gtk_label_set_text (GTK_LABEL (priv->view_widget),
+ gtk_entry_get_text (GTK_ENTRY (priv->edit_widget)));
}
static void
-gcal_editable_entry_activated (GtkEntry *entry,
- gpointer user_data)
+gcal_editable_entry_clear (GcalEditable *editable)
{
- if (gtk_entry_get_text_length (entry) != 0)
- {
- gcal_editable_leave_edit_mode (GCAL_EDITABLE (user_data));
- }
+ GcalEditableEntryPrivate *priv;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_ENTRY (editable));
+ priv = GCAL_EDITABLE_ENTRY (editable)->priv;
+
+ gtk_label_set_text (GTK_LABEL (priv->view_widget), NULL);
+ gtk_entry_set_text (GTK_ENTRY (priv->edit_widget), NULL);
}
/**
* gcal_editable_entry_new:
- * @date:
+ *
+ * Init the entry in EDIT_MODE
*
* Since: 0.1
* Returns: (transfer full):
@@ -160,5 +162,41 @@ gcal_editable_entry_activated (GtkEntry *entry,
GtkWidget*
gcal_editable_entry_new (void)
{
- return g_object_new (GCAL_TYPE_EDITABLE_ENTRY, NULL);
+ GtkWidget *entry = g_object_new (GCAL_TYPE_EDITABLE_ENTRY, NULL);
+ gcal_editable_enter_edit_mode (GCAL_EDITABLE (entry));
+ return entry;
+}
+
+/**
+ * gcal_editable_entry_new_with_content:
+ *
+ * Init the entry in VIEW_MODE
+ *
+ * Since 0.2
+ * Returns: (transfer full)
+ */
+GtkWidget*
+gcal_editable_entry_new_with_content (const gchar* content)
+{
+ GtkWidget *entry;
+ entry = g_object_new (GCAL_TYPE_EDITABLE_ENTRY, NULL);
+ gcal_editable_entry_set_content (GCAL_EDITABLE_ENTRY (entry), content, FALSE);
+ gcal_editable_leave_edit_mode (GCAL_EDITABLE (entry));
+ return entry;
+}
+
+void
+gcal_editable_entry_set_content (GcalEditableEntry *entry,
+ const gchar *content,
+ gboolean use_markup)
+{
+ GcalEditableEntryPrivate *priv;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_ENTRY (entry));
+ priv = entry->priv;
+
+ if (use_markup)
+ gtk_label_set_markup (GTK_LABEL (priv->view_widget), content);
+ else
+ gtk_label_set_text (GTK_LABEL (priv->view_widget), content);
}
diff --git a/src/gcal-editable-entry.h b/src/gcal-editable-entry.h
index b3017b6..3681ff6 100644
--- a/src/gcal-editable-entry.h
+++ b/src/gcal-editable-entry.h
@@ -1,5 +1,5 @@
/*
- * gcal-editable.h
+ * gcal-editable-entry.h
*
* Copyright (C) 2012 - Erick PÃrez Castellanos
*
@@ -52,6 +52,11 @@ GType gcal_editable_entry_get_type (void);
GtkWidget* gcal_editable_entry_new (void);
+GtkWidget* gcal_editable_entry_new_with_content (const gchar *content);
+
+void gcal_editable_entry_set_content (GcalEditableEntry *entry,
+ const gchar *content,
+ gboolean use_markup);
G_END_DECLS
#endif /* __GCAL_EDITABLE_ENTRY_H__ */
diff --git a/src/gcal-editable-text.c b/src/gcal-editable-text.c
new file mode 100644
index 0000000..748996e
--- /dev/null
+++ b/src/gcal-editable-text.c
@@ -0,0 +1,190 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 2 -*- */
+/*
+ * gcal-editable-text.c
+ *
+ * Copyright (C) 2012 - Erick PÃrez Castellanos
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gcal-editable-text.h"
+
+struct _GcalEditableTextPrivate
+{
+ GtkWidget *view_widget;
+
+ GtkWidget *desc_frame;
+ GtkWidget *scrolled_win;
+ GtkWidget *edit_widget;
+};
+
+static void gcal_editable_text_constructed (GObject *object);
+
+static void gcal_editable_text_enter_edit_mode (GcalEditable *editable);
+
+static void gcal_editable_text_leave_edit_mode (GcalEditable *editable);
+
+static void gcal_editable_text_clear (GcalEditable *editable);
+
+G_DEFINE_TYPE (GcalEditableText, gcal_editable_text, GCAL_TYPE_EDITABLE);
+
+static void gcal_editable_text_class_init (GcalEditableTextClass *klass)
+{
+ GcalEditableClass *editable_class;
+ GObjectClass *object_class;
+
+ editable_class = GCAL_EDITABLE_CLASS (klass);
+ editable_class->enter_edit_mode = gcal_editable_text_enter_edit_mode;
+ editable_class->leave_edit_mode = gcal_editable_text_leave_edit_mode;
+ editable_class->clear = gcal_editable_text_clear;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->constructed = gcal_editable_text_constructed;
+
+ g_type_class_add_private ((gpointer)klass, sizeof (GcalEditableTextPrivate));
+}
+
+
+
+static void gcal_editable_text_init (GcalEditableText *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ GCAL_TYPE_EDITABLE_TEXT,
+ GcalEditableTextPrivate);
+}
+
+static void
+gcal_editable_text_constructed (GObject *object)
+{
+ GcalEditableTextPrivate *priv;
+
+ priv = GCAL_EDITABLE_TEXT (object)->priv;
+
+ if (G_OBJECT_CLASS (gcal_editable_text_parent_class)->constructed != NULL)
+ G_OBJECT_CLASS (gcal_editable_text_parent_class)->constructed (object);
+
+ priv->view_widget = gtk_label_new (NULL);
+ gtk_label_set_ellipsize (GTK_LABEL (priv->view_widget),
+ PANGO_ELLIPSIZE_END);
+ gtk_widget_show (priv->view_widget);
+ gtk_widget_set_valign (priv->view_widget, GTK_ALIGN_START);
+ gtk_widget_set_halign (priv->view_widget, GTK_ALIGN_START);
+ gcal_editable_set_view_widget (GCAL_EDITABLE (object), priv->view_widget);
+
+ priv->edit_widget = gtk_text_view_new ();
+ gtk_widget_show (priv->edit_widget);
+
+ priv->scrolled_win = gtk_scrolled_window_new (NULL, NULL);
+ gtk_container_add (GTK_CONTAINER (priv->scrolled_win), priv->edit_widget);
+
+ priv->desc_frame = gtk_frame_new (NULL);
+ gtk_container_add (GTK_CONTAINER (priv->desc_frame), priv->scrolled_win);
+
+ gtk_widget_show (priv->desc_frame);
+ gcal_editable_set_edit_widget (GCAL_EDITABLE (object), priv->desc_frame);
+}
+
+static void
+gcal_editable_text_enter_edit_mode (GcalEditable *editable)
+{
+ GcalEditableTextPrivate *priv;
+ GtkTextBuffer *buffer;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_TEXT (editable));
+ priv = GCAL_EDITABLE_TEXT (editable)->priv;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->edit_widget));
+ gtk_text_buffer_set_text (buffer,
+ gtk_label_get_text (GTK_LABEL (priv->view_widget)),
+ -1);
+
+ gtk_widget_grab_focus (priv->edit_widget);
+}
+
+static void
+gcal_editable_text_leave_edit_mode (GcalEditable *editable)
+{
+ GcalEditableTextPrivate *priv;
+ GtkTextBuffer *buffer;
+ GtkTextIter start, end;
+ gchar *text;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_TEXT (editable));
+ priv = GCAL_EDITABLE_TEXT (editable)->priv;
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->edit_widget));
+ gtk_text_buffer_get_start_iter (buffer, &start);
+ gtk_text_buffer_get_end_iter (buffer, &end);
+ text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+ gtk_label_set_text (GTK_LABEL (priv->view_widget), text);
+ g_free (text);
+}
+
+static void
+gcal_editable_text_clear (GcalEditable *editable)
+{
+ GcalEditableTextPrivate *priv;
+ GtkTextBuffer *buffer;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_TEXT (editable));
+ priv = GCAL_EDITABLE_TEXT (editable)->priv;
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->edit_widget));
+ gtk_text_buffer_set_text (buffer, NULL, -1);
+}
+
+/* Public API */
+/**
+ * gcal_editable_text_new:
+ *
+ * Init the entry in EDIT_MODE
+ *
+ * Since: 0.1
+ * Returns: (transfer full):
+ **/
+GtkWidget*
+gcal_editable_text_new (void)
+{
+ GtkWidget *entry = g_object_new (GCAL_TYPE_EDITABLE_TEXT, NULL);
+ gcal_editable_enter_edit_mode (GCAL_EDITABLE (entry));
+ return entry;
+}
+
+/**
+ * gcal_editable_text_new_with_content:
+ *
+ * Init the entry in VIEW_MODE
+ *
+ * Since 0.2
+ * Returns: (transfer full)
+ */
+GtkWidget*
+gcal_editable_text_new_with_content (const gchar* content)
+{
+ GtkWidget *entry;
+ entry = g_object_new (GCAL_TYPE_EDITABLE_TEXT, NULL);
+ gcal_editable_text_set_content (GCAL_EDITABLE_TEXT (entry), content);
+ gcal_editable_leave_edit_mode (GCAL_EDITABLE (entry));
+ return entry;
+}
+
+void
+gcal_editable_text_set_content (GcalEditableText *entry,
+ const gchar *content)
+{
+ GcalEditableTextPrivate *priv;
+
+ g_return_if_fail (GCAL_IS_EDITABLE_TEXT (entry));
+ priv = entry->priv;
+
+ gtk_label_set_text (GTK_LABEL (priv->view_widget), content);
+}
diff --git a/src/gcal-editable-text.h b/src/gcal-editable-text.h
new file mode 100644
index 0000000..5b6f52c
--- /dev/null
+++ b/src/gcal-editable-text.h
@@ -0,0 +1,61 @@
+/*
+ * gcal-editable-text.h
+ *
+ * Copyright (C) 2012 - Erick PÃrez Castellanos
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GCAL_EDITABLE_TEXT_H__
+#define __GCAL_EDITABLE_TEXT_H__
+
+#include "gcal-editable.h"
+
+G_BEGIN_DECLS
+
+#define GCAL_TYPE_EDITABLE_TEXT (gcal_editable_text_get_type ())
+#define GCAL_EDITABLE_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_EDITABLE_TEXT, GcalEditableText))
+#define GCAL_EDITABLE_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_EDITABLE_TEXT, GcalEditableTextClass))
+#define GCAL_IS_EDITABLE_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_EDITABLE_TEXT))
+#define GCAL_IS_EDITABLE_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_EDITABLE_TEXT))
+#define GCAL_EDITABLE_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_EDITABLE_TEXT, GcalEditableTextClass))
+
+typedef struct _GcalEditableText GcalEditableText;
+typedef struct _GcalEditableTextClass GcalEditableTextClass;
+typedef struct _GcalEditableTextPrivate GcalEditableTextPrivate;
+
+struct _GcalEditableText
+{
+ GcalEditable parent;
+
+ /* add your public declarations here */
+ GcalEditableTextPrivate *priv;
+};
+
+struct _GcalEditableTextClass
+{
+ GcalEditableClass parent_class;
+};
+
+GType gcal_editable_text_get_type (void);
+
+GtkWidget* gcal_editable_text_new (void);
+
+GtkWidget* gcal_editable_text_new_with_content (const gchar *content);
+
+void gcal_editable_text_set_content (GcalEditableText *entry,
+ const gchar *content);
+G_END_DECLS
+
+#endif /* __GCAL_EDITABLE_TEXT_H__ */
diff --git a/src/gcal-editable.c b/src/gcal-editable.c
index b4a3dd9..91eeaae 100644
--- a/src/gcal-editable.c
+++ b/src/gcal-editable.c
@@ -19,13 +19,12 @@
*/
#include "gcal-editable.h"
-#include "gcal-utils.h"
struct _GcalEditablePrivate
{
- GtkWidget *view_widget;
GtkWidget *event_box;
+ gboolean locked;
GcalEditableMode mode : 1;
};
@@ -44,7 +43,6 @@ static void gcal_editable_class_init (GcalEditableClass *klass)
object_class = G_OBJECT_CLASS (klass);
object_class->constructed = gcal_editable_constructed;
- klass->update_view_widget = NULL;
klass->enter_edit_mode = gcal_editable_enter_edit_mode;
klass->leave_edit_mode = gcal_editable_leave_edit_mode;
@@ -61,24 +59,22 @@ static void gcal_editable_init (GcalEditable *self)
}
static void
-gcal_editable_constructed (GObject *object)
+gcal_editable_constructed (GObject *object)
{
GcalEditablePrivate *priv;
priv = GCAL_EDITABLE (object)->priv;
+ priv->locked = FALSE;
priv->mode = GCAL_VIEW_MODE;
- priv->view_widget = gtk_label_new (NULL);
+
priv->event_box = gtk_event_box_new ();
- gtk_container_add (GTK_CONTAINER (priv->event_box),
- priv->view_widget);
gtk_widget_show_all (priv->event_box);
gtk_notebook_insert_page (GTK_NOTEBOOK (object),
priv->event_box,
NULL,
0);
- gtk_notebook_set_current_page (GTK_NOTEBOOK (object), 0);
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (object), FALSE);
g_signal_connect (priv->event_box,
@@ -99,15 +95,15 @@ gcal_editable_button_pressed (GtkWidget *widget,
/* Public API */
void
-gcal_editable_set_view_contents (GcalEditable *editable,
- const gchar *contents)
+gcal_editable_set_view_widget (GcalEditable *editable,
+ GtkWidget *widget)
{
GcalEditablePrivate *priv;
g_return_if_fail (GCAL_IS_EDITABLE (editable));
priv = editable->priv;
- gtk_label_set_text (GTK_LABEL (priv->view_widget), contents);
+ gtk_container_add (GTK_CONTAINER (priv->event_box), widget);
}
void
@@ -122,26 +118,23 @@ gcal_editable_set_edit_widget (GcalEditable *editable,
gtk_notebook_insert_page (GTK_NOTEBOOK (editable), widget, NULL, 1);
}
-const gchar*
-gcal_editable_get_view_contents (GcalEditable *editable)
-{
- GcalEditablePrivate *priv;
-
- g_return_val_if_fail (GCAL_IS_EDITABLE (editable), NULL);
- priv = GCAL_EDITABLE (editable)->priv;
- return gtk_label_get_text (GTK_LABEL (priv->view_widget));
-}
-
void
gcal_editable_enter_edit_mode (GcalEditable *editable)
{
GcalEditablePrivate *priv;
+ GtkWidget *view_widget;
+ GtkWidget *edit_widget;
g_return_if_fail (GCAL_IS_EDITABLE (editable));
priv = editable->priv;
- if (priv->mode == GCAL_VIEW_MODE)
+ if (! priv->locked && priv->mode == GCAL_VIEW_MODE)
{
+ edit_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (editable), 1);
+ gtk_widget_show_all (edit_widget);
+ view_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (editable), 0);
+ gtk_widget_hide (view_widget);
+
gtk_notebook_set_current_page (GTK_NOTEBOOK (editable), 1);
if (GCAL_EDITABLE_GET_CLASS (editable)->enter_edit_mode != NULL)
@@ -155,19 +148,18 @@ void
gcal_editable_leave_edit_mode (GcalEditable *editable)
{
GcalEditablePrivate *priv;
- gchar *str;
+ GtkWidget *view_widget;
+ GtkWidget *edit_widget;
g_return_if_fail (GCAL_IS_EDITABLE (editable));
priv = editable->priv;
- if (priv->mode == GCAL_EDIT_MODE)
+ if (! priv->locked && priv->mode == GCAL_EDIT_MODE)
{
- str = GCAL_EDITABLE_GET_CLASS (editable)->update_view_widget (editable);
- if (str != NULL)
- {
- gtk_label_set_text (GTK_LABEL (priv->view_widget), str);
- g_free (str);
- }
+ edit_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (editable), 1);
+ gtk_widget_hide (edit_widget);
+ view_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (editable), 0);
+ gtk_widget_show_all (view_widget);
gtk_notebook_set_current_page (GTK_NOTEBOOK (editable), 0);
@@ -177,3 +169,50 @@ gcal_editable_leave_edit_mode (GcalEditable *editable)
priv->mode = GCAL_VIEW_MODE;
}
}
+
+/**
+ * gcal_editable_clear:
+ * @editable: A GcalEditable widget
+ *
+ * Will clear the content of the widgets, and set it into GCAL_EDIT_MODE
+ */
+void
+gcal_editable_clear (GcalEditable *editable)
+{
+ g_return_if_fail (GCAL_IS_EDITABLE (editable));
+
+ if (GCAL_EDITABLE_GET_CLASS (editable)->clear != NULL)
+ GCAL_EDITABLE_GET_CLASS (editable)->clear (editable);
+
+ GCAL_EDITABLE_GET_CLASS (editable)->enter_edit_mode (editable);
+}
+
+GcalEditableMode
+gcal_editable_get_mode (GcalEditable *editable)
+{
+ GcalEditablePrivate *priv;
+
+ g_return_val_if_fail (GCAL_IS_EDITABLE (editable), GCAL_VIEW_MODE);
+ priv = editable->priv;
+ return priv->mode;
+}
+
+void
+gcal_editable_lock (GcalEditable *editable)
+{
+ GcalEditablePrivate *priv;
+
+ g_return_if_fail (GCAL_IS_EDITABLE (editable));
+ priv = editable->priv;
+ priv->locked = TRUE;
+}
+
+void
+gcal_editable_unlock (GcalEditable *editable)
+{
+ GcalEditablePrivate *priv;
+
+ g_return_if_fail (GCAL_IS_EDITABLE (editable));
+ priv = editable->priv;
+ priv->locked = FALSE;
+}
diff --git a/src/gcal-editable.h b/src/gcal-editable.h
index c7dfa43..e17430d 100644
--- a/src/gcal-editable.h
+++ b/src/gcal-editable.h
@@ -20,6 +20,8 @@
#ifndef __GCAL_EDITABLE_H__
#define __GCAL_EDITABLE_H__
+#include "gcal-utils.h"
+
#include <gtk/gtk.h>
G_BEGIN_DECLS
@@ -48,24 +50,30 @@ struct _GcalEditableClass
GtkNotebookClass parent_class;
/* virtual methods */
- gchar* (*update_view_widget) (GcalEditable *editable);
void (*enter_edit_mode) (GcalEditable *editable);
void (*leave_edit_mode) (GcalEditable *editable);
+ void (*clear) (GcalEditable *editable);
};
-GType gcal_editable_get_type (void);
+GType gcal_editable_get_type (void);
+
+void gcal_editable_set_view_widget (GcalEditable *editable,
+ GtkWidget *widget);
+
+void gcal_editable_set_edit_widget (GcalEditable *editable,
+ GtkWidget *widget);
+
+void gcal_editable_enter_edit_mode (GcalEditable *editable);
-void gcal_editable_set_view_contents (GcalEditable *editable,
- const gchar *contents);
+void gcal_editable_leave_edit_mode (GcalEditable *editable);
-void gcal_editable_set_edit_widget (GcalEditable *editable,
- GtkWidget *widget);
+void gcal_editable_clear (GcalEditable *editable);
-const gchar* gcal_editable_get_view_contents (GcalEditable *editable);
+GcalEditableMode gcal_editable_get_mode (GcalEditable *editable);
-void gcal_editable_enter_edit_mode (GcalEditable *editable);
+void gcal_editable_lock (GcalEditable *editable);
-void gcal_editable_leave_edit_mode (GcalEditable *editable);
+void gcal_editable_unlock (GcalEditable *editable);
G_END_DECLS
diff --git a/src/gcal-event-view.c b/src/gcal-event-view.c
index 5251113..478bc67 100644
--- a/src/gcal-event-view.c
+++ b/src/gcal-event-view.c
@@ -19,37 +19,45 @@
#include "gcal-event-view.h"
#include "gcal-editable-entry.h"
+#include "gcal-editable-text.h"
+#include "gcal-editable-date.h"
+#include "gcal-editable-combo.h"
#include <glib/gi18n.h>
struct _GcalEventViewPrivate
{
- gboolean edit_mode;
+ GcalEditableMode edit_mode;
+ gchar *source_uid;
+ gchar *event_uid;
+ GSList *e_widgets;
- GtkWidget *e_what;
- GtkWidget *e_host;
+ GtkWidget *e_what;
+ GtkWidget *e_host;
- GtkWidget *e_since;
- GtkWidget *e_until;
- GtkWidget *c_all_day;
+ GtkWidget *d_when;
- GtkWidget *e_where;
+ GtkWidget *e_where;
- GtkWidget *cb_cal;
+ GtkWidget *cb_cal;
- GtkWidget *t_desc;
+ GtkWidget *t_desc;
- GtkWidget *attending_yes;
- GtkWidget *attending_maybe;
- GtkWidget *attending_no;
+ GtkWidget *attending_yes;
+ GtkWidget *attending_maybe;
+ GtkWidget *attending_no;
- GcalManager *manager;
+ GcalManager *manager;
};
static void gcal_event_view_constructed (GObject *object);
+static void gcal_event_view_finalize (GObject *object);
+
static void gcal_event_view_set_combo_box (GcalEventView *view);
+static void gcal_event_view_update (GcalEventView *view);
+
G_DEFINE_TYPE(GcalEventView, gcal_event_view, GTK_TYPE_GRID)
static void
@@ -59,6 +67,7 @@ gcal_event_view_class_init(GcalEventViewClass *klass)
object_class = G_OBJECT_CLASS (klass);
object_class->constructed = gcal_event_view_constructed;
+ object_class->finalize = gcal_event_view_finalize;
g_type_class_add_private((gpointer)klass, sizeof(GcalEventViewPrivate));
}
@@ -82,11 +91,9 @@ gcal_event_view_constructed (GObject *object)
GtkWidget *what;
GtkWidget *host;
GtkWidget *when;
- GtkWidget *to;
GtkWidget *calendar;
GtkWidget *where;
GtkWidget *desc;
- GtkWidget *desc_frame;
GtkWidget *attending;
GtkWidget *attending_box;
@@ -94,22 +101,33 @@ gcal_event_view_constructed (GObject *object)
if (G_OBJECT_CLASS (gcal_event_view_parent_class)->constructed != NULL)
G_OBJECT_CLASS (gcal_event_view_parent_class)->constructed (object);
+ priv->edit_mode = GCAL_EDIT_MODE;
+ priv->source_uid = NULL;
+ priv->event_uid = NULL;
+ priv->e_widgets = NULL;
+
priv->e_what = gcal_editable_entry_new ();
- gcal_editable_enter_edit_mode (GCAL_EDITABLE (priv->e_what));
+ priv->e_widgets = g_slist_append (priv->e_widgets, priv->e_what);
priv->e_host = gcal_editable_entry_new ();
- gcal_editable_enter_edit_mode (GCAL_EDITABLE (priv->e_host));
+ priv->e_widgets = g_slist_append (priv->e_widgets, priv->e_host);
- priv->e_since = gtk_entry_new ();
- priv->e_until = gtk_entry_new ();
- priv->c_all_day = gtk_check_button_new_with_label (_("All day"));
+ priv->d_when = gcal_editable_date_new ();
+ priv->e_widgets = g_slist_append (priv->e_widgets, priv->d_when);
- priv->e_where = gtk_entry_new ();
+ priv->e_where = gcal_editable_entry_new ();
+ priv->e_widgets = g_slist_append (priv->e_widgets, priv->e_where);
- priv->cb_cal = gtk_combo_box_new ();
+ /* FIXME: turn me into a GcalEditable Widget */
+ priv->cb_cal = gcal_editable_combo_new ();
+ priv->e_widgets = g_slist_append (priv->e_widgets, priv->cb_cal);
gtk_widget_set_halign (priv->cb_cal, GTK_ALIGN_START);
- priv->t_desc = gtk_text_view_new ();
+ priv->t_desc = gcal_editable_text_new ();
+ priv->e_widgets = g_slist_append (priv->e_widgets, priv->t_desc);
+ /* FIXME: do something with this to add it on the slist of widget
+ * something like, turning all the three into on widget
+ */
priv->attending_yes = gtk_toggle_button_new_with_label (_("Yes"));
priv->attending_maybe = gtk_toggle_button_new_with_label (_("Maybe"));
priv->attending_no = gtk_toggle_button_new_with_label (_("No"));
@@ -133,64 +151,165 @@ gcal_event_view_constructed (GObject *object)
gtk_grid_attach (GTK_GRID (object), priv->e_host, 5, 0, 1, 1);
when = gtk_label_new (_("When"));
+ gtk_widget_set_valign (when, GTK_ALIGN_START);
gtk_widget_set_halign (when, GTK_ALIGN_END);
gtk_grid_attach (GTK_GRID (object), when, 0, 1, 1, 1);
- gtk_grid_attach (GTK_GRID (object), priv->e_since, 1, 1, 1, 1);
- to = gtk_label_new (_("to"));
- gtk_grid_attach (GTK_GRID (object), to, 2, 1, 1, 1);
- gtk_grid_attach (GTK_GRID (object), priv->e_until, 3, 1, 1, 1);
- gtk_grid_attach (GTK_GRID (object), priv->c_all_day, 1, 2, 1, 1);
+ gtk_grid_attach (GTK_GRID (object), priv->d_when, 1, 1, 1, 1);
where = gtk_label_new (_("Where"));
gtk_widget_set_halign (where, GTK_ALIGN_END);
- gtk_grid_attach (GTK_GRID (object), where, 0, 3, 1, 1);
- gtk_grid_attach (GTK_GRID (object), priv->e_where, 1, 3, 3, 1);
+ gtk_grid_attach (GTK_GRID (object), where, 0, 2, 1, 1);
+ gtk_grid_attach (GTK_GRID (object), priv->e_where, 1, 2, 3, 1);
calendar = gtk_label_new (_("Calendar"));
gtk_widget_set_halign (calendar, GTK_ALIGN_END);
- gtk_grid_attach (GTK_GRID (object), calendar, 0, 4, 1, 1);
- gtk_grid_attach (GTK_GRID (object), priv->cb_cal, 1, 4, 3, 1);
+ gtk_grid_attach (GTK_GRID (object), calendar, 0, 3, 1, 1);
+ gtk_grid_attach (GTK_GRID (object), priv->cb_cal, 1, 3, 3, 1);
desc = gtk_label_new (_("Description"));
gtk_widget_set_halign (desc, GTK_ALIGN_END);
gtk_widget_set_valign (desc, GTK_ALIGN_START);
- gtk_grid_attach (GTK_GRID (object), desc, 0, 5, 1, 1);
- desc_frame = gtk_frame_new (NULL);
- gtk_container_add (GTK_CONTAINER (desc_frame), priv->t_desc);
- gtk_widget_set_size_request (desc_frame, -1, 200);
- gtk_grid_attach (GTK_GRID (object), desc_frame, 1, 5, 3, 1);
+ gtk_grid_attach (GTK_GRID (object), desc, 0, 4, 1, 1);
+ gtk_widget_set_size_request (priv->t_desc, -1, 200);
+ gtk_grid_attach (GTK_GRID (object), priv->t_desc, 1, 4, 3, 1);
attending = gtk_label_new (_("Attending"));
gtk_widget_set_halign (attending, GTK_ALIGN_END);
- gtk_grid_attach (GTK_GRID (object), attending, 0, 6, 1, 1);
- gtk_grid_attach (GTK_GRID (object), attending_box, 1, 6, 3, 1);
+ gtk_grid_attach (GTK_GRID (object), attending, 0, 5, 1, 1);
+ gtk_grid_attach (GTK_GRID (object), attending_box, 1, 5, 3, 1);
- gtk_grid_set_row_spacing (GTK_GRID (object), 10);
- gtk_grid_set_column_spacing (GTK_GRID (object), 6);
+ gtk_grid_set_row_spacing (GTK_GRID (object), 16);
+ gtk_grid_set_column_spacing (GTK_GRID (object), 16);
gtk_widget_show_all (GTK_WIDGET (object));
}
static void
-gcal_event_view_set_combo_box (GcalEventView *view)
+gcal_event_view_finalize (GObject *object)
{
GcalEventViewPrivate *priv;
- GtkCellRenderer *renderer;
+ priv = GCAL_EVENT_VIEW (object)->priv;
+
+ if (priv->source_uid != NULL)
+ g_free (priv->source_uid);
+ if (priv->event_uid != NULL)
+ g_free (priv->event_uid);
+
+ if (G_OBJECT_CLASS (gcal_event_view_parent_class)->finalize != NULL)
+ G_OBJECT_CLASS (gcal_event_view_parent_class)->finalize (object);
+}
+
+static void
+gcal_event_view_set_combo_box (GcalEventView *view)
+{
+ GcalEventViewPrivate *priv;
priv = view->priv;
- gtk_combo_box_set_model (
- GTK_COMBO_BOX (priv->cb_cal),
+ gcal_editable_combo_set_model (
+ GCAL_EDITABLE_COMBO (priv->cb_cal),
GTK_TREE_MODEL (gcal_manager_get_sources_model (priv->manager)));
- renderer = gtk_cell_renderer_text_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->cb_cal), renderer, TRUE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->cb_cal),
- renderer,
- "text",
- 1,
- NULL);
- gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cb_cal), 0);
}
+/**
+ * gcal_event_view_update:
+ * @view: A GcalEventView widget
+ *
+ * Update the contents of the widget.
+ */
+static void
+gcal_event_view_update (GcalEventView *view)
+{
+ GcalEventViewPrivate *priv;
+
+ g_return_if_fail (GCAL_IS_EVENT_VIEW (view));
+ priv = view->priv;
+
+ if (priv->event_uid == NULL)
+ {
+ /* Setting the widget to blank state */
+ g_slist_foreach (priv->e_widgets, (GFunc) gcal_editable_clear, NULL);
+ }
+ else
+ {
+ gchar *summary;
+ gchar *organizer_label;
+ gchar **organizer;
+ gchar *when;
+ const gchar *location;
+ gchar *description;
+
+ g_slist_foreach (priv->e_widgets, (GFunc) gcal_editable_leave_edit_mode, NULL);
+
+ summary = gcal_manager_get_event_summary (priv->manager,
+ priv->source_uid,
+ priv->event_uid);
+ gcal_editable_entry_set_content (GCAL_EDITABLE_ENTRY (priv->e_what),
+ summary,
+ FALSE);
+
+ /* FIXME: Hide when no shost, hide the panel completely */
+ organizer = gcal_manager_get_event_organizer (priv->manager,
+ priv->source_uid,
+ priv->event_uid);
+ if (organizer == NULL)
+ {
+ //HIDE PANEL
+ ;
+ }
+ else
+ {
+ gchar *link;
+ link = g_utf8_strdown (organizer[1], -1);
+ organizer_label = g_strdup_printf ("<a href=\"%s\">%s</a>",
+ link,
+ organizer[0]);
+ gcal_editable_entry_set_content (GCAL_EDITABLE_ENTRY (priv->e_host),
+ organizer_label,
+ TRUE);
+
+ g_free (organizer_label);
+ g_free (link);
+ g_strfreev (organizer);
+ }
+
+ when = gcal_manager_get_event_date (priv->manager,
+ priv->source_uid,
+ priv->event_uid);
+
+ gcal_editable_date_set_content (GCAL_EDITABLE_DATE (priv->d_when),
+ when);
+
+ location = gcal_manager_get_event_location (priv->manager,
+ priv->source_uid,
+ priv->event_uid);
+ gcal_editable_entry_set_content (GCAL_EDITABLE_ENTRY (priv->e_where),
+ location,
+ FALSE);
+
+ gcal_editable_combo_set_content (
+ GCAL_EDITABLE_COMBO (priv->cb_cal),
+ gcal_manager_get_source_name (priv->manager, priv->source_uid));
+
+ description = gcal_manager_get_event_description (priv->manager,
+ priv->source_uid,
+ priv->event_uid);
+ gcal_editable_text_set_content (GCAL_EDITABLE_TEXT (priv->t_desc),
+ description);
+
+ g_free (description);
+ g_free (when);
+ g_free (summary);
+ }
+}
+
+/* Public API */
+
+/**
+ * gcal_event_view_new_with_manager:
+ * @manager: A GcalManager instance, the app singleton
+ *
+ * Returns: (transfer full):
+ */
GtkWidget*
gcal_event_view_new_with_manager (GcalManager *manager)
{
@@ -204,3 +323,74 @@ gcal_event_view_new_with_manager (GcalManager *manager)
return view;
}
+
+/**
+ * gcal_event_view_load_new:
+ * @view: A GcalEventView widget
+ *
+ * Sets the widget in a edit mode for creating a new
+ * event.
+ */
+void
+gcal_event_view_load_new (GcalEventView *view)
+{
+}
+
+/**
+ * gcal_event_view_load_event:
+ * @view: A GcalEventView widget
+ * @event_uuid: the uuid of the event as referenced in GcalManager
+ *
+ * Loads events data in the widget, for viewing
+ */
+void
+gcal_event_view_load_event (GcalEventView *view,
+ const gchar *event_uuid)
+{
+ GcalEventViewPrivate *priv;
+ gchar **tokens;
+
+ g_return_if_fail (GCAL_IS_EVENT_VIEW (view));
+ priv = view->priv;
+
+ if (event_uuid != NULL)
+ {
+ tokens = g_strsplit (event_uuid, ":", -1);
+
+ if (gcal_manager_exists_event (priv->manager, tokens[0], tokens[1]))
+ {
+ if (priv->source_uid != NULL)
+ g_free (priv->source_uid);
+ if (priv->event_uid != NULL)
+ g_free (priv->event_uid);
+
+ priv->source_uid = tokens[0];
+ priv->event_uid = tokens[1];
+ gcal_event_view_update (view);
+ }
+ }
+}
+
+/**
+ * gcal_event_view_enter_edit_mode:
+ * @view: A GcalEventView widget
+ *
+ * Sets the widget into edit mode. If it has an event set
+ * then edit that events, otherwise acts as load_new method.
+ */
+void
+gcal_event_view_enter_edit_mode (GcalEventView *view)
+{
+}
+
+/**
+ * gcal_event_view_leave_edit_mode:
+ * @view: A GcalEventView widget
+ *
+ * Sets the widget into view.
+ * FIXME: Maybe this is the place for update/create the event.
+ */
+void
+gcal_event_view_leave_edit_mode (GcalEventView *view)
+{
+}
diff --git a/src/gcal-event-view.h b/src/gcal-event-view.h
index f65ee91..d1a658b 100644
--- a/src/gcal-event-view.h
+++ b/src/gcal-event-view.h
@@ -51,7 +51,16 @@ struct _GcalEventViewClass
GType gcal_event_view_get_type (void);
-GtkWidget* gcal_event_view_new_with_manager (GcalManager *manager);
+GtkWidget* gcal_event_view_new_with_manager (GcalManager *manager);
+
+void gcal_event_view_load_new (GcalEventView *view);
+
+void gcal_event_view_load_event (GcalEventView *view,
+ const gchar *event_uuid);
+
+void gcal_event_view_enter_edit_mode (GcalEventView *view);
+
+void gcal_event_view_leave_edit_mode (GcalEventView *view);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]