• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

kioslave/mbox

  • kioslave
  • mbox
urlinfo.cpp
1 /*
2  * This is a simple kioslave 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 "urlinfo.h"
20 
21 #include <kdebug.h>
22 #include <kurl.h>
23 
24 #include <QFileInfo>
25 #include <QString>
26 
27 UrlInfo::UrlInfo( const KUrl& url, const UrlType type )
28  : m_type( invalid ),
29  m_filename( new QString ),
30  m_id( new QString )
31 {
32  calculateInfo( url, type );
33 }
34 
35 UrlInfo::~UrlInfo()
36 {
37  delete m_filename;
38  delete m_id;
39 }
40 
41 QString UrlInfo::mimetype() const
42 {
43  switch( m_type )
44  {
45  case message:
46  return "message/rfc822";
47  case directory:
48  return "inode/directory";
49  case invalid:
50  default:
51  return "invalid";
52  }
53 }
54 
55 QString UrlInfo::filename() const
56 {
57  return *m_filename;
58 }
59 
60 QString UrlInfo::id() const
61 {
62  return *m_id;
63 }
64 
65 QString UrlInfo::url() const
66 {
67  return *m_filename + '/' + *m_id;
68 }
69 
70 
71 void UrlInfo::calculateInfo( const KUrl& url, const UrlType type )
72 {
73  bool found = false;
74 
75  if( !found && type & UrlInfo::message )
76  found = isMessage( url );
77  if( !found && type & UrlInfo::directory )
78  found = isDirectory( url );
79  if( !found )
80  {
81  m_type = invalid;
82  *m_filename = "";
83  *m_id = "";
84  }
85 }
86 
87 bool UrlInfo::isDirectory( const KUrl& url )
88 {
89  //Check is url is in the form mbox://{filename}
90  QString filename = url.path();
91  QFileInfo info;
92 
93  //Remove ending /
94  while( filename.length() > 1 && filename.right( 1 ) == "/" )
95  filename.remove( filename.length()-2, 1 );
96 
97  //Is this a directory?
98  info.setFile( filename );
99  if( !info.isFile() )
100  return false;
101 
102  //Setting parameters
103  *m_filename = filename;
104  (*m_id).clear();
105  m_type = directory;
106  kDebug() << "urlInfo::isDirectory(" << url << " )";
107  return true;
108 }
109 
110 bool UrlInfo::isMessage( const KUrl& url )
111 {
112  QString path = url.path();
113  QFileInfo info;
114  int cutindex = path.lastIndexOf( '/' );
115 
116  //Does it contain at least one /?
117  if( cutindex < 0 )
118  return false;
119 
120  //Does the mbox-file exists?
121  info.setFile( path.left( cutindex ) );
122  if( !info.isFile() )
123  return false;
124 
125  //Settings parameters
126  kDebug() <<"urlInfo::isMessage(" << url <<" )";
127  m_type = message;
128  *m_id = path.right( path.length() - cutindex - 1 );
129  *m_filename = path.left( cutindex );
130 
131  return true;
132 }
133 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:25:32 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kioslave/mbox

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

kdepimlibs-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal