Messagelib

openurlwithjob.cpp
1/*
2 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "openurlwithjob.h"
8#include "messageviewer_debug.h"
9#include <KIO/CommandLauncherJob>
10#include <KMacroExpander>
11#include <KNotificationJobUiDelegate>
12#include <KShell>
13using namespace MessageViewer;
14OpenUrlWithJob::OpenUrlWithJob(QObject *parent)
15 : QObject{parent}
16{
17}
18
19OpenUrlWithJob::~OpenUrlWithJob() = default;
20
21bool OpenUrlWithJob::canStart() const
22{
23 return mInfo.isValid() && !mUrl.isEmpty();
24}
25
26void OpenUrlWithJob::start()
27{
28 if (!canStart()) {
30 qCWarning(MESSAGEVIEWER_LOG) << " Impossible to start OpenUrlWithJob";
31 return;
32 }
34 map.insert(QLatin1Char('u'), mUrl.toString());
35
36 const QString commandLine = mInfo.commandLine();
37 const QString cmd = KMacroExpander::expandMacrosShellQuote(commandLine, map);
39 // qDebug() << " cmd " << cmd << " arg " << arg << " mInfo.command() " << mInfo.command();
40 auto job = new KIO::CommandLauncherJob(mInfo.command(), QStringList() << arg);
42 job->start();
44}
45
46const OpenWithUrlInfo &OpenUrlWithJob::info() const
47{
48 return mInfo;
49}
50
51void OpenUrlWithJob::setInfo(const OpenWithUrlInfo &newInfo)
52{
53 mInfo = newInfo;
54}
55
56void OpenUrlWithJob::setUrl(const QUrl &url)
57{
58 mUrl = url;
59}
60
61#include "moc_openurlwithjob.cpp"
The OpenWithUrlInfo class.
QString expandMacrosShellQuote(const QString &str, const QHash< QChar, QString > &map, QChar c=QLatin1Char('%'))
KCOREADDONS_EXPORT QStringList splitArgs(const QString &cmd, Options flags=NoOptions, Errors *err=nullptr)
void deleteLater()
T qobject_cast(QObject *object)
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
bool isEmpty() const const
QString toString(FormattingOptions options) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:12:43 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.