From 3a75bdfe83b71ef1dbc2fbf52f2d18b8174e22e5 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Tue, 15 Dec 2020 11:30:44 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro --- tdeioslave/mbox/CMakeLists.txt | 2 +- tdeioslave/mbox/Makefile.am | 10 +- tdeioslave/mbox/mbox.cc | 168 --------------------------------- tdeioslave/mbox/mbox.cpp | 168 +++++++++++++++++++++++++++++++++ tdeioslave/mbox/mboxfile.cc | 45 --------- tdeioslave/mbox/mboxfile.cpp | 45 +++++++++ tdeioslave/mbox/readmbox.cc | 204 ----------------------------------------- tdeioslave/mbox/readmbox.cpp | 204 +++++++++++++++++++++++++++++++++++++++++ tdeioslave/mbox/stat.cc | 115 ----------------------- tdeioslave/mbox/stat.cpp | 115 +++++++++++++++++++++++ tdeioslave/mbox/urlinfo.cc | 133 --------------------------- tdeioslave/mbox/urlinfo.cpp | 133 +++++++++++++++++++++++++++ 12 files changed, 671 insertions(+), 671 deletions(-) delete mode 100644 tdeioslave/mbox/mbox.cc create mode 100644 tdeioslave/mbox/mbox.cpp delete mode 100644 tdeioslave/mbox/mboxfile.cc create mode 100644 tdeioslave/mbox/mboxfile.cpp delete mode 100644 tdeioslave/mbox/readmbox.cc create mode 100644 tdeioslave/mbox/readmbox.cpp delete mode 100644 tdeioslave/mbox/stat.cc create mode 100644 tdeioslave/mbox/stat.cpp delete mode 100644 tdeioslave/mbox/urlinfo.cc create mode 100644 tdeioslave/mbox/urlinfo.cpp (limited to 'tdeioslave/mbox') diff --git a/tdeioslave/mbox/CMakeLists.txt b/tdeioslave/mbox/CMakeLists.txt index 70da626f9..27e51538a 100644 --- a/tdeioslave/mbox/CMakeLists.txt +++ b/tdeioslave/mbox/CMakeLists.txt @@ -34,7 +34,7 @@ tde_create_translated_desktop( tde_add_kpart( tdeio_mbox SOURCES - mbox.cc mboxfile.cc readmbox.cc stat.cc urlinfo.cc + mbox.cpp mboxfile.cpp readmbox.cpp stat.cpp urlinfo.cpp LINK tdeio-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/tdeioslave/mbox/Makefile.am b/tdeioslave/mbox/Makefile.am index b95ae1b5e..b890ebf34 100644 --- a/tdeioslave/mbox/Makefile.am +++ b/tdeioslave/mbox/Makefile.am @@ -7,11 +7,11 @@ METASOURCES = AUTO kde_module_LTLIBRARIES = tdeio_mbox.la tdeio_mbox_la_SOURCES = \ - mbox.cc \ - mboxfile.cc \ - readmbox.cc \ - stat.cc \ - urlinfo.cc + mbox.cpp \ + mboxfile.cpp \ + readmbox.cpp \ + stat.cpp \ + urlinfo.cpp tdeio_mbox_la_LIBADD = $(LIB_TDEIO) $(LIB_TQT) $(LIB_TDECORE) tdeio_mbox_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) -module $(KDE_PLUGIN) diff --git a/tdeioslave/mbox/mbox.cc b/tdeioslave/mbox/mbox.cc deleted file mode 100644 index 5742baffd..000000000 --- a/tdeioslave/mbox/mbox.cc +++ /dev/null @@ -1,168 +0,0 @@ -/* - * This is a simple tdeioslave to handle mbox-files. - * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "mbox.h" - -#include "readmbox.h" -#include "stat.h" -#include "urlinfo.h" - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "tdepimmacros.h" - -#include "mbox.h" - -extern "C" { KDE_EXPORT int kdemain(int argc, char* argv[]); } - -int kdemain( int argc, char * argv[] ) -{ - TDELocale::setMainCatalogue("tdelibs"); - TDEInstance instance("tdeio_mbox"); - (void) TDEGlobal::locale(); - - if (argc != 4) { - fprintf(stderr, "Usage: tdeio_mbox protocol " - "domain-socket1 domain-socket2\n"); - exit(-1); - } - - MBoxProtocol slave(argv[2], argv[3]); - slave.dispatchLoop(); - - return 0; -} - -MBoxProtocol::MBoxProtocol( const TQCString& arg1, const TQCString& arg2 ) - : TDEIO::SlaveBase( "mbox2", arg1, arg2 ), - m_errorState( true ) -{ - -} - -MBoxProtocol::~MBoxProtocol() -{ -} - -void MBoxProtocol::get( const KURL& url ) -{ - m_errorState = false; - - UrlInfo info( url, UrlInfo::message ); - TQString line; - TQByteArray ba_line; - - if( info.type() == UrlInfo::invalid && !m_errorState ) - { - error( TDEIO::ERR_DOES_NOT_EXIST, info.url() ); - return; - } - - ReadMBox mbox( &info, this ); - - while( !mbox.atEnd() && !m_errorState) - { - line = mbox.currentLine(); - line += '\n'; - ba_line = TQCString( line.utf8() ); - ba_line.truncate( ba_line.size() - 1 ); //Removing training '\0' - data( ba_line ); - mbox.nextLine(); - }; - - if( !m_errorState ) - { - data( TQByteArray() ); - finished(); - } -} - -void MBoxProtocol::listDir( const KURL& url ) -{ - m_errorState = false; - - TDEIO::UDSEntry entry; - UrlInfo info( url, UrlInfo::directory ); - ReadMBox mbox( &info, this, hasMetaData( "onlynew" ), hasMetaData( "savetime" ) ); - - if( m_errorState ) - return; - - if( info.type() != UrlInfo::directory ) - { - error( TDEIO::ERR_DOES_NOT_EXIST, info.url() ); - return; - } - - while( !mbox.atEnd() && !m_errorState ) - { - entry = Stat::stat( mbox, info ); - if( mbox.inListing() ) - listEntry( entry, false ); - } - - listEntry( TDEIO::UDSEntry(), true ); - finished(); -} - -void MBoxProtocol::stat( const KURL& url ) -{ - UrlInfo info( url ); - if( info.type() == UrlInfo::invalid ) - { - error( TDEIO::ERR_DOES_NOT_EXIST, url.path() ); - return; - } else - { - statEntry( Stat::stat( info ) ); - } - finished(); -} - -void MBoxProtocol::mimetype( const KURL& url ) -{ - m_errorState = false; - - UrlInfo info( url ); - - if( m_errorState ) - return; - - if( info.type() == UrlInfo::invalid ) - error( TDEIO::ERR_DOES_NOT_EXIST, i18n( "Invalid URL" ) ); - else - mimeType( info.mimetype() ); - finished(); -} - -void MBoxProtocol::emitError( int errno, const TQString& arg ) -{ - m_errorState = true; - error( errno, arg ); -} - diff --git a/tdeioslave/mbox/mbox.cpp b/tdeioslave/mbox/mbox.cpp new file mode 100644 index 000000000..5742baffd --- /dev/null +++ b/tdeioslave/mbox/mbox.cpp @@ -0,0 +1,168 @@ +/* + * This is a simple tdeioslave to handle mbox-files. + * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "mbox.h" + +#include "readmbox.h" +#include "stat.h" +#include "urlinfo.h" + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "tdepimmacros.h" + +#include "mbox.h" + +extern "C" { KDE_EXPORT int kdemain(int argc, char* argv[]); } + +int kdemain( int argc, char * argv[] ) +{ + TDELocale::setMainCatalogue("tdelibs"); + TDEInstance instance("tdeio_mbox"); + (void) TDEGlobal::locale(); + + if (argc != 4) { + fprintf(stderr, "Usage: tdeio_mbox protocol " + "domain-socket1 domain-socket2\n"); + exit(-1); + } + + MBoxProtocol slave(argv[2], argv[3]); + slave.dispatchLoop(); + + return 0; +} + +MBoxProtocol::MBoxProtocol( const TQCString& arg1, const TQCString& arg2 ) + : TDEIO::SlaveBase( "mbox2", arg1, arg2 ), + m_errorState( true ) +{ + +} + +MBoxProtocol::~MBoxProtocol() +{ +} + +void MBoxProtocol::get( const KURL& url ) +{ + m_errorState = false; + + UrlInfo info( url, UrlInfo::message ); + TQString line; + TQByteArray ba_line; + + if( info.type() == UrlInfo::invalid && !m_errorState ) + { + error( TDEIO::ERR_DOES_NOT_EXIST, info.url() ); + return; + } + + ReadMBox mbox( &info, this ); + + while( !mbox.atEnd() && !m_errorState) + { + line = mbox.currentLine(); + line += '\n'; + ba_line = TQCString( line.utf8() ); + ba_line.truncate( ba_line.size() - 1 ); //Removing training '\0' + data( ba_line ); + mbox.nextLine(); + }; + + if( !m_errorState ) + { + data( TQByteArray() ); + finished(); + } +} + +void MBoxProtocol::listDir( const KURL& url ) +{ + m_errorState = false; + + TDEIO::UDSEntry entry; + UrlInfo info( url, UrlInfo::directory ); + ReadMBox mbox( &info, this, hasMetaData( "onlynew" ), hasMetaData( "savetime" ) ); + + if( m_errorState ) + return; + + if( info.type() != UrlInfo::directory ) + { + error( TDEIO::ERR_DOES_NOT_EXIST, info.url() ); + return; + } + + while( !mbox.atEnd() && !m_errorState ) + { + entry = Stat::stat( mbox, info ); + if( mbox.inListing() ) + listEntry( entry, false ); + } + + listEntry( TDEIO::UDSEntry(), true ); + finished(); +} + +void MBoxProtocol::stat( const KURL& url ) +{ + UrlInfo info( url ); + if( info.type() == UrlInfo::invalid ) + { + error( TDEIO::ERR_DOES_NOT_EXIST, url.path() ); + return; + } else + { + statEntry( Stat::stat( info ) ); + } + finished(); +} + +void MBoxProtocol::mimetype( const KURL& url ) +{ + m_errorState = false; + + UrlInfo info( url ); + + if( m_errorState ) + return; + + if( info.type() == UrlInfo::invalid ) + error( TDEIO::ERR_DOES_NOT_EXIST, i18n( "Invalid URL" ) ); + else + mimeType( info.mimetype() ); + finished(); +} + +void MBoxProtocol::emitError( int errno, const TQString& arg ) +{ + m_errorState = true; + error( errno, arg ); +} + diff --git a/tdeioslave/mbox/mboxfile.cc b/tdeioslave/mbox/mboxfile.cc deleted file mode 100644 index 7297457ef..000000000 --- a/tdeioslave/mbox/mboxfile.cc +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This is a simple tdeioslave to handle mbox-files. - * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "mboxfile.h" - -#include - -MBoxFile::MBoxFile( const UrlInfo* info, MBoxProtocol* parent ) - : m_info( info ), - m_mbox( parent ) -{ - assert( m_info ); -} - -MBoxFile::~MBoxFile() -{ -} - -bool MBoxFile::lock() -{ - //Not implemented - return true; -} - -void MBoxFile::unlock() -{ - //Not implemented -} - - diff --git a/tdeioslave/mbox/mboxfile.cpp b/tdeioslave/mbox/mboxfile.cpp new file mode 100644 index 000000000..7297457ef --- /dev/null +++ b/tdeioslave/mbox/mboxfile.cpp @@ -0,0 +1,45 @@ +/* + * This is a simple tdeioslave to handle mbox-files. + * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "mboxfile.h" + +#include + +MBoxFile::MBoxFile( const UrlInfo* info, MBoxProtocol* parent ) + : m_info( info ), + m_mbox( parent ) +{ + assert( m_info ); +} + +MBoxFile::~MBoxFile() +{ +} + +bool MBoxFile::lock() +{ + //Not implemented + return true; +} + +void MBoxFile::unlock() +{ + //Not implemented +} + + diff --git a/tdeioslave/mbox/readmbox.cc b/tdeioslave/mbox/readmbox.cc deleted file mode 100644 index 942f369e5..000000000 --- a/tdeioslave/mbox/readmbox.cc +++ /dev/null @@ -1,204 +0,0 @@ -/* - * This is a simple tdeioslave to handle mbox-files. - * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include - -#include "readmbox.h" - -#include "mbox.h" -#include "urlinfo.h" - -#include -#include - -#include -#include -#include -#include - -#ifdef HAVE_SYS_TYPES_H -#include -#endif - -#include - -ReadMBox::ReadMBox( const UrlInfo* info, MBoxProtocol* parent, bool onlynew, bool savetime ) - : MBoxFile( info, parent ), - m_file( 0 ), - m_stream( 0 ), - m_current_line( new TQString( TQString() ) ), - m_current_id( new TQString( TQString() ) ), - m_atend( true ), - m_prev_time( 0 ), - m_only_new( onlynew ), - m_savetime( savetime ), - m_status( false ), - m_prev_status( false ), - m_header( true ) - -{ - if( m_info->type() == UrlInfo::invalid ) - m_mbox->emitError( TDEIO::ERR_DOES_NOT_EXIST, info->url() ); - - if( !open( savetime ) ) - m_mbox->emitError( TDEIO::ERR_CANNOT_OPEN_FOR_READING, info->url() ); - - if( m_info->type() == UrlInfo::message ) - if( !searchMessage( m_info->id() ) ) - m_mbox->emitError( TDEIO::ERR_DOES_NOT_EXIST, info->url() ); -} - -ReadMBox::~ReadMBox() -{ - delete m_current_line; - close(); -} - -TQString ReadMBox::currentLine() const -{ - return *m_current_line; -} - -TQString ReadMBox::currentID() const -{ - return *m_current_id; -} - -bool ReadMBox::nextLine() -{ - if( !m_stream ) - return true; - - *m_current_line = m_stream->readLine(); - m_atend = m_current_line->isNull(); - if( m_atend ) // Cursor was at EOF - { - *m_current_id = TQString(); - m_prev_status = m_status; - return true; - } - - //New message - if( m_current_line->left( 5 ) == "From " ) - { - *m_current_id = *m_current_line; - m_prev_status = m_status; - m_status = true; - m_header = true; - return true; - } else if( m_only_new ) - { - if( m_header && m_current_line->left( 7 ) == "Status:" && - ! m_current_line->contains( "U" ) && ! m_current_line->contains( "N" ) ) - { - m_status = false; - } - } - - if( m_current_line->stripWhiteSpace().isEmpty() ) - m_header = false; - - return false; -} - -bool ReadMBox::searchMessage( const TQString& id ) -{ - if( !m_stream ) - return false; - - while( !m_atend && *m_current_id != id ) - nextLine(); - - return *m_current_id == id; -} - -unsigned int ReadMBox::skipMessage() -{ - unsigned int result = m_current_line->length(); - - if( !m_stream ) - return 0; - - while( !nextLine() ) - result += m_current_line->length(); - - return result; -} - -void ReadMBox::rewind() -{ - if( !m_stream ) - return; //Rewinding not possible - - m_stream->device()->reset(); - m_atend = m_stream->atEnd(); -} - -bool ReadMBox::atEnd() const -{ - if( !m_stream ) - return true; - - return m_atend || ( m_info->type() == UrlInfo::message && *m_current_id != m_info->id() ); -} - -bool ReadMBox::inListing() const -{ - return !m_only_new || m_prev_status; -} - -bool ReadMBox::open( bool savetime ) -{ - if( savetime ) - { - TQFileInfo info( m_info->filename() ); - - m_prev_time = new utimbuf; - m_prev_time->actime = info.lastRead().toTime_t(); - m_prev_time->modtime = info.lastModified().toTime_t(); - } - - if( m_file ) - return false; //File already open - - m_file = new TQFile( m_info->filename() ); - if( !m_file->open( IO_ReadOnly ) ) - { - delete m_file; - m_file = 0; - return false; - } - m_stream = new TQTextStream( m_file ); - skipMessage(); - - return true; -} - -void ReadMBox::close() -{ - if( !m_stream ) - return; - - delete m_stream; m_stream = 0; - m_file->close(); - delete m_file; m_file = 0; - - if( m_prev_time ) - utime( TQFile::encodeName( m_info->filename() ), m_prev_time ); -} - diff --git a/tdeioslave/mbox/readmbox.cpp b/tdeioslave/mbox/readmbox.cpp new file mode 100644 index 000000000..942f369e5 --- /dev/null +++ b/tdeioslave/mbox/readmbox.cpp @@ -0,0 +1,204 @@ +/* + * This is a simple tdeioslave to handle mbox-files. + * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include + +#include "readmbox.h" + +#include "mbox.h" +#include "urlinfo.h" + +#include +#include + +#include +#include +#include +#include + +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#include + +ReadMBox::ReadMBox( const UrlInfo* info, MBoxProtocol* parent, bool onlynew, bool savetime ) + : MBoxFile( info, parent ), + m_file( 0 ), + m_stream( 0 ), + m_current_line( new TQString( TQString() ) ), + m_current_id( new TQString( TQString() ) ), + m_atend( true ), + m_prev_time( 0 ), + m_only_new( onlynew ), + m_savetime( savetime ), + m_status( false ), + m_prev_status( false ), + m_header( true ) + +{ + if( m_info->type() == UrlInfo::invalid ) + m_mbox->emitError( TDEIO::ERR_DOES_NOT_EXIST, info->url() ); + + if( !open( savetime ) ) + m_mbox->emitError( TDEIO::ERR_CANNOT_OPEN_FOR_READING, info->url() ); + + if( m_info->type() == UrlInfo::message ) + if( !searchMessage( m_info->id() ) ) + m_mbox->emitError( TDEIO::ERR_DOES_NOT_EXIST, info->url() ); +} + +ReadMBox::~ReadMBox() +{ + delete m_current_line; + close(); +} + +TQString ReadMBox::currentLine() const +{ + return *m_current_line; +} + +TQString ReadMBox::currentID() const +{ + return *m_current_id; +} + +bool ReadMBox::nextLine() +{ + if( !m_stream ) + return true; + + *m_current_line = m_stream->readLine(); + m_atend = m_current_line->isNull(); + if( m_atend ) // Cursor was at EOF + { + *m_current_id = TQString(); + m_prev_status = m_status; + return true; + } + + //New message + if( m_current_line->left( 5 ) == "From " ) + { + *m_current_id = *m_current_line; + m_prev_status = m_status; + m_status = true; + m_header = true; + return true; + } else if( m_only_new ) + { + if( m_header && m_current_line->left( 7 ) == "Status:" && + ! m_current_line->contains( "U" ) && ! m_current_line->contains( "N" ) ) + { + m_status = false; + } + } + + if( m_current_line->stripWhiteSpace().isEmpty() ) + m_header = false; + + return false; +} + +bool ReadMBox::searchMessage( const TQString& id ) +{ + if( !m_stream ) + return false; + + while( !m_atend && *m_current_id != id ) + nextLine(); + + return *m_current_id == id; +} + +unsigned int ReadMBox::skipMessage() +{ + unsigned int result = m_current_line->length(); + + if( !m_stream ) + return 0; + + while( !nextLine() ) + result += m_current_line->length(); + + return result; +} + +void ReadMBox::rewind() +{ + if( !m_stream ) + return; //Rewinding not possible + + m_stream->device()->reset(); + m_atend = m_stream->atEnd(); +} + +bool ReadMBox::atEnd() const +{ + if( !m_stream ) + return true; + + return m_atend || ( m_info->type() == UrlInfo::message && *m_current_id != m_info->id() ); +} + +bool ReadMBox::inListing() const +{ + return !m_only_new || m_prev_status; +} + +bool ReadMBox::open( bool savetime ) +{ + if( savetime ) + { + TQFileInfo info( m_info->filename() ); + + m_prev_time = new utimbuf; + m_prev_time->actime = info.lastRead().toTime_t(); + m_prev_time->modtime = info.lastModified().toTime_t(); + } + + if( m_file ) + return false; //File already open + + m_file = new TQFile( m_info->filename() ); + if( !m_file->open( IO_ReadOnly ) ) + { + delete m_file; + m_file = 0; + return false; + } + m_stream = new TQTextStream( m_file ); + skipMessage(); + + return true; +} + +void ReadMBox::close() +{ + if( !m_stream ) + return; + + delete m_stream; m_stream = 0; + m_file->close(); + delete m_file; m_file = 0; + + if( m_prev_time ) + utime( TQFile::encodeName( m_info->filename() ), m_prev_time ); +} + diff --git a/tdeioslave/mbox/stat.cc b/tdeioslave/mbox/stat.cc deleted file mode 100644 index 99267ca7d..000000000 --- a/tdeioslave/mbox/stat.cc +++ /dev/null @@ -1,115 +0,0 @@ -/* - * This is a simple tdeioslave to handle mbox-files. - * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "stat.h" - -#include "readmbox.h" -#include "urlinfo.h" - -#include -#include - -#include - -TDEIO::UDSEntry Stat::stat( const UrlInfo& info ) -{ - if( info.type() == UrlInfo::message ) - return Stat::statMessage( info ); - else if( info.type() == UrlInfo::directory ) - return Stat::statDirectory( info ); - else - return TDEIO::UDSEntry(); -} - -TDEIO::UDSEntry Stat::stat( ReadMBox& mbox, const UrlInfo& info ) -{ - kdDebug() << "Stat::stat()" << endl; - TDEIO::UDSEntry entry; - TQString url; - - if( info.type() == UrlInfo::invalid ) - return entry; - else if( info.type() == UrlInfo::message ) - mbox.searchMessage( info.id() ); - - Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFREG ); - Stat::addAtom( entry, TDEIO::UDS_MIME_TYPE, "message/rfc822" ); - - url = TQString( "mbox:%1/%2" ).arg( info.filename(), mbox.currentID() ); - Stat::addAtom( entry, TDEIO::UDS_URL, url ); - if( mbox.currentID().isEmpty() ) - Stat::addAtom( entry, TDEIO::UDS_NAME, "foobar" ); - else - Stat::addAtom( entry, TDEIO::UDS_NAME, mbox.currentID() ); - - - Stat::addAtom( entry, TDEIO::UDS_SIZE, mbox.skipMessage() ); - - return entry; -} - -TDEIO::UDSEntry Stat::statDirectory( const UrlInfo& info ) -{ - kdDebug() << "statDirectory()" << endl; - TDEIO::UDSEntry entry; - - //Specific things for a directory - Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFDIR ); - Stat::addAtom( entry, TDEIO::UDS_NAME, info.filename() ); - - return entry; -} - -TDEIO::UDSEntry Stat::statMessage( const UrlInfo& info ) -{ - kdDebug() << "statMessage( " << info.url() << " )" << endl; - TDEIO::UDSEntry entry; - TQString url = TQString( "mbox:%1" ).arg( info.url() ); - - //Specific things for a message - Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFREG ); - Stat::addAtom( entry, TDEIO::UDS_MIME_TYPE, "message/rfc822" ); - - Stat::addAtom( entry, TDEIO::UDS_URL, url ); - url = url.right( url.length() - url.findRev( "/" ) - 1 ); - Stat::addAtom( entry, TDEIO::UDS_NAME, url ); - - return entry; -} - -void Stat::addAtom( TDEIO::UDSEntry& entry, unsigned int uds, const TQString& str ) -{ - TDEIO::UDSAtom atom; - atom.m_uds = uds; - atom.m_str = str; - atom.m_long = 0; - - entry.append( atom ); -} - - -void Stat::addAtom( TDEIO::UDSEntry& entry, unsigned int uds, long lng ) -{ - TDEIO::UDSAtom atom; - atom.m_uds = uds; - atom.m_str = TQString(); - atom.m_long = lng; - - entry.append( atom ); -} - diff --git a/tdeioslave/mbox/stat.cpp b/tdeioslave/mbox/stat.cpp new file mode 100644 index 000000000..99267ca7d --- /dev/null +++ b/tdeioslave/mbox/stat.cpp @@ -0,0 +1,115 @@ +/* + * This is a simple tdeioslave to handle mbox-files. + * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "stat.h" + +#include "readmbox.h" +#include "urlinfo.h" + +#include +#include + +#include + +TDEIO::UDSEntry Stat::stat( const UrlInfo& info ) +{ + if( info.type() == UrlInfo::message ) + return Stat::statMessage( info ); + else if( info.type() == UrlInfo::directory ) + return Stat::statDirectory( info ); + else + return TDEIO::UDSEntry(); +} + +TDEIO::UDSEntry Stat::stat( ReadMBox& mbox, const UrlInfo& info ) +{ + kdDebug() << "Stat::stat()" << endl; + TDEIO::UDSEntry entry; + TQString url; + + if( info.type() == UrlInfo::invalid ) + return entry; + else if( info.type() == UrlInfo::message ) + mbox.searchMessage( info.id() ); + + Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFREG ); + Stat::addAtom( entry, TDEIO::UDS_MIME_TYPE, "message/rfc822" ); + + url = TQString( "mbox:%1/%2" ).arg( info.filename(), mbox.currentID() ); + Stat::addAtom( entry, TDEIO::UDS_URL, url ); + if( mbox.currentID().isEmpty() ) + Stat::addAtom( entry, TDEIO::UDS_NAME, "foobar" ); + else + Stat::addAtom( entry, TDEIO::UDS_NAME, mbox.currentID() ); + + + Stat::addAtom( entry, TDEIO::UDS_SIZE, mbox.skipMessage() ); + + return entry; +} + +TDEIO::UDSEntry Stat::statDirectory( const UrlInfo& info ) +{ + kdDebug() << "statDirectory()" << endl; + TDEIO::UDSEntry entry; + + //Specific things for a directory + Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFDIR ); + Stat::addAtom( entry, TDEIO::UDS_NAME, info.filename() ); + + return entry; +} + +TDEIO::UDSEntry Stat::statMessage( const UrlInfo& info ) +{ + kdDebug() << "statMessage( " << info.url() << " )" << endl; + TDEIO::UDSEntry entry; + TQString url = TQString( "mbox:%1" ).arg( info.url() ); + + //Specific things for a message + Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFREG ); + Stat::addAtom( entry, TDEIO::UDS_MIME_TYPE, "message/rfc822" ); + + Stat::addAtom( entry, TDEIO::UDS_URL, url ); + url = url.right( url.length() - url.findRev( "/" ) - 1 ); + Stat::addAtom( entry, TDEIO::UDS_NAME, url ); + + return entry; +} + +void Stat::addAtom( TDEIO::UDSEntry& entry, unsigned int uds, const TQString& str ) +{ + TDEIO::UDSAtom atom; + atom.m_uds = uds; + atom.m_str = str; + atom.m_long = 0; + + entry.append( atom ); +} + + +void Stat::addAtom( TDEIO::UDSEntry& entry, unsigned int uds, long lng ) +{ + TDEIO::UDSAtom atom; + atom.m_uds = uds; + atom.m_str = TQString(); + atom.m_long = lng; + + entry.append( atom ); +} + diff --git a/tdeioslave/mbox/urlinfo.cc b/tdeioslave/mbox/urlinfo.cc deleted file mode 100644 index 4b359e403..000000000 --- a/tdeioslave/mbox/urlinfo.cc +++ /dev/null @@ -1,133 +0,0 @@ -/* - * This is a simple tdeioslave to handle mbox-files. - * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "urlinfo.h" - -#include -#include - -#include -#include - -UrlInfo::UrlInfo( const KURL& url, const UrlType type ) - : m_type( invalid ), - m_filename( new TQString ), - m_id( new TQString ) -{ - calculateInfo( url, type ); -} - -UrlInfo::~UrlInfo() -{ - delete m_filename; - delete m_id; -} - -TQString UrlInfo::mimetype() const -{ - switch( m_type ) - { - case message: - return "message/rfc822"; - case directory: - return "inode/directory"; - case invalid: - default: - return "invalid"; - } -} - -TQString UrlInfo::filename() const -{ - return *m_filename; -} - -TQString UrlInfo::id() const -{ - return *m_id; -} - -TQString UrlInfo::url() const -{ - return *m_filename + "/" + *m_id; -} - - -void UrlInfo::calculateInfo( const KURL& url, const UrlType type ) -{ - bool found = false; - - if( !found && type & UrlInfo::message ) - found = isMessage( url ); - if( !found && type & UrlInfo::directory ) - found = isDirectory( url ); - if( !found ) - { - m_type = invalid; - *m_filename = ""; - *m_id = ""; - } -} - -bool UrlInfo::isDirectory( const KURL& url ) -{ - //Check is url is in the form mbox://{filename} - TQString filename = url.path(); - TQFileInfo info; - - //Remove ending / - while( filename.length() > 1 && filename.right( 1 ) == "/" ) - filename.remove( filename.length()-2, 1 ); - - //Is this a directory? - info.setFile( filename ); - if( !info.isFile() ) - return false; - - //Setting paramaters - *m_filename = filename; - *m_id = TQString(); - m_type = directory; - kdDebug() << "urlInfo::isDirectory( " << url << " )" << endl; - return true; -} - -bool UrlInfo::isMessage( const KURL& url ) -{ - TQString path = url.path(); - TQFileInfo info; - int cutindex = path.findRev( '/' ); - - //Does it contain at least one /? - if( cutindex < 0 ) - return false; - - //Does the mbox-file exists? - info.setFile( path.left( cutindex ) ); - if( !info.isFile() ) - return false; - - //Settings parameters - kdDebug() << "urlInfo::isMessage( " << url << " )" << endl; - m_type = message; - *m_id = path.right( path.length() - cutindex - 1 ); - *m_filename = path.left( cutindex ); - - return true; -} - diff --git a/tdeioslave/mbox/urlinfo.cpp b/tdeioslave/mbox/urlinfo.cpp new file mode 100644 index 000000000..4b359e403 --- /dev/null +++ b/tdeioslave/mbox/urlinfo.cpp @@ -0,0 +1,133 @@ +/* + * This is a simple tdeioslave to handle mbox-files. + * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "urlinfo.h" + +#include +#include + +#include +#include + +UrlInfo::UrlInfo( const KURL& url, const UrlType type ) + : m_type( invalid ), + m_filename( new TQString ), + m_id( new TQString ) +{ + calculateInfo( url, type ); +} + +UrlInfo::~UrlInfo() +{ + delete m_filename; + delete m_id; +} + +TQString UrlInfo::mimetype() const +{ + switch( m_type ) + { + case message: + return "message/rfc822"; + case directory: + return "inode/directory"; + case invalid: + default: + return "invalid"; + } +} + +TQString UrlInfo::filename() const +{ + return *m_filename; +} + +TQString UrlInfo::id() const +{ + return *m_id; +} + +TQString UrlInfo::url() const +{ + return *m_filename + "/" + *m_id; +} + + +void UrlInfo::calculateInfo( const KURL& url, const UrlType type ) +{ + bool found = false; + + if( !found && type & UrlInfo::message ) + found = isMessage( url ); + if( !found && type & UrlInfo::directory ) + found = isDirectory( url ); + if( !found ) + { + m_type = invalid; + *m_filename = ""; + *m_id = ""; + } +} + +bool UrlInfo::isDirectory( const KURL& url ) +{ + //Check is url is in the form mbox://{filename} + TQString filename = url.path(); + TQFileInfo info; + + //Remove ending / + while( filename.length() > 1 && filename.right( 1 ) == "/" ) + filename.remove( filename.length()-2, 1 ); + + //Is this a directory? + info.setFile( filename ); + if( !info.isFile() ) + return false; + + //Setting paramaters + *m_filename = filename; + *m_id = TQString(); + m_type = directory; + kdDebug() << "urlInfo::isDirectory( " << url << " )" << endl; + return true; +} + +bool UrlInfo::isMessage( const KURL& url ) +{ + TQString path = url.path(); + TQFileInfo info; + int cutindex = path.findRev( '/' ); + + //Does it contain at least one /? + if( cutindex < 0 ) + return false; + + //Does the mbox-file exists? + info.setFile( path.left( cutindex ) ); + if( !info.isFile() ) + return false; + + //Settings parameters + kdDebug() << "urlInfo::isMessage( " << url << " )" << endl; + m_type = message; + *m_id = path.right( path.length() - cutindex - 1 ); + *m_filename = path.left( cutindex ); + + return true; +} + -- cgit v1.2.1