statusbar.h File Reference

#include <glib.h>
Include dependency graph for statusbar.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef GtkWidget *(* dialog_cb_t )(GtkMessageType type, const char *title, const char *message, eripc_context_t *context, const char *message_id)
 Create and initialize the statusbar.

Functions

void statusbar_create (dialog_cb_t cb)
gboolean statusbar_item_set_state (const char *item, const char *statename)
 Set the state of a status bar item.
gboolean statusbar_item_show (const char *item, const char *mode)
 Show a status bar item.
gboolean statusbar_remove_item (const char *item)
 Remove and free a status bar item.
void statusbar_update_battery_state (gint level, const char *state)
 Update battery state icon.
void statusbar_update_signal_strength (const char *medium, gint strength)
void statusbar_update_pagecounter (gint curpage, gint numpages, gboolean boundary_check)
void statusbar_hide_pagecounter ()
void statusbar_set_text (void)

Variables

G_BEGIN_DECLS GtkWindow * g_statusbar_window

Typedef Documentation

typedef GtkWidget*(* dialog_cb_t)(GtkMessageType type, const char *title, const char *message, eripc_context_t *context, const char *message_id)

Create and initialize the statusbar.

---------------------------------------------------------------------------

Name : statusbar_create

Returns:
--

--------------------------------------------------------------------------

Definition at line 60 of file statusbar.h.


Function Documentation

void statusbar_create ( dialog_cb_t  cb  ) 

Definition at line 233 of file statusbar.c.

References add_system_status_items(), dialog_cb, g_icon_left_disabled, g_icon_left_enabled, g_icon_right_disabled, g_icon_right_enabled, g_leftbutton, g_menu_button, g_pagecounter, g_right_spacer, g_rightbutton, g_statusbar_window, LOGPRINTF, on_leftbutton_press(), on_popup_button_press(), on_rightbutton_press(), on_size_allocate(), PATH_IMG, statusbar, STATUSBAR_HEIGHT, statusbar_set_text(), TOOLBAR_MARGIN_LEFT, and TOOLBAR_MARGIN_RIGHT.

Referenced by main().

00234 {
00235     LOGPRINTF("entry");
00236     dialog_cb = cb;
00237     
00238     GdkColor color;
00239     gdk_color_parse ("#aaaaaa", &color);
00240     
00241     // window 
00242     //   |
00243     GtkWidget *widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
00244     gtk_widget_set_name(widget, "irex-statusbar");
00245     GtkWindow *window = GTK_WINDOW(widget);
00246     g_statusbar_window = window;
00247 
00248     // use hint DOCK so it is hidden for fullscreen windows
00249     gtk_window_set_type_hint(window, GDK_WINDOW_TYPE_HINT_DOCK);
00250     gtk_window_set_decorated(window, FALSE);
00251     gtk_window_set_accept_focus(window, FALSE);
00252     gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &color);
00253 
00254     // resize and move to dock at the botton of the screen
00255     gtk_window_set_default_size(window, -1, STATUSBAR_HEIGHT);
00256     int bar_width  = 0;
00257     int bar_height = 0;
00258     gtk_window_get_size(window, &bar_width, &bar_height);
00259     gtk_widget_set_size_request(widget, bar_width, bar_height);
00260     gtk_window_resize(window, bar_width, bar_height);   
00261     gtk_window_move(window, 0, gdk_screen_height());
00262     
00263     gtk_window_set_resizable(window, FALSE);
00264     gtk_widget_show(widget);
00265 
00266     //   |
00267     //   +-- alignment
00268     //         |
00269     GtkWidget *alignment = gtk_alignment_new(0, 0.0, 1.0, 1.0); 
00270     gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 5, 
00271                               TOOLBAR_MARGIN_LEFT, TOOLBAR_MARGIN_RIGHT);
00272     gtk_container_add(GTK_CONTAINER(window), alignment);    
00273     gtk_widget_show(alignment);
00274 
00275     //         |
00276     //         +-- gtktoolbar
00277     //               |
00278     widget = gtk_toolbar_new();
00279     gtk_toolbar_set_orientation(GTK_TOOLBAR(widget), GTK_ORIENTATION_HORIZONTAL);
00280     
00281     gtk_toolbar_set_tooltips(GTK_TOOLBAR(widget), FALSE);
00282     gtk_toolbar_set_show_arrow(GTK_TOOLBAR(widget), FALSE);
00283     gtk_toolbar_set_style(GTK_TOOLBAR(widget), GTK_TOOLBAR_ICONS);
00284     gtk_container_add(GTK_CONTAINER(alignment), widget);
00285     gtk_widget_show(widget);
00286     statusbar = widget;    
00287 
00288     // Add menu button
00289     //               |
00290     //               +-- toolitem 
00291     //               |     |
00292     widget = (GtkWidget *) gtk_tool_item_new();
00293     
00294     //               |     |
00295     //               |     +-- eventbox
00296     //               |
00297     GtkWidget *eventbox = (GtkWidget *) gtk_event_box_new();
00298     gtk_widget_modify_fg (eventbox, GTK_STATE_NORMAL, &color);
00299     gtk_container_add(GTK_CONTAINER(widget), eventbox);
00300     
00301     //               |           |  
00302     //               |           +-- icon
00303     //               |
00304     GtkWidget *icon = gtk_image_new_from_file(PATH_IMG"statusbar_menu_button.png");
00305     gtk_container_add(GTK_CONTAINER(eventbox), icon);
00306     gtk_toolbar_insert(GTK_TOOLBAR(statusbar), GTK_TOOL_ITEM(widget), -1);
00307     g_signal_connect(G_OBJECT(eventbox), "button-release-event", G_CALLBACK(on_popup_button_press), NULL);
00308     gtk_widget_show(icon);
00309     gtk_widget_show(widget);
00310     gtk_widget_show(eventbox);
00311     
00312     //               |
00313     //               +-- toolitem
00314     //               |     |
00315     //               |     +-- button with label
00316     //               |
00317     widget = (GtkWidget *) gtk_tool_item_new();
00318     GtkWidget *button = gtk_button_new_with_label("");
00319     gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
00320     gtk_container_add(GTK_CONTAINER(widget), button);
00321     gtk_toolbar_insert(GTK_TOOLBAR(statusbar), GTK_TOOL_ITEM(widget), -1);
00322     g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_popup_button_press), NULL);
00323     gtk_widget_show(button);
00324     gtk_widget_show(widget);
00325 
00326     g_menu_button = button;
00327 
00328 #if MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00329     widget = (GtkWidget*) gtk_separator_tool_item_new();
00330     gtk_separator_tool_item_set_draw(GTK_SEPARATOR_TOOL_ITEM(widget), FALSE);
00331     gtk_tool_item_set_expand(GTK_TOOL_ITEM(widget), FALSE); 
00332     gtk_toolbar_insert(GTK_TOOLBAR(statusbar), GTK_TOOL_ITEM(widget), -1);
00333     gtk_widget_set_size_request(widget, MENUBUTTON_MARGIN, -1);
00334     gtk_widget_show(widget);
00335 
00336     int i;
00337     for (i=0; i<MENUSTORE_NUM_TOOLS; i++)
00338     {
00339         add_toolbar_item(i);
00340     }
00341 #endif
00342 
00343     // Add left separator
00344     //               |
00345     //               +-- separator
00346     //               |
00347     widget = (GtkWidget*) gtk_separator_tool_item_new();
00348     gtk_separator_tool_item_set_draw(GTK_SEPARATOR_TOOL_ITEM(widget), FALSE);
00349     gtk_tool_item_set_expand(GTK_TOOL_ITEM(widget), TRUE); 
00350     gtk_toolbar_insert(GTK_TOOLBAR(statusbar), GTK_TOOL_ITEM(widget), -1);
00351     gtk_widget_show(widget);
00352 
00353     // Add left button
00354     //               |
00355     //               +-- tool button
00356     //               |
00357     g_icon_left_enabled = gtk_image_new_from_file(PATH_IMG"statusbar_arrow_left.png");
00358     g_object_ref(G_OBJECT(g_icon_left_enabled));
00359     gtk_widget_show(g_icon_left_enabled);
00360 
00361     g_icon_left_disabled = gtk_image_new_from_file(PATH_IMG"statusbar_arrow_left_disabled.png");
00362     g_object_ref(G_OBJECT(g_icon_left_disabled));
00363     gtk_widget_show(g_icon_left_disabled);
00364 
00365     GtkToolItem *leftbutton = gtk_tool_button_new(g_icon_left_disabled, "");
00366     gtk_widget_show(GTK_WIDGET(leftbutton));
00367     gtk_toolbar_insert(GTK_TOOLBAR(statusbar), leftbutton, -1);
00368     g_signal_connect(G_OBJECT(leftbutton), "clicked", G_CALLBACK(on_leftbutton_press), NULL);
00369     g_leftbutton = GTK_WIDGET(leftbutton);
00370 
00371     // Add page counter
00372     //               |
00373     //               +-- toolitem
00374     //               |     |  
00375     //               |     +-- label
00376     //               |
00377     widget = (GtkWidget *) gtk_tool_item_new();
00378     GtkWidget* pageLabel = gtk_label_new("");
00379     gtk_widget_set_name(pageLabel, "irex-page-label");
00380     gtk_widget_show(pageLabel);
00381     gtk_container_add(GTK_CONTAINER(widget), pageLabel);
00382     gtk_toolbar_insert(GTK_TOOLBAR(statusbar), GTK_TOOL_ITEM(widget), -1);
00383     gtk_widget_show(widget);
00384     g_pagecounter = pageLabel;
00385 
00386     // Add right button
00387     //               |
00388     //               +-- tool button
00389     //               |
00390     g_icon_right_enabled = gtk_image_new_from_file(PATH_IMG"statusbar_arrow_right.png");
00391     g_object_ref(G_OBJECT(g_icon_right_enabled));
00392     gtk_widget_show(g_icon_right_enabled);
00393     
00394     g_icon_right_disabled = gtk_image_new_from_file(PATH_IMG"statusbar_arrow_right_disabled.png");
00395     g_object_ref(G_OBJECT(g_icon_right_disabled));
00396     gtk_widget_show(g_icon_right_disabled);
00397 
00398     GtkToolItem *rightbutton = gtk_tool_button_new(g_icon_right_disabled, "");
00399     gtk_widget_show(GTK_WIDGET(rightbutton));
00400     gtk_toolbar_insert(GTK_TOOLBAR(statusbar), rightbutton, -1);
00401     g_signal_connect(G_OBJECT(rightbutton), "clicked", G_CALLBACK(on_rightbutton_press), NULL);
00402     g_rightbutton = GTK_WIDGET(rightbutton);
00403 
00404     // Fill out with blank space
00405     //               |
00406     //               +-- separator
00407     //
00408     widget = (GtkWidget*) gtk_separator_tool_item_new();
00409     gtk_separator_tool_item_set_draw(GTK_SEPARATOR_TOOL_ITEM(widget), FALSE);
00410     gtk_tool_item_set_expand(GTK_TOOL_ITEM(widget), FALSE); 
00411     gtk_toolbar_insert(GTK_TOOLBAR(statusbar), GTK_TOOL_ITEM(widget), -1);
00412     gtk_widget_show(widget);
00413     g_right_spacer = widget;
00414     g_signal_connect(statusbar, "size-allocate", G_CALLBACK(on_size_allocate), NULL);
00415 
00416     // Add system icons here
00417     add_system_status_items();
00418 
00419     // Set defaults
00420     statusbar_set_text();
00421 }

Here is the call graph for this function:

Here is the caller graph for this function:

void statusbar_hide_pagecounter (  ) 

Definition at line 879 of file statusbar.c.

References g_leftbutton, g_pagecounter, g_pagecounter_shown, g_rightbutton, and LOGPRINTF.

Referenced by show_menu_cb(), and statusbar_update_pagecounter().

00880 {
00881     LOGPRINTF("entry");
00882 
00883     gtk_widget_hide(g_pagecounter);
00884     gtk_widget_hide(g_leftbutton);
00885     gtk_widget_hide(g_rightbutton);
00886     g_pagecounter_shown = FALSE;
00887 }

Here is the caller graph for this function:

gboolean statusbar_item_set_state ( const char *  item,
const char *  statename 
)

Set the state of a status bar item.

---------------------------------------------------------------------------

Name : statusbar_item_set_state

Parameters:
item Item name
statename Name of new state
Returns:
Returns TRUE on success, FALSE otherwise

--------------------------------------------------------------------------

Definition at line 589 of file statusbar.c.

References statusEntry_t::eventbox, get_status_item(), get_status_item_state(), stateEntry_t::image, statusEntry_t::image, statusEntry_t::state, TRACE, and WARNPRINTF.

Referenced by set_statusitem_state_cb(), statusbar_update_battery_state(), and statusbar_update_signal_strength().

00590 {
00591     TRACE("%s() item=%s  statename=%s\n", __func__, item, statename);
00592 
00593     statusEntry_t *pStatusEntry = get_status_item(item);
00594     if (pStatusEntry == NULL)
00595     {
00596         WARNPRINTF("item `%s` not defined", item);
00597         return FALSE;
00598     }
00599  
00600     gint state_index;
00601     stateEntry_t  *pStateEntry = get_status_item_state(pStatusEntry, statename, &state_index);
00602     if (pStateEntry == NULL)
00603     {
00604         WARNPRINTF("state `%s.%s` not defined", item, statename);
00605         return FALSE;
00606     }
00607 
00608     // remove old icon
00609     gtk_container_remove(GTK_CONTAINER(pStatusEntry->eventbox), pStatusEntry->image);
00610     
00611     // set new icon
00612     pStatusEntry->state = state_index;
00613     pStatusEntry->image = pStateEntry->image;
00614     gtk_widget_show(pStatusEntry->image);
00615     gtk_container_add(GTK_CONTAINER(pStatusEntry->eventbox), pStatusEntry->image);
00616     
00617     return TRUE;    
00618 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean statusbar_item_show ( const char *  item,
const char *  mode 
)

Show a status bar item.

---------------------------------------------------------------------------

Name : statusbar_item_show

Parameters:
item Item name
mode New mode (show/hide)
Returns:
Returns TRUE on success, FALSE otherwise

--------------------------------------------------------------------------

Definition at line 621 of file statusbar.c.

References ERRORPRINTF, get_status_item(), statusEntry_t::item, TRACE, and WARNPRINTF.

Referenced by set_statusitem_show_cb().

00622 {
00623     TRACE("%s() item=%s  mode=%s\n", __func__, item, mode);
00624 
00625     statusEntry_t *pStatusEntry = get_status_item(item);
00626     if (pStatusEntry == NULL)
00627     {
00628         WARNPRINTF("item `%s` not defined", item);
00629         return FALSE;
00630     }
00631     
00632     if (g_ascii_strcasecmp(mode, "show") == 0)
00633     {
00634         gtk_widget_show(pStatusEntry->item);
00635     }
00636     else if (g_ascii_strcasecmp(mode, "hide") == 0)
00637     {
00638         gtk_widget_hide(pStatusEntry->item);
00639     }
00640     else
00641     {
00642         ERRORPRINTF("mode unknown: %s", mode);
00643         return FALSE;
00644     }
00645     
00646     return TRUE;
00647 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean statusbar_remove_item ( const char *  item  ) 

Remove and free a status bar item.

---------------------------------------------------------------------------

Name : statusbar_remove_item

Parameters:
item Item name
Returns:
Returns TRUE on success, FALSE otherwise

--------------------------------------------------------------------------

Definition at line 650 of file statusbar.c.

References get_status_item(), statusEntry_t::item, statusEntry_t::itemname, statusEntry_t::stateArray, TRACE, and WARNPRINTF.

00651 {
00652     TRACE("%s() item=%s\n", __func__, item);
00653     
00654     statusEntry_t *pStatusEntry = get_status_item(item);
00655     if (pStatusEntry == NULL)
00656     {
00657         WARNPRINTF("item `%s` not defined", item);
00658         return FALSE;
00659     }
00660 
00661     // free state names
00662     guint i = 0;
00663     for (i=0; i < pStatusEntry->stateArray->len; i++)
00664     {
00665         g_free(g_array_index(pStatusEntry->stateArray, stateEntry_t*, i)->statename);
00666     }
00667     
00668     // free tool entry
00669     // icon will be freed automatically as it is toolitem container
00670     gtk_widget_destroy(pStatusEntry->item);
00671     g_array_free(pStatusEntry->stateArray, TRUE);
00672     g_free(pStatusEntry->itemname);
00673     
00674     return TRUE;
00675 }

Here is the call graph for this function:

void statusbar_set_text ( void   ) 

Definition at line 890 of file statusbar.c.

References fix_center_pagebar(), g_curpage, g_menu_button, g_numpages, statusbar, and update_pagecounter().

Referenced by cb_sys_changed_locale(), and statusbar_create().

00891 {
00892     update_pagecounter(g_curpage, g_numpages);
00893     gtk_button_set_label(GTK_BUTTON(g_menu_button), _("Menu"));
00894     
00895     GtkRequisition requisition;
00896     gtk_widget_size_request(statusbar, &requisition);
00897     fix_center_pagebar(requisition.width);
00898 }

Here is the call graph for this function:

Here is the caller graph for this function:

void statusbar_update_battery_state ( gint  level,
const char *  state 
)

Update battery state icon.

---------------------------------------------------------------------------

Name : statusbar_update_battery_state

Parameters:
level Battery level in percent
state Charge state string
Returns:
--

--------------------------------------------------------------------------

Definition at line 678 of file statusbar.c.

References ERRORPRINTF, and statusbar_item_set_state().

Referenced by cb_sys_battery_state(), main(), and on_check_low_battery().

00679 {
00680     g_return_if_fail(state!=NULL);
00681 
00682     gchar *item  = "statusbar_battery";
00683 
00684 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800S || MACHINE_IS_DR800SW
00685     const gint four_bars_limit  = 88;
00686     const gint three_bars_limit = 63;
00687     const gint two_bars_limit   = 38;
00688     const gint one_bar_limit    = 13;
00689 #elif MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00690     const gint four_bars_limit  = 75;
00691     const gint three_bars_limit = 50;
00692     const gint two_bars_limit   = 25;
00693     const gint one_bar_limit    = 10;
00694 #else
00695 #error "Unhandled machine type"
00696 #endif
00697     
00698     static const gchar *last_icon = NULL;
00699     const gchar *icon = NULL;
00700     
00701     if (strcmp(state, "charging") == 0)
00702     {
00703         // charging, show level
00704         if (level >= four_bars_limit)
00705         {
00706             icon = "100_charging";
00707         }
00708         else if (level >= three_bars_limit)
00709         {
00710             icon = "75_charging";
00711         }
00712         else if (level >= two_bars_limit)
00713         {
00714             icon = "50_charging";
00715         }
00716         else if (level >= one_bar_limit)
00717         {
00718             icon = "25_charging";
00719         }
00720         else 
00721         {
00722             icon = "charging";
00723         }
00724     }
00725     else if (strcmp(state, "discharging") == 0)
00726     {
00727         // discharging, show level
00728         if (level > four_bars_limit)
00729         {
00730             icon = "100";
00731         }
00732         else if (level > three_bars_limit)
00733         {
00734             icon = "75";
00735         }
00736         else if (level > two_bars_limit)
00737         {
00738             icon = "50";
00739         }
00740         else if (level > one_bar_limit)
00741         {
00742             icon = "25";
00743         }
00744         else
00745         {
00746             icon = "normal";
00747         }
00748     }
00749     else if (strcmp(state, "low") == 0)
00750     {
00751         icon = "verylow";
00752     }
00753     else if (strcmp(state, "full") == 0)
00754     {
00755         icon = "100";
00756     }
00757     else
00758     {
00759         ERRORPRINTF("unhandled state [%s] level [%d]", state, level);
00760     }
00761         
00762     if (icon && (icon != last_icon))
00763     {
00764         // update icon to reflect new state
00765         statusbar_item_set_state(item, icon);
00766         last_icon = icon;
00767     }
00768 }

Here is the call graph for this function:

Here is the caller graph for this function:

void statusbar_update_pagecounter ( gint  curpage,
gint  numpages,
gboolean  boundary_check 
)

Definition at line 821 of file statusbar.c.

References enable_left(), enable_right(), g_curpage, g_has_left, g_has_right, g_leftbutton, g_numpages, g_pagecounter, g_pagecounter_shown, g_rightbutton, LOGPRINTF, statusbar_hide_pagecounter(), and update_pagecounter().

Referenced by update_page_counter_cb().

00822 {
00823     LOGPRINTF("entry curpage [%d] numpages [%d] boundary_check [%d] has_left [%d] has_right [%d] g_pagecounter_shown [%d]", curpage, numpages, boundary_check, g_has_left, g_has_right, g_pagecounter_shown);
00824 
00825     if ((curpage == 0) && (numpages == 0))
00826     {
00827         if (g_pagecounter_shown)
00828         {
00829             statusbar_hide_pagecounter();
00830         }
00831     }
00832     else if ((curpage == -1) && (numpages == -1))   // magic value for Counting pages...
00833     {
00834         update_pagecounter(curpage, numpages);
00835         gtk_widget_show(g_pagecounter);
00836 
00837         // Ignore parameter boundary_check.
00838         // Enable previous-/next-page arrows.
00839         enable_left(TRUE);
00840         enable_right(TRUE);
00841         gtk_widget_show(g_leftbutton);
00842         gtk_widget_show(g_rightbutton);
00843     }
00844     else
00845     {
00846         update_pagecounter(curpage, numpages);
00847         
00848         if (curpage == 1 && boundary_check)
00849         {
00850             enable_left(FALSE);
00851         } else {
00852             enable_left(TRUE);
00853         }
00854         
00855         if (curpage == numpages && boundary_check)
00856         {
00857             enable_right(FALSE);
00858         } else {
00859             enable_right(TRUE);
00860         }
00861 
00862         if (!g_pagecounter_shown)
00863         {
00864             gtk_widget_show(g_pagecounter);
00865             gtk_widget_show(g_leftbutton);
00866             gtk_widget_show(g_rightbutton);
00867             g_pagecounter_shown = TRUE;
00868         }
00869     }
00870         
00871     // save for possible update on locale change
00872     g_curpage = curpage;
00873     g_numpages = numpages;
00874     
00875     LOGPRINTF("leave has_left [%d] has_right [%d] g_pagecounter_shown [%d]", g_has_left, g_has_right, g_pagecounter_shown);
00876 }

Here is the call graph for this function:

Here is the caller graph for this function:

void statusbar_update_signal_strength ( const char *  medium,
gint  strength 
)

Definition at line 771 of file statusbar.c.

References statusbar_item_set_state(), and WARNPRINTF.

Referenced by cb_sys_signal_strength().

00772 {
00773     gchar *item = NULL;
00774     const gchar *icon = NULL;
00775     if (strcmp(medium,"3g")==0) {
00776         item  = "statusbar_3g"; 
00777     } else {
00778         WARNPRINTF("Unhandled signal strength update on medium %s", medium);
00779         return;
00780     }
00781 
00782     if (strength>=90)
00783         icon = "connected_5b";
00784     else if (strength>=70)
00785         icon = "connected_4b";
00786     else if (strength>=50)
00787         icon = "connected_3b";
00788     else if (strength>=30)
00789         icon = "connected_2b";
00790     else if (strength>=10)
00791         icon = "connected_1b";
00792     else
00793         icon = "connected";
00794         
00795     statusbar_item_set_state(item, icon);
00796 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

G_BEGIN_DECLS GtkWindow* g_statusbar_window

File Name : statusbar.h

Description: The statusbar item functions Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Definition at line 44 of file statusbar.h.

Referenced by dialog_message_confirm(), dialog_message_info(), and statusbar_create().

Generated by  doxygen 1.6.2-20100208