Statistics
| Revision:

root / src / progressdialog.c @ 3069

History | View | Annotate | Download (9 kB)

1 1 hiro
/*
2 1 hiro
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 2196 hiro
 * Copyright (C) 1999-2009 Hiroyuki Yamamoto
4 1 hiro
 *
5 1 hiro
 * This program is free software; you can redistribute it and/or modify
6 1 hiro
 * it under the terms of the GNU General Public License as published by
7 1 hiro
 * the Free Software Foundation; either version 2 of the License, or
8 1 hiro
 * (at your option) any later version.
9 1 hiro
 *
10 1 hiro
 * This program is distributed in the hope that it will be useful,
11 1 hiro
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 1 hiro
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 1 hiro
 * GNU General Public License for more details.
14 1 hiro
 *
15 1 hiro
 * You should have received a copy of the GNU General Public License
16 1 hiro
 * along with this program; if not, write to the Free Software
17 1 hiro
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 1 hiro
 */
19 1 hiro
20 1 hiro
#ifdef HAVE_CONFIG_H
21 1 hiro
#  include "config.h"
22 1 hiro
#endif
23 1 hiro
24 1 hiro
#include <glib.h>
25 92 hiro
#include <glib/gi18n.h>
26 126 hiro
#include <gtk/gtkdialog.h>
27 1 hiro
#include <gtk/gtkhbox.h>
28 1 hiro
#include <gtk/gtklabel.h>
29 1 hiro
#include <gtk/gtkprogressbar.h>
30 1 hiro
#include <gtk/gtkscrolledwindow.h>
31 321 hiro
#include <gtk/gtkliststore.h>
32 321 hiro
#include <gtk/gtktreeview.h>
33 321 hiro
#include <gtk/gtktreeselection.h>
34 321 hiro
#include <gtk/gtkcellrendererpixbuf.h>
35 321 hiro
#include <gtk/gtkcellrenderertext.h>
36 1 hiro
#include <gtk/gtkbutton.h>
37 30 hiro
#include <gtk/gtkstock.h>
38 1 hiro
39 1 hiro
#include "progressdialog.h"
40 1 hiro
#include "gtkutils.h"
41 1 hiro
#include "utils.h"
42 1 hiro
43 1 hiro
ProgressDialog *progress_dialog_create(void)
44 1 hiro
{
45 1 hiro
        ProgressDialog *progress;
46 1 hiro
        GtkWidget *scrolledwin;
47 321 hiro
        GtkWidget *treeview;
48 321 hiro
        GtkListStore *store;
49 321 hiro
        GtkTreeSelection *selection;
50 321 hiro
        GtkTreeViewColumn *column;
51 321 hiro
        GtkCellRenderer *renderer;
52 1 hiro
53 2196 hiro
        progress = progress_dialog_simple_create();
54 1 hiro
55 1 hiro
        scrolledwin = gtk_scrolled_window_new(NULL, NULL);
56 1 hiro
        gtk_widget_show(scrolledwin);
57 2196 hiro
        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(progress->window)->vbox),
58 2196 hiro
                           scrolledwin, TRUE, TRUE, 0);
59 1 hiro
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
60 1 hiro
                                       GTK_POLICY_AUTOMATIC,
61 1 hiro
                                       GTK_POLICY_AUTOMATIC);
62 321 hiro
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
63 321 hiro
                                            GTK_SHADOW_IN);
64 1 hiro
65 321 hiro
        store = gtk_list_store_new(PROG_N_COLS, GDK_TYPE_PIXBUF, G_TYPE_STRING,
66 2043 hiro
                                   G_TYPE_STRING, G_TYPE_STRING,
67 2043 hiro
                                   G_TYPE_POINTER);
68 1 hiro
69 321 hiro
        treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
70 321 hiro
        g_object_unref(G_OBJECT(store));
71 321 hiro
        gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE);
72 321 hiro
        gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
73 321 hiro
        gtk_widget_show(treeview);
74 321 hiro
        gtk_container_add(GTK_CONTAINER(scrolledwin), treeview);
75 321 hiro
        gtk_widget_set_size_request(treeview, -1, 120);
76 321 hiro
77 321 hiro
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
78 321 hiro
        gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
79 321 hiro
80 321 hiro
        renderer = gtk_cell_renderer_pixbuf_new();
81 321 hiro
        g_object_set(renderer, "xalign", 0.5, NULL);
82 321 hiro
        column = gtk_tree_view_column_new_with_attributes
83 321 hiro
                (NULL, renderer, "pixbuf", PROG_COL_PIXBUF, NULL);
84 321 hiro
        gtk_tree_view_column_set_alignment(column, 0.5);
85 321 hiro
        gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
86 321 hiro
        gtk_tree_view_column_set_fixed_width(column, 20);
87 321 hiro
        gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
88 321 hiro
89 321 hiro
        renderer = gtk_cell_renderer_text_new();
90 321 hiro
        column = gtk_tree_view_column_new_with_attributes
91 321 hiro
                (_("Account"), renderer, "text", PROG_COL_NAME, NULL);
92 321 hiro
        gtk_tree_view_column_set_resizable(column, TRUE);
93 321 hiro
        gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
94 2043 hiro
        gtk_tree_view_column_set_fixed_width(column, 120);
95 321 hiro
        gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
96 321 hiro
97 321 hiro
        renderer = gtk_cell_renderer_text_new();
98 321 hiro
        column = gtk_tree_view_column_new_with_attributes
99 321 hiro
                (_("Status"), renderer, "text", PROG_COL_STATUS, NULL);
100 321 hiro
        gtk_tree_view_column_set_resizable(column, TRUE);
101 321 hiro
        gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
102 2043 hiro
        gtk_tree_view_column_set_fixed_width(column, 80);
103 321 hiro
        gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
104 321 hiro
105 2043 hiro
        renderer = gtk_cell_renderer_text_new();
106 2043 hiro
        column = gtk_tree_view_column_new_with_attributes
107 2043 hiro
                (_("Progress"), renderer, "text", PROG_COL_PROGRESS, NULL);
108 2043 hiro
        gtk_tree_view_column_set_resizable(column, TRUE);
109 2043 hiro
        gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
110 2043 hiro
        gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
111 2043 hiro
112 2196 hiro
        progress->treeview = treeview;
113 2196 hiro
        progress->store    = store;
114 2196 hiro
115 2196 hiro
        return progress;
116 2196 hiro
}
117 2196 hiro
118 2196 hiro
ProgressDialog *progress_dialog_simple_create(void)
119 2196 hiro
{
120 2196 hiro
        ProgressDialog *progress;
121 2196 hiro
        GtkWidget *dialog;
122 2196 hiro
        GtkWidget *hbox;
123 2196 hiro
        GtkWidget *label;
124 2196 hiro
        GtkWidget *cancel_btn;
125 2196 hiro
        GtkWidget *progressbar;
126 2196 hiro
127 2196 hiro
        debug_print("Creating progress dialog\n");
128 2196 hiro
        progress = g_new0(ProgressDialog, 1);
129 2196 hiro
130 2196 hiro
        dialog = gtk_dialog_new();
131 2196 hiro
        gtk_widget_set_size_request(dialog, 460, -1);
132 2196 hiro
        gtk_container_set_border_width(GTK_CONTAINER(dialog), 8);
133 2196 hiro
        gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
134 2196 hiro
        gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, TRUE, TRUE);
135 2196 hiro
        gtk_widget_realize(dialog);
136 2196 hiro
137 2196 hiro
        gtk_container_set_border_width
138 2196 hiro
                (GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 0);
139 2196 hiro
        gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 8);
140 2196 hiro
        gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
141 2196 hiro
142 2196 hiro
        hbox = gtk_hbox_new(FALSE, 0);
143 2196 hiro
        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox,
144 2196 hiro
                           FALSE, FALSE, 8);
145 2196 hiro
        gtk_widget_show(hbox);
146 2196 hiro
147 2196 hiro
        label = gtk_label_new("");
148 2196 hiro
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8);
149 2196 hiro
        gtk_widget_show(label);
150 2196 hiro
151 2196 hiro
        cancel_btn = gtk_dialog_add_button(GTK_DIALOG(dialog),
152 2196 hiro
                                           GTK_STOCK_CANCEL,
153 2196 hiro
                                           GTK_RESPONSE_NONE);
154 2196 hiro
        gtk_widget_grab_default(cancel_btn);
155 2196 hiro
        gtk_widget_grab_focus(cancel_btn);
156 2196 hiro
157 2196 hiro
        progressbar = gtk_progress_bar_new();
158 2196 hiro
        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), progressbar,
159 2196 hiro
                           FALSE, FALSE, 0);
160 2196 hiro
        gtk_widget_show(progressbar);
161 2196 hiro
162 126 hiro
        progress->window      = dialog;
163 1 hiro
        progress->label       = label;
164 1 hiro
        progress->cancel_btn  = cancel_btn;
165 1 hiro
        progress->progressbar = progressbar;
166 2196 hiro
        progress->treeview    = NULL;
167 2196 hiro
        progress->store       = NULL;
168 1 hiro
169 1 hiro
        return progress;
170 1 hiro
}
171 1 hiro
172 321 hiro
void progress_dialog_destroy(ProgressDialog *progress)
173 321 hiro
{
174 321 hiro
        if (progress) {
175 321 hiro
                gtk_widget_destroy(progress->window);
176 321 hiro
                g_free(progress);
177 321 hiro
        }
178 321 hiro
}
179 321 hiro
180 1 hiro
void progress_dialog_set_label(ProgressDialog *progress, gchar *str)
181 1 hiro
{
182 1 hiro
        gtk_label_set_text(GTK_LABEL(progress->label), str);
183 1 hiro
}
184 1 hiro
185 1 hiro
void progress_dialog_set_value(ProgressDialog *progress, gfloat value)
186 1 hiro
{
187 1 hiro
        gtk_progress_set_value(GTK_PROGRESS(progress->progressbar), value);
188 1 hiro
}
189 1 hiro
190 1 hiro
void progress_dialog_set_percentage(ProgressDialog *progress,
191 1 hiro
                                    gfloat percentage)
192 1 hiro
{
193 1 hiro
        gtk_progress_set_percentage(GTK_PROGRESS(progress->progressbar),
194 1 hiro
                                    percentage);
195 1 hiro
}
196 1 hiro
197 321 hiro
void progress_dialog_append(ProgressDialog *progress, GdkPixbuf *pixbuf,
198 321 hiro
                            const gchar *name, const gchar *status,
199 2043 hiro
                            const gchar *progress_str, gpointer data)
200 1 hiro
{
201 321 hiro
        GtkListStore *store = progress->store;
202 321 hiro
        GtkTreeIter iter;
203 321 hiro
204 321 hiro
        gtk_list_store_append(store, &iter);
205 321 hiro
206 321 hiro
        gtk_list_store_set(store, &iter,
207 321 hiro
                           PROG_COL_PIXBUF, pixbuf,
208 321 hiro
                           PROG_COL_NAME, name,
209 321 hiro
                           PROG_COL_STATUS, status,
210 2043 hiro
                           PROG_COL_PROGRESS, progress_str,
211 321 hiro
                           PROG_COL_POINTER, data,
212 321 hiro
                           -1);
213 321 hiro
}
214 321 hiro
215 321 hiro
void progress_dialog_set_row(ProgressDialog *progress, gint row,
216 321 hiro
                             GdkPixbuf *pixbuf, const gchar *name,
217 2043 hiro
                             const gchar *status, const gchar *progress_str,
218 2043 hiro
                             gpointer data)
219 321 hiro
{
220 321 hiro
        GtkListStore *store = progress->store;
221 321 hiro
        GtkTreeIter iter;
222 321 hiro
223 321 hiro
        if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store),
224 321 hiro
                                          &iter, NULL, row)) {
225 321 hiro
                gtk_list_store_set(store, &iter,
226 321 hiro
                                   PROG_COL_PIXBUF, pixbuf,
227 321 hiro
                                   PROG_COL_NAME, name,
228 321 hiro
                                   PROG_COL_STATUS, status,
229 2043 hiro
                                   PROG_COL_PROGRESS, progress_str,
230 321 hiro
                                   PROG_COL_POINTER, data,
231 321 hiro
                                   -1);
232 1 hiro
        }
233 1 hiro
}
234 321 hiro
235 321 hiro
void progress_dialog_set_row_pixbuf(ProgressDialog *progress, gint row,
236 321 hiro
                                    GdkPixbuf *pixbuf)
237 321 hiro
{
238 321 hiro
        GtkListStore *store = progress->store;
239 321 hiro
        GtkTreeIter iter;
240 321 hiro
241 321 hiro
        if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store),
242 321 hiro
                                          &iter, NULL, row)) {
243 321 hiro
                gtk_list_store_set(store, &iter, PROG_COL_PIXBUF, pixbuf, -1);
244 321 hiro
        }
245 321 hiro
}
246 321 hiro
247 321 hiro
void progress_dialog_set_row_name(ProgressDialog *progress, gint row,
248 321 hiro
                                  const gchar *name)
249 321 hiro
{
250 321 hiro
        GtkListStore *store = progress->store;
251 321 hiro
        GtkTreeIter iter;
252 321 hiro
253 321 hiro
        if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store),
254 321 hiro
                                          &iter, NULL, row)) {
255 321 hiro
                gtk_list_store_set(store, &iter, PROG_COL_NAME, name, -1);
256 321 hiro
        }
257 321 hiro
}
258 321 hiro
259 321 hiro
void progress_dialog_set_row_status(ProgressDialog *progress, gint row,
260 321 hiro
                                    const gchar *status)
261 321 hiro
{
262 321 hiro
        GtkListStore *store = progress->store;
263 321 hiro
        GtkTreeIter iter;
264 321 hiro
265 321 hiro
        if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store),
266 321 hiro
                                          &iter, NULL, row)) {
267 321 hiro
                gtk_list_store_set(store, &iter, PROG_COL_STATUS, status, -1);
268 321 hiro
        }
269 321 hiro
}
270 321 hiro
271 2043 hiro
void progress_dialog_set_row_progress(ProgressDialog *progress, gint row,
272 2043 hiro
                                      const gchar *progress_str)
273 2043 hiro
{
274 2043 hiro
        GtkListStore *store = progress->store;
275 2043 hiro
        GtkTreeIter iter;
276 2043 hiro
277 2043 hiro
        if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store),
278 2043 hiro
                                          &iter, NULL, row)) {
279 2043 hiro
                gtk_list_store_set(store, &iter, PROG_COL_PROGRESS,
280 2043 hiro
                                   progress_str, -1);
281 2043 hiro
        }
282 2043 hiro
}
283 2043 hiro
284 321 hiro
void progress_dialog_scroll_to_row(ProgressDialog *progress, gint row)
285 321 hiro
{
286 321 hiro
        GtkTreeModel *model = GTK_TREE_MODEL(progress->store);
287 321 hiro
        GtkTreeIter iter;
288 321 hiro
        GtkTreePath *path;
289 321 hiro
290 321 hiro
        if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row))
291 321 hiro
                return;
292 321 hiro
293 321 hiro
        path = gtk_tree_model_get_path(model, &iter);
294 321 hiro
        gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(progress->treeview),
295 321 hiro
                                     path, NULL, FALSE, 0.0, 0.0);
296 321 hiro
        gtk_tree_path_free(path);
297 321 hiro
}