CuteLogger
Fast and simple logging solution for Qt based applications
util.h
1/*
2 * Copyright (c) 2014-2026 Meltytech, LLC
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef UTIL_H
19#define UTIL_H
20
21#include <MltProperties.h>
22#include <functional>
23#include <QColorDialog>
24#include <QFileDialog>
25#include <QPair>
26#include <QPalette>
27#include <QString>
28#include <QUrl>
29
30class QWidget;
31class QDoubleSpinBox;
32class QTemporaryFile;
33
34namespace Mlt {
35class Filter;
36class Link;
37class Producer;
38} // namespace Mlt
39
40class Util
41{
42private:
43 Util() {}
44
45public:
46 static QString baseName(const QString &filePath, bool trimQuery = false);
47 static void setColorsToHighlight(QWidget *widget, QPalette::ColorRole role = QPalette::Window);
48 static void showInFolder(const QString &path);
49 static bool warnIfNotWritable(const QString &filePath, QWidget *parent, const QString &caption);
50 static QString producerTitle(const Mlt::Producer &producer);
51 static QString removeFileScheme(QUrl &url, bool fromPercentEncoding = true);
52 static const QStringList sortedFileList(const QList<QUrl> &urls);
53 static int coerceMultiple(int value, int multiple = 2);
54 static QList<QUrl> expandDirectories(const QList<QUrl> &urls);
55 static bool isDecimalPoint(QChar ch);
56 static bool isNumeric(QString &str);
57 static bool convertNumericString(QString &str, QChar decimalPoint);
58 static bool convertDecimalPoints(QString &str, QChar decimalPoint);
59 static void showFrameRateDialog(const QString &caption,
60 int numerator,
61 QDoubleSpinBox *spinner,
62 QWidget *parent = Q_NULLPTR);
63 static QTemporaryFile *writableTemporaryFile(const QString &filePath = QString(),
64 const QString &templateName = QString());
65 static void applyCustomProperties(Mlt::Producer &destination,
66 Mlt::Producer &source,
67 int in,
68 int out);
69 static QString getFileHash(const QString &path);
70 static QString getHash(Mlt::Properties &properties);
71 static bool hasDriveLetter(const QString &path);
72 static QColorDialog::ColorDialogOptions getColorDialogOptions();
73 static QFileDialog::Options getFileDialogOptions();
74 static bool isMemoryLow();
75 static QString removeQueryString(const QString &s);
76 static int greatestCommonDivisor(int m, int n);
77 static void normalizeFrameRate(double fps, int &numerator, int &denominator);
78 static QString textColor(const QColor &color);
79 static void cameraFrameRateSize(const QByteArray &deviceName, qreal &frameRate, QSize &size);
80 static bool ProducerIsTimewarp(Mlt::Producer *producer);
81 static QString GetFilenameFromProducer(Mlt::Producer *producer, bool useOriginal = true);
82 static double GetSpeedFromProducer(Mlt::Producer *producer);
83 static QString updateCaption(Mlt::Producer *producer);
84 static void passProducerProperties(Mlt::Producer *src, Mlt::Producer *dst);
85 static bool warnIfLowDiskSpace(const QString &path);
86 static bool isFpsDifferent(double a, double b);
87 static QString getNextFile(const QString &filePath);
88 static QString trcString(int trc);
89 static bool trcIsSdrCompatible(int trc);
90 static QString getConversionAdvice(Mlt::Producer *producer);
91 static mlt_color mltColorFromQColor(const QColor &color);
92 static void offerSingleFileConversion(QString &message,
93 Mlt::Producer *producer,
94 QWidget *parent);
95 static double getAndroidFrameRate(Mlt::Producer *producer);
96 static double getSuggestedFrameRate(Mlt::Producer *producer);
97 static Mlt::Producer openMltVirtualClip(const QString &path);
98 static bool hasiPhoneAmbisonic(Mlt::Producer *producer);
99 static bool installFlatpakWrappers(QWidget *parent);
100 static QString getExecutable(QWidget *parent);
101 // Returns a pair of booleans: (dockerInstalled, imagePresent)
102 // imagePresent is only meaningful (true/false) if dockerInstalled is true; otherwise false.
103 static QPair<bool, bool> dockerStatus(const QString &imageName);
104 static bool isDockerImageCurrent(const QString &imageRef);
105 // Asynchronous version of isDockerImageCurrent. The callback is invoked on the GUI thread
106 // with the result. If any step fails (including docker not found), result is false.
107 // 'receiver' is used as the parent for internal QProcess objects (may be nullptr).
108 static void isDockerImageCurrentAsync(const QString &imageRef,
109 QObject *receiver,
110 std::function<void(bool)> callback);
111 static bool isChromiumAvailable();
112 static bool startDetached(const QString &program, const QStringList &arguments);
113 static bool openUrl(const QUrl &url);
114 static bool cpuHasAVX2();
115 static int msToPosition(int64_t ms);
116 static bool isPostUserFilter(Mlt::Filter *filter);
117 static bool isPreUserFilter(Mlt::Filter *filter);
118 static bool isUserFilter(Mlt::Filter *filter);
119 static bool isUserLink(Mlt::Link *link);
120};
121
122#endif // UTIL_H