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/>.
22 #include "claws-features.h"
26 #include <glib/gi18n.h>
29 #include "progressdialog.h"
32 #include "prefs_common.h"
41 static gint
progress_dialog_insert_account(ProgressDialog
*progress
,
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
;
58 GtkWidget
*showlog_btn
;
59 GtkWidget
*cancel_btn
;
60 GtkWidget
*progressbar
;
61 GtkWidget
*scrolledwin
;
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
,
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
),
91 showlog_btn
= gtk_dialog_add_button(GTK_DIALOG(dialog
),
94 cancel_btn
= gtk_dialog_add_button(GTK_DIALOG(dialog
),
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
,
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
,
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
;
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
,
182 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress
->progressbar
),
186 void progress_dialog_destroy(ProgressDialog
*progress
)
189 gtk_widget_destroy(progress
->window
);
195 *\return gint Row where status was set
197 gint
progress_dialog_list_set_status(ProgressDialog
*progress
,
201 return progress_dialog_insert_account(progress
, row
, NULL
,
206 *\return gint Row where data were set
208 gint
progress_dialog_list_set(ProgressDialog
*progress
,
211 const gchar
*account_name
,
214 return progress_dialog_insert_account(progress
, row
, account_name
,
218 void progress_dialog_scroll_to_row(ProgressDialog
*progress
, gint row
)
220 GtkTreeModel
*model
= GTK_TREE_MODEL(progress
->store
);
224 if (!gtk_tree_model_iter_nth_child(model
, &iter
, NULL
, row
))
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
,
235 const gchar
*account
,
240 GtkListStore
*store
= progress
->store
;
243 if (account
== NULL
&& status
== NULL
&& image
== NULL
)
246 /* see if row exists, if not append */
247 if (row
< 0 || !gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store
),
249 result
= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store
),
251 gtk_list_store_append(store
, &iter
);
256 * XXX: uhm, when does the iter invalidate? sure not while
257 * just setting a row's column i hope?
261 gtk_list_store_set(store
, &iter
,
262 PROGRESS_ACCOUNT
, account
,
265 gtk_list_store_set(store
, &iter
,
266 PROGRESS_STATE
, status
,
269 gtk_list_store_set(store
, &iter
,
270 PROGRESS_IMAGE
, image
,
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
);