diff options
author | Burt P <pburt0@gmail.com> | 2017-07-25 06:24:47 -0500 |
---|---|---|
committer | Leandro Pereira <leandro@hardinfo.org> | 2017-07-30 10:16:42 -0700 |
commit | 03184de73de4adf8fcba09b8eac6b8c0a3f06aab (patch) | |
tree | 934ffbe93bd846ac95a1c57f2fed8871ee3b6e47 | |
parent | 6f8cedca0671ab68514352c64579546547804475 (diff) |
GTK3 updates
* Use gtk_widget_get_window() instead of ->window
cmake:
* add option to build against gtk3 `-DHARDINFO_GTK3=1`
* combine hardinfo-shell static library and hardinfo
* disable guibench for gtk3
hardinfo/util.c:
* widget_set_cursor() gtk3 changes
* For now, the whole function tree_view_save_image() is disabled
for gtk3.
shell/shell.c:
* add gtk_notebook_set_page() compatibility macro if not defined
* shell_summary_add_item() fixes
* Disable RANGE_GET_VALUE() RANGE_SET_VALUE() macros for GTK3. This
is a nigtmare onion to try and peel.
shell/callbacks.c:
* gtk_about_dialog_set_name() -> gtk_about_dialog_set_program_name()
after GTK+2.12.
shell/loadgraph.c:
* builds, but not yet functioning under gtk3
Signed-off-by: Burt P <pburt0@gmail.com>
-rw-r--r-- | CMakeLists.txt | 42 | ||||
-rw-r--r-- | hardinfo/util.c | 23 | ||||
-rwxr-xr-x | includes/loadgraph.h | 64 | ||||
-rwxr-xr-x | shell/callbacks.c | 12 | ||||
-rwxr-xr-x | shell/loadgraph.c | 182 | ||||
-rwxr-xr-x | shell/report.c | 66 | ||||
-rwxr-xr-x | shell/shell.c | 82 |
7 files changed, 268 insertions, 203 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ec1397be..04bc34c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ cmake_policy(VERSION 2.6) set(HARDINFO_VERSION "0.6-alpha") option(HARDINFO_NOSYNC "Disable database sync via libsoup" 1) +option(HARDINFO_GTK3 "Attempt to build for GTK3 (0/off for GTK2)" 0) set(OVRARCH "" CACHE STRING "Override HARDINFO_ARCH value") set(OVRCPUINFO "" CACHE STRING "Specify a different file for /proc/cpuinfo") set(OVRDTRROOT "" CACHE STRING "Specify a different path for /proc/device-tree") @@ -73,7 +74,15 @@ add_definitions("-std=gnu89") add_subdirectory(po) include(FindPkgConfig) -pkg_check_modules(GTK REQUIRED gtk+-2.0>=2.10 glib-2.0>=2.10 gthread-2.0>=2.10 gmodule-export-2.0>=2.10) +if (HARDINFO_GTK3) + message(STATUS "Building for GTK3 (experimental!)") + pkg_check_modules(GTK REQUIRED gtk+-3.0>=3.0 cairo>=1.0 cairo-png>=1.0 glib-2.0>=2.10 gthread-2.0>=2.10 gmodule-export-2.0>=2.10) + add_definitions(-DGTK_DISABLE_SINGLE_INCLUDES) +else() + message(STATUS "Building for GTK2") + pkg_check_modules(GTK REQUIRED gtk+-2.0>=2.10 glib-2.0>=2.10 gthread-2.0>=2.10 gmodule-export-2.0>=2.10) +endif() + if(NOT HARDINFO_NOSYNC) pkg_check_modules(LIBSOUP libsoup-2.4>=2.24) endif() @@ -145,7 +154,7 @@ set(MODULE_network_SOURCES modules/network/nfs.c modules/network/samba.c ) -set(MODULE_benchmark_SOURCES +set(MODULE_benchmark_SOURCES_GTKANY modules/benchmark.c modules/benchmark/blowfish.c modules/benchmark/cryptohash.c @@ -154,13 +163,20 @@ set(MODULE_benchmark_SOURCES modules/benchmark/fftbench.c modules/benchmark/fft.c modules/benchmark/fib.c - modules/benchmark/guibench.c modules/benchmark/md5.c modules/benchmark/nqueens.c modules/benchmark/raytrace.c modules/benchmark/sha1.c modules/benchmark/zlib.c ) +set(MODULE_benchmark_SOURCES_GTK2 + modules/benchmark/guibench.c +) +if (HARDINFO_GTK3) + set(MODULE_benchmark_SOURCES ${MODULE_benchmark_SOURCES_GTKANY}) +else() + set(MODULE_benchmark_SOURCES ${MODULE_benchmark_SOURCES_GTKANY} ${MODULE_network_SOURCES_GTK2}) +endif() set_source_files_properties( modules/benchmark/blowfish.c @@ -176,16 +192,6 @@ foreach (_module ${HARDINFO_MODULES}) set_target_properties(${_module} PROPERTIES PREFIX "") endforeach() -add_library(hardinfo-shell STATIC - shell/callbacks.c - shell/iconcache.c - shell/loadgraph.c - shell/menu.c - shell/report.c - shell/shell.c - shell/stock.c - shell/syncmanager.c -) add_executable(hardinfo hardinfo/binreloc.c hardinfo/expr.c @@ -193,11 +199,19 @@ add_executable(hardinfo hardinfo/socket.c hardinfo/util.c hardinfo/vendor.c + shell/callbacks.c + shell/iconcache.c + shell/loadgraph.c + shell/menu.c + shell/report.c + shell/shell.c + shell/stock.c + shell/syncmanager.c ) + target_link_libraries(hardinfo ${GTK_LIBRARIES} ${LIBSOUP_LIBRARIES} - hardinfo-shell m ${ZLIB_LIBRARIES} ) diff --git a/hardinfo/util.c b/hardinfo/util.c index d1329d24..cf6857f8 100644 --- a/hardinfo/util.c +++ b/hardinfo/util.c @@ -169,15 +169,30 @@ void remove_linefeed(gchar * str) void widget_set_cursor(GtkWidget * widget, GdkCursorType cursor_type) { GdkCursor *cursor; + GdkDisplay *display; +#if GTK_CHECK_VERSION(3, 0, 0) + GdkWindow *gdk_window; +#endif + + display = gtk_widget_get_display(widget); +#if GTK_CHECK_VERSION(3, 0, 0) + gdk_window = gtk_widget_get_window(widget); + if ((cursor = gdk_cursor_new_for_display(display, cursor_type))) { + gdk_window_set_cursor(gdk_window, cursor); + gdk_display_flush(display); + g_object_unref(cursor); + } +#else if ((cursor = gdk_cursor_new(cursor_type))) { gdk_window_set_cursor(GDK_WINDOW(widget->window), cursor); - gdk_display_flush(gtk_widget_get_display(widget)); + gdk_display_flush(display); gdk_cursor_unref(cursor); } +#endif while (gtk_events_pending()) - gtk_main_iteration(); + gtk_main_iteration(); } static gboolean __nonblock_cb(gpointer data) @@ -979,6 +994,9 @@ gint tree_view_get_visible_height(GtkTreeView * tv) void tree_view_save_image(gchar * filename) { +#if GTK_CHECK_VERSION(3, 0, 0) + /* TODO:GTK3 needs conversion for gtk3 */ +#else /* this is ridiculously complicated :/ why in the hell gtk+ makes this kind of thing so difficult? */ @@ -1074,6 +1092,7 @@ void tree_view_save_image(gchar * filename) g_free(tmp); gtk_widget_set_sensitive(widget, tv_enabled); +#endif } static gboolean __idle_free_do(gpointer ptr) diff --git a/includes/loadgraph.h b/includes/loadgraph.h index 2854cf01..6ea29113 100755 --- a/includes/loadgraph.h +++ b/includes/loadgraph.h @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Lesser General Public * License along with the Simple Load Graph; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307 USA. + * 02111-1307 USA. */ @@ -24,12 +24,6 @@ #include <stdlib.h> #include <gtk/gtk.h> #include <math.h> -/*#include <libintl.h> -#include <locale.h> -#define _(STRING) gettext(STRING) -#define N_(STRING) (STRING)*/ - - typedef struct _LoadGraph LoadGraph; @@ -42,50 +36,40 @@ typedef enum { struct _LoadGraph { #if GTK_CHECK_VERSION(3, 0, 0) cairo_surface_t *buf; -#else - GdkPixmap *buf; -#endif - GtkWidget *area; - -#if GTK_CHECK_VERSION(3, 0, 0) cairo_t *grid; -#else - GdkGC *grid; -#endif -#if GTK_CHECK_VERSION(3, 0, 0) cairo_t *trace; -#else - GdkGC *trace; -#endif -#if GTK_CHECK_VERSION(3, 0, 0) cairo_t *fill; #else - GdkGC *fill; + GdkPixmap *buf; + GdkGC *grid; + GdkGC *trace; + GdkGC *fill; #endif + GtkWidget *area; - gint *data; + gint *data; gfloat scale; - gint size; - gint width, height; - LoadGraphColor color; - - gint max_value, remax_count; - + gint size; + gint width, height; + LoadGraphColor color; + + gint max_value, remax_count; + PangoLayout *layout; - gchar *suffix; + gchar *suffix; }; -LoadGraph *load_graph_new(gint size); -void load_graph_destroy(LoadGraph *lg); -void load_graph_configure_expose(LoadGraph *lg); -GtkWidget *load_graph_get_framed(LoadGraph *lg); +LoadGraph *load_graph_new(gint size); +void load_graph_destroy(LoadGraph *lg); +void load_graph_configure_expose(LoadGraph *lg); +GtkWidget *load_graph_get_framed(LoadGraph *lg); -void load_graph_update(LoadGraph *lg, gint value); -void load_graph_set_color(LoadGraph *lg, LoadGraphColor color); -void load_graph_clear(LoadGraph *lg); +void load_graph_update(LoadGraph *lg, gint value); +void load_graph_set_color(LoadGraph *lg, LoadGraphColor color); +void load_graph_clear(LoadGraph *lg); -void load_graph_set_data_suffix(LoadGraph *lg, gchar *suffix); -gchar *load_graph_get_data_suffix(LoadGraph *lg); +void load_graph_set_data_suffix(LoadGraph *lg, gchar *suffix); +gchar *load_graph_get_data_suffix(LoadGraph *lg); -#endif /* __LOADGRAPH_H__ */ +#endif /* __LOADGRAPH_H__ */ diff --git a/shell/callbacks.c b/shell/callbacks.c index ecf2beac..6599975b 100755 --- a/shell/callbacks.c +++ b/shell/callbacks.c @@ -161,7 +161,11 @@ void cb_about_module(GtkAction * action) gtk_window_set_transient_for(GTK_WINDOW(about), GTK_WINDOW(shell->window)); text = g_strdup_printf(_("%s Module"), sm->name); +#if GTK_CHECK_VERSION(2, 12, 0) + gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(about), text); +#else gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(about), text); +#endif g_free(text); gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about), @@ -225,7 +229,13 @@ void cb_about() about = gtk_about_dialog_new(); gtk_window_set_transient_for(GTK_WINDOW(about), GTK_WINDOW(shell->window)); + +#if GTK_CHECK_VERSION(2, 12, 0) + gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(about), "HardInfo"); +#else gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(about), "HardInfo"); +#endif + gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about), VERSION); gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about), "Copyright \302\251 2003-2016 " @@ -274,6 +284,6 @@ void cb_quit(void) do { gtk_main_quit(); } while (gtk_main_level() > 1); - + exit(0); } diff --git a/shell/loadgraph.c b/shell/loadgraph.c index b8720464..e78524ca 100755 --- a/shell/loadgraph.c +++ b/shell/loadgraph.c @@ -20,7 +20,7 @@ * You should have received a copy of the GNU Lesser General Public * License along with the Simple Load Graph; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307 USA. + * 02111-1307 USA. */ #include "loadgraph.h" @@ -89,7 +89,7 @@ void load_graph_clear(LoadGraph * lg) gint i; for (i = 0; i < lg->size; i++) - lg->data[i] = 0; + lg->data[i] = 0; lg->scale = 1.0; lg->max_value = 1; @@ -101,39 +101,44 @@ void load_graph_clear(LoadGraph * lg) void load_graph_set_color(LoadGraph * lg, LoadGraphColor color) { lg->color = color; +#if GTK_CHECK_VERSION(3, 0, 0) +#define UNPACK_COLOR(C) (((C)>>16) & 0xff), (((C)>>8) & 0xff), ((C) & 0xff) + cairo_set_source_rgb(lg->trace, UNPACK_COLOR(lg->color) ); + cairo_set_source_rgb(lg->fill, UNPACK_COLOR(lg->color - 0x303030) ); + cairo_set_source_rgb(lg->grid, UNPACK_COLOR(lg->color - 0xcdcdcd) ); +#else gdk_rgb_gc_set_foreground(lg->trace, lg->color); gdk_rgb_gc_set_foreground(lg->fill, lg->color - 0x303030); gdk_rgb_gc_set_foreground(lg->grid, lg->color - 0xcdcdcd); +#endif } void load_graph_destroy(LoadGraph * lg) { - g_free(lg->data); - gtk_widget_destroy(lg->area); +#if GTK_CHECK_VERSION(3, 0, 0) + g_object_unref(lg->buf); +#else gdk_pixmap_unref(lg->buf); +#endif g_object_unref(lg->trace); g_object_unref(lg->grid); g_object_unref(lg->fill); g_object_unref(lg->layout); + gtk_widget_destroy(lg->area); + g_free(lg->data); g_free(lg); } -static gboolean _expose(GtkWidget * widget, GdkEventExpose * event, - gpointer user_data) +static gboolean _expose(GtkWidget * widget, GdkEventExpose * event, gpointer user_data) { LoadGraph *lg = (LoadGraph *) user_data; #if GTK_CHECK_VERSION(3, 0, 0) - cairo_t *draw = GDK_WINDOW(lg->buf); + /* TODO:GTK3 copy from lg->buf or lg->area? to widget? */ #else GdkDrawable *draw = GDK_DRAWABLE(lg->buf); -#endif - cairo_t *cr; -#if GTK_CHECK_VERSION(3, 0, 0) - gdk_cairo_set_source_window(cr, lg->area, 0, 0); -#else gdk_draw_drawable(lg->area->window, - lg->area->style->black_gc, - draw, 0, 0, 0, 0, lg->width, lg->height); + lg->area->style->black_gc, + draw, 0, 0, 0, 0, lg->width, lg->height); #endif return FALSE; } @@ -144,15 +149,18 @@ void load_graph_configure_expose(LoadGraph * lg) gtk_widget_realize(lg->area); #if GTK_CHECK_VERSION(3, 0, 0) cairo_content_t content; - lg->buf = gdk_window_create_similar_surface(lg->area, CAIRO_CONTENT_COLOR, lg->width, lg->height); + GdkWindow *gdk_window = gtk_widget_get_window(lg->area); + lg->buf = gdk_window_create_similar_surface(gdk_window, CAIRO_CONTENT_COLOR, lg->width, lg->height); + lg->grid = cairo_create(lg->buf); + lg->trace = cairo_create(lg->buf); + lg->fill = cairo_create(lg->buf); #else lg->buf = gdk_pixmap_new(lg->area->window, lg->width, lg->height, -1); -#endif - /* create the graphic contexts */ lg->grid = gdk_gc_new(GDK_DRAWABLE(lg->buf)); lg->trace = gdk_gc_new(GDK_DRAWABLE(lg->buf)); lg->fill = gdk_gc_new(GDK_DRAWABLE(lg->buf)); +#endif /* the default color is green */ load_graph_set_color(lg, LG_COLOR_GREEN); @@ -165,12 +173,12 @@ void load_graph_configure_expose(LoadGraph * lg) cairo_set_dash(lg->grid, 0, (gint8*)"\2\2", 2); #else gdk_gc_set_line_attributes(lg->grid, - 1, GDK_LINE_ON_OFF_DASH, - GDK_CAP_NOT_LAST, GDK_JOIN_ROUND); + 1, GDK_LINE_ON_OFF_DASH, + GDK_CAP_NOT_LAST, GDK_JOIN_ROUND); gdk_gc_set_dashes(lg->grid, 0, (gint8*)"\2\2", 2); #endif - -#if 0 /* old-style grid */ + +#if 0 /* old-style grid */ gdk_rgb_gc_set_foreground(lg->grid, 0x707070); #endif @@ -180,47 +188,61 @@ void load_graph_configure_expose(LoadGraph * lg) cairo_set_line_join(lg->trace, CAIRO_LINE_JOIN_MITER); #else gdk_gc_set_line_attributes(lg->trace, - 1, GDK_LINE_SOLID, - GDK_CAP_PROJECTING, GDK_JOIN_ROUND); + 1, GDK_LINE_SOLID, + GDK_CAP_PROJECTING, GDK_JOIN_ROUND); #endif -#if 0 /* old-style fill */ +#if 0 /* old-style fill */ gdk_gc_set_line_attributes(lg->fill, - 1, GDK_LINE_SOLID, - GDK_CAP_BUTT, GDK_JOIN_BEVEL); + 1, GDK_LINE_SOLID, + GDK_CAP_BUTT, GDK_JOIN_BEVEL); #endif +#if GTK_CHECK_VERSION(3, 0, 0) + /* configures the draw event */ + g_signal_connect(G_OBJECT(lg->area), "draw", + (GCallback) _expose, lg); +#else /* configures the expose event */ g_signal_connect(G_OBJECT(lg->area), "expose-event", - (GCallback) _expose, lg); + (GCallback) _expose, lg); +#endif } +#if GTK_CHECK_VERSION(3, 0, 0) +#define _draw_line(D, CR, X1, Y1, X2, Y2) \ + cairo_move_to(CR, X1, Y1); \ + cairo_line_to(CR, X2, Y2); +#else +#define _draw_line(D, GC, X1, Y1, X2, Y2) gdk_draw_line(D, GC, X1, Y1, X2, Y2) +#endif + static void _draw_label_and_line(LoadGraph * lg, gint position, gint value) { gchar *tmp; /* draw lines */ - if (position > 0) - gdk_draw_line(GDK_DRAWABLE(lg->buf), lg->grid, 0, position, - lg->width, position); - else - position = -1 * position; + if (position > 0) { + _draw_line(GDK_DRAWABLE(lg->buf), lg->grid, 0, position, + lg->width, position); + } else + position = -1 * position; /* draw label */ tmp = - g_strdup_printf("<span size=\"x-small\">%d%s</span>", value, - lg->suffix); + g_strdup_printf("<span size=\"x-small\">%d%s</span>", value, + lg->suffix); pango_layout_set_markup(lg->layout, tmp, -1); #if GTK_CHECK_VERSION(3, 0, 0) pango_layout_set_width(lg->layout, - lg->width * PANGO_SCALE); - gtk_widget_create_pango_layout(GDK_WINDOW(lg->buf), NULL); + lg->width * PANGO_SCALE); + gtk_widget_create_pango_layout(lg->area, NULL); #else pango_layout_set_width(lg->layout, - lg->area->allocation.width * PANGO_SCALE); + lg->area->allocation.width * PANGO_SCALE); gdk_draw_layout(GDK_DRAWABLE(lg->buf), lg->trace, 2, position, - lg->layout); + lg->layout); #endif g_free(tmp); @@ -229,7 +251,7 @@ static void _draw_label_and_line(LoadGraph * lg, gint position, gint value) static void _draw(LoadGraph * lg) { #if GTK_CHECK_VERSION(3, 0, 0) - cairo_t *draw = GDK_WINDOW(lg->buf); + void *draw = NULL; /* not used by cairo */ #else GdkDrawable *draw = GDK_DRAWABLE(lg->buf); #endif @@ -237,10 +259,11 @@ static void _draw(LoadGraph * lg) /* clears the drawing area */ #if GTK_CHECK_VERSION(3, 0, 0) - cairo_rectangle(draw, 0, 0, lg->width, lg->height); + cairo_rectangle(lg->fill, 0, 0, lg->width, lg->height); + cairo_fill (lg->fill); #else gdk_draw_rectangle(draw, lg->area->style->black_gc, - TRUE, 0, 0, lg->width, lg->height); + TRUE, 0, 0, lg->width, lg->height); #endif @@ -248,23 +271,28 @@ static void _draw(LoadGraph * lg) GdkPoint *points = g_new0(GdkPoint, lg->size + 1); for (i = 0; i < lg->size; i++) { - points[i].x = i * 4; - points[i].y = lg->height - lg->data[i] * lg->scale; + points[i].x = i * 4; + points[i].y = lg->height - lg->data[i] * lg->scale; } points[0].x = points[1].x = 0; points[0].y = points[i].y = lg->height; points[i].x = points[i - 1].x = lg->width; +#if GTK_CHECK_VERSION(3, 0, 0) + /* TODO:GTK3 draw using loop and _draw_line() */ +#else gdk_draw_polygon(draw, lg->fill, TRUE, points, lg->size + 1); gdk_draw_polygon(draw, lg->trace, FALSE, points, lg->size + 1); +#endif g_free(points); /* vertical bars */ for (i = lg->width, d = 0; i > 1; i--, d++) - if ((d % 45) == 0 && d) - gdk_draw_line(draw, lg->grid, i, 0, i, lg->height); + if ((d % 45) == 0 && d) { + _draw_line(draw, lg->grid, i, 0, i, lg->height); + } /* horizontal bars and labels; 25%, 50% and 75% */ _draw_label_and_line(lg, -1, lg->max_value); @@ -272,25 +300,25 @@ static void _draw(LoadGraph * lg) _draw_label_and_line(lg, lg->height / 2, lg->max_value / 2); _draw_label_and_line(lg, 3 * (lg->height / 4), lg->max_value / 4); -#if 0 /* old-style drawing */ +#if 0 /* old-style drawing */ for (i = 0; i < lg->size; i++) { - gint this = lg->height - lg->data[i] * lg->scale; - gint next = lg->height - lg->data[i + 1] * lg->scale; - gint i4 = i * 4; + gint this = lg->height - lg->data[i] * lg->scale; + gint next = lg->height - lg->data[i + 1] * lg->scale; + gint i4 = i * 4; - gdk_draw_line(draw, lg->fill, i4, this, i4, lg->height); - gdk_draw_line(draw, lg->fill, i4 + 2, this, i4 + 2, lg->height); + _draw_line(draw, lg->fill, i4, this, i4, lg->height); + _draw_line(draw, lg->fill, i4 + 2, this, i4 + 2, lg->height); } for (i = 0; i < lg->size; i++) { - gint this = lg->height - lg->data[i] * lg->scale; - gint next = lg->height - lg->data[i + 1] * lg->scale; - gint i4 = i * 4; - - gdk_draw_line(draw, lg->trace, i4, this, i4 + 2, - (this + next) / 2); - gdk_draw_line(draw, lg->trace, i4 + 2, (this + next) / 2, - i4 + 4, next); + gint this = lg->height - lg->data[i] * lg->scale; + gint next = lg->height - lg->data[i + 1] * lg->scale; + gint i4 = i * 4; + + _draw_line(draw, lg->trace, i4, this, i4 + 2, + (this + next) / 2); + _draw_line(draw, lg->trace, i4 + 2, (this + next) / 2, + i4 + 4, next); } #endif @@ -302,11 +330,11 @@ void load_graph_update(LoadGraph * lg, gint value) gint i; if (value < 0) - return; + return; /* shift-right our data */ for (i = 0; i < lg->size - 1; i++) { - lg->data[i] = lg->data[i + 1]; + lg->data[i] = lg->data[i + 1]; } /* insert the updated value */ @@ -314,20 +342,20 @@ void load_graph_update(LoadGraph * lg, gint value) /* calculates the maximum value */ if (lg->remax_count++ > 20) { - /* only finds the maximum amongst the data every 20 times */ - lg->remax_count = 0; + /* only finds the maximum amongst the data every 20 times */ + lg->remax_count = 0; - gint max = lg->data[0]; - for (i = 1; i < lg->size; i++) { - if (lg->data[i] > max) - max = lg->data[i]; - } + gint max = lg->data[0]; + for (i = 1; i < lg->size; i++) { + if (lg->data[i] > max) + max = lg->data[i]; + } - lg->max_value = max; + lg->max_value = max; } else { - /* otherwise, select the maximum between the current maximum - and the supplied value */ - lg->max_value = MAX(value, lg->max_value); + /* otherwise, select the maximum between the current maximum + and the supplied value */ + lg->max_value = MAX(value, lg->max_value); } /* recalculates the scale; always use 90% of it */ @@ -346,16 +374,16 @@ gboolean lg_update(gpointer d) static int j = 1; if (i > 150) { - j = -1; + j = -1; } else if (i < 0) { - j = 1; + j = 1; } i += j; if (rand() % 10 > 8) - i *= 2; + i *= 2; if (rand() % 10 < 2) - i /= 2; + i /= 2; load_graph_update(lg, i + rand() % 50); return TRUE; @@ -363,8 +391,6 @@ gboolean lg_update(gpointer d) int main(int argc, char **argv) { - - LoadGraph *lg; GtkWidget *window; diff --git a/shell/report.c b/shell/report.c index 5d325ff9..0f3412a3 100755 --- a/shell/report.c +++ b/shell/report.c @@ -67,7 +67,7 @@ void report_key_value(ReportContext * ctx, gchar * key, gchar * value) gint report_get_visible_columns(ReportContext *ctx) { gint columns; - + /* Column count starts at two, since we always have at least two columns visible. */ columns = 2; @@ -77,10 +77,10 @@ gint report_get_visible_columns(ReportContext *ctx) if (ctx->columns & REPORT_COL_EXTRA1) columns++; - + if (ctx->columns & REPORT_COL_EXTRA2) columns++; - + return columns; } @@ -88,7 +88,7 @@ void report_context_configure(ReportContext * ctx, GKeyFile * keyfile) { gchar **keys; const gchar *group = "$ShellParam$"; - + /* FIXME: sometime in the future we'll save images in the report. this flag will be set if we should support that. @@ -100,19 +100,19 @@ void report_context_configure(ReportContext * ctx, GKeyFile * keyfile) "ViewType", NULL) == SHELL_VIEW_PROGRESS); - + keys = g_key_file_get_keys(keyfile, group, NULL, NULL); if (keys) { gint i = 0; - + for (; keys[i]; i++) { gchar *key = keys[i]; - + if (g_str_equal(key, "ShowColumnHeaders")) { ctx->show_column_headers = g_key_file_get_boolean(keyfile, group, key, NULL); } else if (g_str_has_prefix(key, "ColumnTitle")) { gchar *value, *title = strchr(key, '$'); - + if (!title) { DEBUG("couldn't find column title"); break; @@ -135,20 +135,20 @@ void report_context_configure(ReportContext * ctx, GKeyFile * keyfile) } else if (g_str_equal(title, "Progress")) { ctx->columns |= REPORT_COL_PROGRESS; } - + g_hash_table_replace(ctx->column_titles, g_strdup(title), g_strdup(value)); } else if (g_str_equal(key, "ViewType")) { if (g_key_file_get_integer(keyfile, group, "ViewType", NULL) == SHELL_VIEW_PROGRESS) { ctx->columns &= ~REPORT_COL_VALUE; ctx->columns |= REPORT_COL_PROGRESS; - } + } } } - g_strfreev(keys); + g_strfreev(keys); } - + } void report_table(ReportContext * ctx, gchar * text) @@ -164,7 +164,7 @@ void report_table(ReportContext * ctx, gchar * text) /**/ g_key_file_load_from_data(key_file, text, strlen(text), 0, NULL); groups = g_key_file_get_groups(key_file, NULL); - + for (i = 0; groups[i]; i++) { if (groups[i][0] == '$') { report_context_configure(ctx, key_file); @@ -209,7 +209,7 @@ void report_table(ReportContext * ctx, gchar * text) value = g_strdup("..."); } } - + if (*key == '$') { report_key_value(ctx, strchr(key + 1, '$') + 1, value); @@ -301,7 +301,7 @@ report_html_key_value(ReportContext * ctx, gchar * key, gchar * value) gint columns = report_get_visible_columns(ctx); gchar **values; gint i; - + if (columns == 2) { ctx->output = h_strdup_cprintf("<tr><td class=\"field\">%s</td>" "<td class=\"value\">%s</td></tr>\n", @@ -309,9 +309,9 @@ report_html_key_value(ReportContext * ctx, gchar * key, gchar * value) key, value); } else { values = g_strsplit(value, "|", columns); - + ctx->output = h_strdup_cprintf("\n<tr>\n<td class=\"field\">%s</td>", ctx->output, key); - + for (i = columns - 2; i >= 0; i--) { ctx->output = h_strdup_cprintf("<td class=\"value\">%s</td>", ctx->output, @@ -319,7 +319,7 @@ report_html_key_value(ReportContext * ctx, gchar * key, gchar * value) } ctx->output = h_strdup_cprintf("</tr>\n", ctx->output); - + g_strfreev(values); } } @@ -372,7 +372,7 @@ report_text_key_value(ReportContext * ctx, gchar * key, gchar * value) gint columns = report_get_visible_columns(ctx); gchar **values; gint i; - + if (columns == 2) { if (strlen(value)) ctx->output = h_strdup_cprintf("%s\t\t: %s\n", ctx->output, key, value); @@ -380,9 +380,9 @@ report_text_key_value(ReportContext * ctx, gchar * key, gchar * value) ctx->output = h_strdup_cprintf("%s\n", ctx->output, key); } else { values = g_strsplit(value, "|", columns); - + ctx->output = h_strdup_cprintf("%s\t", ctx->output, key); - + for (i = columns - 2; i >= 0; i--) { ctx->output = h_strdup_cprintf("%s\t", ctx->output, @@ -390,7 +390,7 @@ report_text_key_value(ReportContext * ctx, gchar * key, gchar * value) } ctx->output = h_strdup_cprintf("\n", ctx->output); - + g_strfreev(values); } } @@ -558,7 +558,7 @@ ReportContext *report_context_text_new() ctx->output = g_strdup(""); ctx->format = REPORT_FORMAT_TEXT; - + ctx->column_titles = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); ctx->first_table = TRUE; @@ -657,10 +657,10 @@ static gboolean report_generate(ReportDialog * rd) #endif if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { gchar *temp; - + temp = g_strdup_printf("file://%s", file); open_url(temp); - + g_free(temp); } @@ -760,7 +760,7 @@ report_dialog_sel_toggle(GtkCellRendererToggle * cellrenderertoggle, if (active) { GtkTreeIter parent; - + if (gtk_tree_model_iter_parent(model, &parent, &iter)) { gtk_tree_store_set(GTK_TREE_STORE(model), &parent, TREE_COL_SEL, active, -1); @@ -803,8 +803,7 @@ static ReportDialog GDK_WINDOW_TYPE_HINT_DIALOG); #if GTK_CHECK_VERSION(3, 0, 0) - /*dialog1_vbox = GTK_BOX(GTK_DIALOG(dialog)->vbox);*/ - dialog1_vbox = GTK_DIALOG(dialog)/*->vbox*/; + dialog1_vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); #else dialog1_vbox = GTK_DIALOG(dialog)->vbox; #endif @@ -825,7 +824,7 @@ static ReportDialog gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); gtk_label_set_use_markup(GTK_LABEL(label), TRUE); #if GTK_CHECK_VERSION(3, 0, 0) - gtk_widget_set_valign(GTK_LABEL(label), GTK_ALIGN_CENTER); + gtk_widget_set_valign(label, GTK_ALIGN_CENTER); #else gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); #endif @@ -914,7 +913,12 @@ static ReportDialog rd); #if GTK_CHECK_VERSION(3, 0, 0) - dialog1_action_area = GTK_DIALOG(dialog)/*->action_area*/; +/* TODO:GTK3 + * [https://developer.gnome.org/gtk3/stable/GtkDialog.html#gtk-dialog-get-action-area] + * gtk_dialog_get_action_area has been deprecated since version 3.12 and should not be used in newly-written code. + * Direct access to the action area is discouraged; use gtk_dialog_add_button(), etc. + */ + dialog1_action_area = gtk_dialog_get_action_area(GTK_DIALOG(dialog)); #else dialog1_action_area = GTK_DIALOG(dialog)->action_area; #endif @@ -923,7 +927,7 @@ static ReportDialog GTK_BUTTONBOX_END); #if GTK_CHECK_VERSION(3, 0, 0) - button8 = gtk_button_new_with_label("_Cancel"); + button8 = gtk_button_new_with_mnemonic(_("_Cancel")); #else button8 = gtk_button_new_from_stock(GTK_STOCK_CANCEL); #endif diff --git a/shell/shell.c b/shell/shell.c index b4532782..539b55ea 100755 --- a/shell/shell.c +++ b/shell/shell.c @@ -33,6 +33,10 @@ #include "callbacks.h" +#ifndef gtk_notebook_set_page +#define gtk_notebook_set_page(P, N) gtk_notebook_set_current_page(P, N) +#endif + /* * Internal Prototypes ******************************************************** */ @@ -844,6 +848,9 @@ static gboolean update_field(gpointer data) static gboolean reload_section(gpointer data) { ShellModuleEntry *entry = (ShellModuleEntry *) data; +#if GTK_CHECK_VERSION(3, 0, 0) + GdkWindow *gdk_window = gtk_widget_get_window(GTK_WIDGET(shell->window)); +#endif /* if the entry is still selected, update it */ if (entry->selected) { @@ -852,14 +859,18 @@ static gboolean reload_section(gpointer data) double pos_info_scroll, pos_more_scroll; /* save current position */ +#if GTK_CHECK_VERSION(3, 0, 0) + /* TODO:GTK3 */ +#else #if GTK_CHECK_VERSION(2, 0, 0) pos_info_scroll = RANGE_GET_VALUE(info, vscrollbar); pos_more_scroll = RANGE_GET_VALUE(moreinfo, vscrollbar); #endif +#endif /* avoid drawing the window while we reload */ #if GTK_CHECK_VERSION(3, 0, 0) - gdk_window_freeze_updates(shell->window/*->window*/); + gdk_window_freeze_updates(gdk_window); #else gdk_window_freeze_updates(shell->window->window); #endif @@ -883,13 +894,17 @@ static gboolean reload_section(gpointer data) gtk_tree_path_free(path); } else { /* restore position */ +#if GTK_CHECK_VERSION(3, 0, 0) + /* TODO:GTK3 */ +#else RANGE_SET_VALUE(info, vscrollbar, pos_info_scroll); RANGE_SET_VALUE(moreinfo, vscrollbar, pos_more_scroll); +#endif } /* make the window drawable again */ #if GTK_CHECK_VERSION(3, 0, 0) - gdk_window_thaw_updates(shell->window/*->window*/); + gdk_window_thaw_updates(gdk_window); #else gdk_window_thaw_updates(shell->window->window); #endif @@ -944,6 +959,10 @@ info_tree_compare_val_func(GtkTreeModel * model, static void set_view_type(ShellViewType viewtype, gboolean reload) { +#if GTK_CHECK_VERSION(3, 0, 0) + GtkAllocation* alloc; +#endif + if (viewtype < SHELL_VIEW_NORMAL || viewtype >= SHELL_VIEW_N_VIEWS) viewtype = SHELL_VIEW_NORMAL; @@ -989,27 +1008,31 @@ static void set_view_type(ShellViewType viewtype, gboolean reload) case SHELL_VIEW_DUAL: gtk_widget_show(shell->info->scroll); gtk_widget_show(shell->moreinfo->scroll); - gtk_notebook_set_page(GTK_NOTEBOOK(shell->notebook), 0); - gtk_widget_show(shell->notebook); + gtk_notebook_set_page(GTK_NOTEBOOK(shell->notebook), 0); + gtk_widget_show(shell->notebook); #if GTK_CHECK_VERSION(3, 0, 0) - gtk_paned_set_position(GTK_PANED(shell->vpaned), - shell->hpaned/*->allocation.height / 2*/); + alloc = g_new(GtkAllocation, 1); + gtk_widget_get_allocation(shell->hpaned, alloc); + gtk_paned_set_position(GTK_PANED(shell->vpaned), alloc->height / 2); + g_free(alloc); #else gtk_paned_set_position(GTK_PANED(shell->vpaned), - shell->hpaned->allocation.height / 2); + shell->hpaned->allocation.height / 2); #endif - break; + break; case SHELL_VIEW_LOAD_GRAPH: gtk_widget_show(shell->info->scroll); - gtk_notebook_set_page(GTK_NOTEBOOK(shell->notebook), 1); - gtk_widget_show(shell->notebook); - load_graph_clear(shell->loadgraph); + gtk_notebook_set_page(GTK_NOTEBOOK(shell->notebook), 1); + gtk_widget_show(shell->notebook); + load_graph_clear(shell->loadgraph); #if GTK_CHECK_VERSION(3, 0, 0) - gtk_paned_set_position(GTK_PANED(shell->vpaned), - shell->hpaned/*->allocation.height*/ - - shell->loadgraph->height - 16); + alloc = g_new(GtkAllocation, 1); + gtk_widget_get_allocation(shell->hpaned, alloc); + gtk_paned_set_position(GTK_PANED(shell->vpaned), + alloc->height - shell->loadgraph->height - 16); + g_free(alloc); #else gtk_paned_set_position(GTK_PANED(shell->vpaned), shell->hpaned->allocation.height - @@ -1389,13 +1412,16 @@ module_selected_show_info(ShellModuleEntry * entry, gboolean reload) gboolean has_shell_param = FALSE; gint i; gsize ngroups; +#if GTK_CHECK_VERSION(3, 0, 0) + GdkWindow *gdk_window = gtk_widget_get_window(GTK_WIDGET(shell->info->view)); +#endif module_entry_scan(entry); key_data = module_entry_function(entry); /* */ #if GTK_CHECK_VERSION(3, 0, 0) - gdk_window_freeze_updates(shell->info->view/*->window*/); + gdk_window_freeze_updates(gdk_window); #else gdk_window_freeze_updates(shell->info->view->window); #endif @@ -1450,7 +1476,7 @@ module_selected_show_info(ShellModuleEntry * entry, gboolean reload) gtk_tree_view_expand_all(GTK_TREE_VIEW(shell->info->view)); #if GTK_CHECK_VERSION(3, 0, 0) - gdk_window_thaw_updates(shell->info->view/*->window*/); + gdk_window_thaw_updates(gdk_window); #else gdk_window_thaw_updates(shell->info->view->window); #endif @@ -1601,29 +1627,14 @@ static void shell_summary_add_item(ShellSummary *summary, gtk_box_pack_start(GTK_BOX(frame_label_box), frame_image, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(frame_label_box), frame_label, FALSE, FALSE, 0); -#if GTK_CHECK_VERSION(3, 0, 0) - gtk_widget_set_halign(alignment, GTK_ALIGN_CENTER); - gtk_widget_set_valign(alignment, GTK_ALIGN_CENTER); -#else + /* TODO:GTK3 gtk_alignment_new(), etc is deprecated from 3.14 */ alignment = gtk_alignment_new(0.5, 0.5, 1, 1); -#endif + gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 0, 48, 0); gtk_widget_show(alignment); gtk_container_add(GTK_CONTAINER(frame), alignment); -#if GTK_CHECK_VERSION(3, 0, 0) - gtk_widget_set_margin_top(alignment, 0); - gtk_widget_set_margin_bottom(alignment, 0); - gtk_widget_set_margin_start(alignment, 48); - gtk_widget_set_margin_end(alignment, 0); -#else - gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 0, 48, 0); -#endif content = gtk_label_new(temp); -#if GTK_CHECK_VERSION(3, 0, 0) - gtk_widget_set_valign(GTK_MISC(content), GTK_ALIGN_CENTER); -#else gtk_misc_set_alignment(GTK_MISC(content), 0.0, 0.5); -#endif gtk_container_add(GTK_CONTAINER(alignment), content); gtk_widget_show_all(frame); @@ -1780,10 +1791,7 @@ static void module_selected(gpointer data) /* urgh. why don't GTK do this when the model is cleared? */ #if GTK_CHECK_VERSION(3, 0, 0) - RANGE_SET_VALUE(info, vscrollbar, 0.0); - RANGE_SET_VALUE(info, hscrollbar, 0.0); - RANGE_SET_VALUE(moreinfo, vscrollbar, 0.0); - RANGE_SET_VALUE(moreinfo, hscrollbar, 0.0); + /* TODO:GTK3 */ #else RANGE_SET_VALUE(info, vscrollbar, 0.0); RANGE_SET_VALUE(info, hscrollbar, 0.0); |