File indexing completed on 2024-04-28 15:29:04
0001 /* 0002 SPDX-FileCopyrightText: 2008 Jeremy Whiting <jpwhiting@kde.org> 0003 SPDX-FileCopyrightText: 2010 Reza Fatahilah Shah <rshah0385@kireihana.com> 0004 SPDX-FileCopyrightText: 2010 Frederik Gladhorn <gladhorn@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 */ 0008 0009 #include "itemsviewbasedelegate_p.h" 0010 0011 #include "core/itemsmodel.h" 0012 0013 #include "entrydetailsdialog_p.h" 0014 0015 #include <QAction> 0016 0017 #include <knewstuff_debug.h> 0018 #include <qstandardpaths.h> 0019 0020 namespace KNS3 0021 { 0022 ItemsViewBaseDelegate::ItemsViewBaseDelegate(QAbstractItemView *itemView, KNSCore::Engine *engine, QObject *parent) 0023 : KWidgetItemDelegate(itemView, parent) 0024 , m_engine(engine) 0025 , m_itemView(itemView) 0026 , m_iconInvalid(QIcon::fromTheme(QStringLiteral("dialog-error"))) 0027 , m_iconInstall(QIcon::fromTheme(QStringLiteral("dialog-ok"))) 0028 , m_iconUpdate(QIcon::fromTheme(QStringLiteral("system-software-update"))) 0029 , m_iconDelete(QIcon::fromTheme(QStringLiteral("edit-delete"))) 0030 { 0031 const QString framefile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/knewstuff/pics/thumb_frame.png")); 0032 m_frameImage = QPixmap(framefile); 0033 } 0034 0035 ItemsViewBaseDelegate::~ItemsViewBaseDelegate() 0036 { 0037 } 0038 0039 bool ItemsViewBaseDelegate::eventFilter(QObject *watched, QEvent *event) 0040 { 0041 if (event->type() == QEvent::MouseButtonDblClick) { 0042 slotDetailsClicked(); 0043 return true; 0044 } 0045 0046 return KWidgetItemDelegate::eventFilter(watched, event); 0047 } 0048 0049 void ItemsViewBaseDelegate::slotLinkClicked(const QString &url) 0050 { 0051 Q_UNUSED(url) 0052 QModelIndex index = focusedIndex(); 0053 Q_ASSERT(index.isValid()); 0054 0055 KNSCore::EntryInternal entry = index.data(Qt::UserRole).value<KNSCore::EntryInternal>(); 0056 m_engine->contactAuthor(entry); 0057 } 0058 0059 void ItemsViewBaseDelegate::slotInstallClicked() 0060 { 0061 QModelIndex index = focusedIndex(); 0062 if (index.isValid()) { 0063 KNSCore::EntryInternal entry = index.data(Qt::UserRole).value<KNSCore::EntryInternal>(); 0064 if (!entry.isValid()) { 0065 qCDebug(KNEWSTUFF) << "Invalid entry: " << entry.name(); 0066 return; 0067 } 0068 0069 if (entry.status() == Entry::Installed) { 0070 m_engine->uninstall(entry); 0071 } else { 0072 m_engine->install(entry); 0073 } 0074 } 0075 } 0076 0077 void ItemsViewBaseDelegate::slotInstallActionTriggered(QAction *action) 0078 { 0079 if (action->data().isNull()) { 0080 return; 0081 } 0082 0083 QPoint rowDownload = action->data().toPoint(); 0084 int row = rowDownload.x(); 0085 QModelIndex index = m_itemView->model()->index(row, 0); 0086 if (index.isValid()) { 0087 KNSCore::EntryInternal entry = index.data(Qt::UserRole).value<KNSCore::EntryInternal>(); 0088 m_engine->install(entry, rowDownload.y()); 0089 } 0090 } 0091 0092 void ItemsViewBaseDelegate::slotDetailsClicked() 0093 { 0094 QModelIndex index = focusedIndex(); 0095 slotDetailsClicked(index); 0096 } 0097 0098 void ItemsViewBaseDelegate::slotDetailsClicked(const QModelIndex &index) 0099 { 0100 if (index.isValid()) { 0101 KNSCore::EntryInternal entry = index.data(Qt::UserRole).value<KNSCore::EntryInternal>(); 0102 if (!entry.isValid()) { 0103 return; 0104 } 0105 qCDebug(KNEWSTUFF) << "Details: " << entry.name(); 0106 Q_EMIT signalShowDetails(entry); 0107 } 0108 } 0109 } 0110 0111 #include "moc_itemsviewbasedelegate_p.cpp"