Improve some sieve-related translations
[claws.git] / src / gtk / progressdialog.c
blobb5b6381316b19156547d1bb8141f61a033c3aee5
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2021 the Claws Mail team and 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 3 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, see <http://www.gnu.org/licenses/>.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #include "claws-features.h"
23 #endif
25 #include <glib.h>
26 #include <glib/gi18n.h>
27 #include <gtk/gtk.h>
29 #include "progressdialog.h"
30 #include "gtkutils.h"
31 #include "utils.h"
32 #include "prefs_common.h"
34 enum {
35 PROGRESS_IMAGE,
36 PROGRESS_ACCOUNT,
37 PROGRESS_STATE,
38 N_PROGRESS_COLUMNS
41 static gint progress_dialog_insert_account(ProgressDialog *progress,
42 gint row,
43 const gchar *account,
44 const gchar *status,
45 GdkPixbuf *image);
47 static void progress_dialog_hide_btn_cb(GtkWidget *widget, gpointer data);
48 static void progress_dialog_delete_event_btn_cb(GtkWidget *widget, gpointer data);
50 ProgressDialog *progress_dialog_create(void)
52 ProgressDialog *progress;
53 GtkWidget *dialog;
54 GtkWidget *hbox;
55 GtkWidget *vbox;
56 GtkWidget *label;
57 GtkWidget *hide_btn;
58 GtkWidget *showlog_btn;
59 GtkWidget *cancel_btn;
60 GtkWidget *progressbar;
61 GtkWidget *scrolledwin;
62 GtkWidget *treeview;
63 GtkListStore *store;
64 GtkTreeSelection *selection;
65 GtkTreeViewColumn *column;
66 GtkCellRenderer *renderer;
68 debug_print("Creating progress dialog...\n");
69 progress = g_new0(ProgressDialog, 1);
71 dialog = gtk_dialog_new();
72 gtk_window_set_resizable(GTK_WINDOW(dialog), TRUE);
73 gtk_widget_realize(dialog);
75 vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
76 gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
77 gtk_box_set_spacing(GTK_BOX(vbox), 8);
79 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
80 gtk_box_pack_start(GTK_BOX(vbox), hbox,
81 FALSE, FALSE, 8);
82 gtk_widget_show(hbox);
84 label = gtk_label_new("");
85 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8);
86 gtk_widget_show(label);
88 hide_btn = gtk_dialog_add_button(GTK_DIALOG(dialog),
89 _("_Hide"),
90 GTK_RESPONSE_NONE);
91 showlog_btn = gtk_dialog_add_button(GTK_DIALOG(dialog),
92 _("_View log"),
93 GTK_RESPONSE_NONE);
94 cancel_btn = gtk_dialog_add_button(GTK_DIALOG(dialog),
95 _("_Cancel"),
96 GTK_RESPONSE_NONE);
97 gtk_widget_grab_default(cancel_btn);
98 gtk_widget_grab_focus(cancel_btn);
100 progressbar = gtk_progress_bar_new();
101 gtk_box_pack_start(GTK_BOX(vbox), progressbar,
102 FALSE, FALSE, 0);
103 gtk_widget_show(progressbar);
105 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
106 gtk_widget_show(scrolledwin);
107 gtk_box_pack_start(GTK_BOX(vbox), scrolledwin,
108 TRUE, TRUE, 0);
109 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
110 GTK_POLICY_AUTOMATIC,
111 GTK_POLICY_AUTOMATIC);
113 store = gtk_list_store_new(N_PROGRESS_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING,
114 G_TYPE_STRING, G_TYPE_POINTER);
116 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
117 g_object_unref(G_OBJECT(store));
118 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE);
119 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview),
120 prefs_common.use_stripes_everywhere);
121 gtk_widget_show(treeview);
122 gtk_container_add(GTK_CONTAINER(scrolledwin), treeview);
123 gtk_widget_set_size_request(treeview, -1, 120);
125 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
126 gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
128 renderer = gtk_cell_renderer_pixbuf_new();
129 g_object_set(renderer, "xalign", 0.5, NULL);
130 column = gtk_tree_view_column_new_with_attributes
131 (NULL, renderer, "pixbuf", PROGRESS_IMAGE, NULL);
132 gtk_tree_view_column_set_alignment(column, 0.5);
133 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
134 gtk_tree_view_column_set_fixed_width(column, 20);
135 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
137 renderer = gtk_cell_renderer_text_new();
138 column = gtk_tree_view_column_new_with_attributes
139 (_("Account"), renderer, "text", PROGRESS_ACCOUNT, NULL);
140 gtk_tree_view_column_set_resizable(column, TRUE);
141 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
142 gtk_tree_view_column_set_fixed_width(column, 160);
143 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
145 renderer = gtk_cell_renderer_text_new();
146 column = gtk_tree_view_column_new_with_attributes
147 (_("Status"), renderer, "text", PROGRESS_STATE, NULL);
148 gtk_tree_view_column_set_resizable(column, TRUE);
149 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
150 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
152 /* the WM close and hide buttons are handled internally and not published to caller */
153 g_signal_connect(G_OBJECT(dialog), "delete_event",
154 G_CALLBACK(progress_dialog_delete_event_btn_cb), NULL);
155 g_signal_connect(G_OBJECT(hide_btn), "clicked",
156 G_CALLBACK(progress_dialog_hide_btn_cb), dialog);
158 progress->window = dialog;
159 progress->label = label;
160 progress->showlog_btn = showlog_btn;
161 progress->cancel_btn = cancel_btn;
162 progress->progressbar = progressbar;
163 progress->treeview = treeview;
164 progress->store = store;
166 return progress;
169 void progress_dialog_set_label(ProgressDialog *progress, gchar *str)
171 gtk_label_set_text(GTK_LABEL(progress->label), str);
174 void progress_dialog_get_fraction(ProgressDialog *progress)
176 gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progress->progressbar));
179 void progress_dialog_set_fraction(ProgressDialog *progress,
180 gfloat percentage)
182 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->progressbar),
183 percentage);
186 void progress_dialog_destroy(ProgressDialog *progress)
188 if (progress) {
189 gtk_widget_destroy(progress->window);
190 g_free(progress);
195 *\return gint Row where status was set
197 gint progress_dialog_list_set_status(ProgressDialog *progress,
198 gint row,
199 const gchar *status)
201 return progress_dialog_insert_account(progress, row, NULL,
202 status, NULL);
206 *\return gint Row where data were set
208 gint progress_dialog_list_set(ProgressDialog *progress,
209 gint row,
210 GdkPixbuf *image,
211 const gchar *account_name,
212 const gchar *status)
214 return progress_dialog_insert_account(progress, row, account_name,
215 status, image);
218 void progress_dialog_scroll_to_row(ProgressDialog *progress, gint row)
220 GtkTreeModel *model = GTK_TREE_MODEL(progress->store);
221 GtkTreeIter iter;
222 GtkTreePath *path;
224 if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row))
225 return;
227 path = gtk_tree_model_get_path(model, &iter);
228 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(progress->treeview),
229 path, NULL, FALSE, 0.0, 0.0);
230 gtk_tree_path_free(path);
233 static gint progress_dialog_insert_account(ProgressDialog *progress,
234 gint row,
235 const gchar *account,
236 const gchar *status,
237 GdkPixbuf *image)
239 GtkTreeIter iter;
240 GtkListStore *store = progress->store;
241 gint result = -1;
243 if (account == NULL && status == NULL && image == NULL)
244 return -1;
246 /* see if row exists, if not append */
247 if (row < 0 || !gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store),
248 &iter, NULL, row)) {
249 result = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store),
250 NULL);
251 gtk_list_store_append(store, &iter);
252 } else
253 result = row;
256 * XXX: uhm, when does the iter invalidate? sure not while
257 * just setting a row's column i hope?
260 if (account)
261 gtk_list_store_set(store, &iter,
262 PROGRESS_ACCOUNT, account,
263 -1);
264 if (status)
265 gtk_list_store_set(store, &iter,
266 PROGRESS_STATE, status,
267 -1);
268 if (image)
269 gtk_list_store_set(store, &iter,
270 PROGRESS_IMAGE, image,
271 -1);
273 return result;
276 static void progress_dialog_hide_btn_cb(GtkWidget *widget, gpointer data)
278 gtk_widget_hide(GTK_WIDGET(data));
281 static void progress_dialog_delete_event_btn_cb(GtkWidget *widget, gpointer data)
283 gtk_widget_hide(widget);