[Kde-bindings] [kdepimlibs] akonadi/calendar: Add the ability to load only specific mime types.

Sergio Martins iamsergio at gmail.com
Mon Jun 17 20:15:55 UTC 2013


Git commit a5744ffd680d5f44e632cafc58b1e45a2b9b5a18 by Sergio Martins.
Committed on 17/06/2013 at 21:28.
Pushed by smartins into branch 'master'.

Add the ability to load only specific mime types.

Will save memory in plasma-clock, kontact-mobile, summary-view
etc, which don't need all 3 mime types ( events, journals, to-dos).

CCMAIL: kde-bindings at kde.org

M  +16   -4    akonadi/calendar/etmcalendar.cpp
M  +11   -1    akonadi/calendar/etmcalendar.h
M  +1    -0    akonadi/calendar/etmcalendar_p.h

http://commits.kde.org/kdepimlibs/a5744ffd680d5f44e632cafc58b1e45a2b9b5a18

diff --git a/akonadi/calendar/etmcalendar.cpp b/akonadi/calendar/etmcalendar.cpp
index 2fcd19d..724ad79 100644
--- a/akonadi/calendar/etmcalendar.cpp
+++ b/akonadi/calendar/etmcalendar.cpp
@@ -72,10 +72,15 @@ void ETMCalendarPrivate::init()
   monitor->setCollectionMonitored( Akonadi::Collection::root() );
   monitor->fetchCollection( true );
   monitor->setItemFetchScope( scope );
-  monitor->setMimeTypeMonitored( "text/calendar", true );
-  monitor->setMimeTypeMonitored( KCalCore::Event::eventMimeType(), true );
-  monitor->setMimeTypeMonitored( KCalCore::Todo::todoMimeType(), true );
-  monitor->setMimeTypeMonitored( KCalCore::Journal::journalMimeType(), true );
+
+  QStringList allMimeTypes;
+  allMimeTypes << KCalCore::Event::eventMimeType() << KCalCore::Todo::todoMimeType()
+               << KCalCore::Journal::journalMimeType();
+
+  foreach( const QString &mimetype, allMimeTypes ) {
+    monitor->setMimeTypeMonitored( mimetype, mMimeTypes.isEmpty() || mMimeTypes.contains(mimetype) );
+  }
+
   mETM = new CalendarModel( monitor, q );
   mETM->setObjectName( "ETM" );
 
@@ -424,6 +429,13 @@ ETMCalendar::ETMCalendar( QObject *parent ) : CalendarBase( new ETMCalendarPriva
   d->init();
 }
 
+ETMCalendar::ETMCalendar( const QStringList &mimeTypes, QObject *parent ) : CalendarBase( new ETMCalendarPrivate( this ), parent )
+{
+  Q_D( ETMCalendar );
+  d->mMimeTypes = mimeTypes;
+  d->init();
+}
+
 ETMCalendar::~ETMCalendar()
 {
 }
diff --git a/akonadi/calendar/etmcalendar.h b/akonadi/calendar/etmcalendar.h
index bfc7163..f2b1842 100644
--- a/akonadi/calendar/etmcalendar.h
+++ b/akonadi/calendar/etmcalendar.h
@@ -66,7 +66,17 @@ public:
   /**
     * Constructs a new ETMCalendar. Loading begins immediately, asynchronously.
     */
-  ETMCalendar( QObject *parent = 0 );
+  explicit ETMCalendar( QObject *parent = 0 );
+
+
+  /**
+   * Constructs a new ETMCalendar that will only load the specified mime types.
+   * Use this ctor to ignore journals or to-dos for example.
+   * If no mime types are specified, all mime types will be used.
+   *
+   * @since 4.12
+   */
+  explicit ETMCalendar( const QStringList &mimeTypes, QObject *parent = 0 );
 
   /**
     * Destroys this ETMCalendar.
diff --git a/akonadi/calendar/etmcalendar_p.h b/akonadi/calendar/etmcalendar_p.h
index f3cc0a8..3b706dc 100644
--- a/akonadi/calendar/etmcalendar_p.h
+++ b/akonadi/calendar/etmcalendar_p.h
@@ -136,6 +136,7 @@ public:
   KSelectionProxyModel *mSelectionProxy;
   bool mCollectionFilteringEnabled;
   QSet<Akonadi::Collection::Id> mPopulatedCollectionIds;
+  QStringList mMimeTypes;
 private:
   ETMCalendar *const q;
 };


More information about the Kde-bindings mailing list