1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2008 by George Goldberg <grundleborg@googlemail.com> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program 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 *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "konq_fileitemcapabilities.h"
23 #include <kfileitem.h>
24 #include <kprotocolmanager.h>
28 class KonqFileItemCapabilitiesPrivate
: public QSharedData
31 KonqFileItemCapabilitiesPrivate()
32 : m_supportsReading(false),
33 m_supportsDeleting(false),
34 m_supportsWriting(false),
35 m_supportsMoving(false),
38 bool m_supportsReading
: 1;
39 bool m_supportsDeleting
: 1;
40 bool m_supportsWriting
: 1;
41 bool m_supportsMoving
: 1;
46 KonqFileItemCapabilities::KonqFileItemCapabilities()
47 : d(new KonqFileItemCapabilitiesPrivate
)
51 KonqFileItemCapabilities::KonqFileItemCapabilities(const KFileItemList
& items
)
52 : d(new KonqFileItemCapabilitiesPrivate
)
57 void KonqFileItemCapabilities::setItems(const KFileItemList
& items
)
59 const bool initialValue
= !items
.isEmpty();
60 d
->m_supportsReading
= initialValue
;
61 d
->m_supportsDeleting
= initialValue
;
62 d
->m_supportsWriting
= initialValue
;
63 d
->m_supportsMoving
= initialValue
;
66 QFileInfo parentDirInfo
;
67 foreach (const KFileItem
&item
, items
) {
68 const KUrl url
= item
.url();
69 d
->m_isLocal
= d
->m_isLocal
&& url
.isLocalFile();
70 d
->m_supportsReading
= d
->m_supportsReading
&& KProtocolManager::supportsReading(url
);
71 d
->m_supportsDeleting
= d
->m_supportsDeleting
&& KProtocolManager::supportsDeleting(url
);
72 d
->m_supportsWriting
= d
->m_supportsWriting
&& KProtocolManager::supportsWriting(url
) && item
.isWritable();
73 d
->m_supportsMoving
= d
->m_supportsMoving
&& KProtocolManager::supportsMoving(url
);
75 // For local files we can do better: check if we have write permission in parent directory
76 if (d
->m_isLocal
&& (d
->m_supportsDeleting
|| d
->m_supportsMoving
)) {
77 const QString directory
= url
.directory();
78 if (parentDirInfo
.filePath() != directory
) {
79 parentDirInfo
.setFile(directory
);
81 if (!parentDirInfo
.isWritable()) {
82 d
->m_supportsDeleting
= false;
83 d
->m_supportsMoving
= false;
89 KonqFileItemCapabilities::KonqFileItemCapabilities(const KonqFileItemCapabilities
& other
)
94 KonqFileItemCapabilities
& KonqFileItemCapabilities::operator=(const KonqFileItemCapabilities
& other
)
100 KonqFileItemCapabilities::~KonqFileItemCapabilities()
104 bool KonqFileItemCapabilities::supportsReading() const
106 return d
->m_supportsReading
;
109 bool KonqFileItemCapabilities::supportsDeleting() const
111 return d
->m_supportsDeleting
;
114 bool KonqFileItemCapabilities::supportsWriting() const
116 return d
->m_supportsWriting
;
119 bool KonqFileItemCapabilities::supportsMoving() const
121 return d
->m_supportsMoving
;
124 bool KonqFileItemCapabilities::isLocal() const