File indexing completed on 2024-05-05 04:19:20
0001 // vim: set tabstop=4 shiftwidth=4 expandtab: 0002 /* 0003 Gwenview: an image viewer 0004 Copyright 2007 Aurélien Gâteau <agateau@kde.org> 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License 0008 as published by the Free Software Foundation; either version 2 0009 of the License, or (at your option) any later version. 0010 0011 This program is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU General Public License for more details. 0015 0016 You should have received a copy of the GNU General Public License 0017 along with this program; if not, write to the Free Software 0018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0019 0020 */ 0021 // Self 0022 #include "thumbnailviewhelper.h" 0023 0024 #include <config-gwenview.h> 0025 0026 // Qt 0027 #include <QAction> 0028 #include <QCursor> 0029 #include <QMenu> 0030 0031 // KF 0032 #include <KActionCollection> 0033 0034 // Local 0035 #include "fileoperations.h" 0036 #include "gwenview_app_debug.h" 0037 #include <lib/document/documentfactory.h> 0038 0039 namespace Gwenview 0040 { 0041 struct ThumbnailViewHelperPrivate { 0042 KActionCollection *mActionCollection = nullptr; 0043 QUrl mCurrentDirUrl; 0044 0045 void addActionToMenu(QMenu &popup, const char *name) 0046 { 0047 QAction *action = mActionCollection->action(name); 0048 if (!action) { 0049 qCWarning(GWENVIEW_APP_LOG) << "Unknown action" << name; 0050 return; 0051 } 0052 if (action->isEnabled()) { 0053 popup.addAction(action); 0054 } 0055 } 0056 void addActionToMenu(QMenu &popup, const QString &name) 0057 { 0058 QAction *action = mActionCollection->action(name); 0059 if (!action) { 0060 qCWarning(GWENVIEW_APP_LOG) << "Unknown action" << name; 0061 return; 0062 } 0063 if (action->isEnabled()) { 0064 popup.addAction(action); 0065 } 0066 } 0067 }; 0068 0069 ThumbnailViewHelper::ThumbnailViewHelper(QObject *parent, KActionCollection *actionCollection) 0070 : AbstractThumbnailViewHelper(parent) 0071 , d(new ThumbnailViewHelperPrivate) 0072 { 0073 d->mActionCollection = actionCollection; 0074 } 0075 0076 ThumbnailViewHelper::~ThumbnailViewHelper() 0077 { 0078 delete d; 0079 } 0080 0081 void ThumbnailViewHelper::setCurrentDirUrl(const QUrl &url) 0082 { 0083 d->mCurrentDirUrl = url; 0084 } 0085 0086 void ThumbnailViewHelper::showContextMenu(QWidget *parent) 0087 { 0088 QMenu popup(parent); 0089 if (d->mCurrentDirUrl.scheme() == QLatin1String("trash")) { 0090 d->addActionToMenu(popup, "file_restore"); 0091 d->addActionToMenu(popup, "deletefile"); 0092 popup.addSeparator(); 0093 d->addActionToMenu(popup, "file_show_properties"); 0094 } else { 0095 d->addActionToMenu(popup, "file_create_folder"); 0096 popup.addSeparator(); 0097 d->addActionToMenu(popup, "file_rename"); 0098 d->addActionToMenu(popup, "file_trash"); 0099 d->addActionToMenu(popup, "deletefile"); 0100 popup.addSeparator(); 0101 d->addActionToMenu(popup, KStandardAction::name(KStandardAction::Copy)); 0102 d->addActionToMenu(popup, "file_copy_to"); 0103 d->addActionToMenu(popup, "file_move_to"); 0104 d->addActionToMenu(popup, "file_link_to"); 0105 popup.addSeparator(); 0106 d->addActionToMenu(popup, "file_open_in_new_window"); 0107 d->addActionToMenu(popup, "file_open_with"); 0108 d->addActionToMenu(popup, "file_open_containing_folder"); 0109 #ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE 0110 d->addActionToMenu(popup, "edit_tags"); 0111 #endif 0112 popup.addSeparator(); 0113 d->addActionToMenu(popup, "file_show_properties"); 0114 } 0115 popup.exec(QCursor::pos()); 0116 } 0117 0118 void ThumbnailViewHelper::showMenuForUrlDroppedOnViewport(QWidget *parent, const QList<QUrl> &lst) 0119 { 0120 showMenuForUrlDroppedOnDir(parent, lst, d->mCurrentDirUrl); 0121 } 0122 0123 void ThumbnailViewHelper::showMenuForUrlDroppedOnDir(QWidget *parent, const QList<QUrl> &urlList, const QUrl &destUrl) 0124 { 0125 FileOperations::showMenuForDroppedUrls(parent, urlList, destUrl); 0126 } 0127 0128 } // namespace 0129 0130 #include "moc_thumbnailviewhelper.cpp"