Importing new tool for configuring preferred applications. Not finished

This commit is contained in:
Sanel Zukan 2011-10-20 15:13:04 +00:00
parent 24683b07ca
commit 93f7e1d1f6
7 changed files with 273 additions and 0 deletions

View File

@ -33,6 +33,7 @@ SubInclude TOP ede-launch ;
SubInclude TOP emountd ;
SubInclude TOP ede-timedate ;
SubInclude TOP ede-tip ;
SubInclude TOP ede-preferred-applications ;
SubInclude TOP evoke ;
SubInclude TOP doc ;
SubInclude TOP data ;

View File

@ -0,0 +1,72 @@
#include <string.h>
#include <FL/Fl_Choice.H>
#include <edelib/Debug.h>
#include <edelib/File.h>
#include "Apps.h"
EDELIB_NS_USING(file_path)
EDELIB_NS_USING(String)
void app_for_each(KnownApp *lst, KnownAppCb cb, void *data) {
E_RETURN_IF_FAIL(lst != 0);
for(int i = 0; lst[i].name; i++)
cb(lst[i], data);
}
KnownApp *app_find_by_cmd(KnownApp *lst, const char *name) {
E_RETURN_VAL_IF_FAIL(lst != 0, 0);
E_RETURN_VAL_IF_FAIL(name, 0);
for(int i = 0; lst[i].name; i++)
if(strcmp(lst[i].name, name) == 0)
return &lst[i];
return 0;
}
KnownApp *app_find_by_name(KnownApp *lst, const char *cmd) {
E_RETURN_VAL_IF_FAIL(lst != 0, 0);
E_RETURN_VAL_IF_FAIL(cmd, 0);
for(int i = 0; lst[i].name; i++)
if(strcmp(lst[i].cmd, cmd) == 0)
return &lst[i];
return 0;
}
KnownApp *app_get(KnownApp *lst, int index) {
E_RETURN_VAL_IF_FAIL(lst != 0, 0);
return &lst[index];
}
static void populate_menu(const KnownApp &item, void *data) {
Fl_Choice *c = (Fl_Choice*)data;
const char *cmd = item.cmd;
/* check some magic values first */
if(app_is_magic_cmd(cmd)) {
c->add(item.name);
return;
}
/* check if binary exists */
String ret = file_path(cmd);
if(ret.empty()) return;
c->add(item.name);
}
void app_populate_menu(KnownApp *lst, Fl_Choice *c) {
E_RETURN_IF_FAIL(lst != 0);
E_RETURN_IF_FAIL(c != 0);
app_for_each(lst, populate_menu, c);
}
bool app_is_magic_cmd(const char *cmd) {
E_RETURN_VAL_IF_FAIL(cmd != 0, false);
if(cmd[0] == '_' && strlen(cmd) == 3 && (cmd[1] == 'n' || cmd[1] == 'b'))
return true;
return false;
}

View File

@ -0,0 +1,27 @@
#ifndef __EDE_PREFERRED_APPLICATIONS_APPS_H__
#define __EDE_PREFERRED_APPLICATIONS_APPS_H__
class Fl_Choice;
struct KnownApp {
const char *name;
const char *cmd;
};
/* _n_ and _b_ are special predefined values so we from callback knows what to do */
#define KNOWN_APP_START {_("None"), "_n_"}
#define KNOWN_APP_END \
{"Browse...", "_b_"}, \
{0, 0}
typedef void (*KnownAppCb)(const KnownApp &app, void *data);
void app_for_each(KnownApp *lst, KnownAppCb cb, void *data = 0);
KnownApp *app_find_by_name(KnownApp *lst, const char *name);
KnownApp *app_find_by_cmd(KnownApp *lst, const char *cmd);
KnownApp *app_get(KnownApp *lst, int index);
void app_populate_menu(KnownApp *lst, Fl_Choice *c);
bool app_is_magic_cmd(const char *cmd);
#endif

View File

@ -0,0 +1,10 @@
#
# $Id:$
#
SubDir TOP ede-preferred-applications ;
SOURCE = ede-preferred-applications.cpp Apps.cpp ;
EdeProgram ede-preferred-applications : $(SOURCE) ;
TranslationStrings locale : $(SOURCE) ;

View File

@ -0,0 +1,41 @@
#ifndef __EDE_PREFERRED_APPLICATIONS_PREDEFAPPS_H__
#define __EDE_PREFERRED_APPLICATIONS_PREDEFAPPS_H__
#include "Apps.h"
static KnownApp app_browsers[] = {
KNOWN_APP_START,
{"Mozilla Firefox", "firefox"},
{"Mozilla Seamonkey", "seamonkey"},
{"Google Chrome", "google-chrome"},
{"Midori", "midori"},
{"Konqueror", "konqueror"},
{"Dillo", "dillo"},
KNOWN_APP_END
};
static KnownApp app_mails[] = {
KNOWN_APP_START,
{"Mozilla Thunderbird", "thunderbird"},
KNOWN_APP_END
};
static KnownApp app_filemanagers[] = {
KNOWN_APP_START,
{"Thunar", "thunar"},
{"Nautilus", "nautilus"},
{"Dolphin", "dolphin"},
{"Konqueror", "konqueror"},
KNOWN_APP_END
};
static KnownApp app_terminals[] = {
KNOWN_APP_START,
{"X11 terminal", "xterm"},
{"Rxvt", "rxvt"},
{"Mrxvt", "mrxvt"},
{"Xfce Terminal", "xfterm4"},
KNOWN_APP_END
};
#endif

View File

@ -0,0 +1,72 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Choice.H>
#include <FL/Fl_Tabs.H>
#include <edelib/Window.h>
#include <edelib/Nls.h>
#include <edelib/Ede.h>
#include "PredefApps.h"
EDELIB_NS_USING_AS(Window, EdeWindow)
static void close_cb(Fl_Widget *widget, void *ww) {
EdeWindow *win = (EdeWindow*)ww;
win->hide();
}
static void ok_cb(Fl_Widget *widget, void *ww) {
close_cb(widget, ww);
}
int main(int argc, char** argv) {
EDE_APPLICATION("ede-preferred-applications");
EdeWindow *win = new EdeWindow(365, 220, _("Preferred applications"));
Fl_Tabs *tabs = new Fl_Tabs(10, 10, 345, 165);
tabs->begin();
Fl_Group *gint = new Fl_Group(15, 30, 335, 140, _("Internet"));
gint->begin();
Fl_Choice *cint = new Fl_Choice(20, 65, 320, 25, _("Web browser"));
cint->align(FL_ALIGN_TOP_LEFT);
app_populate_menu(app_browsers, cint);
cint->value(0);
Fl_Choice *cmail = new Fl_Choice(20, 120, 320, 25, _("Mail reader"));
cmail->align(FL_ALIGN_TOP_LEFT);
app_populate_menu(app_mails, cmail);
cmail->value(0);
gint->end();
Fl_Group *gutil = new Fl_Group(15, 30, 335, 140, _("Utilities"));
gutil->hide();
gutil->begin();
Fl_Choice *ufile = new Fl_Choice(20, 65, 320, 25, _("File manager"));
ufile->align(FL_ALIGN_TOP_LEFT);
app_populate_menu(app_filemanagers, ufile);
ufile->value(0);
Fl_Choice *uterm = new Fl_Choice(20, 120, 320, 25, _("Terminal"));
uterm->align(FL_ALIGN_TOP_LEFT);
app_populate_menu(app_terminals, uterm);
uterm->value(0);
gutil->end();
tabs->end();
Fl_Button *ok = new Fl_Button(170, 185, 90, 25, _("&OK"));
Fl_Button *cancel = new Fl_Button(265, 185, 90, 25, _("&Cancel"));
ok->callback(ok_cb, win);
cancel->callback(close_cb, win);
win->set_modal();
win->end();
win->show(argc, argv);
return Fl::run();
}

View File

@ -0,0 +1,50 @@
# data file for the Fltk User Interface Designer (fluid)
version 1.0300
header_name {.h}
code_name {.cxx}
Function {} {open
} {
Fl_Window {} {
label {Preferred applications} open selected
xywh {583 354 365 220} type Double modal visible
} {
Fl_Button {} {
label {&OK}
xywh {170 185 90 25}
}
Fl_Button {} {
label {&Cancel}
xywh {265 185 90 25}
}
Fl_Tabs {} {open
xywh {10 10 345 165}
} {
Fl_Group {} {
label Internet open
xywh {15 30 335 140}
} {
Fl_Choice {} {
label {Web browser} open
xywh {20 65 320 25} align 5
} {}
Fl_Choice {} {
label {Mail reader} open
xywh {20 120 320 25} align 5
} {}
}
Fl_Group {} {
label Utilities open
xywh {15 30 335 140} hide
} {
Fl_Choice {} {
label {File manager} open
xywh {20 65 320 25} align 5
} {}
Fl_Choice {} {
label Terminal open
xywh {20 120 320 25} align 5
} {}
}
}
}
}