/[svn]/qsampler/trunk/src/qsamplerDeviceForm.ui.h
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerDeviceForm.ui.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 430 by capela, Tue Mar 8 17:23:29 2005 UTC revision 431 by capela, Tue Mar 8 20:12:08 2005 UTC
# Line 33  Line 33 
33  // Kind of constructor.  // Kind of constructor.
34  void qsamplerDeviceForm::init (void)  void qsamplerDeviceForm::init (void)
35  {  {
36      // Initialize locals.          // Initialize locals.
37      m_pMainForm   = (qsamplerMainForm *) QWidget::parentWidget();          m_pMainForm   = (qsamplerMainForm *) QWidget::parentWidget();
38      m_pClient     = NULL;          m_pClient     = NULL;
39          m_iDirtySetup = 0;          m_iDirtySetup = 0;
40      m_iDirtyCount = 0;          m_iDirtyCount = 0;
41      m_iUntitled   = 1;          m_iUntitled   = 1;
42      m_bNewDevice  = false;          m_bNewDevice  = false;
43    
44      // Try to restore normal window positioning.          // Try to restore normal window positioning.
45      adjustSize();          adjustSize();
46  }  }
47    
48    
# Line 55  void qsamplerDeviceForm::destroy (void) Line 55  void qsamplerDeviceForm::destroy (void)
55  // Notify our parent that we're emerging.  // Notify our parent that we're emerging.
56  void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent )  void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent )
57  {  {
58      if (m_pMainForm)          if (m_pMainForm)
59          m_pMainForm->stabilizeForm();                  m_pMainForm->stabilizeForm();
60    
61      stabilizeForm();          stabilizeForm();
62    
63      QWidget::showEvent(pShowEvent);          QWidget::showEvent(pShowEvent);
64  }  }
65    
66    
67  // Notify our parent that we're closing.  // Notify our parent that we're closing.
68  void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent )  void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent )
69  {  {
70      QWidget::hideEvent(pHideEvent);          QWidget::hideEvent(pHideEvent);
71    
72      if (m_pMainForm)          if (m_pMainForm)
73          m_pMainForm->stabilizeForm();                  m_pMainForm->stabilizeForm();
74  }  }
75    
76    
# Line 79  void qsamplerDeviceForm::setClient ( lsc Line 79  void qsamplerDeviceForm::setClient ( lsc
79  {  {
80          // If it has not changed, do nothing.          // If it has not changed, do nothing.
81          if (m_pClient && m_pClient == pClient)          if (m_pClient && m_pClient == pClient)
82              return;                  return;
83    
84          // Set new reference.          // Set new reference.
85          m_pClient = pClient;          m_pClient = pClient;
# Line 92  void qsamplerDeviceForm::setClient ( lsc Line 92  void qsamplerDeviceForm::setClient ( lsc
92  // Format the displayable device configuration filename.  // Format the displayable device configuration filename.
93  QString qsamplerDeviceForm::devicesName ( const QString& sFilename )  QString qsamplerDeviceForm::devicesName ( const QString& sFilename )
94  {  {
95      QString sDevicesName = sFilename;          QString sDevicesName = sFilename;
96      qsamplerOptions *pOptions = m_pMainForm->options();          qsamplerOptions *pOptions = m_pMainForm->options();
97      if (pOptions) {          if (pOptions) {
98          bool bCompletePath = (pOptions && pOptions->bCompletePath);                  bool bCompletePath = (pOptions && pOptions->bCompletePath);
99          if (sDevicesName.isEmpty())                  if (sDevicesName.isEmpty())
100                  sDevicesName = tr("Untitled") + QString::number(m_iUntitled);                          sDevicesName = tr("Untitled") + QString::number(m_iUntitled);
101          else if (!bCompletePath)                  else if (!bCompletePath)
102                  sDevicesName = QFileInfo(sDevicesName).fileName();                          sDevicesName = QFileInfo(sDevicesName).fileName();
103          }          }
104      return sDevicesName;          return sDevicesName;
105  }  }
106    
107    
108  // Window close event handlers.  // Window close event handlers.
109  bool qsamplerDeviceForm::queryClose (void)  bool qsamplerDeviceForm::queryClose (void)
110  {  {
111      bool bQueryClose = true;          bool bQueryClose = true;
112    
113      if (m_iDirtyCount > 0) {          if (m_iDirtyCount > 0) {
114          switch (QMessageBox::warning(this, tr("Warning"),                  switch (QMessageBox::warning(this, tr("Warning"),
115              tr("The device configuration has been changed.\n\n"                          tr("The device configuration has been changed.\n\n"
116                 "\"%1\"\n\n"                          "\"%1\"\n\n"
117                 "Do you want to save the changes?")                          "Do you want to save the changes?")
118                             .arg(devicesName(m_sFilename)),                          .arg(devicesName(m_sFilename)),
119              tr("Save"), tr("Discard"), tr("Cancel"))) {                          tr("Save"), tr("Discard"), tr("Cancel"))) {
120          case 0:     // Save...                  case 0:     // Save...
121              saveDevices();                          saveDevices();
122              // Fall thru....                          // Fall thru....
123          case 1:     // Discard                  case 1:     // Discard
124              break;                          break;
125          default:    // Cancel.                  default:    // Cancel.
126              bQueryClose = false;                          bQueryClose = false;
127          }                  }
128      }          }
129    
130      return bQueryClose;          return bQueryClose;
131  }  }
132    
133    
# Line 135  bool qsamplerDeviceForm::queryClose (voi Line 135  bool qsamplerDeviceForm::queryClose (voi
135  // Dirty up settings.  // Dirty up settings.
136  void qsamplerDeviceForm::contentsChanged (void)  void qsamplerDeviceForm::contentsChanged (void)
137  {  {
138      if (m_iDirtySetup > 0)          if (m_iDirtySetup > 0)
139          return;                  return;
140    
141      m_iDirtyCount++;          m_iDirtyCount++;
142      stabilizeForm();          stabilizeForm();
143  }  }
144    
145    
146  // Load device configuration slot.  // Load device configuration slot.
147  void qsamplerDeviceForm::loadDevices (void)  void qsamplerDeviceForm::loadDevices (void)
148  {  {
149      QString sFilename = QFileDialog::getOpenFileName(          QString sFilename = QFileDialog::getOpenFileName(
150              m_sFilename,                                    // Start here.                          m_sFilename,                                    // Start here.
151              tr("Device Configuration files") + " (*.lscp)", // Filter (XML files)                          tr("Device Configuration files") + " (*.lscp)", // Filter (XML files)
152              this, 0,                                        // Parent and name (none)                          this, 0,                                        // Parent and name (none)
153              tr("Load Device Configuration")                 // Caption.                          tr("Load Device Configuration")                 // Caption.
154      );          );
155    
156      if (sFilename.isEmpty())          if (sFilename.isEmpty())
157          return;                  return;
   
     // Check if we're going to discard safely the current one...  
     if (!queryClose())  
         return;  
158    
159      // Load it right away...          // Check if we're going to discard safely the current one...
160      loadDevicesFile(sFilename);          if (!queryClose())
161                    return;
162    
163            // Load it right away...
164            loadDevicesFile(sFilename);
165  }  }
166    
167    
168  // Save device configuration slot.  // Save device configuration slot.
169  void qsamplerDeviceForm::saveDevices (void)  void qsamplerDeviceForm::saveDevices (void)
170  {  {
171      QString sFilename = QFileDialog::getSaveFileName(          QString sFilename = QFileDialog::getSaveFileName(
172              m_sFilename,                                    // Start here.                          m_sFilename,                                    // Start here.
173              tr("Device Configuration files") + " (*.lscp)", // Filter (XML files)                          tr("Device Configuration files") + " (*.lscp)", // Filter (XML files)
174              this, 0,                                        // Parent and name (none)                          this, 0,                                        // Parent and name (none)
175              tr("Save Device Configuration")                 // Caption.                          tr("Save Device Configuration")                 // Caption.
176      );          );
177    
178      if (sFilename.isEmpty())          if (sFilename.isEmpty())
179          return;                  return;
   
     // Enforce .xml extension...  
     if (QFileInfo(sFilename).extension().isEmpty())  
         sFilename += ".lscp";  
180    
181      // Save it right away...          // Enforce .xml extension...
182      saveDevicesFile(sFilename);          if (QFileInfo(sFilename).extension().isEmpty())
183                    sFilename += ".lscp";
184    
185            // Save it right away...
186            saveDevicesFile(sFilename);
187  }  }
188    
189    
# Line 191  void qsamplerDeviceForm::saveDevices (vo Line 191  void qsamplerDeviceForm::saveDevices (vo
191  void qsamplerDeviceForm::loadDevicesFile ( const QString& sFilename )  void qsamplerDeviceForm::loadDevicesFile ( const QString& sFilename )
192  {  {
193          //          //
194      // TODO: Load device configuration from file...          // TODO: Load device configuration from file...
195          //          //
196          m_pMainForm->appendMessages("qsamplerDeviceForm::loadDevicesFile(\"" + sFilename + "\")...");          m_pMainForm->appendMessages("qsamplerDeviceForm::loadDevicesFile(\"" + sFilename + "\")...");
197    
# Line 206  void qsamplerDeviceForm::loadDevicesFile Line 206  void qsamplerDeviceForm::loadDevicesFile
206  void qsamplerDeviceForm::saveDevicesFile ( const QString& sFilename )  void qsamplerDeviceForm::saveDevicesFile ( const QString& sFilename )
207  {  {
208          //          //
209      // TODO: Save device configuration into file...          // TODO: Save device configuration into file...
210      //          //
211          m_pMainForm->appendMessages("qsamplerDeviceForm::saveDevicesFile(\"" + sFilename + "\")...");          m_pMainForm->appendMessages("qsamplerDeviceForm::saveDevicesFile(\"" + sFilename + "\")...");
212    
213          m_sFilename   = sFilename;          m_sFilename   = sFilename;
# Line 220  void qsamplerDeviceForm::saveDevicesFile Line 220  void qsamplerDeviceForm::saveDevicesFile
220  void qsamplerDeviceForm::createDevice (void)  void qsamplerDeviceForm::createDevice (void)
221  {  {
222          //          //
223      // TODO: Create a new device from current table view...          // TODO: Create a new device from current table view...
224      //          //
225          m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()...");          m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()...");
226                    
227          m_iDirtyCount++;          m_iDirtyCount++;
# Line 233  void qsamplerDeviceForm::createDevice (v Line 233  void qsamplerDeviceForm::createDevice (v
233  void qsamplerDeviceForm::updateDevice (void)  void qsamplerDeviceForm::updateDevice (void)
234  {  {
235          //          //
236      // TODO: Update current device in table view...          // TODO: Update current device in table view...
237      //          //
238          m_pMainForm->appendMessages("qsamplerDeviceForm::updateDevice()...");          m_pMainForm->appendMessages("qsamplerDeviceForm::updateDevice()...");
239    
240          m_iDirtyCount++;          m_iDirtyCount++;
# Line 246  void qsamplerDeviceForm::updateDevice (v Line 246  void qsamplerDeviceForm::updateDevice (v
246  void qsamplerDeviceForm::deleteDevice (void)  void qsamplerDeviceForm::deleteDevice (void)
247  {  {
248          //          //
249      // TODO: Delete current device in table view...          // TODO: Delete current device in table view...
250      //          //
251          m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()...");          m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()...");
252    
253          m_iDirtyCount++;          m_iDirtyCount++;
# Line 258  void qsamplerDeviceForm::deleteDevice (v Line 258  void qsamplerDeviceForm::deleteDevice (v
258  // Refresh all device list and views.  // Refresh all device list and views.
259  void qsamplerDeviceForm::refreshDevices (void)  void qsamplerDeviceForm::refreshDevices (void)
260  {  {
261      // Avoid nested changes.          // Avoid nested changes.
262      m_iDirtySetup++;          m_iDirtySetup++;
263    
264          //          //
265      // TODO: Load device configuration data ...          // TODO: Load device configuration data ...
266      //          //
267          m_pMainForm->appendMessages("qsamplerDeviceForm::refreshDevices()");          m_pMainForm->appendMessages("qsamplerDeviceForm::refreshDevices()");
268    
269      DeviceListView->clear();          DeviceListView->clear();
270      if (m_pClient) {          if (m_pClient) {
271                  qsamplerDeviceItem *pItem;                  qsamplerDeviceItem *pItem;
272                  int *piDeviceIDs;                  int *piDeviceIDs;
273                  // Grab and pop Audio devices...                  // Grab and pop Audio devices...
274          pItem = new qsamplerDeviceItem(DeviceListView, m_pClient,                  pItem = new qsamplerDeviceItem(DeviceListView, m_pClient,
275                          qsamplerDevice::Audio);                          qsamplerDevice::Audio);
276          if (pItem) {                  if (pItem) {
277                          pItem->setText(0, tr("Audio"));                          pItem->setText(0, tr("Audio"));
278                          piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio);                          piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio);
279                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
280                              new qsamplerDeviceItem(pItem, m_pClient,                                  new qsamplerDeviceItem(pItem, m_pClient,
281                                          qsamplerDevice::Audio, piDeviceIDs[i]);                                          qsamplerDevice::Audio, piDeviceIDs[i]);
282                          }                          }
283                          pItem->setOpen(true);                          pItem->setOpen(true);
284                  }                  }
285                  // Grab and pop MIDI devices...                  // Grab and pop MIDI devices...
286          pItem = new qsamplerDeviceItem(DeviceListView, m_pClient,                  pItem = new qsamplerDeviceItem(DeviceListView, m_pClient,
287                          qsamplerDevice::Midi);                          qsamplerDevice::Midi);
288          if (pItem) {                  if (pItem) {
289                          pItem->setText(0, tr("MIDI"));                          pItem->setText(0, tr("MIDI"));
290                          piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi);                          piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi);
291                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
292                              new qsamplerDeviceItem(pItem, m_pClient,                                  new qsamplerDeviceItem(pItem, m_pClient,
293                                          qsamplerDevice::Midi, piDeviceIDs[i]);                                          qsamplerDevice::Midi, piDeviceIDs[i]);
294                          }                          }
295                          pItem->setOpen(true);                          pItem->setOpen(true);
296                  }                  }
297          }          }
298    
299      // Done.          // Done.
300      selectDevice();          selectDevice();
301      m_iDirtySetup--;          m_iDirtySetup--;
302  }  }
303    
304    
# Line 310  void qsamplerDeviceForm::selectDriver ( Line 310  void qsamplerDeviceForm::selectDriver (
310          //          //
311          m_pMainForm->appendMessages("qsamplerDeviceForm::selectDriver(\"" + sDriverName + "\")");          m_pMainForm->appendMessages("qsamplerDeviceForm::selectDriver(\"" + sDriverName + "\")");
312    
313          m_iDirtyCount++;          QListViewItem *pItem = DeviceListView->selectedItem();
314            if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
315                    return;
316    
317            qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
318            if (m_bNewDevice) {
319                    device.setDriver(m_pClient, sDriverName);
320                    m_iDirtyCount++;
321            }
322    
323            // Done.
324          stabilizeForm();          stabilizeForm();
325  }  }
326    
# Line 323  void qsamplerDeviceForm::selectDevice (v Line 333  void qsamplerDeviceForm::selectDevice (v
333          //          //
334          m_pMainForm->appendMessages("qsamplerDeviceForm::selectDevice()");          m_pMainForm->appendMessages("qsamplerDeviceForm::selectDevice()");
335    
336      QListViewItem *pItem = DeviceListView->selectedItem();          QListViewItem *pItem = DeviceListView->selectedItem();
337          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) {          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) {
338                  stabilizeForm();                  stabilizeForm();
339                  return;                  return;
340          }          }
341    
342          const qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
343          m_bNewDevice = (device.deviceID() < 0);          m_bNewDevice = (device.deviceID() < 0);
344    
345          // Fill the device heading...          // Fill the device heading...
# Line 338  void qsamplerDeviceForm::selectDevice (v Line 348  void qsamplerDeviceForm::selectDevice (v
348          DriverNameComboBox->insertStringList(          DriverNameComboBox->insertStringList(
349                  qsamplerDevice::getDrivers(m_pClient, device.deviceType()));                  qsamplerDevice::getDrivers(m_pClient, device.deviceType()));
350          const QString& sDriverName = device.driverName();          const QString& sDriverName = device.driverName();
351      if (!sDriverName.isEmpty()) {          if (m_bNewDevice || sDriverName.isEmpty()) {
352          if (DriverNameComboBox->listBox()->findItem(sDriverName, Qt::ExactMatch) == NULL)                  device.setDriver(m_pClient, DriverNameComboBox->currentText());
353              DriverNameComboBox->insertItem(sDriverName);          } else {
354          DriverNameComboBox->setCurrentText(sDriverName);                  if (DriverNameComboBox->listBox()->findItem(sDriverName, Qt::ExactMatch) == NULL)
355      }                          DriverNameComboBox->insertItem(sDriverName);
356                    DriverNameComboBox->setCurrentText(sDriverName);
357            }
358          DriverNameTextLabel->setEnabled(m_bNewDevice);          DriverNameTextLabel->setEnabled(m_bNewDevice);
359          DriverNameComboBox->setEnabled(m_bNewDevice);          DriverNameComboBox->setEnabled(m_bNewDevice);
360                    
361          // Fill the device parameter table...          // Fill the device parameter table...
362          DeviceParamTable->setEnabled(true);          DeviceParamTable->refresh(device);
         DeviceParamTable->setDevice(m_pClient,  
             device.deviceType(), device.deviceID());  
363    
364          // Done.          // Done.
365          stabilizeForm();          stabilizeForm();
# Line 359  void qsamplerDeviceForm::selectDevice (v Line 369  void qsamplerDeviceForm::selectDevice (v
369  // Stabilize current form state.  // Stabilize current form state.
370  void qsamplerDeviceForm::stabilizeForm (void)  void qsamplerDeviceForm::stabilizeForm (void)
371  {  {
372      // Update the main caption...          // Update the main caption...
373      QString sDevicesName = devicesName(m_sFilename);          QString sDevicesName = devicesName(m_sFilename);
374      if (m_iDirtyCount > 0)          if (m_iDirtyCount > 0)
375          sDevicesName += '*';                  sDevicesName += '*';
376      setCaption(tr("Devices - [%1]").arg(sDevicesName));          setCaption(tr("Devices - [%1]").arg(sDevicesName));
377    
378          //          //
379          // TODO: Enable/disable available command buttons.          // TODO: Enable/disable available command buttons.
380          //          //
381          m_pMainForm->appendMessages("qsamplerDeviceForm::stabilizeForm()");          m_pMainForm->appendMessages("qsamplerDeviceForm::stabilizeForm()");
382    
383      SaveDevicesPushButton->setEnabled(m_iDirtyCount > 0);          SaveDevicesPushButton->setEnabled(m_iDirtyCount > 0);
384    
385      QListViewItem *pItem = DeviceListView->selectedItem();          QListViewItem *pItem = DeviceListView->selectedItem();
386      bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
387          DeviceNameTextLabel->setEnabled(bEnabled);          DeviceNameTextLabel->setEnabled(bEnabled);
388          DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice);          DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice);
389          DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);          DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
390          DeviceParamTable->setEnabled(bEnabled);          DeviceParamTable->setEnabled(bEnabled);
391      CreateDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 ||  m_bNewDevice));          CreateDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 ||  m_bNewDevice));
392      UpdateDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 && !m_bNewDevice));          UpdateDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 && !m_bNewDevice));
393      DeleteDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 && !m_bNewDevice));          DeleteDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 && !m_bNewDevice));
394  }  }
395    
396    

Legend:
Removed from v.430  
changed lines
  Added in v.431

  ViewVC Help
Powered by ViewVC