From 2ec5ece68d2cd8350fa7c0bb12d767545d7b36be Mon Sep 17 00:00:00 2001 From: Harald Judt Date: Mon, 7 May 2012 12:12:38 +0200 Subject: Always update the progress bars even when stats are unavailable. In case of an error (e.g. a device gets removed or some misdetection by the kernel), stats may become unavailable, but the progress bars still show the old values, and the plugin may seem frozen. Because we don't like it to appear frozen, always update the bars and set their values to 0 when no stats are available. --- panel-plugin/main.c | 35 +++++++++++++++++++++++------------ 1 files changed, 23 insertions(+), 12 deletions(-) diff --git a/panel-plugin/main.c b/panel-plugin/main.c index 66f29b6..43f5450 100644 --- a/panel-plugin/main.c +++ b/panel-plugin/main.c @@ -143,6 +143,27 @@ typedef struct diskperf_t { static int timerNeedsUpdate = 0; +static void UpdateProgressBars(struct diskperf_t *p_poPlugin, uint64_t rw, uint64_t r, uint64_t w) { + /* Update combined or separate progress bars with actual data */ + struct monitor_t *poMonitor = &(p_poPlugin->oMonitor); + struct param_t *poConf = &(p_poPlugin->oConf.oParam); + struct perfbar_t *poPerf = poMonitor->aoPerfBar; + + if (poConf->fRW_DataCombined) + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR + (*(poPerf[RW_DATA].pwBar)), + rw); + else { + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR + (*(poPerf[R_DATA].pwBar)), + r); + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR + (*(poPerf[W_DATA].pwBar)), + w); + } +} + + static int DisplayPerf (struct diskperf_t *p_poPlugin) /* Get the last disk perfomance data, compute the statistics and update the panel-docked monitor bars */ @@ -179,6 +200,7 @@ static int DisplayPerf (struct diskperf_t *p_poPlugin) if (status == -1) { snprintf (acToolTips, sizeof(acToolTips), _("%s: Device statistics unavailable."), poConf->acTitle); + UpdateProgressBars(p_poPlugin, 0, 0, 0); gtk_tooltips_set_tip (s_poToolTips, GTK_WIDGET (poMonitor->wEventBox), acToolTips, 0); return (-1); @@ -263,18 +285,7 @@ static int DisplayPerf (struct diskperf_t *p_poPlugin) else if (*pr < 0) *pr = 0; } - if (poConf->fRW_DataCombined) - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR - (*(poPerf[RW_DATA].pwBar)), - prData[RW_DATA]); - else { - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR - (*(poPerf[R_DATA].pwBar)), - prData[R_DATA]); - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR - (*(poPerf[W_DATA].pwBar)), - prData[W_DATA]); - } + UpdateProgressBars(p_poPlugin, prData[RW_DATA], prData[R_DATA], prData[W_DATA]); return (0); } /* DisplayPerf() */ -- 1.7.8.5