Skip to content
Permalink
Browse files

Implement "mumble rpc" subcommand

This allows users to more easily issue SocketRPC
requests to a running Mumble client.

Currently, only commands for muting/deafning are
supported.

Example:

  $ mumble rpc mute    # Mute a running Mumble client
  $ mumble rpc unmute  # Unmute a running Mumble client
  [...]

Supported commands are currently:

  'mute' - Unmute self
  'unmute' - Unmute self
  'deaf' - Deafen self
  'undeaf' - Undeafen self

(You can also see them via 'mumble rpc --help')
  • Loading branch information...
meisekimiu authored and mkrautz committed Feb 8, 2015
1 parent 44dc94e commit bc5852d3dc8e54a44bf4b476e7e0a78968260bae
Showing with 86 additions and 12 deletions.
  1. +16 −1 src/mumble/SocketRPC.cpp
  2. +70 −11 src/mumble/main.cpp
@@ -137,6 +137,14 @@ void SocketRPCClient::processXml() {
g.mw->qaAudioMute->trigger();
}
}
iter = qmRequest.find(QLatin1String("unmute"));
if (iter != qmRequest.constEnd()) {
bool set = iter.value().toBool();
if (set == g.s.bMute) {
g.mw->qaAudioMute->setChecked(set);
g.mw->qaAudioMute->trigger();
}
}
iter = qmRequest.find(QLatin1String("deaf"));
if (iter != qmRequest.constEnd()) {
bool set = iter.value().toBool();
@@ -145,7 +153,14 @@ void SocketRPCClient::processXml() {
g.mw->qaAudioDeaf->trigger();
}
}

iter = qmRequest.find(QLatin1String("undeaf"));
if (iter != qmRequest.constEnd()) {
bool set = iter.value().toBool();
if (set == g.s.bDeaf) {
g.mw->qaAudioDeaf->setChecked(set);
g.mw->qaAudioDeaf->trigger();
}
}
ack = true;
} else if (request.nodeName() == QLatin1String("url")) {
if (g.sh && g.sh->isRunning() && g.uiSession) {
@@ -129,6 +129,8 @@ int main(int argc, char **argv) {
#endif

bool bAllowMultiple = false;
bool bRpcMode = false;
QString rpcCommand;
QUrl url;
if (a.arguments().count() > 1) {
QStringList args = a.arguments();
@@ -138,7 +140,8 @@ int main(int argc, char **argv) {
|| args.at(i) == QLatin1String("/?")
#endif
) {
QString helpmessage = MainWindow::tr( "Usage: mumble [options] [<url>]\n"
QString helpMessage = MainWindow::tr(
"Usage: mumble [options] [<url>]\n"
"\n"
"<url> specifies a URL to connect to after startup instead of showing\n"
"the connection window, and has the following form:\n"
@@ -153,25 +156,69 @@ int main(int argc, char **argv) {
" Allow multiple instances of the client to be started.\n"
" -n, --noidentity\n"
" Suppress loading of identity files (i.e., certificates.)\n"
);
"\n"
);
QString rpcHelpBanner = MainWindow::tr(
"Remote controlling Mumble:\n"
"\n"
);
QString rpcHelpMessage = MainWindow::tr(
"Usage: mumble rpc <action> [options]\n"
"\n"
"It is possible to remote control a running instance of Mumble by using\n"
"the 'mumble rpc' command.\n"
"\n"
"Valid actions are:\n"
" mute\n"
" Mute self\n"
" unmute\n"
" Unmute self\n"
" deaf\n"
" Deafen self\n"
" undeaf\n"
" Undeafen self\n"
"\n"
);

QString helpOutput = helpMessage + rpcHelpBanner + rpcHelpMessage;
if (bRpcMode) {
helpOutput = rpcHelpMessage;
}

#if defined(Q_OS_WIN)
QMessageBox::information(NULL, MainWindow::tr("Invocation"), helpmessage);
QMessageBox::information(NULL, MainWindow::tr("Invocation"), helpOutput);
#else
printf("%s", qPrintable(helpmessage));
printf("%s", qPrintable(helpOutput));
#endif
return 1;
} else if (args.at(i) == QLatin1String("-m") || args.at(i) == QLatin1String("--multiple")) {
bAllowMultiple = true;
} else if (args.at(i) == QLatin1String("-n") || args.at(i) == QLatin1String("--noidentity")) {
g.s.bSuppressIdentity = true;
} else if (args.at(i) == QLatin1String("rpc")) {
bRpcMode = true;
if (args.count() - 1 > i) {
rpcCommand = QString(args.at(i + 1));
}
else {
QString rpcError = MainWindow::tr("Error: No RPC command specified");
#if defined(Q_OS_WIN)
QMessageBox::information(NULL, MainWindow::tr("RPC"), rpcError);
#else
printf("%s\n", qPrintable(rpcError));
#endif
return 1;
}
} else {
QUrl u = QUrl::fromEncoded(args.at(i).toUtf8());
if (u.isValid() && (u.scheme() == QLatin1String("mumble"))) {
url = u;
} else {
QFile f(args.at(i));
if (f.exists()) {
url = QUrl::fromLocalFile(f.fileName());
if (!bRpcMode) {
QUrl u = QUrl::fromEncoded(args.at(i).toUtf8());
if (u.isValid() && (u.scheme() == QLatin1String("mumble"))) {
url = u;
} else {
QFile f(args.at(i));
if (f.exists()) {
url = QUrl::fromLocalFile(f.fileName());
}
}
}
}
@@ -198,6 +245,18 @@ int main(int argc, char **argv) {
#endif
#endif

if (bRpcMode) {
bool sent = false;
QMap<QString, QVariant> param;
param.insert(rpcCommand, rpcCommand);
sent = SocketRPC::send(QLatin1String("Mumble"), QLatin1String("self"), param);
if (sent) {
return 0;
} else {
return 1;
}
}

if (! bAllowMultiple) {
if (url.isValid()) {
#ifndef USE_DBUS

0 comments on commit bc5852d

Please sign in to comment.
You can’t perform that action at this time.