Mercurial > audlegacy-plugins
changeset 2582:9b4dfc007b87
use more local configuration options
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Tue, 20 May 2008 15:36:47 +0200 |
parents | 6a0755e8c1b3 |
children | 294232665cb0 |
files | src/skins/plugin.c src/skins/plugin.h src/skins/skins_cfg.c src/skins/skins_cfg.h src/skins/ui_skinned_menurow.c src/skins/ui_skinned_window.c |
diffstat | 6 files changed, 110 insertions(+), 88 deletions(-) [+] |
line wrap: on
line diff
--- a/src/skins/plugin.c Tue May 20 14:37:50 2008 +0200 +++ b/src/skins/plugin.c Tue May 20 15:36:47 2008 +0200 @@ -40,15 +40,13 @@ GeneralPlugin *skins_gplist[] = { &skins_gp, NULL }; SIMPLE_GENERAL_PLUGIN(skins, skins_gplist); GtkWidget *mainwin; -skins_cfg_t * config = NULL; gboolean plugin_is_active = FALSE; void skins_init(void) { plugin_is_active = TRUE; g_log_set_handler(NULL, G_LOG_LEVEL_WARNING, g_log_default_handler, NULL); - config = skins_cfg_new(); - skins_cfg_load(config); + skins_cfg_load(); gint width, height; @@ -58,7 +56,7 @@ gtk_window_set_resizable(GTK_WINDOW(mainwin), FALSE); - init_skins(config->skin); + init_skins(config.skin); width = aud_active_skin->properties.mainwin_width; height = aud_active_skin->properties.mainwin_height; @@ -70,11 +68,7 @@ void skins_cleanup(void) { if (plugin_is_active == TRUE) { - - if (config != NULL) { - skins_cfg_delete(config); - config = NULL; - } + skins_cfg_free(); gtk_widget_destroy(mainwin); skin_free(aud_active_skin); aud_active_skin = NULL;
--- a/src/skins/plugin.h Tue May 20 14:37:50 2008 +0200 +++ b/src/skins/plugin.h Tue May 20 15:36:47 2008 +0200 @@ -26,7 +26,6 @@ #include "skins_cfg.h" extern GtkWidget *mainwin; -extern skins_cfg_t *config; void skins_init(void); void skins_cleanup(void);
--- a/src/skins/skins_cfg.c Tue May 20 14:37:50 2008 +0200 +++ b/src/skins/skins_cfg.c Tue May 20 15:36:47 2008 +0200 @@ -25,23 +25,49 @@ #include <stdlib.h> #include <audacious/plugin.h> -skins_cfg_t * skins_cfg_new(void) { - skins_cfg_t *cfg = g_malloc0(sizeof(skins_cfg_t)); - cfg->set = FALSE; - cfg->skin = NULL; - return cfg; +skins_cfg_t config; + +skins_cfg_t skins_default_config = { + .scaled = FALSE, + .always_on_top = FALSE, + .scale_factor = 2.0, + .always_show_cb = TRUE, + .skin = NULL, + .player_shaded = FALSE, + .equalizer_shaded = FALSE, + .playlist_shaded = FALSE, + .dim_titlebar = TRUE, + .show_wm_decorations = FALSE, + .easy_move = TRUE, +}; + +typedef struct skins_cfg_boolent_t { + char const *be_vname; + gboolean *be_vloc; + gboolean be_wrt; +} skins_cfg_boolent; + +static skins_cfg_boolent skins_boolents[] = { + {"always_show_cb", &config.always_show_cb, TRUE}, + {"always_on_top", &config.always_on_top, TRUE}, + {"always_show_cb", &config.always_show_cb, TRUE}, + {"scaled", &config.scaled, TRUE}, + {"player_shaded", &config.player_shaded, TRUE}, + {"equalizer_shaded", &config.equalizer_shaded, TRUE}, + {"playlist_shaded", &config.playlist_shaded, TRUE}, + {"dim_titlebar", &config.dim_titlebar, TRUE}, + {"show_wm_decorations", &config.show_wm_decorations, TRUE}, + {"easy_move", &config.easy_move, TRUE}, +}; + +static gint ncfgbent = G_N_ELEMENTS(skins_boolents); + +void skins_cfg_free() { + if (config.skin) { g_free(config.skin); config.skin = NULL; } } - -void skins_cfg_delete(skins_cfg_t * cfg) { - if (cfg != NULL) { - if (cfg->skin) g_free(cfg->skin); - g_free(cfg); - } -} - -gint skins_cfg_load(skins_cfg_t * cfg) { - mcs_handle_t *cfgfile = aud_cfg_db_open(); +void skins_cfg_load() { + mcs_handle_t *cfgfile = aud_cfg_db_open(); /* if (!aud_cfg_db_get_int(cfgfile, "skins", "field_name", &(cfg->where))) cfg->where = default value @@ -50,36 +76,29 @@ if (!aud_cfg_db_get_bool(cfgfile, "skins", "field_name", &(cfg->where))) cfg->where = FALSE / TRUE; */ - - if (!aud_cfg_db_get_string(cfgfile, "skins", "skin", &(cfg->skin))) - cfg->skin = g_strdup(BMP_DEFAULT_SKIN_PATH); - - if (!aud_cfg_db_get_bool(cfgfile, "skins", "scaled", &(cfg->scaled))) - cfg->scaled = FALSE; - - if (!aud_cfg_db_get_bool(cfgfile, "skins", "always_on_top", &(cfg->always_on_top))) - cfg->always_on_top = FALSE; + + memcpy(&config, &skins_default_config, sizeof(skins_cfg_t)); + int i; + + for (i = 0; i < ncfgbent; ++i) { + aud_cfg_db_get_bool(cfgfile, "skins", + skins_boolents[i].be_vname, + skins_boolents[i].be_vloc); + } - if (!aud_cfg_db_get_float(cfgfile, "skins", "scale_factor", &(cfg->scale_factor))) - cfg->scale_factor = 2.0; - - if (!aud_cfg_db_get_bool(cfgfile, "skins", "always_show_cb", &(cfg->always_show_cb))) - cfg->always_show_cb = TRUE; + if (!aud_cfg_db_get_string(cfgfile, "skins", "skin", &(config.skin))) + config.skin = g_strdup(BMP_DEFAULT_SKIN_PATH); - aud_cfg_db_close( cfgfile ); + if (!aud_cfg_db_get_float(cfgfile, "skins", "scale_factor", &(config.scale_factor))) + config.scale_factor = 2.0; - cfg->set = TRUE; - - return 0; + aud_cfg_db_close(cfgfile); } -gint skins_cfg_save(skins_cfg_t * cfg) { +void skins_cfg_save(skins_cfg_t * cfg) { mcs_handle_t *cfgfile = aud_cfg_db_open(); - if (cfg->set == FALSE) - return -1; - /* aud_cfg_db_set_int(cfgfile, "skins", "field_name", cfg->where); aud_cfg_db_set_string(cfgfile, "skins", "field_name", cfg->where); @@ -87,7 +106,13 @@ */ aud_cfg_db_set_string(cfgfile, "skins", "skin", cfg->skin); - aud_cfg_db_close(cfgfile); + int i; - return 0; + for (i = 0; i < ncfgbent; ++i) + if (skins_boolents[i].be_wrt) + aud_cfg_db_set_bool(cfgfile, "skins", + skins_boolents[i].be_vname, + *skins_boolents[i].be_vloc); + + aud_cfg_db_close(cfgfile); }
--- a/src/skins/skins_cfg.h Tue May 20 14:37:50 2008 +0200 +++ b/src/skins/skins_cfg.h Tue May 20 15:36:47 2008 +0200 @@ -25,19 +25,22 @@ typedef struct { - gboolean set; - gboolean scaled; - gboolean always_on_top; - gfloat scale_factor; - gboolean always_show_cb; - gchar *skin; -} -skins_cfg_t; + gboolean scaled; + gboolean always_on_top; + gfloat scale_factor; + gboolean always_show_cb; + gchar *skin; + gboolean player_shaded, equalizer_shaded, playlist_shaded; + gboolean dim_titlebar; + gboolean show_wm_decorations; + gboolean easy_move; +} skins_cfg_t; +extern skins_cfg_t config; skins_cfg_t * skins_cfg_new(void); -void skins_cfg_delete(skins_cfg_t * cfg); -gint skins_cfg_load(skins_cfg_t * cfg); -gint skins_cfg_save(skins_cfg_t * cfg); +void skins_cfg_free(); +void skins_cfg_load(); +void skins_cfg_save(); #endif
--- a/src/skins/ui_skinned_menurow.c Tue May 20 14:37:50 2008 +0200 +++ b/src/skins/ui_skinned_menurow.c Tue May 20 15:36:47 2008 +0200 @@ -114,8 +114,8 @@ } static void ui_skinned_menurow_init(UiSkinnedMenurow *menurow) { - menurow->scale_selected = config->scaled; - menurow->always_selected = config->always_on_top; + menurow->scale_selected = config.scaled; + menurow->always_selected = config.always_on_top; } GtkWidget* ui_skinned_menurow_new(GtkWidget *fixed, gint x, gint y, gint nx, gint ny, gint sx, gint sy, SkinPixmapId si) { @@ -186,21 +186,21 @@ static void ui_skinned_menurow_size_request(GtkWidget *widget, GtkRequisition *requisition) { UiSkinnedMenurow *menurow = UI_SKINNED_MENUROW(widget); - requisition->width = menurow->width*(menurow->scaled ? config->scale_factor : 1); - requisition->height = menurow->height*(menurow->scaled ? config->scale_factor : 1); + requisition->width = menurow->width*(menurow->scaled ? config.scale_factor : 1); + requisition->height = menurow->height*(menurow->scaled ? config.scale_factor : 1); } static void ui_skinned_menurow_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { UiSkinnedMenurow *menurow = UI_SKINNED_MENUROW (widget); widget->allocation = *allocation; - widget->allocation.x *= (menurow->scaled ? config->scale_factor : 1); - widget->allocation.y *= (menurow->scaled ? config->scale_factor : 1); + widget->allocation.x *= (menurow->scaled ? config.scale_factor : 1); + widget->allocation.y *= (menurow->scaled ? config.scale_factor : 1); if (GTK_WIDGET_REALIZED (widget)) gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height); - menurow->x = widget->allocation.x/(menurow->scaled ? config->scale_factor : 1); - menurow->y = widget->allocation.y/(menurow->scaled ? config->scale_factor : 1); + menurow->x = widget->allocation.x/(menurow->scaled ? config.scale_factor : 1); + menurow->y = widget->allocation.y/(menurow->scaled ? config.scale_factor : 1); } static gboolean ui_skinned_menurow_expose(GtkWidget *widget, GdkEventExpose *event) { @@ -215,7 +215,7 @@ obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, menurow->width, menurow->height); if (menurow->selected == MENUROW_NONE) { - if (config->always_show_cb || menurow->pushed) + if (config.always_show_cb || menurow->pushed) skin_draw_pixbuf(widget, aud_active_skin, obj, menurow->skin_index, menurow->nx, menurow->ny, 0, 0, 8, 43); else @@ -227,7 +227,7 @@ menurow->sx + ((menurow->selected - 1) * 8), menurow->sy, 0, 0, 8, 43); } - if (config->always_show_cb || menurow->pushed) { + if (config.always_show_cb || menurow->pushed) { if (menurow->always_selected) skin_draw_pixbuf(widget, aud_active_skin, obj, menurow->skin_index, menurow->sx + 8, menurow->sy + 10, 0, 10, 8, 8); @@ -246,8 +246,8 @@ static MenuRowItem menurow_find_selected(UiSkinnedMenurow * mr, gint x, gint y) { MenuRowItem ret = MENUROW_NONE; - x = x/(mr->scaled ? config->scale_factor : 1); - y = y/(mr->scaled ? config->scale_factor : 1); + x = x/(mr->scaled ? config.scale_factor : 1); + y = y/(mr->scaled ? config.scale_factor : 1); if (x > 0 && x < 8) { if (y >= 0 && y <= 10) ret = MENUROW_OPTIONS; @@ -325,8 +325,8 @@ GtkWidget *widget = GTK_WIDGET (menurow); menurow->scaled = !menurow->scaled; - gtk_widget_set_size_request(widget, menurow->width* (menurow->scaled ? config->scale_factor : 1), - menurow->height * (menurow->scaled ? config->scale_factor : 1)); + gtk_widget_set_size_request(widget, menurow->width* (menurow->scaled ? config.scale_factor : 1), + menurow->height * (menurow->scaled ? config.scale_factor : 1)); gtk_widget_queue_draw(GTK_WIDGET(menurow)); }
--- a/src/skins/ui_skinned_window.c Tue May 20 14:37:50 2008 +0200 +++ b/src/skins/ui_skinned_window.c Tue May 20 15:36:47 2008 +0200 @@ -20,6 +20,7 @@ #include "platform/smartinclude.h" #include "ui_skin.h" +#include "skins_cfg.h" #include <gtk/gtkmain.h> #include <glib-object.h> @@ -71,11 +72,11 @@ SkinnedWindow *window = SKINNED_WINDOW(widget); if (window->type == WINDOW_MAIN) - gtk_widget_shape_combine_mask(widget, skin_get_mask(aud_active_skin, SKIN_MASK_MAIN + aud_cfg->player_shaded), 0, 0); + gtk_widget_shape_combine_mask(widget, skin_get_mask(aud_active_skin, SKIN_MASK_MAIN + config.player_shaded), 0, 0); else if (window->type == WINDOW_EQ) - gtk_widget_shape_combine_mask(widget, skin_get_mask(aud_active_skin, SKIN_MASK_EQ + aud_cfg->equalizer_shaded), 0, 0); + gtk_widget_shape_combine_mask(widget, skin_get_mask(aud_active_skin, SKIN_MASK_EQ + config.equalizer_shaded), 0, 0); - gtk_window_set_keep_above(GTK_WINDOW(widget), aud_cfg->always_on_top); + gtk_window_set_keep_above(GTK_WINDOW(widget), config.always_on_top); } static gboolean @@ -102,7 +103,7 @@ static gboolean ui_skinned_window_button_press(GtkWidget *widget, GdkEventButton *event) { if (event->button == 1 && event->type == GDK_BUTTON_PRESS && - (aud_cfg->easy_move || aud_cfg->equalizer_shaded || (event->y / aud_cfg->scale_factor) < 14)) { + (config.easy_move || config.equalizer_shaded || (event->y / config.scale_factor) < 14)) { dock_move_press(get_dock_window_list(), GTK_WINDOW(widget), event, SKINNED_WINDOW(widget)->type == WINDOW_MAIN ? TRUE : FALSE); } @@ -129,8 +130,8 @@ height = aud_active_skin->properties.mainwin_height; break; case WINDOW_EQ: - width = 275 * (aud_cfg->scaled ? aud_cfg->scale_factor : 1); - height = 116 * (aud_cfg->scaled ? aud_cfg->scale_factor : 1) ; + width = 275 * (config.scaled ? config.scale_factor : 1); + height = 116 * (config.scaled ? config.scale_factor : 1) ; break; case WINDOW_PLAYLIST: #if 0 @@ -148,25 +149,25 @@ switch (window->type) { case WINDOW_MAIN: skin_draw_pixbuf(widget, aud_active_skin, obj,SKIN_MAIN, 0, 0, 0, 0, width, height); - skin_draw_mainwin_titlebar(aud_active_skin, obj, aud_cfg->player_shaded, focus || !aud_cfg->dim_titlebar); + skin_draw_mainwin_titlebar(aud_active_skin, obj, config.player_shaded, focus || !aud_cfg->dim_titlebar); break; case WINDOW_EQ: skin_draw_pixbuf(widget, aud_active_skin, obj, SKIN_EQMAIN, 0, 0, 0, 0, width, height); - if (focus || !aud_cfg->dim_titlebar) { - if (!aud_cfg->equalizer_shaded) + if (focus || !config.dim_titlebar) { + if (!config.equalizer_shaded) skin_draw_pixbuf(widget, aud_active_skin, obj, SKIN_EQMAIN, 0, 134, 0, 0, width, 14); else skin_draw_pixbuf(widget, aud_active_skin, obj, SKIN_EQ_EX, 0, 0, 0, 0, width, 14); } else { - if (!aud_cfg->equalizer_shaded) + if (!config.equalizer_shaded) skin_draw_pixbuf(widget, aud_active_skin, obj, SKIN_EQMAIN, 0, 149, 0, 0, width, 14); else skin_draw_pixbuf(widget, aud_active_skin, obj, SKIN_EQ_EX, 0, 15, 0, 0, width, 14); } break; case WINDOW_PLAYLIST: - focus |= !aud_cfg->dim_titlebar; - if (aud_cfg->playlist_shaded) { + focus |= !config.dim_titlebar; + if (config.playlist_shaded) { skin_draw_playlistwin_shaded(aud_active_skin, obj, width, focus); } else { skin_draw_playlistwin_frame(aud_active_skin, obj, width, aud_cfg->playlist_height, focus); @@ -175,7 +176,7 @@ } ui_skinned_widget_draw(GTK_WIDGET(window), obj, width, height, - window->type != WINDOW_PLAYLIST && aud_cfg->scaled); + window->type != WINDOW_PLAYLIST && config.scaled); g_object_unref(obj); @@ -247,7 +248,7 @@ set_dock_window_list(dock_window_set_decorated(get_dock_window_list(), GTK_WINDOW(widget), - aud_cfg->show_wm_decorations)); + config.show_wm_decorations)); gtk_widget_set_app_paintable(GTK_WIDGET(widget), TRUE); gdk_window_set_back_pixmap(widget->window, NULL, FALSE); gtk_widget_shape_combine_mask(widget, NULL, 0, 0);