aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid <dbphillipsnz@gmail.com>2014-05-02 11:22:22 +1200
committerDavid <dbphillipsnz@gmail.com>2014-05-02 11:22:22 +1200
commit91b78cb1f60430a9f2e87c27af26c883f95de754 (patch)
tree23814bc764a8a1fa5d910974c5b6b3639411e5bd
parent139ee2e0ef4eb42fe0f17e7bf1bfedd7812d27a5 (diff)
downloadparamano-91b78cb1f60430a9f2e87c27af26c883f95de754.tar.xz
Done
-rw-r--r--config_file.c6
-rw-r--r--defaults.c11
-rw-r--r--defaults.h3
-rw-r--r--freq_tray/getcore.c2
-rw-r--r--trayfreq.c42
-rw-r--r--trayfreq_set/trayfreq_set_interface.c15
-rw-r--r--trayfreq_set/trayfreq_set_interface.h2
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 <glib.h>
+#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 <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
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);