kmail

identitylistview.cpp
1 /*
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 
7  KMail is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License, version 2, as
9  published by the Free Software Foundation.
10 
11  KMail is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 
20  In addition, as a special exception, the copyright holders give
21  permission to link the code of this program with any edition of
22  the TQt library by Trolltech AS, Norway (or with modified versions
23  of TQt that use the same license as TQt), and distribute linked
24  combinations including the two. You must obey the GNU General
25  Public License in all respects for all of the code used other than
26  TQt. If you modify this file, you may extend this exception to
27  your version of the file, but you are not obligated to do so. If
28  you do not wish to do so, delete this exception statement from
29  your version.
30 */
31 
32 #ifdef HAVE_CONFIG_H
33 #include <config.h>
34 #endif
35 
36 #include "identitylistview.h"
37 
38 #include "identitydrag.h"
39 #include <libkpimidentities/identitymanager.h>
40 #include "kmkernel.h"
41 
42 #include <tdelocale.h> // i18n
43 #include <kiconloader.h> // SmallIcon
44 
45 #include <cassert>
46 
47 namespace KMail {
48 
49  //
50  //
51  // IdentityListViewItem
52  //
53  //
54 
55  IdentityListViewItem::IdentityListViewItem( IdentityListView * parent, const KPIM::Identity & ident )
56  : TDEListViewItem( parent ), mUOID( ident.uoid() ) {
57  init( ident );
58  }
59 
60  IdentityListViewItem::IdentityListViewItem( IdentityListView * parent, TQListViewItem * after, const KPIM::Identity & ident )
61  : TDEListViewItem( parent, after ), mUOID( ident.uoid() ) {
62  init( ident );
63  }
64 
65  KPIM::Identity & IdentityListViewItem::identity() const {
66  KPIM::IdentityManager * im = kmkernel->identityManager();
67  assert( im );
68  return im->modifyIdentityForUoid( uoid() );
69  }
70 
71  void IdentityListViewItem::setIdentity( const KPIM::Identity & ident ) {
72  mUOID = ident.uoid();
73  init( ident );
74  }
75 
76  void IdentityListViewItem::redisplay() {
77  init( identity() );
78  }
79 
80  void IdentityListViewItem::init( const KPIM::Identity & ident ) {
81  if ( ident.isDefault() )
82  // Add "(Default)" to the end of the default identity's name:
83  setText( 0, i18n("%1: identity name. Used in the config "
84  "dialog, section Identity, to indicate the "
85  "default identity", "%1 (Default)")
86  .arg( ident.identityName() ) );
87  else
88  setText( 0, ident.identityName() );
89  setText( 1, ident.fullEmailAddr() );
90  }
91 
92  //
93  //
94  // IdentityListView
95  //
96  //
97 
98  IdentityListView::IdentityListView( TQWidget * parent, const char * name )
99  : TDEListView( parent, name )
100  {
101  setFullWidth( true );
102  setDragEnabled( true );
103  setAcceptDrops( true );
104  setDropVisualizer( true );
105  addColumn( i18n("Identity Name") );
106  addColumn( i18n("Email Address") );
107  setRootIsDecorated( false );
108  setRenameable( 0 );
109  setItemsRenameable( true );
110  // setShowToolTips( true );
111  setItemsMovable( false );
112  setAllColumnsShowFocus( true );
113  setSorting( -1 ); // disabled
114  setSelectionModeExt( Single ); // ### Extended would be nicer...
115  }
116 
117  void IdentityListView::rename( TQListViewItem * i, int col ) {
118  if ( col == 0 && isRenameable( col ) ) {
119  IdentityListViewItem * item = dynamic_cast<IdentityListViewItem*>( i );
120  if ( item ) {
121  KPIM::Identity & ident = item->identity();
122  if ( ident.isDefault() )
123  item->setText( 0, ident.identityName() );
124  }
125  }
126  TDEListView::rename( i, col );
127  }
128 
129  bool IdentityListView::acceptDrag( TQDropEvent * e ) const {
130  // disallow moving:
131  return e->source() != viewport() && IdentityDrag::canDecode( e );
132  }
133 
134  TQDragObject * IdentityListView::dragObject() {
135  IdentityListViewItem * item = dynamic_cast<IdentityListViewItem*>( currentItem() );
136  if ( !item ) return 0;
137 
138  IdentityDrag * drag = new IdentityDrag( item->identity(), viewport() );
139  drag->setPixmap( SmallIcon("identity") );
140  return drag;
141  }
142 
143 } // namespace KMail
144 
145 
146 #include "identitylistview.moc"
folderdiaquotatab.h
Definition: aboutdata.cpp:40