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

kioslave/mbox

  • sources
  • kde-4.14
  • kdepimlibs
  • 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  case message:
45  return "message/rfc822";
46  case directory:
47  return "inode/directory";
48  case invalid:
49  default:
50  return "invalid";
51  }
52 }
53 
54 QString UrlInfo::filename() const
55 {
56  return *m_filename;
57 }
58 
59 QString UrlInfo::id() const
60 {
61  return *m_id;
62 }
63 
64 QString UrlInfo::url() const
65 {
66  return *m_filename + '/' + *m_id;
67 }
68 
69 
70 void UrlInfo::calculateInfo( const KUrl& url, const UrlType type )
71 {
72  bool found = false;
73 
74  if( !found && type & UrlInfo::message ) {
75  found = isMessage( url );
76  }
77  if( !found && type & UrlInfo::directory ) {
78  found = isDirectory( url );
79  }
80  if( !found ) {
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 
98  //Is this a directory?
99  info.setFile( filename );
100  if( !info.isFile() ) {
101  return false;
102  }
103 
104  //Setting parameters
105  *m_filename = filename;
106  (*m_id).clear();
107  m_type = directory;
108  kDebug() << "urlInfo::isDirectory(" << url << " )";
109  return true;
110 }
111 
112 bool UrlInfo::isMessage( const KUrl& url )
113 {
114  QString path = url.path();
115  QFileInfo info;
116  int cutindex = path.lastIndexOf( '/' );
117 
118  //Does it contain at least one /?
119  if( cutindex < 0 ) {
120  return false;
121  }
122 
123  //Does the mbox-file exists?
124  info.setFile( path.left( cutindex ) );
125  if( !info.isFile() ) {
126  return false;
127  }
128 
129  //Settings parameters
130  kDebug() <<"urlInfo::isMessage(" << url <<" )";
131  m_type = message;
132  *m_id = path.right( path.length() - cutindex - 1 );
133  *m_filename = path.left( cutindex );
134 
135  return true;
136 }
QFileInfo::setFile
void setFile(const QString &file)
QString::remove
QString & remove(int position, int n)
QString::lastIndexOf
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QString::clear
void clear()
QFileInfo::isFile
bool isFile() const
QString
QString::right
QString right(int n) const
QFileInfo
QString::length
int length() const
QString::left
QString left(int n) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:11 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs 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

Search



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