diff --git a/akonadi/collectionrequester.cpp b/akonadi/collectionrequester.cpp index afff840e5..7e126f832 100644 --- a/akonadi/collectionrequester.cpp +++ b/akonadi/collectionrequester.cpp @@ -1,151 +1,151 @@ /* Copyright 2008 Ingo Klöcker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "collectionrequester.h" #include "collectiondialog.h" #include #include #include #include #include #include #include using namespace Akonadi; class CollectionRequester::Private { public: Private( CollectionRequester *parent ) : q( parent ), edit( 0 ), button( 0 ), collectionDialog( 0 ) { } ~Private() { } void init(); // slots void _k_slotOpenDialog(); CollectionRequester *q; Collection collection; KLineEdit *edit; KPushButton *button; CollectionDialog *collectionDialog; }; void CollectionRequester::Private::init() { q->setMargin( 0 ); edit = new KLineEdit( q ); edit->setReadOnly( true ); edit->setClearButtonShown( false ); button = new KPushButton( q ); button->setIcon( KIcon( QLatin1String( "document-open" ) ) ); const int buttonSize = edit->sizeHint().height(); button->setFixedSize( buttonSize, buttonSize ); button->setToolTip( i18n( "Open collection dialog" ) ); - q->setSpacing( KDialog::spacingHint() ); + q->setSpacing( -1 ); edit->installEventFilter( q ); q->setFocusProxy( edit ); q->setFocusPolicy( Qt::StrongFocus ); q->connect( button, SIGNAL( clicked() ), q, SLOT( _k_slotOpenDialog() ) ); QAction *openAction = new QAction( q ); openAction->setShortcut( KStandardShortcut::Open ); q->connect( openAction, SIGNAL( triggered( bool ) ), q, SLOT( _k_slotOpenDialog() ) ); collectionDialog = new CollectionDialog( q ); collectionDialog->setSelectionMode( QAbstractItemView::SingleSelection ); } void CollectionRequester::Private::_k_slotOpenDialog() { CollectionDialog *dlg = collectionDialog; if ( dlg->exec() != QDialog::Accepted ) return; q->setCollection( dlg->selectedCollection() ); } CollectionRequester::CollectionRequester( QWidget *parent ) : KHBox( parent ), d( new Private( this ) ) { d->init(); } CollectionRequester::CollectionRequester( const Akonadi::Collection &collection, QWidget *parent ) : KHBox( parent ), d( new Private( this ) ) { d->init(); setCollection( collection ); } CollectionRequester::~CollectionRequester() { delete d; } Collection CollectionRequester::collection() const { return d->collection; } void CollectionRequester::setCollection( const Collection& collection ) { d->collection = collection; d->edit->setText( collection.isValid() ? collection.name() : i18n( "no collection" ) ); } void CollectionRequester::setMimeTypeFilter( const QStringList &mimeTypes ) { if ( d->collectionDialog ) d->collectionDialog->setMimeTypeFilter( mimeTypes ); } QStringList CollectionRequester::mimeTypeFilter() const { if ( d->collectionDialog ) return d->collectionDialog->mimeTypeFilter(); else return QStringList(); } #include "collectionrequester.moc" diff --git a/kabc/addresseedialog.cpp b/kabc/addresseedialog.cpp index 3e6a5310c..01020412d 100644 --- a/kabc/addresseedialog.cpp +++ b/kabc/addresseedialog.cpp @@ -1,338 +1,337 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "addresseedialog.h" #include "stdaddressbook.h" #include #include #include #include #include #include using namespace KABC; class AddresseeItem::Private { public: Addressee mAddressee; }; AddresseeItem::AddresseeItem( QTreeWidget *parent, const Addressee &addressee ) : QTreeWidgetItem( parent ), d( new Private ) { d->mAddressee = addressee; setText( Name, addressee.realName() ); setText( Email, addressee.preferredEmail() ); } AddresseeItem::~AddresseeItem() { delete d; } Addressee AddresseeItem::addressee() const { return d->mAddressee; } QString AddresseeItem::key( int column, bool ) const { if ( column == Email ) { QString value = text( Email ); QRegExp emailRe( QLatin1String( "<\\S*>" ) ); int match = emailRe.indexIn( value ); if ( match > -1 ) { value = value.mid( match + 1, emailRe.matchedLength() - 2 ); } return value.toLower(); } return text( column ).toLower(); } class AddresseeDialog::Private { public: Private( bool multiple ) : mMultiple( multiple ) { } void addressBookChanged(); void selectItem( const QString & ); void updateEdit(); void addSelected( QTreeWidgetItem *item ); void removeSelected(); void loadAddressBook(); void addCompletionItem( const QString &str, QTreeWidgetItem *item ); bool mMultiple; QTreeWidget *mAddresseeList; KLineEdit *mAddresseeEdit; QTreeWidget *mSelectedList; AddressBook *mAddressBook; QHash mItemDict; QHash mSelectedDict; }; AddresseeDialog::AddresseeDialog( QWidget *parent, bool multiple ) : KDialog( parent ), d( new Private( multiple ) ) { setCaption( i18nc( "@title:window", "Select Addressee" ) ); setButtons( Ok | Cancel ); setDefaultButton( Ok ); QWidget *topWidget = new QWidget( this ); setMainWidget( topWidget ); QBoxLayout *topLayout = new QHBoxLayout( topWidget ); QBoxLayout *listLayout = new QVBoxLayout; topLayout->addLayout( listLayout ); d->mAddresseeList = new QTreeWidget( topWidget ); d->mAddresseeList->setColumnCount( 2 ); QStringList headerTitles; headerTitles << i18nc( "@title:column addressee name", "Name" ) << i18nc( "@title:column addressee email", "Email" ); d->mAddresseeList->setHeaderItem( new QTreeWidgetItem( headerTitles ) ); listLayout->addWidget( d->mAddresseeList ); connect( d->mAddresseeList, SIGNAL( itemDoubleClicked( QTreeWidgetItem *, int ) ), SLOT( accept() ) ); connect( d->mAddresseeList, SIGNAL( itemSelectionChanged() ), SLOT( updateEdit() ) ); d->mAddresseeEdit = new KLineEdit( topWidget ); d->mAddresseeEdit->setCompletionMode( KGlobalSettings::CompletionAuto ); connect( d->mAddresseeEdit->completionObject(), SIGNAL( match( const QString & ) ), SLOT( selectItem( const QString & ) ) ); d->mAddresseeEdit->setFocus(); d->mAddresseeEdit->completionObject()->setIgnoreCase( true ); listLayout->addWidget( d->mAddresseeEdit ); setInitialSize( QSize( 450, 300 ) ); if ( d->mMultiple ) { QBoxLayout *selectedLayout = new QVBoxLayout; topLayout->addLayout( selectedLayout ); - topLayout->setSpacing( spacingHint() ); QGroupBox *selectedGroup = new QGroupBox( i18nc( "@title:group selected addressees", "Selected" ), topWidget ); QHBoxLayout *groupLayout = new QHBoxLayout; selectedGroup->setLayout( groupLayout ); selectedLayout->addWidget( selectedGroup ); d->mSelectedList = new QTreeWidget( selectedGroup ); groupLayout->addWidget( d->mSelectedList ); d->mSelectedList->setColumnCount( 2 ); QStringList headerTitles; headerTitles << i18nc( "@title:column addressee name", "Name" ) << i18nc( "@title:column addressee email", "Email" ); d->mSelectedList->setHeaderItem( new QTreeWidgetItem( headerTitles ) ); connect( d->mSelectedList, SIGNAL( itemDoubleClicked( QTreeWidgetItem *, int ) ), SLOT( removeSelected() ) ); QPushButton *unselectButton = new QPushButton( i18nc( "@action:button unselect addressee", "Unselect" ), selectedGroup ); selectedLayout->addWidget( unselectButton ); connect( unselectButton, SIGNAL( clicked() ), SLOT( removeSelected() ) ); connect( d->mAddresseeList, SIGNAL( itemClicked( QTreeWidgetItem *, int ) ), SLOT( addSelected( QTreeWidgetItem * ) ) ); setInitialSize( QSize( 650, 350 ) ); } d->mAddressBook = StdAddressBook::self( true ); connect( d->mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ), SLOT( addressBookChanged() ) ); connect( d->mAddressBook, SIGNAL( loadingFinished( Resource* ) ), SLOT( addressBookChanged() ) ); d->loadAddressBook(); } AddresseeDialog::~AddresseeDialog() { delete d; } Addressee AddresseeDialog::addressee() const { AddresseeItem *aItem = 0; if ( d->mMultiple ) { aItem = dynamic_cast( d->mSelectedList->topLevelItem( 0 ) ); } else { QList selected = d->mAddresseeList->selectedItems(); if ( selected.count() != 0 ) { aItem = dynamic_cast( selected.at( 0 ) ); } } if ( aItem ) { return aItem->addressee(); } return Addressee(); } Addressee::List AddresseeDialog::addressees() const { Addressee::List al; AddresseeItem *aItem = 0; if ( d->mMultiple ) { for ( int i = 0; i < d->mSelectedList->topLevelItemCount(); ++i ) { aItem = dynamic_cast( d->mSelectedList->topLevelItem( i ) ); if ( aItem ) { al.append( aItem->addressee() ); } } } else { QList selected = d->mAddresseeList->selectedItems(); if ( selected.count() != 0 ) { aItem = dynamic_cast( selected.at( 0 ) ); } if ( aItem ) { al.append( aItem->addressee() ); } } return al; } Addressee AddresseeDialog::getAddressee( QWidget *parent ) { AddresseeDialog dlg( parent ); if ( dlg.exec() ) { return dlg.addressee(); } return Addressee(); } Addressee::List AddresseeDialog::getAddressees( QWidget *parent ) { AddresseeDialog dlg( parent, true ); if ( dlg.exec() ) { return dlg.addressees(); } return Addressee::List(); } void AddresseeDialog::Private::loadAddressBook() { mAddresseeList->clear(); mItemDict.clear(); mAddresseeEdit->completionObject()->clear(); AddressBook::Iterator it; for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { AddresseeItem *item = new AddresseeItem( mAddresseeList, (*it) ); addCompletionItem( (*it).realName(), item ); addCompletionItem( (*it).preferredEmail(), item ); } } void AddresseeDialog::Private::addCompletionItem( const QString &str, QTreeWidgetItem *item ) { if ( str.isEmpty() ) { return; } mItemDict.insert( str, item ); mAddresseeEdit->completionObject()->addItem( str ); } void AddresseeDialog::Private::selectItem( const QString &str ) { if ( str.isEmpty() ) { return; } QTreeWidgetItem *item = mItemDict.value( str, 0 ); if ( item ) { mAddresseeList->blockSignals( true ); mAddresseeList->setItemSelected( item, true ); mAddresseeList->scrollToItem( item ); mAddresseeList->blockSignals( false ); } } void AddresseeDialog::Private::updateEdit() { QList selected = mAddresseeList->selectedItems(); if ( selected.count() == 0 ) { return; } QTreeWidgetItem *item = selected.at( 0 ); mAddresseeEdit->setText( item->text( 0 ) ); mAddresseeEdit->setSelection( 0, item->text( 0 ).length() ); } void AddresseeDialog::Private::addSelected( QTreeWidgetItem *item ) { AddresseeItem *addrItem = dynamic_cast( item ); if ( !addrItem ) { return; } Addressee a = addrItem->addressee(); QTreeWidgetItem *selectedItem = mSelectedDict.value( a.uid(), 0 ); if ( !selectedItem ) { selectedItem = new AddresseeItem( mSelectedList, a ); mSelectedDict.insert( a.uid(), selectedItem ); } } void AddresseeDialog::Private::removeSelected() { QList selected = mSelectedList->selectedItems(); if ( selected.count() == 0 ) { return; } AddresseeItem *addrItem = dynamic_cast( selected.at( 0 ) ); if ( !addrItem ) { return; } mSelectedDict.remove( addrItem->addressee().uid() ); delete addrItem; } void AddresseeDialog::Private::addressBookChanged() { loadAddressBook(); } #include "addresseedialog.moc" diff --git a/kabc/distributionlistdialog.cpp b/kabc/distributionlistdialog.cpp index 816c575d9..dace97959 100644 --- a/kabc/distributionlistdialog.cpp +++ b/kabc/distributionlistdialog.cpp @@ -1,482 +1,481 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "distributionlistdialog.h" #include "distributionlist.h" #include "addressbook.h" #include "addresseedialog.h" #include #include #include #include #include #include #include #include #include #include #include #include using namespace KABC; DistributionListDialog::DistributionListDialog( AddressBook *addressBook, QWidget *parent ) : KDialog( parent ), d( 0 ) { setModal( true ); setCaption( i18n( "Configure Distribution Lists" ) ); setButtons( Ok ); setDefaultButton( Ok ); showButtonSeparator( true ); DistributionListEditorWidget *editor = new DistributionListEditorWidget( addressBook, this ); setMainWidget( editor ); connect( this, SIGNAL( okClicked() ), editor, SLOT( save() ) ); } DistributionListDialog::~DistributionListDialog() { } class EmailSelector::Private { public: QButtonGroup *mButtonGroup; QMap mEmailMap; }; EmailSelector::EmailSelector( const QStringList &emails, const QString ¤t, QWidget *parent ) : KDialog( parent ), d( new Private ) { setCaption( i18n( "Select Email Address" ) ); setButtons( Ok ); setDefaultButton( Ok ); QFrame *topFrame = new QFrame( this ); setMainWidget( topFrame ); QBoxLayout *topLayout = new QVBoxLayout( topFrame ); QGroupBox *box = new QGroupBox( i18n( "Email Addresses" ) ); d->mButtonGroup = new QButtonGroup( box ); topLayout->addWidget( box ); QVBoxLayout *layout = new QVBoxLayout; QStringList::ConstIterator it; for ( it = emails.begin(); it != emails.end(); ++it ) { QRadioButton *button = new QRadioButton( *it, box ); d->mButtonGroup->addButton( button ); d->mEmailMap.insert( button, *it ); layout->addWidget( button ); if ( (*it) == current ) { button->setChecked( true ); } } layout->addStretch( 1 ); box->setLayout( layout ); } EmailSelector::~EmailSelector() { delete d; } QString EmailSelector::selected() const { QAbstractButton *button = d->mButtonGroup->checkedButton(); if ( !button ) { return QString(); } return d->mEmailMap[button]; } QString EmailSelector::getEmail( const QStringList &emails, const QString ¤t, QWidget *parent ) { EmailSelector dlg( emails, current, parent ); dlg.exec(); return dlg.selected(); } class EntryItem : public QTreeWidgetItem { public: EntryItem( QTreeWidget *parent, const Addressee &addressee, const QString &email=QString() ) : QTreeWidgetItem( parent ), mAddressee( addressee ), mEmail( email ) { setText( 0, addressee.realName() ); if ( email.isEmpty() ) { setText( 1, addressee.preferredEmail() ); setText( 2, i18nc( "this the preferred email address", "Yes" ) ); } else { setText( 1, email ); setText( 2, i18nc( "this is not the preferred email address", "No" ) ); } } Addressee addressee() const { return mAddressee; } QString email() const { return mEmail; } private: Addressee mAddressee; QString mEmail; }; class DistributionListEditorWidget::Private { public: Private( AddressBook *addressBook, DistributionListEditorWidget *parent ) : mParent( parent ), mAddressBook( addressBook ) { } ~Private() { } void newList(); void editList(); void removeList(); void addEntry(); void removeEntry(); void changeEmail(); void updateEntryView(); void updateAddresseeView(); void updateNameCombo(); void slotSelectionEntryViewChanged(); void slotSelectionAddresseeViewChanged(); void save(); DistributionListEditorWidget *mParent; KComboBox *mNameCombo; QLabel *mListLabel; QTreeWidget *mEntryView; QTreeWidget *mAddresseeView; AddressBook *mAddressBook; QPushButton *mNewButton, *mEditButton, *mRemoveButton; QPushButton *mChangeEmailButton, *mRemoveEntryButton, *mAddEntryButton; }; DistributionListEditorWidget::DistributionListEditorWidget( AddressBook *addressBook, QWidget *parent ) : QWidget( parent ), d( new Private( addressBook, this ) ) { kDebug(); QBoxLayout *topLayout = new QVBoxLayout( this ); - topLayout->setSpacing( KDialog::spacingHint() ); QBoxLayout *nameLayout = new QHBoxLayout(); topLayout->addLayout( topLayout ); d->mNameCombo = new KComboBox( this ); nameLayout->addWidget( d->mNameCombo ); connect( d->mNameCombo, SIGNAL( activated( int ) ), SLOT( updateEntryView() ) ); d->mNewButton = new QPushButton( i18n( "New List..." ), this ); nameLayout->addWidget( d->mNewButton ); connect( d->mNewButton, SIGNAL( clicked() ), SLOT( newList() ) ); d->mEditButton = new QPushButton( i18n( "Rename List..." ), this ); nameLayout->addWidget( d->mEditButton ); connect( d->mEditButton, SIGNAL( clicked() ), SLOT( editList() ) ); d->mRemoveButton = new QPushButton( i18n( "Remove List" ), this ); nameLayout->addWidget( d->mRemoveButton ); connect( d->mRemoveButton, SIGNAL( clicked() ), SLOT( removeList() ) ); QGridLayout *gridLayout = new QGridLayout(); topLayout->addLayout( gridLayout ); gridLayout->setColumnStretch( 1, 1 ); QLabel *listLabel = new QLabel( i18n( "Available addresses:" ), this ); gridLayout->addWidget( listLabel, 0, 0 ); d->mListLabel = new QLabel( this ); gridLayout->addWidget( d->mListLabel, 0, 0, 1, 2 ); d->mAddresseeView = new QTreeWidget( this ); d->mAddresseeView->setColumnCount( 2 ); QStringList labels; labels << i18nc( "@title:column addressee name", "Name" ) << i18nc( "@title:column addressee preferred email", "Preferred Email" ); d->mAddresseeView->setHeaderLabels( labels ); gridLayout->addWidget( d->mAddresseeView, 1, 0 ); connect( d->mAddresseeView, SIGNAL( itemSelectionChanged() ), SLOT( slotSelectionAddresseeViewChanged() ) ); connect( d->mAddresseeView, SIGNAL( itemDoubleClicked( QTreeWidgetItem *, int ) ), SLOT( addEntry() ) ); d->mAddEntryButton = new QPushButton( i18n( "Add Entry" ), this ); d->mAddEntryButton->setEnabled( false ); gridLayout->addWidget( d->mAddEntryButton, 2, 0 ); connect( d->mAddEntryButton, SIGNAL( clicked() ), SLOT( addEntry() ) ); d->mEntryView = new QTreeWidget( this ); QStringList entryLabels; entryLabels << i18nc( "@title:column addressee name", "Name" ) << i18nc( "@title:column addressee preferred email", "Email" ) << i18nc( "@title:column use preferred email", "Use Preferred" ); d->mEntryView->setEnabled( false ); gridLayout->addWidget( d->mEntryView, 1, 1, 1, 2 ); connect( d->mEntryView, SIGNAL( itemSelectionChanged() ), SLOT( slotSelectionEntryViewChanged() ) ); d->mChangeEmailButton = new QPushButton( i18n( "Change Email..." ), this ); gridLayout->addWidget( d->mChangeEmailButton, 2, 1 ); connect( d->mChangeEmailButton, SIGNAL( clicked() ), SLOT( changeEmail() ) ); d->mRemoveEntryButton = new QPushButton( i18n( "Remove Entry" ), this ); gridLayout->addWidget( d->mRemoveEntryButton, 2, 2 ); connect( d->mRemoveEntryButton, SIGNAL( clicked() ), SLOT( removeEntry() ) ); d->updateAddresseeView(); d->updateNameCombo(); } DistributionListEditorWidget::~DistributionListEditorWidget() { delete d; } void DistributionListEditorWidget::Private::save() { // FIXME new distribution list handling // do we need extra save? //mManager->save(); } void DistributionListEditorWidget::Private::slotSelectionEntryViewChanged() { QList selected = mEntryView->selectedItems(); bool state = selected.count() > 0; mChangeEmailButton->setEnabled( state ); mRemoveEntryButton->setEnabled( state ); } void DistributionListEditorWidget::Private::newList() { bool ok; QString name = KInputDialog::getText( i18n( "New Distribution List" ), i18n( "Please enter &name:" ), QString(), &ok ); if ( !ok ) { return; } mAddressBook->createDistributionList( name ); mNameCombo->clear(); mNameCombo->addItems( mAddressBook->allDistributionListNames() ); mNameCombo->setCurrentIndex( mNameCombo->count() - 1 ); updateEntryView(); slotSelectionAddresseeViewChanged(); } void DistributionListEditorWidget::Private::editList() { QString oldName = mNameCombo->currentText(); bool ok; QString name = KInputDialog::getText( i18n( "Distribution List" ), i18n( "Please change &name:" ), oldName, &ok ); if ( !ok ) { return; } DistributionList *list = mAddressBook->findDistributionListByName( oldName ); if ( list ) { list->setName( name ); } mNameCombo->clear(); mNameCombo->addItems( mAddressBook->allDistributionListNames() ); mNameCombo->setCurrentIndex( mNameCombo->count() - 1 ); updateEntryView(); slotSelectionAddresseeViewChanged(); } void DistributionListEditorWidget::Private::removeList() { int result = KMessageBox::warningContinueCancel( mParent, i18n( "Delete distribution list '%1'?", mNameCombo->currentText() ), QString(), KStandardGuiItem::del() ); if ( result != KMessageBox::Continue ) { return; } DistributionList *list = mAddressBook->findDistributionListByName( mNameCombo->currentText() ); if ( list ) { // FIXME new distribution list handling // list should be deleted, no? mAddressBook->removeDistributionList( list ); mNameCombo->removeItem( mNameCombo->currentIndex() ); } updateEntryView(); slotSelectionAddresseeViewChanged(); } void DistributionListEditorWidget::Private::addEntry() { QList selected = mAddresseeView->selectedItems(); if ( selected.count() == 0 ) { kDebug() << "No addressee selected."; return; } AddresseeItem *addresseeItem = static_cast( selected.at( 0 ) ); DistributionList *list = mAddressBook->findDistributionListByName( mNameCombo->currentText() ); if ( !list ) { kDebug() << "No dist list '" << mNameCombo->currentText() << "'"; return; } list->insertEntry( addresseeItem->addressee() ); updateEntryView(); slotSelectionAddresseeViewChanged(); } void DistributionListEditorWidget::Private::removeEntry() { DistributionList *list = mAddressBook->findDistributionListByName( mNameCombo->currentText() ); if ( !list ) { return; } QList selected = mEntryView->selectedItems(); if ( selected.count() == 0 ) { return; } EntryItem *entryItem = static_cast( selected.at( 0 ) ); list->removeEntry( entryItem->addressee(), entryItem->email() ); delete entryItem; } void DistributionListEditorWidget::Private::changeEmail() { DistributionList *list = mAddressBook->findDistributionListByName( mNameCombo->currentText() ); if ( !list ) { return; } QList selected = mEntryView->selectedItems(); if ( selected.count() == 0 ) { return; } EntryItem *entryItem = static_cast( selected.at( 0 ) ); QString email = EmailSelector::getEmail( entryItem->addressee().emails(), entryItem->email(), mParent ); list->removeEntry( entryItem->addressee(), entryItem->email() ); list->insertEntry( entryItem->addressee(), email ); updateEntryView(); } void DistributionListEditorWidget::Private::updateEntryView() { if ( mNameCombo->currentText().isEmpty() ) { mListLabel->setText( i18n( "Selected addressees:" ) ); } else { mListLabel->setText( i18n( "Selected addresses in '%1':", mNameCombo->currentText() ) ); } mEntryView->clear(); DistributionList *list = mAddressBook->findDistributionListByName( mNameCombo->currentText() ); if ( !list ) { mEditButton->setEnabled( false ); mRemoveButton->setEnabled( false ); mChangeEmailButton->setEnabled( false ); mRemoveEntryButton->setEnabled( false ); mAddresseeView->setEnabled( false ); mEntryView->setEnabled( false ); return; } else { mEditButton->setEnabled( true ); mRemoveButton->setEnabled( true ); mAddresseeView->setEnabled( true ); mEntryView->setEnabled( true ); } DistributionList::Entry::List entries = list->entries(); DistributionList::Entry::List::ConstIterator it; for ( it = entries.constBegin(); it != entries.constEnd(); ++it ) { new EntryItem( mEntryView, (*it).addressee(), (*it).email() ); } QList selected = mEntryView->selectedItems(); bool state = ( selected.count() != 0 ); mChangeEmailButton->setEnabled( state ); mRemoveEntryButton->setEnabled( state ); } void DistributionListEditorWidget::Private::updateAddresseeView() { mAddresseeView->clear(); AddressBook::Iterator it; for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { new AddresseeItem( mAddresseeView, *it ); } } void DistributionListEditorWidget::Private::updateNameCombo() { mNameCombo->addItems( mAddressBook->allDistributionListNames() ); updateEntryView(); } void DistributionListEditorWidget::Private::slotSelectionAddresseeViewChanged() { QList selected = mAddresseeView->selectedItems(); bool state = ( selected.count() != 0 ); mAddEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty() ); } #include "distributionlistdialog.moc" diff --git a/kabc/plugins/dir/resourcedirconfig.cpp b/kabc/plugins/dir/resourcedirconfig.cpp index 19d95e1a9..5c7e55623 100644 --- a/kabc/plugins/dir/resourcedirconfig.cpp +++ b/kabc/plugins/dir/resourcedirconfig.cpp @@ -1,110 +1,104 @@ /* This file is part of libkabc. Copyright (c) 2002 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "resourcedirconfig.h" #include "resourcedir.h" #include "kabc/formatfactory.h" #include "kabc/stdaddressbook.h" #include #include #include #include -#include -#include +#include using namespace KABC; ResourceDirConfig::ResourceDirConfig( QWidget *parent ) : KRES::ConfigWidget( parent ) { - QGridLayout *mainLayout = new QGridLayout( this ); + QFormLayout *mainLayout = new QFormLayout( this ); mainLayout->setMargin( 0 ); - mainLayout->setSpacing( KDialog::spacingHint() ); - QLabel *label = new QLabel( i18n( "Format:" ), this ); mFormatBox = new KComboBox( this ); - mainLayout->addWidget( label, 0, 0 ); - mainLayout->addWidget( mFormatBox, 0, 1 ); + mainLayout->addRow( i18n( "Format:" ), mFormatBox ); - label = new QLabel( i18n( "Location:" ), this ); mFileNameEdit = new KUrlRequester( this ); mFileNameEdit->setMode( KFile::Directory ); - mainLayout->addWidget( label, 1, 0 ); - mainLayout->addWidget( mFileNameEdit, 1, 1 ); + mainLayout->addRow( i18n( "Location:" ), mFileNameEdit ); FormatFactory *factory = FormatFactory::self(); QStringList formats = factory->formats(); QStringList::Iterator it; for ( it = formats.begin(); it != formats.end(); ++it ) { FormatInfo info = factory->info( *it ); if ( !info.isNull() ) { mFormatTypes << (*it); mFormatBox->addItem( info.nameLabel ); } } mInEditMode = false; } void ResourceDirConfig::setEditMode( bool value ) { mFormatBox->setEnabled( !value ); mInEditMode = value; } void ResourceDirConfig::loadSettings( KRES::Resource *res ) { ResourceDir *resource = dynamic_cast( res ); if ( !resource ) { kDebug() << "cast failed"; return; } mFormatBox->setCurrentIndex( mFormatTypes.indexOf( resource->format() ) ); mFileNameEdit->setUrl( resource->path() ); if ( mFileNameEdit->url().isEmpty() ) { mFileNameEdit->setUrl( KABC::StdAddressBook::directoryName() ); } } void ResourceDirConfig::saveSettings( KRES::Resource *res ) { ResourceDir *resource = dynamic_cast( res ); if ( !resource ) { kDebug() << "cast failed"; return; } if ( mInEditMode ) { resource->setFormat( mFormatTypes[ mFormatBox->currentIndex() ] ); } resource->setPath( mFileNameEdit->url().path() ); } #include "resourcedirconfig.moc" diff --git a/kabc/plugins/file/resourcefileconfig.cpp b/kabc/plugins/file/resourcefileconfig.cpp index 8c78aac46..186e7dca7 100644 --- a/kabc/plugins/file/resourcefileconfig.cpp +++ b/kabc/plugins/file/resourcefileconfig.cpp @@ -1,123 +1,117 @@ /* This file is part of libkabc. Copyright (c) 2002 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "resourcefileconfig.h" #include "resourcefile.h" #include "kabc/formatfactory.h" #include "kabc/stdaddressbook.h" #include #include #include #include -#include -#include +#include #include using namespace KABC; ResourceFileConfig::ResourceFileConfig( QWidget *parent ) : ConfigWidget( parent ) { - QGridLayout *mainLayout = new QGridLayout( this ); + QFormLayout *mainLayout = new QFormLayout( this ); mainLayout->setMargin( 0 ); - mainLayout->setSpacing( KDialog::spacingHint() ); - QLabel *label = new QLabel( i18n( "Format:" ), this ); mFormatBox = new KComboBox( this ); - mainLayout->addWidget( label, 0, 0 ); - mainLayout->addWidget( mFormatBox, 0, 1 ); + mainLayout->addRow( i18n( "Format:" ), mFormatBox ); - label = new QLabel( i18n( "Location:" ), this ); mFileNameEdit = new KUrlRequester( this ); mFileNameEdit->setMode( KFile::File | KFile::LocalOnly ); + mainLayout->addRow( i18n( "Location:" ), mFileNameEdit ); + connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ), SLOT( checkFilePermissions( const QString & ) ) ); - mainLayout->addWidget( label, 1, 0 ); - mainLayout->addWidget( mFileNameEdit, 1, 1 ); - FormatFactory *factory = FormatFactory::self(); QStringList formats = factory->formats(); QStringList::Iterator it; for ( it = formats.begin(); it != formats.end(); ++it ) { FormatInfo info = factory->info( *it ); if ( !info.isNull() ) { mFormatTypes << (*it); mFormatBox->addItem( info.nameLabel ); } } mInEditMode = false; } void ResourceFileConfig::setEditMode( bool value ) { mFormatBox->setEnabled( !value ); mInEditMode = value; } void ResourceFileConfig::loadSettings( KRES::Resource *res ) { ResourceFile *resource = dynamic_cast( res ); if ( !resource ) { kDebug() << "cast failed"; return; } mFormatBox->setCurrentIndex( mFormatTypes.indexOf( resource->format() ) ); mFileNameEdit->setUrl( KUrl::fromPath( resource->fileName() ) ); if ( mFileNameEdit->url().isEmpty() ) { mFileNameEdit->setUrl( KUrl::fromPath( KABC::StdAddressBook::fileName() ) ); } } void ResourceFileConfig::saveSettings( KRES::Resource *res ) { ResourceFile *resource = dynamic_cast( res ); if ( !resource ) { kDebug() << "cast failed"; return; } if ( !mInEditMode ) { resource->setFormat( mFormatTypes[ mFormatBox->currentIndex() ] ); } resource->setFileName( mFileNameEdit->url().path() ); } void ResourceFileConfig::checkFilePermissions( const QString &fileName ) { // If file exist but is not writeable... if ( access( QFile::encodeName( fileName ), F_OK ) == 0 ) { emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 ); } } #include "resourcefileconfig.moc" diff --git a/kabc/plugins/ldapkio/resourceldapkioconfig.cpp b/kabc/plugins/ldapkio/resourceldapkioconfig.cpp index f96e5ecb8..2fdb392b4 100644 --- a/kabc/plugins/ldapkio/resourceldapkioconfig.cpp +++ b/kabc/plugins/ldapkio/resourceldapkioconfig.cpp @@ -1,465 +1,464 @@ /* This file is part of libkabc. Copyright (c) 2002 - 2003 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "resourceldapkioconfig.h" #include "resourceldapkio.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "resourceldapkioconfig.moc" using namespace KABC; ResourceLDAPKIOConfig::ResourceLDAPKIOConfig( QWidget *parent ) : KRES::ConfigWidget( parent ) { QBoxLayout *mainLayout = new QVBoxLayout( this ); mainLayout->setMargin( 0 ); - mainLayout->setSpacing( KDialog::spacingHint() ); KPageWidget *pageWidget = new KPageWidget( this ); pageWidget->setFaceType( KPageView::Tabbed ); mCfg = new KLDAP::LdapConfigWidget( KLDAP::LdapConfigWidget::W_USER | KLDAP::LdapConfigWidget::W_PASS | KLDAP::LdapConfigWidget::W_BINDDN | KLDAP::LdapConfigWidget::W_REALM | KLDAP::LdapConfigWidget::W_HOST | KLDAP::LdapConfigWidget::W_PORT | KLDAP::LdapConfigWidget::W_VER | KLDAP::LdapConfigWidget::W_DN | KLDAP::LdapConfigWidget::W_FILTER | KLDAP::LdapConfigWidget::W_TIMELIMIT | KLDAP::LdapConfigWidget::W_SIZELIMIT, this ); mSecurityCfg = new KLDAP::LdapConfigWidget( KLDAP::LdapConfigWidget::W_SECBOX | KLDAP::LdapConfigWidget::W_AUTHBOX, this ); pageWidget->addPage( mCfg, i18nc( "@title:tab general account settings", "General" ) ); pageWidget->addPage( mSecurityCfg, i18nc( "@title:tab account security settings", "Security" ) ); mSubTree = new QCheckBox( i18n( "Sub-tree query" ), this ); KHBox *box = new KHBox( this ); - box->setSpacing( KDialog::spacingHint() ); + box->setSpacing( -1 ); mEditButton = new QPushButton( i18n( "Edit Attributes..." ), box ); mCacheButton = new QPushButton( i18n( "Offline Use..." ), box ); mainLayout->addWidget( pageWidget ); mainLayout->addWidget( mSubTree ); mainLayout->addWidget( box ); connect( mEditButton, SIGNAL( clicked() ), SLOT( editAttributes() ) ); connect( mCacheButton, SIGNAL( clicked() ), SLOT( editCache() ) ); } void ResourceLDAPKIOConfig::loadSettings( KRES::Resource *res ) { ResourceLDAPKIO *resource = dynamic_cast( res ); if ( !resource ) { kDebug() << "cast failed"; return; } mCfg->setUser( resource->user() ); mCfg->setPassword( resource->password() ); mCfg->setRealm( resource->realm() ); mCfg->setBindDn( resource->bindDN() ); mCfg->setHost( resource->host() ); mCfg->setPort( resource->port() ); mCfg->setVersion( resource->ver() ); mCfg->setTimeLimit( resource->timeLimit() ); mCfg->setSizeLimit( resource->sizeLimit() ); mCfg->setDn( KLDAP::LdapDN( resource->dn() ) ); mCfg->setFilter( resource->filter() ); mSecurityCfg->setMech( resource->mech() ); if ( resource->isTLS() ) { mSecurityCfg->setSecurity( KLDAP::LdapConfigWidget::TLS ); } else if ( resource->isSSL() ) { mSecurityCfg->setSecurity( KLDAP::LdapConfigWidget::SSL ); } else { mSecurityCfg->setSecurity( KLDAP::LdapConfigWidget::None ); } if ( resource->isAnonymous() ) { mSecurityCfg->setAuth( KLDAP::LdapConfigWidget::Anonymous ); } else if ( resource->isSASL() ) { mSecurityCfg->setAuth( KLDAP::LdapConfigWidget::SASL ); } else { mSecurityCfg->setAuth( KLDAP::LdapConfigWidget::Simple ); } mSubTree->setChecked( resource->isSubTree() ); mAttributes = resource->attributes(); mRDNPrefix = resource->RDNPrefix(); mCachePolicy = resource->cachePolicy(); mCacheDst = resource->cacheDst(); mAutoCache = resource->autoCache(); } void ResourceLDAPKIOConfig::saveSettings( KRES::Resource *res ) { ResourceLDAPKIO *resource = dynamic_cast( res ); if ( !resource ) { kDebug() << "cast failed"; return; } resource->setUser( mCfg->user() ); resource->setPassword( mCfg->password() ); resource->setRealm( mCfg->realm() ); resource->setBindDN( mCfg->bindDn() ); resource->setHost( mCfg->host() ); resource->setPort( mCfg->port() ); resource->setVer( mCfg->version() ); resource->setTimeLimit( mCfg->timeLimit() ); resource->setSizeLimit( mCfg->sizeLimit() ); resource->setDn( mCfg->dn().toString() ); resource->setFilter( mCfg->filter() ); resource->setIsAnonymous( mSecurityCfg->auth() == KLDAP::LdapConfigWidget::Anonymous ); resource->setIsSASL( mSecurityCfg->auth() == KLDAP::LdapConfigWidget::SASL ); resource->setMech( mSecurityCfg->mech() ); resource->setIsTLS( mSecurityCfg->security() == KLDAP::LdapConfigWidget::TLS ); resource->setIsSSL( mSecurityCfg->security() == KLDAP::LdapConfigWidget::SSL ); resource->setIsSubTree( mSubTree->isChecked() ); resource->setAttributes( mAttributes ); resource->setRDNPrefix( mRDNPrefix ); resource->setCachePolicy( mCachePolicy ); resource->init(); } void ResourceLDAPKIOConfig::editAttributes() { AttributesDialog dlg( mAttributes, mRDNPrefix, this ); if ( dlg.exec() ) { mAttributes = dlg.attributes(); mRDNPrefix = dlg.rdnprefix(); } } void ResourceLDAPKIOConfig::editCache() { KLDAP::LdapUrl src; QStringList attr; src = mCfg->url(); src.setScope( mSubTree->isChecked() ? KLDAP::LdapUrl::Sub : KLDAP::LdapUrl::One ); if ( !mAttributes.empty() ) { QMap::Iterator it; QStringList attr; for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) { if ( !it.value().isEmpty() && it.key() != QLatin1String( "objectClass" ) ) { attr.append( it.value() ); } } src.setAttributes( attr ); } src.setExtension( QLatin1String( "x-dir" ), QLatin1String( "base" ) ); OfflineDialog dlg( mAutoCache, mCachePolicy, src, mCacheDst, this ); if ( dlg.exec() ) { mCachePolicy = dlg.cachePolicy(); mAutoCache = dlg.autoCache(); } } AttributesDialog::AttributesDialog( const QMap &attributes, int rdnprefix, QWidget *parent ) : KDialog( parent ) { setCaption( i18n( "Attributes Configuration" ) ); setButtons( Ok | Cancel ); setDefaultButton( Ok ); setModal( true ); showButtonSeparator( true ); mNameDict.insert( QLatin1String( "objectClass" ), i18n( "Object classes" ) ); mNameDict.insert( QLatin1String( "commonName" ), i18n( "Common name" ) ); mNameDict.insert( QLatin1String( "formattedName" ), i18n( "Formatted name" ) ); mNameDict.insert( QLatin1String( "familyName" ), i18n( "Family name" ) ); mNameDict.insert( QLatin1String( "givenName" ), i18n( "Given name" ) ); mNameDict.insert( QLatin1String( "organization" ), i18n( "Organization" ) ); mNameDict.insert( QLatin1String( "title" ), i18nc( "job title", "Title" ) ); mNameDict.insert( QLatin1String( "street" ), i18n( "Street" ) ); mNameDict.insert( QLatin1String( "state" ), i18nc( "state/province", "State" ) ); mNameDict.insert( QLatin1String( "city" ), i18n( "City" ) ); mNameDict.insert( QLatin1String( "postalcode" ), i18n( "Postal code" ) ); mNameDict.insert( QLatin1String( "mail" ), i18nc( "email address", "Email" ) ); mNameDict.insert( QLatin1String( "mailAlias" ), i18n( "Email alias" ) ); mNameDict.insert( QLatin1String( "phoneNumber" ), i18n( "Telephone number" ) ); mNameDict.insert( QLatin1String( "telephoneNumber" ), i18n( "Work telephone number" ) ); mNameDict.insert( QLatin1String( "facsimileTelephoneNumber" ), i18n( "Fax number" ) ); mNameDict.insert( QLatin1String( "mobile" ), i18n( "Cell phone number" ) ); mNameDict.insert( QLatin1String( "pager" ), i18n( "Pager" ) ); mNameDict.insert( QLatin1String( "description" ), i18n( "Note" ) ); mNameDict.insert( QLatin1String( "uid" ), i18n( "UID" ) ); mNameDict.insert( QLatin1String( "jpegPhoto" ), i18n( "Photo" ) ); // default map mDefaultMap.insert( QLatin1String( "objectClass" ), QLatin1String( "inetOrgPerson" ) ); mDefaultMap.insert( QLatin1String( "commonName" ), QLatin1String( "cn" ) ); mDefaultMap.insert( QLatin1String( "formattedName" ), QLatin1String( "displayName" ) ); mDefaultMap.insert( QLatin1String( "familyName" ), QLatin1String( "sn" ) ); mDefaultMap.insert( QLatin1String( "givenName" ), QLatin1String( "givenName" ) ); mDefaultMap.insert( QLatin1String( "title" ), QLatin1String( "title" ) ); mDefaultMap.insert( QLatin1String( "street" ), QLatin1String( "street" ) ); mDefaultMap.insert( QLatin1String( "state" ), QLatin1String( "st" ) ); mDefaultMap.insert( QLatin1String( "city" ), QLatin1String( "l" ) ); mDefaultMap.insert( QLatin1String( "organization" ), QLatin1String( "o" ) ); mDefaultMap.insert( QLatin1String( "postalcode" ), QLatin1String( "postalCode" ) ); mDefaultMap.insert( QLatin1String( "mail" ), QLatin1String( "mail" ) ); mDefaultMap.insert( QLatin1String( "mailAlias" ), QString() ); mDefaultMap.insert( QLatin1String( "phoneNumber" ), QLatin1String( "homePhone" ) ); mDefaultMap.insert( QLatin1String( "telephoneNumber" ), QLatin1String( "telephoneNumber" ) ); mDefaultMap.insert( QLatin1String( "facsimileTelephoneNumber" ), QLatin1String( "facsimileTelephoneNumber" ) ); mDefaultMap.insert( QLatin1String( "mobile" ), QLatin1String( "mobile" ) ); mDefaultMap.insert( QLatin1String( "pager" ), QLatin1String( "pager" ) ); mDefaultMap.insert( QLatin1String( "description" ), QLatin1String( "description" ) ); mDefaultMap.insert( QLatin1String( "uid" ), QLatin1String( "uid" ) ); mDefaultMap.insert( QLatin1String( "jpegPhoto" ), QLatin1String( "jpegPhoto" ) ); // overwrite the default values here QMap kolabMap, netscapeMap, evolutionMap, outlookMap; // kolab kolabMap.insert( QLatin1String( "formattedName" ), QLatin1String( "display-name" ) ); kolabMap.insert( QLatin1String( "mailAlias" ), QLatin1String( "mailalias" ) ); // evolution evolutionMap.insert( QLatin1String( "formattedName" ), QLatin1String( "fileAs" ) ); mMapList.append( attributes ); mMapList.append( kolabMap ); mMapList.append( netscapeMap ); mMapList.append( evolutionMap ); mMapList.append( outlookMap ); QFrame *page = new QFrame( this ); setMainWidget( page ); QGridLayout *layout = new QGridLayout( page ); QLabel *label = new QLabel( i18n( "Template:" ), page ); layout->addWidget( label, 0, 0 ); mMapCombo = new KComboBox( page ); layout->addWidget( mMapCombo, 0, 1 ); mMapCombo->addItem( i18n( "User Defined" ) ); mMapCombo->addItem( i18n( "Kolab" ) ); mMapCombo->addItem( i18n( "Netscape" ) ); mMapCombo->addItem( i18n( "Evolution" ) ); mMapCombo->addItem( i18n( "Outlook" ) ); connect( mMapCombo, SIGNAL( activated( int ) ), SLOT( mapChanged( int ) ) ); label = new QLabel( i18n( "RDN prefix attribute:" ), page ); layout->addWidget( label, 1, 0 ); mRDNCombo = new KComboBox( page ); layout->addWidget( mRDNCombo, 1, 1 ); mRDNCombo->addItem( i18n( "commonName" ) ); mRDNCombo->addItem( i18n( "UID" ) ); mRDNCombo->setCurrentIndex( rdnprefix ); QMap::ConstIterator it; int i, j = 0; for ( i = 2, it = attributes.begin(); it != attributes.end(); ++it, ++i ) { if ( mNameDict[ it.key() ].isEmpty() ) { i--; continue; } if ( ( i - 2 ) == ( mNameDict.count() >> 1 ) ) { i = 0; j = 2; } kDebug() << "itkey:" << it.key() << "i:" << i; label = new QLabel( mNameDict[ it.key() ] + QLatin1Char( ':' ), page ); KLineEdit *lineedit = new KLineEdit( page ); mLineEditDict.insert( it.key(), lineedit ); lineedit->setText( it.value() ); label->setBuddy( lineedit ); layout->addWidget( label, i, j ); layout->addWidget( lineedit, i, j+1 ); } for ( i = 1; i < mMapCombo->count(); ++i ) { QHash::const_iterator it2 = mLineEditDict.constBegin(); while ( it2 != mLineEditDict.constEnd() ) { if ( mMapList[ i ].contains( it2.key() ) ) { if ( mMapList[ i ][ it2.key() ] != it2.value()->text() ) { break; } } else { if ( mDefaultMap[ it2.key() ] != it2.value()->text() ) { break; } } ++it2; } if ( it2 != mLineEditDict.constEnd() ) { mMapCombo->setCurrentIndex( i ); break; } } KAcceleratorManager::manage( this ); } AttributesDialog::~AttributesDialog() { mNameDict.clear(); } QMap AttributesDialog::attributes() const { QMap map; QHash::const_iterator it = mLineEditDict.constBegin(); while ( it != mLineEditDict.constEnd() ) { map.insert( it.key(), it.value()->text() ); ++it; } return map; } int AttributesDialog::rdnprefix() const { return mRDNCombo->currentIndex(); } void AttributesDialog::mapChanged( int pos ) { // apply first the default and than the spezific changes QMap::Iterator it; for ( it = mDefaultMap.begin(); it != mDefaultMap.end(); ++it ) { mLineEditDict[ it.key() ]->setText( it.value() ); } for ( it = mMapList[ pos ].begin(); it != mMapList[ pos ].end(); ++it ) { if ( !it.value().isEmpty() ) { KLineEdit *le = mLineEditDict[ it.key() ]; if ( le ) { le->setText( it.value() ); } } } } OfflineDialog::OfflineDialog( bool autoCache, int cachePolicy, const KUrl &src, const QString &dst, QWidget *parent ) : KDialog( parent ) { setCaption( i18n( "Offline Configuration" ) ); setButtons( Ok | Cancel ); setDefaultButton( Ok ); setModal( true ); showButtonSeparator( true ); QFrame *page = new QFrame( this ); setMainWidget( page ); QVBoxLayout *layout = new QVBoxLayout( page ); mSrc = src; mDst = dst; mCacheBox = new QGroupBox( i18n( "Offline Cache Policy" ), page ); QVBoxLayout *cacheBoxLayout = new QVBoxLayout( mCacheBox ); mCacheGroup = new QButtonGroup( this ); QRadioButton *bt; bt = new QRadioButton( i18n( "Do not use offline cache" ), mCacheBox ); cacheBoxLayout->addWidget( bt ); bt->setDown(true); mCacheGroup->addButton( bt ); bt = new QRadioButton( i18n( "Use local copy if no connection" ), mCacheBox ); cacheBoxLayout->addWidget( bt ); mCacheGroup->addButton( bt ); bt = new QRadioButton( i18n( "Always use local copy" ), mCacheBox ); cacheBoxLayout->addWidget( bt ); mCacheGroup->addButton( bt ); if ( mCacheGroup->button( cachePolicy ) ) { mCacheGroup->button( cachePolicy )->setDown( true ); } mAutoCache = new QCheckBox( i18n( "Refresh offline cache automatically" ), page ); mAutoCache->setChecked( autoCache ); mAutoCache->setEnabled( bt->isChecked() ); connect( bt, SIGNAL(toggled(bool)), mAutoCache, SLOT(setEnabled(bool)) ); QPushButton *lcache = new QPushButton( i18n( "Load into Cache" ), page ); connect( lcache, SIGNAL( clicked() ), SLOT( loadCache() ) ); layout->addWidget( mCacheBox ); layout->addWidget( mAutoCache ); layout->addWidget( lcache ); } OfflineDialog::~OfflineDialog() { } bool OfflineDialog::autoCache() const { return mAutoCache->isChecked(); } int OfflineDialog::cachePolicy() const { return mCacheGroup->checkedId(); } void OfflineDialog::loadCache() { if ( KIO::NetAccess::download( mSrc, mDst, this ) ) { KMessageBox::information( this, i18n( "Successfully downloaded directory server contents." ) ); } else { KMessageBox::error( this, i18n( "An error occurred downloading directory server contents into file %1.", mDst ) ); } } diff --git a/kabc/plugins/net/resourcenetconfig.cpp b/kabc/plugins/net/resourcenetconfig.cpp index 898f6be98..fe0f0f5b7 100644 --- a/kabc/plugins/net/resourcenetconfig.cpp +++ b/kabc/plugins/net/resourcenetconfig.cpp @@ -1,104 +1,98 @@ /* This file is part of libkabc. Copyright (c) 2003 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "resourcenetconfig.h" #include "resourcenet.h" #include "kabc/formatfactory.h" #include "kabc/stdaddressbook.h" #include #include #include -#include -#include +#include using namespace KABC; ResourceNetConfig::ResourceNetConfig( QWidget *parent ) : ConfigWidget( parent ), mInEditMode( false ) { - QGridLayout *mainLayout = new QGridLayout( this ); + QFormLayout *mainLayout = new QFormLayout( this ); mainLayout->setMargin( 0 ); - mainLayout->setSpacing( KDialog::spacingHint() ); - QLabel *label = new QLabel( i18n( "Format:" ), this ); mFormatBox = new KComboBox( this ); - mainLayout->addWidget( label, 0, 0 ); - mainLayout->addWidget( mFormatBox, 0, 1 ); + mainLayout->addRow( i18n( "Format:" ), mFormatBox ); - label = new QLabel( i18n( "Location:" ), this ); mUrlEdit = new KUrlRequester( this ); mUrlEdit->setMode( KFile::File ); - mainLayout->addWidget( label, 1, 0 ); - mainLayout->addWidget( mUrlEdit, 1, 1 ); + mainLayout->addRow( i18n( "Location:" ), mUrlEdit ); FormatFactory *factory = FormatFactory::self(); QStringList formats = factory->formats(); QStringList::Iterator it; for ( it = formats.begin(); it != formats.end(); ++it ) { FormatInfo info = factory->info( *it ); if ( !info.isNull() ) { mFormatTypes << (*it); mFormatBox->addItem( info.nameLabel ); } } } void ResourceNetConfig::setEditMode( bool value ) { mFormatBox->setEnabled( !value ); mInEditMode = value; } void ResourceNetConfig::loadSettings( KRES::Resource *res ) { ResourceNet *resource = dynamic_cast( res ); if ( !resource ) { kDebug() << "cast failed"; return; } mFormatBox->setCurrentIndex( mFormatTypes.indexOf( resource->format() ) ); mUrlEdit->setUrl( resource->url() ); } void ResourceNetConfig::saveSettings( KRES::Resource *res ) { ResourceNet *resource = dynamic_cast( res ); if ( !resource ) { kDebug() << "cast failed"; return; } if ( !mInEditMode ) { resource->setFormat( mFormatTypes[ mFormatBox->currentIndex() ] ); } resource->setUrl( KUrl( mUrlEdit->url() ) ); } #include "resourcenetconfig.moc" diff --git a/kabc/tests/testlock.cpp b/kabc/tests/testlock.cpp index 616954874..3d6a51c02 100644 --- a/kabc/tests/testlock.cpp +++ b/kabc/tests/testlock.cpp @@ -1,210 +1,208 @@ /* This file is part of libkabc. Copyright (c) 2003 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testlock.h" #include "kabc/stdaddressbook.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace KABC; LockWidget::LockWidget( const QString &identifier ) { QVBoxLayout *topLayout = new QVBoxLayout( this ); - topLayout->setMargin( KDialog::marginHint() ); - topLayout->setSpacing( KDialog::spacingHint() ); if ( identifier.isEmpty() ) { mLock = 0; } else { mLock = new Lock( identifier ); int pid = getpid(); QLabel *pidLabel = new QLabel( QLatin1String( "Process ID: " ) + QString::number( pid ), this ); topLayout->addWidget( pidLabel ); QHBoxLayout *identifierLayout = new QHBoxLayout(); identifierLayout->setParent( topLayout ); - topLayout->addItem( identifierLayout ); + topLayout->addLayout( identifierLayout ); QLabel *resourceLabel = new QLabel( QLatin1String( "Identifier:" ), this ); identifierLayout->addWidget( resourceLabel ); QLabel *resourceIdentifier = new QLabel( identifier, this ); identifierLayout->addWidget( resourceIdentifier ); mStatus = new QLabel( QLatin1String( "Status: Unlocked" ), this ); topLayout->addWidget( mStatus ); QPushButton *button = new QPushButton( QLatin1String( "Lock" ), this ); topLayout->addWidget( button ); connect( button, SIGNAL( clicked() ), SLOT( lock() ) ); button = new QPushButton( QLatin1String( "Unlock" ), this ); topLayout->addWidget( button ); connect( button, SIGNAL( clicked() ), SLOT( unlock() ) ); } mLockView = new QTreeWidget( this ); topLayout->addWidget( mLockView ); QStringList headers; headers.append( QLatin1String( "Lock File" ) ); headers.append( QLatin1String( "PID" ) ); headers.append( QLatin1String( "Locking App" ) ); mLockView->setHeaderLabels( headers ); updateLockView(); QPushButton *quitButton = new QPushButton( QLatin1String( "Quit" ), this ); topLayout->addWidget( quitButton ); connect( quitButton, SIGNAL( clicked() ), SLOT( close() ) ); KDirWatch *watch = KDirWatch::self(); connect( watch, SIGNAL( dirty( const QString & ) ), SLOT( updateLockView() ) ); connect( watch, SIGNAL( created( const QString & ) ), SLOT( updateLockView() ) ); connect( watch, SIGNAL( deleted( const QString & ) ), SLOT( updateLockView() ) ); watch->addDir( Lock::locksDir() ); watch->startScan(); } LockWidget::~LockWidget() { delete mLock; } void LockWidget::updateLockView() { mLockView->clear(); QDir dir( Lock::locksDir() ); QStringList files = dir.entryList( QStringList( QLatin1String( "*.lock" ) ) ); QStringList::ConstIterator it; for ( it = files.constBegin(); it != files.constEnd(); ++it ) { if ( *it == QLatin1String( "." ) || *it == QLatin1String( ".." ) ) { continue; } QString app; int pid; if ( !Lock::readLockFile( dir.filePath( *it ), pid, app ) ) { kWarning() << "Unable to open lock file '" << *it << "'"; } else { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText( 0, *it ); item->setText( 1, QString::number( pid ) ); item->setText( 2, app ); mLockView->addTopLevelItem( item ); } } } void LockWidget::lock() { if ( !mLock->lock() ) { KMessageBox::sorry( this, mLock->error() ); } else { mStatus->setText( QLatin1String( "Status: Locked" ) ); } } void LockWidget::unlock() { if ( !mLock->unlock() ) { KMessageBox::sorry( this, mLock->error() ); } else { mStatus->setText( QLatin1String( "Status: Unlocked" ) ); } } int main( int argc, char **argv ) { KAboutData aboutData( "testlock", 0, ki18n( "Test libkabc Lock" ), "0.1" ); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineOptions options; options.add( "a" ); options.add( "addressbook", ki18n( "Standard address book" ) ); options.add( "d" ); options.add( "diraddressbook", ki18n( "Standard address book directory resource" ) ); options.add( "+identifier", ki18n( "Identifier of resource to be locked, e.g. filename" ) ); KCmdLineArgs::addCmdLineOptions( options ); KApplication app; QString identifier; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if ( args->count() == 1 ) { identifier = args->arg( 0 ); } else if ( args->count() != 0 ) { std::cerr << "Usage: testlock " << std::endl; return 1; } if ( args->isSet( "addressbook" ) ) { if ( args->count() == 1 ) { std::cerr << "Ignoring resource identifier" << std::endl; } identifier = StdAddressBook::fileName(); } if ( args->isSet( "diraddressbook" ) ) { if ( args->count() == 1 ) { std::cerr << "Ignoring resource identifier" << std::endl; } identifier = StdAddressBook::directoryName(); } LockWidget mainWidget( identifier ); mainWidget.show(); return app.exec(); } #include "testlock.moc" diff --git a/kcal/confirmsavedialog.cpp b/kcal/confirmsavedialog.cpp index 2013c65d4..d587151bd 100644 --- a/kcal/confirmsavedialog.cpp +++ b/kcal/confirmsavedialog.cpp @@ -1,96 +1,95 @@ /* This file is part of the kcal library. Copyright (c) 2004 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "confirmsavedialog.h" #include #include #include #include #include using namespace KCal; /** Private class that helps to provide binary compatibility between releases. @internal */ //@cond PRIVATE class KCal::ConfirmSaveDialog::Private { public: Private() {} QTreeWidget *mListView; }; //@endcond ConfirmSaveDialog::ConfirmSaveDialog( const QString &destination, QWidget *parent ) : KDialog( parent ), d( new KCal::ConfirmSaveDialog::Private ) { setCaption( i18n( "Confirm Save" ) ); setModal( true ); setButtons( Ok | Cancel ); setDefaultButton( Ok ); QFrame *topFrame = new QFrame( this ); setMainWidget( topFrame ); QBoxLayout *topLayout = new QVBoxLayout( topFrame ); - topLayout->setSpacing( spacingHint() ); QLabel *label = new QLabel( i18n( "You have requested to save the following objects to '%1':", destination ), topFrame ); topLayout->addWidget( label ); QStringList headers; headers << i18n( "Operation" ) << i18n( "Type" ) << i18n( "Summary" ) << i18n( "UID" ); d->mListView = new QTreeWidget( topFrame ); d->mListView->setColumnCount( 4 ); d->mListView->setHeaderLabels( headers ); topLayout->addWidget( d->mListView ); } ConfirmSaveDialog::~ConfirmSaveDialog() { delete d; } void ConfirmSaveDialog::addIncidences( const Incidence::List &incidences, const QString &operation ) { Incidence::List::ConstIterator it; for ( it = incidences.begin(); it != incidences.end(); ++it ) { Incidence *i = *it; QTreeWidgetItem *item = new QTreeWidgetItem( d->mListView ); item->setText( 0, operation ); item->setText( 1, i->type() ); item->setText( 2, i->summary() ); item->setText( 3, i->uid() ); } } diff --git a/kioslave/smtp/tests/interactivesmtpserver.cpp b/kioslave/smtp/tests/interactivesmtpserver.cpp index 2030b71a0..9c98b3e4d 100644 --- a/kioslave/smtp/tests/interactivesmtpserver.cpp +++ b/kioslave/smtp/tests/interactivesmtpserver.cpp @@ -1,206 +1,205 @@ /* -*- c++ -*- interactivesmtpserver.cc Code based on the serverSocket example by Jesper Pedersen. This file is part of the testsuite of kio_smtp, the KDE SMTP kioslave. Copyright (c) 2004 Marc Mutz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #include #include #include #include #include #include #include #include #include #include #include #include "interactivesmtpserver.h" static const QHostAddress localhost( 0x7f000001 ); // 127.0.0.1 static QString err2str( QAbstractSocket::SocketError error ) { switch ( error ) { case QAbstractSocket::ConnectionRefusedError: return "Connection refused"; case QAbstractSocket::HostNotFoundError: return "Host not found"; default: return "Unknown error"; } } static QString escape( QString s ) { return s .replace( '&', "&" ) .replace( '>', ">" ) .replace( '<', "<" ) .replace( '"', """ ) ; } static QString trim( const QString & s ) { if ( s.endsWith( "\r\n" ) ) return s.left( s.length() - 2 ); if ( s.endsWith( "\r" ) || s.endsWith( "\n" ) ) return s.left( s.length() - 1 ); return s; } InteractiveSMTPServerWindow::~InteractiveSMTPServerWindow() { if ( mSocket ) { mSocket->close(); if ( mSocket->state() == QAbstractSocket::ClosingState ) connect( mSocket, SIGNAL(delayedCloseFinished()), mSocket, SLOT(deleteLater()) ); else mSocket->deleteLater(); mSocket = 0; } } void InteractiveSMTPServerWindow::slotSendResponse() { const QString line = mLineEdit->text(); mLineEdit->clear(); QTextStream s( mSocket ); s << line + "\r\n"; slotDisplayServer( line ); } InteractiveSMTPServer::InteractiveSMTPServer( QObject* parent ) : QTcpServer( parent ) { listen( localhost, 2525 ); setMaxPendingConnections( 1 ); connect( this, SIGNAL( newConnection() ), this, SLOT( newConnectionAvailable() ) ); } void InteractiveSMTPServer::newConnectionAvailable() { InteractiveSMTPServerWindow * w = new InteractiveSMTPServerWindow( nextPendingConnection() ); w->show(); } int main( int argc, char * argv[] ) { QApplication app( argc, argv ); InteractiveSMTPServer server; qDebug( "Server should now listen on localhost:2525" ); qDebug( "Hit CTRL-C to quit." ); return app.exec(); } InteractiveSMTPServerWindow::InteractiveSMTPServerWindow( QTcpSocket * socket, QWidget * parent ) : QWidget( parent ), mSocket( socket ) { QPushButton * but; Q_ASSERT( socket ); QVBoxLayout * vlay = new QVBoxLayout( this ); - vlay->setSpacing( 6 ); mTextEdit = new QTextEdit( this ); vlay->addWidget( mTextEdit, 1 ); QWidget *mLayoutWidget = new QWidget; vlay->addWidget( mLayoutWidget ); QHBoxLayout * hlay = new QHBoxLayout( mLayoutWidget ); mLineEdit = new QLineEdit( this ); mLabel = new QLabel( "&Response:", this ); mLabel->setBuddy( mLineEdit ); but = new QPushButton( "&Send", this ); hlay->addWidget( mLabel ); hlay->addWidget( mLineEdit, 1 ); hlay->addWidget( but ); connect( mLineEdit, SIGNAL(returnPressed()), SLOT(slotSendResponse()) ); connect( but, SIGNAL(clicked()), SLOT(slotSendResponse()) ); but = new QPushButton( "&Close Connection", this ); vlay->addWidget( but ); connect( but, SIGNAL(clicked()), SLOT(slotConnectionClosed()) ); connect( socket, SIGNAL(disconnected()), SLOT(slotConnectionClosed()) ); connect( socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(slotError(QAbstractSocket::SocketError)) ); connect( socket, SIGNAL(readyRead()), SLOT(slotReadyRead()) ); mLineEdit->setText( "220 hi there" ); mLineEdit->setFocus(); } void InteractiveSMTPServerWindow::slotDisplayClient( const QString & s ) { mTextEdit->append( "C:" + escape(s) ); } void InteractiveSMTPServerWindow::slotDisplayServer( const QString & s ) { mTextEdit->append( "S:" + escape(s) ); } void InteractiveSMTPServerWindow::slotDisplayMeta( const QString & s ) { mTextEdit->append( "" + escape(s) + "" ); } void InteractiveSMTPServerWindow::slotReadyRead() { while ( mSocket->canReadLine() ) slotDisplayClient( trim( mSocket->readLine() ) ); } void InteractiveSMTPServerWindow::slotError( QAbstractSocket::SocketError error ) { slotDisplayMeta( QString( "E: %1" ).arg( err2str( error ) ) ); } void InteractiveSMTPServerWindow::slotConnectionClosed() { slotDisplayMeta( "Connection closed by peer" ); } void InteractiveSMTPServerWindow::slotCloseConnection() { mSocket->close(); } #include "interactivesmtpserver.moc" diff --git a/kldap/ldapconfigwidget.cpp b/kldap/ldapconfigwidget.cpp index fbe1423eb..1472d9a37 100644 --- a/kldap/ldapconfigwidget.cpp +++ b/kldap/ldapconfigwidget.cpp @@ -1,890 +1,889 @@ /* This file is part of libkldap. Copyright (c) 2004-2006 Szombathelyi György This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ldapconfigwidget.h" #include "ldapsearch.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace KLDAP; class LdapConfigWidget::Private { public: Private( LdapConfigWidget *parent ) : mParent( parent ), mFeatures( W_ALL ), mProg( 0 ) { mainLayout = new QGridLayout( mParent ); mainLayout->setMargin( 0 ); - mainLayout->setSpacing( KDialog::spacingHint() ); } void setLDAPPort(); void setLDAPSPort(); void setAnonymous( bool on ); void setSimple( bool on ); void setSASL( bool on ); void queryDNClicked(); void queryMechClicked(); void loadData( LdapSearch *search, const LdapObject &object ); void loadResult( LdapSearch *search ); void sendQuery(); void initWidget(); LdapConfigWidget *mParent; WinFlags mFeatures; QStringList mQResult; QString mAttr; KLineEdit *mUser; KLineEdit *mPassword; KLineEdit *mHost; QSpinBox *mPort, *mVersion, *mSizeLimit, *mTimeLimit, *mPageSize; KLineEdit *mDn, *mBindDn, *mRealm; KLineEdit *mFilter; QRadioButton *mAnonymous,*mSimple,*mSASL; QCheckBox *mSubTree; QPushButton *mEditButton; QPushButton *mQueryMech; QRadioButton *mSecNo,*mSecTLS,*mSecSSL; KComboBox *mMech; bool mCancelled; KProgressDialog *mProg; QGridLayout *mainLayout; }; void LdapConfigWidget::Private::initWidget() { QLabel *label; mUser = mPassword = mHost = mDn = mBindDn = mRealm = mFilter = 0; mPort = mVersion = mTimeLimit = mSizeLimit = 0; mAnonymous = mSimple = mSASL = mSecNo = mSecTLS = mSecSSL = 0; mEditButton = mQueryMech = 0; mPageSize = 0; mMech = 0; int row = 0; int col; if ( mFeatures & W_USER ) { label = new QLabel( i18n( "User:" ), mParent ); mUser = new KLineEdit( mParent ); mUser->setObjectName( "kcfg_ldapuser" ); mainLayout->addWidget( label, row, 0 ); mainLayout->addWidget( mUser, row, 1, 1, 3 ); row++; } if ( mFeatures & W_BINDDN ) { label = new QLabel( i18n( "Bind DN:" ), mParent ); mBindDn = new KLineEdit( mParent ); mBindDn->setObjectName( "kcfg_ldapbinddn" ); mainLayout->addWidget( label, row, 0 ); mainLayout->addWidget( mBindDn, row, 1, 1, 3 ); row++; } if ( mFeatures & W_REALM ) { label = new QLabel( i18n( "Realm:" ), mParent ); mRealm = new KLineEdit( mParent ); mRealm->setObjectName( "kcfg_ldaprealm" ); mainLayout->addWidget( label, row, 0 ); mainLayout->addWidget( mRealm, row, 1, 1, 3 ); row++; } if ( mFeatures & W_PASS ) { label = new QLabel( i18n( "Password:" ), mParent ); mPassword = new KLineEdit( mParent ); mPassword->setObjectName( "kcfg_ldappassword" ); mPassword->setEchoMode( KLineEdit::Password ); mainLayout->addWidget( label, row, 0 ); mainLayout->addWidget( mPassword, row, 1, 1, 3 ); row++; } if ( mFeatures & W_HOST ) { label = new QLabel( i18n( "Host:" ), mParent ); mHost = new KLineEdit( mParent ); mHost->setObjectName( "kcfg_ldaphost" ); mainLayout->addWidget( label, row, 0 ); mainLayout->addWidget( mHost, row, 1, 1, 3 ); row++; } col = 0; if ( mFeatures & W_PORT ) { label = new QLabel( i18n( "Port:" ), mParent ); mPort = new QSpinBox( mParent ); mPort->setRange( 0, 65535 ); mPort->setObjectName( "kcfg_ldapport" ); mPort->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) ); mPort->setValue( 389 ); mainLayout->addWidget( label, row, col ); mainLayout->addWidget( mPort, row, col+1 ); col += 2; } if ( mFeatures & W_VER ) { label = new QLabel( i18n( "LDAP version:" ), mParent ); mVersion = new QSpinBox( mParent ); mVersion->setRange( 2, 3 ); mVersion->setObjectName( "kcfg_ldapver" ); mVersion->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) ); mVersion->setValue( 3 ); mainLayout->addWidget( label, row, col ); mainLayout->addWidget( mVersion, row, col+1 ); } if ( mFeatures & ( W_PORT | W_VER ) ) { row++; } col = 0; if ( mFeatures & W_SIZELIMIT ) { label = new QLabel( i18n( "Size limit:" ), mParent ); mSizeLimit = new QSpinBox( mParent ); mSizeLimit->setRange( 0, 9999999 ); mSizeLimit->setObjectName( "kcfg_ldapsizelimit" ); mSizeLimit->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) ); mSizeLimit->setValue( 0 ); mSizeLimit->setSpecialValueText( i18nc( "default ldap size limit", "Default" ) ); mainLayout->addWidget( label, row, col ); mainLayout->addWidget( mSizeLimit, row, col+1 ); col += 2; } if ( mFeatures & W_TIMELIMIT ) { label = new QLabel( i18n( "Time limit:" ), mParent ); mTimeLimit = new QSpinBox( mParent ); mTimeLimit->setRange( 0, 9999999 ); mTimeLimit->setObjectName( "kcfg_ldaptimelimit" ); mTimeLimit->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) ); mTimeLimit->setValue( 0 ); mTimeLimit->setSuffix( i18n( " sec" ) ); mTimeLimit->setSpecialValueText( i18nc( "default ldap time limit", "Default" ) ); mainLayout->addWidget( label, row, col ); mainLayout->addWidget( mTimeLimit, row, col+1 ); } if ( mFeatures & ( W_SIZELIMIT | W_TIMELIMIT ) ) { row++; } if ( mFeatures & W_PAGESIZE ) { label = new QLabel( i18n( "Page size:" ), mParent ); mPageSize = new QSpinBox( mParent ); mPageSize->setRange( 0, 9999999 ); mPageSize->setObjectName( "kcfg_ldappagesize" ); mPageSize->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) ); mPageSize->setValue( 0 ); mPageSize->setSpecialValueText( i18n( "No paging" ) ); mainLayout->addWidget( label, row, 0 ); mainLayout->addWidget( mPageSize, row++, 1 ); } if ( mFeatures & W_DN ) { label = new QLabel( i18nc( "Distinguished Name", "DN:" ), mParent ); mDn = new KLineEdit( mParent ); mDn->setObjectName( "kcfg_ldapdn" ); mainLayout->addWidget( label, row, 0 ); mainLayout->addWidget( mDn, row, 1, 1, 1 ); //without host query doesn't make sense if ( mHost ) { QPushButton *dnquery = new QPushButton( i18n( "Query Server" ), mParent ); connect( dnquery, SIGNAL( clicked() ), mParent, SLOT( queryDNClicked() ) ); mainLayout->addWidget( dnquery, row, 2, 1, 1 ); } row++; } if ( mFeatures & W_FILTER ) { label = new QLabel( i18n( "Filter:" ), mParent ); mFilter = new KLineEdit( mParent ); mFilter->setObjectName( "kcfg_ldapfilter" ); mainLayout->addWidget( label, row, 0 ); mainLayout->addWidget( mFilter, row, 1, 1, 3 ); row++; } if ( mFeatures & W_SECBOX ) { QGroupBox *btgroup = new QGroupBox( i18n( "Security" ), mParent ); QHBoxLayout *hbox = new QHBoxLayout; btgroup->setLayout( hbox ); mSecNo = new QRadioButton( i18nc( "@option:radio set no security", "No" ), btgroup ); mSecNo->setObjectName( "kcfg_ldapnosec" ); hbox->addWidget( mSecNo ); mSecTLS = new QRadioButton( i18nc( "@option:radio use TLS security", "TLS" ), btgroup ); mSecTLS->setObjectName( "kcfg_ldaptls" ); hbox->addWidget( mSecTLS ); mSecSSL = new QRadioButton( i18nc( "@option:radio use SSL security", "SSL" ), btgroup ); mSecSSL->setObjectName( "kcfg_ldapssl" ); hbox->addWidget( mSecSSL ); mainLayout->addWidget( btgroup, row, 0, 1, 4 ); connect( mSecNo, SIGNAL( clicked() ), mParent, SLOT( setLDAPPort() ) ); connect( mSecTLS, SIGNAL( clicked() ), mParent, SLOT( setLDAPPort() ) ); connect( mSecSSL, SIGNAL( clicked() ), mParent, SLOT( setLDAPSPort( ) ) ); mSecNo->setChecked( true ); row++; } if ( mFeatures & W_AUTHBOX ) { QGroupBox *authbox = new QGroupBox( i18n( "Authentication" ), mParent ); QVBoxLayout *vbox = new QVBoxLayout; authbox->setLayout( vbox ); QHBoxLayout *hbox = new QHBoxLayout; vbox->addLayout( hbox ); mAnonymous = new QRadioButton( i18nc( "@option:radio anonymous authentication", "Anonymous" ), authbox ); mAnonymous->setObjectName( "kcfg_ldapanon" ); hbox->addWidget( mAnonymous ); mSimple = new QRadioButton( i18nc( "@option:radio simple authentication", "Simple" ), authbox ); mSimple->setObjectName( "kcfg_ldapsimple" ); hbox->addWidget( mSimple ); mSASL = new QRadioButton( i18nc( "@option:radio SASL authentication", "SASL" ), authbox ); mSASL->setObjectName( "kcfg_ldapsasl" ); hbox->addWidget( mSASL ); hbox = new QHBoxLayout; vbox->addLayout( hbox ); label = new QLabel( i18n( "SASL mechanism:" ), authbox ); hbox->addWidget( label ); mMech = new KComboBox( false, authbox ); mMech->setObjectName( "kcfg_ldapsaslmech" ); mMech->setEditable( true ); mMech->addItem( "DIGEST-MD5" ); mMech->addItem( "GSSAPI" ); mMech->addItem( "PLAIN" ); hbox->addWidget( mMech ); //without host query doesn't make sense if ( mHost ) { mQueryMech = new QPushButton( i18n( "Query Server" ), authbox ); hbox->addWidget( mQueryMech ); connect( mQueryMech, SIGNAL( clicked() ), mParent, SLOT( queryMechClicked() ) ); } mainLayout->addWidget( authbox, row, 0, 2, 4 ); connect( mAnonymous, SIGNAL( toggled( bool ) ), mParent, SLOT( setAnonymous( bool ) ) ); connect( mSimple, SIGNAL( toggled( bool ) ), mParent, SLOT( setSimple( bool ) ) ); connect( mSASL, SIGNAL( toggled( bool ) ), mParent, SLOT( setSASL( bool ) ) ); mAnonymous->setChecked( true ); } } void LdapConfigWidget::Private::sendQuery() { LdapUrl _url; mQResult.clear(); mCancelled = true; _url.setProtocol( ( mSecSSL && mSecSSL->isChecked() ) ? "ldaps" : "ldap" ); if ( mHost ) { _url.setHost( mHost->text() ); } if ( mPort ) { _url.setPort( mPort->value() ); } _url.setDn( LdapDN( "" ) ); _url.setAttributes( QStringList( mAttr ) ); _url.setScope( LdapUrl::Base ); if ( mVersion ) { _url.setExtension( "x-ver", QString::number( mVersion->value() ) ); } if ( mSecTLS && mSecTLS->isChecked() ) { _url.setExtension( "x-tls", "" ); } kDebug() << "sendQuery url:" << _url.prettyUrl(); LdapSearch search; connect( &search, SIGNAL( data( KLDAP::LdapSearch*, const KLDAP::LdapObject& ) ), mParent, SLOT( loadData( KLDAP::LdapSearch*, const KLDAP::LdapObject& ) ) ); connect( &search, SIGNAL( result( KLDAP::LdapSearch* ) ), mParent, SLOT( loadResult( KLDAP::LdapSearch* ) ) ); if ( !search.search( _url ) ) { KMessageBox::error( mParent, search.errorString() ); return; } if ( mProg == 0 ) { mProg = new KProgressDialog( mParent ); mProg->setWindowTitle( i18n( "LDAP Query" ) ); mProg->setModal( true ); } mProg->setLabelText( _url.prettyUrl() ); mProg->progressBar()->setRange( 0, 1 ); mProg->progressBar()->setValue( 0 ); mProg->exec(); if ( mCancelled ) { kDebug() << "query canceled!"; search.abandon(); } else { if ( search.error() ) { KMessageBox::error( mParent, search.errorString() ); } } } void LdapConfigWidget::Private::queryMechClicked() { mAttr = "supportedsaslmechanisms"; sendQuery(); if ( !mQResult.isEmpty() ) { mQResult.sort(); mMech->clear(); mMech->addItems( mQResult ); } } void LdapConfigWidget::Private::queryDNClicked() { mAttr = "namingcontexts"; sendQuery(); if ( !mQResult.isEmpty() ) { mDn->setText( mQResult.first() ); } } void LdapConfigWidget::Private::loadData( LdapSearch *, const LdapObject &object ) { kDebug() << "object:" << object.toString(); mProg->progressBar()->setValue( mProg->progressBar()->value() + 1 ); for ( LdapAttrMap::ConstIterator it = object.attributes().constBegin(); it != object.attributes().constEnd(); ++it ) { for ( LdapAttrValue::ConstIterator it2 = (*it).constBegin(); it2 != (*it).constEnd(); ++it2 ) { mQResult.push_back( QString::fromUtf8( *it2 ) ); } } } void LdapConfigWidget::Private::loadResult( LdapSearch *search ) { Q_UNUSED( search ); mCancelled = false; mProg->close(); } void LdapConfigWidget::Private::setAnonymous( bool on ) { if ( !on ) { return; } if ( mUser ) { mUser->setEnabled( false ); } if ( mPassword ) { mPassword->setEnabled( false ); } if ( mBindDn ) { mBindDn->setEnabled( false ); } if ( mRealm ) { mRealm->setEnabled( false ); } if ( mMech ) { mMech->setEnabled( false ); } if ( mQueryMech ) { mQueryMech->setEnabled( false ); } } void LdapConfigWidget::Private::setSimple( bool on ) { if ( !on ) { return; } if ( mUser ) { mUser->setEnabled( false ); } if ( mPassword ) { mPassword->setEnabled( true ); } if ( mBindDn ) { mBindDn->setEnabled( true ); } if ( mRealm ) { mRealm->setEnabled( false ); } if ( mMech ) { mMech->setEnabled( false ); } if ( mQueryMech ) { mQueryMech->setEnabled( false ); } } void LdapConfigWidget::Private::setSASL( bool on ) { if ( !on ) { return; } if ( mUser ) { mUser->setEnabled( true ); } if ( mPassword ) { mPassword->setEnabled( true ); } if ( mBindDn ) { mBindDn->setEnabled( true ); } if ( mRealm ) { mRealm->setEnabled( true ); } if ( mMech ) { mMech->setEnabled( true ); } if ( mQueryMech ) { mQueryMech->setEnabled( true ); } } void LdapConfigWidget::Private::setLDAPPort() { if ( mPort ) { mPort->setValue( 389 ); } } void LdapConfigWidget::Private::setLDAPSPort() { if ( mPort ) { mPort->setValue( 636 ); } } LdapConfigWidget::LdapConfigWidget( QWidget *parent, Qt::WFlags fl ) : QWidget( parent, fl ), d( new Private( this ) ) { } LdapConfigWidget::LdapConfigWidget( LdapConfigWidget::WinFlags flags, QWidget *parent, Qt::WFlags fl ) : QWidget( parent, fl ), d( new Private( this ) ) { d->mFeatures = flags; d->initWidget(); } LdapConfigWidget::~LdapConfigWidget() { delete d; } LdapUrl LdapConfigWidget::url() const { return server().url(); } void LdapConfigWidget::setUrl( const LdapUrl &url ) { LdapServer _server; _server.setUrl( url ); setServer( _server ); } LdapServer LdapConfigWidget::server() const { LdapServer _server; if ( d->mSecSSL && d->mSecSSL->isChecked() ) { _server.setSecurity( LdapServer::SSL ); } else if ( d->mSecTLS && d->mSecTLS->isChecked() ) { _server.setSecurity( LdapServer::TLS ); } else { _server.setSecurity( LdapServer::None ); } if ( d->mUser ) { _server.setUser( d->mUser->text() ); } if ( d->mBindDn ) { _server.setBindDn( d->mBindDn->text() ); } if ( d->mPassword ) { _server.setPassword( d->mPassword->text() ); } if ( d->mRealm ) { _server.setRealm( d->mRealm->text() ); } if ( d->mHost ) { _server.setHost( d->mHost->text() ); } if ( d->mPort ) { _server.setPort( d->mPort->value() ); } if ( d->mDn ) { _server.setBaseDn( LdapDN( d->mDn->text() ) ); } if ( d->mFilter ) { _server.setFilter( d->mFilter->text() ); } if ( d->mVersion ) { _server.setVersion( d->mVersion->value() ); } if ( d->mSizeLimit && d->mSizeLimit->value() != 0 ) { _server.setSizeLimit( d->mSizeLimit->value() ); } if ( d->mTimeLimit && d->mTimeLimit->value() != 0 ) { _server.setTimeLimit( d->mTimeLimit->value() ); } if ( d->mPageSize && d->mPageSize->value() != 0 ) { _server.setPageSize( d->mPageSize->value() ); } if ( d->mAnonymous && d->mAnonymous->isChecked() ) { _server.setAuth( LdapServer::Anonymous ); } else if ( d->mSimple && d->mSimple->isChecked() ) { _server.setAuth( LdapServer::Simple ); } else if ( d->mSASL && d->mSASL->isChecked() ) { _server.setAuth( LdapServer::SASL ); _server.setMech( d->mMech->currentText() ); } return _server; } void LdapConfigWidget::setServer( const LdapServer &server ) { switch ( server.security() ) { case LdapServer::SSL: if ( d->mSecSSL ) { d->mSecSSL->setChecked( true ); } case LdapServer::TLS: if ( d->mSecTLS ) { d->mSecTLS->setChecked( true ); } case LdapServer::None: if ( d->mSecNo ) { d->mSecNo->setChecked( true ); } } switch ( server.auth() ) { case LdapServer::Anonymous: if ( d->mAnonymous ) { d->mAnonymous->setChecked( true ); } case LdapServer::Simple: if ( d->mSimple ) { d->mSimple->setChecked( true ); } case LdapServer::SASL: if ( d->mSASL ) { d->mSASL->setChecked( true ); } } setUser( server.user() ); setBindDn( server.bindDn() ); setPassword( server.password() ); setRealm( server.realm() ); setHost( server.host() ); setPort( server.port() ); setFilter( server.filter() ); setDn( server.baseDn() ); setVersion( server.version() ); setSizeLimit( server.sizeLimit() ); setTimeLimit( server.timeLimit() ); setPageSize( server.pageSize() ); setMech( server.mech() ); } void LdapConfigWidget::setUser( const QString &user ) { if ( d->mUser ) { d->mUser->setText( user ); } } QString LdapConfigWidget::user() const { return d->mUser ? d->mUser->text() : QString(); } void LdapConfigWidget::setPassword( const QString &password ) { if ( d->mPassword ) { d->mPassword->setText( password ); } } QString LdapConfigWidget::password() const { return d->mPassword ? d->mPassword->text() : QString(); } void LdapConfigWidget::setBindDn( const QString &binddn ) { if ( d->mBindDn ) { d->mBindDn->setText( binddn ); } } QString LdapConfigWidget::bindDn() const { return d->mBindDn ? d->mBindDn->text() : QString(); } void LdapConfigWidget::setRealm( const QString &realm ) { if ( d->mRealm ) { d->mRealm->setText( realm ); } } QString LdapConfigWidget::realm() const { return d->mRealm ? d->mRealm->text() : QString(); } void LdapConfigWidget::setHost( const QString &host ) { if ( d->mHost ) { d->mHost->setText( host ); } } QString LdapConfigWidget::host() const { return d->mHost ? d->mHost->text() : QString(); } void LdapConfigWidget::setPort( int port ) { if ( d->mPort ) { d->mPort->setValue( port ); } } int LdapConfigWidget::port() const { return d->mPort ? d->mPort->value() : 389; } void LdapConfigWidget::setVersion( int version ) { if ( d->mVersion ) { d->mVersion->setValue( version ); } } int LdapConfigWidget::version() const { return d->mVersion ? d->mVersion->value() : 3; } void LdapConfigWidget::setDn( const LdapDN &dn ) { if ( d->mDn ) { d->mDn->setText( dn.toString() ); } } LdapDN LdapConfigWidget::dn() const { return d->mDn ? LdapDN( d->mDn->text() ) : LdapDN(); } void LdapConfigWidget::setFilter( const QString &filter ) { if ( d->mFilter ) { d->mFilter->setText( filter ); } } QString LdapConfigWidget::filter() const { return d->mFilter ? d->mFilter->text() : QString(); } void LdapConfigWidget::setMech( const QString &mech ) { if ( d->mMech == 0 ) { return; } if ( !mech.isEmpty() ) { int i = 0; while ( i < d->mMech->count() ) { if ( d->mMech->itemText( i ) == mech ) { break; } i++; } if ( i == d->mMech->count() ) { d->mMech->addItem( mech ); } d->mMech->setCurrentIndex( i ); } } QString LdapConfigWidget::mech() const { return d->mMech ? d->mMech->currentText() : QString(); } void LdapConfigWidget::setSecurity( Security security ) { switch ( security ) { case None: d->mSecNo->setChecked( true ); break; case SSL: d->mSecSSL->setChecked( true ); break; case TLS: d->mSecTLS->setChecked( true ); break; } } LdapConfigWidget::Security LdapConfigWidget::security() const { if ( d->mSecTLS->isChecked() ) { return TLS; } if ( d->mSecSSL->isChecked() ) { return SSL; } return None; } void LdapConfigWidget::setAuth( Auth auth ) { switch ( auth ) { case Anonymous: d->mAnonymous->setChecked( true ); break; case Simple: d->mSimple->setChecked( true ); break; case SASL: d->mSASL->setChecked( true ); break; } } LdapConfigWidget::Auth LdapConfigWidget::auth() const { if ( d->mSimple->isChecked() ) { return Simple; } if ( d->mSASL->isChecked() ) { return SASL; } return Anonymous; } void LdapConfigWidget::setSizeLimit( int sizelimit ) { if ( d->mSizeLimit ) { d->mSizeLimit->setValue( sizelimit ); } } int LdapConfigWidget::sizeLimit() const { return d->mSizeLimit ? d->mSizeLimit->value() : 0; } void LdapConfigWidget::setTimeLimit( int timelimit ) { if ( d->mTimeLimit ) { d->mTimeLimit->setValue( timelimit ); } } int LdapConfigWidget::timeLimit() const { return d->mTimeLimit ? d->mTimeLimit->value() : 0; } void LdapConfigWidget::setPageSize( int pagesize ) { if ( d->mPageSize ) { d->mPageSize->setValue( pagesize ); } } int LdapConfigWidget::pageSize() const { return d->mPageSize ? d->mPageSize->value() : 0; } LdapConfigWidget::WinFlags LdapConfigWidget::features() const { return d->mFeatures; } void LdapConfigWidget::setFeatures( LdapConfigWidget::WinFlags features ) { d->mFeatures = features; // First delete all the child widgets. // FIXME: I hope it's correct QList ch = children(); for ( int i = 0; i < ch.count(); ++i ) { QWidget *widget = dynamic_cast( ch[ i ] ); if ( widget && widget->parent() == this ) { delete ( widget ); } } // Re-create child widgets according to the new flags d->initWidget(); } #include "ldapconfigwidget.moc" diff --git a/kpimidentities/signatureconfigurator.cpp b/kpimidentities/signatureconfigurator.cpp index 10a082445..802f3d75e 100644 --- a/kpimidentities/signatureconfigurator.cpp +++ b/kpimidentities/signatureconfigurator.cpp @@ -1,421 +1,418 @@ /* -*- c++ -*- Copyright 2008 Thomas McGuire Copyright 2008 Edwin Schepers Copyright 2004 Marc Mutz This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "signatureconfigurator.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace KPIMIdentities; namespace KPIMIdentities { /** Private class that helps to provide binary compatibility between releases. @internal */ //@cond PRIVATE class KPIMIdentities::SignatureConfigurator::Private { public: bool inlinedHtml; }; //@endcond SignatureConfigurator::SignatureConfigurator( QWidget * parent ) : QWidget( parent ), d( new Private ) { // tmp. vars: QLabel * label; QWidget * page; QHBoxLayout * hlay; QVBoxLayout * vlay; QVBoxLayout * page_vlay; vlay = new QVBoxLayout( this ); vlay->setObjectName( "main layout" ); - vlay->setSpacing( KDialog::spacingHint() ); vlay->setMargin( 0 ); // "enable signatue" checkbox: mEnableCheck = new QCheckBox( i18n("&Enable signature"), this ); mEnableCheck->setWhatsThis( i18n("Check this box if you want KMail to append a signature to mails " "written with this identity.")); vlay->addWidget( mEnableCheck ); // "obtain signature text from" combo and label: hlay = new QHBoxLayout(); // inherits spacing vlay->addLayout( hlay ); mSourceCombo = new KComboBox( this ); mSourceCombo->setEditable( false ); mSourceCombo->setWhatsThis( i18n("Click on the widgets below to obtain help on the input methods.")); mSourceCombo->setEnabled( false ); // since !mEnableCheck->isChecked() mSourceCombo->addItems( QStringList() << i18nc("continuation of \"obtain signature text from\"", "Input Field Below") << i18nc("continuation of \"obtain signature text from\"", "File") << i18nc("continuation of \"obtain signature text from\"", "Output of Command") ); label = new QLabel( i18n("Obtain signature &text from:"), this ); label->setBuddy( mSourceCombo ); label->setEnabled( false ); // since !mEnableCheck->isChecked() hlay->addWidget( label ); hlay->addWidget( mSourceCombo, 1 ); // widget stack that is controlled by the source combo: QStackedWidget * widgetStack = new QStackedWidget( this ); widgetStack->setEnabled( false ); // since !mEnableCheck->isChecked() vlay->addWidget( widgetStack, 1 ); connect( mSourceCombo, SIGNAL(currentIndexChanged(int)), widgetStack, SLOT(setCurrentIndex (int)) ); connect( mSourceCombo, SIGNAL(highlighted(int)), widgetStack, SLOT(setCurrentIndex (int)) ); // connects for the enabling of the widgets depending on // signatureEnabled: connect( mEnableCheck, SIGNAL(toggled(bool)), mSourceCombo, SLOT(setEnabled(bool)) ); connect( mEnableCheck, SIGNAL(toggled(bool)), widgetStack, SLOT(setEnabled(bool)) ); connect( mEnableCheck, SIGNAL(toggled(bool)), label, SLOT(setEnabled(bool)) ); // The focus might be still in the widget that is disabled connect( mEnableCheck, SIGNAL(clicked()), mEnableCheck, SLOT(setFocus()) ); int pageno = 0; // page 0: input field for direct entering: page = new QWidget( widgetStack ); widgetStack->insertWidget( pageno, page ); page_vlay = new QVBoxLayout( page ); mEditToolBar = new KToolBar( this ); mEditToolBar->setToolButtonStyle( Qt::ToolButtonIconOnly ); page_vlay->addWidget( mEditToolBar, 0 ); mFormatToolBar = new KToolBar( this ); mFormatToolBar->setToolButtonStyle( Qt::ToolButtonIconOnly ); page_vlay->addWidget( mFormatToolBar, 1 ); mTextEdit = new KPIMTextEdit::TextEdit( this ); page_vlay->addWidget( mTextEdit, 2 ); mTextEdit->setWhatsThis( i18n("Use this field to enter an arbitrary static signature.")); // exclude SupportToPlainText. mTextEdit->setRichTextSupport( KRichTextWidget::FullTextFormattingSupport | KRichTextWidget::FullListSupport | KRichTextWidget::SupportAlignment | KRichTextWidget::SupportRuleLine | KRichTextWidget::SupportHyperlinks | KRichTextWidget::SupportFormatPainting ); // Fill the toolbars. KActionCollection *actionCollection = new KActionCollection(this); mTextEdit->createActions( actionCollection ); mEditToolBar->addAction( actionCollection->action( "format_text_bold" ) ); mEditToolBar->addAction( actionCollection->action( "format_text_italic" ) ); mEditToolBar->addAction( actionCollection->action( "format_text_underline" ) ); mEditToolBar->addAction( actionCollection->action( "format_text_strikeout" ) ); mEditToolBar->addAction( actionCollection->action( "format_text_foreground_color" ) ); mEditToolBar->addAction( actionCollection->action( "format_text_background_color" ) ); mEditToolBar->addAction( actionCollection->action( "format_font_family" ) ); mEditToolBar->addAction( actionCollection->action( "format_font_size" ) ); mFormatToolBar->addAction( actionCollection->action( "format_list_style" ) ); mFormatToolBar->addAction( actionCollection->action( "format_list_indent_more" ) ); mFormatToolBar->addAction( actionCollection->action( "format_list_indent_less" ) ); mFormatToolBar->addAction( actionCollection->action( "format_list_indent_less" ) ); mFormatToolBar->addSeparator(); mFormatToolBar->addAction( actionCollection->action( "format_align_left" ) ); mFormatToolBar->addAction( actionCollection->action( "format_align_center" ) ); mFormatToolBar->addAction( actionCollection->action( "format_align_right" ) ); mFormatToolBar->addAction( actionCollection->action( "format_align_justify" ) ); mFormatToolBar->addSeparator(); mFormatToolBar->addAction( actionCollection->action( "insert_horizontal_rule" ) ); mFormatToolBar->addAction( actionCollection->action( "manage_link" ) ); mFormatToolBar->addAction( actionCollection->action( "format_painter" ) ); hlay = new QHBoxLayout(); // inherits spacing page_vlay->addLayout( hlay ); mHtmlCheck = new QCheckBox( i18n("&Use HTML"), page ); connect( mHtmlCheck, SIGNAL(clicked()), this, SLOT(slotSetHtml()) ); hlay->addWidget( mHtmlCheck ); d->inlinedHtml = true; widgetStack->setCurrentIndex( 0 ); // since mSourceCombo->currentItem() == 0 // page 1: "signature file" requester, label, "edit file" button: ++pageno; page = new QWidget( widgetStack ); widgetStack->insertWidget( pageno, page ); // force sequential numbers (play safe) page_vlay = new QVBoxLayout( page ); page_vlay->setMargin( 0 ); - page_vlay->setSpacing( KDialog::spacingHint() ); hlay = new QHBoxLayout(); // inherits spacing page_vlay->addLayout( hlay ); mFileRequester = new KUrlRequester( page ); mFileRequester->setWhatsThis( i18n("Use this requester to specify a text file that contains your " "signature. It will be read every time you create a new mail or " "append a new signature.")); label = new QLabel( i18n("S&pecify file:"), page ); label->setBuddy( mFileRequester ); hlay->addWidget( label ); hlay->addWidget( mFileRequester, 1 ); mFileRequester->button()->setAutoDefault( false ); connect( mFileRequester, SIGNAL(textChanged(const QString &)), this, SLOT(slotEnableEditButton(const QString &)) ); mEditButton = new QPushButton( i18n("Edit &File"), page ); mEditButton->setWhatsThis( i18n("Opens the specified file in a text editor.")); connect( mEditButton, SIGNAL(clicked()), SLOT(slotEdit()) ); mEditButton->setAutoDefault( false ); mEditButton->setEnabled( false ); // initially nothing to edit hlay->addWidget( mEditButton ); page_vlay->addStretch( 1 ); // spacer // page 2: "signature command" requester and label: ++pageno; page = new QWidget( widgetStack ); widgetStack->insertWidget( pageno,page ); page_vlay = new QVBoxLayout( page ); page_vlay->setMargin( 0 ); - page_vlay->setSpacing( KDialog::spacingHint() ); hlay = new QHBoxLayout(); // inherits spacing page_vlay->addLayout( hlay ); mCommandEdit = new KLineEdit( page ); mCommandEdit->setCompletionObject( new KShellCompletion() ); mCommandEdit->setAutoDeleteCompletionObject( true ); mCommandEdit->setWhatsThis( i18n("You can add an arbitrary command here, either with or without path " "depending on whether or not the command is in your Path. For every " "new mail, KMail will execute the command and use what it outputs (to " "standard output) as a signature. Usual commands for use with this " "mechanism are \"fortune\" or \"ksig -random\".")); label = new QLabel( i18n("S&pecify command:"), page ); label->setBuddy( mCommandEdit ); hlay->addWidget( label ); hlay->addWidget( mCommandEdit, 1 ); page_vlay->addStretch( 1 ); // spacer } SignatureConfigurator::~SignatureConfigurator() { delete d; } bool SignatureConfigurator::isSignatureEnabled() const { return mEnableCheck->isChecked(); } void SignatureConfigurator::setSignatureEnabled( bool enable ) { mEnableCheck->setChecked( enable ); } Signature::Type SignatureConfigurator::signatureType() const { if ( !isSignatureEnabled() ) return Signature::Disabled; switch ( mSourceCombo->currentIndex() ) { case 0: return Signature::Inlined; case 1: return Signature::FromFile; case 2: return Signature::FromCommand; default: return Signature::Disabled; } } void SignatureConfigurator::setSignatureType( Signature::Type type ) { setSignatureEnabled( type != Signature::Disabled ); int idx = 0; switch( type ) { case Signature::Inlined: idx = 0; break; case Signature::FromFile: idx = 1; break; case Signature::FromCommand: idx = 2; break; default: idx = 0; break; }; mSourceCombo->setCurrentIndex( idx ); } void SignatureConfigurator::setInlineText( const QString & text ) { mTextEdit->setTextOrHtml( text ); } QString SignatureConfigurator::fileURL() const { QString file = mFileRequester->url().path(); // Force the filename to be relative to ~ instead of $PWD depending // on the rest of the code (KRun::run in Edit and KFileItem on save) if ( !file.isEmpty() && QFileInfo( file ).isRelative() ) file = QDir::home().absolutePath() + QDir::separator() + file; return file; } void SignatureConfigurator::setFileURL( const QString & url ) { mFileRequester->setUrl( url ); } QString SignatureConfigurator::commandURL() const { return mCommandEdit->text(); } void SignatureConfigurator::setCommandURL( const QString & url ) { mCommandEdit->setText( url ); } Signature SignatureConfigurator::signature() const { Signature sig; const Signature::Type sigType = signatureType(); switch ( sigType ) { case Signature::Inlined: sig.setInlinedHtml( d->inlinedHtml ); sig.setText( d->inlinedHtml ? asCleanedHTML() : mTextEdit->textOrHtml() ); break; case Signature::FromCommand: sig.setUrl( commandURL(), true ); break; case Signature::FromFile: sig.setUrl( fileURL(), false ); break; case Signature::Disabled: /* do nothing */ break; } sig.setType( sigType ); return sig; } void SignatureConfigurator::setSignature( const Signature & sig ) { setSignatureType( sig.type() ); if ( sig.isInlinedHtml() ) mHtmlCheck->setCheckState( Qt::Checked ); else mHtmlCheck->setCheckState( Qt::Unchecked ); slotSetHtml(); setInlineText( sig.text() ); if ( sig.type() == Signature::FromFile ) setFileURL( sig.url() ); else setFileURL( QString() ); if ( sig.type() == Signature::FromCommand ) setCommandURL( sig.url() ); else setCommandURL( QString() ); } void SignatureConfigurator::slotEnableEditButton( const QString & url ) { mEditButton->setDisabled( url.trimmed().isEmpty() ); } void SignatureConfigurator::slotEdit() { QString url = fileURL(); // slotEnableEditButton should prevent this assert from being hit: assert( !url.isEmpty() ); (void)KRun::runUrl( KUrl( url ), QString::fromLatin1("text/plain"), this ); } QString SignatureConfigurator::asCleanedHTML() const { QString text = mTextEdit->toHtml(); // Beautiful little hack to find the html headers produced by Qt. QTextDocument textDocument; QString html = textDocument.toHtml(); // Now remove each line from the text, the result is clean html. foreach( const QString& line, html.split( '\n' ) ){ text.remove( line + '\n' ); } return text; } // "use HTML"-checkbox (un)checked void SignatureConfigurator::slotSetHtml() { if ( mHtmlCheck->checkState() == Qt::Unchecked ) { mHtmlCheck->setText( i18n("&Use HTML") ); mEditToolBar->setVisible( false ); mEditToolBar->setEnabled( false ); mFormatToolBar->setVisible( false ); mFormatToolBar->setEnabled( false ); mTextEdit->switchToPlainText(); d->inlinedHtml = false; } else { mHtmlCheck->setText( i18n("&Use HTML (disabling removes formatting)") ); d->inlinedHtml = true; mEditToolBar->setVisible( true ); mEditToolBar->setEnabled( true ); mFormatToolBar->setVisible( true ); mFormatToolBar->setEnabled( true ); mTextEdit->enableRichTextMode(); } } } #include "signatureconfigurator.moc" diff --git a/kresources/configdialog.cpp b/kresources/configdialog.cpp index 327eb9db2..f8afad008 100644 --- a/kresources/configdialog.cpp +++ b/kresources/configdialog.cpp @@ -1,171 +1,167 @@ /* This file is part of libkresources. Copyright (c) 2002 Tobias Koenig Copyright (c) 2002 Jan-Pascal van Best Copyright (c) 2003 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** @file This file is part of the KDE resource framework and defines the ConfigDialog class. @brief Provides a resource configuration dialog. @author Tobias Koenig @author Jan-Pascal van Best */ #include "configdialog.h" #include #include #include #include #include #include #include #include "factory.h" using namespace KRES; class ConfigDialog::Private { public: ConfigWidget *mConfigWidget; Resource *mResource; KLineEdit *mName; QCheckBox *mReadOnly; }; ConfigDialog::ConfigDialog( QWidget *parent, const QString &resourceFamily, Resource *resource ) : KDialog( parent ), d( new Private ) { setModal( true ); setCaption( i18nc( "@title:window", "Resource Configuration" ) ); setButtons( Ok | Cancel ); setDefaultButton( Ok ); showButtonSeparator( false ); d->mResource = resource; Factory *factory = Factory::self( resourceFamily ); QFrame *main = new QFrame( this ); setMainWidget( main ); QVBoxLayout *mainLayout = new QVBoxLayout( main ); - mainLayout->setSpacing( spacingHint() ); mainLayout->setMargin( 0 ); QGroupBox *generalGroupBox = new QGroupBox( main ); QGridLayout *gbLayout = new QGridLayout; - gbLayout->setSpacing( spacingHint() ); generalGroupBox->setLayout( gbLayout ); generalGroupBox->setTitle( i18nc( "@title:group", "General Settings" ) ); gbLayout->addWidget( new QLabel( i18nc( "@label resource name", "Name:" ), generalGroupBox ), 0, 0 ); d->mName = new KLineEdit(); gbLayout->addWidget( d->mName, 0, 1 ); d->mReadOnly = new QCheckBox( i18nc( "@option:check if resource is read-only", "Read-only" ), generalGroupBox ); gbLayout->addWidget( d->mReadOnly, 1, 0, 1, 2 ); d->mName->setText( d->mResource->resourceName() ); d->mReadOnly->setChecked( d->mResource->readOnly() ); mainLayout->addWidget( generalGroupBox ); QGroupBox *resourceGroupBox = new QGroupBox( main ); QGridLayout *resourceLayout = new QGridLayout; - resourceLayout->setSpacing( spacingHint() ); - resourceLayout->setMargin( marginHint() ); resourceGroupBox->setLayout( resourceLayout ); resourceGroupBox->setTitle( i18nc( "@title:group", "%1 Resource Settings", factory->typeName( resource->type() ) ) ); mainLayout->addWidget( resourceGroupBox ); mainLayout->addStretch(); d->mConfigWidget = factory->configWidget( resource->type(), resourceGroupBox ); if ( d->mConfigWidget ) { resourceLayout->addWidget( d->mConfigWidget ); d->mConfigWidget->setInEditMode( false ); d->mConfigWidget->loadSettings( d->mResource ); d->mConfigWidget->show(); connect( d->mConfigWidget, SIGNAL( setReadOnly( bool ) ), SLOT( setReadOnly( bool ) ) ); } connect( d->mName, SIGNAL( textChanged(const QString &) ), SLOT( slotNameChanged(const QString &) ) ); slotNameChanged( d->mName->text() ); setMinimumSize( sizeHint() ); } ConfigDialog::~ConfigDialog() { delete d; } void ConfigDialog::setInEditMode( bool value ) { if ( d->mConfigWidget ) { d->mConfigWidget->setInEditMode( value ); } } void ConfigDialog::slotNameChanged( const QString &text ) { enableButtonOk( !text.isEmpty() ); } void ConfigDialog::setReadOnly( bool value ) { d->mReadOnly->setChecked( value ); } void ConfigDialog::accept() { if ( d->mName->text().isEmpty() ) { KMessageBox::sorry( this, i18nc( "@info", "Please enter a resource name." ) ); return; } d->mResource->setResourceName( d->mName->text() ); d->mResource->setReadOnly( d->mReadOnly->isChecked() ); if ( d->mConfigWidget ) { // First save generic information // Also save setting of specific resource type d->mConfigWidget->saveSettings( d->mResource ); } KDialog::accept(); } #include "configdialog.moc" diff --git a/kresources/configpage.cpp b/kresources/configpage.cpp index 8f2c1846b..98c72ff4b 100644 --- a/kresources/configpage.cpp +++ b/kresources/configpage.cpp @@ -1,615 +1,614 @@ /* This file is part of libkresources. Copyright (c) 2002 Tobias Koenig Copyright (c) 2002 Jan-Pascal van Best Copyright (c) 2003 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** @file This file is part of the KDE resource framework and defines the ConfigPage class. @brief A resource configuration page. @author Tobias Koenig @author Jan-Pascal van Best @author Cornelius Schumacher */ #include "configpage.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "resource.h" #include "configdialog.h" namespace KRES { class ResourcePageInfo::Private { }; ResourcePageInfo::ResourcePageInfo() : d( new KRES::ResourcePageInfo::Private ) { mManager = 0; mConfig = 0; } ResourcePageInfo::~ResourcePageInfo() { //delete mManager; mManager = 0; //delete mConfig; mConfig = 0; delete d; } class ConfigViewItem : public QTreeWidgetItem { public: ConfigViewItem( QTreeWidget *parent, Resource *resource ) : QTreeWidgetItem( parent ), mResource( resource ), mIsStandard( false ) { updateItem(); } void setStandard( bool value ) { setText( 2, ( value ? i18nc( "yes, a standard resource", "Yes" ) : QString() ) ); mIsStandard = value; } bool standard() const { return mIsStandard; } bool readOnly() const { return mResource->readOnly(); } Resource *resource() { return mResource; } void updateItem() { setCheckState( 0, mResource->isActive() ? Qt::Checked : Qt::Unchecked ); setText( 0, mResource->resourceName() ); setText( 1, mResource->type() ); setText( 2, mIsStandard ? i18nc( "yes, a standard resource", "Yes" ) : QString() ); } bool isOn() { return checkState( 0 ) == Qt::Checked; } private: Resource *mResource; bool mIsStandard; }; class ConfigPage::Private { public: void loadManager( const QString &family, ConfigPage *page ); void saveResourceSettings( ConfigPage *page ); Manager *mCurrentManager; KConfig *mCurrentConfig; KConfigGroup *mConfigGroup; QString mFamily; QStringList mFamilyMap; QList > mInfoMap; KComboBox *mFamilyCombo; QTreeWidget *mListView; QPushButton *mAddButton; QPushButton *mRemoveButton; QPushButton *mEditButton; QPushButton *mStandardButton; QTreeWidgetItem *mLastItem; }; ConfigPage::ConfigPage( QWidget *parent ) : QWidget( parent ), d( new KRES::ConfigPage::Private ) { setWindowTitle( i18n( "Resource Configuration" ) ); QVBoxLayout *mainLayout = new QVBoxLayout( this ); + mainLayout->setMargin( 0 ); QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this ); QGridLayout *groupBoxLayout = new QGridLayout(); groupBox->setLayout( groupBoxLayout ); - groupBoxLayout->setSpacing( 6 ); - groupBoxLayout->setMargin( 11 ); d->mFamilyCombo = new KComboBox( false, groupBox ); groupBoxLayout->addWidget( d->mFamilyCombo, 0, 0, 1, 2 ); d->mCurrentManager = 0; d->mCurrentConfig = 0; d->mListView = new QTreeWidget( groupBox ); d->mListView->setColumnCount( 3 ); QStringList headerLabels; headerLabels << i18nc( "@title:column resource name", "Name" ) << i18nc( "@title:column resource type", "Type" ) << i18nc( "@title:column a standard resource?", "Standard" ); d->mListView->setHeaderItem( new QTreeWidgetItem( headerLabels ) ); groupBoxLayout->addWidget( d->mListView, 1, 0 ); connect( d->mListView, SIGNAL( itemDoubleClicked( QTreeWidgetItem *, int ) ), this, SLOT( slotEdit() ) ); KDialogButtonBox *buttonBox = new KDialogButtonBox( groupBox, Qt::Vertical ); d->mAddButton = buttonBox->addButton( i18n( "&Add..." ), KDialogButtonBox::ActionRole, this, SLOT(slotAdd()) ); d->mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), KDialogButtonBox::ActionRole, this, SLOT(slotRemove()) ); d->mRemoveButton->setEnabled( false ); d->mEditButton = buttonBox->addButton( i18n( "&Edit..." ), KDialogButtonBox::ActionRole, this, SLOT(slotEdit()) ); d->mEditButton->setEnabled( false ); d->mStandardButton = buttonBox->addButton( i18n( "&Use as Standard" ), KDialogButtonBox::ActionRole, this, SLOT(slotStandard()) ); d->mStandardButton->setEnabled( false ); buttonBox->layout(); groupBoxLayout->addWidget( buttonBox, 1, 1 ); mainLayout->addWidget( groupBox ); connect( d->mFamilyCombo, SIGNAL( activated( int ) ), SLOT( slotFamilyChanged( int ) ) ); connect( d->mListView, SIGNAL( itemSelectionChanged() ), SLOT( slotSelectionChanged() ) ); connect( d->mListView, SIGNAL( itemClicked( QTreeWidgetItem *, int ) ), SLOT( slotItemClicked( QTreeWidgetItem * ) ) ); d->mLastItem = 0; d->mConfigGroup = new KConfigGroup( new KConfig( "kcmkresourcesrc" ), "General" ); load(); } ConfigPage::~ConfigPage() { QList >::Iterator it; for ( it = d->mInfoMap.begin(); it != d->mInfoMap.end(); ++it ) { (*it)->mManager->removeObserver( this ); } d->mConfigGroup->writeEntry( "CurrentFamily", d->mFamilyCombo->currentIndex() ); delete d->mConfigGroup->config(); delete d->mConfigGroup; d->mConfigGroup = 0; delete d; } void ConfigPage::load() { kDebug(); d->mListView->clear(); d->mFamilyMap.clear(); d->mInfoMap.clear(); QStringList familyDisplayNames; // KDE-3.3 compatibility code: get families from the plugins QStringList compatFamilyNames; const KService::List plugins = KServiceTypeTrader::self()->query( "KResources/Plugin" ); KService::List::ConstIterator it = plugins.begin(); KService::List::ConstIterator end = plugins.end(); for ( ; it != end; ++it ) { const QString family = (*it)->property( "X-KDE-ResourceFamily" ).toString(); if ( compatFamilyNames.indexOf( family ) == -1 ) { compatFamilyNames.append( family ); } } const KService::List managers = KServiceTypeTrader::self()->query( "KResources/Manager" ); KService::List::ConstIterator m_it; for ( m_it = managers.begin(); m_it != managers.end(); ++m_it ) { QString displayName = (*m_it)->property( "Name" ).toString(); familyDisplayNames.append( displayName ); QString family = (*m_it)->property( "X-KDE-ResourceFamily" ).toString(); if ( !family.isEmpty() ) { compatFamilyNames.removeAll( family ); d->mFamilyMap.append( family ); d->loadManager( family, this ); } } // Rest of the kde-3.3 compat code QStringList::ConstIterator cfit = compatFamilyNames.constBegin(); for ( ; cfit != compatFamilyNames.constEnd(); ++cfit ) { d->mFamilyMap.append( *cfit ); familyDisplayNames.append( *cfit ); d->loadManager( *cfit, this ); } d->mCurrentManager = 0; d->mFamilyCombo->clear(); d->mFamilyCombo->insertItems( 0, familyDisplayNames ); int currentFamily = d->mConfigGroup->readEntry( "CurrentFamily", 0 ); d->mFamilyCombo->setCurrentIndex( currentFamily ); slotFamilyChanged( currentFamily ); emit changed( false ); } void ConfigPage::Private::loadManager( const QString &family, ConfigPage *page ) { mCurrentManager = new Manager( family ); if ( mCurrentManager ) { mCurrentManager->addObserver( page ); ResourcePageInfo *info = new ResourcePageInfo; info->mManager = mCurrentManager; info->mConfig = new KConfig( KRES::ManagerImpl::defaultConfigFile( family ) ); info->mManager->readConfig( info->mConfig ); mInfoMap.append( KSharedPtr( info ) ); } } void ConfigPage::save() { d->saveResourceSettings( this ); QList >::Iterator it; for ( it = d->mInfoMap.begin(); it != d->mInfoMap.end(); ++it ) { (*it)->mManager->writeConfig( (*it)->mConfig ); } emit changed( false ); } void ConfigPage::defaults() { } void ConfigPage::slotFamilyChanged( int pos ) { if ( pos < 0 || pos >= (int)d->mFamilyMap.count() ) { return; } d->saveResourceSettings( this ); d->mFamily = d->mFamilyMap[ pos ]; d->mCurrentManager = d->mInfoMap[ pos ]->mManager; d->mCurrentConfig = d->mInfoMap[ pos ]->mConfig; if ( !d->mCurrentManager ) { kDebug() << "ERROR: cannot create ResourceManager( mFamily )"; } d->mListView->clear(); if ( d->mCurrentManager->isEmpty() ) { defaults(); } Resource *standardResource = d->mCurrentManager->standardResource(); Manager::Iterator it; for ( it = d->mCurrentManager->begin(); it != d->mCurrentManager->end(); ++it ) { ConfigViewItem *item = new ConfigViewItem( d->mListView, *it ); if ( *it == standardResource ) { item->setStandard( true ); } } if ( d->mListView->topLevelItemCount() == 0 ) { defaults(); emit changed( true ); d->mCurrentManager->writeConfig( d->mCurrentConfig ); } else { if ( !standardResource ) { KMessageBox::sorry( this, i18n( "There is no standard resource. Please select one." ) ); } emit changed( false ); } } void ConfigPage::slotAdd() { if ( !d->mCurrentManager ) { return; } QStringList types = d->mCurrentManager->resourceTypeNames(); QStringList descs = d->mCurrentManager->resourceTypeDescriptions(); bool ok = false; QString desc = KInputDialog::getItem( i18n( "Resource Configuration" ), i18n( "Please select type of the new resource:" ), descs, 0, false, &ok, this ); if ( !ok ) { return; } QString type = types[ descs.indexOf( desc ) ]; // Create new resource Resource *resource = d->mCurrentManager->createResource( type ); if ( !resource ) { KMessageBox::error( this, i18n( "Unable to create resource of type '%1'.", type ) ); return; } resource->setResourceName( type + "-resource" ); ConfigDialog dlg( this, d->mFamily, resource ); if ( dlg.exec() ) { d->mCurrentManager->add( resource ); ConfigViewItem *item = new ConfigViewItem( d->mListView, resource ); d->mLastItem = item; // if there are only read-only resources we'll set this resource // as standard resource if ( !resource->readOnly() ) { bool onlyReadOnly = true; for ( int i = 0; i < d->mListView->topLevelItemCount(); ++i ) { ConfigViewItem *confIt = static_cast( d->mListView->topLevelItem( i ) ); if ( !confIt->readOnly() && confIt != item ) { onlyReadOnly = false; } } if ( onlyReadOnly ) { item->setStandard( true ); } } emit changed( true ); } else { delete resource; resource = 0; } } void ConfigPage::slotRemove() { if ( !d->mCurrentManager ) { return; } QTreeWidgetItem *item = d->mListView->currentItem(); ConfigViewItem *confItem = static_cast( item ); if ( !confItem ) { return; } if ( confItem->standard() ) { KMessageBox::sorry( this, i18n( "You cannot remove your standard resource. " "Please select a new standard resource first." ) ); return; } d->mCurrentManager->remove( confItem->resource() ); if ( item == d->mLastItem ) { d->mLastItem = 0; } d->mListView->takeTopLevelItem( d->mListView->indexOfTopLevelItem( item ) ); delete item; emit changed( true ); } void ConfigPage::slotEdit() { if ( !d->mCurrentManager ) { return; } QTreeWidgetItem *item = d->mListView->currentItem(); ConfigViewItem *configItem = static_cast( item ); if ( !configItem ) { return; } Resource *resource = configItem->resource(); ConfigDialog dlg( this, d->mFamily, resource ); if ( dlg.exec() ) { configItem->setText( 0, resource->resourceName() ); configItem->setText( 1, resource->type() ); if ( configItem->standard() && configItem->readOnly() ) { KMessageBox::sorry( this, i18n( "You cannot use a read-only resource as standard." ) ); configItem->setStandard( false ); } d->mCurrentManager->change( resource ); emit changed( true ); } } void ConfigPage::slotStandard() { if ( !d->mCurrentManager ) { return; } ConfigViewItem *item = static_cast( d->mListView->currentItem() ); if ( !item ) { return; } if ( item->readOnly() ) { KMessageBox::sorry( this, i18n( "You cannot use a read-only resource as standard." ) ); return; } if ( !item->isOn() ) { KMessageBox::sorry( this, i18n( "You cannot use an inactive resource as standard." ) ); return; } for ( int i = 0; i < d->mListView->topLevelItemCount(); ++i ) { ConfigViewItem *configItem = static_cast( d->mListView->topLevelItem( i ) ); if ( configItem->standard() ) { configItem->setStandard( false ); } } item->setStandard( true ); d->mCurrentManager->setStandardResource( item->resource() ); emit changed( true ); } void ConfigPage::slotSelectionChanged() { bool state = ( d->mListView->currentItem() != 0 ); d->mRemoveButton->setEnabled( state ); d->mEditButton->setEnabled( state ); d->mStandardButton->setEnabled( state ); } void ConfigPage::resourceAdded( Resource *resource ) { kDebug() << resource->resourceName(); ConfigViewItem *item = new ConfigViewItem( d->mListView, resource ); item->setCheckState( 0, resource->isActive()? Qt::Checked : Qt::Unchecked ); d->mLastItem = item; emit changed( true ); } void ConfigPage::resourceModified( Resource *resource ) { kDebug() << resource->resourceName(); ConfigViewItem *item = findItem( resource ); if ( !item ) { return; } // TODO: Reread resource config. Otherwise we won't see the modification. item->updateItem(); } void ConfigPage::resourceDeleted( Resource *resource ) { kDebug() << resource->resourceName(); ConfigViewItem *item = findItem( resource ); if ( !item ) { return; } delete item; } ConfigViewItem *ConfigPage::findItem( Resource *resource ) { for ( int i = 0; i < d->mListView->topLevelItemCount(); ++i ) { ConfigViewItem *item = static_cast( d->mListView->topLevelItem( i ) ); if ( item->resource() == resource ) { return item; } } return 0; } void ConfigPage::slotItemClicked( QTreeWidgetItem *item ) { ConfigViewItem *configItem = static_cast( item ); if ( !configItem ) { return; } if ( configItem->standard() && !configItem->isOn() ) { KMessageBox::sorry( this, i18n( "You cannot deactivate the standard resource. " "Choose another standard resource first." ) ); configItem->setCheckState( 0, Qt::Checked ); return; } if ( configItem->isOn() != configItem->resource()->isActive() ) { emit changed( true ); } } void ConfigPage::Private::saveResourceSettings( ConfigPage *page ) { if ( mCurrentManager ) { for ( int i = 0; i < mListView->topLevelItemCount(); ++i ) { ConfigViewItem *configItem = static_cast( mListView->topLevelItem( i ) ); // check if standard resource if ( configItem->standard() && !configItem->readOnly() && configItem->isOn() ) { mCurrentManager->setStandardResource( configItem->resource() ); } // check if active or passive resource configItem->resource()->setActive( configItem->isOn() ); } mCurrentManager->writeConfig( mCurrentConfig ); if ( !mCurrentManager->standardResource() ) { KMessageBox::sorry( page, i18n( "There is no valid standard resource. " "Please select one which is neither read-only nor inactive." ) ); } } } } #include "configpage.moc" diff --git a/kresources/kcmkresources.cpp b/kresources/kcmkresources.cpp index 66a7f4205..402c51c8f 100644 --- a/kresources/kcmkresources.cpp +++ b/kresources/kcmkresources.cpp @@ -1,70 +1,71 @@ /* This file is part of libkresources. Copyright (c) 2003 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kcmkresources.h" #include #include #include #include #include #include "configpage.h" K_PLUGIN_FACTORY( ResourcesFactory, registerPlugin(); ) K_EXPORT_PLUGIN( ResourcesFactory( "kcmkresources" ) ) KCMKResources::KCMKResources( QWidget *parent, const QVariantList &l ) : KCModule( ResourcesFactory::componentData(), parent, QVariantList() ) { Q_UNUSED( l ); KGlobal::locale()->insertCatalog( "libkresources" ); QVBoxLayout *layout = new QVBoxLayout( this ); + layout->setMargin( 0 ); mConfigPage = new KRES::ConfigPage( this ); layout->addWidget( mConfigPage ); connect( mConfigPage, SIGNAL( changed( bool ) ), SIGNAL( changed( bool ) ) ); setButtons( Help | Apply ); KAboutData *about = new KAboutData( I18N_NOOP( "kcmkresources" ), 0, ki18n( "KDE Resources configuration module" ), 0, KLocalizedString(), KAboutData::License_GPL, ki18n( "(c) 2003 Tobias Koenig" ) ); about->addAuthor( ki18n( "Tobias Koenig" ), KLocalizedString(), "tokoe@kde.org" ); setAboutData( about ); } void KCMKResources::load() { mConfigPage->load(); } void KCMKResources::save() { mConfigPage->save(); } void KCMKResources::defaults() { mConfigPage->defaults(); } #include "kcmkresources.moc" diff --git a/kresources/selectdialog.cpp b/kresources/selectdialog.cpp index 18353ee62..8803b202c 100644 --- a/kresources/selectdialog.cpp +++ b/kresources/selectdialog.cpp @@ -1,138 +1,135 @@ /* This file is part of libkresources. Copyright (c) 2002 Tobias Koenig Copyright (c) 2002 Jan-Pascal van Best Copyright (c) 2003 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "selectdialog.h" #include #include #include #include #include #include "resource.h" using namespace KRES; class SelectDialog::SelectDialogPrivate { public: QListWidget *mResourceId; QMap mResourceMap; }; SelectDialog::SelectDialog( QList list, QWidget *parent ) : KDialog( parent ), d( new SelectDialogPrivate ) { setModal(true); setCaption( i18n( "Resource Selection" ) ); resize( 300, 200 ); setButtons( Ok|Cancel ); setDefaultButton( Ok ); QWidget *widget = new QWidget( this ); setMainWidget( widget ); QVBoxLayout *mainLayout = new QVBoxLayout( widget ); mainLayout->setMargin( 0 ); - mainLayout->setSpacing( spacingHint() ); QGroupBox *groupBox = new QGroupBox( widget ); QGridLayout *grid = new QGridLayout; - grid->setMargin( marginHint() ); - grid->setSpacing( spacingHint() ); groupBox->setLayout( grid ); groupBox->setTitle( i18n( "Resources" ) ); d->mResourceId = new QListWidget( groupBox ); grid->addWidget( d->mResourceId, 0, 0 ); mainLayout->addWidget( groupBox ); // setup listbox uint counter = 0; for ( int i = 0; i < list.count(); ++i ) { Resource *resource = list.at( i ); if ( resource && !resource->readOnly() ) { d->mResourceMap.insert( counter, resource ); d->mResourceId->addItem( resource->resourceName() ); counter++; } } d->mResourceId->setCurrentRow( 0 ); connect( d->mResourceId, SIGNAL( itemActivated(QListWidgetItem*)), SLOT(accept()) ); } SelectDialog::~SelectDialog() { delete d; } Resource *SelectDialog::resource() { if ( d->mResourceId->currentRow() != -1 ) { return d->mResourceMap[ d->mResourceId->currentRow() ]; } else { return 0; } } Resource *SelectDialog::getResource( QList list, QWidget *parent ) { if ( list.count() == 0 ) { KMessageBox::error( parent, i18n( "There is no resource available." ) ); return 0; } if ( list.count() == 1 ) { return list.first(); } // the following lines will return a writeable resource if only _one_ // writeable resource exists Resource *found = 0; for ( int i=0; i< list.size(); ++i ) { if ( !list.at(i)->readOnly() ) { if ( found ) { found = 0; break; } } else { found = list.at(i); } } if ( found ) { return found; } SelectDialog dlg( list, parent ); if ( dlg.exec() == KDialog::Accepted ) { return dlg.resource(); } else { return 0; } } diff --git a/mailtransport/sendmailsettings.ui b/mailtransport/sendmailsettings.ui index 745b8ad22..480f1144e 100644 --- a/mailtransport/sendmailsettings.ui +++ b/mailtransport/sendmailsettings.ui @@ -1,103 +1,97 @@ Volker Krause <vkrause@kde.org> SendmailSettings 0 0 400 159 - - 9 - - - 6 - Qt::Vertical 20 21 75 true Transport: Sendmail &Location: kcfg_host &Name: kcfg_name Choos&e... KSeparator QFrame
kseparator.h
KPushButton QPushButton
kpushbutton.h
KLineEdit QLineEdit
klineedit.h
diff --git a/mailtransport/transportmanagementwidget.ui b/mailtransport/transportmanagementwidget.ui index f43cb5f49..46c546ab8 100644 --- a/mailtransport/transportmanagementwidget.ui +++ b/mailtransport/transportmanagementwidget.ui @@ -1,103 +1,97 @@ MailTransport::TransportManagementWidget 0 0 400 300 - - 9 - - - 6 - Qt::Vertical 20 141 Set Default R&emove &Modify... A&dd... true false false true true 2 1 1 KPushButton QPushButton
kpushbutton.h