44 #include <QtCore/QCoreApplication>
45 #include <QtCore/QProcess>
46 #include <QtCore/QHash>
47 #include <QtCore/QDebug>
48 #include <QtCore/QBool>
49 #include <QtCore/QFile>
50 #include <QtDBus/QtDBus>
71 bool insidequote =
false;
73 for (
int index=0; index<aStr.length(); index++) {
76 switch (aStr[index].toLatin1()) {
78 if (commentlevel == 0)
79 insidequote = !insidequote;
100 if (!insidequote && (commentlevel == 0)) {
101 addr = aStr.mid(addrstart, index-addrstart);
103 list += addr.simplified();
110 if (!insidequote && (commentlevel == 0)) {
111 addr = aStr.mid(addrstart, aStr.length()-addrstart);
113 list += addr.simplified();
127 typedef bool (*Ptr_hildon_uri_open)(
const char *,
void *,
void **);
128 static Ptr_hildon_uri_open hildon_uri_open = 0;
130 if (!hildon_uri_open) {
131 QLibrary lib(QLatin1String(
"libhildonmime"), 0, 0);
132 hildon_uri_open = (Ptr_hildon_uri_open)lib.resolve(
"hildon_uri_open");
135 return hildon_uri_open(url.toEncoded().constData(), 0, 0);
143 const QByteArray& startup_id )
145 if (!isMainThreadActive())
151 QString group = defaultsGrp.readEntry(
"Profile",
"Default");
154 QString command = profileGrp.readPathEntry(
"EmailClient",
QString());
157 if (command.isEmpty() || command == QLatin1String(
"kmail")
158 || command.endsWith(QLatin1String(
"/kmail")))
160 command = QLatin1String(
"kmail --composer -s %s -c %c -b %b --body %B --attach %A -- %t");
161 if ( !_to.isEmpty() )
166 to = QString::fromLatin1(url.toEncoded());
168 if ( !_cc.isEmpty() )
173 cc = QString::fromLatin1(url.toEncoded());
175 if ( !_bcc.isEmpty() )
180 bcc = QString::fromLatin1(url.toEncoded());
186 if( !command.contains( QLatin1Char(
'%') ))
187 command += QLatin1String(
" %u");
190 if (profileGrp.readEntry(
"TerminalClient",
false))
193 QString preferredTerminal = confGroup.readPathEntry(
"TerminalApplication", QString::fromLatin1(
"konsole"));
194 command = preferredTerminal + QString::fromLatin1(
" -e ") + command;
198 QString cmd = cmdTokens.takeFirst();
206 tos.erase( tos.begin() );
207 for (QStringList::ConstIterator it = tos.constBegin(); it != tos.constEnd(); ++it)
212 for (QStringList::ConstIterator it = ccs.constBegin(); it != ccs.constEnd(); ++it)
216 for (QStringList::ConstIterator it = bccs.constBegin(); it != bccs.constEnd(); ++it)
219 for (QStringList::ConstIterator it = attachURLs.constBegin(); it != attachURLs.constEnd(); ++it)
222 if (!subject.isEmpty())
223 url.
addQueryItem(QString::fromLatin1(
"subject"), subject);
230 if ( ! (to.isEmpty() && (!url.hasQuery())) )
234 keyMap.insert(QLatin1Char(
't'), to);
235 keyMap.insert(QLatin1Char(
's'), subject);
236 keyMap.insert(QLatin1Char(
'c'), cc);
237 keyMap.insert(QLatin1Char(
'b'), bcc);
238 keyMap.insert(QLatin1Char(
'B'), body);
239 keyMap.insert(QLatin1Char(
'u'), url.
url());
241 QString attachlist = attachURLs.join(QString::fromLatin1(
","));
242 attachlist.prepend(QLatin1Char(
'\''));
243 attachlist.append(QLatin1Char(
'\''));
244 keyMap.insert(QLatin1Char(
'A'), attachlist);
246 for (QStringList::Iterator it = cmdTokens.begin(); it != cmdTokens.end(); )
248 if (*it == QLatin1String(
"%A"))
250 if (it == cmdTokens.begin())
252 QStringList::ConstIterator urlit = attachURLs.begin();
253 QStringList::ConstIterator urlend = attachURLs.end();
254 if ( urlit != urlend )
256 QStringList::Iterator previt = it;
260 while ( ++urlit != urlend )
262 cmdTokens.insert( it, *previt );
263 cmdTokens.insert( it, *urlit );
267 it = cmdTokens.erase( cmdTokens.erase( it ) );
278 if (
kdeinitExec(cmd, cmdTokens, &error, NULL, startup_id ))
281 i18n(
"Could not launch the mail client:\n\n%1", error),
282 i18n(
"Could not launch Mail Client"));
288 if (!isMainThreadActive())
310 if (qgetenv(
"KDE_FULL_SESSION").isEmpty()) {
318 if (!browserApp.isEmpty()) {
320 if (exe.startsWith(QLatin1Char(
'!'))) {
323 exe = cmdTokens.takeFirst();
324 args = cmdTokens + args;
329 kDebug() <<
"Starting service" << service->entryPath();
331 &error, 0, 0, startup_id)) {
334 i18n(
"Could not launch the browser:\n\n%1", error),
335 i18n(
"Could not launch Browser"));
349 QString entryPath = htmlApp->entryPath();
350 if (entryPath.endsWith(QLatin1String(
"kfmclient_html.desktop"))) {
351 entryPath.remove(entryPath.length()-13, 5);
359 i18n(
"Could not launch the browser:\n\n%1", error),
360 i18n(
"Could not launch Browser"));
371 exe = QString::fromLatin1(
"kde-open");
374 kDebug(180) <<
"Using" << exe <<
"to open" << url;
375 if (
kdeinitExec(exe, args, &error, NULL, startup_id ))
379 i18n(
"Could not launch the browser:\n\n%1", error),
380 i18n(
"Could not launch Browser"));
386 const QByteArray &startup_id)
388 if (!isMainThreadActive()) {
393 QString exec = confGroup.readPathEntry(
"TerminalApplication", QString::fromLatin1(
"konsole"));
395 if (!command.isEmpty()) {
396 if (exec == QLatin1String(
"konsole")) {
397 exec += QString::fromLatin1(
" --noclose");
398 }
else if (exec == QLatin1String(
"xterm")) {
399 exec += QString::fromLatin1(
" -hold");
402 exec += QString::fromLatin1(
" -e ") + command;
406 QString cmd = cmdTokens.takeFirst();
408 if (exec == QLatin1String(
"konsole") && !workdir.isEmpty()) {
409 cmdTokens << QString::fromLatin1(
"--workdir");
410 cmdTokens << workdir;
416 if (
self()->startServiceInternal(
"kdeinit_exec_with_workdir",
417 cmd, cmdTokens, &error, 0, NULL, startup_id,
false, workdir)) {
419 i18n(
"Could not launch the terminal client:\n\n%1", error),
420 i18n(
"Could not launch Terminal Client"));