1 |
// qsamplerOptions.cpp |
// qsamplerOptions.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2015, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2021, 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 |
|
|
32 |
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
33 |
|
#include <QDesktopWidget> |
34 |
|
#endif |
35 |
|
|
36 |
#include <lscp/client.h> |
#include <lscp/client.h> |
37 |
|
|
38 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
39 |
|
#if defined(Q_CC_GNU) || defined(Q_CC_MINGW) |
40 |
|
#pragma GCC diagnostic push |
41 |
|
#pragma GCC diagnostic ignored "-Wunused-parameter" |
42 |
|
#endif |
43 |
#include <gig.h> |
#include <gig.h> |
44 |
|
#if defined(Q_CC_GNU) || defined(Q_CC_MINGW) |
45 |
|
#pragma GCC diagnostic pop |
46 |
|
#endif |
47 |
#endif |
#endif |
48 |
|
|
49 |
|
|
110 |
bMessagesLimit = m_settings.value("/MessagesLimit", true).toBool(); |
bMessagesLimit = m_settings.value("/MessagesLimit", true).toBool(); |
111 |
iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt(); |
iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt(); |
112 |
bConfirmRemove = m_settings.value("/ConfirmRemove", true).toBool(); |
bConfirmRemove = m_settings.value("/ConfirmRemove", true).toBool(); |
113 |
|
bConfirmReset = m_settings.value("/ConfirmReset", true).toBool(); |
114 |
|
bConfirmRestart = m_settings.value("/ConfirmRestart", true).toBool(); |
115 |
|
bConfirmError = m_settings.value("/ConfirmError", true).toBool(); |
116 |
bKeepOnTop = m_settings.value("/KeepOnTop", true).toBool(); |
bKeepOnTop = m_settings.value("/KeepOnTop", true).toBool(); |
117 |
bStdoutCapture = m_settings.value("/StdoutCapture", true).toBool(); |
bStdoutCapture = m_settings.value("/StdoutCapture", true).toBool(); |
118 |
bCompletePath = m_settings.value("/CompletePath", true).toBool(); |
bCompletePath = m_settings.value("/CompletePath", true).toBool(); |
127 |
#endif |
#endif |
128 |
m_settings.endGroup(); |
m_settings.endGroup(); |
129 |
|
|
130 |
|
// Load custom options... |
131 |
|
m_settings.beginGroup("/Custom"); |
132 |
|
sCustomColorTheme = m_settings.value("/ColorTheme").toString(); |
133 |
|
sCustomStyleTheme = m_settings.value("/StyleTheme").toString(); |
134 |
|
m_settings.endGroup(); |
135 |
|
|
136 |
// And go into view options group. |
// And go into view options group. |
137 |
m_settings.beginGroup("/View"); |
m_settings.beginGroup("/View"); |
138 |
bMenubar = m_settings.value("/Menubar", true).toBool(); |
bMenubar = m_settings.value("/Menubar", true).toBool(); |
181 |
{ |
{ |
182 |
// Make program version available in the future. |
// Make program version available in the future. |
183 |
m_settings.beginGroup("/Program"); |
m_settings.beginGroup("/Program"); |
184 |
m_settings.setValue("/Version", QSAMPLER_VERSION); |
m_settings.setValue("/Version", CONFIG_BUILD_VERSION); |
185 |
m_settings.endGroup(); |
m_settings.endGroup(); |
186 |
|
|
187 |
// And go into general options group. |
// And go into general options group. |
214 |
m_settings.setValue("/MessagesLimit", bMessagesLimit); |
m_settings.setValue("/MessagesLimit", bMessagesLimit); |
215 |
m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines); |
m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines); |
216 |
m_settings.setValue("/ConfirmRemove", bConfirmRemove); |
m_settings.setValue("/ConfirmRemove", bConfirmRemove); |
217 |
|
m_settings.setValue("/ConfirmReset", bConfirmReset); |
218 |
|
m_settings.setValue("/ConfirmRestart", bConfirmRestart); |
219 |
|
m_settings.setValue("/ConfirmError", bConfirmError); |
220 |
m_settings.setValue("/KeepOnTop", bKeepOnTop); |
m_settings.setValue("/KeepOnTop", bKeepOnTop); |
221 |
m_settings.setValue("/StdoutCapture", bStdoutCapture); |
m_settings.setValue("/StdoutCapture", bStdoutCapture); |
222 |
m_settings.setValue("/CompletePath", bCompletePath); |
m_settings.setValue("/CompletePath", bCompletePath); |
225 |
m_settings.setValue("/InstrumentNames", bInstrumentNames); |
m_settings.setValue("/InstrumentNames", bInstrumentNames); |
226 |
m_settings.endGroup(); |
m_settings.endGroup(); |
227 |
|
|
228 |
|
// Save custom options... |
229 |
|
m_settings.beginGroup("/Custom"); |
230 |
|
m_settings.setValue("/ColorTheme", sCustomColorTheme); |
231 |
|
m_settings.setValue("/StyleTheme", sCustomStyleTheme); |
232 |
|
m_settings.endGroup(); |
233 |
|
|
234 |
// View options group. |
// View options group. |
235 |
m_settings.beginGroup("/View"); |
m_settings.beginGroup("/View"); |
236 |
m_settings.setValue("/Menubar", bMenubar); |
m_settings.setValue("/Menubar", bMenubar); |
311 |
{ |
{ |
312 |
QTextStream out(stderr); |
QTextStream out(stderr); |
313 |
const QString sEol = "\n\n"; |
const QString sEol = "\n\n"; |
|
int iCmdArgs = 0; |
|
314 |
const int argc = args.count(); |
const int argc = args.count(); |
315 |
|
int iCmdArgs = 0; |
316 |
|
|
317 |
for (int i = 1; i < argc; i++) { |
for (int i = 1; i < argc; ++i) { |
318 |
|
|
319 |
if (iCmdArgs > 0) { |
if (iCmdArgs > 0) { |
320 |
sSessionFile += " "; |
sSessionFile += " "; |
321 |
sSessionFile += args.at(i); |
sSessionFile += args.at(i); |
322 |
iCmdArgs++; |
++iCmdArgs; |
323 |
continue; |
continue; |
324 |
} |
} |
325 |
|
|
326 |
QString sArg = args.at(i); |
QString sArg = args.at(i); |
327 |
QString sVal = QString::null; |
QString sVal; |
328 |
const int iEqual = sArg.indexOf("="); |
const int iEqual = sArg.indexOf("="); |
329 |
if (iEqual >= 0) { |
if (iEqual >= 0) { |
330 |
sVal = sArg.right(sArg.length() - iEqual - 1); |
sVal = sArg.right(sArg.length() - iEqual - 1); |
346 |
} |
} |
347 |
sServerHost = sVal; |
sServerHost = sVal; |
348 |
if (iEqual < 0) |
if (iEqual < 0) |
349 |
i++; |
++i; |
350 |
} |
} |
351 |
else if (sArg == "-p" || sArg == "--port") { |
else if (sArg == "-p" || sArg == "--port") { |
352 |
if (sVal.isNull()) { |
if (sVal.isNull()) { |
355 |
} |
} |
356 |
iServerPort = sVal.toInt(); |
iServerPort = sVal.toInt(); |
357 |
if (iEqual < 0) |
if (iEqual < 0) |
358 |
i++; |
++i; |
359 |
} |
} |
360 |
else if (sArg == "-?" || sArg == "--help") { |
else if (sArg == "-?" || sArg == "--help") { |
361 |
print_usage(args.at(0)); |
print_usage(args.at(0)); |
362 |
return false; |
return false; |
363 |
} |
} |
364 |
else if (sArg == "-v" || sArg == "--version") { |
else if (sArg == "-v" || sArg == "--version") { |
365 |
out << QObject::tr("Qt: %1\n").arg(qVersion()); |
out << QString("Qt: %1").arg(qVersion()); |
366 |
|
#if defined(QT_STATIC) |
367 |
|
out << "-static"; |
368 |
|
#endif |
369 |
|
out << '\n'; |
370 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
371 |
out << QString("%1: %2\n") |
out << QString("%1: %2\n") |
372 |
.arg(gig::libraryName().c_str()) |
.arg(gig::libraryName().c_str()) |
375 |
out << QString("%1: %2\n") |
out << QString("%1: %2\n") |
376 |
.arg(::lscp_client_package()) |
.arg(::lscp_client_package()) |
377 |
.arg(::lscp_client_version()); |
.arg(::lscp_client_version()); |
378 |
out << QObject::tr(QSAMPLER_TITLE ": %1\n").arg(QSAMPLER_VERSION); |
out << QString("%1: %2\n") |
379 |
|
.arg(QSAMPLER_TITLE) |
380 |
|
.arg(CONFIG_BUILD_VERSION); |
381 |
return false; |
return false; |
382 |
} |
} |
383 |
else { |
else { |
384 |
// If we don't have one by now, |
// If we don't have one by now, |
385 |
// this will be the startup sesion file... |
// this will be the startup sesion file... |
386 |
sSessionFile += sArg; |
sSessionFile += sArg; |
387 |
iCmdArgs++; |
++iCmdArgs; |
388 |
} |
} |
389 |
} |
} |
390 |
|
|
400 |
{ |
{ |
401 |
// Try to restore old form window positioning. |
// Try to restore old form window positioning. |
402 |
if (pWidget) { |
if (pWidget) { |
403 |
|
// if (bVisible) pWidget->show(); -- force initial exposure? |
404 |
|
m_settings.beginGroup("/Geometry/" + pWidget->objectName()); |
405 |
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
406 |
|
const QByteArray& geometry |
407 |
|
= m_settings.value("/geometry").toByteArray(); |
408 |
|
if (geometry.isEmpty()) { |
409 |
|
QWidget *pParent = pWidget->parentWidget(); |
410 |
|
if (pParent) |
411 |
|
pParent = pParent->window(); |
412 |
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
413 |
|
if (pParent == nullptr) |
414 |
|
pParent = QApplication::desktop(); |
415 |
|
#endif |
416 |
|
if (pParent) { |
417 |
|
QRect wrect(pWidget->geometry()); |
418 |
|
wrect.moveCenter(pParent->geometry().center()); |
419 |
|
pWidget->move(wrect.topLeft()); |
420 |
|
} |
421 |
|
} else { |
422 |
|
pWidget->restoreGeometry(geometry); |
423 |
|
} |
424 |
|
#else//--LOAD_OLD_GEOMETRY |
425 |
QPoint wpos; |
QPoint wpos; |
426 |
QSize wsize; |
QSize wsize; |
|
m_settings.beginGroup("/Geometry/" + pWidget->objectName()); |
|
427 |
wpos.setX(m_settings.value("/x", -1).toInt()); |
wpos.setX(m_settings.value("/x", -1).toInt()); |
428 |
wpos.setY(m_settings.value("/y", -1).toInt()); |
wpos.setY(m_settings.value("/y", -1).toInt()); |
429 |
wsize.setWidth(m_settings.value("/width", -1).toInt()); |
wsize.setWidth(m_settings.value("/width", -1).toInt()); |
430 |
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(); |
|
431 |
if (wpos.x() > 0 && wpos.y() > 0) |
if (wpos.x() > 0 && wpos.y() > 0) |
432 |
pWidget->move(wpos); |
pWidget->move(wpos); |
433 |
if (wsize.width() > 0 && wsize.height() > 0) |
if (wsize.width() > 0 && wsize.height() > 0) |
434 |
pWidget->resize(wsize); |
pWidget->resize(wsize); |
435 |
|
#endif |
436 |
// else |
// else |
437 |
// pWidget->adjustSize(); |
// pWidget->adjustSize(); |
438 |
|
if (!bVisible) |
439 |
|
bVisible = m_settings.value("/visible", false).toBool(); |
440 |
if (bVisible) |
if (bVisible) |
441 |
pWidget->show(); |
pWidget->show(); |
442 |
// else |
else |
443 |
// pWidget->hide(); |
pWidget->hide(); |
444 |
|
m_settings.endGroup(); |
445 |
} |
} |
446 |
} |
} |
447 |
|
|
453 |
// only save the form geometry while its up and visible) |
// only save the form geometry while its up and visible) |
454 |
if (pWidget) { |
if (pWidget) { |
455 |
m_settings.beginGroup("/Geometry/" + pWidget->objectName()); |
m_settings.beginGroup("/Geometry/" + pWidget->objectName()); |
456 |
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
457 |
|
m_settings.setValue("/geometry", pWidget->saveGeometry()); |
458 |
|
#else//--SAVE_OLD_GEOMETRY |
459 |
const QPoint& wpos = pWidget->pos(); |
const QPoint& wpos = pWidget->pos(); |
460 |
const QSize& wsize = pWidget->size(); |
const QSize& wsize = pWidget->size(); |
|
if (!bVisible) bVisible = pWidget->isVisible(); |
|
461 |
m_settings.setValue("/x", wpos.x()); |
m_settings.setValue("/x", wpos.x()); |
462 |
m_settings.setValue("/y", wpos.y()); |
m_settings.setValue("/y", wpos.y()); |
463 |
m_settings.setValue("/width", wsize.width()); |
m_settings.setValue("/width", wsize.width()); |
464 |
m_settings.setValue("/height", wsize.height()); |
m_settings.setValue("/height", wsize.height()); |
465 |
|
#endif |
466 |
|
if (!bVisible) bVisible = pWidget->isVisible(); |
467 |
m_settings.setValue("/visible", bVisible); |
m_settings.setValue("/visible", bVisible); |
468 |
m_settings.endGroup(); |
m_settings.endGroup(); |
469 |
} |
} |
475 |
|
|
476 |
void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit ) |
void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit ) |
477 |
{ |
{ |
478 |
|
const bool bBlockSignals = pComboBox->blockSignals(true); |
479 |
|
|
480 |
// Load combobox list from configuration settings file... |
// Load combobox list from configuration settings file... |
481 |
m_settings.beginGroup("/History/" + pComboBox->objectName()); |
m_settings.beginGroup("/History/" + pComboBox->objectName()); |
482 |
|
|
484 |
pComboBox->setUpdatesEnabled(false); |
pComboBox->setUpdatesEnabled(false); |
485 |
pComboBox->setDuplicatesEnabled(false); |
pComboBox->setDuplicatesEnabled(false); |
486 |
pComboBox->clear(); |
pComboBox->clear(); |
487 |
for (int i = 0; i < iLimit; i++) { |
for (int i = 0; i < iLimit; ++i) { |
488 |
const QString& sText = m_settings.value( |
const QString& sText = m_settings.value( |
489 |
"/Item" + QString::number(i + 1)).toString(); |
"/Item" + QString::number(i + 1)).toString(); |
490 |
if (sText.isEmpty()) |
if (sText.isEmpty()) |
495 |
} |
} |
496 |
|
|
497 |
m_settings.endGroup(); |
m_settings.endGroup(); |
498 |
|
|
499 |
|
pComboBox->blockSignals(bBlockSignals); |
500 |
} |
} |
501 |
|
|
502 |
|
|
503 |
void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit ) |
void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit ) |
504 |
{ |
{ |
505 |
|
const bool bBlockSignals = pComboBox->blockSignals(true); |
506 |
|
|
507 |
// Add current text as latest item... |
// Add current text as latest item... |
508 |
const QString& sCurrentText = pComboBox->currentText(); |
const QString sCurrentText = pComboBox->currentText(); |
509 |
int iCount = pComboBox->count(); |
int iCount = pComboBox->count(); |
510 |
for (int i = 0; i < iCount; i++) { |
for (int i = 0; i < iCount; i++) { |
511 |
const QString& sText = pComboBox->itemText(i); |
const QString& sText = pComboBox->itemText(i); |
512 |
if (sText == sCurrentText) { |
if (sText == sCurrentText) { |
513 |
pComboBox->removeItem(i); |
pComboBox->removeItem(i); |
514 |
iCount--; |
--iCount; |
515 |
break; |
break; |
516 |
} |
} |
517 |
} |
} |
518 |
while (iCount >= iLimit) |
while (iCount >= iLimit) |
519 |
pComboBox->removeItem(--iCount); |
pComboBox->removeItem(--iCount); |
520 |
pComboBox->insertItem(0, sCurrentText); |
pComboBox->insertItem(0, sCurrentText); |
521 |
iCount++; |
pComboBox->setCurrentIndex(0); |
522 |
|
++iCount; |
523 |
|
|
524 |
// Save combobox list to configuration settings file... |
// Save combobox list to configuration settings file... |
525 |
m_settings.beginGroup("/History/" + pComboBox->objectName()); |
m_settings.beginGroup("/History/" + pComboBox->objectName()); |
526 |
for (int i = 0; i < iCount; i++) { |
for (int i = 0; i < iCount; ++i) { |
527 |
const QString& sText = pComboBox->itemText(i); |
const QString& sText = pComboBox->itemText(i); |
528 |
if (sText.isEmpty()) |
if (sText.isEmpty()) |
529 |
break; |
break; |
530 |
m_settings.setValue("/Item" + QString::number(i + 1), sText); |
m_settings.setValue("/Item" + QString::number(i + 1), sText); |
531 |
} |
} |
532 |
m_settings.endGroup(); |
m_settings.endGroup(); |
533 |
|
|
534 |
|
pComboBox->blockSignals(bBlockSignals); |
535 |
} |
} |
536 |
|
|
537 |
|
|
538 |
int Options::getMaxVoices() { |
int Options::getMaxVoices() { |
539 |
#ifndef CONFIG_MAX_VOICES |
#ifndef CONFIG_MAX_VOICES |
540 |
return -1; |
return -1; |
632 |
|
|
633 |
|
|
634 |
// end of qsamplerOptions.cpp |
// end of qsamplerOptions.cpp |
635 |
|
|