Commit 1a018fa6 authored by Alberto Mardegan's avatar Alberto Mardegan

OSX: add class to open files in desired application

Unfortunately it doesn't look like Qt provides a wrapper for this functionality.
parent ba704317
......@@ -183,6 +183,10 @@ macx {
QMAKE_SUBSTITUTES += $${TOP_SRC_DIR}/data/desktop/ImaginarioInfo.plist.in
QMAKE_INFO_PLIST = $${TOP_BUILD_DIR}/data/desktop/ImaginarioInfo.plist
QT += svg # so that macdeployqt copies the svg plugin
SOURCES += macos.mm
HEADERS += macos.h
LIBS += -framework CoreServices
}
win32 {
......
/*
* Copyright (C) 2019 Alberto Mardegan <mardy@users.sourceforge.net>
*
* This file is part of Imaginario.
*
* Imaginario is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Imaginario is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Imaginario. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef IMAGINARIO_MACOS_H
#define IMAGINARIO_MACOS_H
#include <QList>
#include <QString>
#include <QUrl>
namespace Imaginario {
class MacOS
{
public:
static void runApp(const QString &app, const QList<QUrl> &files);
};
} // namespace
#endif // IMAGINARIO_MACOS_H
/*
* Copyright (C) 2019 Alberto Mardegan <mardy@users.sourceforge.net>
*
* This file is part of Imaginario.
*
* Imaginario is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Imaginario is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Imaginario. If not, see <http://www.gnu.org/licenses/>.
*/
#include "macos.h"
#include <QDebug>
#import <CoreFoundation/CoreFoundation.h>
#import <ApplicationServices/ApplicationServices.h>
namespace Imaginario {
void MacOS::runApp(const QString &app, const QList<QUrl> &files)
{
CFURLRef appUrl = QUrl::fromLocalFile(app).toCFURL();
CFMutableArrayRef cfaFiles =
CFArrayCreateMutable(kCFAllocatorDefault,
files.count(),
&kCFTypeArrayCallBacks);
for (const QUrl &url: files) {
CFURLRef u = url.toCFURL();
CFArrayAppendValue(cfaFiles, u);
CFRelease(u);
}
LSLaunchURLSpec inspec;
inspec.appURL = appUrl;
inspec.itemURLs = cfaFiles;
inspec.asyncRefCon = NULL;
inspec.launchFlags = kLSLaunchDefaults + kLSLaunchAndDisplayErrors;
inspec.passThruParams = NULL;
OSStatus ret;
ret = LSOpenFromURLSpec(&inspec, NULL);
CFRelease(appUrl);
}
} // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment