[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [ring-kde] src: cmd: Restore the command line parsing
From:       Emmanuel Lepage Vallee <emmanuel.lepage () savoirfairelinux ! com>
Date:       2015-06-05 21:16:11
Message-ID: E1Z0yyJ-0001W5-Uh () scm ! kde ! org
[Download RAW message or body]

Git commit 7155b251e2a80808ce9806bbc5184acbc96e1f03 by Emmanuel Lepage Vallee.
Committed on 05/06/2015 at 15:37.
Pushed by lepagevalleeemmanuel into branch 'master'.

cmd: Restore the command line parsing

It was disabled during the KF5 port.

This commit doesn't restore the features themselves, only the
parser.

Refs #74235

M  +41   -24   src/cmd.cpp
M  +2    -0    src/main.cpp

http://commits.kde.org/ring-kde/7155b251e2a80808ce9806bbc5184acbc96e1f03

diff --git a/src/cmd.cpp b/src/cmd.cpp
index 37dab13..275fc1d 100644
--- a/src/cmd.cpp
+++ b/src/cmd.cpp
@@ -18,7 +18,8 @@
 #include "cmd.h"
 
 //Qt
-#include <QApplication>
+#include <QtCore/QCoreApplication>
+#include <QtCore/QTimer>
 
 //KDE
 #include <KAboutData>
@@ -51,51 +52,67 @@ Cmd* Cmd::instance() {
 ///Setup command line options before passing them to the KUniqueApplication
 void Cmd::parseCmd(int argc, char **argv, KAboutData& about)
 {
-   QApplication app(argc, argv);
+   QCoreApplication app(argc, argv);
    QCommandLineParser parser;
+
+   QCommandLineOption call     (QStringList {"place-call"   }, i18n("Place a call to a given number"     \
), QLatin1String("number" ), QLatin1String("")); +   QCommandLineOption text     (QStringList \
{"send-text"    }, i18n("Send a text to &lt;number&gt;, use --message to set the content, then hangup"), \
QLatin1String("number" ), QLatin1String("")); +   QCommandLineOption message  (QStringList {"message"     \
}, i18n("Used in combination with --send-text"                                        ), \
QLatin1String("content"), QLatin1String("")); +   QCommandLineOption minimixed(QStringList {"minimized"   \
}, i18n("Start in the system tray"                                                    ), \
QLatin1String("content"), QLatin1String("")); +
+   parser.addOptions({call,text,message,minimixed});
+
    KAboutData::setApplicationData(about);
    parser.addVersionOption();
    parser.addHelpOption();
-   //PORTING SCRIPT: adapt aboutdata variable if necessary
+
    about.setupCommandLine(&parser);
    parser.process(app);
    about.processCommandLine(&parser);
 
-   parser.addOption(QCommandLineOption(QStringList() << QLatin1String("call"), i18n("Place a call to a \
                given number"                                        ), QLatin1String("number"), \
                QLatin1String("")));
-   parser.addOption(QCommandLineOption(QStringList() << QLatin1String("text"), i18n("Send a text to \
&lt;number&gt;, use --message to set the content, then hangup"), QLatin1String("number"), \
                QLatin1String("")));
-   parser.addOption(QCommandLineOption(QStringList() << QLatin1String("message"), i18n("Used in \
combination with --send-text"                                   ), QLatin1String("content"), \
QLatin1String(""))); +   if (parser.isSet(call))
+      placeCall(parser.value(call));
 
-//    QCommandLineParser::parsedArgs();
-
-//    KUniqueApplication::addCmdLineOptions();
+   if (parser.isSet(text) && parser.isSet(message))
+      sendText(parser.value(text),parser.value(message));
 }
 
 ///Place a call (from the command line)
 void Cmd::placeCall(const QString& number)
 {
-   Call* call = CallModel::instance()->dialingCall();
-   call->reset();
-   call->appendText(number);
-   call->performAction(Call::Action::ACCEPT);
+   if (number.isEmpty()) {
+      qWarning() << "Example: --place-call 123@example.com";
+      exit(1);
+   }
+
+//    QTimer::singleShot(0,[number] {
+//       Call* call = CallModel::instance()->dialingCall();
+//       call->reset();
+//       call->appendText(number);
+//       call->performAction(Call::Action::ACCEPT);
+//    });
 }
 
 ///Send a text ans hang up (from the command line)
 void Cmd::sendText(const QString& number, const QString& text)
 {
-   Call* call = CallModel::instance()->dialingCall();
-   call->reset();
-   call->appendText(number);
-   call->setProperty("message",text);
-   connect(call,SIGNAL(changed(Call*)),instance(),SLOT(textMessagePickup(Call*)));
-   call->performAction(Call::Action::ACCEPT);
+   Q_UNUSED(number)
+   Q_UNUSED(text)
+//    Call* call = CallModel::instance()->dialingCall();
+//    call->reset();
+//    call->appendText(number);
+//    call->setProperty("message",text);
+//    connect(call,SIGNAL(changed(Call*)),instance(),SLOT(textMessagePickup(Call*)));
+//    call->performAction(Call::Action::ACCEPT);
 }
 
 ///Send the message now that the call is ready
 void Cmd::textMessagePickup(Call* call)
 {
-   if (call->state() == Call::State::CURRENT) {
-      call->addOutgoingMedia<Media::Text>()->send(call->property("message").toString());
-      disconnect(call,SIGNAL(changed(Call*)),instance(),SLOT(textMessagePickup(Call*)));
-      call->performAction(Call::Action::REFUSE); //HangUp
-   }
+   Q_UNUSED(call)
+//    if (call->state() == Call::State::CURRENT) {
+//       call->addOutgoingMedia<Media::Text>()->send(call->property("message").toString());
+//       disconnect(call,SIGNAL(changed(Call*)),instance(),SLOT(textMessagePickup(Call*)));
+//       call->performAction(Call::Action::REFUSE); //HangUp
+//    }
 }
diff --git a/src/main.cpp b/src/main.cpp
index 3c81532..73300ad 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -79,6 +79,8 @@ int main(int argc, char **argv)
 
       KAboutData::setApplicationData(about);
 
+      Cmd::parseCmd(argc, argv, about);
+
       app = new RingApplication(argc, argv);
 
       const int retVal = app->exec();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic