File indexing completed on 2025-02-23 04:34:21
0001 /** 0002 * \file filelist.h 0003 * List of files to operate on. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 9 Jan 2003 0008 * 0009 * Copyright (C) 2003-2024 Urs Fleisch 0010 * 0011 * This file is part of Kid3. 0012 * 0013 * Kid3 is free software; you can redistribute it and/or modify 0014 * it under the terms of the GNU General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or 0016 * (at your option) any later version. 0017 * 0018 * Kid3 is distributed in the hope that it will be useful, 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0021 * GNU General Public License for more details. 0022 * 0023 * You should have received a copy of the GNU General Public License 0024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #pragma once 0028 0029 #include <QList> 0030 #include <QMap> 0031 #include <QScopedPointer> 0032 #include "configurabletreeview.h" 0033 #include "kid3api.h" 0034 0035 class BaseMainWindowImpl; 0036 class ExternalProcess; 0037 0038 /** 0039 * List of files to operate on. 0040 */ 0041 class KID3_GUI_EXPORT FileList : public ConfigurableTreeView { 0042 Q_OBJECT 0043 public: 0044 /** 0045 * Constructor. 0046 * @param parent parent widget 0047 * @param mainWin main window 0048 */ 0049 FileList(QWidget* parent, BaseMainWindowImpl* mainWin); 0050 0051 /** 0052 * Destructor. 0053 */ 0054 ~FileList() override; 0055 0056 /** 0057 * Returns the recommended size for the widget. 0058 * @return recommended size. 0059 */ 0060 QSize sizeHint() const override; 0061 0062 /** 0063 * Set rename action. 0064 * @param action rename action 0065 */ 0066 void setRenameAction(QAction* action); 0067 0068 /** 0069 * Set delete action. 0070 * @param action delete action 0071 */ 0072 void setDeleteAction(QAction* action); 0073 0074 protected: 0075 /** 0076 * Enable dragging if the item is pressed at the left icon side. 0077 * @param event mouse event 0078 */ 0079 void mousePressEvent(QMouseEvent* event) override; 0080 0081 /** 0082 * Called when a drag operation is started. 0083 * Reimplemented to close all tagged files before being dropped to another 0084 * application, which would not be able to open them on Windows. 0085 * @param supportedActions drop actions 0086 */ 0087 void startDrag(Qt::DropActions supportedActions) override; 0088 0089 public slots: 0090 /** 0091 * Init the user actions for the context menu. 0092 */ 0093 void initUserActions(); 0094 0095 signals: 0096 /** 0097 * Emitted when a user action is added. 0098 * @param name name of action 0099 * @param action action added 0100 */ 0101 void userActionAdded(const QString& name, QAction* action); 0102 0103 /** 0104 * Emitted when a user action is removed. 0105 * @param name name of action 0106 * @param action action removed 0107 */ 0108 void userActionRemoved(const QString& name, QAction* action); 0109 0110 private slots: 0111 /** 0112 * Display a context menu with operations for selected files. 0113 * 0114 * @param index index of item 0115 * @param pos position where context menu is drawn on screen 0116 */ 0117 void contextMenu(const QModelIndex& index, const QPoint& pos); 0118 0119 /** 0120 * Execute a context menu command. 0121 * 0122 * @param id command ID 0123 */ 0124 void executeContextCommand(int id); 0125 0126 /** 0127 * Execute a context menu action. 0128 * 0129 * @param action action of selected menu, 0 to use sender() action 0130 */ 0131 void executeAction(const QAction* action = nullptr); 0132 0133 /** 0134 * Execute context menu action which sent signal. 0135 * Same as executeAction() with default arguments, provided for functor-based 0136 * connections. 0137 */ 0138 void executeSenderAction(); 0139 0140 /** 0141 * Display a custom context menu with operations for selected files. 0142 * 0143 * @param pos position where context menu is drawn on screen 0144 */ 0145 void customContextMenu(const QPoint& pos); 0146 0147 /** 0148 * Handle double click to file. 0149 * 0150 * @param index model index of item 0151 */ 0152 void onDoubleClicked(const QModelIndex& index); 0153 0154 /** 0155 * Open with standard application. 0156 */ 0157 void openFile(); 0158 0159 /** 0160 * Called when "Edit" action is called from context menu. 0161 */ 0162 void editPlaylist(); 0163 0164 /** 0165 * Open containing folder. 0166 */ 0167 void openContainingFolder(); 0168 0169 private: 0170 Q_DISABLE_COPY(FileList) 0171 0172 /** 0173 * Format a string list from the selected files. 0174 * Supported format fields: 0175 * Those supported by FrameFormatReplacer::getReplacement(), 0176 * when prefixed with u, encoded as URL 0177 * %f filename 0178 * %F list of files 0179 * %uf URL of single file 0180 * %uF list of URLs 0181 * %d directory name 0182 * %b the web browser set in the configuration 0183 * 0184 * @todo %f and %F are full paths, which is inconsistent with the 0185 * export format strings but compatible with .desktop files. 0186 * %d is duration in export format. 0187 * The export codes should be changed. 0188 * 0189 * @param format format specification 0190 * 0191 * @return formatted string list. 0192 */ 0193 QStringList formatStringList(const QStringList& format) const; 0194 0195 /** Process for context menu commands */ 0196 QScopedPointer<ExternalProcess> m_process; 0197 BaseMainWindowImpl* m_mainWin; 0198 QAction* m_renameAction; 0199 QAction* m_deleteAction; 0200 QMap<QString, QAction*> m_userActions; 0201 };