1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2000, 2006 David Faure <faure@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6*/
7
8#include "keditbookmarks_p.h"
9
10#include <QGuiApplication>
11#include <QObject>
12#include <QProcess>
13#include <QStandardPaths>
14
15#include "kbookmarksettings_p.h"
16
17void KEditBookmarks::setBrowserMode(bool browserMode)
18{
19 m_browserMode = browserMode;
20}
21
22KEditBookmarks::OpenResult KEditBookmarks::openForFile(const QString &file)
23{
24 QStringList args;
25 args << QStringLiteral("--customcaption") << QGuiApplication::applicationDisplayName();
26
27 if (!m_browserMode) {
28 args << QStringLiteral("--nobrowser");
29 }
30
31 args << file;
32 return startKEditBookmarks(args);
33}
34
35KEditBookmarks::OpenResult KEditBookmarks::openForFileAtAddress(const QString &file, const QString &address)
36{
37 QStringList args;
38 args << QStringLiteral("--customcaption") << QGuiApplication::applicationDisplayName();
39
40 if (!m_browserMode) {
41 args << QStringLiteral("--nobrowser");
42 }
43
44 args << QStringLiteral("--address") << address;
45
46 args << file;
47 return startKEditBookmarks(args);
48}
49
50KEditBookmarks::OpenResult KEditBookmarks::startKEditBookmarks(const QStringList &args)
51{
52 const QString exec = QStandardPaths::findExecutable(QStringLiteral(KEDITBOOKMARKS_BINARY));
53 if (!exec.isEmpty()) {
54 bool success = QProcess::startDetached(program: exec, arguments: args);
55
56 if (!success) {
57 OpenResult result;
58 result.m_sucess = false;
59 result.m_errorMessage = QObject::tr(s: "keditbookmarks could not be started");
60 return result;
61 }
62
63 } else {
64 OpenResult result;
65 result.m_sucess = false;
66 result.m_errorMessage = QObject::tr(s: "The keditbookmarks executable was not found");
67 return result;
68 }
69
70 OpenResult result;
71 result.m_sucess = true;
72 return result;
73}
74

source code of kbookmarks/src/keditbookmarks.cpp