File indexing completed on 2024-05-05 05:00:10
0001 /* 0002 SPDX-FileCopyrightText: 2010 Pino Toscano <pino@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 "places_module.h" 0008 0009 #include <QIcon> 0010 #include <QAction> 0011 #include <QGuiApplication> 0012 0013 #include <kfileplacesmodel.h> 0014 #include <KLocalizedString> 0015 #include <kpluginfactory.h> 0016 0017 0018 KonqSideBarPlacesModule::KonqSideBarPlacesModule(QWidget *parent, 0019 const KConfigGroup &configGroup) 0020 : KonqSidebarModule(parent, configGroup) 0021 { 0022 m_placesView = new KFilePlacesView(parent); 0023 m_placesView->setModel(new KFilePlacesModel(m_placesView)); 0024 m_placesView->setShowAll(true); 0025 m_placesView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 0026 0027 m_placesView->setAutoResizeItemsEnabled(false); 0028 // m_placesView->setResizeMode(QListView::Fixed); 0029 int iconSize = m_placesView->style()->pixelMetric(QStyle::PM_SmallIconSize); // this would best be done by detecting the size of icons for other widgets 0030 m_placesView->setIconSize(QSize(iconSize, iconSize)); 0031 0032 connect(m_placesView, &KFilePlacesView::urlChanged, this, &KonqSideBarPlacesModule::slotPlaceUrlChanged); 0033 } 0034 0035 QWidget *KonqSideBarPlacesModule::getWidget() 0036 { 0037 return m_placesView; 0038 } 0039 0040 void KonqSideBarPlacesModule::slotPlaceUrlChanged(const QUrl &url) 0041 { 0042 const Qt::MouseButtons buttons = QGuiApplication::mouseButtons(); 0043 const Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers(); 0044 0045 if ((buttons & Qt::MiddleButton) != 0 || (modifiers & Qt::ControlModifier) != 0) { 0046 emit createNewWindow(url); 0047 } else { 0048 emit openUrlRequest(url); 0049 } 0050 } 0051 0052 class KonqSidebarPlacesPlugin : public KonqSidebarPlugin 0053 { 0054 public: 0055 KonqSidebarPlacesPlugin(QObject *parent, const QVariantList &args) 0056 : KonqSidebarPlugin(parent, args) {} 0057 ~KonqSidebarPlacesPlugin() override {} 0058 0059 KonqSidebarModule *createModule(QWidget *parent, 0060 const KConfigGroup &configGroup, 0061 const QString &desktopname, 0062 const QVariant &unused) override 0063 { 0064 Q_UNUSED(desktopname); 0065 Q_UNUSED(unused); 0066 return new KonqSideBarPlacesModule(parent, configGroup); 0067 } 0068 0069 QList<QAction *> addNewActions(QObject *parent, 0070 const QList<KConfigGroup> &existingModules, 0071 const QVariant &unused) override 0072 { 0073 Q_UNUSED(existingModules); 0074 Q_UNUSED(unused); 0075 QAction *action = new QAction(parent); 0076 action->setText(i18nc("@action:inmenu Add", "Places Sidebar Module")); 0077 action->setIcon(QIcon::fromTheme("folder-favorites")); 0078 return QList<QAction *>() << action; 0079 } 0080 0081 QString templateNameForNewModule(const QVariant &actionData, 0082 const QVariant &unused) const override 0083 { 0084 Q_UNUSED(actionData); 0085 Q_UNUSED(unused); 0086 return QString::fromLatin1("placessidebarplugin%1.desktop"); 0087 } 0088 0089 bool createNewModule(const QVariant &actionData, 0090 KConfigGroup &configGroup, 0091 QWidget *parentWidget, 0092 const QVariant &unused) override 0093 { 0094 Q_UNUSED(actionData); 0095 Q_UNUSED(parentWidget); 0096 Q_UNUSED(unused); 0097 configGroup.writeEntry("Type", "Link"); 0098 configGroup.writeEntry("Icon", "folder-favorites"); 0099 configGroup.writeEntry("Name", i18nc("@title:tab", "Places")); 0100 configGroup.writeEntry("X-KDE-KonqSidebarModule", "konqsidebar_places"); 0101 return true; 0102 } 0103 }; 0104 0105 K_PLUGIN_FACTORY_WITH_JSON(KonqSidebarPlacesPluginFactory, "konqsidebar_places.json", registerPlugin<KonqSidebarPlacesPlugin>();) 0106 0107 #include "places_module.moc"