Better handling if configuration isn't present.

This commit is contained in:
Sanel Zukan 2013-06-06 09:48:01 +00:00
parent 0d6f18e867
commit fc433aa342
2 changed files with 38 additions and 23 deletions

View File

@ -165,6 +165,8 @@ static void folder_create_cb(Fl_Widget*, void *d) {
Desktop::Desktop() : EDE_DESKTOP_WINDOW(0, 0, 100, 100, EDE_DESKTOP_APP) {
end();
/* use nice darker blue color as default for background */
color(fl_rgb_color(73, 64, 102));
conf = NULL;
selbox = new SelectionOverlay;
@ -239,15 +241,14 @@ void Desktop::read_config(void) {
E_DEBUG(E_STRLOC ": Reading desktop config...\n");
if(!conf) conf = new DesktopConfig();
E_RETURN_IF_FAIL(conf->load(EDE_DESKTOP_APP));
conf->load(EDE_DESKTOP_APP);
char buf[PATH_MAX];
bool wp_use = true;
int bcolor;
/* use nice darker blue color as default for background */
conf->get("Desktop", "color", bcolor, fl_rgb_color(73, 64, 102));
color(bcolor);
if(conf->get("Desktop", "color", bcolor, color()))
color(bcolor);
conf->get("Desktop", "wallpaper_use", wp_use, wp_use);
@ -277,18 +278,17 @@ void Desktop::read_config(void) {
if(wallpaper) wallpaper->hide();
}
/* get options for icons */
if(!icon_opts) icon_opts = new IconOptions;
#define ICON_CONF_GET(var, fallback) conf->get("Icons", #var, icon_opts->var, fallback)
ICON_CONF_GET(label_background, FL_BLACK);
ICON_CONF_GET(label_foreground, FL_WHITE);
ICON_CONF_GET(label_maxwidth, 75);
ICON_CONF_GET(label_transparent, 1);
ICON_CONF_GET(label_visible, 1);
ICON_CONF_GET(one_click_exec, false);
#define ICON_CONF_GET(var) conf->get("Icons", #var, icon_opts->var, icon_opts->var)
ICON_CONF_GET(label_background);
ICON_CONF_GET(label_foreground);
ICON_CONF_GET(label_maxwidth);
ICON_CONF_GET(label_transparent);
ICON_CONF_GET(label_visible);
ICON_CONF_GET(one_click_exec);
if(ICON_CONF_GET(label_font, FL_HELVETICA) && ICON_CONF_GET(label_fontsize, 12))
if(ICON_CONF_GET(label_font) && ICON_CONF_GET(label_fontsize))
E_WARNING(E_STRLOC ": 'label_font' && 'label_fontsize' are deprecated. Use 'label_fontname' with full font name and size instead (e.g 'sans 12')\n");
/* if found new 'label_fontname' variable, overwrite 'label_font' && 'label_fontsize' */
@ -297,10 +297,7 @@ void Desktop::read_config(void) {
E_WARNING(E_STRLOC ": Unable to find '%s' font. Using default values...\n", buf);
}
/* sanitize */
if(icon_opts->label_font < 0) icon_opts->label_font = FL_HELVETICA;
if(icon_opts->label_fontsize < 8) icon_opts->label_fontsize = 12;
if(icon_opts->label_maxwidth < 30) icon_opts->label_maxwidth = 75;
icon_opts->sanitize_font();
/* doing this will redraw _all_ children, and they will in turn read modified 'icon_opts' */
if(visible()) redraw();

View File

@ -54,6 +54,24 @@ struct IconOptions {
int label_transparent;
int label_visible;
bool one_click_exec;
IconOptions() {
label_background = FL_BLACK;
label_foreground = FL_WHITE;
label_maxwidth = 75;
label_transparent = 1;
label_visible = 1;
label_font = FL_HELVETICA;
label_fontsize = 12;
one_click_exec = false;
}
/* should be called only when values are assigned to fonts */
void sanitize_font(void) {
if(label_font < 0) label_font = FL_HELVETICA;
if(label_fontsize < 8) label_fontsize = 12;
if(label_maxwidth < 30) label_maxwidth = 75;
}
};
class MovableIcon;