Commit 09577d4d authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port to qcommanderlineparser

parent a690331d
......@@ -104,6 +104,7 @@ target_link_libraries(pimsettingexporter
KF5::PimUtils
KF5::MailTransport
KF5::AlarmCalendar
KF5::DBusAddons
mailimporter
mailcommon
pimcommon
......
......@@ -220,8 +220,8 @@ void AbstractImportExportJob::initializeImportJob()
mTempDir = new QTemporaryDir();
mTempDirName = mTempDir->path();
mCreateResource = new PimCommon::CreateResource();
connect(mCreateResource, SIGNAL(createResourceInfo(QString)), SIGNAL(info(QString)));
connect(mCreateResource, SIGNAL(createResourceError(QString)), SIGNAL(error(QString)));
connect(mCreateResource, &PimCommon::CreateResource::createResourceInfo, this, &AbstractImportExportJob::info);
connect(mCreateResource, &PimCommon::CreateResource::createResourceError, this, &AbstractImportExportJob::error);
}
}
......
......@@ -16,38 +16,45 @@
*/
#include "pimsettingexporterwindow.h"
#include "pimsettingexporter_options.h"
#include <kcmdlineargs.h>
#include <k4aboutdata.h>
#include <kaboutdata.h>
#include <KLocalizedString>
#include <KUniqueApplication>
#include <KDBusService>
#include <QDebug>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include "kdepim-version.h"
int main(int argc, char *argv[])
{
KLocalizedString::setApplicationDomain("pimsettingexporter");
K4AboutData aboutData("pimsettingexporter", 0, ki18n("PIM Setting Exporter"),
KDEPIM_VERSION, ki18n("PIM Setting Exporter"), K4AboutData::License_GPL_V2,
ki18n("Copyright © 2012-2014 pimsettingexporter authors"));
aboutData.addAuthor(ki18n("Laurent Montel"), ki18n("Maintainer"), "montel@kde.org");
KAboutData aboutData(QLatin1String("pimsettingexporter"), i18n("PIM Setting Exporter"),
QLatin1String(KDEPIM_VERSION), i18n("PIM Setting Exporter"), KAboutLicense::GPL_V2,
i18n("Copyright © 2012-2014 pimsettingexporter authors"));
aboutData.addAuthor(i18n("Laurent Montel"), i18n("Maintainer"), QStringLiteral("montel@kde.org"));
aboutData.setProgramIconName(QLatin1String("kontact"));
KCmdLineArgs::init(argc, argv, &aboutData);
KCmdLineArgs::addCmdLineOptions(pimsettingexporter_options()); // Add our own options.
KUniqueApplication::addCmdLineOptions();
QApplication app(argc, argv);
QCommandLineParser parser;
KAboutData::setApplicationData(aboutData);
parser.addVersionOption();
parser.addHelpOption();
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("template"), i18n("Template file uses to define what data, settings to import or export"), QLatin1String("file")));
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("import"), i18n("Import the given file")));
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("export"), i18n("Export the given file")));
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("+[url]"), i18n("File or url. The user will be asked whether to import or export.")));
aboutData.setupCommandLine(&parser);
parser.process(app);
aboutData.processCommandLine(&parser);
KDBusService service(KDBusService::Unique);
//QT5 TODO connect service to load file when necessary
if (!KUniqueApplication::start()) {
qDebug() << "pimsettingexporter is already running!";
return (0);
}
KUniqueApplication a;
PimSettingExporterWindow *backupMailWin = new PimSettingExporterWindow();
a.setTopWidget(backupMailWin);
backupMailWin->show();
backupMailWin->handleCommandLine();
backupMailWin->handleCommandLine(parser);
return a.exec();
return app.exec();
}
/*
Copyright (c) 2013, 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef PIMSETTINGEXPORTER_OPTIONS_H
#define PIMSETTINGEXPORTER_OPTIONS_H
#include <kcmdlineargs.h>
#include <KLocalizedString>
static KCmdLineOptions pimsettingexporter_options()
{
KCmdLineOptions options;
options.add("template <file>", ki18n("Template file uses to define what data, settings to import or export"));
options.add("import", ki18n("Import the given file"));
options.add("export", ki18n("Export the given file"));
options.add("+[url]",
ki18n("File or url. "
"The user will be asked whether to import or export."));
return options;
}
#endif // PIMSETTINGEXPORTER_OPTIONS_H
......@@ -70,6 +70,7 @@
#include <QStandardPaths>
#include <QLocale>
#include <QFileDialog>
#include <QCommandLineParser>
PimSettingExporterWindow::PimSettingExporterWindow(QWidget *parent)
: KXmlGuiWindow(parent),
......@@ -110,23 +111,21 @@ PimSettingExporterWindow::~PimSettingExporterWindow()
mRecentFilesAction->saveEntries(groupConfig);
}
void PimSettingExporterWindow::handleCommandLine()
void PimSettingExporterWindow::handleCommandLine(const QCommandLineParser &parser)
{
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
QString templateFile;
if (args->isSet("template")) {
templateFile = args->getOption("template");
if (parser.isSet(QStringLiteral("template"))) {
templateFile = parser.value(QStringLiteral("template"));
}
if (args->isSet("import")) {
if (args->count() > 0) {
loadData(args->url(0).path(), templateFile);
if (parser.isSet(QStringLiteral("import"))) {
if (parser.positionalArguments().count() > 0) {
loadData(parser.positionalArguments().at(0), templateFile);
}
} else if (args->isSet("export")) {
if (args->count() > 0) {
backupData(args->url(0).path(), templateFile);
} else if (parser.isSet(QStringLiteral("export"))) {
if (parser.positionalArguments().count() > 0) {
backupData(parser.positionalArguments().at(0), templateFile);
}
}
args->clear();
}
void PimSettingExporterWindow::setupActions(bool canZipFile)
......
......@@ -24,6 +24,7 @@ class AbstractImportExportJob;
class KRecentFilesAction;
class ArchiveStorage;
class QAction;
class QCommandLineParser;
class PimSettingExporterWindow: public KXmlGuiWindow
{
......@@ -31,7 +32,7 @@ class PimSettingExporterWindow: public KXmlGuiWindow
public:
explicit PimSettingExporterWindow(QWidget *parent = 0);
~PimSettingExporterWindow();
void handleCommandLine();
void handleCommandLine(const QCommandLineParser &parser);
private Q_SLOTS:
void slotJobFinished();
......
......@@ -275,11 +275,11 @@ void PimSettingsBackupRestore::restoreFinished()
void PimSettingsBackupRestore::executeJob()
{
connect(mImportExportData, SIGNAL(info(QString)), SIGNAL(addInfo(QString)));
connect(mImportExportData, SIGNAL(error(QString)), SIGNAL(addError(QString)));
connect(mImportExportData, SIGNAL(title(QString)), SIGNAL(addTitle(QString)));
connect(mImportExportData, SIGNAL(endLine()), SIGNAL(addEndLine()));
connect(mImportExportData, SIGNAL(jobFinished()), SIGNAL(jobFinished()));
connect(mImportExportData, &AbstractImportExportJob::info, this, &PimSettingsBackupRestore::addInfo);
connect(mImportExportData, &AbstractImportExportJob::error, this, &PimSettingsBackupRestore::addError);
connect(mImportExportData, &AbstractImportExportJob::title, this, &PimSettingsBackupRestore::addTitle);
connect(mImportExportData, &AbstractImportExportJob::endLine, this, &PimSettingsBackupRestore::addEndLine);
connect(mImportExportData, &AbstractImportExportJob::jobFinished, this, &PimSettingsBackupRestore::jobFinished);
mImportExportData->start();
}
......
......@@ -94,7 +94,7 @@ void SelectionTypeTreeWidget::initialize()
createSubItem(mBlogiloItem, Utils::Config);
createSubItem(mBlogiloItem, Utils::Data);
connect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)), SLOT(slotItemChanged(QTreeWidgetItem*,int)));
connect(this, &SelectionTypeTreeWidget::itemChanged, this, &SelectionTypeTreeWidget::slotItemChanged);
}
QHash<Utils::AppsType, Utils::importExportParameters> SelectionTypeTreeWidget::storedType() const
......
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