#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sched.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <libergtk/ergtk.h>
#include "i18n.h"
#include "log.h"
#include "ipc.h"
#include "settings.h"
#include "settings_utils.h"
#include "settings_style.h"
#include "sd_capacity.h"
Go to the source code of this file.
Functions | |
static GtkWidget * | create_sdcapacity_widgets (GtkBox *parent) |
static void | update_sd_widgets () |
static void | init_widgets_with_settings (void) |
static void | on_listview_row_activated (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) |
static void | on_listview_navigate_cursor (erGtkListView *er_listview, erGtkListViewKeyPress keycode, gpointer user_data) |
static gboolean | on_focus_in (GtkWidget *widget, gpointer data) |
static gboolean | on_focus_out (GtkWidget *widget, gpointer data) |
GtkWidget * | create_sdcapacity_window (GtkWidget *parent) |
void | load_sdcapacity_settings () |
void | save_sdcapacity_settings () |
void | sd_card_mounted (gboolean is_mounted) |
Variables | |
static gboolean | g_sd_card_mounted = FALSE |
static GtkWidget * | g_sdcapacity_window = NULL |
static GtkWidget * | g_capacity_bar = NULL |
static GtkWidget * | g_used_space_label = NULL |
static GtkWidget * | g_free_space_label = NULL |
static volatile gboolean | g_is_updating = FALSE |
static GtkWidget * create_sdcapacity_widgets | ( | GtkBox * | parent | ) | [static] |
Definition at line 237 of file sd_capacity.c.
References g_capacity_bar, g_free_space_label, g_used_space_label, and label.
Referenced by create_sdcapacity_window().
00238 { 00239 // Top level vbox. 00240 GtkWidget* top_level_vbox = gtk_vbox_new(FALSE, 3); 00241 gtk_box_pack_start(parent, top_level_vbox, FALSE, FALSE, 0); 00242 00243 // The label "Card Storage Capacity". 00244 GtkWidget* label = gtk_label_new(_("SD Card Memory")); 00245 gtk_widget_set_name(label, "irex-normal-text"); 00246 gtk_widget_set_size_request(label, -1, -1); 00247 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); 00248 gtk_box_pack_start(GTK_BOX(top_level_vbox), label, FALSE, FALSE, 6); 00249 00250 // The GtkProgressBar. 00251 g_capacity_bar = gtk_progress_bar_new(); 00252 // gtk_widget_set_name(g_capacity_bar, "capacity"); 00253 gtk_box_pack_start(GTK_BOX(top_level_vbox), g_capacity_bar, FALSE, FALSE, 6); 00254 00255 // The label "Used Space:" 00256 g_used_space_label = gtk_label_new(NULL); 00257 gtk_widget_set_name(g_used_space_label, "irex-normal-text"); 00258 gtk_widget_set_size_request(g_used_space_label, -1, -1); 00259 gtk_misc_set_alignment(GTK_MISC(g_used_space_label), 0.0, 0.0); 00260 gtk_box_pack_start(GTK_BOX(top_level_vbox), g_used_space_label, FALSE, FALSE, 6); 00261 00262 // The label "Free Space:" 00263 g_free_space_label = gtk_label_new(NULL); 00264 gtk_widget_set_name(g_free_space_label, "irex-normal-text"); 00265 gtk_widget_set_size_request(g_free_space_label, -1, -1); 00266 gtk_misc_set_alignment(GTK_MISC(g_free_space_label), 0.0, 0.0); 00267 gtk_box_pack_start(GTK_BOX(top_level_vbox), g_free_space_label, FALSE, FALSE, 6); 00268 00269 00270 return top_level_vbox; 00271 }
GtkWidget* create_sdcapacity_window | ( | GtkWidget * | parent | ) |
Copyright (C) 2008 iRex Technologies B.V. All rights reserved.
Definition at line 104 of file sd_capacity.c.
References create_sdcapacity_widgets(), create_settingsview(), create_title(), g_sdcapacity_window, init_widgets_with_settings(), on_focus_in(), on_focus_out(), on_listview_navigate_cursor(), on_listview_row_activated(), SMALL_SPACING, WINDOW_BORDER_PADDING, WINDOW_BOTTOM_PADDING, WINDOW_H_PADDING, and WINDOW_TOP_ALT_PADDING.
Referenced by create_concrete_win().
00105 { 00106 // create top window 00107 GtkWidget* top_window = parent; 00108 gtk_window_maximize(GTK_WINDOW(top_window)); 00109 gtk_window_set_resizable(GTK_WINDOW(top_window), FALSE); 00110 gtk_container_set_border_width(GTK_CONTAINER(top_window),WINDOW_BORDER_PADDING ); 00111 gtk_window_set_modal(GTK_WINDOW(top_window), TRUE); 00112 00113 // top level vbox (vboxtop) 00114 GtkWidget* vboxtop = gtk_vbox_new(FALSE, 0); 00115 gtk_container_add(GTK_CONTAINER(top_window), vboxtop); 00116 00117 // add header container the title and subtitle of this settings page 00118 create_title(GTK_VBOX(vboxtop), _("Settings"), _("SD Card Information")); 00119 00120 // add the back/exit bar below the title 00121 GtkWidget* view = create_settingsview(); 00122 gtk_box_pack_start(GTK_BOX(vboxtop), view, FALSE, FALSE,0 ); 00123 g_signal_connect(view, "row-activated", G_CALLBACK(on_listview_row_activated), NULL ) ; 00124 g_signal_connect(view, "navigate-cursor", G_CALLBACK(on_listview_navigate_cursor), NULL ) ; 00125 g_signal_connect(view, "focus-in-event", G_CALLBACK(on_focus_in), NULL ); 00126 g_signal_connect(view, "focus-out-event", G_CALLBACK(on_focus_out), NULL ); 00127 00128 // add an alignment below the exit bar 00129 GtkWidget* alignment = gtk_alignment_new(0, 0, 1.0, 0.0); 00130 gtk_container_add(GTK_CONTAINER(vboxtop), alignment); 00131 00132 // introdude a frame in the alignment 00133 GtkWidget* frame = gtk_frame_new(NULL); 00134 gtk_widget_set_name(frame, "irex-margins-frame"); 00135 gtk_container_add(GTK_CONTAINER(alignment), frame); 00136 gtk_container_set_border_width(GTK_CONTAINER(frame), 3); 00137 00138 // alignment in frame 00139 GtkWidget* alignment2 = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); 00140 gtk_container_add(GTK_CONTAINER(frame), alignment2); 00141 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment2), 00142 WINDOW_TOP_ALT_PADDING, 00143 WINDOW_BOTTOM_PADDING, 00144 WINDOW_H_PADDING, 00145 WINDOW_H_PADDING); 00146 00147 // vbox in alignment2 00148 GtkWidget* innervbox = gtk_vbox_new(FALSE, SMALL_SPACING); 00149 gtk_container_add(GTK_CONTAINER(alignment2), innervbox); 00150 00151 // The margin settings section. 00152 create_sdcapacity_widgets(GTK_BOX(innervbox)); 00153 00154 // Update widget with current settings. 00155 init_widgets_with_settings(); 00156 00157 gtk_widget_grab_focus(view); 00158 00159 gtk_widget_show_all(top_window); 00160 00161 g_sdcapacity_window = top_window; 00162 00163 return top_window; 00164 }
static void init_widgets_with_settings | ( | void | ) | [static] |
Definition at line 273 of file sd_capacity.c.
References g_is_updating, and update_sd_widgets().
Referenced by create_sdcapacity_window().
00274 { 00275 00276 if ( g_is_updating == FALSE ) 00277 { 00278 g_is_updating = TRUE; 00279 update_sd_widgets(); 00280 g_is_updating = FALSE; 00281 } 00282 00283 }
void load_sdcapacity_settings | ( | ) |
Definition at line 167 of file sd_capacity.c.
static gboolean on_focus_in | ( | GtkWidget * | widget, | |
gpointer | data | |||
) | [static] |
Definition at line 285 of file sd_capacity.c.
References ERGTK_LIST_VIEW, and ergtk_list_view_set_cursor().
Referenced by create_sdcapacity_window().
00286 { 00287 g_assert(widget != NULL ) ; 00288 ergtk_list_view_set_cursor( ERGTK_LIST_VIEW(widget), 0); // row = 0; 00289 return FALSE; 00290 }
static gboolean on_focus_out | ( | GtkWidget * | widget, | |
gpointer | data | |||
) | [static] |
Definition at line 292 of file sd_capacity.c.
Referenced by create_sdcapacity_window().
00293 { 00294 g_assert(widget != NULL ) ; 00295 GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) widget); 00296 g_assert( my_selection != NULL ) ; 00297 gtk_tree_selection_unselect_all(my_selection); 00298 return FALSE; 00299 }
static void on_listview_navigate_cursor | ( | erGtkListView * | er_listview, | |
erGtkListViewKeyPress | keycode, | |||
gpointer | user_data | |||
) | [static] |
Definition at line 214 of file sd_capacity.c.
References ERGTK_LIST_VIEW_PRESS_LONG_DOWN, ERGTK_LIST_VIEW_PRESS_SHORT_DOWN, and LOGPRINTF.
Referenced by create_sdcapacity_window().
00217 { 00218 GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) er_listview); 00219 g_assert( my_selection != NULL ) ; 00220 00221 // determine new cursor position 00222 switch (keycode) 00223 { 00224 case ERGTK_LIST_VIEW_PRESS_SHORT_DOWN: 00225 case ERGTK_LIST_VIEW_PRESS_LONG_DOWN: 00226 //gtk_widget_grab_focus(GTK_WIDGET(g_calibrate_button)); 00227 gtk_tree_selection_unselect_all(my_selection); 00228 break; 00229 default: 00230 LOGPRINTF("illegal erGtkListViewKeyPress [%d]", keycode); 00231 ; // ignore 00232 break; 00233 } 00234 00235 }
static void on_listview_row_activated | ( | GtkTreeView * | view, | |
GtkTreePath * | path, | |||
GtkTreeViewColumn * | column, | |||
gpointer | user_data | |||
) | [static] |
Definition at line 205 of file sd_capacity.c.
References main_quit().
Referenced by create_sdcapacity_window().
00209 { 00210 main_quit(); 00211 return; 00212 }
void save_sdcapacity_settings | ( | ) |
Definition at line 173 of file sd_capacity.c.
void sd_card_mounted | ( | gboolean | is_mounted | ) |
Definition at line 179 of file sd_capacity.c.
References g_is_updating, g_sd_card_mounted, g_sdcapacity_window, LOGPRINTF, and update_sd_widgets().
Referenced by on_mounted(), and on_unmounted().
00180 { 00181 LOGPRINTF("entry: is_mounted [%d]", is_mounted); 00182 00183 while (g_is_updating == TRUE) { 00184 sched_yield(); 00185 } 00186 00187 g_is_updating = TRUE; 00188 00189 // remember card state 00190 g_sd_card_mounted = is_mounted; 00191 00192 // show free space 00193 00194 if (g_sdcapacity_window != NULL) 00195 { 00196 update_sd_widgets(); 00197 } 00198 g_is_updating = FALSE; 00199 }
static void update_sd_widgets | ( | ) | [static] |
Definition at line 301 of file sd_capacity.c.
References g_capacity_bar, g_free_space_label, g_sd_card_mounted, g_used_space_label, LOGPRINTF, SD_CARD_MOUNTPOINT, and usage().
Referenced by init_widgets_with_settings(), and sd_card_mounted().
00302 { 00303 #ifndef WIN32 00304 int rc; 00305 struct statfs stat; 00306 long used_blocks; 00307 gdouble usage; 00308 gchar* message = NULL ; 00309 00310 LOGPRINTF("entry"); 00311 00312 rc = statfs(SD_CARD_MOUNTPOINT, &stat); 00313 00314 if ( rc == 0 && g_sd_card_mounted ) 00315 { 00316 // update filesystem usage 00317 used_blocks = stat.f_blocks - stat.f_bfree; 00318 usage = (gdouble)used_blocks / (gdouble)stat.f_blocks; 00319 /* TRANSLATORS: '%ld' is the percentage of remaining free space on the SD card 00320 * Example: "95% remaining" 00321 * Note: '%%' creates literally a %-sign 00322 */ 00323 gchar* progress_text = g_strdup_printf(_("%ld%% remaining"), (long)(100-(100*usage))); 00324 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(g_capacity_bar), usage); 00325 gtk_widget_show(g_capacity_bar); 00326 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(g_capacity_bar), progress_text); 00327 g_free(progress_text); 00328 00329 /* TRANSLATORS: '%ld' is the total number of Megabytes 00330 * Example: "Total: 1024 MB" 00331 */ 00332 message = g_strdup_printf(_("Total: %ld MB"), stat.f_blocks / (1048576 / stat.f_bsize)); 00333 gtk_label_set_label(GTK_LABEL(g_used_space_label), message); 00334 gtk_widget_show(g_used_space_label); 00335 g_free(message); 00336 00337 /* TRANSLATORS: '%ld' is the number of Megabytes available 00338 * Example: "Available: 560 MB" 00339 */ 00340 message = g_strdup_printf(_("Available: %ld MB"), stat.f_bfree / (1048576 / stat.f_bsize)); 00341 gtk_label_set_label(GTK_LABEL(g_free_space_label), message); 00342 gtk_widget_show(g_free_space_label); 00343 g_free(message); 00344 } 00345 else 00346 { 00347 /* TRANSLATORS: N/A stands for not applicable 00348 */ 00349 gtk_label_set_label(GTK_LABEL(g_used_space_label), _("Total: N/A")); 00350 gtk_widget_show(g_capacity_bar); 00351 gtk_label_set_label(GTK_LABEL(g_free_space_label), _("Available: N/A")); 00352 gtk_widget_show(g_free_space_label); 00353 00354 gchar* progress_text = g_strdup_printf(_("Unknown remaining")); 00355 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(g_capacity_bar), 0.0); 00356 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(g_capacity_bar), progress_text); 00357 g_free(progress_text); 00358 00359 gtk_widget_show(g_capacity_bar); 00360 } 00361 00362 #endif 00363 }
GtkWidget* g_capacity_bar = NULL [static] |
Definition at line 74 of file sd_capacity.c.
Referenced by create_sdcapacity_widgets(), and update_sd_widgets().
GtkWidget* g_free_space_label = NULL [static] |
Definition at line 76 of file sd_capacity.c.
Referenced by create_sdcapacity_widgets(), and update_sd_widgets().
volatile gboolean g_is_updating = FALSE [static] |
Definition at line 78 of file sd_capacity.c.
Referenced by init_widgets_with_settings(), and sd_card_mounted().
gboolean g_sd_card_mounted = FALSE [static] |
Copyright (C) 2008 iRex Technologies B.V. All rights reserved.
Definition at line 71 of file sd_capacity.c.
Referenced by sd_card_mounted(), and update_sd_widgets().
GtkWidget* g_sdcapacity_window = NULL [static] |
Definition at line 73 of file sd_capacity.c.
Referenced by create_sdcapacity_window(), and sd_card_mounted().
GtkWidget* g_used_space_label = NULL [static] |
Definition at line 75 of file sd_capacity.c.
Referenced by create_sdcapacity_widgets(), and update_sd_widgets().