Allow autostart programs be started without dialog

Documentation update
ImagesDirectory key renamed to DataDirectory; images renamed
to data to follow later changes
This commit is contained in:
Sanel Zukan 2007-09-11 14:06:44 +00:00
parent dffebaf72a
commit f0e0bc9032
14 changed files with 67 additions and 41 deletions

View File

@ -35,12 +35,15 @@ void run_all_cb(Fl_Widget*, void* w) {
win->run_all(); win->run_all();
} }
AstartDialog::AstartDialog(unsigned int sz) : Fl_Window(370, 305, _("Autostart warning")), AstartDialog::AstartDialog(unsigned int sz, bool do_show) : Fl_Window(370, 305, _("Autostart warning")),
curr(0), lst_sz(sz), lst(0) { curr(0), lst_sz(sz), show_dialog(do_show), lst(0) {
if(lst_sz) if(lst_sz)
lst = new AstartItem[lst_sz]; lst = new AstartItem[lst_sz];
if(!show_dialog)
return;
begin(); begin();
img = new Fl_Box(10, 10, 65, 60); img = new Fl_Box(10, 10, 65, 60);
img->image(warnpix); img->image(warnpix);
@ -77,6 +80,11 @@ void AstartDialog::add_item(const edelib::String& n, const edelib::String& e) {
} }
void AstartDialog::run(void) { void AstartDialog::run(void) {
if(!show_dialog) {
run_all();
return;
}
for(unsigned int i = 0; i < curr; i++) for(unsigned int i = 0; i < curr; i++)
cbrowser->add(lst[i].name.c_str()); cbrowser->add(lst[i].name.c_str());
@ -88,6 +96,9 @@ void AstartDialog::run(void) {
} }
void AstartDialog::run_selected(void) { void AstartDialog::run_selected(void) {
if(!show_dialog)
return;
int it = cbrowser->nchecked(); int it = cbrowser->nchecked();
if(!it) if(!it)
return; return;

View File

@ -29,6 +29,7 @@ class AstartDialog : public Fl_Window {
private: private:
unsigned int curr; unsigned int curr;
unsigned int lst_sz; unsigned int lst_sz;
bool show_dialog;
AstartItem* lst; AstartItem* lst;
Fl_Box* img; Fl_Box* img;
@ -39,7 +40,7 @@ class AstartDialog : public Fl_Window {
Fl_Button* cancel; Fl_Button* cancel;
public: public:
AstartDialog(unsigned int sz); AstartDialog(unsigned int sz, bool do_show);
~AstartDialog(); ~AstartDialog();
unsigned int list_size(void) { return curr; } unsigned int list_size(void) { return curr; }

View File

@ -35,18 +35,18 @@
#include <string.h> // strdup, memset #include <string.h> // strdup, memset
#include <errno.h> // error codes #include <errno.h> // error codes
void resolve_path(const edelib::String& imgdir, edelib::String& img, bool have_imgdir) { void resolve_path(const edelib::String& datadir, edelib::String& item, bool have_datadir) {
if(img.empty()) if(item.empty())
return; return;
const char* im = img.c_str(); const char* i = item.c_str();
if(!edelib::file_exists(im) && have_imgdir) { if(!edelib::file_exists(i) && have_datadir) {
img = edelib::build_filename("/", imgdir.c_str(), im); item = edelib::build_filename("/", datadir.c_str(), i);
im = img.c_str(); i = item.c_str();
if(!edelib::file_exists(im)) { if(!edelib::file_exists(i)) {
// no file, send then empty // no file, send then empty
img.clear(); item.clear();
} }
} }
} }
@ -206,18 +206,18 @@ bool EvokeService::init_splash(const char* config, bool no_splash, bool dry_run)
return false; return false;
char buff[1024]; char buff[1024];
bool have_imgdir = false; bool have_datadir = false;
c.get("evoke", "ImagesDirectory", buff, sizeof(buff)); c.get("evoke", "DataDirectory", buff, sizeof(buff));
// no evoke section // no evoke section
if(c.error() == edelib::CONF_ERR_SECTION) if(c.error() == edelib::CONF_ERR_SECTION)
return false; return false;
edelib::String imgdir; edelib::String datadir;
if(c.error() == edelib::CONF_SUCCESS) { if(c.error() == edelib::CONF_SUCCESS) {
imgdir = buff; datadir = buff;
have_imgdir = true; have_datadir = true;
} }
edelib::String splashimg; edelib::String splashimg;
@ -228,7 +228,6 @@ bool EvokeService::init_splash(const char* config, bool no_splash, bool dry_run)
if(c.get("evoke", "Sound", buff, sizeof(buff))) if(c.get("evoke", "Sound", buff, sizeof(buff)))
sound = buff; sound = buff;
// Startup key must exists // Startup key must exists
if(!c.get("evoke", "Startup", buff, sizeof(buff))) if(!c.get("evoke", "Startup", buff, sizeof(buff)))
return false; return false;
@ -267,9 +266,12 @@ bool EvokeService::init_splash(const char* config, bool no_splash, bool dry_run)
* Now, before data is send to Splash, resolve directories * Now, before data is send to Splash, resolve directories
* since Splash expects that. * since Splash expects that.
*/ */
resolve_path(imgdir, splashimg, have_imgdir); resolve_path(datadir, splashimg, have_datadir);
for(ClientListIter it = clients.begin(); it != clients.end(); ++it) resolve_path(datadir, sound, have_datadir);
resolve_path(imgdir, (*it).icon, have_imgdir);
ClientListIter it, it_end;
for(it = clients.begin(), it_end = clients.end(); it != it_end; ++it)
resolve_path(datadir, (*it).icon, have_datadir);
Splash sp(no_splash, dry_run); Splash sp(no_splash, dry_run);
sp.set_clients(&clients); sp.set_clients(&clients);
@ -299,9 +301,11 @@ bool EvokeService::init_splash(const char* config, bool no_splash, bool dry_run)
* contains environment name, MUST not be started/not started. * contains environment name, MUST not be started/not started.
* TryExec is same as for .desktop spec. * TryExec is same as for .desktop spec.
*/ */
void EvokeService::init_autostart(void) { void EvokeService::init_autostart(bool safe) {
const char* autostart_dirname = "/autostart/";
edelib::String adir = edelib::user_config_dir(); edelib::String adir = edelib::user_config_dir();
adir += "/autostart/"; adir += autostart_dirname;
StringList dfiles, sysdirs; StringList dfiles, sysdirs;
StringListIter it, it_end; StringListIter it, it_end;
@ -311,8 +315,7 @@ void EvokeService::init_autostart(void) {
edelib::system_config_dirs(sysdirs); edelib::system_config_dirs(sysdirs);
if(!sysdirs.empty()) { if(!sysdirs.empty()) {
for(it = sysdirs.begin(), it_end = sysdirs.end(); it != it_end; ++it) { for(it = sysdirs.begin(), it_end = sysdirs.end(); it != it_end; ++it) {
*it += "/autostart/"; *it += autostart_dirname;
// append content // append content
edelib::dir_list((*it).c_str(), dfiles, true, false, false); edelib::dir_list((*it).c_str(), dfiles, true, false, false);
} }
@ -339,7 +342,7 @@ void EvokeService::init_autostart(void) {
edelib::DesktopFile df; edelib::DesktopFile df;
edelib::String item_name; edelib::String item_name;
AstartDialog dlg(dfiles.size()); AstartDialog dlg(dfiles.size(), safe);
for(it = dfiles.begin(), it_end = dfiles.end(); it != it_end; ++it) { for(it = dfiles.begin(), it_end = dfiles.end(); it != it_end; ++it) {
if((*it).empty()) if((*it).empty())
@ -629,11 +632,11 @@ int EvokeService::handle(const XEvent* ev) {
if(ev->xproperty.atom == _ede_spawn) { if(ev->xproperty.atom == _ede_spawn) {
char buff[1024]; char buff[1024];
if(get_string_property_value(_ede_spawn, buff, sizeof(buff))) { if(get_string_property_value(_ede_spawn, buff, sizeof(buff))) {
logfile->printf("Got _EVOKE_SPAWN with %s. Starting client...\n", buff); logfile->printf("Got _EDE_EVOKE_SPAWN with %s. Starting client...\n", buff);
run_program(buff); run_program(buff);
//heuristic_run_program(buff); //heuristic_run_program(buff);
} else { } else {
logfile->printf("Got _EVOKE_SPAWN with malformed data. Ignoring...\n"); logfile->printf("Got _EDE_EVOKE_SPAWN with malformed data. Ignoring...\n");
} }
return 1; return 1;
} }

View File

@ -69,7 +69,7 @@ class EvokeService {
bool setup_pid(const char* file, const char* lock); bool setup_pid(const char* file, const char* lock);
void setup_atoms(Display* d); void setup_atoms(Display* d);
bool init_splash(const char* config, bool no_splash, bool dry_run); bool init_splash(const char* config, bool no_splash, bool dry_run);
void init_autostart(void); void init_autostart(bool safe);
int handle(const XEvent* ev); int handle(const XEvent* ev);

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 163 KiB

After

Width:  |  Height:  |  Size: 163 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -27,6 +27,10 @@ Options
Run in autostart mode. It will check 'autostart' directory and run .desktop Run in autostart mode. It will check 'autostart' directory and run .desktop
files from it. This will be done according to freedesktop.org autostart specification. files from it. This will be done according to freedesktop.org autostart specification.
-u, --autostart-safe::
Same as '-a' or '--autostart' option, but display dialog with items that should
be run.
-c, --config [FILE]:: -c, --config [FILE]::
Read [FILE] as config file. This file is only used in startup mode to read Read [FILE] as config file. This file is only used in startup mode to read
components to be started. components to be started.
@ -71,13 +75,16 @@ Hidden = true
--------------- ---------------
Make sure that 'Hidden' key is under '[Desktop Entry]' section. Make sure that 'Hidden' key is under '[Desktop Entry]' section.
By default when you are using autostart mode, it will popup window with programs that are 'registered' Autostart mode can be run in two ways: safe and unsafe. Safe way ('-u' or '--autostart-safe') will
for starting, from where you can choose either to start some of them, start all of them or to start popup window with programs that are 'registered' for starting, from where you can choose either to
nothing. This is intentionally; you definitely don't want some application to be started without start some of them, start all of them or to start nothing. On other hand, unsafe way ('-a' or '--autostart')
your knowledge (not to say how this can be very insecure). will simply run all 'registered' items without any questioning (should I say that this can be very insecure).
These options are intentionally provided so you can choose startup policy depending on your security
options.
*Startup mode* is meant to be used when EDE is starting, running each component (or program) *Startup mode* is meant to be used when EDE is starting, running each component (or program)
from evoke.conf (or file specified with '-c' option). This configuration file must be in following form: from evoke.conf (or file specified with '-c' option). This configuration file must be in the following form:
-------------- --------------
# [evoke] section must be present # [evoke] section must be present
[evoke] [evoke]

View File

@ -2,7 +2,7 @@
# main section; must be present # main section; must be present
[evoke] [evoke]
Startup = edewm,eiconman,eworkpanel,xscreensaver Startup = edewm,eiconman,eworkpanel,xscreensaver
ImagesDirectory = images DataDirectory = data
#ImagesDirectory = /home/sanel/blentavo/EDE/ede2/evoke/images #ImagesDirectory = /home/sanel/blentavo/EDE/ede2/evoke/images
Splash = splash-alpha1.png Splash = splash-alpha1.png
Sound = startup.ogg Sound = startup.ogg

View File

@ -63,7 +63,8 @@ void help(void) {
puts(" -s, --startup run in starup mode"); puts(" -s, --startup run in starup mode");
puts(" -n, --no-splash do not show splash screen in starup mode"); puts(" -n, --no-splash do not show splash screen in starup mode");
puts(" -d, --dry-run run in starup mode, but don't execute anything"); puts(" -d, --dry-run run in starup mode, but don't execute anything");
puts(" -a, --autostart read autostart directory"); puts(" -a, --autostart read autostart directory and run all items");
puts(" -u, --autostart-safe read autostart directory and display dialog what will be run");
puts(" -c, --config [FILE] use FILE as config file"); puts(" -c, --config [FILE] use FILE as config file");
puts(" -p, --pid [FILE] use FILE to store PID number"); puts(" -p, --pid [FILE] use FILE to store PID number");
puts(" -l, --log [FILE] log traffic to FILE (FILE can be stdout/stderr for console output)\n"); puts(" -l, --log [FILE] log traffic to FILE (FILE can be stdout/stderr for console output)\n");
@ -74,10 +75,11 @@ int main(int argc, char** argv) {
const char* pid_file = NULL; const char* pid_file = NULL;
const char* log_file = NULL; const char* log_file = NULL;
bool do_startup = 0; bool do_startup = 0;
bool do_dryrun = 0; bool do_dryrun = 0;
bool no_splash = 0; bool no_splash = 0;
bool do_autostart = 0; bool do_autostart = 0;
bool do_autostart_safe = 0;
if(argc > 1) { if(argc > 1) {
const char* a; const char* a;
@ -116,6 +118,8 @@ int main(int argc, char** argv) {
no_splash = 1; no_splash = 1;
else if(CHECK_ARGV(a, "-a", "--autostart")) else if(CHECK_ARGV(a, "-a", "--autostart"))
do_autostart = 1; do_autostart = 1;
else if(CHECK_ARGV(a, "-u", "--autostart-safe"))
do_autostart_safe = 1;
else { else {
printf("Unknown parameter '%s'. Run '"APPNAME" -h' for options\n", a); printf("Unknown parameter '%s'. Run '"APPNAME" -h' for options\n", a);
return 1; return 1;
@ -156,8 +160,8 @@ int main(int argc, char** argv) {
} }
} }
if(do_autostart) { if(do_autostart || do_autostart_safe) {
service->init_autostart(); service->init_autostart(do_autostart_safe);
} }
service->setup_atoms(fl_display); service->setup_atoms(fl_display);