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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 267 - (show annotations) (download)
Wed Oct 6 15:42:59 2004 UTC (15 years, 6 months ago) by capela
File size: 13650 byte(s)
* Channel strip display glass effect is now an option.

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

  ViewVC Help
Powered by ViewVC