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

Legend:
Removed from v.119  
changed lines
  Added in v.1527

  ViewVC Help
Powered by ViewVC