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