添加应用最近安装功能
This commit is contained in:
parent
0c317e9a41
commit
24ca01368f
|
@ -33,7 +33,7 @@ MouseArea {
|
|||
|
||||
Loader {
|
||||
id: tag
|
||||
property bool recentInsatlled: false
|
||||
property bool recentInsatlled: (recentInstall === undefined) ? false : recentInstall
|
||||
property bool fixToTop: (toTop !== undefined) && (toTop !== 0)
|
||||
visible: fixToTop || recentInsatlled
|
||||
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
||||
|
|
|
@ -46,6 +46,7 @@ Item {
|
|||
property string name: model.name
|
||||
property string icon: model.icon
|
||||
property int toTop: model.top
|
||||
property bool recentInstall: model.recentInstall
|
||||
sourceComponent: {
|
||||
if (type === DataType.Normal) {
|
||||
return appItem;
|
||||
|
@ -72,6 +73,9 @@ Item {
|
|||
}
|
||||
if (mouse.button === Qt.LeftButton) {
|
||||
appManager.launchApp(id);
|
||||
if (recentInstall) {
|
||||
appManager.appLaunched(id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ public Q_SLOTS:
|
|||
void fixToFavoriteSlot(const QString &path, const int &num);
|
||||
void changedFavoriteOrderSlot(const QString &path, const int &num);
|
||||
void fixToTopSlot(const QString &path, const int &num);
|
||||
void setAppLaunched(const QString &path);
|
||||
|
||||
private:
|
||||
void updateFavoriteApps();
|
||||
|
@ -93,8 +94,11 @@ void AppDataWorker::initAppData()
|
|||
<< UkuiSearch::ApplicationProperty::Property::LocalName
|
||||
<< UkuiSearch::ApplicationProperty::Property::Category
|
||||
<< UkuiSearch::ApplicationProperty::Property::FirstLetterAll
|
||||
<< UkuiSearch::ApplicationProperty::Property::DontDisplay;
|
||||
<< UkuiSearch::ApplicationProperty::Property::DontDisplay
|
||||
<< UkuiSearch::ApplicationProperty::Property::InsertTime
|
||||
<< UkuiSearch::ApplicationProperty::Property::Launched;
|
||||
m_appPropertyMap.insert(UkuiSearch::ApplicationProperty::Property::DontDisplay, 0);
|
||||
m_appPropertyMap.insert(UkuiSearch::ApplicationProperty::Property::AutoStart, 0);
|
||||
|
||||
UkuiSearch::ApplicationInfoMap appInfos = m_applicationInfo->getInfo(m_appProperties, m_appPropertyMap);
|
||||
|
||||
|
@ -172,6 +176,8 @@ void AppDataWorker::addInfoToApp(const UkuiSearch::ApplicationPropertyMap &info,
|
|||
app.setName(info.value(UkuiSearch::ApplicationProperty::Property::LocalName).toString());
|
||||
app.setCategory(info.value(UkuiSearch::ApplicationProperty::Property::Category).toString());
|
||||
app.setFirstLetter(info.value(UkuiSearch::ApplicationProperty::Property::FirstLetterAll).toString());
|
||||
app.setInsertTime(info.value(UkuiSearch::ApplicationProperty::Property::InsertTime).toString());
|
||||
app.setLaunched(info.value(UkuiSearch::ApplicationProperty::Property::Launched).toInt());
|
||||
}
|
||||
|
||||
void AppDataWorker::onAppUpdated(const UkuiSearch::ApplicationInfoMap &infos)
|
||||
|
@ -239,6 +245,12 @@ void AppDataWorker::updateApps(const UkuiSearch::ApplicationInfoMap &infos, QLis
|
|||
case UkuiSearch::ApplicationProperty::Property::FirstLetterAll:
|
||||
app.setFirstLetter(infos.value(info).value(UkuiSearch::ApplicationProperty::Property::FirstLetterAll).toString());
|
||||
break;
|
||||
case UkuiSearch::ApplicationProperty::Property::InsertTime:
|
||||
app.setInsertTime(infos.value(info).value(UkuiSearch::ApplicationProperty::Property::InsertTime).toString());
|
||||
break;
|
||||
case UkuiSearch::ApplicationProperty::Property::Launched:
|
||||
app.setLaunched(infos.value(info).value(UkuiSearch::ApplicationProperty::Property::Launched).toInt());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -297,6 +309,11 @@ void AppDataWorker::fixToTopSlot(const QString &path, const int &num)
|
|||
}
|
||||
}
|
||||
|
||||
void AppDataWorker::setAppLaunched(const QString &path)
|
||||
{
|
||||
m_applicationInfo->setAppLaunchedState(path);
|
||||
}
|
||||
|
||||
void AppDataWorker::removeApps(QStringList &appIdList, QStringList &removedIdList)
|
||||
{
|
||||
QMutexLocker locker(&m_appManager->m_mutex);
|
||||
|
@ -328,6 +345,7 @@ AppDataManager::AppDataManager()
|
|||
connect(this, &AppDataManager::fixToFavoriteSignal, appDataWorker, &AppDataWorker::fixToFavoriteSlot);
|
||||
connect(this, &AppDataManager::changedFavoriteOrderSignal, appDataWorker, &AppDataWorker::changedFavoriteOrderSlot);
|
||||
connect(this, &AppDataManager::fixToTop, appDataWorker, &AppDataWorker::fixToTopSlot);
|
||||
connect(this, &AppDataManager::appLaunch, appDataWorker, &AppDataWorker::setAppLaunched);
|
||||
|
||||
m_workerThread.start();
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ Q_SIGNALS:
|
|||
void fixToFavoriteSignal(const QString &path, const int &num);
|
||||
void changedFavoriteOrderSignal(const QString &path, const int &num);
|
||||
void fixToTop(const QString &path, const int &num);
|
||||
void appLaunch(const QString &path);
|
||||
|
||||
private:
|
||||
AppDataManager();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "app-folder-helper.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
|
||||
namespace UkuiMenu {
|
||||
|
||||
|
@ -92,23 +93,15 @@ void AllAppDataProvider::reloadAppData()
|
|||
return;
|
||||
}
|
||||
|
||||
for (const auto &app : apps) {
|
||||
for (auto &app : apps) {
|
||||
if (AppFolderHelper::instance()->containApp(app.id())) {
|
||||
continue;
|
||||
}
|
||||
setRecentState(app);
|
||||
appData.append(app);
|
||||
}
|
||||
|
||||
std::sort(appData.begin(), appData.end(), [](const DataEntity &a, const DataEntity &b) {
|
||||
if (a.top() == 0) {
|
||||
return (a.top() == b.top()) ? (a.launchTimes() > b.launchTimes()) : (a.top() > b.top());
|
||||
} else if (b.top() == 0) {
|
||||
return a.top() > b.top();
|
||||
} else {
|
||||
return a.top() < b.top();
|
||||
}
|
||||
});
|
||||
|
||||
std::sort(appData.begin(), appData.end(), appDataSort);
|
||||
m_appData.swap(appData);
|
||||
}
|
||||
|
||||
|
@ -143,6 +136,43 @@ void AllAppDataProvider::mergeData(QVector<DataEntity> &data)
|
|||
data.append(m_appData);
|
||||
}
|
||||
|
||||
bool AllAppDataProvider::appDataSort(const DataEntity &a, const DataEntity &b)
|
||||
{
|
||||
if ((a.top() != 0) && (b.top() != 0)) {
|
||||
return a.top() < b.top();
|
||||
} else if ((a.top() == 0) && (b.top() == 0)) {
|
||||
if (a.isRecentInstall()) {
|
||||
if (b.isRecentInstall()) {
|
||||
return QDateTime::fromString(a.insertTime(), "yyyy-MM-dd hh:mm:ss")
|
||||
> QDateTime::fromString(b.insertTime(), "yyyy-MM-dd hh:mm:ss");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else if (b.isRecentInstall()) {
|
||||
return false;
|
||||
} else {
|
||||
return a.launchTimes() > b.launchTimes();
|
||||
}
|
||||
} else {
|
||||
return a.top() > b.top();
|
||||
}
|
||||
}
|
||||
|
||||
void AllAppDataProvider::setRecentState(DataEntity &app)
|
||||
{
|
||||
if (app.launched() == 0) {
|
||||
QDateTime installTime = QDateTime::fromString(app.insertTime(), "yyyy-MM-dd hh:mm:ss");
|
||||
if (installTime.isValid()) {
|
||||
int appTime = installTime.secsTo(QDateTime::currentDateTime());
|
||||
if ((appTime >= 0 ) && (appTime <= 3600*48)) {
|
||||
app.setRecentInstall(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
app.setRecentInstall(false);
|
||||
}
|
||||
|
||||
void AllAppDataProvider::sendData()
|
||||
{
|
||||
QVector<DataEntity> data;
|
||||
|
@ -159,7 +189,11 @@ void AllAppDataProvider::onAppAdded(const QList<DataEntity>& apps)
|
|||
{
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
m_appData.append(apps.toVector());
|
||||
for (auto app : apps) {
|
||||
setRecentState(app);
|
||||
m_appData.append(app);
|
||||
}
|
||||
std::sort(m_appData.begin(), m_appData.end(), appDataSort);
|
||||
}
|
||||
sendData();
|
||||
}
|
||||
|
@ -167,6 +201,7 @@ void AllAppDataProvider::onAppAdded(const QList<DataEntity>& apps)
|
|||
void AllAppDataProvider::onAppDeleted(QStringList idList)
|
||||
{
|
||||
removeApps(idList);
|
||||
reloadFolderData();
|
||||
sendData();
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ private:
|
|||
void reloadAppData();
|
||||
void reloadFolderData();
|
||||
void mergeData(QVector<DataEntity> &data);
|
||||
static bool appDataSort(const DataEntity &a, const DataEntity &b);
|
||||
static void setRecentState(DataEntity &app);
|
||||
|
||||
private:
|
||||
QMutex m_mutex;
|
||||
|
|
|
@ -28,6 +28,8 @@ public:
|
|||
: type(type), name(std::move(name)), icon(std::move(icon)), comment(std::move(comment)), extraData(std::move(extraData)) {}
|
||||
|
||||
bool lock{false}; // 应用锁定
|
||||
bool recentInstall{false};
|
||||
int launched{0}; // 是否启动过
|
||||
int top{0}; // 置顶状态及序号
|
||||
int favorite{0}; // 收藏状态及序号
|
||||
int launchTimes{0}; // 启动次数
|
||||
|
@ -39,6 +41,7 @@ public:
|
|||
QString firstLetter;
|
||||
QString comment; // 应用描述
|
||||
QString extraData; // 额外的数据
|
||||
QString insertTime; //安装的时间
|
||||
};
|
||||
|
||||
DataEntity::DataEntity() : d(new DataEntityPrivate) {}
|
||||
|
@ -69,6 +72,26 @@ void DataEntity::setLock(bool lock)
|
|||
d->lock = lock;
|
||||
}
|
||||
|
||||
bool DataEntity::isRecentInstall() const
|
||||
{
|
||||
return d->recentInstall;
|
||||
}
|
||||
|
||||
void DataEntity::setRecentInstall(bool recentInsatll)
|
||||
{
|
||||
d->recentInstall = recentInsatll;
|
||||
}
|
||||
|
||||
int DataEntity::launched() const
|
||||
{
|
||||
return d->launched;
|
||||
}
|
||||
|
||||
void DataEntity::setLaunched(int launched)
|
||||
{
|
||||
d->launched = launched;
|
||||
}
|
||||
|
||||
int DataEntity::favorite() const
|
||||
{
|
||||
return d->favorite;
|
||||
|
@ -89,6 +112,16 @@ void DataEntity::setLaunchTimes(int launchTimes)
|
|||
d->launchTimes = launchTimes;
|
||||
}
|
||||
|
||||
QString DataEntity::insertTime() const
|
||||
{
|
||||
return d->insertTime;
|
||||
}
|
||||
|
||||
void DataEntity::setInsertTime(const QString &insertTime)
|
||||
{
|
||||
d->insertTime = insertTime;
|
||||
}
|
||||
|
||||
QString DataEntity::id() const
|
||||
{
|
||||
return d->id;
|
||||
|
@ -179,6 +212,7 @@ QHash<int, QByteArray> DataEntity::AppRoleNames()
|
|||
names.insert(DataEntity::Comment, "comment");
|
||||
names.insert(DataEntity::ExtraData, "extraData");
|
||||
names.insert(DataEntity::Top, "top");
|
||||
names.insert(DataEntity::RecentInstall, "recentInstall");
|
||||
return names;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,8 @@ public:
|
|||
Name,
|
||||
Comment,
|
||||
ExtraData,
|
||||
Top
|
||||
Top,
|
||||
RecentInstall
|
||||
};
|
||||
DataEntity();
|
||||
DataEntity(DataType::Type type, const QString& name, const QString& icon, const QString& comment, const QString& extraData);
|
||||
|
@ -76,12 +77,21 @@ public:
|
|||
bool isLock() const;
|
||||
void setLock(bool lock);
|
||||
|
||||
bool isRecentInstall() const;
|
||||
void setRecentInstall(bool recentInsatll);
|
||||
|
||||
int launched() const;
|
||||
void setLaunched(int launched);
|
||||
|
||||
int favorite() const;
|
||||
void setFavorite(int favorite);
|
||||
|
||||
int launchTimes() const;
|
||||
void setLaunchTimes(int launchTimes);
|
||||
|
||||
QString insertTime() const;
|
||||
void setInsertTime(const QString& insertTime);
|
||||
|
||||
QString id() const;
|
||||
void setId(const QString& id);
|
||||
|
||||
|
|
|
@ -63,6 +63,11 @@ QVariant AppModel::data(const QModelIndex &index, int role) const
|
|||
return m_apps.at(i).top();
|
||||
}
|
||||
return 0;
|
||||
case DataEntity::RecentInstall:
|
||||
if (DataProviderManager::instance()->activatedProvider() == "all") {
|
||||
return m_apps.at(i).isRecentInstall();
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ private:
|
|||
QVector<DataEntity> m_apps;
|
||||
|
||||
Q_SIGNALS:
|
||||
Q_INVOKABLE void renameText(QString id);
|
||||
void renameText(QString id);
|
||||
};
|
||||
|
||||
} // UkuiMenu
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <gio/gio.h>
|
||||
|
||||
#include "app-manager.h"
|
||||
#include "app-data-manager.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDBusReply>
|
||||
|
@ -76,6 +77,11 @@ bool AppManager::launchBinaryApp(const QString &app, const QString &args)
|
|||
return QProcess::startDetached(cmd);
|
||||
}
|
||||
|
||||
void AppManager::appLaunched(const QString &desktopFilePath)
|
||||
{
|
||||
AppDataManager::instance()->appLaunch(desktopFilePath);
|
||||
}
|
||||
|
||||
bool AppManager::launchAppWithDBus(const QString &app)
|
||||
{
|
||||
if (!m_appManagerDbusInterface) {
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
|
||||
Q_INVOKABLE bool launchApp(const QString &desktopFilePath);
|
||||
Q_INVOKABLE bool launchBinaryApp(const QString &app, const QString &args = QString());
|
||||
Q_INVOKABLE void appLaunched(const QString &desktopFilePath);
|
||||
|
||||
private:
|
||||
explicit AppManager(QObject *parent = nullptr);
|
||||
|
|
Loading…
Reference in New Issue