From 5f92935840bd0263b2e8c04b91976e202f030e2b Mon Sep 17 00:00:00 2001 From: keke <243768648@qq.com> Date: Tue, 3 May 2022 23:25:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=201=E3=80=81=E9=80=8F=E6=98=8E=E6=A8=A1?= =?UTF-8?q?=E7=B3=8A=E6=95=88=E6=9E=9C=E5=85=BC=E5=AE=B9=E9=9D=9Edeepin?= =?UTF-8?q?=E5=8F=91=E8=A1=8C=E7=89=88=E7=B3=BB=E7=BB=9F=EF=BC=9B2?= =?UTF-8?q?=E3=80=81=E4=BC=98=E5=8C=96=E5=8A=A0=E8=BD=BD=E9=80=9F=E5=BA=A6?= =?UTF-8?q?=E5=92=8C=E5=86=85=E5=AD=98=E5=8D=A0=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appmanagercommon.h | 6 + appmanagerjob.cpp | 80 +++--------- appmanagermodel.cpp | 83 +++++++++++- appmanagermodel.h | 2 + appmanagerwidget.cpp | 22 ++++ ccc-app-manager.pro | 3 +- ccc-app-manager.pro.user | 267 --------------------------------------- mainwindow.cpp | 41 ++++-- mainwindow.h | 2 + 9 files changed, 159 insertions(+), 347 deletions(-) delete mode 100644 ccc-app-manager.pro.user diff --git a/appmanagercommon.h b/appmanagercommon.h index f5b472b..8001b69 100644 --- a/appmanagercommon.h +++ b/appmanagercommon.h @@ -8,6 +8,10 @@ namespace AM { struct PkgInfo { + QString infosFilePath; // 包信息文件路径 + qint64 contentOffset; // 内容在包信息文件中的地址偏移 + qint64 contentSize; // 内容大小 + QString depositoryUrl; // 仓库地址 QString pkgName; int installedSize; QString updatedTime; @@ -22,6 +26,8 @@ struct PkgInfo { QStringList installedFileList; PkgInfo() { + contentOffset = 0; + contentSize = 0; installedSize = 0; pkgSize = 0; } diff --git a/appmanagerjob.cpp b/appmanagerjob.cpp index 71cd8b4..cbaafcf 100644 --- a/appmanagerjob.cpp +++ b/appmanagerjob.cpp @@ -169,7 +169,6 @@ void AppManagerJob::reloadAppInfos() reloadSourceUrlList(); - m_appInfosMap.clear(); QDir aptPkgInfoListDir("/var/lib/apt/lists"); const QStringList fileNameList = aptPkgInfoListDir.entryList(QDir::Filter::Files | QDir::Filter::NoDot | QDir::Filter::NoDotDot); for (const QString &fileName : fileNameList) { @@ -459,64 +458,31 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS } PkgInfo pkgInfo; - bool isReadingDescription = false; QTextStream txtStrem(&pkgInfosFile); - while (!txtStrem.atEnd()) { - QString lineTxt = txtStrem.readLine(); - if (lineTxt.startsWith("Package: ")) { - pkgInfo.pkgName = lineTxt.split(": ").last(); - continue; - } - if (lineTxt.startsWith("Installed-Size: ")) { - pkgInfo.installedSize = lineTxt.split(": ").last().toInt(); - continue; - } - if (lineTxt.startsWith("Maintainer: ")) { - pkgInfo.maintainer = lineTxt.split(": ").last(); - continue; - } - if (lineTxt.startsWith("Architecture: ")) { - pkgInfo.arch = lineTxt.split(": ").last(); - continue; - } - if (lineTxt.startsWith("Version: ")) { - pkgInfo.version = lineTxt.split(": ").last(); - continue; - } - if (lineTxt.startsWith("Depends: ")) { - pkgInfo.depends = lineTxt.split(": ").last(); - continue; - } - if (lineTxt.startsWith("Filename: ")) { - const QString downloadFileName = lineTxt.split(": ").last(); - pkgInfo.downloadUrl = QString("%1/%2").arg(depositoryUrlStr).arg(downloadFileName); - continue; - } - if (lineTxt.startsWith("Size: ")) { - pkgInfo.pkgSize = lineTxt.split(": ").last().toInt(); - continue; + bool isReadingFirstApp = true; + qint64 contentOffset = 0; + while (!pkgInfosFile.atEnd()) { + if (!isReadingFirstApp && 0 == pkgInfo.contentOffset) { + pkgInfo.contentOffset = contentOffset; } - if (lineTxt.startsWith("Description: ")) { - pkgInfo.description = lineTxt.split(": ").last(); - pkgInfo.description.append("\n"); - isReadingDescription = true; - continue; - } - if (lineTxt.startsWith("Homepage: ")) { - pkgInfo.homepage = lineTxt.split(": ").last(); - continue; - } + const QByteArray ba = pkgInfosFile.readLine(); + contentOffset += ba.size(); - if (lineTxt.startsWith(" ") && isReadingDescription) { - pkgInfo.description += lineTxt; + QString lineText = QString::fromUtf8(ba).remove("\n"); + if (lineText.startsWith("Package: ")) { + pkgInfo.pkgName = lineText.split(": ").last(); continue; } // 检测到下一包信息 - if (lineTxt.isEmpty()) { + if (lineText.isEmpty()) { + pkgInfo.infosFilePath = pkgInfosFilePath; + pkgInfo.depositoryUrl = depositoryUrlStr; + pkgInfo.contentSize = contentOffset - pkgInfo.contentOffset; pkgInfoList.append(pkgInfo); - isReadingDescription = false; + pkgInfo = {}; + isReadingFirstApp = false; } } pkgInfosFile.close(); @@ -530,7 +496,7 @@ void AppManagerJob::loadSrvAppInfosFromFile(QMap &appInfosMap, { QList pkgInfoList; getPkgInfoListFromFile(pkgInfoList, pkgInfosFilePath); - qInfo() << Q_FUNC_INFO << pkgInfoList.size(); + qInfo() << Q_FUNC_INFO << pkgInfosFilePath << pkgInfoList.size(); for (const PkgInfo &pkgInfo : pkgInfoList) { m_mutex.lock(); // appInfosMap为成员变量,加锁 @@ -552,14 +518,6 @@ void AppManagerJob::loadInstalledAppInfosFromFile(QMap &appInf appInfo->pkgName = pkgInfo.pkgName; appInfo->isInstalled = true; appInfo->installedPkgInfo = pkgInfo; - // 根据版本找到候选包中对应的包大小和下载地址 - for (const PkgInfo &srvPkgInfo : appInfo->pkgInfoList) { - if (appInfo->installedPkgInfo.version == srvPkgInfo.version) { - appInfo->installedPkgInfo.pkgSize = srvPkgInfo.pkgSize; - appInfo->installedPkgInfo.downloadUrl = srvPkgInfo.downloadUrl; - break; - } - } // 获取安装文件路径列表 appInfo->installedPkgInfo.installedFileList = getAppInstalledFileList(appInfo->installedPkgInfo.pkgName); @@ -567,6 +525,7 @@ void AppManagerJob::loadInstalledAppInfosFromFile(QMap &appInf appInfo->desktopInfo.desktopPath = getAppDesktopPath(appInfo->installedPkgInfo.installedFileList, appInfo->installedPkgInfo.pkgName); appInfo->desktopInfo = getDesktopInfo(appInfo->desktopInfo.desktopPath); + m_mutex.unlock(); // 解锁 } } @@ -577,7 +536,7 @@ QStringList AppManagerJob::getAppInstalledFileList(const QString &pkgName) QFile installedListFile(QString("/var/lib/dpkg/info/%1.list").arg(pkgName)); if (!installedListFile.open(QIODevice::OpenModeFlag::ReadOnly)) { - qDebug() << Q_FUNC_INFO << "open" << installedListFile.fileName() << "failed!"; + qInfo() << Q_FUNC_INFO << "open" << installedListFile.fileName() << "failed!"; return fileList; } @@ -586,7 +545,6 @@ QStringList AppManagerJob::getAppInstalledFileList(const QString &pkgName) fileList.append(txtStrem.readLine()); } installedListFile.close(); - sync(); return fileList; } diff --git a/appmanagermodel.cpp b/appmanagermodel.cpp index bb1cc1d..c15b535 100644 --- a/appmanagermodel.cpp +++ b/appmanagermodel.cpp @@ -5,6 +5,7 @@ #include #include #include +#include using namespace AM; @@ -123,6 +124,78 @@ QString AppManagerModel::getPkgBuildDirPath() const return m_appManagerJob->getPkgBuildDirPath(); } +bool AppManagerModel::extendPkgInfo(PkgInfo &pkgInfo) +{ + QFile pkgInfosFile(pkgInfo.infosFilePath); + + if (!pkgInfosFile.open(QIODevice::OpenModeFlag::ReadOnly)) { + qInfo() << Q_FUNC_INFO << "open" << pkgInfosFile.fileName() << "failed!"; + return false; + } + + pkgInfosFile.seek(pkgInfo.contentOffset); + QString content = pkgInfosFile.read(pkgInfo.contentSize); + pkgInfosFile.close(); + + QStringList infoLineList = content.split("\n"); + bool isReadingDescription = false; + for (const QString &infoLine : infoLineList) { + if (infoLine.startsWith("Package: ")) { + pkgInfo.pkgName = infoLine.split(": ").last(); + continue; + } + + if (infoLine.startsWith("Installed-Size: ")) { + pkgInfo.installedSize = infoLine.split(": ").last().toInt(); + continue; + } + if (infoLine.startsWith("Maintainer: ")) { + pkgInfo.maintainer = infoLine.split(": ").last(); + continue; + } + if (infoLine.startsWith("Architecture: ")) { + pkgInfo.arch = infoLine.split(": ").last(); + continue; + } + if (infoLine.startsWith("Version: ")) { + pkgInfo.version = infoLine.split(": ").last(); + continue; + } + if (infoLine.startsWith("Depends: ")) { + pkgInfo.depends = infoLine.split(": ").last(); + continue; + } + if (infoLine.startsWith("Filename: ")) { + const QString downloadFileName = infoLine.split(": ").last(); + pkgInfo.downloadUrl = QString("%1/%2").arg(pkgInfo.depositoryUrl).arg(downloadFileName); + continue; + } + if (infoLine.startsWith("Size: ")) { + pkgInfo.pkgSize = infoLine.split(": ").last().toInt(); + continue; + } + + if (infoLine.startsWith("Homepage: ")) { + pkgInfo.homepage = infoLine.split(": ").last(); + continue; + } + + + if (infoLine.startsWith("Description: ")) { + pkgInfo.description = infoLine.split(": ").last(); + pkgInfo.description.append("\n"); + isReadingDescription = true; + continue; + } + if (infoLine.startsWith(" ") && isReadingDescription) { + pkgInfo.description += infoLine; + continue; + } + } + + return true; +} + void AppManagerModel::initData() { // 注册结构体 @@ -162,12 +235,12 @@ void AppManagerModel::initConnection() }); connect(this, &AppManagerModel::notifyThreadUninstallPkg, m_appManagerJob, &AppManagerJob::uninstallPkg); - connect(m_appManagerJob, &AppManagerJob::uninstallPkgFinished, this, [this](const QString &pkgName) { + connect(m_appManagerJob, &AppManagerJob::uninstallPkgFinished, this, [](const QString &pkgName) { QProcess uninstnotify; - QString cmd = QString("notify-send ccc-app-manager \"\软件包 ")+pkgName+QString(" 已卸载\"\ "); - uninstnotify.start(cmd); - uninstnotify.waitForStarted(); - uninstnotify.waitForFinished(); + QString cmd = QString("notify-send ccc-app-manager \" 软件包 ")+ pkgName + QString(" 已卸载\" "); + uninstnotify.start(cmd); + uninstnotify.waitForStarted(); + uninstnotify.waitForFinished(); qInfo() << pkgName << "uninstalled"; }); diff --git a/appmanagermodel.h b/appmanagermodel.h index 3dec67d..15a3de2 100644 --- a/appmanagermodel.h +++ b/appmanagermodel.h @@ -33,6 +33,8 @@ public: void openSpkStoreAppDetailPage(const QString &pkgName); QString getDownloadDirPath() const; QString getPkgBuildDirPath() const; + // 拓展包信息 + bool extendPkgInfo(AM::PkgInfo &pkgInfo); Q_SIGNALS: void notifyThreadreloadAppInfos(); diff --git a/appmanagerwidget.cpp b/appmanagerwidget.cpp index 68c326e..a78f1cc 100644 --- a/appmanagerwidget.cpp +++ b/appmanagerwidget.cpp @@ -386,6 +386,28 @@ AppManagerWidget::~AppManagerWidget() void AppManagerWidget::showAppInfo(const AppInfo &info) { m_showingAppInfo = info; + + // 拓展已安装应用信息 + if (m_showingAppInfo.isInstalled) { + if (!m_model->extendPkgInfo(m_showingAppInfo.installedPkgInfo)) { + return; + } + } + + // 拓展仓库应用信息 + for (PkgInfo &srvPkgInfo : m_showingAppInfo.pkgInfoList) { + if (!m_model->extendPkgInfo(srvPkgInfo)) { + continue; + } + + // 根据版本找到候选包中对应的包大小和下载地址 + if (m_showingAppInfo.installedPkgInfo.version == srvPkgInfo.version) { + m_showingAppInfo.installedPkgInfo.pkgSize = srvPkgInfo.pkgSize; + m_showingAppInfo.installedPkgInfo.downloadUrl = srvPkgInfo.downloadUrl; + } + } + + m_model->setShowingAppInfo(m_showingAppInfo); const QString themeIconName = m_showingAppInfo.desktopInfo.themeIconName; diff --git a/ccc-app-manager.pro b/ccc-app-manager.pro index fa86262..92f834e 100644 --- a/ccc-app-manager.pro +++ b/ccc-app-manager.pro @@ -22,7 +22,8 @@ DEFINES += QT_DEPRECATED_WARNINGS # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -CONFIG += c++11 zlib +CONFIG += c++11 link_pkgconfig zlib +PKGCONFIG += gsettings-qt SOURCES += \ main.cpp \ diff --git a/ccc-app-manager.pro.user b/ccc-app-manager.pro.user deleted file mode 100644 index 5e313c2..0000000 --- a/ccc-app-manager.pro.user +++ /dev/null @@ -1,267 +0,0 @@ - - - - - - EnvironmentId - {e449a305-5aa8-4e93-ba50-fb0fb2456d52} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - false - true - false - 0 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - - 0 - true - - - - ProjectExplorer.Project.Target.0 - - Desktop - 桌面 - 桌面 - {1faf3a27-8017-40cf-a22f-a590b11a0980} - 0 - 0 - 0 - - 0 - /home/shenmo/Desktop/build-ccc-app-manager-unknown-Debug - /home/shenmo/Desktop/build-ccc-app-manager-unknown-Debug - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - /home/shenmo/Desktop/build-ccc-app-manager-unknown-Release - /home/shenmo/Desktop/build-ccc-app-manager-unknown-Release - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - /home/shenmo/Desktop/build-ccc-app-manager-unknown-Profile - /home/shenmo/Desktop/build-ccc-app-manager-unknown-Profile - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - true - - 2 - - ProjectExplorer.CustomExecutableRunConfiguration - - false - true - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/mainwindow.cpp b/mainwindow.cpp index ca9b281..d4e4fe1 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -5,35 +5,40 @@ #include #include #include +#include #include +#include MainWindow::MainWindow(QWidget *parent) : DMainWindow(parent) -// , m_centralWidgetBlurBg(nullptr) -// 在非dde下无法正常blur导致标题栏难以看清 + , m_centralWidgetBlurBg(nullptr) + , m_isDeepin(false) { setMinimumSize(1000, 600); // 设置背景 - setAttribute(Qt::WA_TranslucentBackground); setTitlebarShadowEnabled(false); setFocusPolicy(Qt::FocusPolicy::ClickFocus); titlebar()->setIcon(QIcon::fromTheme("chromium-app-list")); titlebar()->setTitle("应用管理器"); titlebar()->setFixedHeight(40); - titlebar()->setBackgroundTransparent(false);//透明就彻底啥也看不见了 + titlebar()->setBackgroundTransparent(true); -// m_centralWidgetBlurBg = new DBlurEffectWidget(this); -// m_centralWidgetBlurBg->setBlendMode(DBlurEffectWidget::BlendMode::BehindWindowBlend); -// m_centralWidgetBlurBg->setMaskAlpha(30); -// m_centralWidgetBlurBg->setFixedSize(size()); -// m_centralWidgetBlurBg->lower(); + m_centralWidgetBlurBg = new DBlurEffectWidget(this); + m_centralWidgetBlurBg->setBlendMode(DBlurEffectWidget::BlendMode::BehindWindowBlend); + m_centralWidgetBlurBg->setMaskAlpha(100); + m_centralWidgetBlurBg->setFixedSize(size()); + m_centralWidgetBlurBg->lower(); -// 透明+blur确实很好看,但是在非dde上是一场灾难。。。 + // 判断系统是否是deepin + m_isDeepin = DSysInfo::isDeepin(); DFrame *centralWidget = new DFrame(this); - centralWidget->setContentsMargins(3, 0, 3, 3); + QGSettings deepinSettings("com.deepin.xsettings"); + int dtkWindowRadius = deepinSettings.get("dtk-window-radius").toInt(); + int internalPix = dtkWindowRadius < 9 ? 0 : (dtkWindowRadius - 8) / 2; + centralWidget->setContentsMargins(4 + internalPix, 0, 4 + internalPix, 4 + internalPix); setCentralWidget(centralWidget); QHBoxLayout *mainLayout = new QHBoxLayout; @@ -42,6 +47,17 @@ MainWindow::MainWindow(QWidget *parent) AppManagerWidget *appManagerWidget = new AppManagerWidget(this); mainLayout->addWidget(appManagerWidget); + + // post init + if (m_isDeepin) { + setAttribute(Qt::WA_TranslucentBackground, true); + m_centralWidgetBlurBg->setVisible(true); + titlebar()->setBackgroundTransparent(true); + } else { + setAttribute(Qt::WA_TranslucentBackground, false); + m_centralWidgetBlurBg->setVisible(false); + titlebar()->setBackgroundTransparent(false); + } } MainWindow::~MainWindow() @@ -51,8 +67,7 @@ MainWindow::~MainWindow() void MainWindow::resizeEvent(QResizeEvent *event) { DMainWindow::resizeEvent(event); - -// m_centralWidgetBlurBg->setFixedSize(size()); + m_centralWidgetBlurBg->setFixedSize(size()); } void MainWindow::closeEvent(QCloseEvent *event) diff --git a/mainwindow.h b/mainwindow.h index d5e6c91..2193c20 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -7,6 +7,7 @@ class DBlurEffectWidget; DWIDGET_END_NAMESPACE DWIDGET_USE_NAMESPACE +DCORE_USE_NAMESPACE class MainWindow : public DMainWindow { @@ -22,4 +23,5 @@ protected: private: DBlurEffectWidget *m_barBlurBg; DBlurEffectWidget *m_centralWidgetBlurBg; + bool m_isDeepin; }; -- Gitee