Search apps in user's PATH.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
r14.0.x
Michele Calgaro 2 years ago
parent aacfa49889
commit ffa531ae90
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -25,6 +25,7 @@
#include <tqapplication.h> #include <tqapplication.h>
#include <tqeventloop.h> #include <tqeventloop.h>
#include <tqmap.h>
#include <kdebug.h> #include <kdebug.h>
#include <kstandarddirs.h> #include <kstandarddirs.h>
@ -47,17 +48,14 @@ void AppImpl::listRoot()
createTopLevelEntry(entry); createTopLevelEntry(entry);
m_slave->listEntry(entry, false); m_slave->listEntry(entry, false);
//TQStringList dirList = TQStringList::split(":", getenv("PATH")); TQStringList dirList = TQStringList::split(":", getenv("PATH"));
TQStringList dirList;
dirList << "/opt/trinity/bin/";
dirList << "/usr/bin/";
dirList << "/usr/local/bin/";
kdDebug() << dirList << endl; kdDebug() << dirList << endl;
TQMap<TQString, bool> knownApps;
TQValueList<TDEIO::UDSEntry> list; TQValueList<TDEIO::UDSEntry> list;
for (const TQString &dirName : dirList) for (const TQString &dirname : dirList)
{ {
TQDir dir(dirName); TQDir dir(dirname);
if (!dir.exists()) if (!dir.exists())
{ {
continue; continue;
@ -67,6 +65,10 @@ void AppImpl::listRoot()
TDEIO::UDSEntry entry; TDEIO::UDSEntry entry;
for (const TQString &filename : filenames) for (const TQString &filename : filenames)
{ {
TQString fullname = dirname + filename;
if (!knownApps.contains(fullname))
{
knownApps[fullname] = true;
createEntry(entry, filename); createEntry(entry, filename);
list.append(entry); list.append(entry);
if (list.count() >= 50) if (list.count() >= 50)
@ -76,6 +78,7 @@ void AppImpl::listRoot()
} }
} }
} }
}
if (list.count() > 0) if (list.count() > 0)
{ {
m_slave->listEntries(list); m_slave->listEntries(list);
@ -124,9 +127,9 @@ bool AppImpl::statByName(const TQString &filename, TDEIO::UDSEntry &entry)
dirList << "/opt/trinity/bin/"; dirList << "/opt/trinity/bin/";
TQStringList names_found; TQStringList names_found;
for (const TQString &dirName : dirList) for (const TQString &dirname : dirList)
{ {
TQDir dir(dirName); TQDir dir(dirname);
if (!dir.exists()) if (!dir.exists())
{ {
continue; continue;
@ -151,9 +154,9 @@ KURL AppImpl::findBaseURL(const TQString &filename) const
kdDebug() << "AppImpl::findBaseURL" << endl; kdDebug() << "AppImpl::findBaseURL" << endl;
TQStringList dirList = TDEGlobal::dirs()->resourceDirs("system_entries"); TQStringList dirList = TDEGlobal::dirs()->resourceDirs("system_entries");
for (const TQString &dirName : dirList) for (const TQString &dirname : dirList)
{ {
TQDir dir(dirName); TQDir dir(dirname);
if (!dir.exists()) if (!dir.exists())
{ {
continue; continue;
@ -165,7 +168,7 @@ KURL AppImpl::findBaseURL(const TQString &filename) const
{ {
if (fname == filename + ".desktop") if (fname == filename + ".desktop")
{ {
KDesktopFile desktop(dirName + fname, true); KDesktopFile desktop(dirname + fname, true);
if (desktop.readURL().isEmpty()) if (desktop.readURL().isEmpty())
{ {
KURL url; KURL url;
@ -489,7 +492,6 @@ void AppImpl::slotResult(TDEIO::Job *)
bool AppImpl::listAppContents(const TQString &name, TQValueList<TDEIO::UDSEntry> &list) bool AppImpl::listAppContents(const TQString &name, TQValueList<TDEIO::UDSEntry> &list)
{ {
tqWarning("MIKE AppImpl::listAppContents name="+name);
kdDebug() << "AppImpl::listAppContents" << endl; kdDebug() << "AppImpl::listAppContents" << endl;
TDEIO::UDSEntry entry; TDEIO::UDSEntry entry;
@ -522,10 +524,7 @@ tqWarning("MIKE AppImpl::listAppContents name="+name);
TQStringList AppImpl::getAppAddress(const TQString &name) TQStringList AppImpl::getAppAddress(const TQString &name)
{ {
TQStringList dirList; TQStringList dirList = TQStringList::split(":", getenv("PATH"));
dirList << "/opt/trinity/bin/";
dirList << "/usr/bin/";
dirList << "/usr/local/bin/";
return getFullLocation(dirList, name, return getFullLocation(dirList, name,
TQDir::FilterSpec(TQDir::Files | TQDir::Readable), false, false); TQDir::FilterSpec(TQDir::Files | TQDir::Readable), false, false);
@ -533,6 +532,7 @@ TQStringList AppImpl::getAppAddress(const TQString &name)
TQStringList AppImpl::getFullLocation(const TQStringList &dirList, const TQString &name, TQStringList AppImpl::getFullLocation(const TQStringList &dirList, const TQString &name,
const TQDir::FilterSpec &filter, bool beginswith, bool recursive) const TQDir::FilterSpec &filter, bool beginswith, bool recursive)
{ {
TQMap<TQString, bool> knownApps;
TQStringList finds; TQStringList finds;
for (const TQString &dirpath : dirList) for (const TQString &dirpath : dirList)
{ {
@ -569,7 +569,12 @@ TQStringList AppImpl::getFullLocation(const TQStringList &dirList, const TQStrin
if (name == filename || (beginswith && filename.startsWith(name))) if (name == filename || (beginswith && filename.startsWith(name)))
{ {
finds << dirpath + filename; TQString fullname = dirpath + filename;
if (!knownApps.contains(fullname))
{
knownApps[fullname] = true;
finds << fullname;
}
} }
} }
} }

Loading…
Cancel
Save