~israeldahl/jwm-settings-manager/trunk

« back to all changes in this revision

Viewing changes to src/autostart.cpp

  • Committer: Israel Dahl
  • Date: 2014-07-06 02:48:28 UTC
  • Revision ID: israeldahl@gmail.com-20140706024828-1bt17riyy2ep06bt
actually added the themes, buttons, etc...
* Alpha Version update
 * Desktop
 - Added Rox checkers, and getters and setters, but haven't finished/enabled it
 - Finished gradient support
 - finished Single color support
 - moved the image setting code to flDesktop(h/cpp)
 * Window
 - fixed Window icon code to reliably open the directory containing icons
 - added 'BoxShaped' window buttons

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*                 Joe's Window Manager Configuration
2
 
 *
3
 
 * This program configures JWM using pugixml and FLTK
4
 
 *
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.
10
 
 * 
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.
15
 
 *
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
19
 
 *
20
 
 *
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.
23
 
 */
24
 
#include <libintl.h>
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){
33
 
                desktopeditor+=" ";
34
 
                desktopeditor+=temp;
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 ;
41
 
                }
42
 
                int sys=system(desktopeditor.c_str());
43
 
                if(sys!=0){debug_out(desktopeditor+" did not work");}
44
 
                return sys;
45
 
        }
46
 
        else{debug_out("Desktop File editor was not found!");}
47
 
        return -1;
48
 
}
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){
56
 
                desktopeditor+=" ";
57
 
                desktopeditor+=temp;
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 ;
64
 
                }
65
 
                int sys=system(desktopeditor.c_str());
66
 
                if(sys!=0){debug_out(desktopeditor+" did not work");}
67
 
                return sys;
68
 
        }
69
 
        else{debug_out("Desktop File editor was not found!");}
70
 
        return -1;
71
 
}
72
 
void JSM_Autostart::add_program_to_autostart(Fl_Browser *o,std::string input) {
73
 
        o->clear();
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())){
78
 
                load();
79
 
                populateFLBrowser(o,"StartupCommand");
80
 
                o->redraw();
81
 
        }
82
 
        else{errorOUT("Couldn't save the file correctly");}
83
 
}
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;}
87
 
        else{
88
 
                if( (deleteSubElement("StartupCommand",item)) && (saveNoRestart()) ){
89
 
                        o->clear();
90
 
                        load();
91
 
                        populateFLBrowser(o,"StartupCommand");
92
 
                        o->redraw();
93
 
                }
94
 
                else{std::cerr<<"Couldn't save the file correctly"<<std::endl;}
95
 
        }
96
 
}
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());
100
 
        if(item==NULL){
101
 
                debug_out("could not get the current value from the browser sent in");
102
 
                return;
103
 
        }
104
 
        int retval=desktopFileEdit(o);
105
 
        if(retval!=0){debug_out("FAILED to edit the desktop file");}
106
 
        return;
107
 
        std::string file=item;
108
 
        bool findDE=false;
109
 
        bool findONLY=false;
110
 
        bool findNOT=false;
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);
118
 
        if(DE!=NULL){
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);
123
 
        }
124
 
        
125
 
        if(xdgDE!=NULL){
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);
130
 
        }
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);
136
 
        }
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);
141
 
        
142
 
}