refact: suppress warnings and standardize project
Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
@ -32,7 +32,10 @@ void ApplicationManager1Service::initService(QDBusConnection &connection) noexce
|
||||
qFatal("%s", connection.lastError().message().toLocal8Bit().data());
|
||||
}
|
||||
|
||||
new (std::nothrow) ProcessGuesser1Service{connection, this};
|
||||
if (auto *tmp = new (std::nothrow) ProcessGuesser1Service{connection, this}; tmp == nullptr) {
|
||||
qCritical() << "new ProcessGuesser1Service failed.";
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
if (auto *tmp = new (std::nothrow) ApplicationManager1Adaptor{this}; tmp == nullptr) {
|
||||
qCritical() << "new Application Manager Adaptor failed.";
|
||||
@ -154,7 +157,9 @@ void ApplicationManager1Service::initService(QDBusConnection &connection) noexce
|
||||
watcher->deleteLater();
|
||||
};
|
||||
|
||||
*sigCon = connect(watcher, &QDBusServiceWatcher::serviceRegistered, singleSlot);
|
||||
if (watcher != nullptr) {
|
||||
*sigCon = connect(watcher, &QDBusServiceWatcher::serviceRegistered, singleSlot);
|
||||
}
|
||||
|
||||
auto msg =
|
||||
QDBusMessage::createMethodCall("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameHasOwner");
|
||||
@ -192,7 +197,7 @@ void ApplicationManager1Service::addInstanceToApplication(const QString &unitNam
|
||||
m_applicationList.cend(),
|
||||
[&appId](const QSharedPointer<ApplicationService> &app) { return app->id() == appId; });
|
||||
|
||||
if (appIt == m_applicationList.cend()) [[unlikely]] {
|
||||
if (appIt == m_applicationList.cend()) {
|
||||
qWarning() << "couldn't find app" << appId << "in application manager.";
|
||||
return;
|
||||
}
|
||||
@ -201,7 +206,7 @@ void ApplicationManager1Service::addInstanceToApplication(const QString &unitNam
|
||||
|
||||
const auto &applicationPath = (*appIt)->applicationPath().path();
|
||||
|
||||
if (!(*appIt)->addOneInstance(instanceId, applicationPath, systemdUnitPath.path(), launcher)) [[likely]] {
|
||||
if (!(*appIt)->addOneInstance(instanceId, applicationPath, systemdUnitPath.path(), launcher)) {
|
||||
qCritical() << "add Instance failed:" << applicationPath << unitName << systemdUnitPath.path();
|
||||
}
|
||||
}
|
||||
@ -225,7 +230,7 @@ void ApplicationManager1Service::removeInstanceFromApplication(const QString &un
|
||||
m_applicationList.cend(),
|
||||
[&appId](const QSharedPointer<ApplicationService> &app) { return app->id() == appId; });
|
||||
|
||||
if (appIt == m_applicationList.cend()) [[unlikely]] {
|
||||
if (appIt == m_applicationList.cend()) {
|
||||
qWarning() << "couldn't find app" << appId << "in application manager.";
|
||||
return;
|
||||
}
|
||||
@ -237,12 +242,12 @@ void ApplicationManager1Service::removeInstanceFromApplication(const QString &un
|
||||
return value->property("SystemdUnitPath") == systemdUnitPath;
|
||||
});
|
||||
|
||||
if (instanceIt != appIns.cend()) [[likely]] {
|
||||
if (instanceIt != appIns.cend()) {
|
||||
(*appIt)->removeOneInstance(instanceIt.key());
|
||||
return;
|
||||
}
|
||||
|
||||
orphanedInstances->removeIf([&systemdUnitPath](const QSharedPointer<InstanceService> &ptr) {
|
||||
orphanedInstances.removeIf([&systemdUnitPath](const QSharedPointer<InstanceService> &ptr) {
|
||||
return (ptr->property("SystemdUnitPath").value<QDBusObjectPath>() == systemdUnitPath);
|
||||
});
|
||||
}
|
||||
@ -426,7 +431,7 @@ QHash<QSharedPointer<ApplicationService>, QString> ApplicationManager1Service::s
|
||||
}
|
||||
|
||||
qInfo() << "launch new autostart application " << newApp->id();
|
||||
newApp->setAutostartSource({desktopFile.sourcePath()});
|
||||
newApp->setAutostartSource({desktopFile.sourcePath(), {}});
|
||||
ret.insert(newApp, {});
|
||||
}
|
||||
|
||||
|
@ -779,23 +779,29 @@ QList<QDBusObjectPath> ApplicationService::instances() const noexcept
|
||||
bool ApplicationService::addOneInstance(const QString &instanceId,
|
||||
const QString &application,
|
||||
const QString &systemdUnitPath,
|
||||
const QString &launcher)
|
||||
const QString &launcher) noexcept
|
||||
{
|
||||
auto *service = new InstanceService{instanceId, application, systemdUnitPath, launcher};
|
||||
auto *adaptor = new InstanceAdaptor(service);
|
||||
QString objectPath{m_applicationPath.path() + "/" + instanceId};
|
||||
|
||||
if (registerObjectToDBus(service, objectPath, InstanceInterface)) {
|
||||
m_Instances.insert(QDBusObjectPath{objectPath}, QSharedPointer<InstanceService>{service});
|
||||
service->moveToThread(this->thread());
|
||||
adaptor->moveToThread(this->thread());
|
||||
emit InterfacesAdded(QDBusObjectPath{objectPath}, getChildInterfacesAndPropertiesFromObject(service));
|
||||
return true;
|
||||
auto *service = new (std::nothrow) InstanceService{instanceId, application, systemdUnitPath, launcher};
|
||||
if (service == nullptr) {
|
||||
qCritical() << "couldn't new InstanceService.";
|
||||
return false;
|
||||
}
|
||||
|
||||
adaptor->deleteLater();
|
||||
service->deleteLater();
|
||||
return false;
|
||||
auto *adaptor = new (std::nothrow) InstanceAdaptor{service};
|
||||
QString objectPath{m_applicationPath.path() + "/" + instanceId};
|
||||
|
||||
if (adaptor == nullptr or !registerObjectToDBus(service, objectPath, InstanceInterface)) {
|
||||
adaptor->deleteLater();
|
||||
service->deleteLater();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_Instances.insert(QDBusObjectPath{objectPath}, QSharedPointer<InstanceService>{service});
|
||||
service->moveToThread(this->thread());
|
||||
adaptor->moveToThread(this->thread());
|
||||
emit InterfacesAdded(QDBusObjectPath{objectPath}, getChildInterfacesAndPropertiesFromObject(service));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ApplicationService::removeOneInstance(const QDBusObjectPath &instance) noexcept
|
||||
@ -817,7 +823,7 @@ void ApplicationService::removeAllInstance() noexcept
|
||||
void ApplicationService::detachAllInstance() noexcept
|
||||
{
|
||||
for (auto &instance : m_Instances.values()) {
|
||||
orphanedInstances->append(instance);
|
||||
orphanedInstances.append(instance);
|
||||
instance->setProperty("Orphaned", true);
|
||||
}
|
||||
|
||||
@ -869,7 +875,12 @@ std::optional<QStringList> ApplicationService::unescapeExecArgs(const QString &s
|
||||
wordfree(word);
|
||||
delete word;
|
||||
};
|
||||
|
||||
std::unique_ptr<wordexp_t, decltype(deleter)> words{new (std::nothrow) wordexp_t{0, nullptr, 0}, deleter};
|
||||
if (words == nullptr) {
|
||||
qCritical() << "couldn't new wordexp_t";
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (auto ret = wordexp(unescapedStr.toLocal8Bit(), words.get(), WRDE_SHOWERR); ret != 0) {
|
||||
if (ret != 0) {
|
||||
@ -899,7 +910,7 @@ std::optional<QStringList> ApplicationService::unescapeExecArgs(const QString &s
|
||||
}
|
||||
|
||||
QStringList execList;
|
||||
for (int i = 0; i < words->we_wordc; ++i) {
|
||||
for (std::size_t i = 0; i < words->we_wordc; ++i) {
|
||||
execList.emplace_back(words->we_wordv[i]);
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ public:
|
||||
bool addOneInstance(const QString &instanceId,
|
||||
const QString &application,
|
||||
const QString &systemdUnitPath,
|
||||
const QString &launcher);
|
||||
const QString &launcher) noexcept;
|
||||
void recoverInstances(const QList<QDBusObjectPath> &instanceList) noexcept;
|
||||
void removeOneInstance(const QDBusObjectPath &instance) noexcept;
|
||||
void removeAllInstance() noexcept;
|
||||
|
@ -14,7 +14,10 @@ InstanceService::InstanceService(QString instanceId, QString application, QStrin
|
||||
, m_Application(std::move(application))
|
||||
, m_SystemdUnitPath(std::move(systemdUnitPath))
|
||||
{
|
||||
new PropertiesForwarder{application + "/" + instanceId, this};
|
||||
if (auto *tmp = new (std::nothrow) PropertiesForwarder{application + "/" + instanceId, this}; tmp == nullptr) {
|
||||
qCritical() << "couldn't new PropertiesForwarder for instanceService.";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
InstanceService::~InstanceService() = default;
|
||||
|
@ -42,6 +42,6 @@ private:
|
||||
QDBusObjectPath m_SystemdUnitPath;
|
||||
};
|
||||
|
||||
Q_GLOBAL_STATIC(QList<QSharedPointer<InstanceService>>, orphanedInstances)
|
||||
static inline QList<QSharedPointer<InstanceService>> orphanedInstances{};
|
||||
|
||||
#endif
|
||||
|
@ -8,10 +8,11 @@
|
||||
JobManager1Service::JobManager1Service(ApplicationManager1Service *parent)
|
||||
: m_parent(parent)
|
||||
{
|
||||
new JobManager1Adaptor{this};
|
||||
if (!registerObjectToDBus(this, DDEApplicationManager1JobManager1ObjectPath, JobManager1Interface)) {
|
||||
auto *adaptor = new (std::nothrow) JobManager1Adaptor{this};
|
||||
if (adaptor == nullptr or !registerObjectToDBus(this, DDEApplicationManager1JobManager1ObjectPath, JobManager1Interface)) {
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
qRegisterMetaType<LaunchTask>();
|
||||
}
|
||||
|
||||
|
@ -58,11 +58,16 @@ public:
|
||||
qOverload<QVariantList::parameter_type>(&QVariantList::append),
|
||||
QVariantList{},
|
||||
QtConcurrent::ReduceOption::OrderedReduce);
|
||||
QSharedPointer<JobService> job{new JobService{future}};
|
||||
QSharedPointer<JobService> job{new (std::nothrow) JobService{future}};
|
||||
if (job == nullptr) {
|
||||
qCritical() << "couldn't new JobService.";
|
||||
future.cancel();
|
||||
return {};
|
||||
}
|
||||
|
||||
auto *ptr = job.data();
|
||||
new JobAdaptor(ptr);
|
||||
if (!registerObjectToDBus(ptr, objectPath, JobInterface)) {
|
||||
auto *adaptor = new (std::nothrow) JobAdaptor(ptr);
|
||||
if (adaptor == nullptr or !registerObjectToDBus(ptr, objectPath, JobInterface)) {
|
||||
qCritical() << "can't register job to dbus.";
|
||||
future.cancel();
|
||||
return {};
|
||||
|
@ -10,8 +10,8 @@
|
||||
MimeManager1Service::MimeManager1Service(ApplicationManager1Service *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
new MimeManager1Adaptor{this};
|
||||
if (!registerObjectToDBus(this, DDEApplicationManager1MimeManager1ObjectPath, MimeManager1Interface)) {
|
||||
auto *adaptor = new (std::nothrow) MimeManager1Adaptor{this};
|
||||
if (adaptor == nullptr or !registerObjectToDBus(this, DDEApplicationManager1MimeManager1ObjectPath, MimeManager1Interface)) {
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
|
@ -13,11 +13,9 @@ ProcessGuesser1Service::ProcessGuesser1Service(QDBusConnection &connection, Appl
|
||||
qFatal("%s", connection.lastError().message().toLocal8Bit().data());
|
||||
}
|
||||
|
||||
if (auto *tmp = new (std::nothrow) ProcessGuesser1Adaptor{this}; tmp == nullptr) {
|
||||
qFatal("new Process Guesser Adaptor failed.");
|
||||
}
|
||||
|
||||
if (!registerObjectToDBus(this, "/org/desktopspec/ProcessGuesser1", "org.desktopspec.ProcessGuesser1")) {
|
||||
auto *adaptor = new (std::nothrow) ProcessGuesser1Adaptor{this};
|
||||
if (adaptor == nullptr or
|
||||
!registerObjectToDBus(this, "/org/desktopspec/ProcessGuesser1", "org.desktopspec.ProcessGuesser1")) {
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user