Some refactoring so icon properties does not get's copied

Added some hack to make valgrind silent in wallpaper code
This commit is contained in:
Sanel Zukan 2009-05-19 11:10:23 +00:00
parent 12acd9ea6c
commit ffee0edd57
6 changed files with 81 additions and 89 deletions

View File

@ -46,7 +46,6 @@
// label offset from icon y()+h(), so selection box can be drawn nicely
#define LABEL_OFFSET 2
static void rename_cb(Fl_Widget*, void* d);
static void props_cb(Fl_Widget*, void* d);
@ -93,25 +92,10 @@ DesktopIcon::DesktopIcon(GlobalIconSettings* gs, IconSettings* is, int bg) :
micon = NULL;
darker_img = NULL;
/*
* GlobalIconSettings is shared from desktop so we only
* reference it. On other hand IconSettings is not shared
* and we must construct a copy from given parameter
*/
globals = gs;
gsettings = gs;
settings = is;
settings = new IconSettings;
settings->name = is->name;
settings->cmd = is->cmd;
settings->icon = is->icon;
settings->icon2 = is->icon2;
settings->type = is->type;
settings->key_name= is->key_name;
settings->full_path = is->full_path;
// x,y are not needed since x(), y() are filled with it
// setting fonts is TODO :P
/* setting fonts is TODO :P */
#if 0
Fl::set_font((Fl_Font)20, "-windows-*-medium-r-*-*-14-*-*-*-*-*-*-*");
labelfont((Fl_Font)20);
@ -128,7 +112,7 @@ DesktopIcon::DesktopIcon(GlobalIconSettings* gs, IconSettings* is, int bg) :
load_icon(ICON_FACE_ONE);
fix_position(x(), y());
//Use desktop color as color for icon background
/* use desktop color as color for icon background */
color(bg);
align(FL_ALIGN_WRAP);
@ -138,11 +122,8 @@ DesktopIcon::DesktopIcon(GlobalIconSettings* gs, IconSettings* is, int bg) :
DesktopIcon::~DesktopIcon() {
E_DEBUG("DesktopIcon::~DesktopIcon()\n");
if(settings)
delete settings;
if(micon)
delete micon;
delete settings;
delete micon;
delete darker_img;
delete imenu;
}
@ -184,8 +165,8 @@ void DesktopIcon::load_icon(int face) {
}
void DesktopIcon::update_label_size(void) {
labelsize(globals->label_fontsize);
lwidth = globals->label_maxwidth;
labelsize(gsettings->label_fontsize);
lwidth = gsettings->label_maxwidth;
lheight= 0;
/*
@ -344,14 +325,14 @@ void DesktopIcon::draw(void) {
E_DEBUG(E_STRLOC ": DesktopIcon icon redraw\n");
}
if(globals->label_draw && (damage() & (FL_DAMAGE_ALL | EDAMAGE_CHILD_LABEL))) {
if(gsettings->label_draw && (damage() & (FL_DAMAGE_ALL | EDAMAGE_CHILD_LABEL))) {
int X = x() + w()-(w()/2)-(lwidth/2);
int Y = y() + h() + LABEL_OFFSET;
Fl_Color old = fl_color();
if(!globals->label_transparent) {
fl_color(globals->label_background);
if(!gsettings->label_transparent) {
fl_color(gsettings->label_background);
fl_rectf(X, Y, lwidth, lheight);
}
@ -365,7 +346,7 @@ void DesktopIcon::draw(void) {
fl_color(FL_BLACK);
fl_draw(label(), X+1, Y+1, lwidth, lheight, align(), 0, 0);
fl_color(globals->label_foreground);
fl_color(gsettings->label_foreground);
fl_draw(label(), X, Y, lwidth, lheight, align(), 0, 0);
/* restore old font */
@ -373,7 +354,7 @@ void DesktopIcon::draw(void) {
if(is_focused()) {
/* draw focused box on our way so later this can be used to draw customised boxes */
fl_color(globals->label_foreground);
fl_color(gsettings->label_foreground);
fl_line_style(FL_DOT);
fl_push_matrix();

View File

@ -31,8 +31,8 @@ class Fl_Menu_Button;
class DesktopIcon : public Fl_Widget {
private:
IconSettings* settings;
const GlobalIconSettings* globals;
IconSettings* settings;
const GlobalIconSettings* gsettings;
int lwidth;
int lheight;

View File

@ -363,6 +363,8 @@ static void create_tile(Fl_Image* orig, Fl_RGB_Image** copied, int X, int Y, int
Wallpaper::~Wallpaper() {
if(rootpmap_pixmap)
XFreePixmap(fl_display, rootpmap_pixmap);
delete stretched_alloc;
}
void Wallpaper::set_rootpmap(void) {
@ -396,13 +398,18 @@ bool Wallpaper::load(const char* path, WallpaperState s) {
create_tile((Fl_Image*)i, &tiled, x(), y(), w(), h());
image(tiled);
} else if(s == WALLPAPER_STRETCH) {
Fl_Image* stretched;
Fl_Image* stretched = NULL;
if(i->w() == w() && i->h() == h())
stretched = i;
else {
/* valgrind reports it as possible lost, but FLTK should free it */
delete stretched_alloc;
stretched = i->copy(w(), h());
i->release();
stretched_alloc = stretched;
}
image(stretched);

View File

@ -22,14 +22,19 @@ enum WallpaperState {
WALLPAPER_TILE
};
class Fl_Image;
class Wallpaper : public Fl_Box {
private:
Pixmap rootpmap_pixmap;
WallpaperState state;
Fl_Image* stretched_alloc; /* FLTK issue */
void set_rootpmap(void);
public:
Wallpaper(int X, int Y, int W, int H) : Fl_Box(X, Y, W, H), rootpmap_pixmap(0), state(WALLPAPER_CENTER) { }
Wallpaper(int X, int Y, int W, int H) : Fl_Box(X, Y, W, H),
rootpmap_pixmap(0), state(WALLPAPER_CENTER), stretched_alloc(NULL) { }
~Wallpaper();
bool load(const char* path, WallpaperState s);

View File

@ -376,17 +376,19 @@ void Desktop::save_icons_positions(void) {
E_WARNING(E_STRLOC ": Unable to store icons positions\n");
}
bool Desktop::read_desktop_file(const char* path, IconSettings& is) {
IconSettings* Desktop::read_desktop_file(const char* path) {
E_ASSERT(path != NULL);
edelib::DesktopFile dconf;
if(!dconf.load(path)) {
E_WARNING(E_STRLOC ": Can't read %s (%s)\n", path, dconf.strerror());
return false;
return NULL;
}
char buf[128];
int bufsz = sizeof(buf);
int bufsz = sizeof(buf);
IconSettings* is = new IconSettings;
/*
* Check for 'EmptyIcon' key since via it is determined is icon trash type or not
@ -395,47 +397,48 @@ bool Desktop::read_desktop_file(const char* path, IconSettings& is) {
* FIXME: any other way to check for trash icons ???
*/
if(dconf.get("Desktop Entry", "EmptyIcon", buf, bufsz)) {
is.type = ICON_TRASH;
is.icon = buf;
is->type = ICON_TRASH;
is->icon = buf;
} else
is.type = ICON_NORMAL;
is->type = ICON_NORMAL;
if(!dconf.icon(buf, bufsz)) {
E_WARNING(E_STRLOC ": No Icon key, balling out\n");
return false;
delete is;
return NULL;
}
if(is.type == ICON_TRASH)
is.icon2 = buf;
if(is->type == ICON_TRASH)
is->icon2 = buf;
else
is.icon = buf;
is->icon = buf;
edelib::DesktopFileType dtype = dconf.type();
if(dtype == edelib::DESK_FILE_TYPE_LINK) {
is.cmd_is_url = true;
is->cmd_is_url = true;
dconf.url(buf, bufsz);
}
else {
is.cmd_is_url = false;
is->cmd_is_url = false;
dconf.exec(buf, bufsz);
}
is.cmd = buf;
is->cmd = buf;
if(!dconf.name(buf, bufsz)) {
E_DEBUG(E_STRLOC ": No Name key\n");
is.name = "(none)";
is->name = "(none)";
} else
is.name = buf;
is->name = buf;
return true;
return is;
}
bool Desktop::add_icon_by_path(const char* path, edelib::Resource* conf) {
E_ASSERT(path != NULL);
IconSettings is;
bool can_add = false;
IconSettings* is = NULL;
const char* base = get_basename(path);
/*
@ -445,53 +448,50 @@ bool Desktop::add_icon_by_path(const char* path, edelib::Resource* conf) {
* to be always present, or .desktop does not have to be Desktop File at all
*/
if(edelib::str_ends(path, ".desktop")) {
if(read_desktop_file(path, is))
can_add = true;
is = read_desktop_file(path);
} else {
edelib::MimeType mt;
/* then try to figure out it's mime; if fails, ignore it */
if(mt.set(path)) {
E_DEBUG(E_STRLOC ": Loading icon as mime-type %s\n", mt.icon_name().c_str());
is.icon = mt.icon_name();
is = new IconSettings;
is->icon = mt.icon_name();
/* icon label path's basename */
is.name = base;
is.type = ICON_FILE;
can_add = true;
} else {
E_DEBUG(E_STRLOC ": Failed mime-type for %s, ignoring...\n", path);
can_add = false;
is->name = base;
is->type = ICON_FILE;
}
}
if(can_add) {
/*
* key_name is section in config file with icon X/Y values
* FIXME: this should be named 'section_name'
*/
is.key_name = base;
if(!is)
return false;
/* random_pos() is used if X/Y keys are not found */
int icon_x = random_pos(w() - 10);
int icon_y = random_pos(w() - 10);
/*
* key_name is section in config file with icon X/Y values
* FIXME: this should be named 'section_name'
*/
is->key_name = base;
if(conf) {
/* we load positions from used ede-desktop-icos.conf only */
conf->get(base, "X", icon_x, icon_x, edelib::RES_USER_ONLY);
conf->get(base, "Y", icon_y, icon_y, edelib::RES_USER_ONLY);
}
/* random_pos() is used if X/Y keys are not found */
int icon_x = random_pos(w() - 10);
int icon_y = random_pos(w() - 10);
E_DEBUG(E_STRLOC ": %s found with: %i %i\n", base, icon_x, icon_y);
is.x = icon_x;
is.y = icon_y;
is.full_path = path;
DesktopIcon* dic = new DesktopIcon(gisett, &is, color());
add_icon(dic);
if(conf) {
/* we load positions from used ede-desktop-icos.conf only */
conf->get(base, "X", icon_x, icon_x, edelib::RES_USER_ONLY);
conf->get(base, "Y", icon_y, icon_y, edelib::RES_USER_ONLY);
}
return can_add;
E_DEBUG(E_STRLOC ": %s found with: %i %i\n", base, icon_x, icon_y);
is->x = icon_x;
is->y = icon_y;
is->full_path = path;
DesktopIcon* dic = new DesktopIcon(gisett, is, color());
add_icon(dic);
return true;
}
DesktopIcon* Desktop::find_icon_by_path(const char* path, DesktopIconListIter* ret) {

View File

@ -3,7 +3,7 @@
*
* ede-desktop, desktop and icon manager
* Part of Equinox Desktop Environment (EDE).
* Copyright (c) 2006-2008 EDE Authors.
* Copyright (c) 2006-2009 EDE Authors.
*
* This program is licensed under terms of the
* GNU General Public License version 2 or newer.
@ -38,7 +38,6 @@
#define ICON_FACE_ONE 1 // use icon
#define ICON_FACE_TWO 2 // use icon2
struct GlobalIconSettings {
int label_background;
int label_foreground;
@ -118,7 +117,7 @@ private:
void load_icons(const char* path);
void save_icons_positions(void);
bool read_desktop_file(const char* path, IconSettings& is);
IconSettings* read_desktop_file(const char* path);
void add_icon(DesktopIcon* ic);