comparison widgets/PluginPathConfigurator.cpp @ 1296:34b941921ac8 plugin-path-config

Use type keys as indices rather than labels
author Chris Cannam
date Fri, 08 Jun 2018 14:31:47 +0100
parents 11888b7e193d
children bc8134fb9752
comparison
equal deleted inserted replaced
1295:11888b7e193d 1296:34b941921ac8
105 105
106 PluginPathConfigurator::~PluginPathConfigurator() 106 PluginPathConfigurator::~PluginPathConfigurator()
107 { 107 {
108 } 108 }
109 109
110 QString
111 PluginPathConfigurator::getLabelFor(PluginPathSetter::TypeKey key)
112 {
113 if (key.second == KnownPlugins::FormatNative) {
114 switch (key.first) {
115 case KnownPlugins::VampPlugin:
116 return tr("Vamp");
117 case KnownPlugins::LADSPAPlugin:
118 return tr("LADSPA");
119 case KnownPlugins::DSSIPlugin:
120 return tr("DSSI");
121 }
122 } else if (key.second == KnownPlugins::FormatNonNative32Bit) {
123 switch (key.first) {
124 case KnownPlugins::VampPlugin:
125 return tr("Vamp (32-bit)");
126 case KnownPlugins::LADSPAPlugin:
127 return tr("LADSPA (32-bit)");
128 case KnownPlugins::DSSIPlugin:
129 return tr("DSSI (32-bit)");
130 }
131 } else {
132 SVCERR << "PluginPathConfigurator::getLabelFor: WARNING: "
133 << "Unknown format value " << key.second << endl;
134 return "<unknown>";
135 }
136 }
137
138 PluginPathSetter::TypeKey
139 PluginPathConfigurator::getKeyForLabel(QString label)
140 {
141 for (const auto &p: m_paths) {
142 auto key = p.first;
143 if (getLabelFor(key) == label) {
144 return key;
145 }
146 }
147 SVCERR << "PluginPathConfigurator::getKeyForLabel: WARNING: "
148 << "Unrecognised label \"" << label << "\"" << endl;
149 return { KnownPlugins::VampPlugin, KnownPlugins::FormatNative };
150 }
151
110 void 152 void
111 PluginPathConfigurator::setPaths(PluginPathSetter::Paths paths) 153 PluginPathConfigurator::setPaths(PluginPathSetter::Paths paths)
112 { 154 {
113 m_paths = paths; 155 m_paths = paths;
114 156
115 m_defaultPaths = PluginPathSetter::getDefaultPaths(); 157 m_defaultPaths = PluginPathSetter::getDefaultPaths();
116 158
117 m_pluginTypeSelector->clear(); 159 m_pluginTypeSelector->clear();
118 for (const auto &p: paths) { 160 for (const auto &p: paths) {
119 m_pluginTypeSelector->addItem(p.first); 161 m_pluginTypeSelector->addItem(getLabelFor(p.first));
120 } 162 }
121 163
122 populate(); 164 populate();
123 } 165 }
124 166
127 { 169 {
128 m_list->clear(); 170 m_list->clear();
129 171
130 if (m_paths.empty()) return; 172 if (m_paths.empty()) return;
131 173
132 populateFor(m_paths.rbegin()->first, -1); 174 populateFor(m_paths.begin()->first, -1);
133 } 175 }
134 176
135 void 177 void
136 PluginPathConfigurator::populateFor(QString type, int makeCurrent) 178 PluginPathConfigurator::populateFor(PluginPathSetter::TypeKey key,
137 { 179 int makeCurrent)
138 QString envVariable = m_paths.at(type).envVariable; 180 {
139 bool useEnvVariable = m_paths.at(type).useEnvVariable; 181 QString envVariable = m_paths.at(key).envVariable;
182 bool useEnvVariable = m_paths.at(key).useEnvVariable;
140 QString envVarValue = 183 QString envVarValue =
141 PluginPathSetter::getOriginalEnvironmentValue(envVariable); 184 PluginPathSetter::getOriginalEnvironmentValue(envVariable);
142 QString currentValueRubric; 185 QString currentValueRubric;
143 if (envVarValue == QString()) { 186 if (envVarValue == QString()) {
144 currentValueRubric = tr("(Variable is currently unset)"); 187 currentValueRubric = tr("(Variable is currently unset)");
159 m_envOverride->setCheckState(useEnvVariable ? Qt::Checked : Qt::Unchecked); 202 m_envOverride->setCheckState(useEnvVariable ? Qt::Checked : Qt::Unchecked);
160 203
161 m_list->clear(); 204 m_list->clear();
162 205
163 for (int i = 0; i < m_pluginTypeSelector->count(); ++i) { 206 for (int i = 0; i < m_pluginTypeSelector->count(); ++i) {
164 if (type == m_pluginTypeSelector->itemText(i)) { 207 if (getLabelFor(key) == m_pluginTypeSelector->itemText(i)) {
165 m_pluginTypeSelector->blockSignals(true); 208 m_pluginTypeSelector->blockSignals(true);
166 m_pluginTypeSelector->setCurrentIndex(i); 209 m_pluginTypeSelector->setCurrentIndex(i);
167 m_pluginTypeSelector->blockSignals(false); 210 m_pluginTypeSelector->blockSignals(false);
168 } 211 }
169 } 212 }
170 213
171 QStringList path = m_paths.at(type).directories; 214 QStringList path = m_paths.at(key).directories;
172 215
173 for (int i = 0; i < path.size(); ++i) { 216 for (int i = 0; i < path.size(); ++i) {
174 m_list->addItem(path[i]); 217 m_list->addItem(path[i]);
175 } 218 }
176 219
181 } 224 }
182 225
183 void 226 void
184 PluginPathConfigurator::currentLocationChanged(int i) 227 PluginPathConfigurator::currentLocationChanged(int i)
185 { 228 {
186 QString type = m_pluginTypeSelector->currentText(); 229 QString label = m_pluginTypeSelector->currentText();
187 QStringList path = m_paths.at(type).directories; 230 PluginPathSetter::TypeKey key = getKeyForLabel(label);
231 QStringList path = m_paths.at(key).directories;
188 m_up->setEnabled(i > 0); 232 m_up->setEnabled(i > 0);
189 m_down->setEnabled(i >= 0 && i + 1 < path.size()); 233 m_down->setEnabled(i >= 0 && i + 1 < path.size());
190 m_delete->setEnabled(i >= 0 && i < path.size()); 234 m_delete->setEnabled(i >= 0 && i < path.size());
191 m_reset->setEnabled(path != m_defaultPaths.at(type).directories); 235 m_reset->setEnabled(path != m_defaultPaths.at(key).directories);
192 } 236 }
193 237
194 void 238 void
195 PluginPathConfigurator::currentTypeChanged(QString type) 239 PluginPathConfigurator::currentTypeChanged(QString label)
196 { 240 {
197 populateFor(type, -1); 241 populateFor(getKeyForLabel(label), -1);
198 } 242 }
199 243
200 void 244 void
201 PluginPathConfigurator::envOverrideChanged(int state) 245 PluginPathConfigurator::envOverrideChanged(int state)
202 { 246 {
203 bool useEnvVariable = (state == Qt::Checked); 247 bool useEnvVariable = (state == Qt::Checked);
204 248
205 QString type = m_pluginTypeSelector->currentText(); 249 QString label = m_pluginTypeSelector->currentText();
206 250 PluginPathSetter::TypeKey key = getKeyForLabel(label);
207 auto newEntry = m_paths.at(type); 251
252 auto newEntry = m_paths.at(key);
208 newEntry.useEnvVariable = useEnvVariable; 253 newEntry.useEnvVariable = useEnvVariable;
209 m_paths[type] = newEntry; 254 m_paths[key] = newEntry;
210 255
211 emit pathsChanged(); 256 emit pathsChanged();
212 } 257 }
213 258
214 void 259 void
215 PluginPathConfigurator::upClicked() 260 PluginPathConfigurator::upClicked()
216 { 261 {
217 QString type = m_pluginTypeSelector->currentText(); 262 QString label = m_pluginTypeSelector->currentText();
218 QStringList path = m_paths.at(type).directories; 263 PluginPathSetter::TypeKey key = getKeyForLabel(label);
264 QStringList path = m_paths.at(key).directories;
219 265
220 int current = m_list->currentRow(); 266 int current = m_list->currentRow();
221 if (current <= 0) return; 267 if (current <= 0) return;
222 268
223 QStringList newPath; 269 QStringList newPath;
229 } else { 275 } else {
230 newPath.push_back(path[i]); 276 newPath.push_back(path[i]);
231 } 277 }
232 } 278 }
233 279
234 auto newEntry = m_paths.at(type); 280 auto newEntry = m_paths.at(key);
235 newEntry.directories = newPath; 281 newEntry.directories = newPath;
236 m_paths[type] = newEntry; 282 m_paths[key] = newEntry;
237 283
238 populateFor(type, current - 1); 284 populateFor(key, current - 1);
239 285
240 emit pathsChanged(); 286 emit pathsChanged();
241 } 287 }
242 288
243 void 289 void
244 PluginPathConfigurator::downClicked() 290 PluginPathConfigurator::downClicked()
245 { 291 {
246 QString type = m_pluginTypeSelector->currentText(); 292 QString label = m_pluginTypeSelector->currentText();
247 QStringList path = m_paths.at(type).directories; 293 PluginPathSetter::TypeKey key = getKeyForLabel(label);
294 QStringList path = m_paths.at(key).directories;
248 295
249 int current = m_list->currentRow(); 296 int current = m_list->currentRow();
250 if (current < 0 || current + 1 >= path.size()) return; 297 if (current < 0 || current + 1 >= path.size()) return;
251 298
252 QStringList newPath; 299 QStringList newPath;
258 } else { 305 } else {
259 newPath.push_back(path[i]); 306 newPath.push_back(path[i]);
260 } 307 }
261 } 308 }
262 309
263 auto newEntry = m_paths.at(type); 310 auto newEntry = m_paths.at(key);
264 newEntry.directories = newPath; 311 newEntry.directories = newPath;
265 m_paths[type] = newEntry; 312 m_paths[key] = newEntry;
266 313
267 populateFor(type, current + 1); 314 populateFor(key, current + 1);
268 315
269 emit pathsChanged(); 316 emit pathsChanged();
270 } 317 }
271 318
272 void 319 void
273 PluginPathConfigurator::addClicked() 320 PluginPathConfigurator::addClicked()
274 { 321 {
275 QString type = m_pluginTypeSelector->currentText(); 322 QString label = m_pluginTypeSelector->currentText();
323 PluginPathSetter::TypeKey key = getKeyForLabel(label);
276 324
277 QString newDir = QFileDialog::getExistingDirectory 325 QString newDir = QFileDialog::getExistingDirectory
278 (this, tr("Choose directory to add")); 326 (this, tr("Choose directory to add"));
279 327
280 if (newDir == QString()) return; 328 if (newDir == QString()) return;
281 329
282 auto newEntry = m_paths.at(type); 330 auto newEntry = m_paths.at(key);
283 newEntry.directories.push_back(newDir); 331 newEntry.directories.push_back(newDir);
284 m_paths[type] = newEntry; 332 m_paths[key] = newEntry;
285 333
286 populateFor(type, newEntry.directories.size() - 1); 334 populateFor(key, newEntry.directories.size() - 1);
287 335
288 emit pathsChanged(); 336 emit pathsChanged();
289 } 337 }
290 338
291 void 339 void
292 PluginPathConfigurator::deleteClicked() 340 PluginPathConfigurator::deleteClicked()
293 { 341 {
294 QString type = m_pluginTypeSelector->currentText(); 342 QString label = m_pluginTypeSelector->currentText();
295 QStringList path = m_paths.at(type).directories; 343 PluginPathSetter::TypeKey key = getKeyForLabel(label);
344 QStringList path = m_paths.at(key).directories;
296 345
297 int current = m_list->currentRow(); 346 int current = m_list->currentRow();
298 if (current < 0) return; 347 if (current < 0) return;
299 348
300 QStringList newPath; 349 QStringList newPath;
302 if (i != current) { 351 if (i != current) {
303 newPath.push_back(path[i]); 352 newPath.push_back(path[i]);
304 } 353 }
305 } 354 }
306 355
307 auto newEntry = m_paths.at(type); 356 auto newEntry = m_paths.at(key);
308 newEntry.directories = newPath; 357 newEntry.directories = newPath;
309 m_paths[type] = newEntry; 358 m_paths[key] = newEntry;
310 359
311 populateFor(type, current < newPath.size() ? current : current-1); 360 populateFor(key, current < newPath.size() ? current : current-1);
312 361
313 emit pathsChanged(); 362 emit pathsChanged();
314 } 363 }
315 364
316 void 365 void
317 PluginPathConfigurator::resetClicked() 366 PluginPathConfigurator::resetClicked()
318 { 367 {
319 QString type = m_pluginTypeSelector->currentText(); 368 QString label = m_pluginTypeSelector->currentText();
320 m_paths[type] = m_defaultPaths[type]; 369 PluginPathSetter::TypeKey key = getKeyForLabel(label);
321 populateFor(type, -1); 370 m_paths[key] = m_defaultPaths[key];
371 populateFor(key, -1);
322 372
323 emit pathsChanged(); 373 emit pathsChanged();
324 } 374 }
325 375
326 void 376 void