~ubuntu-branches/ubuntu/vivid/krusader/vivid-proposed

« back to all changes in this revision

Viewing changes to krusader/KViewer/lister.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-05-05 22:26:37 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505222637-ydv3cwjwy365on2r
Tags: 1:2.1.0~beta1-1ubuntu1
* Merge from Debian Unstable.  Remaining changes:
  - Retain Kubuntu doc path

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          lister.h  -  description
 
3
                             -------------------
 
4
    copyright            : (C) 2009 + by Csaba Karai
 
5
    e-mail               : krusader@users.sourceforge.net
 
6
    web site             : http://krusader.sourceforge.net
 
7
 ---------------------------------------------------------------------------
 
8
  Description
 
9
 ***************************************************************************
 
10
 
 
11
  A
 
12
 
 
13
     db   dD d8888b. db    db .d8888.  .d8b.  d8888b. d88888b d8888b.
 
14
     88 ,8P' 88  `8D 88    88 88'  YP d8' `8b 88  `8D 88'     88  `8D
 
15
     88,8P   88oobY' 88    88 `8bo.   88ooo88 88   88 88ooooo 88oobY'
 
16
     88`8b   88`8b   88    88   `Y8b. 88~~~88 88   88 88~~~~~ 88`8b
 
17
     88 `88. 88 `88. 88b  d88 db   8D 88   88 88  .8D 88.     88 `88.
 
18
     YP   YD 88   YD ~Y8888P' `8888Y' YP   YP Y8888D' Y88888P 88   YD
 
19
 
 
20
                                                     H e a d e r    F i l e
 
21
 
 
22
 ***************************************************************************
 
23
 *                                                                         *
 
24
 *   This program is free software; you can redistribute it and/or modify  *
 
25
 *   it under the terms of the GNU General Public License as published by  *
 
26
 *   the Free Software Foundation; either version 2 of the License, or     *
 
27
 *   (at your option) any later version.                                   *
 
28
 *                                                                         *
 
29
 ***************************************************************************/
 
30
 
 
31
#ifndef LISTER_H
 
32
#define LISTER_H
 
33
 
 
34
#include <QtCore/QList>
 
35
#include <QtCore/QTimer>
 
36
#include <QtGui/QColor>
 
37
#include <QtGui/QWidget>
 
38
 
 
39
#include <KLineEdit>
 
40
#include <KParts/BrowserExtension>
 
41
#include <KParts/Part>
 
42
#include <KTextEdit>
 
43
 
 
44
#include "../VFS/krquery.h"
 
45
 
 
46
#define  SLIDER_MAX          10000
 
47
#define  MAX_CHAR_LENGTH     4
 
48
 
 
49
class Lister;
 
50
class QLabel;
 
51
class QProgressBar;
 
52
class QPushButton;
 
53
class QToolButton;
 
54
class KAction;
 
55
class KTemporaryFile;
 
56
class ListerEncodingMenu;
 
57
 
 
58
class ListerTextArea : public KTextEdit
 
59
{
 
60
    Q_OBJECT
 
61
 
 
62
public:
 
63
    ListerTextArea(Lister *lister, QWidget *parent);
 
64
    void           reset();
 
65
    void           calculateText(bool forcedUpdate = false);
 
66
    void           redrawTextArea(bool forcedUpdate = false);
 
67
 
 
68
    qint64         textToFilePosition(int x, int y, bool &isfirst);
 
69
    void           fileToTextPosition(qint64 p, bool isfirst, int &x, int &y);
 
70
 
 
71
    QTextCodec   * codec();
 
72
    int            tabWidth() {
 
73
        return _tabWidth;
 
74
    }
 
75
    bool           hexMode() {
 
76
        return _hexMode;
 
77
    }
 
78
    void           setHexMode(bool hexMode);
 
79
 
 
80
    void           copySelectedToClipboard();
 
81
 
 
82
    void           getCursorPosition(int &x, int &y);
 
83
    qint64         getCursorPosition(bool &isfirst);
 
84
    qint64         getCursorAnchor() {
 
85
        return _cursorAnchorPos;
 
86
    }
 
87
    void           setCursorPosition(qint64 p, bool isfirst);
 
88
    void           ensureVisibleCursor();
 
89
    void           deleteAnchor() {
 
90
        _cursorAnchorPos = -1;
 
91
    }
 
92
 
 
93
    void           setAnchorAndCursor(qint64 anchor, qint64 cursor);
 
94
    void           sizeChanged();
 
95
 
 
96
protected:
 
97
    virtual void   resizeEvent(QResizeEvent * event);
 
98
    virtual void   keyPressEvent(QKeyEvent * e);
 
99
    virtual void   mousePressEvent(QMouseEvent * e);
 
100
    virtual void   mouseDoubleClickEvent(QMouseEvent * e);
 
101
    virtual void   mouseMoveEvent(QMouseEvent * e);
 
102
    virtual void   wheelEvent(QWheelEvent * event);
 
103
 
 
104
    QStringList    readLines(qint64 filePos, qint64 &endPos, int lines, QList<qint64> * locs = 0);
 
105
    QString        readSection(qint64 p1, qint64 p2);
 
106
    void           setUpScrollBar();
 
107
    void           setCursorPosition(int x, int y, int anchorX = -1, int anchorY = -1);
 
108
    void           handleAnchorChange(int oldAnchor);
 
109
    void           getScreenPosition(int position, int &x, int &y);
 
110
 
 
111
protected slots:
 
112
    void           slotActionTriggered(int action);
 
113
    void           slotCursorPositionChanged();
 
114
 
 
115
protected:
 
116
    Lister        *_lister;
 
117
 
 
118
    qint64         _screenStartPos;
 
119
    qint64         _screenEndPos;
 
120
    qint64         _averagePageSize;
 
121
 
 
122
    qint64         _lastPageStartPos;
 
123
 
 
124
    int            _sizeX;
 
125
    int            _sizeY;
 
126
    int            _pageSize;
 
127
 
 
128
    int            _tabWidth;
 
129
 
 
130
    bool           _sizeChanged;
 
131
 
 
132
    QStringList    _rowContent;
 
133
    QList<qint64>  _rowStarts;
 
134
 
 
135
    qint64         _cursorPos;
 
136
    bool           _cursorAtFirstColumn;
 
137
 
 
138
    qint64         _cursorAnchorPos;
 
139
 
 
140
    int            _skippedLines;
 
141
 
 
142
    bool           _inSliderOp;
 
143
    bool           _inCursorUpdate;
 
144
    bool           _hexMode;
 
145
};
 
146
 
 
147
class ListerBrowserExtension : public KParts::BrowserExtension
 
148
{
 
149
    Q_OBJECT
 
150
 
 
151
public:
 
152
    ListerBrowserExtension(Lister * lister);
 
153
 
 
154
public slots:
 
155
    void copy();
 
156
    void print();
 
157
 
 
158
protected:
 
159
    Lister   *_lister;
 
160
};
 
161
 
 
162
 
 
163
class Lister : public KParts::ReadOnlyPart
 
164
{
 
165
    Q_OBJECT
 
166
 
 
167
public:
 
168
    Lister(QWidget *parent);
 
169
    ~Lister();
 
170
 
 
171
    QScrollBar     *scrollBar() {
 
172
        return _scrollBar;
 
173
    }
 
174
    ListerTextArea *textArea() {
 
175
        return _textArea;
 
176
    }
 
177
 
 
178
    inline qint64   fileSize() {
 
179
        return _fileSize;
 
180
    }
 
181
    char *          cacheRef(qint64 filePos, int &size);
 
182
 
 
183
    void            enableSearch(bool);
 
184
    void            enableActions(bool);
 
185
 
 
186
    QString         characterSet() {
 
187
        return _characterSet;
 
188
    }
 
189
    void            setCharacterSet(QString set);
 
190
    void            setHexMode(bool);
 
191
 
 
192
    QStringList     readHexLines(qint64 &filePos, qint64 endPos, int columns, int lines);
 
193
    int             hexBytesPerLine(int columns);
 
194
    int             hexPositionDigits();
 
195
    int             hexIndexToPosition(int columns, int index);
 
196
    int             hexPositionToIndex(int columns, int position);
 
197
 
 
198
 
 
199
public slots:
 
200
    void            searchAction() {
 
201
        enableSearch(true);
 
202
    }
 
203
    void            searchNext();
 
204
    void            searchPrev();
 
205
    void            jumpToPosition();
 
206
    void            saveAs();
 
207
    void            saveSelected();
 
208
    void            print();
 
209
    void            toggleHexMode();
 
210
 
 
211
protected slots:
 
212
    void            slotUpdate();
 
213
    void            slotSearchMore();
 
214
 
 
215
    void            searchSucceeded();
 
216
    void            searchFailed();
 
217
    void            searchDelete();
 
218
    void            searchTextChanged();
 
219
 
 
220
    void            slotFileDataReceived(KIO::Job *, const QByteArray &);
 
221
    void            slotFileFinished(KJob *);
 
222
 
 
223
    void            slotDataSend(KIO::Job *, QByteArray &);
 
224
    void            slotSendFinished(KJob *);
 
225
 
 
226
protected:
 
227
    virtual bool    openUrl(const KUrl &url);
 
228
    virtual bool    closeUrl() {
 
229
        return true;
 
230
    }
 
231
    virtual bool    openFile() {
 
232
        return true;
 
233
    }
 
234
    virtual void    guiActivateEvent(KParts::GUIActivateEvent * event);
 
235
    void            setColor(bool match, bool restore);
 
236
    void            hideProgressBar();
 
237
    void            updateProgressBar();
 
238
    void            resetSearchPosition();
 
239
 
 
240
    qint64          getFileSize();
 
241
    void            search(bool forward, bool restart = false);
 
242
    QStringList     readLines(qint64 &filePos, qint64 endPos, int columns, int lines);
 
243
 
 
244
    QTimer          _updateTimer;
 
245
    ListerTextArea *_textArea;
 
246
    QScrollBar     *_scrollBar;
 
247
    QLabel         *_listerLabel;
 
248
    KLineEdit      *_searchLineEdit;
 
249
    QProgressBar   *_searchProgressBar;
 
250
    QToolButton    *_searchStopButton;
 
251
    QPushButton    *_searchNextButton;
 
252
    QPushButton    *_searchPrevButton;
 
253
    bool            _searchInProgress;
 
254
    bool            _searchHexadecimal;
 
255
    QPushButton    *_searchOptions;
 
256
    QLabel         *_statusLabel;
 
257
 
 
258
    QAction        *_fromCursorAction;
 
259
    QAction        *_caseSensitiveAction;
 
260
    QAction        *_matchWholeWordsOnlyAction;
 
261
    QAction        *_regExpAction;
 
262
    QAction        *_hexAction;
 
263
 
 
264
    KAction        *_actionSaveSelected;
 
265
    KAction        *_actionSaveAs;
 
266
    KAction        *_actionPrint;
 
267
    KAction        *_actionSearch;
 
268
    KAction        *_actionSearchNext;
 
269
    KAction        *_actionSearchPrev;
 
270
    KAction        *_actionJumpToPosition;
 
271
    KAction        *_actionHexMode;
 
272
    ListerEncodingMenu *_actionEncoding;
 
273
 
 
274
    QString         _filePath;
 
275
    qint64          _fileSize;
 
276
 
 
277
    char           *_cache;
 
278
    int             _cacheSize;
 
279
    qint64          _cachePos;
 
280
 
 
281
    bool            _active;
 
282
 
 
283
    KRQuery         _searchQuery;
 
284
    QByteArray      _searchHexQuery;
 
285
    qint64          _searchPosition;
 
286
    bool            _searchIsForward;
 
287
    qint64          _searchLastFailedPosition;
 
288
    int             _searchProgressCounter;
 
289
 
 
290
    QColor          _originalBackground;
 
291
    QColor          _originalForeground;
 
292
 
 
293
    QString         _characterSet;
 
294
 
 
295
    KTemporaryFile *_tempFile;
 
296
 
 
297
    bool            _downloading;
 
298
    bool            _restartFromBeginning;
 
299
 
 
300
    qint64          _savePosition;
 
301
    qint64          _saveEnd;
 
302
};
 
303
 
 
304
#endif // __LISTER_H__