Commit 7e843e13 authored by Ignacio Casal Quinteiro's avatar Ignacio Casal Quinteiro Committed by Ignacio Casal Quinteiro

Now progress bar is inside of our statusbar class. (Fixes bug #514758).

2008-03-25  Ignacio Casal Quinteiro  <nacho.resa@gmail.com>

        * src/actions-go.c:
        * src/window.ch:
        * src/statusbar.ch:
        * src/actions-file.c:
        Now progress bar is inside of our statusbar class.
        (Fixes bug #514758).


svn path=/trunk/; revision=3525
parent bcd8137b
2008-03-25 Ignacio Casal Quinteiro <nacho.resa@gmail.com>
* src/actions-go.c:
* src/window.ch:
* src/statusbar.ch:
* src/actions-file.c:
Now progress bar is inside of our statusbar class.
(Fixes bug #514758).
2008-03-25 Ignacio Casal Quinteiro <nacho.resa@gmail.com>
* src/main.c:
......
......@@ -32,6 +32,7 @@
#include "file-dialogs.h"
#include "notebook.h"
#include "po.h"
#include "statusbar.h"
#include "tab.h"
#include "window.h"
......@@ -92,7 +93,9 @@ gtranslator_open(const gchar *filename,
active_view = gtranslator_tab_get_active_view(tab);
gtk_widget_grab_focus(GTK_WIDGET(active_view));
gtranslator_window_update_progress_bar(window);
gtranslator_statusbar_update_progress_bar (GTR_STATUSBAR (gtranslator_window_get_statusbar (window)),
(gdouble)gtranslator_po_get_translated_count (po),
(gdouble)gtranslator_po_get_messages_count (po));
return TRUE;
}
......
......@@ -41,8 +41,6 @@ gtranslator_message_go_to_first(GtkAction *action,
po = gtranslator_tab_get_po(current);
gtranslator_tab_message_go_to(current,
g_list_first(gtranslator_po_get_current_message(po)));
//gtranslator_window_update_statusbar(window);
gtranslator_window_update_progress_bar(window);
set_sensitive_according_to_message(window, po);
}
......@@ -57,8 +55,6 @@ gtranslator_message_go_to_previous(GtkAction *action,
po = gtranslator_tab_get_po(current);
gtranslator_tab_message_go_to(current,
g_list_previous(gtranslator_po_get_current_message(po)));
//gtranslator_window_update_statusbar(window);
gtranslator_window_update_progress_bar(window);
set_sensitive_according_to_message(window, po);
}
......@@ -73,8 +69,6 @@ gtranslator_message_go_to_next(GtkAction *action,
po = gtranslator_tab_get_po(current);
gtranslator_tab_message_go_to(current,
g_list_next(gtranslator_po_get_current_message(po)));
//gtranslator_window_update_statusbar(window);
gtranslator_window_update_progress_bar(window);
set_sensitive_according_to_message(window, po);
}
......@@ -89,8 +83,6 @@ gtranslator_message_go_to_last(GtkAction *action,
po = gtranslator_tab_get_po(current);
gtranslator_tab_message_go_to(current,
g_list_last(gtranslator_po_get_current_message(po)));
//gtranslator_window_update_statusbar(window);
gtranslator_window_update_progress_bar(window);
set_sensitive_according_to_message(window, po);
}
......@@ -116,8 +108,6 @@ gtranslator_message_go_to_next_fuzzy(GtkAction *action,
if(msg != NULL)
{
gtranslator_tab_message_go_to(current, msg);
// gtranslator_window_update_statusbar(window);
gtranslator_window_update_progress_bar(window);
set_sensitive_according_to_message(window, po);
}
}
......@@ -136,8 +126,6 @@ gtranslator_message_go_to_prev_fuzzy(GtkAction *action,
if(msg != NULL)
{
gtranslator_tab_message_go_to(current, msg);
//gtranslator_window_update_statusbar(window);
gtranslator_window_update_progress_bar(window);
set_sensitive_according_to_message(window, po);
}
}
......@@ -156,8 +144,6 @@ gtranslator_message_go_to_next_untranslated(GtkAction *action,
if(msg != NULL)
{
gtranslator_tab_message_go_to(current, msg);
//gtranslator_window_update_statusbar(window);
gtranslator_window_update_progress_bar(window);
set_sensitive_according_to_message(window, po);
}
}
......@@ -176,8 +162,6 @@ gtranslator_message_go_to_prev_untranslated(GtkAction *action,
if(msg != NULL)
{
gtranslator_tab_message_go_to(current, msg);
// gtranslator_window_update_statusbar(window);
gtranslator_window_update_progress_bar(window);
set_sensitive_according_to_message(window, po);
}
}
......@@ -34,6 +34,9 @@
struct _GtranslatorStatusbarPrivate
{
GtkWidget *statusbar;
GtkWidget *progress_bar;
GtkWidget *overwrite_mode_label;
/* tmp flash timeout data */
......@@ -42,7 +45,7 @@ struct _GtranslatorStatusbarPrivate
guint flash_message_id;
};
G_DEFINE_TYPE(GtranslatorStatusbar, gtranslator_statusbar, GTK_TYPE_STATUSBAR)
G_DEFINE_TYPE(GtranslatorStatusbar, gtranslator_statusbar, GTK_TYPE_HBOX)
static void
gtranslator_statusbar_finalize (GObject *object)
......@@ -68,13 +71,32 @@ gtranslator_statusbar_class_init (GtranslatorStatusbarClass *klass)
static void
gtranslator_statusbar_init (GtranslatorStatusbar *statusbar)
{
GtkWidget *frame;
GtkShadowType shadow_type;
statusbar->priv = GTR_STATUSBAR_GET_PRIVATE (statusbar);
gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
/*
* Statusbar
*/
statusbar->priv->statusbar = gtk_statusbar_new ();
gtk_widget_show (statusbar->priv->statusbar);
gtk_box_pack_end (GTK_BOX (statusbar), statusbar->priv->statusbar,
TRUE, TRUE, 0);
/*
* Progress bar
*/
statusbar->priv->progress_bar = gtk_progress_bar_new ();
gtk_widget_show (statusbar->priv->progress_bar);
gtk_box_pack_start (GTK_BOX (statusbar), statusbar->priv->progress_bar,
FALSE, FALSE, 0);
/*
* Ins/Ovr stuff
*/
gtk_widget_style_get (GTK_WIDGET (statusbar->priv->statusbar),
"shadow-type", &shadow_type, NULL);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), shadow_type);
......@@ -90,8 +112,8 @@ gtranslator_statusbar_init (GtranslatorStatusbar *statusbar)
gtk_container_add (GTK_CONTAINER (frame), statusbar->priv->overwrite_mode_label);
gtk_widget_show (statusbar->priv->overwrite_mode_label);
gtk_box_pack_start (GTK_BOX (statusbar), frame, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (statusbar->priv->statusbar), frame,
FALSE, FALSE, 0);
}
/**
......@@ -107,6 +129,27 @@ gtranslator_statusbar_new (void)
return GTK_WIDGET (g_object_new (GTR_TYPE_STATUSBAR, NULL));
}
guint
gtranslator_statusbar_push (GtranslatorStatusbar *statusbar,
guint context_id,
const gchar *text)
{
g_return_if_fail (GTR_IS_STATUSBAR (statusbar));
return gtk_statusbar_push (GTK_STATUSBAR (statusbar->priv->statusbar),
context_id, text);
}
void
gtranslator_statusbar_pop (GtranslatorStatusbar *statusbar,
guint context_id)
{
g_return_if_fail (GTR_IS_STATUSBAR (statusbar));
gtk_statusbar_pop (GTK_STATUSBAR (statusbar->priv->statusbar),
context_id);
}
/**
* gtranslator_statusbar_set_overwrite:
* @statusbar: a #GtranslatorStatusbar
......@@ -136,7 +179,7 @@ gtranslator_statusbar_clear_overwrite (GtranslatorStatusbar *statusbar)
static gboolean
remove_message_timeout (GtranslatorStatusbar *statusbar)
{
gtk_statusbar_remove (GTK_STATUSBAR (statusbar),
gtk_statusbar_remove (GTK_STATUSBAR (statusbar->priv->statusbar),
statusbar->priv->flash_context_id,
statusbar->priv->flash_message_id);
......@@ -181,7 +224,7 @@ gtranslator_statusbar_flash_message (GtranslatorStatusbar *statusbar,
}
statusbar->priv->flash_context_id = context_id;
statusbar->priv->flash_message_id = gtk_statusbar_push (GTK_STATUSBAR (statusbar),
statusbar->priv->flash_message_id = gtk_statusbar_push (GTK_STATUSBAR (statusbar->priv->statusbar),
context_id,
msg);
......@@ -191,3 +234,33 @@ gtranslator_statusbar_flash_message (GtranslatorStatusbar *statusbar,
g_free (msg);
}
/*
* Update the progress bar
*/
void
gtranslator_statusbar_update_progress_bar (GtranslatorStatusbar *statusbar,
gdouble translated_count,
gdouble messages_count)
{
gdouble percentage;
g_return_if_fail (GTR_IS_STATUSBAR (statusbar));
/*
* Calculate the percentage.
*/
percentage = translated_count / messages_count;
/*
* Set the progress only if the values are reasonable.
*/
if(percentage > 0.0 || percentage < 1.0)
{
/*
* Set the progressbar status.
*/
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (statusbar->priv->progress_bar),
percentage);
}
}
......@@ -21,7 +21,7 @@
#ifndef GTR_STATUSBAR_H
#define GTR_STATUSBAR_H
#include <gtk/gtkstatusbar.h>
#include <gtk/gtkhbox.h>
G_BEGIN_DECLS
......@@ -38,7 +38,7 @@ typedef struct _GtranslatorStatusbarClass GtranslatorStatusbarClass;
struct _GtranslatorStatusbar
{
GtkStatusbar parent;
GtkHBox parent;
/* <private/> */
GtranslatorStatusbarPrivate *priv;
......@@ -46,13 +46,19 @@ struct _GtranslatorStatusbar
struct _GtranslatorStatusbarClass
{
GtkStatusbarClass parent_class;
GtkHBoxClass parent_class;
};
GType gtranslator_statusbar_get_type (void) G_GNUC_CONST;
GType gtranslator_statusbar_get_type (void) G_GNUC_CONST;
GtkWidget *gtranslator_statusbar_new (void);
guint gtranslator_statusbar_push (GtranslatorStatusbar *statusbar,
guint context_id,
const gchar *text);
void gtranslator_statusbar_pop (GtranslatorStatusbar *statusbar,
guint context_id);
void gtranslator_statusbar_set_overwrite (GtranslatorStatusbar *statusbar,
gboolean overwrite);
......@@ -63,6 +69,11 @@ void gtranslator_statusbar_flash_message (GtranslatorStatusbar *statusbar,
guint context_id,
const gchar *format,
...) G_GNUC_PRINTF(3, 4);
void gtranslator_statusbar_update_progress_bar (GtranslatorStatusbar *statusbar,
gdouble translated_count,
gdouble messages_count);
G_END_DECLS
#endif
......@@ -77,9 +77,7 @@ struct _GtranslatorWindowPrivate
GtkWidget *statusbar;
guint generic_message_cid;
guint tip_message_cid;
GtkWidget *progressbar;
GtkUIManager *ui_manager;
GtkRecentManager *recent_manager;
GtkWidget *recent_menu;
......@@ -716,12 +714,12 @@ gtranslator_window_update_statusbar_message_count(GtranslatorTab *tab,
msg = g_strconcat(" ", current, " ", status_msg, " ", total,
" ", fuzzy_msg, " ", untranslated_msg, NULL);
gtk_statusbar_pop(GTK_STATUSBAR(window->priv->statusbar),
0);
gtranslator_statusbar_pop (GTR_STATUSBAR (window->priv->statusbar),
0);
gtk_statusbar_push(GTK_STATUSBAR(window->priv->statusbar),
0,
msg);
gtranslator_statusbar_push (GTR_STATUSBAR (window->priv->statusbar),
0,
msg);
g_free(msg);
g_free(current);
......@@ -729,6 +727,13 @@ gtranslator_window_update_statusbar_message_count(GtranslatorTab *tab,
g_free(total);
g_free(fuzzy_msg);
g_free(untranslated_msg);
/*
* We have to update the progress bar too
*/
gtranslator_statusbar_update_progress_bar (GTR_STATUSBAR (window->priv->statusbar),
(gdouble)gtranslator_po_get_translated_count (po),
(gdouble)gtranslator_po_get_messages_count (po));
}
static GtranslatorWindow *
......@@ -1299,16 +1304,9 @@ gtranslator_window_draw (GtranslatorWindow *window)
hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start( GTK_BOX(priv->main_box), hbox, FALSE, FALSE, 0);
gtk_widget_show(hbox);
/*
* progressbar
*/
priv->progressbar = gtk_progress_bar_new();
gtk_box_pack_start( GTK_BOX(hbox), priv->progressbar, FALSE, FALSE, 0);
gtk_widget_show(priv->progressbar);
/*
* statusbar
* statusbar & progress bar
*/
window->priv->statusbar = gtranslator_statusbar_new ();
......@@ -1563,10 +1561,10 @@ gtranslator_window_get_notebook(GtranslatorWindow *window)
return GTR_NOTEBOOK(window->priv->notebook);
}
GtkStatusbar *
GtkWidget *
gtranslator_window_get_statusbar(GtranslatorWindow *window)
{
return GTK_STATUSBAR(window->priv->statusbar);
return window->priv->statusbar;
}
GtkUIManager *
......@@ -1637,38 +1635,6 @@ gtranslator_window_get_all_views(GtranslatorWindow *window,
return views;
}
/*
* Update the progress bar
*/
void
gtranslator_window_update_progress_bar(GtranslatorWindow *window)
{
gdouble percentage;
GtranslatorTab *current_page;
GtranslatorPo *po;
current_page = gtranslator_window_get_active_tab(window);
po = gtranslator_tab_get_po(current_page);
/*
* Calculate the percentage.
*/
percentage = (gdouble)(gtranslator_po_get_translated_count(po)
/ (gdouble)gtranslator_po_get_messages_count(po));
/*
* Set the progress only if the values are reasonable.
*/
if(percentage > 0.0 || percentage < 1.0)
{
/*
* Set the progressbar status.
*/
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(window->priv->progressbar),
percentage);
}
}
void
gtranslator_window_add_widget (GtranslatorWindow *window,
GtkWidget *widget,
......
......@@ -94,7 +94,7 @@ GList *gtranslator_window_get_all_tabs (GtranslatorWindow *window
GtranslatorNotebook *gtranslator_window_get_notebook (GtranslatorWindow *window);
GtranslatorHeader *gtranslator_window_get_header_from_active_tab (GtranslatorWindow *window);
GtkStatusbar *gtranslator_window_get_statusbar (GtranslatorWindow *window);
GtkWidget *gtranslator_window_get_statusbar (GtranslatorWindow *window);
GtkUIManager *gtranslator_window_get_ui_manager (GtranslatorWindow *window);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment