From kde-commits Fri Jan 12 15:17:29 2007 From: Volker Krause Date: Fri, 12 Jan 2007 15:17:29 +0000 To: kde-commits Subject: KDE/kdepim/akonadi/libakonadi Message-Id: <1168615049.741437.26899.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=116861505800382 SVN commit 622650 by vkrause: ItemModel now keeps itself up-to-date M +0 -3 CMakeLists.txt M +42 -78 itemmodel.cpp M +4 -9 itemmodel.h D itemquery.cpp D itemquery.h M +0 -1 messagemodel.cpp D messagequery.cpp D messagequery.h --- trunk/KDE/kdepim/akonadi/libakonadi/CMakeLists.txt #622649:622650 @@ -36,7 +36,6 @@ itemdeletejob.cpp itemfetchjob.cpp itemstorejob.cpp - itemquery.cpp itemmodel.cpp job.cpp jobqueue.cpp @@ -45,7 +44,6 @@ message.cpp messagefetchjob.cpp messagemodel.cpp - messagequery.cpp monitor.cpp profilemanager.cpp profilemodel.cpp @@ -93,7 +91,6 @@ message.h messagefetchjob.h messagemodel.h - messagequery.h monitor.h profilemanager.h transactionjobs.h --- trunk/KDE/kdepim/akonadi/libakonadi/itemmodel.cpp #622649:622650 @@ -1,5 +1,5 @@ /* - Copyright (c) 2006 Volker Krause + Copyright (c) 2006 - 2007 Volker Krause 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 @@ -17,7 +17,6 @@ 02110-1301, USA. */ -#include "itemquery.h" #include "itemfetchjob.h" #include "itemmodel.h" #include "monitor.h" @@ -38,7 +37,7 @@ QString path; ItemFetchJob *listingJob; Monitor *monitor; - QList fetchJobs, updateJobs; + QList fetchJobs; }; Akonadi::ItemModel::ItemModel( QObject *parent ) : @@ -55,7 +54,6 @@ delete d->monitor; qDeleteAll( d->items ); qDeleteAll( d->fetchJobs ); - qDeleteAll( d->updateJobs ); delete d; } @@ -122,10 +120,8 @@ // stop all running jobs delete d->monitor; d->monitor = 0; - qDeleteAll( d->updateJobs ); - d->updateJobs.clear(); qDeleteAll( d->fetchJobs ); - d->updateJobs.clear(); + d->fetchJobs.clear(); delete d->listingJob; // start listing job d->listingJob = createFetchJob( path, this ); @@ -142,104 +138,72 @@ } else { d->items = d->listingJob->items(); reset(); - kDebug() << k_funcinfo << "################################" << d->items.count() << endl; } d->listingJob->deleteLater(); d->listingJob = 0; - // start monitor job - // TODO error handling - /*d->monitor = new Monitor( "folder=" + d->path ); - connect( d->monitor, SIGNAL( changed( const DataReference::List& ) ), - SLOT( messagesChanged( const DataReference::List& ) ) ); - connect( d->monitor, SIGNAL( added( const DataReference::List& ) ), - SLOT( messagesAdded( const DataReference::List& ) ) ); - connect( d->monitor, SIGNAL( removed( const DataReference::List& ) ), - SLOT( messagesRemoved( const DataReference::List& ) ) );*/ -// d->monitor->start(); + // start monitor + d->monitor = new Monitor( this ); + d->monitor->monitorCollection( d->path, false ); + connect( d->monitor, SIGNAL(itemChanged(Akonadi::DataReference)), + SLOT(itemChanged(Akonadi::DataReference)) ); + connect( d->monitor, SIGNAL(itemAdded(Akonadi::DataReference)), + SLOT(itemAdded(Akonadi::DataReference)) ); + connect( d->monitor, SIGNAL(itemRemoved(Akonadi::DataReference)), + SLOT(itemRemoved(Akonadi::DataReference)) ); } void Akonadi::ItemModel::fetchingNewDone( Akonadi::Job * job ) { - Q_ASSERT( d->fetchJobs.contains( static_cast( job ) ) ); + Q_ASSERT( d->fetchJobs.contains( static_cast( job ) ) ); if ( job->error() ) { // TODO kWarning() << k_funcinfo << "Fetching new items failed!" << endl; } else { - Item::List list = static_cast( job )->items(); - beginInsertRows( QModelIndex(), d->items.size(), d->items.size() + list.size() ); - d->items += list; - endInsertRows(); + Item::List list = static_cast( job )->items(); + if ( !list.isEmpty() ) { + beginInsertRows( QModelIndex(), d->items.size(), d->items.size() + list.size() ); + d->items += list; + endInsertRows(); + } else + kWarning() << k_funcinfo << "Got unexpected empty fetch response!" << endl; } - d->fetchJobs.removeAll( static_cast( job ) ); + d->fetchJobs.removeAll( static_cast( job ) ); job->deleteLater(); } -void Akonadi::ItemModel::fetchingUpdatesDone( Akonadi::Job * job ) +void ItemModel::itemChanged( const DataReference &reference ) { - Q_ASSERT( d->updateJobs.contains( static_cast( job ) ) ); - if ( job->error() ) { - // TODO - kWarning() << k_funcinfo << "Updating changed items failed!" << endl; - } else { - Item::List list = static_cast( job )->items(); - foreach ( Item* itm, list ) { - // ### *slow* - for ( int i = 0; i < d->items.size(); ++i ) { - if ( d->items.at( i )->reference() == itm->reference() ) { - delete d->items.at( i ); - d->items.replace( i, itm ); - emit dataChanged( index( i, 0 ), index( i, columnCount() ) ); - break; - } - } - } - } - d->updateJobs.removeAll( static_cast( job ) ); - job->deleteLater(); + itemRemoved( reference ); + itemAdded( reference ); } -void Akonadi::ItemModel::itemsChanged( const DataReference::List & references ) +void ItemModel::itemAdded( const DataReference &reference ) { - // TODO: build query based on the reference list - Q_UNUSED( references ); - QString query; - ItemQuery* job = new ItemQuery( query ); - connect( job, SIGNAL( done( Akonadi::Job* ) ), SLOT( fetchingUpdatesDone( Akonadi::Job* job ) ) ); + // TODO: make sure we don't fetch the complete data here! + ItemFetchJob *job = new ItemFetchJob( reference, this ); + connect( job, SIGNAL(done(Akonadi::Job*)), SLOT(fetchingNewDone(Akonadi::Job*)) ); job->start(); - d->updateJobs.append( job ); -} - -void Akonadi::ItemModel::itemsAdded( const DataReference::List & references ) -{ - // TODO: build query based on the reference list - Q_UNUSED( references ); - QString query; - ItemQuery* job = new ItemQuery( query ); - connect( job, SIGNAL( done( Akonadi::Job* ) ), SLOT( fetchingNewDone( Akonadi::Job* job ) ) ); - job->start(); d->fetchJobs.append( job ); } -void Akonadi::ItemModel::itemsRemoved( const DataReference::List & references ) +void ItemModel::itemRemoved( const DataReference &reference ) { - foreach ( DataReference ref, references ) { - // ### *slow* - int index = -1; - for ( int i = 0; i < d->items.size(); ++i ) { - if ( d->items.at( i )->reference() == ref ) { - index = i; - break; - } + // ### *slow* + int index = -1; + for ( int i = 0; i < d->items.size(); ++i ) { + if ( d->items.at( i )->reference() == reference ) { + index = i; + break; } - if ( index < 0 ) - continue; - beginRemoveRows( QModelIndex(), index, index ); - Item* itm = d->items.at( index ); - d->items.removeAt( index ); - delete itm; - endRemoveRows(); } + if ( index < 0 ) + return; + beginRemoveRows( QModelIndex(), index, index ); + Item* itm = d->items.at( index ); + d->items.removeAt( index ); + delete itm; + endRemoveRows(); } DataReference Akonadi::ItemModel::referenceForIndex( const QModelIndex & index ) const --- trunk/KDE/kdepim/akonadi/libakonadi/itemmodel.h #622649:622650 @@ -1,5 +1,5 @@ /* - Copyright (c) 2006 Volker Krause + Copyright (c) 2006 - 2007 Volker Krause 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 @@ -118,24 +118,19 @@ void fetchingNewDone( Akonadi::Job* job ); /** - Connected to message queries that handle changed messages. - */ - void fetchingUpdatesDone( Akonadi::Job* job ); - - /** Connected to the monitor job. */ - void itemsChanged( const DataReference::List &references ); + void itemChanged( const Akonadi::DataReference &reference ); /** Connected to the monitor job. */ - void itemsAdded( const DataReference::List &references ); + void itemAdded( const Akonadi::DataReference &reference ); /** Connected to the monitor job. */ - void itemsRemoved( const DataReference::List &references ); + void itemRemoved( const Akonadi::DataReference &reference ); private: class Private; --- trunk/KDE/kdepim/akonadi/libakonadi/messagemodel.cpp #622649:622650 @@ -20,7 +20,6 @@ #include "message.h" #include "messagefetchjob.h" #include "messagemodel.h" -#include "messagequery.h" #include "monitor.h" #include