File indexing completed on 2024-05-19 04:56:00

0001 /**
0002  * \file commandformatreplacer.h
0003  * Replaces context command format codes in a string.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 09 Aug 2011
0008  *
0009  * Copyright (C) 2011-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 "frame.h"
0030 
0031 /**
0032  * Replaces context command format codes in a string.
0033  */
0034 class KID3_CORE_EXPORT CommandFormatReplacer : public FrameFormatReplacer {
0035 public:
0036   /**
0037    * Constructor.
0038    *
0039    * @param frames frame collection
0040    * @param str    string with format codes
0041    * @param files  file list
0042    * @param isDir  true if directory
0043    */
0044   explicit CommandFormatReplacer(
0045     const FrameCollection& frames, const QString& str,
0046     const QStringList& files, bool isDir);
0047 
0048   /**
0049    * Destructor.
0050    */
0051   ~CommandFormatReplacer() override = default;
0052 
0053   /**
0054    * Get help text for supported format codes.
0055    *
0056    * @param onlyRows if true only the tr elements are returned,
0057    *                 not the surrounding table
0058    *
0059    * @return help text.
0060    */
0061   static QString getToolTip(bool onlyRows = false);
0062 
0063 protected:
0064   /**
0065    * Replace a format code (one character %c or multiple characters %{chars}).
0066    * Supported format fields:
0067    * Those supported by FrameFormatReplacer::getReplacement()
0068    * %f %{file} filename
0069    * %d %{directory} directory name
0070    * %b %{browser} the web browser set in the configuration
0071    * %q %{qmlpath} base directory for QML files
0072    *
0073    * @param code format code
0074    *
0075    * @return replacement string,
0076    *         QString::null if code not found.
0077    */
0078   QString getReplacement(const QString& code) const override;
0079 
0080 private:
0081   const QStringList& m_files;
0082   const bool m_isDir;
0083 };