File indexing completed on 2025-01-05 03:58:08
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2021-02-04 0007 * Description : a command line tool to open file with the default 0008 * MacOS apllication bundle. 0009 * 0010 * SPDX-FileCopyrightText: 2021-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 // Qt includes 0017 0018 #include <QString> 0019 #include <QUrl> 0020 #include <QList> 0021 #include <QFileInfo> 0022 0023 // Local includes 0024 0025 #include "digikam_debug.h" 0026 #include "dservicemenu.h" 0027 0028 using namespace Digikam; 0029 0030 int main(int argc, char** argv) 0031 { 0032 if (argc != 2) 0033 { 0034 qCDebug(DIGIKAM_TESTS_LOG) << "openfilewithapplication - Open file with default MacOS bundle Application"; 0035 qCDebug(DIGIKAM_TESTS_LOG) << "Usage: <file path>"; 0036 return -1; 0037 } 0038 0039 QString fname = QString::fromUtf8(argv[1]); 0040 QString suffix = QFileInfo(fname).suffix(); 0041 QList<QUrl> list = DServiceMenu::MacApplicationForFileExtension(suffix); 0042 0043 if (list.isEmpty()) 0044 { 0045 qCDebug(DIGIKAM_TESTS_LOG) << "No application found to open" << fname; 0046 return -1; 0047 } 0048 0049 QUrl appUrl = list.first(); 0050 QUrl fileUrl = QUrl::fromLocalFile(fname); 0051 0052 bool ret = DServiceMenu::MacOpenFilesWithApplication(QList<QUrl>() << fileUrl, appUrl); 0053 0054 if (!ret) 0055 { 0056 qCDebug(DIGIKAM_TESTS_LOG) << "Cannot start application" << DServiceMenu::MacApplicationBundleName(appUrl) << "to open" << fname; 0057 return -1; 0058 } 0059 0060 qCDebug(DIGIKAM_TESTS_LOG) << "Application" << DServiceMenu::MacApplicationBundleName(appUrl) << "started to open" << fname; 0061 0062 return 0; 0063 }