SVN commit 558732 by carewolf: The beginnings of File::open M +82 -2 file.cc M +1 -0 file.h --- branches/work/kio_virtualfile/kioslave/file/file.cc #558731:558732 @@ -339,6 +339,86 @@ finished(); } +void FileProtocol::open( const KUrl& url ) +{ + QByteArray _path( QFile::encodeName(url.path())); + KDE_struct_stat buff; + if ( KDE_stat( _path.data(), &buff ) == -1 ) { + if ( errno == EACCES ) + error( KIO::ERR_ACCESS_DENIED, url.path() ); + else + error( KIO::ERR_DOES_NOT_EXIST, url.path() ); + return; + } + + if ( S_ISDIR( buff.st_mode ) ) { + error( KIO::ERR_IS_DIRECTORY, url.path() ); + return; + } + if ( !S_ISREG( buff.st_mode ) ) { + error( KIO::ERR_CANNOT_OPEN_FOR_READING, url.path() ); + return; + } + + int fd = KDE_open( _path.data(), O_RDONLY); + if ( fd < 0 ) { + error( KIO::ERR_CANNOT_OPEN_FOR_READING, url.path() ); + return; + } + // Determine the mimetype of the file to be retrieved, and emit it. + // This is mandatory in all slaves (for KRun/BrowserRun to work). + KMimeType::Ptr mt = KMimeType::findByURL( url, buff.st_mode, true /* local URL */ ); + emit mimeType( mt->name() ); + + totalSize( buff.st_size ); + + emit file(fd); + + QByteArray array; + + // Command-loop: + int cmd = CMD_NONE; + while (true) { + QByteArray data; + appconn->read(&cmd, data); + QDataStream stream( data ); + switch( command ) { + case CMD_READ: { + char buffer[ bytes ]; + int bytes; + stream >> bytes; + ::read(fd, buffer, bytes); + array = array.fromRawData(buffer, n); + data( array ); + array.clear(); + break; + } + case CMD_WRITE: {/* + QByteArray buffer; + dataReq(); // Request for data + result = readData( buffer ); + + if (result >= 0) + { + */ + break; + } + case CMD_SEEK: { + int offset; + stream >> offset; + KDE_seek(fd, offset); + } + case CMD_CLOSE: + close( fd ); + finished(); + break; + default: + // wrong command + } + if (cmd == CMD_CLOSE) break; + } +} + static int write_all(int fd, const char *buf, size_t len) { @@ -622,7 +702,7 @@ return; } - if ( same_inode( buff_dest, buff_src) ) + if ( same_inode( buff_dest, buff_src) ) { error( KIO::ERR_IDENTICAL_FILES, dest.path() ); return; @@ -835,7 +915,7 @@ return; } - if ( same_inode( buff_dest, buff_src) ) + if ( same_inode( buff_dest, buff_src) ) { error( KIO::ERR_IDENTICAL_FILES, dest.path() ); return; --- branches/work/kio_virtualfile/kioslave/file/file.h #558731:558732 @@ -61,6 +61,7 @@ virtual void mkdir( const KUrl& url, int permissions ); virtual void chmod( const KUrl& url, int permissions ); virtual void del( const KUrl& url, bool isfile); + virtual void open( const KUrl& url ); /** * Special commands supported by this slave: