deepin sysbro 源码阅读笔记

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32768743/article/details/88815557

项目地址:https://github.com/rekols/sysbro
还在开发中,所以以后可能会变。
阅读时间是2019年03月26日
在这里插入图片描述

  • 开机自启动管理
    在这里插入图片描述
    实现是读文件夹下~/.config/autostart/所有文件
m_autoStartPath(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation).append("/autostart/"))
  • 网络测速
    在这里插入图片描述
    在这里插入图片描述
    我没等这个框停
    直接下载一个大文件
http://dlied6.qq.com/invc/xfspeed/qqpcmgr/download/Test216MB.dat

在这里插入图片描述

  • 文件粉碎机
    在这里插入图片描述
    在这里插入图片描述
    我点击粉碎文件,没啥反应
    看代码
void FileModel::removeAllFiles()
{
    if (m_filePaths.isEmpty())
        return;

    int count = m_filePaths.count();

    QProcess *process = new QProcess;
    bool failed = false;
    process->start("pkexec", QStringList() << "sysbro-delete-files" << m_filePaths);
    process->waitForFinished(-1);
    failed |= process->exitCode();
    process->deleteLater();

    if (!failed) {
        removeAllItems();

        emit removeAllFilesFinished(count);
    }
}

调用了sysbro-delete-files
然后看了实现
调用Qt的API删除的,没太懂文件粉碎的意思,以前在Windows没怎么用过这个功能.

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    QCommandLineParser parser;
    parser.process(app);

    const QStringList fileList = parser.positionalArguments();

    for (const QString file : fileList) {
        QFileInfo fileInfo(file);

        if (fileInfo.isDir()) {
            QDir(file).removeRecursively();
        } else {
            QFile openFile(file);

            if (openFile.remove()) {
                std::cout << "finished" << std::endl;
            } else {
                std::cout << "error" << std::endl;
            }
        }
    }

    return 0;
}
  • 快递查询
    在这里插入图片描述
    调的是一个API
http://api.kuaidi100.com/api
  • 主页面
    在这里插入图片描述
    | 项 | 实现 | 备注 |
    | ---- | -------------------------------- | ------ |
    | cpu | 读/proc/stat | |
    | 内存 | 读/proc/meminfo | |
    | 磁盘 | QStorageInfo::mountedVolumes() | Qt API |
    | 网络 | 读/proc/net/dev | |

系统信息部分

    m_platform->setText(tr("Platform: %1").arg(Utils::getPlatform()));
    m_distribution->setText(tr("Distribution: %1").arg(Utils::getDistribution()));
    m_bootTime->setText(tr("Startup time: %1").arg(Utils::getBootTime()));
    m_kernel->setText(tr("Kernal Release: %1").arg(Utils::getKernel()));
    m_cpuModel->setText(tr("CPU Model: %1").arg(strCpuModel));
    m_cpuCoreCount->setText(tr("CPU Core: %1").arg(strCpuCore));

其他的截图吧
在这里插入图片描述
还剩清理和开机启动服务的实现,下午再看吧

  • Cleaner
    在这里插入图片描述
    这个的实现,还是扫文件
void ScannedWidget::scan()
{
    m_totalSize = 0;
    m_treeWidget->clear();

    // addRoot(TRASH, "Trash", { QFileInfo(QString("%1/.local/share/Trash/").arg(Utils::getHomePath())) }, true);
    addRoot(APPLICATION_CACHES, tr("Application Caches"), Utils::getAppCaches());
    addRoot(APPLICATION_LOGS, tr("Application Log"), Utils::getAppLogs());
    addRoot(CRASH_REPORTS, tr("Crash Reports"), Utils::getCrashReports());
    addRoot(PACKAGE_CACHE, tr("Package Caches"), Utils::getDpkgPackages());

    QFileInfo bashShellHistory(QDir::homePath() + "/.bash_history");
    if (bashShellHistory.exists()) {
        addRoot(BASHSHELL_HISTORY, tr("Shell Terminal History"), { bashShellHistory });
    }

    m_treeWidget->update();

    emit scanFinished(m_totalSize);
}

具体的文件位置
在这里插入图片描述

  • Speed up
    在这里插入图片描述
    这个的实现核心是这个命令
systemctl list-unit-files -t service -a --state=enabled,disabled

在这里插入图片描述
启动服务或者停止服务
用的用命令

systemctl enable 服务名
systemctl disable 服务名
  • Tools
    在这里插入图片描述
    这个没啥好说的,前面已经写了具体的实现

猜你喜欢

转载自blog.csdn.net/qq_32768743/article/details/88815557