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

0001 /**
0002  * \file icoreplatformtools.h
0003  * Interface for GUI independent platform specific tools.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 06 Apr 2013
0008  *
0009  * Copyright (C) 2013-2018  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 <QPair>
0031 #include "kid3api.h"
0032 
0033 class QObject;
0034 class QString;
0035 class QWidget;
0036 class ISettings;
0037 class CoreTaggedFileIconProvider;
0038 class Kid3Application;
0039 
0040 /**
0041  * Interface for GUI independent platform specific tools.
0042  */
0043 class KID3_CORE_EXPORT ICorePlatformTools {
0044 public:
0045   /**
0046    * Destructor.
0047    */
0048   virtual ~ICorePlatformTools();
0049 
0050   /**
0051    * Get application settings.
0052    * @return settings instance.
0053    */
0054   virtual ISettings* applicationSettings() = 0;
0055 
0056   /**
0057    * Get icon provider for tagged files.
0058    * @return icon provider.
0059    */
0060   virtual CoreTaggedFileIconProvider* iconProvider() = 0;
0061 
0062   /**
0063    * Write text to clipboard.
0064    * @param text text to write
0065    * @return true if operation is supported.
0066    */
0067   virtual bool writeToClipboard(const QString& text) const = 0;
0068 
0069   /**
0070    * Read text from clipboard.
0071    * @return text, null if operation not supported.
0072    */
0073   virtual QString readFromClipboard() const = 0;
0074 
0075   /**
0076    * Create an audio player instance.
0077    * @param app application context
0078    * @param dbusEnabled true to enable MPRIS D-Bus interface
0079    * @return audio player, nullptr if not supported.
0080    */
0081   virtual QObject* createAudioPlayer(Kid3Application* app,
0082                                      bool dbusEnabled) const = 0;
0083 
0084   /**
0085    * Move file or directory to trash.
0086    *
0087    * @param path path to file or directory
0088    *
0089    * @return true if ok.
0090    */
0091   virtual bool moveToTrash(const QString& path) const = 0;
0092 
0093   /**
0094    * Construct a name filter string suitable for file dialogs.
0095    * @param nameFilters list of description, filter pairs, e.g.
0096    * [("Images", "*.jpg *.jpeg *.png"), ("All Files", "*")].
0097    * @return name filter string.
0098    */
0099   virtual QString fileDialogNameFilter(
0100       const QList<QPair<QString, QString> >& nameFilters) const = 0;
0101 
0102   /**
0103    * Get file pattern part of m_nameFilter.
0104    * @param nameFilter name filter string
0105    * @return file patterns, e.g. "*.mp3".
0106    */
0107   virtual QString getNameFilterPatterns(const QString& nameFilter) const = 0;
0108 
0109   /**
0110    * Display dialog to select an existing file.
0111    * This default implementation only displays a warning, it is only supported
0112    * when having a GUI.
0113    * @param parent parent widget
0114    * @param caption caption
0115    * @param dir directory
0116    * @param filter filter
0117    * @param selectedFilter the selected filter is returned here
0118    * @return selected file, empty if canceled.
0119    */
0120   virtual QString getOpenFileName(QWidget* parent,
0121       const QString& caption, const QString& dir, const QString& filter,
0122       QString* selectedFilter);
0123 
0124   /**
0125    * Display dialog to select a file to save.
0126    * This default implementation only displays a warning, it is only supported
0127    * when having a GUI.
0128    * @param parent parent widget
0129    * @param caption caption
0130    * @param dir directory
0131    * @param filter filter
0132    * @param selectedFilter the selected filter is returned here
0133    * @return selected file, empty if canceled.
0134    */
0135   virtual QString getSaveFileName(QWidget* parent,
0136       const QString& caption, const QString& dir, const QString& filter,
0137       QString* selectedFilter);
0138 
0139   /**
0140    * Display dialog to select an existing directory.
0141    * This default implementation only displays a warning, it is only supported
0142    * when having a GUI.
0143    * @param parent parent widget
0144    * @param caption caption
0145    * @param startDir start directory
0146    * @return selected directory, empty if canceled.
0147    */
0148   virtual QString getExistingDirectory(QWidget* parent,
0149       const QString& caption, const QString& startDir);
0150 
0151   /**
0152    * Check if platform has a graphical user interface.
0153    * @return true if platform has GUI.
0154    */
0155   virtual bool hasGui() const;
0156 
0157 protected:
0158   /**
0159    * Construct a name filter string suitable for file dialogs.
0160    * This function can be used to implement fileDialogNameFilter()
0161    * for QFileDialog.
0162    * @param nameFilters list of description, filter pairs, e.g.
0163    * [("Images", "*.jpg *.jpeg *.png"), ("All Files", "*")].
0164    * @return name filter string.
0165    */
0166   static QString qtFileDialogNameFilter(
0167       const QList<QPair<QString, QString> >& nameFilters);
0168 
0169   /**
0170    * Get file pattern part of m_nameFilter.
0171    * This function can be used to implement getNameFilterPatterns()
0172    * for QFileDialog.
0173    * @param nameFilter name filter string
0174    * @return file patterns, e.g. "*.mp3".
0175    */
0176   static QString qtNameFilterPatterns(const QString& nameFilter);
0177 };