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.
116 lines
3.2 KiB
116 lines
3.2 KiB
15 years ago
|
/*
|
||
12 years ago
|
* This is a simple tdeioslave to handle mbox-files.
|
||
15 years ago
|
* 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 <kdebug.h>
|
||
12 years ago
|
#include <tdeio/global.h>
|
||
15 years ago
|
|
||
|
#include <sys/stat.h>
|
||
|
|
||
12 years ago
|
TDEIO::UDSEntry Stat::stat( const UrlInfo& info )
|
||
15 years ago
|
{
|
||
|
if( info.type() == UrlInfo::message )
|
||
|
return Stat::statMessage( info );
|
||
|
else if( info.type() == UrlInfo::directory )
|
||
|
return Stat::statDirectory( info );
|
||
|
else
|
||
12 years ago
|
return TDEIO::UDSEntry();
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDEIO::UDSEntry Stat::stat( ReadMBox& mbox, const UrlInfo& info )
|
||
15 years ago
|
{
|
||
|
kdDebug() << "Stat::stat()" << endl;
|
||
12 years ago
|
TDEIO::UDSEntry entry;
|
||
15 years ago
|
TQString url;
|
||
15 years ago
|
|
||
|
if( info.type() == UrlInfo::invalid )
|
||
|
return entry;
|
||
|
else if( info.type() == UrlInfo::message )
|
||
|
mbox.searchMessage( info.id() );
|
||
|
|
||
12 years ago
|
Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFREG );
|
||
|
Stat::addAtom( entry, TDEIO::UDS_MIME_TYPE, "message/rfc822" );
|
||
15 years ago
|
|
||
13 years ago
|
url = TQString( "mbox:%1/%2" ).arg( info.filename(), mbox.currentID() );
|
||
12 years ago
|
Stat::addAtom( entry, TDEIO::UDS_URL, url );
|
||
15 years ago
|
if( mbox.currentID().isEmpty() )
|
||
12 years ago
|
Stat::addAtom( entry, TDEIO::UDS_NAME, "foobar" );
|
||
15 years ago
|
else
|
||
12 years ago
|
Stat::addAtom( entry, TDEIO::UDS_NAME, mbox.currentID() );
|
||
15 years ago
|
|
||
|
|
||
12 years ago
|
Stat::addAtom( entry, TDEIO::UDS_SIZE, mbox.skipMessage() );
|
||
15 years ago
|
|
||
|
return entry;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIO::UDSEntry Stat::statDirectory( const UrlInfo& info )
|
||
15 years ago
|
{
|
||
|
kdDebug() << "statDirectory()" << endl;
|
||
12 years ago
|
TDEIO::UDSEntry entry;
|
||
15 years ago
|
|
||
|
//Specific things for a directory
|
||
12 years ago
|
Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFDIR );
|
||
|
Stat::addAtom( entry, TDEIO::UDS_NAME, info.filename() );
|
||
15 years ago
|
|
||
|
return entry;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIO::UDSEntry Stat::statMessage( const UrlInfo& info )
|
||
15 years ago
|
{
|
||
|
kdDebug() << "statMessage( " << info.url() << " )" << endl;
|
||
12 years ago
|
TDEIO::UDSEntry entry;
|
||
13 years ago
|
TQString url = TQString( "mbox:%1" ).arg( info.url() );
|
||
15 years ago
|
|
||
|
//Specific things for a message
|
||
12 years ago
|
Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFREG );
|
||
|
Stat::addAtom( entry, TDEIO::UDS_MIME_TYPE, "message/rfc822" );
|
||
15 years ago
|
|
||
12 years ago
|
Stat::addAtom( entry, TDEIO::UDS_URL, url );
|
||
14 years ago
|
url = url.right( url.length() - url.findRev( "/" ) - 1 );
|
||
12 years ago
|
Stat::addAtom( entry, TDEIO::UDS_NAME, url );
|
||
15 years ago
|
|
||
|
return entry;
|
||
|
}
|
||
|
|
||
12 years ago
|
void Stat::addAtom( TDEIO::UDSEntry& entry, unsigned int uds, const TQString& str )
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEIO::UDSAtom atom;
|
||
15 years ago
|
atom.m_uds = uds;
|
||
|
atom.m_str = str;
|
||
|
atom.m_long = 0;
|
||
|
|
||
|
entry.append( atom );
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void Stat::addAtom( TDEIO::UDSEntry& entry, unsigned int uds, long lng )
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEIO::UDSAtom atom;
|
||
15 years ago
|
atom.m_uds = uds;
|
||
14 years ago
|
atom.m_str = TQString();
|
||
15 years ago
|
atom.m_long = lng;
|
||
|
|
||
|
entry.append( atom );
|
||
|
}
|
||
|
|