/[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 426 by capela, Mon Mar 7 11:09:32 2005 UTC revision 429 by capela, Tue Mar 8 14:56:05 2005 UTC
# Line 20  Line 20 
20    
21  *****************************************************************************/  *****************************************************************************/
22    
 #include <qvalidator.h>  
23  #include <qmessagebox.h>  #include <qmessagebox.h>
24    #include <qfiledialog.h>
25    #include <qfileinfo.h>
26    
27  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
28    
# Line 32  Line 33 
33  void qsamplerDeviceForm::init (void)  void qsamplerDeviceForm::init (void)
34  {  {
35      // Initialize locals.      // Initialize locals.
36      m_pMainForm   = NULL;      m_pMainForm   = (qsamplerMainForm *) QWidget::parentWidget();
37        m_pClient     = NULL;
38          m_iDirtySetup = 0;          m_iDirtySetup = 0;
39      m_iDirtyCount = 0;      m_iDirtyCount = 0;
40        m_iUntitled   = 1;
41    
42      // Try to restore normal window positioning.      // Try to restore normal window positioning.
43      adjustSize();      adjustSize();
# Line 47  void qsamplerDeviceForm::destroy (void) Line 50  void qsamplerDeviceForm::destroy (void)
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.  // Device configuration dialog setup formal initializer.
76  void qsamplerDeviceForm::setup ( qsamplerMainForm *pMainForm )  void qsamplerDeviceForm::setClient ( lscp_client_t *pClient )
77  {  {
78      m_pMainForm   = pMainForm;          // If it has not changed, do nothing.
79          m_iDirtySetup = 0;          if (m_pClient && m_pClient == pClient)
80      m_iDirtyCount = 0;              return;
81    
82            // Set new reference.
83            m_pClient = pClient;
84            
85            // OK. Do a whole refresh around.
86            refreshDevices();
87    }
88    
     if (m_pMainForm == NULL)  
         return;  
     if (m_pMainForm->client() == NULL)  
         return;  
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();      qsamplerOptions *pOptions = m_pMainForm->options();
95      if (pOptions == NULL)      if (pOptions) {
96          return;          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    
         // Set our main client reference.  
     DeviceParameterTable->setClient(pMainForm->client());  
105    
106      // Avoid nested changes.  // Window close event handlers.
107      m_iDirtySetup++;  bool qsamplerDeviceForm::queryClose (void)
108    {
109        bool bQueryClose = true;
110    
111          //      if (m_iDirtyCount > 0) {
112      // TODO: Load initial device configuration data ...          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      // Done.      return bQueryClose;
     m_iDirtySetup--;  
     stabilizeForm();  
129  }  }
130    
131    
132    
133  // Dirty up settings.  // Dirty up settings.
134  void qsamplerDeviceForm::contentsChanged (void)  void qsamplerDeviceForm::contentsChanged (void)
135  {  {
# Line 90  void qsamplerDeviceForm::contentsChanged Line 141  void qsamplerDeviceForm::contentsChanged
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.  // Stabilize current form state.
309  void qsamplerDeviceForm::stabilizeForm (void)  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.          // 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    

Legend:
Removed from v.426  
changed lines
  Added in v.429

  ViewVC Help
Powered by ViewVC