KVIrc 5.2.6
Developer APIs
KviWindow.h
Go to the documentation of this file.
1#ifndef _KVI_WINDOW_H_
2#define _KVI_WINDOW_H_
3//=============================================================================
4//
5// File : KviWindow.h
6// Creation date : Tue Jul 6 1999 14:52:20 by Szymon Stefanek
7//
8// This file is part of the KVIrc IRC client distribution
9// Copyright (C) 1999-2010 Szymon Stefanek (pragma at kvirc dot net)
10//
11// This program is FREE software. You can redistribute it and/or
12// modify it under the terms of the GNU General Public License
13// as published by the Free Software Foundation; either version 2
14// of the License, or (at your option) any later version.
15//
16// This program is distributed in the HOPE that it will be USEFUL,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19// See the GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program. If not, write to the Free Software Foundation,
23// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24//
25//=============================================================================
26
32#include "kvi_settings.h"
33#include "KviApplication.h"
34#include "KviCString.h"
35#include "KviQString.h"
36#include "KviIrcContext.h"
37#include "KviIrcConnection.h"
38#include "KviInput.h"
39#include "KviTalHBox.h"
40#include "KviTalSplitter.h"
41#include "KviIconManager.h"
42
43#include <QFrame>
44#include <QWidget>
45#include <QToolButton>
46#include <QTextEncoder>
47#include <QByteArray>
48#include <QDateTime>
49
50class QPushButton;
51class QPixmap;
52class QTextCodec;
53class KviMainWindow;
56class KviIrcView;
60class QMenu;
61class KviTalHBox;
62
63#ifdef COMPILE_CRYPT_SUPPORT
64class KviCryptController;
65class KviCryptSessionInfo;
66#endif
67
68#define KVI_WINDOW_TYPE_USER 10000
69
74class KVIRC_API KviWindow : public QWidget
75{
76 friend class KviInput;
77 friend class KviMainWindow;
78 friend class KviWindowStack;
79 friend class KviWindowListItem;
80 friend class KviWindowListButton;
82 friend class KviTreeWindowList;
84 Q_PROPERTY(int KviProperty_ChildFocusOwner READ type)
85 Q_OBJECT
86public:
92 {
93 None = 0,
94 VeryLow = 1,
95 Low = 2,
96 Medium = 3,
97 High = 4,
98 VeryHigh = 5
99 };
100
106 {
107 Ice = 0,
108 VeryCold = 1,
109 Cold = 2,
110 Undefined = 3,
111 Hot = 4,
112 VeryHot = 5,
113 Fire = 6
114 };
115
121 {
122 VisibleAndActive = 0,
123 MainWindowIsVisible = 1
124 };
130 enum Type
131 {
132 Console = 0,
133 Channel = 1,
134 Query = 2,
135 DeadChannel = 3,
136 DeadQuery = 4,
137 Editor = 5,
138 Help = 6,
139 Terminal = 7,
140 SocketSpy = 8,
141 Links = 9,
142 List = 10,
143 DccChat = 11,
144 DccTransfer = 12,
145 DccCanvas = 13,
146 DccVoice = 14,
147 DccVideo = 15,
149 Tool = 17,
150 IOGraph = 18,
151 DirBrowser = 19,
152 ScriptEditor = 20,
153 ScriptObject = 21,
154 LogView = 22,
155 Offer = 23,
156 Debug = 24,
157 Unknown = 25,
158 TypeCount = 26
159 };
160
169 KviWindow(Type eType, const QString & szName, KviConsoleWindow * pConsole = nullptr);
170
174 ~KviWindow();
175
176protected: // almost private: don't touch :D
177 QString m_szName; // the current window name (usually also the target)
187 unsigned long int m_uId;
189#ifdef COMPILE_CRYPT_SUPPORT
190 KviWindowToolPageButton * m_pCryptControllerButton;
191 KviCryptController * m_pCryptController;
192 KviCryptSessionInfo * m_pCryptSessionInfo;
193#endif
195 QToolButton * m_pHideToolsButton;
197 static const char * m_typeTable[TypeCount];
198 // text encoding and decoding
199 //unsigned int m_uTextEncoding;
200 QTextCodec * m_pTextCodec;
201 //KviToolWindowsContainer * m_pEditorsContainer;
204
205public:
206 bool isDocked() const { return m_bIsDocked; }
207
214 QString id() const { return QString("%1").arg(m_uId); }
215
222 unsigned long int numericId() const { return m_uId; }
223
228 const QString & windowName() const { return m_szName; }
229
235 void setWindowName(const QString & szName);
236
244 void setProgress(int iProgress);
245
250 Type type() const { return m_eType; }
251
255 bool isChannel() const { return m_eType == Channel; }
256
260 bool isQuery() const { return m_eType == Query; }
261
265 bool isConsole() const { return m_eType == Console; }
266
271 virtual const char * typeString();
272
273 QTextCodec * textCodec() { return m_pTextCodec ? m_pTextCodec : defaultTextCodec(); }
274 void forceTextCodec(QTextCodec * pCodec);
275
282 KviIrcView * view() const { return m_pIrcView; }
283
291 virtual KviIrcView * lastClickedView() const { return m_pIrcView; };
292
299 KviConsoleWindow * console() const { return m_pConsole; }
300
301 KviIrcContext * context();
302
307 KviIrcConnection * connection();
308
315 KviTalSplitter * splitter() const { return m_pSplitter; }
316
323 KviWindowListItem * windowListItem() const { return m_pWindowListItem; }
324
325 // The window *might* have a button container
326 virtual QFrame * buttonContainer() { return (QFrame *)m_pButtonBox; };
327 virtual void toggleButtonContainer();
328
329 // The window *might* have an output proxy: if it has no view() for example
330 virtual KviWindow * outputProxy();
331
332 // The window input widget
333 KviInput * input() const { return m_pInput; }
334
335 // The target of this window: empty when it makes no sense :D
336 virtual const QString & target() { return KviQString::Empty; };
337
338 // The local nickname bound to this window: might be empty when a local nickname makes no sense
339 virtual const QString & localNick() { return KviQString::Empty; };
340
341#ifdef COMPILE_CRYPT_SUPPORT
342 KviCryptSessionInfo * cryptSessionInfo()
343 {
344 return m_pCryptSessionInfo;
345 };
346 void setCryptSessionInfo(KviCryptSessionInfo * pInfo);
347#endif
348
349 virtual bool activityMeter(unsigned int * puActivityValue, unsigned int * puActivityTemperature);
350
351 //* \param puValue Highlight level
352 virtual bool highlightMeter(unsigned int * puValue);
353 virtual bool highlightMe(unsigned int uValue);
354
355 void unhighlight();
356
357 virtual void getWindowListTipText(QString & szBuffer) { szBuffer = m_szPlainTextCaption; }
358
359 // This is meaningful only if view() is non nullptr
360 const QString & lastLineOfText();
361 const QString & lastMessageText();
362
363 const QString & textEncoding() const { return m_szTextEncoding; }
364 // returns true if the encoding could be successfully set
365 bool setTextEncoding(const QString & szTextEncoding);
366 // this must return a default text codec suitable for this window
367 virtual QTextCodec * defaultTextCodec();
368 // encode the text from szSource by using m_uTextEncoding
369 QByteArray encodeText(const QString & szText);
370 QString decodeText(const char * pcText);
371 //return a text encoder
372 QTextEncoder * makeEncoder();
373
374 void contextPopup();
375 // Raises the window (after a light delay to prevent focus pingpongs)
376 void delayedAutoRaise();
377
378 // Retrieves the default log file name: this is pre-build
379 void getDefaultLogFileName(QString & szBuffer);
380 void getDefaultLogFileName(QString & szBuffer, QDate date, bool bGzip, unsigned int uDatetimeFormat);
381
382 void delayedClose(); // close that jumps out of the current event loop
383
384 // Interesting overridables:
385 virtual void getConfigGroupName(QString & szBuffer);
386 virtual void getBaseLogFileName(QString & szBuffer);
387 virtual void updateCaption();
388 virtual void applyOptions();
389 virtual void updateIcon();
390 virtual void ownMessage(const QString &, bool = true){};
391 virtual void ownAction(const QString &){};
392 virtual const QString & plainTextCaption() { return m_szPlainTextCaption; };
393
394 void internalOutput(KviIrcView * pView, int iMsgType, const kvi_wchar_t * pwText, int iFlags = 0, const QDateTime & datetime = QDateTime());
395 // You *might* want to override these too.. but better don't touch them :D
396 virtual void output(int iMsgType, const char * pcFormat, ...);
397 virtual void output(int iMsgType, const kvi_wchar_t * pwFormat, ...);
398 virtual void output(int iMsgType, QString szFmt, ...);
399 void output(int iMsgType, const QDateTime & datetime, const char * pcFormat, ...);
400 void output(int iMsgType, const QDateTime & datetime, const kvi_wchar_t * pwFormat, ...);
401 void output(int iMsgType, const QDateTime & datetime, QString szFmt, ...);
402 virtual void outputNoFmt(int iMsgType, const char * pcText, int iFlags = 0, const QDateTime & datetime = QDateTime());
403 virtual void outputNoFmt(int iMsgType, const kvi_wchar_t * pwText, int iFlags = 0, const QDateTime & datetime = QDateTime()) { internalOutput(m_pIrcView, iMsgType, pwText, iFlags, datetime); };
404 virtual void outputNoFmt(int iMsgType, const QString & szText, int iFlags = 0, const QDateTime & datetime = QDateTime()); // <-- iFlags are KviIrcView::AppendTextFlags
405 // Just helpers.. FIXME: might be redesigned in some other way
406 void updateBackgrounds(QObject * pObj = nullptr);
407
416 void demandAttention();
417
429 bool hasAttention(AttentionLevel eLevel = VisibleAndActive);
430
431 // This should die, probably
432 void listWindowTypes();
433
434 // call this in the constructor if your caption is fixed:
435 // it will set m_szPlainTextCaption to szCaption and it will
436 // automatically use it without the need of overriding fillCaptionBuffers
437 void setFixedCaption(const QString & szCaption) { m_szPlainTextCaption = szCaption; }
438
439 void setWindowTitle(QString & szTitle);
440
449 void pasteLastLog();
450
451private:
460 QByteArray loadLogFile(const QString & szFileName, bool bGzip);
461
462protected:
463 // Loading and saving of properties
464 // Protected: only KviMainWindow can call these
465 virtual void saveProperties(KviConfigurationFile * pCfg);
466 virtual void loadProperties(KviConfigurationFile * pCfg);
467 // Creation and destruction events: overridden in windows that have script events bound to creation and destruction
468 virtual void triggerCreationEvents(){};
469 virtual void triggerDestructionEvents(){};
470 // Internal: do not touch :D (KviMainWindow)
471 virtual void createWindowListItem();
472 virtual void destroyWindowListItem();
473 // called by KviMainWindow
474 // either lost the active window status or the frame is no longer active (but we're still the active kvirc's subwindow)
475 virtual void lostUserFocus();
476 // this by default calls fillSingleColorCaptionBuffer(plainTextCaption());
477 virtual void fillCaptionBuffers();
478 // protected helper
479 void fillSingleColorCaptionBuffers(const QString & szName) { m_szPlainTextCaption = szName; }
480 // Virtual events that signal dock state change
481 virtual void youAreDocked();
482 virtual void youAreUndocked();
483 // Reimplement to show a special icon in the WindowList items and captions
484 virtual QPixmap * myIconPtr();
485 // Sets the type of this window: be careful with this
486 void setType(Type eType) { m_eType = eType; };
487
488 bool eventFilter(QObject * pObject, QEvent * pEvent) override;
489
490 // Virtuals overridden to manage the internal layouts...
491 void moveEvent(QMoveEvent * pEvent) override;
492 void closeEvent(QCloseEvent * pEvent) override;
493 void childEvent(QChildEvent * pEvent) override;
494 void focusInEvent(QFocusEvent *) override;
495 void inputMethodEvent(QInputMethodEvent * e) override;
496
497 void childInserted(QWidget * pObject);
498 void childRemoved(QWidget * pObject);
499
500 // Internal helpers
501 void createCryptControllerButton(QWidget * pPar);
502 void createTextEncodingButton(QWidget * pPar);
503 void createSystemTextEncodingPopup();
504
505 QToolButton * createToolButton(QWidget * pPar, const char * pcName, KviIconManager::SmallIcon eIcon, const QString & szToolTip, bool bOn);
506 // This is called by KviInput: actually it links the widgetAdded
507 virtual void childrenTreeChanged(QWidget * pAdded);
508
509 bool focusNextPrevChild(bool bNext) override;
510
511 virtual void preprocessMessage(QString & szMessage);
512public slots:
513 void dock();
514 void undock();
515 void autoRaise();
516 void reloadImages();
517 void savePropertiesAsDefault();
518protected slots:
519 void toggleCryptController(); // This has to be here even if the crypt support is enabled...moc does not support conditionals
520 void cryptControllerFinished(); // same as above
521 void cryptSessionInfoDestroyed(); // same as above
522 void textEncodingButtonClicked();
523 void systemTextEncodingPopupActivated(QAction * pAction);
524 void childDestroyed();
525signals:
527};
528
529#ifndef _KVI_WINDOW_CPP_
530// The active window:
531// This is almost always non null
532// The exception is the startup (when there are no windows at all)
533// and the last phase of the destructor.
534// You usually shouldn't care of checking this pointer for nullptr unless
535// you're running very early at startup or very late at shutdown
537#endif
538
539inline QByteArray KviWindow::encodeText(const QString & szText)
540{
541 if(m_pTextCodec)
542 return m_pTextCodec->fromUnicode(szText);
543 else
544 return defaultTextCodec()->fromUnicode(szText);
545}
546
547inline QString KviWindow::decodeText(const char * pcText)
548{
549 if(m_pTextCodec)
550 return m_pTextCodec->toUnicode(pcText);
551 else
552 return defaultTextCodec()->toUnicode(pcText);
553}
554
555#endif //_KVI_WINDOW_H_
kvi_u16_t kvi_wchar_t
Definition KviCString.h:85
Icon manager.
Input handling.
An abstraction of a connection to an IRC server.
Helper functions for the QString class.
Class for horizontal box.
Class used to workaround unwanted behaviours in QSplitter.
#define KviTalSplitter
Definition KviTalSplitter.h:34
KVIRC_API KviWindow * g_pActiveWindow
Definition KviWindow.cpp:93
Definition KviConfigurationFile.h:50
Definition KviConsoleWindow.h:74
SmallIcon
Contains all KVIrc's small icons.
Definition KviIconManager.h:170
Input handling class.
Definition KviInput.h:54
An abstraction of a connection to an IRC server.
Definition KviIrcConnection.h:97
Definition KviIrcContext.h:60
Definition KviIrcView.h:60
Definition KviMainWindow.h:58
Toolkit Abstraction Layer: hbox class.
Definition KviTalHBox.h:44
Definition KviTreeWindowList.h:123
Definition KviTreeWindowList.h:36
Definition KviTreeWindowList.h:87
Definition KviWindowListBase.h:125
Definition KviWindowListBase.h:50
Handles all docked KviWindow windows.
Definition KviWindowStack.h:47
Definition KviWindowToolWidget.h:47
Base class for all windows in KVIrc.
Definition KviWindow.h:75
ActivityTemperature
Holds the activity meter in temperature scale.
Definition KviWindow.h:106
QToolButton * m_pHideToolsButton
Definition KviWindow.h:195
virtual void triggerDestructionEvents()
Definition KviWindow.h:469
void fillSingleColorCaptionBuffers(const QString &szName)
Definition KviWindow.h:479
bool isChannel() const
Definition KviWindow.h:255
QByteArray encodeText(const QString &szText)
Definition KviWindow.h:539
void windowNameChanged()
const QString & windowName() const
Returns the name of this window.
Definition KviWindow.h:228
bool m_bProcessingInputEvent
Definition KviWindow.h:203
Type m_eType
Definition KviWindow.h:179
QTextCodec * textCodec()
Definition KviWindow.h:273
virtual KviIrcView * lastClickedView() const
Returns the KviIrcView that was last clicked in this window.
Definition KviWindow.h:291
QString id() const
Returns the global ID of this window.
Definition KviWindow.h:214
virtual void outputNoFmt(int iMsgType, const kvi_wchar_t *pwText, int iFlags=0, const QDateTime &datetime=QDateTime())
Definition KviWindow.h:403
QWidget * m_pFocusHandler
Definition KviWindow.h:181
AttentionLevel
attention levels usable in hasAttention()
Definition KviWindow.h:121
KviWindowListItem * m_pWindowListItem
Definition KviWindow.h:180
QString decodeText(const char *pcText)
Definition KviWindow.h:547
virtual void triggerCreationEvents()
Definition KviWindow.h:468
virtual const QString & plainTextCaption()
Definition KviWindow.h:392
KviConsoleWindow * console() const
Returns the console that this window belongs to.
Definition KviWindow.h:299
virtual void getWindowListTipText(QString &szBuffer)
Definition KviWindow.h:357
KviConsoleWindow * m_pConsole
Definition KviWindow.h:178
virtual QTextCodec * defaultTextCodec()
Definition KviWindow.cpp:1364
QString m_szPlainTextCaption
Definition KviWindow.h:182
bool isQuery() const
Definition KviWindow.h:260
virtual void ownAction(const QString &)
Definition KviWindow.h:391
Type type() const
Returns the type of the window.
Definition KviWindow.h:250
QToolButton * m_pTextEncodingButton
Definition KviWindow.h:194
bool isConsole() const
Definition KviWindow.h:265
virtual void ownMessage(const QString &, bool=true)
Definition KviWindow.h:390
KviWindowListItem * windowListItem() const
Returns the windowList item.
Definition KviWindow.h:323
unsigned long int m_uId
Definition KviWindow.h:187
QString m_szName
Definition KviWindow.h:177
void setFixedCaption(const QString &szCaption)
Definition KviWindow.h:437
virtual const QString & localNick()
Definition KviWindow.h:339
QString m_szTextEncoding
Definition KviWindow.h:188
KviIrcView * m_pIrcView
Definition KviWindow.h:183
KviTalSplitter * m_pSplitter
Definition KviWindow.h:185
Type
Holds the types of a window; these are used by the KVIrc core and distributed modules.
Definition KviWindow.h:131
KviInput * input() const
Definition KviWindow.h:333
bool isDocked() const
Definition KviWindow.h:206
unsigned long int numericId() const
Returns the global ID of this window.
Definition KviWindow.h:222
QWidget * m_pLastFocusedChild
Definition KviWindow.h:196
const QString & textEncoding() const
Definition KviWindow.h:363
KviIrcView * view() const
Returns the KviIrcView of this window.
Definition KviWindow.h:282
KviInput * m_pInput
Definition KviWindow.h:184
KviTalSplitter * splitter() const
Returns the splitter of this window.
Definition KviWindow.h:315
void setType(Type eType)
Definition KviWindow.h:486
ActivityValue
Holds the activity meter in value scale.
Definition KviWindow.h:92
virtual const QString & target()
Definition KviWindow.h:336
QTextCodec * m_pTextCodec
Definition KviWindow.h:200
KviTalHBox * m_pButtonBox
Definition KviWindow.h:186
bool m_bIsDocked
Definition KviWindow.h:202
virtual QFrame * buttonContainer()
Definition KviWindow.h:326
Definition UserWindow.h:31
#define e
Definition detector.cpp:70
This file contains compile time settings.
#define KVIRC_API
Definition kvi_settings.h:127
const QString Empty
A global empty string (note that this is ALSO NULL under Qt 3.x)
Definition KviQString.cpp:47
char szBuffer[4096]
Definition winamp.cpp:77