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

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

  ViewVC Help
Powered by ViewVC