diff options
Diffstat (limited to 'modules/computer')
| -rw-r--r-- | modules/computer/alsa.c | 28 | ||||
| -rw-r--r-- | modules/computer/boots.c | 19 | ||||
| -rw-r--r-- | modules/computer/environment.c | 10 | ||||
| -rw-r--r-- | modules/computer/filesystem.c | 114 | ||||
| -rw-r--r-- | modules/computer/languages.c | 96 | ||||
| -rw-r--r-- | modules/computer/memory.c | 27 | ||||
| -rw-r--r-- | modules/computer/modules.c | 80 | ||||
| -rw-r--r-- | modules/computer/os.c | 511 | ||||
| -rw-r--r-- | modules/computer/uptime.c | 43 | ||||
| -rw-r--r-- | modules/computer/users.c | 21 | 
10 files changed, 558 insertions, 391 deletions
| diff --git a/modules/computer/alsa.c b/modules/computer/alsa.c index e1e7b946..00c1fceb 100644 --- a/modules/computer/alsa.c +++ b/modules/computer/alsa.c @@ -23,16 +23,16 @@ gchar *  computer_get_alsacards(Computer * computer)  {      GSList *p; -    gchar *tmp = g_strdup(_("[Audio Devices]\n")); +    gchar *tmp = g_strdup_printf("[%s]\n", _("Audio Devices"));      gint n = 0;      if (computer->alsa) { -	for (p = computer->alsa->cards; p; p = p->next) { -	    AlsaCard *ac = (AlsaCard *) p->data; +        for (p = computer->alsa->cards; p; p = p->next) { +            AlsaCard *ac = (AlsaCard *) p->data; -	    tmp = h_strdup_cprintf(_("Audio Adapter#%d=%s\n"), -	                           tmp, ++n, ac->friendly_name); -	} +            tmp = h_strdup_cprintf("%s#%d=%s\n", tmp, +                        _("Audio Adapter"), ++n, ac->friendly_name); +        }      }      return tmp; @@ -48,22 +48,22 @@ computer_get_alsainfo(void)      cards = fopen("/proc/asound/cards", "r");      if (!cards) -	return NULL; +        return NULL;      ai = g_new0(AlsaInfo, 1);      while (fgets(buffer, 128, cards)) { -	gchar **tmp; +        gchar **tmp; -	ac = g_new0(AlsaCard, 1); +        ac = g_new0(AlsaCard, 1); -	tmp = g_strsplit(buffer, ":", 0); +        tmp = g_strsplit(buffer, ":", 0); -	ac->friendly_name = g_strdup(tmp[1]); -	ai->cards = g_slist_append(ai->cards, ac); +        ac->friendly_name = g_strdup(tmp[1]); +        ai->cards = g_slist_append(ai->cards, ac); -	g_strfreev(tmp); -	(void)fgets(buffer, 128, cards);	/* skip next line */ +        g_strfreev(tmp); +        (void)fgets(buffer, 128, cards);  /* skip next line */      }      fclose(cards); diff --git a/modules/computer/boots.c b/modules/computer/boots.c index 478e89ac..d8a6d32a 100644 --- a/modules/computer/boots.c +++ b/modules/computer/boots.c @@ -30,22 +30,22 @@ scan_boots_real(void)      scan_os(FALSE);      if (!computer->os->boots) -      computer->os->boots = g_strdup(_("[Boots]\n")); +      computer->os->boots = g_strdup_printf("[%s]\n", _("Boots"));      else        return; -     +      last = popen("last", "r");      if (last) {        while (fgets(buffer, 256, last)) {          if (strstr(buffer, "system boot")) {            gchar **tmp, *buf = buffer; -           +            strend(buffer, '\n'); -           +            while (*buf) {              if (*buf == ' ' && *(buf + 1) == ' ') {                memmove(buf, buf + 1, strlen(buf) + 1); -               +                buf--;              } else {                buf++; @@ -53,13 +53,14 @@ scan_boots_real(void)            }            tmp = g_strsplit(buffer, " ", 0); -          computer->os->boots = h_strdup_cprintf("\n%s %s %s %s=%s|%s", -                                                computer->os->boots, -						tmp[4], tmp[5], tmp[6], tmp[7], tmp[3], tmp[8]); +          computer->os->boots = +            h_strdup_cprintf("\n%s %s %s %s=%s|%s", +              computer->os->boots, +              tmp[4], tmp[5], tmp[6], tmp[7], tmp[3], tmp[8]);            g_strfreev(tmp);          }        } -       +        pclose(last);      }  } diff --git a/modules/computer/environment.c b/modules/computer/environment.c index 2a8d235c..dc0fb6f3 100644 --- a/modules/computer/environment.c +++ b/modules/computer/environment.c @@ -23,19 +23,19 @@ static gchar *_env = NULL;  void scan_env_var(gboolean reload)  {      SCAN_START(); -     +      gchar **envlist;      gint i; -     +      g_free(_env); -     -    _env = g_strdup(_("[Environment Variables]\n")); + +    _env = g_strdup_printf("[%s]\n", _("Environment Variables") );      for (i = 0, envlist = g_listenv(); envlist[i]; i++) {        _env = h_strdup_cprintf("%s=%s\n", _env,                                envlist[i], g_getenv(envlist[i]));      }      g_strfreev(envlist); -     +      SCAN_END();  } diff --git a/modules/computer/filesystem.c b/modules/computer/filesystem.c index a7162777..397dc636 100644 --- a/modules/computer/filesystem.c +++ b/modules/computer/filesystem.c @@ -16,8 +16,8 @@   *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA   *   * Some code from xfce4-mount-plugin, version 0.4.3 - *  Copyright (C) 2005 Jean-Baptiste jb_dul@yahoo.com  - *  Distributed under the terms of GNU GPL 2.  + *  Copyright (C) 2005 Jean-Baptiste jb_dul@yahoo.com + *  Distributed under the terms of GNU GPL 2.   */  #include <string.h> @@ -41,62 +41,64 @@ scan_filesystems(void)      mtab = fopen("/etc/mtab", "r");      if (!mtab) -	return; +        return;      while (fgets(buf, 1024, mtab)) { -	gfloat size, used, avail; -	gchar **tmp; - -	tmp = g_strsplit(buf, " ", 0); -	if (!statfs(tmp[1], &sfs)) { -		gfloat use_ratio; - -		size = (float) sfs.f_bsize * (float) sfs.f_blocks; -		avail = (float) sfs.f_bsize * (float) sfs.f_bavail; -		used = size - avail; - -		if (size == 0.0f) { -			continue; -		} - -		if (avail == 0.0f) { -			use_ratio = 100.0f; -		} else { -			use_ratio = 100.0f * (used / size); -		} - -		gchar *strsize = size_human_readable(size), -		      *stravail = size_human_readable(avail), -	  	      *strused = size_human_readable(used); - -		gchar *strhash; -		 -		strreplacechr(tmp[0], "#", '_'); -		strhash = g_strdup_printf("[%s]\n" -					  "Filesystem=%s\n" -					  "Mounted As=%s\n" -					  "Mount Point=%s\n" -					  "Size=%s\n" -					  "Used=%s\n" -					  "Available=%s\n", -					  tmp[0], -					  tmp[2], -					  strstr(tmp[3], "rw") ? "Read-Write" : -					  "Read-Only", tmp[1], strsize, strused, -					  stravail); -               gchar *key = g_strdup_printf("FS%d", ++count); -		moreinfo_add_with_prefix("COMP", key, strhash); -		g_free(key); - -		fs_list = h_strdup_cprintf("$FS%d$%s=%.2f %% (%s of %s)|%s\n", -					  fs_list, -					  count, tmp[0], use_ratio, stravail, strsize, tmp[1]); - -		g_free(strsize); -		g_free(stravail); -		g_free(strused); -	} -	g_strfreev(tmp); +        gfloat size, used, avail; +        gchar **tmp; + +        tmp = g_strsplit(buf, " ", 0); +        if (!statfs(tmp[1], &sfs)) { +                gfloat use_ratio; + +                size = (float) sfs.f_bsize * (float) sfs.f_blocks; +                avail = (float) sfs.f_bsize * (float) sfs.f_bavail; +                used = size - avail; + +                if (size == 0.0f) { +                        continue; +                } + +                if (avail == 0.0f) { +                        use_ratio = 100.0f; +                } else { +                        use_ratio = 100.0f * (used / size); +                } + +                gchar *strsize = size_human_readable(size), +                      *stravail = size_human_readable(avail), +                      *strused = size_human_readable(used); + +                gchar *strhash; + +                strreplacechr(tmp[0], "#", '_'); +                strhash = g_strdup_printf("[%s]\n" +                        "%s=%s\n" +                        "%s=%s\n" +                        "%s=%s\n" +                        "%s=%s\n" +                        "%s=%s\n" +                        "%s=%s\n", +                        tmp[0], /* path */ +                        _("Filesystem"), tmp[2], +                        _("Mounted As"), ( strstr(tmp[3], "rw") != NULL) ? _("Read-Write") : _("Read-Only"), +                        _("Mount Point"), tmp[1], +                        _("Size"), strsize, +                        _("Used"), strused, +                        _("Available"), stravail); +                gchar *key = g_strdup_printf("FS%d", ++count); +                moreinfo_add_with_prefix("COMP", key, strhash); +                g_free(key); + +                fs_list = h_strdup_cprintf("$FS%d$%s=%.2f %% (%s of %s)|%s\n", +                                          fs_list, +                                          count, tmp[0], use_ratio, stravail, strsize, tmp[1]); + +                g_free(strsize); +                g_free(stravail); +                g_free(strused); +        } +        g_strfreev(tmp);      }      fclose(mtab); diff --git a/modules/computer/languages.c b/modules/computer/languages.c index 5877c41c..d4681839 100644 --- a/modules/computer/languages.c +++ b/modules/computer/languages.c @@ -20,6 +20,7 @@  #include "hardinfo.h"  #include "computer.h" +#include "cpu_util.h" /* for UNKIFNULL() */  void  scan_languages(OperatingSystem * os) @@ -67,43 +68,64 @@ scan_languages(OperatingSystem * os)  	    g_strfreev(tmp);  	} else { -	    gchar *currlocale; - -	    retval = h_strdup_cprintf("$%s$%s=%s\n", retval, name, name, title); - -#define FIELD(f) f ? f : "(Unknown)" -	    currlocale = g_strdup_printf("[Locale Information]\n" -					 "Name=%s (%s)\n" -					 "Source=%s\n" -					 "Address=%s\n" -					 "Email=%s\n" -					 "Language=%s\n" -					 "Territory=%s\n" -					 "Revision=%s\n" -					 "Date=%s\n" -					 "Codeset=%s\n", -					 name, FIELD(title), -					 FIELD(source), FIELD(address), -					 FIELD(email), FIELD(language), -					 FIELD(territory), FIELD(revision), -					 FIELD(date), FIELD(codeset)); -#undef FIELD - -           moreinfo_add_with_prefix("COMP", name, currlocale); - -	    g_free(title); -	    g_free(source); -	    g_free(address); -	    g_free(email); -	    g_free(language); -	    g_free(territory); -	    g_free(revision); -	    g_free(date); -	    g_free(codeset); -	     -	    title = source = address = email = language = territory = \ -	        revision = date = codeset = NULL; -	} +        gchar *currlocale; + +        retval = h_strdup_cprintf("$%s$%s=%s\n", retval, name, name, title); + +        UNKIFNULL(title); +        UNKIFNULL(source); +        UNKIFNULL(address); +        UNKIFNULL(email); +        UNKIFNULL(language); +        UNKIFNULL(territory); +        UNKIFNULL(revision); +        UNKIFNULL(date); +        UNKIFNULL(codeset); + +        /* values may have & */ +        title = hardinfo_clean_value(title, 1); +        source = hardinfo_clean_value(source, 1); +        address = hardinfo_clean_value(address, 1); +        email = hardinfo_clean_value(email, 1); +        language = hardinfo_clean_value(language, 1); +        territory = hardinfo_clean_value(territory, 1); + +        currlocale = g_strdup_printf("[%s]\n" +        /* Name */     "%s=%s (%s)\n" +        /* Source */   "%s=%s\n" +        /* Address */  "%s=%s\n" +        /* Email */    "%s=%s\n" +        /* Language */ "%s=%s\n" +        /* Territory */"%s=%s\n" +        /* Revision */ "%s=%s\n" +        /* Date */     "%s=%s\n" +        /* Codeset */  "%s=%s\n", +                     _("Locale Information"), +                     _("Name"), name, title, +                     _("Source"), source, +                     _("Address"), address, +                     _("E-mail"), email, +                     _("Language"), language, +                     _("Territory"), territory, +                     _("Revision"), revision, +                     _("Date"), date, +                     _("Codeset"), codeset ); + +        moreinfo_add_with_prefix("COMP", name, currlocale); + +        g_free(title); +        g_free(source); +        g_free(address); +        g_free(email); +        g_free(language); +        g_free(territory); +        g_free(revision); +        g_free(date); +        g_free(codeset); + +        title = source = address = email = language = territory = \ +            revision = date = codeset = NULL; +    }      }      fclose(locale); diff --git a/modules/computer/memory.c b/modules/computer/memory.c index 3d320e8a..dc8599c2 100644 --- a/modules/computer/memory.c +++ b/modules/computer/memory.c @@ -28,23 +28,26 @@ computer_get_memory(void)      procmem = fopen("/proc/meminfo", "r");      if (!procmem) -	return NULL; +        return NULL;      mi = g_new0(MemoryInfo, 1);      while (fgets(buffer, 128, procmem)) { -	gchar **tmp = g_strsplit(buffer, ":", 2); - -	tmp[0] = g_strstrip(tmp[0]); -	tmp[1] = g_strstrip(tmp[1]); - -	get_int("MemTotal", mi->total); -	get_int("MemFree", mi->free); -	get_int("Cached", mi->cached); - -	g_strfreev(tmp); +        gchar **tmp = g_strsplit(buffer, ":", 2); +        if (tmp[1] == NULL) { +            g_strfreev(tmp); +            continue; +        } +        tmp[0] = g_strstrip(tmp[0]); +        tmp[1] = g_strstrip(tmp[1]); + +        get_int("MemTotal", mi->total); +        get_int("MemFree", mi->free); +        get_int("Cached", mi->cached); + +        g_strfreev(tmp);      }      fclose(procmem); -     +      mi->used = mi->total - mi->free;      mi->total  /= 1000; diff --git a/modules/computer/modules.c b/modules/computer/modules.c index bbc05f42..df876e3a 100644 --- a/modules/computer/modules.c +++ b/modules/computer/modules.c @@ -20,6 +20,7 @@  #include "hardinfo.h"  #include "computer.h" +#include "cpu_util.h" /* for STRIFNULL() */  #define GET_STR(field_name,ptr)      					\    if (!ptr && strstr(tmp[0], field_name)) {				\ @@ -42,7 +43,7 @@ scan_modules_do(void)      }      g_free(module_list); -     +      module_list = NULL;      moreinfo_del_with_prefix("COMP:MOD"); @@ -51,7 +52,7 @@ scan_modules_do(void)          return;      lsmod = popen(lsmod_path, "r");      if (!lsmod) { -        g_free(lsmod_path);  +        g_free(lsmod_path);  	return;      } @@ -99,7 +100,7 @@ scan_modules_do(void)  	   remove_quotes(license); */  	/* old modutils displays <none> when there's no value for a -	   given field; this is not desirable in the module name  +	   given field; this is not desirable in the module name  	   display, so change it to an empty string */  	if (description && g_str_equal(description, "<none>")) {  	    g_free(description); @@ -121,38 +122,45 @@ scan_modules_do(void)  				      modname,  				      description ? description : ""); -#define NONE_IF_NULL(var) (var) ? (var) : "N/A" - -	/* create the module information string */ -	strmodule = g_strdup_printf("[Module Information]\n" -				    "Path=%s\n" -				    "Used Memory=%.2fKiB\n" -				    "[Description]\n" -				    "Name=%s\n" -				    "Description=%s\n" -				    "Version Magic=%s\n" -				    "[Copyright]\n" -				    "Author=%s\n" -				    "License=%s\n", -				    NONE_IF_NULL(filename), -				    memory / 1024.0, -				    modname, -				    NONE_IF_NULL(description), -				    NONE_IF_NULL(vermagic), -				    NONE_IF_NULL(author), -				    NONE_IF_NULL(license)); - -	/* if there are dependencies, append them to that string */ -	if (deps && strlen(deps)) { -	    gchar **tmp = g_strsplit(deps, ",", 0); - -	    strmodule = h_strconcat(strmodule, -                                    "\n[Dependencies]\n", -                                    g_strjoinv("=\n", tmp), -                                    "=\n", NULL); -	    g_strfreev(tmp); -	    g_free(deps); -	} +    STRIFNULL(filename, _("(Not available)") ); +    STRIFNULL(description, _("(Not available)") ); +    STRIFNULL(vermagic, _("(Not available)") ); +    STRIFNULL(author, _("(Not available)") ); +    STRIFNULL(license, _("(Not available)") ); + +    /* create the module information string */ +    strmodule = g_strdup_printf("[%s]\n" +                        "%s=%s\n" +                        "%s=%.2f %s\n" +                        "[%s]\n" +                        "%s=%s\n" +                        "%s=%s\n" +                        "%s=%s\n" +                        "[%s]\n" +                        "%s=%s\n" +                        "%s=%s\n", +                        _("Module Information"), +                        _("Path"), filename, +                        _("Used Memory"), memory / 1024.0, _("KiB"), +                        _("Description"), +                        _("Name"), modname, +                        _("Description"), description, +                        _("Version Magic"), vermagic, +                        _("Copyright"), +                        _("Author"), author, +                        _("License"), license ); + +    /* if there are dependencies, append them to that string */ +    if (deps && strlen(deps)) { +        gchar **tmp = g_strsplit(deps, ",", 0); + +        strmodule = h_strconcat(strmodule, +                                "\n[", _("Dependencies"), "]\n", +                                g_strjoinv("=\n", tmp), +                                "=\n", NULL); +        g_strfreev(tmp); +        g_free(deps); +    }  	moreinfo_add_with_prefix("COMP", hashkey, strmodule);  	g_free(hashkey); @@ -164,6 +172,6 @@ scan_modules_do(void)  	g_free(filename);      }      pclose(lsmod); -     +      g_free(lsmod_path);  } diff --git a/modules/computer/os.c b/modules/computer/os.c index 3caf6c26..a8886f64 100644 --- a/modules/computer/os.c +++ b/modules/computer/os.c @@ -16,6 +16,7 @@   *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA   */ +#include <gdk/gdkx.h>  #include <string.h>  #include <sys/utsname.h>  #include "hardinfo.h" @@ -24,219 +25,350 @@  static gchar *  get_libc_version(void)  { -    FILE *libc; -    gchar buf[256], *tmp, *p; -    char *libc_paths[] = { -		"/lib/ld-uClibc.so.0", "/lib64/ld-uClibc.so.0", -		"/lib/libc.so.6", "/lib64/libc.so.6" -	}; -	int i; -	 -	for (i=0; i < 4; i++) { -		if (g_file_test(libc_paths[i], G_FILE_TEST_EXISTS)) break; -	} -	switch (i) { -		case 0: case 1: return g_strdup("uClibc Library"); -		case 2: case 3: break; // gnu libc, continue processing -		default: goto err; -	} - -    libc = popen(libc_paths[i], "r"); -    if (!libc) goto err; - -    (void)fgets(buf, 256, libc); -    if (pclose(libc)) goto err; - -    tmp = strstr(buf, "version "); -    if (!tmp) goto err; - -    p = strchr(tmp, ','); -    if (p) *p = '\0'; -    else goto err; - -    return g_strdup_printf(_("GNU C Library version %s (%sstable)"), -                           strchr(tmp, ' ') + 1, -                           strstr(buf, " stable ") ? "" : _("un")); -  err: +    static const struct { +        const char *test_cmd; +        const char *match_str; +        const char *lib_name; +        gboolean try_ver_str; +        gboolean use_stderr; +    } libs[] = { +        { "ldd --version", "GLIBC", N_("GNU C Library"), TRUE, FALSE}, +        { "ldd --version", "GNU libc", N_("GNU C Library"), TRUE, FALSE}, +        { "ldconfig -V", "GLIBC", N_("GNU C Library"), TRUE, FALSE}, +        { "ldconfig -V", "GNU libc", N_("GNU C Library"), TRUE, FALSE}, +        { "ldconfig -v", "uClibc", N_("uClibc or uClibc-ng"), FALSE, FALSE}, +        { "diet", "diet version", N_("diet libc"), TRUE, TRUE}, +        { NULL } +    }; +    int i; + +    for (i = 0; libs[i].test_cmd; i++) { +        gboolean spawned; +        gchar *out, *err, *p; + +        spawned = g_spawn_command_line_sync(libs[i].test_cmd, +            &out, &err, NULL, NULL); +        if (!spawned) +            continue; + +        if (libs[i].use_stderr) { +            p = strend(idle_free(err), '\n'); +            g_free(out); +        } else { +            p = strend(idle_free(out), '\n'); +            g_free(err); +        } + +        if (!p || !strstr(p, libs[i].match_str)) +            continue; + +        if (libs[i].try_ver_str) { +            /* skip the first word, likely "ldconfig" or name of utility */ +            const gchar *ver_str = strchr(p, ' '); + +            if (ver_str) { +                return g_strdup_printf("%s / %s", _(libs[i].lib_name), +                    ver_str + 1); +            } +        } + +	return g_strdup(_(libs[i].lib_name)); +    } +      return g_strdup(_("Unknown"));  } -#include <gdk/gdkx.h> +static gchar *detect_kde_version(void) +{ +    const gchar *cmd; +    const gchar *tmp = g_getenv("KDE_SESSION_VERSION"); +    gchar *out; +    gboolean spawned; + +    if (tmp && tmp[0] == '4') { +        cmd = "kwin --version"; +    } else { +        cmd = "kcontrol --version"; +    } + +    spawned = g_spawn_command_line_sync(cmd, &out, NULL, NULL, NULL); +    if (!spawned) +        return NULL; + +    tmp = strstr(idle_free(out), "KDE: "); +    return tmp ? g_strdup(tmp + strlen("KDE: ")) : NULL; +} + +static gchar * +detect_gnome_version(void) +{ +    gchar *tmp; +    gchar *out; +    gboolean spawned; + +    spawned = g_spawn_command_line_sync( +        "gnome-shell --version", &out, NULL, NULL, NULL); +    if (spawned) { +        tmp = strstr(idle_free(out), _("GNOME Shell ")); + +        if (tmp) { +            tmp += strlen(_("GNOME Shell ")); +            return g_strdup_printf("GNOME %s", strend(tmp, '\n')); +        } +    } + +    spawned = g_spawn_command_line_sync( +        "gnome-about --gnome-version", &out, NULL, NULL, NULL); +    if (spawned) { +        tmp = strstr(idle_free(out), _("Version: ")); + +        if (tmp) { +            tmp += strlen(_("Version: ")); +            return g_strdup_printf("GNOME %s", strend(tmp, '\n')); +        } +    } + +    return NULL; +} -void -detect_desktop_environment(OperatingSystem * os) +static gchar * +detect_window_manager(void)  { -    const gchar *tmp = g_getenv("GNOME_DESKTOP_SESSION_ID"); -    FILE *version; -    char vers[16]; +    GdkScreen *screen = gdk_screen_get_default(); +    const gchar *windowman; +    const gchar *curdesktop; + +    if (!screen || !GDK_IS_SCREEN(screen)) +        return NULL; + +    windowman = gdk_x11_screen_get_window_manager_name(screen); +    if (g_str_equal(windowman, "Xfwm4")) +        return g_strdup("XFCE 4"); + +    curdesktop = g_getenv("XDG_CURRENT_DESKTOP"); +    if (curdesktop) { +        const gchar *desksession = g_getenv("DESKTOP_SESSION"); + +        if (desksession && !g_str_equal(curdesktop, desksession)) +            return g_strdup(desksession); +    } + +    return g_strdup_printf(_("Unknown (Window Manager: %s)"), windowman); +} + +static gchar * +desktop_with_session_type(const gchar *desktop_env) +{ +    const char *tmp; + +    tmp = g_getenv("XDG_SESSION_TYPE");      if (tmp) { -	/* FIXME: this might not be true, as the gnome-panel in path -	   may not be the one that's running. -	   see where the user's running panel is and run *that* to -	   obtain the version. */ -	version = popen("gnome-about --gnome-version", "r"); -	if (version) { -	    (void)fscanf(version, _("Version: %s"), vers); -	    if (pclose(version)) -	        goto unknown; -	} else { -	    goto unknown; -	} - -	os->desktop = g_strdup_printf("GNOME %s", vers); -    } else if (g_getenv("KDE_FULL_SESSION")) { - -	if (g_getenv("KDE_SESSION_VERSION") && strstr(g_getenv("KDE_SESSION_VERSION"),(gchar *)"4")) { -	    version = popen("kwin --version", "r"); -	} else { -	    version = popen("kcontrol --version", "r"); -	} - -	if (version) { -	    char buf[32]; - -	    (void)fgets(buf, 32, version); - -	    (void)fscanf(version, "KDE: %s", vers); -	    if (pclose(version)) -	        goto unknown; -	} else { -	    goto unknown; -	} - -	os->desktop = g_strdup_printf("KDE %s", vers); -    } else { -      unknown: -        os->desktop = NULL; -         -	if (!g_getenv("DISPLAY")) { -	    os->desktop = g_strdup(_("Terminal")); -	} else { -            GdkScreen *screen = gdk_screen_get_default(); - -            if (screen && GDK_IS_SCREEN(screen)) { -              const gchar *windowman; - -              windowman = gdk_x11_screen_get_window_manager_name(screen); -              if (g_str_equal(windowman, "Xfwm4")) { -                  /* FIXME: check if xprop -root | grep XFCE_DESKTOP_WINDOW is defined */ -                  os->desktop = g_strdup("XFCE 4"); -              } else if ((tmp = g_getenv("XDG_CURRENT_DESKTOP"))) { -                  os->desktop = g_strdup(tmp); -                  if ((tmp = g_getenv("DESKTOP_SESSION")) && !g_str_equal(os->desktop, tmp)) { -                      g_free(os->desktop); -                      os->desktop = g_strdup(tmp); -                  } -              } - -              if (!os->desktop) { -                  os->desktop = g_strdup_printf(_("Unknown (Window Manager: %s)"), -                                                windowman); -              } -            } else { -                  os->desktop = g_strdup(_("Unknown")); -            } -	} +        if (!g_str_equal(tmp, "unspecified")) +            return g_strdup_printf(_(/*/{desktop environment} on {session type}*/ "%s on %s"), desktop_env, tmp); +    } + +    return g_strdup(desktop_env); +} + +static gchar * +detect_xdg_environment(const gchar *env_var) +{ +    const gchar *tmp; + +    tmp = g_getenv(env_var); +    if (!tmp) +        return NULL; + +    if (g_str_equal(tmp, "GNOME") || g_str_equal(tmp, "gnome")) { +        gchar *maybe_gnome = detect_gnome_version(); + +        if (maybe_gnome) +            return maybe_gnome;      } +    if (g_str_equal(tmp, "KDE") || g_str_equal(tmp, "kde")) { +        gchar *maybe_kde = detect_kde_version(); + +        if (maybe_kde) +            return maybe_kde; +    } + +    return g_strdup(tmp); +} + +static gchar * +detect_desktop_environment(void) +{ +    const gchar *tmp; +    gchar *windowman; + +    windowman = detect_xdg_environment("XDG_CURRENT_DESKTOP"); +    if (windowman) +        return windowman; +    windowman = detect_xdg_environment("XDG_SESSION_DESKTOP"); +    if (windowman) +        return windowman; + +    tmp = g_getenv("KDE_FULL_SESSION"); +    if (tmp) { +        gchar *maybe_kde = detect_kde_version(); + +        if (maybe_kde) +            return maybe_kde; +    } +    tmp = g_getenv("GNOME_DESKTOP_SESSION_ID"); +    if (tmp) { +        gchar *maybe_gnome = detect_gnome_version(); + +        if (maybe_gnome) +            return maybe_gnome; +    } + +    windowman = detect_window_manager(); +    if (windowman) +        return windowman; + +    if (!g_getenv("DISPLAY")) +        return g_strdup(_("Terminal")); + +    return g_strdup(_("Unknown"));  }  gchar *  computer_get_entropy_avail(void)  { +    gchar tab_entropy_fstr[][32] = { +      N_(/*/bits of entropy for rng (0)*/              "(None or not available)"), +      N_(/*/bits of entropy for rng (low/poor value)*/  "%d bits (low)"), +      N_(/*/bits of entropy for rng (medium value)*/    "%d bits (medium)"), +      N_(/*/bits of entropy for rng (high/good value)*/ "%d bits (healthy)") +    };      gint bits = h_sysfs_read_int("/proc/sys/kernel/random", "entropy_avail"); -    if (bits < 200) -        return g_strdup_printf("%d bits (low)", bits); -    if (bits < 3000) -        return g_strdup_printf("%d bits (medium)", bits); -    return g_strdup_printf("%d bits (healthy)", bits); +    if (bits > 3000) return g_strdup_printf(_(tab_entropy_fstr[3]), bits); +    if (bits > 200)  return g_strdup_printf(_(tab_entropy_fstr[2]), bits); +    if (bits > 1)    return g_strdup_printf(_(tab_entropy_fstr[1]), bits); +    return g_strdup_printf(_(tab_entropy_fstr[0]), bits);  } -OperatingSystem * -computer_get_os(void) +gchar * +computer_get_language(void)  { -    struct utsname utsbuf; -    OperatingSystem *os; +    gchar *tab_lang_env[] = +        { "LANGUAGE", "LANG", "LC_ALL", "LC_MESSAGES", NULL }; +    gchar *lc = NULL, *env = NULL, *ret = NULL; +    gint i = 0; + +    lc = setlocale(LC_ALL, NULL); + +    while (tab_lang_env[i] != NULL) { +        env = g_strdup( g_getenv(tab_lang_env[i]) ); +        if (env != NULL)  break; +        i++; +    } + +    if (env != NULL) +        if (lc != NULL) +            ret = g_strdup_printf("%s (%s)", lc, env); +        else +            ret = g_strdup_printf("%s", env); +    else +        if (lc != NULL) +            ret = g_strdup_printf("%s", lc); + +    if (ret == NULL) +        ret = g_strdup( _("(Unknown)") ); + +    return ret; +} + +static gchar * +detect_distro(void) +{ +    static const struct { +        const gchar *file; +        const gchar *codename; +        const gchar *override; +    } distro_db[] = { +#define DB_PREFIX "/etc/" +        { DB_PREFIX "arch-release", "arch", "Arch Linux" }, +        { DB_PREFIX "fatdog-version", "fatdog" }, +        { DB_PREFIX "debian_version", "deb" }, +        { DB_PREFIX "slackware-version", "slk" }, +        { DB_PREFIX "mandrake-release", "mdk" }, +        { DB_PREFIX "mandriva-release", "mdv" }, +        { DB_PREFIX "fedora-release", "fdra" }, +        { DB_PREFIX "coas", "coas" }, +        { DB_PREFIX "environment.corel", "corel"}, +        { DB_PREFIX "gentoo-release", "gnt" }, +        { DB_PREFIX "conectiva-release", "cnc" }, +        { DB_PREFIX "versão-conectiva", "cnc" }, +        { DB_PREFIX "turbolinux-release", "tl" }, +        { DB_PREFIX "yellowdog-release", "yd" }, +        { DB_PREFIX "sabayon-release", "sbn" }, +        { DB_PREFIX "arch-release", "arch" }, +        { DB_PREFIX "enlisy-release", "enlsy" }, +        { DB_PREFIX "SuSE-release", "suse" }, +        { DB_PREFIX "sun-release", "sun" }, +        { DB_PREFIX "zenwalk-version", "zen" }, +        { DB_PREFIX "DISTRO_SPECS", "ppy", "Puppy Linux" }, +        { DB_PREFIX "puppyversion", "ppy", "Puppy Linux" }, +        { DB_PREFIX "distro-release", "fl" }, +        { DB_PREFIX "vine-release", "vine" }, +        { DB_PREFIX "PartedMagic-version", "pmag" }, +         /* +         * RedHat must be the *last* one to be checked, since +         * some distros (like Mandrake) includes a redhat-relase +         * file too. +         */ +        { DB_PREFIX "redhat-release", "rh" }, +#undef DB_PREFIX +        { NULL, NULL } +    }; +    gchar *contents;      int i; -    os = g_new0(OperatingSystem, 1); +    if (g_spawn_command_line_sync("lsb_release -d", &contents, NULL, NULL, NULL)) { +        gchar *tmp = strstr(idle_free(contents), "Description:\t"); -    /* Attempt to get the Distribution name; try using /etc/lsb-release first, -       then doing the legacy method (checking for /etc/$DISTRO-release files) */ -    if (g_file_test("/etc/lsb-release", G_FILE_TEST_EXISTS)) { -	FILE *release; -	gchar buffer[128]; +        if (tmp) +            return g_strdup(tmp + strlen("Description:\t")); +    } -	release = popen("lsb_release -d", "r"); -	if (release) { -            (void)fgets(buffer, 128, release); -            pclose(release); +    for (i = 0; distro_db[i].file; i++) { +        if (!g_file_get_contents(distro_db[i].file, &contents, NULL, NULL)) +            continue; -            os->distro = buffer; -            os->distro = g_strdup(os->distro + strlen("Description:\t")); +        if (distro_db[i].override) { +            g_free(contents); +            return g_strdup(distro_db[i].override);          } -    } else if (g_file_test("/etc/arch-release", G_FILE_TEST_EXISTS)) { -        os->distrocode = g_strdup("arch"); -        os->distro = g_strdup("Arch Linux"); -    } else { -        for (i = 0;; i++) { -            if (distro_db[i].file == NULL) { -                os->distrocode = g_strdup("unk"); -                os->distro = g_strdup(_("Unknown distribution")); -                break; -            } -            if (g_file_test(distro_db[i].file, G_FILE_TEST_EXISTS)) { -                FILE *distro_ver; -                char buf[128]; - -                distro_ver = fopen(distro_db[i].file, "r"); -                if (distro_ver) { -                    (void)fgets(buf, 128, distro_ver); -                    fclose(distro_ver); -                } else { -                    continue; -                } - -                buf[strlen(buf) - 1] = 0; - -                if (!os->distro) { -                    /* -                     * HACK: Some Debian systems doesn't include -                     * the distribuition name in /etc/debian_release, -                     * so add them here. -                     */ -                    if (!strncmp(distro_db[i].codename, "deb", 3) && -                        ((buf[0] >= '0' && buf[0] <= '9') || buf[0] != 'D')) { -                        os->distro = g_strdup_printf -                            ("Debian GNU/Linux %s", buf); -                    } else { -                        os->distro = g_strdup(buf); -                    } -                } - -                if (g_str_equal(distro_db[i].codename, "ppy")) { -                  gchar *tmp; -                    tmp = g_strdup_printf("Puppy Linux"); -                  g_free(os->distro); -                  os->distro = tmp; -                } - -                if (g_str_equal(distro_db[i].codename, "fatdog")) { -                  gchar *tmp; -                    tmp = g_strdup_printf("Fatdog64 [%.10s]", os->distro); -                  g_free(os->distro); -                  os->distro = tmp; -                } - -                os->distrocode = g_strdup(distro_db[i].codename); - -                break; -            } +        if (g_str_equal(distro_db[i].codename, "deb")) { +            /* HACK: Some Debian systems doesn't include the distribuition +             * name in /etc/debian_release, so add them here. */ +            if (isdigit(contents[0]) || contents[0] != 'D') +                return g_strdup_printf("Debian GNU/Linux %s", (char*)idle_free(contents));          } + +        if (g_str_equal(distro_db[i].codename, "fatdog")) +            return g_strdup_printf("Fatdog64 [%.10s]", (char*)idle_free(contents)); + +        return contents;      } -    os->distro = g_strstrip(os->distro); +    return g_strdup(_("Unknown")); +} + +OperatingSystem * +computer_get_os(void) +{ +    struct utsname utsbuf; +    OperatingSystem *os; +    int i; + +    os = g_new0(OperatingSystem, 1); + +    os->distro = g_strstrip(detect_distro());      /* Kernel and hostname info */      uname(&utsbuf); @@ -244,13 +376,16 @@ computer_get_os(void)      os->kernel = g_strdup_printf("%s %s (%s)", utsbuf.sysname,  				 utsbuf.release, utsbuf.machine);      os->hostname = g_strdup(utsbuf.nodename); -    os->language = g_strdup(g_getenv("LC_MESSAGES")); +    os->language = computer_get_language();      os->homedir = g_strdup(g_get_home_dir());      os->username = g_strdup_printf("%s (%s)",  				   g_get_user_name(), g_get_real_name());      os->libc = get_libc_version();      scan_languages(os); -    detect_desktop_environment(os); + +    os->desktop = detect_desktop_environment(); +    if (os->desktop) +        os->desktop = desktop_with_session_type(idle_free(os->desktop));      os->entropy_avail = computer_get_entropy_avail(); diff --git a/modules/computer/uptime.c b/modules/computer/uptime.c index 8eb563fa..5f0f1942 100644 --- a/modules/computer/uptime.c +++ b/modules/computer/uptime.c @@ -26,11 +26,11 @@ computer_get_uptime(void)      gulong minutes;      if ((procuptime = fopen("/proc/uptime", "r")) != NULL) { -	(void)fscanf(procuptime, "%lu", &minutes); -	ui->minutes = minutes / 60; -	fclose(procuptime); +        (void)fscanf(procuptime, "%lu", &minutes); +        ui->minutes = minutes / 60; +        fclose(procuptime);      } else { -	return NULL; +        return NULL;      }      ui->hours = ui->minutes / 60; @@ -45,32 +45,27 @@ gchar *  computer_get_formatted_uptime()  {      UptimeInfo *ui; -    gchar *tmp; +    const gchar *days_fmt, *hours_fmt, *minutes_fmt; +    gchar *full_fmt = NULL, *ret = NULL;      ui = computer_get_uptime(); -    /* FIXME: Use ngettext */ -#define plural(x) ((x > 1) ? "s" : "") +    days_fmt = ngettext("%d day", "%d days", ui->days); +    hours_fmt = ngettext("%d hour", "%d hours", ui->hours); +    minutes_fmt = ngettext("%d minute", "%d minutes", ui->minutes);      if (ui->days < 1) { -	if (ui->hours < 1) { -	    tmp = -		g_strdup_printf("%d minute%s", ui->minutes, -				plural(ui->minutes)); -	} else { -	    tmp = -		g_strdup_printf("%d hour%s, %d minute%s", ui->hours, -				plural(ui->hours), ui->minutes, -				plural(ui->minutes)); -	} +        if (ui->hours < 1) { +            ret = g_strdup_printf(minutes_fmt, ui->minutes); +        } else { +            full_fmt = g_strdup_printf("%s %s", hours_fmt, minutes_fmt); +            ret = g_strdup_printf(full_fmt, ui->hours, ui->minutes); +        }      } else { -	tmp = -	    g_strdup_printf("%d day%s, %d hour%s and %d minute%s", -			    ui->days, plural(ui->days), ui->hours, -			    plural(ui->hours), ui->minutes, -			    plural(ui->minutes)); +        full_fmt = g_strdup_printf("%s %s %s", days_fmt, hours_fmt, minutes_fmt); +        ret = g_strdup_printf(full_fmt, ui->days, ui->hours, ui->minutes);      } - +    g_free(full_fmt);      g_free(ui); -    return tmp; +    return ret;  } diff --git a/modules/computer/users.c b/modules/computer/users.c index e8f891ac..f47320bb 100644 --- a/modules/computer/users.c +++ b/modules/computer/users.c @@ -39,15 +39,16 @@ scan_users_do(void)      while (passwd_) {          gchar *key = g_strdup_printf("USER%s", passwd_->pw_name); -        gchar *val = g_strdup_printf("[User Information]\n" -                "User ID=%d\n" -                "Group ID=%d\n" -                "Home directory=%s\n" -                "Default shell=%s\n", -                (gint) passwd_->pw_uid, -                (gint) passwd_->pw_gid, -                passwd_->pw_dir, -                passwd_->pw_shell); +        gchar *val = g_strdup_printf("[%s]\n" +                "%s=%d\n" +                "%s=%d\n" +                "%s=%s\n" +                "%s=%s\n", +                _("User Information"), +                _("User ID"), (gint) passwd_->pw_uid, +                _("Group ID"), (gint) passwd_->pw_gid, +                _("Home Directory"), passwd_->pw_dir, +                _("Default Shell"), passwd_->pw_shell);          moreinfo_add_with_prefix("COMP", key, val);          strend(passwd_->pw_gecos, ','); @@ -55,6 +56,6 @@ scan_users_do(void)          passwd_ = getpwent();          g_free(key);      } -     +      endpwent();  } | 
