(no commit message)
authorJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 22 Apr 2013 19:27:14 +0000 (19:27 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 22 Apr 2013 19:27:14 +0000 (19:27 +0000)
src/glade/prss.glade
src/main.c
src/ttrss.c

index 37c45b6..3315f2c 100644 (file)
@@ -1,6 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkAction" id="action1">
+    <property name="label" translatable="yes">Refresh</property>
+    <property name="stock_id">gtk-refresh</property>
+  </object>
   <object class="GtkListStore" id="feed_store">
     <columns>
       <!-- column-name gchararray1 -->
           </packing>
         </child>
         <child>
+          <object class="GtkToolbar" id="toolbar1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkToolButton" id="refresh">
+                <property name="related_action">action1</property>
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">toolbutton1</property>
+                <property name="use_underline">True</property>
+                <signal name="clicked" handler="refresh_clicked_cbk" swapped="no"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
           <object class="GtkPaned" id="paned1">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
           <packing>
             <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="position">1</property>
+            <property name="position">2</property>
           </packing>
         </child>
       </object>
index 73d537d..7a50b5c 100644 (file)
@@ -85,9 +85,10 @@ void update()
                    g_settings_get_string(settings, "password"));
 
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
-       gtk_list_store_clear(GTK_LIST_STORE(model));
 
-       for (feeds = ttrss_get_feeds(); *feeds; feeds++) {
+       gtk_list_store_clear(GTK_LIST_STORE(model));
+       feeds = ttrss_get_feeds();
+       while(feeds && *feeds) {
                if ((*feeds)->unread)
                        title = g_strdup_printf("<b>%s (%d)</b>",
                                                (*feeds)->title,
@@ -104,10 +105,17 @@ void update()
                                   1, (*feeds),
                                   -1);
                free(title);
+               feeds++;
        }
        printf("refresh done\n");
 }
 
+void refresh_clicked_cbk(GtkWidget *btn, gpointer data)
+{
+       printf("refresh_clicked_cbk\n");
+       update();
+}
+
 void settings_activate_cbk(GtkWidget *menu_item, gpointer data)
 {
        GtkDialog *diag;
@@ -300,8 +308,6 @@ int main(int argc, char **argv)
 
        gtk_widget_show_all(window);
 
-       update();
-
        gtk_main();
 
        exit(EXIT_SUCCESS);
index 89fbd94..ec67cc8 100644 (file)
@@ -70,13 +70,13 @@ void ttrss_login(const char *url, const char *user, const char *password)
 
        content = json_object_object_get(rp, "content");
        if (!content) {
-               fprintf(stderr, "Login failed: no content");
+               fprintf(stderr, "Login failed: no content\n");
                return ;
        }
 
        error = json_object_object_get(content, "error");
        if (error) {
-               fprintf(stderr, "Login failed");
+               fprintf(stderr, "Login failed\n");
                return ;
        }
 
@@ -147,11 +147,45 @@ static struct headline **get_headlines(int feed_id)
        return headlines;
 }
 
+static int feeds_length(struct feed **list)
+{
+       int n;
+
+       if (!list)
+               return 0;
+       
+       n = 0;
+       while(*list) {
+               n++;
+               list++;
+       }
+
+       return n;
+}
+
+static struct feed **feeds_add(struct feed **feeds, struct feed *feed)
+{
+       int n;
+       struct feed **result;
+
+       n = feeds_length(feeds);
+
+       result = malloc((n + 1 + 1) * sizeof(struct feed *));
+
+       if (feeds)
+               memcpy(result, feeds, n * sizeof(struct feed *));
+
+       result[n] = feed;
+       result[n + 1] = NULL;
+
+       return result;
+}
+
 struct feed **ttrss_get_feeds()
 {
        struct json_object *rp, *rq, *content, *jfeed, *j;
        int i, n;
-       struct feed **feeds, *feed;
+       struct feed **feeds, *feed, **tmp;
 
        printf("ttrss_get_feeds\n");
 
@@ -165,7 +199,7 @@ struct feed **ttrss_get_feeds()
        if (content) {
                n = json_object_array_length(content);
 
-               feeds = malloc((n+1) * sizeof(struct feed *));
+               feeds = NULL;
                for (i = 0; i < n; i++) {
                        jfeed = json_object_array_get_idx(content, i);
 
@@ -185,9 +219,10 @@ struct feed **ttrss_get_feeds()
 
                        feed->headlines = NULL;
 
-                       feeds[i] = feed;
+                       tmp = feeds_add(feeds, feed);
+                       free(feeds);
+                       feeds = tmp;
                }
-               feeds[n] = NULL;
        } else {
                feeds = NULL;
        }