/** status_applet.c **/ #include #include #include gint updateCallback(GtkWidget *label); void loadStats(void); static int stIndex; static int stLast; static char stString[40][60]; #define APPLETNAME "status-applet" #define VERSION "1.0" int main(int argc,char *argv[]) { GtkWidget *applet; GtkWidget *label; applet_widget_init(APPLETNAME,VERSION, argc,argv, NULL,0,NULL); applet = applet_widget_new(APPLETNAME); label = gtk_label_new("*\n 0% Used"); gtk_widget_set_usize(label,75,47); applet_widget_add(APPLET_WIDGET(applet),label); gtk_widget_show(label); loadStats(); updateCallback(label); gtk_timeout_add(5000,(GtkFunction)updateCallback, label); gtk_widget_show_all(applet); applet_widget_gtk_main(); exit(0); } gint updateCallback(GtkWidget *label) { if(stIndex > stLast) loadStats(); gtk_label_set_text(GTK_LABEL(label), stString[stIndex++]); return(TRUE); } void loadStats() { int i; FILE *df; char rawInput[80]; char fileSystem[40]; char percent[40]; stIndex = 0; stLast = 0; strcpy(stString[0],"No\nStats"); if((df = popen("df","r")) == NULL) return; fgets(rawInput,sizeof(rawInput),df); while(fgets(rawInput,sizeof(rawInput),df) != NULL) { strtok(rawInput," \n"); for(i=1; i<4; i++) strtok(NULL," \n"); strcpy(percent,strtok(NULL," \n")); strcpy(fileSystem,strtok(NULL," \n")); stLast = stIndex; sprintf(stString[stIndex++],"%s\n%s Used", fileSystem,percent); } stIndex = 0; pclose(df); }