Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/chatdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ( "<b>" + Url.toString() + "</b>" ),
QMessageBox::Yes | QMessageBox::No ) == QMessageBox::Yes )
{
Expand Down
13 changes: 6 additions & 7 deletions src/clientdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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." ) );
Expand Down Expand Up @@ -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." ) );
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
224 changes: 208 additions & 16 deletions src/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <QMessageBox>
# define tMainform QDialog
#else
# define tMainform void
#endif

// html text macro's (for use in message texts)
#define htmlBold( T ) "<b>" + T + "</b>"
#define htmlNewLine() "<br>"

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
Loading