[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [calligra] plan/workpackage: Port planwork KUniqueApplication/KCmdLineArgs -> QApplication/QCommandL
From: Friedrich W. H. Kossebau <kossebau () kde ! org>
Date: 2015-12-31 19:05:23
Message-ID: E1aEiXL-0005pd-Vj () scm ! kde ! org
[Download RAW message or body]
Git commit 3e5debbafa671430402d024ce3d229aa0df3fbf4 by Friedrich W. H. Kossebau.
Committed on 31/12/2015 at 19:02.
Pushed by kossebau into branch 'master'.
Port planwork KUniqueApplication/KCmdLineArgs -> QApplication/QCommandLineParser
M +3 -6 plan/workpackage/CMakeLists.txt
M +14 -10 plan/workpackage/aboutdata.h
M +52 -33 plan/workpackage/application.cpp
M +12 -19 plan/workpackage/application.h
M +6 -6 plan/workpackage/factory.cpp
M +6 -7 plan/workpackage/factory.h
M +10 -15 plan/workpackage/main.cpp
M +1 -2 plan/workpackage/part.cpp
http://commits.kde.org/calligra/3e5debbafa671430402d024ce3d229aa0df3fbf4
diff --git a/plan/workpackage/CMakeLists.txt b/plan/workpackage/CMakeLists.txt
index 1648884..08a57bc 100644
--- a/plan/workpackage/CMakeLists.txt
+++ b/plan/workpackage/CMakeLists.txt
@@ -106,12 +106,9 @@ endif ()
target_link_libraries(
kdeinit_calligraplanwork
planworkapp
-
-
- Qt5::Core
- Qt5::Gui
- KF5::Parts
- )
+
+ KF5::DBusAddons
+)
install(TARGETS kdeinit_calligraplanwork ${INSTALL_TARGETS_DEFAULT_ARGS})
diff --git a/plan/workpackage/aboutdata.h b/plan/workpackage/aboutdata.h
index ee821cc..a8171b8 100644
--- a/plan/workpackage/aboutdata.h
+++ b/plan/workpackage/aboutdata.h
@@ -21,8 +21,9 @@
#ifndef KPLATOWORK_ABOUTDATA
#define KPLATOWORK_ABOUTDATA
-#include <k4aboutdata.h>
+#include <KAboutData>
#include <KLocalizedString>
+
#include <calligraversion.h>
namespace KPlatoWork
@@ -31,16 +32,19 @@ namespace KPlatoWork
static const char PLANWORK_DESCRIPTION[] = I18N_NOOP("PlanWork - Work Package \
handler for the Plan Project Planning Tool"); static const char PLANWORK_VERSION[] = \
CALLIGRA_VERSION_STRING;
-K4AboutData * newAboutData()
+KAboutData * newAboutData()
{
- K4AboutData * aboutData=new K4AboutData( "planwork", 0, ki18nc("application \
name", "Plan WorkPackage Handler"),
- PLANWORK_VERSION, \
ki18n(PLANWORK_DESCRIPTION),
- K4AboutData::License_GPL,
- ki18n(" © 1998-%1, The Plan \
Team").subs(CALLIGRA_YEAR),
- KLocalizedString(),
- "https://www.calligra.org/plan/" );
-
- aboutData->addAuthor(ki18n("Dag Andersen"), KLocalizedString(), \
"danders@get2net.dk"); + KAboutData * aboutData = new KAboutData(
+ QStringLiteral("planwork"),
+ i18nc("application name", "Plan WorkPackage Handler"),
+ QStringLiteral(CALLIGRA_VERSION_STRING),
+ i18n("PlanWork - Work Package handler for the Plan Project Planning Tool"),
+ KAboutLicense::GPL,
+ i18n("Copyright 1998-%1, The Plan Team").arg(QStringLiteral(CALLIGRA_YEAR)),
+ QString(),
+ QStringLiteral("https://www.calligra.org/plan/"));
+
+ aboutData->addAuthor(i18n("Dag Andersen"), QString(), \
QStringLiteral("danders@get2net.dk"));
aboutData->setProductName( "calligra-plan/work" );
aboutData->setProgramIconName( "calligraplanwork" );
diff --git a/plan/workpackage/application.cpp b/plan/workpackage/application.cpp
index fb41f91..973a237 100644
--- a/plan/workpackage/application.cpp
+++ b/plan/workpackage/application.cpp
@@ -24,32 +24,35 @@
#include "application.h"
#include "part.h"
#include "mainwindow.h"
-
-#include <QSplitter>
-#include <QLabel>
-
-#include <assert.h>
-
-#include <KoApplicationAdaptor.h>
-#include <KoDocument.h>
-#include <KoDocumentEntry.h>
-#include <KoDocumentInfo.h>
-#include <KoFilterManager.h>
-#include <KoGlobal.h>
-#include <KoView.h>
-
-#include <kcmdlineargs.h>
+#include "aboutdata.h"
#include <kiconloader.h>
#include <KLocalizedString>
+#include <KAboutData>
+#include <KStartupInfo>
+#include <KWindowSystem>
#include <kmessagebox.h>
+#include <QDir>
+
#include "debugarea.h"
-KPlatoWork_Application::KPlatoWork_Application()
- : KUniqueApplication(),
+KPlatoWork_Application::KPlatoWork_Application(int argc, char **argv)
+ : QApplication(argc, argv),
m_mainwindow( 0 )
{
+ KAboutData *aboutData = KPlatoWork::newAboutData();
+ KAboutData::setApplicationData( *aboutData );
+
+ aboutData->setupCommandLine(&m_commandLineParser);
+ m_commandLineParser.addHelpOption();
+ m_commandLineParser.addVersionOption();
+ m_commandLineParser.addPositionalArgument(QStringLiteral("[file]"), i18n("File \
to open")); +
+ m_commandLineParser.process(*this);
+
+ aboutData->processCommandLine(&m_commandLineParser);
+
// Tell the iconloader about share/apps/calligra/icons
/* KIconLoader::global()->addAppDir("calligra");
@@ -58,24 +61,36 @@ KPlatoWork_Application::KPlatoWork_Application()
new KoApplicationAdaptor(this);
QDBusConnection::sessionBus().registerObject("/application", this);*/
+
+ delete aboutData;
}
KPlatoWork_Application::~KPlatoWork_Application()
{
}
-int KPlatoWork_Application::newInstance()
+void KPlatoWork_Application::handleActivateRequest(const QStringList &arguments, \
const QString &workingDirectory) +{
+ Q_UNUSED(workingDirectory);
+
+ m_commandLineParser.parse(arguments);
+
+ handleCommandLine(QDir(workingDirectory));
+
+ // terminate startup notification and activate the mainwindow
+ KStartupInfo::setNewStartupId(m_mainwindow, KStartupInfo::startupId());
+ KWindowSystem::forceActiveWindow(m_mainwindow->winId());
+
+}
+
+void KPlatoWork_Application::handleCommandLine(const QDir &workingDirectory)
{
debugPlanWork<<"starting------------------------";
- int status = KUniqueApplication::newInstance(); // bring up window (if any)
- if ( status != 0 ) {
- return status;
- }
QList<KMainWindow*> lst = KMainWindow::memberList();
debugPlanWork<<"windows"<<lst.count();
if ( lst.count() > 1 ) {
debugPlanWork<<"windows"<<lst.count();
- return 1; // should never happen
+ return; // should never happen
}
if ( lst.isEmpty() ) {
Q_ASSERT( m_mainwindow == 0 );
@@ -84,20 +99,24 @@ int KPlatoWork_Application::newInstance()
m_mainwindow = new KPlatoWork_MainWindow();
m_mainwindow->show();
}
+
// Get the command line arguments which we have to parse
- KCmdLineArgs *args= KCmdLineArgs::parsedArgs();
- int argsCount = args->count();
- if ( argsCount > 0 ) {
- //short int n=0; // number of documents open
- for(int i=0; i < argsCount; i++ ) {
- // For now create an empty document
- if ( ! m_mainwindow->openDocument( args->url(i) ) ) {
+ const QStringList fileUrls = m_commandLineParser.positionalArguments();
+ // TODO: remove once Qt has proper handling itself
+ const QRegExp withProtocolChecker( QStringLiteral("^[a-zA-Z]+:") );
+ foreach(const QString &fileUrl, fileUrls) {
+ // convert to an url
+ const bool startsWithProtocol = (withProtocolChecker.indexIn(fileUrl) == 0);
+ const QUrl url = startsWithProtocol ?
+ QUrl::fromUserInput(fileUrl) :
+ QUrl::fromLocalFile(workingDirectory.absoluteFilePath(fileUrl));
+
+ // For now create an empty document
+ if ( ! m_mainwindow->openDocument(url) ) {
KMessageBox::error(0, i18n("Failed to open document") );
}
- }
}
- args->clear();
+
// not calling this before since the program will quit there.
debugPlanWork<<"started------------------------";
- return 0;
}
diff --git a/plan/workpackage/application.h b/plan/workpackage/application.h
index f74c14e..b8da76e 100644
--- a/plan/workpackage/application.h
+++ b/plan/workpackage/application.h
@@ -25,36 +25,29 @@
#include "planworkapp_export.h"
-#include <KoMainWindow.h>
-
-#include <KoApplication.h>
-
-#include <kuniqueapplication.h>
-
-#include <QMap>
-#include <QToolButton>
-#include <QLabel>
+#include <QApplication>
+#include <QCommandLineParser>
class KPlatoWork_MainWindow;
+class QDir;
-namespace KPlatoWork {
-}
-namespace KPlato {
- class Document;
-}
-
-
-class PLANWORKAPP_EXPORT KPlatoWork_Application : public KUniqueApplication
+class PLANWORKAPP_EXPORT KPlatoWork_Application : public QApplication
{
Q_OBJECT
+
public:
- KPlatoWork_Application();
+ KPlatoWork_Application(int argc, char **argv);
~KPlatoWork_Application();
- virtual int newInstance();
+public:
+ void handleCommandLine(const QDir &workingDirectory);
+
+public Q_SLOTS:
+ void handleActivateRequest(const QStringList &arguments, const QString \
&workingDirectory);
private:
KPlatoWork_MainWindow *m_mainwindow;
+ QCommandLineParser m_commandLineParser;
};
diff --git a/plan/workpackage/factory.cpp b/plan/workpackage/factory.cpp
index 94a11cd..7281302 100644
--- a/plan/workpackage/factory.cpp
+++ b/plan/workpackage/factory.cpp
@@ -23,16 +23,16 @@
#include "aboutdata.h"
#include <KoResourcePaths.h>
+#include <KoComponentData.h>
-#include <kcomponentdata.h>
#include <kiconloader.h>
namespace KPlatoWork
{
-KComponentData* Factory::s_global = 0L;
-K4AboutData* Factory::s_aboutData = 0L;
+KoComponentData* Factory::s_global = 0L;
+KAboutData* Factory::s_aboutData = 0L;
Factory::Factory()
: KPluginFactory()
@@ -58,18 +58,18 @@ QObject* Factory::create( const char* iface, QWidget* \
parentWidget, QObject *par return part;
}
-K4AboutData* Factory::aboutData()
+KAboutData* Factory::aboutData()
{
if ( !s_aboutData )
s_aboutData = newAboutData();
return s_aboutData;
}
-const KComponentData &Factory::global()
+const KoComponentData &Factory::global()
{
if ( !s_global )
{
- s_global = new KComponentData( aboutData() );
+ s_global = new KoComponentData( *aboutData() );
// Add any application-specific resource directories here
KoResourcePaths::addResourceType("planwork_template", "data", \
"planwork/templates/");
diff --git a/plan/workpackage/factory.h b/plan/workpackage/factory.h
index 2cfaae5..733fb3e 100644
--- a/plan/workpackage/factory.h
+++ b/plan/workpackage/factory.h
@@ -25,8 +25,8 @@
#include <kpluginfactory.h>
-class K4AboutData;
-class KComponentData;
+class KAboutData;
+class KoComponentData;
namespace KPlatoWork
{
@@ -40,14 +40,13 @@ public:
virtual QObject* create(const char* iface, QWidget* parentWidget, QObject \
*parent, const QVariantList& args, const QString& keyword);
- static const KComponentData &global();
+ static const KoComponentData &global();
- // _Creates_ a K4AboutData but doesn't keep ownership
- static K4AboutData* aboutData();
+ static KAboutData* aboutData();
private:
- static KComponentData* s_global;
- static K4AboutData* s_aboutData;
+ static KoComponentData* s_global;
+ static KAboutData* s_aboutData;
};
} // KPlatoWork namespace
diff --git a/plan/workpackage/main.cpp b/plan/workpackage/main.cpp
index 0cea73e..2dac0c1 100644
--- a/plan/workpackage/main.cpp
+++ b/plan/workpackage/main.cpp
@@ -19,28 +19,23 @@
#include "kplatowork_export.h"
-#include "aboutdata.h"
#include "application.h"
-#include <kcmdlineargs.h>
+#include <KDBusService>
-#include <QFile>
+#include <QDir>
-extern "C" KPLATOWORK_EXPORT int kdemain( int argc, char **argv ) {
- KCmdLineArgs::init( argc, argv, KPlatoWork::newAboutData());
- KCmdLineOptions options;
- options.add("+[file]", ki18n("File to open"));
- KCmdLineArgs::addCmdLineOptions( options );
+extern "C" KPLATOWORK_EXPORT int kdemain( int argc, char **argv )
+{
+ KPlatoWork_Application app(argc, argv);
- if (!KUniqueApplication::start()) {
- fprintf(stderr, "PlanWork is already running!\n");
- return 0;
- }
-
- KPlatoWork_Application app;
- fprintf(stderr, "app created\n");
+ KDBusService service(KDBusService::Unique);
+ QObject::connect(&service, &KDBusService::activateRequested,
+ &app, &KPlatoWork_Application::handleActivateRequest);
+ app.handleCommandLine(QDir::current());
app.exec();
+
return 0;
}
diff --git a/plan/workpackage/part.cpp b/plan/workpackage/part.cpp
index 7072afe..39396c6 100644
--- a/plan/workpackage/part.cpp
+++ b/plan/workpackage/part.cpp
@@ -52,7 +52,6 @@
#include <QUrl>
#include <QMimeDatabase>
-#include <kcomponentdata.h>
#include <KLocalizedString>
#include <kmessagebox.h>
#include <kparts/partmanager.h>
@@ -344,7 +343,7 @@ Part::Part( QWidget *parentWidget, QObject *parent, const \
QVariantList & /*args* m_undostack( new KUndo2QStack( this ) )
{
debugPlanWork;
- setComponentData( Factory::global() );
+ setComponentData( *Factory::aboutData() );
if ( isReadWrite() ) {
setXMLFile( "planwork.rc" );
} else {
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic