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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 119 - (show annotations) (download)
Wed Jun 9 20:24:48 2004 UTC (15 years, 3 months ago) by capela
File size: 13129 byte(s)
* Maximum channel volume percent setting is now a global option,
  provided to override the default (which is 100%).

* Client/server transaction timeout option upper limit has been
  increased from 5000 to 60000 milliseconds.

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

  ViewVC Help
Powered by ViewVC