File indexing completed on 2024-05-05 04:48:24
0001 /**************************************************************************************** 0002 * Copyright (c) 2005 Martin Aumueller <aumuell@reserv.at> * 0003 * Copyright (c) 2006 Jeff Mitchell <kde-dev@emailgoeshere.com> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) any later * 0008 * version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License along with * 0015 * this program. If not, see <http://www.gnu.org/licenses/>. * 0016 ****************************************************************************************/ 0017 0018 #include "deviceconfiguredialog.h" 0019 0020 #include "core/support/Amarok.h" 0021 #include "core/support/Debug.h" 0022 #include "HintLineEdit.h" 0023 #include "mediabrowser.h" 0024 #include "MediaDevice.h" 0025 #include "core/support/PluginManager.h" 0026 #include "scripting/scriptmanager/ScriptManager.h" 0027 0028 #include <KLocalizedString> 0029 #include <QVBoxLayout> 0030 0031 #include <QCheckBox> 0032 #include <QRadioButton> 0033 #include <QLabel> 0034 #include <q3buttongroup.h> 0035 #include <KConfigGroup> 0036 #include <QDialogButtonBox> 0037 #include <QPushButton> 0038 0039 0040 DeviceConfigureDialog::DeviceConfigureDialog( MediaDevice *device ) 0041 : QDialog( Amarok::mainWindow() ) 0042 , m_device( device ) 0043 { 0044 setWindowTitle( i18n("Select Plugin for %1", m_device->name() ) ); 0045 setModal( true ); 0046 0047 0048 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); 0049 QVBoxLayout *mainLayout = new QVBoxLayout; 0050 setLayout(mainLayout); 0051 0052 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0053 okButton->setDefault(true); 0054 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0055 connect(buttonBox, &QDialogButtonBox::accepted, this, SLOT(accept())); 0056 connect(buttonBox, &QDialogButtonBox::rejected, this, SLOT(reject())); 0057 // showButtonSeparator( true ); 0058 0059 0060 //kapp->setTopWidget( this ); 0061 setWindowTitle( i18n( "Configure Media Device" ) ); 0062 buttonBox->button(QDialogButtonBox::Apply)->setVisible(false); 0063 0064 QVBoxLayout* vbox = new QVBoxLayout( this ); 0065 mainLayout->addWidget(vbox); 0066 vbox->setSpacing( QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing) ); 0067 //TODO KF5:PM_DefaultLayoutSpacing is obsolete. Look in QStyle docs for correctly replacing it. 0068 0069 QLabel *connectLabel = 0; 0070 m_connectEdit = 0; 0071 QLabel *disconnectLabel = 0; 0072 m_disconnectEdit = 0; 0073 m_transcodeCheck = 0; 0074 Q3ButtonGroup *transcodeGroup = 0; 0075 m_transcodeAlways = 0; 0076 m_transcodeWhenNecessary = 0; 0077 m_transcodeRemove = 0; 0078 0079 if( device ) 0080 { 0081 device->loadConfig(); 0082 0083 // pre-connect/post-disconnect (mount/umount) 0084 connectLabel = new QLabel( vbox ); 0085 connectLabel->setText( i18n( "Pre-&connect command:" ) ); 0086 m_connectEdit = new HintLineEdit( device->m_preconnectcmd, vbox ); 0087 m_connectEdit->setHint( i18n( "Example: mount %d" ) ); 0088 connectLabel->setBuddy( m_connectEdit ); 0089 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." ) ); 0090 0091 disconnectLabel = new QLabel( vbox ); 0092 disconnectLabel->setText( i18n( "Post-&disconnect command:" ) ); 0093 m_disconnectEdit = new HintLineEdit( device->m_postdisconnectcmd, vbox ); 0094 disconnectLabel->setBuddy( m_disconnectEdit ); 0095 m_disconnectEdit->setHint( i18n( "Example: eject %d" ) ); 0096 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." ) ); 0097 0098 // transcode 0099 m_transcodeCheck = new QCheckBox( vbox ); 0100 m_transcodeCheck->setText( i18n( "&Transcode before transferring to device" ) ); 0101 m_transcodeCheck->setChecked( device->m_transcode ); 0102 0103 transcodeGroup = new Q3VButtonGroup( vbox ); 0104 QString format = "mp3"; 0105 if( !device->supportedFiletypes().isEmpty() ) 0106 format = device->supportedFiletypes().first(); 0107 transcodeGroup->setTitle( i18n( "Transcode to preferred format (%1) for device", format ) ); 0108 m_transcodeAlways = new QRadioButton( transcodeGroup ); 0109 m_transcodeAlways->setText( i18n( "Whenever possible" ) ); 0110 m_transcodeAlways->setChecked( device->m_transcodeAlways ); 0111 m_transcodeWhenNecessary = new QRadioButton( transcodeGroup ); 0112 m_transcodeWhenNecessary->setText( i18n( "When necessary" ) ); 0113 m_transcodeWhenNecessary->setChecked( !device->m_transcodeAlways ); 0114 connect( m_transcodeCheck, &QCheckBox::toggled, 0115 transcodeGroup, SLOT(setEnabled(bool)) ); 0116 transcodeGroup->insert( m_transcodeAlways ); 0117 transcodeGroup->insert( m_transcodeWhenNecessary ); 0118 m_transcodeRemove = new QCheckBox( transcodeGroup ); 0119 m_transcodeRemove->setText( i18n( "Remove transcoded files after transfer" ) ); 0120 m_transcodeRemove->setChecked( device->m_transcodeRemove ); 0121 0122 const ScriptManager *sm = ScriptManager::instance(); 0123 m_transcodeCheck->setEnabled( !sm->transcodeScriptRunning().isEmpty() ); 0124 transcodeGroup->setEnabled( !sm->transcodeScriptRunning().isEmpty() && device->m_transcode ); 0125 if( sm->transcodeScriptRunning().isNull() ) 0126 { 0127 m_transcodeCheck->setToolTip( i18n( "For this feature, a script of type \"Transcode\" has to be running" ) ); 0128 transcodeGroup->setToolTip( i18n( "For this feature, a script of type \"Transcode\" has to be running" ) ); 0129 } 0130 0131 device->addConfigElements( vbox ); 0132 } 0133 0134 m_accepted = false; 0135 } 0136 0137 DeviceConfigureDialog::~DeviceConfigureDialog() 0138 { 0139 delete m_connectEdit; 0140 delete m_disconnectEdit; 0141 }