author | zautrix <zautrix> | 2005-08-17 17:09:57 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-08-17 17:09:57 (UTC) |
commit | b3de38d3c4c3935a3fa428eeb4ad97fa8c60c43a (patch) (side-by-side diff) | |
tree | ed4d04abe2996cde745757632d8616b23a15670b /kaddressbook | |
parent | c21edc19916722f5dd4e939f1522d311a86411fd (diff) | |
download | kdepimpi-b3de38d3c4c3935a3fa428eeb4ad97fa8c60c43a.zip kdepimpi-b3de38d3c4c3935a3fa428eeb4ad97fa8c60c43a.tar.gz kdepimpi-b3de38d3c4c3935a3fa428eeb4ad97fa8c60c43a.tar.bz2 |
view select fix
-rw-r--r-- | kaddressbook/viewmanager.cpp | 7 | ||||
-rw-r--r-- | kaddressbook/views/configuretableviewdialog.cpp | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp index c738ad8..b5d9419 100644 --- a/kaddressbook/viewmanager.cpp +++ b/kaddressbook/viewmanager.cpp @@ -52,433 +52,440 @@ $Id$ #include <qmessagebox.h> #include <qpopupmenu.h> #include <kconfigbase.h> #endif //KAB_EMBEDDED #include <kdebug.h> #include <kactionclasses.h> #include <qlayout.h> #include <qapplication.h> #include <qwidgetstack.h> #include <kabc/addressbook.h> #include "filtereditdialog.h" #include "addviewdialog.h" #include "kabcore.h" #include "kabprefs.h" #include "viewmanager.h" ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name ) : QWidget( parent, name ), mCore( core ), mActiveView( 0 ) { initGUI(); initActions(); mViewDict.setAutoDelete( true ); createViewFactories(); } ViewManager::~ViewManager() { unloadViews(); mViewFactoryDict.clear(); } void ViewManager::scrollUP() { if ( mActiveView ) mActiveView->scrollUP(); } void ViewManager::scrollDOWN() { if ( mActiveView ) mActiveView->scrollDOWN(); } void ViewManager::restoreSettings() { mViewNameList = KABPrefs::instance()->mViewNames; QString activeViewName = KABPrefs::instance()->mCurrentView; mActionSelectView->setItems( mViewNameList ); // Filter mFilterList = Filter::restore( mCore->config(), "Filter" ); mActionSelectFilter->setItems( filterNames() ); mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); int cw = 150; if ( QApplication::desktop()->width() >= 800 ) cw = 200; if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch) cw = 0; mActionSelectFilter->setComboWidth( cw ); // Tell the views to reread their config, since they may have // been modified by global settings QString _oldgroup = mCore->config()->group(); QDictIterator<KAddressBookView> it( mViewDict ); for ( it.toFirst(); it.current(); ++it ) { KConfigGroupSaver saver( mCore->config(), it.currentKey() ); it.current()->readConfig( mCore->config() ); } setActiveView( activeViewName ); mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); } void ViewManager::saveSettings() { QString _oldgroup = mCore->config()->group(); QDictIterator<KAddressBookView> it( mViewDict ); for ( it.toFirst(); it.current(); ++it ) { KConfigGroupSaver saver( mCore->config(), it.currentKey() ); #ifdef DESKTOP_VERSION (*it)->writeConfig( mCore->config() ); #else (*it).writeConfig( mCore->config() ); #endif } Filter::save( mCore->config(), "Filter", mFilterList ); KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); // write the view name list KABPrefs::instance()->mViewNames = mViewNameList; KABPrefs::instance()->mCurrentView = mActiveView->caption(); } QStringList ViewManager::selectedUids() const { if ( mActiveView ) return mActiveView->selectedUids(); else return QStringList(); } QStringList ViewManager::selectedEmails() const { if ( mActiveView ) return mActiveView->selectedEmails(); else return QStringList(); } KABC::Addressee::List ViewManager::selectedAddressees() const { KABC::Addressee::List list; if ( mActiveView ) { QStringList uids = mActiveView->selectedUids(); QStringList::Iterator it; for ( it = uids.begin(); it != uids.end(); ++it ) { KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); if ( !addr.isEmpty() ) list.append( addr ); } } return list; } //US added another method with no parameter, since my moc compiler does not support default parameters. void ViewManager::setSelected() { setSelected( QString::null, true ); } void ViewManager::setSelected( const QString &uid, bool selected ) { if ( mActiveView ) mActiveView->setSelected( uid, selected ); } void ViewManager::setListSelected(QStringList list) { int i, count = list.count(); for ( i = 0; i < count;++i ) setSelected( list[i], true ); } void ViewManager::unloadViews() { mViewDict.clear(); mActiveView = 0; } void ViewManager::selectView( const QString &name ) { setActiveView( name ); mCore->saveSettings(); } void ViewManager::setActiveView( const QString &name ) { KAddressBookView *view = 0; // Check that this isn't the same as the current active view if ( mActiveView && ( mActiveView->caption() == name ) ) return; // At this point we know the view that should be active is not // currently active. We will try to find the new on in the list. If // we can't find it, it means it hasn't been instantiated, so we will // create it on demand. view = mViewDict.find( name ); // Check if we found the view. If we didn't, then we need to create it if ( view == 0 ) { KConfig *config = mCore->config(); KConfigGroupSaver saver( config, name ); QString type = config->readEntry( "Type", "Table" ); kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; ViewFactory *factory = mViewFactoryDict.find( type ); if ( factory ) view = factory->view( mCore->addressBook(), mViewWidgetStack ); if ( view ) { + if ( !mViewNameList.contains( name ) ) { + mViewNameList.append( name ); + } view->setCaption( name ); mViewDict.insert( name, view ); //US my version needs an int as second parameter to addWidget mViewWidgetStack->addWidget( view, -1 ); view->readConfig( config ); // The manager just relays the signals connect( view, SIGNAL( selected( const QString& ) ), SIGNAL( selected( const QString & ) ) ); connect( view, SIGNAL( executed( const QString& ) ), SIGNAL( executed( const QString& ) ) ); connect( view, SIGNAL( deleteRequest( ) ), SIGNAL( deleteRequest( ) ) ); connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); connect( view, SIGNAL( dropped( QDropEvent* ) ), SLOT( dropped( QDropEvent* ) ) ); connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); } } // If we found or created the view, raise it and refresh it if ( view ) { mActiveView = view; mViewWidgetStack->raiseWidget( view ); // Set the proper filter in the view. By setting the combo // box, the activated slot will be called, which will push // the filter to the view and refresh it. if ( view->defaultFilterType() == KAddressBookView::None ) { mActionSelectFilter->setCurrentItem( 0 ); setActiveFilter( 0 ); } else if ( view->defaultFilterType() == KAddressBookView::Active ) { setActiveFilter( mActionSelectFilter->currentItem() ); } else { uint pos = filterPosition( view->defaultFilterName() ); mActionSelectFilter->setCurrentItem( pos ); setActiveFilter( pos ); } //US qDebug("ViewManager::setActiveView 6" ); // Update the inc search widget to show the fields in the new active // view. mCore->setSearchFields( mActiveView->fields() ); //US performance optimization. setActiveFilter calls also mActiveView->refresh() //US mActiveView->refresh(); + + mActionSelectView->setItems( mViewNameList ); + mActionSelectView->setCurrentItem( mViewNameList.findIndex( mActiveView->caption() ) ); + } else { qDebug("ViewManager::setActiveView: unable to find view" ); } } //US added another method with no parameter, since my moc compiler does not support default parameters. void ViewManager::refreshView() { refreshView( QString::null ); } void ViewManager::refreshView( const QString &uid ) { if ( mActiveView ) mActiveView->refresh( uid ); } void ViewManager::setFocusAV() { if ( mActiveView ) mActiveView->setFocusAV(); } void ViewManager::editView() { if ( !mActiveView ) return; ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() ); ViewConfigureWidget *wdg = 0; ViewConfigureDialog* dlg = 0; if ( factory ) { // Save the filters so the dialog has the latest set Filter::save( mCore->config(), "Filter", mFilterList ); dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" ); wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" ); } else { qDebug("ViewManager::editView()::cannot find viewfactory "); return; } if ( wdg ) { dlg->setWidget( wdg ); #ifndef DESKTOP_VERSION //dlg.setMaximumSize( 640, 480 ); //dlg->setGeometry( 40,40, 400, 300); dlg->showMaximized(); #endif KConfigGroupSaver saver( mCore->config(), mActiveView->caption() ); dlg->restoreSettings( mCore->config() ); if ( dlg->exec() ) { dlg->saveSettings( mCore->config() ); mActiveView->readConfig( mCore->config() ); // Set the proper filter in the view. By setting the combo // box, the activated slot will be called, which will push // the filter to the view and refresh it. if ( mActiveView->defaultFilterType() == KAddressBookView::None ) { mActionSelectFilter->setCurrentItem( 0 ); setActiveFilter( 0 ); } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) { setActiveFilter( mActionSelectFilter->currentItem() ); } else { uint pos = filterPosition( mActiveView->defaultFilterName() ); mActionSelectFilter->setCurrentItem( pos ); setActiveFilter( pos ); } mCore->setSearchFields( mActiveView->fields() ); //US performance optimization. setActiveFilter calls also mActiveView->refresh() //US mActiveView->refresh(); //US this is a bugfix, that we get notified if we change a views configuration emit modified(); } } delete dlg; } void ViewManager::deleteView() { QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" ) .arg( mActiveView->caption() ); QString caption = i18n( "Confirm Delete" ); if (QMessageBox::information( this, caption, text, i18n("Yes!"), i18n("No"), 0, 0 ) == 0) { mViewNameList.remove( mActiveView->caption() ); // remove the view from the config file KConfig *config = mCore->config(); config->deleteGroup( mActiveView->caption() ); mViewDict.remove( mActiveView->caption() ); mActiveView = 0; // we are in an invalid state now, but that should be fixed after // we emit the signal mActionSelectView->setItems( mViewNameList ); if ( mViewNameList.count() > 0 ) { mActionSelectView->setCurrentItem( 0 ); setActiveView( mViewNameList[ 0 ] ); } mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); } } void ViewManager::addView() { AddViewDialog dialog( &mViewFactoryDict, this ); if ( dialog.exec() ) { QString newName = dialog.viewName(); QString type = dialog.viewType(); // Check for name conflicts bool firstConflict = true; int numTries = 1; while ( mViewNameList.contains( newName ) > 0 ) { if ( !firstConflict ) { newName = newName.left( newName.length() - 4 ); firstConflict = false; } newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); numTries++; } // Add the new one to the list mViewNameList.append( newName ); // write the view to the config file, KConfig *config = mCore->config(); config->deleteGroup( newName ); KConfigGroupSaver saver( config, newName ); config->writeEntry( "Type", type ); // try to set the active view mActionSelectView->setItems( mViewNameList ); mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); setActiveView( newName ); editView(); mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); } } void ViewManager::createViewFactories() { #ifndef KAB_EMBEDDED KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); KTrader::OfferList::ConstIterator it; for ( it = plugins.begin(); it != plugins.end(); ++it ) { if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) continue; KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); if ( !factory ) { kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; continue; } ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); if ( !viewFactory ) { kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; continue; } mViewFactoryDict.insert( viewFactory->type(), viewFactory ); } #else //KAB_EMBEDDED ViewFactory* viewFactory = new IconViewFactory(); mViewFactoryDict.insert( viewFactory->type(), viewFactory ); // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); viewFactory = new TableViewFactory(); diff --git a/kaddressbook/views/configuretableviewdialog.cpp b/kaddressbook/views/configuretableviewdialog.cpp index 0e36abd..c329cd9 100644 --- a/kaddressbook/views/configuretableviewdialog.cpp +++ b/kaddressbook/views/configuretableviewdialog.cpp @@ -1,302 +1,302 @@ /* This file is part of KAddressBook. Copyright (c) 2002 Mike Pilone <mpilone@slac.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qstring.h> #include <qwidget.h> #include <qlayout.h> #include <qlabel.h> #include <qradiobutton.h> #include <qcheckbox.h> #include <qvbox.h> #include <qbuttongroup.h> #include <qtabwidget.h> #include <qwhatsthis.h> #include <qpushbutton.h> #include <kglobal.h> #include <klocale.h> #include <klineedit.h> #include <kurlrequester.h> #include <kiconloader.h> #include <kfontdialog.h> #ifndef KAB_EMBEDDED #include <kimageio.h> #else //KAB_EMBEDDED #endif //KAB_EMBEDDED #include <kconfig.h> #include "colorlistbox.h" #include "configuretableviewdialog.h" ConfigureTableViewWidget::ConfigureTableViewWidget( KABC::AddressBook *ab, QWidget *parent, const char *name ) : ViewConfigureWidget( ab, parent, name ) { QWidget *page = addPage( i18n( "Look & Feel" ), QString::null, KGlobal::iconLoader()->loadIcon( "looknfeel", KIcon::Panel ) ); mPage = new LookAndFeelPage( page ); } ConfigureTableViewWidget::~ConfigureTableViewWidget() { } void ConfigureTableViewWidget::restoreSettings( KConfig *config ) { ViewConfigureWidget::restoreSettings( config ); mPage->restoreSettings( config ); } void ConfigureTableViewWidget::saveSettings( KConfig *config ) { ViewConfigureWidget::saveSettings( config ); mPage->saveSettings( config ); } LookAndFeelPage::LookAndFeelPage(QWidget *parent, const char *name) : QVBox(parent, name) { initGUI(); // Set initial state enableBackgroundToggled(mBackgroundBox->isChecked()); } void LookAndFeelPage::restoreSettings( KConfig *config ) { mAlternateButton->setChecked(config->readBoolEntry("ABackground", true)); mLineButton->setChecked(config->readBoolEntry("SingleLine", false)); mToolTipBox->setChecked(config->readBoolEntry("ToolTips", true)); if (!mAlternateButton->isChecked() & !mLineButton->isChecked()) mNoneButton->setChecked(true); mBackgroundBox->setChecked(config->readBoolEntry("Background", false)); mBackgroundName->lineEdit()->setText(config->readEntry("BackgroundName")); // colors cbEnableCustomColors->setChecked( config->readBoolEntry( "EnableCustomColors", false ) ); QColor c; -qDebug("LookAndFeelPage::restoreSettings make base color configurable"); + //qDebug("LookAndFeelPage::restoreSettings make base color configurable"); #ifndef KAB_EMBEDDED c = KGlobalSettings::baseColor(); #else //KAB_EMBEDDED c = QColor(0,0,0); #endif //KAB_EMBEDDED c = colorGroup().background(); lbColors->insertItem( new ColorListItem( i18n("Background Color"), config->readColorEntry( "BackgroundColor", &c ) ) ); c = colorGroup().foreground(); lbColors->insertItem( new ColorListItem( i18n("Text Color"), config->readColorEntry( "TextColor", &c ) ) ); c = colorGroup().button(); lbColors->insertItem( new ColorListItem( i18n("Header Background Color"), config->readColorEntry( "HeaderBackgroundColor", &c ) ) ); c = colorGroup().buttonText(); lbColors->insertItem( new ColorListItem( i18n("Header Text Color"), config->readColorEntry( "HeaderTextColor", &c ) ) ); c = colorGroup().highlight(); lbColors->insertItem( new ColorListItem( i18n("Highlight Color"), config->readColorEntry( "HighlightColor", &c ) ) ); c = colorGroup().highlightedText(); lbColors->insertItem( new ColorListItem( i18n("Highlighted Text Color"), config->readColorEntry( "HighlightedTextColor", &c ) ) ); c = colorGroup().background(); lbColors->insertItem( new ColorListItem( i18n("Alternating Background Color"), config->readColorEntry( "AlternatingBackgroundColor", &c ) ) ); enableColors(); // fonts QFont fnt = font(); updateFontLabel( config->readFontEntry( "TextFont", &fnt ), (QLabel*)lTextFont ); fnt.setBold( true ); updateFontLabel( config->readFontEntry( "HeaderFont", &fnt ), (QLabel*)lHeaderFont ); cbEnableCustomFonts->setChecked( config->readBoolEntry( "EnableCustomFonts", false ) ); enableFonts(); } void LookAndFeelPage::saveSettings( KConfig *config ) { config->writeEntry("ABackground", mAlternateButton->isChecked()); config->writeEntry("SingleLine", mLineButton->isChecked()); config->writeEntry("ToolTips", mToolTipBox->isChecked()); config->writeEntry("Background", mBackgroundBox->isChecked()); config->writeEntry("BackgroundName", mBackgroundName->lineEdit()->text()); // colors config->writeEntry( "EnableCustomColors", cbEnableCustomColors->isChecked() ); if ( cbEnableCustomColors->isChecked() ) // ?? - Hmmm. { config->writeEntry( "BackgroundColor", lbColors->color( 0 ) ); config->writeEntry( "TextColor", lbColors->color( 1 ) ); config->writeEntry( "HeaderBackgroundColor", lbColors->color( 2 ) ); config->writeEntry( "HeaderTextColor", lbColors->color( 3 ) ); config->writeEntry( "HighlightColor", lbColors->color( 4 ) ); config->writeEntry( "HighlightedTextColor", lbColors->color( 5 ) ); config->writeEntry( "AlternatingBackgroundColor", lbColors->color( 6 ) ); } // fonts config->writeEntry( "EnableCustomFonts", cbEnableCustomFonts->isChecked() ); if ( cbEnableCustomFonts->isChecked() ) { config->writeEntry( "TextFont", lTextFont->font() ); config->writeEntry( "HeaderFont", lHeaderFont->font() ); } } void LookAndFeelPage::setTextFont() { QFont f( lTextFont->font() ); #ifndef KAB_EMBEDDED if ( KFontDialog::getFont( f, false, this ) == QDialog::Accepted ) updateFontLabel( f, lTextFont ); #else //KAB_EMBEDDED bool ok; QFont fout = KFontDialog::getFont( f, ok); if ( ok ) updateFontLabel( fout, lTextFont ); #endif //KAB_EMBEDDED } void LookAndFeelPage::setHeaderFont() { QFont f( lHeaderFont->font() ); #ifndef KAB_EMBEDDED if ( KFontDialog::getFont( f,false, this ) == QDialog::Accepted ) updateFontLabel( f, lHeaderFont ); #else //KAB_EMBEDDED bool ok; QFont fout = KFontDialog::getFont( f, ok); if ( ok ) updateFontLabel( fout, lHeaderFont ); #endif //KAB_EMBEDDED } void LookAndFeelPage::enableFonts() { vbFonts->setEnabled( cbEnableCustomFonts->isChecked() ); if ( cbEnableCustomFonts->isChecked() ) vbFonts->setFocus(); } void LookAndFeelPage::enableColors() { lbColors->setEnabled( cbEnableCustomColors->isChecked() ); if ( cbEnableCustomColors->isChecked() ) lbColors->setFocus(); } void LookAndFeelPage::initGUI() { int spacing = KDialog::spacingHint(); int margin = KDialog::marginHint(); QTabWidget *tabs = new QTabWidget( this ); // General QVBox *generalTab = new QVBox( this, "generaltab" ); generalTab->setSpacing( spacing ); generalTab->setMargin( margin ); QButtonGroup *group = new QButtonGroup(1, Qt::Horizontal, i18n("Row Separator"), generalTab); mAlternateButton = new QRadioButton(i18n("Alternating backgrounds"), group, "mAlternateButton"); mLineButton = new QRadioButton(i18n("Single line"), group, "mLineButton"); mNoneButton = new QRadioButton(i18n("None"), group, "mNoneButton"); mBackgroundBox = new QCheckBox(i18n("Enable background image:"), generalTab, "mBackgroundBox"); connect(mBackgroundBox, SIGNAL(toggled(bool)), SLOT(enableBackgroundToggled(bool))); // LR image not implemented mBackgroundBox->setEnabled( false ); mBackgroundName = new KURLRequester(generalTab, "mBackgroundName"); #ifndef KAB_EMBEDDED mBackgroundName->setMode(KFile::File | KFile::ExistingOnly | KFile::LocalOnly); mBackgroundName->setFilter(KImageIO::pattern(KImageIO::Reading)); #endif //KAB_EMBEDDED // ToolTip Checkbox mToolTipBox = new QCheckBox(i18n("Enable contact tooltips"), generalTab, "mToolTipBox"); tabs->addTab( generalTab, i18n("&General") ); // Colors QVBox *colorTab = new QVBox( this, "colortab" ); colorTab->setSpacing( spacing ); colorTab->setMargin( spacing ); cbEnableCustomColors = new QCheckBox( i18n("&Enable custom Colors"), colorTab ); connect( cbEnableCustomColors, SIGNAL(clicked()), this, SLOT(enableColors()) ); lbColors = new ColorListBox( colorTab ); tabs->addTab( colorTab, i18n("&Colors") ); QWhatsThis::add( cbEnableCustomColors, i18n( "If custom colors are enabled, you may choose the colors for the view below. " "Otherwise colors from your current KDE color scheme are used." ) ); QWhatsThis::add( lbColors, i18n( "Double click or press RETURN on a item to select a color for the related strings in the view." ) ); // Fonts QVBox *fntTab = new QVBox( this, "fonttab" ); fntTab->setSpacing( spacing ); fntTab->setMargin( spacing ); cbEnableCustomFonts = new QCheckBox( i18n("&Enable custom fonts"), fntTab ); connect( cbEnableCustomFonts, SIGNAL(clicked()), this, SLOT(enableFonts()) ); vbFonts = new QWidget( fntTab ); QGridLayout *gFnts = new QGridLayout( vbFonts, 2, 3 ); gFnts->setSpacing( spacing ); gFnts->setAutoAdd( true ); gFnts->setColStretch( 1, 1 ); QLabel *lTFnt = new QLabel( i18n("&Text font:"), vbFonts ); lTextFont = new QLabel( vbFonts ); lTextFont->setFrameStyle( QFrame::Panel|QFrame::Sunken ); #ifndef KAB_EMBEDDED btnFont = new KPushButton( i18n("Choose..."), vbFonts ); #else //KAB_EMBEDDED btnFont = new QPushButton( i18n("Choose..."), vbFonts ); #endif //KAB_EMBEDDED |