修改排序优先级
This commit is contained in:
parent
95406ad135
commit
c51e78b505
|
@ -59,7 +59,7 @@ Q_SIGNALS:
|
||||||
void pluginChanged(const QString &id, PluginGroup::Group group);
|
void pluginChanged(const QString &id, PluginGroup::Group group);
|
||||||
void dataChanged(QVector<DataEntity> data, DataUpdateMode::Mode mode, quint32 index);
|
void dataChanged(QVector<DataEntity> data, DataUpdateMode::Mode mode, quint32 index);
|
||||||
void labelChanged();
|
void labelChanged();
|
||||||
void toUpdate();
|
void toUpdate(bool isShowed);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DataProviderManager();
|
DataProviderManager();
|
||||||
|
|
|
@ -80,7 +80,7 @@ public:
|
||||||
virtual void forceUpdate(QString &key) {};
|
virtual void forceUpdate(QString &key) {};
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
virtual void update() {};
|
virtual void update(bool isShowed) {};
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -83,21 +83,33 @@ void AllAppDataProvider::forceUpdate()
|
||||||
sendData();
|
sendData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AllAppDataProvider::update()
|
void AllAppDataProvider::update(bool isShowed)
|
||||||
{
|
{
|
||||||
bool isRecentDataChanged = false;
|
m_windowStatus = isShowed;
|
||||||
{
|
if (isShowed) {
|
||||||
QMutexLocker locker(&m_mutex);
|
m_timer->blockSignals(true);
|
||||||
for (DataEntity & appdata : m_appData) {
|
bool isRecentDataChanged = false;
|
||||||
bool info = appdata.isRecentInstall();
|
{
|
||||||
setRecentState(appdata);
|
QMutexLocker locker(&m_mutex);
|
||||||
if (appdata.isRecentInstall() != info) {
|
for (DataEntity &appdata : m_appData) {
|
||||||
isRecentDataChanged = true;
|
bool info = appdata.isRecentInstall();
|
||||||
|
setRecentState(appdata);
|
||||||
|
if (appdata.isRecentInstall() != info) {
|
||||||
|
isRecentDataChanged = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (isRecentDataChanged) {
|
||||||
if (isRecentDataChanged) {
|
std::sort(m_appData.begin(), m_appData.end(), appDataSort);
|
||||||
sendData();
|
sendData();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
m_timer->blockSignals(false);
|
||||||
|
if (m_updateStatus) {
|
||||||
|
reloadAppData();
|
||||||
|
m_updateStatus = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,11 +129,13 @@ void AllAppDataProvider::reloadAppData()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
setRecentState(app);
|
setRecentState(app);
|
||||||
|
setSortPriority(app);
|
||||||
appData.append(app);
|
appData.append(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(appData.begin(), appData.end(), appDataSort);
|
std::sort(appData.begin(), appData.end(), appDataSort);
|
||||||
m_appData.swap(appData);
|
m_appData.swap(appData);
|
||||||
|
updateTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AllAppDataProvider::reloadFolderData()
|
void AllAppDataProvider::reloadFolderData()
|
||||||
|
@ -163,6 +177,7 @@ void AllAppDataProvider::updateData(const QList<DataEntity> &apps)
|
||||||
if (appdata.id() == app.id()) {
|
if (appdata.id() == app.id()) {
|
||||||
appdata = app;
|
appdata = app;
|
||||||
setRecentState(appdata);
|
setRecentState(appdata);
|
||||||
|
setSortPriority(appdata);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,6 +201,22 @@ void AllAppDataProvider::updateFolderData(QStringList &idList)
|
||||||
AppFolderHelper::instance()->forceSync();
|
AppFolderHelper::instance()->forceSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AllAppDataProvider::updateTimer()
|
||||||
|
{
|
||||||
|
if (m_timer == nullptr) {
|
||||||
|
m_timer = new QTimer(this);
|
||||||
|
m_timer->setInterval(3600000*48);
|
||||||
|
connect(m_timer, &QTimer::timeout, this, [this]{
|
||||||
|
if (m_windowStatus) {
|
||||||
|
m_updateStatus = true;
|
||||||
|
} else {
|
||||||
|
reloadAppData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
m_timer->start();
|
||||||
|
}
|
||||||
|
|
||||||
bool AllAppDataProvider::appDataSort(const DataEntity &a, const DataEntity &b)
|
bool AllAppDataProvider::appDataSort(const DataEntity &a, const DataEntity &b)
|
||||||
{
|
{
|
||||||
if ((a.top() != 0) && (b.top() != 0)) {
|
if ((a.top() != 0) && (b.top() != 0)) {
|
||||||
|
@ -206,10 +237,10 @@ bool AllAppDataProvider::appDataSort(const DataEntity &a, const DataEntity &b)
|
||||||
} else if (b.isRecentInstall()) {
|
} else if (b.isRecentInstall()) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (a.launchTimes() == b.launchTimes()) {
|
if (a.priority() == b.priority()) {
|
||||||
return letterSort(a.firstLetter(), b.firstLetter());
|
return letterSort(a.firstLetter(), b.firstLetter());
|
||||||
} else {
|
} else {
|
||||||
return a.launchTimes() > b.launchTimes();
|
return a.priority() > b.priority();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -217,13 +248,32 @@ bool AllAppDataProvider::appDataSort(const DataEntity &a, const DataEntity &b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AllAppDataProvider::setSortPriority(DataEntity &app)
|
||||||
|
{
|
||||||
|
QDateTime installTime = QDateTime::fromString(app.insertTime(), "yyyy-MM-dd hh:mm:ss");
|
||||||
|
if (installTime.isValid()) {
|
||||||
|
qint64 appTime = installTime.secsTo(QDateTime::currentDateTime());
|
||||||
|
if (appTime <= 3600*240) {
|
||||||
|
appTime = appTime / (3600*24);
|
||||||
|
double priority = app.launchTimes() * (-0.4 * (appTime^2) + 100);
|
||||||
|
app.setPriority(priority);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
appTime = appTime / (3600*24);
|
||||||
|
double priority = app.launchTimes() * (240 / (appTime - 6));
|
||||||
|
app.setPriority(priority);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AllAppDataProvider::setRecentState(DataEntity &app)
|
void AllAppDataProvider::setRecentState(DataEntity &app)
|
||||||
{
|
{
|
||||||
if (!UserConfig::instance()->isPreInstalledApps(app.id())) {
|
if (!UserConfig::instance()->isPreInstalledApps(app.id())) {
|
||||||
if (app.launched() == 0) {
|
if (app.launched() == 0) {
|
||||||
QDateTime installTime = QDateTime::fromString(app.insertTime(), "yyyy-MM-dd hh:mm:ss");
|
QDateTime installTime = QDateTime::fromString(app.insertTime(), "yyyy-MM-dd hh:mm:ss");
|
||||||
if (installTime.isValid()) {
|
if (installTime.isValid()) {
|
||||||
int appTime = installTime.secsTo(QDateTime::currentDateTime());
|
qint64 appTime = installTime.secsTo(QDateTime::currentDateTime());
|
||||||
if ((appTime >= 0 ) && (appTime <= 3600*48)) {
|
if ((appTime >= 0 ) && (appTime <= 3600*48)) {
|
||||||
app.setRecentInstall(true);
|
app.setRecentInstall(true);
|
||||||
return;
|
return;
|
||||||
|
@ -260,6 +310,7 @@ void AllAppDataProvider::onAppAdded(const QList<DataEntity>& apps)
|
||||||
QMutexLocker locker(&m_mutex);
|
QMutexLocker locker(&m_mutex);
|
||||||
for (auto app : apps) {
|
for (auto app : apps) {
|
||||||
setRecentState(app);
|
setRecentState(app);
|
||||||
|
setSortPriority(app);
|
||||||
m_appData.append(app);
|
m_appData.append(app);
|
||||||
}
|
}
|
||||||
std::sort(m_appData.begin(), m_appData.end(), appDataSort);
|
std::sort(m_appData.begin(), m_appData.end(), appDataSort);
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "data-provider-plugin-iface.h"
|
#include "data-provider-plugin-iface.h"
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
namespace UkuiMenu {
|
namespace UkuiMenu {
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ public:
|
||||||
void forceUpdate() override;
|
void forceUpdate() override;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void update() override;
|
void update(bool isShowed) override;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onAppAdded(const QList<DataEntity>& apps);
|
void onAppAdded(const QList<DataEntity>& apps);
|
||||||
|
@ -57,14 +58,19 @@ private:
|
||||||
void mergeData(QVector<DataEntity> &data);
|
void mergeData(QVector<DataEntity> &data);
|
||||||
void updateData(const QList<DataEntity>& apps);
|
void updateData(const QList<DataEntity>& apps);
|
||||||
void updateFolderData(QStringList& idList);
|
void updateFolderData(QStringList& idList);
|
||||||
|
void updateTimer();
|
||||||
static bool appDataSort(const DataEntity &a, const DataEntity &b);
|
static bool appDataSort(const DataEntity &a, const DataEntity &b);
|
||||||
|
static void setSortPriority(DataEntity &app);
|
||||||
static void setRecentState(DataEntity &app);
|
static void setRecentState(DataEntity &app);
|
||||||
static bool letterSort(const QString &a, const QString &b);
|
static bool letterSort(const QString &a, const QString &b);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QTimer *m_timer = nullptr;
|
||||||
QMutex m_mutex;
|
QMutex m_mutex;
|
||||||
QVector<DataEntity> m_appData;
|
QVector<DataEntity> m_appData;
|
||||||
QVector<DataEntity> m_folderData;
|
QVector<DataEntity> m_folderData;
|
||||||
|
bool m_updateStatus = false;
|
||||||
|
bool m_windowStatus = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // UkuiMenu
|
} // UkuiMenu
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
int top{0}; // 置顶状态及序号
|
int top{0}; // 置顶状态及序号
|
||||||
int favorite{0}; // 收藏状态及序号
|
int favorite{0}; // 收藏状态及序号
|
||||||
int launchTimes{0}; // 启动次数
|
int launchTimes{0}; // 启动次数
|
||||||
|
double priority{0};
|
||||||
DataType::Type type {DataType::Normal};
|
DataType::Type type {DataType::Normal};
|
||||||
QString id; // 应用可执行文件路径
|
QString id; // 应用可执行文件路径
|
||||||
QString icon;
|
QString icon;
|
||||||
|
@ -112,6 +113,16 @@ void DataEntity::setLaunchTimes(int launchTimes)
|
||||||
d->launchTimes = launchTimes;
|
d->launchTimes = launchTimes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double DataEntity::priority() const
|
||||||
|
{
|
||||||
|
return d->priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataEntity::setPriority(double priority)
|
||||||
|
{
|
||||||
|
d->priority = priority;
|
||||||
|
}
|
||||||
|
|
||||||
QString DataEntity::insertTime() const
|
QString DataEntity::insertTime() const
|
||||||
{
|
{
|
||||||
return d->insertTime;
|
return d->insertTime;
|
||||||
|
|
|
@ -89,6 +89,9 @@ public:
|
||||||
int launchTimes() const;
|
int launchTimes() const;
|
||||||
void setLaunchTimes(int launchTimes);
|
void setLaunchTimes(int launchTimes);
|
||||||
|
|
||||||
|
double priority() const;
|
||||||
|
void setPriority(double priority);
|
||||||
|
|
||||||
QString insertTime() const;
|
QString insertTime() const;
|
||||||
void setInsertTime(const QString& insertTime);
|
void setInsertTime(const QString& insertTime);
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,14 @@ void UkuiMenuApplication::loadMenuUI()
|
||||||
const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
|
const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
|
||||||
m_mainWindow = new MenuWindow(m_engine, nullptr);
|
m_mainWindow = new MenuWindow(m_engine, nullptr);
|
||||||
m_mainWindow->setSource(url);
|
m_mainWindow->setSource(url);
|
||||||
|
connect(m_mainWindow, &QQuickView::activeFocusItemChanged, m_mainWindow, [this] {
|
||||||
|
if (m_mainWindow->activeFocusItem()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
execCommand(Hide);
|
||||||
|
DataProviderManager::instance()->toUpdate(false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiMenuApplication::initDbusService()
|
void UkuiMenuApplication::initDbusService()
|
||||||
|
@ -136,16 +144,12 @@ void UkuiMenuApplication::execCommand(Command command)
|
||||||
case Active: {
|
case Active: {
|
||||||
if (m_mainWindow) {
|
if (m_mainWindow) {
|
||||||
m_mainWindow->setVisible(!m_mainWindow->isVisible());
|
m_mainWindow->setVisible(!m_mainWindow->isVisible());
|
||||||
if (m_mainWindow->isVisible()) {
|
|
||||||
DataProviderManager::instance()->toUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Show: {
|
case Show: {
|
||||||
if (m_mainWindow) {
|
if (m_mainWindow) {
|
||||||
m_mainWindow->setVisible(true);
|
m_mainWindow->setVisible(true);
|
||||||
DataProviderManager::instance()->toUpdate();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -166,6 +170,8 @@ void UkuiMenuApplication::execCommand(Command command)
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
bool isShowed = m_mainWindow->isVisible();
|
||||||
|
DataProviderManager::instance()->toUpdate(isShowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
UkuiMenuApplication::~UkuiMenuApplication()
|
UkuiMenuApplication::~UkuiMenuApplication()
|
||||||
|
|
|
@ -399,7 +399,6 @@ void MenuWindow::init()
|
||||||
|
|
||||||
// 访问窗口api
|
// 访问窗口api
|
||||||
rootContext()->setContextProperty("mainWindow", this);
|
rootContext()->setContextProperty("mainWindow", this);
|
||||||
connect(this, &QQuickView::activeFocusItemChanged, this, &MenuWindow::onActiveFocusItemChanged);
|
|
||||||
|
|
||||||
connect(m_geometryHelper, &WindowGeometryHelper::geometryChanged, this, [this] {
|
connect(m_geometryHelper, &WindowGeometryHelper::geometryChanged, this, [this] {
|
||||||
QEvent event(QEvent::Move);
|
QEvent event(QEvent::Move);
|
||||||
|
@ -526,15 +525,6 @@ void MenuWindow::showEvent(QShowEvent *event)
|
||||||
QQuickView::showEvent(event);
|
QQuickView::showEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuWindow::onActiveFocusItemChanged()
|
|
||||||
{
|
|
||||||
if (activeFocusItem()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MenuWindow::effectEnabled() const
|
bool MenuWindow::effectEnabled() const
|
||||||
{
|
{
|
||||||
return GlobalSetting::instance()->get(GlobalSetting::EffectEnabled).toBool();
|
return GlobalSetting::instance()->get(GlobalSetting::EffectEnabled).toBool();
|
||||||
|
|
|
@ -133,9 +133,6 @@ Q_SIGNALS:
|
||||||
void beforeFullScreenExited();
|
void beforeFullScreenExited();
|
||||||
void panelPosChanged();
|
void panelPosChanged();
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void onActiveFocusItemChanged();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void exposeEvent(QExposeEvent *event) override;
|
void exposeEvent(QExposeEvent *event) override;
|
||||||
void focusOutEvent(QFocusEvent *event) override;
|
void focusOutEvent(QFocusEvent *event) override;
|
||||||
|
|
Loading…
Reference in New Issue