2 // C++ Implementation: deviceconfiguredialog.cpp
7 // Author: Jeff Mitchell <kde-dev@emailgoeshere.com>, (C) 2006
8 // Martin Aumueller <aumuell@reserv.at>, (C) 2005
10 // Copyright: See COPYING file that comes with this distribution
14 #include "deviceconfiguredialog.h"
18 #include "hintlineedit.h"
19 #include "mediabrowser.h"
21 #include "plugin/pluginconfig.h"
22 #include "pluginmanager.h"
23 #include "scriptmanager.h"
25 #include <KApplication>
28 #include <KPushButton>
30 #include <KWindowSystem>
34 #include <q3buttongroup.h>
37 DeviceConfigureDialog::DeviceConfigureDialog( const Medium
&medium
)
38 : KDialog( Amarok::mainWindow() )
40 setCaption( i18n("Select Plugin for %1", medium
.name() ) );
42 setButtons( Ok
| Cancel
);
43 showButtonSeparator( true );
45 m_medium
= new Medium( medium
);
46 kapp
->setTopWidget( this );
47 setCaption( KDialog::makeStandardCaption( i18n( "Configure Media Device" ) ) );
48 showButton( KDialog::Apply
, false );
50 KVBox
* vbox
= new KVBox( this );
51 setMainWidget( vbox
);
52 vbox
->setSpacing( KDialog::spacingHint() );
54 QLabel
*connectLabel
= 0;
56 QLabel
*disconnectLabel
= 0;
59 Q3ButtonGroup
*transcodeGroup
= 0;
60 m_transcodeAlways
= 0;
61 m_transcodeWhenNecessary
= 0;
62 m_transcodeRemove
= 0;
64 MediaDevice
* device
= MediaBrowser::instance()->deviceFromId( m_medium
->id() );
70 // pre-connect/post-disconnect (mount/umount)
71 connectLabel
= new QLabel( vbox
);
72 connectLabel
->setText( i18n( "Pre-&connect command:" ) );
73 m_connectEdit
= new HintLineEdit( device
->m_preconnectcmd
, vbox
);
74 m_connectEdit
->setHint( i18n( "Example: mount %d" ) );
75 connectLabel
->setBuddy( m_connectEdit
);
76 m_connectEdit
->setToolTip( i18n( "Set a command to be run before connecting to your device (e.g. a mount command) here.\n%d is replaced by the device node, %m by the mount point.\nEmpty commands are not executed." ) );
78 disconnectLabel
= new QLabel( vbox
);
79 disconnectLabel
->setText( i18n( "Post-&disconnect command:" ) );
80 m_disconnectEdit
= new HintLineEdit( device
->m_postdisconnectcmd
, vbox
);
81 disconnectLabel
->setBuddy( m_disconnectEdit
);
82 m_disconnectEdit
->setHint( i18n( "Example: eject %d" ) );
83 m_disconnectEdit
->setToolTip( i18n( "Set a command to be run after disconnecting from your device (e.g. an eject command) here.\n%d is replaced by the device node, %m by the mount point.\nEmpty commands are not executed." ) );
86 m_transcodeCheck
= new QCheckBox( vbox
);
87 m_transcodeCheck
->setText( i18n( "&Transcode before transferring to device" ) );
88 m_transcodeCheck
->setChecked( device
->m_transcode
);
90 transcodeGroup
= new Q3VButtonGroup( vbox
);
91 QString format
= "mp3";
92 if( !device
->supportedFiletypes().isEmpty() )
93 format
= device
->supportedFiletypes().first();
94 transcodeGroup
->setTitle( i18n( "Transcode to preferred format (%1) for device", format
) );
95 m_transcodeAlways
= new QRadioButton( transcodeGroup
);
96 m_transcodeAlways
->setText( i18n( "Whenever possible" ) );
97 m_transcodeAlways
->setChecked( device
->m_transcodeAlways
);
98 m_transcodeWhenNecessary
= new QRadioButton( transcodeGroup
);
99 m_transcodeWhenNecessary
->setText( i18n( "When necessary" ) );
100 m_transcodeWhenNecessary
->setChecked( !device
->m_transcodeAlways
);
101 connect( m_transcodeCheck
, SIGNAL(toggled( bool )),
102 transcodeGroup
, SLOT(setEnabled( bool )) );
103 transcodeGroup
->insert( m_transcodeAlways
);
104 transcodeGroup
->insert( m_transcodeWhenNecessary
);
105 m_transcodeRemove
= new QCheckBox( transcodeGroup
);
106 m_transcodeRemove
->setText( i18n( "Remove transcoded files after transfer" ) );
107 m_transcodeRemove
->setChecked( device
->m_transcodeRemove
);
109 const ScriptManager
*sm
= ScriptManager::instance();
110 m_transcodeCheck
->setEnabled( !sm
->transcodeScriptRunning().isEmpty() );
111 transcodeGroup
->setEnabled( !sm
->transcodeScriptRunning().isEmpty() && device
->m_transcode
);
112 if( sm
->transcodeScriptRunning().isNull() )
114 m_transcodeCheck
->setToolTip( i18n( "For this feature, a script of type \"Transcode\" has to be running" ) );
115 transcodeGroup
->setToolTip( i18n( "For this feature, a script of type \"Transcode\" has to be running" ) );
118 device
->addConfigElements( vbox
);
124 DeviceConfigureDialog::~DeviceConfigureDialog()
126 delete m_connectEdit
;
127 delete m_disconnectEdit
;
132 DeviceConfigureDialog::slotButtonClicked( KDialog::ButtonCode button
)
134 if ( button
!= KDialog::Ok
)
135 KDialog::slotButtonClicked( button
);
137 MediaDevice
* device
= MediaBrowser::instance()->deviceFromId( m_medium
->id() );
141 device
->m_preconnectcmd
= m_connectEdit
->text();
142 device
->setConfigString( "PreConnectCommand", device
->m_preconnectcmd
);
143 device
->m_postdisconnectcmd
= m_disconnectEdit
->text();
144 device
->setConfigString( "PostDisconnectCommand", device
->m_postdisconnectcmd
);
145 device
->setConfigBool( "Transcode", device
->m_transcode
);
146 device
->m_transcode
= m_transcodeCheck
->isChecked();
147 device
->setConfigBool( "Transcode", device
->m_transcode
);
148 device
->m_transcodeAlways
= m_transcodeAlways
->isChecked();
149 device
->setConfigBool( "TranscodeAlways", device
->m_transcodeAlways
);
150 device
->m_transcodeRemove
= m_transcodeRemove
->isChecked();
151 device
->setConfigBool( "TranscodeRemove", device
->m_transcodeRemove
);
152 device
->applyConfig();
155 MediaBrowser::instance()->updateButtons();
156 MediaBrowser::instance()->updateStats();
157 MediaBrowser::instance()->updateDevices();
159 KDialog::slotButtonClicked( button
);
162 #include "deviceconfiguredialog.moc"