claws-mail/src/gtk/progressdialog.c
Colin Leroy 6edf2f5fe8 2012-07-07 [colin] 3.8.1cvs7
* claws-features.h.in
	* configure.ac
	* Makefile.am
	* src/account.c
	* src/action.c
	* src/addr_compl.c
	* src/addrcustomattr.c
	* src/addrduplicates.c
	* src/addressadd.c
	* src/addressbook.c
	* src/addressbook_foldersel.c
	* src/addrgather.c
	* src/addrindex.c
	* src/alertpanel.c
	* src/autofaces.c
	* src/browseldap.c
	* src/codeconv.c
	* src/codeconv.h
	* src/compose.c
	* src/crash.c
	* src/customheader.c
	* src/displayheader.c
	* src/editaddress.c
	* src/editaddress_other_attributes_ldap.c
	* src/editbook.c
	* src/editgroup.c
	* src/editjpilot.c
	* src/editldap.c
	* src/editldap_basedn.c
	* src/edittags.c
	* src/editvcard.c
	* src/exphtmldlg.c
	* src/expldifdlg.c
	* src/export.c
	* src/exporthtml.c
	* src/exportldif.c
	* src/folder.c
	* src/folder_item_prefs.c
	* src/grouplistdialog.c
	* src/headerview.c
	* src/image_viewer.c
	* src/imap.c
	* src/imap_gtk.c
	* src/imap_gtk.h
	* src/import.c
	* src/importldif.c
	* src/importmutt.c
	* src/importpine.c
	* src/inc.c
	* src/inc.h
	* src/jpilot.c
	* src/jpilot.h
	* src/ldapctrl.c
	* src/ldaplocate.c
	* src/ldapquery.c
	* src/ldapserver.c
	* src/ldapupdate.c
	* src/ldaputil.c
	* src/main.c
	* src/manual.c
	* src/matcher.c
	* src/mbox.c
	* src/message_search.c
	* src/messageview.h
	* src/mh.c
	* src/mh_gtk.c
	* src/mimeview.c
	* src/msgcache.c
	* src/msgcache.h
	* src/news.c
	* src/news_gtk.c
	* src/news_gtk.h
	* src/noticeview.c
	* src/partial_download.c
	* src/partial_download.h
	* src/pop.c
	* src/pop.h
	* src/prefs_account.c
	* src/prefs_account.h
	* src/prefs_actions.c
	* src/prefs_common.c
	* src/prefs_common.h
	* src/prefs_compose_writing.c
	* src/prefs_customheader.c
	* src/prefs_display_header.c
	* src/prefs_ext_prog.c
	* src/prefs_filtering.c
	* src/prefs_filtering_action.c
	* src/prefs_folder_column.c
	* src/prefs_folder_item.c
	* src/prefs_fonts.c
	* src/prefs_gtk.c
	* src/prefs_image_viewer.c
	* src/prefs_logging.c
	* src/prefs_matcher.c
	* src/prefs_message.c
	* src/prefs_msg_colors.c
	* src/prefs_other.c
	* src/prefs_quote.c
	* src/prefs_receive.c
	* src/prefs_send.c
	* src/prefs_spelling.c
	* src/prefs_summaries.c
	* src/prefs_summary_column.c
	* src/prefs_summary_open.c
	* src/prefs_toolbar.c
	* src/prefs_wrapping.c
	* src/printing.c
	* src/printing.h
	* src/procheader.c
	* src/procmime.c
	* src/procmime.h
	* src/procmsg.h
	* src/quote_fmt.c
	* src/recv.c
	* src/send_message.c
	* src/setup.c
	* src/ssl_manager.c
	* src/statusbar.c
	* src/summary_search.c
	* src/textview.c
	* src/textview.h
	* src/toolbar.c
	* src/undo.c
	* src/unmime.c
	* src/uri_opener.c
	* src/wizard.c
	* src/common/claws.c
	* src/common/defs.h
	* src/common/hooks.c
	* src/common/log.c
	* src/common/log.h
	* src/common/plugin.c
	* src/common/prefs.c
	* src/common/session.c
	* src/common/session.h
	* src/common/smtp.c
	* src/common/smtp.h
	* src/common/socket.c
	* src/common/socket.h
	* src/common/ssl.c
	* src/common/ssl.h
	* src/common/ssl_certificate.c
	* src/common/ssl_certificate.h
	* src/common/string_match.c
	* src/common/tags.c
	* src/common/timing.h
	* src/common/utils.c
	* src/common/utils.h
	* src/etpan/etpan-thread-manager.c
	* src/etpan/imap-thread.c
	* src/etpan/nntp-thread.c
	* src/gtk/about.c
	* src/gtk/combobox.c
	* src/gtk/description_window.c
	* src/gtk/filesel.c
	* src/gtk/gtkaspell.c
	* src/gtk/gtkaspell.h
	* src/gtk/gtkshruler.c
	* src/gtk/gtkunit.c
	* src/gtk/gtkutils.c
	* src/gtk/gtkutils.h
	* src/gtk/gtkvscrollbutton.c
	* src/gtk/icon_legend.c
	* src/gtk/inputdialog.c
	* src/gtk/logwindow.c
	* src/gtk/menu.c
	* src/gtk/pluginwindow.c
	* src/gtk/pluginwindow.h
	* src/gtk/prefswindow.c
	* src/gtk/progressdialog.c
	* src/gtk/quicksearch.c
	* src/gtk/spell_entry.c
	* src/gtk/spell_entry.h
	* src/gtk/sslcertwindow.c
	* src/gtk/sslcertwindow.h
	* src/plugins/bogofilter/bogofilter.c
	* src/plugins/bogofilter/bogofilter_gtk.c
	* src/plugins/dillo_viewer/dillo_prefs.c
	* src/plugins/dillo_viewer/dillo_viewer.c
	* src/plugins/pgpcore/pgp_viewer.c
	* src/plugins/pgpcore/plugin.c
	* src/plugins/pgpcore/sgpgme.c
	* src/plugins/pgpinline/pgpinline.c
	* src/plugins/pgpinline/plugin.c
	* src/plugins/pgpmime/pgpmime.c
	* src/plugins/pgpmime/plugin.c
	* src/plugins/smime/plugin.c
	* src/plugins/smime/smime.c
	* src/plugins/spamassassin/libspamc.c
	* src/plugins/spamassassin/spamassassin.c
	* src/plugins/spamassassin/spamassassin_gtk.c
	* src/plugins/trayicon/trayicon.c
	* src/plugins/trayicon/trayicon_prefs.c
		Specify Claws compile-time features in a specific header
2012-07-07 07:09:39 +00:00

286 lines
8.4 KiB
C

/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
* Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#include "claws-features.h"
#endif
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include "progressdialog.h"
#include "gtkutils.h"
#include "utils.h"
#include "prefs_common.h"
enum {
PROGRESS_IMAGE,
PROGRESS_ACCOUNT,
PROGRESS_STATE,
N_PROGRESS_COLUMNS
};
static gint progress_dialog_insert_account(ProgressDialog *progress,
gint row,
const gchar *account,
const gchar *status,
GdkPixbuf *image);
static void progress_dialog_hide_btn_cb(GtkWidget *widget, gpointer data);
static void progress_dialog_delete_event_btn_cb(GtkWidget *widget, gpointer data);
ProgressDialog *progress_dialog_create(void)
{
ProgressDialog *progress;
GtkWidget *dialog;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *label;
GtkWidget *hide_btn;
GtkWidget *showlog_btn;
GtkWidget *cancel_btn;
GtkWidget *progressbar;
GtkWidget *scrolledwin;
GtkWidget *treeview;
GtkListStore *store;
GtkTreeSelection *selection;
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
debug_print("Creating progress dialog...\n");
progress = g_new0(ProgressDialog, 1);
dialog = gtk_dialog_new();
gtk_container_set_border_width(GTK_CONTAINER(dialog), 8);
gtk_window_set_resizable(GTK_WINDOW(dialog), TRUE);
gtk_widget_realize(dialog);
gtk_container_set_border_width
(GTK_CONTAINER(gtk_dialog_get_action_area(GTK_DIALOG(dialog))), 0);
vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
gtk_box_set_spacing(GTK_BOX(vbox), 8);
hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), hbox,
FALSE, FALSE, 8);
gtk_widget_show(hbox);
label = gtk_label_new("");
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8);
gtk_widget_show(label);
hide_btn = gtk_dialog_add_button(GTK_DIALOG(dialog),
_("_Hide"),
GTK_RESPONSE_NONE);
showlog_btn = gtk_dialog_add_button(GTK_DIALOG(dialog),
_("_View log"),
GTK_RESPONSE_NONE);
cancel_btn = gtk_dialog_add_button(GTK_DIALOG(dialog),
GTK_STOCK_CANCEL,
GTK_RESPONSE_NONE);
gtk_widget_grab_default(cancel_btn);
gtk_widget_grab_focus(cancel_btn);
progressbar = gtk_progress_bar_new();
gtk_box_pack_start(GTK_BOX(vbox), progressbar,
FALSE, FALSE, 0);
gtk_widget_show(progressbar);
scrolledwin = gtk_scrolled_window_new(NULL, NULL);
gtk_widget_show(scrolledwin);
gtk_box_pack_start(GTK_BOX(vbox), scrolledwin,
TRUE, TRUE, 0);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
store = gtk_list_store_new(N_PROGRESS_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_POINTER);
treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
g_object_unref(G_OBJECT(store));
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE);
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview),
prefs_common.use_stripes_everywhere);
gtk_widget_show(treeview);
gtk_container_add(GTK_CONTAINER(scrolledwin), treeview);
gtk_widget_set_size_request(treeview, -1, 120);
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
renderer = gtk_cell_renderer_pixbuf_new();
g_object_set(renderer, "xalign", 0.5, NULL);
column = gtk_tree_view_column_new_with_attributes
(NULL, renderer, "pixbuf", PROGRESS_IMAGE, NULL);
gtk_tree_view_column_set_alignment(column, 0.5);
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_fixed_width(column, 20);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes
(_("Account"), renderer, "text", PROGRESS_ACCOUNT, NULL);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_fixed_width(column, 160);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes
(_("Status"), renderer, "text", PROGRESS_STATE, NULL);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
/* the WM close and hide buttons are handled internally and not published to caller */
g_signal_connect(G_OBJECT(dialog), "delete_event",
G_CALLBACK(progress_dialog_delete_event_btn_cb), NULL);
g_signal_connect(G_OBJECT(hide_btn), "clicked",
G_CALLBACK(progress_dialog_hide_btn_cb), dialog);
progress->window = dialog;
progress->label = label;
progress->showlog_btn = showlog_btn;
progress->cancel_btn = cancel_btn;
progress->progressbar = progressbar;
progress->treeview = treeview;
progress->store = store;
return progress;
}
void progress_dialog_set_label(ProgressDialog *progress, gchar *str)
{
gtk_label_set_text(GTK_LABEL(progress->label), str);
}
void progress_dialog_get_fraction(ProgressDialog *progress)
{
gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progress->progressbar));
}
void progress_dialog_set_fraction(ProgressDialog *progress,
gfloat percentage)
{
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->progressbar),
percentage);
}
void progress_dialog_destroy(ProgressDialog *progress)
{
if (progress) {
gtk_widget_destroy(progress->window);
g_free(progress);
}
}
/*!
*\return gint Row where status was set
*/
gint progress_dialog_list_set_status(ProgressDialog *progress,
gint row,
const gchar *status)
{
return progress_dialog_insert_account(progress, row, NULL,
status, NULL);
}
/*!
*\return gint Row where data were set
*/
gint progress_dialog_list_set(ProgressDialog *progress,
gint row,
GdkPixbuf *image,
const gchar *account_name,
const gchar *status)
{
return progress_dialog_insert_account(progress, row, account_name,
status, image);
}
void progress_dialog_scroll_to_row(ProgressDialog *progress, gint row)
{
GtkTreeModel *model = GTK_TREE_MODEL(progress->store);
GtkTreeIter iter;
GtkTreePath *path;
if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row))
return;
path = gtk_tree_model_get_path(model, &iter);
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(progress->treeview),
path, NULL, FALSE, 0.0, 0.0);
gtk_tree_path_free(path);
}
static gint progress_dialog_insert_account(ProgressDialog *progress,
gint row,
const gchar *account,
const gchar *status,
GdkPixbuf *image)
{
GtkTreeIter iter;
GtkListStore *store = progress->store;
gint result = -1;
if (account == NULL && status == NULL && image == NULL)
return -1;
/* see if row exists, if not append */
if (row < 0 || !gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store),
&iter, NULL, row)) {
result = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store),
NULL);
gtk_list_store_append(store, &iter);
} else
result = row;
/*
* XXX: uhm, when does the iter invalidate? sure not while
* just setting a row's column i hope?
*/
if (account)
gtk_list_store_set(store, &iter,
PROGRESS_ACCOUNT, account,
-1);
if (status)
gtk_list_store_set(store, &iter,
PROGRESS_STATE, status,
-1);
if (image)
gtk_list_store_set(store, &iter,
PROGRESS_IMAGE, image,
-1);
return result;
}
static void progress_dialog_hide_btn_cb(GtkWidget *widget, gpointer data)
{
gtk_widget_hide(GTK_WIDGET(data));
}
static void progress_dialog_delete_event_btn_cb(GtkWidget *widget, gpointer data)
{
gtk_widget_hide(widget);
}