• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libkonq

konq_fileitemcapabilities.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at>                  *
00003  *   Copyright (C) 2008 by George Goldberg <grundleborg@googlemail.com>    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
00019  ***************************************************************************/
00020 
00021 #include "konq_fileitemcapabilities.h"
00022 
00023 #include <kfileitem.h>
00024 #include <kprotocolmanager.h>
00025 
00026 #include <QFileInfo>
00027 
00028 class KonqFileItemCapabilitiesPrivate : public QSharedData
00029 {
00030 public:
00031     KonqFileItemCapabilitiesPrivate()
00032         : m_supportsReading(false),
00033           m_supportsDeleting(false),
00034           m_supportsWriting(false),
00035           m_supportsMoving(false),
00036           m_isLocal(true)
00037     { }
00038     bool m_supportsReading : 1;
00039     bool m_supportsDeleting : 1;
00040     bool m_supportsWriting : 1;
00041     bool m_supportsMoving : 1;
00042     bool m_isLocal : 1;
00043 };
00044 
00045 
00046 KonqFileItemCapabilities::KonqFileItemCapabilities()
00047     : d(new KonqFileItemCapabilitiesPrivate)
00048 {
00049 }
00050 
00051 KonqFileItemCapabilities::KonqFileItemCapabilities(const KFileItemList& items)
00052     : d(new KonqFileItemCapabilitiesPrivate)
00053 {
00054     setItems(items);
00055 }
00056 
00057 void KonqFileItemCapabilities::setItems(const KFileItemList& items)
00058 {
00059     const bool initialValue = !items.isEmpty();
00060     d->m_supportsReading = initialValue;
00061     d->m_supportsDeleting = initialValue;
00062     d->m_supportsWriting = initialValue;
00063     d->m_supportsMoving = initialValue;
00064     d->m_isLocal = true;
00065 
00066     QFileInfo parentDirInfo;
00067     foreach (const KFileItem &item, items) {
00068         const KUrl url = item.url();
00069         d->m_isLocal = d->m_isLocal && url.isLocalFile();
00070         d->m_supportsReading  = d->m_supportsReading  && KProtocolManager::supportsReading(url);
00071         d->m_supportsDeleting = d->m_supportsDeleting && KProtocolManager::supportsDeleting(url);
00072         d->m_supportsWriting  = d->m_supportsWriting  && KProtocolManager::supportsWriting(url) && item.isWritable();
00073         d->m_supportsMoving   = d->m_supportsMoving   && KProtocolManager::supportsMoving(url);
00074 
00075         // For local files we can do better: check if we have write permission in parent directory
00076         if (d->m_isLocal && (d->m_supportsDeleting || d->m_supportsMoving)) {
00077             const QString directory = url.directory();
00078             if (parentDirInfo.filePath() != directory) {
00079                 parentDirInfo.setFile(directory);
00080             }
00081             if (!parentDirInfo.isWritable()) {
00082                 d->m_supportsDeleting = false;
00083                 d->m_supportsMoving = false;
00084             }
00085         }
00086     }
00087 }
00088 
00089 KonqFileItemCapabilities::KonqFileItemCapabilities(const KonqFileItemCapabilities& other)
00090     : d(other.d)
00091 { }
00092 
00093 
00094 KonqFileItemCapabilities& KonqFileItemCapabilities::operator=(const KonqFileItemCapabilities& other)
00095 {
00096     d = other.d;
00097     return *this;
00098 }
00099 
00100 KonqFileItemCapabilities::~KonqFileItemCapabilities()
00101 {
00102 }
00103 
00104 bool KonqFileItemCapabilities::supportsReading() const
00105 {
00106     return d->m_supportsReading;
00107 }
00108 
00109 bool KonqFileItemCapabilities::supportsDeleting() const
00110 {
00111     return d->m_supportsDeleting;
00112 }
00113 
00114 bool KonqFileItemCapabilities::supportsWriting() const
00115 {
00116     return d->m_supportsWriting;
00117 }
00118 
00119 bool KonqFileItemCapabilities::supportsMoving() const
00120 {
00121     return d->m_supportsMoving;
00122 }
00123 
00124 bool KonqFileItemCapabilities::isLocal() const
00125 {
00126     return d->m_isLocal;
00127 }

libkonq

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

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.7
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