/[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 3558 by capela, Wed Aug 21 17:10:11 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 27  Line 27 
27  #include <QTextStream>  #include <QTextStream>
28  #include <QComboBox>  #include <QComboBox>
29    
30    #include <QApplication>
31    #include <QDesktopWidget>
32    
33  #include <lscp/client.h>  #include <lscp/client.h>
34    
35  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
# Line 44  namespace QSampler { Line 47  namespace QSampler {
47  Options::Options (void)  Options::Options (void)
48          : m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE)          : m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE)
49  {  {
50            loadOptions();
51    }
52    
53    
54    // Default Destructor.
55    Options::~Options (void)
56    {
57            saveOptions();
58    }
59    
60    
61    // Explicit load method.
62    void Options::loadOptions (void)
63    {
64          // Begin into general options group.          // Begin into general options group.
65          m_settings.beginGroup("/Options");          m_settings.beginGroup("/Options");
66    
# Line 51  Options::Options (void) Line 68  Options::Options (void)
68          m_settings.beginGroup("/Server");          m_settings.beginGroup("/Server");
69          sServerHost    = m_settings.value("/ServerHost", "localhost").toString();          sServerHost    = m_settings.value("/ServerHost", "localhost").toString();
70          iServerPort    = m_settings.value("/ServerPort", 8888).toInt();          iServerPort    = m_settings.value("/ServerPort", 8888).toInt();
71          #if defined(__APPLE__)  //  Toshi Nagata 20080105  #if defined(__APPLE__)  //  Toshi Nagata 20080105
72          //  TODO: Should this be a configure option?          //  TODO: Should this be a configure option?
73          iServerTimeout = m_settings.value("/ServerTimeout", 10000).toInt();          iServerTimeout = m_settings.value("/ServerTimeout", 10000).toInt();
74          #else  #else
75          iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt();          iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt();
76          #endif  #endif
77          bServerStart   = m_settings.value("/ServerStart", true).toBool();          bServerStart   = m_settings.value("/ServerStart", true).toBool();
78          #if defined(__APPLE__)  //  Toshi Nagata 20080113  #if defined(__APPLE__)
79          sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler.starter").toString();          sServerCmdLine = m_settings.value("/ServerCmdLine", "/usr/local/bin/linuxsampler").toString();
80          #else  #else
81          sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString();          sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString();
82          #endif  #endif
83          iStartDelay    = m_settings.value("/StartDelay", 3).toInt();          iStartDelay    = m_settings.value("/StartDelay", 3).toInt();
84          m_settings.endGroup();          m_settings.endGroup();
85    
# Line 83  Options::Options (void) Line 100  Options::Options (void)
100          bMessagesLimit   = m_settings.value("/MessagesLimit", true).toBool();          bMessagesLimit   = m_settings.value("/MessagesLimit", true).toBool();
101          iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt();          iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt();
102          bConfirmRemove   = m_settings.value("/ConfirmRemove", true).toBool();          bConfirmRemove   = m_settings.value("/ConfirmRemove", true).toBool();
103            bConfirmReset    = m_settings.value("/ConfirmReset", true).toBool();
104            bConfirmRestart  = m_settings.value("/ConfirmRestart", true).toBool();
105            bConfirmError    = m_settings.value("/ConfirmError", true).toBool();
106          bKeepOnTop       = m_settings.value("/KeepOnTop", true).toBool();          bKeepOnTop       = m_settings.value("/KeepOnTop", true).toBool();
107          bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();          bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();
108          bCompletePath    = m_settings.value("/CompletePath", true).toBool();          bCompletePath    = m_settings.value("/CompletePath", true).toBool();
# Line 90  Options::Options (void) Line 110  Options::Options (void)
110          iBaseFontSize    = m_settings.value("/BaseFontSize", 0).toInt();          iBaseFontSize    = m_settings.value("/BaseFontSize", 0).toInt();
111  // 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
112  // .gig files, then we enable this feature by default  // .gig files, then we enable this feature by default
113  #if HAVE_LIBGIG_SETAUTOLOAD  #ifdef CONFIG_LIBGIG_SETAUTOLOAD
114          bInstrumentNames = m_settings.value("/InstrumentNames", true).toBool();          bInstrumentNames = m_settings.value("/InstrumentNames", true).toBool();
115  #else  #else
116          bInstrumentNames = m_settings.value("/InstrumentNames", false).toBool();          bInstrumentNames = m_settings.value("/InstrumentNames", false).toBool();
# Line 140  Options::Options (void) Line 160  Options::Options (void)
160  }  }
161    
162    
163  // Default Destructor.  // Explicit save method.
164  Options::~Options (void)  void Options::saveOptions (void)
165  {  {
166          // Make program version available in the future.          // Make program version available in the future.
167          m_settings.beginGroup("/Program");          m_settings.beginGroup("/Program");
168          m_settings.setValue("/Version", QSAMPLER_VERSION);          m_settings.setValue("/Version", CONFIG_BUILD_VERSION);
169          m_settings.endGroup();          m_settings.endGroup();
170    
171          // And go into general options group.          // And go into general options group.
# Line 178  Options::~Options (void) Line 198  Options::~Options (void)
198          m_settings.setValue("/MessagesLimit", bMessagesLimit);          m_settings.setValue("/MessagesLimit", bMessagesLimit);
199          m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines);          m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines);
200          m_settings.setValue("/ConfirmRemove", bConfirmRemove);          m_settings.setValue("/ConfirmRemove", bConfirmRemove);
201            m_settings.setValue("/ConfirmReset", bConfirmReset);
202            m_settings.setValue("/ConfirmRestart", bConfirmRestart);
203            m_settings.setValue("/ConfirmError", bConfirmError);
204          m_settings.setValue("/KeepOnTop", bKeepOnTop);          m_settings.setValue("/KeepOnTop", bKeepOnTop);
205          m_settings.setValue("/StdoutCapture", bStdoutCapture);          m_settings.setValue("/StdoutCapture", bStdoutCapture);
206          m_settings.setValue("/CompletePath", bCompletePath);          m_settings.setValue("/CompletePath", bCompletePath);
# Line 225  Options::~Options (void) Line 248  Options::~Options (void)
248          m_settings.setValue("/Volume", iVolume);          m_settings.setValue("/Volume", iVolume);
249          m_settings.setValue("/Loadmode", iLoadMode);          m_settings.setValue("/Loadmode", iLoadMode);
250          m_settings.endGroup();          m_settings.endGroup();
251    
252            // Save/commit to disk.
253            m_settings.sync();
254  }  }
255    
256    
257  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
258  // Settings accessor.  // Settings accessor.
259  //  //
# Line 242  QSettings& Options::settings (void) Line 269  QSettings& Options::settings (void)
269  //  //
270    
271  // Help about command line options.  // Help about command line options.
272  void Options::print_usage ( const char *arg0 )  void Options::print_usage ( const QString& arg0 )
273  {  {
274          QTextStream out(stderr);          QTextStream out(stderr);
275          out << QObject::tr("Usage: %1 [options] [session-file]\n\n"          out << QObject::tr("Usage: %1 [options] [session-file]\n\n"
276                  QSAMPLER_TITLE " - " QSAMPLER_SUBTITLE "\n\n"                  QSAMPLER_TITLE " - " QSAMPLER_SUBTITLE "\n\n"
277                  "Options:\n\n"                  "Options:\n\n"
278                  "  -s, --start\n\tStart linuxsampler server locally\n\n"                  "  -s, --start\n\tStart linuxsampler server locally\n\n"
279                  "  -h, --hostname\n\tSpecify linuxsampler server hostname\n\n"                  "  -h, --hostname\n\tSpecify linuxsampler server hostname (default = localhost)\n\n"
280                  "  -p, --port\n\tSpecify linuxsampler server port number\n\n"                  "  -p, --port\n\tSpecify linuxsampler server port number (default = 8888)\n\n"
281                  "  -?, --help\n\tShow help about command line options\n\n"                  "  -?, --help\n\tShow help about command line options\n\n"
282                  "  -v, --version\n\tShow version information\n\n")                  "  -v, --version\n\tShow version information\n\n")
283                  .arg(arg0);                  .arg(arg0);
# Line 258  void Options::print_usage ( const char * Line 285  void Options::print_usage ( const char *
285    
286    
287  // Parse command line arguments into m_settings.  // Parse command line arguments into m_settings.
288  bool Options::parse_args ( int argc, char **argv )  bool Options::parse_args ( const QStringList& args )
289  {  {
290          QTextStream out(stderr);          QTextStream out(stderr);
291          const QString sEol = "\n\n";          const QString sEol = "\n\n";
292            const int argc = args.count();
293          int iCmdArgs = 0;          int iCmdArgs = 0;
294    
295          for (int i = 1; i < argc; i++) {          for (int i = 1; i < argc; ++i) {
296    
297                  if (iCmdArgs > 0) {                  if (iCmdArgs > 0) {
298                          sSessionFile += " ";                          sSessionFile += " ";
299                          sSessionFile += argv[i];                          sSessionFile += args.at(i);
300                          iCmdArgs++;                          ++iCmdArgs;
301                          continue;                          continue;
302                  }                  }
303    
304                  QString sArg = argv[i];                  QString sArg = args.at(i);
305                  QString sVal = QString::null;                  QString sVal;
306                  int iEqual = sArg.indexOf("=");                  const int iEqual = sArg.indexOf("=");
307                  if (iEqual >= 0) {                  if (iEqual >= 0) {
308                          sVal = sArg.right(sArg.length() - iEqual - 1);                          sVal = sArg.right(sArg.length() - iEqual - 1);
309                          sArg = sArg.left(iEqual);                          sArg = sArg.left(iEqual);
310                  }                  }
311                  else if (i < argc)                  else if (i < argc - 1) {
312                          sVal = argv[i + 1];                          sVal = args.at(i + 1);
313                            if (sVal[0] == '-')
314                                    sVal.clear();
315                    }
316    
317                  if (sArg == "-s" || sArg == "--start") {                  if (sArg == "-s" || sArg == "--start") {
318                          bServerStart = true;                          bServerStart = true;
319                  }                  }
320                  else if (sArg == "-h" || sArg == "--hostname") {                  else if (sArg == "-h" || sArg == "--hostname") {
321                          if (sVal.isNull()) {                          if (sVal.isNull()) {
322                                  out << QObject::tr("Option -h requires an argument (hostname).") + sEol;                                  out << QObject::tr("Option -h requires an argument (host).") + sEol;
323                                  return false;                                  return false;
324                          }                          }
325                          sServerHost = sVal;                          sServerHost = sVal;
326                          if (iEqual < 0)                          if (iEqual < 0)
327                                  i++;                                  ++i;
328                  }                  }
329                  else if (sArg == "-p" || sArg == "--port") {                  else if (sArg == "-p" || sArg == "--port") {
330                          if (sVal.isNull()) {                          if (sVal.isNull()) {
# Line 302  bool Options::parse_args ( int argc, cha Line 333  bool Options::parse_args ( int argc, cha
333                          }                          }
334                          iServerPort = sVal.toInt();                          iServerPort = sVal.toInt();
335                          if (iEqual < 0)                          if (iEqual < 0)
336                                  i++;                                  ++i;
337                  }                  }
338                  else if (sArg == "-?" || sArg == "--help") {                  else if (sArg == "-?" || sArg == "--help") {
339                          print_usage(argv[0]);                          print_usage(args.at(0));
340                          return false;                          return false;
341                  }                  }
342                  else if (sArg == "-v" || sArg == "--version") {                  else if (sArg == "-v" || sArg == "--version") {
343                          out << QObject::tr("Qt: %1\n").arg(qVersion());                          out << QString("Qt: %1\n")
344  #ifdef CONFIG_LIBGIG                                  .arg(qVersion());
345                            out << QString("%1: %2\n")
346                                    .arg(QSAMPLER_TITLE)
347                                    .arg(CONFIG_BUILD_VERSION);
348                    #ifdef CONFIG_LIBGIG
349                          out << QString("%1: %2\n")                          out << QString("%1: %2\n")
350                                  .arg(gig::libraryName().c_str())                                  .arg(gig::libraryName().c_str())
351                                  .arg(gig::libraryVersion().c_str());                                  .arg(gig::libraryVersion().c_str());
352  #endif                  #endif
353                          out << QString("%1: %2\n")                          out << QString("%1: %2\n")
354                                  .arg(::lscp_client_package())                                  .arg(::lscp_client_package())
355                                  .arg(::lscp_client_version());                                  .arg(::lscp_client_version());
                         out << QObject::tr(QSAMPLER_TITLE ": %1\n").arg(QSAMPLER_VERSION);  
356                          return false;                          return false;
357                  }                  }
358                  else {                  else {
359                          // If we don't have one by now,                          // If we don't have one by now,
360                          // this will be the startup sesion file...                          // this will be the startup sesion file...
361                          sSessionFile += sArg;                          sSessionFile += sArg;
362                          iCmdArgs++;                          ++iCmdArgs;
363                  }                  }
364          }          }
365    
# Line 337  bool Options::parse_args ( int argc, cha Line 371  bool Options::parse_args ( int argc, cha
371  //---------------------------------------------------------------------------  //---------------------------------------------------------------------------
372  // Widget geometry persistence helper methods.  // Widget geometry persistence helper methods.
373    
374  void Options::loadWidgetGeometry ( QWidget *pWidget )  void Options::loadWidgetGeometry ( QWidget *pWidget, bool bVisible )
375  {  {
376          // Try to restore old form window positioning.          // Try to restore old form window positioning.
377          if (pWidget) {          if (pWidget) {
378                  QPoint fpos;          //      if (bVisible) pWidget->show(); -- force initial exposure?
                 QSize  fsize;  
                 bool bVisible;  
379                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());
380                  fpos.setX(m_settings.value("/x", -1).toInt());          #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
381                  fpos.setY(m_settings.value("/y", -1).toInt());                  const QByteArray& geometry
382                  fsize.setWidth(m_settings.value("/width", -1).toInt());                          = m_settings.value("/geometry").toByteArray();
383                  fsize.setHeight(m_settings.value("/height", -1).toInt());                  if (geometry.isEmpty()) {
384                  bVisible = m_settings.value("/visible", false).toBool();                          QWidget *pParent = pWidget->parentWidget();
385                  m_settings.endGroup();                          if (pParent)
386                  if (fpos.x() > 0 && fpos.y() > 0)                                  pParent = pParent->window();
387                          pWidget->move(fpos);                          if (pParent == nullptr)
388                  if (fsize.width() > 0 && fsize.height() > 0)                                  pParent = QApplication::desktop();
389                          pWidget->resize(fsize);                          if (pParent) {
390                  else                                  QRect wrect(pWidget->geometry());
391                          pWidget->adjustSize();                                  wrect.moveCenter(pParent->geometry().center());
392                                    pWidget->move(wrect.topLeft());
393                            }
394                    } else {
395                            pWidget->restoreGeometry(geometry);
396                    }
397            #else//--LOAD_OLD_GEOMETRY
398                    QPoint wpos;
399                    QSize  wsize;
400                    wpos.setX(m_settings.value("/x", -1).toInt());
401                    wpos.setY(m_settings.value("/y", -1).toInt());
402                    wsize.setWidth(m_settings.value("/width", -1).toInt());
403                    wsize.setHeight(m_settings.value("/height", -1).toInt());
404                    if (wpos.x() > 0 && wpos.y() > 0)
405                            pWidget->move(wpos);
406                    if (wsize.width() > 0 && wsize.height() > 0)
407                            pWidget->resize(wsize);
408            #endif
409            //      else
410            //      pWidget->adjustSize();
411                    if (!bVisible)
412                            bVisible = m_settings.value("/visible", false).toBool();
413                  if (bVisible)                  if (bVisible)
414                          pWidget->show();                          pWidget->show();
415                  else                  else
416                          pWidget->hide();                          pWidget->hide();
417                    m_settings.endGroup();
418          }          }
419  }  }
420    
421    
422  void Options::saveWidgetGeometry ( QWidget *pWidget )  void Options::saveWidgetGeometry ( QWidget *pWidget, bool bVisible )
423  {  {
424          // Try to save form window position...          // Try to save form window position...
425          // (due to X11 window managers ideossincrasies, we better          // (due to X11 window managers ideossincrasies, we better
426          // only save the form geometry while its up and visible)          // only save the form geometry while its up and visible)
427          if (pWidget) {          if (pWidget) {
428                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());
429                  bool bVisible = pWidget->isVisible();          #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
430                  const QPoint& fpos  = pWidget->pos();                  m_settings.setValue("/geometry", pWidget->saveGeometry());
431                  const QSize&  fsize = pWidget->size();          #else//--SAVE_OLD_GEOMETRY
432                  m_settings.setValue("/x", fpos.x());                  const QPoint& wpos  = pWidget->pos();
433                  m_settings.setValue("/y", fpos.y());                  const QSize&  wsize = pWidget->size();
434                  m_settings.setValue("/width", fsize.width());                  m_settings.setValue("/x", wpos.x());
435                  m_settings.setValue("/height", fsize.height());                  m_settings.setValue("/y", wpos.y());
436                    m_settings.setValue("/width", wsize.width());
437                    m_settings.setValue("/height", wsize.height());
438            #endif
439                    if (!bVisible) bVisible = pWidget->isVisible();
440                  m_settings.setValue("/visible", bVisible);                  m_settings.setValue("/visible", bVisible);
441                  m_settings.endGroup();                  m_settings.endGroup();
442          }          }
# Line 390  void Options::saveWidgetGeometry ( QWidg Line 448  void Options::saveWidgetGeometry ( QWidg
448    
449  void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )  void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )
450  {  {
451            const bool bBlockSignals = pComboBox->blockSignals(true);
452    
453          // Load combobox list from configuration settings file...          // Load combobox list from configuration settings file...
454          m_settings.beginGroup("/History/" + pComboBox->objectName());          m_settings.beginGroup("/History/" + pComboBox->objectName());
455    
# Line 397  void Options::loadComboBoxHistory ( QCom Line 457  void Options::loadComboBoxHistory ( QCom
457                  pComboBox->setUpdatesEnabled(false);                  pComboBox->setUpdatesEnabled(false);
458                  pComboBox->setDuplicatesEnabled(false);                  pComboBox->setDuplicatesEnabled(false);
459                  pComboBox->clear();                  pComboBox->clear();
460                  for (int i = 0; i < iLimit; i++) {                  for (int i = 0; i < iLimit; ++i) {
461                          const QString& sText = m_settings.value(                          const QString& sText = m_settings.value(
462                                  "/Item" + QString::number(i + 1)).toString();                                  "/Item" + QString::number(i + 1)).toString();
463                          if (sText.isEmpty())                          if (sText.isEmpty())
# Line 408  void Options::loadComboBoxHistory ( QCom Line 468  void Options::loadComboBoxHistory ( QCom
468          }          }
469    
470          m_settings.endGroup();          m_settings.endGroup();
471    
472            pComboBox->blockSignals(bBlockSignals);
473  }  }
474    
475    
476  void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )  void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )
477  {  {
478            const bool bBlockSignals = pComboBox->blockSignals(true);
479    
480          // Add current text as latest item...          // Add current text as latest item...
481          const QString& sCurrentText = pComboBox->currentText();          const QString sCurrentText = pComboBox->currentText();
482          int iCount = pComboBox->count();          int iCount = pComboBox->count();
483          for (int i = 0; i < iCount; i++) {          for (int i = 0; i < iCount; i++) {
484                  const QString& sText = pComboBox->itemText(i);                  const QString& sText = pComboBox->itemText(i);
485                  if (sText == sCurrentText) {                  if (sText == sCurrentText) {
486                          pComboBox->removeItem(i);                          pComboBox->removeItem(i);
487                          iCount--;                          --iCount;
488                          break;                          break;
489                  }                  }
490          }          }
491          while (iCount >= iLimit)          while (iCount >= iLimit)
492                  pComboBox->removeItem(--iCount);                  pComboBox->removeItem(--iCount);
493          pComboBox->insertItem(0, sCurrentText);          pComboBox->insertItem(0, sCurrentText);
494          iCount++;          pComboBox->setCurrentIndex(0);
495            ++iCount;
496    
497          // Save combobox list to configuration settings file...          // Save combobox list to configuration settings file...
498          m_settings.beginGroup("/History/" + pComboBox->objectName());          m_settings.beginGroup("/History/" + pComboBox->objectName());
499          for (int i = 0; i < iCount; i++) {          for (int i = 0; i < iCount; ++i) {
500                  const QString& sText = pComboBox->itemText(i);                  const QString& sText = pComboBox->itemText(i);
501                  if (sText.isEmpty())                  if (sText.isEmpty())
502                          break;                          break;
503                  m_settings.setValue("/Item" + QString::number(i + 1), sText);                  m_settings.setValue("/Item" + QString::number(i + 1), sText);
504          }          }
505          m_settings.endGroup();          m_settings.endGroup();
506    
507            pComboBox->blockSignals(bBlockSignals);
508  }  }
509    
510    
511  int Options::getMaxVoices() {  int Options::getMaxVoices() {
512  #ifndef CONFIG_MAX_VOICES  #ifndef CONFIG_MAX_VOICES
513          return -1;          return -1;
# Line 537  void Options::sendFineTuningSettings() { Line 605  void Options::sendFineTuningSettings() {
605    
606    
607  // end of qsamplerOptions.cpp  // end of qsamplerOptions.cpp
608    

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

  ViewVC Help
Powered by ViewVC