-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstamprss.c
139 lines (102 loc) · 3.28 KB
/
stamprss.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* This file is part of stamprss, a simple Webkit-based rss reader */
/* stamprss is licensed under the GPL v3 */
#include <libgrss/libgrss.h>
#include <webkit/webkit.h>
#include <gtk/gtk.h>
#include <glib.h>
typedef struct {
GtkWidget *win, *scroll, *view;
FeedsPool *fp;
time_t stamp;
FeedItem *item;
GAsyncQueue *items;
} Client;
void
feed_fetched (FeedsPool *pool,
FeedChannel *feed,
GList *items,
gpointer user_data) {
GList *iter;
FeedItem *item;
Client *c = (Client*) user_data;
printf("Fetched a feed!\n");
for (iter = items; iter; iter = g_list_next (iter)) {
item = (FeedItem*) iter->data;
if (feed_item_get_publish_time(item) >= c->stamp) {
printf("timestamp %i\n", feed_item_get_publish_time(item));
g_object_ref(item);
if (c->item == NULL) {
c->item = item;
/* update the screen here! */
} else {
g_async_queue_push(c->items, item);
}
}
}
}
gboolean
keypress_event (GtkWidget *widget,
GdkEventKey *event,
gpointer userdata) {
/* for now, just do the same thing every time */
Client *c = (Client*) userdata;
if (c->item != NULL) {
g_object_unref(c->item);
}
c->item = (FeedItem*) g_async_queue_try_pop(c->items);
if (!c->item) {
return true;
}
if (!feed_item_get_description(c->item)) {
printf ("null description\n");
}
webkit_web_view_load_string(WEBKIT_WEB_VIEW(c->view),
feed_item_get_description(c->item),
"text/html", /* MIME type */
NULL, /* encoding (default chosen) */
""); /* base URL (irrelevant here) */
return TRUE;
}
int
main (int argc,
char **argv) {
gtk_init(&argc, &argv);
/* Create the widgets */
Client *c = malloc(sizeof(Client));
c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
c->scroll = gtk_scrolled_window_new(NULL, NULL);
c->view = webkit_web_view_new();
/* Place the WebKitWebView in the GtkScrolledWindow */
gtk_container_add(GTK_CONTAINER(c->scroll), c->view);
gtk_container_add(GTK_CONTAINER(c->win), c->scroll);
g_signal_connect(G_OBJECT(c->win),
"delete_event",
G_CALLBACK(gtk_main_quit),
NULL);
GError *error = NULL;
FeedsGroup *fg = feeds_group_new();
GList *feeds = feeds_group_parse_file(fg, "feedlist.opml", error);
if (!feeds) {
printf("Error: %s\n", error->message);
}
printf ("The GList feeds has %i members\n", g_list_position(feeds, g_list_last(feeds)));
/* c->stamp = */
c->items = g_async_queue_new();
c->item = NULL;
c->stamp = 1314472098;
/* Fetch items */
c->fp = feeds_pool_new();
feeds_pool_listen(c->fp, feeds);
g_signal_connect(c->fp, "feed-ready", G_CALLBACK(feed_fetched), c);
feeds_pool_switch(c->fp, TRUE);
/* Link spacebar, enter, and so forth to "next feed" */
/* link q, etc. to "exit" */
/* link Q, etc. to "exit don't save" */
g_signal_connect(G_OBJECT(c->win), "key-press-event", G_CALLBACK(keypress_event), c);
/* Show the result */
gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600);
gtk_widget_show_all(c->win);
gtk_main();
free(c);
return 0;
}