aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid <dbphillipsnz@gmail.com>2014-07-20 13:01:10 +1200
committerDavid <dbphillipsnz@gmail.com>2014-07-20 13:01:10 +1200
commitce5d47962ac628521a658f20b3f48aee7d041fe3 (patch)
tree7f16220115512d443b7e7c2bb7a881620ac26887
downloadparamano-ce5d47962ac628521a658f20b3f48aee7d041fe3.tar.xz
Removed licence symlink all together
-rw-r--r--Makefile148
-rw-r--r--README.md75
-rw-r--r--bat_tray.c214
-rw-r--r--bat_tray.h34
-rw-r--r--common.c81
-rw-r--r--common.h48
-rw-r--r--config_file.c53
-rw-r--r--config_file.h34
-rw-r--r--defaults.c40
-rw-r--r--defaults.h36
-rw-r--r--getcore.c63
-rw-r--r--getcore.h25
-rw-r--r--getfreq.c154
-rw-r--r--getfreq.h31
-rw-r--r--getgov.c127
-rw-r--r--getgov.h28
-rw-r--r--lc/fr.po68
-rw-r--r--reload.c45
-rw-r--r--reload.h23
-rw-r--r--themes/default/cpufreq-0.pngbin0 -> 939 bytes
-rw-r--r--themes/default/cpufreq-100.pngbin0 -> 1057 bytes
-rw-r--r--themes/default/cpufreq-25.pngbin0 -> 942 bytes
-rw-r--r--themes/default/cpufreq-50.pngbin0 -> 988 bytes
-rw-r--r--themes/default/cpufreq-75.pngbin0 -> 1014 bytes
-rw-r--r--themes/default/traybat-0-charging.pngbin0 -> 1270 bytes
-rw-r--r--themes/default/traybat-0.pngbin0 -> 922 bytes
-rw-r--r--themes/default/traybat-100-charging.pngbin0 -> 1261 bytes
-rw-r--r--themes/default/traybat-100.pngbin0 -> 839 bytes
-rw-r--r--themes/default/traybat-20-charging.pngbin0 -> 1297 bytes
-rw-r--r--themes/default/traybat-20.pngbin0 -> 923 bytes
-rw-r--r--themes/default/traybat-40-charging.pngbin0 -> 1288 bytes
-rw-r--r--themes/default/traybat-40.pngbin0 -> 925 bytes
-rw-r--r--themes/default/traybat-60-charging.pngbin0 -> 1305 bytes
-rw-r--r--themes/default/traybat-60.pngbin0 -> 912 bytes
-rw-r--r--themes/default/traybat-80-charging.pngbin0 -> 1280 bytes
-rw-r--r--themes/default/traybat-80.pngbin0 -> 872 bytes
-rw-r--r--themes/default/traybat-charged.pngbin0 -> 1913 bytes
-rw-r--r--tray.c406
-rw-r--r--tray.h33
-rw-r--r--trayfreq.c152
-rw-r--r--trayfreq.conf.src41
-rw-r--r--trayfreq.desktop7
-rw-r--r--trayfreq.h24
-rw-r--r--trayfreq_set.c160
-rw-r--r--trayfreq_set_interface.c50
-rw-r--r--trayfreq_set_interface.h25
46 files changed, 2225 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..589df84
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,148 @@
+# Tabsize: 4
+
+# Build utils
+MAKE = make
+CC = gcc
+
+# Directories
+PREFIX=/usr
+BINDIR=$(PREFIX)/bin
+SYSCONFDIR=/etc
+SHAREDIR=$(PREFIX)/share
+LOCALEDIR=$(SHAREDIR)/locale
+
+# External program/support programs
+SUDO=$(BINDIR)/sudo
+TRAYFREQ_SET=$(BINDIR)/trayfreq-set
+
+# Misc
+TRAYFREQ_CONF=$(SYSCONFDIR)/trayfreq.conf
+ROOT_UID=0
+
+
+ifdef DEBUG
+ EXTRA_CFLAGS+=-DDEBUG
+endif
+
+EXTRA_CFLAGS+= -DPREFIX=\"$(PREFIX)\" \
+ -DBINDIR=\"$(BINDIR)\" \
+ -DSUDO=\"$(SUDO)\" \
+ -DTRAYFREQ_SET=\"$(TRAYFREQ_SET)\" \
+ -DTRAYFREQ_CONF=\"$(TRAYFREQ_CONF)\" \
+ -DLOCALEDIR=\"$(LOCALEDIR)\" \
+ -DSHAREDIR=\"$(SHAREDIR)\" \
+ -DROOT_UID=$(ROOT_UID)
+
+
+DEPS = bat_tray.h \
+ common.h \
+ config_file.h \
+ defaults.h \
+ getcore.h \
+ getfreq.h \
+ getgov.h \
+ reload.h \
+ trayfreq.h \
+ tray.h \
+ trayfreq_set_interface.h
+
+CFLAGS = -I/usr/include/gtk-2.0 \
+ -I/usr/lib/gtk-2.0/include \
+ -I/usr/include/pango-1.0 \
+ -I/usr/include/cairo \
+ -I/usr/include/gdk-pixbuf-2.0 \
+ -I/usr/include/atk-1.0 \
+ -I/usr/include/glib-2.0 \
+ -I/usr/lib/glib-2.0/include \
+ -Wall \
+ -D_=gettext
+
+LDFLAGS = -lgtk-3 \
+ -lgobject-2.0 \
+ -lglib-2.0
+########################################################################
+# Make entire suite
+all: trayfreq trayfreq-set lang trayfreq.conf
+########################################################################
+
+
+########################################################################
+# Make main trayfreq system tray program
+trayfreq: bat_tray.o \
+ common.o \
+ config_file.o \
+ defaults.o \
+ getcore.o \
+ getfreq.o \
+ getgov.o \
+ reload.o \
+ trayfreq.o \
+ tray.o \
+ trayfreq_set_interface.o
+ $(CC) -o $@ $? $(LDFLAGS)
+
+########################################################################
+# Make trayfreq-set utility
+trayfreq-set: \
+ trayfreq_set.o \
+ getcore.o \
+ getfreq.o \
+ getgov.o
+
+ $(CC) -o $@ $? $(LDFLAGS)
+########################################################################
+
+
+########################################################################
+%.o: %.c $(DEPS)
+ $(CC) -c -o $@ $< $(CFLAGS) $(EXTRA_CFLAGS)
+########################################################################
+
+
+########################################################################
+# Make language file(s)
+lang:
+ msgfmt -c -o lc/fr.mo lc/fr.po
+########################################################################
+
+
+########################################################################
+# Prepare template config file
+trayfreq.conf:
+ sed -e 's:SHAREDIR:$(SHAREDIR):g' \
+ -e 's:TRAYFREQ_CONF:$(TRAYFREQ_CONF):g' \
+ trayfreq.conf.src > trayfreq.conf
+########################################################################
+
+
+########################################################################
+# Strip all symbols from binaries
+strip:
+ strip -s trayfreq trayfreq-set
+
+########################################################################
+
+
+########################################################################
+# Remove generated files
+clean:
+ rm -f trayfreq trayfreq-set *.o lc/*.mo trayfreq.conf
+########################################################################
+
+
+########################################################################
+# Install entire suite
+install:
+ mkdir -p $(DESTDIR)/$(SHAREDIR)/trayfreq/
+ cp -r themes $(DESTDIR)/$(SHAREDIR)/trayfreq/
+
+ install -Dm 644 lc/fr.mo $(DESTDIR)/$(LOCALEDIR)/fr/LC_MESSAGES/trayfreq.mo
+
+ install -Dm 644 trayfreq.conf $(DESTDIR)/etc/trayfreq.conf
+ install -Dm 644 trayfreq.desktop $(DESTDIR)/etc/xdg/autostart/trayfreq.desktop
+
+ install -Dm 755 trayfreq $(DESTDIR)/$(BINDIR)/trayfreq
+ install -Dm 755 trayfreq-set $(DESTDIR)/$(BINDIR)/trayfreq-set
+
+ ln -s ../../../etc/trayfreq.conf $(DESTDIR)/$(SHAREDIR)/trayfreq/trayfreq.conf
+########################################################################
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..2072b48
--- /dev/null
+++ b/README.md
@@ -0,0 +1,75 @@
+What?
+=====
+
+This is a fork of trayfreq, intended to work on modern Linux systems.
+The original trayfreq wasn't compatible with Archlinux, due to the migration away from a `/proc/acpi` directory.
+I forked the project and got it working again.
+
+If you're using ArchLinux, just jump over to the [AUR page for this software](https://aur.archlinux.org/packages/trayfreq-archlinux) and install it that way.
+
+Despite the software's name, it should work on other distros as well.
+
+
+Runtime Dependencies
+--------------------
+
+* gtk3
+* sudo
+
+Building
+========
+Due to KISS, I don't tend to use ./configure scripts for relatively small programs.
+Instead, it's up to the user to check they have the right libraries.
+The sort of parameters you might pass to a ./configure can instead be passed to make.
+
+Here's a list:
+
+* BINDIR to override default binary directory (`/usr/bin`) for trayfreq and trayfreq-set
+* PREFIX to prefix all paths with something
+* LOCALE_DIR to override default of `/usr/share/locale`
+* SUDO to override default sudo program `/usr/bin/sudo`
+* MAKE to override default make program `make`
+* CC to override default compiler `gcc`
+* TRAYFREQ_SET to override default trayfreq-set program of `PREFIX/BINDIR/trayfreq-set`
+* DESTDIR (only for `make install` -- see below)
+
+If you'd like a huge amount of debug information on the tty every time you run trayfreq or trayfreq-set, then set DEBUG to something, eg:
+
+ make all DEBUG=yeah
+
+
+Extreme example for nutty system with binaries at `/exec` and sudo `/exec/sodu`:
+
+ make all BINDIR=/exec SUDO=/exec/sodu
+
+
+Installation
+============
+A plain `make install` should work if you're installing straight to `/`, i.e. you're not building a package or anything.
+If you *are* building a package or installing to a special dir, then you might want something like this:
+
+ make install DESTDIR=/path/to/package/temp/dir
+
+This will prefix **all** paths with `/path/to/package/temp/dir` while installing.
+
+Autostarting
+------------
+`make install` will copy a .desktop file to /etc/xdg/autostart, meaning that all xdg-compliant window managers should start it automatically when Bob logs in.
+Bob's WM starts these programs as root, thus he is fully able to change the governor.
+
+Alice uses a non-xdg-compliant WM (e.g. dwm) so trayfreq is run as the user `alice`.
+She doesn't have permission to write to the files under `/sys/` so trayfreq can't change the governor.
+Alice needs to make trayfreq run `trayfreq-set` through sudo.
+This can be done in the configuration file.
+Then, she also needs to give herself passwordless permission to run `trayfreq-set` through sudo:
+
+
+ # ... (/etc/sudoers
+ alice ALL = NOPASSWD: /usr/bin/trayfreq-set
+ # ...
+
+Simple.
+
+Screenshots 'n' Stuff
+=====================
+See the [official page](http://batchbin.ueuo.com/projects/trayfreq-archlinux) for screenshots
diff --git a/bat_tray.c b/bat_tray.c
new file mode 100644
index 0000000..ac8fc94
--- /dev/null
+++ b/bat_tray.c
@@ -0,0 +1,214 @@
+/************************************************************************
+ * This file is part of trayfreq-archlinux. *
+ * *
+ * trayfreq-archlinux 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 3 of the *
+ * License, or (at your option) any later version. *
+ * *
+ * trayfreq-archlinux 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 trayfreq-archlinux. If not, see *
+ * <http://www.gnu.org/licenses/>. *
+ ************************************************************************/
+
+
+#include "bat_tray.h"
+
+#include <gtk/gtk.h>
+#include <libintl.h>
+#include "common.h"
+#include "defaults.h"
+
+
+static GtkStatusIcon* tray;
+
+int bat_num; // Shortcoming: we only detect one battery
+char CHARGE_VALUE_PATH[FILE_PATH_SIZE];
+char CHARGE_STATE_PATH[FILE_PATH_SIZE];
+
+/***********************************************************************
+ * Return the battery level percentage
+ **********************************************************************/
+int get_bat_percent()
+{
+ return get_int_value_from_file(CHARGE_VALUE_PATH);
+}
+
+
+#define TOOLTIP_TEXT_SIZE 128
+char tooltip_text[TOOLTIP_TEXT_SIZE];
+
+
+/***********************************************************************
+ * Updates the battery tray tooltip text
+ **********************************************************************/
+static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean keyboard_mode,GtkTooltip* tooltip,gpointer data)
+{
+ char msg[TOOLTIP_TEXT_SIZE];
+
+ switch(get_battery_state())
+ {
+ case STATE_DISCHARGING:
+ debug("Discharging\n");
+ sprintf(msg, _("Discharging (%d%%)"), get_bat_percent());
+ break;
+
+ case STATE_CHARGING:
+ debug("Charging\n");
+ sprintf(msg, _("Charging (%d%%)"), get_bat_percent());
+ break;
+
+ case STATE_CHARGED:
+ debug("Charged\n");
+ sprintf(msg, _("Fully charged") );
+ break;
+
+ default:
+ debug("Unknown\n");
+ sprintf(msg, _("Unknown status") );
+ break;
+ }
+
+ debug("Setting tooltip text to '%s'\n",msg);
+ gtk_tooltip_set_text(tooltip, msg);
+
+ return true;
+}
+
+
+/***********************************************************************
+ * Updates the battery tray icon based upon battery percent
+ **********************************************************************/
+gboolean update_icon(gpointer user_data)
+{
+ char *icon_file;
+ char percent_string[4]; // worst case scenario 100 + \0
+ unsigned int rounded;
+
+ rounded = 20* (int)((get_bat_percent()+10)/20); // Round percentage to 0, 20, 40, 60, 80 or 100
+
+ debug("Rounded/adjusted percentage: %d\n",rounded);
+ sprintf(percent_string, "%d", rounded);
+
+ switch ( get_battery_state() )
+ {
+ case STATE_DISCHARGING:
+ icon_file = g_strconcat(_DEFAULT_THEME, "/traybat-", percent_string, ".png", NULL);
+ break;
+
+ case STATE_CHARGING:
+ icon_file = g_strconcat(_DEFAULT_THEME, "/traybat-", percent_string, "-charging.png", NULL);
+ break;
+
+ default:
+ icon_file = g_strconcat(_DEFAULT_THEME, "/traybat-charged.png", NULL);
+ break;
+ }
+
+ debug("Setting tray icon to '%s'\n",icon_file);
+ gtk_status_icon_set_from_file(tray, icon_file);
+ return true;
+}
+
+
+
+/***********************************************************************
+ * Initialise the tray and related variables
+ **********************************************************************/
+void bat_tray_init()
+{
+ // Get the battery number, store it for later
+ bat_num = get_bat_num();
+
+ // Set up battery info filenames/paths
+ sprintf(CHARGE_VALUE_PATH, "/sys/class/power_supply/BAT%d/capacity", bat_num);
+ sprintf(CHARGE_STATE_PATH, "/sys/class/power_supply/BAT%d/status", bat_num);
+
+ debug("Spawning new status icon\n");
+ tray = gtk_status_icon_new();
+ char* icon_file = g_strconcat(_DEFAULT_THEME, "/traybat-charged.png", NULL);
+ gtk_status_icon_set_from_file(tray, icon_file);
+ gtk_status_icon_set_has_tooltip (tray, TRUE);
+ g_signal_connect(G_OBJECT(tray), "query-tooltip", GTK_SIGNAL_FUNC(update_tooltip), NULL);
+ g_timeout_add(5000, update_icon, NULL);
+}
+
+
+/***********************************************************************
+ * Show the battery tray
+ **********************************************************************/
+void bat_tray_show()
+{
+ debug("Showing tray\n");
+ gtk_status_icon_set_visible(tray, TRUE);
+}
+
+
+/***********************************************************************
+ * Hide the battery tray
+ **********************************************************************/
+void bat_tray_hide()
+{
+ debug("Hiding tray\n");
+ gtk_status_icon_set_visible(tray, FALSE);
+}
+
+
+/***********************************************************************
+ * Return the battery state
+ **********************************************************************/
+int get_battery_state()
+{
+ if (file_has_line(CHARGE_STATE_PATH, "Discharging"))
+ {
+ debug("Battery discharging\n");
+ return STATE_DISCHARGING;
+ }
+
+ if (file_has_line(CHARGE_STATE_PATH, "Full"))
+ {
+ debug("Battery full\n");
+ return STATE_CHARGED;
+ }
+
+ if (file_has_line(CHARGE_STATE_PATH, "Charging"))
+ {
+ debug("Battery charging\n");
+ return STATE_CHARGING;
+ }
+ debug("Fallthrough: unknown status\n");
+ return STATE_UNKNOWN;
+}
+
+/***********************************************************************
+ * Get the number of the first (who has more than one?) battery
+ * Returns -1 if no battery present
+ **********************************************************************/
+int get_bat_num()
+{
+ FILE* fd;
+ gchar file[40];
+ unsigned int i;
+ for(i = 0; i < 3; i++)
+ {
+ sprintf(file, "/sys/class/power_supply/BAT%d/present", i);
+ debug("Attempting to open '%s'\n",file);
+ if( (fd = fopen(file, "r")) )
+ {
+ debug("Found battery %d\n",i);
+ if (fgetc(fd) == '1')
+ {
+ debug("Battery %d is present\n",i);
+ fclose(fd);
+ return i;
+ }
+ }
+ }
+ debug("Fallthrough: couldn't find battery\n");
+ return -1;
+}
diff --git a/bat_tray.h b/bat_tray.h
new file mode 100644
index 0000000..e459a11
--- /dev/null
+++ b/bat_tray.h
@@ -0,0 +1,34 @@
+/************************************************************************
+ * This file is part of trayfreq-archlinux. *
+ * *
+ * trayfreq-archlinux 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 3 of the *
+ * License, or (at your option) any later version. *
+ * *
+ * trayfreq-archlinux 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 trayfreq-archlinux. If not, see *
+ * <http://www.gnu.org/licenses/>. *
+ ************************************************************************/
+
+#ifndef BAT_TRAY_H
+#define BAT_TRAY_H
+
+#define STATE_CHARGING 0
+#define STATE_DISCHARGING 1
+#define STATE_CHARGED 2
+#define STATE_FULL STATE_CHARGED
+#define STATE_UNKNOWN 3
+
+void bat_tray_init();
+void bat_tray_show();
+void bat_tray_hide();
+int get_battery_state();
+int get_bat_num();
+
+#endif /* ifndef BAT_TRAY_H */
diff --git a/common.c b/common.c
new file mode 100644
index 0000000..3bf7dd1
--- /dev/null
+++ b/common.c
@@ -0,0 +1,81 @@
+/************************************************************************
+ * This file is part of trayfreq-archlinux. *
+ * *
+ * trayfreq-archlinux 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 3 of the *
+ * License, or (at your option) any later version. *
+ * *
+ * trayfreq-archlinux 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 trayfreq-archlinux. If not, see *
+ * <http://www.gnu.org/licenses/>. *
+ ************************************************************************/
+
+#include "common.h"
+
+#include <stdio.h> /* fopen, fgets, printf */
+#include <stdlib.h> /* atoi */
+#include <string.h> /* lots of functions */
+
+/***********************************************************************
+ * Return integer value from first line in file
+ **********************************************************************/
+int get_int_value_from_file(const char* filename)
+{
+ FILE* fd;
+ char buffer[512];
+ int value;
+
+ if(!(fd = fopen(filename, "r")))
+ return -1;
+
+ if (fgets(buffer, sizeof(buffer), fd))
+ value = get_int(buffer);
+
+ fclose(fd);
+ return value;
+}
+
+
+/***********************************************************************
+ * Return true/false if a file has specified line of text
+ **********************************************************************/
+bool file_has_line(const char *filename, const char *line)
+{
+ FILE* fd;
+ char buffer[512];
+
+ if (!(fd = fopen(filename, "r")))
+ return false;
+
+ while (fgets(buffer, sizeof(buffer), fd) != NULL)
+ {
+ if(strstr(buffer, line) != NULL)
+ {
+ fclose(fd);
+ return true;
+ }
+ }
+ fclose(fd);
+ return false;
+}
+
+
+/***********************************************************************
+ * Fetches first number (ie the 35 of "35 123") from a
+ * string
+ **********************************************************************/
+int get_int(const char* string)
+{
+ char* first_num;
+
+ first_num = strpbrk(string, "0123456789");
+ debug("first_num: '%s'\n",first_num);
+
+ return atoi(first_num);
+}
diff --git a/common.h b/common.h
new file mode 100644
index 0000000..ca1be0f
--- /dev/null
+++ b/common.h
@@ -0,0 +1,48 @@
+/************************************************************************
+ * This file is part of trayfreq-archlinux. *
+ * *
+ * trayfreq-archlinux 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 3 of the *
+ * License, or (at your option) any later version. *
+ * *
+ * trayfreq-archlinux 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 trayfreq-archlinux. If not, see *
+ * <http://www.gnu.org/licenses/>. *
+ ************************************************************************/
+
+#ifndef COMMON_H
+#define COMMON_H
+
+#include <stdbool.h>
+
+int get_int_value_from_file(const char* filename);
+int get_int(const char* string);
+bool file_has_line(const char *filename, const char *line);
+
+#include <stdio.h>
+// <ew> Stringification of line number
+#define STRING2(x) #x
+#define STRING(x) STRING2(x)
+#define STR_LINE STRING(__LINE__)
+// </ew>
+
+
+#ifdef DEBUG
+/*
+ Make debug macros into empty space if debug mode's not enabled.
+ Otherwise, make debug macro calls into appropriate printf()s
+*/
+ #define debug(...) printf("DEBUG: "__FILE__":"STR_LINE" --- "__VA_ARGS__)
+#else
+ #define debug(...);
+#endif
+
+#define info(...) printf("INFO: "__FILE__":"STR_LINE" --- "__VA_ARGS__)
+#define FILE_PATH_SIZE 2048
+#endif
diff --git a/config_file.c b/config_file.c
new file mode 100644
index 0000000..169b82a
--- /dev/null
+++ b/config_file.c
@@ -0,0 +1,53 @@
+/************************************************************************
+ * This file is part of trayfreq-archlinux. *
+ * *
+ * trayfreq-archlinux 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 3 of the *
+ * License, or (at your option) any later version. *
+ * *
+ * trayfreq-archlinux 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 trayfreq-archlinux. If not, see *
+ * <http://www.gnu.org/licenses/>. *
+ ************************************************************************/
+
+#include "config_file.h"
+#include "common.h"
+
+gboolean config_open(struct config_file* config_file)
+{
+ if(config_file->key_file)
+ {
+ debug("Freeing config_file->keyfile\n");
+ g_key_file_free(config_file->key_file);
+ }
+
+ debug("Creating new config_file->key_file\n");
+ config_file->key_file = g_key_file_new();
+ gboolean success = g_key_file_load_from_file(
+ config_file->key_file,
+ config_file->file_name,
+ G_KEY_FILE_NONE,
+ NULL);
+ debug("Returning %s\n",success? "TRUE" : "FALSE");
+ return success;
+}
+
+void config_close(struct config_file* config_file)
+{
+ debug("Freeing key_file with %s value\n",config_file->key_file == NULL? "NULL":"non-NULL");
+ g_key_file_free(config_file->key_file);
+}
+
+gchar* config_get_key(struct config_file* config_file, const gchar* group_name, const gchar* key_name)
+{
+ return g_key_file_get_value(config_file->key_file,
+ group_name,
+ key_name,
+ NULL);
+}
diff --git a/config_file.h b/config_file.h
new file mode 100644
index 0000000..d8e150b
--- /dev/null
+++ b/config_file.h
@@ -0,0 +1,34 @@
+/************************************************************************
+ * This file is part of trayfreq-archlinux. *
+ * *
+ * trayfreq-archlinux 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 3 of the *
+ * License, or (at your option) any later version. *
+ * *
+ * trayfreq-archlinux 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 trayfreq-archlinux. If not, see *
+ * <http://www.gnu.org/licenses/>. *
+ ************************************************************************/
+
+#ifndef CONFIG_FILE_H
+#define CONFIG_FILE_H
+
+#include <glib.h>
+
+struct config_file
+{
+ GKeyFile* key_file;
+ gchar* file_name;
+};
+
+gboolean config_open(struct config_file* config_file);
+void config_close(struct config_file* config_file);
+gchar* config_get_key(struct config_file* config_file, const gchar* group_name, const gchar* key_name);
+
+#endif /* ifndef CONFIG_FILE_H */
diff --git a/defaults.c b/defaults.c
new file mode 100644
index 0000000..627b702
--- /dev/null
+++ b/defaults.c
@@ -0,0 +1,40 @@
+/************************************************************************
+ * This file is part of trayfreq-archlinux. *
+ * *
+ * trayfreq-archlinux 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 3 of the *
+ * License, or (at your option) any later version. *
+ * *
+ * trayfreq-archlinux 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 trayfreq-archlinux. If not, see *
+ * <http://www.gnu.org/licenses/>. *
+ ************************************************************************/
+
+#include "defaults.h"
+
+#include <stdio.h>
+
+char* _DEFAULT_GOV;
+char* _DEFAULT_FREQ;
+char* _DEFAULT_PROG;
+char* _DEFAULT_BAT_GOV;
+char* _DEFAULT_AC_GOV;
+bool _DEFAULT_SHOW_BATTERY = true;
+char _DEFAULT_THEME[2048]; // to do : make dynamic with malloc
+
+void defaults_init()
+{
+ _DEFAULT_GOV = NULL;
+ _DEFAULT_FREQ = NULL;
+ _DEFAULT_PROG = NULL;
+ _DEFAULT_BAT_GOV = NULL;
+ _DEFAULT_AC_GOV = NULL;
+ _DEFAULT_SHOW_BATTERY = true;
+ sprintf (_DEFAULT_THEME, SHAREDIR"/trayfreq/themes/default");
+}
diff --gi