summary refs log tree commit diff stats
path: root/src/htm
diff options
context:
space:
mode:
authorBerke Viktor <bviktor@hexchat.org>2012-09-22 20:32:52 +0200
committerBerke Viktor <bviktor@hexchat.org>2012-09-22 20:32:52 +0200
commitbc7eac560f827ac19dd9db16eac64a5da00b8dba (patch)
tree10977dbd430bab0a4298aff4cf6ff0b88979bb47 /src/htm
parentcc694ad47311c7413b28387c967524b6f54b622c (diff)
Force relative path for logs, for full path you can still use symlinks anyway
Diffstat (limited to 'src/htm')
0 files changed, 0 insertions, 0 deletions
7 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
/*
 * SysInfo - sysinfo plugin for HexChat
 * Copyright (c) 2015 Patrick Griffis.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <glib.h>
#include "parse.h"
#include "match.h"
#include "sysinfo.h"
#include "format.h"
#include "df.h"

char *sysinfo_backend_get_os(void)
{
	char name[bsize];

	if (xs_parse_distro (name) != 0)
	{
		return NULL;
	}

	return g_strdup(name);
}

char *sysinfo_backend_get_disk(void)
{
	gint64 total, free;

	if (xs_parse_df (&total, &free))
	{
		return NULL;
	}

	return sysinfo_format_disk (total, free);
}

char *sysinfo_backend_get_memory(void)
{
	unsigned long long mem_total;
	unsigned long long mem_free;
	unsigned long long swap_total;
	unsigned long long swap_free;
	char *swap_fmt = NULL, *mem_fmt, *ret;

	if (xs_parse_meminfo (&mem_total, &mem_free, 0) == 1)
	{
		return NULL;
	}
	if (xs_parse_meminfo (&swap_total, &swap_free, 1) != 1 && swap_total != 0)
	{
		swap_fmt = sysinfo_format_memory (swap_total, swap_free);
	}

	mem_fmt = sysinfo_format_memory (mem_total, mem_free);

	if (swap_fmt)
	{
		ret = g_strdup_printf ("Physical: %s Swap: %s", mem_fmt, swap_fmt);
		g_free (mem_fmt);
		g_free (swap_fmt);
	}
	else
		ret = mem_fmt;

	return ret;
}

char *sysinfo_backend_get_cpu(void)
{
	char model[bsize];
	char vendor[bsize];
	char buffer[bsize];
	double freq;
	int giga = 0;

	if (xs_parse_cpu (model, vendor, &freq) != 0)
	{
		return NULL;
	}

	if (freq > 1000)
	{
		freq /= 1000;
		giga = 1;
	}

	if (giga)
	{
		g_snprintf (buffer, bsize, "%s (%.2fGHz)", model, freq);
	}
	else
	{
		g_snprintf (buffer, bsize, "%s (%.0fMHz)", model, freq);
	}
	
	return g_strdup (buffer);
}

char *sysinfo_backend_get_gpu(void)
{
	char vid_card[bsize];
	char agp_bridge[bsize];
	char buffer[bsize];
	int ret;

	if ((ret = xs_parse_video (vid_card)) != 0)
	{
		return NULL;
	}

	if (xs_parse_agpbridge (agp_bridge) != 0)
	{
		g_snprintf (buffer, bsize, "%s", vid_card);
	}
	else
	{
		g_snprintf (buffer, bsize, "%s @ %s", vid_card, agp_bridge);
	}

	return g_strdup (buffer);
}

char *sysinfo_backend_get_sound(void)
{
	char sound[bsize];

	if (xs_parse_sound (sound) != 0)
	{
		return NULL;
	}
	return g_strdup (sound);
}

char *sysinfo_backend_get_uptime(void)
{
	gint64 uptime;

	if ((uptime = xs_parse_uptime ()) == 0)
	{
		return NULL;
	}

	return sysinfo_format_uptime (uptime);
}

char *sysinfo_backend_get_network(void)
{
	char ethernet_card[bsize];

	if (xs_parse_ether (ethernet_card))
	{
		g_strlcpy (ethernet_card, "None found", bsize);
	}
	
	return g_strdup (ethernet_card);
}