Factor out the shared parts of the agent action manager setup.
[kdepim.git] / knode / kncollectionviewitem.cpp
blob6d3dbfbbc4488298ffa446bfd2b6ac9c9770b033
1 /*
2 KNode, the KDE newsreader
3 Copyright (c) 1999-2006 the KNode authors.
4 See file AUTHORS for details
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 You should have received a copy of the GNU General Public License
11 along with this program; if not, write to the Free Software Foundation,
12 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
15 #include "kncollectionviewitem.h"
17 #include "kncollectionview.h"
18 #include "kngroup.h"
19 #include "knfolder.h"
20 #include "knconfigmanager.h"
22 #include <kiconloader.h>
25 KNCollectionViewItem::KNCollectionViewItem( FolderTreeWidget *parent, Protocol protocol, FolderType type) :
26 FolderTreeWidgetItem( parent, QString(), protocol, type )
28 setUp();
32 KNCollectionViewItem::KNCollectionViewItem( FolderTreeWidgetItem *parent, Protocol protocol, FolderType type, int unread, int total ) :
33 FolderTreeWidgetItem( parent, QString(), protocol, type )
35 setUp();
36 setUnreadCount( unread );
37 setTotalCount( total );
41 KNCollectionViewItem::~KNCollectionViewItem()
43 if(coll) coll->setListItem(0);
47 void KNCollectionViewItem::setUp()
49 // Label edition
50 setFlags( flags() | Qt::ItemIsEditable );
52 // Icons
53 if ( protocol() == FolderTreeWidgetItem::News ) {
54 // news servers/groups
55 switch ( folderType() ) {
56 case FolderTreeWidgetItem::Root:
57 setIcon( 0, KIcon("network-server") );
58 break;
59 default:
60 setIcon( 0, KIcon("group") );
62 } else {
63 // local folders
64 switch ( folderType() ) {
65 case FolderTreeWidgetItem::Outbox:
66 setIcon( 0, KIcon("mail-folder-outbox") );
67 break;
68 case FolderTreeWidgetItem::Drafts:
69 setIcon( 0, KIcon("document-properties") );
70 break;
71 case FolderTreeWidgetItem::SentMail:
72 setIcon( 0, KIcon("mail-folder-sent") );
73 break;
74 default:
75 setIcon( 0, KIcon("folder") );
81 bool KNCollectionViewItem::operator<( const QTreeWidgetItem &other ) const
83 const FolderTreeWidgetItem &otherFolder = static_cast<const FolderTreeWidgetItem&>( other );
85 if( protocol() == FolderTreeWidgetItem::Local ) {
86 if( otherFolder.protocol() == FolderTreeWidgetItem::News) {
87 return false;
91 if( protocol() == FolderTreeWidgetItem::News ) {
92 if( otherFolder.protocol() == FolderTreeWidgetItem::Local ) {
93 return true;
96 return FolderTreeWidgetItem::operator<( other );
100 void KNCollectionViewItem::setCollection( KNCollection::Ptr c )
102 coll = c;
103 setUp();
107 QString KNCollectionViewItem::elidedLabelText( const QFontMetrics &fm, unsigned int width ) const
109 if (protocol() == FolderTreeWidgetItem::News && folderType() == FolderTreeWidgetItem::Other) {
110 QString t( labelText() );
111 int curPos = 0, nextPos = 0;
112 QString temp;
113 while ( (uint)fm.width(t) > width && nextPos != -1 ) {
114 nextPos = t.indexOf( '.', curPos );
115 if ( nextPos != -1 ) {
116 temp = t[curPos];
117 t.replace( curPos, nextPos - curPos, temp );
118 curPos += 2;
121 if ( (uint)fm.width( t ) > width )
122 t = fm.elidedText( t, Qt::ElideRight, width );
123 return t;
124 } else {
125 return FolderTreeWidgetItem::elidedLabelText( fm, width );