2 #define TQT_NO_CAST_ASCII
13 #include "configuredialog_p.h"
16 #include "kmtransport.h"
17 #include "globalsettings.h"
18 #include "kmacctcachedimap.h"
23 #include <ksimpleconfig.h>
24 #include <kstandarddirs.h>
25 #include <tdelocale.h>
30 #include <tqtabwidget.h>
31 #include <tqradiobutton.h>
32 #include <tqbuttongroup.h>
40 NewIdentityDialog::NewIdentityDialog(
const TQStringList & identities,
41 TQWidget *parent,
const char *name,
43 : KDialogBase( parent, name, modal, i18n(
"New Identity"),
44 Ok|Cancel|Help,
Ok, true )
46 setHelp( TQString::fromLatin1(
"configure-identity-newidentitydialog") );
47 TQWidget * page = makeMainWidget();
48 TQVBoxLayout * vlay =
new TQVBoxLayout( page, 0, spacingHint() );
51 TQHBoxLayout * hlay =
new TQHBoxLayout( vlay );
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&)) );
59 mButtonGroup =
new TQButtonGroup( page );
63 TQRadioButton *radio =
new TQRadioButton( i18n(
"&With empty fields"), page );
64 radio->setChecked(
true );
65 mButtonGroup->insert( radio, Empty );
66 vlay->addWidget( radio );
69 radio =
new TQRadioButton( i18n(
"&Use Control Center settings"), page );
70 mButtonGroup->insert( radio, ControlCenter );
71 vlay->addWidget( radio );
74 radio =
new TQRadioButton( i18n(
"&Duplicate existing identity"), page );
75 mButtonGroup->insert( radio, ExistingEntry );
76 vlay->addWidget( radio );
79 hlay =
new TQHBoxLayout( vlay );
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 );
88 vlay->addStretch( 1 );
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)) );
97 enableButtonOK(
false );
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 );
108 void NewIdentityDialog::slotEnableOK(
const TQString & proposedIdentityName ) {
110 TQString name = proposedIdentityName.stripWhiteSpace();
112 if ( name.isEmpty() ) {
113 enableButtonOK(
false );
117 for (
int i = 0 ; i < mComboBox->count() ; i++ )
118 if ( mComboBox->text(i) == name ) {
119 enableButtonOK(
false );
122 enableButtonOK(
true );
125 ListView::ListView( TQWidget *parent,
const char *name,
127 : TDEListView( parent, name )
129 setVisibleItem(visibleItem);
133 void ListView::resizeEvent( TQResizeEvent *e )
135 TDEListView::resizeEvent(e);
140 void ListView::showEvent( TQShowEvent *e )
142 TDEListView::showEvent(e);
147 void ListView::resizeColums()
155 int w1 = viewport()->width();
157 int w3 = w1 - (c-1)*w2;
159 for(
int i=0; i<c-1; i++ )
161 setColumnWidth( i, w2 );
163 setColumnWidth( c-1, w3 );
167 void ListView::setVisibleItem(
int visibleItem,
bool updateSize )
169 mVisibleItem = TQMAX( 1, visibleItem );
170 if( updateSize ==
true )
172 TQSize s = sizeHint();
173 setMinimumSize( s.width() + verticalScrollBar()->sizeHint().width() +
174 lineWidth() * 2, s.height() );
179 TQSize ListView::sizeHint()
const
181 TQSize s = TQListView::sizeHint();
183 int h = fontMetrics().height() + 2*itemMargin();
184 if( h % 2 > 0 ) { h++; }
186 s.setHeight( h*mVisibleItem + lineWidth()*2 + header()->sizeHint().height());
191 static TQString flagPng = TQString::fromLatin1(
"/flag.png");
193 NewLanguageDialog::NewLanguageDialog( LanguageItemList & suppressedLangs,
194 TQWidget *parent,
const char *name,
196 : KDialogBase( parent, name, modal, i18n(
"New Language"),
Ok|Cancel,
Ok, true )
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 );
205 TQStringList pathList = TDEGlobal::dirs()->findAllResources(
"locale",
206 TQString::fromLatin1(
"*/entry.desktop") );
208 TQStringList suppressedAcronyms;
209 for ( LanguageItemList::Iterator lit = suppressedLangs.begin();
210 lit != suppressedLangs.end(); ++lit )
211 suppressedAcronyms << (*lit).mLanguage;
214 for ( TQStringList::ConstIterator it = pathList.begin();
215 it != pathList.end(); ++it )
217 KSimpleConfig entry( *it );
218 entry.setGroup(
"KCM Locale" );
220 TQString name = entry.readEntry(
"Name" );
223 TQString acronym = (*it).section(
'/', -2, -2 );
225 if ( suppressedAcronyms.find( acronym ) == suppressedAcronyms.end() ) {
227 TQString displayname = TQString::fromLatin1(
"%1 (%2)")
228 .arg( name ).arg( acronym );
229 TQPixmap flag( locate(
"locale", acronym + flagPng ) );
230 mComboBox->insertItem( flag, displayname );
233 if ( !mComboBox->count() ) {
234 mComboBox->insertItem( i18n(
"No More Languages Available") );
235 enableButtonOK(
false );
236 }
else mComboBox->listBox()->sort();
239 TQString NewLanguageDialog::language()
const
241 TQString s = mComboBox->currentText();
242 int i = s.findRev(
'(' );
243 return s.mid( i + 1, s.length() - i - 2 );
247 LanguageComboBox::LanguageComboBox(
bool rw, TQWidget *parent,
const char *name )
248 : TQComboBox( rw, parent, name )
252 int LanguageComboBox::insertLanguage(
const TQString & language )
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) );
263 TQString LanguageComboBox::language()
const
265 TQString s = currentText();
266 int i = s.findRev(
'(' );
267 return s.mid( i + 1, s.length() - i - 2 );
270 void LanguageComboBox::setLanguage(
const TQString & language )
272 TQString parenthizedLanguage = TQString::fromLatin1(
"(%1)").arg( language );
273 for (
int i = 0; i < count(); i++)
275 if ( text(i).find( parenthizedLanguage ) >= 0 ) {
287 ProfileDialog::ProfileDialog( TQWidget * parent,
const char * name,
bool modal )
288 : KDialogBase( parent, name, modal, i18n(
"Load Profile"),
Ok|Cancel,
Ok, true )
291 TQWidget * page = makeMainWidget();
292 TQVBoxLayout * vlay =
new TQVBoxLayout( page, 0, spacingHint() );
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 );
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 );
308 connect( mListView, TQ_SIGNAL(selectionChanged()),
309 TQ_SLOT(slotSelectionChanged()) );
310 connect( mListView, TQ_SIGNAL(doubleClicked ( TQListViewItem *,
const TQPoint &,
int ) ),
313 connect(
this, TQ_SIGNAL(finished()), TQ_SLOT(delayedDestruct()) );
315 enableButtonOK(
false );
318 void ProfileDialog::slotSelectionChanged()
320 enableButtonOK( mListView->selectedItem() );
323 void ProfileDialog::setup() {
326 const TQString profileFilenameFilter = TQString::fromLatin1(
"kmail/profile-*-rc");
327 mProfileList = TDEGlobal::dirs()->findAllResources(
"data", profileFilenameFilter );
329 kdDebug(5006) <<
"Profile manager: found " << mProfileList.count()
330 <<
" profiles:" << endl;
333 TQListViewItem * listItem = 0;
334 for ( TQStringList::const_iterator it = mProfileList.begin() ;
335 it != mProfileList.end() ; ++it ) {
336 TDEConfig profile( *it,
true ,
false );
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");
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");
350 listItem =
new TQListViewItem( mListView, listItem, name, desc );
354 void ProfileDialog::slotOk() {
355 const int index = mListView->itemIndex( mListView->selectedItem() );
359 assert( (
unsigned int)index < mProfileList.count() );
361 TDEConfig profile( *mProfileList.at(index),
true,
false );
362 emit profileSelected( &profile );
363 KDialogBase::slotOk();
367 ConfigModuleWithTabs::ConfigModuleWithTabs( TQWidget * parent,
369 : ConfigModule( parent, name )
371 TQVBoxLayout *vlay =
new TQVBoxLayout(
this, 0, KDialog::spacingHint() );
372 mTabWidget =
new TQTabWidget(
this );
373 vlay->addWidget( mTabWidget );
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 )) );
382 void ConfigModuleWithTabs::load() {
383 for (
int i = 0 ; i < mTabWidget->count() ; ++i ) {
384 ConfigModuleTab *tab =
dynamic_cast<ConfigModuleTab*
>( mTabWidget->page(i) );
391 void ConfigModuleWithTabs::save() {
393 for (
int i = 0 ; i < mTabWidget->count() ; ++i ) {
394 ConfigModuleTab *tab =
dynamic_cast<ConfigModuleTab*
>( mTabWidget->page(i) );
400 void ConfigModuleWithTabs::defaults() {
401 ConfigModuleTab *tab =
dynamic_cast<ConfigModuleTab*
>( mTabWidget->currentPage() );
404 TDECModule::defaults();
407 void ConfigModuleWithTabs::installProfile(TDEConfig * ) {
408 for (
int i = 0 ; i < mTabWidget->count() ; ++i ) {
409 ConfigModuleTab *tab =
dynamic_cast<ConfigModuleTab*
>( mTabWidget->page(i) );
411 tab->installProfile();
415 void ConfigModuleTab::load()
417 doLoadFromGlobalSettings();
421 void ConfigModuleTab::defaults()
425 const bool bUseDefaults = GlobalSettings::self()->useDefaults(
true );
426 doLoadFromGlobalSettings();
427 GlobalSettings::self()->useDefaults( bUseDefaults );
429 doResetToDefaultsOther();
432 void ConfigModuleTab::slotEmitChanged(
void ) {
433 emit changed(
true );
437 #include "configuredialog_p.moc"
@ Ok
The user rights/ACL have been fetched from the server sucessfully.