mirror of
https://github.com/alsa-project/alsa-tools.git
synced 2025-10-29 05:40:25 -04:00
envy24control save state of LRGang button in config file
From: Dirk Jagdmann <doj@cubic.org> this patch saves the state of the "LR Gang" buttons in a config/pref file, because this button's state is not preserved throughout runs of envy24control. At present it only works, when envy24control is compiled with GTK2 as I have used routines which were introduced with Glib2.
This commit is contained in:
parent
c53973f82e
commit
2ec6fcc317
2 changed files with 84 additions and 0 deletions
75
envy24control/config.c
Normal file
75
envy24control/config.c
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#include <gtk/gtk.h>
|
||||
#include "envy24control.h"
|
||||
|
||||
#if GLIB_CHECK_VERSION(2,2,0)
|
||||
|
||||
#if GLIB_CHECK_VERSION(2,8,0)
|
||||
#define MYMKDIR g_mkdir_with_parents
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#define MYMKDIR mkdir
|
||||
#endif
|
||||
|
||||
GKeyFile *config_file;
|
||||
gboolean config_stereo[20];
|
||||
gchar *config_filename;
|
||||
|
||||
void config_open()
|
||||
{
|
||||
config_filename=g_strdup_printf("%s/%s", g_get_user_config_dir(), "envy24control");
|
||||
config_file=g_key_file_new();
|
||||
g_key_file_load_from_file(config_file, config_filename, G_KEY_FILE_KEEP_COMMENTS, NULL);
|
||||
}
|
||||
|
||||
void config_close()
|
||||
{
|
||||
gsize len=0;
|
||||
gchar *s;
|
||||
g_key_file_set_boolean_list(config_file, "mixer", "stereo",
|
||||
config_stereo, sizeof(config_stereo)/sizeof(config_stereo[0]));
|
||||
s=g_key_file_to_data(config_file, &len, NULL);
|
||||
if(s && len)
|
||||
{
|
||||
MYMKDIR(g_get_user_config_dir(), 0700);
|
||||
FILE *f=fopen(config_filename, "wb");
|
||||
if(f)
|
||||
{
|
||||
fwrite(s, len, 1, f);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
g_free(config_filename); config_filename=0;
|
||||
g_key_file_free(config_file); config_file=0;
|
||||
}
|
||||
|
||||
void config_set_stereo(GtkWidget *but, gpointer data)
|
||||
{
|
||||
gint i=(gint)data;
|
||||
config_stereo[i]=GTK_TOGGLE_BUTTON(but)->active;
|
||||
}
|
||||
|
||||
void config_restore_stereo()
|
||||
{
|
||||
gint i;
|
||||
gsize len=0;
|
||||
gboolean *s=g_key_file_get_boolean_list(config_file, "mixer", "stereo", &len, NULL);
|
||||
if(s)
|
||||
for(i=0; i!=len; ++i)
|
||||
{
|
||||
config_stereo[i]=s[i];
|
||||
if(mixer_stereo_toggle[i])
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mixer_stereo_toggle[i]), s[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* to be done */
|
||||
void config_open() { }
|
||||
void config_close() { }
|
||||
void config_set_stereo(GtkWidget *but, gpointer data) { }
|
||||
void config_restore_stereo() { }
|
||||
|
||||
#endif
|
||||
9
envy24control/config.h
Normal file
9
envy24control/config.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef CONFIG__H
|
||||
#define CONFIG__H
|
||||
|
||||
void config_open();
|
||||
void config_close();
|
||||
void config_set_stereo(GtkWidget *but, gpointer data);
|
||||
void config_restore_stereo();
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue