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 Producer;
36}
37
38class Util
39{
40private:
41 Util() {}
42
43public:
44 static QString baseName(const QString &filePath, bool trimQuery = false);
45 static void setColorsToHighlight(QWidget *widget, QPalette::ColorRole role = QPalette::Window);
46 static void showInFolder(const QString &path);
47 static bool warnIfNotWritable(const QString &filePath, QWidget *parent, const QString &caption);
48 static QString producerTitle(const Mlt::Producer &producer);
49 static QString removeFileScheme(QUrl &url, bool fromPercentEncoding = true);
50 static const QStringList sortedFileList(const QList<QUrl> &urls);
51 static int coerceMultiple(int value, int multiple = 2);
52 static QList<QUrl> expandDirectories(const QList<QUrl> &urls);
53 static bool isDecimalPoint(QChar ch);
54 static bool isNumeric(QString &str);
55 static bool convertNumericString(QString &str, QChar decimalPoint);
56 static bool convertDecimalPoints(QString &str, QChar decimalPoint);
57 static void showFrameRateDialog(const QString &caption,
58 int numerator,
59 QDoubleSpinBox *spinner,
60 QWidget *parent = Q_NULLPTR);
61 static QTemporaryFile *writableTemporaryFile(const QString &filePath = QString(),
62 const QString &templateName = QString());
63 static void applyCustomProperties(Mlt::Producer &destination,
64 Mlt::Producer &source,
65 int in,
66 int out);
67 static QString getFileHash(const QString &path);
68 static QString getHash(Mlt::Properties &properties);
69 static bool hasDriveLetter(const QString &path);
70 static QColorDialog::ColorDialogOptions getColorDialogOptions();
71 static QFileDialog::Options getFileDialogOptions();
72 static bool isMemoryLow();
73 static QString removeQueryString(const QString &s);
74 static int greatestCommonDivisor(int m, int n);
75 static void normalizeFrameRate(double fps, int &numerator, int &denominator);
76 static QString textColor(const QColor &color);
77 static void cameraFrameRateSize(const QByteArray &deviceName, qreal &frameRate, QSize &size);
78 static bool ProducerIsTimewarp(Mlt::Producer *producer);
79 static QString GetFilenameFromProducer(Mlt::Producer *producer, bool useOriginal = true);
80 static double GetSpeedFromProducer(Mlt::Producer *producer);
81 static QString updateCaption(Mlt::Producer *producer);
82 static void passProducerProperties(Mlt::Producer *src, Mlt::Producer *dst);
83 static bool warnIfLowDiskSpace(const QString &path);
84 static bool isFpsDifferent(double a, double b);
85 static QString getNextFile(const QString &filePath);
86 static QString trcString(int trc);
87 static bool trcIsCompatible(int trc);
88 static QString getConversionAdvice(Mlt::Producer *producer);
89 static mlt_color mltColorFromQColor(const QColor &color);
90 static void offerSingleFileConversion(QString &message,
91 Mlt::Producer *producer,
92 QWidget *parent);
93 static double getAndroidFrameRate(Mlt::Producer *producer);
94 static double getSuggestedFrameRate(Mlt::Producer *producer);
95 static Mlt::Producer openMltVirtualClip(const QString &path);
96 static bool hasiPhoneAmbisonic(Mlt::Producer *producer);
97 static bool installFlatpakWrappers(QWidget *parent);
98 static QString getExecutable(QWidget *parent);
99 // Returns a pair of booleans: (dockerInstalled, imagePresent)
100 // imagePresent is only meaningful (true/false) if dockerInstalled is true; otherwise false.
101 static QPair<bool, bool> dockerStatus(const QString &imageName);
102 static bool isDockerImageCurrent(const QString &imageRef);
103 // Asynchronous version of isDockerImageCurrent. The callback is invoked on the GUI thread
104 // with the result. If any step fails (including docker not found), result is false.
105 // 'receiver' is used as the parent for internal QProcess objects (may be nullptr).
106 static void isDockerImageCurrentAsync(const QString &imageRef,
107 QObject *receiver,
108 std::function<void(bool)> callback);
109 static bool isChromiumAvailable();
110 static bool startDetached(const QString &program, const QStringList &arguments);
111 static bool openUrl(const QUrl &url);
112};
113
114#endif // UTIL_H