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"
20 #include "knconfigmanager.h"
22 #include <kiconloader.h>
25 KNCollectionViewItem::KNCollectionViewItem( FolderTreeWidget
*parent
, Protocol protocol
, FolderType type
) :
26 FolderTreeWidgetItem( parent
, QString(), protocol
, type
)
32 KNCollectionViewItem::KNCollectionViewItem( FolderTreeWidgetItem
*parent
, Protocol protocol
, FolderType type
, int unread
, int total
) :
33 FolderTreeWidgetItem( parent
, QString(), protocol
, type
)
36 setUnreadCount( unread
);
37 setTotalCount( total
);
41 KNCollectionViewItem::~KNCollectionViewItem()
43 if(coll
) coll
->setListItem(0);
47 void KNCollectionViewItem::setUp()
50 setFlags( flags() | Qt::ItemIsEditable
);
53 if ( protocol() == FolderTreeWidgetItem::News
) {
54 // news servers/groups
55 switch ( folderType() ) {
56 case FolderTreeWidgetItem::Root
:
57 setIcon( 0, KIcon("network-server") );
60 setIcon( 0, KIcon("group") );
64 switch ( folderType() ) {
65 case FolderTreeWidgetItem::Outbox
:
66 setIcon( 0, KIcon("mail-folder-outbox") );
68 case FolderTreeWidgetItem::Drafts
:
69 setIcon( 0, KIcon("document-properties") );
71 case FolderTreeWidgetItem::SentMail
:
72 setIcon( 0, KIcon("mail-folder-sent") );
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
) {
91 if( protocol() == FolderTreeWidgetItem::News
) {
92 if( otherFolder
.protocol() == FolderTreeWidgetItem::Local
) {
96 return FolderTreeWidgetItem::operator<( other
);
100 void KNCollectionViewItem::setCollection( KNCollection::Ptr c
)
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;
113 while ( (uint
)fm
.width(t
) > width
&& nextPos
!= -1 ) {
114 nextPos
= t
.indexOf( '.', curPos
);
115 if ( nextPos
!= -1 ) {
117 t
.replace( curPos
, nextPos
- curPos
, temp
);
121 if ( (uint
)fm
.width( t
) > width
)
122 t
= fm
.elidedText( t
, Qt::ElideRight
, width
);
125 return FolderTreeWidgetItem::elidedLabelText( fm
, width
);