1 |
// qsamplerDeviceForm.ui.h |
2 |
// |
3 |
// ui.h extension file, included from the uic-generated form implementation. |
4 |
/**************************************************************************** |
5 |
Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
|
7 |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
9 |
as published by the Free Software Foundation; either version 2 |
10 |
of the License, or (at your option) any later version. |
11 |
|
12 |
This program is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
16 |
|
17 |
You should have received a copy of the GNU General Public License |
18 |
along with this program; if not, write to the Free Software |
19 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
20 |
|
21 |
*****************************************************************************/ |
22 |
|
23 |
#include <qmessagebox.h> |
24 |
#include <qfiledialog.h> |
25 |
#include <qfileinfo.h> |
26 |
|
27 |
#include "qsamplerMainForm.h" |
28 |
|
29 |
#include "config.h" |
30 |
|
31 |
|
32 |
// Kind of constructor. |
33 |
void qsamplerDeviceForm::init (void) |
34 |
{ |
35 |
// Initialize locals. |
36 |
m_pMainForm = (qsamplerMainForm *) QWidget::parentWidget(); |
37 |
m_pClient = NULL; |
38 |
m_iDirtySetup = 0; |
39 |
m_iDirtyCount = 0; |
40 |
m_iUntitled = 1; |
41 |
|
42 |
// Try to restore normal window positioning. |
43 |
adjustSize(); |
44 |
} |
45 |
|
46 |
|
47 |
// Kind of destructor. |
48 |
void qsamplerDeviceForm::destroy (void) |
49 |
{ |
50 |
} |
51 |
|
52 |
|
53 |
// Notify our parent that we're emerging. |
54 |
void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent ) |
55 |
{ |
56 |
if (m_pMainForm) |
57 |
m_pMainForm->stabilizeForm(); |
58 |
|
59 |
stabilizeForm(); |
60 |
|
61 |
QWidget::showEvent(pShowEvent); |
62 |
} |
63 |
|
64 |
|
65 |
// Notify our parent that we're closing. |
66 |
void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent ) |
67 |
{ |
68 |
QWidget::hideEvent(pHideEvent); |
69 |
|
70 |
if (m_pMainForm) |
71 |
m_pMainForm->stabilizeForm(); |
72 |
} |
73 |
|
74 |
|
75 |
// Device configuration dialog setup formal initializer. |
76 |
void qsamplerDeviceForm::setClient ( lscp_client_t *pClient ) |
77 |
{ |
78 |
// If it has not changed, do nothing. |
79 |
if (m_pClient && m_pClient == pClient) |
80 |
return; |
81 |
|
82 |
// Set new reference. |
83 |
m_pClient = pClient; |
84 |
|
85 |
// OK. Do a whole refresh around. |
86 |
refreshDevices(); |
87 |
} |
88 |
|
89 |
|
90 |
// Format the displayable device configuration filename. |
91 |
QString qsamplerDeviceForm::devicesName ( const QString& sFilename ) |
92 |
{ |
93 |
QString sDevicesName = sFilename; |
94 |
qsamplerOptions *pOptions = m_pMainForm->options(); |
95 |
if (pOptions) { |
96 |
bool bCompletePath = (pOptions && pOptions->bCompletePath); |
97 |
if (sDevicesName.isEmpty()) |
98 |
sDevicesName = tr("Untitled") + QString::number(m_iUntitled); |
99 |
else if (!bCompletePath) |
100 |
sDevicesName = QFileInfo(sDevicesName).fileName(); |
101 |
} |
102 |
return sDevicesName; |
103 |
} |
104 |
|
105 |
|
106 |
// Window close event handlers. |
107 |
bool qsamplerDeviceForm::queryClose (void) |
108 |
{ |
109 |
bool bQueryClose = true; |
110 |
|
111 |
if (m_iDirtyCount > 0) { |
112 |
switch (QMessageBox::warning(this, tr("Warning"), |
113 |
tr("The device configuration has been changed.\n\n" |
114 |
"\"%1\"\n\n" |
115 |
"Do you want to save the changes?") |
116 |
.arg(devicesName(m_sFilename)), |
117 |
tr("Save"), tr("Discard"), tr("Cancel"))) { |
118 |
case 0: // Save... |
119 |
saveDevices(); |
120 |
// Fall thru.... |
121 |
case 1: // Discard |
122 |
break; |
123 |
default: // Cancel. |
124 |
bQueryClose = false; |
125 |
} |
126 |
} |
127 |
|
128 |
return bQueryClose; |
129 |
} |
130 |
|
131 |
|
132 |
|
133 |
// Dirty up settings. |
134 |
void qsamplerDeviceForm::contentsChanged (void) |
135 |
{ |
136 |
if (m_iDirtySetup > 0) |
137 |
return; |
138 |
|
139 |
m_iDirtyCount++; |
140 |
stabilizeForm(); |
141 |
} |
142 |
|
143 |
|
144 |
// Load device configuration slot. |
145 |
void qsamplerDeviceForm::loadDevices (void) |
146 |
{ |
147 |
QString sFilename = QFileDialog::getOpenFileName( |
148 |
m_sFilename, // Start here. |
149 |
tr("Device Configuration files") + " (*.lscp)", // Filter (XML files) |
150 |
this, 0, // Parent and name (none) |
151 |
tr("Load Device Configuration") // Caption. |
152 |
); |
153 |
|
154 |
if (sFilename.isEmpty()) |
155 |
return; |
156 |
|
157 |
// Check if we're going to discard safely the current one... |
158 |
if (!queryClose()) |
159 |
return; |
160 |
|
161 |
// Load it right away... |
162 |
loadDevicesFile(sFilename); |
163 |
} |
164 |
|
165 |
|
166 |
// Save device configuration slot. |
167 |
void qsamplerDeviceForm::saveDevices (void) |
168 |
{ |
169 |
QString sFilename = QFileDialog::getSaveFileName( |
170 |
m_sFilename, // Start here. |
171 |
tr("Device Configuration files") + " (*.lscp)", // Filter (XML files) |
172 |
this, 0, // Parent and name (none) |
173 |
tr("Save Device Configuration") // Caption. |
174 |
); |
175 |
|
176 |
if (sFilename.isEmpty()) |
177 |
return; |
178 |
|
179 |
// Enforce .xml extension... |
180 |
if (QFileInfo(sFilename).extension().isEmpty()) |
181 |
sFilename += ".lscp"; |
182 |
|
183 |
// Save it right away... |
184 |
saveDevicesFile(sFilename); |
185 |
} |
186 |
|
187 |
|
188 |
// Load device configuration from file. |
189 |
void qsamplerDeviceForm::loadDevicesFile ( const QString& sFilename ) |
190 |
{ |
191 |
// |
192 |
// TODO: Load device configuration from file... |
193 |
// |
194 |
m_pMainForm->appendMessages("qsamplerDeviceForm::loadDevicesFile(\"" + sFilename + "\")..."); |
195 |
|
196 |
m_sFilename = sFilename; |
197 |
m_iDirtyCount = 0; |
198 |
|
199 |
refreshDevices(); |
200 |
} |
201 |
|
202 |
|
203 |
// Save device configuration into file. |
204 |
void qsamplerDeviceForm::saveDevicesFile ( const QString& sFilename ) |
205 |
{ |
206 |
// |
207 |
// TODO: Save device configuration into file... |
208 |
// |
209 |
m_pMainForm->appendMessages("qsamplerDeviceForm::saveDevicesFile(\"" + sFilename + "\")..."); |
210 |
|
211 |
m_sFilename = sFilename; |
212 |
m_iDirtyCount = 0; |
213 |
stabilizeForm(); |
214 |
} |
215 |
|
216 |
|
217 |
// Create a new device from current table view. |
218 |
void qsamplerDeviceForm::createDevice (void) |
219 |
{ |
220 |
// |
221 |
// TODO: Create a new device from current table view... |
222 |
// |
223 |
m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()..."); |
224 |
} |
225 |
|
226 |
|
227 |
// Update current device in table view. |
228 |
void qsamplerDeviceForm::updateDevice (void) |
229 |
{ |
230 |
// |
231 |
// TODO: Update current device in table view... |
232 |
// |
233 |
m_pMainForm->appendMessages("qsamplerDeviceForm::updateDevice()..."); |
234 |
} |
235 |
|
236 |
|
237 |
// Delete current device in table view. |
238 |
void qsamplerDeviceForm::deleteDevice (void) |
239 |
{ |
240 |
// |
241 |
// TODO: Delete current device in table view... |
242 |
// |
243 |
m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()..."); |
244 |
} |
245 |
|
246 |
|
247 |
// Refresh all device list and views. |
248 |
void qsamplerDeviceForm::refreshDevices (void) |
249 |
{ |
250 |
// Avoid nested changes. |
251 |
m_iDirtySetup++; |
252 |
|
253 |
// |
254 |
// TODO: Load device configuration data ... |
255 |
// |
256 |
|
257 |
m_pMainForm->appendMessages("qsamplerDeviceForm::refreshDevices()"); |
258 |
|
259 |
DeviceListView->clear(); |
260 |
if (m_pClient) { |
261 |
qsamplerDeviceItem *pItem; |
262 |
int *piDeviceIDs; |
263 |
// Grab audio devices... |
264 |
pItem = new qsamplerDeviceItem(DeviceListView, m_pClient, |
265 |
qsamplerDevice::Audio); |
266 |
if (pItem) { |
267 |
pItem->setText(0, tr("Audio")); |
268 |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio); |
269 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
270 |
new qsamplerDeviceItem(pItem, m_pClient, |
271 |
qsamplerDevice::Audio, piDeviceIDs[i]); |
272 |
} |
273 |
} |
274 |
// Grab MIDI devices... |
275 |
pItem = new qsamplerDeviceItem(DeviceListView, m_pClient, |
276 |
qsamplerDevice::Midi); |
277 |
if (pItem) { |
278 |
pItem->setText(0, tr("MIDI")); |
279 |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi); |
280 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
281 |
new qsamplerDeviceItem(pItem, m_pClient, |
282 |
qsamplerDevice::Midi, piDeviceIDs[i]); |
283 |
} |
284 |
} |
285 |
} |
286 |
|
287 |
// Done. |
288 |
m_iDirtySetup--; |
289 |
// stabilizeForm(); |
290 |
} |
291 |
|
292 |
// Device selection slot. |
293 |
void qsamplerDeviceForm::selectDevice ( QListViewItem *pItem ) |
294 |
{ |
295 |
if (pItem == NULL) |
296 |
return; |
297 |
if (pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
298 |
return; |
299 |
|
300 |
m_pMainForm->appendMessages("qsamplerDeviceForm::selectDevice(" + pItem->text(0) + ")"); |
301 |
|
302 |
const qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
303 |
DeviceParamTable->setDevice(m_pClient, |
304 |
device.deviceType(), device.deviceID()); |
305 |
} |
306 |
|
307 |
|
308 |
// Stabilize current form state. |
309 |
void qsamplerDeviceForm::stabilizeForm (void) |
310 |
{ |
311 |
// Update the main caption... |
312 |
QString sDevicesName = devicesName(m_sFilename); |
313 |
if (m_iDirtyCount > 0) |
314 |
sDevicesName += '*'; |
315 |
setCaption(tr("Devices - [%1]").arg(sDevicesName)); |
316 |
|
317 |
// |
318 |
// TODO: Enable/disable available command buttons. |
319 |
// |
320 |
m_pMainForm->appendMessages("qsamplerDeviceForm::stabilizeForm()"); |
321 |
|
322 |
SaveDevicesPushButton->setEnabled(m_iDirtyCount > 0); |
323 |
|
324 |
CreateDevicePushButton->setEnabled(m_iDirtyCount > 0); |
325 |
UpdateDevicePushButton->setEnabled(m_iDirtyCount > 0); |
326 |
DeleteDevicePushButton->setEnabled(m_iDirtyCount > 0); |
327 |
} |
328 |
|
329 |
|
330 |
// end of qsamplerDeviceForm.ui.h |
331 |
|