Skip to content

Commit c8323b3

Browse files
committed
Do not run .desktop files which has OnlyShowIn/NotShowIn without 'EDE' as key.
1 parent 2299143 commit c8323b3

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

ede-autostart/ede-autostart.cpp

+36-23
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <stdio.h>
2020
#include <unistd.h>
2121
#include <limits.h>
22+
#include <errno.h>
2223

2324
#include <FL/Fl.H>
2425
#include <FL/Fl_Check_Browser.H>
@@ -41,16 +42,18 @@
4142
#include <edelib/Ede.h>
4243

4344
EDELIB_NS_USING_AS(Window, AppWindow)
44-
EDELIB_NS_USING_LIST(15, (String,
45+
EDELIB_NS_USING_LIST(17, (String,
4546
DesktopFile,
4647
IconLoader,
4748
list,
4849
dir_list,
4950
system_config_dirs,
5051
user_config_dir,
5152
str_ends,
53+
str_tolower,
5254
run_async,
5355
ask,
56+
alert,
5457
file_test,
5558
window_center_on_screen,
5659
FILE_TEST_IS_REGULAR,
@@ -135,8 +138,8 @@ static void unique_by_basename(StringList& lst) {
135138
}
136139

137140
static void entry_list_run_clear(DialogEntryList& l, bool run) {
138-
DialogEntryListIter dit = l.begin(), dit_end = l.end();
139-
for(; dit != dit_end; ++dit) {
141+
DialogEntryListIter dit = l.begin(), dite = l.end();
142+
for(; dit != dite; ++dit) {
140143
if(run)
141144
AUTOSTART_RUN((*dit)->exec.c_str());
142145
delete *dit;
@@ -188,8 +191,8 @@ static void run_autostart_dialog(DialogEntryList& l) {
188191
txt->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_WRAP);
189192
cbrowser = new Fl_Check_Browser(10, 75, 350, 185);
190193

191-
DialogEntryListIter it = l.begin(), it_end = l.end();
192-
for(; it != it_end; ++it) {
194+
DialogEntryListIter it = l.begin(), ite = l.end();
195+
for(; it != ite; ++it) {
193196
if((*it)->comment.empty())
194197
cbrowser->add((*it)->name.c_str());
195198
else {
@@ -222,13 +225,13 @@ static void perform_autostart(bool safe) {
222225
adir += AUTOSTART_DIRNAME;
223226

224227
StringList dfiles, sysdirs, tmp;
225-
StringListIter it, it_end, tmp_it, tmp_it_end;
228+
StringListIter it, ite, tmp_it, tmp_ite;
226229

227230
dir_list(adir.c_str(), dfiles, true);
228231

229232
system_config_dirs(sysdirs);
230233
if(!sysdirs.empty()) {
231-
for(it = sysdirs.begin(), it_end = sysdirs.end(); it != it_end; ++it) {
234+
for(it = sysdirs.begin(), ite = sysdirs.end(); it != ite; ++it) {
232235
*it += AUTOSTART_DIRNAME;
233236

234237
/*
@@ -237,22 +240,18 @@ static void perform_autostart(bool safe) {
237240
* probably via merge() member
238241
*/
239242
dir_list((*it).c_str(), tmp, true);
240-
for(tmp_it = tmp.begin(), tmp_it_end = tmp.end(); tmp_it != tmp_it_end; ++tmp_it)
243+
for(tmp_it = tmp.begin(), tmp_ite = tmp.end(); tmp_it != tmp_ite; ++tmp_it)
241244
dfiles.push_back(*tmp_it);
242245
}
243246
}
244247

245-
if(dfiles.empty())
246-
return;
248+
if(dfiles.empty()) return;
247249

248250
/*
249-
* Remove duplicates where first one seen have priority to be keept.
250-
* This way is required by spec.
251+
* Remove duplicates where first one seen have priority to be keept. This way is required by spec.
251252
*
252-
* Also handle this case (noted in spec):
253-
* if $XDG_CONFIG_HOME/autostart/foo.desktop and $XDG_CONFIG_DIRS/autostart/foo.desktop
254-
* exists, but $XDG_CONFIG_HOME/autostart/foo.desktop have 'Hidden = true',
255-
* $XDG_CONFIG_DIRS/autostart/foo.autostart is ignored too.
253+
* Also handle this case (noted in spec): * if $XDG_CONFIG_HOME/autostart/foo.desktop and $XDG_CONFIG_DIRS/autostart/foo.desktop
254+
* exists, but $XDG_CONFIG_HOME/autostart/foo.desktop have 'Hidden = true', * $XDG_CONFIG_DIRS/autostart/foo.autostart is ignored too.
256255
*
257256
* Later is implied via unique_by_basename().
258257
*/
@@ -263,7 +262,7 @@ static void perform_autostart(bool safe) {
263262
DesktopFile df;
264263
DialogEntryList entry_list;
265264

266-
for(it = dfiles.begin(), it_end = dfiles.end(); it != it_end; ++it) {
265+
for(it = dfiles.begin(), ite = dfiles.end(); it != ite; ++it) {
267266
if((*it).empty())
268267
continue;
269268

@@ -276,12 +275,23 @@ static void perform_autostart(bool safe) {
276275
E_WARNING(E_STRLOC ": Can't load '%s'. Skipping...\n", name);
277276
continue;
278277
}
278+
279+
/* obey to OnlyShowIn rule */
280+
if(df.only_show_in(buf, sizeof(buf))) {
281+
str_tolower((unsigned char*)buf);
282+
if(strstr(buf, "ede") == NULL)
283+
continue;
284+
}
285+
286+
/* obey to NotShowIn rule */
287+
if(df.not_show_in(buf, sizeof(buf))) {
288+
str_tolower((unsigned char*)buf);
289+
if(strstr(buf, "ede") != NULL)
290+
continue;
291+
}
279292

280293
/* files marked as hidden must be skipped */
281-
if(df.hidden())
282-
continue;
283-
284-
if(!df.exec(buf, sizeof(buf)))
294+
if(df.hidden() || !df.exec(buf, sizeof(buf)))
285295
continue;
286296

287297
DialogEntry* en = new DialogEntry;
@@ -321,8 +331,11 @@ static void perform_autostart_scripts(const char* dir) {
321331
"Would you like to start them?"), dir))
322332
{
323333
/* spec said how we must chdir to the root of the medium */
324-
chdir(dir);
325-
AUTOSTART_RUN(path);
334+
errno = 0;
335+
if(chdir(dir) == 0)
336+
AUTOSTART_RUN(path);
337+
else
338+
alert(_("Unable to change folder: %s"), strerror(errno));
326339
}
327340

328341
/* we only match the one file */

0 commit comments

Comments
 (0)