1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
/*
* libqtxdg - An Qt implementation of freedesktop.org xdg specs
* Copyright (C) 2016 Luís Pereira <luis.artur.pereira@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QFileInfo>
#include <XdgDesktopFile>
#include <iostream>
static void printErr(const QString & out)
{
std::cerr << qPrintable(out);
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName(QLatin1String("qtxdg-desktop-file-start"));
QCoreApplication::setApplicationVersion(QLatin1String(QTXDG_VERSION));
QCommandLineParser parser;
parser.setApplicationDescription(QLatin1String("QtXdg XdgDesktopFile start Tester"));
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument(QLatin1String("file [urls...]"), QLatin1String("desktop file to start and its urls"),QLatin1String("file [urls...]"));
parser.process(app);
if (parser.positionalArguments().isEmpty()) {
parser.showHelp(EXIT_FAILURE);
}
QStringList userArgs = parser.positionalArguments();
const QString userFileName = userArgs.takeFirst();
const QFileInfo fileInfo(userFileName);
if (fileInfo.isAbsolute()) {
if (!fileInfo.exists()) {
printErr(QString::fromLatin1("File %1 does not exist\n").arg(userFileName));
return EXIT_FAILURE;
}
}
XdgDesktopFile f;
const bool valid = f.load(userFileName);
if (valid) {
f.startDetached(userArgs);
} else {
printErr(QString::fromLatin1("%1 doesn't exist or isn't a valid .desktop file\n").arg(userFileName));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
|