/* less expensive than G_TYPE_INSTANCE_GET_PRIVATE */
#define MILK_MAIN_WINDOW_PRIVATE(o) ((MILK_MAIN_WINDOW ((o)))->priv)
+#define NEW_TASK_PLACEHOLDER_TEXT "Enter a new task..."
+
static GtkWidget *default_window = NULL;
struct _MilkMainWindowPrivate
};
static void
+new_task_entry_activated_cb (GtkEntry *entry,
+ MilkMainWindow *window)
+{
+ MilkMainWindowPrivate *priv;
+ char *name;
+
+ priv = MILK_MAIN_WINDOW_PRIVATE (window);
+
+ name = g_strdup (gtk_entry_get_text (entry));
+
+ /* Strip the contents of leading and trailing whitespace, and add as a
+ * new task if the result is non-empty */
+ if (g_strcmp0 (g_strstrip (name), "")) {
+ char *timeline;
+ GError *error = NULL;
+
+ timeline = milk_auth_timeline_create (priv->auth, &error);
+
+ if (error) {
+ g_warning (G_STRLOC ": failed to create a timeline: %s",
+ error->message);
+ g_clear_error (&error);
+ } else {
+ RtmTask *task;
+
+ task = milk_auth_task_add (priv->auth, timeline, name,
+ &error);
+ if (task) {
+ /* empty out the entry and show its placeholder
+ * text */
+ gtk_entry_set_text (entry, "");
+ gtk_widget_grab_focus (priv->task_view);
+ } else {
+ g_warning (G_STRLOC ": failed to add task: %s",
+ error->message);
+ g_clear_error (&error);
+ }
+ }
+ }
+
+ g_free (name);
+}
+
+static gboolean
+new_task_entry_key_press_event_cb (GtkEntry *entry,
+ GdkEventKey *event,
+ MilkMainWindow *window)
+{
+ MilkMainWindowPrivate *priv;
+
+ priv = MILK_MAIN_WINDOW_PRIVATE (window);
+
+ if (!event || event->type != GDK_KEY_PRESS) {
+ return FALSE;
+ }
+
+ switch (event->keyval) {
+ case GDK_KP_Enter:
+ case GDK_Return:
+ new_task_entry_activated_cb (entry, window);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
task_view_selection_changed_cb (HildonTouchSelector *view,
gint column,
MilkMainWindow *window)
/* FIXME: change this to hildon_gtk_entry_set_placeholder_text() is
* fixed, since this is deprecated */
hildon_entry_set_placeholder (HILDON_ENTRY (w),
- _("Enter a new task..."));
+ _(NEW_TASK_PLACEHOLDER_TEXT));
priv->new_task_entry = w;
+ g_signal_connect (G_OBJECT (w), "activate",
+ G_CALLBACK (new_task_entry_activated_cb), self);
+ g_signal_connect (G_OBJECT (w), "key-press-event",
+ G_CALLBACK (new_task_entry_key_press_event_cb), self);
/*
* Task List