/[svn]/qsampler/trunk/src/qsamplerOptions.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerOptions.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4023 by capela, Thu Feb 4 10:09:42 2021 UTC revision 4024 by capela, Sun Feb 6 10:50:27 2022 UTC
# Line 1  Line 1 
1  // qsamplerOptions.cpp  // qsamplerOptions.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2021, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2022, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007,2008,2015 Christian Schoenebeck     Copyright (C) 2007,2008,2015 Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
# Line 27  Line 27 
27  #include <QTextStream>  #include <QTextStream>
28  #include <QComboBox>  #include <QComboBox>
29    
30    #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
31    #include <QCommandLineParser>
32    #include <QCommandLineOption>
33    #if defined(Q_OS_WINDOWS)
34    #include <QMessageBox>
35    #endif
36    #endif
37    
38  #include <QApplication>  #include <QApplication>
39    
40  #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)  #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
41  #include <QDesktopWidget>  #include <QDesktopWidget>
42  #endif  #endif
43    
 #include <lscp/client.h>  
   
 #ifdef CONFIG_LIBGIG  
 #if defined(Q_CC_GNU) || defined(Q_CC_MINGW)  
 #pragma GCC diagnostic push  
 #pragma GCC diagnostic ignored "-Wunused-parameter"  
 #endif  
 #include <gig.h>  
 #if defined(Q_CC_GNU) || defined(Q_CC_MINGW)  
 #pragma GCC diagnostic pop  
 #endif  
 #endif  
   
44    
45  namespace QSampler {  namespace QSampler {
46    
# Line 290  QSettings& Options::settings (void) Line 285  QSettings& Options::settings (void)
285  // Command-line argument stuff.  // Command-line argument stuff.
286  //  //
287    
288    #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
289    
290    void Options::show_error( const QString& msg )
291    {
292    #if defined(Q_OS_WINDOWS)
293            QMessageBox::information(nullptr, QApplication::applicationName(), msg);
294    #else
295            const QByteArray tmp = msg.toUtf8() + '\n';
296            ::fputs(tmp.constData(), stderr);
297    #endif
298    }
299    
300    #else
301    
302  // Help about command line options.  // Help about command line options.
303  void Options::print_usage ( const QString& arg0 )  void Options::print_usage ( const QString& arg0 )
304  {  {
305          QTextStream out(stderr);          QTextStream out(stderr);
306          out << QObject::tr("Usage: %1 [options] [session-file]\n\n"          const QString sEot = "\n\t";
307                  QSAMPLER_TITLE " - " QSAMPLER_SUBTITLE "\n\n"          const QString sEol = "\n\n";
308                  "Options:\n\n"  
309                  "  -s, --start\n\tStart linuxsampler server locally\n\n"          out << QObject::tr("Usage: %1 [options] [session-file]").arg(arg0) + sEol;
310                  "  -h, --hostname\n\tSpecify linuxsampler server hostname (default = localhost)\n\n"          out << QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE) + sEol;
311                  "  -p, --port\n\tSpecify linuxsampler server port number (default = 8888)\n\n"          out << QObject::tr("Options:") + sEol;
312                  "  -?, --help\n\tShow help about command line options\n\n"          out << "  -s, --start" + sEot +
313                  "  -v, --version\n\tShow version information\n\n")                  QObject::tr("Start linuxsampler server locally.") + sEol;
314                  .arg(arg0);          out << "  -n, --hostname" + sEot +
315                    QObject::tr("Specify linuxsampler server hostname (default = localhost)") + sEol;
316            out << "  -p, --port" + sEot +
317                    QObject::tr("Specify linuxsampler server port number (default = 8888)") + sEol;
318            out << "  -h, --help" + sEot +
319                    QObject::tr("Show help about command line options.") + sEol;
320            out << "  -v, --version" + sEot +
321                    QObject::tr("Show version information") + sEol;
322  }  }
323    
324    #endif
325    
326    
327  // Parse command line arguments into m_settings.  // Parse command line arguments into m_settings.
328  bool Options::parse_args ( const QStringList& args )  bool Options::parse_args ( const QStringList& args )
329  {  {
330            int iCmdArgs = 0;
331    
332    #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
333    
334            QCommandLineParser parser;
335            parser.setApplicationDescription(
336                    QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE));
337    
338            parser.addOption({{"s", "start"},
339                    QObject::tr("Start linuxsampler server locally.")});
340            parser.addOption({{"n", "hostname"},
341                    QObject::tr("Specify linuxsampler server hostname (default = localhost)"), "name"});
342            parser.addOption({{"p", "port"},
343                    QObject::tr("Specify linuxsampler server port number (default = 8888)"), "num"});
344            parser.addHelpOption();
345            parser.addVersionOption();
346            parser.addPositionalArgument("session-file",
347                    QObject::tr("Session file (.lscp)"),
348                    QObject::tr("[session-file]"));
349            parser.process(args);
350    
351            if (parser.isSet("start")) {
352                    bServerStart = true;
353            }
354    
355            if (parser.isSet("hostname")) {
356                    const QString& sVal = parser.value("hostname");
357                    if (sVal.isEmpty()) {
358                            show_error(QObject::tr("Option -n requires an argument (hostname)."));
359                            return false;
360                    }
361                    sServerHost = sVal;
362            }
363    
364            if (parser.isSet("port")) {
365                    bool bOK = false;
366                    const int iVal = parser.value("port").toInt(&bOK);
367                    if (!bOK) {
368                            show_error(QObject::tr("Option -p requires an argument (port)."));
369                            return false;
370                    }
371                    iServerPort = iVal;
372            }
373    
374            foreach(const QString& sArg, parser.positionalArguments()) {
375                    if (iCmdArgs > 0)
376                            sSessionFile += ' ';
377                    sSessionFile += sArg;
378                    ++iCmdArgs;
379            }
380    
381    #else
382    
383          QTextStream out(stderr);          QTextStream out(stderr);
384          const QString sEol = "\n\n";          const QString sEol = "\n\n";
385          const int argc = args.count();          const int argc = args.count();
         int iCmdArgs = 0;  
386    
387          for (int i = 1; i < argc; ++i) {          for (int i = 1; i < argc; ++i) {
388    
# Line 339  bool Options::parse_args ( const QString Line 409  bool Options::parse_args ( const QString
409                  if (sArg == "-s" || sArg == "--start") {                  if (sArg == "-s" || sArg == "--start") {
410                          bServerStart = true;                          bServerStart = true;
411                  }                  }
412                  else if (sArg == "-h" || sArg == "--hostname") {                  else if (sArg == "-n" || sArg == "--hostname") {
413                          if (sVal.isNull()) {                          if (sVal.isNull()) {
414                                  out << QObject::tr("Option -h requires an argument (host).") + sEol;                                  out << QObject::tr("Option -n requires an argument (hostname).") + sEol;
415                                  return false;                                  return false;
416                          }                          }
417                          sServerHost = sVal;                          sServerHost = sVal;
# Line 357  bool Options::parse_args ( const QString Line 427  bool Options::parse_args ( const QString
427                          if (iEqual < 0)                          if (iEqual < 0)
428                                  ++i;                                  ++i;
429                  }                  }
430                  else if (sArg == "-?" || sArg == "--help") {                  else if (sArg == "-h" || sArg == "--help") {
431                          print_usage(args.at(0));                          print_usage(args.at(0));
432                          return false;                          return false;
433                  }                  }
# Line 388  bool Options::parse_args ( const QString Line 458  bool Options::parse_args ( const QString
458                  }                  }
459          }          }
460    
461    #endif
462    
463          // Alright with argument parsing.          // Alright with argument parsing.
464          return true;          return true;
465  }  }

Legend:
Removed from v.4023  
changed lines
  Added in v.4024

  ViewVC Help
Powered by ViewVC