reset.c File Reference

#include "config.h"
#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 <sys/time.h>
#include <utime.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <libergtk/ergtk.h>
#include <liberutilstime/time_utils.h>
#include "i18n.h"
#include "log.h"
#include "ipc.h"
#include "settings.h"
#include "settings_utils.h"
#include "settings_style.h"
#include "reset.h"
Include dependency graph for reset.c:

Go to the source code of this file.

Defines

#define DEVICE_VOLUME_NAME   "IREX DR1000"
#define COOKIES_FILE   "/home/root/cookies.txt"
#define USERCAL_FILE   "/home/root/.pointercal"
#define ORIGCAL_FILE   "/etc/pointercal"

Functions

static GtkWidget * create_reset_widgets (GtkBox *parent)
static GtkWidget * create_format_widgets (GtkBox *parent)
static gboolean on_reset_button_clicked (GtkWidget *widget, gpointer data)
static gboolean on_format_button_clicked (GtkWidget *widget, gpointer data)
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)
static void on_umount_done ()
static void on_mount_done ()
void load_reset_settings ()
void save_reset_settings ()
GtkWidget * create_reset_window (GtkWidget *parent)
void reset_sdcard_mounted (gboolean is_mounted)
static gboolean on_format_sd (gpointer data)

Variables

static const char * SD_FORMAT_COMMAND = "mkfs.vfat -F 32 -n \"" DEVICE_VOLUME_NAME "\" " SD_CARD_DEVICE
static GtkWidget * g_reset_window = NULL
static GtkWidget * g_reset_button = NULL
static GtkWidget * g_format_button = NULL
static gboolean g_sd_format_ok = FALSE
static gboolean g_sd_card_mounted = FALSE
static void(* g_cb_post_mount )(void)
static void(* g_cb_post_umount )(void)

Define Documentation

#define COOKIES_FILE   "/home/root/cookies.txt"

Definition at line 85 of file reset.c.

#define DEVICE_VOLUME_NAME   "IREX DR1000"

Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Definition at line 80 of file reset.c.

#define ORIGCAL_FILE   "/etc/pointercal"

Definition at line 87 of file reset.c.

Referenced by on_reset_button_clicked().

#define USERCAL_FILE   "/home/root/.pointercal"

Definition at line 86 of file reset.c.

Referenced by on_reset_button_clicked().


Function Documentation

static GtkWidget * create_format_widgets ( GtkBox *  parent  )  [static]

Definition at line 338 of file reset.c.

References description_create(), g_format_button, ITEM_SPACING, on_format_button_clicked(), and subject_create().

Referenced by create_reset_window().

00339 {
00340     // Top level vbox.
00341     GtkWidget* top_level_vbox = gtk_vbox_new(FALSE, ITEM_SPACING);
00342     gtk_box_pack_start(parent, top_level_vbox, FALSE, FALSE, 0);
00343 
00344     // Subject
00345     GtkWidget* subject = subject_create();
00346     gtk_label_set_label(GTK_LABEL(subject),
00347         _("Format the Device"));
00348     gtk_box_pack_start(GTK_BOX(top_level_vbox), subject, FALSE, FALSE, 0);
00349 
00350     // Description
00351     GtkWidget* desc = description_create();
00352     gtk_label_set_label(GTK_LABEL(desc),
00353         _("Formatting the SD card means that all content stored on the card is permanently erased."));
00354     gtk_box_pack_start(GTK_BOX(top_level_vbox), desc, FALSE, FALSE, 0);
00355 
00356     // create button box
00357     GtkWidget* button_box = gtk_hbutton_box_new();
00358     gtk_box_pack_start(GTK_BOX(top_level_vbox), button_box, FALSE, FALSE, 9);
00359     gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_START);
00360     
00361     g_format_button = gtk_button_new_with_label( _("Format..."));
00362     gtk_box_pack_start(GTK_BOX(button_box), g_format_button, FALSE, FALSE, 0);
00363     
00364     // Add signal handler.
00365     g_signal_connect(G_OBJECT(g_format_button),
00366             "clicked",
00367             G_CALLBACK(on_format_button_clicked ),
00368             (gpointer) NULL );
00369 
00370     return top_level_vbox;
00371 }

Here is the call graph for this function:

Here is the caller graph for this function:

static GtkWidget * create_reset_widgets ( GtkBox *  parent  )  [static]

Definition at line 297 of file reset.c.

References description_create(), g_reset_button, ITEM_SPACING, on_reset_button_clicked(), and subject_create().

Referenced by create_reset_window().

00298 {
00299     // Top level vbox.
00300     GtkWidget* top_level_vbox = gtk_vbox_new(FALSE, ITEM_SPACING);
00301     gtk_box_pack_start(parent, top_level_vbox, FALSE, FALSE, 0);
00302 
00303     // Subject
00304     GtkWidget* subject = subject_create();
00305     gtk_label_set_label(GTK_LABEL(subject),
00306         _("Reset Device Settings"));
00307     gtk_box_pack_start(GTK_BOX(top_level_vbox), subject, FALSE, FALSE, 0);
00308     
00309     // Description
00310     GtkWidget* desc = description_create();
00311 #if MACHINE_IS_DR800S
00312     gtk_label_set_label(GTK_LABEL(desc),
00313         _("When you reset settings, you will restore the settings back to their factory defaults. "));
00314 #else 
00315     gtk_label_set_label(GTK_LABEL(desc),
00316         _("When you reset settings, you will restore the settings back to their factory defaults. "
00317                                         "This will also clear your MYIREX information."));
00318 #endif
00319     gtk_box_pack_start(GTK_BOX(top_level_vbox), desc, FALSE, FALSE, 0);
00320 
00321     // create button box
00322     GtkWidget* button_box = gtk_hbutton_box_new();
00323     gtk_box_pack_start(GTK_BOX(top_level_vbox), button_box, FALSE, FALSE, 9);
00324     gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_START);
00325     
00326     g_reset_button = gtk_button_new_with_label( _("Reset Settings..."));
00327     gtk_box_pack_start(GTK_BOX(button_box), g_reset_button, FALSE, FALSE, 0);
00328 
00329     // Add signal handler.
00330     g_signal_connect(G_OBJECT(g_reset_button),
00331             "clicked",
00332             G_CALLBACK(on_reset_button_clicked ),
00333             (gpointer) NULL );
00334 
00335     return top_level_vbox;
00336 }

Here is the call graph for this function:

Here is the caller graph for this function:

GtkWidget* create_reset_window ( GtkWidget *  parent  ) 

Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Definition at line 166 of file reset.c.

References create_format_widgets(), create_frame(), create_reset_widgets(), create_settingsview(), create_title(), g_reset_window, init_widgets_with_settings(), on_focus_in(), on_focus_out(), on_listview_navigate_cursor(), on_listview_row_activated(), and WINDOW_BORDER_PADDING.

Referenced by create_concrete_win().

00167 {
00168     // create top window
00169     GtkWidget* top_window = parent;
00170     gtk_window_maximize(GTK_WINDOW(top_window));
00171     gtk_window_set_resizable(GTK_WINDOW(top_window), FALSE);
00172     gtk_container_set_border_width(GTK_CONTAINER(top_window),WINDOW_BORDER_PADDING  );
00173     gtk_window_set_modal(GTK_WINDOW(top_window), TRUE);
00174 
00175     // top level vbox (vboxtop)
00176     GtkWidget* vboxtop = gtk_vbox_new(FALSE, 0);
00177     gtk_container_add(GTK_CONTAINER(top_window), vboxtop);
00178 
00179     // add header container the title and subtitle of this settings page
00180     create_title(GTK_VBOX(vboxtop), _("Settings"), _("Device Management"));
00181     
00182     // add the back/exit bar below the title 
00183     GtkWidget* view = create_settingsview();
00184     gtk_box_pack_start(GTK_BOX(vboxtop), view, FALSE, FALSE,0 ); 
00185     g_signal_connect(view, "row-activated", G_CALLBACK(on_listview_row_activated), NULL ) ;
00186     g_signal_connect(view, "navigate-cursor", G_CALLBACK(on_listview_navigate_cursor), NULL ) ;
00187     g_signal_connect(view, "focus-in-event", G_CALLBACK(on_focus_in), NULL );
00188     g_signal_connect(view, "focus-out-event", G_CALLBACK(on_focus_out), NULL );
00189 
00190    
00191     GtkWidget* vbox1 = GTK_WIDGET( create_frame(GTK_VBOX(vboxtop)) );
00192     create_reset_widgets(GTK_BOX(vbox1));
00193 
00194 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00195     GtkWidget* vbox2 = GTK_WIDGET( create_frame(GTK_VBOX(vboxtop)) );
00196     create_deauthorize_widgets(GTK_BOX(vbox2));
00197 #endif
00198 
00199     GtkWidget* vbox3 = GTK_WIDGET( create_frame(GTK_VBOX(vboxtop)) );
00200     create_format_widgets(GTK_BOX(vbox3));
00201 
00202 #if MACHINE_IS_DR800SG
00203     GtkWidget* vbox4 = GTK_WIDGET( create_frame(GTK_VBOX(vboxtop)) );
00204     create_reactivate_widgets(GTK_BOX(vbox4));
00205 #endif
00206 
00207         // Update widget with current settings.
00208     init_widgets_with_settings();
00209 
00210     g_reset_window = top_window;
00211 
00212     gtk_widget_grab_focus(view);
00213 
00214     gtk_widget_show_all(top_window);
00215     return top_window;
00216 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void init_widgets_with_settings ( void   )  [static]

Definition at line 450 of file reset.c.

Referenced by create_reset_window().

00451 {
00452     return;
00453 }

Here is the caller graph for this function:

void load_reset_settings (  ) 

Definition at line 155 of file reset.c.

References LOGPRINTF.

Referenced by create_concrete_win().

00156 {
00157     LOGPRINTF("Loading reset settings, done.\n");
00158 }

Here is the caller graph for this function:

static gboolean on_focus_in ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 248 of file reset.c.

References ERGTK_LIST_VIEW, and ergtk_list_view_set_cursor().

Referenced by create_reset_window().

00249 {
00250     g_assert(widget != NULL ) ;
00251     ergtk_list_view_set_cursor( ERGTK_LIST_VIEW(widget), 0); // row = 0;
00252     return FALSE;
00253 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean on_focus_out ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 255 of file reset.c.

Referenced by create_reset_window().

00256 {
00257     g_assert(widget != NULL ) ;
00258     GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) widget);
00259     g_assert( my_selection != NULL ) ;
00260     gtk_tree_selection_unselect_all(my_selection);
00261     return FALSE;
00262 }

Here is the caller graph for this function:

static gboolean on_format_button_clicked ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 617 of file reset.c.

References g_reset_window, ipc_menu_block(), ipc_menu_unblock(), ipc_sys_busy(), LOGPRINTF, and on_format_sd().

Referenced by create_format_widgets().

00618 {
00619     GtkWidget* dlg = NULL;
00620     int result;
00621 
00622     LOGPRINTF("entry");
00623 
00624     dlg = gtk_message_dialog_new(GTK_WINDOW(g_reset_window),
00625         GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
00626         GTK_MESSAGE_WARNING,
00627         GTK_BUTTONS_YES_NO,
00628         _("All your content will be erased from the card when you format.\n"
00629           "\n"
00630           "Do you want to format this card?"));
00631 
00632     ipc_menu_block();
00633     result = gtk_dialog_run(GTK_DIALOG(dlg));
00634     ipc_menu_unblock();
00635     gtk_widget_destroy(dlg);
00636 
00637     if (result != GTK_RESPONSE_YES)
00638     {
00639         return FALSE;
00640     }
00641 
00642     ipc_sys_busy(TRUE);
00643 
00644     g_idle_add(on_format_sd, NULL);
00645     return FALSE;
00646 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean on_format_sd ( gpointer  data  )  [static]

Definition at line 456 of file reset.c.

References g_cb_post_umount, g_sd_card_mounted, g_sd_format_ok, on_umount_done(), and unmount_sd_card().

Referenced by on_format_button_clicked().

00457 {
00458 
00459     // format not succeeded (yet)
00460     g_sd_format_ok = FALSE;
00461 
00462     // Before formatting sd card, unmount it first.
00463     if ( g_sd_card_mounted )
00464     {
00465         g_cb_post_umount = on_umount_done;
00466         unmount_sd_card();
00467     }
00468     else
00469     {
00470         on_umount_done();
00471     }
00472     
00473 
00474     return FALSE;  // Don't call me again.
00475 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_listview_navigate_cursor ( erGtkListView er_listview,
erGtkListViewKeyPress  keycode,
gpointer  user_data 
) [static]

Definition at line 273 of file reset.c.

References ERGTK_LIST_VIEW_PRESS_LONG_DOWN, ERGTK_LIST_VIEW_PRESS_SHORT_DOWN, g_reset_button, and LOGPRINTF.

Referenced by create_reset_window().

00276 {
00277     GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) er_listview);
00278     g_assert( my_selection != NULL ) ;
00279 
00280     // determine new cursor position
00281     switch (keycode)
00282     {
00283         case ERGTK_LIST_VIEW_PRESS_SHORT_DOWN:
00284         case ERGTK_LIST_VIEW_PRESS_LONG_DOWN:
00285             gtk_widget_grab_focus(GTK_WIDGET(g_reset_button));
00286             gtk_tree_selection_unselect_all(my_selection);
00287             break;
00288         default:
00289             LOGPRINTF("illegal erGtkListViewKeyPress [%d]", keycode);
00290             ;  // ignore
00291             break;
00292     }
00293 
00294 }

Here is the caller graph for this function:

static void on_listview_row_activated ( GtkTreeView *  view,
GtkTreePath *  path,
GtkTreeViewColumn *  column,
gpointer  user_data 
) [static]

Definition at line 264 of file reset.c.

References main_quit().

Referenced by create_reset_window().

00268 {
00269     main_quit();
00270     return;
00271 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_mount_done (  )  [static]

Definition at line 521 of file reset.c.

References g_reset_window, g_sd_format_ok, ipc_menu_block(), ipc_menu_unblock(), ipc_sys_busy(), and LOGPRINTF.

Referenced by on_umount_done().

00522 {
00523     GtkWidget  *dlg = NULL;
00524 
00525     LOGPRINTF("entry: g_sd_format_ok [%d]", g_sd_format_ok);
00526 
00527     ipc_sys_busy(FALSE);
00528 
00529     // Done. Popup a dialog indicating the result
00530     if (g_sd_format_ok)
00531     {
00532         dlg = gtk_message_dialog_new( GTK_WINDOW(g_reset_window),
00533                                       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
00534                                       GTK_MESSAGE_INFO,
00535                                       GTK_BUTTONS_OK,
00536                                       _("The SD card has been formatted.") );
00537     }
00538     else
00539     {
00540         dlg = gtk_message_dialog_new( GTK_WINDOW(g_reset_window),
00541                                       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
00542                                       GTK_MESSAGE_ERROR,
00543                                       GTK_BUTTONS_OK,
00544                                       _("A problem occurred while formatting the SD card.\n"
00545                                         "\n"
00546                                         "Please insert another SD card, then try again") );
00547     }
00548     
00549     ipc_menu_block();
00550     gtk_dialog_run(GTK_DIALOG(dlg));
00551     ipc_menu_unblock();
00552     gtk_widget_destroy(dlg);
00553 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean on_reset_button_clicked ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 648 of file reset.c.

References COOKIES_FILE, ERRORPRINTF, g_reset_window, ipc_menu_block(), ipc_menu_unblock(), ipc_sys_busy(), LOGPRINTF, ORIGCAL_FILE, SD_CARD_MOUNTPOINT, sync(), TZ_FILE, and USERCAL_FILE.

Referenced by create_reset_widgets().

00649 {
00650     GtkWidget* dlg = NULL;
00651     int result;
00652 
00653     LOGPRINTF("entry");
00654 
00655     dlg = gtk_message_dialog_new(GTK_WINDOW(g_reset_window),
00656         GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
00657         GTK_MESSAGE_WARNING,
00658         GTK_BUTTONS_YES_NO,
00659         _("All your settings will be returned to their original defaults if you continue.\n"
00660           "\n"
00661           "Do you want to reset the settings?"));
00662 
00663     ipc_menu_block();
00664     result = gtk_dialog_run(GTK_DIALOG(dlg));
00665     gtk_widget_destroy(dlg);
00666 
00667     if (result != GTK_RESPONSE_YES)
00668     {
00669         ipc_menu_unblock();
00670         return FALSE;
00671     }
00672 
00673     ipc_sys_busy(TRUE);
00674     
00675     // Delete tree in GConf registry
00676     system("/usr/bin/erconftool -d /apps/er -d /system/networking/connections");
00677     
00678     // Restore factory stylus calibration
00679     gchar   *content = NULL;
00680     gsize   length   = 0;    
00681     if (g_file_get_contents(ORIGCAL_FILE, &content, &length, NULL))
00682     {
00683         if (!g_file_set_contents(USERCAL_FILE, content, length, NULL))
00684         {
00685             ERRORPRINTF("Failed to write calibration file [%s]", USERCAL_FILE);
00686         }
00687     }
00688     else
00689     {
00690         ERRORPRINTF("Failed to read calibration file [%s]", ORIGCAL_FILE);
00691     }
00692     g_free(content);
00693 
00694     // Delete cookie jar    
00695     g_unlink(COOKIES_FILE);
00696     
00697     // Delete INI file
00698     g_unlink(SD_CARD_MOUNTPOINT"/System/dr.ini");
00699     
00700     // Delete timezone link
00701     g_unlink(TZ_FILE);
00702     
00703     // Make sure everything is written
00704     sync();
00705 
00706     // Done. Popup a dialog indicating the actions are successfully completed.
00707     dlg = gtk_message_dialog_new(GTK_WINDOW(g_reset_window),
00708         GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
00709         GTK_MESSAGE_INFO,
00710         GTK_BUTTONS_OK,
00711         _("The settings have been reset."));
00712 
00713     ipc_sys_busy(FALSE);
00714     gtk_dialog_run(GTK_DIALOG(dlg));
00715     gtk_widget_destroy(dlg);
00716     ipc_menu_unblock();
00717 
00718     return FALSE;
00719 
00720 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_umount_done (  )  [static]

Definition at line 478 of file reset.c.

References ERRORPRINTF, g_cb_post_mount, g_reset_window, g_sd_format_ok, LOGPRINTF, mount_sd_card(), on_mount_done(), and SD_FORMAT_COMMAND.

Referenced by on_format_sd().

00479 {
00480     int         rc;
00481     int         exitcode;
00482 
00483 
00484     // Function void if no SD screen
00485     if (g_reset_window == NULL)
00486     {
00487         return;
00488     }
00489 
00490     // SD card unmounted, start formatting.
00491     rc = system(SD_FORMAT_COMMAND);
00492     exitcode = WEXITSTATUS(rc);
00493     if (rc == -1)
00494     {
00495         ERRORPRINTF("format failed, cmd [%s]", SD_FORMAT_COMMAND);
00496     }
00497     else if (exitcode != 0)
00498     {
00499         ERRORPRINTF("format failed with exitcode [%d], cmd [%s]", exitcode, SD_FORMAT_COMMAND);
00500     }
00501     else
00502     {
00503         LOGPRINTF("format succeeded, cmd [%s]", SD_FORMAT_COMMAND);
00504         g_sd_format_ok = TRUE;
00505     }
00506 
00507     if (g_sd_format_ok)
00508     {
00509         // re-mount SD card after succesful formatting
00510         g_cb_post_mount = on_mount_done;
00511         mount_sd_card();
00512     }
00513     else
00514     {
00515         // format failed, no use to remount SD card
00516         on_mount_done();
00517     }
00518 }

Here is the call graph for this function:

Here is the caller graph for this function:

void reset_sdcard_mounted ( gboolean  is_mounted  ) 

Definition at line 218 of file reset.c.

References g_cb_post_mount, g_cb_post_umount, g_sd_card_mounted, and LOGPRINTF.

00219 {
00220     LOGPRINTF("entry: is_mounted [%d]", is_mounted);
00221 
00222     // remember card state
00223     g_sd_card_mounted = is_mounted;
00224 
00225     // Do post-mount stuff.
00226     if (is_mounted)
00227     {
00228         if (g_cb_post_mount)
00229         {
00230             (*g_cb_post_mount)();
00231             g_cb_post_mount = NULL;
00232         }
00233     }
00234     else
00235     {
00236         if (g_cb_post_umount)
00237         {
00238             (*g_cb_post_umount)();
00239             g_cb_post_umount = NULL;
00240         }
00241     }
00242 }

void save_reset_settings (  ) 

Definition at line 161 of file reset.c.

References LOGPRINTF.

00162 {
00163     LOGPRINTF("Saving reset settings, done.\n");
00164 }


Variable Documentation

void(* g_cb_post_mount)(void) [static]
void(* g_cb_post_umount)(void) [static]
GtkWidget* g_format_button = NULL [static]

Definition at line 96 of file reset.c.

Referenced by create_format_widgets().

GtkWidget* g_reset_button = NULL [static]

Definition at line 95 of file reset.c.

Referenced by create_reset_widgets(), and on_listview_navigate_cursor().

GtkWidget* g_reset_window = NULL [static]
gboolean g_sd_card_mounted = FALSE [static]

Definition at line 105 of file reset.c.

Referenced by on_format_sd(), and reset_sdcard_mounted().

gboolean g_sd_format_ok = FALSE [static]

Definition at line 104 of file reset.c.

Referenced by on_format_sd(), on_mount_done(), and on_umount_done().

const char* SD_FORMAT_COMMAND = "mkfs.vfat -F 32 -n \"" DEVICE_VOLUME_NAME "\" " SD_CARD_DEVICE [static]

Definition at line 83 of file reset.c.

Referenced by on_umount_done().

Generated by  doxygen 1.6.2-20100208