Commit 3f3ffba2 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Avoid to create two parser.

Idea from David. Thanks
parent 2d331622
......@@ -18,14 +18,12 @@
#include "pimsettingexporterwindow.h"
#include "pimsettingcommandlineoption.h"
#include <kaboutdata.h>
#include <KLocalizedString>
#include <KDBusService>
#include "pimsettingexport_debug.h"
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QApplication>
#include "kdepim-version.h"
#include <kdelibs4configmigrator.h>
int main(int argc, char *argv[])
......@@ -37,26 +35,19 @@ int main(int argc, char *argv[])
migrate.setUiFiles(QStringList() << QStringLiteral("pimsettingexporter.rc"));
migrate.migrate();
KLocalizedString::setApplicationDomain("pimsettingexporter");
KAboutData aboutData(QStringLiteral("pimsettingexporter"), i18n("PIM Setting Exporter"),
QStringLiteral(KDEPIM_VERSION), i18n("PIM Setting Exporter"), KAboutLicense::GPL_V2,
i18n("Copyright © 2012-2015 pimsettingexporter authors"));
aboutData.addAuthor(i18n("Laurent Montel"), i18n("Maintainer"), QStringLiteral("montel@kde.org"));
QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("kontact")));
PimSettingCommandLineOption parser;
KAboutData::setApplicationData(aboutData);
aboutData.setupCommandLine(&parser);
parser.process(app);
aboutData.processCommandLine(&parser);
PimSettingCommandLineOption parser;
parser.createParser(app);
KDBusService service(KDBusService::Unique);
PimSettingExporterWindow *backupMailWin = new PimSettingExporterWindow();
parser.setExportWindow(backupMailWin);
QObject::connect(&service, SIGNAL(activateRequested(QStringList,QString)),
backupMailWin, SLOT(slotActivateRequested(QStringList,QString)));
&parser, SLOT(slotActivateRequested(QStringList,QString)));
backupMailWin->show();
backupMailWin->handleCommandLine(parser);
parser.handleCommandLine();
return app.exec();
}
......@@ -17,16 +17,63 @@
#include "pimsettingcommandlineoption.h"
#include "pimsettingexporterwindow.h"
#include "kdepim-version.h"
#include <KLocalizedString>
#include <KAboutData>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QApplication>
#include <QDebug>
PimSettingCommandLineOption::PimSettingCommandLineOption()
: QCommandLineParser()
PimSettingCommandLineOption::PimSettingCommandLineOption(QObject *parent)
: QObject(parent),
mExporterWindow(Q_NULLPTR)
{
addVersionOption();
addHelpOption();
addOption(QCommandLineOption(QStringList() << QStringLiteral("template"), i18n("Template file uses to define what data, settings to import or export"), QStringLiteral("file")));
addOption(QCommandLineOption(QStringList() << QStringLiteral("import"), i18n("Import the given file")));
addOption(QCommandLineOption(QStringList() << QStringLiteral("export"), i18n("Export the given file")));
addOption(QCommandLineOption(QStringList() << QStringLiteral("+[url]"), i18n("File or url. The user will be asked whether to import or export.")));
}
PimSettingCommandLineOption::~PimSettingCommandLineOption()
{
}
void PimSettingCommandLineOption::slotActivateRequested(const QStringList &arguments,const QString &workingDirectory)
{
if (mParser.parse(arguments)) {
handleCommandLine();
} else {
qDebug()<<" ";
}
}
void PimSettingCommandLineOption::createParser(const QApplication &app)
{
KAboutData aboutData(QStringLiteral("pimsettingexporter"), i18n("PIM Setting Exporter"),
QStringLiteral(KDEPIM_VERSION), i18n("PIM Setting Exporter"), KAboutLicense::GPL_V2,
i18n("Copyright © 2012-2015 pimsettingexporter authors"));
aboutData.addAuthor(i18n("Laurent Montel"), i18n("Maintainer"), QStringLiteral("montel@kde.org"));
mParser.addVersionOption();
mParser.addHelpOption();
mParser.addOption(QCommandLineOption(QStringList() << QStringLiteral("template"), i18n("Template file uses to define what data, settings to import or export"), QStringLiteral("file")));
mParser.addOption(QCommandLineOption(QStringList() << QStringLiteral("import"), i18n("Import the given file")));
mParser.addOption(QCommandLineOption(QStringList() << QStringLiteral("export"), i18n("Export the given file")));
mParser.addOption(QCommandLineOption(QStringList() << QStringLiteral("+[url]"), i18n("File or url. The user will be asked whether to import or export.")));
KAboutData::setApplicationData(aboutData);
aboutData.setupCommandLine(&mParser);
mParser.process(app);
aboutData.processCommandLine(&mParser);
}
void PimSettingCommandLineOption::setExportWindow(PimSettingExporterWindow *exporterWindow)
{
mExporterWindow = exporterWindow;
}
void PimSettingCommandLineOption::handleCommandLine()
{
if (mExporterWindow) {
mExporterWindow->handleCommandLine(mParser);
}
}
......@@ -18,12 +18,27 @@
#ifndef PIMSETTINGCOMMANDLINEOPTION_H
#define PIMSETTINGCOMMANDLINEOPTION_H
#include <QObject>
#include <QCommandLineParser>
class PimSettingCommandLineOption : public QCommandLineParser
class QApplication;
class PimSettingExporterWindow;
class PimSettingCommandLineOption : public QObject
{
Q_OBJECT
public:
PimSettingCommandLineOption();
explicit PimSettingCommandLineOption(QObject *parent = Q_NULLPTR);
~PimSettingCommandLineOption();
void createParser(const QApplication &app);
void setExportWindow(PimSettingExporterWindow *exporterWindow);
void handleCommandLine();
public Q_SLOTS:
void slotActivateRequested(const QStringList &arguments, const QString &workingDirectory);
private:
QCommandLineParser mParser;
PimSettingExporterWindow *mExporterWindow;
};
#endif // PIMSETTINGCOMMANDLINEOPTION_H
......@@ -16,7 +16,6 @@
*/
#include "pimsettingexporterwindow.h"
#include "pimsettingcommandlineoption.h"
#include "dialog/showarchivestructuredialog.h"
#include "widgets/logwidget.h"
......@@ -182,15 +181,6 @@ void PimSettingExporterWindow::slotShowArchiveInformations()
delete dlg;
}
void PimSettingExporterWindow::slotActivateRequested(const QStringList &arguments, const QString &workingDirectory)
{
qDebug()<<" arguments"<<arguments << " workingDirectory"<<workingDirectory;
PimSettingCommandLineOption parser;
if (parser.parse(arguments)) {
handleCommandLine(parser);
}
}
void PimSettingExporterWindow::slotSaveLog()
{
if (mLogWidget->isEmpty()) {
......
......@@ -46,7 +46,6 @@ private Q_SLOTS:
void slotShowStructureInfos();
void slotRestoreFile(const QUrl &url);
void slotShowArchiveInformations();
void slotActivateRequested(const QStringList &arguments, const QString &workingDirectory);
private:
enum Action {
......
Supports Markdown
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