Back to index

lshw  02.16
Classes | Defines | Functions | Variables
stock.c File Reference
#include "stock.h"
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>

Go to the source code of this file.

Classes

struct  StockIcon

Defines

#define UIFILE   "gtk-lshw.ui"

Functions

static gchar * find_file (const char *base, const char *dir)
void lshw_gtk_stock_init (void)
void lshw_ui_init (void)

Variables

static char * id = "@(#) $Id: stock.c 2433 2012-01-10 22:01:30Z lyonel $"
GtkWidget * mainwindow = NULL
GtkWidget * about = NULL
GtkWidget * list1 = NULL
GtkWidget * list2 = NULL
GtkWidget * list3 = NULL
GtkWidget * description = NULL
GtkWidget * go_up_button = NULL
GtkWidget * save_button = NULL
GtkWidget * statusbar = NULL
static struct StockIcon stock_icons []

Class Documentation

struct StockIcon

Definition at line 20 of file stock.c.

Class Members
const char * filename
const char * name

Define Documentation

#define UIFILE   "gtk-lshw.ui"

Definition at line 8 of file stock.c.


Function Documentation

static gchar* find_file ( const char *  base,
const char *  dir 
) [static]

Definition at line 63 of file stock.c.

{
  char *filename;
  char *basedir;

  if (base == NULL)
    return NULL;

  if((basedir = getenv("BASEDIR")))
    filename = g_build_filename(basedir, dir, base, NULL);
  else
    filename = g_build_filename(DATADIR, "lshw", dir, base, NULL);

  if (!g_file_test(filename, G_FILE_TEST_EXISTS))
  {
    g_free(filename);
    return NULL;
  }
  else
    return filename;
}

Here is the caller graph for this function:

void lshw_gtk_stock_init ( void  )

Definition at line 87 of file stock.c.

{
  static int stock_initted = 0;
  GtkIconFactory *icon_factory;
  int i;
  GtkWidget *win;

  if (stock_initted)
    return;

  stock_initted = 1;

/* Setup the icon factory. */
  icon_factory = gtk_icon_factory_new();

  gtk_icon_factory_add_default(icon_factory);

/* Er, yeah, a hack, but it works. :) */
  win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_widget_realize(win);

  for (i = 0; i < G_N_ELEMENTS(stock_icons); i++)
  {
    GdkPixbuf *pixbuf;
    GtkIconSet *iconset;
    gchar *filename;

      filename = find_file(stock_icons[i].filename, "artwork");

      if (filename == NULL)
        continue;

      pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
      g_free(filename);

      if(pixbuf)     /* we managed to load something */
      {
        iconset = gtk_icon_set_new_from_pixbuf(pixbuf);
        g_object_unref(G_OBJECT(pixbuf));
        gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset);
        gtk_icon_set_unref(iconset);
      }
  }

  gtk_widget_destroy(win);

/* register logo icon size */
  gtk_icon_size_register(LSHW_ICON_SIZE_LOGO, LSHW_DEFAULT_ICON_SIZE, LSHW_DEFAULT_ICON_SIZE);

  g_object_unref(G_OBJECT(icon_factory));

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

Here is the call graph for this function:

Here is the caller graph for this function:

void lshw_ui_init ( void  )

Definition at line 141 of file stock.c.

{
  GError *error = NULL;
  GtkBuilder *builder = NULL;
  GdkPixbuf *icon = NULL;
  gchar *uiname = NULL;

  mainwindow = NULL;

  builder = gtk_builder_new();
  uiname = find_file(UIFILE, "ui");
  if(!uiname)
  {
    g_critical( "Could not find UI file: %s", UIFILE );
    return;
  }
  if(!gtk_builder_add_from_file(builder, uiname, &error))
  {
    g_critical( "Could not create UI: %s", error->message );
    g_free( error );
    g_object_unref( G_OBJECT( builder ) );
    return;
  }
  g_free(uiname);

  mainwindow = GTK_WIDGET( gtk_builder_get_object( builder, "mainwindow" ) );
  about = GTK_WIDGET( gtk_builder_get_object( builder, "aboutlshw" ) );
  list1 = GTK_WIDGET(gtk_builder_get_object( builder, "treeview1"));
  list2 = GTK_WIDGET(gtk_builder_get_object( builder, "treeview2"));
  list3 = GTK_WIDGET(gtk_builder_get_object( builder, "treeview3"));
  description = GTK_WIDGET(gtk_builder_get_object( builder, "description"));
  go_up_button = GTK_WIDGET(gtk_builder_get_object( builder, "upbutton"));
  save_button = GTK_WIDGET(gtk_builder_get_object( builder, "savebutton"));
  statusbar = GTK_WIDGET(gtk_builder_get_object( builder, "statusbar"));
  gtk_builder_connect_signals( builder, mainwindow );
  g_object_unref( G_OBJECT( builder ) );

  icon = gtk_widget_render_icon(GTK_WIDGET(mainwindow),
    "lshw-logo",
    GTK_ICON_SIZE_DIALOG,
    NULL);
  if(GDK_IS_PIXBUF(icon))
  {
    gtk_window_set_icon(GTK_WINDOW(mainwindow), icon);
    gtk_window_set_default_icon(icon);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

GtkWidget* about = NULL

Definition at line 11 of file stock.c.

GtkWidget* description = NULL

Definition at line 15 of file stock.c.

GtkWidget* go_up_button = NULL

Definition at line 16 of file stock.c.

char* id = "@(#) $Id: stock.c 2433 2012-01-10 22:01:30Z lyonel $" [static]

Definition at line 6 of file stock.c.

GtkWidget* list1 = NULL

Definition at line 12 of file stock.c.

GtkWidget* list2 = NULL

Definition at line 13 of file stock.c.

GtkWidget* list3 = NULL

Definition at line 14 of file stock.c.

GtkWidget* mainwindow = NULL

Definition at line 10 of file stock.c.

GtkWidget* save_button = NULL

Definition at line 17 of file stock.c.

GtkWidget* statusbar = NULL

Definition at line 18 of file stock.c.

struct StockIcon stock_icons[] [static]