device_info.c File Reference

#include <sys/utsname.h>
#include <dirent.h>
#include <ctype.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <libergtk/ergtk.h>
#include "i18n.h"
#include "ipc.h"
#include "log.h"
#include "settings.h"
#include "settings_utils.h"
#include "settings_style.h"
#include "device_info.h"
Include dependency graph for device_info.c:

Go to the source code of this file.

Data Structures

struct  InfoItem

Defines

#define INFORMATION_ITEMS_INDENT   40
#define ITEM_TITLE_VALUE_SPACING   30
#define ADOBE_COPYRIGHT_HEAD   "This IREX Digital Reader"
#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."
#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."
#define GET_SYSSET_FILE(path)   (get_file_content("/sys/devices/system/sysset/sysset0/"path))

Enumerations

enum  InfoItemType {
  SERIAL_NUMBER, PRODUCT_TYPE, PCBA_REVISION, PCBA_ID,
  EPD_ID, SOFTWARE_VERSION, SOFTWARE_BUILDNO, KERNEL_VERSION,
  MICRO_APP_VER, MICRO_BOOT_VER, WIFI_MAC, BLUETOOTH_MAC,
  THREEG_MEID, THREEG_IMEI, ITEM_TYPE_COUNT
}

Functions

static GtkWidget * create_device_info_widgets (GtkBox *parent)
static GtkWidget * create_copyright_widgets (GtkBox *parent)
static char * get_kernel_version ()
static char * get_sub_dir (const char *parent, const char *sub_dir)
static char * micro_sysfs_read (const char *file)
static gchar * get_file_content (const gchar *file_path)
GtkWidget * create_device_info_window (GtkWidget *parent)
void add_info_item (char *title, char *value)
void load_device_info ()
static gchar * make_adobe_copyright (void)

Variables

static InfoItem g_info_items [ITEM_TYPE_COUNT]
GtkWidget * g_frame = NULL
int total_info_items

Define Documentation

#define ADOBE_COPYRIGHT_HEAD   "This IREX Digital Reader"

Definition at line 70 of file device_info.c.

Referenced by make_adobe_copyright().

#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."

Definition at line 71 of file device_info.c.

Referenced by make_adobe_copyright().

#define GET_SYSSET_FILE ( path   )     (get_file_content("/sys/devices/system/sysset/sysset0/"path))

Definition at line 209 of file device_info.c.

Referenced by load_device_info(), and make_adobe_copyright().

#define INFORMATION_ITEMS_INDENT   40

Definition at line 68 of file device_info.c.

#define ITEM_TITLE_VALUE_SPACING   30

Definition at line 69 of file device_info.c.

Referenced by create_device_info_widgets().

#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."

Definition at line 72 of file device_info.c.

Referenced by create_copyright_widgets().


Enumeration Type Documentation

Enumerator:
SERIAL_NUMBER 
PRODUCT_TYPE 
PCBA_REVISION 
PCBA_ID 
EPD_ID 
SOFTWARE_VERSION 
SOFTWARE_BUILDNO 
KERNEL_VERSION 
MICRO_APP_VER 
MICRO_BOOT_VER 
WIFI_MAC 
BLUETOOTH_MAC 
THREEG_MEID 
THREEG_IMEI 
ITEM_TYPE_COUNT 

Definition at line 74 of file device_info.c.

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 };


Function Documentation

void add_info_item ( char *  title,
char *  value 
)

Definition at line 192 of file device_info.c.

References ERRORPRINTF, ITEM_TYPE_COUNT, InfoItem::title, total_info_items, and InfoItem::value.

Referenced by load_device_info().

00193 {
00194     if (total_info_items==ITEM_TYPE_COUNT)
00195     {
00196         ERRORPRINTF("Too many items in device box");
00197         return;
00198     }
00199     // FIXME: this still leaks
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 }

Here is the caller graph for this function:

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

Definition at line 334 of file device_info.c.

References make_adobe_copyright(), and OS_LICENSE.

Referenced by create_device_info_window().

00335 {
00336     // add an alignment for the frame 
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     // frame in the alignment
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     // padding in frame 
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      // vbox in padding 
00353     GtkWidget* innervbox = gtk_vbox_new(FALSE, 20);
00354     gtk_container_add(GTK_CONTAINER(padding), innervbox);
00355 
00356     // logo in vbox
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     // label in vbox
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     // label in vbox
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 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 386 of file device_info.c.

References ITEM_SPACING, ITEM_TITLE_VALUE_SPACING, label, and total_info_items.

Referenced by create_device_info_window().

00387 {
00388 
00389     // Top level vbox.
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     // The vbox containing the item titles.
00397     GtkWidget* vbox = gtk_vbox_new(TRUE, 0);
00398     gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
00399 
00400     // The item titles goes here.
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     // The vbox containing the item value.
00412     vbox = gtk_vbox_new(TRUE, 0);
00413     gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
00414 
00415     // The item values go here
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 }

Here is the caller graph for this function:

GtkWidget* create_device_info_window ( GtkWidget *  parent  ) 

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

Definition at line 136 of file device_info.c.

References create_copyright_widgets(), create_device_info_widgets(), create_settingsview_for_type(), create_title(), g_frame, SETTING_DEVINFO, SMALL_SPACING, WINDOW_BORDER_PADDING, WINDOW_BOTTOM_PADDING, WINDOW_H_PADDING, and WINDOW_TOP_ALT_PADDING.

Referenced by create_concrete_win().

00137 {
00138     // create top window
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     // top level vbox (vboxtop)
00147     GtkWidget* vboxtop = gtk_vbox_new(FALSE, 3);
00148     gtk_container_add(GTK_CONTAINER(top_window), vboxtop);
00149 
00150     // add header container the title and subtitle of this settings page
00151     create_title(GTK_VBOX(vboxtop), _("Settings"), _("Device Information"));
00152     
00153     // add the back/exit bar below the title 
00154     GtkWidget* view = create_settingsview_for_type( SETTING_DEVINFO );
00155     gtk_box_pack_start(GTK_BOX(vboxtop), view, FALSE, FALSE,0 ); 
00156 
00157     // add an alignment below the exit bar
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     // introdude a frame in the alignment
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     // alignment in frame 
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     // vbox in alignment2
00178     GtkWidget* innervbox = gtk_vbox_new(FALSE, SMALL_SPACING);
00179     gtk_container_add(GTK_CONTAINER(alignment2), innervbox);
00180 
00181     // The device info section.
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 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gchar * get_file_content ( const gchar *  file_path  )  [static]

Definition at line 429 of file device_info.c.

Referenced by load_device_info(), and micro_sysfs_read().

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     // Remove trailing '\n' characters
00440     // End of string may have more than one \0 char
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 }

Here is the caller graph for this function:

static char * get_kernel_version ( void   )  [static]

Definition at line 450 of file device_info.c.

Referenced by load_device_info().

00451 {
00452 #ifndef WIN32
00453     struct utsname utsbuf;
00454     unsigned int   build_no;
00455 
00456     if (-1 == uname(&utsbuf))
00457     {
00458         // An error occurred.
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 }

Here is the caller graph for this function:

static char * get_sub_dir ( const char *  parent,
const char *  sub_dir 
) [static]

Definition at line 470 of file device_info.c.

Referenced by micro_sysfs_read().

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         // Skip regular file.
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             // Sub dir found.
00490             return g_strdup_printf("%s/%s", parent, file);
00491         }
00492     }
00493 
00494     g_dir_close(dir);
00495     return NULL;
00496 }

Here is the caller graph for this function:

void load_device_info (  ) 

Definition at line 211 of file device_info.c.

References add_info_item(), get_file_content(), get_kernel_version(), GET_SYSSET_FILE, micro_sysfs_read(), and total_info_items.

Referenced by create_concrete_win().

00212 {
00213     total_info_items = 0;
00214 
00215     // serial number
00216     add_info_item(
00217             _("Serial Number"),
00218             GET_SYSSET_FILE("fasm/serial"));
00219 
00220     // product type
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     // pcba revision
00232     add_info_item(
00233             _("PCBA Revision"),
00234             micro_sysfs_read("pcba_rev"));
00235 
00236     // pcba id
00237     add_info_item(
00238             _("PCBA ID"),
00239             micro_sysfs_read("mfg_serial"));
00240 #elif MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00241     // pcba revision
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     // epd id
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     // software version
00258     add_info_item(
00259             _("Software Version"),
00260             get_file_content("/etc/er_version_commercial"));
00261 
00262     // build number
00263     add_info_item(
00264             _("Software Build Number"),
00265             get_file_content("/etc/version"));
00266 
00267     // kernel version
00268     add_info_item(
00269             _("Kernel Version"),
00270             get_kernel_version());
00271 
00272 #if MACHINE_IS_DR800S || MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00273     // micro boot version
00274     add_info_item(
00275             _("Micro Bootloader Version"),
00276             micro_sysfs_read("boot_ver"));
00277 #endif
00278 
00279     // micro app version
00280     add_info_item(
00281             _("Micro Application Version"),
00282             micro_sysfs_read("micro_ver"));
00283 
00284 #if MACHINE_IS_DR1000SW || MACHINE_IS_DR800SW
00285     // wifi mac
00286     add_info_item(
00287             _("WiFi MAC Address"),
00288             GET_SYSSET_FILE("wifi/address"));
00289 
00290     // bluetooth mac
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 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gchar* make_adobe_copyright ( void   )  [static]

Definition at line 310 of file device_info.c.

References ADOBE_COPYRIGHT_HEAD, ADOBE_COPYRIGHT_TAIL, and GET_SYSSET_FILE.

Referenced by create_copyright_widgets().

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 }

Here is the caller graph for this function:

static char * micro_sysfs_read ( const char *  file  )  [static]

Definition at line 498 of file device_info.c.

References ERRORPRINTF, get_file_content(), get_sub_dir(), and path.

Referenced by load_device_info().

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 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

GtkWidget* g_frame = NULL

Definition at line 116 of file device_info.c.

Referenced by create_device_info_window().

InfoItem g_info_items[ITEM_TYPE_COUNT] [static]
Initial value:
{
    {NULL, NULL},
    {NULL, NULL},
    {NULL, NULL},
    {NULL, NULL},
    {NULL, NULL},
    {NULL, NULL},
    {NULL, NULL},
    {NULL, NULL},
    {NULL, NULL},
    {NULL, NULL},
    {NULL, NULL},
    {NULL, NULL},
    {NULL, NULL},
    {NULL, NULL}
}

Definition at line 98 of file device_info.c.

Definition at line 130 of file device_info.c.

Referenced by add_info_item(), create_device_info_widgets(), and load_device_info().

Generated by  doxygen 1.6.2-20100208