2
* Authors: Rodney Dawes <dobey@gnome.org>
4
* Copyright 2008-2009 Rodney Dawes
12
#include "sw-taskview.h"
14
#include <glib/gi18n.h>
15
#include <gtk/gtkcelleditable.h>
16
#include <gtk/gtkcellrenderer.h>
17
#include <gtk/gtkcellrendererpixbuf.h>
18
#include <gtk/gtkcellrenderertext.h>
19
#include <gtk/gtkbutton.h>
20
#include <gtk/gtkhbox.h>
21
#include <gtk/gtklabel.h>
22
#include <gtk/gtkliststore.h>
23
#include <gtk/gtkscrolledwindow.h>
24
#include <gtk/gtkstock.h>
25
#include <gtk/gtktreeview.h>
26
#include <gtk/gtktreeviewcolumn.h>
27
#include <gtk/gtkvbox.h>
30
struct _SWTaskViewPrivate {
43
SW_ACTIVITY_COLUMN = 0,
50
static void sw_taskview_finalize (GObject * object);
52
/* GtkObject Methods */
53
static void sw_taskview_destroy (GtkObject * object);
55
G_DEFINE_TYPE (SWTaskView, sw_taskview, GTK_TYPE_EVENT_BOX)
57
static void sw_taskview_class_init (SWTaskViewClass * klass) {
58
GObjectClass * o_class;
59
GtkObjectClass * obj_class;
60
GtkWidgetClass * wid_class;
62
o_class = (GObjectClass *) klass;
63
obj_class = (GtkObjectClass *) klass;
64
wid_class = (GtkWidgetClass *) klass;
67
o_class->finalize = sw_taskview_finalize;
69
/* GtkObject Methods */
70
obj_class->destroy = sw_taskview_destroy;
73
static gboolean sw_taskview_ebox_expose (GtkWidget * widget,
74
GdkEventExpose * event,
76
gtk_paint_shadow (widget->style, widget->window, GTK_STATE_NORMAL,
77
GTK_SHADOW_OUT, &event->area, widget, "toolbar",
78
0, 0, widget->allocation.width, widget->allocation.height);
80
gtk_container_propagate_expose (GTK_CONTAINER (widget),
81
GTK_BIN (widget)->child,
87
static void sw_taskview_edit_started (GtkCellRenderer * cell,
88
GtkCellEditable * editable,
90
SWTaskView * taskview) {
91
SWTaskViewPrivate * priv;
95
priv = taskview->priv;
97
gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (priv->store),
99
gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
100
SW_TASKUID_COLUMN, &uid, -1);
106
static void sw_taskview_edit_finished (GtkCellRendererText * cell,
109
SWTaskView * taskview) {
110
SWTaskViewPrivate * priv;
115
priv = taskview->priv;
117
gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (priv->store),
119
gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
120
SW_TASKUID_COLUMN, &uid, -1);
122
if (uid == 0 && strcmp (text, _("Click here to add a new task...")) != 0) {
127
static int sw_taskview_sort (GtkTreeModel * model,
128
GtkTreeIter * a, GtkTreeIter * b,
130
unsigned int uida, uidb;
131
const char * stra, * strb;
133
gtk_tree_model_get (model, a,
134
SW_TASKUID_COLUMN, &uida,
135
SW_TASKINFO_COLUMN, &stra,
137
gtk_tree_model_get (model, b,
138
SW_TASKUID_COLUMN, &uidb,
139
SW_TASKINFO_COLUMN, &strb,
147
return g_utf8_collate (stra, strb);
150
static void sw_taskview_init (SWTaskView * taskview) {
151
SWTaskViewPrivate * priv;
155
GtkTreeViewColumn * column;
156
GtkCellRenderer * renderer;
159
priv = g_new0 (SWTaskViewPrivate, 1);
160
taskview->priv = priv;
162
GTK_WIDGET_SET_FLAGS (GTK_WIDGET (taskview), GTK_NO_WINDOW);
164
priv->mainbox = gtk_vbox_new (FALSE, 0);
165
gtk_container_add (GTK_CONTAINER (taskview), priv->mainbox);
166
gtk_widget_show (priv->mainbox);
168
ebox = gtk_event_box_new ();
169
gtk_box_pack_start (GTK_BOX (priv->mainbox), ebox, FALSE, FALSE, 0);
170
gtk_widget_show (ebox);
172
g_signal_connect (ebox, "expose_event",
173
G_CALLBACK (sw_taskview_ebox_expose), taskview);
175
hbox = gtk_hbox_new (FALSE, 12);
176
gtk_container_add (GTK_CONTAINER (ebox), hbox);
177
gtk_widget_show (hbox);
179
priv->stopbtn = gtk_button_new ();
180
gtk_button_set_relief (GTK_BUTTON (priv->stopbtn), GTK_RELIEF_NONE);
181
gtk_button_set_image (GTK_BUTTON (priv->stopbtn),
182
gtk_image_new_from_stock (GTK_STOCK_MEDIA_STOP,
183
GTK_ICON_SIZE_BUTTON));
184
gtk_widget_set_sensitive (priv->stopbtn, FALSE);
185
gtk_box_pack_start (GTK_BOX (hbox), priv->stopbtn, FALSE, FALSE, 0);
186
gtk_widget_show (priv->stopbtn);
188
priv->timelbl = gtk_label_new ("<span size=\"xx-large\">0</span>.<big>00</big>");
189
gtk_misc_set_alignment (GTK_MISC (priv->timelbl), 1.0, 0.5);
190
gtk_label_set_use_markup (GTK_LABEL (priv->timelbl), TRUE);
191
gtk_box_pack_end (GTK_BOX (hbox), priv->timelbl, TRUE, TRUE, 6);
192
gtk_widget_show (priv->timelbl);
194
swin = gtk_scrolled_window_new (NULL, NULL);
195
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
196
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
197
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin),
199
gtk_box_pack_start (GTK_BOX (priv->mainbox), swin, TRUE, TRUE, 0);
200
gtk_widget_show (swin);
202
priv->treeview = gtk_tree_view_new ();
203
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->treeview), FALSE);
204
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (priv->treeview), FALSE);
205
gtk_container_add (GTK_CONTAINER (swin), priv->treeview);
206
gtk_widget_show (priv->treeview);
208
priv->store = gtk_list_store_new (4,
213
gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
214
GTK_TREE_MODEL (priv->store));
216
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (priv->store),
218
(GtkTreeIterCompareFunc) sw_taskview_sort,
220
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (priv->store),
224
column = gtk_tree_view_column_new ();
225
renderer = gtk_cell_renderer_pixbuf_new ();
226
gtk_tree_view_column_pack_start (column, renderer, FALSE);
227
gtk_tree_view_column_set_attributes (column, renderer,
228
"pixbuf", SW_ACTIVITY_COLUMN,
231
renderer = gtk_cell_renderer_text_new ();
232
gtk_tree_view_column_pack_start (column, renderer, FALSE);
233
gtk_cell_renderer_text_set_fixed_height_from_font (GTK_CELL_RENDERER_TEXT (renderer), 2);
234
gtk_tree_view_column_set_attributes (column, renderer,
235
"markup", SW_TASKINFO_COLUMN,
238
g_object_set (renderer, "editable", TRUE, NULL);
240
g_signal_connect (renderer, "editing_started",
241
G_CALLBACK (sw_taskview_edit_started), taskview);
242
g_signal_connect (renderer, "edited",
243
G_CALLBACK (sw_taskview_edit_finished), taskview);
245
renderer = gtk_cell_renderer_pixbuf_new ();
246
gtk_tree_view_column_pack_end (column, renderer, FALSE);
247
gtk_tree_view_column_set_attributes (column, renderer,
248
"pixbuf", SW_STATUS_COLUMN,
250
gtk_tree_view_append_column (GTK_TREE_VIEW (priv->treeview), column);
252
gtk_list_store_append (priv->store, &iter);
253
gtk_list_store_set (priv->store, &iter,
254
SW_TASKINFO_COLUMN, _("<i>Click here to add a new task...</i>"),
255
SW_TASKUID_COLUMN, 0,
258
priv->tasks = g_hash_table_new_full (g_direct_hash, g_direct_equal,
262
static void sw_taskview_finalize (GObject * object) {
264
SWTaskViewPrivate * priv;
266
view = SW_TASKVIEW (object);
270
g_hash_table_destroy (priv->tasks);
274
if (G_OBJECT_CLASS (sw_taskview_parent_class)->finalize)
275
(* G_OBJECT_CLASS (sw_taskview_parent_class)->finalize) (object);
278
/* GtkObject Methods */
279
static void sw_taskview_destroy (GtkObject * object) {
280
if (GTK_OBJECT_CLASS (sw_taskview_parent_class)->destroy)
281
(* GTK_OBJECT_CLASS (sw_taskview_parent_class)->destroy) (object);
285
GtkWidget * sw_taskview_new (void) {
286
return GTK_WIDGET (g_object_new (SW_TYPE_TASKVIEW, NULL));