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"
20 #include "MediaDevice.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( MediaDevice
*device
)
38 : KDialog( Amarok::mainWindow() )
41 setCaption( i18n("Select Plugin for %1", m_device
->name() ) );
43 setButtons( Ok
| Cancel
);
44 showButtonSeparator( true );
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;
68 // pre-connect/post-disconnect (mount/umount)
69 connectLabel
= new QLabel( vbox
);
70 connectLabel
->setText( i18n( "Pre-&connect command:" ) );
71 m_connectEdit
= new HintLineEdit( device
->m_preconnectcmd
, vbox
);
72 m_connectEdit
->setHint( i18n( "Example: mount %d" ) );
73 connectLabel
->setBuddy( m_connectEdit
);
74 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." ) );
76 disconnectLabel
= new QLabel( vbox
);
77 disconnectLabel
->setText( i18n( "Post-&disconnect command:" ) );
78 m_disconnectEdit
= new HintLineEdit( device
->m_postdisconnectcmd
, vbox
);
79 disconnectLabel
->setBuddy( m_disconnectEdit
);
80 m_disconnectEdit
->setHint( i18n( "Example: eject %d" ) );
81 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." ) );
84 m_transcodeCheck
= new QCheckBox( vbox
);
85 m_transcodeCheck
->setText( i18n( "&Transcode before transferring to device" ) );
86 m_transcodeCheck
->setChecked( device
->m_transcode
);
88 transcodeGroup
= new Q3VButtonGroup( vbox
);
89 QString format
= "mp3";
90 if( !device
->supportedFiletypes().isEmpty() )
91 format
= device
->supportedFiletypes().first();
92 transcodeGroup
->setTitle( i18n( "Transcode to preferred format (%1) for device", format
) );
93 m_transcodeAlways
= new QRadioButton( transcodeGroup
);
94 m_transcodeAlways
->setText( i18n( "Whenever possible" ) );
95 m_transcodeAlways
->setChecked( device
->m_transcodeAlways
);
96 m_transcodeWhenNecessary
= new QRadioButton( transcodeGroup
);
97 m_transcodeWhenNecessary
->setText( i18n( "When necessary" ) );
98 m_transcodeWhenNecessary
->setChecked( !device
->m_transcodeAlways
);
99 connect( m_transcodeCheck
, SIGNAL(toggled( bool )),
100 transcodeGroup
, SLOT(setEnabled( bool )) );
101 transcodeGroup
->insert( m_transcodeAlways
);
102 transcodeGroup
->insert( m_transcodeWhenNecessary
);
103 m_transcodeRemove
= new QCheckBox( transcodeGroup
);
104 m_transcodeRemove
->setText( i18n( "Remove transcoded files after transfer" ) );
105 m_transcodeRemove
->setChecked( device
->m_transcodeRemove
);
107 const ScriptManager
*sm
= ScriptManager::instance();
108 m_transcodeCheck
->setEnabled( !sm
->transcodeScriptRunning().isEmpty() );
109 transcodeGroup
->setEnabled( !sm
->transcodeScriptRunning().isEmpty() && device
->m_transcode
);
110 if( sm
->transcodeScriptRunning().isNull() )
112 m_transcodeCheck
->setToolTip( i18n( "For this feature, a script of type \"Transcode\" has to be running" ) );
113 transcodeGroup
->setToolTip( i18n( "For this feature, a script of type \"Transcode\" has to be running" ) );
116 device
->addConfigElements( vbox
);
122 DeviceConfigureDialog::~DeviceConfigureDialog()
124 delete m_connectEdit
;
125 delete m_disconnectEdit
;
129 DeviceConfigureDialog::slotButtonClicked( KDialog::ButtonCode button
)
131 if ( button
!= KDialog::Ok
)
132 KDialog::slotButtonClicked( button
);
137 m_device
->m_preconnectcmd
= m_connectEdit
->text();
138 m_device
->setConfigString( "PreConnectCommand", m_device
->m_preconnectcmd
);
139 m_device
->m_postdisconnectcmd
= m_disconnectEdit
->text();
140 m_device
->setConfigString( "PostDisconnectCommand", m_device
->m_postdisconnectcmd
);
141 m_device
->setConfigBool( "Transcode", m_device
->m_transcode
);
142 m_device
->m_transcode
= m_transcodeCheck
->isChecked();
143 m_device
->setConfigBool( "Transcode", m_device
->m_transcode
);
144 m_device
->m_transcodeAlways
= m_transcodeAlways
->isChecked();
145 m_device
->setConfigBool( "TranscodeAlways", m_device
->m_transcodeAlways
);
146 m_device
->m_transcodeRemove
= m_transcodeRemove
->isChecked();
147 m_device
->setConfigBool( "TranscodeRemove", m_device
->m_transcodeRemove
);
148 m_device
->applyConfig();
151 MediaBrowser::instance()->updateButtons();
152 MediaBrowser::instance()->updateStats();
153 MediaBrowser::instance()->updateDevices();
155 KDialog::slotButtonClicked( button
);
158 #include "deviceconfiguredialog.moc"