From 93f7e1d1f66f057d9024fda73a6f02d0030fb87b Mon Sep 17 00:00:00 2001 From: Sanel Zukan Date: Thu, 20 Oct 2011 15:13:04 +0000 Subject: [PATCH] Importing new tool for configuring preferred applications. Not finished --- Jamfile | 1 + ede-preferred-applications/Apps.cpp | 72 +++++++++++++++++++ ede-preferred-applications/Apps.h | 27 +++++++ ede-preferred-applications/Jamfile | 10 +++ ede-preferred-applications/PredefApps.h | 41 +++++++++++ .../ede-preferred-applications.cpp | 72 +++++++++++++++++++ .../ede-preferred-applications.fld | 50 +++++++++++++ 7 files changed, 273 insertions(+) create mode 100644 ede-preferred-applications/Apps.cpp create mode 100644 ede-preferred-applications/Apps.h create mode 100644 ede-preferred-applications/Jamfile create mode 100644 ede-preferred-applications/PredefApps.h create mode 100644 ede-preferred-applications/ede-preferred-applications.cpp create mode 100644 ede-preferred-applications/ede-preferred-applications.fld diff --git a/Jamfile b/Jamfile index d1840ec..f118f87 100644 --- a/Jamfile +++ b/Jamfile @@ -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 ; diff --git a/ede-preferred-applications/Apps.cpp b/ede-preferred-applications/Apps.cpp new file mode 100644 index 0000000..b8a7079 --- /dev/null +++ b/ede-preferred-applications/Apps.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#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; +} diff --git a/ede-preferred-applications/Apps.h b/ede-preferred-applications/Apps.h new file mode 100644 index 0000000..99c9e53 --- /dev/null +++ b/ede-preferred-applications/Apps.h @@ -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 diff --git a/ede-preferred-applications/Jamfile b/ede-preferred-applications/Jamfile new file mode 100644 index 0000000..e324ef4 --- /dev/null +++ b/ede-preferred-applications/Jamfile @@ -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) ; diff --git a/ede-preferred-applications/PredefApps.h b/ede-preferred-applications/PredefApps.h new file mode 100644 index 0000000..558ad02 --- /dev/null +++ b/ede-preferred-applications/PredefApps.h @@ -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 diff --git a/ede-preferred-applications/ede-preferred-applications.cpp b/ede-preferred-applications/ede-preferred-applications.cpp new file mode 100644 index 0000000..7e70597 --- /dev/null +++ b/ede-preferred-applications/ede-preferred-applications.cpp @@ -0,0 +1,72 @@ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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(); +} diff --git a/ede-preferred-applications/ede-preferred-applications.fld b/ede-preferred-applications/ede-preferred-applications.fld new file mode 100644 index 0000000..ada7ba8 --- /dev/null +++ b/ede-preferred-applications/ede-preferred-applications.fld @@ -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 + } {} + } + } + } +}