mirror of
https://github.com/edeproject/ede.git
synced 2023-08-10 21:13:03 +03:00
Implemented save_config().
eiconman recognize plain files besides .desktop files.
This commit is contained in:
parent
4ef5be0c9b
commit
04e1c63cb2
@ -45,13 +45,11 @@ void icon_delete_cb(fltk::Widget*, void* di) {
|
||||
edelib::ask(_("Delete '%s' ?"), dicon->label());
|
||||
}
|
||||
|
||||
DesktopIcon::DesktopIcon(GlobalIconSettings* gisett, IconSettings* isett, int icon_type) :
|
||||
DesktopIcon::DesktopIcon(GlobalIconSettings* gisett, IconSettings* isett) :
|
||||
fltk::Widget(isett->x, isett->y, ICONSIZE, ICONSIZE), settings(NULL)
|
||||
{
|
||||
EASSERT(gisett != NULL); EASSERT(isett != NULL);
|
||||
|
||||
type = icon_type;
|
||||
|
||||
lwidth = lheight = 0;
|
||||
focus = false;
|
||||
micon = false;
|
||||
@ -69,6 +67,8 @@ DesktopIcon::DesktopIcon(GlobalIconSettings* gisett, IconSettings* isett, int ic
|
||||
settings->name = isett->name;
|
||||
settings->cmd = isett->cmd;
|
||||
settings->icon = isett->icon;
|
||||
settings->type = isett->type;
|
||||
settings->key_name= isett->key_name;
|
||||
|
||||
// x,y are not needed since x(), y() are filled with it
|
||||
|
||||
@ -107,7 +107,7 @@ DesktopIcon::DesktopIcon(GlobalIconSettings* gisett, IconSettings* isett, int ic
|
||||
|
||||
pmenu = new fltk::PopupMenu(0, 0, 100, 100);
|
||||
pmenu->begin();
|
||||
if(type == ICON_TRASH) {
|
||||
if(settings->type == ICON_TRASH) {
|
||||
edelib::Item* it = new edelib::Item(_("&Open"));
|
||||
it->offset_x(12, 12);
|
||||
it = new edelib::Item(_("&Properties"));
|
||||
|
@ -18,9 +18,6 @@
|
||||
#include <fltk/Image.h>
|
||||
#include <fltk/PopupMenu.h>
|
||||
|
||||
#define ICON_NORMAL 1
|
||||
#define ICON_TRASH 2
|
||||
|
||||
class GlobalIconSettings;
|
||||
class IconSettings;
|
||||
class MovableIcon;
|
||||
@ -30,7 +27,6 @@ class DesktopIcon : public fltk::Widget {
|
||||
IconSettings* settings;
|
||||
const GlobalIconSettings* globals;
|
||||
|
||||
int type;
|
||||
int lwidth;
|
||||
int lheight;
|
||||
bool focus;
|
||||
@ -45,7 +41,7 @@ class DesktopIcon : public fltk::Widget {
|
||||
void update_label_size(void);
|
||||
|
||||
public:
|
||||
DesktopIcon(GlobalIconSettings* gisett, IconSettings* isett, int icon_type = NORMAL);
|
||||
DesktopIcon(GlobalIconSettings* gisett, IconSettings* isett);
|
||||
~DesktopIcon();
|
||||
virtual void draw(void);
|
||||
virtual int handle(int event);
|
||||
@ -62,6 +58,8 @@ class DesktopIcon : public fltk::Widget {
|
||||
bool is_focused(void) { return focus; }
|
||||
|
||||
fltk::Image* icon_image(void) { return (fltk::Image*)image(); }
|
||||
|
||||
const IconSettings* get_settings(void) const { return settings; }
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,32 +1,28 @@
|
||||
# general settings for desktop
|
||||
[Desktop]
|
||||
Color = 35
|
||||
WallpaperUse=1
|
||||
Wallpaper=/home/sanel/wallpapers/Abaddon.png
|
||||
WallpaperUse = 0
|
||||
Wallpaper = /home/foo/xxx/baz/tax
|
||||
|
||||
# general settings for icons on desktop
|
||||
[Icons]
|
||||
Label Background = 216
|
||||
Label Foreground = 7
|
||||
Label Fontsize = 10
|
||||
Label Maxwidth = 55
|
||||
Label Transparent = 1
|
||||
Label Visible = 1
|
||||
Gridspacing = 10
|
||||
OneClickExec = 0
|
||||
Label Transparent=True
|
||||
Label Background=216
|
||||
AutoArrange=0
|
||||
Label Maxwidth=55
|
||||
Label Fontsize=10
|
||||
|
||||
# positions of each icon on desktop (if icon is visible)
|
||||
|
||||
AutoArrange = 1
|
||||
|
||||
[Demo folder]
|
||||
X = 20
|
||||
Y = 151
|
||||
|
||||
[Home.desktop]
|
||||
X=13
|
||||
Y=8
|
||||
|
||||
[System.desktop]
|
||||
X=12
|
||||
Y=212
|
||||
X = 113
|
||||
Y = 16
|
||||
|
||||
[trash.desktop]
|
||||
X=15
|
||||
Y=106
|
||||
X = 20
|
||||
Y = 20
|
||||
|
||||
|
@ -170,6 +170,8 @@ Desktop::Desktop() : fltk::Window(0, 0, 100, 100, "")
|
||||
Desktop::~Desktop() {
|
||||
EDEBUG(ESTRLOC ": Desktop::~Desktop()\n");
|
||||
|
||||
save_config();
|
||||
|
||||
if(selbox)
|
||||
delete selbox;
|
||||
|
||||
@ -275,6 +277,12 @@ void Desktop::read_config(void) {
|
||||
conf.get("Desktop", "Wallpaper", wpath, sizeof(wpath));
|
||||
|
||||
dsett->wp_path = wpath;
|
||||
|
||||
// keep path but disable wallpaper if file does not exists
|
||||
if(!edelib::file_exists(wpath)) {
|
||||
EDEBUG(ESTRLOC ": %s as wallpaper does not exists\n", wpath);
|
||||
dsett->wp_use = false;
|
||||
}
|
||||
} else {
|
||||
// color is already filled
|
||||
dsett->wp_use = default_wp_use;
|
||||
@ -341,23 +349,51 @@ void Desktop::load_icons(const char* path, edelib::Config& conf) {
|
||||
edelib::String full_path;
|
||||
full_path.reserve(256);
|
||||
|
||||
for(unsigned int i = 0; i < lst.size(); i++) {
|
||||
name = lst[i].c_str();
|
||||
bool can_add = false;
|
||||
|
||||
if(edelib::str_ends(name, ".desktop")) {
|
||||
edelib::MimeType mt;
|
||||
|
||||
unsigned int sz = lst.size();
|
||||
for(unsigned int i = 0; i < sz; i++) {
|
||||
name = lst[i].c_str();
|
||||
|
||||
full_path = path;
|
||||
full_path += '/';
|
||||
full_path += name;
|
||||
|
||||
can_add = false;
|
||||
|
||||
IconSettings is;
|
||||
int icon_type;
|
||||
|
||||
if(read_desktop_file(full_path.c_str(), is, icon_type)) {
|
||||
// see is possible .desktop file, icon, name fields are filled from read_desktop_file()
|
||||
if(edelib::str_ends(name, ".desktop")) {
|
||||
if(read_desktop_file(full_path.c_str(), is))
|
||||
can_add = true;
|
||||
} else {
|
||||
// then try to figure out it's mime; if fails, ignore it
|
||||
if(mt.set(full_path.c_str())) {
|
||||
/*
|
||||
* FIXME: MimeType fails for directories
|
||||
* Temp solution untill that is fixed in edelib
|
||||
*/
|
||||
if(edelib::dir_exists(full_path.c_str()))
|
||||
is.icon = "folder";
|
||||
else
|
||||
is.icon = mt.icon_name();
|
||||
|
||||
// store dekstop name for key in saving positions
|
||||
is.desktop_name = name;
|
||||
// icon label is name of file
|
||||
is.name = name;
|
||||
is.type = ICON_FILE;
|
||||
|
||||
can_add = true;
|
||||
} else {
|
||||
EDEBUG(ESTRLOC ": Failed mime-type for %s, ignoring...\n", name);
|
||||
can_add = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(can_add) {
|
||||
is.key_name = name;
|
||||
// random_pos() is used if X/Y keys are not found
|
||||
conf.get(name, "X", icon_x, random_pos(w() - 10));
|
||||
conf.get(name, "Y", icon_y, random_pos(h() - 10));
|
||||
@ -366,16 +402,14 @@ void Desktop::load_icons(const char* path, edelib::Config& conf) {
|
||||
is.x = icon_x;
|
||||
is.y = icon_y;
|
||||
|
||||
DesktopIcon* dic = new DesktopIcon(&gisett, &is, icon_type);
|
||||
DesktopIcon* dic = new DesktopIcon(&gisett, &is);
|
||||
add_icon(dic);
|
||||
} else
|
||||
EDEBUG(ESTRLOC ": Skipped %s section\n", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reads .desktop file content
|
||||
bool Desktop::read_desktop_file(const char* path, IconSettings& is, int& icon_type) {
|
||||
bool Desktop::read_desktop_file(const char* path, IconSettings& is) {
|
||||
EASSERT(path != NULL);
|
||||
|
||||
if(!edelib::file_exists(path)) {
|
||||
@ -398,10 +432,10 @@ bool Desktop::read_desktop_file(const char* path, IconSettings& is, int& icon_ty
|
||||
* FIXME: any other way to check for trash icons ???
|
||||
*/
|
||||
if(dconf.get("Desktop Entry", "EmptyIcon", buff, buffsz)) {
|
||||
icon_type = ICON_TRASH;
|
||||
is.type = ICON_TRASH;
|
||||
is.icon = buff;
|
||||
} else
|
||||
icon_type = ICON_NORMAL;
|
||||
is.type = ICON_NORMAL;
|
||||
|
||||
if(dconf.error() == edelib::CONF_ERR_SECTION) {
|
||||
EDEBUG(ESTRLOC ": %s is not valid .desktop file\n");
|
||||
@ -410,11 +444,11 @@ bool Desktop::read_desktop_file(const char* path, IconSettings& is, int& icon_ty
|
||||
|
||||
dconf.get("Desktop Entry", "Icon", buff, buffsz);
|
||||
|
||||
if(icon_type == ICON_TRASH)
|
||||
if(is.type == ICON_TRASH)
|
||||
is.icon2 = buff;
|
||||
else {
|
||||
is.icon = buff;
|
||||
icon_type = ICON_NORMAL;
|
||||
is.type = ICON_NORMAL;
|
||||
}
|
||||
|
||||
EDEBUG(ESTRLOC ": Icon is: %s\n", is.icon.c_str());
|
||||
@ -430,6 +464,10 @@ bool Desktop::read_desktop_file(const char* path, IconSettings& is, int& icon_ty
|
||||
* Specs (desktop entry file) said that Type=Link means there must
|
||||
* be somewhere URL key. My thoughts is that in this case Exec key
|
||||
* should be ignored, even if exists. Then I will follow my thoughts.
|
||||
*
|
||||
* FIXME: 'Type' should be seen as test for .desktop file; if key
|
||||
* is not present, then file should not be considered as .desktop. This
|
||||
* should be checked before all others.
|
||||
*/
|
||||
if(!dconf.get("Desktop Entry", "Type", buff, buffsz)) {
|
||||
EDEBUG(ESTRLOC ": Missing mandatory Type key\n");
|
||||
@ -462,7 +500,33 @@ bool Desktop::read_desktop_file(const char* path, IconSettings& is, int& icon_ty
|
||||
}
|
||||
|
||||
void Desktop::save_config(void) {
|
||||
// TODO
|
||||
edelib::Config conf;
|
||||
|
||||
conf.set("Desktop", "Color", dsett->color);
|
||||
conf.set("Desktop", "WallpaperUse", dsett->wp_use);
|
||||
conf.set("Desktop", "Wallpaper", dsett->wp_path.c_str());
|
||||
|
||||
conf.set("Icons", "Label Background", gisett.label_background);
|
||||
conf.set("Icons", "Label Foreground", gisett.label_foreground);
|
||||
conf.set("Icons", "Label Fontsize", gisett.label_fontsize);
|
||||
conf.set("Icons", "Label Maxwidth", gisett.label_maxwidth);
|
||||
conf.set("Icons", "Label Transparent",gisett.label_transparent);
|
||||
conf.set("Icons", "Label Visible", gisett.label_draw);
|
||||
conf.set("Icons", "Gridspacing", gisett.gridspacing);
|
||||
conf.set("Icons", "OneClickExec", gisett.one_click_exec);
|
||||
conf.set("Icons", "AutoArrange", gisett.auto_arr);
|
||||
|
||||
unsigned int sz = icons.size();
|
||||
const IconSettings* is = NULL;
|
||||
|
||||
for(unsigned int i = 0; i < sz; i++) {
|
||||
is = icons[i]->get_settings();
|
||||
conf.set(is->key_name.c_str(), "X", icons[i]->x());
|
||||
conf.set(is->key_name.c_str(), "Y", icons[i]->y());
|
||||
}
|
||||
|
||||
if(!conf.save(CONFIG_NAME))
|
||||
EDEBUG(ESTRLOC ": Unable to save to %s\n", CONFIG_NAME);
|
||||
}
|
||||
|
||||
void Desktop::add_icon(DesktopIcon* ic) {
|
||||
@ -643,6 +707,7 @@ void Desktop::drop_source(const char* src, int x, int y) {
|
||||
|
||||
is.name = "XXX";
|
||||
is.cmd = "(none)";
|
||||
is.type = ICON_NORMAL;
|
||||
|
||||
edelib::MimeType mt;
|
||||
if(!mt.set(src)) {
|
||||
@ -654,7 +719,7 @@ void Desktop::drop_source(const char* src, int x, int y) {
|
||||
|
||||
EDEBUG("---------> %s\n", is.icon.c_str());
|
||||
|
||||
DesktopIcon* dic = new DesktopIcon(&gisett, &is, ICON_NORMAL);
|
||||
DesktopIcon* dic = new DesktopIcon(&gisett, &is);
|
||||
add_icon(dic);
|
||||
}
|
||||
|
||||
|
@ -40,17 +40,28 @@ struct GlobalIconSettings {
|
||||
bool same_size;
|
||||
};
|
||||
|
||||
// settings related to .desktop files
|
||||
#define ICON_NORMAL 1 // .desktop file
|
||||
#define ICON_TRASH 2 // trash.desktop (specific since have two icons for empty/full)
|
||||
#define ICON_FILE 3 // real file
|
||||
#define ICON_SYMLINK 4 // symbolic link
|
||||
|
||||
/*
|
||||
* Settings representing related to icon on desktop. To complicate our lives
|
||||
* (and to, at least, simplify code) it can be:
|
||||
* - .desktop file content (normal or trash like)
|
||||
* - real file copied/moved inside ~/Desktop directory
|
||||
* - symlink in ~/Desktop directory pointing to the real file
|
||||
*/
|
||||
struct IconSettings {
|
||||
int x, y;
|
||||
|
||||
int type;
|
||||
bool cmd_is_url; // interpret cmd as url, like system:/,trash:/,$HOME
|
||||
|
||||
edelib::String name;
|
||||
edelib::String cmd;
|
||||
edelib::String icon;
|
||||
edelib::String icon2; // for stateable icons, like trash (empty/full)
|
||||
edelib::String desktop_name; // name used as key when storing positions
|
||||
edelib::String key_name; // name used as key when storing positions
|
||||
};
|
||||
|
||||
// selection overlay
|
||||
@ -91,7 +102,7 @@ class Desktop : public fltk::Window {
|
||||
void init_desktops(void);
|
||||
|
||||
void load_icons(const char* path, edelib::Config& conf);
|
||||
bool read_desktop_file(const char* path, IconSettings& is, int& icon_type);
|
||||
bool read_desktop_file(const char* path, IconSettings& is);
|
||||
|
||||
void add_icon(DesktopIcon* ic);
|
||||
void unfocus_all(void);
|
||||
|
Loading…
Reference in New Issue
Block a user