]>
cloud.milkyroute.net Git - dolphin.git/blob - src/fileitemcapabilities.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
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. *
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. *
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 ***************************************************************************/
20 #include "fileitemcapabilities.h"
22 #include <kfileitem.h>
23 #include <kprotocolmanager.h>
27 FileItemCapabilities::FileItemCapabilities(const KFileItemList
& items
) :
28 m_supportsReading(true),
29 m_supportsDeleting(true),
30 m_supportsWriting(true),
31 m_supportsMoving(true),
34 QFileInfo parentDirInfo
;
35 foreach (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::supportsReading(url
);
40 m_supportsWriting
= m_supportsWriting
&& KProtocolManager::supportsWriting(url
);
41 m_supportsMoving
= m_supportsMoving
&& KProtocolManager::supportsMoving(url
);
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
);
50 if (!parentDirInfo
.isWritable()) {
51 m_supportsDeleting
= false;
52 m_supportsMoving
= false;
58 FileItemCapabilities::~FileItemCapabilities()