aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-16 14:09:45 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-16 14:09:45 +0000
commit453dd5556e94b083977c08e2542dadc97d67d46e (patch)
tree28361fe87194929d3656a49e928d371d416c2e07
parent00202c91999fc4113d84b6380a4d780aeba14155 (diff)
downloadgnunet-gtk-453dd5556e94b083977c08e2542dadc97d67d46e.tar.gz
gnunet-gtk-453dd5556e94b083977c08e2542dadc97d67d46e.zip
-code towards fixing #2217
-rw-r--r--contrib/gnunet_fs_gtk_publish_tab.glade2
-rw-r--r--contrib/gnunet_fs_gtk_search_tab.glade2
-rw-r--r--contrib/gnunet_fs_gtk_unindex.glade2
-rw-r--r--src/fs/gnunet-fs-gtk_event-handler.c12
-rw-r--r--src/fs/gnunet-fs-gtk_unindex.c7
-rw-r--r--src/lib/Makefile.am1
-rw-r--r--src/lib/animations.c223
7 files changed, 247 insertions, 2 deletions
diff --git a/contrib/gnunet_fs_gtk_publish_tab.glade b/contrib/gnunet_fs_gtk_publish_tab.glade
index 346319e0..480663a4 100644
--- a/contrib/gnunet_fs_gtk_publish_tab.glade
+++ b/contrib/gnunet_fs_gtk_publish_tab.glade
@@ -16,6 +16,8 @@
16 <column type="gpointer"/> 16 <column type="gpointer"/>
17 <!-- column-name result_string --> 17 <!-- column-name result_string -->
18 <column type="gchararray"/> 18 <column type="gchararray"/>
19 <!-- column-name status_icon -->
20 <column type="GdkPixbuf"/>
19 </columns> 21 </columns>
20 </object> 22 </object>
21 <object class="GtkWindow" id="_publish_frame_window"> 23 <object class="GtkWindow" id="_publish_frame_window">
diff --git a/contrib/gnunet_fs_gtk_search_tab.glade b/contrib/gnunet_fs_gtk_search_tab.glade
index 036d9ec4..69675b89 100644
--- a/contrib/gnunet_fs_gtk_search_tab.glade
+++ b/contrib/gnunet_fs_gtk_search_tab.glade
@@ -38,6 +38,8 @@
38 <column type="gchararray"/> 38 <column type="gchararray"/>
39 <!-- column-name downloaded_anonymity --> 39 <!-- column-name downloaded_anonymity -->
40 <column type="gint"/> 40 <column type="gint"/>
41 <!-- column-name status_icon -->
42 <column type="GdkPixbuf"/>
41 </columns> 43 </columns>
42 </object> 44 </object>
43 <object class="GtkWindow" id="_search_result_frame_window"> 45 <object class="GtkWindow" id="_search_result_frame_window">
diff --git a/contrib/gnunet_fs_gtk_unindex.glade b/contrib/gnunet_fs_gtk_unindex.glade
index b1872235..95fe85b1 100644
--- a/contrib/gnunet_fs_gtk_unindex.glade
+++ b/contrib/gnunet_fs_gtk_unindex.glade
@@ -18,6 +18,8 @@
18 <column type="gboolean"/> 18 <column type="gboolean"/>
19 <!-- column-name error_message --> 19 <!-- column-name error_message -->
20 <column type="gchararray"/> 20 <column type="gchararray"/>
21 <!-- column-name status_icon -->
22 <column type="GdkPixbuf"/>
21 </columns> 23 </columns>
22 </object> 24 </object>
23 <object class="GtkDialog" id="GNUNET_FS_GTK_unindex_dialog"> 25 <object class="GtkDialog" id="GNUNET_FS_GTK_unindex_dialog">
diff --git a/src/fs/gnunet-fs-gtk_event-handler.c b/src/fs/gnunet-fs-gtk_event-handler.c
index 74a87598..003a2ea7 100644
--- a/src/fs/gnunet-fs-gtk_event-handler.c
+++ b/src/fs/gnunet-fs-gtk_event-handler.c
@@ -119,6 +119,12 @@ enum SEARCH_TAB_ModelColumns
119 * A gint. 119 * A gint.
120 */ 120 */
121 SEARCH_TAB_MC_DOWNLOADED_ANONYMITY = 16, 121 SEARCH_TAB_MC_DOWNLOADED_ANONYMITY = 16,
122
123 /**
124 * A GdkPixbuf.
125 */
126 SEARCH_TAB_MC_STATUS_ICON = 17
127
122 }; 128 };
123 129
124 130
@@ -156,6 +162,11 @@ enum PUBLISH_TAB_ModelColumns
156 * A gchararray. 162 * A gchararray.
157 */ 163 */
158 PUBLISH_TAB_MC_RESULT_STRING = 5, 164 PUBLISH_TAB_MC_RESULT_STRING = 5,
165
166 /**
167 * A GdkPixbuf.
168 */
169 PUBLISH_TAB_MC_STATUS_ICON = 6
159 }; 170 };
160 171
161 172
@@ -218,7 +229,6 @@ struct PublishEntry
218}; 229};
219 230
220 231
221
222/** 232/**
223 * Head of linked list of tabs for searches. 233 * Head of linked list of tabs for searches.
224 */ 234 */
diff --git a/src/fs/gnunet-fs-gtk_unindex.c b/src/fs/gnunet-fs-gtk_unindex.c
index a3b5cf94..5c730c96 100644
--- a/src/fs/gnunet-fs-gtk_unindex.c
+++ b/src/fs/gnunet-fs-gtk_unindex.c
@@ -67,7 +67,12 @@ enum UNINDEX_ModelColumns
67 /** 67 /**
68 * A gchararray. 68 * A gchararray.
69 */ 69 */
70 UNINDEX_MC_ERROR = 6 70 UNINDEX_MC_ERROR = 6,
71
72 /**
73 * A GdkPixbuf.
74 */
75 UNINDEX_MC_STATUS_ICON = 7
71 }; 76 };
72 77
73 78
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 8113885f..156e44a6 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -13,6 +13,7 @@ lib_LTLIBRARIES = libgnunetgtk.la
13 13
14libgnunetgtk_la_SOURCES = \ 14libgnunetgtk_la_SOURCES = \
15 about.c \ 15 about.c \
16 animations.c \
16 eventloop.c \ 17 eventloop.c \
17 glade.c \ 18 glade.c \
18 nls.c \ 19 nls.c \
diff --git a/src/lib/animations.c b/src/lib/animations.c
new file mode 100644
index 00000000..8a66a6dd
--- /dev/null
+++ b/src/lib/animations.c
@@ -0,0 +1,223 @@
1/*
2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file src/lib/animations.c
23 * @brief drawing animations in gnunet-gtk
24 * @author Christian Grothoff
25 * @author LRN
26 */
27#include "gnunet_gtk.h"
28
29
30#define TICKER_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100)
31
32
33struct GNUNET_FS_AnimationContext
34{
35 struct GNUNET_FS_AnimationContext *next;
36
37 struct GNUNET_FS_AnimationContext *prev;
38
39 GdkPixbufAnimation *ani;
40
41 GdkPixbufAnimationIter *iter;
42
43 GdkPixbuf *pixbuf;
44
45};
46
47
48struct GNUNET_FS_AnimationTreeViewHandle
49{
50 struct GNUNET_FS_AnimationTreeViewHandle *next;
51
52 struct GNUNET_FS_AnimationTreeViewHandle *prev;
53
54 GtkTreeView *tv;
55
56 GtkTreeViewColumn *image_col;
57};
58
59
60static struct GNUNET_FS_AnimationContext *animation_head;
61
62static struct GNUNET_FS_AnimationContext *animation_tail;
63
64static struct GNUNET_FS_AnimationTreeViewHandle *atv_head;
65
66static struct GNUNET_FS_AnimationTreeViewHandle *atv_tail;
67
68static GNUNET_SCHEDULER_TaskIdentifier ticker_task;
69
70
71struct GNUNET_FS_AnimationContext *
72GNUNET_GTK_animation_context_create (const char *filename)
73{
74 GError *err = NULL;
75 struct GNUNET_FS_AnimationContext *ac;
76
77 ac = GNUNET_malloc (sizeof (struct GNUNET_FS_AnimationContext));
78 ac->ani = gdk_pixbuf_animation_new_from_file (filename, &err);
79 ac->iter = gdk_pixbuf_animation_get_iter (ac->ani, NULL);
80 ac->pixbuf = gdk_pixbuf_copy (gdk_pixbuf_animation_iter_get_pixbuf (ac->iter));
81 GNUNET_CONTAINER_DLL_insert (animation_head,
82 animation_tail,
83 ac);
84 return ac;
85}
86
87
88void
89GNUNET_GTK_animation_context_destroy (struct GNUNET_FS_AnimationContext *ac)
90{
91 g_object_unref (ac->pixbuf);
92 g_object_unref (ac->iter);
93 g_object_unref (ac->ani);
94 GNUNET_CONTAINER_DLL_remove (animation_head,
95 animation_tail,
96 ac);
97 GNUNET_free (ac);
98}
99
100
101GdkPixbuf *
102GNUNET_GTK_animation_context_get_pixbuf (struct GNUNET_FS_AnimationContext *ac)
103{
104 return ac->pixbuf;
105}
106
107
108/**
109 * Advance the given animation by a frame, if the time is ripe.
110 *
111 * @param ac animation to advance
112 * @return 0 if nothing needed to be done
113 */
114static int
115tick_animation (struct GNUNET_FS_AnimationContext *ac)
116{
117 GdkPixbuf *pixbuf;
118 gint width;
119 gint height;
120
121 if (!gdk_pixbuf_animation_iter_advance (ac->iter, NULL))
122 return 0;
123 pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (ac->iter);
124 width = gdk_pixbuf_get_width (pixbuf);
125 height = gdk_pixbuf_get_height (pixbuf);
126 gdk_pixbuf_copy_area (pixbuf, 0, 0, width, height, ac->pixbuf, 0, 0);
127 return 1;
128}
129
130
131static void
132redraw_tree_view (struct GNUNET_FS_AnimationTreeViewHandle *atv)
133{
134 GdkWindow *gw;
135 GdkRectangle r;
136 GdkRectangle tr;
137 gint x;
138 gint width;
139
140 gw = gtk_widget_get_window (GTK_WIDGET (atv->tv));
141
142 /* Get column x and width in bin window coordinates */
143 gtk_tree_view_get_cell_area (atv->tv, NULL, atv->image_col, &r);
144 /* Convert x and width to window coordinates */
145 x = r.x;
146 width = r.width;
147 gtk_tree_view_convert_bin_window_to_widget_coords (atv->tv, x, 0, &r.x, NULL);
148 gtk_tree_view_convert_bin_window_to_widget_coords (atv->tv, x + width, 0, &r.width, NULL);
149
150 /* Get visible area of the treeview, in tree coordinates */
151 gtk_tree_view_get_visible_rect (atv->tv, &tr);
152
153 /* Convert y and height of the visible area to widget coordinates */
154 gtk_tree_view_convert_tree_to_widget_coords (atv->tv, 0, tr.y, NULL, &r.y);
155 gtk_tree_view_convert_tree_to_widget_coords (atv->tv, 0, tr.y + tr.height, NULL, &r.height);
156
157 /* r now encloses only column image_col, redraw it */
158 gdk_window_invalidate_rect (gw, &r, TRUE);
159}
160
161
162/**
163 * Task run periodically to advance all of our animations.
164 *
165 * @param cls closure, unused
166 * @param tc scheduler context, unused
167 */
168static void
169ticker (void *cls,
170 const struct GNUNET_SCHEDULER_TaskContext *tc)
171{
172 struct GNUNET_FS_AnimationContext *pos;
173 struct GNUNET_FS_AnimationTreeViewHandle *atv;
174 unsigned int counter;
175
176 ticker_task = GNUNET_SCHEDULER_add_delayed (TICKER_DELAY,
177 &ticker,
178 NULL);
179 counter = 0;
180 for (pos = animation_head; NULL != pos; pos = pos->next)
181 counter += tick_animation (pos);
182 if (0 == counter)
183 return; /* nothing to be done */
184 for (atv = atv_head; NULL != atv; atv = atv->next)
185 redraw_tree_view (atv);
186}
187
188
189struct GNUNET_FS_AnimationTreeViewHandle *
190GNUNET_GTK_animation_tree_view_register (GtkTreeView *tv,
191 GtkTreeViewColumn *image_col)
192{
193 struct GNUNET_FS_AnimationTreeViewHandle *atv;
194
195 atv = GNUNET_malloc (sizeof (struct GNUNET_FS_AnimationTreeViewHandle));
196 atv->tv = tv;
197 atv->image_col = image_col;
198 GNUNET_CONTAINER_DLL_insert (atv_head,
199 atv_tail,
200 atv);
201 if (GNUNET_SCHEDULER_NO_TASK == ticker_task)
202 ticker_task = GNUNET_SCHEDULER_add_delayed (TICKER_DELAY,
203 &ticker,
204 NULL);
205 return atv;
206}
207
208
209void
210GNUNET_GTK_animation_tree_view_unregister (struct GNUNET_FS_AnimationTreeViewHandle *atv)
211{
212 GNUNET_CONTAINER_DLL_remove (atv_head,
213 atv_tail,
214 atv);
215 GNUNET_free (atv);
216 if (NULL != atv_head)
217 return;
218 GNUNET_SCHEDULER_cancel (ticker_task);
219 ticker_task = GNUNET_SCHEDULER_NO_TASK;
220}
221
222
223/* end of animations.c */