1
/* Joe's Window Manager Configuration
3
* This program configures JWM using pugixml and FLTK
5
* Copyright (C) 2016 Israel <israeldahl@gmail.com>
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
* This has been developed as a part of the ToriOS Project
21
* You may redistribute this, but you must keep this comment in place
22
* Jesus is my Lord, and if you don't like it feel free to ignore it.
25
#include "../include/autostart.hpp"
26
int JSM_Autostart::desktopFileEdit(Fl_Browser* o){
27
const char* line=o->text(o->value());
28
if(line==NULL) return 1;
29
std::string temp=line;
30
std::string casa=linuxcommon::home_path();
31
std::string desktopeditor=linuxcommon::term_out("which desktop-file-editor");
32
if(desktopeditor.compare("")!=0){
35
if(temp.find(casa)>temp.length()){
36
std::string pkexec=linuxcommon::term_out("which pkexec");
37
if(pkexec.compare("")==0) pkexec=linuxcommon::term_out("which gksudo");
38
if(pkexec.compare("")==0) pkexec=linuxcommon::term_out("which gksu");
39
if(pkexec.compare("")==0) pkexec=linuxcommon::term_out("which sudo");
40
if(pkexec.compare("")!=0) desktopeditor= pkexec + " " +desktopeditor ;
42
int sys=system(desktopeditor.c_str());
43
if(sys!=0){debug_out(desktopeditor+" did not work");}
46
else{debug_out("Desktop File editor was not found!");}
49
int JSM_Autostart::desktopFileEdit(std::string line){
50
debug_out("int desktopFileEdit(const char* "+line+")");
51
if(line.compare("")==0) return 1;
52
std::string temp=line;
53
std::string casa=linuxcommon::home_path();
54
std::string desktopeditor=linuxcommon::term_out("which desktop-file-editor");
55
if(desktopeditor.compare("")!=0){
58
if(temp.find(casa)>temp.length()){
59
std::string pkexec=linuxcommon::term_out("which pkexec");
60
if(pkexec.compare("")==0) pkexec=linuxcommon::term_out("which gksudo");
61
if(pkexec.compare("")==0) pkexec=linuxcommon::term_out("which gksu");
62
if(pkexec.compare("")==0) pkexec=linuxcommon::term_out("which sudo");
63
if(pkexec.compare("")!=0) desktopeditor= pkexec + " " +desktopeditor ;
65
int sys=system(desktopeditor.c_str());
66
if(sys!=0){debug_out(desktopeditor+" did not work");}
69
else{debug_out("Desktop File editor was not found!");}
72
void JSM_Autostart::add_program_to_autostart(Fl_Browser *o,std::string input) {
74
bool tryADD=addElementWithText("StartupCommand",input);
75
if(!tryADD){errorOUT("ADDING StartupCommand->"+input+" FAILED");return;}
76
if(!linuxcommon::program_is_running(input)){linuxcommon::run_a_program_in_background(input);}
77
if((loadTemp())&&(saveNoRestart())){
79
populateFLBrowser(o,"StartupCommand");
82
else{errorOUT("Couldn't save the file correctly");}
84
void JSM_Autostart::remove_program_from_autostart(Fl_Browser *o) {
85
int item = o->value();
86
if( (item<1) && (item > o->size()) ){std::cerr<<"Please click on an item to remove!"<<std::endl;}
88
if( (deleteSubElement("StartupCommand",item)) && (saveNoRestart()) ){
91
populateFLBrowser(o,"StartupCommand");
94
else{std::cerr<<"Couldn't save the file correctly"<<std::endl;}
97
void JSM_Autostart::remove_program_from_xdg_autostart(Fl_Browser* o){
98
debug_out("void remove_program_from_xdg_autostart(Fl_Browser* o)");
99
const char* item=o->text(o->value());
101
debug_out("could not get the current value from the browser sent in");
104
int retval=desktopFileEdit(o);
105
if(retval!=0){debug_out("FAILED to edit the desktop file");}
107
std::string file=item;
111
const char* DE=getenv("DESKTOP_SESSION");
112
const char* xdgDE=getenv("XDG_SESSION_DESKTOP");
113
const char* xdgCurrentDE=getenv("XDG_CURRENT_DESKTOP");
114
std::string JWM="JWM";
115
std::string ONLY=linuxcommon::get_line_with_equal(file,"OnlyShowIn=");
116
std::string NOT=linuxcommon::get_line_with_equal(file,"NotShowIn=");
117
debug_out("File="+file+"\nOnlyShowIn="+ONLY+"\nNotShowIn="+NOT);
119
if(ONLY.find(DE)<ONLY.length()){findONLY=true;}
120
else{if(ONLY.compare("")!=0){findDE=true;}}
121
if(NOT.find(DE)<NOT.length()){findNOT=true;}
122
removeXDGautostart(findNOT,findONLY,findDE,file,DE);
126
if(ONLY.find(xdgDE)<ONLY.length()){findONLY=true;}
127
else{if(ONLY.compare("")!=0){findDE=true;}}
128
if(NOT.find(xdgDE)<NOT.length()){findNOT=true;}
129
removeXDGautostart(findNOT,findONLY,findDE,file,xdgDE);
131
if(xdgCurrentDE!=NULL){
132
if(ONLY.find(xdgCurrentDE)<ONLY.length()){findONLY=true;}
133
else{if(ONLY.compare("")!=0){findDE=true;}}
134
if(NOT.find(xdgCurrentDE)<NOT.length()){findNOT=true;}
135
removeXDGautostart(findNOT,findONLY,findDE,file,xdgCurrentDE);
137
if(ONLY.find(JWM)<ONLY.length()){ONLY=true;}
138
else{if(ONLY.compare("")!=0){findDE=true;}}
139
if(NOT.find(JWM)<NOT.length()){NOT=true;}
140
removeXDGautostart(findNOT,findONLY,findDE,file,JWM);