00001
00002 #include "mediumglobal.h"
00003
00004
00005 #include <opie2/odebug.h>
00006 using namespace Opie::Core;
00007 #include <qpe/config.h>
00008
00009
00010 #include <qlineedit.h>
00011 #include <qcheckbox.h>
00012 #include <qlabel.h>
00013 #include <qabstractlayout.h>
00014 #include <qlayout.h>
00015 #include <qframe.h>
00016 #include <qgroupbox.h>
00017 #include <qwhatsthis.h>
00018
00019
00020
00021 using namespace MediumMountSetting;
00022
00023
00024
00025 MediumGlobalWidget::MediumGlobalWidget(QWidget *wid, const char *name )
00026 : QWidget( wid, name, WStyle_ContextHelp )
00027 {
00028 m_config = 0;
00029 initGUI();
00030 readConfig();
00031
00032 }
00033 void MediumGlobalWidget::initGUI()
00034 {
00035 m_layout = new QVBoxLayout(this );
00036 m_layout->setMargin( 4 );
00037
00038
00039
00040 m_label = new QLabel( this );
00041 m_label->setTextFormat( Qt::RichText );
00042 m_label->setText( "" );
00043 QWhatsThis::add( this, tr("If a medium gets inserted into this device Opie "
00044 "tries to search the medium for Documents. On "
00045 "large mediums this can take some time. You can choose "
00046 "if Opie should scan for Documents globally or on a "
00047 "per medium level. You're also able to reconfigure "
00048 "each medium.") );
00049
00050 m_layout->addWidget( m_label );
00051
00052 m_check = new QCheckBox( tr("Enable medium checking" ), this );
00053 connect( m_check, SIGNAL(stateChanged(int) ),
00054 this, SLOT(slotEnableChecking() ) );
00055 m_layout->addWidget(m_check );
00056
00057 m_frame = new QFrame(this, "Frame" );
00058 m_frame->setFrameShape( QFrame::Box );
00059 m_frame->setFrameShadow( QFrame::Sunken );
00060
00061 m_box = new QVBoxLayout( m_frame );
00062 m_box->setMargin( 5 );
00063 m_useglobal = new QCheckBox( tr("Use global settings"), m_frame );
00064 connect( m_useglobal, SIGNAL( stateChanged(int) ),
00065 this, SLOT( slotGlobalChanged() ) );
00066
00067 m_box->addWidget( m_useglobal );
00068
00069 m_global = new QGroupBox( tr("Which media files"), m_frame );
00070 m_frameLay = new QGridLayout(m_global, 4, 3 );
00071 m_frameLay->setMargin( 10 );
00072
00073 QSpacerItem *item2 = new QSpacerItem( 5, 8,
00074 QSizePolicy::Fixed,
00075 QSizePolicy::Fixed );
00076 m_audio = new QCheckBox( tr("Audio"), m_global );
00077 m_all = new QCheckBox( tr("All") , m_global );
00078 m_image = new QCheckBox( tr("Image"), m_global );
00079 m_text = new QCheckBox( tr("Text") , m_global );
00080 m_video = new QCheckBox( tr("Video"), m_global );
00081
00082 connect(m_all, SIGNAL(stateChanged(int) ),
00083 this, SLOT(slotAllChanged() ) );
00084
00085 m_frameLay->addItem( item2, 0, 0 );
00086
00087 m_frameLay->addWidget( m_audio, 1, 0 );
00088 m_frameLay->addWidget( m_image, 2, 0 );
00089 m_frameLay->addWidget( m_all, 3, 0 );
00090
00091 m_frameLay->addWidget( m_text, 1, 2 );
00092 m_frameLay->addWidget( m_video, 2, 2 );
00093
00094 m_frameLay->addRowSpacing( 0, 8 );
00095 m_frameLay->addColSpacing( 1, 2 );
00096
00097 m_box->addWidget( m_global );
00098
00099
00100 m_layout->addWidget( m_frame );
00101
00102 QSpacerItem *item1 = new QSpacerItem( 1, 24,
00103 QSizePolicy::Fixed,
00104 QSizePolicy::Expanding );
00105 m_layout->addItem( item1 );
00106 }
00107 void MediumGlobalWidget::readConfig()
00108 {
00109 if( m_config == 0 )
00110 m_config = new Config("medium" );
00111
00112 m_config->setGroup("main");
00113 m_useglobal->setChecked( m_config->readBoolEntry("global", false ) );
00114 m_check->setChecked( m_config->readBoolEntry("use", true ) );
00115
00116 m_config->setGroup("mimetypes" );
00117 m_all->setChecked ( m_config->readBoolEntry("all", false ) );
00118 m_audio->setChecked( m_config->readBoolEntry("audio", true ) );
00119 m_video->setChecked( m_config->readBoolEntry("video", true ) );
00120 m_text->setChecked ( m_config->readBoolEntry("text", true ) );
00121 m_image->setChecked( m_config->readBoolEntry("image", true ) );
00122
00123 slotAllChanged();
00124 slotEnableChecking();
00125 slotGlobalChanged();
00126 if( m_all->isChecked() ){
00127 m_video->setEnabled( false );
00128 m_text->setEnabled( false );
00129 m_audio->setEnabled( false );
00130 m_image->setEnabled( false );
00131
00132 }
00133 }
00134 void MediumGlobalWidget::writeConfig()
00135 {
00136 m_config->setGroup( "main" );
00137 m_config->writeEntry("global", m_useglobal->isChecked() );
00138 m_config->writeEntry("use", m_check->isChecked() );
00139
00140 m_config->setGroup("mimetypes" );
00141
00142 m_config->writeEntry("all", m_all->isChecked() );
00143 m_config->writeEntry("audio", m_audio->isChecked() );
00144 m_config->writeEntry("video", m_video->isChecked() );
00145 m_config->writeEntry("text", m_text->isChecked() );
00146 m_config->writeEntry("image", m_image->isChecked() );
00147 }
00148 MediumGlobalWidget::~MediumGlobalWidget()
00149 {
00150 delete m_config;
00151 }
00152 void MediumGlobalWidget::slotGlobalChanged()
00153 {
00154 int mode = GLOBAL_DISABLED;
00155 bool enabled = false;
00156 if( ( enabled =m_useglobal->isChecked() ) ){
00157 mode = GLOBAL_ENABLED;
00158 }else
00159 mode = GLOBAL_DISABLED;
00160 owarn << "enabled = " << enabled << oendl;
00161 m_all->setEnabled ( enabled );
00162 m_audio->setEnabled( enabled );
00163 m_image->setEnabled( enabled );
00164 m_text->setEnabled ( enabled );
00165 m_video->setEnabled ( enabled );
00166 slotAllChanged();
00167
00168 emit globalStateChanged( mode );
00169 }
00170 void MediumGlobalWidget::slotEnableChecking()
00171 {
00172 int mode = ENABLE_CHECKS;
00173 bool enabled = false;
00174 if( ( enabled = m_check->isChecked() ) ){
00175 mode = ENABLE_CHECKS;
00176 }else{
00177 mode = DISABLE_CHECKS;
00178 }
00179 m_frame->setEnabled( enabled );
00180 slotGlobalChanged();
00181 emit enableStateChanged( mode );
00182 }
00183 void MediumGlobalWidget::slotAllChanged()
00184 {
00185 bool enable = !m_all->isChecked();
00186 m_audio->setEnabled( enable );
00187 m_text->setEnabled( enable );
00188 m_video->setEnabled( enable );
00189 m_image->setEnabled( enable );
00190 }