ede/edesktopconf/edesktopconf.cpp

462 lines
14 KiB
C++
Raw Normal View History

2007-11-01 19:47:19 +03:00
/*
* $Id$
*
* Desktop configuration tool
* Part of Equinox Desktop Environment (EDE).
* Copyright (c) 2000-2007 EDE Authors.
*
* This program is licensed under terms of the
* GNU General Public License version 2 or newer.
* See COPYING for details.
*/
2007-11-06 17:34:15 +03:00
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
2007-11-01 19:47:19 +03:00
#include <edelib/Nls.h>
#include <edelib/Color.h>
#include <edelib/Window.h>
2007-11-06 17:34:15 +03:00
#include <edelib/Config.h>
2007-11-01 19:47:19 +03:00
#include <edelib/Debug.h>
2007-11-06 17:34:15 +03:00
#include <edelib/Util.h>
#include <edelib/Directory.h>
#include <string.h>
2007-11-01 19:47:19 +03:00
#include <FL/Fl.H>
#include <FL/Fl_Tabs.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Choice.H>
#include <FL/Fl_Check_Button.H>
#include <FL/Fl_Value_Slider.H>
#include <FL/Fl_Color_Chooser.h>
#include <FL/Fl_File_Chooser.h>
#include <FL/Fl_Shared_Image.h>
#include <FL/Fl_Menu_Button.h>
2007-11-06 17:34:15 +03:00
#define EICOMAN_UID 0x10
#define EICOMAN_CONFIG "../eiconman/eiconman.conf"
2007-11-01 19:47:19 +03:00
Fl_Menu_Item mode_menu[] = {
{_("Center"), 0, 0},
{_("Stretch"), 0, 0},
{_("Stretch (aspect)"), 0, 0},
{_("Tiled"), 0, 0},
{0}
};
Fl_Button* browse;
Fl_Button* desk_background_color;
Fl_Input* desk_background;
Fl_Choice* desk_background_mode;
Fl_Check_Button* desk_use_wallpaper;
Fl_Box* wallpaper;
Fl_Button* icon_background_color;
Fl_Button* icon_label_color;
Fl_Check_Button* icon_show_background_color;
Fl_Check_Button* icon_show_label;
Fl_Value_Slider* icon_font_size;
Fl_Value_Slider* icon_label_width;
Fl_Check_Button* engage_with_one_click;
void set_wallpaper(const char* path) {
if(!path)
return;
const char* old = desk_background->value();
if(!old || strcmp(old, path) != 0)
desk_background->value(path);
Fl_Image* img = Fl_Shared_Image::get(path);
if(!img)
return;
Fl_Image* scaled = img->copy(wallpaper->w() - 2, wallpaper->h() - 2);
wallpaper->image(scaled);
wallpaper->redraw();
}
void disable_wallpaper(bool doit) {
if(doit) {
desk_use_wallpaper->value(0);
desk_background_mode->deactivate();
desk_background->deactivate();
browse->deactivate();
wallpaper->color(desk_background_color->color());
if(wallpaper->image()) {
wallpaper->image(NULL);
wallpaper->redraw();
}
} else {
desk_use_wallpaper->value(1);
desk_background_mode->activate();
desk_background->activate();
browse->activate();
set_wallpaper(desk_background->value());
}
}
void set_rgb_color(Fl_Button* btn, unsigned char r, unsigned char g, unsigned char b) {
Fl_Color c = (Fl_Color)edelib::color_rgb_to_fltk(r, g, b);
btn->color(c);
}
void close_cb(Fl_Widget*, void* w) {
edelib::Window* win = (edelib::Window*)w;
win->hide();
}
void color_cb(Fl_Button* btn, void*) {
unsigned char r, g, b;
edelib::color_fltk_to_rgb(btn->color(), r, g, b);
if(fl_color_chooser(_("Choose color"), r, g, b)) {
btn->color(edelib::color_rgb_to_fltk(r, g, b));
btn->redraw();
}
}
void wallpaper_color_cb(Fl_Widget*, void* w) {
unsigned char r, g, b;
edelib::color_fltk_to_rgb(desk_background_color->color(), r, g, b);
if(fl_color_chooser(_("Choose color"), r, g, b)) {
Fl_Color c = (Fl_Color)edelib::color_rgb_to_fltk(r, g, b);
desk_background_color->color(c);
wallpaper->color(c);
wallpaper->redraw();
}
}
void browse_cb(Fl_Widget*, void*) {
char* ret = fl_file_chooser(_("Background image"), "*.jpg\t*.png", NULL);
if(!ret)
return;
set_wallpaper(ret);
}
void wallpaper_use_cb(Fl_Widget*, void*) {
if(desk_use_wallpaper->value()) {
disable_wallpaper(false);
set_wallpaper(desk_background->value());
} else
disable_wallpaper(true);
}
void apply_cb(Fl_Widget*, void* w) {
2007-11-06 17:34:15 +03:00
#if 0
2007-11-01 19:47:19 +03:00
unsigned char r, g, b;
edelib::Window* win = (edelib::Window*)w;
win->xsettings()->set("EDE/Desktop/Background/Wallpaper", desk_background->value());
win->xsettings()->set("EDE/Desktop/Background/WallpaperMode", desk_background_mode->value());
win->xsettings()->set("EDE/Desktop/Background/WallpaperShow", desk_use_wallpaper->value());
edelib::color_fltk_to_rgb(desk_background_color->color(), r, g, b);
win->xsettings()->set("EDE/Desktop/Background/Color", r, g, b, 0);
edelib::color_fltk_to_rgb(icon_background_color->color(), r, g, b);
win->xsettings()->set("EDE/Desktop/Icons/BackgroundColor", r, g, b, 0);
edelib::color_fltk_to_rgb(icon_label_color->color(), r, g, b);
win->xsettings()->set("EDE/Desktop/Icons/LabelColor", r, g, b, 0);
win->xsettings()->set("EDE/Desktop/Icons/BackgroundColorShow", icon_show_background_color->value());
win->xsettings()->set("EDE/Desktop/Icons/LabelShow", icon_show_label->value());
win->xsettings()->set("EDE/Desktop/Icons/FontSize", (int)icon_font_size->value());
win->xsettings()->set("EDE/Desktop/Icons/LabelWidth", (int)icon_label_width->value());
win->pause_xsettings_callback();
win->xsettings()->manager_notify();
win->restore_xsettings_callback();
2007-11-06 17:34:15 +03:00
#endif
edelib::Config conf;
conf.set("Desktop", "Color", (int)desk_background_color->color());
conf.set("Desktop", "WallpaperUse", desk_use_wallpaper->value());
conf.set("Desktop", "WallpaperMode", desk_background_mode->value());
if(desk_background->value())
conf.set("Desktop", "Wallpaper", desk_background->value());
conf.set("Icons", "Label Background", (int)icon_background_color->color());
conf.set("Icons", "Label Foreground", (int)icon_label_color->color());
conf.set("Icons", "Label Fontsize", icon_font_size->value());
conf.set("Icons", "Label Maxwidth", icon_label_width->value());
conf.set("Icons", "Label Transparent", icon_show_background_color->value());
conf.set("Icons", "Label Visible", icon_show_label->value());
conf.set("Icons", "OneClickExec", engage_with_one_click->value());
if(conf.save(EICOMAN_CONFIG))
edelib::Window::update_settings(EICOMAN_UID);
2007-11-01 19:47:19 +03:00
}
2007-11-06 17:34:15 +03:00
void ok_cb(Fl_Widget*, void* w) {
2007-11-01 19:47:19 +03:00
edelib::Window* win = (edelib::Window*)w;
apply_cb(0, win);
win->hide();
}
2007-11-06 17:34:15 +03:00
/*
* XSETTINGS getter. Left commented for future
*/
#if 0
2007-11-01 19:47:19 +03:00
bool xsettings_cb(const char* name, edelib::XSettingsAction action, const edelib::XSettingsSetting* setting, void* data) {
if(strcmp(name, "EDE/Desktop/Background/Wallpaper") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_STRING)
disable_wallpaper(true);
else
set_wallpaper(setting->data.v_string);
} else if(strcmp(name, "EDE/Desktop/Background/Color") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_COLOR)
desk_background_color->color(FL_BLACK);
else set_rgb_color(icon_label_color,
setting->data.v_color.red,
setting->data.v_color.green,
setting->data.v_color.blue);
} else if(strcmp(name, "EDE/Desktop/Background/WallpaperMode") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_INT)
desk_background_mode->value(0);
else {
int m = setting->data.v_int;
if(m > 3) {
EWARNING(ESTRLOC ": Got wrong value from %s (%i), zeroing...\n", setting->name, setting->data.v_int);
m = 0;
}
desk_background_mode->value(m);
}
} else if(strcmp(name, "EDE/Desktop/Background/WallpaperShow") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_INT)
disable_wallpaper(true);
else {
if(setting->data.v_int)
disable_wallpaper(false);
else
disable_wallpaper(true);
}
} else if(strcmp(name, "EDE/Desktop/Icons/BackgroundColor") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_COLOR)
icon_background_color->color(FL_BLUE);
else
set_rgb_color(icon_background_color,
setting->data.v_color.red,
setting->data.v_color.green,
setting->data.v_color.blue);
} else if(strcmp(name, "EDE/Desktop/Icons/LabelColor") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_COLOR)
icon_label_color->color(FL_WHITE);
else
set_rgb_color(icon_label_color,
setting->data.v_color.red,
setting->data.v_color.green,
setting->data.v_color.blue);
} else if(strcmp(name, "EDE/Desktop/Icons/BackgroundColorShow") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_INT)
icon_show_background_color->value(0);
else {
if(setting->data.v_int)
icon_show_background_color->value(1);
else
icon_show_background_color->value(0);
}
} else if(strcmp(name, "EDE/Desktop/Icons/LabelShow") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_INT)
icon_show_label->value(0);
else {
if(setting->data.v_int)
icon_show_label->value(1);
else
icon_show_label->value(0);
}
} else if(strcmp(name, "EDE/Desktop/Icons/FontSize") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_INT)
icon_font_size->value(12);
else
icon_font_size->value(setting->data.v_int);
} else if(strcmp(name, "EDE/Desktop/Icons/LabelWidth") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_INT)
icon_label_width->value(55);
else
icon_label_width->value(setting->data.v_int);
}
return false;
}
2007-11-06 17:34:15 +03:00
#endif
void load_settings(void) {
int b_mode = 0;
bool d_wp_use = false;
int d_background_color = FL_BLUE;
int i_background_color = FL_BLUE;
int i_label_color = FL_WHITE;
int i_show_background_color = 0;
int i_show_label = 1;
int i_font_size = 12;
int i_label_width = 55;
bool one_click = false;
edelib::Config conf;
char wpath[256];
if(conf.load(EICOMAN_CONFIG)) {
conf.get("Desktop", "Color", d_background_color, d_background_color);
conf.get("Desktop", "WallpaperUse", d_wp_use, d_wp_use);
conf.get("Desktop", "WallpaperMode", b_mode, b_mode);
if(conf.get("Desktop", "Wallpaper", wpath, sizeof(wpath)))
set_wallpaper(wpath);
else
disable_wallpaper(true);
conf.get("Icons", "Label Background", i_background_color, i_background_color);
conf.get("Icons", "Label Foreground", i_label_color, i_label_color);
conf.get("Icons", "Label Fontsize", i_font_size, i_font_size);
conf.get("Icons", "Label Maxwidth", i_label_width, i_label_width);
conf.get("Icons", "Label Transparent",i_show_background_color, i_show_background_color);
conf.get("Icons", "Label Visible", i_show_label, i_show_label);
conf.get("Icons", "OneClickExec", one_click, one_click);
}
desk_background_color->color(d_background_color);
desk_background_mode->value(b_mode);
desk_use_wallpaper->value(d_wp_use);
if(!d_wp_use)
disable_wallpaper(true);
icon_background_color->color(i_background_color);
icon_label_color->color(i_label_color);
icon_show_background_color->value(i_show_background_color);
icon_show_label->value(i_show_label);
icon_font_size->value(i_font_size);
icon_label_width->value(i_label_width);
engage_with_one_click->value(one_click);
}
int main(int argc, char** argv) {
int show_group = 1;
if(argc > 1) {
if(strcmp(argv[1], "--desktop") == 0)
show_group = 1;
else if(strcmp(argv[1], "--icons") == 0)
show_group = 2;
else if(strcmp(argv[1], "--icons-behaviour") == 0)
show_group = 3;
}
2007-11-01 19:47:19 +03:00
edelib::Window* win = new edelib::Window(550, 285, _("Desktop options"));
2007-11-06 17:34:15 +03:00
//win->xsettings_callback(xsettings_cb, NULL);
2007-11-01 19:47:19 +03:00
win->begin();
Fl_Tabs* tabs = new Fl_Tabs(10, 10, 530, 230);
tabs->begin();
2007-11-06 17:34:15 +03:00
2007-11-01 19:47:19 +03:00
Fl_Group* g1 = new Fl_Group(20, 30, 510, 200, _("Background"));
2007-11-06 17:34:15 +03:00
if(show_group != 1)
g1->hide();
2007-11-01 19:47:19 +03:00
g1->begin();
Fl_Box* b1 = new Fl_Box(85, 196, 100, 15);
b1->box(FL_BORDER_BOX);
Fl_Box* b2 = new Fl_Box(30, 43, 210, 158);
b2->box(FL_THIN_UP_BOX);
/* box size is intentionaly odd so preserve aspect ratio */
wallpaper = new Fl_Box(43, 53, 184, 138);
wallpaper->box(FL_DOWN_BOX);
wallpaper->color(FL_BLACK);
Fl_Box* b4 = new Fl_Box(60, 206, 145, 14);
b4->box(FL_THIN_UP_BOX);
desk_background = new Fl_Input(295, 80, 190, 25, _("Image:"));
browse = new Fl_Button(490, 80, 25, 25, "...");
browse->callback(browse_cb);
desk_background_mode = new Fl_Choice(295, 116, 220, 24, _("Mode:"));
desk_background_mode->down_box(FL_BORDER_BOX);
desk_background_mode->menu(mode_menu);
desk_background_color = new Fl_Button(295, 161, 25, 24, _("Background color"));
desk_background_color->color(FL_BLACK);
desk_background_color->align(FL_ALIGN_RIGHT);
desk_background_color->callback(wallpaper_color_cb);
desk_use_wallpaper = new Fl_Check_Button(295, 45, 220, 25, _("Use wallpaper"));
desk_use_wallpaper->down_box(FL_DOWN_BOX);
desk_use_wallpaper->value(1);
desk_use_wallpaper->callback(wallpaper_use_cb);
g1->end();
Fl_Group* g2 = new Fl_Group(20, 30, 510, 195, _("Icons"));
2007-11-06 17:34:15 +03:00
if(show_group != 2)
g2->hide();
2007-11-01 19:47:19 +03:00
g2->begin();
icon_background_color = new Fl_Button(30, 51, 25, 24, _("Background color"));
icon_background_color->color(FL_BLUE);
icon_background_color->align(FL_ALIGN_RIGHT);
icon_background_color->callback((Fl_Callback*)color_cb);
icon_label_color = new Fl_Button(30, 91, 25, 24, _("Label color"));
icon_label_color->color(FL_WHITE);
icon_label_color->align(FL_ALIGN_RIGHT);
icon_label_color->callback((Fl_Callback*)color_cb);
icon_show_background_color = new Fl_Check_Button(260, 50, 220, 25, _("Show background color"));
icon_show_background_color->down_box(FL_DOWN_BOX);
icon_show_label = new Fl_Check_Button(260, 90, 220, 25, _("Show label"));
icon_show_label->down_box(FL_DOWN_BOX);
icon_font_size = new Fl_Value_Slider(30, 155, 220, 20, _("Font size"));
icon_font_size->type(5);
icon_font_size->step(1);
icon_font_size->maximum(48);
icon_font_size->align(FL_ALIGN_TOP_LEFT);
icon_label_width = new Fl_Value_Slider(260, 155, 220, 20, _("Label width"));
icon_label_width->type(5);
icon_label_width->step(1);
icon_label_width->maximum(200);
icon_label_width->align(FL_ALIGN_TOP_LEFT);
g2->end();
Fl_Group* g3 = new Fl_Group(20, 30, 510, 195, _("Icons behaviour"));
2007-11-06 17:34:15 +03:00
if(show_group != 3)
g3->hide();
2007-11-01 19:47:19 +03:00
g3->begin();
engage_with_one_click = new Fl_Check_Button(30, 50, 220, 25, _("Engage with just one click"));
engage_with_one_click->down_box(FL_DOWN_BOX);
g3->end();
tabs->end();
Fl_Button* ok = new Fl_Button(260, 250, 90, 25, _("&OK"));
2007-11-06 17:34:15 +03:00
ok->callback(ok_cb, win);
2007-11-01 19:47:19 +03:00
Fl_Button* apply = new Fl_Button(355, 250, 90, 25, _("&Apply"));
apply->callback(apply_cb, win);
Fl_Button* cancel = new Fl_Button(450, 250, 90, 25, _("&Cancel"));
cancel->callback(close_cb, win);
win->end();
win->init(edelib::WIN_INIT_IMAGES);
2007-11-06 17:34:15 +03:00
load_settings();
2007-11-01 19:47:19 +03:00
win->show();
return Fl::run();
}