1 /* ============================================================ 2 * TabManager plugin for Falkon 3 * Copyright (C) 2013-2017 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com> 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * ============================================================ */ 18 #ifndef TABMANAGERWIDGET_H 19 #define TABMANAGERWIDGET_H 20 21 #include <QWidget> 22 #include <QPointer> 23 #include <QHash> 24 #include <QTreeWidgetItem> 25 26 namespace Ui 27 { 28 class TabManagerWidget; 29 } 30 class QUrl; 31 class QTreeWidgetItem; 32 class BrowserWindow; 33 class WebPage; 34 class WebTab; 35 class WebView; 36 class TLDExtractor; 37 38 class TabTreeWidget : public QTreeWidget 39 { 40 Q_OBJECT 41 42 public: 43 TabTreeWidget(QWidget* parent = 0); 44 45 Qt::DropActions supportedDropActions() const override; 46 QStringList mimeTypes() const override; 47 QMimeData* mimeData(const QList<QTreeWidgetItem*> items) const override; 48 bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) override; 49 50 void setEnableDragTabs(bool enable); 51 52 Q_SIGNALS: 53 void requestRefreshTree(); 54 55 }; 56 57 class TabManagerWidget : public QWidget 58 { 59 Q_OBJECT 60 61 public: 62 enum GroupType { 63 GroupByWindow = 0, 64 GroupByDomain = 1, 65 GroupByHost = 2 66 }; 67 68 explicit TabManagerWidget(BrowserWindow* mainClass, QWidget* parent = 0, bool defaultWidget = false); 69 ~TabManagerWidget(); 70 71 void closeSelectedTabs(const QHash<BrowserWindow*, WebTab*> &tabsHash); 72 void detachSelectedTabs(const QHash<BrowserWindow*, WebTab*> &tabsHash); 73 bool bookmarkSelectedTabs(const QHash<BrowserWindow*, WebTab*> &tabsHash); 74 void unloadSelectedTabs(const QHash<BrowserWindow*, WebTab*> &tabsHash); 75 76 void setGroupType(GroupType type); 77 78 static QString domainFromUrl(const QUrl &url, bool useHostName = false); 79 80 public Q_SLOTS: 81 void delayedRefreshTree(WebPage* p = 0); 82 void changeGroupType(); 83 84 private: 85 QTreeWidgetItem* groupByDomainName(bool useHostName = false); 86 QTreeWidgetItem* groupByWindow(); 87 BrowserWindow* getWindow(); 88 89 Ui::TabManagerWidget* ui; 90 QPointer<BrowserWindow> m_window; 91 WebPage* m_webPage; 92 93 bool m_isRefreshing; 94 bool m_refreshBlocked; 95 bool m_waitForRefresh; 96 bool m_isDefaultWidget; 97 GroupType m_groupType; 98 99 QString m_filterText; 100 101 static TLDExtractor* s_tldExtractor; 102 103 private Q_SLOTS: 104 void refreshTree(); 105 void processActions(); 106 void onItemActivated(QTreeWidgetItem* item, int column); 107 bool isTabSelected(); 108 void customContextMenuRequested(const QPoint &pos); 109 void filterChanged(const QString &filter, bool force = false); 110 void filterBarClosed(); 111 112 protected: 113 bool eventFilter(QObject* obj, QEvent* event) override; 114 115 Q_SIGNALS: 116 void showSideBySide(); 117 void groupTypeChanged(TabManagerWidget::GroupType); 118 }; 119 120 class TabItem : public QObject, public QTreeWidgetItem 121 { 122 Q_OBJECT 123 124 public: 125 enum StateRole { 126 ActiveOrCaptionRole = Qt::UserRole + 1, 127 SavedRole = Qt::UserRole + 2 128 }; 129 130 TabItem(QTreeWidget* treeWidget, bool supportDrag = true, bool isTab = true, QTreeWidgetItem* parent = 0, bool addToTree = true); 131 132 BrowserWindow* window() const; 133 void setBrowserWindow(BrowserWindow* window); 134 135 WebTab* webTab() const; 136 void setWebTab(WebTab* webTab); 137 138 bool isTab() const; 139 140 public Q_SLOTS: 141 void updateIcon(); 142 void setTitle(const QString& title); 143 void setIsActiveOrCaption(bool yes); 144 void setIsSavedTab(bool yes); 145 146 private: 147 QTreeWidget* m_treeWidget; 148 BrowserWindow* m_window; 149 WebTab* m_webTab; 150 bool m_isTab; 151 }; 152 153 #endif // TABMANAGERWIDGET_H 154