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

KIO

kfileitemlistproperties.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at>
00003    Copyright (C) 2008 by George Goldberg <grundleborg@googlemail.com>
00004    Copyright     2009 David Faure <faure@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU Library General Public License as published
00008    by the Free Software Foundation; either version 2 of the License or
00009    ( at your option ) version 3 or, at the discretion of KDE e.V.
00010    ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "kfileitemlistproperties.h"
00024 
00025 #include <kfileitem.h>
00026 #include <kprotocolmanager.h>
00027 
00028 #include <QFileInfo>
00029 
00030 class KFileItemListPropertiesPrivate : public QSharedData
00031 {
00032 public:
00033     KFileItemListPropertiesPrivate()
00034         : m_isDirectory(false),
00035           m_supportsReading(false),
00036           m_supportsDeleting(false),
00037           m_supportsWriting(false),
00038           m_supportsMoving(false),
00039           m_isLocal(true)
00040     { }
00041     void setItems(const KFileItemList& items);
00042 
00043     void determineMimeTypeAndGroup() const;
00044 
00045     KFileItemList m_items;
00046     KUrl::List m_urlList;
00047     mutable QString m_mimeType;
00048     mutable QString m_mimeGroup;
00049     bool m_isDirectory : 1;
00050     bool m_supportsReading : 1;
00051     bool m_supportsDeleting : 1;
00052     bool m_supportsWriting : 1;
00053     bool m_supportsMoving : 1;
00054     bool m_isLocal : 1;
00055 };
00056 
00057 
00058 KFileItemListProperties::KFileItemListProperties()
00059     : d(new KFileItemListPropertiesPrivate)
00060 {
00061 }
00062 
00063 KFileItemListProperties::KFileItemListProperties(const KFileItemList& items)
00064     : d(new KFileItemListPropertiesPrivate)
00065 {
00066     setItems(items);
00067 }
00068 
00069 void KFileItemListProperties::setItems(const KFileItemList& items)
00070 {
00071     d->setItems(items);
00072 }
00073 
00074 void KFileItemListPropertiesPrivate::setItems(const KFileItemList& items)
00075 {
00076     const bool initialValue = !items.isEmpty();
00077     m_items = items;
00078     m_urlList = items.targetUrlList();
00079     m_supportsReading = initialValue;
00080     m_supportsDeleting = initialValue;
00081     m_supportsWriting = initialValue;
00082     m_supportsMoving = initialValue;
00083     m_isDirectory = initialValue;
00084     m_isLocal = true;
00085     m_mimeType.clear();
00086     m_mimeGroup.clear();
00087 
00088     QFileInfo parentDirInfo;
00089     foreach (const KFileItem &item, items) {
00090         const KUrl url = item.url();
00091         m_isLocal = m_isLocal && url.isLocalFile();
00092         m_supportsReading  = m_supportsReading  && KProtocolManager::supportsReading(url);
00093         m_supportsDeleting = m_supportsDeleting && KProtocolManager::supportsDeleting(url);
00094         m_supportsWriting  = m_supportsWriting  && KProtocolManager::supportsWriting(url) && item.isWritable();
00095         m_supportsMoving   = m_supportsMoving   && KProtocolManager::supportsMoving(url);
00096 
00097         // For local files we can do better: check if we have write permission in parent directory
00098         // TODO: if we knew about the parent KFileItem, we could even do that for remote protocols too
00099         if (m_isLocal && (m_supportsDeleting || m_supportsMoving)) {
00100             const QString directory = url.directory();
00101             if (parentDirInfo.filePath() != directory) {
00102                 parentDirInfo.setFile(directory);
00103             }
00104             if (!parentDirInfo.isWritable()) {
00105                 m_supportsDeleting = false;
00106                 m_supportsMoving = false;
00107             }
00108         }
00109         if (m_isDirectory && !item.isDir()) {
00110             m_isDirectory = false;
00111         }
00112     }
00113 }
00114 
00115 KFileItemListProperties::KFileItemListProperties(const KFileItemListProperties& other)
00116     : d(other.d)
00117 { }
00118 
00119 
00120 KFileItemListProperties& KFileItemListProperties::operator=(const KFileItemListProperties& other)
00121 {
00122     d = other.d;
00123     return *this;
00124 }
00125 
00126 KFileItemListProperties::~KFileItemListProperties()
00127 {
00128 }
00129 
00130 bool KFileItemListProperties::supportsReading() const
00131 {
00132     return d->m_supportsReading;
00133 }
00134 
00135 bool KFileItemListProperties::supportsDeleting() const
00136 {
00137     return d->m_supportsDeleting;
00138 }
00139 
00140 bool KFileItemListProperties::supportsWriting() const
00141 {
00142     return d->m_supportsWriting;
00143 }
00144 
00145 bool KFileItemListProperties::supportsMoving() const
00146 {
00147     return d->m_supportsMoving && d->m_supportsDeleting;
00148 }
00149 
00150 bool KFileItemListProperties::isLocal() const
00151 {
00152     return d->m_isLocal;
00153 }
00154 
00155 KFileItemList KFileItemListProperties::items() const
00156 {
00157     return d->m_items;
00158 }
00159 
00160 KUrl::List KFileItemListProperties::urlList() const
00161 {
00162     return d->m_urlList;
00163 }
00164 
00165 bool KFileItemListProperties::isDirectory() const
00166 {
00167     return d->m_isDirectory;
00168 }
00169 
00170 QString KFileItemListProperties::mimeType() const
00171 {
00172     if (d->m_mimeType.isEmpty())
00173         d->determineMimeTypeAndGroup();
00174     return d->m_mimeType;
00175 }
00176 
00177 QString KFileItemListProperties::mimeGroup() const
00178 {
00179     if (d->m_mimeType.isEmpty())
00180         d->determineMimeTypeAndGroup();
00181     return d->m_mimeGroup;
00182 }
00183 
00184 void KFileItemListPropertiesPrivate::determineMimeTypeAndGroup() const
00185 {
00186     if (!m_items.isEmpty()) {
00187         m_mimeType = m_items.first().mimetype();
00188         m_mimeGroup = m_mimeType.left(m_mimeType.indexOf('/'));
00189     }
00190     foreach (const KFileItem &item, m_items) {
00191         const QString itemMimeType = item.mimetype();
00192         // Determine if common mimetype among all items
00193         if (m_mimeType != itemMimeType) {
00194             m_mimeType.clear();
00195             if (m_mimeGroup != itemMimeType.left(itemMimeType.indexOf('/'))) {
00196                 m_mimeGroup.clear(); // mimetype groups are different as well!
00197             }
00198         }
00199     }
00200 }

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

Skip menu "kdelibs"
  • 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
Generated for kdelibs by doxygen 1.7.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal