/[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 1803 by schoenebeck, Sun Dec 7 13:58:16 2008 UTC revision 3520 by capela, Mon Jul 1 10:53:41 2019 UTC
# Line 1  Line 1 
1  // qsamplerOptions.cpp  // qsamplerOptions.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2008, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2019, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, 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
8     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 44  namespace QSampler { Line 44  namespace QSampler {
44  Options::Options (void)  Options::Options (void)
45          : m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE)          : m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE)
46  {  {
47            loadOptions();
48    }
49    
50    
51    // Default Destructor.
52    Options::~Options (void)
53    {
54            saveOptions();
55    }
56    
57    
58    // Explicit load method.
59    void Options::loadOptions (void)
60    {
61          // Begin into general options group.          // Begin into general options group.
62          m_settings.beginGroup("/Options");          m_settings.beginGroup("/Options");
63    
# Line 51  Options::Options (void) Line 65  Options::Options (void)
65          m_settings.beginGroup("/Server");          m_settings.beginGroup("/Server");
66          sServerHost    = m_settings.value("/ServerHost", "localhost").toString();          sServerHost    = m_settings.value("/ServerHost", "localhost").toString();
67          iServerPort    = m_settings.value("/ServerPort", 8888).toInt();          iServerPort    = m_settings.value("/ServerPort", 8888).toInt();
68          #if defined(__APPLE__)  //  Toshi Nagata 20080105  #if defined(__APPLE__)  //  Toshi Nagata 20080105
69          //  TODO: Should this be a configure option?          //  TODO: Should this be a configure option?
70          iServerTimeout = m_settings.value("/ServerTimeout", 10000).toInt();          iServerTimeout = m_settings.value("/ServerTimeout", 10000).toInt();
71          #else  #else
72          iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt();          iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt();
73          #endif  #endif
74          bServerStart   = m_settings.value("/ServerStart", true).toBool();          bServerStart   = m_settings.value("/ServerStart", true).toBool();
75          #if defined(__APPLE__)  //  Toshi Nagata 20080113  #if defined(__APPLE__)
76          sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler.starter").toString();          sServerCmdLine = m_settings.value("/ServerCmdLine", "/usr/local/bin/linuxsampler").toString();
77          #else  #else
78          sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString();          sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString();
79          #endif  #endif
80          iStartDelay    = m_settings.value("/StartDelay", 3).toInt();          iStartDelay    = m_settings.value("/StartDelay", 3).toInt();
81          m_settings.endGroup();          m_settings.endGroup();
82    
# Line 83  Options::Options (void) Line 97  Options::Options (void)
97          bMessagesLimit   = m_settings.value("/MessagesLimit", true).toBool();          bMessagesLimit   = m_settings.value("/MessagesLimit", true).toBool();
98          iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt();          iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt();
99          bConfirmRemove   = m_settings.value("/ConfirmRemove", true).toBool();          bConfirmRemove   = m_settings.value("/ConfirmRemove", true).toBool();
100            bConfirmReset    = m_settings.value("/ConfirmReset", true).toBool();
101            bConfirmRestart  = m_settings.value("/ConfirmRestart", true).toBool();
102            bConfirmError    = m_settings.value("/ConfirmError", true).toBool();
103          bKeepOnTop       = m_settings.value("/KeepOnTop", true).toBool();          bKeepOnTop       = m_settings.value("/KeepOnTop", true).toBool();
104          bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();          bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();
105          bCompletePath    = m_settings.value("/CompletePath", true).toBool();          bCompletePath    = m_settings.value("/CompletePath", true).toBool();
# Line 90  Options::Options (void) Line 107  Options::Options (void)
107          iBaseFontSize    = m_settings.value("/BaseFontSize", 0).toInt();          iBaseFontSize    = m_settings.value("/BaseFontSize", 0).toInt();
108  // if libgig provides a fast way to retrieve instrument names even for large  // if libgig provides a fast way to retrieve instrument names even for large
109  // .gig files, then we enable this feature by default  // .gig files, then we enable this feature by default
110  #if HAVE_LIBGIG_SETAUTOLOAD  #ifdef CONFIG_LIBGIG_SETAUTOLOAD
111          bInstrumentNames = m_settings.value("/InstrumentNames", true).toBool();          bInstrumentNames = m_settings.value("/InstrumentNames", true).toBool();
112  #else  #else
113          bInstrumentNames = m_settings.value("/InstrumentNames", false).toBool();          bInstrumentNames = m_settings.value("/InstrumentNames", false).toBool();
# Line 140  Options::Options (void) Line 157  Options::Options (void)
157  }  }
158    
159    
160  // Default Destructor.  // Explicit save method.
161  Options::~Options (void)  void Options::saveOptions (void)
162  {  {
163          // Make program version available in the future.          // Make program version available in the future.
164          m_settings.beginGroup("/Program");          m_settings.beginGroup("/Program");
165          m_settings.setValue("/Version", QSAMPLER_VERSION);          m_settings.setValue("/Version", CONFIG_BUILD_VERSION);
166          m_settings.endGroup();          m_settings.endGroup();
167    
168          // And go into general options group.          // And go into general options group.
# Line 178  Options::~Options (void) Line 195  Options::~Options (void)
195          m_settings.setValue("/MessagesLimit", bMessagesLimit);          m_settings.setValue("/MessagesLimit", bMessagesLimit);
196          m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines);          m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines);
197          m_settings.setValue("/ConfirmRemove", bConfirmRemove);          m_settings.setValue("/ConfirmRemove", bConfirmRemove);
198            m_settings.setValue("/ConfirmReset", bConfirmReset);
199            m_settings.setValue("/ConfirmRestart", bConfirmRestart);
200            m_settings.setValue("/ConfirmError", bConfirmError);
201          m_settings.setValue("/KeepOnTop", bKeepOnTop);          m_settings.setValue("/KeepOnTop", bKeepOnTop);
202          m_settings.setValue("/StdoutCapture", bStdoutCapture);          m_settings.setValue("/StdoutCapture", bStdoutCapture);
203          m_settings.setValue("/CompletePath", bCompletePath);          m_settings.setValue("/CompletePath", bCompletePath);
# Line 225  Options::~Options (void) Line 245  Options::~Options (void)
245          m_settings.setValue("/Volume", iVolume);          m_settings.setValue("/Volume", iVolume);
246          m_settings.setValue("/Loadmode", iLoadMode);          m_settings.setValue("/Loadmode", iLoadMode);
247          m_settings.endGroup();          m_settings.endGroup();
248    
249            // Save/commit to disk.
250            m_settings.sync();
251  }  }
252    
253    
254  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
255  // Settings accessor.  // Settings accessor.
256  //  //
# Line 242  QSettings& Options::settings (void) Line 266  QSettings& Options::settings (void)
266  //  //
267    
268  // Help about command line options.  // Help about command line options.
269  void Options::print_usage ( const char *arg0 )  void Options::print_usage ( const QString& arg0 )
270  {  {
271          QTextStream out(stderr);          QTextStream out(stderr);
272          out << QObject::tr("Usage: %1 [options] [session-file]\n\n"          out << QObject::tr("Usage: %1 [options] [session-file]\n\n"
273                  QSAMPLER_TITLE " - " QSAMPLER_SUBTITLE "\n\n"                  QSAMPLER_TITLE " - " QSAMPLER_SUBTITLE "\n\n"
274                  "Options:\n\n"                  "Options:\n\n"
275                  "  -s, --start\n\tStart linuxsampler server locally\n\n"                  "  -s, --start\n\tStart linuxsampler server locally\n\n"
276                  "  -h, --hostname\n\tSpecify linuxsampler server hostname\n\n"                  "  -h, --hostname\n\tSpecify linuxsampler server hostname (default = localhost)\n\n"
277                  "  -p, --port\n\tSpecify linuxsampler server port number\n\n"                  "  -p, --port\n\tSpecify linuxsampler server port number (default = 8888)\n\n"
278                  "  -?, --help\n\tShow help about command line options\n\n"                  "  -?, --help\n\tShow help about command line options\n\n"
279                  "  -v, --version\n\tShow version information\n\n")                  "  -v, --version\n\tShow version information\n\n")
280                  .arg(arg0);                  .arg(arg0);
# Line 258  void Options::print_usage ( const char * Line 282  void Options::print_usage ( const char *
282    
283    
284  // Parse command line arguments into m_settings.  // Parse command line arguments into m_settings.
285  bool Options::parse_args ( int argc, char **argv )  bool Options::parse_args ( const QStringList& args )
286  {  {
287          QTextStream out(stderr);          QTextStream out(stderr);
288          const QString sEol = "\n\n";          const QString sEol = "\n\n";
289          int iCmdArgs = 0;          int iCmdArgs = 0;
290            const int argc = args.count();
291    
292          for (int i = 1; i < argc; i++) {          for (int i = 1; i < argc; i++) {
293    
294                  if (iCmdArgs > 0) {                  if (iCmdArgs > 0) {
295                          sSessionFile += " ";                          sSessionFile += " ";
296                          sSessionFile += argv[i];                          sSessionFile += args.at(i);
297                          iCmdArgs++;                          iCmdArgs++;
298                          continue;                          continue;
299                  }                  }
300    
301                  QString sArg = argv[i];                  QString sArg = args.at(i);
302                  QString sVal = QString::null;                  QString sVal;
303                  int iEqual = sArg.indexOf("=");                  const int iEqual = sArg.indexOf("=");
304                  if (iEqual >= 0) {                  if (iEqual >= 0) {
305                          sVal = sArg.right(sArg.length() - iEqual - 1);                          sVal = sArg.right(sArg.length() - iEqual - 1);
306                          sArg = sArg.left(iEqual);                          sArg = sArg.left(iEqual);
307                  }                  }
308                  else if (i < argc)                  else if (i < argc - 1) {
309                          sVal = argv[i + 1];                          sVal = args.at(i + 1);
310                            if (sVal[0] == '-')
311                                    sVal.clear();
312                    }
313    
314                  if (sArg == "-s" || sArg == "--start") {                  if (sArg == "-s" || sArg == "--start") {
315                          bServerStart = true;                          bServerStart = true;
316                  }                  }
317                  else if (sArg == "-h" || sArg == "--hostname") {                  else if (sArg == "-h" || sArg == "--hostname") {
318                          if (sVal.isNull()) {                          if (sVal.isNull()) {
319                                  out << QObject::tr("Option -h requires an argument (hostname).") + sEol;                                  out << QObject::tr("Option -h requires an argument (host).") + sEol;
320                                  return false;                                  return false;
321                          }                          }
322                          sServerHost = sVal;                          sServerHost = sVal;
# Line 305  bool Options::parse_args ( int argc, cha Line 333  bool Options::parse_args ( int argc, cha
333                                  i++;                                  i++;
334                  }                  }
335                  else if (sArg == "-?" || sArg == "--help") {                  else if (sArg == "-?" || sArg == "--help") {
336                          print_usage(argv[0]);                          print_usage(args.at(0));
337                          return false;                          return false;
338                  }                  }
339                  else if (sArg == "-v" || sArg == "--version") {                  else if (sArg == "-v" || sArg == "--version") {
340                          out << QObject::tr("Qt: %1\n").arg(qVersion());                          out << QString("Qt: %1\n")
341  #ifdef CONFIG_LIBGIG                                  .arg(qVersion());
342                            out << QString("%1: %2\n")
343                                    .arg(QSAMPLER_TITLE)
344                                    .arg(CONFIG_BUILD_VERSION);
345                    #ifdef CONFIG_LIBGIG
346                          out << QString("%1: %2\n")                          out << QString("%1: %2\n")
347                                  .arg(gig::libraryName().c_str())                                  .arg(gig::libraryName().c_str())
348                                  .arg(gig::libraryVersion().c_str());                                  .arg(gig::libraryVersion().c_str());
349  #endif                  #endif
350                          out << QString("%1: %2\n")                          out << QString("%1: %2\n")
351                                  .arg(::lscp_client_package())                                  .arg(::lscp_client_package())
352                                  .arg(::lscp_client_version());                                  .arg(::lscp_client_version());
                         out << QObject::tr(QSAMPLER_TITLE ": %1\n").arg(QSAMPLER_VERSION);  
353                          return false;                          return false;
354                  }                  }
355                  else {                  else {
# Line 337  bool Options::parse_args ( int argc, cha Line 368  bool Options::parse_args ( int argc, cha
368  //---------------------------------------------------------------------------  //---------------------------------------------------------------------------
369  // Widget geometry persistence helper methods.  // Widget geometry persistence helper methods.
370    
371  void Options::loadWidgetGeometry ( QWidget *pWidget )  void Options::loadWidgetGeometry ( QWidget *pWidget, bool bVisible )
372  {  {
373          // Try to restore old form window positioning.          // Try to restore old form window positioning.
374          if (pWidget) {          if (pWidget) {
375                  QPoint fpos;          //      if (bVisible) pWidget->show(); -- force initial exposure?
                 QSize  fsize;  
                 bool bVisible;  
376                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());
377                  fpos.setX(m_settings.value("/x", -1).toInt());          #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
378                  fpos.setY(m_settings.value("/y", -1).toInt());                  const QByteArray& geometry
379                  fsize.setWidth(m_settings.value("/width", -1).toInt());                          = m_settings.value("/geometry").toByteArray();
380                  fsize.setHeight(m_settings.value("/height", -1).toInt());                  if (!geometry.isEmpty())
381                  bVisible = m_settings.value("/visible", false).toBool();                          pWidget->restoreGeometry(geometry);
382                  m_settings.endGroup();          #else//--LOAD_OLD_GEOMETRY
383                  if (fpos.x() > 0 && fpos.y() > 0)                  QPoint wpos;
384                          pWidget->move(fpos);                  QSize  wsize;
385                  if (fsize.width() > 0 && fsize.height() > 0)                  wpos.setX(m_settings.value("/x", -1).toInt());
386                          pWidget->resize(fsize);                  wpos.setY(m_settings.value("/y", -1).toInt());
387                  else                  wsize.setWidth(m_settings.value("/width", -1).toInt());
388                          pWidget->adjustSize();                  wsize.setHeight(m_settings.value("/height", -1).toInt());
389                    if (wpos.x() > 0 && wpos.y() > 0)
390                            pWidget->move(wpos);
391                    if (wsize.width() > 0 && wsize.height() > 0)
392                            pWidget->resize(wsize);
393            #endif
394            //      else
395            //      pWidget->adjustSize();
396                    if (!bVisible)
397                            bVisible = m_settings.value("/visible", false).toBool();
398                  if (bVisible)                  if (bVisible)
399                          pWidget->show();                          pWidget->show();
400                  else                  else
401                          pWidget->hide();                          pWidget->hide();
402                    m_settings.endGroup();
403          }          }
404  }  }
405    
406    
407  void Options::saveWidgetGeometry ( QWidget *pWidget )  void Options::saveWidgetGeometry ( QWidget *pWidget, bool bVisible )
408  {  {
409          // Try to save form window position...          // Try to save form window position...
410          // (due to X11 window managers ideossincrasies, we better          // (due to X11 window managers ideossincrasies, we better
411          // only save the form geometry while its up and visible)          // only save the form geometry while its up and visible)
412          if (pWidget) {          if (pWidget) {
413                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());
414                  bool bVisible = pWidget->isVisible();          #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
415                  const QPoint& fpos  = pWidget->pos();                  m_settings.setValue("/geometry", pWidget->saveGeometry());
416                  const QSize&  fsize = pWidget->size();          #else//--SAVE_OLD_GEOMETRY
417                  m_settings.setValue("/x", fpos.x());                  const QPoint& wpos  = pWidget->pos();
418                  m_settings.setValue("/y", fpos.y());                  const QSize&  wsize = pWidget->size();
419                  m_settings.setValue("/width", fsize.width());                  m_settings.setValue("/x", wpos.x());
420                  m_settings.setValue("/height", fsize.height());                  m_settings.setValue("/y", wpos.y());
421                    m_settings.setValue("/width", wsize.width());
422                    m_settings.setValue("/height", wsize.height());
423            #endif
424                    if (!bVisible) bVisible = pWidget->isVisible();
425                  m_settings.setValue("/visible", bVisible);                  m_settings.setValue("/visible", bVisible);
426                  m_settings.endGroup();                  m_settings.endGroup();
427          }          }
# Line 390  void Options::saveWidgetGeometry ( QWidg Line 433  void Options::saveWidgetGeometry ( QWidg
433    
434  void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )  void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )
435  {  {
436            const bool bBlockSignals = pComboBox->blockSignals(true);
437    
438          // Load combobox list from configuration settings file...          // Load combobox list from configuration settings file...
439          m_settings.beginGroup("/History/" + pComboBox->objectName());          m_settings.beginGroup("/History/" + pComboBox->objectName());
440    
# Line 397  void Options::loadComboBoxHistory ( QCom Line 442  void Options::loadComboBoxHistory ( QCom
442                  pComboBox->setUpdatesEnabled(false);                  pComboBox->setUpdatesEnabled(false);
443                  pComboBox->setDuplicatesEnabled(false);                  pComboBox->setDuplicatesEnabled(false);
444                  pComboBox->clear();                  pComboBox->clear();
445                  for (int i = 0; i < iLimit; i++) {                  for (int i = 0; i < iLimit; ++i) {
446                          const QString& sText = m_settings.value(                          const QString& sText = m_settings.value(
447                                  "/Item" + QString::number(i + 1)).toString();                                  "/Item" + QString::number(i + 1)).toString();
448                          if (sText.isEmpty())                          if (sText.isEmpty())
# Line 408  void Options::loadComboBoxHistory ( QCom Line 453  void Options::loadComboBoxHistory ( QCom
453          }          }
454    
455          m_settings.endGroup();          m_settings.endGroup();
456    
457            pComboBox->blockSignals(bBlockSignals);
458  }  }
459    
460    
461  void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )  void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )
462  {  {
463            const bool bBlockSignals = pComboBox->blockSignals(true);
464    
465          // Add current text as latest item...          // Add current text as latest item...
466          const QString& sCurrentText = pComboBox->currentText();          const QString sCurrentText = pComboBox->currentText();
467          int iCount = pComboBox->count();          int iCount = pComboBox->count();
468          for (int i = 0; i < iCount; i++) {          for (int i = 0; i < iCount; i++) {
469                  const QString& sText = pComboBox->itemText(i);                  const QString& sText = pComboBox->itemText(i);
470                  if (sText == sCurrentText) {                  if (sText == sCurrentText) {
471                          pComboBox->removeItem(i);                          pComboBox->removeItem(i);
472                          iCount--;                          --iCount;
473                          break;                          break;
474                  }                  }
475          }          }
476          while (iCount >= iLimit)          while (iCount >= iLimit)
477                  pComboBox->removeItem(--iCount);                  pComboBox->removeItem(--iCount);
478          pComboBox->insertItem(0, sCurrentText);          pComboBox->insertItem(0, sCurrentText);
479          iCount++;          pComboBox->setCurrentIndex(0);
480            ++iCount;
481    
482          // Save combobox list to configuration settings file...          // Save combobox list to configuration settings file...
483          m_settings.beginGroup("/History/" + pComboBox->objectName());          m_settings.beginGroup("/History/" + pComboBox->objectName());
484          for (int i = 0; i < iCount; i++) {          for (int i = 0; i < iCount; ++i) {
485                  const QString& sText = pComboBox->itemText(i);                  const QString& sText = pComboBox->itemText(i);
486                  if (sText.isEmpty())                  if (sText.isEmpty())
487                          break;                          break;
488                  m_settings.setValue("/Item" + QString::number(i + 1), sText);                  m_settings.setValue("/Item" + QString::number(i + 1), sText);
489          }          }
490          m_settings.endGroup();          m_settings.endGroup();
491    
492            pComboBox->blockSignals(bBlockSignals);
493  }  }
494    
495    
496  int Options::getMaxVoices() {  int Options::getMaxVoices() {
497  #ifndef CONFIG_MAX_VOICES  #ifndef CONFIG_MAX_VOICES
498          return -1;          return -1;
# Line 537  void Options::sendFineTuningSettings() { Line 590  void Options::sendFineTuningSettings() {
590    
591    
592  // end of qsamplerOptions.cpp  // end of qsamplerOptions.cpp
593    

Legend:
Removed from v.1803  
changed lines
  Added in v.3520

  ViewVC Help
Powered by ViewVC