static void get_loadavg(Enna_Buffer *b) { float load; #ifdef __FreeBSD__ double loadavg[3]; if (getloadavg(loadavg, 3) == -1) return; load = loadavg[0] * 100.0; enna_buffer_append(b, "<hilight>"); enna_buffer_append(b, _("CPU Load:")); enna_buffer_appendf(b, "</hilight> %d%%<br>", (int) load); #else /* __FreeBSD__ */ FILE *f; char buf[256] = { 0 }; char *ld, *x; f = fopen("/proc/loadavg", "r"); if (!f) return; x = fgets(buf, sizeof(buf), f); x = strchr(buf, ' '); if (!x) goto err_loadavg; ld = strndup(buf, sizeof(x)); load = enna_util_atof(ld) * 100.0; enna_buffer_append(b, "<hilight>"); enna_buffer_append(b, _("CPU Load:")); enna_buffer_appendf(b, "</hilight> %d%%<br>", (int) load); err_loadavg: if (ld) free(ld); if (f) fclose(f); #endif /* !__FreeBSD__ */ }
static void get_cpuinfos(Enna_Buffer *b) { #ifdef __FreeBSD__ int nbcpu = 0, i, freq; char cpu_model[256]; size_t len; char buf[256]; len = sizeof(cpu_model); if (sysctlbyname("hw.model", &cpu_model, &len, NULL, 0)) return; len = sizeof(nbcpu); if (sysctlbyname("hw.ncpu", &nbcpu, &len, NULL, 0)) return; enna_buffer_append(b, "<hilight>"); enna_buffer_append(b, _("Available CPUs:")); enna_buffer_append(b, "</hilight><br>"); for (i = 0; i < nbcpu; i++) { snprintf(buf, sizeof(buf), "dev.cpu.%d.freq", i); len = sizeof(freq); if (sysctlbyname(buf, &freq, &len, NULL, 0)) continue; enna_buffer_appendf(b, " * CPU #%d: %s, running at %dMHz<br>", i, cpu_model, freq); } #else /* __FreeBSD__ */ FILE *f; char buf[256] = { 0 }; f = fopen("/proc/cpuinfo", "r"); if (!f) return; enna_buffer_append(b, "<hilight>"); enna_buffer_append(b, _("Available CPUs:")); enna_buffer_append(b, "</hilight><br>"); while (fgets(buf, sizeof(buf), f)) { char *x; buf[strlen(buf) - 1] = '\0'; if (!strncmp(buf, STR_CPU, strlen(STR_CPU))) { x = strchr(buf, ':'); enna_buffer_appendf(b, " * CPU #%s: ", x + 2); } else if (!strncmp(buf, STR_MODEL, strlen(STR_MODEL))) { char *y; x = strchr(buf, ':'); y = x + 2; while (*y) { if (*y != ' ') enna_buffer_appendf(b, "%c", *y); else { if (*(y + 1) != ' ') enna_buffer_appendf(b, " "); } (void) *y++; } } else if (!strncmp(buf, STR_MHZ, strlen(STR_MHZ))) { x = strchr(buf, ':'); enna_buffer_append(b, _(", running at")); enna_buffer_appendf(b, " %d MHz<br>", (int) enna_util_atof(x + 2)); } } fclose(f); #endif /* !__FreeBSD__ */ }
void enna_panel_infos_set_text(Evas_Object *obj, Enna_Metadata *m) { Enna_Buffer *buf; const char *codec, *value; const char *alternative_title, *title, *categories, *year; const char *length, *director, *actors, *overview; Smart_Data *sd = evas_object_data_get(obj, "sd"); int len; if (!sd) return; if (!m) { edje_object_part_text_set(sd->o_edje, "panel.textblock", _("No such information ...")); return; } buf = enna_buffer_new(); enna_buffer_append(buf, "<h4><hl><sd><b>"); alternative_title = enna_metadata_meta_get(m, "alternative_title", 1); title = enna_metadata_meta_get(m, "title", 1); enna_buffer_append(buf, alternative_title ? alternative_title : title); enna_buffer_append(buf, "</b></sd></hl></h4><br>"); len = buf->len; categories = enna_metadata_meta_get(m, "category", 5); if (categories) enna_buffer_appendf(buf, "<h2>%s</h2><br>", categories); year = enna_metadata_meta_get(m, "year", 1); if (year) enna_buffer_append(buf, year); length = enna_metadata_meta_duration_get(m); if (length) { if (year) enna_buffer_append(buf, " - "); enna_buffer_appendf(buf, "%s", length); } enna_buffer_append(buf, "<br><br>"); len += 8; director = enna_metadata_meta_get(m, "director", 1); if (director) { enna_buffer_append(buf, "<ul>"); enna_buffer_append(buf, _("Director:")); enna_buffer_appendf(buf, " </ul> %s<br>", director); } actors = enna_metadata_meta_get(m, "actor", 5); if (actors) { enna_buffer_append(buf, "<ul>"); enna_buffer_append(buf, _("Cast:")); enna_buffer_appendf(buf, " </ul> %s<br>", actors); } if (director || actors) enna_buffer_append(buf, "<br>"); overview = enna_metadata_meta_get(m, "synopsis", 1); if (overview) enna_buffer_appendf(buf, "%s", overview); enna_buffer_append(buf, "<br><br>"); len += 8; codec = enna_metadata_meta_get(m, "video_codec", 1); if (codec) { const char *width, *height, *aspect; width = enna_metadata_meta_get(m, "width", 1); height = enna_metadata_meta_get(m, "height", 1); aspect = enna_metadata_meta_get(m, "video_aspect", 1); enna_buffer_append(buf, "<hl>"); enna_buffer_append(buf, _("Video:")); enna_buffer_appendf(buf, " </hl> %s", codec); if (width && height) enna_buffer_appendf(buf, ", %sx%s", width, height); if (aspect) { float ratio = enna_util_atof(aspect) / 10000; if (ratio) enna_buffer_appendf(buf, ", %.2f", ratio); } enna_buffer_appendf(buf, "<br>"); eina_stringshare_del(width); eina_stringshare_del(height); eina_stringshare_del(aspect); eina_stringshare_del(codec); } codec = enna_metadata_meta_get(m, "audio_codec", 1); if (codec) { const char *channels, *bitrate; channels = enna_metadata_meta_get(m, "audio_channels", 1); bitrate = enna_metadata_meta_get(m, "audio_bitrate", 1); enna_buffer_append(buf, "<hl>"); enna_buffer_append(buf, _("Audio:")); enna_buffer_appendf(buf, " </hl> %s", codec); if (channels) enna_buffer_appendf(buf, ", %s ch.", channels); if (bitrate) enna_buffer_appendf(buf, ", %i kbps", atoi(bitrate) / 1000); enna_buffer_appendf(buf, "<br>"); eina_stringshare_del(channels); eina_stringshare_del(bitrate); eina_stringshare_del(codec); } value = enna_metadata_meta_get(m, "filesize", 1); if (value) { enna_buffer_append(buf, "<hl>"); enna_buffer_append(buf, _("Size:")); enna_buffer_appendf(buf, " </hl> %.2f MB<br>", atol(value) / 1024.0 / 1024.0); } eina_stringshare_del(value); /* tell if no more infos are available */ if (buf->len == len) enna_buffer_append(buf, _("No further information can be retrieved")); edje_object_part_text_set(sd->o_edje, "panel.textblock", buf->buf); enna_buffer_free(buf); eina_stringshare_del(alternative_title); eina_stringshare_del(title); eina_stringshare_del(categories); eina_stringshare_del(year); eina_stringshare_del(length); eina_stringshare_del(director); eina_stringshare_del(actors); eina_stringshare_del(overview); }