diff options
Diffstat (limited to 'src/progressdialog.c')
| -rw-r--r-- | src/progressdialog.c | 300 |
1 files changed, 300 insertions, 0 deletions
diff --git a/src/progressdialog.c b/src/progressdialog.c new file mode 100644 index 0000000..2107da4 --- /dev/null +++ b/src/progressdialog.c | |||
| @@ -0,0 +1,300 @@ | |||
| 1 | /* | ||
| 2 | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client | ||
| 3 | * Copyright (C) 1999-2014 Hiroyuki Yamamoto | ||
| 4 | * | ||
| 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. | ||
| 9 | * | ||
| 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. | ||
| 14 | * | ||
| 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. | ||
| 18 | */ | ||
| 19 | |||
| 20 | #ifdef HAVE_CONFIG_H | ||
| 21 | # include "config.h" | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #include <glib.h> | ||
| 25 | #include <glib/gi18n.h> | ||
| 26 | #include <gtk/gtkdialog.h> | ||
| 27 | #include <gtk/gtkhbox.h> | ||
| 28 | #include <gtk/gtklabel.h> | ||
| 29 | #include <gtk/gtkprogressbar.h> | ||
| 30 | #include <gtk/gtkscrolledwindow.h> | ||
| 31 | #include <gtk/gtkliststore.h> | ||
| 32 | #include <gtk/gtktreeview.h> | ||
| 33 | #include <gtk/gtktreeselection.h> | ||
| 34 | #include <gtk/gtkcellrendererpixbuf.h> | ||
| 35 | #include <gtk/gtkcellrenderertext.h> | ||
| 36 | #include <gtk/gtkbutton.h> | ||
| 37 | #include <gtk/gtkstock.h> | ||
| 38 | |||
| 39 | #include "progressdialog.h" | ||
| 40 | #include "gtkutils.h" | ||
| 41 | #include "utils.h" | ||
| 42 | |||
| 43 | #define PROGRESS_DIALOG_WIDTH 460 | ||
| 44 | #define PROGRESS_TREE_VIEW_HEIGHT 120 | ||
| 45 | |||
| 46 | ProgressDialog *progress_dialog_create(void) | ||
| 47 | { | ||
| 48 | ProgressDialog *progress; | ||
| 49 | GtkWidget *scrolledwin; | ||
| 50 | GtkWidget *treeview; | ||
| 51 | GtkListStore *store; | ||
| 52 | GtkTreeSelection *selection; | ||
| 53 | GtkTreeViewColumn *column; | ||
| 54 | GtkCellRenderer *renderer; | ||
| 55 | |||
| 56 | progress = progress_dialog_simple_create(); | ||
| 57 | |||
| 58 | scrolledwin = gtk_scrolled_window_new(NULL, NULL); | ||
| 59 | gtk_widget_show(scrolledwin); | ||
| 60 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(progress->window)->vbox), | ||
| 61 | scrolledwin, TRUE, TRUE, 0); | ||
| 62 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), | ||
| 63 | GTK_POLICY_AUTOMATIC, | ||
| 64 | GTK_POLICY_AUTOMATIC); | ||
| 65 | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin), | ||
| 66 | GTK_SHADOW_IN); | ||
| 67 | |||
| 68 | store = gtk_list_store_new(PROG_N_COLS, GDK_TYPE_PIXBUF, G_TYPE_STRING, | ||
| 69 | G_TYPE_STRING, G_TYPE_STRING, | ||
| 70 | G_TYPE_POINTER); | ||
| 71 | |||
| 72 | treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | ||
| 73 | g_object_unref(G_OBJECT(store)); | ||
| 74 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE); | ||
| 75 | gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); | ||
| 76 | gtk_widget_show(treeview); | ||
| 77 | gtk_container_add(GTK_CONTAINER(scrolledwin), treeview); | ||
| 78 | gtk_widget_set_size_request(treeview, -1, PROGRESS_TREE_VIEW_HEIGHT * gtkut_get_dpi_multiplier()); | ||
| 79 | |||
| 80 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | ||
| 81 | gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); | ||
| 82 | |||
| 83 | renderer = gtk_cell_renderer_pixbuf_new(); | ||
| 84 | g_object_set(renderer, "xalign", 0.5, NULL); | ||
| 85 | column = gtk_tree_view_column_new_with_attributes | ||
| 86 | (NULL, renderer, "pixbuf", PROG_COL_PIXBUF, NULL); | ||
| 87 | gtk_tree_view_column_set_alignment(column, 0.5); | ||
| 88 | gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | ||
| 89 | gtk_tree_view_column_set_fixed_width(column, 20); | ||
| 90 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | ||
| 91 | |||
| 92 | renderer = gtk_cell_renderer_text_new(); | ||
| 93 | column = gtk_tree_view_column_new_with_attributes | ||
| 94 | (_("Account"), renderer, "text", PROG_COL_NAME, NULL); | ||
| 95 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
| 96 | gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | ||
| 97 | gtk_tree_view_column_set_fixed_width(column, 120 * gtkut_get_dpi_multiplier()); | ||
| 98 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | ||
| 99 | |||
| 100 | renderer = gtk_cell_renderer_text_new(); | ||
| 101 | column = gtk_tree_view_column_new_with_attributes | ||
| 102 | (_("Status"), renderer, "text", PROG_COL_STATUS, NULL); | ||
| 103 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
| 104 | gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | ||
| 105 | gtk_tree_view_column_set_fixed_width(column, 100 * gtkut_get_dpi_multiplier()); | ||
| 106 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | ||
| 107 | |||
| 108 | renderer = gtk_cell_renderer_text_new(); | ||
| 109 | column = gtk_tree_view_column_new_with_attributes | ||
| 110 | (_("Progress"), renderer, "text", PROG_COL_PROGRESS, NULL); | ||
| 111 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
| 112 | gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | ||
| 113 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | ||
| 114 | |||
| 115 | progress->treeview = treeview; | ||
| 116 | progress->store = store; | ||
| 117 | |||
| 118 | return progress; | ||
| 119 | } | ||
| 120 | |||
| 121 | ProgressDialog *progress_dialog_simple_create(void) | ||
| 122 | { | ||
| 123 | ProgressDialog *progress; | ||
| 124 | GtkWidget *dialog; | ||
| 125 | GtkWidget *hbox; | ||
| 126 | GtkWidget *label; | ||
| 127 | GtkWidget *cancel_btn; | ||
| 128 | GtkWidget *progressbar; | ||
| 129 | |||
| 130 | debug_print("Creating progress dialog\n"); | ||
| 131 | progress = g_new0(ProgressDialog, 1); | ||
| 132 | |||
| 133 | dialog = gtk_dialog_new(); | ||
| 134 | gtk_widget_set_size_request(dialog, PROGRESS_DIALOG_WIDTH * gtkut_get_dpi_multiplier(), -1); | ||
| 135 | gtk_container_set_border_width(GTK_CONTAINER(dialog), 8); | ||
| 136 | gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); | ||
| 137 | gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, TRUE, TRUE); | ||
| 138 | gtk_widget_realize(dialog); | ||
| 139 | |||
| 140 | gtk_container_set_border_width | ||
| 141 | (GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 0); | ||
| 142 | gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 8); | ||
| 143 | gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); | ||
| 144 | |||
| 145 | hbox = gtk_hbox_new(FALSE, 0); | ||
| 146 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, | ||
| 147 | FALSE, FALSE, 8); | ||
| 148 | gtk_widget_show(hbox); | ||
| 149 | |||
| 150 | label = gtk_label_new(""); | ||
| 151 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8); | ||
| 152 | gtk_widget_show(label); | ||
| 153 | |||
| 154 | cancel_btn = gtk_dialog_add_button(GTK_DIALOG(dialog), | ||
| 155 | GTK_STOCK_CANCEL, | ||
| 156 | GTK_RESPONSE_NONE); | ||
| 157 | gtk_widget_grab_default(cancel_btn); | ||
| 158 | gtk_widget_grab_focus(cancel_btn); | ||
| 159 | |||
| 160 | progressbar = gtk_progress_bar_new(); | ||
| 161 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), progressbar, | ||
| 162 | FALSE, FALSE, 0); | ||
| 163 | gtk_widget_show(progressbar); | ||
| 164 | |||
| 165 | progress->window = dialog; | ||
| 166 | progress->label = label; | ||
| 167 | progress->cancel_btn = cancel_btn; | ||
| 168 | progress->progressbar = progressbar; | ||
| 169 | progress->treeview = NULL; | ||
| 170 | progress->store = NULL; | ||
| 171 | |||
| 172 | return progress; | ||
| 173 | } | ||
| 174 | |||
| 175 | void progress_dialog_destroy(ProgressDialog *progress) | ||
| 176 | { | ||
| 177 | if (progress) { | ||
| 178 | gtk_widget_destroy(progress->window); | ||
| 179 | g_free(progress); | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | void progress_dialog_set_label(ProgressDialog *progress, gchar *str) | ||
| 184 | { | ||
| 185 | gtk_label_set_text(GTK_LABEL(progress->label), str); | ||
| 186 | } | ||
| 187 | |||
| 188 | void progress_dialog_set_value(ProgressDialog *progress, gfloat value) | ||
| 189 | { | ||
| 190 | gtk_progress_set_value(GTK_PROGRESS(progress->progressbar), value); | ||
| 191 | } | ||
| 192 | |||
| 193 | void progress_dialog_set_percentage(ProgressDialog *progress, | ||
| 194 | gfloat percentage) | ||
| 195 | { | ||
| 196 | gtk_progress_set_percentage(GTK_PROGRESS(progress->progressbar), | ||
| 197 | percentage); | ||
| 198 | } | ||
| 199 | |||
| 200 | void progress_dialog_append(ProgressDialog *progress, GdkPixbuf *pixbuf, | ||
| 201 | const gchar *name, const gchar *status, | ||
| 202 | const gchar *progress_str, gpointer data) | ||
| 203 | { | ||
| 204 | GtkListStore *store = progress->store; | ||
| 205 | GtkTreeIter iter; | ||
| 206 | |||
| 207 | gtk_list_store_append(store, &iter); | ||
| 208 | |||
| 209 | gtk_list_store_set(store, &iter, | ||
| 210 | PROG_COL_PIXBUF, pixbuf, | ||
| 211 | PROG_COL_NAME, name, | ||
| 212 | PROG_COL_STATUS, status, | ||
| 213 | PROG_COL_PROGRESS, progress_str, | ||
| 214 | PROG_COL_POINTER, data, | ||
| 215 | -1); | ||
| 216 | } | ||
| 217 | |||
| 218 | void progress_dialog_set_row(ProgressDialog *progress, gint row, | ||
| 219 | GdkPixbuf *pixbuf, const gchar *name, | ||
| 220 | const gchar *status, const gchar *progress_str, | ||
| 221 | gpointer data) | ||
| 222 | { | ||
| 223 | GtkListStore *store = progress->store; | ||
| 224 | GtkTreeIter iter; | ||
| 225 | |||
| 226 | if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), | ||
| 227 | &iter, NULL, row)) { | ||
| 228 | gtk_list_store_set(store, &iter, | ||
| 229 | PROG_COL_PIXBUF, pixbuf, | ||
| 230 | PROG_COL_NAME, name, | ||
| 231 | PROG_COL_STATUS, status, | ||
| 232 | PROG_COL_PROGRESS, progress_str, | ||
| 233 | PROG_COL_POINTER, data, | ||
| 234 | -1); | ||
| 235 | } | ||
| 236 | } | ||
| 237 | |||
| 238 | void progress_dialog_set_row_pixbuf(ProgressDialog *progress, gint row, | ||
| 239 | GdkPixbuf *pixbuf) | ||
| 240 | { | ||
| 241 | GtkListStore *store = progress->store; | ||
| 242 | GtkTreeIter iter; | ||
| 243 | |||
| 244 | if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), | ||
| 245 | &iter, NULL, row)) { | ||
| 246 | gtk_list_store_set(store, &iter, PROG_COL_PIXBUF, pixbuf, -1); | ||
| 247 | } | ||
| 248 | } | ||
| 249 | |||
| 250 | void progress_dialog_set_row_name(ProgressDialog *progress, gint row, | ||
| 251 | const gchar *name) | ||
| 252 | { | ||
| 253 | GtkListStore *store = progress->store; | ||
| 254 | GtkTreeIter iter; | ||
| 255 | |||
| 256 | if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), | ||
| 257 | &iter, NULL, row)) { | ||
| 258 | gtk_list_store_set(store, &iter, PROG_COL_NAME, name, -1); | ||
| 259 | } | ||
| 260 | } | ||
| 261 | |||
| 262 | void progress_dialog_set_row_status(ProgressDialog *progress, gint row, | ||
| 263 | const gchar *status) | ||
| 264 | { | ||
| 265 | GtkListStore *store = progress->store; | ||
| 266 | GtkTreeIter iter; | ||
| 267 | |||
| 268 | if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), | ||
| 269 | &iter, NULL, row)) { | ||
| 270 | gtk_list_store_set(store, &iter, PROG_COL_STATUS, status, -1); | ||
| 271 | } | ||
| 272 | } | ||
| 273 | |||
| 274 | void progress_dialog_set_row_progress(ProgressDialog *progress, gint row, | ||
| 275 | const gchar *progress_str) | ||
| 276 | { | ||
| 277 | GtkListStore *store = progress->store; | ||
| 278 | GtkTreeIter iter; | ||
| 279 | |||
| 280 | if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), | ||
| 281 | &iter, NULL, row)) { | ||
| 282 | gtk_list_store_set(store, &iter, PROG_COL_PROGRESS, | ||
| 283 | progress_str, -1); | ||
| 284 | } | ||
| 285 | } | ||
| 286 | |||
| 287 | void progress_dialog_scroll_to_row(ProgressDialog *progress, gint row) | ||
| 288 | { | ||
| 289 | GtkTreeModel *model = GTK_TREE_MODEL(progress->store); | ||
| 290 | GtkTreeIter iter; | ||
| 291 | GtkTreePath *path; | ||
| 292 | |||
| 293 | if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) | ||
| 294 | return; | ||
| 295 | |||
| 296 | path = gtk_tree_model_get_path(model, &iter); | ||
| 297 | gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(progress->treeview), | ||
| 298 | path, NULL, FALSE, 0.0, 0.0); | ||
| 299 | gtk_tree_path_free(path); | ||
| 300 | } | ||
