add a separate header file for MetaContact::Private class
[kdenetwork.git] / ksirc / toplevel.h
blob92fc0c905ac9b301c14f3922178c24ffa46511bf
1 #ifndef KSIRCTOPLEVEL_H
2 #define KSIRCTOPLEVEL_H
4 #include <qdatetime.h>
5 #include <Q3Accel>
6 //Added by qt3to4:
7 #include <QByteArray>
8 #include <QCloseEvent>
9 #include <Q3PtrList>
10 #include <QEvent>
11 #include <QLabel>
12 #include <Q3PopupMenu>
13 #include <kmainwindow.h>
15 #include "ahistlineedit.h"
16 #include "messageReceiver.h"
17 #include "chanButtons.h"
18 #include "KSTicker/ksticker.h"
19 #include "ksircchannel.h"
21 #define KST_CHANNEL_ID 2
23 class KSircTopic;
24 class QSplitter;
25 class KSircView;
26 class aListBox;
27 class UserControlMenu;
28 class ChannelParser;
29 class charSelector;
30 class LogFile;
31 class KSelectAction;
32 class QLabel;
33 class KVBox;
34 class Q3ListBoxItem;
36 class Q3PopupMenu;
38 class KSircTopLevel : public KMainWindow,
39 public UnicodeMessageReceiver
41 Q_OBJECT
42 friend class ChannelParser;
43 public:
44 /**
45 * Constructor, needs the controlling ksircprocess passed to it, so
46 * we can make the ksircmessage receiver happy.
48 KSircTopLevel(KSircProcess *_proc, const KSircChannel &channelInfo, const char *
49 name=0);
50 /**
51 * Destructor, destroys itself.
53 ~KSircTopLevel();
55 /**
56 * Reimplement show() to popup the menu bars and toolbar items
58 virtual void show();
60 /**
61 * Line recieved that should be printed on the screen. Unparsed, and
62 * ready processing. This is a single line, and it NOT \n
63 * terminated.
65 virtual void sirc_receive(QString str, bool broadcast = false);
67 /**
68 * Reimplement the ksircmessagereceiver control messages. These
69 * are parsed and dealt with quickly.
71 virtual void control_message(int, QString);
73 QWidget *lineEdit() const { return linee; }
75 void setTopic( const QString &topic );
76 QString topic() const { return m_topic; }
78 /**
79 * This returns the current channel information for a toplevel
81 const KSircChannel &channelInfo() const { return m_channelInfo; }
83 signals:
84 /**
85 * signals thats the toplevel widget wishes to
86 * output a new line. The line is correctly
87 * linefeed terminated, etc.
89 void outputLine(QByteArray);
90 /**
91 * open a new toplevel widget with for the
92 * channel/user QString.
94 void open_toplevel(const KSircChannel &);
95 /**
96 * emittedon shutdown, indicating that
97 * this window is closing. Refrence to outselves
98 * is include.
100 void closing(KSircTopLevel *, QString channel);
102 * emitted when the user typed /quit, will disconnect from this
103 * server and close all toplevels belonging to it.
105 void requestQuit( const QByteArray& command );
107 * emitted when we change channel name
108 * on the fly. old is the old channel name, new
109 * is the new one.
111 void changeChannel(const QString &oldName, const QString &newName);
113 * emitted to say that KSircTopLevel
114 * (this) is now the window with focus. Used by
115 * servercontroller to set the !default window.
117 void currentWindow(KSircTopLevel *);
119 * Stop updating list item sizes, majour changes comming through
122 void freezeUpdates(bool);
124 * Emitted when a new message appeared in the irc window
126 void changed(bool, QString);
128 public slots:
130 * When enter is pressed, we read the SLE and output the results
131 * after processing via emitting outputLine.
133 virtual void sirc_line_return(const QString &s);
136 * Clears the message window
138 void clearWindow();
141 * If the focus shifts this should get called with
142 * the widget that just got focus. Used in MDI modes
143 * where the toplevel doesn't get focus in/out events.
145 void focusChange(QWidget *w);
147 protected slots:
149 * When the rightMouse button is pressed in the nick list, popup
150 * the User popup menu at his cursor location.
152 void UserSelected(int index);
154 * Menu items was selected, now read the UserControlMenu and
155 * reupdate the required menus.
157 void UserParseMenu(int id);
159 * Page down accel key. Tells the mainw to scroll down 1 page.
161 void AccelScrollDownPage();
163 * Page Up accell key. Tells the mainw to scroll down 1 page.
165 void AccelScrollUpPage();
167 * Slot to termiate (close) the window.
169 void terminate() { close( true /*alsoDelete*/ ); }
171 * Called when the user menu is finished and the popup menu needs
172 * to be updated.
174 void UserUpdateMenu();
176 * Open the new channel/window selector.
178 void newWindow();
180 * We've received focus, let's make us the default, and issue a
181 * /join such that we default to the right channel.
183 void gotFocus();
185 * We've lost focus, set ourselves as loosing focus.
187 void lostFocus();
189 * Create and popup the ticker. Make sure to restore it to the
190 * last position is was at.
192 // void showTicker();
194 * toggle the timestamp from the channel window menu (and with keyaccel)
196 void toggleTimestamp();
198 * toggle the filtering of join/part message
200 void toggleFilterJoinPart();
203 * toggle the beep from the channel window menu (and with keyaccel)
205 void toggleBeep();
208 * show the dcc manager
210 void showDCCMgr();
213 * Delete the ticker and ppoup the main window
215 // void unHide();
217 * On a TAB key press we call TabNickCompletion which
218 * reads the last thing in linee matches it with a nick and
219 * puts it back into the line.
221 void TabNickCompletionShift();
223 * On a TAB key press we call TabNickCompletion which
224 * reads the last thing in linee matches it with a nick and
225 * puts it back into the line.
227 void TabNickCompletionNormal();
230 * Signals a Line Change in linee
232 void lineeNotTab();
234 * Move the display to or from the root window
237 void toggleRootWindow();
239 * On a middle mouse button press we call pasteToWindow which
240 * reads the clip board and pastes into the main listbox.
242 void pasteToWindow();
244 * On a midle mouse button press to the nick list we open
245 * a query window and paste the text there
247 void pasteToNickList(int button, Q3ListBoxItem *item, const QPoint &pos);
249 * dnd paste to nick list
251 void dndTextToNickList(const Q3ListBoxItem *itom, const QString& text);
253 * open a toplevel on double click
255 void openQueryFromNick(const QString &);
258 * Some text was dropped on the listbox
260 void slotTextDropped(const QString&);
263 * Calls slotDccURLs with the current nick we're talking to
265 void slotDropURLs(const QStringList& urls);
268 * Sends the list of urls to nick
270 void slotDccURLs(const QStringList& urls, const QString& nick );
273 * Re-apply color settings.
275 void initColors();
278 * Dumps current content of mainw into a logfile
280 void saveCurrLog();
283 * Makes a beep when a change happens (if the user has this on)
284 * the bool is TRUE if changed line contained user's nick
286 void doChange(bool, QString);
289 * show the ticker window
291 void toggleTicker();
294 * ksirc command menu clicked on
296 void cmd_process(int id);
298 protected:
300 * On a TAB key press we call TabNickCompletion which
301 * reads the last thing in linee matches it with a nick and
302 * puts it back into the line.
304 void TabNickCompletion(int dir);
307 * Make sure to update colors correctly.
309 virtual bool event( QEvent *e);
312 * Redfine closeEvent to emit closing and delete itself.
314 virtual void closeEvent(QCloseEvent *);
316 * Searches through the nick list and finds the nick with the best match.
317 * which, arg2, selects nicks other than the first shouldarg1 match more
318 * than 1 nick.
320 virtual QString findNick(QString, uint which = 0);
322 * remove a nick from the prefered in nick completion list
324 virtual void removeCompleteNick(const QString &);
326 * Adds a nick to the list of nicks to prefer in nick completion
327 * or moves it to the top of the list if it was already there
329 virtual void addCompleteNick(const QString &);
331 * Changes a nick in the completion list if it has been listed,
332 * otherwise does nothing
334 virtual void changeCompleteNick(const QString &, const QString &);
336 virtual void setupCommandMenu();
339 * Returns true if this window is a private conversation (query or dcc chat)
340 *, instead of a public chat in a channel or a special window.
342 bool isPrivateChat() const;
345 * Returns true if this is a public channel window
347 bool isPublicChat() const;
350 * Returns true if this is a special window
352 bool isSpecialWindow() const;
354 private slots:
355 void setTopicIntern( const QString &topic );
356 void insertText();
357 void setMode(QString, int, QString currentNick=0);
358 void setEncoding();
359 void returnPressed();
360 void toggleTopic();
362 private:
364 void outputUnicodeLine( const QString &message );
366 bool atBottom();
368 bool continued_line;
369 charSelector *selector;
370 chanButtons *channelButtons;
371 QSplitter *pan;
372 KVBox *nicks_box;
373 KMenuBar *kmenu;
374 QLabel *lag;
375 enum {PING = 10, TOPIC = 20};
376 KSircView *mainw;
377 aHistLineEdit *linee;
378 aListBox *nicks;
380 //QString m_currentNick;
382 //KSircProcess *proc;
384 int lines;
386 struct BufferedLine
388 BufferedLine() { wasBroadcast = false; }
389 BufferedLine( const QString &msg, bool broadc )
390 { message = msg; wasBroadcast = broadc; }
391 bool operator==( const BufferedLine &other )
392 { return message == other.message &&
393 wasBroadcast == other.wasBroadcast; }
395 QString message;
396 bool wasBroadcast;
399 bool Buffer;
400 QList<BufferedLine> LineBuffer;
402 // QPopupMenu's used for the menubar
403 Q3PopupMenu *file, *edit, *command;
405 bool parse_input(const QString &string, QString &plainText);
406 void sirc_write(const QString &str);
408 Q3PopupMenu *user_controls;
409 static Q3PtrList<UserControlMenu> *user_menu;
410 int opami;
412 Q3Accel *accel;
415 * The channel name that we belong too.
417 //QString channel_name;
420 * Caption at the top of the window.
422 QString caption;
424 * Current topic for the channel
426 QString m_topic;
429 * Does the window have focus? 1 when yes, 0 when no.
431 int have_focus;
434 * Number of time tab has been pressed. Each time it's pressed
435 * roll through the list of matching nicks.
437 int tab_pressed;
439 * When tabs pressed save the line for use at a latter date.
440 * tab_nick holds the last nick found so when a blank tab is pressed
441 * we pop the last niick and ": " up.
443 QString tab_saved, tab_nick;
444 int tab_start, tab_end;
446 // Ticker specific variables.
449 * Main pointer to ksticker. Caution, it doesn't always exist!
450 * Set to 0 ifwhen you delete it.
452 KSTicker *ticker;
454 * Size and position of the main window. Main window is returns this
455 * this position when it reappears.
457 QRect myrect;
459 * Position of the main window
461 QPoint mypoint;
463 * Ticker's size and geometry
465 QRect tickerrect;
467 * Tickers position
469 QPoint tickerpoint;
470 QSize tickersize;
472 * Do we have a kick window open?
473 * Remember not to open 2
475 bool KickWinOpen;
478 * Hold an internal parser object which does all our parsing for us.
479 * Since parsing an intergral part of TopLevel, it's also a friend
480 * of ours
482 ChannelParser *ChanParser;
485 * QSize maintains size information in case it changes somehow
487 QSize current_size;
490 * ID of the timestamp menu item, to use in (un)checking it from slot
492 int tsitem;
495 * ID of the filter join/part menu item, to use in (un)checking it from slot
497 int fjpitem;
500 * ID of the beep menu item, to use in (un)checking it from slot
502 int beepitem;
505 * ID of the toggle topic menu item, to use in (un)checking it from slot
507 int topicitem;
510 * ID of the show/hide ticker menu item
512 int tickeritem;
515 * List of nicks already used in nick completion to give them
516 * higher priority
518 QStringList completeNicks;
521 * The time of the last beep to prevent your soundcard from detonating
522 * in high traffic channels
524 QTime lastBeep;
526 KSircTopic *ksTopic;
528 LogFile *logFile;
530 KSelectAction *encodingAction;
532 static QStringList cmd_menu;
534 bool m_gotMsgWithoutFocus;
536 KSircChannel m_channelInfo;
540 #endif
542 // vim: ts=2 sw=2 et