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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 106 - (show annotations) (download)
Fri Jun 4 18:34:58 2004 UTC (19 years, 9 months ago) by capela
File size: 13009 byte(s)
Initial alpha release.

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

  ViewVC Help
Powered by ViewVC