Chris@1285
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@1285
|
2
|
Chris@1285
|
3 /*
|
Chris@1285
|
4 Sonic Visualiser
|
Chris@1285
|
5 An audio file viewer and annotation editor.
|
Chris@1285
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@1285
|
7
|
Chris@1285
|
8 This program is free software; you can redistribute it and/or
|
Chris@1285
|
9 modify it under the terms of the GNU General Public License as
|
Chris@1285
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@1285
|
11 License, or (at your option) any later version. See the file
|
Chris@1285
|
12 COPYING included with this distribution for more information.
|
Chris@1285
|
13 */
|
Chris@1285
|
14
|
Chris@1285
|
15 #include "PluginPathConfigurator.h"
|
Chris@1285
|
16
|
Chris@1285
|
17 #include <QPushButton>
|
Chris@1287
|
18 #include <QListWidget>
|
Chris@1288
|
19 #include <QGridLayout>
|
Chris@1289
|
20 #include <QComboBox>
|
Chris@1285
|
21 #include <QLabel>
|
Chris@1290
|
22 #include <QCheckBox>
|
Chris@1285
|
23
|
Chris@1285
|
24 #include "IconLoader.h"
|
Chris@1285
|
25 #include "WidgetScale.h"
|
Chris@1285
|
26
|
Chris@1285
|
27 PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) :
|
Chris@1287
|
28 QFrame(parent)
|
Chris@1285
|
29 {
|
Chris@1285
|
30 m_layout = new QGridLayout;
|
Chris@1285
|
31 setLayout(m_layout);
|
Chris@1287
|
32
|
Chris@1287
|
33 int row = 0;
|
Chris@1287
|
34
|
Chris@1289
|
35 m_header = new QLabel;
|
Chris@1290
|
36 m_header->setText(tr("Plugin locations for plugin type:"));
|
Chris@1289
|
37 m_layout->addWidget(m_header, row, 0);
|
Chris@1289
|
38
|
Chris@1289
|
39 m_pluginTypeSelector = new QComboBox;
|
Chris@1290
|
40 m_layout->addWidget(m_pluginTypeSelector, row, 1, Qt::AlignLeft);
|
Chris@1289
|
41 connect(m_pluginTypeSelector, SIGNAL(currentTextChanged(QString)),
|
Chris@1289
|
42 this, SLOT(currentTypeChanged(QString)));
|
Chris@1289
|
43
|
Chris@1290
|
44 m_layout->setColumnStretch(1, 10);
|
Chris@1290
|
45
|
Chris@1287
|
46 ++row;
|
Chris@1287
|
47
|
Chris@1287
|
48 m_list = new QListWidget;
|
Chris@1290
|
49 m_layout->addWidget(m_list, row, 0, 1, 3);
|
Chris@1290
|
50 m_layout->setRowStretch(row, 20);
|
Chris@1288
|
51 connect(m_list, SIGNAL(currentRowChanged(int)),
|
Chris@1288
|
52 this, SLOT(currentLocationChanged(int)));
|
Chris@1287
|
53 ++row;
|
Chris@1290
|
54
|
Chris@1287
|
55 QHBoxLayout *buttons = new QHBoxLayout;
|
Chris@1287
|
56
|
Chris@1288
|
57 m_down = new QPushButton;
|
Chris@1288
|
58 m_down->setIcon(IconLoader().load("down"));
|
Chris@1288
|
59 m_down->setToolTip(tr("Move the selected location later in the list"));
|
Chris@1288
|
60 connect(m_down, SIGNAL(clicked()), this, SLOT(downClicked()));
|
Chris@1288
|
61 buttons->addWidget(m_down);
|
Chris@1287
|
62
|
Chris@1288
|
63 m_up = new QPushButton;
|
Chris@1288
|
64 m_up->setIcon(IconLoader().load("up"));
|
Chris@1288
|
65 m_up->setToolTip(tr("Move the selected location earlier in the list"));
|
Chris@1288
|
66 connect(m_up, SIGNAL(clicked()), this, SLOT(upClicked()));
|
Chris@1288
|
67 buttons->addWidget(m_up);
|
Chris@1287
|
68
|
Chris@1288
|
69 m_delete = new QPushButton;
|
Chris@1288
|
70 m_delete->setIcon(IconLoader().load("datadelete"));
|
Chris@1288
|
71 m_delete->setToolTip(tr("Remove the selected location from the list"));
|
Chris@1288
|
72 connect(m_delete, SIGNAL(clicked()), this, SLOT(deleteClicked()));
|
Chris@1288
|
73 buttons->addWidget(m_delete);
|
Chris@1287
|
74
|
Chris@1290
|
75 m_reset = new QPushButton;
|
Chris@1290
|
76 m_reset->setText(tr("Reset"));
|
Chris@1290
|
77 m_reset->setToolTip(tr("Reset the list for this plugin type to its default"));
|
Chris@1290
|
78 connect(m_reset, SIGNAL(clicked()), this, SLOT(resetClicked()));
|
Chris@1290
|
79 buttons->addWidget(m_reset);
|
Chris@1290
|
80
|
Chris@1290
|
81 m_layout->addLayout(buttons, row, 2);
|
Chris@1287
|
82 ++row;
|
Chris@1290
|
83
|
Chris@1290
|
84 m_envOverride = new QCheckBox;
|
Chris@1290
|
85 connect(m_envOverride, SIGNAL(stateChanged(int)),
|
Chris@1290
|
86 this, SLOT(envOverrideChanged(int)));
|
Chris@1290
|
87 m_layout->addWidget(m_envOverride, row, 0, 1, 3);
|
Chris@1285
|
88 }
|
Chris@1285
|
89
|
Chris@1285
|
90 PluginPathConfigurator::~PluginPathConfigurator()
|
Chris@1285
|
91 {
|
Chris@1285
|
92 }
|
Chris@1285
|
93
|
Chris@1285
|
94 void
|
Chris@1289
|
95 PluginPathConfigurator::setPaths(Paths paths)
|
Chris@1285
|
96 {
|
Chris@1289
|
97 m_paths = paths;
|
Chris@1290
|
98 if (m_originalPaths.empty()) {
|
Chris@1290
|
99 m_originalPaths = paths;
|
Chris@1290
|
100 }
|
Chris@1289
|
101
|
Chris@1289
|
102 m_pluginTypeSelector->clear();
|
Chris@1289
|
103 for (const auto &p: paths) {
|
Chris@1289
|
104 m_pluginTypeSelector->addItem(p.first);
|
Chris@1289
|
105 }
|
Chris@1289
|
106
|
Chris@1285
|
107 populate();
|
Chris@1285
|
108 }
|
Chris@1285
|
109
|
Chris@1285
|
110 void
|
Chris@1289
|
111 PluginPathConfigurator::populate()
|
Chris@1285
|
112 {
|
Chris@1287
|
113 m_list->clear();
|
Chris@1286
|
114
|
Chris@1289
|
115 if (m_paths.empty()) return;
|
Chris@1289
|
116
|
Chris@1290
|
117 populateFor(m_paths.begin()->first, -1);
|
Chris@1289
|
118 }
|
Chris@1289
|
119
|
Chris@1289
|
120 void
|
Chris@1289
|
121 PluginPathConfigurator::populateFor(QString type, int makeCurrent)
|
Chris@1289
|
122 {
|
Chris@1290
|
123 QString envVariable = m_paths.at(type).envVariable;
|
Chris@1290
|
124 bool useEnvVariable = m_paths.at(type).useEnvVariable;
|
Chris@1290
|
125 m_envOverride->setText
|
Chris@1290
|
126 (tr("Allow the %1 environment variable to override this")
|
Chris@1290
|
127 .arg(envVariable));
|
Chris@1290
|
128 m_envOverride->setCheckState(useEnvVariable ? Qt::Checked : Qt::Unchecked);
|
Chris@1290
|
129
|
Chris@1289
|
130 m_list->clear();
|
Chris@1289
|
131
|
Chris@1289
|
132 for (int i = 0; i < m_pluginTypeSelector->count(); ++i) {
|
Chris@1289
|
133 if (type == m_pluginTypeSelector->itemText(i)) {
|
Chris@1289
|
134 m_pluginTypeSelector->setCurrentIndex(i);
|
Chris@1289
|
135 }
|
Chris@1289
|
136 }
|
Chris@1289
|
137
|
Chris@1289
|
138 QStringList path = m_paths.at(type).directories;
|
Chris@1289
|
139
|
Chris@1289
|
140 for (int i = 0; i < path.size(); ++i) {
|
Chris@1289
|
141 m_list->addItem(path[i]);
|
Chris@1287
|
142 }
|
Chris@1285
|
143
|
Chris@1290
|
144 if (makeCurrent < path.size()) {
|
Chris@1287
|
145 m_list->setCurrentRow(makeCurrent);
|
Chris@1290
|
146 currentLocationChanged(makeCurrent);
|
Chris@1286
|
147 }
|
Chris@1285
|
148 }
|
Chris@1285
|
149
|
Chris@1285
|
150 void
|
Chris@1288
|
151 PluginPathConfigurator::currentLocationChanged(int i)
|
Chris@1288
|
152 {
|
Chris@1289
|
153 QString type = m_pluginTypeSelector->currentText();
|
Chris@1289
|
154 QStringList path = m_paths.at(type).directories;
|
Chris@1288
|
155 m_up->setEnabled(i > 0);
|
Chris@1290
|
156 m_down->setEnabled(i >= 0 && i + 1 < path.size());
|
Chris@1290
|
157 m_delete->setEnabled(i >= 0 && i < path.size());
|
Chris@1290
|
158 m_reset->setEnabled(path != m_originalPaths.at(type).directories);
|
Chris@1289
|
159 }
|
Chris@1289
|
160
|
Chris@1289
|
161 void
|
Chris@1289
|
162 PluginPathConfigurator::currentTypeChanged(QString type)
|
Chris@1289
|
163 {
|
Chris@1290
|
164 populateFor(type, -1);
|
Chris@1290
|
165 }
|
Chris@1290
|
166
|
Chris@1290
|
167 void
|
Chris@1290
|
168 PluginPathConfigurator::envOverrideChanged(int )
|
Chris@1290
|
169 {
|
Chris@1290
|
170 //!!!
|
Chris@1288
|
171 }
|
Chris@1288
|
172
|
Chris@1288
|
173 void
|
Chris@1285
|
174 PluginPathConfigurator::upClicked()
|
Chris@1285
|
175 {
|
Chris@1289
|
176 QString type = m_pluginTypeSelector->currentText();
|
Chris@1289
|
177 QStringList path = m_paths.at(type).directories;
|
Chris@1289
|
178
|
Chris@1287
|
179 int current = m_list->currentRow();
|
Chris@1287
|
180 if (current <= 0) return;
|
Chris@1287
|
181
|
Chris@1286
|
182 QStringList newPath;
|
Chris@1289
|
183 for (int i = 0; i < path.size(); ++i) {
|
Chris@1287
|
184 if (i + 1 == current) {
|
Chris@1289
|
185 newPath.push_back(path[i+1]);
|
Chris@1289
|
186 newPath.push_back(path[i]);
|
Chris@1286
|
187 ++i;
|
Chris@1286
|
188 } else {
|
Chris@1289
|
189 newPath.push_back(path[i]);
|
Chris@1286
|
190 }
|
Chris@1286
|
191 }
|
Chris@1290
|
192
|
Chris@1290
|
193 auto newEntry = m_paths.at(type);
|
Chris@1290
|
194 newEntry.directories = newPath;
|
Chris@1290
|
195 m_paths[type] = newEntry;
|
Chris@1287
|
196
|
Chris@1289
|
197 populateFor(type, current - 1);
|
Chris@1285
|
198 }
|
Chris@1285
|
199
|
Chris@1285
|
200 void
|
Chris@1285
|
201 PluginPathConfigurator::downClicked()
|
Chris@1285
|
202 {
|
Chris@1289
|
203 QString type = m_pluginTypeSelector->currentText();
|
Chris@1289
|
204 QStringList path = m_paths.at(type).directories;
|
Chris@1289
|
205
|
Chris@1287
|
206 int current = m_list->currentRow();
|
Chris@1289
|
207 if (current < 0 || current + 1 >= path.size()) return;
|
Chris@1289
|
208
|
Chris@1286
|
209 QStringList newPath;
|
Chris@1289
|
210 for (int i = 0; i < path.size(); ++i) {
|
Chris@1287
|
211 if (i == current) {
|
Chris@1289
|
212 newPath.push_back(path[i+1]);
|
Chris@1289
|
213 newPath.push_back(path[i]);
|
Chris@1286
|
214 ++i;
|
Chris@1286
|
215 } else {
|
Chris@1289
|
216 newPath.push_back(path[i]);
|
Chris@1286
|
217 }
|
Chris@1286
|
218 }
|
Chris@1290
|
219
|
Chris@1290
|
220 auto newEntry = m_paths.at(type);
|
Chris@1290
|
221 newEntry.directories = newPath;
|
Chris@1290
|
222 m_paths[type] = newEntry;
|
Chris@1287
|
223
|
Chris@1289
|
224 populateFor(type, current + 1);
|
Chris@1285
|
225 }
|
Chris@1285
|
226
|
Chris@1285
|
227 void
|
Chris@1285
|
228 PluginPathConfigurator::deleteClicked()
|
Chris@1285
|
229 {
|
Chris@1289
|
230 QString type = m_pluginTypeSelector->currentText();
|
Chris@1289
|
231 QStringList path = m_paths.at(type).directories;
|
Chris@1289
|
232
|
Chris@1287
|
233 int current = m_list->currentRow();
|
Chris@1290
|
234 if (current < 0) return;
|
Chris@1289
|
235
|
Chris@1286
|
236 QStringList newPath;
|
Chris@1289
|
237 for (int i = 0; i < path.size(); ++i) {
|
Chris@1287
|
238 if (i != current) {
|
Chris@1289
|
239 newPath.push_back(path[i]);
|
Chris@1286
|
240 }
|
Chris@1286
|
241 }
|
Chris@1290
|
242
|
Chris@1290
|
243 auto newEntry = m_paths.at(type);
|
Chris@1290
|
244 newEntry.directories = newPath;
|
Chris@1290
|
245 m_paths[type] = newEntry;
|
Chris@1287
|
246
|
Chris@1289
|
247 populateFor(type, current < newPath.size() ? current : current-1);
|
Chris@1285
|
248 }
|
Chris@1290
|
249
|
Chris@1290
|
250 void
|
Chris@1290
|
251 PluginPathConfigurator::resetClicked()
|
Chris@1290
|
252 {
|
Chris@1290
|
253 QString type = m_pluginTypeSelector->currentText();
|
Chris@1290
|
254 m_paths[type] = m_originalPaths[type];
|
Chris@1290
|
255 populateFor(type, -1);
|
Chris@1290
|
256 }
|