~ubuntu-branches/ubuntu/precise/kdepim/precise-proposed

« back to all changes in this revision

Viewing changes to messagecore/imagecollector.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:51 UTC
  • mfrom: (0.2.20)
  • Revision ID: package-import@ubuntu.com-20111215141751-yg890pa7vnlo34e0
Tags: 4:4.7.90-0ubuntu1
new upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  -*- c++ -*-
 
2
 *    imagecollector.cpp
 
3
 * 
 
4
 *    This file is part of KMail, the KDE mail client.
 
5
 *    Copyright (c) 2004 Marc Mutz <mutz@kde.org>
 
6
 *    Copyright (c) 2011 Torgny Nyblom <nyblom@kde.org>
 
7
 * 
 
8
 *    KMail is free software; you can redistribute it and/or modify it
 
9
 *    under the terms of the GNU General Public License, version 2, as
 
10
 *    published by the Free Software Foundation.
 
11
 * 
 
12
 *    KMail is distributed in the hope that it will be useful, but
 
13
 *    WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 *    General Public License for more details.
 
16
 * 
 
17
 *    You should have received a copy of the GNU General Public License
 
18
 *    along with this program; if not, write to the Free Software
 
19
 *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
20
 * 
 
21
 *    In addition, as a special exception, the copyright holders give
 
22
 *    permission to link the code of this program with any edition of
 
23
 *    the Qt library by Trolltech AS, Norway (or with modified versions
 
24
 *    of Qt that use the same license as Qt), and distribute linked
 
25
 *    combinations including the two.  You must obey the GNU General
 
26
 *    Public License in all respects for all of the code used other than
 
27
 *    Qt.  If you modify this file, you may extend this exception to
 
28
 *    your version of the file, but you are not obligated to do so.  If
 
29
 *    you do not wish to do so, delete this exception statement from
 
30
 *    your version.
 
31
 */
 
32
 
 
33
 
 
34
#include "imagecollector.h"
 
35
 
 
36
#include "nodehelper.h"
 
37
 
 
38
#include <kdebug.h>
 
39
#include <kmime/kmime_content.h>
 
40
 
 
41
static bool isInSkipList( KMime::Content* )
 
42
{
 
43
  return false;
 
44
}
 
45
 
 
46
static bool isInExclusionList( KMime::Content * node )
 
47
{
 
48
  if ( !node )
 
49
    return true;
 
50
  
 
51
  if ( node->contentType()->mediaType() != "image" ) {
 
52
    return true;
 
53
  }
 
54
 
 
55
  if ( node->contentType()->isMultipart()) {
 
56
    return true;
 
57
  }
 
58
  
 
59
  return false;
 
60
}
 
61
 
 
62
class MessageCore::ImageCollector::Private
 
63
{
 
64
public:
 
65
  std::vector<KMime::Content*> mImages;
 
66
};
 
67
 
 
68
MessageCore::ImageCollector::ImageCollector()
 
69
: d( new Private )
 
70
{
 
71
}
 
72
 
 
73
MessageCore::ImageCollector::~ImageCollector()
 
74
{
 
75
  delete d;
 
76
}
 
77
 
 
78
void MessageCore::ImageCollector::collectImagesFrom( KMime::Content *node )
 
79
{
 
80
  KMime::Content *parent;
 
81
  
 
82
  while ( node ) {
 
83
    parent = node->parent();
 
84
    
 
85
    if ( node->topLevel()->textContent() == node ) {
 
86
      node = MessageCore::NodeHelper::next( node );
 
87
      continue;
 
88
    }
 
89
    
 
90
    if ( isInSkipList( node ) ) {
 
91
      node = MessageCore::NodeHelper::next( node, false ); // skip even the children
 
92
      continue;
 
93
    }
 
94
    
 
95
    if ( isInExclusionList( node ) ) {
 
96
      node = MessageCore::NodeHelper::next( node );
 
97
      continue;
 
98
    }
 
99
    
 
100
    if ( parent && parent->contentType()->isMultipart() &&
 
101
      parent->contentType()->subType() == "related" ) {
 
102
      kWarning() << "Adding image" << node->contentID();
 
103
      d->mImages.push_back( node );
 
104
      node = MessageCore::NodeHelper::next( node );  // skip embedded images
 
105
      continue;
 
106
    }
 
107
 
 
108
      node = MessageCore::NodeHelper::next( node );
 
109
  }
 
110
}
 
111
 
 
112
const std::vector<KMime::Content*>& MessageCore::ImageCollector::images() const
 
113
{
 
114
  return d->mImages;
 
115
}