eiconman now uses settings code.

Removed dead utf8 parts.
Misc stuff...
This commit is contained in:
Sanel Zukan 2007-11-06 14:33:19 +00:00
parent 484717e7b8
commit d8e4d986db
8 changed files with 140 additions and 162 deletions

View File

@ -25,8 +25,6 @@
#include <edelib/MessageBox.h>
#include <edelib/Nls.h>
#define USE_SHAPE 1
#ifdef USE_SHAPE
#include <X11/extensions/shape.h>
#endif
@ -154,6 +152,7 @@ DesktopIcon::~DesktopIcon() {
}
void DesktopIcon::update_label_size(void) {
labelsize(globals->label_fontsize);
lwidth = globals->label_maxwidth;
lheight= 0;

View File

@ -10,7 +10,10 @@
SubDir TOP eiconman ;
SOURCE = eiconman.cpp Utils.cpp Wallpaper.cpp DesktopIcon.cpp NotifyBox.cpp Utf8.cpp ;
ObjectC++Flags DesktopIcon.cpp : -DUSE_SHAPE ;
ObjectC++Flags eiconman.cpp : -DUSE_EDELIB_WINDOW ;
SOURCE = eiconman.cpp Utils.cpp Wallpaper.cpp DesktopIcon.cpp NotifyBox.cpp ;
EdeProgram eiconman : $(SOURCE) ;
TranslationStrings locale : $(SOURCE) ;

View File

@ -1,48 +0,0 @@
#include "Utf8.h"
int utf16_to_utf8(unsigned int from, char* to) {
if(from < 0x000080) {
to[0] = from;
return 1;
} else if(from < 0x000800) {
to[0] = 0xC0 | (from >> 6);
to[1] = 0x80 | (from & 0x3F);
return 2;
} else if(from < 0x010000) {
to[0] = 0xE0 | (from >> 12);
to[1] = 0x80 | ((from >> 6) & 0x3F);
to[2] = 0x80 | (from & 0x3F);
return 3;
} else if(from < 0x00200000) {
to[0] = 0xF0 | (from >> 18);
to[1] = 0x80 | ((from >> 12) & 0x3F);
to[2] = 0x80 | ((from >> 6) & 0x3F);
to[3] = 0x80 | (from & 0x3F);
return 4;
} else if(from < 0x01000000) {
to[0] = 0xF8 | (from >> 24);
to[1] = 0x80 | ((from >> 18) & 0x3F);
to[2] = 0x80 | ((from >> 12) & 0x3F);
to[3] = 0x80 | ((from >> 6) & 0x3F);
to[4] = 0x80 | (from & 0x3F);
return 5;
}
to[0] = '?';
return -1;
}
int utf16_to_utf8_str(unsigned short* from, int len, char* to) {
int j = 0;
for(int i = 0; i < len; i++) {
int s = utf16_to_utf8((unsigned int)from[i], to + j);
if(s < 1)
j += 1;
else
j += s;
}
return j;
}
bool is_utf16(unsigned short* from, int len) {
return !(from[0] < 0x000080);
}

View File

@ -1,13 +0,0 @@
#ifndef __UTF8_H__
#define __UTF8_H__
// 'to' must be at least 5 bytes long
int utf16_to_utf8(unsigned int from, char* to);
// 'to' must be at least len * 5 long
int utf16_to_utf8_str(unsigned short* from, int len, char* to);
// check if characters are in UTF-16 encoding
bool is_utf16(unsigned short* from, int len);
#endif

View File

@ -19,7 +19,7 @@
/*
* Class responsible for displaying images at background
* their scaling (TODO), caching(TODO) and making coffee at spear time.
* their scaling (TODO), caching(TODO) and making coffee at the spear time.
*/
class Wallpaper : public Fl_Box {
private:

View File

@ -1,28 +1,15 @@
[Desktop]
Color = 45
WallpaperUse = 0
Wallpaper = /home/foo/xxx/baz/tax
Color = 458855680
WallpaperUse = 1
WallpaperMode = 1
Wallpaper = /home/sanel/wallpapers/janablack_02_1024.jpg
[Icons]
Label Background = 827223040
Label Foreground = 7
Label Fontsize = 10
Label Fontsize = 12
Label Maxwidth = 55
Label Transparent = 1
Label Visible = 1
Gridspacing = 10
OneClickExec = 0
AutoArrange = 1
[Demo folder]
X = 20
Y = 151
[Home.desktop]
X = 113
Y = 16
[trash.desktop]
X = 20
Y = 20

View File

@ -5,17 +5,20 @@
* 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.
* This program is licensed under the terms of
* the GNU General Public License version 2 or later.
* See COPYING for details.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "eiconman.h"
#include "DesktopIcon.h"
#include "Utils.h"
#include "Wallpaper.h"
#include "NotifyBox.h"
#include "Utf8.h"
#include <edelib/Debug.h>
#include <edelib/File.h>
@ -25,6 +28,7 @@
#include <edelib/MimeType.h>
#include <edelib/StrUtil.h>
#include <edelib/IconTheme.h>
#include <edelib/Run.h>
#include <edelib/Nls.h>
#include <FL/Fl.h>
@ -36,22 +40,24 @@
#include <FL/fl_ask.h>
#include <unistd.h> // sleep
#include <signal.h>
#include <stdlib.h> // rand, srand
#include <time.h> // time
#if 0
#include <X11/extensions/Xdamage.h>
#endif
#include <signal.h>
#include <stdlib.h> // rand, srand
#include <time.h> // time
#define CONFIG_NAME "eiconman.conf"
#define EICONMAN_UID 0x10
#define CONFIG_NAME "eiconman.conf"
#define ICONS_CONFIG_NAME "eiconman-icons.conf"
#define SELECTION_SINGLE (Fl::event_button() == 1)
#define SELECTION_MULTI (Fl::event_button() == 1 && (Fl::event_key(FL_Shift_L) || Fl::event_key(FL_Shift_R)))
#undef MIN
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#undef MAX
#define MAX(x,y) ((x) > (y) ? (x) : (y))
/*
@ -60,6 +66,9 @@
*/
#define NOT_SELECTABLE(widget) ((widget == this) || (widget == wallpaper) || (widget == dmenu))
void background_conf_cb(Fl_Widget*, void*);
void icons_conf_cb(Fl_Widget*, void*);
Fl_Menu_Item desktop_menu[] = {
{_(" &New desktop item "), 0, 0, 0, FL_SUBMENU},
{_(" &Application... "), 0, 0},
@ -74,8 +83,8 @@ Fl_Menu_Item desktop_menu[] = {
{0},
{_(" &Copy "), 0, 0},
{_(" &Paste "), 0, 0, 0, FL_MENU_DIVIDER},
{_(" &Icons settings... "), 0, 0},
{_(" &Background... "), 0, 0},
{_(" &Icons settings... "), 0, icons_conf_cb, 0},
{_(" &Background... "), 0, background_conf_cb, 0},
{0}
};
@ -118,6 +127,19 @@ void dir_watch_cb(const char* dir, const char* changed, int flags, void* data) {
Desktop::instance()->dir_watch(dir, changed, flags);
}
void settings_changed_cb(void* data) {
Desktop::instance()->read_config();
Desktop::instance()->redraw();
}
void background_conf_cb(Fl_Widget*, void*) {
Desktop::instance()->execute("../edesktopconf/edesktopconf");
}
void icons_conf_cb(Fl_Widget*, void*) {
Desktop::instance()->execute("../edesktopconf/edesktopconf --icons");
}
int desktop_xmessage_handler(int event) {
#if 0
if(fl_xevent->type == xevent_base + XDamageNotify) {
@ -167,6 +189,12 @@ Desktop::Desktop() : DESKTOP_WINDOW(0, 0, 100, 100, "") {
moving = false;
do_dirwatch = true;
#ifdef USE_EDELIB_WINDOW
DESKTOP_WINDOW::init();
settings_uid(EICONMAN_UID);
settings_callback(settings_changed_cb);
#endif
selbox = new SelectionOverlay;
selbox->x = selbox->y = selbox->w = selbox->h = 0;
selbox->show = false;
@ -179,6 +207,8 @@ Desktop::Desktop() : DESKTOP_WINDOW(0, 0, 100, 100, "") {
Desktop::~Desktop() {
EDEBUG("Desktop::~Desktop()\n");
save_icons();
delete dsett;
delete selbox;
delete notify;
@ -200,15 +230,6 @@ void Desktop::init_internals(void) {
dmenu->menu(desktop_menu);
wallpaper = new Wallpaper(0, 0, w(), h());
wallpaper->set("/home/sanel/wallpapers/katebig.jpg");
//wallpaper->set_tiled("/home/sanel/wallpapers/katesmall.jpg");
//wallpaper->set_tiled("/home/sanelz/walls/katesmall.jpg");
//wallpaper->set_tiled("/home/sanelz/walls/kate.jpg");
//wallpaper->set("/home/sanelz/walls/katebig.jpg");
//wallpaper->hide();
//wallpaper->set("/home/sanelz/walls/katesmall.jpg");
//wallpaper->set("/home/sanelz/walls/nin/1024x768-04.jpg");
//wallpaper->set("/home/sanelz/walls/nin/1024x768-02.jpg");
end();
notify = new NotifyBox(w(), h());
@ -216,12 +237,29 @@ void Desktop::init_internals(void) {
read_config();
/*
* Now try to load icons, first looking inside ~/Desktop directory
* FIXME: dir_exists() can't handle '~/desktop' ???
*/
edelib::String dd = edelib::dir_home();
if(dd.empty()) {
EWARNING(ESTRLOC ": can't read home directory; icons will not be loaded\n");
return;
}
dd += "/Desktop";
if(edelib::dir_exists(dd.c_str())) {
load_icons(dd.c_str());
install_watch(dd.c_str());
}
running = true;
}
void Desktop::init(void) {
if(Desktop::pinstance != NULL)
return;
Desktop::pinstance = new Desktop();
Desktop::pinstance->init_internals();
}
@ -303,7 +341,6 @@ void Desktop::read_config(void) {
int default_wp_use = false;
char wpath[256];
// read Desktop section
conf.get("Desktop", "Color", dsett->color, default_bg_color);
if(conf.error() != edelib::CONF_ERR_SECTION) {
@ -320,7 +357,6 @@ void Desktop::read_config(void) {
dsett->wp_use = default_wp_use;
}
// read Icons section
conf.get("Icons", "Label Background", gisett.label_background, FL_BLUE);
conf.get("Icons", "Label Foreground", gisett.label_foreground, FL_WHITE);
conf.get("Icons", "Label Fontsize", gisett.label_fontsize, 12);
@ -330,56 +366,42 @@ void Desktop::read_config(void) {
conf.get("Icons", "OneClickExec", gisett.one_click_exec, false);
conf.get("Icons", "AutoArrange", gisett.auto_arrange, true);
/*
* Now try to load icons, first looking inside ~/Desktop directory
* then inside config since config could contain removed entries
* from $HOME/Desktop
*
* FIXME: dir_exists() can't handle '~/Desktop' ???
*/
edelib::String dd = edelib::dir_home();
if(dd.empty()) {
EWARNING(ESTRLOC ": Can't read home directory; icons will not be loaded\n");
return;
}
dd += "/Desktop";
if(dsett->wp_use)
wallpaper->set(wpath);
}
/*
* Setup watcher on ~/Desktop directory. All further events will
* be reported to dir_watch()
*/
if(edelib::dir_exists(dd.c_str())) {
load_icons(dd.c_str(), &conf);
void Desktop::install_watch(const char* path) {
edelib::DirWatch::init();
edelib::DirWatch::callback(dir_watch_cb);
edelib::DirWatch::init();
edelib::DirWatch::callback(dir_watch_cb);
if(!edelib::DirWatch::add(dd.c_str(),
if(!edelib::DirWatch::add(path,
edelib::DW_CREATE | edelib::DW_MODIFY | edelib::DW_RENAME | edelib::DW_DELETE)) {
EWARNING(ESTRLOC ": Can't load %s; icons will not be loaded\n", dd.c_str());
edelib::DirWatch::shutdown();
}
EWARNING(ESTRLOC ": Can't setup watch on %s\n", path);
edelib::DirWatch::shutdown();
}
}
void Desktop::save_config(void) {
// TODO
}
void Desktop::load_icons(const char* path, edelib::Config* conf) {
void Desktop::load_icons(const char* path) {
EASSERT(path != NULL);
edelib::Config conf, *conf_ptr = NULL;
if(!conf.load(ICONS_CONFIG_NAME))
EWARNING(ESTRLOC ": Can't load icons positions from %s, randomizing them...\n", ICONS_CONFIG_NAME);
else
conf_ptr = &conf;
StringList lst;
edelib::list<edelib::String> lst;
// list with full path; icon basename is extracted in add_icon_pathed()
if(!dir_list(path, lst, true)) {
EDEBUG(ESTRLOC ": Can't read %s\n", path);
return;
}
edelib::list<edelib::String>::iterator it, it_end;
StringListIter it, it_end;
for(it = lst.begin(), it_end = lst.end(); it != it_end; ++it)
add_icon_pathed((*it).c_str(), conf);
add_icon_pathed((*it).c_str(), conf_ptr);
}
bool Desktop::add_icon_pathed(const char* path, edelib::Config* conf) {
@ -445,6 +467,24 @@ bool Desktop::add_icon_pathed(const char* path, edelib::Config* conf) {
return can_add;
}
void Desktop::save_icons(void) {
edelib::Config conf;
char* icon_base;
DesktopIconListIter it = icons.begin(), it_end = icons.end();
for(; it != it_end; ++it) {
if((*it)->path().empty())
continue;
icon_base = get_basename((*it)->path().c_str());
conf.set(icon_base, "X", (*it)->x());
conf.set(icon_base, "Y", (*it)->y());
}
if(!conf.save(ICONS_CONFIG_NAME))
EWARNING(ESTRLOC ": Unable to store icons positions\n");
}
DesktopIcon* Desktop::find_icon_pathed(const char* path) {
EASSERT(path != NULL);
@ -742,6 +782,9 @@ void Desktop::notify_desktop_changed(void) {
char** names;
int ret = net_get_workspace_names(names);
if(!ret)
return;
if(num >= ret) {
XFreeStringList(names);
return;
@ -758,21 +801,6 @@ void Desktop::drop_source(const char* src, int src_len, int x, int y) {
if(src_len < 1)
return;
#if 0
/*
* Commented for now since is_utf16() does not works as expected;
* on other hand, UTF-16 conversion is fine
*/
if(is_utf16((unsigned short*)src, src_len)) {
char* utf_src = new char[src_len * 5];
if(utf16_to_utf8_str((unsigned short*)src, src_len, utf_src)) {
utf_src[src_len] = '\0';
EDEBUG(ESTRLOC ":==========> %s|\n", utf_src);
}
delete [] utf_src;
}
#endif
char* src_copy = new char[src_len + 1];
int real_len = 0;
@ -957,6 +985,11 @@ void Desktop::dir_watch(const char* dir, const char* changed, int flags) {
EDEBUG(ESTRLOC ": %s changed with %i\n", changed, flags);
}
void Desktop::execute(const char* cmd) {
EASSERT(cmd != NULL);
edelib::run_program(cmd, false);
}
int Desktop::handle(int event) {
switch(event) {
case FL_FOCUS:
@ -988,7 +1021,8 @@ int Desktop::handle(int event) {
selbox->x = Fl::event_x();
selbox->y = Fl::event_y();
} else if(Fl::event_button() == 3) {
dmenu->menu()->popup(Fl::event_x(), Fl::event_y());
const Fl_Menu_Item* item = dmenu->menu()->popup(Fl::event_x(), Fl::event_y());
dmenu->picked(item);
}
return 1;
@ -1152,9 +1186,10 @@ int main() {
// a lot of preparing code depends on this
fl_open_display();
#ifndef USE_EDELIB_WINDOW
fl_register_images();
edelib::IconTheme::init("edeneu");
#endif
Desktop::init();
Desktop::instance()->show();
@ -1172,7 +1207,8 @@ int main() {
Desktop::shutdown();
#ifndef USE_EDELIB_WINDOW
edelib::IconTheme::shutdown();
#endif
return 0;
}

View File

@ -13,8 +13,13 @@
#ifndef __EICONMAN_H__
#define __EICONMAN_H__
#include <FL/Fl_Window.h>
#include <FL/Fl_Double_Window.h>
#ifdef USE_EDELIB_WINDOW
#include <edelib/Window.h>
#else
#include <FL/Fl_Window.h>
#include <FL/Fl_Double_Window.h>
#endif
#include <FL/Fl_Image.h>
#include <edelib/String.h>
@ -80,8 +85,14 @@ class Fl_Menu_Button;
typedef edelib::list<DesktopIcon*> DesktopIconList;
typedef edelib::list<DesktopIcon*>::iterator DesktopIconListIter;
typedef edelib::list<edelib::String> StringList;
typedef edelib::list<edelib::String>::iterator StringListIter;
#define DESKTOP_WINDOW Fl_Window
#ifdef USE_EDELIB_WINDOW
#define DESKTOP_WINDOW edelib::Window
#else
#define DESKTOP_WINDOW Fl_Window
#endif
class Desktop : public DESKTOP_WINDOW {
private:
@ -105,7 +116,9 @@ class Desktop : public DESKTOP_WINDOW {
void init_internals(void);
void load_icons(const char* path, edelib::Config* conf);
void load_icons(const char* path);
void save_icons(void);
void install_watch(const char* path);
bool read_desktop_file(const char* path, IconSettings& is);
void add_icon(DesktopIcon* ic);
@ -141,7 +154,6 @@ class Desktop : public DESKTOP_WINDOW {
static Desktop* instance(void);
void read_config(void);
void save_config(void);
void update_workarea(void);
void area(int& X, int& Y, int& W, int& H) { X = x(); Y = y(); W = w(); H = h(); }
@ -155,6 +167,8 @@ class Desktop : public DESKTOP_WINDOW {
void dir_watch(const char* dir, const char* changed, int flags);
void dir_watch_on(void) { do_dirwatch = true; }
void dir_watch_off(void) { do_dirwatch = false; }
void execute(const char* cmd);
};
#endif