/[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 1643 by nagata, Sun Jan 13 16:44:00 2008 UTC revision 4043 by capela, Sat Aug 27 11:46:11 2022 UTC
# Line 1  Line 1 
1  // qsamplerOptions.cpp  // qsamplerOptions.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2022, 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 22  Line 22 
22    
23  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
24  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
25    #include "qsamplerMainForm.h"
26    
27  #include <QTextStream>  #include <QTextStream>
28  #include <QComboBox>  #include <QComboBox>
29    
30  #include <lscp/client.h>  #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  #ifdef CONFIG_LIBGIG  #include <QApplication>
39  #include <gig.h>  
40    #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
41    #include <QDesktopWidget>
42  #endif  #endif
43    
44    
# Line 43  namespace QSampler { Line 52  namespace QSampler {
52  Options::Options (void)  Options::Options (void)
53          : m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE)          : m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE)
54  {  {
55            loadOptions();
56    }
57    
58    
59    // Default Destructor.
60    Options::~Options (void)
61    {
62            saveOptions();
63    }
64    
65    
66    // Explicit load method.
67    void Options::loadOptions (void)
68    {
69          // Begin into general options group.          // Begin into general options group.
70          m_settings.beginGroup("/Options");          m_settings.beginGroup("/Options");
71    
# Line 50  Options::Options (void) Line 73  Options::Options (void)
73          m_settings.beginGroup("/Server");          m_settings.beginGroup("/Server");
74          sServerHost    = m_settings.value("/ServerHost", "localhost").toString();          sServerHost    = m_settings.value("/ServerHost", "localhost").toString();
75          iServerPort    = m_settings.value("/ServerPort", 8888).toInt();          iServerPort    = m_settings.value("/ServerPort", 8888).toInt();
76          #if defined(__APPLE__)  //  Toshi Nagata 20080105  #if defined(__APPLE__)  //  Toshi Nagata 20080105
77          //  TODO: Should this be a configure option?          //  TODO: Should this be a configure option?
78          iServerTimeout = m_settings.value("/ServerTimeout", 10000).toInt();          iServerTimeout = m_settings.value("/ServerTimeout", 10000).toInt();
79          #else  #else
80          iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt();          iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt();
81          #endif  #endif
82          bServerStart   = m_settings.value("/ServerStart", true).toBool();          bServerStart   = m_settings.value("/ServerStart", true).toBool();
83          #if defined(__APPLE__)  //  Toshi Nagata 20080113  #if defined(__APPLE__)
84          sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler.starter").toString();          sServerCmdLine = m_settings.value("/ServerCmdLine", "/usr/local/bin/linuxsampler").toString();
85          #else  #else
86          sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString();          sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString();
87          #endif  #endif
88          iStartDelay    = m_settings.value("/StartDelay", 3).toInt();          iStartDelay    = m_settings.value("/StartDelay", 3).toInt();
89          m_settings.endGroup();          m_settings.endGroup();
90    
91            // Load logging options...
92            m_settings.beginGroup("/Logging");
93            bMessagesLog     = m_settings.value("/MessagesLog", false).toBool();
94            sMessagesLogPath = m_settings.value("/MessagesLogPath", "qsampler.log").toString();
95            m_settings.endGroup();
96    
97          // Load display options...          // Load display options...
98          m_settings.beginGroup("/Display");          m_settings.beginGroup("/Display");
99          sDisplayFont     = m_settings.value("/DisplayFont").toString();          sDisplayFont     = m_settings.value("/DisplayFont").toString();
# Line 76  Options::Options (void) Line 105  Options::Options (void)
105          bMessagesLimit   = m_settings.value("/MessagesLimit", true).toBool();          bMessagesLimit   = m_settings.value("/MessagesLimit", true).toBool();
106          iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt();          iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt();
107          bConfirmRemove   = m_settings.value("/ConfirmRemove", true).toBool();          bConfirmRemove   = m_settings.value("/ConfirmRemove", true).toBool();
108            bConfirmReset    = m_settings.value("/ConfirmReset", true).toBool();
109            bConfirmRestart  = m_settings.value("/ConfirmRestart", true).toBool();
110            bConfirmError    = m_settings.value("/ConfirmError", true).toBool();
111          bKeepOnTop       = m_settings.value("/KeepOnTop", true).toBool();          bKeepOnTop       = m_settings.value("/KeepOnTop", true).toBool();
112          bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();          bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();
113          bCompletePath    = m_settings.value("/CompletePath", true).toBool();          bCompletePath    = m_settings.value("/CompletePath", true).toBool();
114          iMaxRecentFiles  = m_settings.value("/MaxRecentFiles", 5).toInt();          iMaxRecentFiles  = m_settings.value("/MaxRecentFiles", 5).toInt();
115            iBaseFontSize    = m_settings.value("/BaseFontSize", 0).toInt();
116  // 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
117  // .gig files, then we enable this feature by default  // .gig files, then we enable this feature by default
118  #if HAVE_LIBGIG_SETAUTOLOAD  #ifdef CONFIG_LIBGIG_SETAUTOLOAD
119          bInstrumentNames = m_settings.value("/InstrumentNames", true).toBool();          bInstrumentNames = m_settings.value("/InstrumentNames", true).toBool();
120  #else  #else
121          bInstrumentNames = m_settings.value("/InstrumentNames", false).toBool();          bInstrumentNames = m_settings.value("/InstrumentNames", false).toBool();
122  #endif  #endif
123          m_settings.endGroup();          m_settings.endGroup();
124    
125            // Load custom options...
126            m_settings.beginGroup("/Custom");
127            sCustomColorTheme = m_settings.value("/ColorTheme").toString();
128            sCustomStyleTheme = m_settings.value("/StyleTheme").toString();
129            m_settings.endGroup();
130    
131          // And go into view options group.          // And go into view options group.
132          m_settings.beginGroup("/View");          m_settings.beginGroup("/View");
133          bMenubar     = m_settings.value("/Menubar", true).toBool();          bMenubar     = m_settings.value("/Menubar", true).toBool();
# Line 110  Options::Options (void) Line 149  Options::Options (void)
149          }          }
150          m_settings.endGroup();          m_settings.endGroup();
151    
152            // Sampler fine tuning settings.
153            m_settings.beginGroup("/Tuning");
154            iMaxVoices  = m_settings.value("/MaxVoices",  -1).toInt();
155            iMaxStreams = m_settings.value("/MaxStreams",  -1).toInt();
156            m_settings.endGroup();
157    
158          // Last but not least, get the default directories.          // Last but not least, get the default directories.
159          m_settings.beginGroup("/Default");          m_settings.beginGroup("/Default");
160          sSessionDir    = m_settings.value("/SessionDir").toString();          sSessionDir    = m_settings.value("/SessionDir").toString();
# Line 126  Options::Options (void) Line 171  Options::Options (void)
171  }  }
172    
173    
174  // Default Destructor.  // Explicit save method.
175  Options::~Options (void)  void Options::saveOptions (void)
176  {  {
177          // Make program version available in the future.          // Make program version available in the future.
178          m_settings.beginGroup("/Program");          m_settings.beginGroup("/Program");
179          m_settings.setValue("/Version", QSAMPLER_VERSION);          m_settings.setValue("/Version", CONFIG_BUILD_VERSION);
180          m_settings.endGroup();          m_settings.endGroup();
181    
182          // And go into general options group.          // And go into general options group.
# Line 147  Options::~Options (void) Line 192  Options::~Options (void)
192          m_settings.setValue("/StartDelay", iStartDelay);          m_settings.setValue("/StartDelay", iStartDelay);
193          m_settings.endGroup();          m_settings.endGroup();
194    
195            // Save logging options...
196            m_settings.beginGroup("/Logging");
197            m_settings.setValue("/MessagesLog", bMessagesLog);
198            m_settings.setValue("/MessagesLogPath", sMessagesLogPath);
199            m_settings.endGroup();
200    
201          // Save display options.          // Save display options.
202          m_settings.beginGroup("/Display");          m_settings.beginGroup("/Display");
203          m_settings.setValue("/DisplayFont", sDisplayFont);          m_settings.setValue("/DisplayFont", sDisplayFont);
# Line 158  Options::~Options (void) Line 209  Options::~Options (void)
209          m_settings.setValue("/MessagesLimit", bMessagesLimit);          m_settings.setValue("/MessagesLimit", bMessagesLimit);
210          m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines);          m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines);
211          m_settings.setValue("/ConfirmRemove", bConfirmRemove);          m_settings.setValue("/ConfirmRemove", bConfirmRemove);
212            m_settings.setValue("/ConfirmReset", bConfirmReset);
213            m_settings.setValue("/ConfirmRestart", bConfirmRestart);
214            m_settings.setValue("/ConfirmError", bConfirmError);
215          m_settings.setValue("/KeepOnTop", bKeepOnTop);          m_settings.setValue("/KeepOnTop", bKeepOnTop);
216          m_settings.setValue("/StdoutCapture", bStdoutCapture);          m_settings.setValue("/StdoutCapture", bStdoutCapture);
217          m_settings.setValue("/CompletePath", bCompletePath);          m_settings.setValue("/CompletePath", bCompletePath);
218          m_settings.setValue("/MaxRecentFiles", iMaxRecentFiles);          m_settings.setValue("/MaxRecentFiles", iMaxRecentFiles);
219            m_settings.setValue("/BaseFontSize", iBaseFontSize);
220          m_settings.setValue("/InstrumentNames", bInstrumentNames);          m_settings.setValue("/InstrumentNames", bInstrumentNames);
221          m_settings.endGroup();          m_settings.endGroup();
222    
223            // Save custom options...
224            m_settings.beginGroup("/Custom");
225            m_settings.setValue("/ColorTheme", sCustomColorTheme);
226            m_settings.setValue("/StyleTheme", sCustomStyleTheme);
227            m_settings.endGroup();
228    
229          // View options group.          // View options group.
230          m_settings.beginGroup("/View");          m_settings.beginGroup("/View");
231          m_settings.setValue("/Menubar", bMenubar);          m_settings.setValue("/Menubar", bMenubar);
# Line 183  Options::~Options (void) Line 244  Options::~Options (void)
244                  m_settings.setValue("/File" + QString::number(++iFile), iter.next());                  m_settings.setValue("/File" + QString::number(++iFile), iter.next());
245          m_settings.endGroup();          m_settings.endGroup();
246    
247            // Sampler fine tuning settings.
248            m_settings.beginGroup("/Tuning");
249            if (iMaxVoices > 0)
250                    m_settings.setValue("/MaxVoices", iMaxVoices);
251            if (iMaxStreams >= 0)
252                    m_settings.setValue("/MaxStreams", iMaxStreams);
253            m_settings.endGroup();
254    
255          // Default directories.          // Default directories.
256          m_settings.beginGroup("/Default");          m_settings.beginGroup("/Default");
257          m_settings.setValue("/SessionDir", sSessionDir);          m_settings.setValue("/SessionDir", sSessionDir);
# Line 196  Options::~Options (void) Line 265  Options::~Options (void)
265          m_settings.setValue("/Volume", iVolume);          m_settings.setValue("/Volume", iVolume);
266          m_settings.setValue("/Loadmode", iLoadMode);          m_settings.setValue("/Loadmode", iLoadMode);
267          m_settings.endGroup();          m_settings.endGroup();
268    
269            // Save/commit to disk.
270            m_settings.sync();
271  }  }
272    
273    
274  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
275  // Settings accessor.  // Settings accessor.
276  //  //
# Line 212  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 char *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\n\n"          out << QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE) + sEol;
311                  "  -p, --port\n\tSpecify linuxsampler server port number\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 ( int argc, char **argv )  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          int iCmdArgs = 0;          const int argc = args.count();
386    
387          for (int i = 1; i < argc; i++) {          for (int i = 1; i < argc; ++i) {
388    
389                  if (iCmdArgs > 0) {                  if (iCmdArgs > 0) {
390                          sSessionFile += " ";                          sSessionFile += " ";
391                          sSessionFile += argv[i];                          sSessionFile += args.at(i);
392                          iCmdArgs++;                          ++iCmdArgs;
393                          continue;                          continue;
394                  }                  }
395    
396                  QString sArg = argv[i];                  QString sArg = args.at(i);
397                  QString sVal = QString::null;                  QString sVal;
398                  int iEqual = sArg.indexOf("=");                  const int iEqual = sArg.indexOf("=");
399                  if (iEqual >= 0) {                  if (iEqual >= 0) {
400                          sVal = sArg.right(sArg.length() - iEqual - 1);                          sVal = sArg.right(sArg.length() - iEqual - 1);
401                          sArg = sArg.left(iEqual);                          sArg = sArg.left(iEqual);
402                  }                  }
403                  else if (i < argc)                  else if (i < argc - 1) {
404                          sVal = argv[i + 1];                          sVal = args.at(i + 1);
405                            if (sVal[0] == '-')
406                                    sVal.clear();
407                    }
408    
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 (hostname).") + sEol;                                  out << QObject::tr("Option -n requires an argument (hostname).") + sEol;
415                                  return false;                                  return false;
416                          }                          }
417                          sServerHost = sVal;                          sServerHost = sVal;
418                          if (iEqual < 0)                          if (iEqual < 0)
419                                  i++;                                  ++i;
420                  }                  }
421                  else if (sArg == "-p" || sArg == "--port") {                  else if (sArg == "-p" || sArg == "--port") {
422                          if (sVal.isNull()) {                          if (sVal.isNull()) {
# Line 273  bool Options::parse_args ( int argc, cha Line 425  bool Options::parse_args ( int argc, cha
425                          }                          }
426                          iServerPort = sVal.toInt();                          iServerPort = sVal.toInt();
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(argv[0]);                          print_usage(args.at(0));
432                          return false;                          return false;
433                  }                  }
434                  else if (sArg == "-v" || sArg == "--version") {                  else if (sArg == "-v" || sArg == "--version") {
435                          out << QObject::tr("Qt: %1\n").arg(qVersion());                          out << QString("Qt: %1").arg(qVersion());
436  #ifdef CONFIG_LIBGIG                  #if defined(QT_STATIC)
437                            out << "-static";
438                    #endif
439                            out << '\n';
440                    #ifdef CONFIG_LIBGIG
441                          out << QString("%1: %2\n")                          out << QString("%1: %2\n")
442                                  .arg(gig::libraryName().c_str())                                  .arg(gig::libraryName().c_str())
443                                  .arg(gig::libraryVersion().c_str());                                  .arg(gig::libraryVersion().c_str());
444  #endif                  #endif
445                          out << QString("%1: %2\n")                          out << QString("%1: %2\n")
446                                  .arg(::lscp_client_package())                                  .arg(::lscp_client_package())
447                                  .arg(::lscp_client_version());                                  .arg(::lscp_client_version());
448                          out << QObject::tr(QSAMPLER_TITLE ": %1\n").arg(QSAMPLER_VERSION);                          out << QString("%1: %2\n")
449                                    .arg(QSAMPLER_TITLE)
450                                    .arg(CONFIG_BUILD_VERSION);
451                          return false;                          return false;
452                  }                  }
453                  else {                  else {
454                          // If we don't have one by now,                          // If we don't have one by now,
455                          // this will be the startup sesion file...                          // this will be the startup sesion file...
456                          sSessionFile += sArg;                          sSessionFile += sArg;
457                          iCmdArgs++;                          ++iCmdArgs;
458                  }                  }
459          }          }
460    
461    #endif
462    
463          // Alright with argument parsing.          // Alright with argument parsing.
464          return true;          return true;
465  }  }
# Line 308  bool Options::parse_args ( int argc, cha Line 468  bool Options::parse_args ( int argc, cha
468  //---------------------------------------------------------------------------  //---------------------------------------------------------------------------
469  // Widget geometry persistence helper methods.  // Widget geometry persistence helper methods.
470    
471  void Options::loadWidgetGeometry ( QWidget *pWidget )  void Options::loadWidgetGeometry ( QWidget *pWidget, bool bVisible )
472  {  {
473          // Try to restore old form window positioning.          // Try to restore old form window positioning.
474          if (pWidget) {          if (pWidget) {
475                  QPoint fpos;          //      if (bVisible) pWidget->show(); -- force initial exposure?
                 QSize  fsize;  
                 bool bVisible;  
476                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());
477                  fpos.setX(m_settings.value("/x", -1).toInt());          #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
478                  fpos.setY(m_settings.value("/y", -1).toInt());                  const QByteArray& geometry
479                  fsize.setWidth(m_settings.value("/width", -1).toInt());                          = m_settings.value("/geometry").toByteArray();
480                  fsize.setHeight(m_settings.value("/height", -1).toInt());                  if (geometry.isEmpty()) {
481                  bVisible = m_settings.value("/visible", false).toBool();                          QWidget *pParent = pWidget->parentWidget();
482                  m_settings.endGroup();                          if (pParent)
483                  if (fpos.x() > 0 && fpos.y() > 0)                                  pParent = pParent->window();
484                          pWidget->move(fpos);                  #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
485                  if (fsize.width() > 0 && fsize.height() > 0)                          if (pParent == nullptr)
486                          pWidget->resize(fsize);                                  pParent = QApplication::desktop();
487                  else                  #endif
488                          pWidget->adjustSize();                          if (pParent) {
489                                    QRect wrect(pWidget->geometry());
490                                    wrect.moveCenter(pParent->geometry().center());
491                                    pWidget->move(wrect.topLeft());
492                            }
493                    } else {
494                            pWidget->restoreGeometry(geometry);
495                    }
496            #else//--LOAD_OLD_GEOMETRY
497                    QPoint wpos;
498                    QSize  wsize;
499                    wpos.setX(m_settings.value("/x", -1).toInt());
500                    wpos.setY(m_settings.value("/y", -1).toInt());
501                    wsize.setWidth(m_settings.value("/width", -1).toInt());
502                    wsize.setHeight(m_settings.value("/height", -1).toInt());
503                    if (wpos.x() > 0 && wpos.y() > 0)
504                            pWidget->move(wpos);
505                    if (wsize.width() > 0 && wsize.height() > 0)
506                            pWidget->resize(wsize);
507            #endif
508            //      else
509            //      pWidget->adjustSize();
510                    if (!bVisible)
511                            bVisible = m_settings.value("/visible", false).toBool();
512                  if (bVisible)                  if (bVisible)
513                          pWidget->show();                          pWidget->show();
514                  else                  else
515                          pWidget->hide();                          pWidget->hide();
516                    m_settings.endGroup();
517          }          }
518  }  }
519    
520    
521  void Options::saveWidgetGeometry ( QWidget *pWidget )  void Options::saveWidgetGeometry ( QWidget *pWidget, bool bVisible )
522  {  {
523          // Try to save form window position...          // Try to save form window position...
524          // (due to X11 window managers ideossincrasies, we better          // (due to X11 window managers ideossincrasies, we better
525          // only save the form geometry while its up and visible)          // only save the form geometry while its up and visible)
526          if (pWidget) {          if (pWidget) {
527                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());
528                  bool bVisible = pWidget->isVisible();          #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
529                  const QPoint& fpos  = pWidget->pos();                  m_settings.setValue("/geometry", pWidget->saveGeometry());
530                  const QSize&  fsize = pWidget->size();          #else//--SAVE_OLD_GEOMETRY
531                  m_settings.setValue("/x", fpos.x());                  const QPoint& wpos  = pWidget->pos();
532                  m_settings.setValue("/y", fpos.y());                  const QSize&  wsize = pWidget->size();
533                  m_settings.setValue("/width", fsize.width());                  m_settings.setValue("/x", wpos.x());
534                  m_settings.setValue("/height", fsize.height());                  m_settings.setValue("/y", wpos.y());
535                    m_settings.setValue("/width", wsize.width());
536                    m_settings.setValue("/height", wsize.height());
537            #endif
538                    if (!bVisible) bVisible = pWidget->isVisible();
539                  m_settings.setValue("/visible", bVisible);                  m_settings.setValue("/visible", bVisible);
540                  m_settings.endGroup();                  m_settings.endGroup();
541          }          }
# Line 361  void Options::saveWidgetGeometry ( QWidg Line 547  void Options::saveWidgetGeometry ( QWidg
547    
548  void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )  void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )
549  {  {
550            const bool bBlockSignals = pComboBox->blockSignals(true);
551    
552          // Load combobox list from configuration settings file...          // Load combobox list from configuration settings file...
553          m_settings.beginGroup("/History/" + pComboBox->objectName());          m_settings.beginGroup("/History/" + pComboBox->objectName());
554    
# Line 368  void Options::loadComboBoxHistory ( QCom Line 556  void Options::loadComboBoxHistory ( QCom
556                  pComboBox->setUpdatesEnabled(false);                  pComboBox->setUpdatesEnabled(false);
557                  pComboBox->setDuplicatesEnabled(false);                  pComboBox->setDuplicatesEnabled(false);
558                  pComboBox->clear();                  pComboBox->clear();
559                  for (int i = 0; i < iLimit; i++) {                  for (int i = 0; i < iLimit; ++i) {
560                          const QString& sText = m_settings.value(                          const QString& sText = m_settings.value(
561                                  "/Item" + QString::number(i + 1)).toString();                                  "/Item" + QString::number(i + 1)).toString();
562                          if (sText.isEmpty())                          if (sText.isEmpty())
# Line 379  void Options::loadComboBoxHistory ( QCom Line 567  void Options::loadComboBoxHistory ( QCom
567          }          }
568    
569          m_settings.endGroup();          m_settings.endGroup();
570    
571            pComboBox->blockSignals(bBlockSignals);
572  }  }
573    
574    
575  void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )  void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )
576  {  {
577          // Add current text as latest item...          const bool bBlockSignals = pComboBox->blockSignals(true);
578          const QString& sCurrentText = pComboBox->currentText();  
579          int iCount = pComboBox->count();          int iCount = pComboBox->count();
580          for (int i = 0; i < iCount; i++) {  
581                  const QString& sText = pComboBox->itemText(i);          // Add current text as latest item (if not blank)...
582                  if (sText == sCurrentText) {          const QString& sCurrentText = pComboBox->currentText();
583                          pComboBox->removeItem(i);          if (!sCurrentText.isEmpty()) {
584                          iCount--;                  for (int i = 0; i < iCount; ++i) {
585                          break;                          const QString& sText = pComboBox->itemText(i);
586                            if (sText == sCurrentText) {
587                                    pComboBox->removeItem(i);
588                                    --iCount;
589                                    break;
590                            }
591                  }                  }
592                    pComboBox->insertItem(0, sCurrentText);
593                    pComboBox->setCurrentIndex(0);
594                    ++iCount;
595          }          }
596    
597          while (iCount >= iLimit)          while (iCount >= iLimit)
598                  pComboBox->removeItem(--iCount);                  pComboBox->removeItem(--iCount);
         pComboBox->insertItem(0, sCurrentText);  
         iCount++;  
599    
600          // Save combobox list to configuration settings file...          // Save combobox list to configuration settings file...
601          m_settings.beginGroup("/History/" + pComboBox->objectName());          m_settings.beginGroup("/History/" + pComboBox->objectName());
602          for (int i = 0; i < iCount; i++) {          for (int i = 0; i < iCount; ++i) {
603                  const QString& sText = pComboBox->itemText(i);                  const QString& sText = pComboBox->itemText(i);
604                  if (sText.isEmpty())                  if (sText.isEmpty())
605                          break;                          break;
606                  m_settings.setValue("/Item" + QString::number(i + 1), sText);                  m_settings.setValue("/Item" + QString::number(i + 1), sText);
607          }          }
608          m_settings.endGroup();          m_settings.endGroup();
609    
610            pComboBox->blockSignals(bBlockSignals);
611    }
612    
613    
614    int Options::getMaxVoices() {
615    #ifndef CONFIG_MAX_VOICES
616            return -1;
617    #else
618            if (iMaxVoices > 0) return iMaxVoices;
619            return getEffectiveMaxVoices();
620    #endif // CONFIG_MAX_VOICES
621    }
622    
623    int Options::getEffectiveMaxVoices() {
624    #ifndef CONFIG_MAX_VOICES
625            return -1;
626    #else
627            MainForm *pMainForm = MainForm::getInstance();
628            if (!pMainForm || !pMainForm->client())
629                    return -1;
630    
631            return ::lscp_get_voices(pMainForm->client());
632    #endif // CONFIG_MAX_VOICES
633    }
634    
635    void Options::setMaxVoices(int iMaxVoices) {
636    #ifdef CONFIG_MAX_VOICES
637            if (iMaxVoices < 1) return;
638    
639            MainForm *pMainForm = MainForm::getInstance();
640            if (!pMainForm || !pMainForm->client())
641                    return;
642    
643            lscp_status_t result =
644                    ::lscp_set_voices(pMainForm->client(), iMaxVoices);
645    
646            if (result != LSCP_OK) {
647                    pMainForm->appendMessagesClient("lscp_set_voices");
648                    return;
649            }
650    
651            this->iMaxVoices = iMaxVoices;
652    #endif // CONFIG_MAX_VOICES
653    }
654    
655    int Options::getMaxStreams() {
656    #ifndef CONFIG_MAX_VOICES
657            return -1;
658    #else
659            if (iMaxStreams > 0) return iMaxStreams;
660            return getEffectiveMaxStreams();
661    #endif // CONFIG_MAX_VOICES
662    }
663    
664    int Options::getEffectiveMaxStreams() {
665    #ifndef CONFIG_MAX_VOICES
666            return -1;
667    #else
668            MainForm *pMainForm = MainForm::getInstance();
669            if (!pMainForm || !pMainForm->client())
670                    return -1;
671    
672            return ::lscp_get_streams(pMainForm->client());
673    #endif // CONFIG_MAX_VOICES
674    }
675    
676    void Options::setMaxStreams(int iMaxStreams) {
677    #ifdef CONFIG_MAX_VOICES
678            if (iMaxStreams < 0) return;
679    
680            MainForm *pMainForm = MainForm::getInstance();
681            if (!pMainForm || !pMainForm->client())
682                    return;
683    
684            lscp_status_t result =
685                    ::lscp_set_streams(pMainForm->client(), iMaxStreams);
686    
687            if (result != LSCP_OK) {
688                    pMainForm->appendMessagesClient("lscp_set_streams");
689                    return;
690            }
691    
692            this->iMaxStreams = iMaxStreams;
693    #endif // CONFIG_MAX_VOICES
694    }
695    
696    void Options::sendFineTuningSettings() {
697            setMaxVoices(iMaxVoices);
698            setMaxStreams(iMaxStreams);
699    
700            MainForm *pMainForm = MainForm::getInstance();
701            if (!pMainForm || !pMainForm->client())
702                    return;
703    
704            pMainForm->appendMessages(QObject::tr("Sent fine tuning settings."));
705  }  }
706    
707  } // namespace QSampler  } // namespace QSampler
708    
709    
710  // end of qsamplerOptions.cpp  // end of qsamplerOptions.cpp
711    

Legend:
Removed from v.1643  
changed lines
  Added in v.4043

  ViewVC Help
Powered by ViewVC