From kde-commits Thu Dec 31 19:05:23 2015 From: Friedrich W. H. Kossebau Date: Thu, 31 Dec 2015 19:05:23 +0000 To: kde-commits Subject: [calligra] plan/workpackage: Port planwork KUniqueApplication/KCmdLineArgs -> QApplication/QCommandL Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=145158873508753 Git commit 3e5debbafa671430402d024ce3d229aa0df3fbf4 by Friedrich W. H. Koss= ebau. Committed on 31/12/2015 at 19:02. Pushed by kossebau into branch 'master'. Port planwork KUniqueApplication/KCmdLineArgs -> QApplication/QCommandLineP= arser 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 +#include #include + #include = namespace KPlatoWork @@ -31,16 +32,19 @@ namespace KPlatoWork static const char PLANWORK_DESCRIPTION[] =3D I18N_NOOP("PlanWork - Work Pa= ckage handler for the Plan Project Planning Tool"); static const char PLANWORK_VERSION[] =3D CALLIGRA_VERSION_STRING; = -K4AboutData * newAboutData() +KAboutData * newAboutData() { - K4AboutData * aboutData=3Dnew K4AboutData( "planwork", 0, ki18nc("appl= ication name", "Plan WorkPackage Handler"), - PLANWORK_VERSION, ki18n(PLANWOR= K_DESCRIPTION), - K4AboutData::License_GPL, - ki18n("=C2=A9 1998-%1, The Plan= Team").subs(CALLIGRA_YEAR), - KLocalizedString(), - "https://www.calligra.org/plan/= " ); - - aboutData->addAuthor(ki18n("Dag Andersen"), KLocalizedString(), "dande= rs@get2net.dk"); + KAboutData * aboutData =3D new KAboutData( + QStringLiteral("planwork"), + i18nc("application name", "Plan WorkPackage Handler"), + QStringLiteral(CALLIGRA_VERSION_STRING), + i18n("PlanWork - Work Package handler for the Plan Project Plannin= g Tool"), + KAboutLicense::GPL, + i18n("Copyright 1998-%1, The Plan Team").arg(QStringLiteral(CALLIG= RA_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/applicatio= n.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 -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include +#include "aboutdata.h" = #include #include +#include +#include +#include #include = +#include + #include "debugarea.h" = -KPlatoWork_Application::KPlatoWork_Application() - : KUniqueApplication(), +KPlatoWork_Application::KPlatoWork_Application(int argc, char **argv) + : QApplication(argc, argv), m_mainwindow( 0 ) { + KAboutData *aboutData =3D KPlatoWork::newAboutData(); + KAboutData::setApplicationData( *aboutData ); + + aboutData->setupCommandLine(&m_commandLineParser); + m_commandLineParser.addHelpOption(); + m_commandLineParser.addVersionOption(); + m_commandLineParser.addPositionalArgument(QStringLiteral("[file]"), i1= 8n("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 &argu= ments, 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 &workingDirector= y) { debugPlanWork<<"starting------------------------"; - int status =3D KUniqueApplication::newInstance(); // bring up window (= if any) - if ( status !=3D 0 ) { - return status; - } QList lst =3D KMainWindow::memberList(); debugPlanWork<<"windows"< 1 ) { debugPlanWork<<"windows"<show(); } + // Get the command line arguments which we have to parse - KCmdLineArgs *args=3D KCmdLineArgs::parsedArgs(); - int argsCount =3D args->count(); - if ( argsCount > 0 ) { - //short int n=3D0; // number of documents open - for(int i=3D0; i < argsCount; i++ ) { - // For now create an empty document - if ( ! m_mainwindow->openDocument( args->url(i) ) ) { + const QStringList fileUrls =3D 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 =3D (withProtocolChecker.indexIn(fil= eUrl) =3D=3D 0); + const QUrl url =3D 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 - -#include - -#include - -#include -#include -#include +#include +#include = 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 +#include = -#include #include = = namespace KPlatoWork { = -KComponentData* Factory::s_global =3D 0L; -K4AboutData* Factory::s_aboutData =3D 0L; +KoComponentData* Factory::s_global =3D 0L; +KAboutData* Factory::s_aboutData =3D 0L; = Factory::Factory() : KPluginFactory() @@ -58,18 +58,18 @@ QObject* Factory::create( const char* iface, QWidget* p= arentWidget, QObject *par return part; } = -K4AboutData* Factory::aboutData() +KAboutData* Factory::aboutData() { if ( !s_aboutData ) s_aboutData =3D newAboutData(); return s_aboutData; } = -const KComponentData &Factory::global() +const KoComponentData &Factory::global() { if ( !s_global ) { - s_global =3D new KComponentData( aboutData() ); + s_global =3D new KoComponentData( *aboutData() ); = // Add any application-specific resource directories here KoResourcePaths::addResourceType("planwork_template", "data", "pla= nwork/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 = -class K4AboutData; -class KComponentData; +class KAboutData; +class KoComponentData; = namespace KPlatoWork { @@ -40,14 +40,13 @@ public: = virtual QObject* create(const char* iface, QWidget* parentWidget, QObj= ect *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 +#include = -#include +#include = = -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 #include = -#include #include #include #include @@ -344,7 +343,7 @@ Part::Part( QWidget *parentWidget, QObject *parent, con= st QVariantList & /*args* m_undostack( new KUndo2QStack( this ) ) { debugPlanWork; - setComponentData( Factory::global() ); + setComponentData( *Factory::aboutData() ); if ( isReadWrite() ) { setXMLFile( "planwork.rc" ); } else {