2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2005 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <glib/gi18n.h>
27 #include <gtk/gtkdialog.h>
28 #include <gtk/gtkhbox.h>
29 #include <gtk/gtklabel.h>
30 #include <gtk/gtkprogressbar.h>
31 #include <gtk/gtkscrolledwindow.h>
32 #include <gtk/gtkbutton.h>
33 #include <gtk/gtkstock.h>
35 #include "progressdialog.h"
38 #include "prefs_common.h"
48 static GtkListStore* progress_dialog_create_data_store(void);
49 static gint progress_dialog_list_view_insert_account(GtkWidget *list_view,
54 static GtkWidget *progress_dialog_list_view_create(void);
55 static void progress_dialog_create_list_view_columns(GtkTreeView *list_view);
57 ProgressDialog *progress_dialog_create(void)
59 ProgressDialog *progress;
63 GtkWidget *cancel_btn;
64 GtkWidget *progressbar;
65 GtkWidget *scrolledwin;
68 gchar *text[] = {NULL, NULL, NULL};
70 text[1] = _("Account");
71 text[2] = _("Status");
73 debug_print("Creating progress dialog...\n");
74 progress = g_new0(ProgressDialog, 1);
76 dialog = gtk_dialog_new();
77 gtk_widget_set_size_request(dialog, 460, -1);
78 gtk_container_set_border_width(GTK_CONTAINER(dialog), 8);
79 gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, TRUE, TRUE);
80 gtk_widget_realize(dialog);
82 gtk_container_set_border_width
83 (GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 0);
84 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 8);
85 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
87 hbox = gtk_hbox_new(FALSE, 0);
88 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox,
90 gtk_widget_show(hbox);
92 label = gtk_label_new("");
93 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8);
94 gtk_widget_show(label);
96 cancel_btn = gtk_dialog_add_button(GTK_DIALOG(dialog),
99 gtk_widget_grab_default(cancel_btn);
100 gtk_widget_grab_focus(cancel_btn);
102 progressbar = gtk_progress_bar_new();
103 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), progressbar,
105 gtk_widget_show(progressbar);
107 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
108 gtk_widget_show(scrolledwin);
109 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), scrolledwin,
111 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
112 GTK_POLICY_AUTOMATIC,
113 GTK_POLICY_AUTOMATIC);
115 /* GTK2: we hide the clist, but it is available for migration
116 * purposes. now if there only was a way to catch "set clist
118 clist = gtk_clist_new_with_titles(3, text);
119 gtk_widget_hide(clist);
120 /* gtk_container_add(GTK_CONTAINER(scrolledwin), clist); */
121 /* gtk_widget_set_size_request(clist, -1, 120); */
122 gtk_clist_set_column_justification(GTK_CLIST(clist), 0,
124 gtk_clist_set_column_width(GTK_CLIST(clist), 0, 16);
125 gtk_clist_set_column_width(GTK_CLIST(clist), 1, 160);
127 list_view = progress_dialog_list_view_create();
128 gtk_widget_show(list_view);
129 gtk_container_add(GTK_CONTAINER(scrolledwin), list_view);
130 gtk_widget_set_size_request(list_view, -1, 120);
132 progress->window = dialog;
133 progress->label = label;
134 progress->cancel_btn = cancel_btn;
135 progress->progressbar = progressbar;
136 progress->clist = clist;
137 progress->list_view = list_view;
142 void progress_dialog_set_label(ProgressDialog *progress, gchar *str)
144 gtk_label_set_text(GTK_LABEL(progress->label), str);
147 void progress_dialog_get_fraction(ProgressDialog *progress)
149 gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progress->progressbar));
152 void progress_dialog_set_fraction(ProgressDialog *progress,
155 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->progressbar),
159 void progress_dialog_destroy(ProgressDialog *progress)
162 gtk_widget_destroy(progress->window);
168 *\return gint Row where account was set
170 gint progress_dialog_list_set_account(ProgressDialog *progress,
172 const gchar *account_name)
174 return progress_dialog_list_view_insert_account(progress->list_view,
175 row, account_name, NULL,
180 *\return gint Row where image was set
182 gint progress_dialog_list_set_image(ProgressDialog *progress,
186 return progress_dialog_list_view_insert_account(progress->list_view,
192 *\return gint Row where status was set
194 gint progress_dialog_list_set_status(ProgressDialog *progress,
198 return progress_dialog_list_view_insert_account(progress->list_view,
204 *\return gint Row where data were set
206 gint progress_dialog_list_set(ProgressDialog *progress,
209 const gchar *account_name,
212 return progress_dialog_list_view_insert_account(progress->list_view,
217 /* XXX: maybe scroll into view, but leaving that for someone else to
218 * pickup: I don't have that many accounts... */
219 gboolean progress_dialog_list_select_row(ProgressDialog *progress,
222 GtkTreeSelection *selection = gtk_tree_view_get_selection
223 (GTK_TREE_VIEW(progress->list_view));
227 model = gtk_tree_view_get_model(GTK_TREE_VIEW(progress->list_view));
229 if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row))
232 gtk_tree_selection_select_iter(selection, &iter);
237 static GtkListStore* progress_dialog_create_data_store(void)
239 return gtk_list_store_new(N_PROGRESS_COLUMNS,
246 static gint progress_dialog_list_view_insert_account(GtkWidget *list_view,
248 const gchar *account,
253 GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model
254 (GTK_TREE_VIEW(list_view)));
257 if (account == NULL && status == NULL && image == NULL)
260 /* see if row exists, if not append */
261 if (row < 0 || !gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store),
263 result = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store),
265 gtk_list_store_append(store, &iter);
270 * XXX: uhm, when does the iter invalidate? sure not while
271 * just setting a row's column i hope?
275 gtk_list_store_set(store, &iter,
276 PROGRESS_ACCOUNT, account,
279 gtk_list_store_set(store, &iter,
280 PROGRESS_STATE, status,
283 gtk_list_store_set(store, &iter,
284 PROGRESS_IMAGE, image,
290 static GtkWidget *progress_dialog_list_view_create(void)
292 GtkTreeView *list_view;
295 model = GTK_TREE_MODEL(progress_dialog_create_data_store());
296 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
297 g_object_unref(model);
299 gtk_tree_view_set_rules_hint(list_view, prefs_common.enable_rules_hint);
301 /* create the columns */
302 progress_dialog_create_list_view_columns(list_view);
304 return GTK_WIDGET(list_view);
307 static void progress_dialog_create_list_view_columns(GtkTreeView *list_view)
309 GtkTreeViewColumn *column;
310 GtkCellRenderer *renderer;
312 renderer = gtk_cell_renderer_pixbuf_new();
313 column = gtk_tree_view_column_new_with_attributes
315 "pixbuf", PROGRESS_IMAGE,
317 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
319 renderer = gtk_cell_renderer_text_new();
320 column = gtk_tree_view_column_new_with_attributes
323 "text", PROGRESS_ACCOUNT,
325 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
327 renderer = gtk_cell_renderer_text_new();
328 column = gtk_tree_view_column_new_with_attributes
331 "text", PROGRESS_STATE,
333 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);