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

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

  ViewVC Help
Powered by ViewVC