2 Copyright (C) 2015-2016 Montel Laurent <montel@kde.org>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU 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.
9 This program 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 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "pimsettingexporter-version.h"
21 #include "pimsettingexporterconsole.h"
22 #include "pimsettingexportconsole_debug.h"
23 #include <kaboutdata.h>
24 #include <KLocalizedString>
26 #include <QCommandLineParser>
27 #include <QCoreApplication>
28 #include <QCommandLineOption>
30 #include <QtCore/qtimer.h>
32 int main(int argc
, char *argv
[])
34 QCoreApplication
app(argc
, argv
);
36 QCommandLineParser parser
;
37 KAboutData
aboutData(QStringLiteral("pimsettingexporterconsole"), i18n("PIM Setting Exporter Console"),
38 QStringLiteral(KDEPIM_VERSION
), i18n("PIM Setting Exporter Console"), KAboutLicense::GPL_V2
,
39 i18n("Copyright © 2015-2016 pimsettingexporter authors"));
40 aboutData
.addAuthor(i18n("Laurent Montel"), i18n("Maintainer"), QStringLiteral("montel@kde.org"));
41 parser
.addVersionOption();
42 parser
.addHelpOption();
43 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("logfile"), i18n("File to log information to."), QStringLiteral("file")));
44 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("template"), i18n("Template file to define what data, settings to import or export."), QStringLiteral("file")));
45 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("import"), i18n("Import the given file."), QStringLiteral("file")));
46 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("export"), i18n("Export the given file."), QStringLiteral("file")));
48 aboutData
.setupCommandLine(&parser
);
50 aboutData
.processCommandLine(&parser
);
54 if (parser
.isSet(QStringLiteral("import"))) {
55 importFile
= parser
.value(QStringLiteral("import"));
56 } else if (parser
.isSet(QStringLiteral("export"))) {
57 exportFile
= parser
.value(QStringLiteral("export"));
59 if (importFile
.isEmpty() && exportFile
.isEmpty()) {
65 if (parser
.isSet(QStringLiteral("template"))) {
66 templateFile
= parser
.value(QStringLiteral("template"));
67 qCDebug(PIMSETTINGEXPORTERCONSOLE_LOG
) << "Template file " << templateFile
;
69 if (parser
.isSet(QStringLiteral("logfile"))) {
70 logFile
= parser
.value(QStringLiteral("logfile"));
71 qCDebug(PIMSETTINGEXPORTERCONSOLE_LOG
) << "Log file " << logFile
;
74 PimSettingExporterConsole
*console
= new PimSettingExporterConsole
;
75 if (!importFile
.isEmpty()) {
76 console
->setMode(PimSettingExporterConsole::Import
);
77 qCDebug(PIMSETTINGEXPORTERCONSOLE_LOG
) << "Import Mode" << importFile
;
78 console
->setImportExportFileName(importFile
);
79 } else if (!exportFile
.isEmpty()) {
80 console
->setMode(PimSettingExporterConsole::Export
);
81 qCDebug(PIMSETTINGEXPORTERCONSOLE_LOG
) << "Export Mode" << exportFile
;
82 console
->setImportExportFileName(exportFile
);
84 if (!logFile
.isEmpty()) {
85 console
->setLogFileName(logFile
);
87 if (!templateFile
.isEmpty()) {
88 console
->setTemplateFileName(templateFile
);
90 QObject::connect(console
, &PimSettingExporterConsole::finished
, &app
, &QCoreApplication::quit
);
91 QTimer::singleShot(0, console
, &PimSettingExporterConsole::start
);