Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
486 andreas 1
/*
2
 * Copyright (C) 2025 by Andreas Theofilu <andreas@theosys.at>
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
19
#include <cstring>
20
#include <unistd.h>
21
 
22
#include "tlauncher.h"
23
#include "terror.h"
24
 
25
#if __cplusplus < 201402L
26
#   error "This module requires at least C++14 standard!"
27
#else
28
#   if __cplusplus < 201703L
29
#       include <experimental/filesystem>
30
namespace fs = std::experimental::filesystem;
31
#       warning "Support for C++14 and experimental filesystem will be removed in a future version!"
32
#   else
33
#       include <filesystem>
34
#       ifdef __ANDROID__
35
namespace fs = std::__fs::filesystem;
36
#       else
37
namespace fs = std::filesystem;
38
#       endif
39
#   endif
40
#endif
41
 
42
using std::string;
43
using std::vector;
44
 
45
bool TLauncher::mInitialized{false};
46
vector<APPDEF_t> TLauncher::APPS;
47
 
48
bool TLauncher::launch(const string& name)
49
{
50
    DECL_TRACER("TLauncher::launch(const string& name)");
51
 
52
    if (name.empty())
53
        return false;
54
 
55
    initialize();
56
 
57
    if (APPS.empty())
58
    {
59
        MSG_WARNING("No application found for " << name << "!");
60
        return false;
61
    }
62
 
63
    vector<APPDEF_t>::iterator iter;
64
    bool started = false;
65
 
66
    for (iter = APPS.begin(); iter != APPS.end(); ++iter)
67
    {
68
        if (iter->name == name)
69
        {
70
            string p = "/usr/bin/";
71
            string exe, prg;
72
            vector<string>::iterator pgIter;
73
 
74
            for (pgIter = iter->executeables.begin(); pgIter != iter->executeables.end(); ++pgIter)
75
            {
76
                string p = "/usr/bin/";
77
                string exe;
78
 
79
                if (fs::exists(p + *pgIter))
80
                {
81
                    exe = p + *pgIter;
82
                    pid_t pid;
83
                    started = true;
84
 
85
                    if (0 == (pid = fork()))
86
                    {
87
                        if (-1 == execl(exe.c_str(), pgIter->c_str(), (char *)NULL))
88
                        {
89
                            MSG_ERROR("Child process execl failed: " << strerror(errno));
90
                            return -1;
91
                        }
92
                    }
93
 
94
                    break;
95
                }
96
            }
97
 
98
            break;
99
        }
100
    }
101
 
102
    if (!started)
103
    {
104
        MSG_WARNING("No application found for " << name << "!");
105
    }
106
 
107
    return started;
108
}
109
 
110
void TLauncher::initialize()
111
{
112
    DECL_TRACER("TLauncher::initialize()");
113
#ifdef __linux__
114
    if (mInitialized)
115
        return;
116
 
117
    APPDEF_t a;
118
 
119
    a.name = "PDF Viewer";
120
    a.executeables.push_back("okular"),
121
    a.executeables.push_back("evince");
122
    APPS.push_back(a);
123
    a.executeables.clear();
124
 
125
    a.name = "Browser";
126
    a.executeables.push_back("firefox");
127
    a.executeables.push_back("chromium");
128
    a.executeables.push_back("konqueror");
129
    APPS.push_back(a);
130
    a.executeables.clear();
131
 
132
    a.name = "Calculator";
133
    a.executeables.push_back("kcalc");
134
    a.executeables.push_back("gnome-calculator");
135
    a.executeables.push_back("xcalc");
136
    APPS.push_back(a);
137
    a.executeables.clear();
138
 
139
    a.name = "Calendar";
140
    a.executeables.push_back("korganizer");
141
    a.executeables.push_back("calindori");
142
    a.executeables.push_back("gnome-calendar");
143
    a.executeables.push_back("evolution");
144
    APPS.push_back(a);
145
    a.executeables.clear();
146
 
147
    a.name = "Contacts";
148
    a.executeables.push_back("kaddressbook");
149
    a.executeables.push_back("gnome-contacts");
150
    APPS.push_back(a);
151
    a.executeables.clear();
152
 
153
    a.name = "Email";
154
    a.executeables.push_back("kmail");
155
    a.executeables.push_back("balsa");
156
    APPS.push_back(a);
157
    a.executeables.clear();
158
 
159
    a.name = "FileBrowser";
160
    a.executeables.push_back("dolphin");
161
    a.executeables.push_back("nautilus");
162
    APPS.push_back(a);
163
    a.executeables.clear();
164
 
165
    mInitialized = true;
166
#endif
167
}