1 #ifndef _KVI_CONSOLE_H_
2 #define _KVI_CONSOLE_H_
3 //=============================================================================
4 //
5 // File : KviConsoleWindow.h
6 // Creation date : Sun Jun 25 2000 15:00:20 by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2000-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
27 #include "kvi_settings.h"
28 #include "KviIrcConnection.h"
29 #include "KviIrcConnectionTarget.h"
30 #include "KviWindow.h"
31 #include "KviIrcSocket.h"
32 #include "KviIrcServer.h"
33 #include "KviCString.h"
34 #include "KviIrcContext.h"
35 #include "KviUserListView.h"
36 #include "KviThemedComboBox.h"
37
38 #include <time.h>
39 #include <vector>
40
41 #include <QToolButton>
42
43 class QToolBar;
44
45 class KviAvatar;
46 class KviDnsResolver;
47 class KviIrcUserDataBase;
48 class KviIrcUserEntry;
49 class KviIrcServer;
50 class KviIrcNetwork;
51 class KviProxy;
52 class KviUserListView;
53 class KviNotifyListManager;
54 class KviRegisteredUser;
55 class KviWindowToolPageButton;
56
57 #ifdef COMPILE_ON_WINDOWS
58 // windoze wants it to compile QList<KviChannelWindow> and QList<KviQueryWindow>
59 #include "KviChannelWindow.h"
60 #include "KviQueryWindow.h"
61 #else
62 class KviChannelWindow;
63 class KviQueryWindow;
64 #endif
65
66 //
67 // The console window
68 //
69
70 #define KVI_CONSOLE_FLAG_FIRSTINAPP 1
71 #define KVI_CONSOLE_FLAG_FIRSTINFRAME 2
72
73 class KVIRC_API KviConsoleWindow : public KviWindow
74 {
75 friend class KviMainWindow;
76 friend class KviIrcSocket;
77 friend class KviChannelWindow;
78 friend class KviQueryWindow;
79 friend class KviIrcContext;
80 Q_OBJECT
81 protected:
82 KviConsoleWindow(int iFlags);
83
84 public:
85 ~KviConsoleWindow();
86
87 protected:
88 int m_iFlags; // FIXME: make this a KviWindow property ?
89 // UI
90 KviUserListView * m_pNotifyListView;
91 KviWindowToolPageButton * m_pNotifyViewButton;
92 KviThemedComboBox * m_pAddressEdit;
93 QString m_szStatusString; // nick (flags) on server | not connected
94 QString m_szOwnSmartColor;
95 QStringList * m_pTmpHighLightedChannels;
96 KviIrcContext * m_pContext;
97 QList<int> m_SplitterSizesList;
98
99 protected:
100 // UI
101 QPixmap * myIconPtr() override;
102 void fillCaptionBuffers() override;
103 void resizeEvent(QResizeEvent * e) override;
104 void closeEvent(QCloseEvent * e) override;
105 void getBaseLogFileName(QString & buffer) override;
106 void getWindowListTipText(QString & buffer) override;
107 QSize sizeHint() const override;
108 void applyOptions() override;
109 void triggerCreationEvents() override;
110 void fillStatusString();
111 //void socketError(int iError);
112 //void socketStateChange();
113 //void registerLinkMonitor(KviIrcSocketMonitor * m);
114 //void unregisterLinkMonitor(KviIrcSocketMonitor * m);
115 void loadProperties(KviConfigurationFile * cfg) override;
116 void saveProperties(KviConfigurationFile * cfg) override;
117
118 void destroyConnection();
119 // internal helper for applyHighlighting
120 int triggerOnHighlight(KviWindow * wnd, int type, const QString & nick, const QString & user, const QString & host, const QString & szMsg, const QString & trigger);
121
122 void showNotifyList(bool bShow, bool bIgnoreSizeChange = false);
123 static int getSmartColorHashForNick(QString * szNick);
124
125 public:
context()126 KviIrcContext * context() { return m_pContext; };
127
128 // UI
notifyListView()129 KviUserListView * notifyListView() const { return m_pNotifyListView; }
130 int selectedCount();
131
132 //
133 // State
134 //
state()135 KviIrcContext::State state() { return context()->state(); }
136
137 // these should disappear!
isConnected()138 bool isConnected() { return context()->isConnected(); }
139 bool isIPv6Connection();
140 bool isNotConnected();
141 bool connectionInProgress();
142 //
143 // This connection info
144 //
145 QString currentNetworkName();
146 KviAvatar * currentAvatar();
147 //
148 // IRC Context wide helpers (connection related)
149 //
150 void getUserTipText(const QString & nick, KviIrcUserEntry * e, QString & buffer);
151 enum OutputPrivmsgFlags
152 {
153 NoWindowFlashing = 1, // has meaning only if NoHighlighting is NOT given, otherwise it is implied
154 NoNotifier = 2, // has meaning only if NoHighlighitng is NOT given, otherwise it is implied
155 NoHighlighting = 4,
156 NoNotifications = 7 // this is 1|2|4 implies NoWindowFlashing and NoNotifier
157 };
158 void outputPrivmsg(KviWindow * wnd, int type, const QString & nick,
159 const QString & user, const QString & host, const QString & msg, int iFlags = 0, const QString & prefix = QString(), const QString & suffix = QString(), const QDateTime & datetime = QDateTime());
160 // this applies highlighting to the specified message
161 // and triggers the OnHighlight event.
162 // it returns KVI_OUT_HIGHLIGHT if highlighting was applied
163 // and -1 if OnHighlight called halt
164 // otherwise it returns <type>
165 int applyHighlighting(KviWindow * wnd, int type, const QString & nick, const QString & user, const QString & host, const QString & szMsg);
166 // Avatar helpers (connection related)
167 void resetAvatarForMatchingUsers(KviRegisteredUser * u);
168 // this should be protected at least
169 void avatarChangedUpdateWindows(const QString & nick, const QString & textLine);
170 void avatarChanged(KviAvatar * avatar, const QString & nick, const QString & user, const QString & host, const QString & textLine);
171 KviAvatar * setAvatar(const QString & nick, const QString & user, const QString & host, const QString & szLocalPath, const QString & szName);
172 void checkDefaultAvatar(KviIrcUserEntry * e, const QString & nick, const QString & user, const QString & host);
173 void setAvatarFromOptions();
174
175 // This returns the default avatar for the current KVIrc user
176 // if he has chosen a valid avatar in the options dialog
177 // otherwise returns 0.
178 // The avatar is allocated with new and must be deleted
179 // when no longer needed.
180 KviAvatar * defaultAvatarFromOptions();
181
182 void terminateConnectionRequest(bool bForce = false, const char * quitMsg = nullptr);
183
184 // Status string (usermode + nick) (connection related too)
statusString()185 const QString & statusString() const { return m_szStatusString; }
186
187 KviWindow * activeWindow();
188 // User db, connection related
189 void completeChannel(const QString & word, std::vector<QString> & matches);
190 void completeServer(const QString & word, std::vector<QString> & matches);
191 void connectionAttached();
192 void connectionDetached();
193
194 /**
195 * \brief Adds a channel to the highlight list
196 * \param szChan The channel name
197 * \return void
198 */
199 void addHighlightedChannel(const QString & szChan);
200
201 /**
202 * \brief Removes a channel from the highlight list
203 * \param szChan The channel name
204 * \return void
205 */
206 void removeHighlightedChannel(const QString & szChan);
207
208 /**
209 * \brief Returns true if the channel is highlighted
210 * \param szChan The channel name
211 * \return bool
212 */
isHighlightedChannel(const QString & szChan)213 bool isHighlightedChannel(const QString & szChan) { return m_pTmpHighLightedChannels->contains(szChan, Qt::CaseInsensitive); };
214
215 public slots:
216 void updateUri();
217 void executeInternalCommand(int index);
218 void recentUrlsChanged();
219 protected slots:
220 void ircUriChanged(const QString &);
221 void toggleNotifyView();
222 void textViewRightClicked();
223 };
224
selectedCount()225 inline int KviConsoleWindow::selectedCount()
226 {
227 return m_pNotifyListView->selectedCount();
228 }
229
isIPv6Connection()230 inline bool KviConsoleWindow::isIPv6Connection()
231 {
232 KVI_ASSERT(connection());
233 return connection()->target()->server()->isIPv6();
234 }
235
isNotConnected()236 inline bool KviConsoleWindow::isNotConnected()
237 {
238 return (context()->state() == KviIrcContext::Idle);
239 }
240
currentNetworkName()241 inline QString KviConsoleWindow::currentNetworkName()
242 {
243 return (connection() ? connection()->currentNetworkName() : QString());
244 }
245
246 #endif //_KVI_CONSOLE_H_
247