2007-05-03 [wwp] 2.9.1cvs41
[claws.git] / src / gtk / gtkutils.c
index ad58fc9..600904a 100644 (file)
@@ -756,6 +756,7 @@ void gtkut_window_popup(GtkWidget *window)
        if (new_x != x || new_y != y)
                gdk_window_move(window->window, new_x, new_y);
 
+       gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), FALSE);
        gtk_window_present(GTK_WINDOW(window));
 }
 
@@ -853,13 +854,32 @@ void gtkut_widget_set_composer_icon(GtkWidget *widget)
        gdk_window_set_icon(widget->window, NULL, xpm, bmp);    
 }
 
+static gboolean move_bar = FALSE;
+static gint move_bar_id = -1;
+
+static gboolean move_bar_cb(gpointer data)
+{
+       GtkWidget *w = (GtkWidget *)data;
+       if (!move_bar)
+               return FALSE;
+
+       if (!GTK_IS_PROGRESS_BAR(w)) {
+               return FALSE;
+       }
+
+       gtk_progress_bar_pulse(GTK_PROGRESS_BAR(w));
+       GTK_EVENTS_FLUSH();
+       return TRUE;
+}
+
 GtkWidget *label_window_create(const gchar *str)
 {
        GtkWidget *window;
-       GtkWidget *label;
+       GtkWidget *label, *vbox, *hbox;
+       GtkWidget *wait_progress = gtk_progress_bar_new();
 
        window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "gtkutils");
-       gtk_widget_set_size_request(window, 380, 60);
+       gtk_widget_set_size_request(window, 380, 70);
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
        gtk_window_set_title(GTK_WINDOW(window), str);
@@ -868,17 +888,41 @@ GtkWidget *label_window_create(const gchar *str)
        manage_window_set_transient(GTK_WINDOW(window));
 
        label = gtk_label_new(str);
-       gtk_container_add(GTK_CONTAINER(window), label);
+       
+       vbox = gtk_vbox_new(FALSE, 6);
+       hbox = gtk_hbox_new(FALSE, 6);
+       gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, FALSE, 0);
+       hbox = gtk_hbox_new(FALSE, 6);
+       gtk_box_pack_start(GTK_BOX(hbox), wait_progress, TRUE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+       
+       gtk_container_add(GTK_CONTAINER(window), vbox);
        gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
-       gtk_widget_show(label);
+       gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
+       gtk_widget_show_all(vbox);
 
        gtk_widget_show_now(window);
        
+       if (move_bar_id == -1) {
+               move_bar_id = g_timeout_add(200, move_bar_cb, wait_progress);
+               move_bar = TRUE;
+       }
+
        GTK_EVENTS_FLUSH();
 
        return window;
 }
 
+void label_window_destroy(GtkWidget *window)
+{
+       move_bar = FALSE;
+       g_source_remove(move_bar_id);
+       move_bar_id = -1;
+       GTK_EVENTS_FLUSH();
+       gtk_widget_destroy(window);     
+}
+
 GtkWidget *gtkut_account_menu_new(GList                        *ac_list,
                                  GCallback              callback,
                                  gpointer               data)
@@ -1568,10 +1612,92 @@ gboolean gtkut_tree_model_get_iter_last(GtkTreeModel *model,
        return gtk_tree_model_iter_nth_child(model, iter, NULL, count - 1);
 }
 
+#ifdef MAEMO
+HildonWindow *gtkut_window_new         (GtkWindowType   type,
+                                        const gchar    *class)
+{
+       HildonWindow *window = HILDON_WINDOW(hildon_window_new());
+       gtk_window_set_role(GTK_WINDOW(window), class);
+       hildon_program_add_window(hildon_program(), window);
+       return window;
+}
+#else
 GtkWidget *gtkut_window_new            (GtkWindowType   type,
                                         const gchar    *class)
 {
        GtkWidget *window = gtk_window_new(type);
-       gtk_window_set_wmclass(window, class, "Claws Mail");
+       gtk_window_set_role(GTK_WINDOW(window), class);
        return window;
 }
+#endif
+
+gboolean gtkut_tree_iter_comp(GtkTreeModel *model, 
+                                    GtkTreeIter *iter1, 
+                                    GtkTreeIter *iter2)
+{
+       GtkTreePath *path1 = gtk_tree_model_get_path(model, iter1);
+       GtkTreePath *path2 = gtk_tree_model_get_path(model, iter2);
+       gboolean result;
+
+       result = gtk_tree_path_compare(path1, path2) == 0;
+
+       gtk_tree_path_free(path1);
+       gtk_tree_path_free(path2);
+       
+       return result;
+}
+
+/*!
+ *\brief       Get selected row number.
+ */
+gint gtkut_list_view_get_selected_row(GtkWidget *list_view)
+{
+       GtkTreeView *view = GTK_TREE_VIEW(list_view);
+       GtkTreeModel *model = gtk_tree_view_get_model(view);
+       int n_rows = gtk_tree_model_iter_n_children(model, NULL);
+       GtkTreeSelection *selection;
+       GtkTreeIter iter;
+       int row;
+
+       if (n_rows == 0) 
+               return -1;
+       
+       selection = gtk_tree_view_get_selection(view);
+       if (!gtk_tree_selection_get_selected(selection, &model, &iter))
+               return -1;
+       
+       /* get all iterators and compare them... */
+       for (row = 0; row < n_rows; row++) {
+               GtkTreeIter itern;
+
+               gtk_tree_model_iter_nth_child(model, &itern, NULL, row);
+               if (gtkut_tree_iter_comp(model, &iter, &itern))
+                       return row;
+       }
+       
+       return -1;
+}
+
+/*!
+ *\brief       Select a row by its number.
+ */
+gboolean gtkut_list_view_select_row(GtkWidget *list, gint row)
+{
+       GtkTreeView *list_view = GTK_TREE_VIEW(list);
+       GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
+       GtkTreeModel *model = gtk_tree_view_get_model(list_view);
+       GtkTreeIter iter;
+       GtkTreePath *path;
+
+       if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row))
+               return FALSE;
+       
+       gtk_tree_selection_select_iter(selection, &iter);
+
+       path = gtk_tree_model_get_path(model, &iter);
+       gtk_tree_view_set_cursor(list_view, path, NULL, FALSE);
+       gtk_tree_path_free(path);
+       
+       return TRUE;
+}
+