Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linphone-desktop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
linphone-desktop
Commits
0721a22b
Commit
0721a22b
authored
Sep 06, 2017
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(Cli): Cli is now a static object + clean code
parent
e43fb27a
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
150 additions
and
166 deletions
+150
-166
en.ts
assets/languages/en.ts
+3
-3
fr.ts
assets/languages/fr.ts
+3
-3
App.cpp
src/app/App.cpp
+7
-10
App.hpp
src/app/App.hpp
+0
-3
Cli.cpp
src/app/cli/Cli.cpp
+120
-131
Cli.hpp
src/app/cli/Cli.hpp
+17
-16
No files found.
assets/languages/en.ts
View file @
0721a22b
...
@@ -69,12 +69,12 @@
...
@@ -69,12 +69,12 @@
<
translation
>
show
app
version
<
/translation
>
<
translation
>
show
app
version
<
/translation
>
<
/message
>
<
/message
>
<
message
>
<
message
>
<
source
>
commandLineCliHelp
<
/source
>
<
source
>
commandLine
Option
CliHelp
<
/source
>
<
translation
>
displays
the
help
menu
to
use
Linphone
with
the
CLI
.
<
/translation
>
<
translation
>
displays
the
help
menu
to
use
Linphone
with
the
CLI
<
/translation
>
<
/message
>
<
/message
>
<
message
>
<
message
>
<
source
>
commandLineDescription
<
/source
>
<
source
>
commandLineDescription
<
/source
>
<
translation
>
send
a
an
order
to
the
application
towards
a
command
line
.
<
/translation
>
<
translation
>
send
a
n
order
to
the
application
towards
a
command
line
<
/translation
>
<
/message
>
<
/message
>
<
/context
>
<
/context
>
<
context
>
<
context
>
...
...
assets/languages/fr.ts
View file @
0721a22b
...
@@ -69,12 +69,12 @@
...
@@ -69,12 +69,12 @@
<
translation
>
affiche
la
version
de
l
&
apos
;
application
<
/translation
>
<
translation
>
affiche
la
version
de
l
&
apos
;
application
<
/translation
>
<
/message
>
<
/message
>
<
message
>
<
message
>
<
source
>
commandLineCliHelp
<
/source
>
<
source
>
commandLine
Option
CliHelp
<
/source
>
<
translation
>
affiche
le
menu
d
&
apos
;
aide
pour
l
&
apos
;
utilisation
de
Linphone
en
CLI
.
<
/translation
>
<
translation
>
affiche
le
menu
d
&
apos
;
aide
pour
l
&
apos
;
utilisation
de
Linphone
en
CLI
<
/translation
>
<
/message
>
<
/message
>
<
message
>
<
message
>
<
source
>
commandLineDescription
<
/source
>
<
source
>
commandLineDescription
<
/source
>
<
translation
>
envoie
un
ordre
à
l
&
apos
;
application
Linphone
,
voir
--
cli
-
help
pour
plus
de
d
é
tails
.
<
/translation
>
<
translation
>
envoie
un
ordre
à
l
&
apos
;
application
Linphone
,
voir
--
cli
-
help
pour
plus
de
d
é
tails
<
/translation
>
<
/message
>
<
/message
>
<
/context
>
<
/context
>
<
context
>
<
context
>
...
...
src/app/App.cpp
View file @
0721a22b
...
@@ -100,9 +100,8 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::U
...
@@ -100,9 +100,8 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::U
mParser
->
showHelp
();
mParser
->
showHelp
();
}
}
if
(
mParser
->
isSet
(
"cli-help"
)){
if
(
mParser
->
isSet
(
"cli-help"
))
{
mCli
=
new
Cli
(
this
);
Cli
::
showHelp
();
mCli
->
showHelp
();
::
exit
(
EXIT_SUCCESS
);
::
exit
(
EXIT_SUCCESS
);
}
}
...
@@ -168,11 +167,10 @@ void App::initContentApp () {
...
@@ -168,11 +167,10 @@ void App::initContentApp () {
setQuitOnLastWindowClosed
(
false
);
setQuitOnLastWindowClosed
(
false
);
// Deal with received messages and CLI.
// Deal with received messages and CLI.
mCli
=
new
Cli
(
this
);
QObject
::
connect
(
this
,
&
App
::
receivedMessage
,
this
,
[
this
](
int
,
const
QByteArray
&
byteArray
)
{
QObject
::
connect
(
this
,
&
App
::
receivedMessage
,
this
,
[
this
](
int
,
const
QByteArray
&
byteArray
)
{
QString
command
(
byteArray
);
QString
command
(
byteArray
);
qInfo
()
<<
QStringLiteral
(
"Received command from other application: `%1`."
).
arg
(
command
);
qInfo
()
<<
QStringLiteral
(
"Received command from other application: `%1`."
).
arg
(
command
);
mCli
->
executeCommand
(
command
);
Cli
::
executeCommand
(
command
);
});
});
// Add plugins directory.
// Add plugins directory.
...
@@ -190,7 +188,7 @@ void App::initContentApp () {
...
@@ -190,7 +188,7 @@ void App::initContentApp () {
const
QString
commandArgument
=
getCommandArgument
();
const
QString
commandArgument
=
getCommandArgument
();
if
(
!
commandArgument
.
isEmpty
())
{
if
(
!
commandArgument
.
isEmpty
())
{
Cli
::
CommandFormat
format
;
Cli
::
CommandFormat
format
;
mCli
->
executeCommand
(
commandArgument
,
&
format
);
Cli
::
executeCommand
(
commandArgument
,
&
format
);
if
(
format
==
Cli
::
UriFormat
)
if
(
format
==
Cli
::
UriFormat
)
mustBeIconified
=
true
;
mustBeIconified
=
true
;
}
}
...
@@ -254,8 +252,7 @@ QString App::getCommandArgument () {
...
@@ -254,8 +252,7 @@ QString App::getCommandArgument () {
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void
App
::
executeCommand
(
const
QString
&
command
)
{
void
App
::
executeCommand
(
const
QString
&
command
)
{
Q_CHECK_PTR
(
mCli
);
Cli
::
executeCommand
(
command
);
mCli
->
executeCommand
(
command
);
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
...
@@ -333,10 +330,10 @@ void App::createParser () {
...
@@ -333,10 +330,10 @@ void App::createParser () {
mParser
=
new
QCommandLineParser
();
mParser
=
new
QCommandLineParser
();
mParser
->
setApplicationDescription
(
tr
(
"applicationDescription"
));
mParser
->
setApplicationDescription
(
tr
(
"applicationDescription"
));
mParser
->
addPositionalArgument
(
"command"
,
tr
(
"commandLineDescription"
),
"[command]"
);
mParser
->
addPositionalArgument
(
"command"
,
tr
(
"commandLineDescription"
),
"[command]"
);
mParser
->
addOptions
({
mParser
->
addOptions
({
{
{
"h"
,
"help"
},
tr
(
"commandLineOptionHelp"
)
},
{
{
"h"
,
"help"
},
tr
(
"commandLineOptionHelp"
)
},
{
"cli-help"
,
tr
(
"commandLineCliHelp"
)
},
{
"cli-help"
,
tr
(
"commandLine
Option
CliHelp"
)
},
{
{
"v"
,
"version"
},
tr
(
"commandLineOptionVersion"
)
},
{
{
"v"
,
"version"
},
tr
(
"commandLineOptionVersion"
)
},
{
"config"
,
tr
(
"commandLineOptionConfig"
),
tr
(
"commandLineOptionConfigArg"
)
},
{
"config"
,
tr
(
"commandLineOptionConfig"
),
tr
(
"commandLineOptionConfigArg"
)
},
#ifndef Q_OS_MACOS
#ifndef Q_OS_MACOS
...
...
src/app/App.hpp
View file @
0721a22b
...
@@ -37,7 +37,6 @@
...
@@ -37,7 +37,6 @@
class
QCommandLineParser
;
class
QCommandLineParser
;
class
QSystemTrayIcon
;
class
QSystemTrayIcon
;
class
Cli
;
class
DefaultTranslator
;
class
DefaultTranslator
;
class
App
:
public
SingleApplication
{
class
App
:
public
SingleApplication
{
...
@@ -143,8 +142,6 @@ private:
...
@@ -143,8 +142,6 @@ private:
Colors
*
mColors
=
nullptr
;
Colors
*
mColors
=
nullptr
;
QSystemTrayIcon
*
mSystemTrayIcon
=
nullptr
;
QSystemTrayIcon
*
mSystemTrayIcon
=
nullptr
;
Cli
*
mCli
=
nullptr
;
};
};
#endif // APP_H_
#endif // APP_H_
src/app/cli/Cli.cpp
View file @
0721a22b
This diff is collapsed.
Click to expand it.
src/app/cli/Cli.hpp
View file @
0721a22b
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#include <memory>
#include <memory>
#include <QHash>
#include <QHash>
#include <QMap>
#include <QObject>
#include <QObject>
// =============================================================================
// =============================================================================
...
@@ -58,8 +59,8 @@ class Cli : public QObject {
...
@@ -58,8 +59,8 @@ class Cli : public QObject {
Command
()
=
default
;
Command
()
=
default
;
Command
(
Command
(
const
QString
&
functionName
,
const
QString
&
functionName
,
const
QString
&
functionDescription
,
const
char
*
functionDescription
,
const
QString
&
cliDescription
,
const
char
*
cliDescription
,
Function
function
,
Function
function
,
const
QHash
<
QString
,
Argument
>
&
argsScheme
const
QHash
<
QString
,
Argument
>
&
argsScheme
);
);
...
@@ -67,25 +68,23 @@ class Cli : public QObject {
...
@@ -67,25 +68,23 @@ class Cli : public QObject {
void
execute
(
QHash
<
QString
,
QString
>
&
args
)
const
;
void
execute
(
QHash
<
QString
,
QString
>
&
args
)
const
;
void
executeUri
(
const
std
::
shared_ptr
<
linphone
::
Address
>
&
address
)
const
;
void
executeUri
(
const
std
::
shared_ptr
<
linphone
::
Address
>
&
address
)
const
;
QString
getFunctionDescription
()
{
const
char
*
getFunctionDescription
()
const
{
return
mFunctionDescription
;
return
mFunctionDescription
;
}
}
QString
getCliDescription
()
{
const
char
*
getCliDescription
()
const
{
return
mCliDescription
;
return
mCliDescription
;
}
}
private:
private:
QString
mFunctionDescription
;
QString
mCliDescription
;
QString
mFunctionName
;
QString
mFunctionName
;
const
char
*
mFunctionDescription
;
const
char
*
mCliDescription
;
Function
mFunction
=
nullptr
;
Function
mFunction
=
nullptr
;
QHash
<
QString
,
Argument
>
mArgsScheme
;
QHash
<
QString
,
Argument
>
mArgsScheme
;
};
};
public:
public:
Cli
(
QObject
*
parent
=
Q_NULLPTR
);
~
Cli
()
=
default
;
~
Cli
()
=
default
;
enum
CommandFormat
{
enum
CommandFormat
{
...
@@ -94,23 +93,25 @@ public:
...
@@ -94,23 +93,25 @@ public:
UriFormat
UriFormat
};
};
void
executeCommand
(
const
QString
&
command
,
CommandFormat
*
format
=
nullptr
)
const
;
static
void
executeCommand
(
const
QString
&
command
,
CommandFormat
*
format
=
nullptr
)
;
void
showHelp
();
static
void
showHelp
();
private:
private:
void
addCommand
(
Cli
();
static
std
::
pair
<
QString
,
Command
>
createCommand
(
const
QString
&
functionName
,
const
QString
&
functionName
,
const
QString
&
functionDescription
,
const
char
*
functionDescription
,
const
QString
&
cliDescription
,
const
char
*
cliDescription
,
Function
function
,
Function
function
,
const
QHash
<
QString
,
Argument
>
&
argsScheme
=
QHash
<
QString
,
Argument
>
()
const
QHash
<
QString
,
Argument
>
&
argsScheme
=
QHash
<
QString
,
Argument
>
()
);
);
QString
parseFunctionName
(
const
QString
&
command
)
const
;
static
QString
parseFunctionName
(
const
QString
&
command
)
;
QHash
<
QString
,
QString
>
parseArgs
(
const
QString
&
command
)
const
;
static
QHash
<
QString
,
QString
>
parseArgs
(
const
QString
&
command
)
;
QHash
<
QString
,
Command
>
mCommands
;
static
QMap
<
QString
,
Command
>
mCommands
;
static
QRegExp
mRegExpArgs
;
static
QRegExp
mRegExpArgs
;
static
QRegExp
mRegExpFunctionName
;
static
QRegExp
mRegExpFunctionName
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment