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

KIO

  • sources
  • kde-4.14
  • kdelibs
  • kio
  • kio
kfileitemlistproperties.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at>
3  Copyright (C) 2008 by George Goldberg <grundleborg@googlemail.com>
4  Copyright 2009 David Faure <faure@kde.org>
5 
6  This library is free software; you can redistribute it and/or modify
7  it under the terms of the GNU Library General Public License as published
8  by the Free Software Foundation; either version 2 of the License or
9  ( at your option ) version 3 or, at the discretion of KDE e.V.
10  ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "kfileitemlistproperties.h"
24 
25 #include <kfileitem.h>
26 #include <kprotocolmanager.h>
27 
28 #include <QFileInfo>
29 
30 class KFileItemListPropertiesPrivate : public QSharedData
31 {
32 public:
33  KFileItemListPropertiesPrivate()
34  : m_isDirectory(false),
35  m_supportsReading(false),
36  m_supportsDeleting(false),
37  m_supportsWriting(false),
38  m_supportsMoving(false),
39  m_isLocal(true)
40  { }
41  void setItems(const KFileItemList& items);
42 
43  void determineMimeTypeAndGroup() const;
44 
45  KFileItemList m_items;
46  KUrl::List m_urlList;
47  mutable QString m_mimeType;
48  mutable QString m_mimeGroup;
49  bool m_isDirectory : 1;
50  bool m_supportsReading : 1;
51  bool m_supportsDeleting : 1;
52  bool m_supportsWriting : 1;
53  bool m_supportsMoving : 1;
54  bool m_isLocal : 1;
55 };
56 
57 
58 KFileItemListProperties::KFileItemListProperties()
59  : d(new KFileItemListPropertiesPrivate)
60 {
61 }
62 
63 KFileItemListProperties::KFileItemListProperties(const KFileItemList& items)
64  : d(new KFileItemListPropertiesPrivate)
65 {
66  setItems(items);
67 }
68 
69 void KFileItemListProperties::setItems(const KFileItemList& items)
70 {
71  d->setItems(items);
72 }
73 
74 void KFileItemListPropertiesPrivate::setItems(const KFileItemList& items)
75 {
76  const bool initialValue = !items.isEmpty();
77  m_items = items;
78  m_urlList = items.targetUrlList();
79  m_supportsReading = initialValue;
80  m_supportsDeleting = initialValue;
81  m_supportsWriting = initialValue;
82  m_supportsMoving = initialValue;
83  m_isDirectory = initialValue;
84  m_isLocal = true;
85  m_mimeType.clear();
86  m_mimeGroup.clear();
87 
88  QFileInfo parentDirInfo;
89  foreach (const KFileItem &item, items) {
90  const KUrl url = item.url();
91  m_isLocal = m_isLocal && url.isLocalFile();
92  m_supportsReading = m_supportsReading && KProtocolManager::supportsReading(url);
93  m_supportsDeleting = m_supportsDeleting && KProtocolManager::supportsDeleting(url);
94  m_supportsWriting = m_supportsWriting && KProtocolManager::supportsWriting(url) && item.isWritable();
95  m_supportsMoving = m_supportsMoving && KProtocolManager::supportsMoving(url);
96 
97  // For local files we can do better: check if we have write permission in parent directory
98  // TODO: if we knew about the parent KFileItem, we could even do that for remote protocols too
99  if (m_isLocal && (m_supportsDeleting || m_supportsMoving)) {
100  const QString directory = url.directory();
101  if (parentDirInfo.filePath() != directory) {
102  parentDirInfo.setFile(directory);
103  }
104  if (!parentDirInfo.isWritable()) {
105  m_supportsDeleting = false;
106  m_supportsMoving = false;
107  }
108  }
109  if (m_isDirectory && !item.isDir()) {
110  m_isDirectory = false;
111  }
112  }
113 }
114 
115 KFileItemListProperties::KFileItemListProperties(const KFileItemListProperties& other)
116  : d(other.d)
117 { }
118 
119 
120 KFileItemListProperties& KFileItemListProperties::operator=(const KFileItemListProperties& other)
121 {
122  d = other.d;
123  return *this;
124 }
125 
126 KFileItemListProperties::~KFileItemListProperties()
127 {
128 }
129 
130 bool KFileItemListProperties::supportsReading() const
131 {
132  return d->m_supportsReading;
133 }
134 
135 bool KFileItemListProperties::supportsDeleting() const
136 {
137  return d->m_supportsDeleting;
138 }
139 
140 bool KFileItemListProperties::supportsWriting() const
141 {
142  return d->m_supportsWriting;
143 }
144 
145 bool KFileItemListProperties::supportsMoving() const
146 {
147  return d->m_supportsMoving && d->m_supportsDeleting;
148 }
149 
150 bool KFileItemListProperties::isLocal() const
151 {
152  return d->m_isLocal;
153 }
154 
155 KFileItemList KFileItemListProperties::items() const
156 {
157  return d->m_items;
158 }
159 
160 KUrl::List KFileItemListProperties::urlList() const
161 {
162  return d->m_urlList;
163 }
164 
165 bool KFileItemListProperties::isDirectory() const
166 {
167  return d->m_isDirectory;
168 }
169 
170 QString KFileItemListProperties::mimeType() const
171 {
172  if (d->m_mimeType.isEmpty())
173  d->determineMimeTypeAndGroup();
174  return d->m_mimeType;
175 }
176 
177 QString KFileItemListProperties::mimeGroup() const
178 {
179  if (d->m_mimeType.isEmpty())
180  d->determineMimeTypeAndGroup();
181  return d->m_mimeGroup;
182 }
183 
184 void KFileItemListPropertiesPrivate::determineMimeTypeAndGroup() const
185 {
186  if (!m_items.isEmpty()) {
187  m_mimeType = m_items.first().mimetype();
188  m_mimeGroup = m_mimeType.left(m_mimeType.indexOf('/'));
189  }
190  foreach (const KFileItem &item, m_items) {
191  const QString itemMimeType = item.mimetype();
192  // Determine if common mimetype among all items
193  if (m_mimeType != itemMimeType) {
194  m_mimeType.clear();
195  if (m_mimeGroup != itemMimeType.left(itemMimeType.indexOf('/'))) {
196  m_mimeGroup.clear(); // mimetype groups are different as well!
197  }
198  }
199  }
200 }
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
KFileItem::isWritable
bool isWritable() const
Checks whether the file or directory is writable.
Definition: kfileitem.cpp:1099
KUrl::directory
QString directory(const DirectoryOptions &options=IgnoreTrailingSlash) const
KFileItem::isDir
bool isDir() const
Returns true if this item represents a directory.
Definition: kfileitem.cpp:1141
KFileItem::mimetype
QString mimetype() const
Returns the mimetype of the file item.
Definition: kfileitem.cpp:770
QFileInfo::setFile
void setFile(const QString &file)
KFileItemListProperties::setItems
void setItems(const KFileItemList &items)
Sets the items that are to have their supported capabilities checked.
Definition: kfileitemlistproperties.cpp:69
KUrl
KFileItemListProperties::supportsMoving
bool supportsMoving() const
Check if moving capability is supported.
Definition: kfileitemlistproperties.cpp:145
KFileItemListProperties::mimeType
QString mimeType() const
Definition: kfileitemlistproperties.cpp:170
kprotocolmanager.h
QString::clear
void clear()
QFileInfo::filePath
QString filePath() const
KFileItemListProperties::operator=
KFileItemListProperties & operator=(const KFileItemListProperties &other)
Assignment operator.
Definition: kfileitemlistproperties.cpp:120
KFileItemListProperties::isLocal
bool isLocal() const
Check if files are local.
Definition: kfileitemlistproperties.cpp:150
QSharedData
KProtocolManager::supportsDeleting
static bool supportsDeleting(const KUrl &url)
Returns whether the protocol can delete files/objects.
Definition: kprotocolmanager.cpp:1077
QList::isEmpty
bool isEmpty() const
KFileItemList
List of KFileItems, which adds a few helper methods to QList.
Definition: kfileitem.h:674
KFileItemListProperties::supportsReading
bool supportsReading() const
Check if reading capability is supported.
Definition: kfileitemlistproperties.cpp:130
KFileItemListProperties::supportsDeleting
bool supportsDeleting() const
Check if deleting capability is supported.
Definition: kfileitemlistproperties.cpp:135
QString
KFileItemListProperties::isDirectory
bool isDirectory() const
Definition: kfileitemlistproperties.cpp:165
KFileItemListProperties::urlList
KUrl::List urlList() const
List of urls, gathered from the fileitems.
Definition: kfileitemlistproperties.cpp:160
QFileInfo
KProtocolManager::supportsReading
static bool supportsReading(const KUrl &url)
Returns whether the protocol can retrieve data from URLs.
Definition: kprotocolmanager.cpp:1050
KFileItemListProperties
Provides information about the common properties of a group of KFileItem objects. ...
Definition: kfileitemlistproperties.h:49
KFileItemListProperties::~KFileItemListProperties
virtual ~KFileItemListProperties()
Destructor.
Definition: kfileitemlistproperties.cpp:126
KFileItemListProperties::KFileItemListProperties
KFileItemListProperties()
Default constructor.
Definition: kfileitemlistproperties.cpp:58
KUrl::List
KFileItemListProperties::items
KFileItemList items() const
List of fileitems passed to the constructor or to setItems().
Definition: kfileitemlistproperties.cpp:155
KFileItemListProperties::mimeGroup
QString mimeGroup() const
Definition: kfileitemlistproperties.cpp:177
QFileInfo::isWritable
bool isWritable() const
QString::left
QString left(int n) const
kfileitemlistproperties.h
KUrl::isLocalFile
bool isLocalFile() const
KProtocolManager::supportsMoving
static bool supportsMoving(const KUrl &url)
Returns whether the protocol can move files/objects between different locations.
Definition: kprotocolmanager.cpp:1095
KFileItemListProperties::supportsWriting
bool supportsWriting() const
Check if writing capability is supported (file managers use this mostly for directories) ...
Definition: kfileitemlistproperties.cpp:140
KProtocolManager::supportsWriting
static bool supportsWriting(const KUrl &url)
Returns whether the protocol can store data to URLs.
Definition: kprotocolmanager.cpp:1059
kfileitem.h
KFileItem::url
KUrl url() const
Returns the url of the file.
Definition: kfileitem.cpp:1543
KFileItem
A KFileItem is a generic class to handle a file, local or remote.
Definition: kfileitem.h:45
KFileItemList::targetUrlList
KUrl::List targetUrlList() const
Definition: kfileitem.cpp:1761
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

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