2005-01-07 [colin] 0.9.13cvs28.3
[claws.git] / src / gtk / progressdialog.c
index f9672d8dde03ff6b40ec98d69334bca648d53316..ab4201740897d9dca0a21541ebcb7b28add3fe10 100644 (file)
@@ -22,6 +22,7 @@
 #endif
 
 #include <glib.h>
+#include <gtk/gtk.h>
 #include <gtk/gtkwindow.h>
 #include <gtk/gtkvbox.h>
 #include <gtk/gtkhbox.h>
 #include "gtkutils.h"
 #include "utils.h"
 
+enum {
+       PROGRESS_IMAGE,
+       PROGRESS_ACCOUNT,
+       PROGRESS_STATE,
+       N_PROGRESS_COLUMNS
+};
+
+
+static GtkListStore* progress_dialog_create_data_store(void);
+static gint progress_dialog_list_view_insert_account(GtkWidget   *list_view,
+                                                    gint         row,
+                                                    const gchar *account,
+                                                    const gchar *status,
+                                                    GdkPixbuf   *image);
+static GtkWidget *progress_dialog_list_view_create(void);
+static void progress_dialog_create_list_view_columns(GtkTreeView *list_view);
+
 ProgressDialog *progress_dialog_create(void)
 {
        ProgressDialog *progress;
@@ -47,6 +65,7 @@ ProgressDialog *progress_dialog_create(void)
        GtkWidget *progressbar;
        GtkWidget *scrolledwin;
        GtkWidget *clist;
+       GtkWidget *list_view;
        gchar *text[] = {NULL, NULL, NULL};
 
        text[1] = _("Account");
@@ -58,8 +77,7 @@ ProgressDialog *progress_dialog_create(void)
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_widget_set_usize(window, 460, -1);
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
-       gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
-       gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE);
+       gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
        gtk_widget_realize(window);
 
        vbox = gtk_vbox_new(FALSE, 8);
@@ -74,8 +92,9 @@ ProgressDialog *progress_dialog_create(void)
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8);
        gtk_widget_show(label);
 
-       gtkut_button_set_create(&cancel_area, &cancel_btn, _("Cancel"),
-                               NULL, NULL, NULL, NULL);
+       gtkut_button_set_create_stock(&cancel_area, &cancel_btn, 
+                                     GTK_STOCK_CANCEL, NULL, NULL, 
+                                     NULL, NULL);
        gtk_box_pack_end(GTK_BOX(vbox), cancel_area, FALSE, FALSE, 0);
        gtk_widget_grab_default(cancel_btn);
        gtk_widget_show_all(cancel_area);
@@ -91,20 +110,29 @@ ProgressDialog *progress_dialog_create(void)
                                       GTK_POLICY_AUTOMATIC,
                                       GTK_POLICY_AUTOMATIC);
 
+       /* GTK2: we hide the clist, but it is available for migration
+        * purposes. now if there only was a way to catch "set clist 
+        * things"!.. */
        clist = gtk_clist_new_with_titles(3, text);
-       gtk_widget_show(clist);
-       gtk_container_add(GTK_CONTAINER(scrolledwin), clist);
-       gtk_widget_set_usize(clist, -1, 120);
+       gtk_widget_hide(clist);
+       /* gtk_container_add(GTK_CONTAINER(scrolledwin), clist); */
+       /* gtk_widget_set_usize(clist, -1, 120); */
        gtk_clist_set_column_justification(GTK_CLIST(clist), 0,
                                           GTK_JUSTIFY_CENTER);
        gtk_clist_set_column_width(GTK_CLIST(clist), 0, 16);
        gtk_clist_set_column_width(GTK_CLIST(clist), 1, 160);
 
+       list_view = progress_dialog_list_view_create();
+       gtk_widget_show(list_view);
+       gtk_container_add(GTK_CONTAINER(scrolledwin), list_view);
+       gtk_widget_set_usize(list_view, -1, 120);
+
        progress->window      = window;
        progress->label       = label;
        progress->cancel_btn  = cancel_btn;
        progress->progressbar = progressbar;
        progress->clist       = clist;
+       progress->list_view   = list_view;
 
        return progress;
 }
@@ -114,16 +142,16 @@ void progress_dialog_set_label(ProgressDialog *progress, gchar *str)
        gtk_label_set_text(GTK_LABEL(progress->label), str);
 }
 
-void progress_dialog_set_value(ProgressDialog *progress, gfloat value)
+void progress_dialog_get_fraction(ProgressDialog *progress)
 {
-       gtk_progress_set_value(GTK_PROGRESS(progress->progressbar), value);
+       gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progress->progressbar));
 }
 
-void progress_dialog_set_percentage(ProgressDialog *progress,
-                                   gfloat percentage)
+void progress_dialog_set_fraction(ProgressDialog *progress,
+                                 gfloat percentage)
 {
-       gtk_progress_set_percentage(GTK_PROGRESS(progress->progressbar),
-                                   percentage);
+       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->progressbar),
+                                     percentage);
 }
 
 void progress_dialog_destroy(ProgressDialog *progress)
@@ -133,3 +161,173 @@ void progress_dialog_destroy(ProgressDialog *progress)
                g_free(progress);
        }
 }
+
+/*!
+ *\return      gint Row where account was set
+ */
+gint progress_dialog_list_set_account(ProgressDialog *progress,
+                                     gint            row,
+                                     const gchar    *account_name)
+{
+       return progress_dialog_list_view_insert_account(progress->list_view,
+                                                       row, account_name, NULL, 
+                                                       NULL);
+}
+
+/*!
+ *\return      gint Row where image was set
+ */
+gint progress_dialog_list_set_image(ProgressDialog *progress,
+                                   gint            row,
+                                   GdkPixbuf      *image)
+{
+       return progress_dialog_list_view_insert_account(progress->list_view,
+                                                       row, NULL, NULL, 
+                                                       image);
+}
+
+/*!
+ *\return      gint Row where status was set
+ */
+gint progress_dialog_list_set_status(ProgressDialog *progress,
+                                    gint            row,
+                                    const gchar    *status)
+{
+       return progress_dialog_list_view_insert_account(progress->list_view,
+                                                       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_list_view_insert_account(progress->list_view,
+                                                       row,  account_name, 
+                                                       status, image);
+}
+
+/* XXX: maybe scroll into view, but leaving that for someone else to
+ * pickup: I don't have that many accounts... */
+gboolean progress_dialog_list_select_row(ProgressDialog *progress,
+                                        gint            row)
+{
+       GtkTreeSelection *selection = gtk_tree_view_get_selection
+                                       (GTK_TREE_VIEW(progress->list_view));
+       GtkTreeIter iter;
+       GtkTreeModel *model;
+
+       model = gtk_tree_view_get_model(GTK_TREE_VIEW(progress->list_view));
+
+       if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row))
+               return FALSE;
+
+       gtk_tree_selection_select_iter(selection, &iter);               
+
+       return TRUE;
+}
+
+static GtkListStore* progress_dialog_create_data_store(void)
+{
+       return gtk_list_store_new(N_PROGRESS_COLUMNS,
+                                 GDK_TYPE_PIXBUF,
+                                 G_TYPE_STRING,
+                                 G_TYPE_STRING,        
+                                 -1);
+}
+
+static gint progress_dialog_list_view_insert_account(GtkWidget   *list_view,
+                                                    gint         row,
+                                                    const gchar *account,
+                                                    const gchar *status,
+                                                    GdkPixbuf   *image)
+{
+       GtkTreeIter iter;
+       GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model
+                                       (GTK_TREE_VIEW(list_view)));
+       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 GtkWidget *progress_dialog_list_view_create(void)
+{
+       GtkTreeView *list_view;
+       GtkTreeModel *model;
+
+       model = GTK_TREE_MODEL(progress_dialog_create_data_store());
+       list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
+       g_object_unref(model);  
+       
+       gtk_tree_view_set_rules_hint(list_view, TRUE);
+       
+       /* create the columns */
+       progress_dialog_create_list_view_columns(list_view);
+
+       return GTK_WIDGET(list_view);
+}
+
+static void progress_dialog_create_list_view_columns(GtkTreeView *list_view)
+{
+       GtkTreeViewColumn *column;
+       GtkCellRenderer *renderer;
+
+       renderer = gtk_cell_renderer_pixbuf_new();
+       column = gtk_tree_view_column_new_with_attributes
+                       ("", renderer, 
+                        "pixbuf", PROGRESS_IMAGE,
+                        NULL);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);                   
+
+       renderer = gtk_cell_renderer_text_new();
+       column = gtk_tree_view_column_new_with_attributes
+               (_("Account"),
+                renderer,
+                "text", PROGRESS_ACCOUNT,
+                NULL);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);          
+
+       renderer = gtk_cell_renderer_text_new();
+       column = gtk_tree_view_column_new_with_attributes
+               (_("Status"),
+                renderer,
+                "text", PROGRESS_STATE,
+                NULL);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);          
+}
+