Improve user experience when requesting the list of available

applications with 'appinfo:/' (makes Konqueror less irresponsive).
Some code renaming for better clarity.

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

@ -18,6 +18,7 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/ ***************************************************************************/
#include "appinfo.h"
#include "appimpl.h" #include "appimpl.h"
#include <stdlib.h> #include <stdlib.h>
@ -33,39 +34,54 @@
#include <tdeio/job.h> #include <tdeio/job.h>
AppImpl::AppImpl() : TQObject() AppImpl::AppImpl(TDEIO_AppInfo *slave) : TQObject(), m_slave(slave)
{ {
} }
bool AppImpl::listRoot(TQValueList<TDEIO::UDSEntry> &list) void AppImpl::listRoot()
{ {
kdDebug() << "AppImpl::listRoot" << endl; kdDebug() << "AppImpl::listRoot" << endl;
//TQStringList dirList = TQStringList::split(":", getenv("PATH")); // Top level entry
TQStringList dirList; TDEIO::UDSEntry entry;
dirList << "/opt/trinity/bin/"; createTopLevelEntry(entry);
dirList << "/usr/bin/"; m_slave->listEntry(entry, false);
dirList << "/usr/local/bin/";
kdDebug() << dirList << endl; //TQStringList dirList = TQStringList::split(":", getenv("PATH"));
TQStringList dirList;
for (const TQString &dirName : dirList) dirList << "/opt/trinity/bin/";
{ dirList << "/usr/bin/";
TQDir dir(dirName); dirList << "/usr/local/bin/";
if (!dir.exists()) kdDebug() << dirList << endl;
{
continue; TQValueList<TDEIO::UDSEntry> list;
} for (const TQString &dirName : dirList)
{
TQStringList filenames = dir.entryList(TQDir::Files | TQDir::Readable); TQDir dir(dirName);
TDEIO::UDSEntry entry; if (!dir.exists())
for (const TQString &filename : filenames) {
{ continue;
createEntry(entry, filename); }
list.append(entry);
} TQStringList filenames = dir.entryList(TQDir::Files | TQDir::Readable);
} TDEIO::UDSEntry entry;
for (const TQString &filename : filenames)
return true; {
createEntry(entry, filename);
list.append(entry);
if (list.count() >= 50)
{
m_slave->listEntries(list);
list.clear();
}
}
}
if (list.count() > 0)
{
m_slave->listEntries(list);
list.clear();
}
m_slave->finished();
} }
bool AppImpl::parseURL(const KURL &url, TQString &name, TQString &path) const bool AppImpl::parseURL(const KURL &url, TQString &name, TQString &path) const

@ -33,6 +33,7 @@ namespace TDEIO
} }
class KURL; class KURL;
class TDEIO_AppInfo;
class AppImpl : public TQObject class AppImpl : public TQObject
@ -40,12 +41,12 @@ class AppImpl : public TQObject
Q_OBJECT Q_OBJECT
public: public:
AppImpl(); AppImpl(TDEIO_AppInfo *slave);
void createTopLevelEntry(TDEIO::UDSEntry &entry) const; void createTopLevelEntry(TDEIO::UDSEntry &entry) const;
bool statByName(const TQString &filename, TDEIO::UDSEntry &entry); bool statByName(const TQString &filename, TDEIO::UDSEntry &entry);
bool listRoot(TQValueList<TDEIO::UDSEntry> &list); void listRoot();
bool listAppContents(const TQString &name, TQValueList<TDEIO::UDSEntry> &list); bool listAppContents(const TQString &name, TQValueList<TDEIO::UDSEntry> &list);
bool parseURL(const KURL &url, TQString &name, TQString &path) const; bool parseURL(const KURL &url, TQString &name, TQString &path) const;
@ -82,6 +83,7 @@ private:
void createEntry(TDEIO::UDSEntry& entry, const TQString &file); void createEntry(TDEIO::UDSEntry& entry, const TQString &file);
bool m_lastListingEmpty; bool m_lastListingEmpty;
TDEIO_AppInfo *m_slave;
/// Last error code stored in class to simplify API. /// Last error code stored in class to simplify API.
/// Note that this means almost no method can be const. /// Note that this means almost no method can be const.

@ -43,34 +43,34 @@ extern "C"
} }
TDEInstance instance("tdeio_appinfo"); TDEInstance instance("tdeio_appinfo");
tdeio_appInfoProtocol slave(argv[2], argv[3]); TDEIO_AppInfo slave(argv[2], argv[3]);
slave.dispatchLoop(); slave.dispatchLoop();
return 0; return 0;
} }
} }
tdeio_appInfoProtocol::tdeio_appInfoProtocol(const TQCString &pool_socket, TDEIO_AppInfo::TDEIO_AppInfo(const TQCString &pool_socket, const TQCString &app_socket)
const TQCString &app_socket) : SlaveBase("tdeio_appinfo", pool_socket, app_socket) : SlaveBase("tdeio_appinfo", pool_socket, app_socket), m_impl(this)
{ {
kdDebug() << "tdeio_appInfoProtocol::tdeio_appInfoProtocol()" << endl; kdDebug() << "TDEIO_AppInfo::TDEIO_AppInfo()" << endl;
} }
tdeio_appInfoProtocol::~tdeio_appInfoProtocol() TDEIO_AppInfo::~TDEIO_AppInfo()
{ {
kdDebug() << "tdeio_appInfoProtocol::~tdeio_appInfoProtocol()" << endl; kdDebug() << "TDEIO_AppInfo::~TDEIO_AppInfo()" << endl;
} }
void tdeio_appInfoProtocol::stat(const KURL &url) void TDEIO_AppInfo::stat(const KURL &url)
{ {
kdDebug() << "tdeio_appInfoProtocol::stat: " << url << endl; kdDebug() << "TDEIO_AppInfo::stat: " << url << endl;
TQString path = url.path(); TQString path = url.path();
if (path.isEmpty() || path == "/") if (path.isEmpty() || path == "/")
{ {
kdDebug() << "tdeio_appInfoProtocol::stat: " << "creating top level entry" << endl; kdDebug() << "TDEIO_AppInfo::stat: " << "creating top level entry" << endl;
// The root is "virtual" - it's not a single physical directory // The root is "virtual" - it's not a single physical directory
TDEIO::UDSEntry entry; TDEIO::UDSEntry entry;
m_impl.createTopLevelEntry(entry); m_impl.createTopLevelEntry(entry);
@ -83,14 +83,14 @@ void tdeio_appInfoProtocol::stat(const KURL &url)
bool ok = m_impl.parseURL(url, name, path); bool ok = m_impl.parseURL(url, name, path);
if (!ok) if (!ok)
{ {
kdDebug() << "tdeio_appInfoProtocol::stat: " << "can't parse url" << endl; kdDebug() << "TDEIO_AppInfo::stat: " << "can't parse url" << endl;
error(TDEIO::ERR_MALFORMED_URL, url.prettyURL()); error(TDEIO::ERR_MALFORMED_URL, url.prettyURL());
return; return;
} }
if (path.isEmpty()) if (path.isEmpty())
{ {
kdDebug() << "tdeio_appInfoProtocol::stat: " << "url empty after parsing" << endl; kdDebug() << "TDEIO_AppInfo::stat: " << "url empty after parsing" << endl;
TDEIO::UDSEntry entry; TDEIO::UDSEntry entry;
if (m_impl.statByName(name, entry)) if (m_impl.statByName(name, entry))
@ -105,18 +105,18 @@ void tdeio_appInfoProtocol::stat(const KURL &url)
} }
else else
{ {
kdDebug() << "tdeio_appInfoProtocol::stat: " << "url not empty after parsing: statting" << endl; kdDebug() << "TDEIO_AppInfo::stat: " << "url not empty after parsing: statting" << endl;
SlaveBase::stat(url); SlaveBase::stat(url);
} }
} }
void tdeio_appInfoProtocol::listDir(const KURL &url) void TDEIO_AppInfo::listDir(const KURL &url)
{ {
kdDebug() << "tdeio_appInfoProtocol::listDir: " << url << endl; kdDebug() << "TDEIO_AppInfo::listDir: " << url << endl;
if (url.path().length() <= 1) if (url.path().length() <= 1)
{ {
kdDebug() << "tdeio_appInfoProtocol::listDir: " << "url empty: listing root" << endl; kdDebug() << "TDEIO_AppInfo::listDir: " << "url empty: listing root" << endl;
listRoot(); listRoot();
return; return;
} }
@ -129,33 +129,19 @@ void tdeio_appInfoProtocol::listDir(const KURL &url)
return; return;
} }
kdDebug() << "tdeio_appInfoProtocol::listDir: " << "name is " << name << endl; kdDebug() << "TDEIO_AppInfo::listDir: " << "name is " << name << endl;
kdDebug() << "tdeio_appInfoProtocol::listDir: " << "path is " << path << endl; kdDebug() << "TDEIO_AppInfo::listDir: " << "path is " << path << endl;
// We've been given something like appinfo:/name // We've been given something like appinfo:/name
listAppContents(name); listAppContents(name);
} }
void tdeio_appInfoProtocol::listRoot() void TDEIO_AppInfo::listRoot()
{ {
TDEIO::UDSEntryList system_entries; m_impl.listRoot();
bool ok = m_impl.listRoot(system_entries);
if (!ok)
{
error(m_impl.lastErrorCode(), m_impl.lastErrorMessage());
return;
}
totalSize(system_entries.count() + 1);
TDEIO::UDSEntry entry;
m_impl.createTopLevelEntry(entry);
listEntry(entry, false);
listEntries(system_entries);
finished();
} }
void tdeio_appInfoProtocol::listAppContents(const TQString &name) void TDEIO_AppInfo::listAppContents(const TQString &name)
{ {
TDEIO::UDSEntryList app_entries; TDEIO::UDSEntryList app_entries;
bool ok = m_impl.listAppContents(name, app_entries); bool ok = m_impl.listAppContents(name, app_entries);

@ -29,11 +29,11 @@ class TQCString;
class TQString; class TQString;
class KURL; class KURL;
class tdeio_appInfoProtocol : public TDEIO::SlaveBase class TDEIO_AppInfo : public TDEIO::SlaveBase
{ {
public: public:
tdeio_appInfoProtocol(const TQCString &pool_socket, const TQCString &app_socket); TDEIO_AppInfo(const TQCString &pool_socket, const TQCString &app_socket);
virtual ~tdeio_appInfoProtocol(); virtual ~TDEIO_AppInfo();
virtual void listDir(const KURL &url); virtual void listDir(const KURL &url);
virtual void stat(const KURL &url); virtual void stat(const KURL &url);

Loading…
Cancel
Save