Skip to content

Commit

Permalink
Implement "mumble rpc" subcommand
Browse files Browse the repository at this point in the history
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 bc5852d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 12 deletions.
17 changes: 16 additions & 1 deletion src/mumble/SocketRPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
81 changes: 70 additions & 11 deletions src/mumble/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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"
Expand All @@ -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());
}
}
}
}
Expand All @@ -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
Expand Down

0 comments on commit bc5852d

Please sign in to comment.