/[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 267 by capela, Wed Oct 6 15:42:59 2004 UTC revision 1749 by capela, Wed Jul 2 13:19:09 2008 UTC
# Line 1  Line 1 
1  // qsamplerOptions.cpp  // qsamplerOptions.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2003-2004, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2008, rncbc aka Rui Nuno Capela. All rights reserved.
5       Copyright (C) 2007, 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 13  Line 14 
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License along
18     along with this program; if not, write to the Free Software     with this program; if not, write to the Free Software Foundation, Inc.,
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20    
21  *****************************************************************************/  *****************************************************************************/
22    
 #include "qsamplerOptions.h"  
23  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
24    #include "qsamplerOptions.h"
25    
26  #include <qcombobox.h>  #include <QTextStream>
27    #include <QComboBox>
28    
29  #include <lscp/client.h>  #include <lscp/client.h>
30    
31  #include "config.h"  #ifdef CONFIG_LIBGIG
32    #include <gig.h>
33    #endif
34    
35    
36    namespace QSampler {
37    
38  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
39  // qsamplerOptions - Prototype settings structure.  // QSampler::Options - Prototype settings structure.
40  //  //
41    
42  // Constructor.  // Constructor.
43  qsamplerOptions::qsamplerOptions (void)  Options::Options (void)
44            : m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE)
45  {  {
46      // Begin master key group.          // Begin into general options group.
47      m_settings.beginGroup("/qsampler");          m_settings.beginGroup("/Options");
   
     // And go into general options group.  
     m_settings.beginGroup("/Options");  
48    
49      // Load server options...          // Load server options...
50      m_settings.beginGroup("/Server");          m_settings.beginGroup("/Server");
51      sServerHost    = m_settings.readEntry("/ServerHost", "localhost");          sServerHost    = m_settings.value("/ServerHost", "localhost").toString();
52      iServerPort    = m_settings.readNumEntry("/ServerPort", 8888);          iServerPort    = m_settings.value("/ServerPort", 8888).toInt();
53      iServerTimeout = m_settings.readNumEntry("/ServerTimeout", 500);          #if defined(__APPLE__)  //  Toshi Nagata 20080105
54      bServerStart   = m_settings.readBoolEntry("/ServerStart", true);          //  TODO: Should this be a configure option?
55      sServerCmdLine = m_settings.readEntry("/ServerCmdLine", "linuxsampler");          iServerTimeout = m_settings.value("/ServerTimeout", 10000).toInt();
56      iStartDelay    = m_settings.readNumEntry("/StartDelay", 2);          #else
57      m_settings.endGroup();          iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt();
58            #endif
59      // Load display options...          bServerStart   = m_settings.value("/ServerStart", true).toBool();
60      m_settings.beginGroup("/Display");          #if defined(__APPLE__)  //  Toshi Nagata 20080113
61      sDisplayFont     = m_settings.readEntry("/DisplayFont", QString::null);          sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler.starter").toString();
62      bDisplayEffect   = m_settings.readBoolEntry("/DisplayEffect", true);          #else
63      bAutoRefresh     = m_settings.readBoolEntry("/AutoRefresh", true);          sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString();
64      iAutoRefreshTime = m_settings.readNumEntry("/AutoRefreshTime", 1000);          #endif
65      iMaxVolume       = m_settings.readNumEntry("/MaxVolume", 100);          iStartDelay    = m_settings.value("/StartDelay", 3).toInt();
66      sMessagesFont    = m_settings.readEntry("/MessagesFont", QString::null);          m_settings.endGroup();
67      bMessagesLimit   = m_settings.readBoolEntry("/MessagesLimit", true);  
68      iMessagesLimitLines = m_settings.readNumEntry("/MessagesLimitLines", 1000);          // Load logging options...
69      bConfirmRemove   = m_settings.readBoolEntry("/ConfirmRemove", true);          m_settings.beginGroup("/Logging");
70      bStdoutCapture   = m_settings.readBoolEntry("/StdoutCapture", true);          bMessagesLog     = m_settings.value("/MessagesLog", false).toBool();
71      bCompletePath    = m_settings.readBoolEntry("/CompletePath", true);          sMessagesLogPath = m_settings.value("/MessagesLogPath", "qsampler.log").toString();
72      iMaxRecentFiles  = m_settings.readNumEntry("/MaxRecentFiles", 5);          m_settings.endGroup();
73      m_settings.endGroup();  
74            // Load display options...
75      // And go into view options group.          m_settings.beginGroup("/Display");
76      m_settings.beginGroup("/View");          sDisplayFont     = m_settings.value("/DisplayFont").toString();
77      bMenubar     = m_settings.readBoolEntry("/Menubar", true);          bDisplayEffect   = m_settings.value("/DisplayEffect", true).toBool();
78      bToolbar     = m_settings.readBoolEntry("/Toolbar", true);          bAutoRefresh     = m_settings.value("/AutoRefresh", true).toBool();
79      bStatusbar   = m_settings.readBoolEntry("/Statusbar", true);          iAutoRefreshTime = m_settings.value("/AutoRefreshTime", 1000).toInt();
80      bAutoArrange = m_settings.readBoolEntry("/AutoArrange", true);          iMaxVolume       = m_settings.value("/MaxVolume", 100).toInt();
81      m_settings.endGroup();          sMessagesFont    = m_settings.value("/MessagesFont").toString();
82            bMessagesLimit   = m_settings.value("/MessagesLimit", true).toBool();
83      m_settings.endGroup(); // Options group.          iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt();
84            bConfirmRemove   = m_settings.value("/ConfirmRemove", true).toBool();
85      // Recent file list.          bKeepOnTop       = m_settings.value("/KeepOnTop", true).toBool();
86      m_settings.beginGroup("/RecentFiles");          bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();
87      recentFiles.clear();          bCompletePath    = m_settings.value("/CompletePath", true).toBool();
88      for (int i = 0; i < iMaxRecentFiles; i++) {          iMaxRecentFiles  = m_settings.value("/MaxRecentFiles", 5).toInt();
89          QString sFilename = m_settings.readEntry("/File" + QString::number(i + 1), QString::null);          iBaseFontSize    = m_settings.value("/BaseFontSize", 0).toInt();
90          if (!sFilename.isEmpty())  // if libgig provides a fast way to retrieve instrument names even for large
91              recentFiles.append(sFilename);  // .gig files, then we enable this feature by default
92      }  #if HAVE_LIBGIG_SETAUTOLOAD
93      m_settings.endGroup();          bInstrumentNames = m_settings.value("/InstrumentNames", true).toBool();
94    #else
95      // Last but not least, get the default directories.          bInstrumentNames = m_settings.value("/InstrumentNames", false).toBool();
96      m_settings.beginGroup("/Default");  #endif
97      sSessionDir    = m_settings.readEntry("/SessionDir", QString::null);          m_settings.endGroup();
98      sInstrumentDir = m_settings.readEntry("/InstrumentDir", QString::null);  
99      sEngineName    = m_settings.readEntry("/EngineName", QString::null);          // And go into view options group.
100      sAudioDriver   = m_settings.readEntry("/AudioDriver", QString::null);          m_settings.beginGroup("/View");
101      sMidiDriver    = m_settings.readEntry("/MidiDriver", QString::null);          bMenubar     = m_settings.value("/Menubar", true).toBool();
102      m_settings.endGroup();          bToolbar     = m_settings.value("/Toolbar", true).toBool();
103            bStatusbar   = m_settings.value("/Statusbar", true).toBool();
104            bAutoArrange = m_settings.value("/AutoArrange", true).toBool();
105            m_settings.endGroup();
106    
107            m_settings.endGroup(); // Options group.
108    
109            // Recent file list.
110            recentFiles.clear();
111            m_settings.beginGroup("/RecentFiles");
112            for (int iFile = 0; iFile < iMaxRecentFiles; iFile++) {
113                    QString sFilename = m_settings.value(
114                            "/File" + QString::number(iFile + 1)).toString();
115                    if (!sFilename.isEmpty())
116                            recentFiles.append(sFilename);
117            }
118            m_settings.endGroup();
119    
120            // Last but not least, get the default directories.
121            m_settings.beginGroup("/Default");
122            sSessionDir    = m_settings.value("/SessionDir").toString();
123            sInstrumentDir = m_settings.value("/InstrumentDir").toString();
124            sEngineName    = m_settings.value("/EngineName").toString();
125            sAudioDriver   = m_settings.value("/AudioDriver").toString();
126            sMidiDriver    = m_settings.value("/MidiDriver").toString();
127            iMidiMap       = m_settings.value("/MidiMap",  0).toInt();
128            iMidiBank      = m_settings.value("/MidiBank", 0).toInt();
129            iMidiProg      = m_settings.value("/MidiProg", 0).toInt();
130            iVolume        = m_settings.value("/Volume", 100).toInt();
131            iLoadMode      = m_settings.value("/Loadmode", 0).toInt();
132            m_settings.endGroup();
133  }  }
134    
135    
136  // Default Destructor.  // Default Destructor.
137  qsamplerOptions::~qsamplerOptions (void)  Options::~Options (void)
138  {  {
139      // Make program version available in the future.          // Make program version available in the future.
140      m_settings.beginGroup("/Program");          m_settings.beginGroup("/Program");
141      m_settings.writeEntry("/Version", QSAMPLER_VERSION);          m_settings.setValue("/Version", QSAMPLER_VERSION);
142      m_settings.endGroup();          m_settings.endGroup();
143    
144      // And go into general options group.          // And go into general options group.
145      m_settings.beginGroup("/Options");          m_settings.beginGroup("/Options");
146    
147      // Save server options.          // Save server options.
148      m_settings.beginGroup("/Server");          m_settings.beginGroup("/Server");
149      m_settings.writeEntry("/ServerHost", sServerHost);          m_settings.setValue("/ServerHost", sServerHost);
150      m_settings.writeEntry("/ServerPort", iServerPort);          m_settings.setValue("/ServerPort", iServerPort);
151      m_settings.writeEntry("/ServerTimeout", iServerTimeout);          m_settings.setValue("/ServerTimeout", iServerTimeout);
152      m_settings.writeEntry("/ServerStart", bServerStart);          m_settings.setValue("/ServerStart", bServerStart);
153      m_settings.writeEntry("/ServerCmdLine", sServerCmdLine);          m_settings.setValue("/ServerCmdLine", sServerCmdLine);
154      m_settings.writeEntry("/StartDelay", iStartDelay);          m_settings.setValue("/StartDelay", iStartDelay);
155      m_settings.endGroup();          m_settings.endGroup();
156    
157      // Save display options.          // Save logging options...
158      m_settings.beginGroup("/Display");          m_settings.beginGroup("/Logging");
159      m_settings.writeEntry("/DisplayFont", sDisplayFont);          m_settings.setValue("/MessagesLog", bMessagesLog);
160      m_settings.writeEntry("/DisplayEffect", bDisplayEffect);          m_settings.setValue("/MessagesLogPath", sMessagesLogPath);
161      m_settings.writeEntry("/AutoRefresh", bAutoRefresh);          m_settings.endGroup();
162      m_settings.writeEntry("/AutoRefreshTime", iAutoRefreshTime);  
163      m_settings.writeEntry("/MaxVolume", iMaxVolume);          // Save display options.
164      m_settings.writeEntry("/MessagesFont", sMessagesFont);          m_settings.beginGroup("/Display");
165      m_settings.writeEntry("/MessagesLimit", bMessagesLimit);          m_settings.setValue("/DisplayFont", sDisplayFont);
166      m_settings.writeEntry("/MessagesLimitLines", iMessagesLimitLines);          m_settings.setValue("/DisplayEffect", bDisplayEffect);
167      m_settings.writeEntry("/ConfirmRemove", bConfirmRemove);          m_settings.setValue("/AutoRefresh", bAutoRefresh);
168      m_settings.writeEntry("/StdoutCapture", bStdoutCapture);          m_settings.setValue("/AutoRefreshTime", iAutoRefreshTime);
169      m_settings.writeEntry("/CompletePath", bCompletePath);          m_settings.setValue("/MaxVolume", iMaxVolume);
170      m_settings.writeEntry("/MaxRecentFiles", iMaxRecentFiles);          m_settings.setValue("/MessagesFont", sMessagesFont);
171      m_settings.endGroup();          m_settings.setValue("/MessagesLimit", bMessagesLimit);
172            m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines);
173      // View options group.          m_settings.setValue("/ConfirmRemove", bConfirmRemove);
174      m_settings.beginGroup("/View");          m_settings.setValue("/KeepOnTop", bKeepOnTop);
175      m_settings.writeEntry("/Menubar", bMenubar);          m_settings.setValue("/StdoutCapture", bStdoutCapture);
176      m_settings.writeEntry("/Toolbar", bToolbar);          m_settings.setValue("/CompletePath", bCompletePath);
177      m_settings.writeEntry("/Statusbar", bStatusbar);          m_settings.setValue("/MaxRecentFiles", iMaxRecentFiles);
178      m_settings.writeEntry("/AutoArrange", bAutoArrange);          m_settings.setValue("/BaseFontSize", iBaseFontSize);
179      m_settings.endGroup();          m_settings.setValue("/InstrumentNames", bInstrumentNames);
180            m_settings.endGroup();
181      m_settings.endGroup(); // Options group.  
182            // View options group.
183      // Recent file list.          m_settings.beginGroup("/View");
184      m_settings.beginGroup("/RecentFiles");          m_settings.setValue("/Menubar", bMenubar);
185      for (int i = 0; i < (int) recentFiles.count(); i++)          m_settings.setValue("/Toolbar", bToolbar);
186          m_settings.writeEntry("/File" + QString::number(i + 1), recentFiles[i]);          m_settings.setValue("/Statusbar", bStatusbar);
187      m_settings.endGroup();          m_settings.setValue("/AutoArrange", bAutoArrange);
188            m_settings.endGroup();
189      // Default directories.  
190      m_settings.beginGroup("/Default");          m_settings.endGroup(); // Options group.
191      m_settings.writeEntry("/SessionDir", sSessionDir);  
192      m_settings.writeEntry("/InstrumentDir", sInstrumentDir);          // Recent file list.
193      m_settings.writeEntry("/EngineName", sEngineName);          int iFile = 0;
194      m_settings.writeEntry("/AudioDriver", sAudioDriver);          m_settings.beginGroup("/RecentFiles");
195      m_settings.writeEntry("/MidiDriver", sMidiDriver);          QStringListIterator iter(recentFiles);
196      m_settings.endGroup();          while (iter.hasNext())
197                    m_settings.setValue("/File" + QString::number(++iFile), iter.next());
198      m_settings.endGroup();          m_settings.endGroup();
199    
200            // Default directories.
201            m_settings.beginGroup("/Default");
202            m_settings.setValue("/SessionDir", sSessionDir);
203            m_settings.setValue("/InstrumentDir", sInstrumentDir);
204            m_settings.setValue("/EngineName", sEngineName);
205            m_settings.setValue("/AudioDriver", sAudioDriver);
206            m_settings.setValue("/MidiDriver", sMidiDriver);
207            m_settings.setValue("/MidiMap", iMidiMap);
208            m_settings.setValue("/MidiBank", iMidiBank);
209            m_settings.setValue("/MidiProg", iMidiProg);
210            m_settings.setValue("/Volume", iVolume);
211            m_settings.setValue("/Loadmode", iLoadMode);
212            m_settings.endGroup();
213  }  }
214    
215  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
216  // Settings accessor.  // Settings accessor.
217  //  //
218    
219  QSettings& qsamplerOptions::settings (void)  QSettings& Options::settings (void)
220  {  {
221      return m_settings;          return m_settings;
222  }  }
223    
224    
# Line 179  QSettings& qsamplerOptions::settings (vo Line 227  QSettings& qsamplerOptions::settings (vo
227  //  //
228    
229  // Help about command line options.  // Help about command line options.
230  void qsamplerOptions::print_usage ( const char *arg0 )  void Options::print_usage ( const char *arg0 )
231  {  {
232      const QString sEot = "\n\t";          QTextStream out(stderr);
233      const QString sEol = "\n\n";          out << QObject::tr("Usage: %1 [options] [session-file]\n\n"
234                    QSAMPLER_TITLE " - " QSAMPLER_SUBTITLE "\n\n"
235      fprintf(stderr, QObject::tr("Usage") + ": %s [" + QObject::tr("options") + "] [" +                  "Options:\n\n"
236          QObject::tr("session-file") + "]" + sEol, arg0);                  "  -s, --start\n\tStart linuxsampler server locally\n\n"
237      fprintf(stderr, QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE) + sEol);                  "  -h, --hostname\n\tSpecify linuxsampler server hostname\n\n"
238      fprintf(stderr, QObject::tr("Options") + ":" + sEol);                  "  -p, --port\n\tSpecify linuxsampler server port number\n\n"
239      fprintf(stderr, "  -s, --start" + sEot +                  "  -?, --help\n\tShow help about command line options\n\n"
240          QObject::tr("Start linuxsampler server locally") + sEol);                  "  -v, --version\n\tShow version information\n\n")
241      fprintf(stderr, "  -h, --hostname" + sEot +                  .arg(arg0);
         QObject::tr("Specify linuxsampler server hostname") + sEol);  
     fprintf(stderr, "  -p, --port" + sEot +  
         QObject::tr("Specify linuxsampler server port number") + sEol);  
     fprintf(stderr, "  -?, --help" + sEot +  
         QObject::tr("Show help about command line options") + sEol);  
     fprintf(stderr, "  -v, --version" + sEot +  
         QObject::tr("Show version information") + sEol);  
242  }  }
243    
244    
245  // Parse command line arguments into m_settings.  // Parse command line arguments into m_settings.
246  bool qsamplerOptions::parse_args ( int argc, char **argv )  bool Options::parse_args ( int argc, char **argv )
247  {  {
248      const QString sEol = "\n\n";          QTextStream out(stderr);
249      int iCmdArgs = 0;          const QString sEol = "\n\n";
250            int iCmdArgs = 0;
251      for (int i = 1; i < argc; i++) {  
252            for (int i = 1; i < argc; i++) {
253    
254                    if (iCmdArgs > 0) {
255                            sSessionFile += " ";
256                            sSessionFile += argv[i];
257                            iCmdArgs++;
258                            continue;
259                    }
260    
261                    QString sArg = argv[i];
262                    QString sVal = QString::null;
263                    int iEqual = sArg.indexOf("=");
264                    if (iEqual >= 0) {
265                            sVal = sArg.right(sArg.length() - iEqual - 1);
266                            sArg = sArg.left(iEqual);
267                    }
268                    else if (i < argc)
269                            sVal = argv[i + 1];
270    
271                    if (sArg == "-s" || sArg == "--start") {
272                            bServerStart = true;
273                    }
274                    else if (sArg == "-h" || sArg == "--hostname") {
275                            if (sVal.isNull()) {
276                                    out << QObject::tr("Option -h requires an argument (hostname).") + sEol;
277                                    return false;
278                            }
279                            sServerHost = sVal;
280                            if (iEqual < 0)
281                                    i++;
282                    }
283                    else if (sArg == "-p" || sArg == "--port") {
284                            if (sVal.isNull()) {
285                                    out << QObject::tr("Option -p requires an argument (port).") + sEol;
286                                    return false;
287                            }
288                            iServerPort = sVal.toInt();
289                            if (iEqual < 0)
290                                    i++;
291                    }
292                    else if (sArg == "-?" || sArg == "--help") {
293                            print_usage(argv[0]);
294                            return false;
295                    }
296                    else if (sArg == "-v" || sArg == "--version") {
297                            out << QObject::tr("Qt: %1\n").arg(qVersion());
298    #ifdef CONFIG_LIBGIG
299                            out << QString("%1: %2\n")
300                                    .arg(gig::libraryName().c_str())
301                                    .arg(gig::libraryVersion().c_str());
302    #endif
303                            out << QString("%1: %2\n")
304                                    .arg(::lscp_client_package())
305                                    .arg(::lscp_client_version());
306                            out << QObject::tr(QSAMPLER_TITLE ": %1\n").arg(QSAMPLER_VERSION);
307                            return false;
308                    }
309                    else {
310                            // If we don't have one by now,
311                            // this will be the startup sesion file...
312                            sSessionFile += sArg;
313                            iCmdArgs++;
314                    }
315            }
316    
317          if (iCmdArgs > 0) {          // Alright with argument parsing.
318              sSessionFile += " ";          return true;
             sSessionFile += argv[i];  
             iCmdArgs++;  
             continue;  
         }  
   
         QString sArg = argv[i];  
         QString sVal = QString::null;  
         int iEqual = sArg.find("=");  
         if (iEqual >= 0) {  
             sVal = sArg.right(sArg.length() - iEqual - 1);  
             sArg = sArg.left(iEqual);  
         }  
         else if (i < argc)  
             sVal = argv[i + 1];  
   
         if (sArg == "-s" || sArg == "--start") {  
             bServerStart = true;  
         }  
         else if (sArg == "-h" || sArg == "--hostname") {  
             if (sVal.isNull()) {  
                 fprintf(stderr, QObject::tr("Option -h requires an argument (hostname).") + sEol);  
                 return false;  
             }  
             sServerHost = sVal;  
             if (iEqual < 0)  
                 i++;  
         }  
         else if (sArg == "-p" || sArg == "--port") {  
             if (sVal.isNull()) {  
                 fprintf(stderr, QObject::tr("Option -p requires an argument (port).") + sEol);  
                 return false;  
             }  
             iServerPort = sVal.toInt();  
             if (iEqual < 0)  
                 i++;  
         }  
         else if (sArg == "-?" || sArg == "--help") {  
             print_usage(argv[0]);  
             return false;  
         }  
         else if (sArg == "-v" || sArg == "--version") {  
             fprintf(stderr, "Qt: %s\n", qVersion());  
             fprintf(stderr, "liblscp: %s\n", ::lscp_client_version());  
             fprintf(stderr, "qsampler: %s\n", QSAMPLER_VERSION);  
             return false;  
         }  
         else {  
             // If we don't have one by now,  
             // this will be the startup sesion file...  
             sSessionFile += sArg;  
             iCmdArgs++;  
         }  
     }  
   
     // Alright with argument parsing.  
     return true;  
319  }  }
320    
321    
322  //---------------------------------------------------------------------------  //---------------------------------------------------------------------------
323  // Widget geometry persistence helper methods.  // Widget geometry persistence helper methods.
324    
325  void qsamplerOptions::loadWidgetGeometry ( QWidget *pWidget )  void Options::loadWidgetGeometry ( QWidget *pWidget )
326  {  {
327      // Try to restore old form window positioning.          // Try to restore old form window positioning.
328      if (pWidget) {          if (pWidget) {
329          QPoint fpos;                  QPoint fpos;
330          QSize  fsize;                  QSize  fsize;
331          bool bVisible;                  bool bVisible;
332          m_settings.beginGroup("/Geometry/" + QString(pWidget->name()));                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());
333          fpos.setX(m_settings.readNumEntry("/x", -1));                  fpos.setX(m_settings.value("/x", -1).toInt());
334          fpos.setY(m_settings.readNumEntry("/y", -1));                  fpos.setY(m_settings.value("/y", -1).toInt());
335          fsize.setWidth(m_settings.readNumEntry("/width", -1));                  fsize.setWidth(m_settings.value("/width", -1).toInt());
336          fsize.setHeight(m_settings.readNumEntry("/height", -1));                  fsize.setHeight(m_settings.value("/height", -1).toInt());
337          bVisible = m_settings.readBoolEntry("/visible", false);                  bVisible = m_settings.value("/visible", false).toBool();
338          m_settings.endGroup();                  m_settings.endGroup();
339          if (fpos.x() > 0 && fpos.y() > 0)                  if (fpos.x() > 0 && fpos.y() > 0)
340              pWidget->move(fpos);                          pWidget->move(fpos);
341          if (fsize.width() > 0 && fsize.height() > 0)                  if (fsize.width() > 0 && fsize.height() > 0)
342              pWidget->resize(fsize);                          pWidget->resize(fsize);
343          else                  else
344              pWidget->adjustSize();                          pWidget->adjustSize();
345          if (bVisible)                  if (bVisible)
346              pWidget->show();                          pWidget->show();
347          else                  else
348              pWidget->hide();                          pWidget->hide();
349      }          }
350  }  }
351    
352    
353  void qsamplerOptions::saveWidgetGeometry ( QWidget *pWidget )  void Options::saveWidgetGeometry ( QWidget *pWidget )
354  {  {
355      // Try to save form window position...          // Try to save form window position...
356      // (due to X11 window managers ideossincrasies, we better          // (due to X11 window managers ideossincrasies, we better
357      // only save the form geometry while its up and visible)          // only save the form geometry while its up and visible)
358      if (pWidget) {          if (pWidget) {
359          m_settings.beginGroup("/Geometry/" + QString(pWidget->name()));                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());
360          bool bVisible = pWidget->isVisible();                  bool bVisible = pWidget->isVisible();
361          if (bVisible) {                  const QPoint& fpos  = pWidget->pos();
362              QPoint fpos  = pWidget->pos();                  const QSize&  fsize = pWidget->size();
363              QSize  fsize = pWidget->size();                  m_settings.setValue("/x", fpos.x());
364              m_settings.writeEntry("/x", fpos.x());                  m_settings.setValue("/y", fpos.y());
365              m_settings.writeEntry("/y", fpos.y());                  m_settings.setValue("/width", fsize.width());
366              m_settings.writeEntry("/width", fsize.width());                  m_settings.setValue("/height", fsize.height());
367              m_settings.writeEntry("/height", fsize.height());                  m_settings.setValue("/visible", bVisible);
368          }                  m_settings.endGroup();
369          m_settings.writeEntry("/visible", bVisible);          }
         m_settings.endGroup();  
     }  
370  }  }
371    
372    
373  //---------------------------------------------------------------------------  //---------------------------------------------------------------------------
374  // Combo box history persistence helper implementation.  // Combo box history persistence helper implementation.
375    
376  void qsamplerOptions::add2ComboBoxHistory ( QComboBox *pComboBox, const QString& sNewText, int iLimit, int iIndex )  void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )
377  {  {
378      int iCount = pComboBox->count();          // Load combobox list from configuration settings file...
379      for (int i = 0; i < iCount; i++) {          m_settings.beginGroup("/History/" + pComboBox->objectName());
         QString sText = pComboBox->text(i);  
         if (sText == sNewText) {  
             pComboBox->removeItem(i);  
             iCount--;  
             break;  
         }  
     }  
     while (iCount >= iLimit)  
         pComboBox->removeItem(--iCount);  
     pComboBox->insertItem(sNewText, iIndex);  
 }  
380    
381            if (m_settings.childKeys().count() > 0) {
382                    pComboBox->setUpdatesEnabled(false);
383                    pComboBox->setDuplicatesEnabled(false);
384                    pComboBox->clear();
385                    for (int i = 0; i < iLimit; i++) {
386                            const QString& sText = m_settings.value(
387                                    "/Item" + QString::number(i + 1)).toString();
388                            if (sText.isEmpty())
389                                    break;
390                            pComboBox->addItem(sText);
391                    }
392                    pComboBox->setUpdatesEnabled(true);
393            }
394    
395  void qsamplerOptions::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )          m_settings.endGroup();
 {  
     pComboBox->setUpdatesEnabled(false);  
     pComboBox->setDuplicatesEnabled(false);  
   
     m_settings.beginGroup("/History/" + QString(pComboBox->name()));  
     for (int i = 0; i < iLimit; i++) {  
         QString sText = m_settings.readEntry("/Item" + QString::number(i + 1), QString::null);  
         if (sText.isEmpty())  
             break;  
         add2ComboBoxHistory(pComboBox, sText, iLimit);  
     }  
     m_settings.endGroup();  
   
     pComboBox->setUpdatesEnabled(true);  
396  }  }
397    
398    
399  void qsamplerOptions::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )  void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )
400  {  {
401      add2ComboBoxHistory(pComboBox, pComboBox->currentText(), iLimit, 0);          // Add current text as latest item...
402            const QString& sCurrentText = pComboBox->currentText();
403      m_settings.beginGroup("/History/" + QString(pComboBox->name()));          int iCount = pComboBox->count();
404      for (int i = 0; i < iLimit && i < pComboBox->count(); i++) {          for (int i = 0; i < iCount; i++) {
405          QString sText = pComboBox->text(i);                  const QString& sText = pComboBox->itemText(i);
406          if (sText.isEmpty())                  if (sText == sCurrentText) {
407              break;                          pComboBox->removeItem(i);
408          m_settings.writeEntry("/Item" + QString::number(i + 1), sText);                          iCount--;
409      }                          break;
410      m_settings.endGroup();                  }
411            }
412            while (iCount >= iLimit)
413                    pComboBox->removeItem(--iCount);
414            pComboBox->insertItem(0, sCurrentText);
415            iCount++;
416    
417            // Save combobox list to configuration settings file...
418            m_settings.beginGroup("/History/" + pComboBox->objectName());
419            for (int i = 0; i < iCount; i++) {
420                    const QString& sText = pComboBox->itemText(i);
421                    if (sText.isEmpty())
422                            break;
423                    m_settings.setValue("/Item" + QString::number(i + 1), sText);
424            }
425            m_settings.endGroup();
426  }  }
427    
428    } // namespace QSampler
429    
430    
431  // end of qsamplerOptions.cpp  // end of qsamplerOptions.cpp

Legend:
Removed from v.267  
changed lines
  Added in v.1749

  ViewVC Help
Powered by ViewVC