File indexing completed on 2024-04-21 04:18:48
0001 /* 0002 Gwenview: an image viewer 0003 Copyright 2000-2009 Aurélien Gâteau <agateau@kde.org> 0004 0005 This program is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU General Public License 0007 as published by the Free Software Foundation; either version 2 0008 of the License, or (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU General Public License for more details. 0014 0015 You should have received a copy of the GNU General Public License 0016 along with this program; if not, write to the Free Software 0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0018 0019 */ 0020 // Qt 0021 #include <QApplication> 0022 #include <QCommandLineParser> 0023 #include <QDir> 0024 #include <QScopedPointer> 0025 #include <QUrl> 0026 0027 // KF 0028 #include <KAboutData> 0029 #include <KLocalizedString> 0030 0031 // Local 0032 #include "gwenview_importer_debug.h" 0033 #include "importdialog.h" 0034 #include <lib/about.h> 0035 0036 int main(int argc, char *argv[]) 0037 { 0038 KLocalizedString::setApplicationDomain("gwenview"); 0039 QApplication app(argc, argv); 0040 QScopedPointer<KAboutData> aboutData(Gwenview::createAboutData(QStringLiteral("gwenview_importer"), /* component name */ 0041 i18n("Gwenview Importer") /* programName */ 0042 )); 0043 aboutData->setShortDescription(i18n("Photo Importer")); 0044 0045 KAboutData::setApplicationData(*aboutData); 0046 0047 QCommandLineParser parser; 0048 aboutData.data()->setupCommandLine(&parser); 0049 parser.addOption( 0050 QCommandLineOption(QStringLiteral("udi"), i18n("The device UDI, used to retrieve information about the device (name, icon...)"), i18n("Device UDI"))); 0051 parser.addPositionalArgument(QStringLiteral("folder"), i18n("Source folder")); 0052 parser.process(app); 0053 aboutData.data()->processCommandLine(&parser); 0054 0055 if (parser.positionalArguments().isEmpty()) { 0056 qCWarning(GWENVIEW_IMPORTER_LOG) << i18n("Missing required source folder argument."); 0057 parser.showHelp(); 0058 } 0059 if (parser.positionalArguments().count() > 1) { 0060 qCWarning(GWENVIEW_IMPORTER_LOG) << i18n("Too many arguments."); 0061 parser.showHelp(); 0062 } 0063 const QString urlString = parser.positionalArguments().constFirst(); 0064 const QUrl url = QUrl::fromUserInput(urlString, QDir::currentPath(), QUrl::AssumeLocalFile); 0065 if (!url.isValid()) { 0066 qCCritical(GWENVIEW_IMPORTER_LOG) << i18n("Invalid source folder."); 0067 return 1; 0068 } 0069 const QString deviceUdi = parser.isSet(QStringLiteral("udi")) ? parser.value(QStringLiteral("udi")) : QString(); 0070 0071 auto dialog = new Gwenview::ImportDialog(); 0072 dialog->show(); 0073 QMetaObject::invokeMethod( 0074 dialog, 0075 [dialog, url, deviceUdi]() { 0076 dialog->setSourceUrl(url, deviceUdi); 0077 }, 0078 Qt::QueuedConnection); 0079 return app.exec(); 0080 }