From 91b78cb1f60430a9f2e87c27af26c883f95de754 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 2 May 2014 11:22:22 +1200 Subject: Done --- config_file.c | 6 +++-- defaults.c | 11 ++++----- defaults.h | 3 ++- freq_tray/getcore.c | 2 +- trayfreq.c | 42 ++++++++++++++--------------------- trayfreq_set/trayfreq_set_interface.c | 15 ++++++++++--- trayfreq_set/trayfreq_set_interface.h | 2 ++ 7 files changed, 44 insertions(+), 37 deletions(-) diff --git a/config_file.c b/config_file.c index 602eb92..a62f094 100644 --- a/config_file.c +++ b/config_file.c @@ -28,11 +28,13 @@ gboolean config_open(struct config_file* config_file) debug("Creating new config_file->key_file\n"); config_file->key_file = g_key_file_new(); - - return g_key_file_load_from_file( config_file->key_file, + 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) diff --git a/defaults.c b/defaults.c index dc54dd4..6b605fc 100644 --- a/defaults.c +++ b/defaults.c @@ -18,8 +18,9 @@ #include "defaults.h" -char* _DEFAULT_GOV = NULL; -char* _DEFAULT_FREQ = NULL; -char* _DEFAULT_PROG = NULL; -char* _DEFAULT_BAT_GOV = NULL; -char* _DEFAULT_AC_GOV = NULL; \ No newline at end of file +char* _DEFAULT_GOV; +char* _DEFAULT_FREQ; +char* _DEFAULT_PROG; +char* _DEFAULT_BAT_GOV; +char* _DEFAULT_AC_GOV; +bool _DEFAULT_USE_SUDO = FALSE; diff --git a/defaults.h b/defaults.h index b92859c..f1d4202 100644 --- a/defaults.h +++ b/defaults.h @@ -19,12 +19,13 @@ #ifndef DEFAULTS_H #define DEFAULTS_H -#include +#include "bool.h" char* _DEFAULT_GOV; char* _DEFAULT_FREQ; char* _DEFAULT_PROG; char* _DEFAULT_BAT_GOV; char* _DEFAULT_AC_GOV; +bool _DEFAULT_USE_SUDO; #endif /* ifndef DEFAULTS_H */ diff --git a/freq_tray/getcore.c b/freq_tray/getcore.c index 44b3940..ad4878f 100644 --- a/freq_tray/getcore.c +++ b/freq_tray/getcore.c @@ -32,7 +32,7 @@ static gboolean core_exists(unsigned int core) sprintf(corestr, "%d", core); sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_cur_freq", corestr); - debug("Checking if core %d exists by opening '%s'",core,path); + debug("Checking if core %d exists by opening '%s'\n",core,path); return (gboolean)(fd = fopen(path, "r")); } diff --git a/trayfreq.c b/trayfreq.c index e3b925e..7e5d8d4 100644 --- a/trayfreq.c +++ b/trayfreq.c @@ -63,39 +63,31 @@ void config_init() config.file_name = g_strconcat("/usr/share/trayfreq/trayfreq.config", NULL); gboolean success = config_open(&config); - if(!success) { debug("Couldn't open '%s' for reading\n",config.file_name); g_warning(_("Failed to open config files!\n")); return; } - - gchar * def_gov = config_get_key(&config, "governor", "default"); - gchar * def_freq = config_get_key(&config, "frequency", "default"); - gchar * show_bat = config_get_key(&config, "battery", "show"); - gchar * bat_gov = config_get_key (&config, "battery", "governor"); - gchar * ac_gov = config_get_key (&config, "ac", "governor"); - - if(def_gov) - _DEFAULT_GOV = def_gov; - - if(def_freq) - _DEFAULT_FREQ = def_freq; - - if (bat_gov) - _DEFAULT_BAT_GOV = bat_gov; - - if (ac_gov) - _DEFAULT_AC_GOV = ac_gov; - - if(show_bat) + _DEFAULT_GOV = config_get_key(&config, "governor", "default"); + _DEFAULT_FREQ = config_get_key(&config, "frequency", "default"); + _DEFAULT_BAT_GOV = config_get_key(&config, "battery", "governor"); + _DEFAULT_AC_GOV = config_get_key(&config, "ac", "governor"); + + char* temp = config_get_key(&config, "battery", "show"); + if (temp) + SHOW_BATTERY = ( temp[0] == '1' ); + + temp = config_get_key(&config, "extra", "sudo"); + if (temp) { - if(g_strcmp0(show_bat, "1") == 0) - SHOW_BATTERY = TRUE; - else - SHOW_BATTERY = FALSE; + _DEFAULT_USE_SUDO = ( temp[0] == '1' ); + debug("woo\n"); } + + + debug("%s sudo\n",_DEFAULT_USE_SUDO? "Using" : "Not using"); + g_free(config.file_name); config_close(&config); } diff --git a/trayfreq_set/trayfreq_set_interface.c b/trayfreq_set/trayfreq_set_interface.c index 490d50c..3e26112 100644 --- a/trayfreq_set/trayfreq_set_interface.c +++ b/trayfreq_set/trayfreq_set_interface.c @@ -18,20 +18,29 @@ #include "trayfreq_set_interface.h" -#include #include #include void si_gov(char* gov, int core) { char cmd[256]; - sprintf(cmd, "/usr/bin/trayfreq-set -g %s -c %i",gov,core); + if (_DEFAULT_USE_SUDO) + { + sprintf(cmd, "sudo trayfreq-set -g %s -c %i",gov,core); + } else { + sprintf(cmd, "trayfreq-set -g %s -c %i",gov,core); + } system(cmd); } void si_freq(int freq, int core) { char cmd[256]; - sprintf(cmd, "/usr/bin/trayfreq-set -f %i -c %i",freq,core); + if (_DEFAULT_USE_SUDO) + { + sprintf(cmd, "sudo trayfreq-set -f %i -c %i",freq,core); + } else { + sprintf(cmd, "trayfreq-set -f %i -c %i",freq,core); + } system(cmd); } diff --git a/trayfreq_set/trayfreq_set_interface.h b/trayfreq_set/trayfreq_set_interface.h index bdbf652..c5681e4 100644 --- a/trayfreq_set/trayfreq_set_interface.h +++ b/trayfreq_set/trayfreq_set_interface.h @@ -19,6 +19,8 @@ #ifndef TRAYFREQ_SET_INTERFACE_H #define TRAYFREQ_SET_INTERFACE_H +#include "../defaults.h" + void si_gov(char* gov, int core); void si_freq(int freq, int core); -- cgit v1.1 From cfc6ca44874961ec468147111745c34a5bf1f9c0 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 2 May 2014 11:31:46 +1200 Subject: Changed config file name, spruced default config up --- Makefile | 2 +- data/trayfreq.config | 9 --------- trayfreq.c | 4 ++-- 3 files changed, 3 insertions(+), 12 deletions(-) delete mode 100644 data/trayfreq.config diff --git a/Makefile b/Makefile index 44a3eb7..1a5609c 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,7 @@ install: mkdir -p $(INSTALL_PATH)/usr/share/locale/fr/LC_MESSAGES/ cp lc/fr.mo $(INSTALL_PATH)/usr/share/locale/fr/LC_MESSAGES/trayfreq.mo - install -Dm 644 data/trayfreq.config $(INSTALL_PATH)/usr/share/trayfreq/trayfreq.config + install -Dm 644 data/trayfreq.conf $(INSTALL_PATH)/usr/share/trayfreq/trayfreq.conf install -Dm 644 data/trayfreq.desktop $(INSTALL_PATH)/etc/xdg/autostart/trayfreq.desktop install -Dm 755 trayfreq $(INSTALL_PATH)/usr/bin/trayfreq install -Dm 755 trayfreq-set $(INSTALL_PATH)/usr/bin/trayfreq-set diff --git a/data/trayfreq.config b/data/trayfreq.config deleted file mode 100644 index 8783104..0000000 --- a/data/trayfreq.config +++ /dev/null @@ -1,9 +0,0 @@ -#[battery] -#show=1 -#governor=powersave -#[ac] -#governor=ondemand -#[governor] -#default=ondemand -#[frequency] -#default=800000 diff --git a/trayfreq.c b/trayfreq.c index 7e5d8d4..4c23982 100644 --- a/trayfreq.c +++ b/trayfreq.c @@ -42,7 +42,7 @@ void config_init() gboolean home_config_exists; config.key_file = NULL; - config.file_name = g_strconcat(getenv("HOME"), "/.trayfreq.config", NULL); + config.file_name = g_strconcat(getenv("HOME"), "/.trayfreq.conf", NULL); // Check if ~/.trayfreq.config exists @@ -60,7 +60,7 @@ void config_init() } if(!home_config_exists) - config.file_name = g_strconcat("/usr/share/trayfreq/trayfreq.config", NULL); + config.file_name = g_strconcat("/usr/share/trayfreq/trayfreq.conf", NULL); gboolean success = config_open(&config); if(!success) -- cgit v1.1 From 4532322b98b9cb4104d69daae7867b8df8459815 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 2 May 2014 11:32:06 +1200 Subject: I always forget to add files when I move them --- data/trayfreq.conf | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 data/trayfreq.conf diff --git a/data/trayfreq.conf b/data/trayfreq.conf new file mode 100644 index 0000000..59dc4d8 --- /dev/null +++ b/data/trayfreq.conf @@ -0,0 +1,36 @@ +# Begin /usr/share/trayfreq/trayfreq.conf +# +# Sample config file for trayfreq-archlinux +# + +[battery] +## Uncomment to hide battery icon -- useful for desktop PCs +# show=0 + +## Governor to use for all cores when on battery power +# governor=powersave + +[ac] +## Governor to use for all core while on AC power +## Often set to a performance or non-power-saving governor +# governor=ondemand + +[governor] +## Governor to set all cores to when trayfreq starts +# default=ondemand + + +## The frequency to set the CPU to when trayfreq starts +[frequency] +# default=800000 + + +[extra] +## Uncomment to make trayfreq run trayfreq-set through sudo. +## Useful if your WM doesn't run trayfreq as root, but you'll have to give the user +## trayfreq is run as passwordless sudo access to `trayfreq-set` +# sudo=1 + + +# +# End /usr/share/trayfreq/trayfreq.conf -- cgit v1.1 From 4bb267e8e416c95fddc59d3c954afc37d9a3f67a Mon Sep 17 00:00:00 2001 From: David Date: Fri, 2 May 2014 11:40:21 +1200 Subject: Cured fuzz --- lc/fr.po | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lc/fr.po b/lc/fr.po index 9e237ca..fdcecc5 100644 --- a/lc/fr.po +++ b/lc/fr.po @@ -1,9 +1,8 @@ # French translation of strings for trayfreq-archlinux. # Copyright (C) David Phillips # This file is distributed under the same license as the trayfreq-archlinux package. -# FIRST AUTHOR , YEAR. +# David Phillips , 2014. # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: trayfreq-archlinux 0.5\n" @@ -27,11 +26,11 @@ msgstr "Profil: %s\n" msgid "CPU%i: %s%s" msgstr "CPU%i: %s%s" -#: trayfreq.c:70 +#: trayfreq.c:69 msgid "Failed to open config files!\n" msgstr "Pouvais pas ouvrier les fichiers config !\n" -#: trayfreq.c:113 +#: trayfreq.c:105 msgid "" "GTK Error: gtk_init_check returned FALSE.\n" "Bailing." -- cgit v1.1