summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/viewmanager.cpp6
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp3
2 files changed, 6 insertions, 3 deletions
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
index e8c5b45..bec1862 100644
--- a/kaddressbook/viewmanager.cpp
+++ b/kaddressbook/viewmanager.cpp
@@ -168,263 +168,265 @@ KABC::Addressee::List ViewManager::selectedAddressees() const
}
//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::unloadViews()
{
mViewDict.clear();
mActiveView = 0;
}
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 ) {
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() );
- mActiveView->refresh();
+//US performance optimization. setActiveFilter calls also mActiveView->refresh()
+//US mActiveView->refresh();
}
else
{
qDebug("ViewManager::setActiveView: unable to find view" );
kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n";
}
}
//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::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() );
- mActiveView->refresh();
+//US performance optimization. setActiveFilter calls also mActiveView->refresh()
+//US mActiveView->refresh();
}
}
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;
}
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp
index ee2fcf8..8d2203e 100644
--- a/kaddressbook/views/kaddressbooktableview.cpp
+++ b/kaddressbook/views/kaddressbooktableview.cpp
@@ -10,193 +10,194 @@
#include <qdragobject.h>
#include <qevent.h>
#include <qurl.h>
#include <qpixmap.h>
#include <kabc/addressbook.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kcolorbutton.h>
#include <kdebug.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <klineedit.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kurl.h>
#include <kurlrequester.h>
//US#include "configuretableviewdialog.h"
#include "contactlistview.h"
#include "kabprefs.h"
#include "undocmds.h"
#include "viewmanager.h"
#include <qlayout.h>
#include "kaddressbooktableview.h"
KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab,
QWidget *parent, const char *name )
: KAddressBookView( ab, parent, name )
{
mainLayout = new QVBoxLayout( viewWidget(), 2 );
// The list view will be created when the config is read.
mListView = 0;
}
KAddressBookTableView::~KAddressBookTableView()
{
}
void KAddressBookTableView::reconstructListView()
{
if (mListView)
{
disconnect(mListView, SIGNAL(selectionChanged()),
this, SLOT(addresseeSelected()));
disconnect(mListView, SIGNAL(executed(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
disconnect(mListView, SIGNAL(startAddresseeDrag()), this,
SIGNAL(startDrag()));
disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
SIGNAL(dropped(QDropEvent*)));
delete mListView;
}
mListView = new ContactListView( this, addressBook(), viewWidget() );
// Add the columns
KABC::Field::List fieldList = fields();
KABC::Field::List::ConstIterator it;
int c = 0;
for( it = fieldList.begin(); it != fieldList.end(); ++it ) {
mListView->addColumn( (*it)->label() );
mListView->setColumnWidthMode(c++, QListView::Manual);
//US
// qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1());
}
connect(mListView, SIGNAL(selectionChanged()),
this, SLOT(addresseeSelected()));
connect(mListView, SIGNAL(startAddresseeDrag()), this,
SIGNAL(startDrag()));
connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
SIGNAL(dropped(QDropEvent*)));
if (KABPrefs::instance()->mHonorSingleClick)
connect(mListView, SIGNAL(executed(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
else
connect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
connect(mListView, SIGNAL(returnPressed(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
connect(mListView, SIGNAL(signalDelete()),
this, SLOT(addresseeDeleted()));
- refresh();
+//US performceimprovement. Refresh is done from the outside
+//US refresh();
mListView->setSorting( 0, true );
mainLayout->addWidget( mListView );
mainLayout->activate();
mListView->show();
}
void KAddressBookTableView::writeConfig(KConfig *config)
{
KAddressBookView::writeConfig(config);
mListView->saveLayout(config, config->group());
}
void KAddressBookTableView::readConfig(KConfig *config)
{
KAddressBookView::readConfig( config );
// The config could have changed the fields, so we need to reconstruct
// the listview.
reconstructListView();
// Set the list view options
mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground",
true));
mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false));
mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true));
if (config->readBoolEntry("Background", false))
mListView->setBackgroundPixmap(config->readEntry("BackgroundName"));
// Restore the layout of the listview
mListView->restoreLayout(config, config->group());
}
void KAddressBookTableView::refresh(QString uid)
{
// For now just repopulate. In reality this method should
// check the value of uid, and if valid iterate through
// the listview to find the entry, then tell it to refresh.
if (uid.isNull()) {
// Clear the list view
QString currentUID, nextUID;
#ifndef KAB_EMBEDDED
ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() );
#else //KAB_EMBEDDED
ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() );
#endif //KAB_EMBEDDED
if ( currentItem ) {
#ifndef KAB_EMBEDDED
ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() );
#else //KAB_EMBEDDED
ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() );
#endif //KAB_EMBEDDED
if ( nextItem )
nextUID = nextItem->addressee().uid();
currentUID = currentItem->addressee().uid();
}
mListView->clear();
currentItem = 0;
KABC::Addressee::List addresseeList = addressees();
KABC::Addressee::List::Iterator it;
for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
if ( (*it).uid() == currentUID )
currentItem = item;
else if ( (*it).uid() == nextUID && !currentItem )
currentItem = item;
}
// Sometimes the background pixmap gets messed up when we add lots
// of items.
mListView->repaint();
if ( currentItem ) {
mListView->setCurrentItem( currentItem );
mListView->ensureItemVisible( currentItem );
}
} else {
// Only need to update on entry. Iterate through and try to find it
ContactListViewItem *ceItem;
QListViewItemIterator it( mListView );
while ( it.current() ) {
#ifndef KAB_EMBEDDED
ceItem = dynamic_cast<ContactListViewItem*>( it.current() );
#else //KAB_EMBEDDED
ceItem = (ContactListViewItem*)( it.current() );
#endif //KAB_EMBEDDED
if ( ceItem && ceItem->addressee().uid() == uid ) {
ceItem->refresh();
return;