00001
00002
00003 #include <qcheckbox.h>
00004 #include <qgroupbox.h>
00005 #include <qhbox.h>
00006 #include <qlabel.h>
00007 #include <qabstractlayout.h>
00008 #include <qlayout.h>
00009 #include <qlineedit.h>
00010 #include <qpixmap.h>
00011 #include <qpushbutton.h>
00012 #include <qvbox.h>
00013 #include <qwhatsthis.h>
00014 #include <qcombobox.h>
00015
00016
00017 #include <qpe/config.h>
00018 #include <qpe/qpeapplication.h>
00019
00020 #include "mediumwidget.h"
00021
00022
00023
00024 using namespace MediumMountSetting;
00025
00026
00027
00028 MediumMountWidget::MediumMountWidget(const QString &path,
00029 const QPixmap &pix,
00030 QWidget *parent,
00031 const char *name )
00032 : QWidget( parent, name )
00033 {
00034 m_path = path;
00035 initGUI();
00036 m_label->setPixmap(pix );
00037 m_config = 0;
00038
00039 readConfig();
00040 }
00041
00042
00043 void MediumMountWidget::initGUI()
00044 {
00045
00046 m_box = new QVBoxLayout( this , 5, 5 );
00047
00048
00049
00050
00051 m_infoBox = new QHBox(this, "infobox" );
00052
00053 m_label = new QLabel(m_infoBox );
00054 m_desc = new QLabel(m_infoBox );
00055 m_desc->setTextFormat( Qt::RichText );
00056 QWhatsThis::add( this, tr("Configure this medium. The changes will"
00057 " go into effect when the application gets"
00058 " closed. To update the Document Tab you need"
00059 " to remove and insert this medium."));
00060 m_desc->setText("" );
00061 m_box->addWidget( m_infoBox );
00062
00063
00064
00065 m_group = new QGroupBox(tr("Which media files"), this, "MediaFiles" );
00066 m_checks = new QGridLayout( m_group, 4, 3 );
00067
00068
00069
00070
00071 QSpacerItem *item2 = new QSpacerItem(5, 8,
00072 QSizePolicy::Fixed,
00073 QSizePolicy::Fixed);
00074 m_box->addItem( item2 );
00075
00076 m_audio = new QCheckBox( tr("Audio"), m_group );
00077 m_all = new QCheckBox( tr("All") , m_group );
00078 m_image = new QCheckBox( tr("Image"), m_group );
00079 m_text = new QCheckBox( tr("Text") , m_group );
00080 m_video = new QCheckBox( tr("Video"), m_group );
00081
00082 QSpacerItem *iti1b = new QSpacerItem(2, 10, QSizePolicy::Fixed,
00083 QSizePolicy::Fixed );
00084 m_checks->addItem( iti1b, 0, 0 );
00085
00086 m_checks->addWidget(m_audio, 1, 0 );
00087 m_checks->addWidget(m_image, 2, 0 );
00088 m_checks->addWidget(m_all , 3, 0 );
00089
00090 m_checks->addWidget(m_text, 1, 2 );
00091 m_checks->addWidget(m_video, 2, 2 );
00092
00093 m_checks->addRowSpacing(0, 8 );
00094 m_checks->addColSpacing(1, 2 );
00095 m_checks->setColStretch(1, -2 );
00096
00097 connect(m_all, SIGNAL(stateChanged(int) ),
00098 this, SLOT(slotStateChanged() ) );
00099
00100 m_box->addWidget( m_group );
00101
00102
00103 m_lblPath = new QLabel(tr("Limit search to:"), this );
00104 m_box->addWidget( m_lblPath );
00105
00106
00107 m_subList = new QComboBox(FALSE,this,"docFolderList");
00108 m_subList->setDuplicatesEnabled(FALSE);
00109 m_subList->setEditable(TRUE);
00110 m_box->addWidget(m_subList);
00111
00112 m_hboxAdd = new QHBox( this );
00113 m_add = new QPushButton(m_hboxAdd );
00114 m_add->setText( tr("Add") );
00115 m_del = new QPushButton(m_hboxAdd);
00116 m_del->setText(tr("Remove"));
00117
00118 connect(m_add, SIGNAL(clicked() ),
00119 this, SLOT(slotAdd() ) );
00120 connect(m_del, SIGNAL(clicked() ),
00121 this, SLOT(slotRemove() ) );
00122
00123 m_box->addWidget(m_hboxAdd );
00124 m_scan_all_check = new QCheckBox( tr("Scan whole media"), this );
00125 connect(m_scan_all_check,SIGNAL(stateChanged(int)),this,SLOT(slotScanAllChanged(int)));
00126
00127 m_box->addWidget(m_scan_all_check);
00128
00129 m_always = new QCheckBox( tr("Always check this medium"), this );
00130
00131 m_box->addWidget( m_always );
00132
00133 QSpacerItem *item = new QSpacerItem(5, 50,
00134 QSizePolicy::Fixed,
00135 QSizePolicy::Expanding );
00136 m_box->addItem(item );
00137 }
00138
00139 void MediumMountWidget::readConfig( )
00140 {
00141 if( m_config == 0 )
00142 m_config = new Config(m_path + "/.opiestorage.cf", Config::File );
00143 m_config->setGroup( "main" );
00144
00145 m_always->setChecked( m_config->readBoolEntry("check", false) );
00146
00147 m_config->setGroup( "mimetypes" );
00148 if( m_config->readBoolEntry("all", false ) ){
00149 m_audio->setEnabled( false );
00150 m_image->setEnabled( false );
00151 m_text->setEnabled ( false );
00152 m_video->setEnabled( false );
00153 m_all->setChecked( true );
00154 }else{
00155 m_audio->setEnabled( true );
00156 m_image->setEnabled( true );
00157 m_text->setEnabled ( true );
00158 m_all->setEnabled ( true );
00159
00160 m_all->setChecked( false );
00161
00162 m_audio->setChecked( m_config->readBoolEntry("audio", true ) );
00163 m_image->setChecked( m_config->readBoolEntry("image", true ) );
00164 m_text->setChecked ( m_config->readBoolEntry("text" , true ) );
00165 m_video->setChecked( m_config->readBoolEntry("video", true ) );
00166 };
00167 m_config->setGroup("subdirs");
00168 QStringList entries = m_config->readListEntry("subdirs",':');
00169 m_subList->clear();
00170 m_subList->insertStringList(entries);
00171 m_scan_all_check->setChecked(m_config->readBoolEntry("wholemedia",true));
00172 }
00173
00174 void MediumMountWidget::writeConfig()
00175 {
00176 m_config->setGroup("main");
00177 m_config->writeEntry("check", m_always->isChecked() );
00178
00179 m_config->setGroup("mimetypes" );
00180 if(m_all->isChecked() ){
00181 m_config->writeEntry("all", true );
00182 }else{
00183 m_config->writeEntry("audio", m_audio->isChecked() );
00184 m_config->writeEntry("image", m_image->isChecked() );
00185 m_config->writeEntry("text" , m_text->isChecked() );
00186 m_config->writeEntry("video", m_video->isChecked() );
00187 }
00188 m_config->setGroup("subdirs");
00189 QStringList entries;
00190 QString ctext;
00191 for (int i = 0; i < m_subList->count();++i) {
00192 ctext = m_subList->text(i);
00193 if (ctext.isEmpty())
00194 continue;
00195 if (ctext.startsWith("/")) {
00196 ctext = ctext.right(ctext.length()-1);
00197 }
00198 if (!ctext.isEmpty()) {
00199 entries.append(ctext);
00200 }
00201 }
00202 m_config->writeEntry("subdirs",entries,':');
00203 m_config->writeEntry("wholemedia",m_scan_all_check->isChecked());
00204 }
00205
00206 MediumMountWidget::~MediumMountWidget()
00207 {
00208 delete m_config;
00209 }
00210
00211 void MediumMountWidget::slotAdd()
00212 {
00213 if (m_subList->currentText()==m_subList->text(m_subList->currentItem()))
00214 return;
00215 m_subList->insertItem(m_subList->currentText());
00216 }
00217
00218 void MediumMountWidget::slotRemove()
00219 {
00220 QString text = m_subList->currentText();
00221 if (text != m_subList->text(m_subList->currentItem())) {
00222 m_subList->clearEdit ();
00223 } else {
00224 m_subList->removeItem(m_subList->currentItem());
00225 }
00226 }
00227
00228 void MediumMountWidget::slotStateChanged()
00229 {
00230 bool state = !(m_all->isChecked());
00231
00232 m_audio->setEnabled( state );
00233 m_text->setEnabled ( state );
00234 m_video->setEnabled( state );
00235 m_image->setEnabled( state );
00236
00237 }
00238
00239 void MediumMountWidget::slotScanAllChanged(int)
00240 {
00241 bool state = !(m_scan_all_check->isChecked());
00242 m_add->setEnabled(state);
00243 m_del->setEnabled(state);
00244 m_subList->setEnabled(state);
00245 }