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