2
* Copyright (C) 2007 OpenedHand Ltd
4
* This program is free software; you can redistribute it and/or modify it under
5
* the terms of the GNU General Public License as published by the Free Software
6
* Foundation; either version 2 of the License, or (at your option) any later
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
* You should have received a copy of the GNU General Public License along with
15
* this program; if not, write to the Free Software Foundation, Inc., 51
16
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <glib/gi18n.h>
23
#include "koto-task-store.h"
24
#include "koto-utils.h"
32
* Foreach function called from update_title() that simply counts the number of
33
* uncompleted tasks. @userdata is an int* to the count.
36
count_pending (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
41
gtk_tree_model_get (model, iter, COLUMN_DONE, &done, -1);
47
* TODO: one day KotoTaskStore will always be sorted, but at the moment new
48
* tasks are appended and then moved to the correct location. When this is
49
* fixed we can return @done here and not bother counting completed tasks.
55
* Update the window title, generally as the number of tasks has changed.
58
update_title (WindowData *data, GtkTreeModel *model)
66
gtk_tree_model_foreach (model, count_pending, &count);
68
title = g_strdup_printf (data->title, count);
69
gtk_window_set_title (data->window, title);
74
* Callback when rows are inserted into the task store, to update the window
78
on_row_inserted (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, WindowData *data)
80
update_title (data, model);
84
* Callback when rows are removed from the task store, to update the window
88
on_row_deleted (GtkTreeModel *model, GtkTreePath *path, WindowData *data)
90
update_title (data, model);
94
* Weak notify for WindowData, to free it when the window is destroyed.
97
on_weak_notify (gpointer user_data, GObject *dead)
99
WindowData *data = user_data;
100
g_free (data->title);
101
g_slice_free (WindowData, data);
105
* koto_sync_window_title:
106
* @window: a #GtkWindow title to set
107
* @model: a #GtkTreeModel to count tasks from
108
* @title: an untranslated format string to use as the title
110
* Synchronise the title of @window with then number of incomplete tasks in
111
* @model. @model must be a #KotoTaskStore, or a filter model based on
112
* #KotoTaskStore. @title should be untranslated and contain a single %d
113
* format, which is the number of incomplete tasks.
116
koto_sync_window_title (GtkWindow *window, GtkTreeModel *model, const char *title)
120
g_return_if_fail (GTK_WINDOW (window));
121
g_return_if_fail (GTK_TREE_MODEL (model));
122
g_return_if_fail (title);
124
data = g_slice_new (WindowData);
125
data->window = window;
126
data->title = g_strdup (title);
128
g_object_weak_ref (G_OBJECT (model), on_weak_notify, data);
130
g_object_connect (model,
131
"signal::row-inserted", G_CALLBACK (on_row_inserted), data,
132
"signal::row-changed", G_CALLBACK (on_row_inserted), data,
133
"signal::row-deleted", G_CALLBACK (on_row_deleted), data,
136
update_title (data, model);