• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

kioslave/mbox

mbox.cpp

00001 /*
00002  * This is a simple kioslave to handle mbox-files.
00003  * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl)
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 #include "mbox.h"
00020 
00021 #include "readmbox.h"
00022 #include "stat.h"
00023 #include "urlinfo.h"
00024 
00025 #include <QString>
00026 
00027 #include <kdebug.h>
00028 #include <klocale.h>
00029 #include <kcomponentdata.h>
00030 #include <kglobal.h>
00031 #include <kurl.h>
00032 #include <kio/global.h>
00033 
00034 #include <stdlib.h>
00035 
00036 #include "kdemacros.h"
00037 
00038 extern "C" { KDE_EXPORT int kdemain(int argc, char* argv[]); }
00039 
00040 int kdemain( int argc, char * argv[] )
00041 {
00042     KComponentData instance("kio_mbox", "kdelibs4");
00043     (void) KGlobal::locale();
00044 
00045     if (argc != 4) {
00046         fprintf(stderr, "Usage: kio_mbox protocol "
00047                         "domain-socket1 domain-socket2\n");
00048         exit(-1);
00049     }
00050 
00051     MBoxProtocol slave(argv[2], argv[3]);
00052     slave.dispatchLoop();
00053     
00054     return 0;
00055 }
00056 
00057 MBoxProtocol::MBoxProtocol( const QByteArray& arg1, const QByteArray& arg2 )
00058     : KIO::SlaveBase( "mbox2", arg1, arg2 ),
00059     m_errorState( true )
00060 {
00061     
00062 }
00063 
00064 MBoxProtocol::~MBoxProtocol()
00065 {
00066 }
00067 
00068 void MBoxProtocol::get( const KUrl& url )
00069 {
00070     m_errorState = false;
00071     
00072     UrlInfo info( url, UrlInfo::message );
00073     QString line;
00074     QByteArray ba_line;
00075 
00076     if( info.type() == UrlInfo::invalid && !m_errorState )
00077     {
00078         error( KIO::ERR_DOES_NOT_EXIST, info.url() );
00079         return;
00080     }
00081     
00082     ReadMBox mbox( &info, this );
00083 
00084     while( !mbox.atEnd() && !m_errorState)
00085     {
00086         line = mbox.currentLine();
00087         line += '\n';
00088         ba_line = QByteArray( line.toUtf8() );
00089         ba_line.truncate( ba_line.size() - 1 ); //Removing training '\0'
00090         data( ba_line );
00091         mbox.nextLine();
00092     };
00093     
00094     if( !m_errorState )
00095     {
00096         data( QByteArray() );
00097         finished();
00098     }
00099 }
00100 
00101 void MBoxProtocol::listDir( const KUrl& url )
00102 {
00103     m_errorState = false;
00104     
00105     KIO::UDSEntry entry;
00106     UrlInfo info( url, UrlInfo::directory );
00107     ReadMBox mbox( &info, this, hasMetaData( "onlynew" ), hasMetaData( "savetime" ) );
00108 
00109     if( m_errorState )
00110         return;
00111     
00112     if( info.type() != UrlInfo::directory )
00113     {
00114         error( KIO::ERR_DOES_NOT_EXIST, info.url() );
00115         return;
00116     }
00117     
00118     while( !mbox.atEnd() && !m_errorState )
00119     {
00120         entry = Stat::stat( mbox, info );
00121         if( mbox.inListing() )
00122             listEntry( entry, false );
00123     }
00124 
00125     listEntry( KIO::UDSEntry(), true );
00126     finished();
00127 }
00128 
00129 void MBoxProtocol::stat( const KUrl& url )
00130 {
00131     UrlInfo info( url );
00132     if( info.type() == UrlInfo::invalid )
00133     {
00134         error( KIO::ERR_DOES_NOT_EXIST, url.path() );
00135         return;
00136     } else
00137     {
00138         statEntry( Stat::stat( info ) );
00139     }
00140     finished();
00141 }
00142 
00143 void MBoxProtocol::mimetype( const KUrl& url )
00144 {   
00145     m_errorState = false;
00146     
00147     UrlInfo info( url );
00148 
00149     if( m_errorState )
00150         return;
00151     
00152     if( info.type() == UrlInfo::invalid )
00153         error( KIO::ERR_DOES_NOT_EXIST, i18n( "Invalid URL" ) );
00154     else
00155         mimeType( info.mimetype() );
00156     finished();
00157 }
00158 
00159 void MBoxProtocol::emitError( int _errno, const QString& arg )
00160 {
00161     m_errorState = true;
00162     error( _errno, arg );
00163 }
00164 

kioslave/mbox

Skip menu "kioslave/mbox"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal