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

0001 /**
0002  * \file coreplatformtools.h
0003  * Core platform specific tools for Qt.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 10 Aug 2013
0008  *
0009  * Copyright (C) 2013-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 <QScopedPointer>
0030 #include "icoreplatformtools.h"
0031 #include "isettings.h"
0032 #include "coretaggedfileiconprovider.h"
0033 
0034 class QSettings;
0035 
0036 /**
0037  * Core platform specific tools for Qt.
0038  */
0039 class KID3_CORE_EXPORT CorePlatformTools : public ICorePlatformTools {
0040 public:
0041   /**
0042    * Constructor.
0043    */
0044   CorePlatformTools();
0045 
0046   /**
0047    * Destructor.
0048    */
0049   ~CorePlatformTools() override;
0050 
0051   /**
0052    * Get application settings.
0053    * @return settings instance.
0054    */
0055   ISettings* applicationSettings() override;
0056 
0057   /**
0058    * Get icon provider for tagged files.
0059    * @return icon provider.
0060    */
0061   CoreTaggedFileIconProvider* iconProvider() override;
0062 
0063   /**
0064    * Write text to clipboard.
0065    * @param text text to write
0066    * @return true if operation is supported.
0067    */
0068   bool writeToClipboard(const QString& text) const override;
0069 
0070   /**
0071    * Read text from clipboard.
0072    * @return text, null if operation not supported.
0073    */
0074   QString readFromClipboard() const override;
0075 
0076   /**
0077    * Create an audio player instance.
0078    * @param app application context
0079    * @param dbusEnabled true to enable MPRIS D-Bus interface
0080    * @return audio player, nullptr if not supported.
0081    */
0082   QObject* createAudioPlayer(Kid3Application* app,
0083                              bool dbusEnabled) const override;
0084 
0085   /**
0086    * Move file or directory to trash.
0087    *
0088    * @param path path to file or directory
0089    *
0090    * @return true if ok.
0091    */
0092   bool moveToTrash(const QString& path) const override;
0093 
0094   /**
0095    * Construct a name filter string suitable for file dialogs.
0096    * @param nameFilters list of description, filter pairs, e.g.
0097    * [("Images", "*.jpg *.jpeg *.png"), ("All Files", "*")].
0098    * @return name filter string.
0099    */
0100   QString fileDialogNameFilter(
0101       const QList<QPair<QString, QString> >& nameFilters) const override;
0102 
0103   /**
0104    * Get file pattern part of m_nameFilter.
0105    * @param nameFilter name filter string
0106    * @return file patterns, e.g. "*.mp3".
0107    */
0108   QString getNameFilterPatterns(const QString& nameFilter) const override;
0109 
0110 #if !defined Q_OS_WIN32 && !defined Q_OS_MAC
0111   /**
0112    * Move file or directory to trash.
0113    *
0114    * @param path path to file or directory
0115    *
0116    * @return true if ok.
0117    */
0118   static bool moveFileToTrash(const QString& path);
0119 #endif
0120 
0121 private:
0122   QSettings* m_settings;
0123   QScopedPointer<ISettings> m_config;
0124   QScopedPointer<CoreTaggedFileIconProvider> m_iconProvider;
0125 };