2022-03-30 17:56:27 +08:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
|
|
|
#include "impl/application_manager.h"
|
|
|
|
#include "impl/application.h"
|
|
|
|
#include "applicationmanageradaptor.h"
|
|
|
|
#include "applicationadaptor.h"
|
2022-05-19 13:13:55 +08:00
|
|
|
#include "applicationhelper.h"
|
2022-06-15 14:14:43 +08:00
|
|
|
#include "mimeadaptor.h"
|
2022-04-24 14:52:13 +08:00
|
|
|
#include "../modules/apps/appmanager.h"
|
|
|
|
#include "../modules/launcher/launchermanager.h"
|
|
|
|
#include "../modules/dock/dockmanager.h"
|
2022-05-15 12:10:42 +08:00
|
|
|
#include "../modules/startmanager/startmanager.h"
|
2022-06-15 14:14:43 +08:00
|
|
|
#include "../modules/mimeapp/mime_app.h"
|
2022-03-30 17:56:27 +08:00
|
|
|
|
|
|
|
#include <QDir>
|
2022-04-24 14:52:13 +08:00
|
|
|
#include <DLog>
|
2022-03-30 17:56:27 +08:00
|
|
|
#include <pwd.h>
|
|
|
|
|
2022-04-24 14:52:13 +08:00
|
|
|
DCORE_USE_NAMESPACE
|
|
|
|
|
2022-11-04 14:22:45 +08:00
|
|
|
#define ApplicationManagerServiceName "org.desktopspec.ApplicationManager"
|
|
|
|
#define ApplicationManagerServicePath "/org/desktopspec/ApplicationManager"
|
|
|
|
#define ApplicationManagerInterface "org.desktopspec.ApplicationManager"
|
|
|
|
|
2022-03-30 17:56:27 +08:00
|
|
|
QFileInfoList scan(const QString &path)
|
|
|
|
{
|
|
|
|
QDir dir(path);
|
|
|
|
dir.setFilter(QDir::Files);
|
|
|
|
dir.setNameFilters({ "*.desktop" });
|
|
|
|
return dir.entryInfoList();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 扫描系统目录
|
|
|
|
// 扫描用户目录
|
|
|
|
QList<QSharedPointer<Application>> scanFiles()
|
|
|
|
{
|
|
|
|
QList<QSharedPointer<Application>> applications;
|
|
|
|
auto apps = scan("/usr/share/applications/");
|
|
|
|
for (const QFileInfo &info : apps) {
|
|
|
|
applications << QSharedPointer<Application>(new Application(
|
|
|
|
"freedesktop",
|
|
|
|
Application::Type::System,
|
|
|
|
QSharedPointer<modules::ApplicationHelper::Helper>(new modules::ApplicationHelper::Helper(info.filePath()))
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct passwd *user = getpwent();
|
|
|
|
while (user) {
|
|
|
|
auto userApps = scan(QString("%1/.local/share/applications/").arg(user->pw_dir));
|
|
|
|
for (const QFileInfo &info : userApps) {
|
|
|
|
applications << QSharedPointer<Application>(new Application(
|
|
|
|
"freedesktop",
|
|
|
|
Application::Type::System,
|
|
|
|
QSharedPointer<modules::ApplicationHelper::Helper>(new modules::ApplicationHelper::Helper(info.filePath()))
|
|
|
|
));
|
|
|
|
}
|
|
|
|
user = getpwent();
|
|
|
|
}
|
|
|
|
endpwent();
|
2022-07-13 10:45:22 +08:00
|
|
|
auto linglong = scan("/persistent/linglong/entries/share/applications/");
|
2022-03-30 17:56:27 +08:00
|
|
|
for (const QFileInfo &info : linglong) {
|
|
|
|
applications << QSharedPointer<Application>(new Application(
|
|
|
|
"linglong",
|
|
|
|
Application::Type::System,
|
|
|
|
QSharedPointer<modules::ApplicationHelper::Helper>(new modules::ApplicationHelper::Helper(info.filePath()))
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
return applications;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
QCoreApplication app(argc, argv);
|
2022-04-24 14:52:13 +08:00
|
|
|
app.setOrganizationName("deepin");
|
|
|
|
app.setApplicationName("dde-application-manager");
|
|
|
|
|
|
|
|
DLogManager::registerConsoleAppender();
|
|
|
|
DLogManager::registerFileAppender();
|
2022-03-30 17:56:27 +08:00
|
|
|
|
2022-06-09 10:38:21 +08:00
|
|
|
QTranslator *translator = new QTranslator();
|
|
|
|
translator->load(QString("/usr/share/dde-application-manager/translations/dde-application-manager_%1.qm").arg(QLocale::system().name()));
|
|
|
|
QCoreApplication::installTranslator(translator);
|
|
|
|
|
2022-05-19 13:13:55 +08:00
|
|
|
new AppManager(ApplicationManager::instance());
|
|
|
|
new LauncherManager(ApplicationManager::instance());
|
|
|
|
new DockManager(ApplicationManager::instance());
|
|
|
|
new ApplicationManagerAdaptor(ApplicationManager::instance());
|
2022-03-30 17:56:27 +08:00
|
|
|
|
2022-11-04 14:22:45 +08:00
|
|
|
QDBusConnection connection = QDBusConnection::sessionBus();
|
|
|
|
if (!connection.registerService("org.desktopspec.Application")) {
|
|
|
|
qWarning() << "error: " << connection.lastError().message();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!connection.registerService(ApplicationManagerServiceName)) {
|
|
|
|
qWarning() << "error: " << connection.lastError().message();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!connection.registerObject(ApplicationManagerServicePath, ApplicationManagerInterface, ApplicationManager::instance())) {
|
|
|
|
qWarning() << "error: " << connection.lastError().message();
|
|
|
|
return -1;
|
|
|
|
}
|
2022-03-30 17:56:27 +08:00
|
|
|
|
|
|
|
QList<QSharedPointer<Application>> apps{ scanFiles() };
|
|
|
|
QList<QSharedPointer<ApplicationAdaptor>> appAdapters;
|
|
|
|
for (const QSharedPointer<Application> app : apps) {
|
|
|
|
QSharedPointer<ApplicationAdaptor> adapter = QSharedPointer<ApplicationAdaptor>(new ApplicationAdaptor(app.get()));
|
|
|
|
appAdapters << adapter;
|
2022-11-04 14:22:45 +08:00
|
|
|
if (!connection.registerObject(app->path().path(), "org.desktopspec.Application", app.get())) {
|
|
|
|
qWarning() << "error: " << connection.lastError().message();
|
|
|
|
continue;
|
|
|
|
}
|
2022-03-30 17:56:27 +08:00
|
|
|
}
|
|
|
|
|
2022-05-19 13:13:55 +08:00
|
|
|
ApplicationManager::instance()->addApplication(apps);
|
|
|
|
|
|
|
|
ApplicationManager::instance()->launchAutostartApps();
|
2022-03-30 17:56:27 +08:00
|
|
|
|
2022-06-15 14:14:43 +08:00
|
|
|
MimeApp* mimeApp = new MimeApp;
|
|
|
|
|
|
|
|
new MimeAdaptor(mimeApp);
|
2022-11-04 14:22:45 +08:00
|
|
|
if (!connection.registerService("org.deepin.daemon.Mime1")) {
|
|
|
|
qWarning() << "error: " << connection.lastError().message();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!connection.registerObject("/org/deepin/daemon/Mime1", "org.deepin.daemon.Mime1", mimeApp)) {
|
|
|
|
qWarning() << "error: " << connection.lastError().message();
|
|
|
|
return -1;
|
|
|
|
}
|
2022-06-15 14:14:43 +08:00
|
|
|
|
2022-03-30 17:56:27 +08:00
|
|
|
return app.exec();
|
|
|
|
}
|