Skip to content

Commit

Permalink
Merge pull request 'Switch to gtk3 by default for gtk-lshw' (#37) fro…
Browse files Browse the repository at this point in the history
…m linkmauve/lshw:gtk3 into master

Reviewed-on: https://ezix.org/src/pkg/lshw/pulls/37
  • Loading branch information
lyonel committed Jul 29, 2020
2 parents e6a0a16 + a116b31 commit 9ae06b4
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 164 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Installation
- a PA-RISC-, Alpha-, IA-64- (Itanium-), PowerPC-, ARM- or x86- based machine
- an ANSI (or close enough to ANSI compliance) C++ compiler (tested with g++ 2.95.4 and 3.x)
- for the (optional) GTK+ graphical user interface, you will need a
complete GTK+ development environment (gtk2-devel on RedHat/Fedora derivatives)
complete GTK+ development environment (gtk3-devel on RedHat/Fedora derivatives)

2. To compile it, just use:

Expand Down
4 changes: 2 additions & 2 deletions lshw.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ http://lshw.ezix.org/
Summary: HardWare LiSter (GUI version)
Group: Applications/System
Requires: %{name} >= %{version}
Requires: gtk2 >= 2.4
BuildRequires: gtk2-devel >= 2.4
Requires: gtk3 >= 3.24
BuildRequires: gtk3-devel >= 3.24

%description gui
lshw (Hardware Lister) is a small tool to provide detailed informaton on
Expand Down
4 changes: 2 additions & 2 deletions src/gui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ STRIP?=strip
OBJCOPY?=objcopy

DEFINES=-DPREFIX=\"$(PREFIX)\" -DSBINDIR=\"$(SBINDIR)\" -DMANDIR=\"$(MANDIR)\" -DDATADIR=\"$(DATADIR)\"
GTKINCLUDES=$(shell pkg-config gtk+-2.0 --cflags)
GTKINCLUDES=$(shell pkg-config gtk+-3.0 --cflags)
INCLUDES=-I../core $(GTKINCLUDES)
CXXFLAGS=-g -Wall $(INCLUDES) $(DEFINES) $(RPM_OPT_FLAGS)
ifeq ($(SQLITE), 1)
CXXFLAGS+= -DSQLITE $(shell pkg-config --cflags sqlite3)
endif
CFLAGS=$(CXXFLAGS) -g $(DEFINES)
GTKLIBS=$(shell pkg-config gtk+-2.0 gmodule-2.0 --libs)
GTKLIBS=$(shell pkg-config gtk+-3.0 gmodule-2.0 --libs)
LIBS+=-L../core -llshw -lresolv $(GTKLIBS)
ifeq ($(SQLITE), 1)
LIBS+= $(shell pkg-config --libs sqlite3)
Expand Down
62 changes: 31 additions & 31 deletions src/gui/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,51 @@ static char *id = "@(#) $Id$";

G_MODULE_EXPORT
void
refresh_display (GtkMenuItem *menuitem,
gpointer user_data)
on_go_up_activated (GSimpleAction *action,
GVariant *parameter,
gpointer app)
{
go_back(mainwindow);
}

G_MODULE_EXPORT
void
on_refresh_activated (GSimpleAction *action,
GVariant *parameter,
gpointer app)
{
refresh(mainwindow);
}

G_MODULE_EXPORT
void
on_save_activated (GSimpleAction *action,
GVariant *parameter,
gpointer app)
{
save_as(mainwindow);
}

G_MODULE_EXPORT
void
on_about1_activate (GtkMenuItem *menuitem,
gpointer user_data)
on_about_activated (GSimpleAction *action,
GVariant *parameter,
gpointer app)
{
if(GTK_IS_WIDGET(about))
{
gtk_widget_show(about);
}
}

G_MODULE_EXPORT
void
on_quit_activated (GSimpleAction *action,
GVariant *parameter,
gpointer app)
{
g_application_quit(G_APPLICATION(app));
}

G_MODULE_EXPORT
void
Expand Down Expand Up @@ -147,37 +174,10 @@ gpointer user_data)
}


G_MODULE_EXPORT
void
go_up (GtkToolButton *toolbutton,
gpointer user_data)
{
go_back(mainwindow);
}


G_MODULE_EXPORT
void
on_lshw_map (GtkWidget *widget,
gpointer user_data)
{
refresh(mainwindow);
}

G_MODULE_EXPORT
void
on_save_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
save_as(mainwindow);
}


G_MODULE_EXPORT
void
on_savebutton_clicked (GtkToolButton *toolbutton,
gpointer user_data)
{
on_save_activate(NULL, NULL);
}

35 changes: 23 additions & 12 deletions src/gui/callbacks.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
#include <gtk/gtk.h>

void refresh_display (GtkMenuItem * menuitem, gpointer user_data);
void
on_go_up_activated (GSimpleAction *action,
GVariant *parameter,
gpointer app);

void
on_refresh_activated (GSimpleAction *action,
GVariant *parameter,
gpointer app);

void on_about1_activate (GtkMenuItem * menuitem, gpointer user_data);
void
on_save_activated (GSimpleAction *action,
GVariant *parameter,
gpointer app);

void
on_about_activated (GSimpleAction *action,
GVariant *parameter,
gpointer app);

void
on_quit_activated (GSimpleAction *action,
GVariant *parameter,
gpointer app);

void on_aboutclose_activate (GtkButton * button, gpointer user_data);

Expand Down Expand Up @@ -35,14 +56,4 @@ void on_treeview2_cursor_changed (GtkTreeView * treeview, gpointer user_data);

void on_treeview3_cursor_changed (GtkTreeView * treeview, gpointer user_data);

void go_up (GtkToolButton * toolbutton, gpointer user_data);

void on_lshw_map (GtkWidget * widget, gpointer user_data);

void
on_save_activate (GtkMenuItem *menuitem,
gpointer user_data);

void
on_savebutton_clicked (GtkToolButton *toolbutton,
gpointer user_data);
44 changes: 17 additions & 27 deletions src/gui/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ static hwNode *selected3 = NULL;
extern GtkWidget *mainwindow;
extern GtkWidget *list1, *list2, *list3;
extern GtkWidget *description;
extern GtkWidget *go_up_button;
extern GtkWidget *save_button;
extern GtkWidget *statusbar;
extern GHashTable *pixbufs;
extern GSimpleAction *go_up_action;
extern GSimpleAction *save_action;

enum
{
Expand Down Expand Up @@ -224,7 +225,7 @@ static void display(GtkWidget * mainwindow)
create_tags(buffer);

string hwpath = gethwpath(*displayed, container);
printmarkup(*displayed, GTK_TEXT_VIEW(description), hwpath);
printmarkup(*displayed, GTK_TEXT_VIEW(description), hwpath, pixbufs);
}
}

Expand All @@ -250,14 +251,11 @@ void refresh(GtkWidget *mainwindow)
{
hwNode computer("computer", hw::system);
static bool lock = false;
//GtkWidget * menu = lookup_widget(mainwindow, "menu");
//GtkWidget * save_menuitem = lookup_widget(menu, "save");

if(lock) return;

lock = true;
gtk_widget_set_sensitive(save_button, FALSE);
//gtk_widget_set_sensitive(save_menuitem, FALSE);
g_simple_action_set_enabled(save_action, FALSE);

populate_sublist(list1, NULL);
populate_sublist(list2, NULL);
Expand All @@ -272,9 +270,8 @@ void refresh(GtkWidget *mainwindow)
status(NULL);
displayed = container.addChild(computer);

gtk_widget_set_sensitive(go_up_button, FALSE);
gtk_widget_set_sensitive(save_button, TRUE);
//gtk_widget_set_sensitive(save_menuitem, TRUE);
g_simple_action_set_enabled(go_up_action, FALSE);
g_simple_action_set_enabled(save_action, TRUE);

selected1 = NULL;
selected2 = NULL;
Expand Down Expand Up @@ -378,10 +375,7 @@ void browse(unsigned list, GtkTreeView *treeview)
break;
}

if(selected1 && (find_parent(selected1, &container)!= &container))
gtk_widget_set_sensitive(go_up_button, 1);
else
gtk_widget_set_sensitive(go_up_button, 0);
g_simple_action_set_enabled(go_up_action, selected1 && (find_parent(selected1, &container)!= &container));

(void) &::id; // avoid warning "id defined but not used"
}
Expand All @@ -403,10 +397,7 @@ void go_back(GtkWidget *mainwindow)
displayed = find_parent(displayed, &container);
}

if(selected1 && (find_parent(selected1, &container)!= &container))
gtk_widget_set_sensitive(go_up_button, 1);
else
gtk_widget_set_sensitive(go_up_button, 0);
g_simple_action_set_enabled(go_up_action, selected1 && (find_parent(selected1, &container)!= &container));

display(mainwindow);
}
Expand Down Expand Up @@ -460,7 +451,7 @@ static void redirect_cout(std::ofstream &out, bool enable = true)
void save_as(GtkWidget *mainwindow)
{
struct utsname buf;
GtkWidget *dialog = NULL;
GtkFileChooserNative *dialog = NULL;
GtkWidget *sanitize = NULL;
GtkFileFilter *filter = NULL;
bool proceed = true;
Expand All @@ -469,12 +460,11 @@ void save_as(GtkWidget *mainwindow)
if(!computer) // nothing to save
return;

dialog = gtk_file_chooser_dialog_new ("Save hardware configuration",
dialog = gtk_file_chooser_native_new ("Save hardware configuration",
GTK_WINDOW(mainwindow),
GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
NULL);
"_Save",
"_Cancel");
//gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
sanitize = gtk_check_button_new_with_label("Anonymize output");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sanitize), enabled("output:sanitize")?TRUE:FALSE);
Expand Down Expand Up @@ -511,7 +501,7 @@ void save_as(GtkWidget *mainwindow)
if(uname(&buf)==0)
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), buf.nodename);

if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
if (gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
char *filename;

Expand Down Expand Up @@ -556,8 +546,8 @@ void save_as(GtkWidget *mainwindow)
"A file named <i><tt>%s</tt></i> already exists in folder <tt>%s</tt>.\n\nDo you want to overwrite it?",
basename(buffer1), dirname(buffer2));
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
"Overwrite", GTK_RESPONSE_ACCEPT,
"_Cancel", GTK_RESPONSE_CANCEL,
"_Overwrite", GTK_RESPONSE_ACCEPT,
NULL);
proceed = (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT);
gtk_widget_destroy (dialog);
Expand Down Expand Up @@ -603,5 +593,5 @@ void save_as(GtkWidget *mainwindow)
}
}

gtk_widget_destroy (dialog);
g_object_unref (dialog);
}
59 changes: 44 additions & 15 deletions src/gui/gtk-lshw.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,27 @@
#include "config.h"
#include "stock.h"
#include "engine.h"
#include "callbacks.h"

static char *id = "@(#) $Id$";

extern GtkWidget *mainwindow;
GSimpleAction *go_up_action;
GSimpleAction *save_action;

int
main (int argc, char *argv[])
static GActionEntry app_entries[] =
{
#ifndef NONLS
bindtextdomain (PACKAGE, LOCALEDIR);
bind_textdomain_codeset (PACKAGE, "UTF-8");
textdomain (PACKAGE);
#endif

gtk_init (&argc, &argv);
{ "go_up", on_go_up_activated, NULL, NULL, NULL },
{ "refresh", on_refresh_activated, NULL, NULL, NULL },
{ "save", on_save_activated, NULL, NULL, NULL },
{ "about", on_about_activated, NULL, NULL, NULL },
{ "quit", on_quit_activated, NULL, NULL, NULL }
};

static void
activate (GApplication *app,
gpointer user_data)
{
if(geteuid() != 0)
{
bool proceed = false;
Expand All @@ -31,27 +36,51 @@ main (int argc, char *argv[])
GTK_BUTTONS_NONE,
"Executing this program as a normal user will give incomplete and maybe erroneous information.");
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
GTK_STOCK_QUIT, GTK_RESPONSE_CANCEL,
GTK_STOCK_EXECUTE, GTK_RESPONSE_ACCEPT,
"_Quit", GTK_RESPONSE_CANCEL,
"_Execute", GTK_RESPONSE_ACCEPT,
NULL);

proceed = (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT);
gtk_widget_destroy (dialog);

if(!proceed)
return -1;
return;
}

g_action_map_add_action_entries (G_ACTION_MAP (app),
app_entries, G_N_ELEMENTS (app_entries),
app);
go_up_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (app), "go_up"));
save_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (app), "save"));

g_simple_action_set_enabled(go_up_action, FALSE);
g_simple_action_set_enabled(save_action, FALSE);

lshw_gtk_stock_init();
lshw_ui_init();

if(!mainwindow)
return(1);
return;

gtk_widget_show(mainwindow);
gtk_main ();
gtk_application_add_window(GTK_APPLICATION(app), GTK_WINDOW(mainwindow));
}

int
main (int argc, char *argv[])
{
#ifndef NONLS
bindtextdomain (PACKAGE, LOCALEDIR);
bind_textdomain_codeset (PACKAGE, "UTF-8");
textdomain (PACKAGE);
#endif

GtkApplication *app = gtk_application_new ("org.ezix.gtk-lshw", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);

(void) &id; // avoid warning "id defined but not used"

return 0;
return status;
}
Loading

0 comments on commit 9ae06b4

Please sign in to comment.