From aad7102f379529e5f7f9e43c5bc0760ba50de0f4 Mon Sep 17 00:00:00 2001 From: Roman Moravcik Date: Tue, 16 Mar 2010 19:18:05 +0100 Subject: [PATCH] imported version 0.1-2 --- debian/changelog | 9 ++ po/sk.po | 18 +++- src/birthday.c | 300 ++++++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 247 insertions(+), 80 deletions(-) diff --git a/debian/changelog b/debian/changelog index 6125b8f..3dd93e4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +birthday (0.1-2) fremantle; urgency=low + + * Fixed loading of avatars. + * If no fullname is set, try to use given name, family name, + nickname or organisation insted. + * Added sorting by name and date. + + -- Roman Moravcik Fri, 12 Mar 2010 14:55:27 +0100 + birthday (0.1-1) fremantle; urgency=low * Temporary disabled loading of avatars, because application was crashing. diff --git a/po/sk.po b/po/sk.po index 10809b2..994cc65 100644 --- a/po/sk.po +++ b/po/sk.po @@ -8,8 +8,8 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-03-10 14:02+0100\n" -"PO-Revision-Date: 2010-03-10 14:04+0100\n" +"POT-Creation-Date: 2010-03-12 14:49+0100\n" +"PO-Revision-Date: 2010-03-12 14:50+0100\n" "Last-Translator: Roman Moravčík \n" "Language-Team: sk_SK <>\n" "MIME-Version: 1.0\n" @@ -17,7 +17,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2\n" -#: ../src/birthday.c:181 +#: ../src/birthday.c:267 #, c-format msgid "next birthday in %d day" msgid_plural "next birthday in %d days" @@ -25,11 +25,19 @@ msgstr[0] "nasledujúce narodeniny za %d deň" msgstr[1] "nasledujúce narodeniny za %d dní" msgstr[2] "nasledujúce narodeniny za %d dní" -#: ../src/birthday.c:219 +#: ../src/birthday.c:346 +msgid "Name" +msgstr "Meno" + +#: ../src/birthday.c:352 +msgid "Date" +msgstr "Dátum" + +#: ../src/birthday.c:370 msgid "Birthday" msgstr "Narodeniny" #. no_search_result label -#: ../src/birthday.c:236 +#: ../src/birthday.c:387 msgid "No contacts with set birthdate" msgstr "Žiadne kontakty s nastavenými narodeninami" diff --git a/src/birthday.c b/src/birthday.c index f1d90f8..022974b 100644 --- a/src/birthday.c +++ b/src/birthday.c @@ -38,6 +38,8 @@ #include #include +GtkWidget *tree_view; + enum { COLUMN_AVATAR = 0, @@ -47,62 +49,115 @@ enum NUM_COLS }; +static void +sort_by_name_clicked (GtkButton *button, + GtkLabel *label) +{ + GtkTreeModel *model; + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model), + COLUMN_FULLNAME, GTK_SORT_ASCENDING); +} + +static void +sort_by_date_clicked (GtkButton *button, + GtkLabel *label) +{ + GtkTreeModel *model; + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model), + COLUMN_NEXT_BIRTHDAY, GTK_SORT_ASCENDING); + +} + +static void +on_search_close_clicked (GtkButton *button, + gpointer data) +{ + GtkWidget *search = GTK_WIDGET (data); + + /* hide search bar */ + gtk_widget_hide (search); + + /* FIXME: refilter treeview */ +} + + +static gboolean +on_key_press_event (GtkWidget *widget, + GdkEventKey *event, + gpointer data) +{ + GtkWidget *search = GTK_WIDGET (data); + + if ((event->keyval > GDK_space) && (event->keyval <= GDK_stricteq) && !GTK_WIDGET_VISIBLE (search)) { + /* show search bar */ + gtk_widget_show (search); + + /* FIXME: focus on entry */ + } + + return FALSE; +} + static unsigned int calc_age (EContactDate *bdate) { - struct tm tm_bday; - struct tm *tm_age; - time_t t_age; - int age = 0; - - tm_bday.tm_sec = 0; - tm_bday.tm_min = 0; - tm_bday.tm_hour = 0; - tm_bday.tm_mday = bdate->day; - tm_bday.tm_mon = bdate->month - 1; - tm_bday.tm_year = bdate->year - 1900; - - t_age = time (NULL) - mktime (&tm_bday); - tm_age = gmtime (&t_age); - age = tm_age->tm_year - 70; - - if (age < 0) - age = 0; - - return age; + struct tm tm_bday; + struct tm *tm_age; + time_t t_age; + int age = 0; + + tm_bday.tm_sec = 0; + tm_bday.tm_min = 0; + tm_bday.tm_hour = 0; + tm_bday.tm_mday = bdate->day; + tm_bday.tm_mon = bdate->month - 1; + tm_bday.tm_year = bdate->year - 1900; + + t_age = time (NULL) - mktime (&tm_bday); + tm_age = gmtime (&t_age); + age = tm_age->tm_year - 70; + + if (age < 0) + age = 0; + + return age; } static unsigned int calc_next_bday (EContactDate *bdate) { - struct tm tm_current_bday, tm_next_bday; - struct tm *tm_current_date; - time_t t_current_date, t_current_bday, t_next_bday, t_next_bday_in; - - t_current_date = time (NULL); - tm_current_date = localtime (&t_current_date); - - tm_current_bday.tm_sec = 0; - tm_current_bday.tm_min = 0; - tm_current_bday.tm_hour = 0; - tm_current_bday.tm_mday = bdate->day; - tm_current_bday.tm_mon = bdate->month - 1; - tm_current_bday.tm_year = tm_current_date->tm_year; - t_current_bday = mktime (&tm_current_bday); - - if (t_current_date > t_current_bday) { - tm_next_bday.tm_sec = 0; - tm_next_bday.tm_min = 0; - tm_next_bday.tm_hour = 0; - tm_next_bday.tm_mday = bdate->day; - tm_next_bday.tm_mon = bdate->month - 1; - tm_next_bday.tm_year = tm_current_date->tm_year + 1; - t_next_bday = mktime (&tm_next_bday); - } else { - t_next_bday = t_current_bday; - } - t_next_bday_in = t_next_bday - t_current_date; - return (t_next_bday_in / 86400) + 1; + struct tm tm_current_bday, tm_next_bday; + struct tm *tm_current_date; + time_t t_current_date, t_current_bday, t_next_bday; + + t_current_date = time (NULL); + tm_current_date = localtime (&t_current_date); + + tm_current_bday.tm_sec = 0; + tm_current_bday.tm_min = 0; + tm_current_bday.tm_hour = 0; + tm_current_bday.tm_mday = bdate->day; + tm_current_bday.tm_mon = bdate->month - 1; + tm_current_bday.tm_year = tm_current_date->tm_year; + t_current_bday = mktime (&tm_current_bday); + + if (t_current_date > t_current_bday) { + tm_next_bday.tm_sec = 0; + tm_next_bday.tm_min = 0; + tm_next_bday.tm_hour = 0; + tm_next_bday.tm_mday = bdate->day; + tm_next_bday.tm_mon = bdate->month - 1; + tm_next_bday.tm_year = tm_current_date->tm_year + 1; + t_next_bday = mktime (&tm_next_bday); + } else { + t_next_bday = t_current_bday; + } + + return (t_next_bday - t_current_date) / 86400; } static gchar * @@ -130,7 +185,7 @@ get_text_color_by_name (const gchar *name) } static GtkListStore * -create_bday_liststore(GList *contacts) +create_bday_liststore (GList *contacts) { GtkListStore *store; GtkTreeIter iter; @@ -148,43 +203,65 @@ create_bday_liststore(GList *contacts) G_TYPE_INT); /* COLUMN_NEXT_BIRTHDAY */ for (contact = contacts; contact != NULL; contact = contact->next) { - EContactDate *bdate; + EContactDate *bdate = NULL; bdate = e_contact_get (E_CONTACT (contact->data), E_CONTACT_BIRTH_DATE); if (bdate) { - EContactPhoto *photo; + EContactPhoto *photo = NULL; GError *error = NULL; - GdkPixbuf *avatar; - gchar *avatar_filename = NULL; + GdkPixbuf *avatar = NULL; gchar *fullname = NULL; guint age = 0, next_birthday = 0; gchar *display_column = NULL; gchar *next_birthday_text = NULL; -#if 0 photo = e_contact_get (E_CONTACT (contact->data), E_CONTACT_PHOTO); if (photo) { - avatar_filename = g_filename_from_uri (photo->data.uri, NULL, NULL); - if (avatar_filename) { - gint height = 0; + if (photo->type == E_CONTACT_PHOTO_TYPE_INLINED) { + GdkPixbufLoader *loader; + + loader = gdk_pixbuf_loader_new (); + if (gdk_pixbuf_loader_write (loader, (guchar *) photo->data.inlined.data, photo->data.inlined.length, NULL)) + avatar = gdk_pixbuf_loader_get_pixbuf (loader); - avatar = gdk_pixbuf_new_from_file (avatar_filename, &error); - height = gdk_pixbuf_get_height (avatar); + } else { + gchar *avatar_filename = NULL; + + avatar_filename = g_filename_from_uri (photo->data.uri, NULL, NULL); + if (avatar_filename) { + avatar = gdk_pixbuf_new_from_file (avatar_filename, &error); + g_free (avatar_filename); + } + } + + if (avatar) { + gint height = gdk_pixbuf_get_height (avatar); if (height != 48) { gint new_height = 48; - gint new_width = (int) new_height * gdk_pixbuf_get_width (avatar) / height; - gdk_pixbuf_scale_simple (avatar, new_width, new_height, GDK_INTERP_BILINEAR); + gint new_width = new_height * gdk_pixbuf_get_width (avatar) / height; + avatar = gdk_pixbuf_scale_simple (avatar, new_width, new_height, GDK_INTERP_BILINEAR); } - g_free (avatar_filename); } - avatar_filename = NULL; + e_contact_photo_free (photo); + photo = NULL; } else { avatar = gdk_pixbuf_new_from_file ("/usr/share/icons/hicolor/48x48/hildon/general_default_avatar.png", &error); } -#endif - avatar = gdk_pixbuf_new_from_file ("/usr/share/icons/hicolor/48x48/hildon/general_default_avatar.png", &error); fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_FULL_NAME); + if (!fullname) { + fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_GIVEN_NAME); + if (!fullname) { + fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_FAMILY_NAME); + if (!fullname) { + fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_NICKNAME); + if (!fullname) { + fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_ORG); + } + } + } + } + age = calc_age(bdate); next_birthday = calc_next_bday(bdate); next_birthday_text = g_strdup_printf(ngettext ("next birthday in %d day", "next birthday in %d days", next_birthday), next_birthday); @@ -199,6 +276,14 @@ create_bday_liststore(GList *contacts) COLUMN_NEXT_BIRTHDAY, next_birthday, -1); + if (display_column) + g_free (display_column); + display_column = NULL; + + if (fullname) + g_free (fullname); + fullname = NULL; + if (next_birthday_text) g_free (next_birthday_text); next_birthday_text = NULL; @@ -218,10 +303,66 @@ create_bday_liststore(GList *contacts) } static GtkWidget * -create_main_window(GtkListStore *store) +create_search_bar () +{ + GtkWidget *hbox, *entry, *button; + GtkEntryCompletion *completion; + + /* search hbox */ + hbox = gtk_hbox_new (FALSE, HILDON_MARGIN_DEFAULT); + + /* search entry */ + entry = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT); + hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry), HILDON_GTK_INPUT_MODE_FULL); + gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); + + completion = gtk_entry_completion_new (); + gtk_entry_completion_set_inline_completion (completion, TRUE); + gtk_entry_completion_set_popup_completion (completion, FALSE); + gtk_entry_set_completion (GTK_ENTRY (entry), completion); + + /* clear button */ + button = GTK_WIDGET (gtk_tool_button_new (gtk_image_new_from_icon_name + ("general_close", (GtkIconSize) HILDON_ICON_PIXEL_SIZE_FINGER), "Clear")); + gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, TRUE, 0); + + /* search signals */ +// g_signal_connect (entry, "changed", G_CALLBACK (onSearchEntryChanged), this); + g_signal_connect (button, "clicked", G_CALLBACK (on_search_close_clicked), hbox); + + return hbox; +} + +static void +create_main_menu (GtkWidget *window) +{ + HildonAppMenu *menu; + GtkWidget *filter; + + menu = HILDON_APP_MENU (hildon_app_menu_new ()); + hildon_window_set_app_menu (HILDON_WINDOW (window), menu); + + filter = hildon_gtk_radio_button_new (HILDON_SIZE_FINGER_HEIGHT , NULL); + gtk_button_set_label (GTK_BUTTON (filter), _("Name")); + gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (filter), FALSE); + g_signal_connect_after (filter, "clicked", G_CALLBACK (sort_by_name_clicked), NULL); + hildon_app_menu_add_filter (menu, GTK_BUTTON (filter)); + + filter = hildon_gtk_radio_button_new_from_widget (HILDON_SIZE_FINGER_HEIGHT , GTK_RADIO_BUTTON (filter)); + gtk_button_set_label (GTK_BUTTON (filter), _("Date")); + gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (filter), FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (filter), TRUE); + g_signal_connect_after (filter, "clicked", G_CALLBACK (sort_by_date_clicked), NULL); + hildon_app_menu_add_filter (menu, GTK_BUTTON (filter)); + + gtk_widget_show_all (GTK_WIDGET (menu)); +} + +static GtkWidget * +create_main_window (GtkListStore *store) { HildonProgram *program = NULL; - GtkWidget *window, *main_vbox, *alignment, *label, *pannable, *tree_view; + GtkWidget *window, *main_vbox, *alignment, *label, *pannable, *search; GtkTreeViewColumn *column; GtkCellRenderer *renderer; @@ -252,7 +393,7 @@ create_main_window(GtkListStore *store) /* alignment for pannable area */ alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0); gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), - 0, 0, HILDON_MARGIN_DEFAULT, HILDON_MARGIN_DEFAULT); + 0, 0, HILDON_MARGIN_DEFAULT, 0); gtk_box_pack_start (GTK_BOX (main_vbox), alignment, TRUE, TRUE, 0); /* pannable for tree view */ @@ -263,12 +404,9 @@ create_main_window(GtkListStore *store) /* tree view */ tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); gtk_container_add (GTK_CONTAINER (pannable), tree_view); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), - COLUMN_NEXT_BIRTHDAY, GTK_SORT_ASCENDING); - /* display column */ column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_fixed_width (column, 696); + gtk_tree_view_column_set_fixed_width (column, 709); gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_column_pack_start (column, renderer, TRUE); @@ -281,7 +419,7 @@ create_main_window(GtkListStore *store) /* avatar column */ column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_fixed_width (column, 64); + gtk_tree_view_column_set_fixed_width (column, 48); gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED); renderer = gtk_cell_renderer_pixbuf_new (); gtk_tree_view_column_pack_end (column, renderer, FALSE); @@ -290,11 +428,17 @@ create_main_window(GtkListStore *store) NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); + /* search bar */ + search = create_search_bar(); + gtk_box_pack_end (GTK_BOX (main_vbox), search, FALSE, FALSE, 0); + /* window signals */ g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); +// g_signal_connect (G_OBJECT (window), "key-press-event", G_CALLBACK (on_key_press_event), search); - gtk_widget_show_all (GTK_WIDGET(window)); - gtk_widget_hide (GTK_WIDGET(label)); + gtk_widget_show_all (GTK_WIDGET (window)); + gtk_widget_hide (GTK_WIDGET (label)); + gtk_widget_hide (GTK_WIDGET (search)); return window; } @@ -352,6 +496,12 @@ int main (int argc, char **argv) store = create_bday_liststore (contacts); window = create_main_window (store); + g_object_unref (G_OBJECT (store)); + create_main_menu (window); + + /* sort list by next birthdays */ + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), + COLUMN_NEXT_BIRTHDAY, GTK_SORT_ASCENDING); gtk_main (); -- 1.7.9.5