tdeioslave/mbox

stat.cpp
1 /*
2  * This is a simple tdeioslave to handle mbox-files.
3  * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 #include "stat.h"
20 
21 #include "readmbox.h"
22 #include "urlinfo.h"
23 
24 #include <kdebug.h>
25 #include <tdeio/global.h>
26 
27 #include <sys/stat.h>
28 
29 TDEIO::UDSEntry Stat::stat( const UrlInfo& info )
30 {
31  if( info.type() == UrlInfo::message )
32  return Stat::statMessage( info );
33  else if( info.type() == UrlInfo::directory )
34  return Stat::statDirectory( info );
35  else
36  return TDEIO::UDSEntry();
37 }
38 
39 TDEIO::UDSEntry Stat::stat( ReadMBox& mbox, const UrlInfo& info )
40 {
41  kdDebug() << "Stat::stat()" << endl;
42  TDEIO::UDSEntry entry;
43  TQString url;
44 
45  if( info.type() == UrlInfo::invalid )
46  return entry;
47  else if( info.type() == UrlInfo::message )
48  mbox.searchMessage( info.id() );
49 
50  Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFREG );
51  Stat::addAtom( entry, TDEIO::UDS_MIME_TYPE, "message/rfc822" );
52 
53  url = TQString( "mbox:%1/%2" ).arg( info.filename(), mbox.currentID() );
54  Stat::addAtom( entry, TDEIO::UDS_URL, url );
55  if( mbox.currentID().isEmpty() )
56  Stat::addAtom( entry, TDEIO::UDS_NAME, "foobar" );
57  else
58  Stat::addAtom( entry, TDEIO::UDS_NAME, mbox.currentID() );
59 
60 
61  Stat::addAtom( entry, TDEIO::UDS_SIZE, mbox.skipMessage() );
62 
63  return entry;
64 }
65 
66 TDEIO::UDSEntry Stat::statDirectory( const UrlInfo& info )
67 {
68  kdDebug() << "statDirectory()" << endl;
69  TDEIO::UDSEntry entry;
70 
71  //Specific things for a directory
72  Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFDIR );
73  Stat::addAtom( entry, TDEIO::UDS_NAME, info.filename() );
74 
75  return entry;
76 }
77 
78 TDEIO::UDSEntry Stat::statMessage( const UrlInfo& info )
79 {
80  kdDebug() << "statMessage( " << info.url() << " )" << endl;
81  TDEIO::UDSEntry entry;
82  TQString url = TQString( "mbox:%1" ).arg( info.url() );
83 
84  //Specific things for a message
85  Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFREG );
86  Stat::addAtom( entry, TDEIO::UDS_MIME_TYPE, "message/rfc822" );
87 
88  Stat::addAtom( entry, TDEIO::UDS_URL, url );
89  url = url.right( url.length() - url.findRev( "/" ) - 1 );
90  Stat::addAtom( entry, TDEIO::UDS_NAME, url );
91 
92  return entry;
93 }
94 
95 void Stat::addAtom( TDEIO::UDSEntry& entry, unsigned int uds, const TQString& str )
96 {
97  TDEIO::UDSAtom atom;
98  atom.m_uds = uds;
99  atom.m_str = str;
100  atom.m_long = 0;
101 
102  entry.append( atom );
103 }
104 
105 
106 void Stat::addAtom( TDEIO::UDSEntry& entry, unsigned int uds, long lng )
107 {
108  TDEIO::UDSAtom atom;
109  atom.m_uds = uds;
110  atom.m_str = TQString();
111  atom.m_long = lng;
112 
113  entry.append( atom );
114 }
115 
This class handels reading from a mbox-file.
Definition: readmbox.h:37
TQString currentID() const
This function returns the current id.
Definition: readmbox.cpp:77
unsigned int skipMessage()
Skips all lines which belongs to the current message.
Definition: readmbox.cpp:130
bool searchMessage(const TQString &id)
This function search the file for a certain id.
Definition: readmbox.cpp:119
static TDEIO::UDSEntry statDirectory(const UrlInfo &info)
This function gets the stats of a given mbox-file in an UDSEntry.
Definition: stat.cpp:66
static TDEIO::UDSEntry statMessage(const UrlInfo &info)
This function gets the stats of a geven mbox-message in a UDSEntry.
Definition: stat.cpp:78
static TDEIO::UDSEntry stat(const UrlInfo &info)
This functions gives information with a given UrlInfo.
Definition: stat.cpp:29