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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1499 - (hide annotations) (download)
Tue Nov 20 16:48:04 2007 UTC (16 years, 5 months ago) by capela
File size: 13846 byte(s)
* Qt4 migration: one first step forward to kiss Qt3Support goodbye.

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

  ViewVC Help
Powered by ViewVC