[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdepim/akonadi/server
From: Volker Krause <volker.krause () rwth-aachen ! de>
Date: 2006-09-30 17:44:10
Message-ID: 1159638250.270410.12671.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 590736 by vkrause:
Let the DataStore handle persistent searches as well.
M +4 -4 CMakeLists.txt
M +55 -63 src/handler/searchpersistent.cpp
M +7 -1 src/handler/searchpersistent.h
M +1 -1 src/persistentsearchmanager.h
M +2 -2 src/searchprovider.h
M +4 -3 src/searchprovidermanager.cpp
M +65 -7 src/storage/datastore.cpp
M +6 -5 src/storage/datastore.h
M +13 -0 src/storage/entity.cpp
M +17 -0 src/storage/entity.h
--- trunk/KDE/kdepim/akonadi/server/CMakeLists.txt #590735:590736
@@ -47,11 +47,11 @@
src/handler/storequery.cpp
src/handler/transaction.cpp
src/handler/uid.cpp
- src/persistentsearch.cpp
- src/persistentsearchmanager.cpp
- src/searchprovider.cpp
+# src/persistentsearch.cpp
+# src/persistentsearchmanager.cpp
+# src/searchprovider.cpp
src/searchprovidermanager.cpp
- src/searchproviders/emailsearchprovider.cpp
+# src/searchproviders/emailsearchprovider.cpp
src/storage/entity.cpp
src/storage/datastore.cpp
src/storage/dbinitializer.cpp
--- trunk/KDE/kdepim/akonadi/server/src/handler/searchpersistent.cpp #590735:590736
@@ -18,15 +18,14 @@
***************************************************************************/
#include "akonadi.h"
-#include "handlerhelper.h"
+#include "akonadiconnection.h"
+#include "searchpersistent.h"
+#include "imapparser.h"
#include "response.h"
-#include "persistentsearch.h"
-#include "persistentsearchmanager.h"
-#include "searchhelper.h"
-#include "searchprovidermanager.h"
+#include "storage/datastore.h"
+#include "storage/entity.h"
+#include "storage/transaction.h"
-#include "searchpersistent.h"
-
using namespace Akonadi;
SearchPersistent::SearchPersistent()
@@ -40,69 +39,62 @@
bool SearchPersistent::handleLine( const QByteArray& line )
{
- Response response;
- response.setUntagged();
+ int pos = line.indexOf( ' ' ) + 1; // skip tag
+ QByteArray command;
+ pos = ImapParser::parseString( line, command, pos );
- QList<QByteArray> junks = HandlerHelper::splitLine( line );
+ QString collectionName;
+ pos = ImapParser::parseString( line, collectionName, pos );
+ if ( collectionName.isEmpty() )
+ return failureResponse( "No name specified" );
- /**
- * A persistent search can have the following forms:
- *
- * 123 SEARCH_STORE <name> <criterion1> <criterion2> ...
- * or
- * 123 SEARCH_DELETE <name>
- *
- * so we first have to find out which case matches.
- */
- if ( junks[ 1 ].toUpper() == "SEARCH_STORE" ) {
- if ( junks.count() < 4 ) {
- response.setTag( tag() );
- response.setError();
- response.setString( "Too few arguments" );
- emit responseAvailable( response );
- } else {
- QByteArray mimeType = SearchHelper::extractMimetype( junks, 3 );
+ DataStore *db = connection()->storageBackend();
+ Transaction transaction( db );
- SearchProvider *provider = \
SearchProviderManager::self()->createSearchProviderForMimetype( \
mimeType );
- PersistentSearch *persistentSearch = new PersistentSearch( junks.mid( 3 ), \
provider ); + if ( command.toUpper() == "SEARCH_STORE" ) {
- QString identifier = QString::fromUtf8( junks[ 2 ] );
- PersistentSearchManager::self()->addPersistentSearch( identifier, \
persistentSearch ); + PersistentSearch search = db->persistentSearch( \
collectionName ); + if ( search.isValid() )
+ return failureResponse( "Persistent search does already exist" );
- response.setTag( tag() );
- response.setSuccess();
- response.setString( "SEARCH_STORE completed" );
- emit responseAvailable( response );
- }
- } else if ( junks[ 1 ].toUpper() == "SEARCH_DELETE" ) {
- if ( junks.count() < 3 ) {
- response.setTag( tag() );
- response.setError();
- response.setString( "Too few arguments" );
- emit responseAvailable( response );
- } else {
- QString identifier = QString::fromUtf8( junks[ 2 ] );
- PersistentSearchManager::self()->removePersistentSearch( identifier );
+ QByteArray mimeType;
+ pos = ImapParser::parseString( line, mimeType, pos );
+ if ( mimeType.isEmpty() )
+ return failureResponse( "No mimetype specified" );
- response.setTag( tag() );
- response.setSuccess();
- response.setString( "SEARCH_DELETE completed" );
- emit responseAvailable( response );
- }
- } else if ( junks[ 1 ].toUpper() == "SEARCH_DEBUG" ) {
- CollectionList collections = PersistentSearchManager::self()->collections();
- for ( int i = 0; i < collections.count(); ++i ) {
- response.setString( collections[ i ].identifier().toLatin1() );
- emit responseAvailable( response );
- }
+ MimeType mt = db->mimeTypeByName( QString::fromUtf8(mimeType) );
+ if ( !mt.isValid() )
+ return failureResponse( "Invalid mimetype" );
- response.setTag( tag() );
- response.setSuccess();
- response.setString( "SEARCH_DEBUG completed" );
- emit responseAvailable( response );
- }
+ QByteArray queryString;
+ ImapParser::parseString( line, queryString, pos );
+ if ( queryString.isEmpty() )
+ return failureResponse( "No query specified" );
- deleteLater();
+ if ( !db->appendPersisntentSearch( collectionName, queryString ) )
+ return failureResponse( "Unable to create persistent search" );
- return true;
+ } else if ( command.toUpper() == "SEARCH_DELETE" ) {
+
+ PersistentSearch search = db->persistentSearch( collectionName );
+ if ( !search.isValid() )
+ return failureResponse( "No such persistent search" );
+ if ( !db->removePersistentSearch( search ) )
+ return failureResponse( "Unable to remove presistent search" );
+
+ } else {
+ return failureResponse( "Unknwon command" );
+ }
+
+ if ( !transaction.commit() )
+ return failureResponse( "Unable to commit transaction" );
+
+ Response response;
+ response.setTag( tag() );
+ response.setSuccess();
+ response.setString( command + " completed" );
+ emit responseAvailable( response );
+
+ deleteLater();
+ return true;
}
--- trunk/KDE/kdepim/akonadi/server/src/handler/searchpersistent.h #590735:590736
@@ -26,7 +26,13 @@
/**
Handler for the search_store search_delete commands.
- */
+
+ A persistent search can have the following forms:
+
+ 123 SEARCH_STORE <name> "<mimetype>" "<query>"
+ or
+ 123 SEARCH_DELETE <name>
+*/
class SearchPersistent : public Handler
{
public:
--- trunk/KDE/kdepim/akonadi/server/src/persistentsearchmanager.h #590735:590736
@@ -25,11 +25,11 @@
#include <QtSql/QSqlDatabase>
#include "collection.h"
-#include "persistentsearch.h"
namespace Akonadi {
class DataStore;
+class PersistentSearch;
class PersistentSearchManager
{
--- trunk/KDE/kdepim/akonadi/server/src/searchprovider.h #590735:590736
@@ -22,10 +22,10 @@
#include <QtCore/QList>
-#include "storage/datastore.h"
-
namespace Akonadi {
+class DataStore;
+
class SearchProvider
{
public:
--- trunk/KDE/kdepim/akonadi/server/src/searchprovidermanager.cpp #590735:590736
@@ -20,6 +20,7 @@
#include "emailsearchprovider.h"
#include "searchprovidermanager.h"
+#include <QByteArray>
using namespace Akonadi;
@@ -45,9 +46,9 @@
{
SearchProvider *provider = 0;
- if ( mimeType == "message/rfc822" || mimeType == "message/news" ) {
- provider = new EmailSearchProvider;
- }
+// if ( mimeType == "message/rfc822" || mimeType == "message/news" ) {
+// provider = new EmailSearchProvider;
+// }
return provider;
}
--- trunk/KDE/kdepim/akonadi/server/src/storage/datastore.cpp #590735:590736
@@ -36,7 +36,6 @@
#include "dbinitializer.h"
#include "dbusthread.h"
#include "notificationmanager.h"
-#include "persistentsearchmanager.h"
#include "tracer.h"
#include "datastore.h"
@@ -115,10 +114,6 @@
}
}
-QSqlDatabase Akonadi::DataStore::database() const
-{
- return m_database;
-}
QString DataStore::storagePath()
{
@@ -249,13 +244,13 @@
// list queries (only in global namespace)
if ( !resource.isValid() ) {
if ( fullPrefix == locationDelimiter() ) {
- CollectionList persistenSearches = \
PersistentSearchManager::self()->collections(); + CollectionList \
persistenSearches = listPersistentSearches(); if ( !persistenSearches.isEmpty() )
result.append( Collection( QLatin1String("Search") ) );
result.setValid( true );
}
if ( fullPrefix == QLatin1String("/Search/") || (fullPrefix == \
locationDelimiter() && hasStar) ) {
- result += PersistentSearchManager::self()->collections();
+ result += listPersistentSearches();
result.setValid( true );
}
}
@@ -1836,6 +1831,69 @@
}
+
+bool Akonadi::DataStore::appendPersisntentSearch(const QString & name, const \
QByteArray & queryString) +{
+ if ( !m_dbOpened ) return false;
+
+ QSqlQuery query( m_database );
+ query.prepare( QLatin1String("INSERT INTO PersistentSearches (name, query) VALUES \
(:name, :query)") ); + query.bindValue( QLatin1String(":name"), name );
+ query.bindValue( QLatin1String(":query"), queryString );
+
+ if ( !query.exec() ) {
+ debugLastQueryError( query, "Unable to append persistent search" );
+ return false;
+ }
+
+ mNotificationCollector->collectionAdded( name );
+ return true;
+}
+
+bool Akonadi::DataStore::removePersistentSearch( const PersistentSearch &search )
+{
+ // TODO
+// mNotificationCollector->collectionRemoved( search.name() );
+ return removeById( search.id(), QLatin1String("PersistentSearches") );
+}
+
+PersistentSearch Akonadi::DataStore::persistentSearch(const QString & name)
+{
+ if ( !m_dbOpened ) return PersistentSearch();
+
+ QSqlQuery query( m_database );
+ query.prepare( QLatin1String("SELECT id, name, query FROM PersistentSearches WHERE \
name = :name") ); + query.bindValue( QLatin1String(":name"), name );
+
+ if ( !query.exec() || !query.next() ) {
+ debugLastQueryError( query, "Error during selection of persistent search" );
+ return PersistentSearch();
+ }
+
+ int id = query.value( 0 ).toInt();
+ QString searchName = query.value( 1 ).toString();
+ QByteArray queryString = query.value( 2 ).toByteArray();
+
+ return PersistentSearch( id, searchName, queryString );
+}
+
+CollectionList Akonadi::DataStore::listPersistentSearches() const
+{
+ QSqlQuery query( m_database );
+ query.prepare( QLatin1String("SELECT name FROM PersistentSearches") );
+ if ( query.exec() ) {
+ CollectionList list;
+ while ( query.next() ) {
+ QString name = query.value( 0 ).toString();
+ list.append( QLatin1String("Search/") + name );
+ }
+ return list;
+ }
+ return CollectionList();
+}
+
+
+
void DataStore::debugLastDbError( const char* actionDescription ) const
{
qDebug() << actionDescription
--- trunk/KDE/kdepim/akonadi/server/src/storage/datastore.h #590735:590736
@@ -68,11 +68,6 @@
*/
void init();
- /**
- Returns the database object. Can be used for executing queries.
- */
- QSqlDatabase database() const;
-
/* -- higher level API -- */
virtual CollectionList listCollections( const QString& prefix,
const QString& mailboxPattern ) const;
@@ -215,6 +210,12 @@
QList<Resource> listResources() const;
QList<Resource> listResources( const CachePolicy & policy );
+ /* --- Persistent search --------------------------------------------- */
+ bool appendPersisntentSearch( const QString &name, const QByteArray &queryString \
); + bool removePersistentSearch( const PersistentSearch &search );
+ PersistentSearch persistentSearch( const QString &name );
+ CollectionList listPersistentSearches() const;
+
/* --- Helper functions ---------------------------------------------- */
/** Returns the id of the next PIM item that is added to the db.
@return possible id of the next PIM item that is added to the database
--- trunk/KDE/kdepim/akonadi/server/src/storage/entity.cpp #590735:590736
@@ -447,5 +447,18 @@
}
+
+Akonadi::PersistentSearch::PersistentSearch() : Entity()
+{
+}
+
+Akonadi::PersistentSearch::PersistentSearch(int id, const QString &name, const \
QByteArray & query) : + Entity( id ),
+ m_name( name ),
+ m_query( query )
+{
+}
+
+
// namespace Akonadi
--- trunk/KDE/kdepim/akonadi/server/src/storage/entity.h #590735:590736
@@ -292,6 +292,23 @@
friend class DataStore;
};
+/**
+ Represents a persistent search aka virtual folder.
+*/
+class PersistentSearch : public Entity
+{
+ public:
+ PersistentSearch();
+ PersistentSearch( int id, const QString &name, const QByteArray &query );
+
+ QString name() const { return m_name; }
+ QByteArray query() const { return m_query; }
+
+ private:
+ QString m_name;
+ QByteArray m_query;
+};
+
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic