KVIrc  4.9.2
DeveloperAPIs
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 
50 class QPushButton;
51 class QPixmap;
52 class QTextCodec;
53 class KviMainWindow;
54 class KviWindowListItem;
56 class KviIrcView;
57 class KviConsoleWindow;
58 class KviIrcConnection;
60 class QMenu;
61 class KviTalHBox;
62 
63 #ifdef COMPILE_CRYPT_SUPPORT
64 class KviCryptController;
65 class KviCryptSessionInfo;
66 #endif
67 
68 #define KVI_WINDOW_TYPE_USER 10000
69 
74 class 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;
81  friend class KviTreeWindowListItem;
82  friend class KviTreeWindowList;
84  Q_PROPERTY(int KviProperty_ChildFocusOwner READ type)
85  Q_OBJECT
86 public:
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 = 0);
170 
174  virtual ~KviWindow();
175 
176 protected: // almost private: don't touch :D
177  QString m_szName; // the current window name (usually also the target)
181  QWidget * m_pFocusHandler;
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
194  QToolButton * m_pTextEncodingButton;
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 
205 public:
206  inline bool isDocked() { return m_bIsDocked; }
207 
214  inline QString id() { return QString("%1").arg(m_uId); };
215 
222  inline unsigned long int numericId() { return m_uId; };
223 
228  inline const QString & windowName() { return m_szName; };
229 
235  void setWindowName(const QString & szName);
236 
244  void setProgress(int iProgress);
245 
250  inline Type type() const { return m_eType; };
251 
255  inline bool isChannel() const { return m_eType == Channel; };
256 
260  inline bool isQuery() const { return m_eType == Query; };
261 
265  inline bool isConsole() const { return m_eType == Console; };
266 
271  virtual const char * typeString();
272 
273  inline QTextCodec * textCodec() { return m_pTextCodec ? m_pTextCodec : defaultTextCodec(); };
274  void forceTextCodec(QTextCodec * pCodec);
275 
282  inline KviIrcView * view() const { return m_pIrcView; };
283 
290  inline KviConsoleWindow * console() { return m_pConsole; };
291 
292  KviIrcContext * context();
293 
298  KviIrcConnection * connection();
299 
306  inline KviTalSplitter * splitter() { return m_pSplitter; };
307 
314  inline KviWindowListItem * windowListItem() { return m_pWindowListItem; };
315 
316  // The window *might* have a button container
317  virtual QFrame * buttonContainer() { return (QFrame *)m_pButtonBox; };
318  virtual void toggleButtonContainer();
319 
320  // The window *might* have an output proxy: if it has no view() for example
321  virtual KviWindow * outputProxy();
322 
323  // The window input widget
324  inline KviInput * input() { return m_pInput; };
325 
326  // The target of this window: empty when it makes no sense :D
327  virtual const QString & target() { return KviQString::Empty; };
328 
329  // The local nickname bound to this window: might be empty when a local nickname makes no sense
330  virtual const QString & localNick() { return KviQString::Empty; };
331 
332 #ifdef COMPILE_CRYPT_SUPPORT
333  KviCryptSessionInfo * cryptSessionInfo()
334  {
335  return m_pCryptSessionInfo;
336  };
337  void setCryptSessionInfo(KviCryptSessionInfo * pInfo);
338 #endif
339 
340  virtual bool activityMeter(unsigned int * puActivityValue, unsigned int * puActivityTemperature);
341 
342  //* \param puValue Highlight level
343  virtual bool highlightMeter(unsigned int * puValue);
344  virtual bool highlightMe(unsigned int uValue);
345 
346  void unhighlight();
347 
348  virtual inline void getWindowListTipText(QString & szBuffer) { szBuffer = m_szPlainTextCaption; };
349 
350  // This is meaningful only if view() is non NULL
351  const QString & lastLineOfText();
352  const QString & lastMessageText();
353 
354  inline const QString & textEncoding() { return m_szTextEncoding; };
355  // returns true if the encoding could be successfully set
356  bool setTextEncoding(const QString & szTextEncoding);
357  // this must return a default text codec suitable for this window
358  virtual QTextCodec * defaultTextCodec();
359  // encode the text from szSource by using m_uTextEncoding
360  inline QByteArray encodeText(const QString & szText);
361  inline QString decodeText(const char * pcText);
362  //return a text encoder
363  QTextEncoder * makeEncoder();
364 
365  void contextPopup();
366  // Raises the window (after a light delay to prevent focus pingpongs)
367  void delayedAutoRaise();
368 
369  // Retrieves the default log file name: this is pre-build
370  void getDefaultLogFileName(QString & szBuffer);
371 
372  void delayedClose(); // close that jumps out of the current event loop
373 
374  // Interesting overridables:
375  virtual void getConfigGroupName(QString & szBuffer);
376  virtual void getBaseLogFileName(QString & szBuffer);
377  virtual void updateCaption();
378  virtual void applyOptions();
379  virtual void updateIcon();
380  virtual void ownMessage(const QString &, bool = true){};
381  virtual void ownAction(const QString &){};
382  virtual const QString & plainTextCaption() { return m_szPlainTextCaption; };
383 
384  void internalOutput(KviIrcView * pView, int iMsgType, const kvi_wchar_t * pwText, int iFlags = 0, const QDateTime & datetime = QDateTime());
385  // You *might* want to override these too.. but better don't touch them :D
386  virtual void output(int iMsgType, const char * pcFormat, ...);
387  virtual void output(int iMsgType, const kvi_wchar_t * pwFormat, ...);
388  virtual void output(int iMsgType, QString szFmt, ...);
389  void output(int iMsgType, const QDateTime & datetime, const char * pcFormat, ...);
390  void output(int iMsgType, const QDateTime & datetime, const kvi_wchar_t * pwFormat, ...);
391  void output(int iMsgType, const QDateTime & datetime, QString szFmt, ...);
392  virtual void outputNoFmt(int iMsgType, const char * pcText, int iFlags = 0, const QDateTime & datetime = QDateTime());
393  virtual void outputNoFmt(int iMsgType, const kvi_wchar_t * pwText, int iFlags = 0, const QDateTime & datetime = QDateTime()) { internalOutput(m_pIrcView, iMsgType, pwText, iFlags, datetime); };
394  virtual void outputNoFmt(int iMsgType, const QString & szText, int iFlags = 0, const QDateTime & datetime = QDateTime()); // <-- iFlags are KviIrcView::AppendTextFlags
395  // Just helpers.. FIXME: might be redesigned in some other way
396  void updateBackgrounds(QObject * pObj = 0);
397 
406  void demandAttention();
407 
419  bool hasAttention(AttentionLevel eLevel = VisibleAndActive);
420 
421  // This should die, probably
422  void listWindowTypes();
423 
424  // call this in the constructor if your caption is fixed:
425  // it will set m_szPlainTextCaption to szCaption and it will
426  // automatically use it without the need of overriding fillCaptionBuffers
427  inline void setFixedCaption(const QString & szCaption) { m_szPlainTextCaption = szCaption; };
428 
429  void setWindowTitle(QString & szTitle);
430 
431 protected:
432  // Loading and saving of properties
433  // Protected: only KviMainWindow can call these
434  virtual void saveProperties(KviConfigurationFile * pCfg);
435  virtual void loadProperties(KviConfigurationFile * pCfg);
436  // Creation and destruction events: overridden in windows that have script events bound to creation and destruction
437  virtual void triggerCreationEvents(){};
438  virtual void triggerDestructionEvents(){};
439  // Internal: do not touch :D (KviMainWindow)
440  virtual void createWindowListItem();
441  virtual void destroyWindowListItem();
442  // called by KviMainWindow
443  // either lost the active window status or the frame is no longer active (but we're still the active kvirc's subwindow)
444  virtual void lostUserFocus();
445  // this by default calls fillSingleColorCaptionBuffer(plainTextCaption());
446  virtual void fillCaptionBuffers();
447  // protected helper
448  inline void fillSingleColorCaptionBuffers(const QString & szName) { m_szPlainTextCaption = szName; };
449  // Virtual events that signal dock state change
450  virtual void youAreDocked();
451  virtual void youAreUndocked();
452  // Reimplement to show a special icon in the WindowList items and captions
453  virtual QPixmap * myIconPtr();
454  // Sets the type of this window: be careful with this
455  void setType(Type eType) { m_eType = eType; };
456 
457  bool eventFilter(QObject * pObject, QEvent * pEvent);
458 
459  // Virtuals overridden to manage the internal layouts...
460  virtual void moveEvent(QMoveEvent * pEvent);
461  virtual void closeEvent(QCloseEvent * pEvent);
462  virtual void childEvent(QChildEvent * pEvent);
463  virtual void focusInEvent(QFocusEvent *);
464  virtual void inputMethodEvent(QInputMethodEvent * e);
465 
466  void childInserted(QWidget * pObject);
467  void childRemoved(QWidget * pObject);
468 
469  // Internal helpers
470  void createCryptControllerButton(QWidget * pPar);
471  void createTextEncodingButton(QWidget * pPar);
472  void createSystemTextEncodingPopup();
473 
474  QToolButton * createToolButton(QWidget * pPar, const char * pcName, KviIconManager::SmallIcon eIcon, const QString & szToolTip, bool bOn);
475  // This is called by KviInput: actually it links the widgetAdded
476  virtual void childrenTreeChanged(QWidget * pAdded);
477 
478  virtual bool focusNextPrevChild(bool bNext);
479 
480  virtual void preprocessMessage(QString & szMessage);
481 public slots:
482  void dock();
483  void undock();
484  void autoRaise();
485  void reloadImages();
486  void savePropertiesAsDefault();
487 protected slots:
488  void toggleCryptController(); // This has to be here even if the crypt support is enabled...moc does not support conditionals
489  void cryptControllerFinished(); // same as above
490  void cryptSessionInfoDestroyed(); // same as above
491  void textEncodingButtonClicked();
492  void systemTextEncodingPopupActivated(QAction * pAction);
493  void childDestroyed();
494 signals:
495  void windowNameChanged();
496 };
497 
498 #ifndef _KVI_WINDOW_CPP_
499 // The active window:
500 // This is almost always non null
501 // The exception is the startup (when there are no windows at all)
502 // and the last phase of the destructor.
503 // You usually shouldn't care of checking this pointer for NULL unless
504 // you're running very early at startup or very late at shutdown
506 #endif
507 
508 inline QByteArray KviWindow::encodeText(const QString & szText)
509 {
510  if(m_pTextCodec)
511  return m_pTextCodec->fromUnicode(szText);
512  else
513  return defaultTextCodec()->fromUnicode(szText);
514 }
515 
516 inline QString KviWindow::decodeText(const char * pcText)
517 {
518  if(m_pTextCodec)
519  return m_pTextCodec->toUnicode(pcText);
520  else
521  return defaultTextCodec()->toUnicode(pcText);
522 }
523 
524 #endif //_KVI_WINDOW_H_
virtual void triggerDestructionEvents()
Definition: KviWindow.h:438
Toolkit Abstraction Layer: hbox class.
Definition: KviTalHBox.h:44
unsigned long int m_uId
Definition: KviWindow.h:187
AttentionLevel
attention levels usable in hasAttention()
Definition: KviWindow.h:120
Definition: KviMainWindow.h:60
Definition: KviConsoleWindow.h:75
#define KVIRC_API
Definition: kvi_settings.h:128
Class for horizontal box.
An abstraction of a connection to an IRC server.
Definition: KviIrcConnection.h:95
bool m_bProcessingInputEvent
Definition: KviWindow.h:203
Definition: KviConfigurationFile.h:48
bool isDocked()
Definition: KviWindow.h:206
void fillSingleColorCaptionBuffers(const QString &szName)
Definition: KviWindow.h:448
virtual void outputNoFmt(int iMsgType, const kvi_wchar_t *pwText, int iFlags=0, const QDateTime &datetime=QDateTime())
Definition: KviWindow.h:393
KviTalSplitter * m_pSplitter
Definition: KviWindow.h:185
QTextCodec * textCodec()
Definition: KviWindow.h:273
kvi_u16_t kvi_wchar_t
Definition: KviCString.h:87
KviTalHBox * m_pButtonBox
Definition: KviWindow.h:186
QWidget * m_pLastFocusedChild
Definition: KviWindow.h:196
KviIrcView * m_pIrcView
Definition: KviWindow.h:183
ActivityTemperature
Holds the activity meter in temperature scale.
Definition: KviWindow.h:105
QString type()
Definition: KviRuntimeInfo.cpp:646
const QString & windowName()
Returns the name of this window.
Definition: KviWindow.h:228
Input handling.
KviWindowListItem * windowListItem()
Returns the windowList item.
Definition: KviWindow.h:314
virtual const QString & target()
Definition: KviWindow.h:327
QByteArray encodeText(const QString &szText)
Definition: KviWindow.h:508
#define e
Definition: detector.cpp:69
void setFixedCaption(const QString &szCaption)
Definition: KviWindow.h:427
char Channel
Definition: KviIrcNumericCodes.h:391
KviWindowListItem * m_pWindowListItem
Definition: KviWindow.h:180
QString m_szTextEncoding
Definition: KviWindow.h:188
KVIRC_API KviWindow * g_pActiveWindow
Definition: KviWindow.cpp:85
Icon manager.
QString id()
Returns the global ID of this window.
Definition: KviWindow.h:214
Type m_eType
Definition: KviWindow.h:179
SmallIcon
Contains all KVIrc's small icons.
Definition: KviIconManager.h:168
An abstraction of a connection to an IRC server.
bool isQuery() const
Definition: KviWindow.h:260
Definition: KviTreeWindowList.h:120
Input handling class.
Definition: KviInput.h:53
KviIrcView * view() const
Returns the KviIrcView of this window.
Definition: KviWindow.h:282
const QString Empty
A global empty string (note that this is ALSO NULL under Qt 3.x)
Definition: KviQString.cpp:49
Definition: KviWindowListBase.h:124
virtual void ownMessage(const QString &, bool=true)
Definition: KviWindow.h:380
virtual QTextCodec * defaultTextCodec()
Definition: KviWindow.cpp:1353
const QString & textEncoding()
Definition: KviWindow.h:354
Definition: KviWindowToolWidget.h:47
virtual void triggerCreationEvents()
Definition: KviWindow.h:437
Type type() const
Returns the type of the window.
Definition: KviWindow.h:250
KviTalSplitter * splitter()
Returns the splitter of this window.
Definition: KviWindow.h:306
Handles all docked KviWindow windows.
Definition: KviWindowStack.h:46
Definition: KviIrcView.h:57
virtual void getWindowListTipText(QString &szBuffer)
Definition: KviWindow.h:348
virtual void ownAction(const QString &)
Definition: KviWindow.h:381
KviInput * input()
Definition: KviWindow.h:324
QToolButton * m_pHideToolsButton
Definition: KviWindow.h:195
Definition: UserWindow.h:30
Definition: KviTreeWindowList.h:86
QToolButton * m_pTextEncodingButton
Definition: KviWindow.h:194
bool isConsole() const
Definition: KviWindow.h:265
unsigned long int numericId()
Returns the global ID of this window.
Definition: KviWindow.h:222
void setType(Type eType)
Definition: KviWindow.h:455
Type
Holds the types of a window; these are used by the KVIrc core and distributed modules.
Definition: KviWindow.h:130
Base class for all windows in KVIrc.
Definition: KviWindow.h:74
QTextCodec * m_pTextCodec
Definition: KviWindow.h:200
ActivityValue
Holds the activity meter in value scale.
Definition: KviWindow.h:91
Class used to workaround unwanted behaviours in QSplitter.
KviInput * m_pInput
Definition: KviWindow.h:184
Definition: KviTreeWindowList.h:35
KviConsoleWindow * m_pConsole
Definition: KviWindow.h:178
#define KviTalSplitter
Definition: KviTalSplitter.h:35
virtual const QString & localNick()
Definition: KviWindow.h:330
char szBuffer[4096]
Definition: winamp.cpp:77
virtual const QString & plainTextCaption()
Definition: KviWindow.h:382
QString decodeText(const char *pcText)
Definition: KviWindow.h:516
QWidget * m_pFocusHandler
Definition: KviWindow.h:181
This file contains compile time settings.
bool isChannel() const
Definition: KviWindow.h:255
virtual QFrame * buttonContainer()
Definition: KviWindow.h:317
Definition: KviWindowListBase.h:49
Definition: KviIrcContext.h:58
bool m_bIsDocked
Definition: KviWindow.h:202
KviConsoleWindow * console()
Returns the console that this window belongs to.
Definition: KviWindow.h:290
Helper functions for the QString class.
QString m_szName
Definition: KviWindow.h:177
QString m_szPlainTextCaption
Definition: KviWindow.h:182