/************************************************** * * Gnome-panel applet for monitoring Seti@home * client's progress. * * Henry Palonen, h yty dot net, 1999 * * Feel free to modify this. * **************************************************/ #include #include #include #include #include #include #ifdef HAVE_PANEL_SIZE /* this is when the panel size changes */ static void applet_change_size(GtkWidget *w, PanelSizeType o, gpointer data) { switch(o) { case SIZE_TINY: puts("SIZE_TINY"); break; case SIZE_STANDARD: puts("SIZE_STANDARD"); break; case SIZE_LARGE: puts("SIZE_LARGE"); break; case SIZE_HUGE: puts("SIZE_HUGE"); break; } } #endif typedef struct _ProgressData { GtkWidget *window; GtkWidget *pbar; int timer; } ProgressData; /* * Timer event for updating progressbar value */ gint progress_timeout( gpointer data ) { gfloat new_val; GtkAdjustment *adj; gfloat ourValue_1000; QString ourValue; /* Calculate the value of the progress bar using the * value range set in the adjustment object */ // new_val = gtk_progress_get_value( GTK_PROGRESS(data) ) + 1; // adj = GTK_PROGRESS (data)->adjustment; // if (new_val > adj->upper) // new_val = adj->lower; // File-name QFile fileN( "/home/henkka/state.txt" ); fileN.open( IO_ReadOnly ); QTextStream textS(&fileN); while ( !textS.eof() ) { QString line = textS.readLine(); QString leftV = line.left(5); if (!strncmp("prog",leftV,4)) { ourValue = (line.mid(5,12)); ourValue_1000 = ourValue.toFloat() * 100; // if (progBar.progress() > ourValue_1000) // progBar.reset(); // progBar.setProgress (ourValue_1000); // progBar.setCaption(pri); // progBar.show(); } } fileN.close(); // a.processEvents(); /* Set the new value */ // gtk_progress_set_value (GTK_PROGRESS (data), new_val); gtk_progress_set_value (GTK_PROGRESS (data), ourValue_1000); // void (* tooltip_state) (AppletWidget *applet, // int enabled); // applet_widget_set_tooltip (APPLET_WIDGET(data),"lujaa ;)"); // gtk_tooltips_set_tip (ad->tooltips, ad->applet, date, NULL); /* As this is a timeout function, return TRUE so that it * continues to get called */ return(TRUE); } // cleanup void destroy_progress( GtkWidget *widget, ProgressData *pdata) { gtk_timeout_remove (pdata->timer); pdata->timer = 0; pdata->window = NULL; g_free(pdata); gtk_main_quit(); } int main(int argc, char **argv) { GtkWidget *applet; GtkWidget *label; GtkWidget *pbar; // ProgressData *pdata; // GtkAdjustment *adj; ProgressData *pdata; GtkWidget *align; GtkWidget *separator; GtkWidget *table; GtkAdjustment *adj; GtkTooltips *tooltip; GtkWidget *button; GtkWidget *check; GtkWidget *vbox; /* Initialize the i18n stuff */ bindtextdomain (PACKAGE, GNOMELOCALEDIR); textdomain (PACKAGE); pdata = g_malloc( sizeof(ProgressData) ); /* intialize, this will basically set up the applet, corba and call gnome_init */ applet_widget_init("hello_applet", NULL, argc, argv, NULL, 0, NULL); /* create a new applet_widget */ applet = applet_widget_new("hello_applet"); /* in the rare case that the communication with the panel failed, error out */ if (!applet) g_error("Can't create applet!\n"); /* create the widget we are going to put on the applet */ // label = gtk_label_new(_("Hello There!")); // gtk_widget_show(label); adj = (GtkAdjustment *) gtk_adjustment_new (0, 1, 100, 0, 0, 0); pdata->pbar = gtk_progress_bar_new_with_adjustment (adj); // tooltip = (GtkTooltips *) gtk_tooltips_new(); // gtk_progress_bar_set_bar_style( GTK_PROGRESS (prg) ,GTK_PROGRESS_CONTINUOUS); gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR (pdata->pbar), GTK_PROGRESS_CONTINUOUS); gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (pdata->pbar), GTK_PROGRESS_BOTTOM_TO_TOP); gtk_progress_set_format_string (GTK_PROGRESS (pdata->pbar), "%p %%"); gtk_widget_set_usize (pdata->pbar, 15, 48); gtk_widget_show(pdata->pbar); // timer for updating progressbar pdata->timer = gtk_timeout_add (100, progress_timeout, pdata->pbar); applet_widget_set_tooltip (APPLET_WIDGET(applet),"%p %% of seti@home"); #ifdef HAVE_PANEL_SIZE /*we have to bind change_size before we do applet_widget_add since we need to get an initial change_size signal to set our initial size, and we get that during the _add call*/ gtk_signal_connect(GTK_OBJECT(applet),"change_size", GTK_SIGNAL_FUNC(applet_change_size), NULL); #endif /* add the widget to the applet-widget, and thereby actually putting it "onto" the panel */ // applet_widget_add (APPLET_WIDGET (applet), label); applet_widget_add (APPLET_WIDGET (applet), pdata->pbar); gtk_widget_show (applet); /* special corba main loop */ applet_widget_gtk_main (); return 0; }