kioslaves

stat.cc

Go to the documentation of this file.
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 "stat.h"
00020 
00021 #include "readmbox.h"
00022 #include "urlinfo.h"
00023 
00024 #include <kdebug.h>
00025 #include <kio/global.h>
00026 
00027 #include <sys/stat.h>
00028 
00029 KIO::UDSEntry Stat::stat( const UrlInfo& info )
00030 {
00031     if( info.type() == UrlInfo::message )
00032         return Stat::statMessage( info );
00033     else if( info.type() == UrlInfo::directory )
00034         return Stat::statDirectory( info );
00035     else
00036         return KIO::UDSEntry();
00037 }
00038 
00039 KIO::UDSEntry Stat::stat( ReadMBox& mbox, const UrlInfo& info )
00040 {
00041     kdDebug() << "Stat::stat()" << endl;
00042     KIO::UDSEntry entry;
00043     QString url;
00044     
00045     if( info.type() == UrlInfo::invalid )
00046         return entry;
00047     else if( info.type() == UrlInfo::message )
00048         mbox.searchMessage( info.id() );
00049 
00050     Stat::addAtom( entry, KIO::UDS_FILE_TYPE, S_IFREG );
00051         Stat::addAtom( entry, KIO::UDS_MIME_TYPE, "message/rfc822" );
00052                 
00053     url = QString( "mbox:%1/%2" ).arg( info.filename(), mbox.currentID() );
00054     Stat::addAtom( entry, KIO::UDS_URL, url );
00055     if( mbox.currentID().isEmpty() )
00056         Stat::addAtom( entry, KIO::UDS_NAME, "foobar" );
00057     else
00058             Stat::addAtom( entry, KIO::UDS_NAME, mbox.currentID() );
00059     
00060 
00061     Stat::addAtom( entry, KIO::UDS_SIZE, mbox.skipMessage() );
00062 
00063     return entry;
00064 }
00065 
00066 KIO::UDSEntry Stat::statDirectory( const UrlInfo& info )
00067 {
00068     kdDebug() << "statDirectory()" << endl;
00069     KIO::UDSEntry entry;
00070 
00071     //Specific things for a directory
00072     Stat::addAtom( entry, KIO::UDS_FILE_TYPE, S_IFDIR );
00073     Stat::addAtom( entry, KIO::UDS_NAME, info.filename() );
00074 
00075     return entry;
00076 }
00077 
00078 KIO::UDSEntry Stat::statMessage( const UrlInfo& info )
00079 {
00080     kdDebug() << "statMessage( " << info.url()  << " )" << endl;
00081     KIO::UDSEntry entry;
00082     QString url = QString( "mbox:%1" ).arg( info.url() );
00083 
00084     //Specific things for a message
00085     Stat::addAtom( entry, KIO::UDS_FILE_TYPE, S_IFREG );
00086     Stat::addAtom( entry, KIO::UDS_MIME_TYPE, "message/rfc822" );
00087     
00088     Stat::addAtom( entry, KIO::UDS_URL, url );
00089     url = url.right( url.length() - url.findRev( "/" ) - 1 );
00090     Stat::addAtom( entry, KIO::UDS_NAME, url );
00091 
00092     return entry;
00093 }
00094 
00095 void Stat::addAtom( KIO::UDSEntry& entry, unsigned int uds, const QString& str )
00096 {
00097     KIO::UDSAtom atom;
00098     atom.m_uds = uds;
00099     atom.m_str = str;
00100     atom.m_long = 0;
00101 
00102     entry.append( atom );
00103 }
00104 
00105 
00106 void Stat::addAtom( KIO::UDSEntry& entry, unsigned int uds, long lng )
00107 {
00108     KIO::UDSAtom atom;
00109     atom.m_uds = uds;
00110     atom.m_str = QString::null;
00111     atom.m_long = lng;
00112 
00113     entry.append( atom );
00114 }
00115