~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to apps/lib/konq/konq_fileitemcapabilities.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ana Beatriz Guerrero Lopez
  • Date: 2009-04-05 05:22:13 UTC
  • mfrom: (0.4.2 experimental) (0.2.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 235.
  • Revision ID: james.westby@ubuntu.com-20090405052213-39thr4l6p2ss07uj
Tags: 4:4.2.2-1
* New upstream release:
  - khtml fixes. (Closes: #290285, #359680)
  - Default konsole sessions can be deleted. (Closes: #286342)
  - Tag widget uses standard application palette. (Closes: #444800)
  - ... and surely many more but we have lost track...

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at>                  *
 
3
 *   Copyright (C) 2008 by George Goldberg <grundleborg@googlemail.com>    *
 
4
 *                                                                         *
 
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.                                   *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 ***************************************************************************/
 
20
 
 
21
#include "konq_fileitemcapabilities.h"
 
22
 
 
23
#include <kfileitem.h>
 
24
#include <kprotocolmanager.h>
 
25
 
 
26
#include <QFileInfo>
 
27
 
 
28
class KonqFileItemCapabilitiesPrivate : public QSharedData
 
29
{
 
30
public:
 
31
    KonqFileItemCapabilitiesPrivate()
 
32
        : m_supportsReading(false),
 
33
          m_supportsDeleting(false),
 
34
          m_supportsWriting(false),
 
35
          m_supportsMoving(false),
 
36
          m_isLocal(true)
 
37
    { }
 
38
    bool m_supportsReading : 1;
 
39
    bool m_supportsDeleting : 1;
 
40
    bool m_supportsWriting : 1;
 
41
    bool m_supportsMoving : 1;
 
42
    bool m_isLocal : 1;
 
43
};
 
44
 
 
45
 
 
46
KonqFileItemCapabilities::KonqFileItemCapabilities()
 
47
    : d(new KonqFileItemCapabilitiesPrivate)
 
48
{
 
49
}
 
50
 
 
51
KonqFileItemCapabilities::KonqFileItemCapabilities(const KFileItemList& items)
 
52
    : d(new KonqFileItemCapabilitiesPrivate)
 
53
{
 
54
    setItems(items);
 
55
}
 
56
 
 
57
void KonqFileItemCapabilities::setItems(const KFileItemList& items)
 
58
{
 
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;
 
64
    d->m_isLocal = true;
 
65
 
 
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);
 
74
 
 
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);
 
80
            }
 
81
            if (!parentDirInfo.isWritable()) {
 
82
                d->m_supportsDeleting = false;
 
83
                d->m_supportsMoving = false;
 
84
            }
 
85
        }
 
86
    }
 
87
}
 
88
 
 
89
KonqFileItemCapabilities::KonqFileItemCapabilities(const KonqFileItemCapabilities& other)
 
90
    : d(other.d)
 
91
{ }
 
92
 
 
93
 
 
94
KonqFileItemCapabilities& KonqFileItemCapabilities::operator=(const KonqFileItemCapabilities& other)
 
95
{
 
96
    d = other.d;
 
97
    return *this;
 
98
}
 
99
 
 
100
KonqFileItemCapabilities::~KonqFileItemCapabilities()
 
101
{
 
102
}
 
103
 
 
104
bool KonqFileItemCapabilities::supportsReading() const
 
105
{
 
106
    return d->m_supportsReading;
 
107
}
 
108
 
 
109
bool KonqFileItemCapabilities::supportsDeleting() const
 
110
{
 
111
    return d->m_supportsDeleting;
 
112
}
 
113
 
 
114
bool KonqFileItemCapabilities::supportsWriting() const
 
115
{
 
116
    return d->m_supportsWriting;
 
117
}
 
118
 
 
119
bool KonqFileItemCapabilities::supportsMoving() const
 
120
{
 
121
    return d->m_supportsMoving;
 
122
}
 
123
 
 
124
bool KonqFileItemCapabilities::isLocal() const
 
125
{
 
126
    return d->m_isLocal;
 
127
}