From 5f33ccbb5f8174b1b64cc1b2172ded390b22d172 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 8 May 2022 21:10:35 +0900 Subject: [PATCH] Specify TDE config folder through CMAKE parameters. More code clean up. Signed-off-by: Michele Calgaro --- config.h.cmake | 3 ++ src/appimpl.cpp | 105 ++++++++++++++++++++++++------------------------ src/appimpl.h | 28 +++++-------- 3 files changed, 66 insertions(+), 70 deletions(-) diff --git a/config.h.cmake b/config.h.cmake index 61ede3a..9df6206 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -6,3 +6,6 @@ /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ #cmakedefine WORDS_BIGENDIAN @WORDS_BIGENDIAN@ + +/* The compiled in system configuration prefix */ +#define TDESYSCONFDIR "@CONFIG_INSTALL_DIR@/" diff --git a/src/appimpl.cpp b/src/appimpl.cpp index cc4ccb6..913ae0d 100644 --- a/src/appimpl.cpp +++ b/src/appimpl.cpp @@ -32,6 +32,7 @@ #include #include +#include "config.h" AppImpl::AppImpl(TDEIO_AppInfo *slave) : TQObject(), m_slave(slave) { @@ -173,10 +174,10 @@ void AppImpl::createEntry(TDEIO::UDSEntry &entry, const TQString &file) } } -void AppImpl::createExeEntry(TQValueList &list,TDEIO::UDSEntry &entry, - const TQString &shortname, - const TQStringList &fullname) +void AppImpl::createExeEntry(TQValueList &list, const TQString &shortname, + const TQStringList &fullname) { + TDEIO::UDSEntry entry; for (const TQString &name : fullname) { if (name.isEmpty()) @@ -206,10 +207,9 @@ void AppImpl::createExeEntry(TQValueList &list,TDEIO::UDSEntry } } -void AppImpl::createManPageEntry(TQValueList &list, TDEIO::UDSEntry &entry, - const TQString &shortname) +void AppImpl::createManPageEntry(TQValueList &list, const TQString &shortname) { - entry.clear(); + TDEIO::UDSEntry entry; addAtom(entry, TDEIO::UDS_NAME, 0, i18n("Manual for %1").arg(shortname)); addAtom(entry, TDEIO::UDS_URL, 0, "man:/"+shortname); addAtom(entry, TDEIO::UDS_FILE_TYPE, S_IFREG); @@ -218,8 +218,7 @@ void AppImpl::createManPageEntry(TQValueList &list, TDEIO::UDSE list.append(entry); } -void AppImpl::createHomeDirEntry(TQValueList &list, TDEIO::UDSEntry &entry, - const TQString &shortname) +void AppImpl::createHomeDirEntry(TQValueList &list, const TQString &shortname) { TQStringList homedir; homedir << TQString("%1/").arg(getenv("HOME")); @@ -227,6 +226,7 @@ void AppImpl::createHomeDirEntry(TQValueList &list, TDEIO::UDSE TQStringList fullname = getFullLocation(homedir, dirname, TQDir::FilterSpec(TQDir::Hidden | TQDir::Dirs | TQDir::Readable), true, false); + TDEIO::UDSEntry entry; for (const TQString &fname : fullname) { if (fname.isEmpty()) @@ -244,8 +244,7 @@ void AppImpl::createHomeDirEntry(TQValueList &list, TDEIO::UDSE } } -void AppImpl::createTDEDataDirEntry(TQValueList &list,TDEIO::UDSEntry &entry, - const TQString &shortname) +void AppImpl::createTDEDataDirEntry(TQValueList &list, const TQString &shortname) { TQStringList dirList = TDEGlobal::instance()->dirs()->resourceDirs("data"); TQStringList TDEDataDir = getFullLocation(dirList, shortname, @@ -255,6 +254,7 @@ void AppImpl::createTDEDataDirEntry(TQValueList &list,TDEIO::UD return; } + TDEIO::UDSEntry entry; for (const TQString &dirname : TDEDataDir) { if (dirname.isEmpty()) @@ -272,8 +272,7 @@ void AppImpl::createTDEDataDirEntry(TQValueList &list,TDEIO::UD } } -void AppImpl::createStandardDataDirEntry(TQValueList &list, - TDEIO::UDSEntry &entry, const TQString &shortname) +void AppImpl::createStandardDataDirEntry(TQValueList &list, const TQString &shortname) { TQStringList dirList; dirList << "/usr/share/"; @@ -285,6 +284,7 @@ void AppImpl::createStandardDataDirEntry(TQValueList &list, return; } + TDEIO::UDSEntry entry; for (const TQString &dirname : StandardDataDir) { if (dirname.isEmpty()) @@ -302,27 +302,32 @@ void AppImpl::createStandardDataDirEntry(TQValueList &list, } } - -void AppImpl::createTDEConfigEntry(TQValueList &list, - TDEIO::UDSEntry &entry, const TQString &shortname) +void AppImpl::createTDEConfigEntry(TQValueList &list, const TQString &shortname) { + TDEIO::UDSEntry entry; + // Global TDE config - TQStringList dirList; - dirList << "/etc/trinity/"; - TQStringList TDEConfigFiles = getFullLocation(dirList, shortname + "rc", - TQDir::FilterSpec(TQDir::Files | TQDir::Dirs | TQDir::Readable), false, true); + TQString tdeCfgDir(TDESYSCONFDIR); - for (const TQString &filename : TDEConfigFiles) + if (!tdeCfgDir.isEmpty()) { - if (!filename.isEmpty()) + TQStringList dirList; + dirList << tdeCfgDir; + TQStringList TDEConfigFiles = getFullLocation(dirList, shortname + "rc", + TQDir::FilterSpec(TQDir::Files | TQDir::Dirs | TQDir::Readable), false, true); + + for (const TQString &filename : TDEConfigFiles) { - entry.clear(); - addAtom(entry, TDEIO::UDS_NAME, 0, i18n("Config File (%1)").arg(filename)); - addAtom(entry, TDEIO::UDS_URL, 0, filename); - addAtom(entry, TDEIO::UDS_FILE_TYPE, S_IFREG); - addAtom(entry, TDEIO::UDS_MIME_TYPE, 0, "text/plain"); - addAtom(entry, TDEIO::UDS_ICON_NAME, 0, "configure"); - list.append(entry); + if (!filename.isEmpty()) + { + entry.clear(); + addAtom(entry, TDEIO::UDS_NAME, 0, i18n("Config File (%1)").arg(filename)); + addAtom(entry, TDEIO::UDS_URL, 0, filename); + addAtom(entry, TDEIO::UDS_FILE_TYPE, S_IFREG); + addAtom(entry, TDEIO::UDS_MIME_TYPE, 0, "text/plain"); + addAtom(entry, TDEIO::UDS_ICON_NAME, 0, "configure"); + list.append(entry); + } } } @@ -342,8 +347,7 @@ void AppImpl::createTDEConfigEntry(TQValueList &list, list.append(entry); } -void AppImpl::createStandardConfigEntry(TQValueList &list, TDEIO::UDSEntry &entry, - const TQString &shortname) +void AppImpl::createStandardConfigEntry(TQValueList &list, const TQString &shortname) { TQStringList dirList; dirList << "/etc/"; @@ -356,6 +360,7 @@ void AppImpl::createStandardConfigEntry(TQValueList &list, TDEI return; } + TDEIO::UDSEntry entry; for (const TQString &fname : StandardConfigFile) { if (fname.isEmpty()) @@ -363,7 +368,6 @@ void AppImpl::createStandardConfigEntry(TQValueList &list, TDEI continue; } - entry.clear(); bool isFolder = false; TQFileInfo fi(fname); if (fi.isDir()) @@ -373,6 +377,7 @@ void AppImpl::createStandardConfigEntry(TQValueList &list, TDEI kdDebug() << "createStandardConfigEntry: " << fname << endl; + entry.clear(); addAtom(entry, TDEIO::UDS_URL, 0, fname); TQString icon; if (isFolder) @@ -393,8 +398,7 @@ void AppImpl::createStandardConfigEntry(TQValueList &list, TDEI } } -void AppImpl::createTmpDirEntry(TQValueList &list, TDEIO::UDSEntry &entry, - const TQString &shortname) +void AppImpl::createTmpDirEntry(TQValueList &list, const TQString &shortname) { TQStringList dirList; dirList << "/tmp/"; @@ -412,7 +416,6 @@ void AppImpl::createTmpDirEntry(TQValueList &list, TDEIO::UDSEn continue; } - entry.clear(); bool isFolder = false; TQFileInfo fi(fname); if (fi.isDir()) @@ -422,6 +425,7 @@ void AppImpl::createTmpDirEntry(TQValueList &list, TDEIO::UDSEn kdDebug() << "createTmpDirEntry: " << fname << endl; + TDEIO::UDSEntry entry; addAtom(entry, TDEIO::UDS_URL, 0, fname); if (isFolder) { @@ -441,8 +445,7 @@ void AppImpl::createTmpDirEntry(TQValueList &list, TDEIO::UDSEn } } -void AppImpl::createXDGDirEntry(TQValueList &list, TDEIO::UDSEntry &entry, - const TQString &shortname) +void AppImpl::createXDGDirEntry(TQValueList &list, const TQString &shortname) { TQStringList dirList; dirList << TQString("%1/.config/").arg(getenv("HOME")); @@ -456,7 +459,6 @@ void AppImpl::createXDGDirEntry(TQValueList &list, TDEIO::UDSEn continue; } - entry.clear(); bool isFolder = false; TQFileInfo fi(filename); if (fi.isDir()) @@ -466,6 +468,7 @@ void AppImpl::createXDGDirEntry(TQValueList &list, TDEIO::UDSEn kdDebug() << "createXdgDirEntry: " << filename << endl; + TDEIO::UDSEntry entry; addAtom(entry, TDEIO::UDS_URL, 0, filename); if (isFolder) { @@ -489,30 +492,28 @@ bool AppImpl::listAppContents(const TQString &name, TQValueList { kdDebug() << "AppImpl::listAppContents" << endl; - TDEIO::UDSEntry entry; - // Create entry for binary file - createExeEntry(list, entry, name, getAppAddress(name)); - - // Create entry for data folder in home dir - createHomeDirEntry(list, entry, name); + createExeEntry(list, name, getAppAddress(name)); // Create entry for standard config and data folders - createStandardConfigEntry(list, entry, name); - createStandardDataDirEntry(list, entry, name); - - //Create entry for app XDF config folder in home dir - createXDGDirEntry(list, entry, name); + createStandardConfigEntry(list, name); + createStandardDataDirEntry(list, name); // Create entry for TDE config and data folders - createTDEConfigEntry(list, entry, name); - createTDEDataDirEntry(list, entry, name); + createTDEConfigEntry(list, name); + createTDEDataDirEntry(list, name); + + // Create entry for data folder in home dir + createHomeDirEntry(list, name); + + //Create entry for app XDF config folder in home dir + createXDGDirEntry(list, name); // Create entry for manual - createManPageEntry(list, entry, name); + createManPageEntry(list, name); //Create entry for folders in tmp dir - createTmpDirEntry(list, entry, name); + createTmpDirEntry(list, name); return true; } diff --git a/src/appimpl.h b/src/appimpl.h index 8402e15..7b28306 100644 --- a/src/appimpl.h +++ b/src/appimpl.h @@ -55,24 +55,16 @@ public: TQString lastErrorMessage() const { return m_lastErrorMessage; } private slots: - void createManPageEntry(TQValueList &list, TDEIO::UDSEntry &entry, - const TQString &shortname); - void createExeEntry(TQValueList &list, TDEIO::UDSEntry &entry, - const TQString &shortname, const TQStringList &fullname); - void createHomeDirEntry(TQValueList &list,TDEIO::UDSEntry &entry, - const TQString &shortname); - void createTDEDataDirEntry(TQValueList &list,TDEIO::UDSEntry &entry, - const TQString &shortname); - void createTDEConfigEntry(TQValueList &list, TDEIO::UDSEntry &entry, - const TQString &shortname); - void createStandardConfigEntry(TQValueList &list, TDEIO::UDSEntry &entry, - const TQString &shortname); - void createStandardDataDirEntry(TQValueList &list, TDEIO::UDSEntry &entry, - const TQString &shortname); - void createTmpDirEntry(TQValueList &list, TDEIO::UDSEntry &entry, - const TQString &shortname); - void createXDGDirEntry(TQValueList &list, TDEIO::UDSEntry &entry, - const TQString &shortname); + void createManPageEntry(TQValueList &list, const TQString &shortname); + void createExeEntry(TQValueList &list, const TQString &shortname, + const TQStringList &fullname); + void createHomeDirEntry(TQValueList &list, const TQString &shortname); + void createTDEDataDirEntry(TQValueList &list, const TQString &shortname); + void createTDEConfigEntry(TQValueList &list, const TQString &shortname); + void createStandardConfigEntry(TQValueList &list, const TQString &shortname); + void createStandardDataDirEntry(TQValueList &list, const TQString &shortname); + void createTmpDirEntry(TQValueList &list, const TQString &shortname); + void createXDGDirEntry(TQValueList &list, const TQString &shortname); TQStringList getAppAddress(const TQString &name); TQStringList getFullLocation(const TQStringList &dirList, const TQString &name,