Logo Search packages:      
Sourcecode: karpski version File versions  Download package

help.c

/*

RIG ALERT

This code is the ass of code.
Not that karpski is a work of art, but this code is doo doo brown.
To say help was an afterthought would be substantially understating the case!

Much code in here was stolen from testgtk written by the gtk+ folks.

*/

#include <stdio.h>
#include <gtk/gtk.h>

GtkWidget *helpwindow;
GdkPixmap *book_open;
GdkPixmap *book_closed;
GdkBitmap *book_open_mask;
GdkBitmap *book_closed_mask;   

#define NUM_HELP_PAGES 12

static char *labels[NUM_HELP_PAGES] = {"Introduction", "Quick start", "Log button", "Connections", "Stats", "Launch", "Watch", "Protocols", "Info", "Contact", "License", "Home site"};
static char *helptexts[NUM_HELP_PAGES] = {"The story of K.ARP.SKI\n\nNow, my story goes back to 19 dickety two.\nWe had to say dickety cause that Kaiser had stolen\nour word twenty.  I chased that rascal to get it back, but\ngave up after dickety six miles...\n\nOops, wrong story\n",
                            "Quick start:\n\nHit the start button.  Watch as the screen\nfills with local addresses.\nClicking any button aside from start, stop, log\n and overall stats perform\nan action on the hilighted MAC address.",
                            "The log button:\n\nLog: Opens the log window so that you can view important\npieces of info.  If this is not selected, the info\nwill only be logged to the logfile.\n",
                            "Connections:\n\nThis button reveals all connections on this NIC.\nOnly TCP connections are currently supported.\n",
                            "Stats:\n\nView overall K.ARP.SKI statistics such as:\n\nConnections, bytes read, number of NICs found, etc.\n",
                            "Launch:\n\nLaunch a program vs. the selected NIC.\n",
                            "Watch:\n\nPut a watch on all ether traffic over this NIC.\n",
                            "Protocols:\n\nView a semi-realtime list of all ethernet\nprotocols used.  When a protocol has an encapsulated\nprotocol, the encapsulated protocol is indented.\n",
                            "Info:\n\nThis prints information about the currently selected\nNIC.\n",
                            "Contact\n\nBrian Costello (the author)\nEmail: btx@calyx.net\nI would like to thank\nthe Gtk folks (all GUI code is stolen from them!) and\nThe Lawrence Berkeley Labs (for pcap) which\nis a portable packet capture interface.\n",
                            "License\n\nk.arp.ski\nCopyright (c) 1998, Brian Costello\nbtx@calyx.net\nThis program comes with NO WARRANTY.\nFor details, read LICENSE.TXT that\nshould have come with your karpski distribution.\n",
                            "Homesite\n\nTo download the latest version of Karpski:\nhttp://mojo.calyx.net/~btx/karpski.html"};

static char * book_open_xpm[] = {
"16 16 4 1",
"       c None s None",
".      c black",
"X      c #808080",
"o      c white",
"                ",
"  ..            ",
" .Xo.    ...    ",
" .Xoo. ..oo.    ",
" .Xooo.Xooo...  ",
" .Xooo.oooo.X.  ",
" .Xooo.Xooo.X.  ",
" .Xooo.oooo.X.  ",
" .Xooo.Xooo.X.  ",
" .Xooo.oooo.X.  ",
"  .Xoo.Xoo..X.  ",
"   .Xo.o..ooX.  ",
"    .X..XXXXX.  ",
"    ..X.......  ",
"     ..         ",
"                "};

static char * book_closed_xpm[] = {
"16 16 6 1",
"       c None s None",    
".      c black",
"X      c red",
"o      c yellow",
"O      c #808080",
"#      c white",
"                ",
"       ..       ",
"     ..XX.      ",
"   ..XXXXX.     ",
" ..XXXXXXXX.    ",
".ooXXXXXXXXX.   ",
"..ooXXXXXXXXX.  ",
".X.ooXXXXXXXXX. ",
".XX.ooXXXXXX..  ",
" .XX.ooXXX..#O  ",
"  .XX.oo..##OO. ",
"   .XX..##OO..  ",
"    .X.#OO..    ",
"     ..O..      ",
"      ..        ",
"                "};

void page_switch(GtkWidget *widget, GtkNotebookPage *page, gint page_num)
{
  GtkNotebookPage *oldpage;
  GtkWidget *pixwid;
    
   oldpage = GTK_NOTEBOOK (widget)->cur_page;
   if (page == oldpage)
      return;
   pixwid = ((GtkBoxChild*)(GTK_BOX (page->tab_label)->children->data))->widget;
   gtk_pixmap_set (GTK_PIXMAP (pixwid), book_open, book_open_mask);
   pixwid = ((GtkBoxChild*) (GTK_BOX (page->menu_label)->children->data))->widget;
   gtk_pixmap_set (GTK_PIXMAP (pixwid), book_open, book_open_mask);
   if (oldpage)
   {
      pixwid = ((GtkBoxChild*) (GTK_BOX(oldpage->tab_label)->children->data))->widget;
      gtk_pixmap_set (GTK_PIXMAP (pixwid), book_closed, book_closed_mask);
      pixwid = ((GtkBoxChild*) (GTK_BOX (oldpage->menu_label)->children->data))->widget;
      gtk_pixmap_set (GTK_PIXMAP (pixwid), book_closed, book_closed_mask);
   }
                                                                                         
}

void create_pages(GtkNotebook *notebook)
{
   GtkWidget *child = NULL;
   GtkWidget *title, *title_box, *menu_box;
   GtkWidget *pixwid, *label;
   char buffer[40];
   int i;
   
   for (i=0; i<NUM_HELP_PAGES; i++)
   {
      sprintf(buffer,"Page %d\n", i+1);
      child = gtk_frame_new(buffer);            /* Frame title */
      gtk_container_border_width(GTK_CONTAINER(child), 10);

      title = gtk_label_new(helptexts[i]);
      gtk_container_add(GTK_CONTAINER(child), title);

      gtk_widget_show_all(child);

      title_box = gtk_hbox_new(FALSE, 0);
      pixwid = gtk_pixmap_new (book_closed, book_closed_mask);
      gtk_box_pack_start (GTK_BOX (title_box), pixwid, FALSE, TRUE, 0);
      gtk_misc_set_padding (GTK_MISC (pixwid), 3, 1);
      title = gtk_label_new(labels[i]);
      gtk_container_add(GTK_CONTAINER(title_box), title);
      gtk_widget_show_all(title_box);

/* What is this shit?? @@@ */

      menu_box = gtk_hbox_new (FALSE, 0);
      pixwid = gtk_pixmap_new (book_closed, book_closed_mask);
      gtk_box_pack_start (GTK_BOX (menu_box), pixwid, FALSE, TRUE, 0);
      gtk_misc_set_padding (GTK_MISC (pixwid), 3, 1);
      label = gtk_label_new ("Introduction4");

      gtk_box_pack_start (GTK_BOX (menu_box), label, FALSE, TRUE, 0);
      gtk_widget_show_all (menu_box);                                       

/* Ask the gtk folks... */

      gtk_notebook_append_page_menu(notebook, child, title_box, menu_box);
   }
}

void switchhelp(GtkWidget *widget)
{

/*   GtkWidget *hscrollbar, *vscrollbar, *table,  */
   GtkWidget *separator;
   GtkWidget *notebook;
   GtkWidget *box1, *box2, *button;
   GdkColor *transparent = NULL;
   
   if (!helpwindow)
   {
      helpwindow= gtk_window_new(GTK_WINDOW_TOPLEVEL);
      gtk_widget_set_name(helpwindow, "help");

      gtk_window_set_policy (GTK_WINDOW(helpwindow), TRUE, TRUE, FALSE);
         
      gtk_signal_connect (GTK_OBJECT (helpwindow), "destroy",
                          GTK_SIGNAL_FUNC(gtk_widget_destroyed), &helpwindow);
      gtk_window_set_title (GTK_WINDOW (helpwindow), "Help");
      gtk_container_border_width (GTK_CONTAINER (helpwindow), 0);
      box1 = gtk_vbox_new (FALSE, 0);
      gtk_container_add (GTK_CONTAINER (helpwindow), box1);
      gtk_widget_show (box1);
      
      notebook = gtk_notebook_new();
      gtk_notebook_set_show_tabs(GTK_NOTEBOOK (notebook), TRUE);
      gtk_notebook_set_scrollable(GTK_NOTEBOOK (notebook), TRUE);

      gtk_signal_connect (GTK_OBJECT (notebook), "switch_page",
                          GTK_SIGNAL_FUNC (page_switch), NULL);
      gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
      gtk_box_pack_start (GTK_BOX (box1), notebook, TRUE, TRUE, 0);
      gtk_container_border_width (GTK_CONTAINER (notebook), 10);
      gtk_widget_realize (notebook);
      gtk_widget_show (notebook);
      book_open = gdk_pixmap_create_from_xpm_d (notebook->window,
                                                &book_open_mask,
                                                transparent,
                                                book_open_xpm);
                                                
      book_closed = gdk_pixmap_create_from_xpm_d (notebook->window,
                                                  &book_closed_mask,
                                                  transparent,
                                                  book_closed_xpm);

      create_pages (GTK_NOTEBOOK (notebook));
      separator = gtk_hseparator_new ();
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
      gtk_widget_show (separator);
      box2 = gtk_vbox_new (FALSE, 10);
      gtk_container_border_width (GTK_CONTAINER (box2), 10);
      gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
      gtk_widget_show (box2);
      button = gtk_button_new_with_label ("close");
      gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                                GTK_SIGNAL_FUNC(gtk_widget_destroy),
                                GTK_OBJECT (helpwindow));
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
      GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
      gtk_widget_grab_default (button);
      gtk_widget_show (button);
   }
   if (!GTK_WIDGET_VISIBLE(helpwindow))
      gtk_widget_show(helpwindow);
   else
   {
      gtk_widget_destroy(helpwindow);
   }
      
   return;
}

Generated by  Doxygen 1.6.0   Back to index