DtkCore
DTK Core module
载入中...
搜索中...
未找到
dutil.h
浏览该文件的文档.
1// SPDX-FileCopyrightText: 2016 - 2026 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#pragma once
6
7#include <QTimer>
8#include <QThread>
9#include <QMetaObject>
10#include <QCoreApplication>
11#include <QRegularExpression>
12#include <QStandardPaths>
13#include <QDir>
14#include <type_traits>
15#include <cstring>
16
17namespace DUtil
18{
19
20template <typename Func1>
21inline void TimerSingleShot(int msec, Func1 slot)
22{
23#if QT_VERSION >= 0x050500
24 QTimer::singleShot(msec, slot);
25#else
26 QTimer *timer = new QTimer;
27 timer->setSingleShot(true);
28 timer->setInterval(msec);
29 timer->moveToThread(qApp->thread());
30 QObject::connect(timer, &QTimer::timeout, slot);
31 QObject::connect(timer, &QTimer::timeout, timer, &QTimer::deleteLater);
32 if (QThread::currentThread() == qApp->thread()) { timer->start(); }
33 else { QMetaObject::invokeMethod(timer, "start", Qt::QueuedConnection); }
34#endif
35}
36
37template <class T>
38void SecureErase(T *p, size_t size)
39{
40 static_assert(std::is_standard_layout<T>::value && std::is_trivially_destructible<T>::value,
41 "try to erase content of raw pointer, but type T isn't suitable");
42
43 std::memset(p, 0, size);
44}
45
46template <class T>
47void SecureErase(T &obj)
48{
49 static_assert(std::is_default_constructible<typename T::value_type>::value,
50 "container's value type must have a default constructor.");
51
52 for (typename T::iterator i = obj.begin(); i != obj.end(); ++i) {
53 *i = typename T::value_type{};
54 }
55}
56
57QString escapeToObjectPath(const QByteArray &str) noexcept;
58
59QString escapeToObjectPath(const QString &str) noexcept;
60
61QString unescapeFromObjectPath(const QString &str) noexcept;
62
63QString getAppIdFromAbsolutePath(const QString &path) noexcept;
64
65QStringList getAbsolutePathFromAppId(const QString &appId) noexcept;
66}
QStringList getAbsolutePathFromAppId(const QString &appId) noexcept
从appId中获取符合条件的Desktop文件路径
QString unescapeFromObjectPath(const QString &str) noexcept
将DBus ObjectPath的部分路径转义成原来的字符串
QString getAppIdFromAbsolutePath(const QString &path) noexcept
从desktop文件的绝对路径中提取出AppId