• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

messageviewer

  • sources
  • kde-4.14
  • kdepim
  • messageviewer
  • viewer
  • mimeparttree
mimeparttreeview.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2014-2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "mimeparttreeview.h"
19 #include "mimetreemodel.h"
20 #include "settings/globalsettings.h"
21 
22 #include <KMime/Content>
23 
24 #include <KConfigGroup>
25 #include <QHeaderView>
26 
27 using namespace MessageViewer;
28 
29 MimePartTreeView::MimePartTreeView(QWidget *parent)
30  : QTreeView(parent)
31 {
32  setObjectName( QLatin1String("mMimePartTree") );
33 
34  mMimePartModel = new MimeTreeModel( this );
35  setModel( mMimePartModel );
36  setSelectionMode( QAbstractItemView::ExtendedSelection );
37  setSelectionBehavior( QAbstractItemView::SelectRows );
38  connect(this, SIGNAL(destroyed(QObject*)), this, SLOT(slotMimePartDestroyed()) );
39  setContextMenuPolicy(Qt::CustomContextMenu);
40  header()->setResizeMode( QHeaderView::ResizeToContents );
41  connect(mMimePartModel,SIGNAL(modelReset()),this,SLOT(expandAll()));
42  restoreMimePartTreeConfig();
43 }
44 
45 MimePartTreeView::~MimePartTreeView()
46 {
47  saveMimePartTreeConfig();
48 }
49 
50 MimeTreeModel *MimePartTreeView::mimePartModel() const
51 {
52  return mMimePartModel;
53 }
54 
55 void MimePartTreeView::restoreMimePartTreeConfig()
56 {
57  KConfigGroup grp( GlobalSettings::self()->config(), "MimePartTree" );
58  header()->restoreState( grp.readEntry( "State", QByteArray() ) );
59 }
60 
61 void MimePartTreeView::saveMimePartTreeConfig()
62 {
63  KConfigGroup grp( GlobalSettings::self()->config(), "MimePartTree" );
64  grp.writeEntry( "State", header()->saveState() );
65 }
66 
67 void MimePartTreeView::slotMimePartDestroyed()
68 {
69  //root is either null or a modified tree that we need to clean up
70  clearModel();
71 }
72 
73 
74 void MimePartTreeView::clearModel()
75 {
76  delete mMimePartModel->root();
77  mMimePartModel->setRoot(0);
78 }
79 
80 void MimePartTreeView::setRoot(KMime::Content *root)
81 {
82  delete mMimePartModel->root();
83  mMimePartModel->setRoot( root );
84 }
85 
86 KMime::Content::List MimePartTreeView::selectedContents()
87 {
88  KMime::Content::List contents;
89  QItemSelectionModel *selectModel = selectionModel();
90  QModelIndexList selectedRows = selectModel->selectedRows();
91 
92  Q_FOREACH( const QModelIndex &index, selectedRows )
93  {
94  KMime::Content *content = static_cast<KMime::Content*>( index.internalPointer() );
95  if ( content )
96  contents.append( content );
97  }
98  return contents;
99 }
QModelIndex
globalsettings.h
QWidget
QAbstractItemView::setSelectionMode
void setSelectionMode(QAbstractItemView::SelectionMode mode)
QByteArray
QAbstractItemView::selectionModel
QItemSelectionModel * selectionModel() const
QHeaderView::restoreState
bool restoreState(const QByteArray &state)
MessageViewer::MimeTreeModel
A model representing the mime part tree of a message.
Definition: mimetreemodel.h:34
MessageViewer::MimeTreeModel::root
KMime::Content * root()
Definition: mimetreemodel.cpp:140
QAbstractItemView::setSelectionBehavior
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
QObject
MessageViewer::MimePartTreeView::setRoot
void setRoot(KMime::Content *root)
Definition: mimeparttreeview.cpp:80
QObject::setObjectName
void setObjectName(const QString &name)
MessageViewer::GlobalSettings::self
static GlobalSettings * self()
Definition: globalsettings.cpp:34
QItemSelectionModel::selectedRows
QModelIndexList selectedRows(int column) const
mimeparttreeview.h
QModelIndex::internalPointer
void * internalPointer() const
MessageViewer::MimePartTreeView::MimePartTreeView
MimePartTreeView(QWidget *parent=0)
Definition: mimeparttreeview.cpp:29
mimetreemodel.h
MessageViewer::MimePartTreeView::~MimePartTreeView
~MimePartTreeView()
Definition: mimeparttreeview.cpp:45
QWidget::setContextMenuPolicy
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
QTreeView::expandAll
void expandAll()
MessageViewer::MimeTreeModel::setRoot
void setRoot(KMime::Content *root)
Definition: mimetreemodel.cpp:134
MessageViewer::MimePartTreeView::clearModel
void clearModel()
Definition: mimeparttreeview.cpp:74
QLatin1String
QTreeView
QTreeView::setModel
virtual void setModel(QAbstractItemModel *model)
QHeaderView::setResizeMode
void setResizeMode(ResizeMode mode)
MessageViewer::MimePartTreeView::selectedContents
KMime::Content::List selectedContents()
Definition: mimeparttreeview.cpp:86
QTreeView::header
QHeaderView * header() const
MessageViewer::MimePartTreeView::mimePartModel
MessageViewer::MimeTreeModel * mimePartModel() const
Definition: mimeparttreeview.cpp:50
QItemSelectionModel
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::destroyed
void destroyed(QObject *obj)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:45 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

Skip menu "messageviewer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal