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@1285
|
22
|
Chris@1285
|
23 #include "IconLoader.h"
|
Chris@1285
|
24 #include "WidgetScale.h"
|
Chris@1285
|
25
|
Chris@1285
|
26 PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) :
|
Chris@1287
|
27 QFrame(parent)
|
Chris@1285
|
28 {
|
Chris@1285
|
29 m_layout = new QGridLayout;
|
Chris@1285
|
30 setLayout(m_layout);
|
Chris@1287
|
31
|
Chris@1287
|
32 int row = 0;
|
Chris@1287
|
33
|
Chris@1289
|
34 m_header = new QLabel;
|
Chris@1289
|
35 m_header->setText(tr("Plugin locations"));
|
Chris@1289
|
36 m_layout->addWidget(m_header, row, 0);
|
Chris@1289
|
37
|
Chris@1289
|
38 m_pluginTypeSelector = new QComboBox;
|
Chris@1289
|
39 m_layout->addWidget(m_pluginTypeSelector, row, 1);
|
Chris@1289
|
40 connect(m_pluginTypeSelector, SIGNAL(currentTextChanged(QString)),
|
Chris@1289
|
41 this, SLOT(currentTypeChanged(QString)));
|
Chris@1289
|
42
|
Chris@1287
|
43 ++row;
|
Chris@1287
|
44
|
Chris@1287
|
45 m_list = new QListWidget;
|
Chris@1287
|
46 m_layout->addWidget(m_list, row, 0, 1, 2);
|
Chris@1287
|
47 m_layout->setRowStretch(row, 10);
|
Chris@1287
|
48 m_layout->setColumnStretch(0, 10);
|
Chris@1288
|
49 connect(m_list, SIGNAL(currentRowChanged(int)),
|
Chris@1288
|
50 this, SLOT(currentLocationChanged(int)));
|
Chris@1287
|
51 ++row;
|
Chris@1287
|
52
|
Chris@1287
|
53 QHBoxLayout *buttons = new QHBoxLayout;
|
Chris@1287
|
54
|
Chris@1288
|
55 m_down = new QPushButton;
|
Chris@1288
|
56 m_down->setIcon(IconLoader().load("down"));
|
Chris@1288
|
57 m_down->setToolTip(tr("Move the selected location later in the list"));
|
Chris@1288
|
58 m_down->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
|
Chris@1288
|
59 connect(m_down, SIGNAL(clicked()), this, SLOT(downClicked()));
|
Chris@1288
|
60 buttons->addWidget(m_down);
|
Chris@1287
|
61
|
Chris@1288
|
62 m_up = new QPushButton;
|
Chris@1288
|
63 m_up->setIcon(IconLoader().load("up"));
|
Chris@1288
|
64 m_up->setToolTip(tr("Move the selected location earlier in the list"));
|
Chris@1288
|
65 m_up->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
|
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 m_delete->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
|
Chris@1288
|
73 connect(m_delete, SIGNAL(clicked()), this, SLOT(deleteClicked()));
|
Chris@1288
|
74 buttons->addWidget(m_delete);
|
Chris@1287
|
75
|
Chris@1287
|
76 m_layout->addLayout(buttons, row, 1);
|
Chris@1287
|
77 ++row;
|
Chris@1285
|
78 }
|
Chris@1285
|
79
|
Chris@1285
|
80 PluginPathConfigurator::~PluginPathConfigurator()
|
Chris@1285
|
81 {
|
Chris@1285
|
82 }
|
Chris@1285
|
83
|
Chris@1285
|
84 void
|
Chris@1289
|
85 PluginPathConfigurator::setPaths(Paths paths)
|
Chris@1285
|
86 {
|
Chris@1289
|
87 m_paths = paths;
|
Chris@1289
|
88
|
Chris@1289
|
89 m_pluginTypeSelector->clear();
|
Chris@1289
|
90 for (const auto &p: paths) {
|
Chris@1289
|
91 m_pluginTypeSelector->addItem(p.first);
|
Chris@1289
|
92 }
|
Chris@1289
|
93
|
Chris@1285
|
94 populate();
|
Chris@1285
|
95 }
|
Chris@1285
|
96
|
Chris@1285
|
97 void
|
Chris@1289
|
98 PluginPathConfigurator::populate()
|
Chris@1285
|
99 {
|
Chris@1287
|
100 m_list->clear();
|
Chris@1286
|
101
|
Chris@1289
|
102 if (m_paths.empty()) return;
|
Chris@1289
|
103
|
Chris@1289
|
104 populateFor(m_paths.begin()->first, 0);
|
Chris@1289
|
105 }
|
Chris@1289
|
106
|
Chris@1289
|
107 void
|
Chris@1289
|
108 PluginPathConfigurator::populateFor(QString type, int makeCurrent)
|
Chris@1289
|
109 {
|
Chris@1289
|
110 m_list->clear();
|
Chris@1289
|
111
|
Chris@1289
|
112 for (int i = 0; i < m_pluginTypeSelector->count(); ++i) {
|
Chris@1289
|
113 if (type == m_pluginTypeSelector->itemText(i)) {
|
Chris@1289
|
114 m_pluginTypeSelector->setCurrentIndex(i);
|
Chris@1289
|
115 }
|
Chris@1289
|
116 }
|
Chris@1289
|
117
|
Chris@1289
|
118 QStringList path = m_paths.at(type).directories;
|
Chris@1289
|
119
|
Chris@1289
|
120 for (int i = 0; i < path.size(); ++i) {
|
Chris@1289
|
121 m_list->addItem(path[i]);
|
Chris@1287
|
122 }
|
Chris@1285
|
123
|
Chris@1289
|
124 if (makeCurrent >= 0 && makeCurrent < path.size()) {
|
Chris@1287
|
125 m_list->setCurrentRow(makeCurrent);
|
Chris@1286
|
126 }
|
Chris@1285
|
127 }
|
Chris@1285
|
128
|
Chris@1285
|
129 void
|
Chris@1288
|
130 PluginPathConfigurator::currentLocationChanged(int i)
|
Chris@1288
|
131 {
|
Chris@1289
|
132 QString type = m_pluginTypeSelector->currentText();
|
Chris@1289
|
133 QStringList path = m_paths.at(type).directories;
|
Chris@1288
|
134 m_up->setEnabled(i > 0);
|
Chris@1289
|
135 m_down->setEnabled(i + 1 < path.size());
|
Chris@1289
|
136 m_delete->setEnabled(i < path.size());
|
Chris@1289
|
137 }
|
Chris@1289
|
138
|
Chris@1289
|
139 void
|
Chris@1289
|
140 PluginPathConfigurator::currentTypeChanged(QString type)
|
Chris@1289
|
141 {
|
Chris@1289
|
142 populateFor(type, 0);
|
Chris@1288
|
143 }
|
Chris@1288
|
144
|
Chris@1288
|
145 void
|
Chris@1285
|
146 PluginPathConfigurator::upClicked()
|
Chris@1285
|
147 {
|
Chris@1289
|
148 QString type = m_pluginTypeSelector->currentText();
|
Chris@1289
|
149 QStringList path = m_paths.at(type).directories;
|
Chris@1289
|
150 QString variable = m_paths.at(type).envVariable;
|
Chris@1289
|
151
|
Chris@1287
|
152 int current = m_list->currentRow();
|
Chris@1287
|
153 if (current <= 0) return;
|
Chris@1287
|
154
|
Chris@1286
|
155 QStringList newPath;
|
Chris@1289
|
156 for (int i = 0; i < path.size(); ++i) {
|
Chris@1287
|
157 if (i + 1 == current) {
|
Chris@1289
|
158 newPath.push_back(path[i+1]);
|
Chris@1289
|
159 newPath.push_back(path[i]);
|
Chris@1286
|
160 ++i;
|
Chris@1286
|
161 } else {
|
Chris@1289
|
162 newPath.push_back(path[i]);
|
Chris@1286
|
163 }
|
Chris@1286
|
164 }
|
Chris@1289
|
165 m_paths[type] = { newPath, variable };
|
Chris@1287
|
166
|
Chris@1289
|
167 populateFor(type, current - 1);
|
Chris@1285
|
168 }
|
Chris@1285
|
169
|
Chris@1285
|
170 void
|
Chris@1285
|
171 PluginPathConfigurator::downClicked()
|
Chris@1285
|
172 {
|
Chris@1289
|
173 QString type = m_pluginTypeSelector->currentText();
|
Chris@1289
|
174 QStringList path = m_paths.at(type).directories;
|
Chris@1289
|
175 QString variable = m_paths.at(type).envVariable;
|
Chris@1289
|
176
|
Chris@1287
|
177 int current = m_list->currentRow();
|
Chris@1289
|
178 if (current < 0 || current + 1 >= path.size()) return;
|
Chris@1289
|
179
|
Chris@1286
|
180 QStringList newPath;
|
Chris@1289
|
181 for (int i = 0; i < path.size(); ++i) {
|
Chris@1287
|
182 if (i == current) {
|
Chris@1289
|
183 newPath.push_back(path[i+1]);
|
Chris@1289
|
184 newPath.push_back(path[i]);
|
Chris@1286
|
185 ++i;
|
Chris@1286
|
186 } else {
|
Chris@1289
|
187 newPath.push_back(path[i]);
|
Chris@1286
|
188 }
|
Chris@1286
|
189 }
|
Chris@1289
|
190 m_paths[type] = { newPath, variable };
|
Chris@1287
|
191
|
Chris@1289
|
192 populateFor(type, current + 1);
|
Chris@1285
|
193 }
|
Chris@1285
|
194
|
Chris@1285
|
195 void
|
Chris@1285
|
196 PluginPathConfigurator::deleteClicked()
|
Chris@1285
|
197 {
|
Chris@1289
|
198 QString type = m_pluginTypeSelector->currentText();
|
Chris@1289
|
199 QStringList path = m_paths.at(type).directories;
|
Chris@1289
|
200 QString variable = m_paths.at(type).envVariable;
|
Chris@1289
|
201
|
Chris@1287
|
202 int current = m_list->currentRow();
|
Chris@1289
|
203
|
Chris@1286
|
204 QStringList newPath;
|
Chris@1289
|
205 for (int i = 0; i < path.size(); ++i) {
|
Chris@1287
|
206 if (i != current) {
|
Chris@1289
|
207 newPath.push_back(path[i]);
|
Chris@1286
|
208 }
|
Chris@1286
|
209 }
|
Chris@1289
|
210 m_paths[type] = { newPath, variable };
|
Chris@1287
|
211
|
Chris@1289
|
212 populateFor(type, current < newPath.size() ? current : current-1);
|
Chris@1285
|
213 }
|