source: trunk/examples/network/ftpclient/ftpviewitem.cpp

Last change on this file was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1/****************************************************************************
2** $Id: ftpviewitem.cpp 2 2005-11-16 15:49:26Z dmik $
3**
4** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
5**
6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation.
8**
9*****************************************************************************/
10
11#include <qpixmap.h>
12
13#include "ftpviewitem.h"
14
15
16FtpViewItem::FtpViewItem( QListView *parent, Type t, const QString &name, const QString &size, const QString &lastModified )
17 : QListViewItem(parent,name,size,lastModified), type(t)
18{
19 // the pixmaps for folders and files are in an image collection
20 if ( type == Directory )
21 setPixmap( 0, QPixmap::fromMimeSource( "folder.png" ) );
22 else
23 setPixmap( 0, QPixmap::fromMimeSource( "file.png" ) );
24}
25
26int FtpViewItem::compare( QListViewItem * i, int col, bool ascending ) const
27{
28 // The entry ".." is always the first one.
29 if ( text(0) == ".." ) {
30 if ( ascending )
31 return -1;
32 else
33 return 1;
34 }
35 if ( i->text(0) == ".." ) {
36 if ( ascending )
37 return 1;
38 else
39 return -1;
40 }
41
42 // Directories are before files.
43 if ( type != ((FtpViewItem*)i)->type ) {
44 if ( type == Directory ) {
45 if ( ascending )
46 return -1;
47 else
48 return 1;
49 } else {
50 if ( ascending )
51 return 1;
52 else
53 return -1;
54 }
55 }
56
57 // Use default sorting otherwise.
58 return QListViewItem::compare( i, col, ascending );
59}
Note: See TracBrowser for help on using the repository browser.