Warning, file /network/konqueror/sidebar/history_module/history_module.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2009 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "history_module.h" 0008 #include <konqhistoryview.h> 0009 0010 #include <QAction> 0011 #include <QApplication> 0012 #include <QTreeView> 0013 #include <QIcon> 0014 0015 #include <KLocalizedString> 0016 #include <KPluginFactory> 0017 0018 KonqSidebarHistoryModule::KonqSidebarHistoryModule(QWidget *parent, 0019 const KConfigGroup &configGroup) 0020 : KonqSidebarModule(parent, configGroup), m_settings(KonqHistorySettings::self()) 0021 { 0022 m_historyView = new KonqHistoryView(parent); 0023 connect(m_historyView->treeView(), &QAbstractItemView::activated, this, &KonqSidebarHistoryModule::slotActivated); 0024 connect(m_historyView->treeView(), &QAbstractItemView::pressed, this, &KonqSidebarHistoryModule::slotPressed); 0025 connect(m_historyView->treeView(), &QAbstractItemView::clicked, this, &KonqSidebarHistoryModule::slotClicked); 0026 connect(m_historyView, &KonqHistoryView::openUrlInNewWindow, this, &KonqSidebarHistoryModule::slotOpenWindow); 0027 connect(m_historyView, &KonqHistoryView::openUrlInNewTab, this, &KonqSidebarHistoryModule::slotOpenTab); 0028 connect(m_settings, &KonqHistorySettings::settingsChanged, this, &KonqSidebarHistoryModule::reparseConfiguration); 0029 reparseConfiguration(); 0030 } 0031 0032 KonqSidebarHistoryModule::~KonqSidebarHistoryModule() 0033 { 0034 } 0035 0036 void KonqSidebarHistoryModule::reparseConfiguration() 0037 { 0038 m_defaultAction = m_settings->m_defaultAction; 0039 } 0040 0041 0042 QWidget *KonqSidebarHistoryModule::getWidget() 0043 { 0044 return m_historyView; 0045 } 0046 0047 void KonqSidebarHistoryModule::slotCurViewUrlChanged(const QUrl& url) 0048 { 0049 m_currentUrl = url; 0050 } 0051 0052 0053 // LMB activation (single or double click) handling 0054 void KonqSidebarHistoryModule::slotActivated(const QModelIndex &index) 0055 { 0056 if (m_lastPressedButtons == Qt::MiddleButton) { // already handled by slotClicked 0057 return; 0058 } 0059 const QUrl url = m_historyView->urlForIndex(index); 0060 if (!url.isValid()) { 0061 return; 0062 } 0063 if (m_defaultAction == KonqHistorySettings::Action::OpenNewWindow) { 0064 slotOpenWindow(url); 0065 return; 0066 } 0067 BrowserArguments bargs; 0068 //Ideally, if m_defaultAction is Auto, the current tab should only be created if the current tab 0069 //has a konq: or an empty URL. However, it seems you can't get this information from here, so always 0070 //open a new tab unless the default action is OpenCurrentTab 0071 if (m_defaultAction == KonqHistorySettings::Action::OpenCurrentTab) { 0072 bargs.setNewTab(true); 0073 } else if (m_defaultAction == KonqHistorySettings::Action::Auto && !(m_currentUrl.isEmpty() || m_currentUrl.scheme() == "konq")) { 0074 bargs.setNewTab(true); 0075 } 0076 emit openUrlRequest(url, KParts::OpenUrlArguments(), bargs); 0077 } 0078 0079 // Needed for MMB handling; no convenient API in QAbstractItemView 0080 void KonqSidebarHistoryModule::slotPressed(const QModelIndex &index) 0081 { 0082 Q_UNUSED(index); 0083 m_lastPressedButtons = qApp->mouseButtons(); 0084 } 0085 0086 // MMB handling 0087 void KonqSidebarHistoryModule::slotClicked(const QModelIndex &index) 0088 { 0089 if (m_lastPressedButtons & Qt::MiddleButton) { 0090 const QUrl url = m_historyView->urlForIndex(index); 0091 if (url.isValid()) { 0092 createNewWindow(url); 0093 } 0094 } 0095 } 0096 0097 void KonqSidebarHistoryModule::slotOpenWindow(const QUrl &url) 0098 { 0099 KParts::OpenUrlArguments args; 0100 args.setActionRequestedByUser(true); 0101 BrowserArguments browserArgs; 0102 browserArgs.setForcesNewWindow(true); 0103 createNewWindow(url, args, browserArgs); 0104 } 0105 0106 void KonqSidebarHistoryModule::slotOpenTab(const QUrl &url) 0107 { 0108 KParts::OpenUrlArguments args; 0109 args.setActionRequestedByUser(true); 0110 BrowserArguments browserArgs; 0111 browserArgs.setNewTab(true); 0112 createNewWindow(url, args, browserArgs); 0113 } 0114 0115 class KonqSidebarHistoryPlugin : public KonqSidebarPlugin 0116 { 0117 public: 0118 KonqSidebarHistoryPlugin(QObject *parent, const QVariantList &args) 0119 : KonqSidebarPlugin(parent, args) {} 0120 ~KonqSidebarHistoryPlugin() override {} 0121 0122 KonqSidebarModule *createModule(QWidget *parent, 0123 const KConfigGroup &configGroup, 0124 const QString &desktopname, 0125 const QVariant &unused) override 0126 { 0127 Q_UNUSED(unused); 0128 Q_UNUSED(desktopname); 0129 return new KonqSidebarHistoryModule(parent, configGroup); 0130 } 0131 0132 QList<QAction *> addNewActions(QObject *parent, 0133 const QList<KConfigGroup> &existingModules, 0134 const QVariant &unused) override 0135 { 0136 Q_UNUSED(unused); 0137 Q_UNUSED(existingModules); 0138 QAction *action = new QAction(parent); 0139 action->setText(i18nc("@action:inmenu Add", "History Sidebar Module")); 0140 action->setIcon(QIcon::fromTheme("view-history")); 0141 return QList<QAction *>() << action; 0142 } 0143 0144 QString templateNameForNewModule(const QVariant &actionData, 0145 const QVariant &unused) const override 0146 { 0147 Q_UNUSED(actionData); 0148 Q_UNUSED(unused); 0149 return QString::fromLatin1("historyplugin%1.desktop"); 0150 } 0151 0152 bool createNewModule(const QVariant &actionData, KConfigGroup &configGroup, 0153 QWidget *parentWidget, 0154 const QVariant &unused) override 0155 { 0156 Q_UNUSED(parentWidget); 0157 Q_UNUSED(actionData); 0158 Q_UNUSED(unused); 0159 0160 configGroup.writeEntry("Type", "Link"); 0161 configGroup.writeEntry("Icon", "view-history"); 0162 configGroup.writeEntry("Name", i18nc("@title:tab", "History")); 0163 configGroup.writeEntry("X-KDE-KonqSidebarModule", "konqsidebar_history"); 0164 return true; 0165 } 0166 }; 0167 0168 K_PLUGIN_FACTORY_WITH_JSON(KonqSidebarHistoryPluginFactory, "konqsidebar_history.json", registerPlugin<KonqSidebarHistoryPlugin>();) 0169 0170 #include "history_module.moc"