Exemple #1
0
static void
parse_config(void)
{
   char                buff[1024], *s, ss[1024];

   image = Epplet_query_config_def("image", "8ball.png");

   Esnprintf(ss, sizeof(ss), "%s/answers.txt", Epplet_data_dir());
   ans_file = Epplet_query_config_def("answers", ss);
   if (!parse_answers(ans_file) && !parse_answers(ans_file = ss))
     {
	/* Couldn't find the answers.  Exit. */
	Esnprintf(buff, sizeof(buff),
		  "E-Magic:  Missing/invalid answers file \"%s\"", ans_file);
	Epplet_dialog_ok(buff);
	Esync();
	exit(-1);
     }

   s = Epplet_query_config("delay");
   if (s)
     {
	delay = atof(s);
     }
   else
     {
	Epplet_add_config("delay", "2.0");
     }
}
Exemple #2
0
static void
close_cb(void *data)
{
   Epplet_unremember();
   Esync();
   data = NULL;
   exit(0);
}
Exemple #3
0
static void
cb_close(void *data)
{
   Epplet_unremember();
   Esync();
   Epplet_cleanup();
   data = NULL;
   exit(0);
}
Exemple #4
0
static void
cb_close(void *data)
{
   save_config();
   Epplet_unremember();
   Esync();
   exit(0);
   data = NULL;
}
Exemple #5
0
static void
cb_close(void *data)
{
   Epplet_unremember();
   close(fd_mixer);
   Esync();
   data = NULL;
   exit(0);
}
Exemple #6
0
static void
close_cb(void *data)
{

   stop_hack();
   Epplet_unremember();
   Esync();
   exit(0);
   data = NULL;
}
static void
timer_cb(void *data)
{

   char                buff[1024];
   unsigned long       days, hours, mins, secs;
   double              total_secs, delay;

#ifdef HAVE_LIBGTOP

   glibtop_uptime      uptime;

   glibtop_get_uptime(&uptime);
   secs = (unsigned long)uptime.uptime;

#else

   FILE               *fp;

   if (!(fp = fopen("/proc/uptime", "r")))
     {
	D(("Failed to open /proc/uptime -- %s\n", strerror(errno)));
	return;
     }
   fgets(buff, sizeof(buff), fp);
   sscanf(buff, "%lf", &total_secs);
   secs = (unsigned long)total_secs;
   fclose(fp);

#endif

   days = secs / 86400;
   secs %= 86400;
   hours = secs / 3600;
   secs %= 3600;
   mins = secs / 60;
   secs %= 60;
   if (secs == 0)
     {
	secs = 60;
     }
   delay = (double)secs;

   Esnprintf(buff, sizeof(buff), "%lu days", days);
   Epplet_change_label(label2, buff);
   Esnprintf(buff, sizeof(buff), "%lu hours", hours);
   Epplet_change_label(label3, buff);
   Esnprintf(buff, sizeof(buff), "%lu mins", mins);
   Epplet_change_label(label4, buff);

   Esync();
   Epplet_timer(timer_cb, NULL, delay, "TIMER");
   return;
   data = NULL;
}
Exemple #8
0
static void
cb_close(void *data)
{
   /* save options */
   save_config();
   /* User closed, so forget session restart */
   Epplet_unremember();
   /* Sync drawing and ipc to eesh */
   Esync();
   exit(0);
   data = NULL;
}
Exemple #9
0
/* Scroll the string around */
static void
scroll_string(void *data)
{
   char                buf[20];
   static int          back = 0;
   static int          pause = 0;

   if (dtext.len > 19)
     {
	if (dtext.pos > (dtext.len - 19))
	  {
	     dtext.pos = dtext.len - 19;
	     back = 1;
	     pause = 1;
	  }
	else if (dtext.pos == 0)
	  {
	     back = 0;
	     pause = 1;
	  }

	Esnprintf(buf, sizeof(buf), "%s", dtext.str + dtext.pos);

	if (!back)
	   dtext.pos += 1;
	else
	   dtext.pos -= 1;

	Epplet_change_label(lbl_url, buf);
     }
   else
      Epplet_change_label(lbl_url, dtext.str);

   if (pause)
     {
	Epplet_timer(scroll_string, NULL, 1.0, "SCROLL_TIMER");
	pause = 0;
     }
   else
      Epplet_timer(scroll_string, NULL, 0.3, "SCROLL_TIMER");

   Esync();

   return;
   data = NULL;
}
Exemple #10
0
void temporizador(void *datos){
  FILE *aTemp;
  FILE *aFreq;
  aTemp=fopen("/sys/class/hwmon/hwmon0/temp1_input","r");
  fgets(textoTemperatura,3,aTemp);
  fclose(aTemp);
  aFreq=popen("cpufreq-info -f","r");
  fgets(texto,5,aFreq);
  if(texto[0]=='8')texto[3]='\0';
  pclose(aFreq);
  
  temperatura=atoi(textoTemperatura);
  Epplet_gadget_data_changed(barra);
  sprintf(textoTemperatura,"%s C",textoTemperatura);
  Epplet_change_label(visorNumerico,texto);
  Epplet_change_label(visorTemperatura,textoTemperatura);
  Esync();
  Epplet_timer(temporizador, NULL, REFRESCO, "TIMER");
  //datos = NULL;
}
static void
resize(int nw, int nh, int c)
{
   char                tmp_w[8], tmp_h[8];

   w = nw;
   h = nh;
   save_config();

   if (!c)
     {
	Epplet_unremember();
     }
   Epplet_cleanup();
   Esync();

   Esnprintf(tmp_w, sizeof(tmp_w), "%d", w);
   Esnprintf(tmp_h, sizeof(tmp_h), "%d", h);
   execlp(prog_name, prog_name, "-w", tmp_w, "-h", tmp_h, (c ? "-c" : NULL),
	  NULL);
   fprintf(stderr, "execlp() failed -- %s\n", strerror(errno));
}
Exemple #12
0
static void
timer_cb(void *data)
{
   char                buff[1024];
   double              val = -1.0, val2 = -1.0;
   unsigned char       invalid;
   unsigned long       in_bytes, out_bytes;
   static unsigned long in_delta = -1, out_delta = -1;

   invalid = net_get_bytes_inout(device_string, &val, &val2);
   if (invalid)
     {
	D(("Failed to open %s -- %s\n", device_string, strerror(errno)));
	Esync();
	Epplet_timer(timer_cb, NULL, 10.0, "TIMER");
	return;
     }
   if ((last_in == 0) && (last_out == 0))
     {
	last_in = (unsigned long)val;
	last_out = (unsigned long)val2;
	Esync();
	Epplet_timer(timer_cb, NULL, 1.0, "TIMER");
	return;
     }

   in_bytes = (unsigned long)val - last_in;
   out_bytes = (unsigned long)val2 - last_out;
   D(("In %lu, out %lu\n", in_bytes, out_bytes));

   if (in_bytes > max_in)
     {
	max_in = in_bytes;
	Esnprintf(buff, sizeof(buff), "%lu", max_in);
	Epplet_modify_config("max_in", buff);
	D(("Set max_in to %lu\n", max_in));
     }
   if (in_bytes != in_delta)
     {
	in_val = (int)((((float)in_bytes) / max_in) * 100.0);
	Epplet_gadget_data_changed(in_bar);
	sprintf(buff, "I: ");
	show_size(in_bytes, buff + 3);
	strcat(buff, "/s");
	Epplet_change_label(in_label, buff);
	in_delta = in_bytes;
     }
   last_in += in_bytes;

   if (out_bytes > max_out)
     {
	max_out = out_bytes;
	Esnprintf(buff, sizeof(buff), "%lu", max_out);
	Epplet_modify_config("max_out", buff);
	D(("Set max_out to %lu\n", max_out));
     }
   if (out_bytes != out_delta)
     {
	out_val = (int)((((float)out_bytes) / max_out) * 100.0);
	Epplet_gadget_data_changed(out_bar);
	sprintf(buff, "O: ");
	show_size(out_bytes, buff + 3);
	strcat(buff, "/s");
	Epplet_change_label(out_label, buff);
	out_delta = out_bytes;
     }
   last_out += out_bytes;

   Esync();
   Epplet_timer(timer_cb, NULL, 1.0, "TIMER");
   return;
   data = NULL;
}
static void
timer_cb(void *data)
{

   FILE               *fp;
   char                buff[1024];
   unsigned long       a, b, c, d, e;
   unsigned long       in_blks = 0, out_blks = 0;
   static unsigned long last_in = 0, last_out = 0, in_delta = 0, out_delta = 0;

   if (!(fp = fopen("/proc/diskstats", "r")))
     {
	if (!(fp = fopen("/proc/stat", "r")))
	  {
	     D(("Failed to open /proc/stat -- %s\n", strerror(errno)));
	     return;
	  }
     }

   for (; fgets(buff, sizeof(buff), fp);)
     {
	if (BEGMATCH(buff, "disk_rblk"))
	  {
	     sscanf(buff, "%*s %lu %lu %lu %lu", &a, &b, &c, &d);
	     in_blks = a + b + c + d;
	     fgets(buff, sizeof(buff), fp);
	     sscanf(buff, "%*s %lu %lu %lu %lu", &a, &b, &c, &d);
	     out_blks = a + b + c + d;
	  }
	else if (BEGMATCH(buff, "disk_io"))
	  {
	     char               *pbuff = buff + 9;

	     for (in_blks = out_blks = 0; *pbuff == '(';
		  pbuff = strchr(pbuff, ' ') + 1)
	       {
		  pbuff = strchr(++pbuff, '(');
		  sscanf(++pbuff, "%lu,%lu,%lu,%lu,%lu", &a, &b, &c, &d, &e);
		  in_blks += c;
		  out_blks += e;
	       }
	  }
	else
	  {
	     char                tmp[64];

	     /* Hopefully no one can exploit /proc/diskstats without root. :-) */
	     sscanf(buff, "%lu %lu %s %*u %*u %lu %*u %*u %*u %lu", &a, &b, tmp,
		    &c, &d);
	     /* Check for hdX or sdX, or md#, or...??? */
	     if ((((*tmp == 'h') || (*tmp == 's')) && (tmp[1] == 'd')
		  && (isalpha(tmp[2])) && (tmp[3] == 0)) || ((*tmp == 'm')
							     && (tmp[1] == 'd')
							     &&
							     (isdigit(tmp[2]))))
	       {
		  in_blks += c;
		  out_blks += d;
	       }
	  }
     }
   in_blks -= last_in;
   out_blks -= last_out;
   fclose(fp);

   if (last_in)
     {
	/* We must have some history data to do anything. */
	if (in_blks > max_in)
	  {
	     max_in = in_blks;
	     Esnprintf(buff, sizeof(buff), "%lu", max_in);
	     Epplet_modify_config("max_in", buff);
	  }
	if (in_blks != in_delta)
	  {
	     in_val = (int)((((float)in_blks) / max_in) * 100.0);
	     Epplet_gadget_data_changed(in_bar);
	     sprintf(buff, "I: ");
	     show_size(in_blks * 512, buff + 3);
	     strcat(buff, "/s");
	     Epplet_change_label(in_label, buff);
	  }
	in_delta = in_blks;
     }
   last_in += in_blks;

   if (last_out)
     {
	/* We must have some history data to do anything. */
	if (out_blks > max_out)
	  {
	     max_out = out_blks;
	     Esnprintf(buff, sizeof(buff), "%lu", max_out);
	     Epplet_modify_config("max_out", buff);
	  }
	if (out_blks != out_delta)
	  {
	     out_val = (int)((((float)out_blks) / max_out) * 100.0);
	     Epplet_gadget_data_changed(out_bar);
	     sprintf(buff, "O: ");
	     show_size(out_blks * 512, buff + 3);
	     strcat(buff, "/s");
	     Epplet_change_label(out_label, buff);
	  }
	out_delta = out_blks;
     }
   last_out += out_blks;

   Esync();
   Epplet_timer(timer_cb, NULL, 1.0, "TIMER");
   return;
   data = NULL;
}
Exemple #14
0
void cerrar(void *datos){
  Epplet_unremember();
  Esync();
  //datos = NULL;
  exit(0);
}