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
00032 #ifndef WIN32
00033 #include <sys/utsname.h>
00034 #include <dirent.h>
00035 #endif
00036
00037 #include <ctype.h>
00038 #include <gtk/gtk.h>
00039 #include <gdk/gdk.h>
00040 #include <glib.h>
00041
00042 #include <libergtk/ergtk.h>
00043
00044
00045 #include "i18n.h"
00046 #include "ipc.h"
00047 #include "log.h"
00048 #include "settings.h"
00049 #include "settings_utils.h"
00050 #include "settings_style.h"
00051 #include "device_info.h"
00052
00053
00054
00055
00056
00057 typedef struct
00058 {
00059 char* title;
00060 char* value;
00061 } InfoItem;
00062
00063
00064
00065
00066
00067
00068 #define INFORMATION_ITEMS_INDENT 40
00069 #define ITEM_TITLE_VALUE_SPACING 30
00070 #define ADOBE_COPYRIGHT_HEAD "This IREX Digital Reader"
00071 #define ADOBE_COPYRIGHT_TAIL "contains Adobe® Reader® Mobile software (version 9.1.0) under license from Adobe Systems Incorporated, Copyright © 1995-2010 Adobe Systems Incorporated. All rights reserved. Adobe and Reader are trademarks of Adobe Systems Incorporated."
00072 #define OS_LICENSE "This product includes certain third-party open source software which is subject to different and/or additional licenses, disclaimers and notices. For more information about license terms and source code availability, see the Open Source Software Notification document in Help."
00073
00074 enum InfoItemType
00075 {
00076 SERIAL_NUMBER,
00077 PRODUCT_TYPE,
00078 PCBA_REVISION,
00079 PCBA_ID,
00080 EPD_ID,
00081 SOFTWARE_VERSION,
00082 SOFTWARE_BUILDNO,
00083 KERNEL_VERSION,
00084 MICRO_APP_VER,
00085 MICRO_BOOT_VER,
00086 WIFI_MAC,
00087 BLUETOOTH_MAC,
00088 THREEG_MEID,
00089 THREEG_IMEI,
00090 ITEM_TYPE_COUNT
00091 };
00092
00093
00094
00095
00096
00097
00098 static InfoItem g_info_items[ITEM_TYPE_COUNT] =
00099 {
00100 {NULL, NULL},
00101 {NULL, NULL},
00102 {NULL, NULL},
00103 {NULL, NULL},
00104 {NULL, NULL},
00105 {NULL, NULL},
00106 {NULL, NULL},
00107 {NULL, NULL},
00108 {NULL, NULL},
00109 {NULL, NULL},
00110 {NULL, NULL},
00111 {NULL, NULL},
00112 {NULL, NULL},
00113 {NULL, NULL}
00114 };
00115
00116 GtkWidget* g_frame = NULL ;
00117
00118
00119
00120
00121
00122
00123 static GtkWidget* create_device_info_widgets(GtkBox* parent);
00124 static GtkWidget* create_copyright_widgets(GtkBox* parent);
00125 static char* get_kernel_version();
00126 static char* get_sub_dir(const char* parent, const char* sub_dir);
00127 static char* micro_sysfs_read(const char* file);
00128 static gchar* get_file_content(const gchar* file_path);
00129
00130 int total_info_items;
00131
00132
00133
00134
00135
00136 GtkWidget* create_device_info_window(GtkWidget* parent)
00137 {
00138
00139 GtkWidget* top_window = parent;
00140 gtk_window_maximize(GTK_WINDOW(top_window));
00141 gtk_window_set_resizable(GTK_WINDOW(top_window), FALSE);
00142 gtk_container_set_border_width(GTK_CONTAINER(top_window), WINDOW_BORDER_PADDING );
00143 gtk_window_set_modal(GTK_WINDOW(top_window), TRUE);
00144
00145
00146
00147 GtkWidget* vboxtop = gtk_vbox_new(FALSE, 3);
00148 gtk_container_add(GTK_CONTAINER(top_window), vboxtop);
00149
00150
00151 create_title(GTK_VBOX(vboxtop), _("Settings"), _("Device Information"));
00152
00153
00154 GtkWidget* view = create_settingsview_for_type( SETTING_DEVINFO );
00155 gtk_box_pack_start(GTK_BOX(vboxtop), view, FALSE, FALSE,0 );
00156
00157
00158 GtkWidget* alignment = gtk_alignment_new(0, 0, 1.0, 0.0);
00159 gtk_box_pack_start(GTK_BOX(vboxtop), alignment, FALSE, FALSE, 0);
00160
00161
00162 GtkWidget* frame = gtk_frame_new(NULL);
00163 gtk_widget_set_name(frame, "irex-margins-frame");
00164 gtk_container_add(GTK_CONTAINER(alignment), frame);
00165 gtk_container_set_border_width(GTK_CONTAINER(frame), 3);
00166 g_frame = frame ;
00167
00168
00169 GtkWidget* alignment2 = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
00170 gtk_container_add(GTK_CONTAINER(frame), alignment2);
00171 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment2),
00172 WINDOW_TOP_ALT_PADDING,
00173 WINDOW_BOTTOM_PADDING,
00174 WINDOW_H_PADDING,
00175 WINDOW_H_PADDING);
00176
00177
00178 GtkWidget* innervbox = gtk_vbox_new(FALSE, SMALL_SPACING);
00179 gtk_container_add(GTK_CONTAINER(alignment2), innervbox);
00180
00181
00182 create_device_info_widgets(GTK_BOX(innervbox));
00183
00184 create_copyright_widgets(GTK_BOX(vboxtop));
00185
00186 gtk_widget_grab_focus(view);
00187
00188 gtk_widget_show_all(top_window);
00189 return top_window;
00190 }
00191
00192 void add_info_item(char *title, char *value)
00193 {
00194 if (total_info_items==ITEM_TYPE_COUNT)
00195 {
00196 ERRORPRINTF("Too many items in device box");
00197 return;
00198 }
00199
00200 if (g_info_items[total_info_items].value)
00201 {
00202 g_free(g_info_items[total_info_items].value);
00203 }
00204 g_info_items[total_info_items].title = title;
00205 g_info_items[total_info_items].value = value;
00206 total_info_items++;
00207 }
00208
00209 #define GET_SYSSET_FILE(path) (get_file_content("/sys/devices/system/sysset/sysset0/"path))
00210
00211 void load_device_info()
00212 {
00213 total_info_items = 0;
00214
00215
00216 add_info_item(
00217 _("Serial Number"),
00218 GET_SYSSET_FILE("fasm/serial"));
00219
00220
00221 add_info_item(
00222 _("Product Type"),
00223 g_strconcat(
00224 GET_SYSSET_FILE("fasm/category"),
00225 GET_SYSSET_FILE("fasm/model"),
00226 "-",
00227 GET_SYSSET_FILE("fasm/region"),
00228 NULL));
00229
00230 #if MACHINE_IS_DR800S || MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00231
00232 add_info_item(
00233 _("PCBA Revision"),
00234 micro_sysfs_read("pcba_rev"));
00235
00236
00237 add_info_item(
00238 _("PCBA ID"),
00239 micro_sysfs_read("mfg_serial"));
00240 #elif MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00241
00242 add_info_item(
00243 _("PCBA Revision"),
00244 GET_SYSSET_FILE("mpcb/pcb_rev"));
00245 #else
00246 #error Unhandled machine type
00247 #endif
00248
00249
00250 add_info_item(
00251 _("EPD ID"),
00252 g_strconcat(
00253 GET_SYSSET_FILE("display/fpl"),
00254 GET_SYSSET_FILE("display/waveform"),
00255 NULL));
00256
00257
00258 add_info_item(
00259 _("Software Version"),
00260 get_file_content("/etc/er_version_commercial"));
00261
00262
00263 add_info_item(
00264 _("Software Build Number"),
00265 get_file_content("/etc/version"));
00266
00267
00268 add_info_item(
00269 _("Kernel Version"),
00270 get_kernel_version());
00271
00272 #if MACHINE_IS_DR800S || MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00273
00274 add_info_item(
00275 _("Micro Bootloader Version"),
00276 micro_sysfs_read("boot_ver"));
00277 #endif
00278
00279
00280 add_info_item(
00281 _("Micro Application Version"),
00282 micro_sysfs_read("micro_ver"));
00283
00284 #if MACHINE_IS_DR1000SW || MACHINE_IS_DR800SW
00285
00286 add_info_item(
00287 _("WiFi MAC Address"),
00288 GET_SYSSET_FILE("wifi/address"));
00289
00290
00291 add_info_item(
00292 _("Bluetooth MAC Address"),
00293 GET_SYSSET_FILE("bluetooth/address"));
00294 #endif
00295
00296 #if MACHINE_IS_DR800SG
00297 add_info_item(
00298 _("3G MEID"),
00299 GET_SYSSET_FILE("3g/meid"));
00300 add_info_item(
00301 _("3G IMEI"),
00302 GET_SYSSET_FILE("3g/imei"));
00303 #endif
00304 }
00305
00306
00307
00308
00309
00310 static gchar* make_adobe_copyright(void)
00311 {
00312 gchar* device_string = GET_SYSSET_FILE("fasm/model");
00313 gchar* copyright = NULL;
00314
00315 if ( device_string == NULL )
00316 {
00317 copyright = g_strconcat ( ADOBE_COPYRIGHT_HEAD
00318 , " "
00319 , ADOBE_COPYRIGHT_TAIL
00320 , NULL );
00321 }
00322 else
00323 {
00324 copyright = g_strconcat ( ADOBE_COPYRIGHT_HEAD
00325 , " "
00326 , device_string
00327 , " "
00328 , ADOBE_COPYRIGHT_TAIL
00329 , NULL );
00330 }
00331 return copyright;
00332 }
00333
00334 static GtkWidget* create_copyright_widgets(GtkBox* parent)
00335 {
00336
00337 GtkWidget* alignment = gtk_alignment_new(0, 0, 1.0, 0.0);
00338 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 0, 0, 0);
00339 gtk_box_pack_start(GTK_BOX(parent), alignment, FALSE, FALSE, 0);
00340
00341
00342 GtkWidget* frame = gtk_frame_new(NULL);
00343 gtk_container_add(GTK_CONTAINER(alignment), frame);
00344 gtk_widget_set_name(frame, "irex-margins-frame");
00345 gtk_container_set_border_width(GTK_CONTAINER(frame), 3);
00346
00347
00348 GtkWidget* padding = gtk_alignment_new(0, 0, 0.0, 0.0);
00349 gtk_alignment_set_padding(GTK_ALIGNMENT(padding), 20, 20, 20, 20);
00350 gtk_container_add(GTK_CONTAINER(frame), padding ) ;
00351
00352
00353 GtkWidget* innervbox = gtk_vbox_new(FALSE, 20);
00354 gtk_container_add(GTK_CONTAINER(padding), innervbox);
00355
00356
00357 char logopath[512];
00358 snprintf(logopath, 512, "%s/%s", DATADIR, "includes_reader_mobile.png");
00359 GtkWidget* logo = gtk_image_new_from_file((gchar*) logopath );
00360 gtk_misc_set_alignment(GTK_MISC(logo), 0.0, 0.0);
00361 gtk_misc_set_padding(GTK_MISC(logo), 0, 0);
00362 gtk_box_pack_start(GTK_BOX(innervbox), logo, FALSE, FALSE, 0);
00363
00364
00365 gchar* copyright = make_adobe_copyright();
00366 GtkWidget* copyright_label = gtk_label_new(copyright);
00367 gtk_label_set_line_wrap(GTK_LABEL(copyright_label), TRUE);
00368 gtk_widget_set_size_request(copyright_label, 600, -1);
00369 gtk_misc_set_alignment(GTK_MISC(copyright_label), 0.0, 0.0);
00370 gtk_misc_set_padding(GTK_MISC(copyright_label), 0, 0);
00371 gtk_box_pack_start(GTK_BOX(innervbox), copyright_label, FALSE, FALSE, 0);
00372 g_free (copyright);
00373
00374
00375 GtkWidget* os_label = gtk_label_new( OS_LICENSE );
00376 gtk_label_set_line_wrap(GTK_LABEL(os_label), TRUE);
00377 gtk_widget_set_size_request(os_label, 600, -1);
00378 gtk_misc_set_alignment(GTK_MISC(os_label), 0.0, 0.0);
00379 gtk_misc_set_padding(GTK_MISC(os_label), 0, 0);
00380 gtk_box_pack_start(GTK_BOX(innervbox), os_label, FALSE, FALSE, 0);
00381
00382 return alignment;
00383
00384 }
00385
00386 static GtkWidget* create_device_info_widgets(GtkBox* parent)
00387 {
00388
00389
00390 GtkWidget* top_level_vbox = gtk_vbox_new(FALSE, ITEM_SPACING);
00391 gtk_box_pack_start(parent, top_level_vbox, FALSE, FALSE, 0);
00392
00393 GtkWidget* hbox = gtk_hbox_new(FALSE, ITEM_TITLE_VALUE_SPACING);
00394 gtk_container_add(GTK_CONTAINER(top_level_vbox), hbox);
00395
00396
00397 GtkWidget* vbox = gtk_vbox_new(TRUE, 0);
00398 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
00399
00400
00401 int i = 0;
00402 for (i=0; i<total_info_items; i++)
00403 {
00404 GtkWidget* label = gtk_label_new(g_info_items[i].title);
00405 gtk_widget_set_name(label, "irex-info-item-title");
00406 gtk_widget_set_size_request(label, -1, -1);
00407 gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.0);
00408 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
00409 }
00410
00411
00412 vbox = gtk_vbox_new(TRUE, 0);
00413 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
00414
00415
00416 i=0;
00417 for (i=0; i<total_info_items; i++)
00418 {
00419 GtkWidget* label = gtk_label_new(g_info_items[i].value);
00420 gtk_widget_set_name(label, "irex-sans-small-grey");
00421 gtk_widget_set_size_request(label, -1, -1);
00422 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00423 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
00424 }
00425
00426 return top_level_vbox;
00427 }
00428
00429 static gchar* get_file_content(const gchar* file_path)
00430 {
00431 gchar* contents = NULL;
00432 gsize len = 0;
00433
00434 if (g_file_get_contents(file_path, &contents, &len, NULL) == FALSE)
00435 {
00436 return NULL;
00437 }
00438
00439
00440
00441 while (len > 0 && (contents[len - 1] == '\n' || contents[len - 1] == '\0'))
00442 {
00443 contents[len - 1] = '\0';
00444 len--;
00445 }
00446 return contents;
00447 }
00448
00449
00450 static char* get_kernel_version()
00451 {
00452 #ifndef WIN32
00453 struct utsname utsbuf;
00454 unsigned int build_no;
00455
00456 if (-1 == uname(&utsbuf))
00457 {
00458
00459 return NULL;
00460 }
00461
00462 sscanf(utsbuf.version, "#%d", &build_no);
00463 return g_strdup_printf("%s (%d)", utsbuf.release, build_no);
00464 #else
00465 return NULL;
00466 #endif
00467 }
00468
00469
00470 static char* get_sub_dir(const char* parent, const char* sub_dir)
00471 {
00472 GDir* dir = g_dir_open(parent, 0, NULL);
00473 const char* file = NULL;
00474
00475 if (dir == NULL)
00476 {
00477 return NULL;
00478 }
00479
00480 while ((file = g_dir_read_name(dir)) != NULL)
00481 {
00482
00483 gchar* full_path = g_strdup_printf("%s/%s", parent, file);
00484 gboolean is_dir = g_file_test(full_path, G_FILE_TEST_IS_DIR);
00485 g_free(full_path);
00486
00487 if (is_dir == TRUE && g_str_has_prefix(file, sub_dir) == TRUE)
00488 {
00489
00490 return g_strdup_printf("%s/%s", parent, file);
00491 }
00492 }
00493
00494 g_dir_close(dir);
00495 return NULL;
00496 }
00497
00498 static char* micro_sysfs_read(const char* file)
00499 {
00500 char* serio = get_sub_dir("/sys/devices", "serio");
00501 char* path = NULL;
00502 char* content = NULL;
00503
00504 if (serio == NULL)
00505 {
00506 ERRORPRINTF("Can't find the micro device name!");
00507 return NULL;
00508 }
00509
00510 path = g_strdup_printf("%s/%s", serio, file);
00511 content = get_file_content(path);
00512
00513 g_free(path);
00514 g_free(serio);
00515 return content;
00516 }
00517
00518
00519