~ubuntu-branches/ubuntu/precise/konversation/precise-updates

« back to all changes in this revision

Viewing changes to .pc/kubuntu_02_marker_line_crash_workaround.diff/src/viewer/ircview.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-11-11 00:14:52 UTC
  • Revision ID: package-import@ubuntu.com-20111111001452-gebhs7i1fzm6zkx2
Tags: 1.3.1-2ubuntu7
Add kubuntu_02_marker_line_crash_workaround.diff from upstream
to fix crashes on refresh, LP: #888825

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  This program is free software; you can redistribute it and/or modify
 
3
  it under the terms of the GNU General Public License as published by
 
4
  the Free Software Foundation; either version 2 of the License, or
 
5
  (at your option) any later version.
 
6
*/
 
7
 
 
8
/*
 
9
  Copyright (C) 2002 Dario Abatianni <eisfuchs@tigress.com>
 
10
  Copyright (C) 2005-2006 Peter Simonsson <psn@linux.se>
 
11
  Copyright (C) 2006-2008 Eike Hein <hein@kde.org>
 
12
*/
 
13
 
 
14
#ifndef IRCVIEW_H
 
15
#define IRCVIEW_H
 
16
 
 
17
#include "common.h"
 
18
 
 
19
#include <QFontDatabase>
 
20
#include <QList>
 
21
 
 
22
#include <KTextBrowser>
 
23
#include <KUrl>
 
24
 
 
25
class Server;
 
26
class ChatWindow;
 
27
 
 
28
 
 
29
class KToggleAction;
 
30
class KMenu;
 
31
 
 
32
#include <QAbstractTextDocumentLayout>
 
33
 
 
34
class IrcViewMarkerLine: public QObject, public QTextObjectInterface
 
35
{
 
36
    Q_OBJECT
 
37
    Q_INTERFACES(QTextObjectInterface)
 
38
 
 
39
    public:
 
40
        IrcViewMarkerLine(QObject *p) : QObject(p), QTextObjectInterface() {}
 
41
        ~IrcViewMarkerLine() {}
 
42
        virtual void drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format);
 
43
        virtual QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format);
 
44
};
 
45
 
 
46
 
 
47
class IRCView : public KTextBrowser
 
48
{
 
49
    Q_OBJECT
 
50
 
 
51
    public:
 
52
        IRCView(QWidget* parent,Server* newServer);
 
53
        ~IRCView();
 
54
 
 
55
        //void clear();
 
56
        //! Some people apparently want the text in the view to be doublespaced :/
 
57
        void enableParagraphSpacing();
 
58
 
 
59
        //! this function is proper given it is not nessary for the ircview to have a server for DCC.
 
60
        void setServer(Server* server);
 
61
        //! FIXME assumes the IRCView looks at a chatwin
 
62
        void setChatWin(ChatWindow* chatWin);
 
63
 
 
64
        // Returns the current nick under context menu.
 
65
        const QString& getContextNick() const;
 
66
 
 
67
        //!Obtain the context menu popup in order to add things to it
 
68
        KMenu* getPopup() const;
 
69
 
 
70
 
 
71
        bool search(const QString& pattern, bool caseSensitive, bool wholeWords, bool forward, bool fromCursor);
 
72
        bool searchNext(bool reversed = false);
 
73
 
 
74
        //! FIXME maybe we should create some sort of palette of our own?
 
75
        QColor highlightColor() { return m_highlightColor; }
 
76
 
 
77
        void updateAppearance();
 
78
 
 
79
        QString currentChannel() { return m_currentChannel; }
 
80
 
 
81
        void setNickAndChannelContextMenusEnabled(bool enable);
 
82
 
 
83
 
 
84
    signals:
 
85
        void gotFocus(); // So we can set focus to input line
 
86
        void textToLog(const QString& text); ///< send the to the log file
 
87
        void sendFile(); ///< a command for a target to which we can DCC send
 
88
        void extendedPopup(int id); ///< this is for the query/nickname popup
 
89
        void autoText(const QString& text); ///< helper for autotext-on-highlight
 
90
        void textPasted(bool useSelection); ///< middle button with no m_copyUrlMenu
 
91
        void popupCommand(int); ///< wired to all of the popup menus
 
92
        void urlsDropped(const KUrl::List urls);
 
93
        void doSearch(); /// Emitted when a search should be started
 
94
        void doSearchNext(); /// Emitted when there's a request to go to the next search result.
 
95
        void doSearchPrevious(); /// Emitted when there's a request to go to the previous search result.
 
96
 
 
97
        void setStatusBarTempText(const QString&); //! these two look like mixins to me
 
98
        void clearStatusBarTempText();//! these two look like mixins to me
 
99
 
 
100
 
 
101
    //// Marker lines
 
102
    public:
 
103
        /// Are there any markers or a remember lines in the view?
 
104
        ///Is used internally now.
 
105
        bool hasLines();
 
106
 
 
107
        /// QTextBlockFormat states for setUserState.
 
108
        enum BlockStates { None = -1, BlockIsMarker = 1, BlockIsRemember = 2 };
 
109
 
 
110
        /// QTextCharFormat object types.
 
111
        enum ObjectFormats { MarkerLine = QTextFormat::UserObject, RememberLine};
 
112
 
 
113
    public slots:
 
114
        /// Inserts a marker line.
 
115
        /// Does not disturb m_rememberLineDirtyBit.
 
116
        void insertMarkerLine();
 
117
 
 
118
        /// Insert a remember line now, or when text is appended. Sets the m_rememberLineDirtyBit
 
119
        /// unless configured to add a remember line at any time.
 
120
        void insertRememberLine();
 
121
 
 
122
        /// Prevents the next append from inserting a remember line.
 
123
        ///Simply clears m_rememberLineDirtyBit.
 
124
        void cancelRememberLine();
 
125
 
 
126
        /// Remove all of the marker lines, and the remember line.
 
127
        /// Does not effect m_rememberLineDirtyBit.
 
128
        void clearLines();
 
129
 
 
130
    protected:
 
131
        virtual QMimeData* createMimeDataFromSelection() const;
 
132
        virtual void dragEnterEvent(QDragEnterEvent* e);
 
133
        virtual void dragMoveEvent(QDragMoveEvent* e);
 
134
        virtual void dropEvent(QDropEvent* e);
 
135
 
 
136
    private:
 
137
        /// The internal mechanics of inserting a line.
 
138
        /// Clears m_rememberLineDirtyBit.
 
139
        void appendRememberLine();
 
140
 
 
141
        /// Create a remember line and insert it.
 
142
        void appendLine(ObjectFormats=MarkerLine);
 
143
 
 
144
        /// Forget the position of the remember line and markers.
 
145
        void wipeLineParagraphs();
 
146
 
 
147
        /// Convenience method - is the last block any sort of line, or a specific line?
 
148
        /// @param select - default value is -1, meaning "is any kind of line"
 
149
        bool lastBlockIsLine(int select=-1);
 
150
 
 
151
        /// Causes a block to stop being a marker.
 
152
        void voidLineBlock(QTextBlock rem);
 
153
 
 
154
        /// Shortcut to get an object format of the desired type
 
155
        QTextCharFormat getFormat(ObjectFormats);
 
156
 
 
157
    private slots:
 
158
        /** Called to see if a marker is queued up for deletion. Only triggers if
 
159
            "where" is the beginning and there was nothing added.
 
160
        */
 
161
        void cullMarkedLine(int, int, int);
 
162
 
 
163
    private: //marker/remember line data
 
164
        bool m_nextCullIsMarker; ///< the next time a cull occurs, it'll be a marker
 
165
        QList<QTextBlock> m_markers; ///< what blocks are markers?
 
166
        int m_rememberLinePosition; ///< position of remember line in m_markers
 
167
        bool m_rememberLineDirtyBit; ///< the next append needs a remember line
 
168
        IrcViewMarkerLine markerFormatObject; ///< a QTextObjectInterface
 
169
 
 
170
    //// Other stuff
 
171
    public slots:
 
172
        //! FIXME enum { Raw, Query, Query+Action, Channel+Action, Server Message, Command Message, Backlog message } this looks more like a tuple
 
173
        void append(const QString& nick, const QString& message);
 
174
        void appendRaw(const QString& message, bool suppressTimestamps=false, bool self = false);
 
175
        void appendLog(const QString& message);
 
176
 
 
177
        void appendQuery(const QString& nick, const QString& message, bool inChannel = false);
 
178
        void appendQueryAction(const QString& nick, const QString& message);
 
179
    protected:
 
180
        //! FIXME why is this protected, and all alone down there?
 
181
        void appendAction(const QString& nick, const QString& message);
 
182
 
 
183
        /// Appends a new line without any scrollback or notification checks
 
184
        void doRawAppend(const QString& newLine, bool rtl);
 
185
 
 
186
    public slots:
 
187
        void appendChannelAction(const QString& nick, const QString& message);
 
188
 
 
189
        void appendServerMessage(const QString& type, const QString& message, bool parseURL = true);
 
190
        void appendCommandMessage(const QString& command, const QString& message, bool important, bool parseURL=true, bool self=false);
 
191
        void appendBacklogMessage(const QString& firstColumn, const QString& message);
 
192
 
 
193
    protected:
 
194
        void doAppend(const QString& line, bool rtl, bool self=false);
 
195
 
 
196
        void updateNickMenuEntries(const QString& nickname);
 
197
 
 
198
    public slots:
 
199
        /// Emits the doSeach signal.
 
200
        void findText();
 
201
        /// Emits the doSeachNext signal.
 
202
        void findNextText();
 
203
        /// Emits the doSeachPrevious signal.
 
204
        void findPreviousText();
 
205
 
 
206
        //! FIXME eh? what is this?
 
207
        void setCurrentChannel(const QString& channel) { m_currentChannel = channel; }
 
208
 
 
209
        /// Overwritten so the scrollview remains not freaked out
 
210
        //virtual void removeSelectedText(int selNum=0);
 
211
        //! TODO FIXME meta, derived
 
212
        //virtual void scrollToBottom();            // Overwritten for internal reasons
 
213
 
 
214
        // Clears context nick
 
215
        //! The name of this method is unclear enough that it needs documentation, but clear enough that the documentation just needs to be a repeat of the name. Thanks for playing, but get some kills next time.
 
216
        void clearContextNick();
 
217
 
 
218
        // Updates the scrollbar position
 
219
        //! Again. Really? Two in a row? Couldn't be more inventive, whoever you are? Come on, show some personality. Let your vocabulary loose! Because right now its looking like you don't know what you're taking about.
 
220
        //void updateScrollBarPos();
 
221
 
 
222
    protected slots:
 
223
        void highlightedSlot(const QString& link);
 
224
        void saveLinkAs();
 
225
        void anchorClicked(const QUrl& url);
 
226
        void copyUrl();
 
227
        void slotBookmark();
 
228
        void handleContextActions();
 
229
 
 
230
    protected:
 
231
        void openLink(const QUrl &url);
 
232
 
 
233
        QString filter(const QString& line, const QString& defaultColor, const QString& who=NULL, bool doHighlight=true, bool parseURL=true, bool self=false);
 
234
 
 
235
        void replaceDecoration(QString& line,char decoration,char replacement);
 
236
 
 
237
        virtual void resizeEvent(QResizeEvent *event);
 
238
        virtual void mouseReleaseEvent(QMouseEvent* ev);
 
239
        virtual void mousePressEvent(QMouseEvent* ev);
 
240
        virtual void mouseMoveEvent(QMouseEvent* ev);
 
241
        virtual void keyPressEvent(QKeyEvent* ev);
 
242
        virtual void contextMenuEvent(QContextMenuEvent* ev);
 
243
 
 
244
        bool contextMenu(QContextMenuEvent* ce);
 
245
 
 
246
        void setupNickPopupMenu(bool isQuery);
 
247
        void updateNickMenuEntries(KMenu* popup, const QString& nickname);
 
248
        void setupChannelPopupMenu();
 
249
 
 
250
        QChar::Direction basicDirection(const QString &string);
 
251
 
 
252
        /// Returns a formated timestamp if timestamps are enabled else it returns QString::null
 
253
        QString timeStamp();
 
254
 
 
255
        /// Returns a formated nick string
 
256
        //! FIXME formatted in what way?
 
257
        QString createNickLine(const QString& nick, const QString& defaultColor,
 
258
            bool encapsulateNick = true, bool privMsg = false);
 
259
 
 
260
 
 
261
 
 
262
        //// Search
 
263
        QTextDocument::FindFlags m_searchFlags;
 
264
        bool m_forward;
 
265
        QString m_pattern;
 
266
 
 
267
        //used in ::filter
 
268
        QColor m_highlightColor;
 
269
 
 
270
 
 
271
        QString m_lastStatusText; //last sent status text to the statusbar. Is empty after clearStatusBarTempText()
 
272
 
 
273
        bool m_resetScrollbar; ///< decide if we should place the scrollbar at the bottom on show()
 
274
 
 
275
        //used in ::filter
 
276
        QString m_autoTextToSend;
 
277
 
 
278
        //TODO FIXME light this on fire and send it sailing down an uncharted river riddled with arrows
 
279
        Konversation::TabNotifyType m_tabNotification;
 
280
 
 
281
 
 
282
        //QString m_buffer; ///< our text
 
283
        Server* m_server; //! FIXME assumes we have a server
 
284
 
 
285
        //// Popup menus
 
286
        KMenu* m_popup; ///< text area context menu
 
287
        QAction* copyUrlMenuSeparator;
 
288
        QAction* m_copyUrlClipBoard;
 
289
        QAction* m_bookmark;
 
290
        QAction* m_saveUrl;
 
291
        KToggleAction* m_ignoreAction;
 
292
        QAction* m_addNotifyAction;
 
293
        bool m_copyUrlMenu; ///<the menu we're popping up, is it for copying URI?
 
294
        KMenu* m_nickPopup; ///<menu to show when context-click on a nickname
 
295
        KMenu* m_channelPopup; ///<menu to show when context-click on a channel
 
296
 
 
297
 
 
298
        QString m_urlToCopy; ///< the URL we might be about to copy
 
299
 
 
300
        //// RTL hack
 
301
        static QChar LRM;
 
302
        static QChar RLM;
 
303
        static QChar LRE;
 
304
        static QChar RLE;
 
305
        static QChar RLO;
 
306
        static QChar LRO;
 
307
        static QChar PDF;
 
308
 
 
309
        //// Nickname colorization
 
310
        uint m_offset;
 
311
        QStringList m_colorList;
 
312
 
 
313
        QString m_currentNick;
 
314
        QString m_currentChannel;
 
315
        bool m_isOnNick; ///< context menu click hit a nickname
 
316
        bool m_isOnChannel; ///< context menu click hit a channel
 
317
        bool m_mousePressed; ///< currently processing a mouse press
 
318
        QString m_urlToDrag; ///< we took a stab at whatever was clicked on, may or may not actually be a URL
 
319
        QPoint m_pressPosition; ///< x,y of the click, relative to the GPS location of tip of Phantom's left ear
 
320
 
 
321
        //! TODO FIXME i'll bite. why do we have this in here?
 
322
        QFontDatabase m_fontDataBase;
 
323
 
 
324
        ChatWindow* m_chatWin;
 
325
        friend class IRCStyleSheet;
 
326
};
 
327
#endif