2022-03-30 17:56:27 +08:00
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
|
|
|
|
|
#include "impl/application_manager.h"
|
|
|
|
|
#include "impl/application.h"
|
2022-11-17 17:25:20 +08:00
|
|
|
|
#include "manageradaptor.h"
|
|
|
|
|
#include "application1adaptor.h"
|
2022-05-19 13:13:55 +08:00
|
|
|
|
#include "applicationhelper.h"
|
2022-11-17 17:25:20 +08:00
|
|
|
|
#include "mime1adaptor.h"
|
2022-12-07 18:42:04 +08:00
|
|
|
|
#include "settings.h"
|
|
|
|
|
#include "dsysinfo.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-17 17:25:20 +08:00
|
|
|
|
#define ApplicationManagerServiceName "org.deepin.dde.Application1.Manager"
|
|
|
|
|
#define ApplicationManagerServicePath "/org/deepin/dde/Application1/Manager"
|
|
|
|
|
#define ApplicationManagerInterface "org.deepin.dde.Application1.Manager"
|
2022-11-04 14:22:45 +08:00
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-07 18:42:04 +08:00
|
|
|
|
void init()
|
|
|
|
|
{
|
|
|
|
|
// 从DConfig中读取当前的显示模式,如果为空,则认为是第一次进入(新安装的系统),否则,就认为系统之前已经进入设置过,直接返回即可
|
|
|
|
|
QSharedPointer<DConfig> config(Settings::ConfigPtr("com.deepin.dde.dock"));
|
|
|
|
|
if (config.isNull() || !config->value("Display_Mode").toString().isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// 然后判断当前系统是否为社区版,社区版默认任务栏模式为时尚模式,其他版本默认为高效模式
|
|
|
|
|
QString displayMode = DSysInfo::isCommunityEdition() ? QString("fashion") : QString("efficient");
|
|
|
|
|
config->setValue("Display_Mode", displayMode);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-30 17:56:27 +08:00
|
|
|
|
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-12-07 18:42:04 +08:00
|
|
|
|
// 初始化
|
|
|
|
|
init();
|
|
|
|
|
|
2022-05-19 13:13:55 +08:00
|
|
|
|
new AppManager(ApplicationManager::instance());
|
|
|
|
|
new LauncherManager(ApplicationManager::instance());
|
|
|
|
|
new DockManager(ApplicationManager::instance());
|
2022-11-17 17:25:20 +08:00
|
|
|
|
new ManagerAdaptor(ApplicationManager::instance());
|
2022-03-30 17:56:27 +08:00
|
|
|
|
|
2022-11-04 14:22:45 +08:00
|
|
|
|
QDBusConnection connection = QDBusConnection::sessionBus();
|
2022-11-17 17:25:20 +08:00
|
|
|
|
if (!connection.registerService("org.deepin.dde.Application1")) {
|
2022-11-04 14:22:45 +08:00
|
|
|
|
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() };
|
2022-11-17 17:25:20 +08:00
|
|
|
|
QList<QSharedPointer<Application1Adaptor>> appAdapters;
|
2022-03-30 17:56:27 +08:00
|
|
|
|
for (const QSharedPointer<Application> app : apps) {
|
2022-11-17 17:25:20 +08:00
|
|
|
|
QSharedPointer<Application1Adaptor> adapter = QSharedPointer<Application1Adaptor>(new Application1Adaptor(app.get()));
|
2022-03-30 17:56:27 +08:00
|
|
|
|
appAdapters << adapter;
|
2022-11-17 17:25:20 +08:00
|
|
|
|
if (!connection.registerObject(app->path().path(), "org.deepin.dde.Application1", app.get())) {
|
2022-11-04 14:22:45 +08:00
|
|
|
|
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;
|
|
|
|
|
|
2022-11-17 17:25:20 +08:00
|
|
|
|
new Mime1Adaptor(mimeApp);
|
|
|
|
|
if (!connection.registerService("org.deepin.dde.Mime1")) {
|
2022-11-04 14:22:45 +08:00
|
|
|
|
qWarning() << "error: " << connection.lastError().message();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 17:25:20 +08:00
|
|
|
|
if (!connection.registerObject("/org/deepin/dde/Mime1", "org.deepin.dde.Mime1", mimeApp)) {
|
2022-11-04 14:22:45 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|