(no commit message)
authorJean-Philippe Orsini <jeanfi@gmail.com>
Thu, 2 May 2013 20:18:44 +0000 (20:18 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Thu, 2 May 2013 20:18:44 +0000 (20:18 +0000)
src/glade/prss.glade
src/ttrss_ws.c
src/ttrss_wsasync.c

index 1c7a070..aff2879 100644 (file)
                     <property name="model">feed_store</property>
                     <property name="headers_visible">False</property>
                     <property name="headers_clickable">False</property>
                     <property name="model">feed_store</property>
                     <property name="headers_visible">False</property>
                     <property name="headers_clickable">False</property>
+                    <property name="reorderable">True</property>
                     <property name="fixed_height_mode">True</property>
                     <property name="enable_tree_lines">True</property>
                     <signal name="cursor-changed" handler="feed_cursor_changed_cbk" swapped="no"/>
                     <property name="fixed_height_mode">True</property>
                     <property name="enable_tree_lines">True</property>
                     <signal name="cursor-changed" handler="feed_cursor_changed_cbk" swapped="no"/>
                         <property name="min_width">1</property>
                         <property name="title" translatable="yes">Feed</property>
                         <property name="expand">True</property>
                         <property name="min_width">1</property>
                         <property name="title" translatable="yes">Feed</property>
                         <property name="expand">True</property>
+                        <property name="reorderable">True</property>
+                        <property name="sort_indicator">True</property>
+                        <property name="sort_column_id">0</property>
                         <child>
                           <object class="GtkCellRendererText" id="cellrenderertext5"/>
                           <attributes>
                         <child>
                           <object class="GtkCellRendererText" id="cellrenderertext5"/>
                           <attributes>
index ac6ee06..2c0da73 100644 (file)
@@ -135,7 +135,7 @@ execute(struct http_session *sess, struct json_object *rq, char **err)
                        if (str) {
                                log_debug("execute() err=%s", str);
                                content = NULL;
                        if (str) {
                                log_debug("execute() err=%s", str);
                                content = NULL;
-                               
+
                                if (err)
                                        *err = strdup(str);
                        } else {
                                if (err)
                                        *err = strdup(str);
                        } else {
index cb30f84..f3c3d84 100644 (file)
 #include "ttrss_ws.h"
 #include "ttrss_wsasync.h"
 
 #include "ttrss_ws.h"
 #include "ttrss_wsasync.h"
 
+struct async_request {
+       void *data;
+       struct json_object *request;
+       void (*callback)(struct json_object *, void *);
+};
+
 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 
 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 
-static struct json_object **requests;
+static struct async_request **requests;
 
 static pthread_t *thread;
 
 
 static pthread_t *thread;
 
-void *loop()
+static void async_request_free(struct async_request *rq)
 {
 {
-       struct json_object **tmp, **cur, *rp, *rq;
+       if (rq) {
+               if (rq->request)
+                       json_object_put(rq->request);
+               free(rq);
+       }
+}
+
+static void *loop()
+{
+       struct json_object *rp;
+       struct async_request **tmp, **cur, *rq;
 
        while (1) {
                log_debug("loop()");
 
        while (1) {
                log_debug("loop()");
@@ -55,10 +71,15 @@ void *loop()
                        cur = tmp;
                        while (*cur) {
                                rq = *cur;
                        cur = tmp;
                        while (*cur) {
                                rq = *cur;
-                               rp = ws_execute(rq);
-                               json_object_put(rq);
+                               rp = ws_execute(rq->request);
+
+                               if (rq->callback)
+                                       rq->callback(rp, rq->data);
+
+                               async_request_free(rq);
                                if (rp)
                                        json_object_put(rp);
                                if (rp)
                                        json_object_put(rp);
+
                                cur++;
                                usleep(100000);
                        }
                                cur++;
                                usleep(100000);
                        }
@@ -72,24 +93,44 @@ void *loop()
        pthread_exit(NULL);
 }
 
        pthread_exit(NULL);
 }
 
-void ws_async_set_article_unread(int id, int unread)
+static struct async_request *
+add_async_request(struct json_object *rq,
+                 void (*callback)(struct json_object *, void *data),
+                 void *data)
 {
 {
-       struct json_object *rq, **tmp;
-
-       log_debug("ws_async_set_article_unread(%d,%d)", id, unread);
-
-       rq = ws_request_new_set_article_unread(id, unread);
+       struct async_request *async_rq;
+       struct async_request **tmp;
 
        pthread_mutex_lock(&lock);
        if (!thread) {
                thread = malloc(sizeof(pthread_t));
                pthread_create(thread, NULL, loop, NULL);
        }
 
        pthread_mutex_lock(&lock);
        if (!thread) {
                thread = malloc(sizeof(pthread_t));
                pthread_create(thread, NULL, loop, NULL);
        }
+       pthread_mutex_unlock(&lock);
+
+       async_rq = malloc(sizeof(struct async_request));
+       async_rq->request = rq;
+       async_rq->data = data;
+       async_rq->callback = callback;
 
 
-       tmp = (struct json_object **)list_add((void **)requests, rq);
+       pthread_mutex_lock(&lock);
+       tmp = (struct async_request **)list_add((void **)requests, async_rq);
        list_free((void **)requests);
        requests = tmp;
        pthread_mutex_unlock(&lock);
 
        list_free((void **)requests);
        requests = tmp;
        pthread_mutex_unlock(&lock);
 
+       return async_rq;
+}
+
+void ws_async_set_article_unread(int id, int unread)
+{
+       struct json_object *rq;
+
+       log_debug("ws_async_set_article_unread(%d,%d)", id, unread);
+
+       rq = ws_request_new_set_article_unread(id, unread);
+
+       add_async_request(rq, NULL, NULL);
+
        log_debug("ws_async_set_article_unread(%d,%d) done", id, unread);
 }
        log_debug("ws_async_set_article_unread(%d,%d) done", id, unread);
 }