lkmonitor.c File Reference

#include <glib.h>
#include <gtk/gtk.h>
#include "eggtrayicon.h"
#include "support.h"
#include "others.h"
#include "lininfo.h"

Go to the source code of this file.

Functions

void lkmonitor_exit ()
 performs collector cancellation
void docklet_onclick (GtkWidget *w)
void lkmonitor_create_tray_icon ()
 Creates docklet.
void lkmonitor_init_widgets (GtkWidget *window)
void lkmonitor_fill_tv (GtkListStore *model, GtkTreeView *gtv, GtkTreeIter iter, char *buffer)
void lkmonitor_write_settings ()
 Write settings.

Variables

struct {
   EggTrayIcon *   eti
   GtkWidget *   eb
   GtkWidget *   image
docklet
GThread * gt_collector
GtkWidget * window1


Function Documentation

void docklet_onclick ( GtkWidget *  w  ) 

Shows the window when click on the docklet.

Parameters:
w the clicked widget

Definition at line 65 of file lkmonitor.c.

References is_icon, and window1.

Referenced by lkmonitor_create_tray_icon().

00066 {
00067         extern gboolean is_icon;
00068         
00069         gtk_widget_show(window1);
00070         is_icon=FALSE;
00071         
00072 }

void lkmonitor_create_tray_icon (  ) 

Creates docklet.

Creates the tray_icon. Based on the code of jabber IM client.

Definition at line 77 of file lkmonitor.c.

References create_pixbuf(), docklet_onclick(), egg_tray_icon_new(), and window1.

Referenced by main().

00077                                  {
00078 
00079   gint w = 0;
00080   gint h = 0;
00081         
00082   docklet.eti = egg_tray_icon_new("lkmonitor");
00083   docklet.eb = gtk_event_box_new();
00084   docklet.image = gtk_image_new();
00085 
00086   GdkPixbuf *pb = NULL;
00087   GdkPixbuf *pb_scaled = NULL;
00088 
00089   pb =create_pixbuf("lkmonitor/spider-shadow32.png");
00090   gtk_icon_size_lookup(GTK_ICON_SIZE_LARGE_TOOLBAR, &w, &h);
00091   pb_scaled = gdk_pixbuf_scale_simple(pb, w, h, GDK_INTERP_BILINEAR);
00092   gtk_image_set_from_pixbuf(GTK_IMAGE(docklet.image), pb_scaled);
00093 
00094 
00095   gtk_container_add(GTK_CONTAINER(docklet.eb), docklet.image);
00096   gtk_container_add(GTK_CONTAINER(docklet.eti), docklet.eb);
00097   gtk_widget_show_all(GTK_WIDGET(docklet.eti));
00098   
00099  
00100   g_signal_connect(G_OBJECT(docklet.eb), "button-press-event", G_CALLBACK(docklet_onclick), window1);
00101   
00102   
00103   g_object_ref(G_OBJECT(docklet.eti));
00104 }

void lkmonitor_exit (  ) 

performs collector cancellation

Stops collector thread and runs outside event loop.

Definition at line 54 of file lkmonitor.c.

References collector_exit.

Referenced by on_quit1_activate().

00055 {
00056         extern gboolean collector_exit;
00057 
00058         collector_exit=TRUE;
00059         gtk_main_quit();
00060 }

void lkmonitor_fill_tv ( GtkListStore *  model,
GtkTreeView *  gtv,
GtkTreeIter  iter,
char *  buffer 
)

Fills devices treeviews with data.

Parameters:
model the model
gtv the treview to fill
iter iterator for the model
buffer string with data to be inserted into the model
Returns:
0 if success

Definition at line 182 of file lkmonitor.c.

Referenced by update_devs().

00184 {
00185         g_assert(model!=NULL && gtv!=NULL && buffer !=NULL);
00186         
00187         char *pointer;
00188         char name[50];
00189         int num;
00190         //Now add data to model
00191 
00192         pointer=buffer;
00193 
00194         while(*pointer!='\0'){
00195                 gtk_list_store_append(model,&iter);
00196                 sscanf(pointer,"%d %s",&num,name);
00197                 gtk_list_store_set(model,&iter,0,num,1,name,-1);
00198                 pointer=strchr(pointer,'\n')+1;
00199         }
00200 }

void lkmonitor_init_widgets ( GtkWidget *  window  ) 

Initialize additional widgets. This function initialize more widgets like GtkTreeViews.

Parameters:
window main window

Definition at line 111 of file lkmonitor.c.

References lookup_widget().

Referenced by main().

00112 {
00113 
00114   GtkListStore *block_list;
00115   GtkListStore *char_list;
00116   GtkCellRenderer *b_renderer;
00117   GtkCellRenderer *c_renderer;
00118   GtkTreeView *gtv_char;
00119   GtkTreeView *gtv_block;
00120 
00121         /*Tree views to show devices*/
00122         /*For block devices*/
00123         
00124         /*First column*/
00125   gtv_block= (GtkTreeView *)lookup_widget(window,"gtv_block");
00126   block_list=gtk_list_store_new(2,G_TYPE_INT, G_TYPE_STRING);
00127   gtk_tree_view_set_model(GTK_TREE_VIEW(gtv_block),GTK_TREE_MODEL(block_list));
00128  
00129   b_renderer = gtk_cell_renderer_text_new ();
00130   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (gtv_block),
00131                                                -1,      
00132                                                _("Number"),  
00133                                                b_renderer,
00134                                                "text", 0,
00135                                                NULL);
00136 
00137   /*Second column*/
00138 
00139   b_renderer = gtk_cell_renderer_text_new ();
00140   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (gtv_block),
00141                                                -1,      
00142                                                _("Device"),  
00143                                                b_renderer,
00144                                                "text", 1,
00145                                                NULL);
00146                                                                                            
00147   
00148   /*For char devices*/  
00149   
00150   /*First column*/
00151   gtv_char= (GtkTreeView *)lookup_widget(window,"gtv_char");
00152   char_list=gtk_list_store_new(2,G_TYPE_INT, G_TYPE_STRING);
00153   gtk_tree_view_set_model(GTK_TREE_VIEW(gtv_char),GTK_TREE_MODEL(char_list));
00154  
00155   c_renderer = gtk_cell_renderer_text_new ();
00156   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (gtv_char),
00157                                                -1,      
00158                                                _("Number"),  
00159                                                c_renderer,
00160                                                "text", 0,
00161                                                NULL);
00162 
00163   /*Second column*/
00164 
00165   c_renderer = gtk_cell_renderer_text_new ();
00166   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (gtv_char),
00167                                                -1,      
00168                                                _("Device"),  
00169                                                c_renderer,
00170                                                "text", 1,
00171                                                NULL);
00172 }

void lkmonitor_write_settings (  ) 

Write settings.

Write new settings.

Definition at line 204 of file lkmonitor.c.

References DOMAIN_NAME, FILE_MAX, HOST_NAME, INODES, lookup_widget(), P_MAX_M, P_MAX_Q, P_MAX_S, PAGE_MAX, SEG_MAX, SEG_SIZE, SEM, THREADS_MAX, window1, write_string_to_file(), and write_values_to_file().

Referenced by on_btn_write_clicked().

00205 {
00206   //This is called from a callback, so we are still running in a gtk lock.
00207   GtkEntry *ent;
00208   GtkLabel *lbl;
00209   GtkSpinButton *spb;
00210   GString *gs;
00211   int val1,val2,val3,val4;
00212         
00213 /*For Identification*/
00214   ent=GTK_ENTRY(lookup_widget(window1,"ent_hostname"));
00215   gs=g_string_new(gtk_entry_get_text(ent));
00216   write_string_to_file(gs->str,HOST_NAME);
00217         
00218   ent=GTK_ENTRY(lookup_widget(window1,"ent_domainname"));
00219   gs=g_string_new(gtk_entry_get_text(ent));
00220   write_string_to_file(gs->str,DOMAIN_NAME);
00221         
00222 /*For Files*/
00223         
00224   spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_fdmax"));
00225   val1=(int)gtk_spin_button_get_value_as_int(spb);
00226 
00227   write_values_to_file(3,FILE_MAX,val1);
00228 
00229 /*For Inodes*/
00230         lbl=GTK_LABEL(lookup_widget(window1,"lbl_inmax"));
00231         val1=atoi((char *)gtk_label_get_text(lbl));
00232         
00233         lbl=GTK_LABEL(lookup_widget(window1,"lbl_ina"));
00234         val2=atoi((char *)gtk_label_get_text(lbl));
00235         
00236         write_values_to_file(2,INODES,val1,val2);
00237 
00238 /*For POSIX signals*/
00239         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_mq"));
00240         val1=gtk_spin_button_get_value_as_int(spb);
00241         write_values_to_file(1,P_MAX_Q,val1);
00242         
00243         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_max_mpq"));
00244         val1=gtk_spin_button_get_value_as_int(spb);
00245         write_values_to_file(1,P_MAX_M,val1);
00246         
00247         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_max_ms"));
00248         val1=gtk_spin_button_get_value_as_int(spb);
00249         write_values_to_file(1,P_MAX_S,val1);
00250 
00251 /*For shared memory*/
00252         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_max_pages"));
00253         val1=gtk_spin_button_get_value_as_int(spb);
00254         write_values_to_file(1,PAGE_MAX,val1);
00255         
00256         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_max_segs"));
00257         val1=gtk_spin_button_get_value_as_int(spb);
00258         write_values_to_file(1,SEG_MAX,val1);
00259         
00260         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_seg_size"));
00261         val1=gtk_spin_button_get_value_as_int(spb);
00262         write_values_to_file(1,SEG_SIZE,val1);
00263         
00264 /*For semaphores*/
00265         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_sem_per_id"));
00266         val1=gtk_spin_button_get_value_as_int(spb);
00267         
00268         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_sem_val"));
00269         val2=gtk_spin_button_get_value_as_int(spb);
00270         
00271         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_ops"));
00272         val3=gtk_spin_button_get_value_as_int(spb);
00273         
00274         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_sem_id"));
00275         val4=gtk_spin_button_get_value_as_int(spb);
00276         
00277         write_values_to_file(4,SEM,val1,val2,val3,val4);
00278         
00279 /*For threads*/
00280         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_maxthreads"));
00281         val1=gtk_spin_button_get_value_as_int(spb);
00282         
00283         write_values_to_file(1,THREADS_MAX,val1);
00284 }


Variable Documentation

struct { ... } docklet

GtkWidget* eb

Definition at line 43 of file lkmonitor.c.

EggTrayIcon* eti

Definition at line 42 of file lkmonitor.c.

GThread* gt_collector

Definition at line 61 of file main.c.

Referenced by main().

GtkWidget* image

Definition at line 44 of file lkmonitor.c.

GtkWidget* window1

Definition at line 47 of file main.c.

Referenced by create_window1(), docklet_onclick(), lkmonitor_create_tray_icon(), lkmonitor_write_settings(), main(), refresh(), update_cpu(), update_cpu_mhz(), update_devs(), update_mem(), update_misc(), and update_settings().


Generated on Sat Dec 2 11:27:53 2006 for lkmonitor by  doxygen 1.5.1