1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/*
* Copyright (C) 2019 ~ 2020 UnionTech Software Technology Co.,Ltd
*
* Author: zyc <zyc@uniontech.com>
* Maintainer: zyc <zyc@uniontech.com>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LOGAPPLICATIONHELPER_H
#define LOGAPPLICATIONHELPER_H
#include "com_deepin_dde_daemon_launcherd.h"
#include <QMap>
#include <QObject>
#include <mutex>
using DBbusLauncher = com::deepin::dde::daemon::Launcher;
/**
* @brief The LogApplicationHelper class 获取应用日志文件路径信息工具类
*/
class LogApplicationHelper : public QObject
{
Q_OBJECT
public:
/**
* @brief instance 全局单列模式实现
* @return 此类的唯一对象
*/
static LogApplicationHelper *instance()
{
LogApplicationHelper *sin = m_instance.load();
if (!sin) {
//加锁 线程安全
std::lock_guard<std::mutex> lock(m_mutex);
sin = m_instance.load();
if (!sin) {
sin = new LogApplicationHelper();
m_instance.store(sin);
}
}
return sin;
}
QMap<QString, QString> getMap();
QString transName(QString str);
private:
explicit LogApplicationHelper(QObject *parent = nullptr);
void init();
void createDesktopFiles();
void createLogFiles();
void parseField(QString path, QString name, bool isDeepin, bool isGeneric, bool isName);
QString getLogFile(QString path);
signals:
public slots:
private:
/**
* @brief m_en_log_map 应用包名-日志路径键值对
*/
QMap<QString, QString> m_en_log_map;
/**
* @brief m_en_trans_map 应用包名-应用显示文本键值对
*/
QMap<QString, QString> m_en_trans_map;
/**
* @brief m_trans_log_map 应用显示文本-日志路径键值对
*/
QMap<QString, QString> m_trans_log_map;
/**
* @brief m_desktop_files 所有符合条件的应用的desktop文件路径
*/
QStringList m_desktop_files;
/**
* @brief m_log_files 所有符合条件的应用的日志文件路径
*/
QStringList m_log_files;
/**
* @brief m_current_system_language 系统语言
*/
QString m_current_system_language;
/**
* @brief m_instance 单例用的本类指针的原子性封装
*/
static std::atomic<LogApplicationHelper *> m_instance;
/**
* @brief m_mutex 单例用的锁
*/
static std::mutex m_mutex;
/**
* @brief m_DbusLauncher 获取所有应用信息的dbus接口
*/
DBbusLauncher *m_DbusLauncher;
};
#endif // LOGAPPLICATIONHELPER_H
|