summaryrefslogtreecommitdiff
path: root/noncore/settings/mediummount/mediumglobal.cc
blob: 0c6cf12466cac64e4768c7ec199f07c86c437e12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

#include "mediumglobal.h"

/* OPIE */
#include <opie2/odebug.h>
using namespace Opie::Core;
#include <qpe/config.h>

/* QT */
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qlabel.h>
#include <qabstractlayout.h> // spacer item
#include <qlayout.h>
#include <qframe.h>
#include <qgroupbox.h>
#include <qwhatsthis.h>



using namespace MediumMountSetting;

/* TRANSLATOR MediumMountSetting::MediumGlobalWidget */

MediumGlobalWidget::MediumGlobalWidget(QWidget *wid, const char *name )
  : QWidget( wid, name, WStyle_ContextHelp )
{
  m_config = 0;
  initGUI();
  readConfig();

}
void MediumGlobalWidget::initGUI()
{
  m_layout = new QVBoxLayout(this );
   m_layout->setMargin( 4 );
  // m_layout->setSpacing( 10 );


  m_label = new QLabel( this );
  m_label->setTextFormat( Qt::RichText );
  m_label->setText( tr("") );
  QWhatsThis::add( this, tr("If a medium gets inserted into this device Opie "
           "tries to search the medium for Documents. On "
           "large mediums this can take some time. You can choose "
           "if Opie should scan for Documents globally or on a "
           "per medium level. You're also able to reconfigure "
           "each medium.") );

  m_layout->addWidget( m_label );

  m_check = new QCheckBox( tr("Enable medium checking" ), this );
  connect( m_check, SIGNAL(stateChanged(int) ),
     this, SLOT(slotEnableChecking() ) );
  m_layout->addWidget(m_check );

  m_frame = new QFrame(this, "Frame" );
  m_frame->setFrameShape( QFrame::Box );
  m_frame->setFrameShadow( QFrame::Sunken );

  m_box = new QVBoxLayout( m_frame );
  m_box->setMargin( 5 );
  m_useglobal = new QCheckBox( tr("Use global settings"), m_frame );
  connect( m_useglobal, SIGNAL( stateChanged(int) ),
     this, SLOT( slotGlobalChanged() ) );

  m_box->addWidget( m_useglobal );

  m_global = new QGroupBox( tr("Which media files"), m_frame );
  m_frameLay = new QGridLayout(m_global, 4, 3 );
   m_frameLay->setMargin( 10 );

  QSpacerItem *item2 = new QSpacerItem( 5, 8,
          QSizePolicy::Fixed,
          QSizePolicy::Fixed );
  m_audio = new QCheckBox( tr("Audio"), m_global );
  m_all   = new QCheckBox( tr("All")  , m_global );
  m_image = new QCheckBox( tr("Image"), m_global );
  m_text  = new QCheckBox( tr("Text") , m_global );
  m_video = new QCheckBox( tr("Video"), m_global );

  connect(m_all, SIGNAL(stateChanged(int) ),
    this, SLOT(slotAllChanged()  ) );

  m_frameLay->addItem( item2, 0, 0 );

  m_frameLay->addWidget( m_audio, 1, 0 );
  m_frameLay->addWidget( m_image, 2, 0 );
  m_frameLay->addWidget( m_all,   3, 0 );

  m_frameLay->addWidget( m_text,  1, 2 );
  m_frameLay->addWidget( m_video, 2, 2 );

  m_frameLay->addRowSpacing( 0, 8 );
  m_frameLay->addColSpacing( 1, 2 );

  m_box->addWidget( m_global );


  m_layout->addWidget( m_frame );

  QSpacerItem *item1 = new QSpacerItem( 1, 24,
          QSizePolicy::Fixed,
          QSizePolicy::Expanding );
  m_layout->addItem( item1 );
}
void MediumGlobalWidget::readConfig()
{
  if( m_config == 0 )
    m_config = new Config("medium" );

  m_config->setGroup("main");
  m_useglobal->setChecked( m_config->readBoolEntry("global", false ) );
  m_check->setChecked( m_config->readBoolEntry("use", true ) );

  m_config->setGroup("mimetypes" );
  m_all->setChecked  ( m_config->readBoolEntry("all", false ) );
  m_audio->setChecked( m_config->readBoolEntry("audio", true ) );
  m_video->setChecked( m_config->readBoolEntry("video", true ) );
  m_text->setChecked ( m_config->readBoolEntry("text", true ) );
  m_image->setChecked( m_config->readBoolEntry("image", true ) );

  slotAllChanged();
  slotEnableChecking();
  slotGlobalChanged();
  if( m_all->isChecked() ){
    m_video->setEnabled( false );
    m_text->setEnabled(  false );
    m_audio->setEnabled( false );
    m_image->setEnabled( false );

  }
}
void MediumGlobalWidget::writeConfig()
{
  m_config->setGroup( "main" );
  m_config->writeEntry("global", m_useglobal->isChecked() );
  m_config->writeEntry("use", m_check->isChecked() );

  m_config->setGroup("mimetypes" );

  m_config->writeEntry("all", m_all->isChecked() );
  m_config->writeEntry("audio", m_audio->isChecked() );
  m_config->writeEntry("video", m_video->isChecked() );
  m_config->writeEntry("text", m_text->isChecked() );
  m_config->writeEntry("image", m_image->isChecked() );
}
MediumGlobalWidget::~MediumGlobalWidget()
{
  delete m_config;
}
void MediumGlobalWidget::slotGlobalChanged()
{
  int mode = GLOBAL_DISABLED;
  bool enabled = false;
  if( ( enabled =m_useglobal->isChecked() ) ){
    mode = GLOBAL_ENABLED;
  }else
    mode = GLOBAL_DISABLED;
  owarn << "enabled = " << enabled << oendl;
  m_all->setEnabled  ( enabled );
  m_audio->setEnabled( enabled );
  m_image->setEnabled( enabled );
  m_text->setEnabled ( enabled );
  m_video->setEnabled ( enabled );
  slotAllChanged();

  emit globalStateChanged( mode );
}
void MediumGlobalWidget::slotEnableChecking()
{
  int mode = ENABLE_CHECKS;
  bool enabled = false;
  if( ( enabled = m_check->isChecked() ) ){
    mode = ENABLE_CHECKS;
  }else{
    mode = DISABLE_CHECKS;
  }
  m_frame->setEnabled( enabled );
  slotGlobalChanged();
  emit enableStateChanged( mode );
}
void MediumGlobalWidget::slotAllChanged()
{
  bool enable = !m_all->isChecked();
  m_audio->setEnabled( enable );
  m_text->setEnabled( enable );
  m_video->setEnabled( enable );
  m_image->setEnabled( enable );
}