/[svn]/qsampler/trunk/src/qsamplerOptions.cpp
ViewVC logotype

Annotation of /qsampler/trunk/src/qsamplerOptions.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1558 - (hide annotations) (download)
Thu Dec 6 09:35:33 2007 UTC (16 years, 3 months ago) by capela
File size: 13269 byte(s)
* Qt4 migration: complete QSampler namespace overhaul.

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

  ViewVC Help
Powered by ViewVC