kmail

configuredialog_p.cpp
1 #ifndef KDE_USE_FINAL
2 #define TQT_NO_CAST_ASCII
3 #endif
4 // configuredialog_p.cpp: classes internal to ConfigureDialog
5 // see configuredialog.cpp for details.
6 
7 // This must be first
8 #ifdef HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11 
12 // my header:
13 #include "configuredialog_p.h"
14 
15 // other KMail headers:
16 #include "kmtransport.h"
17 #include "globalsettings.h"
18 #include "kmacctcachedimap.h"
19 
20 // other tdenetwork headers: (none)
21 
22 // other KDE headers:
23 #include <ksimpleconfig.h>
24 #include <kstandarddirs.h>
25 #include <tdelocale.h>
26 #include <kdebug.h>
27 
28 // TQt headers:
29 #include <tqheader.h>
30 #include <tqtabwidget.h>
31 #include <tqradiobutton.h>
32 #include <tqbuttongroup.h>
33 #include <tqlabel.h>
34 #include <tqlayout.h>
35 
36 // Other headers:
37 #include <assert.h>
38 
39 
40 NewIdentityDialog::NewIdentityDialog( const TQStringList & identities,
41  TQWidget *parent, const char *name,
42  bool modal )
43  : KDialogBase( parent, name, modal, i18n("New Identity"),
44  Ok|Cancel|Help, Ok, true )
45 {
46  setHelp( TQString::fromLatin1("configure-identity-newidentitydialog") );
47  TQWidget * page = makeMainWidget();
48  TQVBoxLayout * vlay = new TQVBoxLayout( page, 0, spacingHint() );
49 
50  // row 0: line edit with label
51  TQHBoxLayout * hlay = new TQHBoxLayout( vlay ); // inherits spacing
52  mLineEdit = new KLineEdit( page );
53  mLineEdit->setFocus();
54  hlay->addWidget( new TQLabel( mLineEdit, i18n("&New identity:"), page ) );
55  hlay->addWidget( mLineEdit, 1 );
56  connect( mLineEdit, TQ_SIGNAL(textChanged(const TQString&)),
57  this, TQ_SLOT(slotEnableOK(const TQString&)) );
58 
59  mButtonGroup = new TQButtonGroup( page );
60  mButtonGroup->hide();
61 
62  // row 1: radio button
63  TQRadioButton *radio = new TQRadioButton( i18n("&With empty fields"), page );
64  radio->setChecked( true );
65  mButtonGroup->insert( radio, Empty );
66  vlay->addWidget( radio );
67 
68  // row 2: radio button
69  radio = new TQRadioButton( i18n("&Use Control Center settings"), page );
70  mButtonGroup->insert( radio, ControlCenter );
71  vlay->addWidget( radio );
72 
73  // row 3: radio button
74  radio = new TQRadioButton( i18n("&Duplicate existing identity"), page );
75  mButtonGroup->insert( radio, ExistingEntry );
76  vlay->addWidget( radio );
77 
78  // row 4: combobox with existing identities and label
79  hlay = new TQHBoxLayout( vlay ); // inherits spacing
80  mComboBox = new TQComboBox( false, page );
81  mComboBox->insertStringList( identities );
82  mComboBox->setEnabled( false );
83  TQLabel *label = new TQLabel( mComboBox, i18n("&Existing identities:"), page );
84  label->setEnabled( false );
85  hlay->addWidget( label );
86  hlay->addWidget( mComboBox, 1 );
87 
88  vlay->addStretch( 1 ); // spacer
89 
90  // enable/disable combobox and label depending on the third radio
91  // button's state:
92  connect( radio, TQ_SIGNAL(toggled(bool)),
93  label, TQ_SLOT(setEnabled(bool)) );
94  connect( radio, TQ_SIGNAL(toggled(bool)),
95  mComboBox, TQ_SLOT(setEnabled(bool)) );
96 
97  enableButtonOK( false ); // since line edit is empty
98 }
99 
100 NewIdentityDialog::DuplicateMode NewIdentityDialog::duplicateMode() const {
101  int id = mButtonGroup->id( mButtonGroup->selected() );
102  assert( id == (int)Empty
103  || id == (int)ControlCenter
104  || id == (int)ExistingEntry );
105  return static_cast<DuplicateMode>( id );
106 }
107 
108 void NewIdentityDialog::slotEnableOK( const TQString & proposedIdentityName ) {
109  // OK button is disabled if
110  TQString name = proposedIdentityName.stripWhiteSpace();
111  // name isn't empty
112  if ( name.isEmpty() ) {
113  enableButtonOK( false );
114  return;
115  }
116  // or name doesn't yet exist.
117  for ( int i = 0 ; i < mComboBox->count() ; i++ )
118  if ( mComboBox->text(i) == name ) {
119  enableButtonOK( false );
120  return;
121  }
122  enableButtonOK( true );
123 }
124 
125 ListView::ListView( TQWidget *parent, const char *name,
126  int visibleItem )
127  : TDEListView( parent, name )
128 {
129  setVisibleItem(visibleItem);
130 }
131 
132 
133 void ListView::resizeEvent( TQResizeEvent *e )
134 {
135  TDEListView::resizeEvent(e);
136  resizeColums();
137 }
138 
139 
140 void ListView::showEvent( TQShowEvent *e )
141 {
142  TDEListView::showEvent(e);
143  resizeColums();
144 }
145 
146 
147 void ListView::resizeColums()
148 {
149  int c = columns();
150  if( c == 0 )
151  {
152  return;
153  }
154 
155  int w1 = viewport()->width();
156  int w2 = w1 / c;
157  int w3 = w1 - (c-1)*w2;
158 
159  for( int i=0; i<c-1; i++ )
160  {
161  setColumnWidth( i, w2 );
162  }
163  setColumnWidth( c-1, w3 );
164 }
165 
166 
167 void ListView::setVisibleItem( int visibleItem, bool updateSize )
168 {
169  mVisibleItem = TQMAX( 1, visibleItem );
170  if( updateSize == true )
171  {
172  TQSize s = sizeHint();
173  setMinimumSize( s.width() + verticalScrollBar()->sizeHint().width() +
174  lineWidth() * 2, s.height() );
175  }
176 }
177 
178 
179 TQSize ListView::sizeHint() const
180 {
181  TQSize s = TQListView::sizeHint();
182 
183  int h = fontMetrics().height() + 2*itemMargin();
184  if( h % 2 > 0 ) { h++; }
185 
186  s.setHeight( h*mVisibleItem + lineWidth()*2 + header()->sizeHint().height());
187  return s;
188 }
189 
190 
191 static TQString flagPng = TQString::fromLatin1("/flag.png");
192 
193 NewLanguageDialog::NewLanguageDialog( LanguageItemList & suppressedLangs,
194  TQWidget *parent, const char *name,
195  bool modal )
196  : KDialogBase( parent, name, modal, i18n("New Language"), Ok|Cancel, Ok, true )
197 {
198  // layout the page (a combobox with label):
199  TQWidget *page = makeMainWidget();
200  TQHBoxLayout *hlay = new TQHBoxLayout( page, 0, spacingHint() );
201  mComboBox = new TQComboBox( false, page );
202  hlay->addWidget( new TQLabel( mComboBox, i18n("Choose &language:"), page ) );
203  hlay->addWidget( mComboBox, 1 );
204 
205  TQStringList pathList = TDEGlobal::dirs()->findAllResources( "locale",
206  TQString::fromLatin1("*/entry.desktop") );
207  // extract a list of language tags that should not be included:
208  TQStringList suppressedAcronyms;
209  for ( LanguageItemList::Iterator lit = suppressedLangs.begin();
210  lit != suppressedLangs.end(); ++lit )
211  suppressedAcronyms << (*lit).mLanguage;
212 
213  // populate the combo box:
214  for ( TQStringList::ConstIterator it = pathList.begin();
215  it != pathList.end(); ++it )
216  {
217  KSimpleConfig entry( *it );
218  entry.setGroup( "KCM Locale" );
219  // full name:
220  TQString name = entry.readEntry( "Name" );
221  // {2,3}-letter abbreviation:
222  // we extract it from the path: "/prefix/de/entry.desktop" -> "de"
223  TQString acronym = (*it).section( '/', -2, -2 );
224 
225  if ( suppressedAcronyms.find( acronym ) == suppressedAcronyms.end() ) {
226  // not found:
227  TQString displayname = TQString::fromLatin1("%1 (%2)")
228  .arg( name ).arg( acronym );
229  TQPixmap flag( locate("locale", acronym + flagPng ) );
230  mComboBox->insertItem( flag, displayname );
231  }
232  }
233  if ( !mComboBox->count() ) {
234  mComboBox->insertItem( i18n("No More Languages Available") );
235  enableButtonOK( false );
236  } else mComboBox->listBox()->sort();
237 }
238 
239 TQString NewLanguageDialog::language() const
240 {
241  TQString s = mComboBox->currentText();
242  int i = s.findRev( '(' );
243  return s.mid( i + 1, s.length() - i - 2 );
244 }
245 
246 
247 LanguageComboBox::LanguageComboBox( bool rw, TQWidget *parent, const char *name )
248  : TQComboBox( rw, parent, name )
249 {
250 }
251 
252 int LanguageComboBox::insertLanguage( const TQString & language )
253 {
254  static TQString entryDesktop = TQString::fromLatin1("/entry.desktop");
255  KSimpleConfig entry( locate("locale", language + entryDesktop) );
256  entry.setGroup( "KCM Locale" );
257  TQString name = entry.readEntry( "Name" );
258  TQString output = TQString::fromLatin1("%1 (%2)").arg( name ).arg( language );
259  insertItem( TQPixmap( locate("locale", language + flagPng ) ), output );
260  return listBox()->index( listBox()->findItem(output) );
261 }
262 
263 TQString LanguageComboBox::language() const
264 {
265  TQString s = currentText();
266  int i = s.findRev( '(' );
267  return s.mid( i + 1, s.length() - i - 2 );
268 }
269 
270 void LanguageComboBox::setLanguage( const TQString & language )
271 {
272  TQString parenthizedLanguage = TQString::fromLatin1("(%1)").arg( language );
273  for (int i = 0; i < count(); i++)
274  // ### FIXME: use .endWith():
275  if ( text(i).find( parenthizedLanguage ) >= 0 ) {
276  setCurrentItem(i);
277  return;
278  }
279 }
280 
281 //
282 //
283 // ProfileDialog
284 //
285 //
286 
287 ProfileDialog::ProfileDialog( TQWidget * parent, const char * name, bool modal )
288  : KDialogBase( parent, name, modal, i18n("Load Profile"), Ok|Cancel, Ok, true )
289 {
290  // tmp. vars:
291  TQWidget * page = makeMainWidget();
292  TQVBoxLayout * vlay = new TQVBoxLayout( page, 0, spacingHint() );
293 
294  mListView = new TDEListView( page, "mListView" );
295  mListView->addColumn( i18n("Available Profiles") );
296  mListView->addColumn( i18n("Description") );
297  mListView->setFullWidth( true );
298  mListView->setAllColumnsShowFocus( true );
299  mListView->setSorting( -1 );
300 
301  vlay->addWidget( new TQLabel( mListView,
302  i18n("&Select a profile and click 'OK' to "
303  "load its settings:"), page ) );
304  vlay->addWidget( mListView, 1 );
305 
306  setup();
307 
308  connect( mListView, TQ_SIGNAL(selectionChanged()),
309  TQ_SLOT(slotSelectionChanged()) );
310  connect( mListView, TQ_SIGNAL(doubleClicked ( TQListViewItem *, const TQPoint &, int ) ),
311  TQ_SLOT(slotOk()) );
312 
313  connect( this, TQ_SIGNAL(finished()), TQ_SLOT(delayedDestruct()) );
314 
315  enableButtonOK( false );
316 }
317 
318 void ProfileDialog::slotSelectionChanged()
319 {
320  enableButtonOK( mListView->selectedItem() );
321 }
322 
323 void ProfileDialog::setup() {
324  mListView->clear();
325  // find all profiles (config files named "profile-xyz-rc"):
326  const TQString profileFilenameFilter = TQString::fromLatin1("kmail/profile-*-rc");
327  mProfileList = TDEGlobal::dirs()->findAllResources( "data", profileFilenameFilter );
328 
329  kdDebug(5006) << "Profile manager: found " << mProfileList.count()
330  << " profiles:" << endl;
331 
332  // build the list and populate the list view:
333  TQListViewItem * listItem = 0;
334  for ( TQStringList::const_iterator it = mProfileList.begin() ;
335  it != mProfileList.end() ; ++it ) {
336  TDEConfig profile( *it, true /* read-only */, false /* no KDE global */ );
337  profile.setGroup("KMail Profile");
338  TQString name = profile.readEntry( "Name" );
339  if ( name.isEmpty() ) {
340  kdWarning(5006) << "File \"" << (*it)
341  << "\" doesn't provide a profile name!" << endl;
342  name = i18n("Missing profile name placeholder","Unnamed");
343  }
344  TQString desc = profile.readEntry( "Comment" );
345  if ( desc.isEmpty() ) {
346  kdWarning(5006) << "File \"" << (*it)
347  << "\" doesn't provide a description!" << endl;
348  desc = i18n("Missing profile description placeholder","Not available");
349  }
350  listItem = new TQListViewItem( mListView, listItem, name, desc );
351  }
352 }
353 
354 void ProfileDialog::slotOk() {
355  const int index = mListView->itemIndex( mListView->selectedItem() );
356  if ( index < 0 )
357  return; // none selected
358 
359  assert( (unsigned int)index < mProfileList.count() );
360 
361  TDEConfig profile( *mProfileList.at(index), true, false );
362  emit profileSelected( &profile );
363  KDialogBase::slotOk();
364 }
365 
366 
367 ConfigModuleWithTabs::ConfigModuleWithTabs( TQWidget * parent,
368  const char * name )
369  : ConfigModule( parent, name )
370 {
371  TQVBoxLayout *vlay = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
372  mTabWidget = new TQTabWidget( this );
373  vlay->addWidget( mTabWidget );
374 }
375 
376 void ConfigModuleWithTabs::addTab( ConfigModuleTab* tab, const TQString & title ) {
377  mTabWidget->addTab( tab, title );
378  connect( tab, TQ_SIGNAL(changed( bool )),
379  this, TQ_SIGNAL(changed( bool )) );
380 }
381 
382 void ConfigModuleWithTabs::load() {
383  for ( int i = 0 ; i < mTabWidget->count() ; ++i ) {
384  ConfigModuleTab *tab = dynamic_cast<ConfigModuleTab*>( mTabWidget->page(i) );
385  if ( tab )
386  tab->load();
387  }
388  TDECModule::load();
389 }
390 
391 void ConfigModuleWithTabs::save() {
392  TDECModule::save();
393  for ( int i = 0 ; i < mTabWidget->count() ; ++i ) {
394  ConfigModuleTab *tab = dynamic_cast<ConfigModuleTab*>( mTabWidget->page(i) );
395  if ( tab )
396  tab->save();
397  }
398 }
399 
400 void ConfigModuleWithTabs::defaults() {
401  ConfigModuleTab *tab = dynamic_cast<ConfigModuleTab*>( mTabWidget->currentPage() );
402  if ( tab )
403  tab->defaults();
404  TDECModule::defaults();
405 }
406 
407 void ConfigModuleWithTabs::installProfile(TDEConfig * /* profile */ ) {
408  for ( int i = 0 ; i < mTabWidget->count() ; ++i ) {
409  ConfigModuleTab *tab = dynamic_cast<ConfigModuleTab*>( mTabWidget->page(i) );
410  if ( tab )
411  tab->installProfile();
412  }
413 }
414 
415 void ConfigModuleTab::load()
416 {
417  doLoadFromGlobalSettings();
418  doLoadOther();
419 }
420 
421 void ConfigModuleTab::defaults()
422 {
423  // reset settings which are available via GlobalSettings to their defaults
424  // (stolen from TDEConfigDialogManager::updateWidgetsDefault())
425  const bool bUseDefaults = GlobalSettings::self()->useDefaults( true );
426  doLoadFromGlobalSettings();
427  GlobalSettings::self()->useDefaults( bUseDefaults );
428  // reset other settings to default values
429  doResetToDefaultsOther();
430 }
431 
432 void ConfigModuleTab::slotEmitChanged( void ) {
433  emit changed( true );
434 }
435 
436 
437 #include "configuredialog_p.moc"
@ Ok
The user rights/ACL have been fetched from the server sucessfully.
Definition: acljobs.h:66