/* * openmoko-dates -- OpenMoko Calendar Application * * Authored by Chris Lord * * Copyright (C) 2006-2007 OpenMoko Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser Public License as published by * the Free Software Foundation; version 2 of the license. * * 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 Lesser Public License for more details. * * Current Version: $Rev$ ($Date$) [$Author$] */ #include #include #include #include #include #include #include #include "dates.h" #include "dates-list.h" #include "dates-utils.h" static gboolean hidden = TRUE; static void selection_changed_cb (GtkTreeSelection *selection, DatesData *data); static void update_header (DatesData *data) { gchar *title; GtkTreeViewColumn *column; /* Set column title */ title = jana_utils_strftime (data->start, "Week starting %A %-d/%-m"); g_object_get (G_OBJECT (data->list_view), "column", &column, NULL); gtk_tree_view_column_set_title (column, title); g_object_unref (column); g_free (title); /* Set window title */ title = jana_utils_strftime (data->start, "%-d %b %Y"); gtk_window_set_title (GTK_WINDOW (data->window), title); g_free (title); } static void page_shown (DatesData *data) { /* Remove window title setting callback */ if (data->title_idle) { g_source_remove (data->title_idle); data->title_idle = 0; } /* If the last visible time is still in range, use it */ if (data->list_time && (jana_utils_time_compare ( data->list_time, data->start, TRUE) > 0) && (jana_utils_time_compare ( data->list_time, data->end, TRUE) < 0)) { g_object_unref (data->start); data->start = jana_time_duplicate (data->list_time); } g_object_unref (data->end); data->end = jana_time_duplicate (data->start); /* TODO: Should this range be a week? Or less? */ jana_time_set_day (data->end, jana_time_get_day (data->end) + 7); dates_utils_refresh_query (data); update_header (data); selection_changed_cb (gtk_tree_view_get_selection ( GTK_TREE_VIEW (data->list_view)), data); } static void page_hidden (DatesData *data) { if (data->list_time) g_object_unref (data->list_time); data->list_time = jana_time_duplicate (data->start); if (!data->title_idle) data->title_idle = g_idle_add ((GSourceFunc) dates_utils_title_idle_cb, data); } static void notify_visible_cb (GObject *gobject, GParamSpec *arg1, DatesData *data) { if ((!hidden) && (!GTK_WIDGET_VISIBLE (gobject))) { hidden = TRUE; page_hidden (data); } } static gboolean visibility_notify_event_cb (GtkWidget *widget, GdkEventVisibility *event, DatesData *data) { if (((event->state == GDK_VISIBILITY_PARTIAL) || (event->state == GDK_VISIBILITY_UNOBSCURED)) && (hidden)) { hidden = FALSE; page_shown (data); }/* else if ((event->state == GDK_VISIBILITY_FULLY_OBSCURED) && (!hidden)) { hidden = TRUE; }*/ return FALSE; } static void unmap_cb (GtkWidget *widget, DatesData *data) { if (!hidden) { hidden = TRUE; page_hidden (data); } } static void new_clicked_cb (GtkToolButton *button, DatesData *data) { JanaTime *time; if (!(time = dates_utils_event_list_get_time (JANA_GTK_EVENT_LIST ( data->list_view)))) time = jana_time_duplicate (data->start); if (jana_time_get_isdate (time)) { jana_time_set_isdate (time, FALSE); jana_time_set_hours (time, 9); } dates_utils_create_new_event (data, time); g_object_unref (time); data->editing = TRUE; gtk_notebook_set_current_page (GTK_NOTEBOOK (data->notebook), -1); } static void back_clicked_cb (GtkToolButton *button, DatesData *data) { jana_time_set_day (data->start, jana_time_get_day (data->start) - 7); jana_time_set_day (data->end, jana_time_get_day (data->end) - 7); dates_utils_refresh_query (data); update_header (data); } static void home_clicked_cb (GtkToolButton *button, DatesData *data) { g_object_unref (data->start); g_object_unref (data->end); data->start = jana_ecal_utils_time_today (data->location); data->end = jana_time_duplicate (data->start); jana_time_set_day (data->end, jana_time_get_day (data->end) + 7); dates_utils_refresh_query (data); update_header (data); } static void forward_clicked_cb (GtkToolButton *button, DatesData *data) { jana_time_set_day (data->start, jana_time_get_day (data->start) + 7); jana_time_set_day (data->end, jana_time_get_day (data->end) + 7); dates_utils_refresh_query (data); update_header (data); } static void selection_changed_cb (GtkTreeSelection *selection, DatesData *data) { /* If we're hidden, don't do anything */ if (hidden) return; dates_utils_event_list_selection_changed_cb (selection, data); } static void row_activated_cb (GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, DatesData *data) { /*g_debug ("Row activated");*/ } static void search_text_changed_cb (MokoSearchBar *bar, GtkEditable *editable, DatesData *data) { if (hidden || (!moko_search_bar_search_visible (bar))) return; if (data->category) { g_free (data->category); data->category = NULL; } g_free (data->search); data->search = g_utf8_casefold (gtk_entry_get_text ( GTK_ENTRY (editable)), -1); jana_gtk_event_list_refilter ((JanaGtkEventList *)data->list_view); } static void search_combo_changed_cb (MokoSearchBar *bar, GtkComboBox *combo_box, DatesData *data) { if (hidden || moko_search_bar_search_visible (bar)) return; if (data->search) { g_free (data->search); data->search = NULL; } g_free (data->category); if (gtk_combo_box_get_active (combo_box) > 0) data->category = gtk_combo_box_get_active_text (combo_box); else data->category = NULL; jana_gtk_event_list_refilter ((JanaGtkEventList *)data->list_view); } static void search_toggled_cb (MokoSearchBar *bar, gboolean search_visible, DatesData *data) { if (hidden) return; if (search_visible) { search_text_changed_cb (bar, (GtkEditable *) moko_search_bar_get_entry (bar), data); } else { search_combo_changed_cb (bar, moko_search_bar_get_combo_box (bar), data); } } GtkWidget * dates_create_list_page (DatesData *data) { GtkWidget *vbox, *toolbar, *scroll, *combo; GtkTreeSelection *selection; GtkToolItem *button; vbox = gtk_vbox_new (FALSE, 0); /* Create toolbar */ toolbar = gtk_toolbar_new (); gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, TRUE, 0); /* New event button */ button = dates_utils_toolbutton_new (GTK_STOCK_NEW); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), button, 0); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), gtk_separator_tool_item_new (), 0); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (new_clicked_cb), data); /* Forward button */ button = dates_utils_toolbutton_new (GTK_STOCK_GO_FORWARD); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), button, 0); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), gtk_separator_tool_item_new (), 0); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (forward_clicked_cb), data); /* Home button */ button = dates_utils_toolbutton_new (GTK_STOCK_HOME); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), button, 0); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), gtk_separator_tool_item_new (), 0); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (home_clicked_cb), data); /* Back button */ button = dates_utils_toolbutton_new (GTK_STOCK_GO_BACK); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), button, 0); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (back_clicked_cb), data); gtk_widget_show_all (toolbar); /* Create search box */ combo = gtk_combo_box_new_text (); data->list_searchbar = moko_search_bar_new_with_combo ( GTK_COMBO_BOX (combo)); gtk_box_pack_start (GTK_BOX (vbox), data->list_searchbar, FALSE, TRUE, 0); gtk_widget_show (data->list_searchbar); /* Create event list */ data->list_view = jana_gtk_event_list_new (); gtk_tree_model_filter_set_visible_func (jana_gtk_event_list_get_filter ( JANA_GTK_EVENT_LIST (data->list_view)), (GtkTreeModelFilterVisibleFunc)dates_utils_event_list_filter_cb, data, NULL); gtk_tree_view_set_headers_visible ( GTK_TREE_VIEW (data->list_view), TRUE); scroll = moko_finger_scroll_new (); gtk_container_set_border_width (GTK_CONTAINER (scroll), 12); gtk_container_add (GTK_CONTAINER (scroll), data->list_view); gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 0); gtk_widget_show_all (scroll); gtk_widget_add_events (data->list_view, GDK_VISIBILITY_NOTIFY_MASK); g_signal_connect (data->list_view, "visibility-notify-event", G_CALLBACK (visibility_notify_event_cb), data); g_signal_connect (data->list_view, "notify::visible", G_CALLBACK (notify_visible_cb), data); g_signal_connect (vbox, "unmap", G_CALLBACK (unmap_cb), data); g_signal_connect (data->list_view, "row-activated", G_CALLBACK (row_activated_cb), data); selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (data->list_view)); g_signal_connect (selection, "changed", G_CALLBACK (selection_changed_cb), data); g_signal_connect (data->list_searchbar, "text_changed", G_CALLBACK (search_text_changed_cb), data); g_signal_connect (data->list_searchbar, "combo_changed", G_CALLBACK (search_combo_changed_cb), data); g_signal_connect (data->list_searchbar, "toggled", G_CALLBACK (search_toggled_cb), data); return vbox; }