1 /* 2 SPDX-License-Identifier: GPL-2.0-or-later 3 4 SPDX-FileCopyrightText: 2006-2008 Eike Hein <hein@kde.org> 5 */ 6 7 #ifndef VIEWCONTAINER_H 8 #define VIEWCONTAINER_H 9 10 #include "mainwindow.h" 11 #include "common.h" 12 #include "server.h" 13 14 #include <QAbstractItemModel> 15 #include <QMimeData> 16 #include <QTabWidget> 17 18 class QSplitter; 19 class QToolButton; 20 21 class KActionCollection; 22 23 class MainWindow; 24 class ViewTree; 25 class ChatWindow; 26 class Server; 27 class Images; 28 class UrlCatcher; 29 class NicksOnline; 30 class QueueTuner; 31 class ViewSpringLoader; 32 33 namespace Konversation 34 { 35 class InsertCharDialog; 36 class ServerGroupSettings; 37 38 namespace DCC 39 { 40 class Chat; 41 } 42 } 43 44 class ViewMimeData : public QMimeData 45 { 46 Q_OBJECT 47 48 public: 49 explicit ViewMimeData(ChatWindow *view); 50 ~ViewMimeData() override; 51 52 ChatWindow* view() const; 53 54 private: 55 ChatWindow *m_view; 56 57 Q_DISABLE_COPY(ViewMimeData) 58 }; 59 60 class TabWidget : public QTabWidget 61 { 62 Q_OBJECT 63 64 public: 65 explicit TabWidget(QWidget* parent = nullptr); 66 ~TabWidget() override; 67 68 Q_SIGNALS: 69 void contextMenu(QWidget* widget, const QPoint& pos); 70 void tabBarMiddleClicked(int index); 71 72 protected: 73 void contextMenuEvent(QContextMenuEvent* event) override; 74 void mouseReleaseEvent(QMouseEvent* event) override; 75 76 private: 77 Q_DISABLE_COPY(TabWidget) 78 }; 79 80 class ViewContainer : public QAbstractItemModel 81 { 82 Q_OBJECT 83 84 public: 85 enum DataRoles { 86 ColorRole = Qt::UserRole + 1, 87 DisabledRole, 88 HighlightRole 89 }; 90 91 explicit ViewContainer(MainWindow* window); 92 ~ViewContainer() override; 93 getWidget()94 QSplitter* getWidget() const { return m_viewTreeSplitter; } getWindow()95 MainWindow* getWindow() const { return m_window; } actionCollection()96 KActionCollection* actionCollection() const { return m_window->actionCollection(); } 97 getFrontView()98 QPointer<ChatWindow> getFrontView() const { return m_frontView; } getFrontServer()99 Server* getFrontServer() const { return m_frontServer; } 100 101 void prepareShutdown(); 102 103 int rowCount(const QModelIndex & parent = QModelIndex()) const override; 104 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 105 106 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; 107 QModelIndex indexForView(ChatWindow* view) const; 108 QModelIndex parent(const QModelIndex& index) const override; 109 110 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 111 112 Qt::DropActions supportedDragActions() const override; 113 Qt::DropActions supportedDropActions() const override; 114 Qt::ItemFlags flags(const QModelIndex &index) const override; 115 QStringList mimeTypes() const override; 116 QMimeData* mimeData(const QModelIndexList &indexes) const override; 117 bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override; 118 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; 119 120 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; 121 122 QString currentViewTitle() const; 123 QString currentViewURL(bool passNetwork = true); 124 125 void appendToFrontmost(const QString& type,const QString& message,ChatWindow* serverView, 126 const QHash<QString, QString> &messageTags = QHash<QString, QString>(), bool parseURL = true); 127 128 void showQueueTuner(bool); 129 130 int getViewIndex(QWidget* widget) const; 131 ChatWindow* getViewAt(int index) const; 132 133 QList<QPair<QString,QString> > getChannelsURI() const; 134 135 public Q_SLOTS: 136 void updateAppearance(); 137 void saveSplitterSizes(); 138 void setViewTreeShown(bool show = false); 139 140 void updateViews(const Konversation::ServerGroupSettingsPtr &serverGroup = Konversation::ServerGroupSettingsPtr()); 141 void setViewNotification(ChatWindow* widget, const Konversation::TabNotifyType& type); 142 void unsetViewNotification(ChatWindow* view); 143 void toggleViewNotifications(); 144 void toggleAutoJoin(); 145 void toggleConnectOnStartup(); 146 147 void showView(ChatWindow* view); 148 void goToView(int page); 149 void showNextView(); 150 void showPreviousView(); 151 void showNextActiveView(); 152 void showLastFocusedView(); 153 154 bool canMoveViewLeft() const; 155 bool canMoveViewRight() const; 156 void moveViewLeft(); 157 void moveViewRight(); 158 159 void closeView(int view); 160 void closeView(ChatWindow* view); 161 void closeViewMiddleClick(int view); 162 void closeCurrentView(); 163 void renameKonsole(); 164 void cleanupAfterClose(ChatWindow* view); 165 166 void changeViewCharset(int index); 167 void updateViewEncoding(ChatWindow* view); 168 169 void showViewContextMenu(QWidget* tab, const QPoint& pos); 170 171 void clearView(); 172 void clearAllViews(); 173 174 void findText(); 175 void findNextText(); 176 void findPrevText(); 177 178 void insertCharacter(); 179 void insertChar(uint chr); 180 void insertIRCColor(); 181 void doAutoReplace(); 182 183 void focusInputBox(); 184 185 void clearViewLines(); 186 void insertRememberLine(); 187 void cancelRememberLine(); 188 void insertMarkerLine(); 189 void insertRememberLines(Server* server); 190 191 void openLogFile(); 192 void openLogFile(const QString& caption, const QString& file); 193 194 void addKonsolePanel(); 195 196 void zoomIn(); 197 void zoomOut(); 198 void resetFont(); 199 200 void addUrlCatcher(); 201 void closeUrlCatcher(); 202 203 void toggleDccPanel(); 204 void addDccPanel(); 205 void closeDccPanel(); 206 void deleteDccPanel(); 207 ChatWindow* getDccPanel() const; 208 209 void addDccChat(Konversation::DCC::Chat* myNick); 210 211 StatusPanel* addStatusView(Server* server); 212 RawLog* addRawLog(Server* server); 213 void disconnectFrontServer(); 214 void reconnectFrontServer(); 215 void showJoinChannelDialog(); 216 void connectionStateChanged(Server* server, Konversation::ConnectionState state); 217 void channelJoined(Channel* channel); 218 219 Channel* addChannel(Server* server, const QString& name); 220 void rejoinChannel(); 221 void openChannelSettings(); 222 void toggleChannelNicklists(); 223 224 Query* addQuery(Server* server,const NickInfoPtr & name, bool weinitiated=true); 225 void updateQueryChrome(ChatWindow* view, const QString& name); 226 void closeQueries(); 227 228 ChannelListPanel* addChannelListPanel(Server* server); 229 void openChannelList(Server* server = nullptr, const QString& filter = QString(), bool getList = false); 230 231 void openNicksOnlinePanel(); 232 void closeNicksOnlinePanel(); 233 234 Q_SIGNALS: 235 void viewChanged(const QModelIndex& idx); 236 void setWindowCaption(const QString& caption); 237 void updateChannelAppearance(); 238 void contextMenuClosed(); 239 void resetStatusBar(); 240 void setStatusBarTempText(const QString& text); 241 void clearStatusBarTempText(); 242 void setStatusBarInfoLabel(const QString& text); 243 void clearStatusBarInfoLabel(); 244 void setStatusBarLagLabelShown(bool shown); 245 void updateStatusBarLagLabel(Server* server, int msec); 246 void resetStatusBarLagLabel(Server* server); 247 void setStatusBarLagLabelTooLongLag(Server* server, int msec); 248 void updateStatusBarSSLLabel(Server* server); 249 void removeStatusBarSSLLabel(); 250 void autoJoinToggled(const Konversation::ServerGroupSettingsPtr); 251 void autoConnectOnStartupToggled(const Konversation::ServerGroupSettingsPtr); 252 253 void frontServerChanging(Server*); 254 255 private Q_SLOTS: 256 void viewSwitched(int newIndex); 257 void onViewTreeDestroyed(QObject *object); 258 259 private: 260 void setupTabWidget(); 261 void setupViewTree(); 262 void removeViewTree(); 263 void updateTabWidgetAppearance(); 264 265 void addView(ChatWindow* view, const QString& label, bool weinitiated=true); 266 int insertIndex(ChatWindow* view); 267 void unclutterTabs(); 268 269 void updateViewActions(int index); 270 void updateFrontView(); 271 272 void setFrontServer(Server *); 273 274 void initializeSplitterSizes(); 275 276 private: 277 bool m_saveSplitterSizesLock; 278 279 MainWindow* m_window; 280 281 QSplitter* m_viewTreeSplitter; 282 TabWidget* m_tabWidget; 283 QToolButton* m_tabCloseButton; 284 ViewTree* m_viewTree; 285 QWidget* m_vbox; 286 QueueTuner* m_queueTuner; 287 288 Images* images; 289 290 QPointer<Server> m_frontServer; 291 QPointer<Server> m_contextServer; 292 QPointer<ChatWindow> m_frontView; 293 QPointer<ChatWindow> m_searchView; 294 295 QPointer<ChatWindow> m_currentView; 296 QPointer<ChatWindow> m_lastFocusedView; 297 298 UrlCatcher* m_urlCatcherPanel; 299 NicksOnline* m_nicksOnlinePanel; 300 301 ChatWindow* m_dccPanel; 302 bool m_dccPanelOpen; 303 304 Konversation::InsertCharDialog* m_insertCharDialog; 305 306 int m_popupViewIndex; 307 int m_queryViewCount; 308 309 QList<ChatWindow*> m_activeViewOrderList; 310 311 ViewSpringLoader* m_viewSpringLoader; 312 313 Q_DISABLE_COPY(ViewContainer) 314 }; 315 316 #endif 317