Revert previous commit, was incorrect
[amarok.git] / src / MediaDevicePluginManager.cpp
blob63a67d17c03b01027ab4d71b271df86023d75b26
1 //
2 // C++ Implementation: mediadevicepluginmanager
3 //
4 // Description:
5 //
6 //
7 // Authors: Jeff Mitchell <kde-dev@emailgoeshere.com>, (C) 2005, 2006
8 // Martin Aumueller <aumuell@reserv.at>, (C) 2006
9 //
10 // Copyright: See COPYING file that comes with this distribution
13 #include "MediaDevicePluginManager.h"
15 #include "amarok.h"
16 #include "debug.h"
17 #include "deviceconfiguredialog.h"
18 #include "hintlineedit.h"
19 #include "mediabrowser.h"
20 #include "MediaDeviceCache.h"
21 #include "plugin/pluginconfig.h"
22 #include "pluginmanager.h"
23 #include "ContextStatusBar.h"
25 #include <KApplication>
26 #include <KComboBox>
27 #include <KConfig>
28 #include <KIconLoader>
29 #include <KLineEdit>
30 #include <KLocale>
31 #include <KPushButton>
32 #include <KVBox>
33 #include <Solid/Device>
35 #include <QFile>
36 #include <QGroupBox>
37 #include <QHeaderView>
38 #include <QLabel>
39 #include <QMessageBox>
40 #include <QTextDocument>
41 #include <QTableWidget>
42 #include <QToolTip>
43 #include <QWhatsThis>
45 MediaDevicePluginManagerDialog::MediaDevicePluginManagerDialog()
46 : KDialog( Amarok::mainWindow() )
47 , m_genericDevices( 0 )
48 , m_addButton( 0 )
49 , m_devicesBox( 0 )
50 , m_location( 0 )
51 , m_manager( 0 )
53 setObjectName( "mediadevicepluginmanagerdialog" );
54 setModal( false );
55 setButtons( Ok | Cancel );
56 setDefaultButton( Ok );
58 kapp->setTopWidget( this );
59 setCaption( KDialog::makeStandardCaption( i18n( "Manage Devices and Plugins" ) ) );
61 KVBox *vbox = new KVBox( this );
62 setMainWidget( vbox );
64 vbox->setSpacing( KDialog::spacingHint() );
65 vbox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
67 m_location = new QGroupBox( i18n( "Devices" ), vbox );
68 m_location->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) );
69 m_devicesBox = new KVBox( m_location );
70 m_devicesBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
72 m_manager = new MediaDevicePluginManager( m_devicesBox );
74 KHBox *hbox = new KHBox( vbox );
75 m_genericDevices = new KPushButton( i18n( "Generic Devices and Volumes..." ), hbox);
76 m_genericDevices->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
77 connect( m_genericDevices, SIGNAL( clicked() ), m_manager, SLOT( slotGenericVolumes() ) );
79 m_addButton = new KPushButton( i18n( "Add Device..." ), hbox );
80 m_addButton->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
81 connect( m_addButton, SIGNAL( clicked() ), m_manager, SLOT( slowNewDevice() ) );
82 connect( this, SIGNAL( okClicked() ), this, SLOT( slotOk() ) );
85 MediaDevicePluginManagerDialog::~MediaDevicePluginManagerDialog()
87 disconnect( m_genericDevices, SIGNAL( clicked() ), m_manager, SLOT( slotGenericVolumes() ) );
88 disconnect( m_addButton, SIGNAL( clicked() ), m_manager, SLOT( slotNewDevice() ) );
89 delete m_manager;
92 void
93 MediaDevicePluginManagerDialog::slotOk()
95 m_manager->finished();
96 disconnect( this, SIGNAL( okClicked() ), this, SLOT( slotOk() ) );
99 MediaDevicePluginManager::MediaDevicePluginManager( QWidget *widget )
100 : m_widget( widget )
102 detectDevices();
104 connect( this, SIGNAL( selectedPlugin( const QString &, const QString & ) ), MediaBrowser::instance(), SLOT( pluginSelected( const QString &, const QString & ) ) );
105 connect( MediaDeviceCache::instance(), SIGNAL( deviceAdded(const QString &) ), this, SLOT( slotSolidDeviceAdded(const QString &) ) );
106 connect( MediaDeviceCache::instance(), SIGNAL( deviceRemoved(const QString &) ), this, SLOT( slotSolidDeviceRemoved(const QString &) ) );
109 MediaDevicePluginManager::~MediaDevicePluginManager()
111 foreach( MediaDeviceConfig* mdc, m_deviceList )
112 disconnect( mdc, SIGNAL(deleteDevice(const QString &)), this, SLOT(slotDeleteDevice(const QString &)) );
113 disconnect( this, SIGNAL( selectedPlugin( const QString &, const QString & ) ), MediaBrowser::instance(), SLOT( pluginSelected( const QString &, const QString & ) ) );
114 disconnect( MediaDeviceCache::instance(), SIGNAL( deviceAdded(const QString &) ), this, SLOT( slotSolidDeviceAdded(const QString &) ) );
115 disconnect( MediaDeviceCache::instance(), SIGNAL( deviceRemoved(const QString &) ), this, SLOT( slotSolidDeviceRemoved(const QString &) ) );
118 void
119 MediaDevicePluginManager::slotGenericVolumes()
121 MediaDeviceVolumeMarkerDialog *mdvmd = new MediaDeviceVolumeMarkerDialog();
122 mdvmd->exec();
123 delete mdvmd;
124 detectDevices();
127 bool
128 MediaDevicePluginManager::detectDevices()
130 DEBUG_BLOCK
131 bool foundNew = false;
132 KConfigGroup config = Amarok::config( "PortableDevices" );
133 MediaDeviceCache::instance()->refreshCache();
134 QStringList udiList = MediaDeviceCache::instance()->getAll();
135 foreach( const QString &udi, udiList )
137 debug() << "Checking device udi " << udi;
139 bool skipflag = false;
141 foreach( MediaDeviceConfig* mediadevice, m_deviceList )
143 if( udi == mediadevice->udi() )
145 skipflag = true;
146 debug() << "skipping: already listed";
147 //TODO: Handle case where no longer has .is_audio_player
151 if( skipflag )
152 continue;
154 if( MediaDeviceCache::instance()->deviceType( udi ) == MediaDeviceCache::SolidVolumeType &&
155 !MediaDeviceCache::instance()->isGenericEnabled( udi ) )
157 debug() << "Device generic but not enabled, skipping.";
158 continue;
160 else
162 MediaDeviceConfig *dev = new MediaDeviceConfig( udi, m_widget );
163 m_deviceList.append( dev );
164 connect( dev, SIGNAL(deleteDevice(const QString &)), this, SLOT(slotDeleteDevice(const QString &)) );
165 foundNew = true;
169 return foundNew;
172 void
173 MediaDevicePluginManager::slotSolidDeviceAdded( const QString &udi )
175 foreach( MediaDeviceConfig* mediadevice, m_deviceList )
177 if( udi == mediadevice->udi() )
179 debug() << "skipping: already listed";
180 return;
183 int deviceType = MediaDeviceCache::instance()->deviceType( udi );
184 if( deviceType == MediaDeviceCache::SolidPMPType ||
185 ( deviceType == MediaDeviceCache::SolidVolumeType &&
186 MediaDeviceCache::instance()->isGenericEnabled( udi ) ) )
188 MediaDeviceConfig *dev = new MediaDeviceConfig( udi, m_widget );
189 m_deviceList.append( dev );
190 connect( dev, SIGNAL(deleteDevice(const QString &)), this, SLOT(slotDeleteDevice(const QString&)) );
192 else
194 debug() << "device wasn't PMP, or was volume but not enabled" << endl;
198 void
199 MediaDevicePluginManager::slotSolidDeviceRemoved( const QString &udi )
201 DEBUG_BLOCK
202 debug() << "Trying to remove udi " << udi;
203 for( int i = 0; i < m_deviceList.size(); ++i )
205 if( i < m_deviceList.size() && m_deviceList[i] && m_deviceList[i]->udi() == udi )
207 MediaDeviceConfig* config = m_deviceList[i];
208 m_deviceList.removeAt( i );
209 delete config;
210 --i;
215 void
216 MediaDevicePluginManager::slotDeleteDevice( const QString &udi )
218 DEBUG_BLOCK
219 int i = 0;
220 while( i < m_deviceList.size() )
222 if( m_deviceList[i]->udi() == udi )
224 debug() << "putting device " << udi << " on deleted map";
225 m_deletedMap[udi] = m_deviceList[i];
226 m_deviceList.removeAt( i );
228 else
229 i++;
233 void
234 MediaDevicePluginManager::finished()
236 DEBUG_BLOCK
237 foreach( MediaDeviceConfig* device, m_deviceList )
239 int deviceType = MediaDeviceCache::instance()->deviceType( device->udi() );
240 if( deviceType == MediaDeviceCache::SolidPMPType || deviceType == MediaDeviceCache::SolidVolumeType )
241 continue;
242 debug() << "checking device " << device->udi();
243 debug() << "plugin = " << device->plugin();
244 debug() << "oldPlugin = " << device->oldPlugin();
245 device->setOldPlugin( device->plugin() );
246 emit selectedPlugin( device->udi(), device->plugin() );
249 KConfigGroup config = Amarok::config( "PortableDevices" );
250 foreach( const QString &udi, m_deletedMap.keys() )
252 config.deleteEntry( udi );
253 MediaBrowser::instance()->deviceRemoved( udi );
255 MediaDeviceCache::instance()->refreshCache();
256 m_deletedMap.clear();
259 void
260 MediaDevicePluginManager::slotNewDevice()
262 DEBUG_BLOCK
263 ManualDeviceAdder* mda = new ManualDeviceAdder();
264 int accepted = mda->exec();
265 if( accepted == QDialog::Accepted && mda->successful() )
267 if( !Amarok::config( "PortableDevices" ).readEntry( mda->getId(), QString() ).isNull() )
269 //abort! Can't have the same device defined twice...should never
270 //happen due to name checking earlier...right?
271 Amarok::ContextStatusBar::instance()->longMessageThreadSafe( i18n("Sorry, you cannot define two devices\n"
272 "with the same name and mountpoint!") );
274 else
276 Amarok::config( "PortableDevices" ).writeEntry( mda->getId(), mda->getPlugin() );
277 MediaDeviceCache::instance()->refreshCache();
278 detectDevices();
281 delete mda;
284 /////////////////////////////////////////////////////////////////////
286 ManualDeviceAdder::ManualDeviceAdder()
287 : KDialog( Amarok::mainWindow() )
289 setObjectName( "manualdeviceadder" );
290 setModal( true );
291 setButtons( Ok | Cancel );
292 setDefaultButton( Ok );
295 m_successful = false;
296 m_newId = QString();
298 kapp->setTopWidget( this );
299 setCaption( KDialog::makeStandardCaption( i18n( "Add New Device") ) );
301 KHBox* hbox = new KHBox( this );
302 setMainWidget( hbox );
303 hbox->setSpacing( KDialog::spacingHint() );
305 KVBox* vbox1 = new KVBox( hbox );
307 new QLabel( i18n( "Select the plugin to use with this device:"), vbox1 );
308 m_mdaCombo = new KComboBox( false, vbox1 );
309 m_mdaCombo->setObjectName( "m_mdacombo" );
310 for( KService::List::ConstIterator it = MediaBrowser::instance()->getPlugins().begin();
311 it != MediaBrowser::instance()->getPlugins().end();
312 ++it )
313 m_mdaCombo->addItem( (*it)->name() );
314 if( m_mdaCombo->count() > 0 )
315 m_selectedPlugin = MediaBrowser::instance()->getInternalPluginName( m_mdaCombo->itemText( 0 ) );
317 new QLabel( "", vbox1 );
318 QLabel* nameLabel = new QLabel( vbox1 );
319 nameLabel->setText( i18n( "Enter a &name for this device (required):" ) );
320 m_mdaName = new HintLineEdit( QString(), vbox1);
321 nameLabel->setBuddy( m_mdaName );
322 m_mdaName->setHint( i18n( "Example: My_Ipod" ) );
323 m_mdaName->setToolTip( i18n( "Enter a name for the device. The name must be unique across all manually added devices. It must not contain the pipe ( | ) character." ) );
325 new QLabel( "", vbox1 );
326 QLabel* mpLabel = new QLabel( vbox1 );
327 mpLabel->setText( i18n( "Enter the &mount point of the device, if applicable:" ) );
328 m_mdaMountPoint = new HintLineEdit( QString(), vbox1);
329 mpLabel->setBuddy( m_mdaMountPoint );
330 m_mdaMountPoint->setHint( i18n( "Example: /mnt/ipod" ) );
331 m_mdaMountPoint->setToolTip( i18n( "Enter the device's mount point. Some devices (such as MTP devices) may not have a mount point and this can be ignored. All other devices (iPods, UMS/VFAT devices) should enter the mount point here." ) );
333 connect( m_mdaCombo, SIGNAL( activated(const QString&) ), this, SLOT( slotComboChanged(const QString&) ) );
336 ManualDeviceAdder::~ManualDeviceAdder()
338 disconnect( m_mdaCombo, SIGNAL( activated(const QString&) ), this, SLOT( slotComboChanged(const QString&) ) );
339 delete m_mdaCombo;
340 delete m_mdaName;
341 delete m_mdaMountPoint;
344 void
345 ManualDeviceAdder::slotButtonClicked( int button )
347 DEBUG_BLOCK
348 if( button != KDialog::Ok )
350 debug() << "mda dialog canceled";
351 KDialog::slotButtonClicked( button );
353 if( !getId( true ).isEmpty() &&
354 MediaDeviceCache::instance()->deviceType( m_newId ) == MediaDeviceCache::InvalidType )
356 debug() << "returning with m_successful = true";
357 m_successful = true;
358 KDialog::slotButtonClicked( button );
360 else
362 Amarok::ContextStatusBar::instance()->longMessageThreadSafe( i18n("Sorry, every device must have a name and\n"
363 "you cannot define two devices with the\n"
364 "same name. These names must be unique\n"
365 "across autodetected devices as well.\n") );
369 void
370 ManualDeviceAdder::slotComboChanged( const QString &string )
372 DEBUG_BLOCK
373 //best thing to do here would be to find out if the plugin selected
374 //has m_hasMountPoint set to false...but any way to do this
375 //without instantiating it? This way will suffice for now...
376 if( MediaBrowser::instance()->getInternalPluginName( string ) == "ifp-mediadevice" ||
377 MediaBrowser::instance()->getInternalPluginName( string ) == "daap-mediadevice" ||
378 MediaBrowser::instance()->getInternalPluginName( string ) == "mtp-mediadevice" ||
379 MediaBrowser::instance()->getInternalPluginName( string ) == "njb-mediadevice" )
381 m_mountPointOldText = m_mdaMountPoint->text();
382 m_mdaMountPoint->setText( "No mount point needed" );
383 m_mdaMountPoint->setEnabled(false);
385 else if( m_mdaMountPoint->isEnabled() == false )
387 m_mdaMountPoint->setText( m_mountPointOldText );
388 m_mdaMountPoint->setEnabled(true);
390 m_selectedPlugin = MediaBrowser::instance()->getInternalPluginName( string );
391 debug() << "Selected plugin = " << m_selectedPlugin;
394 QString
395 ManualDeviceAdder::getId( bool recreate )
397 DEBUG_BLOCK
398 if( !recreate )
400 debug() << "No recreate, returning " << m_newId;
401 return m_newId;
404 if( !m_newId.isEmpty() && recreate )
406 m_newId = QString();
409 if( m_mdaMountPoint->isEnabled() == false && m_mdaName->text().isNull() )
411 debug() << "Mount point not enabled, device name is null";
412 return QString();
414 if( m_mdaMountPoint->text().isNull() && m_mdaName->text().isNull() )
416 debug() << "Mount point text is null and device name is null";
417 return QString();
419 if( m_mdaName->text().count( '|' ) )
421 Amarok::ContextStatusBar::instance()->longMessageThreadSafe( i18n( "The device name cannot contain the '|' character" ) );
422 return QString();
424 m_newId = "manual|" + m_mdaName->text() + '|' +
425 ( m_mdaMountPoint->text().isNull() ||
426 m_mdaMountPoint->isEnabled() == false ?
427 "(none)" : m_mdaMountPoint->text() );
428 debug() << "returning id = " << m_newId;
429 return m_newId;
432 MediaDeviceConfig::MediaDeviceConfig( QString udi, QWidget *parent, const char *name )
433 : KHBox( parent )
434 , m_udi( udi )
435 , m_name( MediaDeviceCache::instance()->deviceName( udi ) )
436 , m_oldPlugin( QString() )
437 , m_details( QString() )
438 , m_pluginCombo( 0 )
439 , m_removeButton( 0 )
440 , m_label_details( 0 )
441 , m_new( true )
443 DEBUG_BLOCK
444 setObjectName( name );
446 KConfigGroup config = Amarok::config( "PortableDevices" );
447 m_oldPlugin = config.readEntry( m_udi, QString() );
448 debug() << "oldPlugin = " << m_oldPlugin;
449 if( !m_oldPlugin.isEmpty() )
450 m_new = false;
452 setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
453 setSpacing( 5 );
455 const QString labelTextNone = i18n( "(none)" );
456 QString row = "<tr><td>%1</td><td>%2</td></tr>";
457 QString table;
458 int deviceType = MediaDeviceCache::instance()->deviceType( m_udi );
459 table += row.arg( Qt::escape( i18n( "Autodetected:" ) ),
460 Qt::escape( deviceType == MediaDeviceCache::SolidPMPType || deviceType == MediaDeviceCache::SolidVolumeType ? i18n("Yes") : i18n("No") ) );
461 table += row.arg( Qt::escape( i18n( "Unique ID:" ) ),
462 Qt::escape( m_udi ) );
463 if( deviceType == MediaDeviceCache::SolidPMPType || deviceType == MediaDeviceCache::SolidVolumeType )
465 Solid::Device device( m_udi );
466 if( device.isValid() )
468 if( deviceType == MediaDeviceCache::SolidPMPType )
470 if( !device.vendor().isEmpty() )
471 table += row.arg( Qt::escape( i18n( "Vendor:" ) ),
472 Qt::escape( device.vendor() ) );
473 if( !device.product().isEmpty() )
474 table += row.arg( Qt::escape( i18n( "Product:" ) ),
475 Qt::escape( device.product() ) );
477 else if( deviceType == MediaDeviceCache::SolidVolumeType )
479 if( !device.parent().vendor().isEmpty() )
480 table += row.arg( Qt::escape( i18n( "Vendor:" ) ),
481 Qt::escape( device.parent().vendor() ) );
482 if( !device.parent().product().isEmpty() )
483 table += row.arg( Qt::escape( i18n( "Product:" ) ),
484 Qt::escape( device.parent().product() ) );
489 QString title = Qt::escape( i18n( "Device information for " ) ) + "<b>" + m_udi + "</b>";
490 m_details = QString( "<em>%1</em><br />" "<table>%2</table>" ).arg( title, table );
492 QLabel* label_name = new QLabel( i18n("Name: "), this );
493 Q_UNUSED( label_name );
494 QLabel* label_devicename = new QLabel( m_name, this );
495 Q_UNUSED( label_devicename );
496 QLabel* m_label_details = new QLabel( "<qt>(<a href='details'>" + i18n( "Details" ) + "</a>)</qt>", this );
497 m_label_details->setTextInteractionFlags( Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard );
498 connect( m_label_details, SIGNAL( linkActivated( const QString & ) ), this, SLOT( slotDetailsActivated( const QString & ) ) );
500 QLabel* label_plugin = new QLabel( i18n("Plugin:"), this );
501 Q_UNUSED( label_plugin );
502 m_pluginCombo = new KComboBox( false, this );
504 if( deviceType == MediaDeviceCache::SolidPMPType )
506 debug() << "sending to getDisplayPluginName: " << MediaBrowser::instance()->deviceFromId( m_udi )->type();
507 QString name = MediaBrowser::instance()->getDisplayPluginName( MediaBrowser::instance()->deviceFromId( m_udi )->type() );
508 debug() << "name of protocol from Solid is: " << name;
509 if( name.isEmpty() )
511 m_pluginCombo->addItem( i18n( "Unknown" ) );
513 else
515 debug() << "Adding " << name << " to pluginCombo";
516 m_pluginCombo->addItem( name );
519 else if( deviceType == MediaDeviceCache::SolidVolumeType )
521 m_pluginCombo->addItem( i18n( "Generic Audio Player" ) );
523 else
525 m_pluginCombo->addItem( i18n( "Do not handle" ) );
526 for( KService::List::ConstIterator it = MediaBrowser::instance()->getPlugins().begin();
527 it != MediaBrowser::instance()->getPlugins().end();
528 ++it ){
529 m_pluginCombo->addItem( (*it)->name() );
530 if ( (*it)->property( "X-KDE-Amarok-name" ).toString() == config.readEntry( m_udi, QString() ) )
531 m_pluginCombo->setCurrentItem( (*it)->name() );
534 m_pluginCombo->setEnabled( deviceType == MediaDeviceCache::ManualType );
536 m_removeButton = new KPushButton( i18n( "Remove" ), this );
537 connect( m_removeButton, SIGNAL(clicked()), this, SLOT(slotDeleteDevice()) );
538 m_removeButton->setToolTip( i18n( "Remove entries corresponding to this device from configuration file" ) );
539 m_removeButton->setEnabled( deviceType == MediaDeviceCache::ManualType );
542 MediaDeviceConfig::~MediaDeviceConfig()
544 disconnect( m_label_details, SIGNAL( linkActivated( const QString & ) ), this, SLOT( slotDetailsActivated( const QString & ) ) );
545 disconnect( m_removeButton, SIGNAL(clicked()), this, SLOT(slotDeleteDevice()) );
548 void
549 MediaDeviceConfig::slotConfigureDevice() //slot
551 MediaDevice *device = MediaBrowser::instance()->deviceFromId( m_udi );
552 if( device )
554 DeviceConfigureDialog* dcd = new DeviceConfigureDialog( device );
555 dcd->exec();
556 delete dcd;
558 else
559 debug() << "Could not show the configuration dialog because the device could not be found.";
562 void
563 MediaDeviceConfig::slotDeleteDevice() //slot
565 DEBUG_BLOCK
566 emit deleteDevice( m_udi );
567 delete this;
570 void
571 MediaDeviceConfig::slotDetailsActivated( const QString &link ) //slot
573 Q_UNUSED( link );
574 QWhatsThis::showText( QCursor::pos(), "<qt>" + m_details + "</qt>", Amarok::mainWindow() );
577 QString
578 MediaDeviceConfig::plugin()
580 return MediaBrowser::instance()->getInternalPluginName( m_pluginCombo->currentText() );
583 MediaDeviceVolumeMarkerDialog::MediaDeviceVolumeMarkerDialog()
584 : KDialog( Amarok::mainWindow() )
585 , m_mountPointBox( 0 )
586 , m_table( 0 )
588 setObjectName( "mediadevicevolumemarkerdialog" );
589 setModal( true );
590 setButtons( Ok | Cancel );
591 setDefaultButton( Ok );
593 kapp->setTopWidget( this );
594 setCaption( KDialog::makeStandardCaption( i18n( "Mark Volumes as Media Devices" ) ) );
596 m_mountPointBox = new KVBox( this );
597 m_mountPointBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
598 setMainWidget( m_mountPointBox );
600 KHBox *hbox = new KHBox( m_mountPointBox );
601 m_table = new QTableWidget( 0, 2, hbox );
602 QStringList headerlabels;
603 headerlabels << i18n( "Mount Point:" ) << i18n( "Mark?" );
604 m_table->setHorizontalHeaderLabels( headerlabels );
605 m_table->verticalHeader()->hide();
606 m_table->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
607 m_table->setShowGrid( false );
609 connect( this, SIGNAL( okClicked() ), this, SLOT( slotOk() ) );
611 MediaDeviceCache::instance()->refreshCache();
612 QStringList udiList = MediaDeviceCache::instance()->getAll();
613 foreach( const QString &udi, udiList )
615 if( !MediaDeviceCache::instance()->deviceType( udi ) == MediaDeviceCache::SolidVolumeType ||
616 MediaDeviceCache::instance()->volumeMountPoint( udi ).isEmpty() )
618 debug() << "udi " << udi << " is not a volume, or mount point detected as empty";
619 continue;
621 int row = m_table->rowCount();
622 m_table->insertRow( row );
623 QString mountPoint = MediaDeviceCache::instance()->volumeMountPoint( udi );
624 QTableWidgetItem *item = new QTableWidgetItem( mountPoint );
625 m_table->setItem( row, 0, item );
626 item = new QTableWidgetItem();
627 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
628 if( QFile::exists( mountPoint + "/.is_audio_player" ) )
629 item->setCheckState( Qt::Checked );
630 else
631 item->setCheckState( Qt::Unchecked );
632 m_table->setItem( row, 1, item );
634 m_table->setSortingEnabled( true );
637 MediaDeviceVolumeMarkerDialog::~MediaDeviceVolumeMarkerDialog()
641 void
642 MediaDeviceVolumeMarkerDialog::slotOk()
644 for( int row = 0; row < m_table->rowCount(); row++ )
646 QString mountPoint = m_table->item( row, 0 )->text();
647 bool checkedState = m_table->item( row, 1 )->checkState() == Qt::Checked ? true : false;
648 bool initialState = QFile::exists( mountPoint + "/.is_audio_player" );
649 if( initialState == checkedState )
650 continue;
651 if( initialState == false )
653 //attempt to write the file
656 else
658 //attempt to delete the file
659 bool success = QFile::remove( mountPoint + "/.is_audio_player" );
660 if( !success )
662 QMessageBox::critical( this, i18n( "Well, we tried..." ),
663 i18n( "Could not remove the marking file at %1.\n"
664 "Ensure that you have the correct permissions\n"
665 "to remove that file." ) );
670 disconnect( this, SIGNAL( okClicked() ), this, SLOT( slotOk() ) );
673 #include "MediaDevicePluginManager.moc"