Commit c579db60 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Port KOrganizer to the new PimUniqueApplication API

parent f02ec660
......@@ -24,20 +24,24 @@
#include "aboutdata.h"
#include "kdepim-version.h"
#include <KLocalizedString>
using namespace KOrg;
AboutData::AboutData()
: K4AboutData("korganizer", Q_NULLPTR, ki18n("KOrganizer"), KDEPIM_VERSION,
ki18n("A Personal Organizer"),
K4AboutData::License_GPL,
ki18n("Copyright © 1997–1999 Preston Brown\n"
"Copyright © 2000–2004, 2007 Cornelius Schumacher\n"
"Copyright © 2004–2005 Reinhold Kainhofer\n"
"Copyright © 2006–2012 Allen Winter\n"
"Copyright © 2012–2015 KOrganizer authors"),
KLocalizedString(),
"https://userbase.kde.org/KOrganizer")
: KAboutData(QLatin1String("korganizer"),
i18n("KOrganizer"),
QLatin1String(KDEPIM_VERSION),
i18n("A Personal Organizer"),
KAboutLicense::GPL,
i18n("Copyright © 1997–1999 Preston Brown\n"
"Copyright © 2000–2004, 2007 Cornelius Schumacher\n"
"Copyright © 2004–2005 Reinhold Kainhofer\n"
"Copyright © 2006–2012 Allen Winter\n"
"Copyright © 2012–2015 KOrganizer authors"),
QString(),
QLatin1String("https://userbase.kde.org/KOrganizer"))
{
#if defined( KDEPIM_GIT_REVISION_STRING ) && defined( KDEPIM_GIT_LAST_CHANGE )
const QByteArray rev(KDEPIM_GIT_REVISION_STRING);
......@@ -49,48 +53,49 @@ AboutData::AboutData()
}
#endif
addAuthor(ki18n("Allen Winter"), ki18n("Maintainer"),
"winter@kde.org");
addAuthor(ki18n("Reinhold Kainhofer"), ki18n("Former Maintainer"),
"reinhold@kainhofer.com");
addAuthor(ki18n("Cornelius Schumacher"), ki18n("Former Maintainer"),
"schumacher@kde.org");
addAuthor(ki18n("Preston Brown"), ki18n("Original Author"),
"pbrown@kde.org");
addAuthor(ki18n("Laurent Montel"), ki18n("Developer"), "montel@kde.org");
addCredit(ki18n("Richard Apodaca"));
addCredit(ki18n("Björn Balazs"));
addCredit(ki18n("Jan-Pascal van Best"));
addCredit(ki18n("Bertjan Broeksema"));
addCredit(ki18n("Laszlo Boloni"));
addCredit(ki18n("Barry Benowitz"));
addCredit(ki18n("Christopher Beard"));
addCredit(ki18n("Kalle Dalheimer"));
addCredit(ki18n("Ian Dawes"));
addCredit(ki18n("Thomas Eitzenberger"));
addCredit(ki18n("Neil Hart"));
addCredit(ki18n("Declan Houlihan"));
addCredit(ki18n("Hans-Jürgen Husel"));
addCredit(ki18n("Tim Jansen"));
addCredit(ki18n("Christian Kirsch"));
addCredit(ki18n("Tobias König"));
addCredit(ki18n("Martin Koller"));
addCredit(ki18n("Uwe Koloska"));
addCredit(ki18n("Sergio Luis Martins"));
addCredit(ki18n("Mike McQuaid"));
addCredit(ki18n("Glen Parker"));
addCredit(ki18n("Dan Pilone"));
addCredit(ki18n("Roman Rohr"));
addCredit(ki18n("Rafał Rzepecki"),
ki18n("Part of work sponsored by Google with Summer of Code 2005"));
addCredit(ki18n("Don Sanders"));
addCredit(ki18n("Bram Schoenmakers"));
addCredit(ki18n("Günter Schwann"));
addCredit(ki18n("Herwin Jan Steehouwer"));
addCredit(ki18n("Mario Teijeiro"));
addCredit(ki18n("Nick Thompson"));
addCredit(ki18n("Bo Thorsen"));
addCredit(ki18n("Larry Wright"));
addCredit(ki18n("Thomas Zander"));
addCredit(ki18n("Fester Zigterman"));
addAuthor(i18n("Allen Winter"), i18n("Maintainer"),
QLatin1String("winter@kde.org"));
addAuthor(i18n("Reinhold Kainhofer"), i18n("Former Maintainer"),
QLatin1String("reinhold@kainhofer.com"));
addAuthor(i18n("Cornelius Schumacher"), i18n("Former Maintainer"),
QLatin1String("schumacher@kde.org"));
addAuthor(i18n("Preston Brown"), i18n("Original Author"),
QLatin1String("pbrown@kde.org"));
addAuthor(i18n("Laurent Montel"), i18n("Developer"),
QLatin1String("montel@kde.org"));
addCredit(i18n("Richard Apodaca"));
addCredit(i18n("Björn Balazs"));
addCredit(i18n("Jan-Pascal van Best"));
addCredit(i18n("Bertjan Broeksema"));
addCredit(i18n("Laszlo Boloni"));
addCredit(i18n("Barry Benowitz"));
addCredit(i18n("Christopher Beard"));
addCredit(i18n("Kalle Dalheimer"));
addCredit(i18n("Ian Dawes"));
addCredit(i18n("Thomas Eitzenberger"));
addCredit(i18n("Neil Hart"));
addCredit(i18n("Declan Houlihan"));
addCredit(i18n("Hans-Jürgen Husel"));
addCredit(i18n("Tim Jansen"));
addCredit(i18n("Christian Kirsch"));
addCredit(i18n("Tobias König"));
addCredit(i18n("Martin Koller"));
addCredit(i18n("Uwe Koloska"));
addCredit(i18n("Sergio Luis Martins"));
addCredit(i18n("Mike McQuaid"));
addCredit(i18n("Glen Parker"));
addCredit(i18n("Dan Pilone"));
addCredit(i18n("Roman Rohr"));
addCredit(i18n("Rafał Rzepecki"),
i18n("Part of work sponsored by Google with Summer of Code 2005"));
addCredit(i18n("Don Sanders"));
addCredit(i18n("Bram Schoenmakers"));
addCredit(i18n("Günter Schwann"));
addCredit(i18n("Herwin Jan Steehouwer"));
addCredit(i18n("Mario Teijeiro"));
addCredit(i18n("Nick Thompson"));
addCredit(i18n("Bo Thorsen"));
addCredit(i18n("Larry Wright"));
addCredit(i18n("Thomas Zander"));
addCredit(i18n("Fester Zigterman"));
}
......@@ -25,12 +25,12 @@
#define KORG_ABOUTDATA_H
#include "korganizerprivate_export.h"
#include <k4aboutdata.h>
#include <KAboutData>
namespace KOrg
{
class KORGANIZERPRIVATE_EXPORT AboutData : public K4AboutData
class KORGANIZERPRIVATE_EXPORT AboutData : public KAboutData
{
public:
AboutData();
......
......@@ -88,6 +88,7 @@
#include <KNS3/DownloadDialog>
#include <QIcon>
#include "korganizer_debug.h"
#include "korganizer_options.h"
#include <QApplication>
#include <QTimer>
......@@ -1362,9 +1363,12 @@ bool ActionManager::showIncidenceContext(Akonadi::Item::Id id)
return mCalendarView->showIncidenceContext(id);
}
bool ActionManager::handleCommandLine()
bool ActionManager::handleCommandLine(const QStringList &args)
{
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
QCommandLineParser parser;
korganizer_options(&parser);
parser.process(args);
KOrg::MainWindow *mainWindow = ActionManager::findInstance(QUrl());
bool ret = true;
......@@ -1372,7 +1376,7 @@ bool ActionManager::handleCommandLine()
if (!mainWindow) {
qCCritical(KORGANIZER_LOG) << "Unable to find default calendar resources view.";
ret = false;
} else if (args->count() <= 0) {
} else if (parser.positionalArguments().isEmpty()) {
// No filenames given => all other args are meaningless, show main Window
mainWindow->topLevelWidget()->show();
} else {
......@@ -1380,17 +1384,17 @@ bool ActionManager::handleCommandLine()
mainWindow->topLevelWidget()->show();
// Check for import, merge or ask
if (args->isSet("import")) {
for (int i = 0; i < args->count(); ++i) {
importURL(args->url(i), /*merge=*/false);
if (parser.isSet(QLatin1String("import"))) {
for (const QString &url : parser.positionalArguments()) {
importURL(QUrl::fromUserInput(url), /*merge=*/false);
}
} else if (args->isSet("merge")) {
for (int i = 0; i < args->count(); ++i) {
importURL(args->url(i), /*merge=*/true);
} else if (parser.isSet(QLatin1String("merge"))) {
for (const QString &url : parser.positionalArguments()) {
importURL(QUrl::fromUserInput(url), /*merge=*/true);
}
} else {
for (int i = 0; i < args->count(); ++i) {
mainWindow->actionManager()->importCalendar(args->url(i));
for (const QString &url : parser.positionalArguments()) {
mainWindow->actionManager()->importCalendar(QUrl::fromUserInput(url));
}
}
}
......
......@@ -164,7 +164,7 @@ public:
* Returns true if the command line was successfully handled
* false otherwise.
*/
bool handleCommandLine();
bool handleCommandLine(const QStringList &args);
public Q_SLOTS:
void openEventEditor(const QString &);
......
......@@ -47,6 +47,7 @@
</method>
<method name="handleCommandLine">
<arg type="b" direction="out"/>
<arg name="args" type="as" direction="in"/>
</method>
</interface>
</node>
......@@ -130,8 +130,8 @@ bool KOrganizerIfaceImpl::showIncidenceContext(const QString &uid)
return mActionManager->showIncidenceContext(id);
}
bool KOrganizerIfaceImpl::handleCommandLine()
bool KOrganizerIfaceImpl::handleCommandLine(const QStringList &args)
{
return mActionManager->handleCommandLine();
return mActionManager->handleCommandLine(args);
}
......@@ -102,7 +102,7 @@ public Q_SLOTS:
* Returns true if the command line was successfully handled
* false otherwise.
*/
bool handleCommandLine();
bool handleCommandLine(const QStringList &args);
private:
ActionManager *mActionManager;
......
......@@ -34,11 +34,14 @@
#include <KCmdLineArgs>
#include "korganizer_debug.h"
#include "korganizer_options.h"
#include <KStandardDirs>
#include <KStartupInfo>
#include <KGlobal>
#include <QCommandLineParser>
KOrganizerApp::KOrganizerApp() : KontactInterface::PimUniqueApplication()
KOrganizerApp::KOrganizerApp(int &argc, char **argv[], KAboutData &about)
: KontactInterface::PimUniqueApplication(argc, argv, about)
{
QString prodId = QStringLiteral("-//K Desktop Environment//NONSGML KOrganizer %1//EN");
KCalCore::CalFormat::setApplication(QStringLiteral("KOrganizer"), prodId.arg(QStringLiteral(KDEPIM_VERSION)));
......@@ -51,7 +54,7 @@ KOrganizerApp::~KOrganizerApp()
{
}
int KOrganizerApp::newInstance()
int KOrganizerApp::activate(const QStringList &args)
{
qCDebug(KORGANIZER_LOG);
static bool first = true;
......@@ -65,12 +68,14 @@ int KOrganizerApp::newInstance()
}
first = false;
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
QCommandLineParser parser;
korganizer_options(&parser);
parser.process(args);
KPIM::ReminderClient::startDaemon();
// No filenames given => all other args are meaningless, show main Window
if (args->count() <= 0) {
if (parser.positionalArguments().isEmpty()) {
processCalendar(QUrl());
return 0;
}
......@@ -84,17 +89,17 @@ int KOrganizerApp::newInstance()
return -1;
}
// Check for import, merge or ask
if (args->isSet("import")) {
for (int i = 0; i < args->count(); ++i) {
korg->actionManager()->importURL(args->url(i), false);
if (parser.isSet(QLatin1String("import"))) {
for (const QString &url : parser.positionalArguments()) {
korg->actionManager()->importURL(QUrl::fromUserInput(url), false);
}
} else if (args->isSet("merge")) {
for (int i = 0; i < args->count(); ++i) {
korg->actionManager()->importURL(args->url(i), true);
} else if (parser.isSet(QLatin1String("merge"))) {
for (const QString &url : parser.positionalArguments()) {
korg->actionManager()->importURL(QUrl::fromUserInput(url), true);
}
} else {
for (int i = 0; i < args->count(); ++i) {
korg->actionManager()->importCalendar(args->url(i));
for (const QString &url : parser.positionalArguments()) {
korg->actionManager()->importCalendar(QUrl::fromUserInput(url));
}
}
......
......@@ -34,14 +34,14 @@ class KOrganizerApp : public KontactInterface::PimUniqueApplication
{
Q_OBJECT
public:
KOrganizerApp();
KOrganizerApp(int &argc, char **argv[], KAboutData &aboutData);
~KOrganizerApp();
/**
Create new instance of KOrganizer. If there is already running a
KOrganizer only an additional main window is opened.
*/
int newInstance() Q_DECL_OVERRIDE;
int activate(const QStringList &args) Q_DECL_OVERRIDE;
private:
/**
......
......@@ -30,12 +30,12 @@
#include <QDBusMessage>
#include <QDBusConnection>
void KOrganizerUniqueAppHandler::loadCommandLineOptions()
void KOrganizerUniqueAppHandler::loadCommandLineOptions(QCommandLineParser *parser)
{
KCmdLineArgs::addCmdLineOptions(korganizer_options());
korganizer_options(parser);
}
int KOrganizerUniqueAppHandler::newInstance()
int KOrganizerUniqueAppHandler::activate(const QStringList &args)
{
// Ensure part is loaded
(void)plugin()->part();
......@@ -44,6 +44,7 @@ int KOrganizerUniqueAppHandler::newInstance()
QStringLiteral("/Korganizer"),
QStringLiteral("org.kde.korganizer.Korganizer"),
QStringLiteral("handleCommandLine"));
message.setArguments(QList<QVariant>() << (args));
QDBusConnection::sessionBus().send(message);
// Bring korganizer's plugin to front
......
......@@ -30,8 +30,9 @@ public:
explicit KOrganizerUniqueAppHandler(KontactInterface::Plugin *plugin)
: KontactInterface::UniqueAppHandler(plugin) {}
virtual ~KOrganizerUniqueAppHandler() {}
void loadCommandLineOptions() Q_DECL_OVERRIDE;
int newInstance() Q_DECL_OVERRIDE;
void loadCommandLineOptions(QCommandLineParser *parser) Q_DECL_OVERRIDE;
int activate(const QStringList &args) Q_DECL_OVERRIDE;
};
#endif /* KORG_UNIQUEAPP_H */
......
......@@ -26,22 +26,23 @@
#ifndef KORG_KORGANIZER_OPTIONS_H
#define KORG_KORGANIZER_OPTIONS_H
#include <KCmdLineOptions>
#include <QCommandLineParser>
#include <KLocalizedString>
static KCmdLineOptions korganizer_options()
static void korganizer_options(QCommandLineParser *parser)
{
KCmdLineOptions options;
options.add("i");
options.add("import",
ki18n("Import the specified files as separate calendars"));
options.add("m");
options.add("merge",
ki18n("Merge the specified files into an existing calendar"));
options.add("+[calendars]",
ki18n("Calendar files or urls. "
"Unless -i or -m is explicitly specified, "
"the user will be asked whether to import or merge"));
return options;
parser->addOption(QCommandLineOption(
QStringList() << QLatin1String("i") << QLatin1String("import"),
i18n("Import the specified files as separate calendars")));
parser->addOption(QCommandLineOption(
QStringList() << QLatin1String("m") << QLatin1String("merge"),
i18n("Merge the specified files into an existing calendar")));
parser->addPositionalArgument(
QLatin1String("calendars"),
i18n("Calendar files or urls. Unless -i or -m is explicitly specified, "
"the user will be asked whether to import or merge"),
QLatin1String("[calendar...]"));
}
#endif
......
......@@ -40,7 +40,7 @@
#include <QVBoxLayout>
static const K4AboutData &createAboutData()
static const KAboutData &createAboutData()
{
static KOrg::AboutData about;
return about;
......
......@@ -28,24 +28,30 @@
#include "korganizer.h"
#include "korganizer_options.h"
#include "korgstartup.h"
#include "korganizer_debug.h"
#include <KLocalizedString>
int main(int argc, char **argv)
{
KOrgStartup::migrateConfig();
KLocalizedString::setApplicationDomain("korganizer");
KOrg::AboutData aboutData;
KCmdLineArgs::init(argc, argv, &aboutData);
KCmdLineArgs::addCmdLineOptions(korganizer_options());
KUniqueApplication::addCmdLineOptions();
KOrganizerApp app(argc, &argv, aboutData);
QCommandLineParser *cmdArgs = app.cmdArgs();
korganizer_options(cmdArgs);
KUniqueApplication::StartFlags flags;
//flags |= KUniqueApplication::NonUniqueInstance;
if (!KOrganizerApp::start(flags)) {
const QStringList args = QApplication::arguments();
cmdArgs->process(args);
aboutData.processCommandLine(cmdArgs);
if (!KOrganizerApp::start(args)) {
qCDebug(KORGANIZER_LOG) << "korganizer already running, exiting";
return 0;
}
KOrganizerApp app;
if (app.isSessionRestored()) {
kRestoreMainWindows<KOrganizer>();
}
......
Markdown is supported
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