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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 454 - (show annotations) (download)
Mon Mar 14 10:59:57 2005 UTC (13 years, 7 months ago) by capela
File size: 13914 byte(s)
New keep child windows always on top option; device icon retouching;

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

  ViewVC Help
Powered by ViewVC