|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
1 |
#include <gtk/gtk.h>
|
2 |
#include <couchdb-glib.h>
|
|
3 |
||
4 |
#include "kangaroo-feed-channel.h"
|
|
|
69
by Krzysztof Klimonda
[tests] update gtk-cell-renderers |
5 |
#include "kangaroo-feed-pool.h"
|
6 |
#include "kangaroo-feed-store.h"
|
|
|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
7 |
#include "kangaroo-cell-renderer-channel.h"
|
8 |
||
9 |
#include "test-helpers.h"
|
|
10 |
||
|
69
by Krzysztof Klimonda
[tests] update gtk-cell-renderers |
11 |
static KangarooFeedPool *pool; |
|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
12 |
static GtkListStore *model; |
|
73
by Krzysztof Klimonda
[tests] display items in gtk-cell-renderers |
13 |
static GtkWidget *channel_items; |
|
86
by Krzysztof Klimonda
[tests] gtk-cell-renderers: write more code |
14 |
static KangarooFeedStore *store; |
|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
15 |
|
16 |
/* when adding/removing feeds don't forget to change
|
|
17 |
* g_atomic_int_set call in feed_pool_setup */
|
|
18 |
static const feed_t feeds[] = { |
|
19 |
{"debian", "feeds/debian_rss20.xml"}, |
|
20 |
{"ubuntu", "feeds/ubuntu_rss20.xml"}, |
|
21 |
{"gnome", "feeds/gnome_rss20.xml"}, |
|
22 |
{ NULL } |
|
23 |
};
|
|
24 |
||
25 |
enum { |
|
26 |
COLUMN_CHANNEL, |
|
27 |
N_COLUMNS
|
|
28 |
};
|
|
29 |
||
|
73
by Krzysztof Klimonda
[tests] display items in gtk-cell-renderers |
30 |
enum { |
31 |
ITEM_COLUMN_DATE, |
|
32 |
ITEM_COLUMN_AUTHOR, |
|
33 |
ITEM_COLUMN_TITLE, |
|
34 |
ITEM_N_COLUMNS
|
|
35 |
};
|
|
36 |
||
37 |
void
|
|
38 |
update_items_view (GtkTreeView *channel_view, gpointer user_data) |
|
39 |
{
|
|
40 |
GtkTreePath *path; |
|
41 |
GtkTreeIter iter; |
|
42 |
GtkTreeModel *model; |
|
43 |
KangarooFeedChannel *channel; |
|
44 |
GList *items, *item; |
|
45 |
||
46 |
model = gtk_tree_view_get_model (channel_view); |
|
47 |
gtk_tree_view_get_cursor (channel_view, &path, NULL); |
|
48 |
gtk_tree_model_get_iter (model, &iter, path); |
|
49 |
gtk_tree_model_get (model, &iter, COLUMN_CHANNEL, &channel, -1); |
|
50 |
||
51 |
items = kangaroo_feed_channel_get_items (channel); |
|
52 |
||
53 |
/* it may not be efficient.. at all */
|
|
54 |
model = gtk_tree_view_get_model (GTK_TREE_VIEW (channel_items)); |
|
55 |
gtk_list_store_clear (GTK_LIST_STORE (model)); |
|
56 |
||
57 |
for (item = items; item != NULL; item = g_list_next (item)) |
|
58 |
{
|
|
59 |
GtkTreeIter iter; |
|
60 |
KangarooFeedItem *i; |
|
61 |
const char *date, *author, *title; |
|
62 |
||
63 |
author = "(NULL)"; |
|
64 |
title = kangaroo_feed_item_get_title (item->data); |
|
|
86
by Krzysztof Klimonda
[tests] gtk-cell-renderers: write more code |
65 |
date = g_date_time_format (kangaroo_feed_item_get_updated (item->data), |
66 |
"%H:%M:%s"); |
|
|
73
by Krzysztof Klimonda
[tests] display items in gtk-cell-renderers |
67 |
|
68 |
gtk_list_store_append (GTK_LIST_STORE (model), &iter); |
|
69 |
gtk_list_store_set (GTK_LIST_STORE (model), &iter, |
|
70 |
ITEM_COLUMN_DATE, date, |
|
71 |
ITEM_COLUMN_AUTHOR, author, |
|
72 |
ITEM_COLUMN_TITLE, title, -1); |
|
73 |
}
|
|
74 |
}
|
|
75 |
||
|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
76 |
void
|
77 |
create_interface (GtkWidget *window) |
|
78 |
{
|
|
79 |
GtkWidget *chooser, *box; |
|
80 |
GtkCellRenderer *renderer; |
|
81 |
GtkTreeViewColumn *column; |
|
|
73
by Krzysztof Klimonda
[tests] display items in gtk-cell-renderers |
82 |
GtkScrolledWindow *scrolled; |
|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
83 |
|
|
73
by Krzysztof Klimonda
[tests] display items in gtk-cell-renderers |
84 |
scrolled = gtk_scrolled_window_new (NULL, NULL); |
|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
85 |
chooser = gtk_tree_view_new (); |
|
73
by Krzysztof Klimonda
[tests] display items in gtk-cell-renderers |
86 |
channel_items = gtk_tree_view_new (); |
87 |
||
88 |
model = gtk_list_store_new (ITEM_N_COLUMNS, G_TYPE_STRING, |
|
89 |
G_TYPE_STRING, G_TYPE_STRING); |
|
90 |
||
91 |
gtk_tree_view_set_model (GTK_TREE_VIEW (channel_items), GTK_TREE_MODEL (model)); |
|
92 |
||
93 |
renderer = gtk_cell_renderer_text_new (); |
|
94 |
column = gtk_tree_view_column_new_with_attributes ("Published", renderer, |
|
95 |
"text", ITEM_COLUMN_DATE, NULL); |
|
96 |
gtk_tree_view_append_column (GTK_TREE_VIEW (channel_items), column); |
|
97 |
||
98 |
renderer = gtk_cell_renderer_text_new (); |
|
99 |
column = gtk_tree_view_column_new_with_attributes ("Author", renderer, |
|
100 |
"text", ITEM_COLUMN_AUTHOR, |
|
101 |
NULL); |
|
102 |
gtk_tree_view_append_column (GTK_TREE_VIEW (channel_items), column); |
|
103 |
||
104 |
renderer = gtk_cell_renderer_text_new (); |
|
105 |
column = gtk_tree_view_column_new_with_attributes ("Title", renderer, |
|
106 |
"text", ITEM_COLUMN_TITLE, NULL); |
|
107 |
gtk_tree_view_append_column (GTK_TREE_VIEW (channel_items), column); |
|
108 |
||
109 |
g_signal_connect (chooser, "cursor-changed", G_CALLBACK (update_items_view), NULL); |
|
|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
110 |
|
111 |
model = gtk_list_store_new (N_COLUMNS, KANGAROO_TYPE_FEED_CHANNEL); |
|
112 |
gtk_tree_view_set_model (GTK_TREE_VIEW (chooser), GTK_TREE_MODEL (model)); |
|
113 |
||
114 |
renderer = kangaroo_cell_renderer_channel_new (); |
|
115 |
column = gtk_tree_view_column_new_with_attributes ("Channel", renderer, |
|
116 |
"channel", COLUMN_CHANNEL, NULL); |
|
117 |
gtk_tree_view_append_column (GTK_TREE_VIEW (chooser), column); |
|
118 |
||
|
73
by Krzysztof Klimonda
[tests] display items in gtk-cell-renderers |
119 |
gtk_container_add (GTK_CONTAINER (scrolled), channel_items); |
120 |
box = gtk_hbox_new (FALSE, 1); |
|
|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
121 |
gtk_box_pack_start (GTK_BOX (box), chooser, TRUE, TRUE, 0); |
|
73
by Krzysztof Klimonda
[tests] display items in gtk-cell-renderers |
122 |
gtk_box_pack_start (GTK_BOX (box), scrolled, TRUE, TRUE, 0); |
|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
123 |
|
124 |
gtk_container_add (GTK_CONTAINER (window), box); |
|
125 |
}
|
|
126 |
||
|
69
by Krzysztof Klimonda
[tests] update gtk-cell-renderers |
127 |
void
|
128 |
kangaroo_feed_channel_update_unread_count (KangarooFeedChannel * channel, |
|
129 |
GList * items) |
|
130 |
{
|
|
131 |
guint unread; |
|
132 |
||
133 |
unread = kangaroo_feed_channel_get_unread_count (channel); |
|
134 |
}
|
|
135 |
||
136 |
void
|
|
137 |
update_store (KangarooFeedPool * pool, KangarooFeedChannel * channel, |
|
138 |
GList *items) |
|
139 |
{
|
|
140 |
GtkTreeIter iter; |
|
141 |
KangarooFeedChannel *stored; |
|
|
86
by Krzysztof Klimonda
[tests] gtk-cell-renderers: write more code |
142 |
GList *item; |
143 |
||
144 |
for (item = items; item != NULL; item = g_list_next (item)) |
|
145 |
{
|
|
146 |
kangaroo_feed_store_add_item (store, channel, item->data); |
|
147 |
}
|
|
|
69
by Krzysztof Klimonda
[tests] update gtk-cell-renderers |
148 |
|
149 |
gtk_list_store_append (model, &iter); |
|
150 |
gtk_list_store_set (model, &iter, COLUMN_CHANNEL, channel, -1); |
|
151 |
||
152 |
g_object_unref (channel); |
|
153 |
g_list_foreach (items, (GFunc) g_object_unref, NULL); |
|
154 |
g_list_free (items); |
|
155 |
}
|
|
156 |
||
157 |
void
|
|
158 |
load_channels () |
|
159 |
{
|
|
160 |
KangarooFeedChannel *channel; |
|
161 |
||
162 |
channel = kangaroo_feed_channel_new (); |
|
163 |
kangaroo_feed_channel_set_source (channel, |
|
164 |
"http://planet.ubuntu.com/rss20.xml"); |
|
165 |
kangaroo_feed_pool_add_channel (pool, channel); |
|
166 |
g_object_unref (channel); |
|
167 |
channel = kangaroo_feed_channel_new (); |
|
168 |
kangaroo_feed_channel_set_source (channel, |
|
169 |
"http://planet.debian.org/rss20.xml"); |
|
170 |
kangaroo_feed_pool_add_channel (pool, channel); |
|
171 |
g_object_unref (channel); |
|
172 |
channel = kangaroo_feed_channel_new (); |
|
173 |
kangaroo_feed_channel_set_source (channel, |
|
174 |
"http://www.aljazeera.net/AljazeeraRss/Rss.aspx?URL=RSS-Portal.xml"); |
|
175 |
kangaroo_feed_pool_add_channel (pool, channel); |
|
176 |
g_object_unref (channel); |
|
177 |
channel = kangaroo_feed_channel_new (); |
|
178 |
kangaroo_feed_channel_set_source (channel, |
|
179 |
"http://planet.gnome.org/rss20.xml"); |
|
180 |
kangaroo_feed_pool_add_channel (pool, channel); |
|
181 |
g_object_unref (channel); |
|
182 |
}
|
|
183 |
||
|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
184 |
int
|
185 |
main (int argc, char ** argv) |
|
186 |
{
|
|
187 |
CouchdbSession *session; |
|
188 |
GtkWidget *window; |
|
189 |
KangarooFeedChannel *channel; |
|
|
69
by Krzysztof Klimonda
[tests] update gtk-cell-renderers |
190 |
GError *error; |
191 |
||
192 |
error = NULL; |
|
|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
193 |
|
|
86
by Krzysztof Klimonda
[tests] gtk-cell-renderers: write more code |
194 |
gtk_init (&argc, &argv); |
195 |
||
196 |
session = couchdb_session_new ("http://localhost:5985"); |
|
197 |
||
198 |
store = kangaroo_feed_store_new (session); |
|
199 |
kangaroo_feed_store_bootstrap (store, &error); |
|
200 |
if (error != NULL) |
|
201 |
{
|
|
202 |
if (error->code != KANGAROO_FEED_STORE_ERROR_BOOTSTRAP_FAILED) |
|
203 |
{
|
|
204 |
g_critical ("Unexpected error: %s", error->message); |
|
205 |
}
|
|
206 |
}
|
|
207 |
kangaroo_feed_store_connect (store, NULL); |
|
208 |
||
|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
209 |
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
210 |
g_signal_connect (window, "destroy", (GCallback) gtk_main_quit, NULL); |
|
211 |
create_interface (window); |
|
212 |
||
|
69
by Krzysztof Klimonda
[tests] update gtk-cell-renderers |
213 |
pool = kangaroo_feed_pool_new (); |
214 |
g_signal_connect (pool, "channel-ready", G_CALLBACK (update_store), NULL); |
|
215 |
kangaroo_feed_pool_set_update_interval (pool, 60); |
|
216 |
load_channels (); |
|
217 |
kangaroo_feed_pool_set_enabled (pool, TRUE); |
|
218 |
||
|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
219 |
gtk_widget_show_all (window); |
220 |
||
221 |
gtk_main (); |
|
222 |
||
223 |
g_object_unref (model); |
|
|
69
by Krzysztof Klimonda
[tests] update gtk-cell-renderers |
224 |
g_object_unref (pool); |
|
53
by Krzysztof Klimonda
[tests] rewrite gtk-cell-renderers in C |
225 |
}
|