1
/* This file is part of the KDE project
2
Copyright (C) 2002 Rolf Magnus <ramagnus@kde.org>
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public
6
License as published by the Free Software Foundation version 2.0
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
General Public License for more details.
13
You should have received a copy of the GNU General Public License
14
along with this program; see the file COPYING. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
20
#include "konq_listview.h"
21
#include <konq_settings.h>
22
#include <kfilemetainfo.h>
29
#include <kiconloader.h>
30
#include "konq_infolistviewitem.h"
31
#include "konq_infolistviewwidget.h"
33
/**************************************************************
35
* KonqInfoListViewItem
37
**************************************************************/
38
KonqInfoListViewItem::KonqInfoListViewItem( KonqInfoListViewWidget *_widget, KonqInfoListViewItem * _parent, KFileItem* _fileitem )
39
:KonqBaseListViewItem( _widget,_parent,_fileitem ), m_ILVWidget(_widget)
44
KonqInfoListViewItem::KonqInfoListViewItem( KonqInfoListViewWidget *_listViewWidget, KFileItem* _fileitem )
45
:KonqBaseListViewItem(_listViewWidget,_fileitem), m_ILVWidget(_listViewWidget)
50
void KonqInfoListViewItem::updateContents()
53
setDisabled( m_bDisabled );
55
// Set the text of each column
56
setText(0,m_fileitem->text());
59
if (S_ISDIR(m_fileitem->mode()))
61
//now we have the first column, so let's do the rest
63
for (unsigned int i=0; i<KonqBaseListViewWidget::NumberOfAtoms; i++)
65
ColumnInfo *tmpColumn=&static_cast<KonqBaseListViewWidget *>(listView())->columnConfigInfo()[i];
66
if (tmpColumn->displayThisOne)
68
switch (tmpColumn->udsId)
71
setText(tmpColumn->displayInColumn,m_fileitem->user());
74
setText(tmpColumn->displayInColumn,m_fileitem->group());
76
case KIO::UDS_FILE_TYPE:
77
setText(tmpColumn->displayInColumn,m_fileitem->mimeComment());
79
case KIO::UDS_MIME_TYPE:
80
setText(tmpColumn->displayInColumn,m_fileitem->mimetype());
83
setText(tmpColumn->displayInColumn,m_fileitem->url().prettyURL());
85
case KIO::UDS_LINK_DEST:
86
setText(tmpColumn->displayInColumn,m_fileitem->linkDest());
89
if ( static_cast<KonqBaseListViewWidget *>(listView())->m_pSettings->fileSizeInBytes() )
90
setText(tmpColumn->displayInColumn,KGlobal::locale()->formatNumber( m_fileitem->size(),0)+" ");
92
setText(tmpColumn->displayInColumn,KIO::convertSize(m_fileitem->size())+" ");
95
setText(tmpColumn->displayInColumn,m_fileitem->permissionsString());
97
case KIO::UDS_MODIFICATION_TIME:
98
case KIO::UDS_ACCESS_TIME:
99
case KIO::UDS_CREATION_TIME:
102
time_t _time = m_fileitem->time( tmpColumn->udsId );
105
dt.setTime_t( _time );
106
setText(tmpColumn->displayInColumn,KGlobal::locale()->formatDateTime(dt));
118
void KonqInfoListViewItem::gotMetaInfo()
120
KFileMetaInfo info = item()->metaInfo(false);
122
if (!info.isValid()) return;
124
QStringList::ConstIterator it = m_ILVWidget->columnKeys().begin();
125
for (int i = 1; it != m_ILVWidget->columnKeys().end(); ++it, ++i)
127
KFileMetaInfoItem kfmii = info.item(*it);
129
m_columnTypes.append(kfmii.type());
130
m_columnValues.append(kfmii.value());
132
if (!kfmii.isValid())
135
QString s = kfmii.string().simplifyWhiteSpace();
136
setText(i, s.isNull() ? QString("") : s);
140
int KonqInfoListViewItem::compare( QListViewItem *item, int col, bool ascending ) const
143
return KonqBaseListViewItem::compare( item, 0, ascending );
145
KonqInfoListViewItem *i = static_cast<KonqInfoListViewItem *>(item);
147
int size1 = m_columnValues.size();
148
int size2 = i->m_columnValues.size();
150
if ( size1 < col || size2 < col )
151
return ascending ? ( size2 - size1 ) : ( size1 - size2 );
153
QVariant value1 = m_columnValues[ col-1 ];
154
QVariant value2 = i->m_columnValues[ col-1 ];
155
QVariant::Type type1 = m_columnTypes[ col-1 ];
156
QVariant::Type type2 = i->m_columnTypes[ col-1 ];
158
if ( type1 != type2 )
159
return ascending ? ( type1 - type2 ) : ( type2 - type1 );
161
#define KONQ_CASE( x ) \
163
return ( value1.to##x() > value2.to##x() ) ? 1 : ( value1.to##x() == value2.to##x() ) ? 0 : -1;
168
KONQ_CASE( LongLong )
170
KONQ_CASE( ULongLong )
174
KONQ_CASE( DateTime )
177
int w1 = value1.toSize().width();
178
int w2 = value2.toSize().width();
180
return ( w1 > w2 ) ? 1 : -1;
181
int h1 = value1.toSize().height();
182
int h2 = value2.toSize().height();
183
return ( h1 > h2 ) ? 1 : ( h1 == h2 ) ? 0 : -1;
190
QString text1 = text(col);
191
QString text2 = i->text(col);
193
if ( text1.isEmpty() )
194
return ascending ? 1 : -1;
195
if ( text2.isEmpty() )
196
return ascending ? -1 : 1;
198
return text1.lower().localeAwareCompare(text2.lower());
201
void KonqInfoListViewItem::setDisabled( bool disabled )
203
KonqBaseListViewItem::setDisabled( disabled );
204
int iconSize = static_cast<KonqBaseListViewWidget *>(listView())->iconSize();
205
iconSize = iconSize ? iconSize : KGlobal::iconLoader()->currentSize( KIcon::Small ); // Default = small
206
setPixmap( 0, m_fileitem->pixmap( iconSize, state() ) );
209
void KonqInfoListViewItem::paintCell( QPainter *_painter, const QColorGroup & _cg, int _column, int _width, int _alignment )
211
QColorGroup cg( _cg );
215
_painter->setFont( m_pListViewWidget->itemFont() );
218
cg.setColor( QColorGroup::Text, m_pListViewWidget->itemColor() );
220
KListView *lv = static_cast< KListView* >( listView() );
221
const QPixmap *pm = lv->viewport()->paletteBackgroundPixmap();
222
if ( _column == 0 && isSelected() && !lv->allColumnsShowFocus() )
224
int newWidth = width( lv->fontMetrics(), lv, _column );
225
if ( newWidth > _width )
227
if ( pm && !pm->isNull() )
229
cg.setBrush( QColorGroup::Base, QBrush( backgroundColor(_column), *pm ) );
230
QPoint o = _painter->brushOrigin();
231
_painter->setBrushOrigin( o.x() - lv->contentsX(), o.y() - lv->contentsY() );
232
const QColorGroup::ColorRole crole =
233
QPalette::backgroundRoleFromMode( lv->viewport()->backgroundMode() );
234
_painter->fillRect( newWidth, 0, _width - newWidth, height(), cg.brush( crole ) );
235
_painter->setBrushOrigin( o );
239
_painter->fillRect( newWidth, 0, _width - newWidth, height(), backgroundColor(_column) );
245
KListViewItem::paintCell( _painter, cg, _column, _width, _alignment );
248
void KonqInfoListViewItem::paintFocus( QPainter * _painter, const QColorGroup & cg, const QRect & _r )
251
QListView *lv = static_cast< QListView * >( listView() );
252
r.setWidth( width( lv->fontMetrics(), lv, 0 ) );
253
if ( r.right() > lv->header()->sectionRect( 0 ).right() )
254
r.setRight( lv->header()->sectionRect( 0 ).right() );
255
QListViewItem::paintFocus( _painter, cg, r );
259
void KonqBaseListViewItem::mimetypeFound()
262
setDisabled( m_bDisabled );
264
KonqBaseListViewWidget * lv = static_cast<KonqBaseListViewWidget*>(listView());
265
for (unsigned int i=0; i<KonqBaseListViewWidget::NumberOfAtoms && done < 2; i++)
267
ColumnInfo *tmpColumn=&lv->columnConfigInfo()[i];
268
if (lv->columnConfigInfo()[i].udsId==KIO::UDS_FILE_TYPE && tmpColumn->displayThisOne)
270
setText(tmpColumn->displayInColumn, m_fileitem->mimeComment());
273
if (lv->columnConfigInfo()[i].udsId==KIO::UDS_MIME_TYPE && tmpColumn->displayThisOne)
275
setText(tmpColumn->displayInColumn, m_fileitem->mimetype());