diff --git a/src/chatdlg.cpp b/src/chatdlg.cpp
index 9e275633ea..8d8c7c3efa 100644
--- a/src/chatdlg.cpp
+++ b/src/chatdlg.cpp
@@ -140,8 +140,8 @@ void CChatDlg::OnAnchorClicked ( const QUrl& Url )
// only allow http(s) URLs to be opened in an external browser
if ( Url.scheme() == QLatin1String ( "https" ) || Url.scheme() == QLatin1String ( "http" ) )
{
- if ( QMessageBox::question ( this,
- APP_NAME,
+ if ( QMessageBox::question ( CMsgBoxes::MainForm(),
+ CMsgBoxes::MainFormName(),
tr ( "Do you want to open the link '%1' in your browser?" ).arg ( "" + Url.toString() + "" ),
QMessageBox::Yes | QMessageBox::No ) == QMessageBox::Yes )
{
diff --git a/src/clientdlg.cpp b/src/clientdlg.cpp
index c94c03b707..346eb916ad 100644
--- a/src/clientdlg.cpp
+++ b/src/clientdlg.cpp
@@ -1059,7 +1059,8 @@ void CClientDlg::OnTimerSigMet()
// show message box about feedback issue
QCheckBox* chb = new QCheckBox ( tr ( "Enable feedback detection" ) );
chb->setCheckState ( pSettings->bEnableFeedbackDetection ? Qt::Checked : Qt::Unchecked );
- QMessageBox msgbox;
+ QMessageBox msgbox ( CMsgBoxes::MainForm() );
+ msgbox.setWindowTitle ( CMsgBoxes::MainFormName() + ": " + tr ( "Warning" ) );
msgbox.setText ( tr ( "Audio feedback or loud signal detected.\n\n"
"We muted your channel and activated 'Mute Myself'. Please solve "
"the feedback issue first and unmute yourself afterwards." ) );
@@ -1143,10 +1144,8 @@ void CClientDlg::OnTimerCheckAudioDeviceOk()
// it is trying to connect the server which does not help to solve the problem (#129))
if ( !pClient->IsCallbackEntered() )
{
- QMessageBox::warning ( this,
- APP_NAME,
- tr ( "Your sound card is not working correctly. "
- "Please open the settings dialog and check the device selection and the driver settings." ) );
+ CMsgBoxes::ShowWarning ( tr ( "Your sound card is not working correctly. "
+ "Please open the settings dialog and check the device selection and the driver settings." ) );
}
}
@@ -1163,7 +1162,7 @@ void CClientDlg::OnSoundDeviceChanged ( QString strError )
}
// show the error message of the device setup
- QMessageBox::critical ( this, APP_NAME, strError, tr ( "Ok" ), nullptr );
+ CMsgBoxes::ShowError ( strError );
}
// if the check audio device timer is running, it must be restarted on a device change
@@ -1206,7 +1205,7 @@ void CClientDlg::Connect ( const QString& strSelectedAddress, const QString& str
catch ( const CGenErr& generr )
{
// show error message and return the function
- QMessageBox::critical ( this, APP_NAME, generr.GetErrorText(), "Close", nullptr );
+ CMsgBoxes::ShowError ( generr.GetErrorText() );
return;
}
diff --git a/src/global.h b/src/global.h
index 22ae0c52bf..14e30eb0f7 100644
--- a/src/global.h
+++ b/src/global.h
@@ -358,19 +358,211 @@ class CCustomEvent : public QEvent
int iChanNum;
};
-/* Prototypes for global functions ********************************************/
-// command line parsing, TODO do not declare functions globally but in a class
-QString UsageArguments ( char** argv );
-
-bool GetFlagArgument ( char** argv, int& i, QString strShortOpt, QString strLongOpt );
-
-bool GetStringArgument ( int argc, char** argv, int& i, QString strShortOpt, QString strLongOpt, QString& strArg );
-
-bool GetNumericArgument ( int argc,
- char** argv,
- int& i,
- QString strShortOpt,
- QString strLongOpt,
- double rRangeStart,
- double rRangeStop,
- double& rValue );
+//============================================================================
+// CMsgBoxes class:
+// Use this static class to show basic Error, Warning and Info messageboxes
+// For own created message boxes you should still use
+// CMsgBoxes::MainForm() and CMsgBoxes::MainFormName()
+//============================================================================
+#ifndef HEADLESS
+# include
+# define tMainform QDialog
+#else
+# define tMainform void
+#endif
+
+// html text macro's (for use in message texts)
+#define htmlBold( T ) "" + T + ""
+#define htmlNewLine() "
"
+
+class CMsgBoxes
+{
+protected:
+ static tMainform* pMainForm;
+ static QString strMainFormName;
+
+public:
+ static void init ( tMainform* theMainForm, QString theMainFormName )
+ {
+ pMainForm = theMainForm;
+ strMainFormName = theMainFormName;
+ }
+
+ static tMainform* MainForm() { return pMainForm; }
+ static const QString& MainFormName() { return strMainFormName; }
+
+ // Message boxes:
+ static void ShowError ( QString strError );
+ static void ShowWarning ( QString strWarning );
+ static void ShowInfo ( QString strInfo );
+};
+
+//============================================================================
+// CCommandline class:
+// Note that passing commandline arguments to classes is no longer required,
+// since via this class we can get commandline options anywhere.
+//============================================================================
+
+class CCommandline
+{
+public:
+ CCommandline() { reset(); }
+
+private:
+ friend int main ( int argc, char** argv );
+
+ // Statics assigned from main ()
+ static int argc;
+ static char** argv;
+
+public:
+ static QString GetProgramPath() { return QString ( *argv ); }
+
+public:
+ // sequencial parse functions using the argument index:
+
+ static bool GetFlagArgument ( int& i, const QString& strShortOpt, const QString& strLongOpt );
+
+ static bool GetStringArgument ( int& i, const QString& strShortOpt, const QString& strLongOpt, QString& strArg );
+
+ static bool GetNumericArgument ( int& i,
+ const QString& strShortOpt,
+ const QString& strLongOpt,
+ double rRangeStart,
+ double rRangeStop,
+ double& rValue );
+
+public:
+ // find and get a specific argument:
+
+ static bool GetFlagArgument ( const QString& strShortOpt, const QString& strLongOpt )
+ {
+ for ( int i = 1; i < argc; i++ )
+ {
+ if ( GetFlagArgument ( i, strShortOpt, strLongOpt ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ static bool GetStringArgument ( const QString& strShortOpt, const QString& strLongOpt, QString& strArg )
+ {
+ for ( int i = 1; i < argc; i++ )
+ {
+ if ( GetStringArgument ( i, strShortOpt, strLongOpt, strArg ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ static bool GetNumericArgument ( const QString& strShortOpt, const QString& strLongOpt, double rRangeStart, double rRangeStop, double& rValue )
+ {
+ for ( int i = 1; i < argc; i++ )
+ {
+ if ( GetNumericArgument ( i, strShortOpt, strLongOpt, rRangeStart, rRangeStop, rValue ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ //=================================================
+ // Non statics to parse bare arguments
+ // (These need an instance of CCommandline)
+ //=================================================
+
+protected:
+ int currentIndex;
+ char** currentArgv;
+
+ void reset()
+ {
+ currentArgv = argv;
+ currentIndex = 0;
+ }
+
+public:
+ QString GetFirstArgument()
+ {
+ reset();
+ // Skipping program path
+ return GetNextArgument();
+ }
+
+ QString GetNextArgument()
+ {
+ if ( currentIndex < argc )
+ {
+ currentArgv++;
+ currentIndex++;
+
+ if ( currentIndex < argc )
+ {
+ return QString ( *currentArgv );
+ }
+ }
+
+ return QString();
+ }
+};
+
+// defines for commandline options in the style "shortopt", "longopt"
+// Name is standard CMDLN_LONGOPTNAME
+// These defines can be used for strShortOpt, strLongOpt parameters
+// of the CCommandline functions.
+
+// clang-format off
+
+#define CMDLN_SERVER "-s", "--server"
+#define CMDLN_INIFILE "-i", "--inifile"
+#define CMDLN_NOGUI "-n", "--nogui"
+#define CMDLN_PORT "-p", "--port"
+#define CMDLN_JSONRPCPORT "--jsonrpcport", "--jsonrpcport"
+#define CMDLN_JSONRPCSECRETFILE "--jsonrpcsecretfile", "--jsonrpcsecretfile"
+#define CMDLN_QOS "-Q", "--qos"
+#define CMDLN_NOTRANSLATION "-t", "--notranslation"
+#define CMDLN_ENABLEIPV6 "-6", "--enableipv6"
+#define CMDLN_DISCONONQUIT "-d", "--discononquit"
+#define CMDLN_DIRECTORYSERVER "-e", "--directoryserver"
+#define CMDLN_DIRECTORYFILE "--directoryfile", "--directoryfile"
+#define CMDLN_LISTFILTER "-f", "--listfilter"
+#define CMDLN_FASTUPDATE "-F", "--fastupdate"
+#define CMDLN_LOG "-l", "--log"
+#define CMDLN_LICENCE "-L", "--licence"
+#define CMDLN_HTMLSTATUS "-m", "--htmlstatus"
+#define CMDLN_SERVERINFO "-o", "--serverinfo"
+#define CMDLN_SERVERPUBLICIP "--serverpublicip", "--serverpublicip"
+#define CMDLN_DELAYPAN "-P", "--delaypan"
+#define CMDLN_RECORDING "-R", "--recording"
+#define CMDLN_NORECORD "--norecord", "--norecord"
+#define CMDLN_SERVERBINDIP "--serverbindip", "--serverbindip"
+#define CMDLN_MULTITHREADING "-T", "--multithreading"
+#define CMDLN_NUMCHANNELS "-u", "--numchannels"
+#define CMDLN_WELCOMEMESSAGE "-w", "--welcomemessage"
+#define CMDLN_STARTMINIMIZED "-z", "--startminimized"
+#define CMDLN_CONNECT "-c", "--connect"
+#define CMDLN_NOJACKCONNECT "-j", "--nojackconnect"
+#define CMDLN_MUTESTREAM "-M", "--mutestream"
+#define CMDLN_MUTEMYOWN "--mutemyown", "--mutemyown"
+#define CMDLN_CLIENTNAME "--clientname", "--clientname"
+#define CMDLN_CTRLMIDICH "--ctrlmidich", "--ctrlmidich"
+// Backwards compatibilyty:
+#define CMDLN_CENTRALSERVER "--centralserver", "--centralserver"
+// Debug options: (not in help)
+#define CMDLN_SHOWALLSERVERS "--showallservers", "--showallservers"
+#define CMDLN_SHOWANALYZERCONSOLE "--showanalyzerconsole", "--showanalyzerconsole"
+// CMDLN_SPECIAL: Used for debugging, should NOT be in help, nor documented elsewhere!
+// any option after --special is accepted
+#define CMDLN_SPECIAL "--special", "--special"
+// Special options for sound-redesign testing
+#define CMDLN_JACKINPUTS "--jackinputs", "--jackinputs"
+
+// clang-format on
diff --git a/src/main.cpp b/src/main.cpp
index 0bc792376b..deb9b7ece7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -53,10 +53,24 @@ extern void qt_set_sequence_auto_mnemonic ( bool bEnable );
# include "clientrpc.h"
#endif
+// Forward declarations ********************************************************
+
+QString UsageArguments ( char** argv );
+
// Implementation **************************************************************
+int CCommandline::argc = 0;
+char** CCommandline::argv = NULL;
+
+tMainform* CMsgBoxes::pMainForm = NULL;
+QString CMsgBoxes::strMainFormName = APP_NAME;
+
int main ( int argc, char** argv )
{
+ CCommandline::argc = argc;
+ CCommandline::argv = argv;
+
+ CCommandline cmdLine; // We don't really need an instance here, but using one improves the readability of the code.
#if defined( Q_OS_MACX )
// Mnemonic keys are default disabled in Qt for MacOS. The following function enables them.
@@ -79,6 +93,7 @@ int main ( int argc, char** argv )
#else
bool bIsClient = true;
#endif
+ bool bSpecialOptions = false; // Any options after this option will be accepted ! (mostly used for debugging purpouses)
bool bUseGUI = true;
bool bStartMinimized = false;
bool bShowComplRegConnList = false;
@@ -149,7 +164,7 @@ int main ( int argc, char** argv )
// Common options:
// Initialization file -------------------------------------------------
- if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_INIFILE, strArgument ) )
{
strIniFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- initialization file name: %1" ).arg ( strIniFileName ) );
@@ -158,7 +173,7 @@ int main ( int argc, char** argv )
}
// Disable GUI flag ----------------------------------------------------
- if ( GetFlagArgument ( argv, i, "-n", "--nogui" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_NOGUI ) )
{
bUseGUI = false;
qInfo() << "- no GUI mode chosen";
@@ -167,7 +182,7 @@ int main ( int argc, char** argv )
}
// Port number ---------------------------------------------------------
- if ( GetNumericArgument ( argc, argv, i, "-p", "--port", 0, 65535, rDbleArgument ) )
+ if ( cmdLine.GetNumericArgument ( i, CMDLN_PORT, 0, 65535, rDbleArgument ) )
{
iPortNumber = static_cast ( rDbleArgument );
bCustomPortNumberGiven = true;
@@ -177,7 +192,7 @@ int main ( int argc, char** argv )
}
// JSON-RPC port number ------------------------------------------------
- if ( GetNumericArgument ( argc, argv, i, "--jsonrpcport", "--jsonrpcport", 0, 65535, rDbleArgument ) )
+ if ( cmdLine.GetNumericArgument ( i, CMDLN_JSONRPCPORT, 0, 65535, rDbleArgument ) )
{
iJsonRpcPortNumber = static_cast ( rDbleArgument );
qInfo() << qUtf8Printable ( QString ( "- JSON-RPC port number: %1" ).arg ( iJsonRpcPortNumber ) );
@@ -186,7 +201,7 @@ int main ( int argc, char** argv )
}
// JSON-RPC secret file name -------------------------------------------
- if ( GetStringArgument ( argc, argv, i, "--jsonrpcsecretfile", "--jsonrpcsecretfile", strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_JSONRPCSECRETFILE, strArgument ) )
{
strJsonRpcSecretFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- JSON-RPC secret file: %1" ).arg ( strJsonRpcSecretFileName ) );
@@ -195,7 +210,7 @@ int main ( int argc, char** argv )
}
// Quality of Service --------------------------------------------------
- if ( GetNumericArgument ( argc, argv, i, "-Q", "--qos", 0, 255, rDbleArgument ) )
+ if ( cmdLine.GetNumericArgument ( i, CMDLN_QOS, 0, 255, rDbleArgument ) )
{
iQosNumber = static_cast ( rDbleArgument );
qInfo() << qUtf8Printable ( QString ( "- selected QoS value: %1" ).arg ( iQosNumber ) );
@@ -204,7 +219,7 @@ int main ( int argc, char** argv )
}
// Disable translations ------------------------------------------------
- if ( GetFlagArgument ( argv, i, "-t", "--notranslation" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_NOTRANSLATION ) )
{
bUseTranslation = false;
qInfo() << "- translations disabled";
@@ -213,7 +228,7 @@ int main ( int argc, char** argv )
}
// Enable IPv6 ---------------------------------------------------------
- if ( GetFlagArgument ( argv, i, "-6", "--enableipv6" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_ENABLEIPV6 ) )
{
bEnableIPv6 = true;
qInfo() << "- IPv6 enabled";
@@ -224,7 +239,7 @@ int main ( int argc, char** argv )
// Server only:
// Disconnect all clients on quit --------------------------------------
- if ( GetFlagArgument ( argv, i, "-d", "--discononquit" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_DISCONONQUIT ) )
{
bDisconnectAllClientsOnQuit = true;
qInfo() << "- disconnect all clients on quit";
@@ -234,7 +249,7 @@ int main ( int argc, char** argv )
}
// Directory server ----------------------------------------------------
- if ( GetStringArgument ( argc, argv, i, "-e", "--directoryserver", strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_DIRECTORYSERVER, strArgument ) )
{
strDirectoryServer = strArgument;
qInfo() << qUtf8Printable ( QString ( "- directory server: %1" ).arg ( strDirectoryServer ) );
@@ -244,12 +259,7 @@ int main ( int argc, char** argv )
}
// Central server ** D E P R E C A T E D ** ----------------------------
- if ( GetStringArgument ( argc,
- argv,
- i,
- "--centralserver", // no short form
- "--centralserver",
- strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_CENTRALSERVER, strArgument ) )
{
strDirectoryServer = strArgument;
qInfo() << qUtf8Printable ( QString ( "- directory server: %1" ).arg ( strDirectoryServer ) );
@@ -259,12 +269,7 @@ int main ( int argc, char** argv )
}
// Directory file ------------------------------------------------------
- if ( GetStringArgument ( argc,
- argv,
- i,
- "--directoryfile", // no short form
- "--directoryfile",
- strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_DIRECTORYFILE, strArgument ) )
{
strServerListFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- directory server persistence file: %1" ).arg ( strServerListFileName ) );
@@ -274,7 +279,7 @@ int main ( int argc, char** argv )
}
// Server list filter --------------------------------------------------
- if ( GetStringArgument ( argc, argv, i, "-f", "--listfilter", strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_LISTFILTER, strArgument ) )
{
strServerListFilter = strArgument;
qInfo() << qUtf8Printable ( QString ( "- server list filter: %1" ).arg ( strServerListFilter ) );
@@ -284,7 +289,7 @@ int main ( int argc, char** argv )
}
// Use 64 samples frame size mode --------------------------------------
- if ( GetFlagArgument ( argv, i, "-F", "--fastupdate" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_FASTUPDATE ) )
{
bUseDoubleSystemFrameSize = false; // 64 samples frame size
qInfo() << qUtf8Printable ( QString ( "- using %1 samples frame size mode" ).arg ( SYSTEM_FRAME_SIZE_SAMPLES ) );
@@ -294,7 +299,7 @@ int main ( int argc, char** argv )
}
// Use logging ---------------------------------------------------------
- if ( GetStringArgument ( argc, argv, i, "-l", "--log", strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_LOG, strArgument ) )
{
strLoggingFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- logging file name: %1" ).arg ( strLoggingFileName ) );
@@ -304,7 +309,7 @@ int main ( int argc, char** argv )
}
// Use licence flag ----------------------------------------------------
- if ( GetFlagArgument ( argv, i, "-L", "--licence" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_LICENCE ) )
{
// LT_CREATIVECOMMONS is now used just to enable the pop up
eLicenceType = LT_CREATIVECOMMONS;
@@ -315,7 +320,7 @@ int main ( int argc, char** argv )
}
// HTML status file ----------------------------------------------------
- if ( GetStringArgument ( argc, argv, i, "-m", "--htmlstatus", strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_HTMLSTATUS, strArgument ) )
{
strHTMLStatusFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- HTML status file name: %1" ).arg ( strHTMLStatusFileName ) );
@@ -325,7 +330,7 @@ int main ( int argc, char** argv )
}
// Server info ---------------------------------------------------------
- if ( GetStringArgument ( argc, argv, i, "-o", "--serverinfo", strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_SERVERINFO, strArgument ) )
{
strServerInfo = strArgument;
qInfo() << qUtf8Printable ( QString ( "- server info: %1" ).arg ( strServerInfo ) );
@@ -335,12 +340,7 @@ int main ( int argc, char** argv )
}
// Server Public IP ----------------------------------------------------
- if ( GetStringArgument ( argc,
- argv,
- i,
- "--serverpublicip", // no short form
- "--serverpublicip",
- strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_SERVERPUBLICIP, strArgument ) )
{
strServerPublicIP = strArgument;
qInfo() << qUtf8Printable ( QString ( "- server public IP: %1" ).arg ( strServerPublicIP ) );
@@ -350,7 +350,7 @@ int main ( int argc, char** argv )
}
// Enable delay panning on startup -------------------------------------
- if ( GetFlagArgument ( argv, i, "-P", "--delaypan" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_DELAYPAN ) )
{
bDelayPan = true;
qInfo() << "- starting with delay panning";
@@ -360,7 +360,7 @@ int main ( int argc, char** argv )
}
// Recording directory -------------------------------------------------
- if ( GetStringArgument ( argc, argv, i, "-R", "--recording", strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_RECORDING, strArgument ) )
{
strRecordingDirName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- recording directory name: %1" ).arg ( strRecordingDirName ) );
@@ -370,10 +370,7 @@ int main ( int argc, char** argv )
}
// Disable recording on startup ----------------------------------------
- if ( GetFlagArgument ( argv,
- i,
- "--norecord", // no short form
- "--norecord" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_NORECORD ) )
{
bDisableRecording = true;
qInfo() << "- recording will not take place until enabled";
@@ -383,7 +380,7 @@ int main ( int argc, char** argv )
}
// Server mode flag ----------------------------------------------------
- if ( GetFlagArgument ( argv, i, "-s", "--server" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_SERVER ) )
{
bIsClient = false;
qInfo() << "- server mode chosen";
@@ -393,12 +390,7 @@ int main ( int argc, char** argv )
}
// Server Bind IP --------------------------------------------------
- if ( GetStringArgument ( argc,
- argv,
- i,
- "--serverbindip", // no short form
- "--serverbindip",
- strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_SERVERBINDIP, strArgument ) )
{
strServerBindIP = strArgument;
qInfo() << qUtf8Printable ( QString ( "- server bind IP: %1" ).arg ( strServerBindIP ) );
@@ -408,7 +400,7 @@ int main ( int argc, char** argv )
}
// Use multithreading --------------------------------------------------
- if ( GetFlagArgument ( argv, i, "-T", "--multithreading" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_MULTITHREADING ) )
{
bUseMultithreading = true;
qInfo() << "- using multithreading";
@@ -418,7 +410,7 @@ int main ( int argc, char** argv )
}
// Maximum number of channels ------------------------------------------
- if ( GetNumericArgument ( argc, argv, i, "-u", "--numchannels", 1, MAX_NUM_CHANNELS, rDbleArgument ) )
+ if ( cmdLine.GetNumericArgument ( i, CMDLN_NUMCHANNELS, 1, MAX_NUM_CHANNELS, rDbleArgument ) )
{
iNumServerChannels = static_cast ( rDbleArgument );
@@ -430,7 +422,7 @@ int main ( int argc, char** argv )
}
// Server welcome message ----------------------------------------------
- if ( GetStringArgument ( argc, argv, i, "-w", "--welcomemessage", strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_WELCOMEMESSAGE, strArgument ) )
{
strWelcomeMessage = strArgument;
qInfo() << qUtf8Printable ( QString ( "- welcome message: %1" ).arg ( strWelcomeMessage ) );
@@ -440,7 +432,7 @@ int main ( int argc, char** argv )
}
// Start minimized -----------------------------------------------------
- if ( GetFlagArgument ( argv, i, "-z", "--startminimized" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_STARTMINIMIZED ) )
{
bStartMinimized = true;
qInfo() << "- start minimized enabled";
@@ -452,7 +444,7 @@ int main ( int argc, char** argv )
// Client only:
// Connect on startup --------------------------------------------------
- if ( GetStringArgument ( argc, argv, i, "-c", "--connect", strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_CONNECT, strArgument ) )
{
strConnOnStartupAddress = NetworkUtil::FixAddress ( strArgument );
qInfo() << qUtf8Printable ( QString ( "- connect on startup to address: %1" ).arg ( strConnOnStartupAddress ) );
@@ -462,7 +454,7 @@ int main ( int argc, char** argv )
}
// Disabling auto Jack connections -------------------------------------
- if ( GetFlagArgument ( argv, i, "-j", "--nojackconnect" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_NOJACKCONNECT ) )
{
bNoAutoJackConnect = true;
qInfo() << "- disable auto Jack connections";
@@ -472,7 +464,7 @@ int main ( int argc, char** argv )
}
// Mute stream on startup ----------------------------------------------
- if ( GetFlagArgument ( argv, i, "-M", "--mutestream" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_MUTESTREAM ) )
{
bMuteStream = true;
qInfo() << "- mute stream activated";
@@ -482,10 +474,7 @@ int main ( int argc, char** argv )
}
// For headless client mute my own signal in personal mix --------------
- if ( GetFlagArgument ( argv,
- i,
- "--mutemyown", // no short form
- "--mutemyown" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_MUTEMYOWN ) )
{
bMuteMeInPersonalMix = true;
qInfo() << "- mute me in my personal mix";
@@ -495,12 +484,7 @@ int main ( int argc, char** argv )
}
// Client Name ---------------------------------------------------------
- if ( GetStringArgument ( argc,
- argv,
- i,
- "--clientname", // no short form
- "--clientname",
- strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_CLIENTNAME, strArgument ) )
{
strClientName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- client name: %1" ).arg ( strClientName ) );
@@ -510,12 +494,7 @@ int main ( int argc, char** argv )
}
// Controller MIDI channel ---------------------------------------------
- if ( GetStringArgument ( argc,
- argv,
- i,
- "--ctrlmidich", // no short form
- "--ctrlmidich",
- strArgument ) )
+ if ( cmdLine.GetStringArgument ( i, CMDLN_CTRLMIDICH, strArgument ) )
{
strMIDISetup = strArgument;
qInfo() << qUtf8Printable ( QString ( "- MIDI controller settings: %1" ).arg ( strMIDISetup ) );
@@ -530,10 +509,7 @@ int main ( int argc, char** argv )
// Undocumented debugging command line argument: Show all registered
// servers in the server list regardless if a ping to the server is
// possible or not.
- if ( GetFlagArgument ( argv,
- i,
- "--showallservers", // no short form
- "--showallservers" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_SHOWALLSERVERS ) )
{
bShowComplRegConnList = true;
qInfo() << "- show all registered servers in server list";
@@ -545,10 +521,7 @@ int main ( int argc, char** argv )
// Show analyzer console -----------------------------------------------
// Undocumented debugging command line argument: Show the analyzer
// console to debug network buffer properties.
- if ( GetFlagArgument ( argv,
- i,
- "--showanalyzerconsole", // no short form
- "--showanalyzerconsole" ) )
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_SHOWANALYZERCONSOLE ) )
{
bShowAnalyzerConsole = true;
qInfo() << "- show analyzer console";
@@ -557,14 +530,27 @@ int main ( int argc, char** argv )
continue;
}
- // Unknown option ------------------------------------------------------
- qCritical() << qUtf8Printable ( QString ( "%1: Unknown option '%2' -- use '--help' for help" ).arg ( argv[0] ).arg ( argv[i] ) );
+ // Enable Special Options ----------------------------------------------
+ if ( cmdLine.GetFlagArgument ( i, CMDLN_SPECIAL ) )
+ {
+ bSpecialOptions = true;
+ qInfo() << "- Special options enabled !";
+ continue;
+ }
+
+ // No exit for options after the "--special" option.
+ // Used for debugging and testing new options...
+ if ( !bSpecialOptions )
+ {
+ // Unknown option ------------------------------------------------------
+ qCritical() << qUtf8Printable ( QString ( "%1: Unknown option '%2' -- use '--help' for help" ).arg ( argv[0] ).arg ( argv[i] ) );
// clicking on the Mac application bundle, the actual application
// is called with weird command line args -> do not exit on these
#if !( defined( Q_OS_MACX ) )
- exit ( 1 );
+ exit ( 1 );
#endif
+ }
}
// Dependencies ------------------------------------------------------------
@@ -596,8 +582,7 @@ int main ( int argc, char** argv )
if ( ServerOnlyOptions.size() != 0 )
{
qCritical() << qUtf8Printable ( QString ( "%1: Server only option(s) '%2' used. Did you omit '--server'?" )
- .arg ( argv[0] )
- .arg ( ServerOnlyOptions.join ( ", " ) ) );
+ .arg ( CCommandline::GetProgramPath(), ServerOnlyOptions.join ( ", " ) ) );
exit ( 1 );
}
@@ -901,6 +886,9 @@ int main ( int argc, char** argv )
bEnableIPv6,
nullptr );
+ // initialise message boxes
+ CMsgBoxes::init ( &ClientDlg, strClientName.isEmpty() ? QString ( APP_NAME ) : QString ( APP_NAME ) + " " + strClientName );
+
// show dialog
ClientDlg.show();
pApp->exec();
@@ -911,6 +899,9 @@ int main ( int argc, char** argv )
// only start application without using the GUI
qInfo() << qUtf8Printable ( GetVersionAndNameStr ( false ) );
+ // initialise message boxes
+ CMsgBoxes::init ( NULL, strClientName.isEmpty() ? QString ( APP_NAME ) : QString ( APP_NAME ) + " " + strClientName );
+
pApp->exec();
}
}
@@ -961,6 +952,9 @@ int main ( int argc, char** argv )
// GUI object for the server
CServerDlg ServerDlg ( &Server, &Settings, bStartMinimized, nullptr );
+ // initialise message boxes
+ CMsgBoxes::init ( &ServerDlg, strClientName.isEmpty() ? QString ( APP_NAME ) : QString ( APP_NAME ) + " " + strClientName );
+
// show dialog (if not the minimized flag is set)
if ( !bStartMinimized )
{
@@ -982,6 +976,9 @@ int main ( int argc, char** argv )
Server.SetDirectoryType ( AT_CUSTOM );
}
+ // initialise message boxes
+ CMsgBoxes::init ( NULL, strClientName.isEmpty() ? QString ( APP_NAME ) : QString ( APP_NAME ) + " " + strClientName );
+
pApp->exec();
}
}
@@ -993,7 +990,7 @@ int main ( int argc, char** argv )
#ifndef HEADLESS
if ( bUseGUI )
{
- QMessageBox::critical ( nullptr, APP_NAME, generr.GetErrorText(), "Quit", nullptr );
+ CMsgBoxes::ShowError ( generr.GetErrorText() );
}
else
#endif
@@ -1010,6 +1007,36 @@ int main ( int argc, char** argv )
return 0;
}
+/******************************************************************************\
+* Message Boxes *
+\******************************************************************************/
+void CMsgBoxes::ShowError ( QString strError )
+{
+#ifndef HEADLESS
+ QMessageBox::critical ( pMainForm, strMainFormName + ": " + QObject::tr ( "Error" ), strError, QObject::tr ( "Ok" ), nullptr );
+#else
+ qCritical() << "Error: " << strError.toLocal8Bit().data();
+#endif
+}
+
+void CMsgBoxes::ShowWarning ( QString strWarning )
+{
+#ifndef HEADLESS
+ QMessageBox::warning ( pMainForm, strMainFormName + ": " + QObject::tr ( "Warning" ), strWarning, QObject::tr ( "Ok" ), nullptr );
+#else
+ qWarning() << "Warning: " << strWarning.toLocal8Bit().data();
+#endif
+}
+
+void CMsgBoxes::ShowInfo ( QString strInfo )
+{
+#ifndef HEADLESS
+ QMessageBox::information ( pMainForm, strMainFormName + ": " + QObject::tr ( "Information" ), strInfo, QObject::tr ( "Ok" ), nullptr );
+#else
+ qInfo() << "Info: " << strInfo.toLocal8Bit().data();
+#endif
+}
+
/******************************************************************************\
* Command Line Argument Parsing *
\******************************************************************************/
@@ -1083,7 +1110,7 @@ QString UsageArguments ( char** argv )
// clang-format on
}
-bool GetFlagArgument ( char** argv, int& i, QString strShortOpt, QString strLongOpt )
+bool CCommandline::GetFlagArgument ( int& i, const QString& strShortOpt, const QString& strLongOpt )
{
if ( ( !strShortOpt.compare ( argv[i] ) ) || ( !strLongOpt.compare ( argv[i] ) ) )
{
@@ -1095,7 +1122,7 @@ bool GetFlagArgument ( char** argv, int& i, QString strShortOpt, QString strLong
}
}
-bool GetStringArgument ( int argc, char** argv, int& i, QString strShortOpt, QString strLongOpt, QString& strArg )
+bool CCommandline::GetStringArgument ( int& i, const QString& strShortOpt, const QString& strLongOpt, QString& strArg )
{
if ( ( !strShortOpt.compare ( argv[i] ) ) || ( !strLongOpt.compare ( argv[i] ) ) )
{
@@ -1115,14 +1142,12 @@ bool GetStringArgument ( int argc, char** argv, int& i, QString strShortOpt, QSt
}
}
-bool GetNumericArgument ( int argc,
- char** argv,
- int& i,
- QString strShortOpt,
- QString strLongOpt,
- double rRangeStart,
- double rRangeStop,
- double& rValue )
+bool CCommandline::GetNumericArgument ( int& i,
+ const QString& strShortOpt,
+ const QString& strLongOpt,
+ double rRangeStart,
+ double rRangeStop,
+ double& rValue )
{
if ( ( !strShortOpt.compare ( argv[i] ) ) || ( !strLongOpt.compare ( argv[i] ) ) )
{
diff --git a/src/serverdlg.cpp b/src/serverdlg.cpp
index f467a2f22b..8b827a8681 100644
--- a/src/serverdlg.cpp
+++ b/src/serverdlg.cpp
@@ -571,12 +571,10 @@ void CServerDlg::OnStopRecorder()
UpdateRecorderStatus ( QString() );
if ( pServer->GetRecorderErrMsg() != QString() )
{
- QMessageBox::warning ( this,
- APP_NAME,
- tr ( "Recorder failed to start. "
- "Please check available disk space and permissions and try again. "
- "Error: " ) +
- pServer->GetRecorderErrMsg() );
+ CMsgBoxes::ShowWarning ( tr ( "Recorder failed to start. "
+ "Please check available disk space and permissions and try again. "
+ "Error: " ) +
+ pServer->GetRecorderErrMsg() );
}
}
diff --git a/src/settings.cpp b/src/settings.cpp
index ab9b038dfd..861b85042d 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -336,11 +336,7 @@ void CClientSettings::ReadSettingsFromXML ( const QDomDocument& IniXMLDocument,
if ( !strError.isEmpty() )
{
-# ifndef HEADLESS
- // special case: when settings are loaded no GUI is yet created, therefore
- // we have to create a warning message box here directly
- QMessageBox::warning ( nullptr, APP_NAME, strError );
-# endif
+ CMsgBoxes::ShowWarning ( strError );
}
// sound card channel mapping settings: make sure these settings are
@@ -458,14 +454,14 @@ void CClientSettings::ReadSettingsFromXML ( const QDomDocument& IniXMLDocument,
// custom directories
// clang-format off
// TODO compatibility to old version (< 3.6.1)
-QString strDirectoryAddress = GetIniSetting ( IniXMLDocument, "client", "centralservaddr", "" );
// clang-format on
+ QString strDirectoryAddress = GetIniSetting ( IniXMLDocument, "client", "centralservaddr", "" );
for ( iIdx = 0; iIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIdx++ )
{
// clang-format off
// TODO compatibility to old version (< 3.8.2)
-strDirectoryAddress = GetIniSetting ( IniXMLDocument, "client", QString ( "centralservaddr%1" ).arg ( iIdx ), strDirectoryAddress );
// clang-format on
+ strDirectoryAddress = GetIniSetting ( IniXMLDocument, "client", QString ( "centralservaddr%1" ).arg ( iIdx ), strDirectoryAddress );
vstrDirectoryAddress[iIdx] = GetIniSetting ( IniXMLDocument, "client", QString ( "directoryaddress%1" ).arg ( iIdx ), strDirectoryAddress );
strDirectoryAddress = "";
}
@@ -473,17 +469,19 @@ strDirectoryAddress = GetIniSetting ( IniXMLDocument, "client", QString ( "centr
// directory type
// clang-format off
// TODO compatibility to old version (<3.4.7)
-// only the case that "centralservaddr" was set in old ini must be considered
-if ( !vstrDirectoryAddress[0].isEmpty() && GetFlagIniSet ( IniXMLDocument, "client", "defcentservaddr", bValue ) && !bValue )
-{
- eDirectoryType = AT_CUSTOM;
-}
+ // clang-format on
+ // only the case that "centralservaddr" was set in old ini must be considered
+ if ( !vstrDirectoryAddress[0].isEmpty() && GetFlagIniSet ( IniXMLDocument, "client", "defcentservaddr", bValue ) && !bValue )
+ {
+ eDirectoryType = AT_CUSTOM;
+ }
+ // clang-format off
// TODO compatibility to old version (< 3.8.2)
-else if ( GetNumericIniSet ( IniXMLDocument, "client", "centservaddrtype", 0, static_cast ( AT_CUSTOM ), iValue ) )
-{
- eDirectoryType = static_cast ( iValue );
-}
// clang-format on
+ else if ( GetNumericIniSet ( IniXMLDocument, "client", "centservaddrtype", 0, static_cast ( AT_CUSTOM ), iValue ) )
+ {
+ eDirectoryType = static_cast ( iValue );
+ }
else if ( GetNumericIniSet ( IniXMLDocument, "client", "directorytype", 0, static_cast ( AT_CUSTOM ), iValue ) )
{
eDirectoryType = static_cast ( iValue );
@@ -822,8 +820,8 @@ void CServerSettings::ReadSettingsFromXML ( const QDomDocument& IniXMLDocument,
QString directoryAddress = "";
// clang-format off
// TODO compatibility to old version < 3.8.2
-directoryAddress = GetIniSetting ( IniXMLDocument, "server", "centralservaddr", directoryAddress );
// clang-format on
+ directoryAddress = GetIniSetting ( IniXMLDocument, "server", "centralservaddr", directoryAddress );
directoryAddress = GetIniSetting ( IniXMLDocument, "server", "directoryaddress", directoryAddress );
pServer->SetDirectoryAddress ( directoryAddress );
@@ -843,40 +841,41 @@ directoryAddress = GetIniSetting ( IniXMLDocument, "server", "centralservaddr",
{
// clang-format off
// TODO compatibility to old version < 3.4.7
-if ( GetFlagIniSet ( IniXMLDocument, "server", "defcentservaddr", bValue ) )
-{
- directoryType = bValue ? AT_DEFAULT : AT_CUSTOM;
-}
-else
- // clang-format on
-
- // if "directorytype" itself is set, use it (note "AT_NONE", "AT_DEFAULT" and "AT_CUSTOM" are min/max directory type here)
- // clang-format off
+ // clang-format on
+ if ( GetFlagIniSet ( IniXMLDocument, "server", "defcentservaddr", bValue ) )
+ {
+ directoryType = bValue ? AT_DEFAULT : AT_CUSTOM;
+ }
+ // if "directorytype" itself is set, use it (note "AT_NONE", "AT_DEFAULT" and "AT_CUSTOM" are min/max directory type here)
+ // clang-format off
// TODO compatibility to old version < 3.8.2
-if ( GetNumericIniSet ( IniXMLDocument, "server", "centservaddrtype", static_cast ( AT_DEFAULT ), static_cast ( AT_CUSTOM ), iValue ) )
-{
- directoryType = static_cast ( iValue );
-}
-else
- // clang-format on
- if ( GetNumericIniSet ( IniXMLDocument,
- "server",
- "directorytype",
- static_cast ( AT_NONE ),
- static_cast ( AT_CUSTOM ),
- iValue ) )
+ // clang-format on
+ else if ( GetNumericIniSet ( IniXMLDocument,
+ "server",
+ "centservaddrtype",
+ static_cast ( AT_DEFAULT ),
+ static_cast ( AT_CUSTOM ),
+ iValue ) )
+ {
+ directoryType = static_cast ( iValue );
+ }
+ else if ( GetNumericIniSet ( IniXMLDocument,
+ "server",
+ "directorytype",
+ static_cast ( AT_NONE ),
+ static_cast ( AT_CUSTOM ),
+ iValue ) )
{
directoryType = static_cast ( iValue );
}
-
// clang-format off
// TODO compatibility to old version < 3.9.0
-// override type to AT_NONE if servlistenabled exists and is false
-if ( GetFlagIniSet ( IniXMLDocument, "server", "servlistenabled", bValue ) && !bValue )
-{
- directoryType = AT_NONE;
-}
// clang-format on
+ // override type to AT_NONE if servlistenabled exists and is false
+ if ( GetFlagIniSet ( IniXMLDocument, "server", "servlistenabled", bValue ) && !bValue )
+ {
+ directoryType = AT_NONE;
+ }
}
pServer->SetDirectoryType ( directoryType );
diff --git a/src/soundbase.cpp b/src/soundbase.cpp
index 3e8f2c2b21..c62895b5cf 100644
--- a/src/soundbase.cpp
+++ b/src/soundbase.cpp
@@ -182,7 +182,8 @@ QString CSoundBase::SetDev ( const QString strDevName )
// ASIO drivers
sErrorMessage += "
" + tr ( "Do you want to open the ASIO driver setup to try changing your configuration to a working state?" );
- if ( QMessageBox::Yes == QMessageBox::information ( nullptr, APP_NAME, sErrorMessage, QMessageBox::Yes | QMessageBox::No ) )
+ if ( QMessageBox::Yes ==
+ QMessageBox::information ( CMsgBoxes::MainForm(), CMsgBoxes::MainFormName(), sErrorMessage, QMessageBox::Yes | QMessageBox::No ) )
{
LoadAndInitializeFirstValidDriver ( true );
}
diff --git a/src/util.cpp b/src/util.cpp
index d2f7d6f78b..0aba0d8fc8 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -666,7 +666,9 @@ void CLanguageComboBox::OnLanguageActivated ( int iLanguageIdx )
// only update if the language selection is different from the current selected language
if ( iIdxSelectedLanguage != iLanguageIdx )
{
- QMessageBox::information ( this, tr ( "Restart Required" ), tr ( "Please restart the application for the language change to take effect." ) );
+ QMessageBox::information ( CMsgBoxes::MainForm(),
+ CMsgBoxes::MainFormName() + ": " + tr ( "Restart Required" ),
+ tr ( "Please restart the application for the language change to take effect." ) );
emit LanguageChanged ( itemData ( iLanguageIdx ).toString() );
}
diff --git a/src/util.h b/src/util.h
index 4a546781c9..72b32ff828 100644
--- a/src/util.h
+++ b/src/util.h
@@ -421,7 +421,7 @@ class CHelpMenu : public QMenu
public slots:
void OnHelpWhatsThis() { QWhatsThis::enterWhatsThisMode(); }
void OnHelpAbout() { AboutDlg.exec(); }
- void OnHelpAboutQt() { QMessageBox::aboutQt ( nullptr, QString ( tr ( "About Qt" ) ) ); }
+ void OnHelpAboutQt() { QMessageBox::aboutQt ( CMsgBoxes::MainForm(), QString ( tr ( "About Qt" ) ) ); }
void OnHelpClientGetStarted() { QDesktopServices::openUrl ( QUrl ( CLIENT_GETTING_STARTED_URL ) ); }
void OnHelpServerGetStarted() { QDesktopServices::openUrl ( QUrl ( SERVER_GETTING_STARTED_URL ) ); }
void OnHelpSoftwareMan() { QDesktopServices::openUrl ( QUrl ( SOFTWARE_MANUAL_URL ) ); }
diff --git a/windows/sound.cpp b/windows/sound.cpp
index 58ad034e8a..72f9fcd139 100644
--- a/windows/sound.cpp
+++ b/windows/sound.cpp
@@ -101,8 +101,8 @@ QString CSound::LoadAndInitializeDriver ( QString strDriverName, bool bOpenDrive
if ( bOpenDriverSetup )
{
OpenDriverSetup();
- QMessageBox::question ( nullptr,
- APP_NAME,
+ QMessageBox::question ( CMsgBoxes::MainForm(),
+ CMsgBoxes::MainFormName(),
"Are you done with your ASIO driver settings of " + GetDeviceName ( iDriverIdx ) + "?",
QMessageBox::Yes );
}
@@ -314,9 +314,8 @@ int CSound::GetActualBufferSize ( const int iDesiredBufferSizeMono )
// clang-format off
/*
// TEST
-#include
-QMessageBox::information ( 0, "APP_NAME", QString("lMinSize: %1, lMaxSize: %2, lPreferredSize: %3, lGranularity: %4").
- arg(HWBufferInfo.lMinSize).arg(HWBufferInfo.lMaxSize).arg(HWBufferInfo.lPreferredSize).arg(HWBufferInfo.lGranularity) );
+CMsgBoxes::ShowInfo( QString("lMinSize: %1, lMaxSize: %2, lPreferredSize: %3, lGranularity: %4").
+ arg(HWBufferInfo.lMinSize).arg(HWBufferInfo.lMaxSize).arg(HWBufferInfo.lPreferredSize).arg(HWBufferInfo.lGranularity) );
_exit(1);
*/
// clang-format on