diff --git a/deepin-system-monitor-main/gui/process_page_widget.cpp b/deepin-system-monitor-main/gui/process_page_widget.cpp index 5b713555..c282105b 100644 --- a/deepin-system-monitor-main/gui/process_page_widget.cpp +++ b/deepin-system-monitor-main/gui/process_page_widget.cpp @@ -289,7 +289,8 @@ void ProcessPageWidget::initConnections() // update process summary text when process summary info updated background auto *monitor = ThreadManager::instance()->thread(BaseThread::kSystemMonitorThread)->systemMonitorInstance(); - connect(monitor, &SystemMonitor::statInfoUpdated, this, &ProcessPageWidget::onStatInfoUpdated, Qt::DirectConnection); + // Note: do not update on non-GUI thread. + connect(monitor, &SystemMonitor::appAndProcCountUpdate, this, &ProcessPageWidget::onAppAndProcCountUpdated); auto *dAppHelper = DApplicationHelper::instance(); // change text color dynamically on theme type change, if not do this way, text color wont synchronize with theme type @@ -409,27 +410,10 @@ void ProcessPageWidget::createWindowKiller() &ProcessPageWidget::popupKillConfirmDialog); } -void ProcessPageWidget::onStatInfoUpdated() +void ProcessPageWidget::onAppAndProcCountUpdated(int appCount, int procCount) { - QApplication::processEvents(); const QString &buf = DApplication::translate("Process.Summary", kProcSummaryTemplateText); - - ProcessSet *processSet = ProcessDB::instance()->processSet(); - //记录所有进程数量 - const QList &newpidlst = processSet->getPIDList(); - m_iallProcNum = newpidlst.size(); - int appCount = 0; - for (const auto &pid : newpidlst) { - auto process = processSet->getProcessById(pid); - if (process.appType() == kFilterApps) - appCount++; - } - m_procViewModeSummary->setText(buf.arg(appCount).arg(m_iallProcNum)); - m_model = CPUInfoModel::instance(); - -// CPUPerformance = (m_model->cpuSet()->maxFreq() > CPU_FREQUENCY_STANDARD) ? High : Low; - //qInfo() << m_model->cpuSet()->maxFreq() << (m_model->cpuSet()->maxFreq() > CPU_FREQUENCY_STANDARD) << CPUPerformance; - + m_procViewModeSummary->setText(buf.arg(appCount).arg(procCount)); } // change icon theme when theme changed diff --git a/deepin-system-monitor-main/gui/process_page_widget.h b/deepin-system-monitor-main/gui/process_page_widget.h index 62d3ba19..c222b010 100644 --- a/deepin-system-monitor-main/gui/process_page_widget.h +++ b/deepin-system-monitor-main/gui/process_page_widget.h @@ -107,9 +107,9 @@ private Q_SLOTS: void changeIconTheme(DApplicationHelper::ColorType themeType); /** - * @brief 列表数据刷新 + * @brief 列表数据刷新,更新应用和进程统计 */ - void onStatInfoUpdated(); + void onAppAndProcCountUpdated(int appCount, int procCount); /** * @brief 详情页切换 diff --git a/deepin-system-monitor-main/system/system_monitor.cpp b/deepin-system-monitor-main/system/system_monitor.cpp index 658ddc90..d9f3bf1a 100644 --- a/deepin-system-monitor-main/system/system_monitor.cpp +++ b/deepin-system-monitor-main/system/system_monitor.cpp @@ -25,7 +25,6 @@ SystemMonitor::SystemMonitor(QObject *parent) , m_processDB(new ProcessDB(this)) { m_sysInfo->readSysInfoStatic(); - } SystemMonitor::~SystemMonitor() @@ -84,6 +83,7 @@ void SystemMonitor::timerEvent(QTimerEvent *event) m_processDB->update(); } else { emit statInfoUpdated(); + recountAppAndProcess(); } if(cnt++ >250) cnt = 0; @@ -97,6 +97,25 @@ void SystemMonitor::updateSystemMonitorInfo() m_processDB->update(); emit statInfoUpdated(); + recountAppAndProcess(); +} + +/** + @brief Count current apps and processes on SystemMonitor child thread. + */ +void SystemMonitor::recountAppAndProcess() +{ + ProcessSet *processSet = m_processDB->processSet(); + // count all app + const QList &newpidlst = processSet->getPIDList(); + int appCount = 0; + for (const auto &pid : newpidlst) { + auto process = processSet->getProcessById(pid); + if (process.appType() == kFilterApps) + appCount++; + } + + emit appAndProcCountUpdate(appCount, newpidlst.size()); } } // namespace system diff --git a/deepin-system-monitor-main/system/system_monitor.h b/deepin-system-monitor-main/system/system_monitor.h index ff5121d0..c44b4e38 100644 --- a/deepin-system-monitor-main/system/system_monitor.h +++ b/deepin-system-monitor-main/system/system_monitor.h @@ -30,6 +30,7 @@ class SystemMonitor : public QObject signals: void statInfoUpdated(); + void appAndProcCountUpdate(int appCount, int procCount); public: explicit SystemMonitor(QObject *parent = nullptr); @@ -48,6 +49,7 @@ class SystemMonitor : public QObject private: void updateSystemMonitorInfo(); + void recountAppAndProcess(); private: SysInfo *m_sysInfo;