diff options
| -rw-r--r-- | hardinfo2/arch/common/fib.h | 23 | ||||
| -rwxr-xr-x | hardinfo2/configure | 9 | ||||
| -rw-r--r-- | hardinfo2/hardinfo.c | 31 | ||||
| -rw-r--r-- | hardinfo2/hardinfo.h | 40 | ||||
| -rw-r--r-- | hardinfo2/menu.c | 5 | ||||
| -rw-r--r-- | hardinfo2/report.c | 56 | ||||
| -rw-r--r-- | hardinfo2/report.h | 16 | ||||
| -rw-r--r-- | hardinfo2/shell.c | 8 | ||||
| -rw-r--r-- | hardinfo2/util.c | 99 | 
9 files changed, 199 insertions, 88 deletions
| diff --git a/hardinfo2/arch/common/fib.h b/hardinfo2/arch/common/fib.h index 9f2d4e77..a218c90c 100644 --- a/hardinfo2/arch/common/fib.h +++ b/hardinfo2/arch/common/fib.h @@ -16,12 +16,12 @@   *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA   */ -static unsigned long long -fib(unsigned long long n) +static unsigned int +fib(unsigned int n)  {      if (n == 0)          return 0; -    else if (n == 1 || n == 2) +    else if (n <= 2)          return 1;      return fib(n - 1) + fib(n - 2);  } @@ -30,16 +30,21 @@ static gchar *  benchmark_fib(void)  {      GTimer *timer = g_timer_new(); -    gdouble elapsed = 0; +    gdouble elapsed = 1.0; +    gint i;      shell_view_set_enabled(FALSE);      shell_status_update("Calculating the 42nd Fibonacci number..."); -    g_timer_start(timer); -    fib(42);		/* the answer? :) */ -    g_timer_stop(timer); - -    elapsed = g_timer_elapsed(timer, NULL); +    for (i = 0; i < 3; i++) { +        g_timer_reset(timer); +        g_timer_start(timer); +        fib(42);		/* the answer? :) */ +        g_timer_stop(timer); +        elapsed *= g_timer_elapsed(timer, NULL); +    } +     +    elapsed = pow(elapsed, 1 / 3.0);      g_timer_destroy(timer); diff --git a/hardinfo2/configure b/hardinfo2/configure index 978b476c..869541ea 100755 --- a/hardinfo2/configure +++ b/hardinfo2/configure @@ -82,9 +82,6 @@ case $PROC in  		if [ "$?" == "0" ]; then  			ln -sf linux/m68k arch/this  			ARCH="ARCH_m68k" -		else -			echo "Architeture \"$ARCH\" not supported."  -			exit  		fi  		;; @@ -136,7 +133,8 @@ for i in `which pkg-config`; do  			GTK_FLAGS=`pkg-config gtk+-2.0 --cflags`  			GTK_LIBS=`pkg-config gtk+-2.0 --libs`  			echo "found `pkg-config gtk+-2.0 --modversion`" -			GTK2=1 ;; +			GTK2=1 +			break ;;  		*)  			echo "not found." ;;  	esac @@ -147,7 +145,7 @@ done  if [ $GTK2 -eq -1 ]; then  	echo -e "\nYou need the GTK libraries, including the development stuff."  	echo "If you're using Debian, running the command as root:" -	echo -e "\n\tapt-get install libgtk2.0-dev\n" +	echo -e "\n\taptitude install libgtk2.0-dev\n"  	echo "Will do the trick."  	exit  fi @@ -171,6 +169,7 @@ echo "#define PREFIX \"/usr/share/hardinfo/\"" >> config.h  echo "#define LIBPREFIX \"/usr/lib/hardinfo/\"" >> config.h  echo "#define DEBUG 1" >> config.h  echo "#define ENABLE_BINRELOC" >> config.h +echo "#define RELEASE $RELEASE" >> config.h  echo -e "\n#endif	/* __CONFIG_H__ */" >> config.h diff --git a/hardinfo2/hardinfo.c b/hardinfo2/hardinfo.c index 7cf13875..908c61bf 100644 --- a/hardinfo2/hardinfo.c +++ b/hardinfo2/hardinfo.c @@ -19,37 +19,26 @@  #include <config.h>  #include <shell.h> +#include <hardinfo.h>  #include <iconcache.h>  #include <stock.h>  #include <binreloc.h> -gchar *path_data, *path_lib; +gchar	 *path_data = NULL, +         *path_lib = NULL; +gboolean  gui_running = FALSE;  int  main(int argc, char **argv)  { -    GError *error; +    gui_running = ui_init(&argc, &argv); -    gtk_init(&argc, &argv); -     -    if (!gbr_init(&error)) { -        path_data = g_build_filename(PREFIX, "share", "hardinfo", NULL); -        path_lib = g_build_filename(PREFIX, "lib", "hardinfo", NULL); -         -        g_warning("Cannot initialize BinReloc (%s); using \"%s\" as data dir and " \ -                  "\"%s\" as lib dir.", error->message, path_data, path_lib); -        g_error_free(error); -    } else { -        gchar *tmp; -         -        tmp = gbr_find_data_dir(PREFIX); -        path_data = g_build_filename(tmp, "hardinfo", NULL); -        g_free(tmp); -         -        tmp = gbr_find_lib_dir(PREFIX); -        path_lib = g_build_filename(tmp, "hardinfo", NULL); -        g_free(tmp); +    if (!binreloc_init(FALSE)) { +        g_error("Failed to find runtime data.\n\n" +                "\342\200\242 Is HardInfo correctly installed?\n" +                "\342\200\242 See if %s and %s exists and you have read permision.", +                PREFIX, LIBPREFIX);      }      icon_cache_init(); diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h index afed5ca0..285a422c 100644 --- a/hardinfo2/hardinfo.h +++ b/hardinfo2/hardinfo.h @@ -21,7 +21,7 @@  #include <gtk/gtk.h> -typedef struct _ModuleEntry ModuleEntry; +typedef struct _ModuleEntry	ModuleEntry;  typedef struct _FileTypes	FileTypes;  struct _FileTypes { @@ -36,21 +36,33 @@ struct _ModuleEntry {      gchar *icon;  }; -inline  void  remove_quotes(gchar *str); -inline  void  strend(gchar *str, gchar chr); -inline  void  remove_linefeed(gchar *str); -        void  widget_set_cursor(GtkWidget *widget, GdkCursorType cursor_type); +/* String utility functions */ +inline void remove_quotes(gchar *str); +inline void strend(gchar *str, gchar chr); +inline void remove_linefeed(gchar *str); + +/* Widget utility functions */ +void widget_set_cursor(GtkWidget *widget, GdkCursorType cursor_type); + +/* File Chooser utility functions */ +void      file_chooser_open_expander(GtkWidget *chooser); +void      file_chooser_add_filters(GtkWidget *chooser, FileTypes *filters); +gchar    *file_chooser_get_extension(GtkWidget *chooser, FileTypes *filters); +gchar    *file_chooser_build_filename(GtkWidget *chooser, gchar *extension); +gpointer  file_types_get_data_by_name(FileTypes *file_types, gchar *name); + +/* Misc utility functions */  inline gchar *size_human_readable(gfloat size); -        void  nonblock_sleep(guint msec); +void          nonblock_sleep(guint msec); + +/* BinReloc stuff */ +gboolean binreloc_init(gboolean try_hardcoded); -        void  file_chooser_open_expander(GtkWidget *chooser); -        void  file_chooser_add_filters(GtkWidget *chooser, FileTypes *filters); -       gchar *file_chooser_get_extension(GtkWidget *chooser, FileTypes *filters); -       gchar *file_chooser_build_filename(GtkWidget *chooser, gchar *extension); -        -    gpointer  file_types_get_data_by_name(FileTypes *file_types, gchar *name); +extern gchar* path_lib; +extern gchar* path_data; -extern	gchar*	path_lib; -extern	gchar*	path_data; +/* GTK UI stuff */ +gboolean ui_init(int *argc, char ***argv); +extern gboolean gui_running;  #endif				/* __HARDINFO_H__ */ diff --git a/hardinfo2/menu.c b/hardinfo2/menu.c index 0d9b64eb..e663f918 100644 --- a/hardinfo2/menu.c +++ b/hardinfo2/menu.c @@ -37,7 +37,7 @@ static GtkActionEntry entries[] =    { "ReportAction", HI_STOCK_REPORT,                    /* name, stock id */      "Generate _Report", "<control>R",                   /* label, accelerator */ -    "Creates a report in HTML",                         /* tooltip */  +    NULL, 			                        /* tooltip */       G_CALLBACK(cb_generate_report) },    { "CopyAction", GTK_STOCK_COPY, @@ -116,7 +116,7 @@ void menu_init(Shell *shell)      g_free(uidefs_path);      if (error) { -        g_error("building menus failed: %s", error->message); +        g_error("Building menus failed: %s", error->message);          g_error_free(error);          return;      } @@ -138,3 +138,4 @@ void menu_init(Shell *shell)      gtk_toolbar_set_style(GTK_TOOLBAR(gtk_ui_manager_get_widget(shell->ui_manager, "/MainMenuBarAction")),                            GTK_TOOLBAR_BOTH_HORIZ);  } + diff --git a/hardinfo2/report.c b/hardinfo2/report.c index 500a3536..e3e28705 100644 --- a/hardinfo2/report.c +++ b/hardinfo2/report.c @@ -31,7 +31,6 @@ static FileTypes file_types[] = {    { NULL,			NULL,		NULL,		NULL }  }; -  void  report_header(ReportContext *ctx)  { @@ -273,8 +272,13 @@ static void  report_generate_children(ReportContext *ctx, GtkTreeIter *iter)  {      GtkTreeModel *model = ctx->rd->model; +    gboolean selected;      gchar *name; +    gtk_tree_model_get(model, iter, TREE_COL_SEL, &selected, -1); +    if (!selected) +        return; +          gtk_tree_model_get(model, iter, TREE_COL_NAME, &name, -1);      report_title(ctx, name); @@ -368,40 +372,42 @@ report_generate(ReportDialog *rd)  {      GtkTreeIter		 iter;      ReportContext	*ctx; -    ReportContext	*(*ctx_gen)(ReportDialog *rd); +    ReportContext	*(*create_context)(ReportDialog *rd);      gchar		*file;      FILE		*stream;      if (!(file = report_get_filename()))          return FALSE; -    if (!(stream = fopen(file, "w+"))) -        return FALSE; -     -    ctx_gen = file_types_get_data_by_name(file_types, file); -    if (ctx_gen) { -        ctx = ctx_gen(rd); -         -        report_header(ctx); -         -        gtk_tree_model_get_iter_first(rd->model, &iter); -        do { -             report_generate_children(ctx, &iter); -        } while (gtk_tree_model_iter_next(rd->model, &iter)); - -        report_footer(ctx); -         -        fputs(ctx->output, stream); -        fclose(stream); -         -        report_context_free(ctx); +    if (!(stream = fopen(file, "w+"))) {          g_free(file); -         -        return TRUE; +        return FALSE;      } +    create_context = file_types_get_data_by_name(file_types, file);      g_free(file); -    return FALSE; +     +    if (!create_context) { +        g_warning("Cannot create ReportContext. Programming bug?"); +        return FALSE; +    } + +    ctx = create_context(rd); +    report_header(ctx); +     +    gtk_tree_model_get_iter_first(rd->model, &iter); +    do { +         report_generate_children(ctx, &iter); +    } while (gtk_tree_model_iter_next(rd->model, &iter)); + +    report_footer(ctx); +     +    fputs(ctx->output, stream); +    fclose(stream); +     +    report_context_free(ctx); +     +    return TRUE;  }  void diff --git a/hardinfo2/report.h b/hardinfo2/report.h index 1312f0cd..8762f671 100644 --- a/hardinfo2/report.h +++ b/hardinfo2/report.h @@ -49,15 +49,15 @@ struct _ReportDialog {    GtkTreeModel *model;  }; -void report_dialog_show(); +void		 report_dialog_show(); -void report_header(ReportContext *ctx); -void report_footer(ReportContext *ctx); -void report_title(ReportContext *ctx, gchar *text); -void report_subtitle(ReportContext *ctx, gchar *text); -void report_subsubtitle(ReportContext *ctx, gchar *text); -void report_key_value(ReportContext *ctx, gchar *key, gchar *value); -void report_table(ReportContext *ctx, gchar *text); +void		 report_header		(ReportContext *ctx); +void		 report_footer		(ReportContext *ctx); +void		 report_title		(ReportContext *ctx, gchar *text); +void 		 report_subtitle	(ReportContext *ctx, gchar *text); +void 		 report_subsubtitle	(ReportContext *ctx, gchar *text); +void		 report_key_value	(ReportContext *ctx, gchar *key, gchar *value); +void		 report_table		(ReportContext *ctx, gchar *text);  ReportContext	*report_context_html_new(ReportDialog *rd);  ReportContext	*report_context_text_new(ReportDialog *rd); diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index 40cb8d58..5e602cfa 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -520,6 +520,10 @@ shell_init(void)      shell->moreinfo = info_tree_new(TRUE);      shell->loadgraph = load_graph_new(75); +    shell_action_set_property("CopyAction", "is-important", TRUE); +    shell_action_set_property("RefreshAction", "is-important", TRUE); +    shell_action_set_property("ReportAction", "is-important", TRUE); +      gtk_paned_pack1(GTK_PANED(shell->hpaned), shell->tree->scroll,  		    SHELL_PACK_RESIZE, SHELL_PACK_SHRINK);      gtk_paned_pack1(GTK_PANED(shell->vpaned), shell->info->scroll, @@ -546,16 +550,12 @@ shell_init(void)      gtk_widget_show_all(shell->hpaned);      load_graph_configure_expose(shell->loadgraph); -      gtk_widget_hide(shell->notebook);      shell_action_set_enabled("RefreshAction", FALSE);      shell_action_set_enabled("CopyAction", FALSE);      shell_action_set_active("SidePaneAction", TRUE);      shell_action_set_active("ToolbarAction", TRUE); -    shell_action_set_property("CopyAction", "is-important", TRUE); -    shell_action_set_property("RefreshAction", "is-important", TRUE); -    shell_action_set_property("ReportAction", "is-important", TRUE);  }  static gboolean diff --git a/hardinfo2/util.c b/hardinfo2/util.c index e39f02d9..3e0dc5b3 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/util.c @@ -15,10 +15,14 @@   *    along with this program; if not, write to the Free Software   *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA   */ +#include <config.h> +  #include <string.h>  #include <hardinfo.h>  #include <gtk/gtk.h> +#include <binreloc.h> +  #define KiB 1024  #define MiB 1048576  #define GiB 1073741824 @@ -170,3 +174,98 @@ gchar      return retval;  } + +gboolean +binreloc_init(gboolean try_hardcoded) +{ +    GError *error = NULL; +    gchar *tmp; +     +    /* If the runtime data directories we previously found, don't even try +       to find them again. */ +    if (path_data && path_lib) { +        return TRUE; +    } +     +    if (try_hardcoded || !gbr_init(&error)) { +        /* We were asked to try hardcoded paths or BinReloc failed to initialize. */ +        path_data = g_strdup(PREFIX); +        path_lib = g_strdup(LIBPREFIX); + +        if (error) { +            g_error_free(error); +        }         +    } else { +        /* If we were able to initialize BinReloc, build the default data +           and library paths. */ +        tmp = gbr_find_data_dir(PREFIX); +        path_data = g_build_filename(tmp, "hardinfo", NULL); +        g_free(tmp); + +        tmp = gbr_find_lib_dir(PREFIX); +        path_lib = g_build_filename(tmp, "hardinfo", NULL); +        g_free(tmp); +    } + +    /* Try to see if the uidefs.xml file isn't missing. This isn't the +       definitive test, but it should do okay for most situations. */ +    tmp = g_build_filename(path_data, "uidefs.xml", NULL); +    if (!g_file_test(tmp, G_FILE_TEST_EXISTS)) { +        g_free(path_data); +        g_free(path_lib); +        g_free(tmp); +         +        path_data = path_lib = NULL; +         +        if (try_hardcoded) { +            /* We tried the hardcoded paths, but still was unable to find the +               runtime data. Give up. */ +            return FALSE; +        } else { +            /* Even though BinReloc worked OK, the runtime data was not found. +               Try the hardcoded paths. */ +            return binreloc_init(TRUE); +        } +    } +    g_free(tmp); + +    /* We found the runtime data; hope everything is fine */ +    return TRUE; +} + +static void +log_handler(const gchar *log_domain, +            GLogLevelFlags log_level, +            const gchar *message, +            gpointer user_data) +{ +    if (!gui_running) { +        /* No GUI running: spit the message to the terminal */ +        g_print("\n\n*** %s: %s\n\n", (log_level & G_LOG_FLAG_FATAL) ? "Error" : "Warning", +                message); +    } else { +        /* Hooray! We have a GUI running! */ +        GtkWidget *dialog; +         +        dialog = gtk_message_dialog_new_with_markup(NULL, GTK_DIALOG_MODAL, +                                                    (log_level & G_LOG_FLAG_FATAL) ? +                                                      GTK_MESSAGE_ERROR : GTK_MESSAGE_WARNING, +                                                    GTK_BUTTONS_CLOSE, +                                                    "<big><b>%s</b></big>\n\n%s", +                                                    (log_level & G_LOG_FLAG_FATAL) ? +                                                      "Fatal Error" : "Warning", +                                                    message); + +        gtk_dialog_run(GTK_DIALOG(dialog)); +        gtk_widget_destroy(dialog); +    } +} + +gboolean +ui_init(int *argc, char ***argv) +{ +    g_set_application_name("HardInfo"); +    g_log_set_handler(NULL, G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL | G_LOG_LEVEL_ERROR, +                      log_handler, NULL); +    return gtk_init_check(argc, argv); +} | 
