Make me trust this output by using the original enums.
[kdepim.git] / kaddressbook / globalcontactmodel.cpp
blobf73624ebbc7ee994006e9fd1651725aeec08074d
1 /*
2 This file is part of KAddressBook.
4 Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "globalcontactmodel.h"
23 #include <akonadi/changerecorder.h>
24 #include <akonadi/contact/contactstreemodel.h>
25 #include <akonadi/entitydisplayattribute.h>
26 #include <akonadi/itemfetchscope.h>
27 #include <akonadi/session.h>
28 #include <kabc/addressee.h>
29 #include <kabc/contactgroup.h>
30 #include <klocale.h>
32 GlobalContactModel* GlobalContactModel::mInstance = 0;
34 GlobalContactModel::GlobalContactModel()
36 mSession = new Akonadi::Session( "KAddressBook::GlobalContactSession" );
38 Akonadi::ItemFetchScope scope;
39 scope.fetchFullPayload( true );
40 scope.fetchAttribute<Akonadi::EntityDisplayAttribute>();
42 mMonitor = new Akonadi::ChangeRecorder;
43 mMonitor->setSession(mSession);
44 mMonitor->fetchCollection( true );
45 mMonitor->setItemFetchScope( scope );
46 mMonitor->setCollectionMonitored( Akonadi::Collection::root() );
47 mMonitor->setMimeTypeMonitored( KABC::Addressee::mimeType(), true );
48 mMonitor->setMimeTypeMonitored( KABC::ContactGroup::mimeType(), true );
50 mModel = new Akonadi::ContactsTreeModel( mMonitor );
53 GlobalContactModel::~GlobalContactModel()
55 delete mModel;
56 delete mMonitor;
57 delete mSession;
60 GlobalContactModel* GlobalContactModel::instance()
62 if ( !mInstance )
63 mInstance = new GlobalContactModel();
65 return mInstance;
68 Akonadi::ContactsTreeModel* GlobalContactModel::model() const
70 return mModel;