2008-08-01 22:30:04 +04:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-09-22 17:31:20 +04:00
|
|
|
* ede-conf, a control panel for EDE
|
2008-08-01 22:30:04 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2008-09-22 17:31:20 +04:00
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Button.H>
|
|
|
|
#include <FL/Fl_Box.H>
|
|
|
|
#include <FL/Fl_Shared_Image.H>
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
2009-02-23 18:05:24 +03:00
|
|
|
#include <edelib/Resource.h>
|
2007-05-22 18:51:00 +04:00
|
|
|
#include <edelib/StrUtil.h>
|
|
|
|
#include <edelib/Debug.h>
|
2008-08-01 22:30:04 +04:00
|
|
|
#include <edelib/ExpandableGroup.h>
|
|
|
|
#include <edelib/String.h>
|
2009-03-25 13:33:40 +03:00
|
|
|
#include <edelib/IconLoader.h>
|
2007-05-22 18:51:00 +04:00
|
|
|
#include <edelib/Nls.h>
|
2008-08-01 22:30:04 +04:00
|
|
|
#include <edelib/Window.h>
|
|
|
|
#include <edelib/MessageBox.h>
|
2008-08-05 18:26:38 +04:00
|
|
|
#include <edelib/Run.h>
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2009-03-25 13:33:40 +03:00
|
|
|
EDELIB_NS_USING(list)
|
|
|
|
EDELIB_NS_USING(Resource)
|
|
|
|
EDELIB_NS_USING(ExpandableGroup)
|
|
|
|
EDELIB_NS_USING(String)
|
|
|
|
EDELIB_NS_USING(IconLoader)
|
|
|
|
EDELIB_NS_USING(alert)
|
|
|
|
EDELIB_NS_USING(run_async)
|
|
|
|
EDELIB_NS_USING(stringtok)
|
|
|
|
EDELIB_NS_USING(str_trim)
|
|
|
|
EDELIB_NS_USING(ICON_SIZE_LARGE)
|
|
|
|
|
|
|
|
typedef list<String> StrList;
|
|
|
|
typedef list<String>::iterator StrListIter;
|
2008-08-01 22:30:04 +04:00
|
|
|
|
|
|
|
class ControlButton : public Fl_Button {
|
2009-02-23 18:05:24 +03:00
|
|
|
private:
|
2009-03-25 13:33:40 +03:00
|
|
|
String tipstr;
|
|
|
|
String exec;
|
2009-02-23 18:05:24 +03:00
|
|
|
public:
|
2009-03-25 13:33:40 +03:00
|
|
|
ControlButton(const String& ts, const String& e, int x, int y, int w, int h, const char* l = 0);
|
2009-02-23 18:05:24 +03:00
|
|
|
int handle(int event);
|
2008-08-01 22:30:04 +04:00
|
|
|
};
|
2007-05-22 18:51:00 +04:00
|
|
|
|
2009-03-25 13:33:40 +03:00
|
|
|
ControlButton::ControlButton(const String& ts, const String& e, int x, int y, int w, int h, const char* l) :
|
|
|
|
Fl_Button(x, y, w, h, l),
|
|
|
|
tipstr(ts),
|
|
|
|
exec(e)
|
|
|
|
{
|
|
|
|
box(FL_FLAT_BOX);
|
|
|
|
align(FL_ALIGN_WRAP);
|
|
|
|
color(FL_BACKGROUND2_COLOR);
|
|
|
|
|
|
|
|
if(!tipstr.empty())
|
|
|
|
tooltip(tipstr.c_str());
|
|
|
|
}
|
|
|
|
|
2007-05-22 18:51:00 +04:00
|
|
|
int ControlButton::handle(int event) {
|
|
|
|
switch(event) {
|
2007-06-15 15:05:44 +04:00
|
|
|
case FL_PUSH:
|
2008-10-02 12:21:23 +04:00
|
|
|
if(Fl::visible_focus() && handle(FL_FOCUS))
|
|
|
|
Fl::focus(this);
|
2008-08-01 22:30:04 +04:00
|
|
|
|
2008-10-02 12:21:23 +04:00
|
|
|
box(FL_DOWN_BOX);
|
2009-03-25 13:33:40 +03:00
|
|
|
redraw();
|
|
|
|
|
2008-08-05 18:26:38 +04:00
|
|
|
if(Fl::event_clicks()) {
|
|
|
|
if(exec.empty())
|
2009-03-25 13:33:40 +03:00
|
|
|
alert(_("Unable to execute command for '%s'. Command value is not set"), label());
|
2008-08-05 18:26:38 +04:00
|
|
|
else
|
2009-03-25 13:33:40 +03:00
|
|
|
run_async("ede-launch %s", exec.c_str());
|
2008-08-05 18:26:38 +04:00
|
|
|
}
|
2008-10-02 12:21:23 +04:00
|
|
|
return 1;
|
|
|
|
|
2007-06-15 15:05:44 +04:00
|
|
|
case FL_RELEASE:
|
2008-08-01 22:30:04 +04:00
|
|
|
box(FL_FLAT_BOX);
|
|
|
|
redraw();
|
2008-10-02 12:21:23 +04:00
|
|
|
return 1;
|
2007-05-22 18:51:00 +04:00
|
|
|
}
|
2008-10-02 12:21:23 +04:00
|
|
|
|
2007-06-15 15:05:44 +04:00
|
|
|
return Fl_Button::handle(event);
|
2006-08-20 22:43:09 +04:00
|
|
|
}
|
|
|
|
|
2008-10-02 12:21:23 +04:00
|
|
|
static void close_cb(Fl_Widget*, void* w) {
|
2008-08-01 22:30:04 +04:00
|
|
|
Fl_Window* win = (Fl_Window*)w;
|
|
|
|
win->hide();
|
2006-08-20 22:43:09 +04:00
|
|
|
}
|
|
|
|
|
2009-03-25 13:33:40 +03:00
|
|
|
static void load_buttons(Fl_Group* g) {
|
2009-02-23 18:05:24 +03:00
|
|
|
edelib::Resource c;
|
2009-03-25 13:33:40 +03:00
|
|
|
|
2009-02-23 18:05:24 +03:00
|
|
|
if(!c.load("ede-conf")) {
|
2009-03-25 13:33:40 +03:00
|
|
|
E_WARNING(E_STRLOC ": Can't load config\n");
|
2009-02-23 18:05:24 +03:00
|
|
|
return;
|
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2009-03-25 13:33:40 +03:00
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
if(!c.get("EdeConf", "items", buf, sizeof(buf))) {
|
2008-10-02 12:21:23 +04:00
|
|
|
E_WARNING("Can't find Items key\n");
|
2007-05-22 18:51:00 +04:00
|
|
|
return;
|
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2008-08-01 22:30:04 +04:00
|
|
|
StrList spl;
|
2009-03-25 13:33:40 +03:00
|
|
|
/* get sections */
|
|
|
|
stringtok(spl, buf, ",");
|
2007-08-21 16:17:35 +04:00
|
|
|
if(spl.empty())
|
|
|
|
return;
|
|
|
|
|
2008-08-01 22:30:04 +04:00
|
|
|
const char* section;
|
|
|
|
StrListIter it = spl.begin(), it_end = spl.end();
|
|
|
|
edelib::String name, tip, exec;
|
2007-08-21 16:17:35 +04:00
|
|
|
|
|
|
|
for(; it != it_end; ++it) {
|
2008-08-01 22:30:04 +04:00
|
|
|
section = (*it).c_str();
|
2009-03-25 13:33:40 +03:00
|
|
|
str_trim((char*)section);
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2009-03-25 13:33:40 +03:00
|
|
|
if(c.get_localized(section, "name", buf, sizeof(buf)))
|
|
|
|
name = buf;
|
2007-05-22 18:51:00 +04:00
|
|
|
else {
|
2009-03-25 13:33:40 +03:00
|
|
|
E_WARNING(E_STRLOC ": No %s, skipping...\n", section);
|
2007-05-22 18:51:00 +04:00
|
|
|
continue;
|
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2009-03-25 13:33:40 +03:00
|
|
|
if(c.get_localized(section, "tip", buf, sizeof(buf)))
|
|
|
|
tip = buf;
|
|
|
|
if(c.get(section, "exec", buf, sizeof(buf)))
|
|
|
|
exec = buf;
|
2008-08-01 22:30:04 +04:00
|
|
|
|
2009-03-25 13:33:40 +03:00
|
|
|
ControlButton* cb = new ControlButton(tip, exec, 0, 0, 100, 100);
|
2008-08-01 22:30:04 +04:00
|
|
|
cb->copy_label(name.c_str());
|
|
|
|
|
2009-03-25 13:33:40 +03:00
|
|
|
c.get(section, "icon", buf, sizeof(buf));
|
|
|
|
IconLoader::set(cb, buf, ICON_SIZE_LARGE);
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2008-08-01 22:30:04 +04:00
|
|
|
g->add(cb);
|
2006-08-20 22:43:09 +04:00
|
|
|
}
|
|
|
|
}
|
2007-05-22 18:51:00 +04:00
|
|
|
|
2009-01-17 16:05:03 +03:00
|
|
|
int main(int argc, char** argv) {
|
2008-10-02 12:21:23 +04:00
|
|
|
edelib::Window* win = new edelib::Window(455, 330, _("EDE Configuration Place"));
|
2008-08-01 22:30:04 +04:00
|
|
|
win->begin();
|
2008-10-02 12:21:23 +04:00
|
|
|
|
|
|
|
/*
|
2009-03-25 13:33:40 +03:00
|
|
|
* Resizable invisible box. It is created first so (due stacking order) does not steal
|
|
|
|
* FL_ENTER/FL_LEAVE events from ControlButton children
|
2008-10-02 12:21:23 +04:00
|
|
|
*/
|
|
|
|
Fl_Box* rbox = new Fl_Box(10, 220, 120, 65);
|
|
|
|
win->resizable(rbox);
|
|
|
|
|
2008-08-01 22:30:04 +04:00
|
|
|
Fl_Group* titlegrp = new Fl_Group(0, 0, 455, 50);
|
2007-06-15 15:05:44 +04:00
|
|
|
titlegrp->box(FL_FLAT_BOX);
|
|
|
|
titlegrp->color(138);
|
2007-05-22 18:51:00 +04:00
|
|
|
titlegrp->begin();
|
2008-08-01 22:30:04 +04:00
|
|
|
Fl_Box* title = new Fl_Box(10, 10, 435, 30, win->label());
|
2007-06-15 15:05:44 +04:00
|
|
|
title->color(138);
|
2008-08-01 22:30:04 +04:00
|
|
|
title->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
|
2007-06-15 15:05:44 +04:00
|
|
|
title->labelcolor(23);
|
|
|
|
title->labelfont(FL_HELVETICA_BOLD);
|
2007-05-22 18:51:00 +04:00
|
|
|
title->labelsize(16);
|
|
|
|
titlegrp->end();
|
|
|
|
titlegrp->resizable(title);
|
|
|
|
|
2009-03-25 13:33:40 +03:00
|
|
|
ExpandableGroup* icons = new ExpandableGroup(10, 60, 435, 225);
|
2007-06-15 15:05:44 +04:00
|
|
|
icons->box(FL_DOWN_BOX);
|
|
|
|
icons->color(FL_BACKGROUND2_COLOR);
|
2008-10-02 12:21:23 +04:00
|
|
|
icons->begin();
|
2007-06-15 15:05:44 +04:00
|
|
|
icons->end();
|
2007-05-22 18:51:00 +04:00
|
|
|
|
2009-03-25 13:33:40 +03:00
|
|
|
/*
|
2008-10-02 12:21:23 +04:00
|
|
|
Fl_Box* tipbox = new Fl_Box(10, 295, 240, 25, _("Double click on a desired item"));
|
2007-06-15 15:05:44 +04:00
|
|
|
tipbox->box(FL_FLAT_BOX);
|
2008-08-01 22:30:04 +04:00
|
|
|
tipbox->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
|
2009-03-25 13:33:40 +03:00
|
|
|
tipbox->hide();
|
|
|
|
*/
|
2007-05-22 18:51:00 +04:00
|
|
|
|
2009-03-25 13:33:40 +03:00
|
|
|
load_buttons(icons);
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2009-03-25 13:33:40 +03:00
|
|
|
/* Fl_Button* options = new Fl_Button(260, 295, 90, 25, _("&Options")); */
|
2008-08-01 22:30:04 +04:00
|
|
|
Fl_Button* close = new Fl_Button(355, 295, 90, 25, _("&Close"));
|
|
|
|
close->callback(close_cb, win);
|
|
|
|
Fl::focus(close);
|
|
|
|
win->end();
|
2009-01-17 16:05:03 +03:00
|
|
|
win->show(argc, argv);
|
2007-06-15 15:05:44 +04:00
|
|
|
return Fl::run();
|
2006-08-20 22:43:09 +04:00
|
|
|
}
|