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

KIO

  • 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 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Apr 16 2013 19:14:51 by doxygen 1.8.3.1 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-4.10.2 API Reference

Skip menu "kdelibs-4.10.2 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
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