File indexing completed on 2024-04-14 15:52:16

0001 /*
0002     SPDX-FileCopyrightText: 2002 Shie Erlich <erlich@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2002 Rafi Yanai <yanai@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef KRSERVICES_H
0010 #define KRSERVICES_H
0011 
0012 // QtCore
0013 #include <QMap>
0014 #include <QString>
0015 #include <QStringList>
0016 #include <QUrl>
0017 
0018 class QTextStream;
0019 class QFile;
0020 
0021 /**
0022  * Global static utility functions.
0023  */
0024 class KrServices
0025 {
0026 public:
0027     static bool cmdExist(const QString &cmdName);
0028     static QString chooseFullPathName(QStringList names, const QString &confName);
0029     static QString fullPathName(const QString &name, QString confName = QString());
0030     static bool isExecutable(const QString &path);
0031     static bool isoSupported(const QString &mimetype);
0032     static QString urlToLocalPath(const QUrl &url);
0033     static bool fileToStringList(QTextStream *stream, QStringList &target, bool keepEmptyLines = false);
0034     static bool fileToStringList(QFile *file, QStringList &target, bool keepEmptyLines = false);
0035     static QString quote(const QString &name);
0036     static QStringList quote(const QStringList &names);
0037     static QList<QUrl> toUrlList(const QStringList &list);
0038     static QStringList toStringList(const QList<QUrl> &list);
0039     static QStringList supportedTools(); // find supported tools
0040     static QString escapeFileUrl(QString urlString);
0041     static QUrl escapeFileUrl(const QUrl &url);
0042     /**
0043      * Sets the global logging message handler for qDebug(), qWarning()... messages to a custom one
0044      * with the ability to filter debug messages.
0045      */
0046     static void setGlobalKrMessageHandler(bool withDebugMessages);
0047     static QString GLOBAL_MESSAGE_PATTERN;
0048 
0049 protected:
0050     static QString escape(QString name);
0051 
0052 private:
0053     KrServices()
0054     {
0055     }
0056     ~KrServices()
0057     {
0058     }
0059     static void krMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
0060 };
0061 
0062 // TODO: make KrServices a namespace and move it there
0063 
0064 #endif