Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a gxmessage dialog backend

Tried after kdialog and zenity but before xmessage.
  • Loading branch information...
commit e40d82be20c6822b0337c9b46e054a9515375267 1 parent 57a7128
@dscharrer dscharrer authored
Showing with 26 additions and 12 deletions.
  1. +26 −12 src/platform/Dialog.cpp
View
38 src/platform/Dialog.cpp
@@ -31,6 +31,7 @@
#endif
#include <boost/format.hpp>
+#include <boost/foreach.hpp>
#include "io/log/Logger.h"
#include "platform/String.h"
@@ -226,6 +227,24 @@ int kdialogCommand(DialogType type, const std::string & message,
return system(command.str().c_str());
}
+int gxmessageCommand(DialogType type, const std::string & message,
+ const std::string & dialogTitle) {
+
+ const char * options = "";
+ switch(type) {
+ default: options = "-buttons OK"; break;
+ case DialogYesNo: options = "-buttons Yes:0,No:1"; break;
+ case DialogOkCancel: options = "-buttons OK:0,Cancel:1"; break;
+ }
+
+ boost::format command("gxmessage -center %1% -title \"%2%\" \"%3%\"");
+ command = command % options;
+ command = command % escape(dialogTitle);
+ command = command % escape(message);
+
+ return system(command.str().c_str());
+}
+
int xmessageCommand(DialogType type, const std::string & message,
const std::string & dialogTitle) {
@@ -250,7 +269,6 @@ bool showDialog(DialogType type, const std::string & message,
typedef int (*dialogCommand_t)(DialogType type, const std::string & message,
const std::string & dialogTitle);
- std::vector<dialogCommand_t> commands;
// This may not be the best way
const char * session = getenv("DESKTOP_SESSION");
@@ -259,18 +277,14 @@ bool showDialog(DialogType type, const std::string & message,
usingKDE = usingKDE || (getenv("KDE_SESSION_UID") != NULL);
usingKDE = usingKDE || (getenv("KDE_SESSION_VERSION") != NULL);
- if(usingKDE) {
- commands.push_back(&kdialogCommand);
- commands.push_back(&zenityCommand);
- } else {
- commands.push_back(&zenityCommand);
- commands.push_back(&kdialogCommand);
- }
- commands.push_back(&xmessageCommand);
+ dialogCommand_t commands[4];
+ commands[0] = usingKDE ? &kdialogCommand : &zenityCommand;
+ commands[1] = usingKDE ? &zenityCommand : &kdialogCommand;
+ commands[2] = &gxmessageCommand;
+ commands[3] = &xmessageCommand;
- for(std::vector<dialogCommand_t>::const_iterator it = commands.begin();
- it != commands.end(); ++it) {
- int exitCode = (*it)(type, message, dialogTitle);
+ BOOST_FOREACH(dialogCommand_t command, commands) {
+ int exitCode = command(type, message, dialogTitle);
if(WIFEXITED(exitCode) && WEXITSTATUS(exitCode) >= 0
&& WEXITSTATUS(exitCode) < 127) {
return WEXITSTATUS(exitCode) == 0;
Please sign in to comment.
Something went wrong with that request. Please try again.