1 /* 2 SPDX-FileCopyrightText: 2001 Dawit Alemayehu <adawit@kde.org> 3 4 SPDX-License-Identifier: LGPL-2.0-or-later 5 */ 6 7 #ifndef __UACHANGER_PLUGIN_H 8 #define __UACHANGER_PLUGIN_H 9 10 #include <qmap.h> 11 #include <qstringlist.h> 12 #include <qurl.h> 13 14 #include <kparts/plugin.h> 15 #include <kparts/readonlypart.h> 16 17 class KActionMenu; 18 class QAction; 19 class QActionGroup; 20 class KConfig; 21 22 namespace KIO 23 { 24 } 25 26 class UAChangerPlugin : public KParts::Plugin 27 { 28 Q_OBJECT 29 30 public: 31 explicit UAChangerPlugin(QObject *parent, const QVariantList &args); 32 ~UAChangerPlugin() override; 33 34 protected slots: 35 void slotDefault(); 36 void parseDescFiles(); 37 38 void slotConfigure(); 39 void slotAboutToShow(); 40 void slotApplyToDomain(); 41 void slotEnableMenu(); 42 void slotItemSelected(QAction *); 43 void slotReloadDescriptions(); 44 45 protected: 46 QString findTLD(const QString &hostname); 47 QString filterHost(const QString &hostname); 48 49 private: 50 void reloadPage(); 51 void loadSettings(); 52 void saveSettings(); 53 54 int m_selectedItem; 55 bool m_bApplyToDomain; 56 bool m_bSettingsLoaded; 57 58 KParts::ReadOnlyPart *m_part; 59 KActionMenu *m_pUAMenu; 60 KConfig *m_config; 61 QAction *m_applyEntireSiteAction; 62 QAction *m_defaultAction; 63 QActionGroup *m_actionGroup; 64 65 QUrl m_currentURL; 66 QString m_currentUserAgent; 67 68 QStringList m_lstAlias; // menu entry names 69 QStringList m_lstIdentity; // UA strings 70 71 // A little wrapper around tag names so that other always goes to the end. 72 struct MenuGroupSortKey { 73 QString tag; 74 bool isOther; MenuGroupSortKeyMenuGroupSortKey75 MenuGroupSortKey(): isOther(false) {} MenuGroupSortKeyMenuGroupSortKey76 MenuGroupSortKey(const QString &t, bool oth): tag(t), isOther(oth) {} 77 78 bool operator==(const MenuGroupSortKey &o) const 79 { 80 return tag == o.tag && isOther == o.isOther; 81 } 82 83 bool operator<(const MenuGroupSortKey &o) const 84 { 85 return (!isOther && o.isOther) || (tag < o.tag); 86 } 87 }; 88 89 typedef QList<int> BrowserGroup; 90 typedef QMap<MenuGroupSortKey, BrowserGroup> AliasMap; 91 typedef QMap<MenuGroupSortKey, QString> BrowserMap; 92 93 typedef AliasMap::Iterator AliasIterator; 94 typedef AliasMap::ConstIterator AliasConstIterator; 95 96 BrowserMap m_mapBrowser; // tag -> menu name 97 AliasMap m_mapAlias; // tag -> UA string/menu entry name indices. 98 }; 99 100 #endif 101