00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "config.h"
00032
00033
00034 #ifndef WIN32
00035 #include <sys/stat.h>
00036 #include <sys/statfs.h>
00037 #include <sys/types.h>
00038 #include <sys/wait.h>
00039 #endif
00040
00041 #include <string.h>
00042 #include <stdlib.h>
00043 #include <unistd.h>
00044 #include <stdio.h>
00045 #include <sys/time.h>
00046 #include <utime.h>
00047
00048 #include <gtk/gtk.h>
00049 #include <gdk/gdk.h>
00050 #include <glib.h>
00051 #include <glib/gstdio.h>
00052
00053
00054 #include <libergtk/ergtk.h>
00055 #include <liberutilstime/time_utils.h>
00056
00057
00058 #include "i18n.h"
00059 #include "log.h"
00060 #include "ipc.h"
00061 #include "settings.h"
00062 #include "settings_utils.h"
00063 #include "settings_style.h"
00064 #include "reset.h"
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800S || MACHINE_IS_DR800SW
00078 #define DEVICE_VOLUME_NAME "IREX DR800"
00079 #else
00080 #define DEVICE_VOLUME_NAME "IREX DR1000"
00081 #endif
00082
00083 static const char *SD_FORMAT_COMMAND = "mkfs.vfat -F 32 -n \"" DEVICE_VOLUME_NAME "\" " SD_CARD_DEVICE;
00084
00085 #define COOKIES_FILE "/home/root/cookies.txt"
00086 #define USERCAL_FILE "/home/root/.pointercal"
00087 #define ORIGCAL_FILE "/etc/pointercal"
00088
00089
00090
00091
00092
00093
00094 static GtkWidget* g_reset_window = NULL ;
00095 static GtkWidget* g_reset_button = NULL ;
00096 static GtkWidget* g_format_button = NULL ;
00097 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00098 static GtkWidget* g_deauthorize_button = NULL ;
00099 #endif
00100 #if MACHINE_IS_DR800SG
00101 static GtkWidget* g_reactivate_button = NULL ;
00102 #endif
00103
00104 static gboolean g_sd_format_ok = FALSE;
00105 static gboolean g_sd_card_mounted = FALSE;
00106
00107 static void (*g_cb_post_mount) (void);
00108 static void (*g_cb_post_umount) (void);
00109
00110
00111
00112
00113
00114
00115 static GtkWidget* create_reset_widgets (GtkBox* parent);
00116 static GtkWidget* create_format_widgets (GtkBox* parent);
00117 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00118 static GtkWidget* create_deauthorize_widgets (GtkBox* parent);
00119 #endif
00120 #if MACHINE_IS_DR800SG
00121 static GtkWidget* create_reactivate_widgets (GtkBox* parent);
00122 #endif
00123
00124 static gboolean on_reset_button_clicked (GtkWidget *widget, gpointer data);
00125 static gboolean on_format_button_clicked (GtkWidget *widget, gpointer data);
00126 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00127 static gboolean on_deauthorize_button_clicked (GtkWidget *widget, gpointer data);
00128 static void run_error_dialog(GtkWidget* parent, gchar* err_msg);
00129 #endif
00130 #if MACHINE_IS_DR800SG
00131 static gboolean on_reactivate_button_clicked (GtkWidget *widget, gpointer data);
00132 #endif
00133
00134 static void init_widgets_with_settings (void);
00135 static void on_listview_row_activated ( GtkTreeView *view,
00136 GtkTreePath *path,
00137 GtkTreeViewColumn *column,
00138 gpointer user_data );
00139
00140 static void on_listview_navigate_cursor ( erGtkListView *er_listview,
00141 erGtkListViewKeyPress keycode,
00142 gpointer user_data );
00143
00144 static gboolean on_focus_in(GtkWidget* widget, gpointer data );
00145 static gboolean on_focus_out(GtkWidget* widget, gpointer data );
00146
00147 static void on_umount_done();
00148 static void on_mount_done();
00149
00150
00151
00152
00153
00154
00155 void load_reset_settings()
00156 {
00157 LOGPRINTF("Loading reset settings, done.\n");
00158 }
00159
00160
00161 void save_reset_settings()
00162 {
00163 LOGPRINTF("Saving reset settings, done.\n");
00164 }
00165
00166 GtkWidget* create_reset_window(GtkWidget* parent)
00167 {
00168
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
00176 GtkWidget* vboxtop = gtk_vbox_new(FALSE, 0);
00177 gtk_container_add(GTK_CONTAINER(top_window), vboxtop);
00178
00179
00180 create_title(GTK_VBOX(vboxtop), _("Settings"), _("Device Management"));
00181
00182
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
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 }
00217
00218 void reset_sdcard_mounted(gboolean is_mounted)
00219 {
00220 LOGPRINTF("entry: is_mounted [%d]", is_mounted);
00221
00222
00223 g_sd_card_mounted = is_mounted;
00224
00225
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 }
00243
00244
00245
00246
00247
00248 static gboolean on_focus_in(GtkWidget* widget, gpointer data )
00249 {
00250 g_assert(widget != NULL ) ;
00251 ergtk_list_view_set_cursor( ERGTK_LIST_VIEW(widget), 0);
00252 return FALSE;
00253 }
00254
00255 static gboolean on_focus_out(GtkWidget* widget, gpointer data )
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 }
00263
00264 static void on_listview_row_activated ( GtkTreeView *view,
00265 GtkTreePath *path,
00266 GtkTreeViewColumn *column,
00267 gpointer user_data )
00268 {
00269 main_quit();
00270 return;
00271 }
00272
00273 static void on_listview_navigate_cursor ( erGtkListView *er_listview,
00274 erGtkListViewKeyPress keycode,
00275 gpointer user_data )
00276 {
00277 GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) er_listview);
00278 g_assert( my_selection != NULL ) ;
00279
00280
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 ;
00291 break;
00292 }
00293
00294 }
00295
00296
00297 static GtkWidget* create_reset_widgets(GtkBox* parent)
00298 {
00299
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
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
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
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
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 }
00337
00338 static GtkWidget* create_format_widgets(GtkBox* parent)
00339 {
00340
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
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
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
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
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 }
00372
00373 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00374 static GtkWidget* create_deauthorize_widgets(GtkBox* parent)
00375 {
00376
00377 GtkWidget* top_level_vbox = gtk_vbox_new(FALSE, ITEM_SPACING);
00378 gtk_box_pack_start(parent, top_level_vbox, FALSE, FALSE, 0);
00379
00380
00381 GtkWidget* subject = subject_create();
00382 gtk_label_set_label(GTK_LABEL(subject),
00383 _("Deactivate Device"));
00384 gtk_box_pack_start(GTK_BOX(top_level_vbox), subject, FALSE, FALSE, 0);
00385
00386
00387 GtkWidget* desc = description_create();
00388 gtk_label_set_label(GTK_LABEL(desc),
00389 _("This removes all DRM information from the device. "
00390 "When the device has been deactivated, you cannot open any DRM-protected content."));
00391 gtk_box_pack_start(GTK_BOX(top_level_vbox), desc, FALSE, FALSE, 0);
00392
00393
00394 GtkWidget* button_box = gtk_hbutton_box_new();
00395 gtk_box_pack_start(GTK_BOX(top_level_vbox), button_box, FALSE, FALSE, 9);
00396 gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_START);
00397
00398 g_deauthorize_button = gtk_button_new_with_label( _("Deactivate..."));
00399 gtk_box_pack_start(GTK_BOX(button_box), g_deauthorize_button, FALSE, FALSE, 0);
00400
00401
00402 g_signal_connect(G_OBJECT(g_deauthorize_button),
00403 "clicked",
00404 G_CALLBACK(on_deauthorize_button_clicked ),
00405 (gpointer) NULL );
00406
00407 return top_level_vbox;
00408 }
00409 #endif
00410
00411 #if MACHINE_IS_DR800SG
00412 static GtkWidget* create_reactivate_widgets(GtkBox* parent)
00413 {
00414
00415 GtkWidget* top_level_vbox = gtk_vbox_new(FALSE, ITEM_SPACING);
00416 gtk_box_pack_start(parent, top_level_vbox, FALSE, FALSE, 0);
00417
00418
00419 GtkWidget* subject = subject_create();
00420 gtk_label_set_label(GTK_LABEL(subject),
00421 _("Reactivate 3G Network Connection"));
00422 gtk_box_pack_start(GTK_BOX(top_level_vbox), subject, FALSE, FALSE, 0);
00423
00424
00425 GtkWidget* desc = description_create();
00426 gtk_label_set_label(GTK_LABEL(desc),
00427 _("Reactivate the network connection if the device is having problems connecting."));
00428 gtk_box_pack_start(GTK_BOX(top_level_vbox), desc, FALSE, FALSE, 0);
00429
00430
00431 GtkWidget* button_box = gtk_hbutton_box_new();
00432 gtk_box_pack_start(GTK_BOX(top_level_vbox), button_box, FALSE, FALSE, 9);
00433 gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_START);
00434
00435 g_reactivate_button = gtk_button_new_with_label( _("Reactivate Connection..."));
00436 gtk_box_pack_start(GTK_BOX(button_box), g_reactivate_button, FALSE, FALSE, 0);
00437
00438
00439 g_signal_connect(G_OBJECT(g_reactivate_button),
00440 "clicked",
00441 G_CALLBACK(on_reactivate_button_clicked ),
00442 (gpointer) NULL );
00443
00444
00445 return top_level_vbox;
00446 }
00447 #endif
00448
00449
00450 static void init_widgets_with_settings()
00451 {
00452 return;
00453 }
00454
00455
00456 static gboolean on_format_sd(gpointer data)
00457 {
00458
00459
00460 g_sd_format_ok = FALSE;
00461
00462
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;
00475 }
00476
00477
00478 static void on_umount_done()
00479 {
00480 int rc;
00481 int exitcode;
00482
00483
00484
00485 if (g_reset_window == NULL)
00486 {
00487 return;
00488 }
00489
00490
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
00510 g_cb_post_mount = on_mount_done;
00511 mount_sd_card();
00512 }
00513 else
00514 {
00515
00516 on_mount_done();
00517 }
00518 }
00519
00520
00521 static void on_mount_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
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 }
00554
00555 #if MACHINE_IS_DR800SG
00556 static gboolean on_reactivate(gpointer data)
00557 {
00558 GtkWidget *dlg = NULL;
00559 gchar *error_msg = NULL;
00560 char *error_strings[9] = {
00561 _("No error"),
00562 _("Couldn't enumerate"),
00563 _("No 3g devices found"),
00564 _("Couldn't connect"),
00565 _("Couldn't set activation callback"),
00566 _("Couldn't start activation"),
00567 _("Couldn't shutdown module"),
00568 _("Couldn't disconnect"),
00569 _("Activation failed"),
00570 };
00571
00572 int rc = system("/usr/bin/3greactivate.sh");
00573 int exitcode = WEXITSTATUS(rc);
00574 if (exitcode != 0)
00575 {
00576 ERRORPRINTF("3gactivate failed with exitcode [%d], cmd [/usr/bin/3greactivate.sh]", exitcode);
00577 }
00578 else
00579 {
00580 LOGPRINTF("3gactivate succeeded, cmd [/usr/bin/3greactivate.sh]");
00581 }
00582
00583 ipc_sys_busy(FALSE);
00584
00585
00586 if (exitcode==0)
00587 {
00588 dlg = gtk_message_dialog_new( GTK_WINDOW(g_reset_window),
00589 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
00590 GTK_MESSAGE_INFO,
00591 GTK_BUTTONS_OK,
00592 _("Reactivation was sucessful") );
00593 }
00594 else
00595 {
00596 error_msg = g_strdup_printf(
00597 _("A problem occured while reactivating:\n"
00598 "%s"),
00599 (exitcode < 9) ? error_strings[exitcode] : "Unknown error");
00600 dlg = gtk_message_dialog_new( GTK_WINDOW(g_reset_window),
00601 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
00602 GTK_MESSAGE_ERROR,
00603 GTK_BUTTONS_OK,
00604 error_msg);
00605 }
00606
00607 ipc_menu_block();
00608 gtk_dialog_run(GTK_DIALOG(dlg));
00609 ipc_menu_unblock();
00610 gtk_widget_destroy(dlg);
00611 if (error_msg) g_free(error_msg);
00612 return FALSE;
00613 }
00614 #endif
00615
00616
00617 static gboolean on_format_button_clicked(GtkWidget *widget, gpointer data)
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 }
00647
00648 static gboolean on_reset_button_clicked(GtkWidget *widget, gpointer data)
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
00676 system("/usr/bin/erconftool -d /apps/er -d /system/networking/connections");
00677
00678
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
00695 g_unlink(COOKIES_FILE);
00696
00697
00698 g_unlink(SD_CARD_MOUNTPOINT"/System/dr.ini");
00699
00700
00701 g_unlink(TZ_FILE);
00702
00703
00704 sync();
00705
00706
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 }
00721
00722 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00723 static gboolean on_deauthorize_button_clicked(GtkWidget *widget, gpointer data)
00724 {
00725
00726 GtkWidget* dlg = NULL;
00727 int result;
00728
00729 LOGPRINTF("entry");
00730
00731 dlg = gtk_message_dialog_new(GTK_WINDOW(g_reset_window),
00732 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
00733 GTK_MESSAGE_WARNING,
00734 GTK_BUTTONS_YES_NO,
00735 _("You cannot open any DRM-protected content once the device has been deactivated.\n"
00736 "\n"
00737 "Do you want to deactivate this device?"));
00738
00739 ipc_menu_block();
00740 result = gtk_dialog_run(GTK_DIALOG(dlg));
00741 ipc_menu_unblock();
00742 gtk_widget_destroy(dlg);
00743
00744 if (result != GTK_RESPONSE_YES)
00745 {
00746 return FALSE;
00747 }
00748
00749
00750 g_unlink("/home/root/.ereader");
00751
00752
00753 gchar* adobe_cmdline = "/usr/bin/adobe-activate --deactivate";
00754 gchar* ret_message = NULL;
00755 gchar* error_msg = NULL ;
00756 gint errcode = ipc_sys_start_task(adobe_cmdline, NULL, NULL, NULL, &ret_message);
00757
00758 if ( errcode > 0 )
00759 {
00760 ERRORPRINTF("cannot launch adobe-activate , cmd_line [%s], errcode %d [%s]", adobe_cmdline, errcode, ret_message);
00761 if (ret_message && (ret_message[0] != '\0'))
00762 {
00763 run_error_dialog(g_reset_window, ret_message );
00764 goto exit;
00765 }
00766 else {
00767 switch (errcode)
00768 {
00769 case 1:
00770 default:
00771 error_msg = g_strdup_printf(
00772 _("The '%s' application cannot be opened.\n"
00773 "Try closing some documents or reinstalling the software and try again."),
00774 adobe_cmdline );
00775 run_error_dialog(g_reset_window, error_msg);
00776 break;
00777 case 4:
00778 error_msg = g_strdup_printf(
00779 _("'%s' cannot be opened."),
00780 adobe_cmdline );
00781 run_error_dialog(g_reset_window, error_msg);
00782 break;
00783 case 2:
00784 case 3:
00785 break;
00786 }
00787 }
00788 }
00789
00790
00791 sync();
00792
00793
00794 dlg = gtk_message_dialog_new(GTK_WINDOW(g_reset_window),
00795 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
00796 GTK_MESSAGE_INFO,
00797 GTK_BUTTONS_OK,
00798 _("The device has been deactivated."));
00799
00800 ipc_menu_block();
00801 gtk_dialog_run(GTK_DIALOG(dlg));
00802 ipc_menu_unblock();
00803 gtk_widget_destroy(dlg);
00804
00805 exit:
00806 g_free(ret_message);
00807 g_free(error_msg);
00808
00809 return FALSE;
00810 }
00811 #endif
00812
00813 #if MACHINE_IS_DR800SG
00814 #define EPA_INFO_FILE "/home/root/epa.txt"
00815
00816 static gint get_cooloff()
00817 {
00818 float level;
00819 gint cooloff = 0;
00820 gint sec2wait = 0;
00821
00822 FILE *f = fopen(EPA_INFO_FILE, "rb");
00823 if (f)
00824 {
00825 fscanf(f, "level: %f %%\n", &level);
00826 fscanf(f, "cool-off: %d sec", &cooloff);
00827 LOGPRINTF("level: %f, cool-off: %d", level, cooloff);
00828 fclose(f);
00829 }
00830
00831 if (cooloff > 0)
00832 {
00833 struct stat st;
00834 struct timeval now;
00835 stat(EPA_INFO_FILE, &st);
00836 gettimeofday(&now, NULL);
00837
00838 if (st.st_mtime > now.tv_sec)
00839 {
00840
00841
00842 utime(EPA_INFO_FILE, NULL);
00843 sec2wait = cooloff;
00844 }
00845 else
00846 {
00847 sec2wait = (st.st_mtime + cooloff) - now.tv_sec;
00848 if (sec2wait < 0)
00849 {
00850
00851 sec2wait = 0;
00852 }
00853 }
00854 LOGPRINTF("now: %ld, file: %ld, sec2wait: %d", now.tv_sec, st.st_mtime, sec2wait);
00855 }
00856
00857 return sec2wait;
00858 }
00859 #endif
00860
00861 #if MACHINE_IS_DR800SG
00862 static gboolean on_reactivate_button_clicked(GtkWidget *widget, gpointer data)
00863 {
00864
00865 GtkWidget* dlg = NULL;
00866 int result;
00867 int level;
00868 gchar *state = NULL;
00869 int cooloff = get_cooloff();
00870
00871 LOGPRINTF("entry");
00872
00873
00874 if (cooloff > 0)
00875 {
00876 int minutes = (cooloff+60-1) / 60;
00877 gchar *error_msg = g_strdup_printf(
00878 _("You have reached the data transfer limit at this time.\n"
00879 "You will be able to reactivate after %d %s."),
00880 minutes,
00881 ngettext("minute", "minutes", minutes));
00882 WARNPRINTF("Need to cool off for another %d minutes [%d]", minutes, cooloff);
00883 run_error_dialog(g_reset_window, error_msg);
00884 g_free(error_msg);
00885 return FALSE;
00886 }
00887
00888
00889 ipc_get_battery_state(&level, &state, NULL);
00890 if (level<25)
00891 {
00892 WARNPRINTF("Can't activate - battery < 25%%");
00893 run_error_dialog(g_reset_window,
00894 _("Connect the device to a power source to continue reactivation.\n"
00895 "There must be more than 25%% battery power remaining for the 3G connection to work."));
00896 return FALSE;
00897 }
00898
00899
00900 if (get_value_bool (GCONF_FLIGHTMODE_MODE))
00901 {
00902 WARNPRINTF("Can't activate - flightmode active");
00903 run_error_dialog(g_reset_window,
00904 _("Airplane mode is on and the device cannot reactivate.\n"
00905 "Turn airplane mode off by tapping on the icon at the bottom of the screen."));
00906 return FALSE;
00907 }
00908
00909 dlg = gtk_message_dialog_new(GTK_WINDOW(g_reset_window),
00910 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
00911 GTK_MESSAGE_WARNING,
00912 GTK_BUTTONS_YES_NO,
00913 _("Your 3G network connection will be reactivated. This may take a couple of minutes to complete.\n"
00914 "\n"
00915 "Do you want to reactivate the connection?"));
00916
00917 ipc_menu_block();
00918 result = gtk_dialog_run(GTK_DIALOG(dlg));
00919 ipc_menu_unblock();
00920 gtk_widget_destroy(dlg);
00921
00922 if (result != GTK_RESPONSE_YES)
00923 {
00924 return FALSE;
00925 }
00926
00927 ipc_sys_busy(TRUE);
00928
00929 g_idle_add(on_reactivate, NULL);
00930 return FALSE;
00931 }
00932 #endif
00933
00934
00935 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00936 static void run_error_dialog(GtkWidget* parent, gchar* err_msg)
00937 {
00938
00939 ERRORPRINTF("entry: msg [%s]", err_msg);
00940
00941 GtkWidget *dialog = gtk_message_dialog_new(
00942 GTK_WINDOW(parent),
00943 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
00944 GTK_MESSAGE_ERROR,
00945 GTK_BUTTONS_OK,
00946 err_msg );
00947 gtk_window_set_deletable( GTK_WINDOW(dialog), FALSE );
00948 ipc_menu_block();
00949 gtk_dialog_run( GTK_DIALOG(dialog) );
00950 ipc_menu_unblock();
00951 gtk_widget_destroy( dialog );
00952 }
00953 #endif