]> cloud.milkyroute.net Git - dolphin.git/blob - src/fileitemcapabilities.cpp
Fix compil
[dolphin.git] / src / fileitemcapabilities.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "fileitemcapabilities.h"
21
22 #include <kfileitem.h>
23 #include <kprotocolmanager.h>
24
25 #include <QFileInfo>
26
27 FileItemCapabilities::FileItemCapabilities(const KFileItemList& items) :
28 m_supportsReading(true),
29 m_supportsDeleting(true),
30 m_supportsWriting(true),
31 m_supportsMoving(true),
32 m_isLocal(true)
33 {
34 QFileInfo parentDirInfo;
35 foreach (const KFileItem &item, items) {
36 const KUrl url = item.url();
37 m_isLocal = m_isLocal && url.isLocalFile();
38 m_supportsReading = m_supportsReading && KProtocolManager::supportsReading(url);
39 m_supportsDeleting = m_supportsDeleting && KProtocolManager::supportsDeleting(url);
40 m_supportsWriting = m_supportsWriting && KProtocolManager::supportsWriting(url);
41 m_supportsMoving = m_supportsMoving && KProtocolManager::supportsMoving(url);
42
43 // The following code has been taken from kdebase/apps/lib/konq/konq_popupmenu.cpp:
44 // For local files we can do better: check if we have write permission in parent directory
45 if (m_isLocal && (m_supportsDeleting || m_supportsMoving)) {
46 const QString directory = url.directory();
47 if (parentDirInfo.filePath() != directory) {
48 parentDirInfo.setFile(directory);
49 }
50 if (!parentDirInfo.isWritable()) {
51 m_supportsDeleting = false;
52 m_supportsMoving = false;
53 }
54 }
55 }
56 }
57
58 FileItemCapabilities::~FileItemCapabilities()
59 {
60 }