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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 605 - (show annotations) (download)
Fri Jun 3 10:19:42 2005 UTC (18 years, 10 months ago) by capela
File size: 14111 byte(s)
Include libgig version info on command line request (-v).

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

  ViewVC Help
Powered by ViewVC