Attachment 'kmail_implementation.diff'

Download

   1 Index: kmail/mailmanagerimpl.cpp
   2 ===================================================================
   3 --- kmail/mailmanagerimpl.cpp	(revision 0)
   4 +++ kmail/mailmanagerimpl.cpp	(revision 0)
   5 @@ -0,0 +1,201 @@
   6 +/*  -*- mode: C++; c-file-style: "gnu" -*-
   7 + *
   8 + *  This file is part of KMail, the KDE mail client.
   9 + *  Copyright (c) 2009 Philip Van Hoof <philip@codeminded.be>
  10 + *
  11 + *  KMail is free software; you can redistribute it and/or modify it
  12 + *  under the terms of the GNU General Public License as published by
  13 + *  the Free Software Foundation; either version 2 of the License,
  14 + *  or (at your option) any later version.
  15 + *
  16 + *  KMail is distributed in the hope that it will be useful, but
  17 + *  WITHOUT ANY WARRANTY; without even the implied warranty of
  18 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19 + *  General Public License for more details.
  20 + *
  21 + *  You should have received a copy of the GNU General Public License
  22 + *  along with this program; if not, write to the Free Software
  23 + *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  24 + *
  25 + *  In addition, as a special exception, the copyright holders give
  26 + *  permission to link the code of this program with any edition of
  27 + *  the Qt library by Trolltech AS, Norway (or with modified versions
  28 + *  of Qt that use the same license as Qt), and distribute linked
  29 + *  combinations including the two.  You must obey the GNU General
  30 + *  Public License in all respects for all of the code used other than
  31 + *  Qt.  If you modify this file, you may extend this exception to
  32 + *  your version of the file, but you are not obligated to do so.  If
  33 + *  you do not wish to do so, delete this exception statement from
  34 + *  your version.
  35 + */
  36 +
  37 +#include <iostream>
  38 +#include <time.h>
  39 +
  40 +#include "mailmanagerimpl.h"
  41 +#include "mailmanagerimpl.moc"
  42 +#include <manageradaptor.h>
  43 +#include "composer.h"
  44 +
  45 +#include "kmmessage.h"
  46 +#include "kmmsgpart.h"
  47 +#include "kmfolder.h"
  48 +
  49 +#include <kurl.h>
  50 +#include <kdebug.h>
  51 +#include <QString>
  52 +#include <QDBusConnection>
  53 +
  54 +static const uint max_per_dbus_call = 1000;
  55 +
  56 +namespace KMail {
  57 +
  58 +
  59 +MailManagerImpl::MailManagerImpl()
  60 +{
  61 +  new ManagerAdaptor( this );
  62 +  QDBusConnection::sessionBus().registerObject( "/org/freedesktop/email/metadata/Manager", this );
  63 +}
  64 +
  65 +void MailManagerImpl::processMsgBase( const KMMsgBase *msg, QStringList &subjects, QVector<QStringList> &predicatesArray, QVector<QStringList> &valuesArray )
  66 +{
  67 +  QStringList values;
  68 +  QStringList predicates;
  69 +
  70 +  predicates.append( "EMailMeta:MessageSubject" );
  71 +  values.append( msg->subject() );
  72 +
  73 +  predicates.append( "EMailMeta:MessageFrom" );
  74 +  values.append( msg->fromStrip () );
  75 +
  76 +  predicates.append( "EMailMeta:MessageTo" );
  77 +  values.append( msg->toStrip () );
  78 +
  79 +  predicates.append( "KMail:MessageIdMD5" );
  80 +  values.append( msg->msgIdMD5() );
  81 +
  82 +  predicates.append( "KMail:MessageSerNum" );
  83 +  values.append( QString::number( msg->getMsgSerNum() ) );
  84 +
  85 +  predicates.append( "EMailMeta:MessageSent" );
  86 +  values.append( msg->dateStr () );
  87 +
  88 +  predicates.append( "EMailMeta:MessageSent" );
  89 +  values.append( msg->dateStr () );
  90 +
  91 +  predicates.append( "EMailMeta:MessageSize" );
  92 +  values.append( QString::number( static_cast<uint> ( msg->msgSizeServer() ) ) );
  93 +
  94 +  predicates.append( "KMail:MessageUID" );
  95 +  values.append( QString::number(static_cast<uint> ( msg->UID() ) ) );
  96 +
  97 +  for ( KMMessageTagList::const_iterator it = msg->tagList()->constBegin(); it != msg->tagList()->constEnd(); ++it ) {
  98 +    QString tag = (*it);
  99 +    predicates.append( "KMail:MessageTag" );
 100 +    values.append( tag );
 101 +  }
 102 +
 103 +  const MessageStatus &stat = msg->messageStatus();
 104 +
 105 +  predicates.append( "EMailMeta:MessageSeen" );
 106 +  if (stat.isRead())
 107 +    values.append( "True" );
 108 +  else
 109 +    values.append( "False" );
 110 +
 111 +  predicates.append( "KMail:MessageSpam" );
 112 +  if ( stat.isSpam() )
 113 +    values.append( "True" );
 114 +  else
 115 +    values.append( "False" );
 116 +
 117 +  predicates.append( "KMail:MessageHam" );
 118 +  if ( stat.isHam() )
 119 +    values.append( "True" );
 120 +  else
 121 +    values.append( "False" );
 122 +
 123 +  predicates.append( "EMailMeta:MessageAnswered" );
 124 +  if ( stat.isReplied() )
 125 +    values.append( "True" );
 126 +  else
 127 +    values.append( "False" );
 128 +
 129 +  predicates.append( "EMailMeta:MessageForwarded" );
 130 +  if ( stat.isForwarded() )
 131 +    values.append( "True" );
 132 +  else
 133 +    values.append( "False" );
 134 +
 135 +  subjects.append( "kmail://" + QString::number( msg->getMsgSerNum() ) );
 136 +  predicatesArray.append( predicates );
 137 +  valuesArray.append( values );
 138 +}
 139 +
 140 +void MailManagerImpl::Register( const QDBusObjectPath &registrarPath, uint lastModseq )
 141 +{
 142 +  registrars.append( registrarPath );
 143 +
 144 +  QDBusMessage m = QDBusMessage::createMethodCall( message().service(),
 145 +                     registrarPath.path(),
 146 +                     "org.freedesktop.email.metadata.Registrar", "Cleanup" );
 147 +  QList<QVariant> args;
 148 +  args.append ( static_cast<uint> ( time( 0 ) ) );
 149 +  m.setArguments( args );
 150 +  QDBusConnection::sessionBus().send( m );
 151 +
 152 +  QList< QPointer< KMFolder > > folders = kmkernel->allFolders();
 153 +  QList< QPointer< KMFolder > >::Iterator it = folders.begin();
 154 +
 155 +  while ( it != folders.end() ) {
 156 +    uint i = 0;
 157 +
 158 +    KMFolder *folder = (*it);
 159 +    ++it;
 160 +
 161 +    folder->open("DBus");
 162 +
 163 +    uint fcount = folder->count();
 164 +
 165 +    while ( i < fcount ) {
 166 +
 167 +      QVector<QStringList> predicatesArray;
 168 +      QVector<QStringList> valuesArray;
 169 +      QStringList subjects;
 170 +
 171 +      uint processed = 0;
 172 +
 173 +      for ( ; i < fcount; ++i ) {
 174 +        const KMMsgBase *msg = folder->getMsgBase( i );
 175 +
 176 +        processMsgBase( msg, subjects, predicatesArray, valuesArray );
 177 +        processed++;
 178 +
 179 +        if ( processed >= max_per_dbus_call )
 180 +          break;
 181 +      }
 182 +
 183 +      if (!subjects.isEmpty()) {
 184 +        QDBusMessage m = QDBusMessage::createMethodCall( message().service(),
 185 +                                registrarPath.path(),
 186 +                                "org.freedesktop.email.metadata.Registrar", "SetMany" );
 187 +        QList<QVariant> args;
 188 +
 189 +        args.append( subjects );
 190 +        args.append( qVariantFromValue( predicatesArray ) );
 191 +        args.append( qVariantFromValue( valuesArray ) );
 192 +        args.append( static_cast<uint> ( time( 0 ) ) );
 193 +
 194 +        m.setArguments( args );
 195 +
 196 +        QDBusConnection::sessionBus().send( m );
 197 +      }
 198 +    }
 199 +
 200 +    folder->close( "DBus", false );
 201 +  }
 202 +}
 203 +
 204 +
 205 +}//end namespace KMail
 206 +
 207 Index: kmail/kmkernel.cpp
 208 ===================================================================
 209 --- kmail/kmkernel.cpp	(revision 917233)
 210 +++ kmail/kmkernel.cpp	(working copy)
 211 @@ -46,6 +46,8 @@
 212  #include "kmailicalifaceimpl.h"
 213  #include "mailserviceimpl.h"
 214  using KMail::MailServiceImpl;
 215 +#include "mailmanagerimpl.h"
 216 +using KMail::MailManagerImpl;
 217  #include "jobscheduler.h"
 218  #include "templateparser.h"
 219  using KMail::TemplateParser;
 220 @@ -72,6 +74,7 @@
 221  #include <QObject>
 222  #include <QWidget>
 223  #include <QFileInfo>
 224 +#include <QtDBus/QtDBus>
 225  
 226  #include <sys/types.h>
 227  #include <dirent.h>
 228 @@ -97,7 +100,7 @@
 229  KMKernel::KMKernel (QObject *parent, const char *name) :
 230    QObject(parent),
 231    mIdentityManager(0), mConfigureDialog(0), mICalIface(0), mMailService(0),
 232 -  mContextMenuShown( false ), mWallet( 0 )
 233 +  mMailManager( 0 ), mContextMenuShown( false ), mWallet( 0 )
 234  {
 235    kDebug(5006);
 236    setObjectName( name );
 237 @@ -185,6 +188,8 @@
 238    mICalIface = 0;
 239    delete mMailService;
 240    mMailService = 0;
 241 +  delete mMailManager;
 242 +  mMailManager = 0;
 243  
 244    GlobalSettings::self()->writeConfig();
 245    delete mWallet;
 246 @@ -196,10 +201,12 @@
 247  void KMKernel::setupDBus()
 248  {
 249    (void) new KmailAdaptor( this );
 250 +  qDBusRegisterMetaType<QVector<QStringList> >();
 251    QDBusConnection::sessionBus().registerObject( "/KMail", this );
 252    mICalIface->registerWithDBus();
 253    mICalIface->readConfig();
 254    mMailService =  new MailServiceImpl();
 255 +  mMailManager =  new MailManagerImpl();
 256  }
 257  
 258  bool KMKernel::handleCommandLine( bool noArgsOpensReader )
 259 Index: kmail/mailmanagerimpl.h
 260 ===================================================================
 261 --- kmail/mailmanagerimpl.h	(revision 0)
 262 +++ kmail/mailmanagerimpl.h	(revision 0)
 263 @@ -0,0 +1,58 @@
 264 +/*  -*- mode: C++; c-file-style: "gnu" -*-
 265 + *
 266 + *  This file is part of KMail, the KDE mail client.
 267 + *  Copyright (c) 2009 Philip Van Hoof <philip@codeminded.be>
 268 + *
 269 + *  KMail is free software; you can redistribute it and/or modify it
 270 + *  under the terms of the GNU General Public License as published by
 271 + *  the Free Software Foundation; either version 2 of the License,
 272 + *  or (at your option) any later version.
 273 + *
 274 + *  KMail is distributed in the hope that it will be useful, but
 275 + *  WITHOUT ANY WARRANTY; without even the implied warranty of
 276 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 277 + *  General Public License for more details.
 278 + *
 279 + *  You should have received a copy of the GNU General Public License
 280 + *  along with this program; if not, write to the Free Software
 281 + *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 282 + *
 283 + *  In addition, as a special exception, the copyright holders give
 284 + *  permission to link the code of this program with any edition of
 285 + *  the Qt library by Trolltech AS, Norway (or with modified versions
 286 + *  of Qt that use the same license as Qt), and distribute linked
 287 + *  combinations including the two.  You must obey the GNU General
 288 + *  Public License in all respects for all of the code used other than
 289 + *  Qt.  If you modify this file, you may extend this exception to
 290 + *  your version of the file, but you are not obligated to do so.  If
 291 + *  you do not wish to do so, delete this exception statement from
 292 + *  your version.
 293 + */
 294 +#ifndef MAILMANAGERIMPL_H
 295 +#define MAILMANAGERIMPL_H
 296 +
 297 +class QString;
 298 +#include <QObject>
 299 +#include <QtDBus/QtDBus>
 300 +
 301 +#include "kmkernel.h"
 302 +
 303 +namespace KMail {
 304 +
 305 +  // This class implements the D-Bus interface
 306 +  // libkdepim/interfaces/org.freedesktop.email.metadata.Manager.xml
 307 +  class MailManagerImpl : public QObject,
 308 +                          protected QDBusContext
 309 +  {
 310 +    Q_OBJECT
 311 +  private:
 312 +    QList< QDBusObjectPath > registrars;
 313 +    void processMsgBase ( const KMMsgBase *msg, QStringList &subjects, QVector<QStringList> &predicatesArray, QVector<QStringList> &valuesArray );
 314 +
 315 +  public:
 316 +    MailManagerImpl();
 317 +    void Register( const QDBusObjectPath &registrarPath, uint lastModseq );
 318 +  };
 319 +}
 320 +
 321 +#endif
 322 Index: kmail/kmkernel.h
 323 ===================================================================
 324 --- kmail/kmkernel.h	(revision 917233)
 325 +++ kmail/kmkernel.h	(working copy)
 326 @@ -23,6 +23,8 @@
 327  #define kmkernel KMKernel::self()
 328  #define kmconfig KMKernel::config()
 329  
 330 +Q_DECLARE_METATYPE(QVector<QStringList>)
 331 +
 332  namespace KIO {
 333    class Job;
 334  }
 335 @@ -37,6 +39,7 @@
 336  */
 337  namespace KMail {
 338    class MailServiceImpl;
 339 +  class MailManagerImpl;
 340    class UndoStack;
 341    class JobScheduler;
 342    class MessageSender;
 343 @@ -45,6 +48,7 @@
 344  }
 345  namespace KPIM { class ProgressDialog; }
 346  using KMail::MailServiceImpl;
 347 +using KMail::MailManagerImpl;
 348  using KMail::AccountManager;
 349  using KMail::UndoStack;
 350  using KMail::JobScheduler;
 351 @@ -496,6 +500,7 @@
 352    // temporary mainwin
 353    KMMainWin *mWin;
 354    MailServiceImpl *mMailService;
 355 +  MailManagerImpl *mMailManager;
 356  
 357    // the time of the last change of the unread or total count of a folder;
 358    // this can be queried via D-Bus in order to determine whether the counts
 359 Index: kmail/CMakeLists.txt
 360 ===================================================================
 361 --- kmail/CMakeLists.txt	(revision 917233)
 362 +++ kmail/CMakeLists.txt	(working copy)
 363 @@ -172,6 +172,7 @@
 364     kmailicalifaceimpl.cpp
 365     aboutdata.cpp
 366     mailserviceimpl.cpp
 367 +   mailmanagerimpl.cpp
 368     attachmentlistview.cpp
 369     kmcomposereditor.cpp
 370     kmlineeditspell.cpp
 371 @@ -282,6 +283,10 @@
 372    ${CMAKE_SOURCE_DIR}/libkdepim/interfaces/org.kde.mailtransport.service.xml mailserviceimpl.h
 373    KMail::MailServiceImpl
 374  )
 375 +qt4_add_dbus_adaptor(kmailprivate_LIB_SRCS
 376 +  ${CMAKE_SOURCE_DIR}/libkdepim/interfaces/org.freedesktop.email.metadata.Manager.xml mailmanagerimpl.h
 377 +  KMail::MailManagerImpl
 378 +)
 379  
 380  qt4_add_dbus_interfaces(kmailprivate_LIB_SRCS
 381    ${CMAKE_BINARY_DIR}/kmail/org.kde.kmail.kmail.xml
 382 Index: libkdepim/interfaces/org.freedesktop.email.metadata.Manager.xml
 383 ===================================================================
 384 --- libkdepim/interfaces/org.freedesktop.email.metadata.Manager.xml	(revision 0)
 385 +++ libkdepim/interfaces/org.freedesktop.email.metadata.Manager.xml	(revision 0)
 386 @@ -0,0 +1,10 @@
 387 +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
 388 +"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
 389 +<node>
 390 +  <interface name="org.freedesktop.email.metadata.Manager">
 391 +    <method name="Register">
 392 +      <arg type="o" name="registrar_path" direction="in" />
 393 +      <arg type="u" name="last_modseq" direction="in" />
 394 +    </method>
 395 +  </interface>
 396 +</node>
 397 

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2021-02-25 09:43:14, 112.9 KB) [[attachment:implementation.diff]]
  • [get | view] (2021-02-25 09:43:14, 12.7 KB) [[attachment:kmail_implementation.diff]]
  • [get | view] (2021-02-25 09:43:14, 4.7 KB) [[attachment:valaclientsample.vala]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.