You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tdeio-appinfo/src/app.cpp~

213 lines
4.3 KiB

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#include <qcstring.h>
#include <qsocket.h>
#include <qdatetime.h>
#include <qbitarray.h>
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <kinstance.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <klocale.h>
#include <kurl.h>
#include <ksock.h>
#include "app.h"
using namespace KIO;
extern "C"
{
int kdemain(int argc, char **argv)
{
KInstance instance( "kio_app" );
kdDebug(7101) << "*** Starting kio_app " << endl;
if (argc != 4) {
kdDebug(7101) << "Usage: kio_app protocol domain-socket1 domain-socket2" << endl;
exit(-1);
}
kio_appProtocol slave(argv[2], argv[3]);
slave.dispatchLoop();
kdDebug(7101) << "*** kio_app Done" << endl;
return 0;
}
}
kio_appProtocol::kio_appProtocol(const QCString &pool_socket, const QCString &app_socket)
: SlaveBase("kio_app", pool_socket, app_socket)
{
kdDebug() << "kio_appProtocol::kio_appProtocol()" << endl;
}
kio_appProtocol::~kio_appProtocol()
{
kdDebug() << "kio_appProtocol::~kio_appProtocol()" << endl;
}
void kio_appProtocol::stat(const KURL &url)
{
kdDebug() << "kio_appProtocol::stat: " << url << endl;
QString path = url.path();
if ( path.isEmpty() || path == "/" )
{
kdDebug() << "kio_appProtocol::stat: " << "creating top level entry" << endl;
// The root is "virtual" - it's not a single physical directory
KIO::UDSEntry entry;
m_impl.createTopLevelEntry( entry );
statEntry( entry );
finished();
return;
}
QString name;
bool ok = m_impl.parseURL(url, name, path);
if ( !ok )
{
kdDebug() << "kio_appProtocol::stat: " << "can't parse url" << endl;
error(KIO::ERR_MALFORMED_URL, url.prettyURL());
return;
}
if( path.isEmpty() )
{
kdDebug() << "kio_appProtocol::stat4: " << "url empty after parsing" << endl;
KIO::UDSEntry entry;
if ( m_impl.statByName(name, entry) )
{
statEntry(entry);
finished();
}
else
{
error(KIO::ERR_DOES_NOT_EXIST, url.prettyURL());
}
}
else
{
kdDebug() << "kio_appProtocol::stat4: " << "url not empty after parsing: statting" << endl;
SlaveBase::stat(url);
}
}
void kio_appProtocol::listDir(const KURL &url)
{
kdDebug() << "kio_appProtocol::listDir: " << url << endl;
if ( url.path().length() <= 1 )
{
kdDebug() << "kio_appProtocol::listDir: " << "url empty: listing root" << endl;
listRoot();
return;
}
QString name, path;
bool ok = m_impl.parseURL(url, name, path);
if ( !ok )
{
error(KIO::ERR_MALFORMED_URL, url.prettyURL());
return;
}
kdDebug() << "kio_appProtocol::listDir: " << "url is " << url << ": doing a listDir" << endl;
kdDebug() << "kio_appProtocol::listDir: " << "name is " << name << ": doing a listDir" << endl;
kdDebug() << "kio_appProtocol::listDir: " << "path is " << path << ": doing a listDir" << endl;
// We've been given something like app:/appname
listAppContents(name);
}
void kio_appProtocol::listRoot()
{
KIO::UDSEntry entry;
KIO::UDSEntryList system_entries;
bool ok = m_impl.listRoot(system_entries);
if (!ok)
{
error( m_impl.lastErrorCode(), m_impl.lastErrorMessage() );
return;
}
totalSize(system_entries.count()+1);
m_impl.createTopLevelEntry(entry);
listEntry(entry, false);
KIO::UDSEntryListIterator it = system_entries.begin();
KIO::UDSEntryListIterator end = system_entries.end();
for(; it!=end; ++it)
{
listEntry(*it, false);
}
entry.clear();
listEntry(entry, true);
finished();
}
void kio_appProtocol::listAppContents(const QString &name)
{
KIO::UDSEntry entry;
KIO::UDSEntryList app_entries;
bool ok = m_impl.listAppContents(name, app_entries);
if (!ok)
{
error( m_impl.lastErrorCode(), m_impl.lastErrorMessage() );
return;
}
totalSize(app_entries.count()+1);
m_impl.createTopLevelEntry(entry);
listEntry(entry, false);
KIO::UDSEntryListIterator it = app_entries.begin();
KIO::UDSEntryListIterator end = app_entries.end();
for(; it!=end; ++it)
{
listEntry(*it, false);
}
entry.clear();
listEntry(entry, true);
finished();
}