From 7d244de21521e47bafce032bbf2d84a13d60ab9e Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 8 May 2022 20:01:57 +0900 Subject: [PATCH] Added XDG config folder. Fixed up folder/file lookup for TDE config. Removed unused code. Signed-off-by: Michele Calgaro --- src/appimpl.cpp | 161 +++++++++++++++++++++++------------------------- src/appimpl.h | 6 +- 2 files changed, 80 insertions(+), 87 deletions(-) diff --git a/src/appimpl.cpp b/src/appimpl.cpp index 9077afc..cc4ccb6 100644 --- a/src/appimpl.cpp +++ b/src/appimpl.cpp @@ -23,8 +23,6 @@ #include -#include -#include #include #include @@ -105,26 +103,11 @@ bool AppImpl::parseURL(const KURL &url, TQString &name, TQString &path) const return !name.isEmpty(); } -bool AppImpl::realURL(const TQString &name, const TQString &path, KURL &url) const -{ - url = findBaseURL(name); - if (!url.isValid()) - { - return false; - } - - url.addPath(path); - return true; -} - bool AppImpl::statByName(const TQString &filename, TDEIO::UDSEntry &entry) { kdDebug() << "AppImpl::statByName" << endl; - TQStringList dirList; - dirList << "/usr/bin/"; - dirList << "/usr/local/bin/"; - dirList << "/opt/trinity/bin/"; + TQStringList dirList = TQStringList::split(":", getenv("PATH")); TQStringList names_found; for (const TQString &dirname : dirList) @@ -149,41 +132,6 @@ bool AppImpl::statByName(const TQString &filename, TDEIO::UDSEntry &entry) return false; } -KURL AppImpl::findBaseURL(const TQString &filename) const -{ - kdDebug() << "AppImpl::findBaseURL" << endl; - - TQStringList dirList = TDEGlobal::dirs()->resourceDirs("system_entries"); - for (const TQString &dirname : dirList) - { - TQDir dir(dirname); - if (!dir.exists()) - { - continue; - } - - TQStringList filenames = dir.entryList(TQDir::Files | TQDir::Readable); - TDEIO::UDSEntry entry; - for (const TQString &fname : filenames) - { - if (fname == filename + ".desktop") - { - KDesktopFile desktop(dirname + fname, true); - if (desktop.readURL().isEmpty()) - { - KURL url; - url.setPath(desktop.readPath()); - return url; - } - return desktop.readURL(); - } - } - } - - return KURL(); -} - - static void addAtom(TDEIO::UDSEntry &entry, unsigned int ID, long l, const TQString &s = TQString::null) { @@ -330,7 +278,6 @@ void AppImpl::createStandardDataDirEntry(TQValueList &list, TQStringList dirList; dirList << "/usr/share/"; dirList << "/usr/local/share/"; - dirList << "/opt/trinity/share/"; TQStringList StandardDataDir = getFullLocation(dirList, shortname, TQDir::FilterSpec(TQDir::Files | TQDir::Dirs | TQDir::Readable), true, false); if (StandardDataDir.isEmpty()) @@ -359,13 +306,33 @@ void AppImpl::createStandardDataDirEntry(TQValueList &list, void AppImpl::createTDEConfigEntry(TQValueList &list, TDEIO::UDSEntry &entry, const TQString &shortname) { + // Global TDE config + TQStringList dirList; + dirList << "/etc/trinity/"; + TQStringList TDEConfigFiles = getFullLocation(dirList, shortname + "rc", + TQDir::FilterSpec(TQDir::Files | TQDir::Dirs | TQDir::Readable), false, true); + + for (const TQString &filename : TDEConfigFiles) + { + 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); + } + } + + // Resource file TQString TDEDataDir = locate("config", shortname + "rc"); kdDebug() << "TDEDataDir: " << TDEDataDir << endl; if (TDEDataDir.isEmpty()) { return; } - entry.clear(); addAtom(entry, TDEIO::UDS_NAME, 0, i18n("Config File (%1)").arg(TDEDataDir)); addAtom(entry, TDEIO::UDS_URL, 0, TDEDataDir); @@ -382,7 +349,6 @@ void AppImpl::createStandardConfigEntry(TQValueList &list, TDEI dirList << "/etc/"; dirList << "/usr/etc/"; dirList << "/usr/local/etc/"; - dirList << "/opt/trinity/etc/"; TQStringList StandardConfigFile = getFullLocation(dirList,shortname, TQDir::FilterSpec(TQDir::Files | TQDir::Dirs | TQDir::Readable), true, false); if (StandardConfigFile.isEmpty()) @@ -414,7 +380,7 @@ void AppImpl::createStandardConfigEntry(TQValueList &list, TDEI addAtom(entry, TDEIO::UDS_NAME, 0, i18n("Config Data(%1)").arg(fname)); addAtom(entry, TDEIO::UDS_FILE_TYPE, S_IFDIR); addAtom(entry, TDEIO::UDS_MIME_TYPE, 0, "inode/directory"); - addAtom(entry, TDEIO::UDS_ICON_NAME, 0, "configfolder"); + addAtom(entry, TDEIO::UDS_ICON_NAME, 0, "folder"); } else { @@ -475,19 +441,48 @@ void AppImpl::createTmpDirEntry(TQValueList &list, TDEIO::UDSEn } } -void AppImpl::slotEntries(TDEIO::Job *job, const TDEIO::UDSEntryList &list) +void AppImpl::createXDGDirEntry(TQValueList &list, TDEIO::UDSEntry &entry, + const TQString &shortname) { - if (list.size() > 0) + TQStringList dirList; + dirList << TQString("%1/.config/").arg(getenv("HOME")); + TQStringList xdgDir = getFullLocation(dirList, shortname, + TQDir::FilterSpec(TQDir::Files | TQDir::Dirs | TQDir::Readable), false, true); + + for (const TQString &filename : xdgDir) { - job->kill(true); - m_lastListingEmpty = false; - tqApp->eventLoop()->exitLoop(); - } -} + if (filename.isEmpty()) + { + continue; + } -void AppImpl::slotResult(TDEIO::Job *) -{ - tqApp->eventLoop()->exitLoop(); + entry.clear(); + bool isFolder = false; + TQFileInfo fi(filename); + if (fi.isDir()) + { + isFolder = true; + } + + kdDebug() << "createXdgDirEntry: " << filename << endl; + + addAtom(entry, TDEIO::UDS_URL, 0, filename); + if (isFolder) + { + addAtom(entry, TDEIO::UDS_NAME, 0, i18n("XDG Config Data (%1)").arg(filename)); + addAtom(entry, TDEIO::UDS_FILE_TYPE, S_IFDIR); + addAtom(entry, TDEIO::UDS_MIME_TYPE, 0, "inode/directory"); + addAtom(entry, TDEIO::UDS_ICON_NAME, 0, "folder"); + } + else + { + addAtom(entry, TDEIO::UDS_NAME, 0, i18n("XDG Cconfig File (%1)").arg(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, "eraser"); + } + list.append(entry); + } } bool AppImpl::listAppContents(const TQString &name, TQValueList &list) @@ -499,16 +494,16 @@ bool AppImpl::listAppContents(const TQString &name, TQValueList // Create entry for binary file createExeEntry(list, entry, name, getAppAddress(name)); - // Create entry for man page - entry.clear(); - - // Create entry for apps data folder in home dir + // Create entry for data folder in home dir createHomeDirEntry(list, entry, 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); + // Create entry for TDE config and data folders createTDEConfigEntry(list, entry, name); createTDEDataDirEntry(list, entry, name); @@ -516,7 +511,7 @@ bool AppImpl::listAppContents(const TQString &name, TQValueList // Create entry for manual createManPageEntry(list, entry, name); - //Create entry for apps folder in home dir + //Create entry for folders in tmp dir createTmpDirEntry(list, entry, name); return true; @@ -534,9 +529,9 @@ TQStringList AppImpl::getFullLocation(const TQStringList &dirList, const TQStrin { TQMap knownApps; TQStringList finds; - for (const TQString &dirpath : dirList) + for (const TQString &dirname : dirList) { - TQDir dir = dirpath; + TQDir dir = dirname; if (!dir.exists()) { continue; @@ -547,21 +542,21 @@ TQStringList AppImpl::getFullLocation(const TQStringList &dirList, const TQStrin { if (recursive && filename != ".." && filename != ".") { - TQFileInfo fi(dirpath + filename); + TQFileInfo fi(dirname + filename); if (fi.isDir()) { TQStringList recurfinds; - recurfinds = getFullLocation(TQStringList(dirpath + filename + "/"), + recurfinds = getFullLocation(TQStringList(dirname + filename + "/"), name, filter, beginswith, recursive); if (!recurfinds.isEmpty()) { - for (const TQString &recurFilename : recurfinds) + for (const TQString &recurFullname : recurfinds) { - if (recurFilename.isEmpty()) - { - continue; - } - finds << recurFilename; + if (!knownApps.contains(recurFullname)) + { + knownApps[recurFullname] = true; + finds << recurFullname; + } } } } @@ -569,7 +564,7 @@ TQStringList AppImpl::getFullLocation(const TQStringList &dirList, const TQStrin if (name == filename || (beginswith && filename.startsWith(name))) { - TQString fullname = dirpath + filename; + TQString fullname = dirname + filename; if (!knownApps.contains(fullname)) { knownApps[fullname] = true; diff --git a/src/appimpl.h b/src/appimpl.h index f5dadcd..8402e15 100644 --- a/src/appimpl.h +++ b/src/appimpl.h @@ -50,15 +50,11 @@ public: bool listAppContents(const TQString &name, TQValueList &list); bool parseURL(const KURL &url, TQString &name, TQString &path) const; - bool realURL(const TQString &name, const TQString &path, KURL &url) const; int lastErrorCode() const { return m_lastErrorCode; } TQString lastErrorMessage() const { return m_lastErrorMessage; } private slots: - KURL findBaseURL(const TQString &filename) const; - void slotEntries(TDEIO::Job *job, const TDEIO::UDSEntryList &list); - void slotResult(TDEIO::Job *job); void createManPageEntry(TQValueList &list, TDEIO::UDSEntry &entry, const TQString &shortname); void createExeEntry(TQValueList &list, TDEIO::UDSEntry &entry, @@ -75,6 +71,8 @@ private slots: const TQString &shortname); void createTmpDirEntry(TQValueList &list, TDEIO::UDSEntry &entry, const TQString &shortname); + void createXDGDirEntry(TQValueList &list, TDEIO::UDSEntry &entry, + const TQString &shortname); TQStringList getAppAddress(const TQString &name); TQStringList getFullLocation(const TQStringList &dirList, const TQString &name,