utils/misc.h

utils/misc.h

utils/misc.h

Functions

Name
QStringcreateRandomString(int len)
Create a random alphanumeric string with the given length.
QStringsimplifyStrForModuleName(const QString & s)
Simplify a string for use as a module name.
QStringsimplifyStrForFileBasename(const QString & s)
Simplify a string for use in file basenames.
QStringsimplifyStrForFileBasenameLower(const QString & s)
Simplify a string for use in file basenames, and return a lowercased version.
QStringListqStringSplitLimit(const QString & str, const QChar & sep, int maxSplit, Qt::CaseSensitivity cs =Qt::CaseSensitive)
Split a string, limiting the amount of splits made.
QStringListstringListNaturalSort(QStringList & list)
Naturally sort the give string list (sorting “10” after “9”)
QStringsyntalosVersionFull()
Return the complete current Syntalos version number.
boolisInFlatpakSandbox()
Check if Syntalos is running in a Flatpak sandbox.
QStringtempDirRoot()
Get path to the OSes default temporary directory.
QStringtempDirLargeRoot()
Get path to a temporary directory that can hold large files.
QStringfindHostFile(const QString & path)
Find file on the host system (if running in a sandbox)
boolhostUdevRuleExists(const QString & ruleFilename)
Check if a udev rule exists.
boolisBinaryInPath(const QString & binaryName)
Check if a binary is in the current environment PATH.
voiddelay(int waitMsec)
Delay execution by approximately the given time, not blocking the main event loop.

Functions Documentation

function createRandomString

QString createRandomString(
    int len
)

Create a random alphanumeric string with the given length.

function simplifyStrForModuleName

QString simplifyStrForModuleName(
    const QString & s
)

Simplify a string for use as a module name.

function simplifyStrForFileBasename

QString simplifyStrForFileBasename(
    const QString & s
)

Simplify a string for use in file basenames.

function simplifyStrForFileBasenameLower

QString simplifyStrForFileBasenameLower(
    const QString & s
)

Simplify a string for use in file basenames, and return a lowercased version.

function qStringSplitLimit

QStringList qStringSplitLimit(
    const QString & str,
    const QChar & sep,
    int maxSplit,
    Qt::CaseSensitivity cs =Qt::CaseSensitive
)

Split a string, limiting the amount of splits made.

function stringListNaturalSort

QStringList stringListNaturalSort(
    QStringList & list
)

Naturally sort the give string list (sorting “10” after “9”)

function syntalosVersionFull

QString syntalosVersionFull()

Return the complete current Syntalos version number.

Retrieve the full Syntalos version, including any VCS information.

function isInFlatpakSandbox

bool isInFlatpakSandbox()

Check if Syntalos is running in a Flatpak sandbox.

function tempDirRoot

QString tempDirRoot()

Get path to the OSes default temporary directory.

Return: An absolute path to temp dir.

function tempDirLargeRoot

QString tempDirLargeRoot()

Get path to a temporary directory that can hold large files.

Return: An absolute path to temp dir.

function findHostFile

QString findHostFile(
    const QString & path
)

Find file on the host system (if running in a sandbox)

Parameters:

  • path Path of the file to check for

Return: The absolute path to the requested file, or an empty string if not found.

function hostUdevRuleExists

bool hostUdevRuleExists(
    const QString & ruleFilename
)

Check if a udev rule exists.

Parameters:

  • ruleFilename Name of the udev rule file

Return: true if the rule existed, false otherwise.

function isBinaryInPath

bool isBinaryInPath(
    const QString & binaryName
)

Check if a binary is in the current environment PATH.

Parameters:

  • binaryName Name of the binary to check for

Return: true if the binary is in the PATH, false otherwise.

function delay

void delay(
    int waitMsec
)

Delay execution by approximately the given time, not blocking the main event loop.

Parameters:

  • waitMsec Time to wait.

Source code

/*
 * Copyright (C) 2016-2024 Matthias Klumpp <matthias@tenstral.net>
 *
 * Licensed under the GNU Lesser General Public License Version 3
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the license, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this software.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef UTILS_H
#define UTILS_H

#include <QString>
#include <QStringList>

QString createRandomString(int len);

QString simplifyStrForModuleName(const QString &s);

QString simplifyStrForFileBasename(const QString &s);

QString simplifyStrForFileBasenameLower(const QString &s);

QStringList qStringSplitLimit(
    const QString &str,
    const QChar &sep,
    int maxSplit,
    Qt::CaseSensitivity cs = Qt::CaseSensitive);

QStringList stringListNaturalSort(QStringList &list);

QString syntalosVersionFull();

bool isInFlatpakSandbox();

QString tempDirRoot();

QString tempDirLargeRoot();

QString findHostFile(const QString &path);

bool hostUdevRuleExists(const QString &ruleFilename);

bool isBinaryInPath(const QString &binaryName);

void delay(int waitMsec);

#endif // UTILS_H

Updated on 2024-09-05 at 17:39:59 +0000