Changeset View
Changeset View
Standalone View
Standalone View
plugins/qthelp/qthelpexternalassistant_mac.mm
- This file was added.
1 | /* This file is part of KDevelop | ||||
---|---|---|---|---|---|
2 | Copyright 2017 René J.V. Bertin <rjvbertin@gmail.com> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library 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 GNU | ||||
12 | Library General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "qthelpexternalassistant.h" | ||||
21 | | ||||
22 | #include <QString> | ||||
23 | #include <QUrl> | ||||
24 | #include <QStandardPaths> | ||||
25 | #include <QFileInfo> | ||||
26 | | ||||
27 | #include <AppKit/AppKit.h> | ||||
28 | | ||||
29 | #include "debug.h" | ||||
30 | | ||||
31 | using namespace KDevelop; | ||||
32 | | ||||
33 | bool QtHelpExternalAssistant::hasExternalViewer(QString* path) | ||||
34 | { | ||||
35 | bool ret = false; | ||||
36 | QString execPath; | ||||
37 | QFileInfo info; | ||||
38 | | ||||
39 | if (this == s_self ){ | ||||
40 | if (!m_externalViewerExecutable.isEmpty()) { | ||||
41 | execPath = m_externalViewerExecutable; | ||||
42 | info = QFileInfo(execPath); | ||||
43 | if (info.isBundle()) { | ||||
44 | NSString* bundleExec = [[NSBundle bundleWithPath:m_externalViewerExecutable.toNSString()] executablePath]; | ||||
45 | if (bundleExec) { | ||||
46 | execPath = QString::fromNSString(bundleExec); | ||||
47 | info = QFileInfo(execPath); | ||||
48 | qCDebug(QTHELP) << "Found bundle exec" << execPath << "for external viewer" << m_externalViewerExecutable; | ||||
49 | } else { | ||||
50 | qCWarning(QTHELP) << "Could not find the bundle exec for external viewer" << m_externalViewerExecutable; | ||||
51 | } | ||||
52 | } | ||||
53 | if (info.isExecutable()) { | ||||
54 | ret = true; | ||||
55 | } else { | ||||
56 | qCWarning(QTHELP) << "External viewer" << execPath << "is not executable!"; | ||||
57 | } | ||||
58 | // always return the configured executable path | ||||
59 | if (path) { | ||||
60 | *path = execPath; | ||||
61 | } | ||||
62 | } else if (path) { | ||||
63 | // look for the application on the current path. The result is not cached so the | ||||
64 | // lookup is performed only when we can return the result. | ||||
65 | // First try to find a regular executable, which the user could have created | ||||
66 | // to invoke the right Assistant.app | ||||
67 | const QString assistant = QStandardPaths::findExecutable(QLatin1String("assistant")); | ||||
68 | if (!assistant.isEmpty()) { | ||||
69 | ret = true; | ||||
70 | *path = assistant; | ||||
71 | qCDebug(QTHELP) << "External viewer found at" << assistant; | ||||
72 | } else { | ||||
73 | // try to locate a Qt5 Assistant app bundle | ||||
74 | // There is no way to predict which we'll get beyond "probably the same as last time". | ||||
75 | NSString *assistantAppBundle = [[NSWorkspace sharedWorkspace] | ||||
76 | absolutePathForAppBundleWithIdentifier:@"org.qt-project.assistant"]; | ||||
77 | if (!assistantAppBundle) { | ||||
78 | // fall back to finding whatever Assistant.app application might be available. | ||||
79 | assistantAppBundle = [[NSWorkspace sharedWorkspace] fullPathForApplication:@"Assistant.app"]; | ||||
80 | } | ||||
81 | NSString* assistantExec = assistantAppBundle ? [[NSBundle bundleWithPath:assistantAppBundle] executablePath] : nullptr; | ||||
82 | if (assistantExec) { | ||||
83 | execPath = QString::fromNSString(assistantExec); | ||||
84 | ret = true; | ||||
85 | *path = execPath; | ||||
86 | qCDebug(QTHELP) << "Found bundle exec" << execPath << "for Assistant.app" << QString::fromNSString(assistantAppBundle); | ||||
87 | } else { | ||||
88 | qCWarning(QTHELP) << "External viewer not found!"; | ||||
89 | } | ||||
90 | } | ||||
91 | } | ||||
92 | } else { | ||||
93 | return s_self->hasExternalViewer(path); | ||||
94 | } | ||||
95 | return ret; | ||||
96 | } |