Reworked econtrol code

This commit is contained in:
Sanel Zukan 2008-08-01 18:30:04 +00:00
parent 2b20415eab
commit ebdbed8502
2 changed files with 105 additions and 147 deletions

View File

@ -1,41 +1,71 @@
/*
#include "econtrol.h" * $Id$
*
* Econtrol, control panel for EDE
* Part of Equinox Desktop Environment (EDE).
* Copyright (c) 2008 EDE Authors.
*
* This program is licensed under terms of the
* GNU General Public License version 2 or newer.
* See COPYING for details.
*/
#include <edelib/Config.h> #include <edelib/Config.h>
#include <edelib/StrUtil.h> #include <edelib/StrUtil.h>
#include <edelib/Debug.h> #include <edelib/Debug.h>
#include <edelib/ExpandableGroup.h>
#include <edelib/String.h>
#include <edelib/IconTheme.h>
#include <edelib/Nls.h> #include <edelib/Nls.h>
#include <edelib/Window.h>
#include <edelib/MessageBox.h>
#include <FL/Fl.h> #include <FL/Fl.h>
#include <FL/Fl_Button.h>
#include <FL/Fl_Box.h>
#include <FL/Fl_Shared_Image.h> #include <FL/Fl_Shared_Image.h>
#include <FL/fl_draw.h> #include <FL/fl_draw.h>
using namespace edelib; typedef edelib::list<edelib::String> StrList;
typedef edelib::list<edelib::String>::iterator StrListIter;
ControlButton::ControlButton(Fl_Box* t, String tv, int x, int y, int w, int h, const char* l) : class ControlButton : public Fl_Button {
Fl_Button(x, y, w, h, l) { private:
tip = t; Fl_Box* tipbox;
tipval = tv; edelib::String tipstr;
edelib::String exec;
public:
ControlButton(Fl_Box* t, const edelib::String& ts, int x, int y, int w, int h, const char* l = 0) :
Fl_Button(x, y, w, h, l), tipbox(t), tipstr(ts) {
box(FL_FLAT_BOX); box(FL_FLAT_BOX);
align(FL_ALIGN_WRAP); align(FL_ALIGN_WRAP);
color(FL_WHITE); color(FL_BACKGROUND2_COLOR);
} }
ControlButton::~ControlButton() { ~ControlButton() { }
} int handle(int event);
};
int ControlButton::handle(int event) { int ControlButton::handle(int event) {
switch(event) { switch(event) {
case FL_ENTER: case FL_ENTER:
tip->label(tipval.c_str()); tipbox->label(tipstr.c_str());
return 1; return 1;
case FL_LEAVE: case FL_LEAVE:
tip->label(""); tipbox->label("");
return 1; return 1;
case FL_PUSH: case FL_PUSH:
return 1; box(FL_DOWN_BOX);
redraw();
if(Fl::event_clicks())
edelib::message("Executing programs not implemented yet");
return 0;
case FL_RELEASE: case FL_RELEASE:
return 1; box(FL_FLAT_BOX);
redraw();
return 0;
default: default:
return Fl_Button::handle(event); return Fl_Button::handle(event);
} }
@ -43,25 +73,12 @@ int ControlButton::handle(int event) {
} }
void close_cb(Fl_Widget*, void* w) { void close_cb(Fl_Widget*, void* w) {
ControlWin* cw = (ControlWin*)w; Fl_Window* win = (Fl_Window*)w;
cw->do_close(); win->hide();
} }
ControlWin::ControlWin(const char* title, int w, int h) : Fl_Window(w, h, title) { void load_buttons(Fl_Group* g, Fl_Box* tipbox) {
edelib::Config c;
IconTheme::init("edeneu");
fl_register_images();
load_icons();
init();
}
ControlWin::~ControlWin() {
IconTheme::shutdown();
}
void ControlWin::load_icons(void) {
Config c;
if(!c.load("econtrol.conf")) { if(!c.load("econtrol.conf")) {
EWARNING("Can't load config\n"); EWARNING("Can't load config\n");
@ -74,99 +91,93 @@ void ControlWin::load_icons(void) {
return; return;
} }
list<String> spl; StrList spl;
list<String>::iterator it, it_end; // get sections
stringtok(spl, buff, ","); edelib::stringtok(spl, buff, ",");
if(spl.empty()) if(spl.empty())
return; return;
const char* sect; bool abspath;
ControlIcon cicon; const char* section;
it = spl.begin(); //ControlIcon cicon;
it_end = spl.end(); StrListIter it = spl.begin(), it_end = spl.end();
edelib::String name, tip, exec;
for(; it != it_end; ++it) { for(; it != it_end; ++it) {
sect = (*it).c_str(); section = (*it).c_str();
str_trim((char*)sect); edelib::str_trim((char*)section);
if(c.get(sect, "Name", buff, sizeof(buff))) if(c.get(section, "Name", buff, sizeof(buff)))
cicon.name = buff; name = buff;
else { else {
EWARNING("No %s, skipping...\n", sect); EWARNING("No %s, skipping...\n", section);
continue; continue;
} }
if(c.get(sect, "Tip", buff, sizeof(buff))) if(c.get(section, "Tip", buff, sizeof(buff)))
cicon.tip = buff; tip = buff;
if(c.get(sect, "Exec", buff, sizeof(buff))) if(c.get(section, "Exec", buff, sizeof(buff)))
cicon.exec = buff; exec = buff;
if(c.get(sect, "Icon", buff, sizeof(buff))) {
cicon.icon = buff; ControlButton* cb = new ControlButton(tipbox, tip, 0, 0, 80, 100);
EDEBUG("setting icon (%s): %s\n", sect, cicon.icon.c_str()); cb->copy_label(name.c_str());
c.get(section, "IconPathAbsolute", abspath, false);
if(c.get(section, "Icon", buff, sizeof(buff))) {
if(abspath) {
Fl_Image* img = Fl_Shared_Image::get(buff);
cb->image(img);
} else {
edelib::String iconpath = edelib::IconTheme::get(buff, edelib::ICON_SIZE_LARGE);
if(!iconpath.empty())
cb->image(Fl_Shared_Image::get(iconpath.c_str()));
else
EWARNING("Can't find %s icon\n", buff);
}
} }
c.get(sect, "IconPathAbsolute", cicon.abspath, false); g->add(cb);
c.get(sect, "Position", cicon.abspath, -1);
iconlist.push_back(cicon);
} }
} }
void ControlWin::init(void) { int main() {
begin(); edelib::Window* win = new edelib::Window(455, 330, _("EDE Control Panel"));
titlegrp = new Fl_Group(0, 0, 455, 50); win->init();
win->begin();
Fl_Group* titlegrp = new Fl_Group(0, 0, 455, 50);
titlegrp->box(FL_FLAT_BOX); titlegrp->box(FL_FLAT_BOX);
titlegrp->color(138); titlegrp->color(138);
titlegrp->begin(); titlegrp->begin();
title = new Fl_Box(10, 10, 435, 30, label()); Fl_Box* title = new Fl_Box(10, 10, 435, 30, win->label());
title->color(138); title->color(138);
title->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); title->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
title->labelcolor(23); title->labelcolor(23);
title->labelfont(FL_HELVETICA_BOLD); title->labelfont(FL_HELVETICA_BOLD);
title->labelsize(16); title->labelsize(16);
titlegrp->end(); titlegrp->end();
titlegrp->resizable(title); titlegrp->resizable(title);
icons = new ExpandableGroup(10, 60, 435, 225); edelib::ExpandableGroup* icons = new edelib::ExpandableGroup(10, 60, 435, 225);
icons->box(FL_DOWN_BOX); icons->box(FL_DOWN_BOX);
icons->color(FL_BACKGROUND2_COLOR); icons->color(FL_BACKGROUND2_COLOR);
icons->end(); icons->end();
tipbox = new Fl_Box(10, 295, 240, 25, _("Double click on desired item")); Fl_Box* tipbox = new Fl_Box(10, 295, 240, 25, _("Double click on desired item"));
tipbox->box(FL_FLAT_BOX); tipbox->box(FL_FLAT_BOX);
tipbox->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_CLIP); tipbox->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
list<ControlIcon>::iterator it, it_end; load_buttons(icons, tipbox);
it = iconlist.begin();
it_end = iconlist.end();
for(; it != it_end; ++it) { // Fl_Button* options = new Fl_Button(260, 295, 90, 25, _("&Options"));
ControlButton* b = new ControlButton(tipbox, (*it).tip, 0, 0, 80, 100); Fl_Button* close = new Fl_Button(355, 295, 90, 25, _("&Close"));
String iconpath = IconTheme::get((*it).icon.c_str(), ICON_SIZE_LARGE); close->callback(close_cb, win);
b->label((*it).name.c_str()); Fl::focus(close);
if(!iconpath.empty())
b->image(Fl_Shared_Image::get(iconpath.c_str()));
icons->add(b);
}
//options = new Fl_Button(260, 295, 90, 25, _("&Options"));
close = new Fl_Button(355, 295, 90, 25, _("&Close"));
close->callback(close_cb, this);
// resizable invisible box // resizable invisible box
rbox = new Fl_Box(10, 220, 120, 65); Fl_Box* rbox = new Fl_Box(10, 220, 120, 65);
resizable(rbox); win->resizable(rbox);
end(); win->end();
} win->show();
void ControlWin::do_close(void) {
hide();
}
int main() {
ControlWin cw(_("EDE Control Panel"));
cw.show();
return Fl::run(); return Fl::run();
} }

View File

@ -1,53 +0,0 @@
#ifndef __ECONTROL_H__
#define __ECONTROL_H__
#include <FL/Fl_Window.h>
#include <FL/Fl_Group.h>
#include <FL/Fl_Box.h>
#include <FL/Fl_Button.h>
#include <edelib/IconTheme.h>
#include <edelib/ExpandableGroup.h>
struct ControlIcon {
edelib::String name;
edelib::String tip;
edelib::String exec;
edelib::String icon;
bool abspath;
int pos;
};
class ControlButton : public Fl_Button {
private:
Fl_Box* tip;
edelib::String tipval;
public:
ControlButton(Fl_Box* t, edelib::String tv, int x, int y, int w, int h, const char* l = 0);
~ControlButton();
int handle(int event);
};
class ControlWin : public Fl_Window {
private:
Fl_Group* titlegrp;
Fl_Box* title;
Fl_Button* close;
//Fl_Button* options;
edelib::ExpandableGroup* icons;
Fl_Box* rbox;
Fl_Box* tipbox;
edelib::list<ControlIcon> iconlist;
void init(void);
void load_icons(void);
public:
ControlWin(const char* title, int w = 455, int h = 330);
~ControlWin();
void do_close(void);
};
#endif