kmail Library API Documentation

identitylistview.cpp

00001 /* -*- c++ -*- 00002 identitylistview.cpp 00003 00004 This file is part of KMail, the KDE mail client. 00005 Copyright (c) 2002 Marc Mutz <mutz@kde.org> 00006 00007 KMail is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU General Public License, version 2, as 00009 published by the Free Software Foundation. 00010 00011 KMail is distributed in the hope that it will be useful, but 00012 WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 In addition, as a special exception, the copyright holders give 00021 permission to link the code of this program with any edition of 00022 the Qt library by Trolltech AS, Norway (or with modified versions 00023 of Qt that use the same license as Qt), and distribute linked 00024 combinations including the two. You must obey the GNU General 00025 Public License in all respects for all of the code used other than 00026 Qt. If you modify this file, you may extend this exception to 00027 your version of the file, but you are not obligated to do so. If 00028 you do not wish to do so, delete this exception statement from 00029 your version. 00030 */ 00031 00032 #ifdef HAVE_CONFIG_H 00033 #include <config.h> 00034 #endif 00035 00036 #include "identitylistview.h" 00037 00038 #include "identitydrag.h" 00039 #include <libkpimidentities/identitymanager.h> 00040 #include "kmkernel.h" 00041 00042 #include <klocale.h> // i18n 00043 #include <kiconloader.h> // SmallIcon 00044 00045 #include <cassert> 00046 00047 namespace KMail { 00048 00049 // 00050 // 00051 // IdentityListViewItem 00052 // 00053 // 00054 00055 IdentityListViewItem::IdentityListViewItem( IdentityListView * parent, const KPIM::Identity & ident ) 00056 : KListViewItem( parent ), mUOID( ident.uoid() ) { 00057 init( ident ); 00058 } 00059 00060 IdentityListViewItem::IdentityListViewItem( IdentityListView * parent, QListViewItem * after, const KPIM::Identity & ident ) 00061 : KListViewItem( parent, after ), mUOID( ident.uoid() ) { 00062 init( ident ); 00063 } 00064 00065 KPIM::Identity & IdentityListViewItem::identity() const { 00066 KPIM::IdentityManager * im = kmkernel->identityManager(); 00067 assert( im ); 00068 return im->modifyIdentityForUoid( uoid() ); 00069 } 00070 00071 void IdentityListViewItem::setIdentity( const KPIM::Identity & ident ) { 00072 mUOID = ident.uoid(); 00073 init( ident ); 00074 } 00075 00076 void IdentityListViewItem::redisplay() { 00077 init( identity() ); 00078 } 00079 00080 void IdentityListViewItem::init( const KPIM::Identity & ident ) { 00081 if ( ident.isDefault() ) 00082 // Add "(Default)" to the end of the default identity's name: 00083 setText( 0, i18n("%1: identity name. Used in the config " 00084 "dialog, section Identity, to indicate the " 00085 "default identity", "%1 (Default)") 00086 .arg( ident.identityName() ) ); 00087 else 00088 setText( 0, ident.identityName() ); 00089 setText( 1, ident.fullEmailAddr() ); 00090 } 00091 00092 // 00093 // 00094 // IdentityListView 00095 // 00096 // 00097 00098 IdentityListView::IdentityListView( QWidget * parent, const char * name ) 00099 : KListView( parent, name ) 00100 { 00101 setFullWidth( true ); 00102 setDragEnabled( true ); 00103 setAcceptDrops( true ); 00104 setDropVisualizer( true ); 00105 addColumn( i18n("Identity Name") ); 00106 addColumn( i18n("Email Address") ); 00107 setRootIsDecorated( false ); 00108 setRenameable( 0 ); 00109 setItemsRenameable( true ); 00110 // setShowToolTips( true ); 00111 setItemsMovable( false ); 00112 setAllColumnsShowFocus( true ); 00113 setSorting( -1 ); // disabled 00114 setSelectionModeExt( Single ); // ### Extended would be nicer... 00115 } 00116 00117 void IdentityListView::rename( QListViewItem * i, int col ) { 00118 if ( col == 0 && isRenameable( col ) ) { 00119 IdentityListViewItem * item = dynamic_cast<IdentityListViewItem*>( i ); 00120 if ( item ) { 00121 KPIM::Identity & ident = item->identity(); 00122 if ( ident.isDefault() ) 00123 item->setText( 0, ident.identityName() ); 00124 } 00125 } 00126 KListView::rename( i, col ); 00127 } 00128 00129 bool IdentityListView::acceptDrag( QDropEvent * e ) const { 00130 // disallow moving: 00131 return e->source() != viewport() && IdentityDrag::canDecode( e ); 00132 } 00133 00134 QDragObject * IdentityListView::dragObject() { 00135 IdentityListViewItem * item = dynamic_cast<IdentityListViewItem*>( currentItem() ); 00136 if ( !item ) return 0; 00137 00138 IdentityDrag * drag = new IdentityDrag( item->identity(), viewport() ); 00139 drag->setPixmap( SmallIcon("identity") ); 00140 return drag; 00141 } 00142 00143 } // namespace KMail 00144 00145 00146 #include "identitylistview.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:45 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003