Back to index

lshw  02.16
Functions
engine.h File Reference
#include <gtk/gtk.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void refresh (GtkWidget *)
void change_selection (unsigned list, GtkTreeView *treeview)
void browse (unsigned list, GtkTreeView *treeview)
void go_back (GtkWidget *)
void save_as (GtkWidget *)

Function Documentation

void browse ( unsigned  list,
GtkTreeView *  treeview 
)

Definition at line 331 of file engine.cc.

{
  GtkTreeSelection *selection;
  GtkTreeModel     *model;
  GtkTreeIter       iter;
  hwNode *n = NULL;

  selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
  if (gtk_tree_selection_get_selected(selection, &model, &iter))
    gtk_tree_model_get (model, &iter, COL_NODE, &n, -1);

  if(n)
    switch(list)
    {
      case 1:
//if(n!=selected1)
        {
          selected1 = n;
          selected2 = NULL;
          selected3 = NULL;
          populate_sublist(list2, selected1, selected2);
          populate_sublist(list3, selected2, selected3);
        }
      break;
    case 2:
//if(n!=selected2)
      {
        selected2 = n;
        selected3 = NULL;
        populate_sublist(list3, selected2, selected3);
      }
      break;
    case 3:
//if(n!=selected3)
      {
        selected3 = n;
        if(n->countChildren()>0)
        {
          hwNode *oldselected1 = selected1;
          selected1 = selected2;
          selected2 = n;
          selected3 = NULL;
          populate_sublist(list1, oldselected1, selected1);
          populate_sublist(list2, selected1, selected2);
          populate_sublist(list3, selected2, selected3);
        }
      }
      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);

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

Here is the call graph for this function:

Here is the caller graph for this function:

void change_selection ( unsigned  list,
GtkTreeView *  treeview 
)

Definition at line 292 of file engine.cc.

{
  GtkTreeSelection *selection;
  GtkTreeModel *model;
  GtkTreeIter   iter;

  model = gtk_tree_view_get_model(treeview);

  displayed = NULL;

  selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
  if (gtk_tree_selection_get_selected(selection, &model, &iter))
    gtk_tree_model_get (model, &iter, COL_NODE, &displayed, -1);

  if(list<2) populate_sublist(list2, NULL);
  if(list<3) populate_sublist(list3, NULL);

  display(mainwindow);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void go_back ( GtkWidget *  )

Definition at line 390 of file engine.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

void refresh ( GtkWidget *  )

Definition at line 249 of file engine.cc.

{
  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);

  populate_sublist(list1, NULL);
  populate_sublist(list2, NULL);
  populate_sublist(list3, NULL);
  displayed = NULL;
  gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(description)), "scanning...", -1);

  disable("output:sanitize");
  container = hwNode("container", hw::generic);
  status("Scanning...");
  scan_system(computer);
  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);

  selected1 = NULL;
  selected2 = NULL;
  selected3 = NULL;

  populate_sublist(list1, &container);
  populate_sublist(list2, NULL);
  populate_sublist(list3, NULL);
  display(mainwindow);

  lock = false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void save_as ( GtkWidget *  )

Definition at line 460 of file engine.cc.

{
  struct utsname buf;
  GtkWidget *dialog = NULL;
  GtkWidget *sanitize = NULL;
  GtkFileFilter *filter = NULL;
  bool proceed = true;
  hwNode *computer = container.getChild(0);

  if(!computer)             // nothing to save
    return;

  dialog = gtk_file_chooser_dialog_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);
  //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);
  gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(dialog), sanitize);

  filter = gtk_file_filter_new ();
  gtk_file_filter_set_name(filter, AUTOMATIC);
  gtk_file_filter_add_pattern(filter, "*");
  gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
  filter = gtk_file_filter_new ();
  gtk_file_filter_set_name(filter, LSHW_XML);
  gtk_file_filter_add_pattern(filter, "*.lshw");
  gtk_file_filter_add_pattern(filter, "*.xml");
  gtk_file_filter_add_mime_type(filter, "text/xml");
  gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
  filter = gtk_file_filter_new ();
  gtk_file_filter_set_name(filter, HTML);
  gtk_file_filter_add_pattern(filter, "*.html");
  gtk_file_filter_add_pattern(filter, "*.htm");
  gtk_file_filter_add_mime_type(filter, "text/html");
  gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
  filter = gtk_file_filter_new ();
  gtk_file_filter_set_name(filter, PLAIN_TEXT);
  gtk_file_filter_add_pattern(filter, "*.text");
  gtk_file_filter_add_pattern(filter, "*.txt");
  gtk_file_filter_add_mime_type(filter, "text/plain");
  gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
  filter = gtk_file_filter_new ();
  gtk_file_filter_set_name(filter, JSON);
  gtk_file_filter_add_pattern(filter, "*.json");
  gtk_file_filter_add_mime_type(filter, "application/json");
  gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);

  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)
  {
    char *filename;

    if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sanitize)))
      enable("output:sanitize");
    else
      disable("output:sanitize");

    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
    filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog));
    if(filename && filter)
    {
      const gchar *filtername = gtk_file_filter_get_name(filter);

      if(strcmp(filtername, AUTOMATIC)==0)
        filtername = guess_format(filename);

      if(!exists(filename))        // creating a new file
      {
        if(strcmp(filtername, LSHW_XML)==0)
          filename = fix_filename(filename, "lshw");
        else
        if(strcmp(filtername, HTML)==0)
          filename = fix_filename(filename, "html");
        else
        if(strcmp(filtername, PLAIN_TEXT)==0)
          filename = fix_filename(filename, "txt");
        else
        if(strcmp(filtername, JSON)==0)
          filename = fix_filename(filename, "json");
      }

      if(exists(filename))         // existing file
      {
        char * buffer1 = g_strdup(filename);
        char * buffer2 = g_strdup(filename);

        GtkWidget *dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW(mainwindow),
                                  GTK_DIALOG_DESTROY_WITH_PARENT,
                                  GTK_MESSAGE_WARNING,
                                  GTK_BUTTONS_NONE,
                                  "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,
                                  NULL);
        proceed = (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT);
        gtk_widget_destroy (dialog);
        g_free(buffer1);
        g_free(buffer2);
      }

      if(proceed)
      {
        if(strcmp(filtername, LSHW_XML)==0)
        {
          std::ofstream out(filename);
          redirect_cout(out);
          cout << computer->asXML();
          redirect_cout(out, false);
        }
        else
        if(strcmp(filtername, HTML)==0)
        {
          std::ofstream out(filename);
          redirect_cout(out);
          print(*computer, true);
          redirect_cout(out, false);
        }
        else
        if(strcmp(filtername, PLAIN_TEXT)==0)
        {
          std::ofstream out(filename);
          redirect_cout(out);
          print(*computer, false);
          redirect_cout(out, false);
        }
       else
        if(strcmp(filtername, JSON)==0)
        {
          std::ofstream out(filename);
          redirect_cout(out);
          cout << computer->asJSON() << endl;
          redirect_cout(out, false);
        }
      }
      g_free (filename);
    }
  }

  gtk_widget_destroy (dialog);
}

Here is the call graph for this function:

Here is the caller graph for this function: