refact: restructure project
1. adjust project structure; 2. use config.h to locate app-launch-helper binary.
This commit is contained in:
		
							
								
								
									
										1
									
								
								apps/dde-application-manager/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								apps/dde-application-manager/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
			
		||||
add_subdirectory(src)
 | 
			
		||||
							
								
								
									
										14
									
								
								apps/dde-application-manager/src/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								apps/dde-application-manager/src/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
set(BIN_NAME dde-application-manager)
 | 
			
		||||
 | 
			
		||||
add_executable(${BIN_NAME} main.cpp utils.cpp)
 | 
			
		||||
 | 
			
		||||
target_link_libraries(${BIN_NAME} PRIVATE
 | 
			
		||||
    dde_am_static
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
target_include_directories(${BIN_NAME} PRIVATE
 | 
			
		||||
    ${CMAKE_CURRENT_SOURCE_DIR}
 | 
			
		||||
    ${CMAKE_CURRENT_BINARY_DIR}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
 | 
			
		||||
							
								
								
									
										59
									
								
								apps/dde-application-manager/src/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								apps/dde-application-manager/src/main.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,59 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: LGPL-3.0-or-later
 | 
			
		||||
 | 
			
		||||
#include "global.h"
 | 
			
		||||
#include <QDBusConnection>
 | 
			
		||||
#include <QCoreApplication>
 | 
			
		||||
#include <QDir>
 | 
			
		||||
#include "dbus/applicationmanager1service.h"
 | 
			
		||||
#include "cgroupsidentifier.h"
 | 
			
		||||
#include "global.h"
 | 
			
		||||
 | 
			
		||||
static void registerComplexDbusType()
 | 
			
		||||
{
 | 
			
		||||
    qDBusRegisterMetaType<QMap<QString, QDBusUnixFileDescriptor>>();
 | 
			
		||||
    qDBusRegisterMetaType<QMap<uint, QMap<QString, QDBusUnixFileDescriptor>>>();
 | 
			
		||||
    qDBusRegisterMetaType<IconMap>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
    QCoreApplication app{argc, argv};
 | 
			
		||||
    auto &bus = ApplicationManager1DBus::instance();
 | 
			
		||||
    bus.init(DBusType::Session);
 | 
			
		||||
    auto &AMBus = bus.globalBus();
 | 
			
		||||
 | 
			
		||||
    registerComplexDbusType();
 | 
			
		||||
    ApplicationManager1Service AMService{std::make_unique<CGroupsIdentifier>(), AMBus};
 | 
			
		||||
    QList<DesktopFile> fileList{};
 | 
			
		||||
    auto pathEnv = qgetenv("XDG_DATA_DIRS");
 | 
			
		||||
    if (pathEnv.isEmpty()) {
 | 
			
		||||
        qFatal() << "environment variable $XDG_DATA_DIRS is empty.";
 | 
			
		||||
    }
 | 
			
		||||
    auto desktopFileDirs = pathEnv.split(':');
 | 
			
		||||
 | 
			
		||||
    for (const auto &dir : desktopFileDirs) {
 | 
			
		||||
        auto dirPath = QDir{QDir::cleanPath(dir) + "/applications"};
 | 
			
		||||
        if (!dirPath.exists()) {
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
        QDirIterator it{dirPath.absolutePath(),
 | 
			
		||||
                        {"*.desktop"},
 | 
			
		||||
                        QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::Readable,
 | 
			
		||||
                        QDirIterator::Subdirectories};
 | 
			
		||||
        while (it.hasNext()) {
 | 
			
		||||
            auto file = it.next();
 | 
			
		||||
            ParseError err;
 | 
			
		||||
            auto ret = DesktopFile::searchDesktopFile(file, err);
 | 
			
		||||
            if (!ret.has_value()) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            if (!AMService.addApplication(std::move(ret).value())) {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return app.exec();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										22
									
								
								apps/dde-application-manager/src/utils.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								apps/dde-application-manager/src/utils.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,22 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: LGPL-3.0-or-later
 | 
			
		||||
 | 
			
		||||
#include "global.h"
 | 
			
		||||
 | 
			
		||||
bool registerObjectToDBus(QObject *o, const QString &path, const QString &interface)
 | 
			
		||||
{
 | 
			
		||||
    auto &con = ApplicationManager1DBus::instance().globalBus();
 | 
			
		||||
    if (!con.registerObject(path, interface, o, QDBusConnection::RegisterOption::ExportAllContents)) {
 | 
			
		||||
        qFatal() << "register object failed:" << path << interface << con.lastError();
 | 
			
		||||
    } else {
 | 
			
		||||
        qInfo() << "register object:" << path << interface;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void unregisterObjectFromDBus(const QString &path)
 | 
			
		||||
{
 | 
			
		||||
    auto &con = ApplicationManager1DBus::instance().globalBus();
 | 
			
		||||
    con.unregisterObject(path);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user