summaryrefslogtreecommitdiffstats
path: root/ark/filelistview.h
blob: 88a954656b4c22d31a3a126cd4daa34e6c89206f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*

  ark -- archiver for the KDE project

  Copyright (C)

  1999: Francois-Xavier Duranceau duranceau@kde.org
  1999-2000: Corel Corporation (author: Emily Ezust, emilye@corel.com)
  2001: Corel Corporation (author: Michael Jarrett, michaelj@corel.com)
  2003: Georg Robbers <Georg.Robbers@urz.uni-hd.de>
  2005: Henrique Pinto <henrique.pinto@kdemail.net>

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/
#ifndef FILELISTVIEW_H
#define FILELISTVIEW_H

#include <tqdatetime.h>
#include <tqpair.h>
#include <tqvaluelist.h>

#include <klistview.h>
#include <kio/global.h>

class TQString;
class TQStringList;
class TQRect;
class TQPainter;
class TQColorGroup;
class TQMouseEvent;
class TQPoint;

enum columnName { sizeCol = 1 , packedStrCol, ratioStrCol, timeStampStrCol, otherCol };

class FileLVI : public KListViewItem
{
	public:
		FileLVI( KListView* lv );
		FileLVI( KListViewItem* lvi );

		TQString fileName() const { return m_entryName; }
		KIO::filesize_t fileSize() const { return m_fileSize; }
		KIO::filesize_t packedFileSize() const { return m_packedFileSize; }
		double ratio() const { return m_ratio; }
		TQDateTime timeStamp() const { return m_timeStamp; }

		int compare ( TQListViewItem * i, int col, bool ascending ) const;
		virtual TQString key( int column, bool ) const;
		virtual void setText( int column, const TQString &text );

	private:
		KIO::filesize_t m_fileSize;
		KIO::filesize_t m_packedFileSize;
		double    m_ratio;
		TQDateTime m_timeStamp;
		TQString   m_entryName;
};

typedef TQValueList< TQPair< TQString, TQt::AlignmentFlags > > ColumnList;

class FileListView: public KListView
{
	Q_OBJECT
  
	public:
		FileListView( TQWidget *parent = 0, const char* name = 0 );

		FileLVI *currentItem() {return ((FileLVI *) KListView::currentItem());}

		/**
		 * Returns the full names of the selected files.
		 */
		TQStringList selectedFilenames();

		/**
		 * Return the full names of all files.
		 */
		TQStringList fileNames();

		/**
		 * Returns true if no file is selected
		 */
		bool isSelectionEmpty();

		virtual int addColumn( const TQString & label, int width = -1 );
		virtual void removeColumn( int index );
		columnName nameOfColumn( int index );

		/**
		 * Returns the file item, or 0 if not found.
		 * @param filename The filename in question to reference in the archive
		 * @return The requested file's FileLVI
		 */
		FileLVI* item(const TQString& filename) const;

		/**
		 * Adds a file and stats to the file listing
		 * @param entries A stringlist of the entries for each column of the list.
		 */
		void addItem( const TQStringList & entries );

		/**
		 * Returns the number of files in the archive.
		 */
		int totalFiles();

		/**
		 * Returns the number of selected files.
		 */
		int selectedFilesCount();

		/**
		 * Return the sum of the sizes of all files in the archive.
		 */
		KIO::filesize_t totalSize();

		/**
		 * Return the sum of the sizes of the selected files.
		 */
		KIO::filesize_t selectedSize();

		/**
		 * Adjust the size of all columns to fit their content.
		 */
		void adjustColumns() { for ( int i = 0; i < columns(); ++i ) adjustColumn( i ); }

	public slots:
		void selectAll();
		void unselectAll();
		void setHeaders( const ColumnList& columns );
		void clearHeaders();

	signals:
		void startDragRequest( const TQStringList & fileList );

	protected:
		virtual void contentsMouseReleaseEvent( TQMouseEvent *e );
		virtual void contentsMousePressEvent( TQMouseEvent *e );
		virtual void contentsMouseMoveEvent( TQMouseEvent *e );

	private:
		FileLVI* findParent( const TQString& fullname );
		TQStringList childrenOf( FileLVI* parent );

		TQMap<int, columnName> m_columnMap;
		bool m_pressed;
		TQPoint m_presspos;  // this will save the click pos to correctly recognize drag events
};

#endif
// kate: space-indent off; tab-width 4;