File indexing completed on 2024-05-05 04:48:27
0001 /**************************************************************************************** 0002 * Copyright (c) 2005 Jeff Mitchell <kde-dev@emailgoeshere.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "transferdialog.h" 0018 0019 #include "core/support/Amarok.h" 0020 #include "core/support/Debug.h" 0021 #include "mediabrowser.h" 0022 #include "MediaDevice.h" 0023 0024 #include <KComboBox> 0025 #include <KLocale> 0026 #include <KVBox> 0027 0028 #include <QCheckBox> 0029 #include <QGroupBox> 0030 #include <QLabel> 0031 #include <QLayout> 0032 #include <KConfigGroup> 0033 #include <QDialogButtonBox> 0034 #include <QPushButton> 0035 #include <QVBoxLayout> 0036 0037 0038 TransferDialog::TransferDialog( MediaDevice *mdev ) 0039 : QDialog( Amarok::mainWindow() ) 0040 { 0041 setModal( true ); 0042 0043 0044 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); 0045 QVBoxLayout *mainLayout = new QVBoxLayout; 0046 setLayout(mainLayout); 0047 0048 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0049 okButton->setDefault(true); 0050 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0051 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); 0052 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); 0053 // showButtonSeparator( true ); 0054 0055 0056 m_dev = mdev; 0057 m_accepted = false; 0058 m_sort1LastIndex = m_sort2LastIndex = -1; 0059 0060 //kapp->setTopWidget( this ); 0061 setWindowTitle( i18n( "Transfer Queue to Device" ) ); 0062 0063 KVBox *vbox = new KVBox( this ); 0064 mainLayout->addWidget(vbox); 0065 mainLayout->addWidget(buttonBox); 0066 0067 QString transferDir = mdev->getTransferDir(); 0068 0069 QGroupBox *location = new QGroupBox( i18n( "Music Location" ), vbox ); 0070 location->setAlignment( Qt::Vertical ); 0071 KVBox *locationLayout = new KVBox( location ); 0072 0073 new QLabel( i18n( "Your music will be transferred to:\n%1", 0074 transferDir ), 0075 locationLayout ); 0076 0077 KVBox *vbox2 = new KVBox( vbox ); 0078 QLayout *vlayout = vbox2->layout(); 0079 if( vlayout ) 0080 vlayout->addItem( new QSpacerItem( 0, 25 ) ); 0081 0082 new QLabel( i18n( "You can have your music automatically grouped in\n" 0083 "a variety of ways. Each grouping will create\n" 0084 "directories based upon the specified criteria.\n"), vbox ); 0085 0086 QGroupBox *sorting = new QGroupBox( i18n( "Groupings" ), vbox ); 0087 sorting->setAlignment( Qt::Vertical ); 0088 KVBox *sortingLayout = new KVBox( sorting ); 0089 m_label1 = new QLabel( i18n( "Select first grouping:\n" ), sortingLayout ); 0090 m_sort1 = new KComboBox( sortingLayout ); 0091 m_label2 = new QLabel( i18n( "Select second grouping:\n" ), sortingLayout ); 0092 m_sort2 = new KComboBox( sortingLayout ); 0093 m_label3 = new QLabel( i18n( "Select third grouping:\n" ), sortingLayout ); 0094 m_sort3 = new KComboBox( sortingLayout ); 0095 0096 m_combolist.append( m_sort1 ); 0097 m_combolist.append( m_sort2 ); 0098 m_combolist.append( m_sort3 ); 0099 0100 QListIterator<KComboBox *> it(m_combolist); 0101 while (it.hasNext()) { 0102 it.next()->addItem( i18n("None") ); 0103 it.next()->addItem( i18n("Artist") ); 0104 it.next()->addItem( i18n("Album") ); 0105 it.next()->addItem( i18n("Genre") ); 0106 it.next()->setCurrentItem( 0 ); 0107 } 0108 0109 m_sort1->setCurrentItem( mdev->m_firstSort ); 0110 m_sort2->setCurrentItem( mdev->m_secondSort ); 0111 m_sort3->setCurrentItem( mdev->m_thirdSort ); 0112 0113 m_label2->setDisabled( m_sort1->currentIndex() == 0 ); 0114 m_sort2->setDisabled( m_sort1->currentIndex() == 0 ); 0115 m_label3->setDisabled( m_sort2->currentIndex() == 0 ); 0116 m_sort3->setDisabled( m_sort2->currentIndex() == 0 ); 0117 0118 connect( m_sort1, SIGNAL(activated(int)), SLOT(sort1_activated(int)) ); 0119 connect( m_sort2, SIGNAL(activated(int)), SLOT(sort2_activated(int)) ); 0120 0121 KVBox *vbox3 = new KVBox( vbox ); 0122 QLayout *vlayout2 = vbox3->layout(); 0123 if( vlayout2 ) 0124 vlayout2->addItem( new QSpacerItem( 0, 25 ) ); 0125 0126 QGroupBox *options = new QGroupBox( i18n( "Options" ), vbox ); 0127 options->setAlignment( Qt::Vertical ); 0128 KVBox *optionsLayout = new KVBox( options ); 0129 0130 QCheckBox *convertSpaces = new QCheckBox( i18n( "Convert spaces to underscores" ), optionsLayout ); 0131 convertSpaces->setChecked( mdev->getSpacesToUnderscores() ); 0132 0133 connect( convertSpaces, SIGNAL(toggled(bool)), this, SLOT(convertSpaces_toggled(bool)) ); 0134 connect(okButton,SIGNAL(clicked()),this,SLOT(slotOk())); 0135 connect(buttonBox->button(QDialogButtonBox::Cancel),SIGNAL(clicked()),this,SLOT(slotCancel())); 0136 } 0137 0138 void 0139 TransferDialog::slotOk() 0140 { 0141 m_accepted = true; 0142 //QDialog::slotOk(); 0143 accept(); 0144 m_dev->setFirstSort( m_sort1->currentText() ); 0145 m_dev->setSecondSort( m_sort2->currentText() ); 0146 m_dev->setThirdSort( m_sort3->currentText() ); 0147 } 0148 0149 void 0150 TransferDialog::slotCancel() 0151 { 0152 m_accepted = false; 0153 //QDialog::slotCancel(); 0154 reject(); 0155 } 0156 0157 void 0158 TransferDialog::sort1_activated( int index ) 0159 { 0160 //sort3 0161 if( m_sort2LastIndex > 0 ) 0162 m_sort3->addItem( m_sort2->itemText( m_sort2LastIndex ), m_sort2LastIndex ); 0163 if( m_sort1LastIndex > 0 ) 0164 m_sort3->addItem( m_sort1->itemText( m_sort1LastIndex ), m_sort1LastIndex ); 0165 if( index > 0 ) 0166 m_sort3->removeItem( index ); 0167 m_sort3->setCurrentItem( 0 ); 0168 m_sort3->setDisabled( true ); 0169 //sort2 0170 if( m_sort1LastIndex > 0 ) 0171 m_sort2->addItem( m_sort1->itemText( m_sort1LastIndex ), m_sort1LastIndex ); 0172 if( index > 0 ) 0173 m_sort2->removeItem( index ); 0174 m_sort2->setCurrentItem( 0 ); 0175 if( index == 0 ) 0176 m_sort2->setDisabled( true ); 0177 else 0178 m_sort2->setDisabled( false ); 0179 0180 m_sort2LastIndex = 0; 0181 m_sort1LastIndex = index; 0182 } 0183 0184 void 0185 TransferDialog::sort2_activated( int index ) 0186 { 0187 //sort3 0188 if( m_sort2LastIndex > 0 ) 0189 m_sort3->addItem( m_sort2->itemText( m_sort2LastIndex ), m_sort2LastIndex ); 0190 if( index > 0 ) 0191 m_sort3->removeItem( index ); 0192 m_sort3->setCurrentItem( 0 ); 0193 if( index == 0 ) 0194 m_sort3->setDisabled( true ); 0195 else 0196 m_sort3->setDisabled( false ); 0197 0198 m_sort2LastIndex = index; 0199 } 0200 0201 void 0202 TransferDialog::convertSpaces_toggled( bool on ) 0203 { 0204 m_dev->setSpacesToUnderscores( on ); 0205 } 0206 0207