1 |
// qsamplerOptions.cpp |
// qsamplerOptions.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2015, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2019, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007,2015 Christian Schoenebeck |
Copyright (C) 2007,2008,2015 Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
27 |
#include <QTextStream> |
#include <QTextStream> |
28 |
#include <QComboBox> |
#include <QComboBox> |
29 |
|
|
30 |
|
#include <QApplication> |
31 |
|
#include <QDesktopWidget> |
32 |
|
|
33 |
#include <lscp/client.h> |
#include <lscp/client.h> |
34 |
|
|
35 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
100 |
bMessagesLimit = m_settings.value("/MessagesLimit", true).toBool(); |
bMessagesLimit = m_settings.value("/MessagesLimit", true).toBool(); |
101 |
iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt(); |
iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt(); |
102 |
bConfirmRemove = m_settings.value("/ConfirmRemove", true).toBool(); |
bConfirmRemove = m_settings.value("/ConfirmRemove", true).toBool(); |
103 |
|
bConfirmReset = m_settings.value("/ConfirmReset", true).toBool(); |
104 |
|
bConfirmRestart = m_settings.value("/ConfirmRestart", true).toBool(); |
105 |
|
bConfirmError = m_settings.value("/ConfirmError", true).toBool(); |
106 |
bKeepOnTop = m_settings.value("/KeepOnTop", true).toBool(); |
bKeepOnTop = m_settings.value("/KeepOnTop", true).toBool(); |
107 |
bStdoutCapture = m_settings.value("/StdoutCapture", true).toBool(); |
bStdoutCapture = m_settings.value("/StdoutCapture", true).toBool(); |
108 |
bCompletePath = m_settings.value("/CompletePath", true).toBool(); |
bCompletePath = m_settings.value("/CompletePath", true).toBool(); |
117 |
#endif |
#endif |
118 |
m_settings.endGroup(); |
m_settings.endGroup(); |
119 |
|
|
120 |
|
// Load custom options... |
121 |
|
m_settings.beginGroup("/Custom"); |
122 |
|
sCustomColorTheme = m_settings.value("/ColorTheme").toString(); |
123 |
|
sCustomStyleTheme = m_settings.value("/StyleTheme").toString(); |
124 |
|
m_settings.endGroup(); |
125 |
|
|
126 |
// And go into view options group. |
// And go into view options group. |
127 |
m_settings.beginGroup("/View"); |
m_settings.beginGroup("/View"); |
128 |
bMenubar = m_settings.value("/Menubar", true).toBool(); |
bMenubar = m_settings.value("/Menubar", true).toBool(); |
171 |
{ |
{ |
172 |
// Make program version available in the future. |
// Make program version available in the future. |
173 |
m_settings.beginGroup("/Program"); |
m_settings.beginGroup("/Program"); |
174 |
m_settings.setValue("/Version", QSAMPLER_VERSION); |
m_settings.setValue("/Version", CONFIG_BUILD_VERSION); |
175 |
m_settings.endGroup(); |
m_settings.endGroup(); |
176 |
|
|
177 |
// And go into general options group. |
// And go into general options group. |
204 |
m_settings.setValue("/MessagesLimit", bMessagesLimit); |
m_settings.setValue("/MessagesLimit", bMessagesLimit); |
205 |
m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines); |
m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines); |
206 |
m_settings.setValue("/ConfirmRemove", bConfirmRemove); |
m_settings.setValue("/ConfirmRemove", bConfirmRemove); |
207 |
|
m_settings.setValue("/ConfirmReset", bConfirmReset); |
208 |
|
m_settings.setValue("/ConfirmRestart", bConfirmRestart); |
209 |
|
m_settings.setValue("/ConfirmError", bConfirmError); |
210 |
m_settings.setValue("/KeepOnTop", bKeepOnTop); |
m_settings.setValue("/KeepOnTop", bKeepOnTop); |
211 |
m_settings.setValue("/StdoutCapture", bStdoutCapture); |
m_settings.setValue("/StdoutCapture", bStdoutCapture); |
212 |
m_settings.setValue("/CompletePath", bCompletePath); |
m_settings.setValue("/CompletePath", bCompletePath); |
215 |
m_settings.setValue("/InstrumentNames", bInstrumentNames); |
m_settings.setValue("/InstrumentNames", bInstrumentNames); |
216 |
m_settings.endGroup(); |
m_settings.endGroup(); |
217 |
|
|
218 |
|
// Save custom options... |
219 |
|
m_settings.beginGroup("/Custom"); |
220 |
|
m_settings.setValue("/ColorTheme", sCustomColorTheme); |
221 |
|
m_settings.setValue("/StyleTheme", sCustomStyleTheme); |
222 |
|
m_settings.endGroup(); |
223 |
|
|
224 |
// View options group. |
// View options group. |
225 |
m_settings.beginGroup("/View"); |
m_settings.beginGroup("/View"); |
226 |
m_settings.setValue("/Menubar", bMenubar); |
m_settings.setValue("/Menubar", bMenubar); |
301 |
{ |
{ |
302 |
QTextStream out(stderr); |
QTextStream out(stderr); |
303 |
const QString sEol = "\n\n"; |
const QString sEol = "\n\n"; |
|
int iCmdArgs = 0; |
|
304 |
const int argc = args.count(); |
const int argc = args.count(); |
305 |
|
int iCmdArgs = 0; |
306 |
|
|
307 |
for (int i = 1; i < argc; i++) { |
for (int i = 1; i < argc; ++i) { |
308 |
|
|
309 |
if (iCmdArgs > 0) { |
if (iCmdArgs > 0) { |
310 |
sSessionFile += " "; |
sSessionFile += " "; |
311 |
sSessionFile += args.at(i); |
sSessionFile += args.at(i); |
312 |
iCmdArgs++; |
++iCmdArgs; |
313 |
continue; |
continue; |
314 |
} |
} |
315 |
|
|
316 |
QString sArg = args.at(i); |
QString sArg = args.at(i); |
317 |
QString sVal = QString::null; |
QString sVal; |
318 |
const int iEqual = sArg.indexOf("="); |
const int iEqual = sArg.indexOf("="); |
319 |
if (iEqual >= 0) { |
if (iEqual >= 0) { |
320 |
sVal = sArg.right(sArg.length() - iEqual - 1); |
sVal = sArg.right(sArg.length() - iEqual - 1); |
336 |
} |
} |
337 |
sServerHost = sVal; |
sServerHost = sVal; |
338 |
if (iEqual < 0) |
if (iEqual < 0) |
339 |
i++; |
++i; |
340 |
} |
} |
341 |
else if (sArg == "-p" || sArg == "--port") { |
else if (sArg == "-p" || sArg == "--port") { |
342 |
if (sVal.isNull()) { |
if (sVal.isNull()) { |
345 |
} |
} |
346 |
iServerPort = sVal.toInt(); |
iServerPort = sVal.toInt(); |
347 |
if (iEqual < 0) |
if (iEqual < 0) |
348 |
i++; |
++i; |
349 |
} |
} |
350 |
else if (sArg == "-?" || sArg == "--help") { |
else if (sArg == "-?" || sArg == "--help") { |
351 |
print_usage(args.at(0)); |
print_usage(args.at(0)); |
352 |
return false; |
return false; |
353 |
} |
} |
354 |
else if (sArg == "-v" || sArg == "--version") { |
else if (sArg == "-v" || sArg == "--version") { |
355 |
out << QObject::tr("Qt: %1\n").arg(qVersion()); |
out << QString("Qt: %1\n") |
356 |
|
.arg(qVersion()); |
357 |
|
out << QString("%1: %2\n") |
358 |
|
.arg(QSAMPLER_TITLE) |
359 |
|
.arg(CONFIG_BUILD_VERSION); |
360 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
361 |
out << QString("%1: %2\n") |
out << QString("%1: %2\n") |
362 |
.arg(gig::libraryName().c_str()) |
.arg(gig::libraryName().c_str()) |
365 |
out << QString("%1: %2\n") |
out << QString("%1: %2\n") |
366 |
.arg(::lscp_client_package()) |
.arg(::lscp_client_package()) |
367 |
.arg(::lscp_client_version()); |
.arg(::lscp_client_version()); |
|
out << QObject::tr(QSAMPLER_TITLE ": %1\n").arg(QSAMPLER_VERSION); |
|
368 |
return false; |
return false; |
369 |
} |
} |
370 |
else { |
else { |
371 |
// If we don't have one by now, |
// If we don't have one by now, |
372 |
// this will be the startup sesion file... |
// this will be the startup sesion file... |
373 |
sSessionFile += sArg; |
sSessionFile += sArg; |
374 |
iCmdArgs++; |
++iCmdArgs; |
375 |
} |
} |
376 |
} |
} |
377 |
|
|
387 |
{ |
{ |
388 |
// Try to restore old form window positioning. |
// Try to restore old form window positioning. |
389 |
if (pWidget) { |
if (pWidget) { |
390 |
|
// if (bVisible) pWidget->show(); -- force initial exposure? |
391 |
|
m_settings.beginGroup("/Geometry/" + pWidget->objectName()); |
392 |
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
393 |
|
const QByteArray& geometry |
394 |
|
= m_settings.value("/geometry").toByteArray(); |
395 |
|
if (geometry.isEmpty()) { |
396 |
|
QWidget *pParent = pWidget->parentWidget(); |
397 |
|
if (pParent) |
398 |
|
pParent = pParent->window(); |
399 |
|
if (pParent == nullptr) |
400 |
|
pParent = QApplication::desktop(); |
401 |
|
if (pParent) { |
402 |
|
QRect wrect(pWidget->geometry()); |
403 |
|
wrect.moveCenter(pParent->geometry().center()); |
404 |
|
pWidget->move(wrect.topLeft()); |
405 |
|
} |
406 |
|
} else { |
407 |
|
pWidget->restoreGeometry(geometry); |
408 |
|
} |
409 |
|
#else//--LOAD_OLD_GEOMETRY |
410 |
QPoint wpos; |
QPoint wpos; |
411 |
QSize wsize; |
QSize wsize; |
|
m_settings.beginGroup("/Geometry/" + pWidget->objectName()); |
|
412 |
wpos.setX(m_settings.value("/x", -1).toInt()); |
wpos.setX(m_settings.value("/x", -1).toInt()); |
413 |
wpos.setY(m_settings.value("/y", -1).toInt()); |
wpos.setY(m_settings.value("/y", -1).toInt()); |
414 |
wsize.setWidth(m_settings.value("/width", -1).toInt()); |
wsize.setWidth(m_settings.value("/width", -1).toInt()); |
415 |
wsize.setHeight(m_settings.value("/height", -1).toInt()); |
wsize.setHeight(m_settings.value("/height", -1).toInt()); |
|
if (!bVisible) bVisible = m_settings.value("/visible", false).toBool(); |
|
|
m_settings.endGroup(); |
|
416 |
if (wpos.x() > 0 && wpos.y() > 0) |
if (wpos.x() > 0 && wpos.y() > 0) |
417 |
pWidget->move(wpos); |
pWidget->move(wpos); |
418 |
if (wsize.width() > 0 && wsize.height() > 0) |
if (wsize.width() > 0 && wsize.height() > 0) |
419 |
pWidget->resize(wsize); |
pWidget->resize(wsize); |
420 |
|
#endif |
421 |
// else |
// else |
422 |
// pWidget->adjustSize(); |
// pWidget->adjustSize(); |
423 |
|
if (!bVisible) |
424 |
|
bVisible = m_settings.value("/visible", false).toBool(); |
425 |
if (bVisible) |
if (bVisible) |
426 |
pWidget->show(); |
pWidget->show(); |
427 |
// else |
else |
428 |
// pWidget->hide(); |
pWidget->hide(); |
429 |
|
m_settings.endGroup(); |
430 |
} |
} |
431 |
} |
} |
432 |
|
|
438 |
// only save the form geometry while its up and visible) |
// only save the form geometry while its up and visible) |
439 |
if (pWidget) { |
if (pWidget) { |
440 |
m_settings.beginGroup("/Geometry/" + pWidget->objectName()); |
m_settings.beginGroup("/Geometry/" + pWidget->objectName()); |
441 |
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
442 |
|
m_settings.setValue("/geometry", pWidget->saveGeometry()); |
443 |
|
#else//--SAVE_OLD_GEOMETRY |
444 |
const QPoint& wpos = pWidget->pos(); |
const QPoint& wpos = pWidget->pos(); |
445 |
const QSize& wsize = pWidget->size(); |
const QSize& wsize = pWidget->size(); |
|
if (!bVisible) bVisible = pWidget->isVisible(); |
|
446 |
m_settings.setValue("/x", wpos.x()); |
m_settings.setValue("/x", wpos.x()); |
447 |
m_settings.setValue("/y", wpos.y()); |
m_settings.setValue("/y", wpos.y()); |
448 |
m_settings.setValue("/width", wsize.width()); |
m_settings.setValue("/width", wsize.width()); |
449 |
m_settings.setValue("/height", wsize.height()); |
m_settings.setValue("/height", wsize.height()); |
450 |
|
#endif |
451 |
|
if (!bVisible) bVisible = pWidget->isVisible(); |
452 |
m_settings.setValue("/visible", bVisible); |
m_settings.setValue("/visible", bVisible); |
453 |
m_settings.endGroup(); |
m_settings.endGroup(); |
454 |
} |
} |
460 |
|
|
461 |
void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit ) |
void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit ) |
462 |
{ |
{ |
463 |
|
const bool bBlockSignals = pComboBox->blockSignals(true); |
464 |
|
|
465 |
// Load combobox list from configuration settings file... |
// Load combobox list from configuration settings file... |
466 |
m_settings.beginGroup("/History/" + pComboBox->objectName()); |
m_settings.beginGroup("/History/" + pComboBox->objectName()); |
467 |
|
|
469 |
pComboBox->setUpdatesEnabled(false); |
pComboBox->setUpdatesEnabled(false); |
470 |
pComboBox->setDuplicatesEnabled(false); |
pComboBox->setDuplicatesEnabled(false); |
471 |
pComboBox->clear(); |
pComboBox->clear(); |
472 |
for (int i = 0; i < iLimit; i++) { |
for (int i = 0; i < iLimit; ++i) { |
473 |
const QString& sText = m_settings.value( |
const QString& sText = m_settings.value( |
474 |
"/Item" + QString::number(i + 1)).toString(); |
"/Item" + QString::number(i + 1)).toString(); |
475 |
if (sText.isEmpty()) |
if (sText.isEmpty()) |
480 |
} |
} |
481 |
|
|
482 |
m_settings.endGroup(); |
m_settings.endGroup(); |
483 |
|
|
484 |
|
pComboBox->blockSignals(bBlockSignals); |
485 |
} |
} |
486 |
|
|
487 |
|
|
488 |
void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit ) |
void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit ) |
489 |
{ |
{ |
490 |
|
const bool bBlockSignals = pComboBox->blockSignals(true); |
491 |
|
|
492 |
// Add current text as latest item... |
// Add current text as latest item... |
493 |
const QString& sCurrentText = pComboBox->currentText(); |
const QString sCurrentText = pComboBox->currentText(); |
494 |
int iCount = pComboBox->count(); |
int iCount = pComboBox->count(); |
495 |
for (int i = 0; i < iCount; i++) { |
for (int i = 0; i < iCount; i++) { |
496 |
const QString& sText = pComboBox->itemText(i); |
const QString& sText = pComboBox->itemText(i); |
497 |
if (sText == sCurrentText) { |
if (sText == sCurrentText) { |
498 |
pComboBox->removeItem(i); |
pComboBox->removeItem(i); |
499 |
iCount--; |
--iCount; |
500 |
break; |
break; |
501 |
} |
} |
502 |
} |
} |
503 |
while (iCount >= iLimit) |
while (iCount >= iLimit) |
504 |
pComboBox->removeItem(--iCount); |
pComboBox->removeItem(--iCount); |
505 |
pComboBox->insertItem(0, sCurrentText); |
pComboBox->insertItem(0, sCurrentText); |
506 |
iCount++; |
pComboBox->setCurrentIndex(0); |
507 |
|
++iCount; |
508 |
|
|
509 |
// Save combobox list to configuration settings file... |
// Save combobox list to configuration settings file... |
510 |
m_settings.beginGroup("/History/" + pComboBox->objectName()); |
m_settings.beginGroup("/History/" + pComboBox->objectName()); |
511 |
for (int i = 0; i < iCount; i++) { |
for (int i = 0; i < iCount; ++i) { |
512 |
const QString& sText = pComboBox->itemText(i); |
const QString& sText = pComboBox->itemText(i); |
513 |
if (sText.isEmpty()) |
if (sText.isEmpty()) |
514 |
break; |
break; |
515 |
m_settings.setValue("/Item" + QString::number(i + 1), sText); |
m_settings.setValue("/Item" + QString::number(i + 1), sText); |
516 |
} |
} |
517 |
m_settings.endGroup(); |
m_settings.endGroup(); |
518 |
|
|
519 |
|
pComboBox->blockSignals(bBlockSignals); |
520 |
} |
} |
521 |
|
|
522 |
|
|
523 |
int Options::getMaxVoices() { |
int Options::getMaxVoices() { |
524 |
#ifndef CONFIG_MAX_VOICES |
#ifndef CONFIG_MAX_VOICES |
525 |
return -1; |
return -1; |
617 |
|
|
618 |
|
|
619 |
// end of qsamplerOptions.cpp |
// end of qsamplerOptions.cpp |
620 |
|
|