r1461 - in trunk/src/target/OM-2007/applications/openmoko-rssreader: . data src

zecke at sita.openmoko.org zecke at sita.openmoko.org
Wed Mar 21 20:13:47 CET 2007


Author: zecke
Date: 2007-03-21 20:13:46 +0100 (Wed, 21 Mar 2007)
New Revision: 1461

Added:
   trunk/src/target/OM-2007/applications/openmoko-rssreader/AUTHORS
   trunk/src/target/OM-2007/applications/openmoko-rssreader/COPYING
   trunk/src/target/OM-2007/applications/openmoko-rssreader/ChangeLog
   trunk/src/target/OM-2007/applications/openmoko-rssreader/Makefile.am
   trunk/src/target/OM-2007/applications/openmoko-rssreader/NEWS
   trunk/src/target/OM-2007/applications/openmoko-rssreader/README
   trunk/src/target/OM-2007/applications/openmoko-rssreader/autogen.sh
   trunk/src/target/OM-2007/applications/openmoko-rssreader/configure.ac
   trunk/src/target/OM-2007/applications/openmoko-rssreader/data/
   trunk/src/target/OM-2007/applications/openmoko-rssreader/data/Makefile.am
   trunk/src/target/OM-2007/applications/openmoko-rssreader/data/rssreader_refresh_all.png
   trunk/src/target/OM-2007/applications/openmoko-rssreader/data/rssreader_subscribe.png
   trunk/src/target/OM-2007/applications/openmoko-rssreader/src/
   trunk/src/target/OM-2007/applications/openmoko-rssreader/src/Makefile.am
   trunk/src/target/OM-2007/applications/openmoko-rssreader/src/application-data.h
   trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.c
   trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.h
   trunk/src/target/OM-2007/applications/openmoko-rssreader/src/main.c
Modified:
   trunk/src/target/OM-2007/applications/openmoko-rssreader/
Log:
openmoko-rssreader: Add the RSS Reader as announced on the mailinglist
    This application requires libmrss for feed reading. The application
    will eventually hang or segfault if you have at-spi running in your
    desktop as ATK/Gail/Orbit is not thread safe.



Property changes on: trunk/src/target/OM-2007/applications/openmoko-rssreader
___________________________________________________________________
Name: svn:ignore
   + Makefile.in
Makefile
*.bz2
mkinstalldirs
configure
depcomp
config.guess
ltmain.sh
config.sub
config.h.in
missing
aclocal.m4
install-sh


Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/AUTHORS
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/AUTHORS	2007-03-21 17:38:30 UTC (rev 1460)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/AUTHORS	2007-03-21 19:13:46 UTC (rev 1461)
@@ -0,0 +1 @@
+Holger Hans Peter Freyther

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/COPYING
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/COPYING	2007-03-21 17:38:30 UTC (rev 1460)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/COPYING	2007-03-21 19:13:46 UTC (rev 1461)
@@ -0,0 +1,18 @@
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/ChangeLog
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/ChangeLog	2007-03-21 17:38:30 UTC (rev 1460)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/ChangeLog	2007-03-21 19:13:46 UTC (rev 1461)
@@ -0,0 +1,13 @@
+2007-03-20: Fix the size of the column headers
+	Combat the GtkTreeViewColumn sizing
+
+2007-03-20: Parse content of atom feeds manually
+	Parse content of ATOM feeds manually. Avoid setting NULL text inside the
+	GtkTextBuffer. Store content type and source inside the ListStore as well.
+
+2007-03-20: Fetch feeds inside a GThread
+	Fetching the feeds was implemented inside a GThread. gdk_threads_init et
+	alk is called and this works as long as AT-SPI is not enabled. If it is
+	enabled the application will eventuall crash.
+	Ekiga has the same trouble and it is documented as bug #329454 inside the
+	GNOME bug tracker.

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/Makefile.am
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/Makefile.am	2007-03-21 17:38:30 UTC (rev 1460)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/Makefile.am	2007-03-21 19:13:46 UTC (rev 1461)
@@ -0,0 +1,2 @@
+SUBDIRS = src data
+

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/NEWS
===================================================================

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/README
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/README	2007-03-21 17:38:30 UTC (rev 1460)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/README	2007-03-21 19:13:46 UTC (rev 1461)
@@ -0,0 +1,11 @@
+First try to get a Gtk+ GUI for libmrss
+
+
+Known design flaws:
+    -No real model for the feed
+    -No proxy model that makes use of the filter
+    -No caching of images
+    -Storage size is not limited
+    
+Main objective:
+    -Get familiar with the joy/pain of Gtk+
\ No newline at end of file

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/autogen.sh
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/autogen.sh	2007-03-21 17:38:30 UTC (rev 1460)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/autogen.sh	2007-03-21 19:13:46 UTC (rev 1461)
@@ -0,0 +1,4 @@
+#! /bin/sh
+autoreconf -v --install || exit 1
+glib-gettextize --force --copy || exit 1
+./configure --enable-maintainer-mode "$@"


Property changes on: trunk/src/target/OM-2007/applications/openmoko-rssreader/autogen.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/configure.ac
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/configure.ac	2007-03-21 17:38:30 UTC (rev 1460)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/configure.ac	2007-03-21 19:13:46 UTC (rev 1461)
@@ -0,0 +1,21 @@
+AC_PREREQ([2.59])
+AC_INIT([openmoko-rssreader], [0.0.4], [http://openmoko.org])
+AM_INIT_AUTOMAKE([1.9 foreign dist-bzip2 no-dist-gzip])
+AC_CONFIG_SRCDIR(src/main.c)
+AM_CONFIG_HEADER(config.h)
+
+AC_PROG_CC
+AC_STDC_HEADERS
+AC_PROG_LIBTOOL
+
+# base deps
+PKG_CHECK_MODULES(OPENMOKO, openmoko-libs >= 0.0.1)
+PKG_CHECK_MODULES(MRSS,     mrss          >= 0.17 )
+PKG_CHECK_MODULES(GTHREAD,  gthread-2.0           )
+
+# output stuff
+AC_OUTPUT([
+Makefile
+src/Makefile
+data/Makefile
+])

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/data/Makefile.am
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/data/Makefile.am	2007-03-21 17:38:30 UTC (rev 1460)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/data/Makefile.am	2007-03-21 19:13:46 UTC (rev 1461)
@@ -0,0 +1,5 @@
+EXTRA_DIST = rssreader_refresh_all.png  rssreader_subscribe.png
+
+resourcedir = $(pkgdatadir)
+resource_DATA = rssreader_refresh_all.png  rssreader_subscribe.png
+

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/data/rssreader_refresh_all.png
===================================================================
(Binary files differ)


Property changes on: trunk/src/target/OM-2007/applications/openmoko-rssreader/data/rssreader_refresh_all.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/data/rssreader_subscribe.png
===================================================================
(Binary files differ)


Property changes on: trunk/src/target/OM-2007/applications/openmoko-rssreader/data/rssreader_subscribe.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream


Property changes on: trunk/src/target/OM-2007/applications/openmoko-rssreader/src
___________________________________________________________________
Name: svn:ignore
   + *.*swp
*.swp
Makefile.in
Makefile


Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/src/Makefile.am
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/src/Makefile.am	2007-03-21 17:38:30 UTC (rev 1460)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/src/Makefile.am	2007-03-21 19:13:46 UTC (rev 1461)
@@ -0,0 +1,12 @@
+AM_CPPFLAGS = -DDATADIR=\"$(datadir)\" \
+              -DPKGDATADIR=\"$(pkgdatadir)\"
+
+AM_CFLAGS = -Wall -Werror -pedantic -std=c99 @OPENMOKO_CFLAGS@ @MRSS_CFLAGS@
+
+bin_PROGRAMS = openmoko-rssreader
+
+EXTRA_DIST = application-data.h callbacks.h
+
+openmoko_rssreader_SOURCES = main.c callbacks.c
+openmoko_rssreader_LDADD = @OPENMOKO_LIBS@ @MRSS_LIBS@ @GTHREAD_LIBS@
+

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/src/application-data.h
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/src/application-data.h	2007-03-21 17:38:30 UTC (rev 1460)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/src/application-data.h	2007-03-21 19:13:46 UTC (rev 1461)
@@ -0,0 +1,83 @@
+/*
+ *  RSS Reader, a simple RSS reader
+ *
+ *  Copyright (C) 2007 Holger Hans Peter Freyther
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included
+ *  in all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *  Current Version: $Rev$ ($Date$) [$Author$]
+ */
+
+#ifndef APPLICATION_DATA_H
+#define APPLICATION_DATA_H
+
+
+#include <libmokoui/moko-application.h>
+#include <libmokoui/moko-paned-window.h>
+#include <libmokoui/moko-tree-view.h>
+#include <libmokoui/moko-tool-box.h>
+
+#include <gtk/gtk.h>
+
+struct RSSReaderData {
+    MokoApplication   *app;
+    GtkMenu           *menu;
+    GtkMenu           *filter;
+    MokoPanedWindow   *window;
+    MokoToolBox       *box;
+    MokoMenuBox       *menubox;
+    MokoTreeView      *treeView;
+    GtkListStore      *feed_data;
+    GtkTextTagTable   *tagTable;
+    GtkTextBuffer     *textBuffer;
+    GtkTextView       *textView;
+
+    gchar             *current_filter;
+};
+
+/*
+ * Instead of having a real model we have this... as our feed
+ * model
+ * Either there is a link or text is included. And we contain
+ * the sourcename of the feed. This will be used by the ModelFilter
+ * to implement the FilterMenu
+ */
+enum {
+    RSS_READER_COLUMN_AUTHOR,
+    RSS_READER_COLUMN_SUBJECT,
+    RSS_READER_COLUMN_DATE,
+    RSS_READER_COLUMN_LINK,     /* Is this something like spiegel.de and only has a link */
+    RSS_READER_COLUMN_TEXT,     /* Either link is NULL, or this contains the article     */
+    RSS_READER_COLUMN_TEXT_TYPE,/* The Text Type of Atom feeds HTML, plain...            */
+    RSS_READER_COLUMN_CATEGORY, /* The category as shown in the filter box               */
+    RSS_READER_COLUMN_SOURCE,   /* the source of this entry, the URL of the feed, not the atom <source> */
+    RSS_READER_NUM_COLS,
+};
+
+/**
+ * text type for atom feeds, default is none
+ */
+enum {
+    RSS_READER_TEXT_TYPE_NONE,
+    RSS_READER_TEXT_TYPE_PLAIN,
+    RSS_READER_TEXT_TYPE_HTML,
+    RSS_READER_TEXT_TYPE_UNKNOWN
+};
+
+#endif

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.c	2007-03-21 17:38:30 UTC (rev 1460)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.c	2007-03-21 19:13:46 UTC (rev 1461)
@@ -0,0 +1,228 @@
+/*
+ *  RSS Reader, a simple RSS reader
+ *
+ *  Copyright (C) 2007 Holger Hans Peter Freyther
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included
+ *  in all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *  Current Version: $Rev$ ($Date$) [$Author$]
+ */
+
+#include "callbacks.h"
+
+#include <mrss.h>
+#include <string.h>
+
+#define _(x) (x)
+
+struct FeedEntry {
+    gchar *category;
+    gchar *url;
+};
+
+static const int NUMBER_OF_FEEDS = 2;
+static struct FeedEntry s_feeds[] = {
+    { "OpenMoko", "http://planet.openmoko.org/rss20.xml" },
+    { "GNOME"   , "http://planet.gnome.org/atom.xml"     },
+};
+
+static void remove_container_item( GtkWidget *item, GtkWidget *container ) {
+    gtk_container_remove(GTK_CONTAINER(container), item);
+}
+
+
+/*
+ * TODO: Use the ModelFilter to filter for All or Category
+ */
+void filter_feeds( struct RSSReaderData *data ) {
+}
+
+/*
+ * TODO: use GConf to load the feed data
+ */
+void refresh_categories( struct RSSReaderData *data ) {
+    /*
+     * clear the old menu and add the new one
+     */
+    gtk_container_foreach( GTK_CONTAINER(data->filter), (GtkCallback)remove_container_item, data->filter );
+
+    for ( int i = 0; i < NUMBER_OF_FEEDS; ++i )
+        gtk_menu_shell_append( GTK_MENU_SHELL(data->filter), gtk_menu_item_new_with_label( s_feeds[i].category ) );
+
+    /*
+     * add separator + All
+     */
+    gtk_menu_shell_append( GTK_MENU_SHELL(data->filter), gtk_separator_menu_item_new() );
+    gtk_menu_shell_append( GTK_MENU_SHELL(data->filter), GTK_WIDGET(gtk_menu_item_new_with_label(_("All"))) );
+}
+
+gboolean cb_filter_changed( GtkWidget* widget, gchar *text, struct RSSReaderData *data ) {
+    if ( data->current_filter )
+        g_free( data->current_filter );
+    data->current_filter = g_strdup( text );
+
+    filter_feeds( data );
+    return TRUE;
+}
+
+void cb_subscribe_button_clicked( GtkButton *btn, struct RSSReaderData *data ) {}
+
+
+/*
+ * asynchronous update thread!
+ * This breaks with ATK+
+ */
+static void feed_update_thread( struct RSSReaderData *data ) {
+    GtkTreeIter iter;
+
+    for ( int i = 0; i < NUMBER_OF_FEEDS; ++i ) {
+        mrss_t *rss_data;
+        int ret = mrss_parse_url( s_feeds[i].url, &rss_data );
+        if ( ret ) {
+            /* TODO use the footer to report error? */
+            g_debug( "parse_url failed.." );
+            continue;
+        }
+
+        mrss_item_t *item = rss_data->item;
+        while ( item ) {
+            gint content_type = RSS_READER_TEXT_TYPE_NONE;
+            gchar *description = item->description;
+
+            /*
+             * let us try to find the 'content' tag
+             * and then extract the type
+             */
+            if ( !description && rss_data->version == MRSS_VERSION_ATOM_1_0 && item->other_tags ) {
+                for ( mrss_tag_t *tag = item->other_tags; tag; tag = tag->next ) {
+                    if ( strcmp( tag->name, "content" ) == 0 ) {
+                        description = tag->value;
+
+                        for ( mrss_attribute_t *attribute = tag->attributes; attribute; attribute = attribute->next ) {
+                            if ( strcmp( attribute->name, "type" ) == 0 ) {
+                                if ( strcmp( attribute->value, "plain" ) == 0 ) {
+                                    content_type = RSS_READER_TEXT_TYPE_PLAIN;
+                                } else if ( strcmp( attribute->name, "html" ) == 0 ) {
+                                    content_type = RSS_READER_TEXT_TYPE_HTML;
+                                } else {
+                                    content_type = RSS_READER_TEXT_TYPE_UNKNOWN;
+                                }
+                            }
+                        }
+
+                        /* we are done */
+                        break;
+                    }
+                }
+            }
+
+            /*
+             * update the model here
+             */
+            gdk_threads_enter();
+            gtk_list_store_append( data->feed_data, &iter );
+            gtk_list_store_set   ( data->feed_data, &iter,
+                                   RSS_READER_COLUMN_AUTHOR, g_strdup( item->author  ),
+                                   RSS_READER_COLUMN_SUBJECT,g_strdup( item->title   ),
+                                   RSS_READER_COLUMN_DATE,   g_strdup( item->pubDate ),
+                                   RSS_READER_COLUMN_LINK,   g_strdup( item->link    ),
+                                   RSS_READER_COLUMN_TEXT,   g_strdup( description   ),
+                                   RSS_READER_COLUMN_TEXT_TYPE, content_type          ,
+                                   RSS_READER_COLUMN_CATEGORY, g_strdup( s_feeds[i].category ),
+                                   RSS_READER_COLUMN_SOURCE,  g_strdup( s_feeds[i].url ),
+                                   -1 );
+            gdk_threads_leave();
+            item = item->next;
+        }
+
+        mrss_free( data );
+    }
+
+    gdk_threads_enter();
+    filter_feeds( data );
+    gdk_threads_leave();
+}
+
+/*
+ * TODO use gconf and GThread as this will block
+ * DISCUSSION:
+ *    - Should everything be updated?
+ *    - What happens if we update but some feeds can not be connected? Should the old
+ *      data be kept?
+ *      ( Just keeping/building a new ListStore does not help, we need a model that consists
+ *        out of models... )
+ *
+ *
+ * Clear the current model
+ *
+ * For each feed:
+ *    - Get the Data
+ *    - Fill the GtkListStore
+ *
+ * Refilter the model...
+ */
+void cb_refresh_all_button_clicked( GtkButton *btn, struct RSSReaderData *data ) {
+    /*
+     * once we have a SCM make it not clear the list but remove all items
+     * with the same URL
+     */
+    gtk_list_store_clear( data->feed_data );
+
+    /*
+     * do the complete work in a new thread
+     */
+    GError *error = NULL;
+    (void)g_thread_create( (GThreadFunc)feed_update_thread, data, FALSE, &error );
+
+    /* XXX FOOTER do error reporting */
+    if ( error != NULL ) {
+        fprintf( stderr, "Can not create thread %s:%d '%s'\n", __FILE__, __LINE__, error->message );
+    }
+
+}
+void cb_searchbox_visible( MokoToolBox *box, struct RSSReaderData *data ) {}
+void cb_searchbox_invisible( MokoToolBox *box, struct RSSReaderData *data ) {}
+
+/*
+ * TODO: Update the text and make it rich text.
+ *
+ * TODO: Decide if a browser should be opened or not... e.g. spiegel.de only distributes
+ *       the headlines and not the content. Either we fetch the code or leave it
+ */
+void cb_treeview_selection_changed( GtkTreeSelection *selection, struct RSSReaderData *data ) {
+    GtkTreeModel* model;
+    GtkTreeIter iter;
+    gboolean has_selection = gtk_tree_selection_get_selected( selection, &model, &iter );
+
+    /*
+     * Update the text
+     */
+    if ( has_selection ) {
+        gchar *message;
+        gtk_tree_model_get( model, &iter, RSS_READER_COLUMN_TEXT, &message, -1 );
+        if ( message )
+            gtk_text_buffer_set_text( data->textBuffer, message, -1 );
+        else
+            gtk_text_buffer_set_text( data->textBuffer, g_strdup( "Failed to read the text" ), -1 );
+    }
+}
+
+gboolean cb_treeview_keypress_event( GtkWidget *entry, GdkEventKey *key, struct RSSReaderData *data ) { return TRUE; }
+void cb_search_entry_changed      ( GtkWidget *entry, struct RSSReaderData *data ) {}
+

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.h
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.h	2007-03-21 17:38:30 UTC (rev 1460)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.h	2007-03-21 19:13:46 UTC (rev 1461)
@@ -0,0 +1,57 @@
+/*
+ *  RSS Reader, a simple RSS reader
+ *
+ *  Copyright (C) 2007 Holger Hans Peter Freyther
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included
+ *  in all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *  Current Version: $Rev$ ($Date$) [$Author$]
+ */
+
+#ifndef RSS_READER_CALLBACKS_H
+#define RSS_READER_CALLBACKS_H
+
+#include "application-data.h"
+
+
+/*
+ * filter callbacks
+ */
+gboolean cb_filter_changed(GtkWidget* widget, gchar* text, struct RSSReaderData* d);
+
+/*
+ * toolbox callbacks
+ */
+void cb_subscribe_button_clicked  ( GtkButton *btn, struct RSSReaderData *d);
+void refresh_categories( struct RSSReaderData* );
+void refresh_feeds( struct RSSReaderData *data );
+void filter_feeds ( struct RSSReaderData *data );
+void cb_refresh_all_button_clicked( GtkButton *btn, struct RSSReaderData *d);
+void cb_searchbox_visible(MokoToolBox* toolbox, struct RSSReaderData* d);
+void cb_searchbox_invisible(MokoToolBox* toolbox, struct RSSReaderData* d);
+
+/*
+ * changes to the treeview
+ */
+void cb_treeview_selection_changed( GtkTreeSelection *selection, struct RSSReaderData *d );
+gboolean cb_treeview_keypress_event( GtkWidget *entry, GdkEventKey *key, struct RSSReaderData *d );
+void cb_search_entry_changed      ( GtkWidget *entry, struct RSSReaderData *d );
+
+
+#endif

Added: trunk/src/target/OM-2007/applications/openmoko-rssreader/src/main.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/src/main.c	2007-03-21 17:38:30 UTC (rev 1460)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/src/main.c	2007-03-21 19:13:46 UTC (rev 1461)
@@ -0,0 +1,193 @@
+/*
+ *  RSS Reader, a simple RSS reader
+ *
+ *  Copyright (C) 2007 Holger Hans Peter Freyther
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included
+ *  in all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *  Current Version: $Rev$ ($Date$) [$Author$]
+ */
+
+#include "application-data.h"
+#include "callbacks.h"
+#include <assert.h>
+
+#include <libmokoui/moko-details-window.h>
+
+/*
+ * use gettext...
+ */
+#define _(x) (x)
+#define ASSERT_X(x, error) assert(x)
+
+/*
+ * setup the toolbar
+ */
+static void setup_toolbar( struct RSSReaderData *data ) {
+    GtkButton *a;
+    GtkWidget *anImage;
+    data->box = MOKO_TOOL_BOX(moko_tool_box_new_with_search());
+    gtk_widget_grab_focus( GTK_WIDGET(data->box) );
+    g_signal_connect( G_OBJECT(data->box), "searchbox_visible",   G_CALLBACK(cb_searchbox_visible), data );
+    g_signal_connect( G_OBJECT(data->box), "searchbox_invisible", G_CALLBACK(cb_searchbox_invisible), data );
+
+
+    a = GTK_BUTTON(moko_tool_box_add_action_button( MOKO_TOOL_BOX(data->box) ));
+    anImage = gtk_image_new_from_file( PKGDATADIR "/rssreader_refresh_all.png" );
+    moko_pixmap_button_set_center_image( MOKO_PIXMAP_BUTTON(a), anImage );
+    g_signal_connect( G_OBJECT(a), "clicked", G_CALLBACK(cb_refresh_all_button_clicked), data );
+
+    a = GTK_BUTTON(moko_tool_box_add_action_button( MOKO_TOOL_BOX(data->box) ));
+    anImage = gtk_image_new_from_file( PKGDATADIR "/rssreader_subscribe.png" );
+    moko_pixmap_button_set_center_image( MOKO_PIXMAP_BUTTON(a), anImage );
+    g_signal_connect( G_OBJECT(a), "clicked", G_CALLBACK(cb_subscribe_button_clicked), data );
+
+    a = GTK_BUTTON(moko_tool_box_add_action_button( MOKO_TOOL_BOX(data->box)) );
+    gtk_button_set_label( GTK_BUTTON(a), _("Up for rent") );
+    a = GTK_BUTTON(moko_tool_box_add_action_button( MOKO_TOOL_BOX(data->box)) );
+    gtk_button_set_label( GTK_BUTTON(a), _("Buy more Mate") );
+
+    moko_paned_window_add_toolbox( MOKO_PANED_WINDOW(data->window), MOKO_TOOL_BOX(data->box) );
+}
+
+static void create_navigaton_area( struct RSSReaderData *data ) {
+    data->feed_data = gtk_list_store_new( RSS_READER_NUM_COLS,
+                                          G_TYPE_STRING /* Author    */,
+                                          G_TYPE_STRING /* Subject   */,
+                                          G_TYPE_STRING /* Date      */,
+                                          G_TYPE_STRING /* Link      */,
+                                          G_TYPE_STRING /* Text      */,
+                                          G_TYPE_INT    /* Text_Type */,
+                                          G_TYPE_STRING /* Category  */,
+                                          G_TYPE_STRING /* Source    */ );
+    data->treeView = MOKO_TREE_VIEW(moko_tree_view_new_with_model(GTK_TREE_MODEL(data->feed_data)));
+    moko_paned_window_set_upper_pane( MOKO_PANED_WINDOW(data->window), GTK_WIDGET(moko_tree_view_put_into_scrolled_window(data->treeView)) );
+
+    /*
+     * Only show the SUBJECT and DATE header
+     */
+    GtkCellRenderer *ren;
+    GtkTreeViewColumn *column;
+    ren = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
+    column = GTK_TREE_VIEW_COLUMN(gtk_tree_view_column_new_with_attributes( _("Subject"), ren, "text", RSS_READER_COLUMN_SUBJECT, NULL));
+    moko_tree_view_append_column( MOKO_TREE_VIEW(data->treeView), column );
+
+    ren = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
+    column = GTK_TREE_VIEW_COLUMN(gtk_tree_view_column_new_with_attributes( _("Date"), ren, "text", RSS_READER_COLUMN_DATE, NULL));
+    moko_tree_view_append_column( MOKO_TREE_VIEW(data->treeView), column );
+
+    /*
+     * auto completion and selection updates
+     */
+    GtkTreeSelection *selection = GTK_TREE_SELECTION(gtk_tree_view_get_selection( GTK_TREE_VIEW(data->treeView) ));
+    g_signal_connect( G_OBJECT(selection), "changed", G_CALLBACK(cb_treeview_selection_changed), data );
+
+    GtkWidget *search_entry = GTK_WIDGET(moko_tool_box_get_entry(MOKO_TOOL_BOX(data->box)));
+    g_signal_connect( G_OBJECT(data->treeView), "key_press_event", G_CALLBACK(cb_treeview_keypress_event), data );
+    g_signal_connect( G_OBJECT(search_entry),   "changed", G_CALLBACK(cb_search_entry_changed), data );
+
+}
+
+static void create_details_area( struct RSSReaderData* data ) {
+    data->tagTable   = GTK_TEXT_TAG_TABLE(gtk_text_tag_table_new());
+    data->textBuffer = GTK_TEXT_BUFFER(gtk_text_buffer_new(data->tagTable));
+    data->textView   = GTK_TEXT_VIEW(gtk_text_view_new_with_buffer(GTK_TEXT_BUFFER(data->textBuffer)));
+
+    GValue value = { 0, };
+    g_value_init( &value, G_TYPE_BOOLEAN );
+    g_value_set_boolean( &value, FALSE );
+    g_object_set_property( G_OBJECT(data->textView), "editable",       &value );
+    g_object_set_property( G_OBJECT(data->textView), "cursor-visible", &value );
+    gtk_text_view_set_wrap_mode( data->textView, GTK_WRAP_WORD_CHAR );
+
+    GtkWidget *scrollWindow = GTK_WIDGET(moko_details_window_new());
+    gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollWindow), GTK_WIDGET (data->textView));
+    moko_paned_window_set_lower_pane( MOKO_PANED_WINDOW(data->window), GTK_WIDGET(moko_details_window_put_in_box(MOKO_DETAILS_WINDOW(scrollWindow))) );
+}
+
+/*
+ * create the mainwindow
+ */
+static void setup_ui( struct RSSReaderData* data ) {
+    data->window = MOKO_PANED_WINDOW(moko_paned_window_new());
+    g_signal_connect( G_OBJECT(data->window), "delete_event", G_CALLBACK( gtk_main_quit ), NULL );
+
+    /*
+     * menu
+     */
+    data->menu = GTK_MENU(gtk_menu_new());
+    GtkMenuItem *closeitem = GTK_MENU_ITEM(gtk_menu_item_new_with_label( _("Close")));
+    g_signal_connect( G_OBJECT(closeitem), "activate", G_CALLBACK(gtk_main_quit), NULL );
+    gtk_menu_shell_append( GTK_MENU_SHELL(data->menu), GTK_WIDGET(closeitem) );
+    moko_paned_window_set_application_menu( MOKO_PANED_WINDOW(data->window), GTK_MENU(data->menu) );
+
+    /*
+     * filter
+     */
+    data->filter = GTK_MENU(gtk_menu_new());
+    moko_paned_window_set_filter_menu( MOKO_PANED_WINDOW(data->window), GTK_MENU(data->filter) );
+    data->menubox = MOKO_MENU_BOX(moko_paned_window_get_menubox( MOKO_PANED_WINDOW(data->window) ) );
+    g_signal_connect( G_OBJECT(data->menubox), "filter_changed", G_CALLBACK(cb_filter_changed), data );
+
+
+    /*
+     * tool bar
+     */
+    setup_toolbar( data );
+    create_navigaton_area( data );
+    create_details_area( data );
+}
+
+int main( int argc, char** argv )
+{
+    /*
+     * boiler plate code
+     */
+    g_debug( "openmoko-rssreader starting up" );
+
+    /*
+     * initialize threads for fetching the RSS in the background
+     */
+    g_thread_init( NULL );
+    gdk_threads_init();
+    gdk_threads_enter();
+    gtk_init( &argc, &argv );
+
+    struct RSSReaderData *data = g_new0( struct RSSReaderData, 1 );
+
+
+    data->app = MOKO_APPLICATION( moko_application_get_instance() );
+    g_set_application_name( _("FeedReader") );
+
+    setup_ui( data );
+
+    /*
+     * load data
+     */
+    refresh_categories( data );
+    moko_menu_box_set_active_filter( data->menubox, _("All") );
+
+    gtk_widget_show_all( GTK_WIDGET(data->window) );
+    gtk_main();
+    gdk_threads_leave();
+
+    return 0;
+}
+
+





More information about the commitlog mailing list