1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Sonic Visualiser
An audio file viewer and annotation editor.
Centre for Digital Music, Queen Mary, University of London.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. See the file
COPYING included with this distribution for more information.
*/
#include "PluginPathConfigurator.h"
#include "PluginReviewDialog.h"
#include <QPushButton>
#include <QListWidget>
#include <QGridLayout>
#include <QComboBox>
#include <QLabel>
#include <QCheckBox>
#include <QFileDialog>
#include "IconLoader.h"
#include "WidgetScale.h"
#include "plugin/PluginPathSetter.h"
namespace sv {
PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) :
QFrame(parent)
{
m_layout = new QGridLayout;
setLayout(m_layout);
QHBoxLayout *buttons = new QHBoxLayout;
m_down = new QPushButton;
m_down->setIcon(IconLoader().load("down"));
m_down->setToolTip(tr("Move the selected location later in the list"));
connect(m_down, SIGNAL(clicked()), this, SLOT(downClicked()));
buttons->addWidget(m_down);
m_up = new QPushButton;
m_up->setIcon(IconLoader().load("up"));
m_up->setToolTip(tr("Move the selected location earlier in the list"));
connect(m_up, SIGNAL(clicked()), this, SLOT(upClicked()));
buttons->addWidget(m_up);
m_add = new QPushButton;
m_add->setIcon(IconLoader().load("plus"));
m_add->setToolTip(tr("Add a new location to the list"));
connect(m_add, SIGNAL(clicked()), this, SLOT(addClicked()));
buttons->addWidget(m_add);
m_delete = new QPushButton;
m_delete->setIcon(IconLoader().load("datadelete"));
m_delete->setToolTip(tr("Remove the selected location from the list"));
connect(m_delete, SIGNAL(clicked()), this, SLOT(deleteClicked()));
buttons->addWidget(m_delete);
m_reset = new QPushButton;
m_reset->setText(tr("Reset to Default"));
m_reset->setToolTip(tr("Reset the list for this plugin type to its default"));
connect(m_reset, SIGNAL(clicked()), this, SLOT(resetClicked()));
buttons->addWidget(m_reset);
buttons->addStretch(50);
m_seePlugins = new QPushButton;
m_seePlugins->setText(tr("Review plugins..."));
connect(m_seePlugins, SIGNAL(clicked()), this, SLOT(seePluginsClicked()));
buttons->addWidget(m_seePlugins);
int row = 0;
m_header = new QLabel;
m_header->setText(tr("Plugin locations for plugin type:"));
m_layout->addWidget(m_header, row, 0);
m_pluginTypeSelector = new QComboBox;
m_layout->addWidget(m_pluginTypeSelector, row, 1, Qt::AlignLeft);
connect(m_pluginTypeSelector, SIGNAL(currentTextChanged(QString)),
this, SLOT(currentTypeChanged(QString)));
m_layout->setColumnStretch(1, 10);
++row;
m_list = new QListWidget;
m_layout->addWidget(m_list, row, 0, 1, 3);
m_layout->setRowStretch(row, 20);
connect(m_list, SIGNAL(currentRowChanged(int)),
this, SLOT(currentLocationChanged(int)));
++row;
m_layout->addLayout(buttons, row, 0, 1, 3);
++row;
m_envOverride = new QCheckBox;
connect(m_envOverride, SIGNAL(stateChanged(int)),
this, SLOT(envOverrideChanged(int)));
m_layout->addWidget(m_envOverride, row, 0, 1, 3);
++row;
}
PluginPathConfigurator::~PluginPathConfigurator()
{
}
QString
PluginPathConfigurator::getLabelFor(PluginPathSetter::TypeKey key)
{
if (key.second == KnownPlugins::FormatNative) {
switch (key.first) {
case KnownPlugins::VampPlugin:
return tr("Vamp");
case KnownPlugins::LADSPAPlugin:
return tr("LADSPA");
case KnownPlugins::DSSIPlugin:
return tr("DSSI");
}
} else if (key.second == KnownPlugins::FormatNonNative32Bit) {
switch (key.first) {
case KnownPlugins::VampPlugin:
return tr("Vamp (32-bit)");
case KnownPlugins::LADSPAPlugin:
return tr("LADSPA (32-bit)");
case KnownPlugins::DSSIPlugin:
return tr("DSSI (32-bit)");
}
}
SVCERR << "PluginPathConfigurator::getLabelFor: WARNING: "
<< "Unknown format value " << key.second << endl;
return "<unknown>";
}
PluginPathSetter::TypeKey
PluginPathConfigurator::getKeyForLabel(QString label)
{
for (const auto &p: m_paths) {
auto key = p.first;
if (getLabelFor(key) == label) {
return key;
}
}
SVCERR << "PluginPathConfigurator::getKeyForLabel: WARNING: "
<< "Unrecognised label \"" << label << "\"" << endl;
return { KnownPlugins::VampPlugin, KnownPlugins::FormatNative };
}
void
PluginPathConfigurator::setPaths(PluginPathSetter::Paths paths)
{
m_paths = paths;
m_defaultPaths = PluginPathSetter::getDefaultPaths();
m_pluginTypeSelector->clear();
for (const auto &p: paths) {
m_pluginTypeSelector->addItem(getLabelFor(p.first));
}
populate();
}
void
PluginPathConfigurator::populate()
{
m_list->clear();
if (m_paths.empty()) return;
populateFor(m_paths.begin()->first, -1);
}
void
PluginPathConfigurator::populateFor(PluginPathSetter::TypeKey key,
int makeCurrent)
{
QString envVariable = m_paths.at(key).envVariable;
bool useEnvVariable = m_paths.at(key).useEnvVariable;
QString envVarValue =
PluginPathSetter::getOriginalEnvironmentValue(envVariable);
QString currentValueRubric;
if (envVarValue == QString()) {
currentValueRubric = tr("(Variable is currently unset)");
} else {
if (envVarValue.length() > 100) {
QString envVarStart = envVarValue.left(95);
currentValueRubric = tr("(Current value begins: \"%1 ...\")")
.arg(envVarStart);
} else {
currentValueRubric = tr("(Currently set to: \"%1\")")
.arg(envVarValue);
}
}
m_envOverride->setText
(tr("Allow the %1 environment variable to take priority over this\n%2")
.arg(envVariable)
.arg(currentValueRubric));
m_envOverride->setCheckState(useEnvVariable ? Qt::Checked : Qt::Unchecked);
m_list->clear();
for (int i = 0; i < m_pluginTypeSelector->count(); ++i) {
if (getLabelFor(key) == m_pluginTypeSelector->itemText(i)) {
m_pluginTypeSelector->blockSignals(true);
m_pluginTypeSelector->setCurrentIndex(i);
m_pluginTypeSelector->blockSignals(false);
}
}
QStringList path = m_paths.at(key).directories;
for (int i = 0; i < path.size(); ++i) {
m_list->addItem(path[i]);
}
if (makeCurrent < path.size()) {
m_list->setCurrentRow(makeCurrent);
currentLocationChanged(makeCurrent);
}
}
void
PluginPathConfigurator::currentLocationChanged(int i)
{
QString label = m_pluginTypeSelector->currentText();
PluginPathSetter::TypeKey key = getKeyForLabel(label);
QStringList path = m_paths.at(key).directories;
m_up->setEnabled(i > 0);
m_down->setEnabled(i >= 0 && i + 1 < path.size());
m_delete->setEnabled(i >= 0 && i < path.size());
m_reset->setEnabled(path != m_defaultPaths.at(key).directories);
}
void
PluginPathConfigurator::currentTypeChanged(QString label)
{
populateFor(getKeyForLabel(label), -1);
}
void
PluginPathConfigurator::envOverrideChanged(int state)
{
bool useEnvVariable = (state == Qt::Checked);
QString label = m_pluginTypeSelector->currentText();
PluginPathSetter::TypeKey key = getKeyForLabel(label);
auto newEntry = m_paths.at(key);
newEntry.useEnvVariable = useEnvVariable;
m_paths[key] = newEntry;
emit pathsChanged();
}
void
PluginPathConfigurator::upClicked()
{
QString label = m_pluginTypeSelector->currentText();
PluginPathSetter::TypeKey key = getKeyForLabel(label);
QStringList path = m_paths.at(key).directories;
int current = m_list->currentRow();
if (current <= 0) return;
QStringList newPath;
for (int i = 0; i < path.size(); ++i) {
if (i + 1 == current) {
newPath.push_back(path[i+1]);
newPath.push_back(path[i]);
++i;
} else {
newPath.push_back(path[i]);
}
}
auto newEntry = m_paths.at(key);
newEntry.directories = newPath;
m_paths[key] = newEntry;
populateFor(key, current - 1);
emit pathsChanged();
}
void
PluginPathConfigurator::downClicked()
{
QString label = m_pluginTypeSelector->currentText();
PluginPathSetter::TypeKey key = getKeyForLabel(label);
QStringList path = m_paths.at(key).directories;
int current = m_list->currentRow();
if (current < 0 || current + 1 >= path.size()) return;
QStringList newPath;
for (int i = 0; i < path.size(); ++i) {
if (i == current) {
newPath.push_back(path[i+1]);
newPath.push_back(path[i]);
++i;
} else {
newPath.push_back(path[i]);
}
}
auto newEntry = m_paths.at(key);
newEntry.directories = newPath;
m_paths[key] = newEntry;
populateFor(key, current + 1);
emit pathsChanged();
}
void
PluginPathConfigurator::addClicked()
{
QString label = m_pluginTypeSelector->currentText();
PluginPathSetter::TypeKey key = getKeyForLabel(label);
QString newDir = QFileDialog::getExistingDirectory
(this, tr("Choose directory to add"));
if (newDir == QString()) return;
auto newEntry = m_paths.at(key);
newEntry.directories.push_back(newDir);
m_paths[key] = newEntry;
populateFor(key, newEntry.directories.size() - 1);
emit pathsChanged();
}
void
PluginPathConfigurator::deleteClicked()
{
QString label = m_pluginTypeSelector->currentText();
PluginPathSetter::TypeKey key = getKeyForLabel(label);
QStringList path = m_paths.at(key).directories;
int current = m_list->currentRow();
if (current < 0) return;
QStringList newPath;
for (int i = 0; i < path.size(); ++i) {
if (i != current) {
newPath.push_back(path[i]);
}
}
auto newEntry = m_paths.at(key);
newEntry.directories = newPath;
m_paths[key] = newEntry;
populateFor(key, current < newPath.size() ? current : current-1);
emit pathsChanged();
}
void
PluginPathConfigurator::resetClicked()
{
QString label = m_pluginTypeSelector->currentText();
PluginPathSetter::TypeKey key = getKeyForLabel(label);
m_paths[key] = m_defaultPaths[key];
populateFor(key, -1);
emit pathsChanged();
}
void
PluginPathConfigurator::seePluginsClicked()
{
PluginReviewDialog dialog(this);
dialog.populate();
dialog.exec();
}
} // end namespace sv
|