--- raeddit-01.c 2009-09-01 20:21:18.000000000 -0400 +++ raeddit-02.c 2009-09-01 20:19:07.000000000 -0400 @@ -3,43 +3,86 @@ compile with: - gcc `pkg-config --cflags --libs glib-2.0 hildon-1 json-glib-1.0 libcurl dbus-glib-1` raeddit-01.c greddit.c -o raeddit-01 + gcc `pkg-config --cflags --libs glib-2.0 hildon-1 json-glib-1.0 libcurl dbus-glib-1` raeddit-02.c greddit.c -o raeddit-02 */ #include +#include #include #include #include #include "greddit.h" +/* "r[ae]ddit" */ +#define APP_NAME "r" "\xc3\xa6" "ddit" + +GtkWidget *window; + +static void +show_message (const char *message) +{ + HildonNote* note = HILDON_NOTE + (hildon_note_new_information (GTK_WINDOW (window), + message?message: + "Some message was supposed to be here.")); + gtk_dialog_run (GTK_DIALOG (note)); + gtk_widget_destroy (GTK_WIDGET (note)); +} + int main(int argc, char **argv) { + GtkWidget *pan, *vbox; GSList *posts = NULL; GSList *cursor; - g_type_init (); + gtk_init (&argc, &argv); + g_set_application_name (APP_NAME); curl_global_init (CURL_GLOBAL_ALL); posts = greddit_get_posts (); + window = GTK_WIDGET (hildon_window_new ()); + gtk_window_set_title (GTK_WINDOW (window), APP_NAME); + gtk_widget_show_all (GTK_WIDGET (window)); + + pan = GTK_WIDGET (hildon_pannable_area_new ()); + vbox = GTK_WIDGET (gtk_vbox_new (FALSE, 0)); + for (cursor=posts; cursor; cursor = cursor->next) { GRedditPost *post = (GRedditPost*) cursor->data; - - printf ("%s\n(%d) %s\nposted by %s to %s\n\n", - post->url, - post->score, - post->title, - post->author, - post->subreddit); + char *title0 = g_strdup_printf("(%d) %s", + post->score, + post->title); + char *subtitle0 = g_strdup_printf("posted by %s to %s", + post->author, + post->subreddit); + /* stop buttons being a mile wide */ + char *title = g_strndup (title0, 60); + char *subtitle = g_strndup (subtitle0, 60); + GtkWidget *button = hildon_button_new_with_text (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT, + HILDON_BUTTON_ARRANGEMENT_VERTICAL, + title, subtitle); + + gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0); + + g_free (title0); + g_free (subtitle0); + g_free (title); + g_free (subtitle); } + hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pan), + vbox); + gtk_container_add (GTK_CONTAINER (window), pan); + gtk_widget_show_all (GTK_WIDGET (window)); + if (!posts) { - printf ("Nothing found.\n"); - return EXIT_FAILURE; + show_message ("Nothing found."); } + gtk_main (); greddit_free_posts (posts); curl_global_cleanup ();