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

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
  • identity
identitylistview.cpp
Go to the documentation of this file.
1 /* -*- c++ -*-
2  identitylistview.cpp
3 
4  This file is part of KMail, the KDE mail client.
5  Copyright (c) 2002 Marc Mutz <mutz@kde.org>
6  2007 Mathias Soeken <msoeken@tzi.de>
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 #include "identitylistview.h"
34 
35 #include <kpimidentities/identitymanager.h>
36 #include <kpimidentities/identity.h>
37 
38 #ifndef KCM_KPIMIDENTITIES_STANDALONE
39 #include "kmkernel.h"
40 #endif
41 
42 #include <KDebug>
43 #include <KLocale> // i18n
44 #include <KIconLoader> // SmallIcon
45 
46 #include <QDrag>
47 #include <QHeaderView>
48 #include <QLineEdit>
49 #include <QMimeData>
50 
51 namespace KMail {
52 
53 //
54 //
55 // IdentityListViewItem
56 //
57 //
58 
59 IdentityListViewItem::IdentityListViewItem( IdentityListView *parent,
60  const KPIMIdentities::Identity &ident )
61  : QTreeWidgetItem( parent ), mUOID( ident.uoid() )
62 {
63  init( ident );
64 }
65 
66 IdentityListViewItem::IdentityListViewItem( IdentityListView *parent,
67  QTreeWidgetItem *after,
68  const KPIMIdentities::Identity &ident )
69  : QTreeWidgetItem( parent, after ), mUOID( ident.uoid() )
70 {
71  init( ident );
72 }
73 
74 KPIMIdentities::Identity & IdentityListViewItem::identity() const
75 {
76  KPIMIdentities::IdentityManager *im = qobject_cast<IdentityListView*>( treeWidget() )->identityManager();
77  Q_ASSERT( im );
78  return im->modifyIdentityForUoid( mUOID );
79 }
80 
81 void IdentityListViewItem::setIdentity( const KPIMIdentities::Identity &ident )
82 {
83  mUOID = ident.uoid();
84  init( ident );
85 }
86 
87 void IdentityListViewItem::redisplay()
88 {
89  init( identity() );
90 }
91 
92 void IdentityListViewItem::init( const KPIMIdentities::Identity &ident )
93 {
94  if ( ident.isDefault() ) {
95  // Add "(Default)" to the end of the default identity's name:
96  setText( 0, i18nc( "%1: identity name. Used in the config "
97  "dialog, section Identity, to indicate the "
98  "default identity", "%1 (Default)",
99  ident.identityName() ) );
100  QFont fontItem(font(0));
101  fontItem.setBold(true);
102  setFont(0,fontItem);
103  } else {
104  QFont fontItem(font(0));
105  fontItem.setBold(false);
106  setFont(0,fontItem);
107 
108  setText( 0, ident.identityName() );
109  }
110  setText( 1, ident.fullEmailAddr() );
111 }
112 
113 //
114 //
115 // IdentityListView
116 //
117 //
118 
119 IdentityListView::IdentityListView( QWidget *parent )
120  : QTreeWidget( parent ),
121  mIdentityManager( 0 )
122 {
123 #ifndef QT_NO_DRAGANDDROP
124  setDragEnabled( true );
125  setAcceptDrops( true );
126 #endif
127  setHeaderLabels( QStringList() << i18n( "Identity Name" ) << i18n( "Email Address" ) );
128  setRootIsDecorated( false );
129  header()->setMovable( false );
130  header()->setResizeMode( QHeaderView::ResizeToContents );
131  setAllColumnsShowFocus( true );
132  setAlternatingRowColors( true );
133  setSortingEnabled( true );
134  sortByColumn( 0, Qt::AscendingOrder );
135  setSelectionMode( SingleSelection ); // ### Extended would be nicer...
136  setColumnWidth( 0, 175 );
137 
138  setContextMenuPolicy( Qt::CustomContextMenu );
139  connect( this, SIGNAL(customContextMenuRequested(QPoint)),
140  this, SLOT(slotCustomContextMenuRequested(QPoint)) );
141 }
142 
143 void IdentityListView::editItem( QTreeWidgetItem *item, int column )
144 {
145  if ( column == 0 && item ) {
146  IdentityListViewItem *lvItem = dynamic_cast<IdentityListViewItem*>( item );
147  if ( lvItem ) {
148  KPIMIdentities::Identity& ident = lvItem->identity();
149  if ( ident.isDefault() ) {
150  lvItem->setText( 0, ident.identityName() );
151  }
152  }
153 
154  Qt::ItemFlags oldFlags = item->flags();
155  item->setFlags( oldFlags | Qt::ItemIsEditable );
156  QTreeWidget::editItem( item, 0 );
157  item->setFlags( oldFlags );
158  }
159 }
160 
161 void IdentityListView::commitData( QWidget *editor )
162 {
163  kDebug() << "after editing";
164 
165  if ( !selectedItems().isEmpty() ) {
166 
167  QLineEdit *edit = dynamic_cast<QLineEdit*>( editor ); // krazy:exclude=qclasses
168  if ( edit ) {
169  IdentityListViewItem *item = dynamic_cast<IdentityListViewItem*>( selectedItems()[0] );
170  const QString text = edit->text();
171  emit rename( item, text );
172  }
173  }
174 }
175 
176 void IdentityListView::slotCustomContextMenuRequested( const QPoint &pos )
177 {
178  QTreeWidgetItem *item = itemAt( pos );
179  if ( item ) {
180  IdentityListViewItem *lvItem = dynamic_cast<IdentityListViewItem*>( item );
181  if ( lvItem ) {
182  emit contextMenu( lvItem, viewport()->mapToGlobal( pos ) );
183  }
184  } else {
185  emit contextMenu( 0, viewport()->mapToGlobal( pos ) );
186  }
187 }
188 
189 #ifndef QT_NO_DRAGANDDROP
190 void IdentityListView::startDrag ( Qt::DropActions /*supportedActions*/ )
191 {
192  IdentityListViewItem * item = dynamic_cast<IdentityListViewItem*>( currentItem() );
193  if ( !item )
194  return;
195 
196  QDrag *drag = new QDrag( viewport() );
197  QMimeData *md = new QMimeData;
198  drag->setMimeData( md );
199  item->identity().populateMimeData( md );
200  drag->setPixmap( SmallIcon(QLatin1String("user-identity")) );
201  drag->start();
202 }
203 #endif
204 
205 KPIMIdentities::IdentityManager* IdentityListView::identityManager() const
206 {
207  Q_ASSERT( mIdentityManager );
208  return mIdentityManager;
209 }
210 
211 void IdentityListView::setIdentityManager(KPIMIdentities::IdentityManager* im)
212 {
213  mIdentityManager = im;
214 }
215 
216 } // namespace KMail
217 
218 
219 #include "identitylistview.moc"
KMail::IdentityListViewItem::IdentityListViewItem
IdentityListViewItem(IdentityListView *parent, const KPIMIdentities::Identity &ident)
Definition: identitylistview.cpp:59
KMail::IdentityListView::IdentityListView
IdentityListView(QWidget *parent=0)
Definition: identitylistview.cpp:119
KMail::IdentityListView::commitData
void commitData(QWidget *editor)
Definition: identitylistview.cpp:161
KMail::IdentityListView::slotCustomContextMenuRequested
void slotCustomContextMenuRequested(const QPoint &)
Definition: identitylistview.cpp:176
QTreeWidget
text
virtual QByteArray text(quint32 serialNumber) const =0
KMail::IdentityListView::contextMenu
void contextMenu(KMail::IdentityListViewItem *, const QPoint &)
QWidget
KMail::IdentityListView::identityManager
KPIMIdentities::IdentityManager * identityManager() const
Definition: identitylistview.cpp:205
KMail::IdentityListViewItem::identity
KPIMIdentities::Identity & identity() const
Definition: identitylistview.cpp:74
KMail::IdentityListView::setIdentityManager
void setIdentityManager(KPIMIdentities::IdentityManager *im)
Definition: identitylistview.cpp:211
KMail::IdentityListView::editItem
void editItem(QTreeWidgetItem *item, int column=0)
Definition: identitylistview.cpp:143
KMail::IdentityListView::startDrag
void startDrag(Qt::DropActions supportedActions)
Definition: identitylistview.cpp:190
QMimeData
KMail::IdentityListViewItem
A QWidgetTreeItem for use in IdentityListView.
Definition: identitylistview.h:51
QTreeWidgetItem
kmkernel.h
KMail::IdentityListView::rename
void rename(KMail::IdentityListViewItem *, const QString &)
identitylistview.h
KMail::IdentityListView
A QTreeWidget for KPIMIdentities::Identity.
Definition: identitylistview.h:71
KMail::IdentityListViewItem::setIdentity
virtual void setIdentity(const KPIMIdentities::Identity &ident)
Definition: identitylistview.cpp:81
KMail::IdentityListViewItem::redisplay
void redisplay()
Definition: identitylistview.cpp:87
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

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

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