1 /* This file is part of the KDE project
3 Copyright 2008 David Faure <faure@kde.org>
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Library General Public License as published
7 by the Free Software Foundation; either version 2 of the License or
8 ( at your option ) version 3 or, at the discretion of KDE e.V.
9 ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
22 #include "konq_popupmenuinformation.h"
23 #include <kfileitem.h>
25 class KonqPopupMenuInformationPrivate
: public QSharedData
28 KonqPopupMenuInformationPrivate()
32 QWidget
* m_parentWidget
;
33 KFileItemList m_items
;
34 KonqFileItemCapabilities m_capabilities
;
41 KonqPopupMenuInformation::KonqPopupMenuInformation()
42 : d(new KonqPopupMenuInformationPrivate
)
46 KonqPopupMenuInformation::~KonqPopupMenuInformation()
50 KonqPopupMenuInformation::KonqPopupMenuInformation(const KonqPopupMenuInformation
& other
)
55 KonqPopupMenuInformation
& KonqPopupMenuInformation::operator=(const KonqPopupMenuInformation
& other
)
61 void KonqPopupMenuInformation::setItems(const KFileItemList
& items
)
63 Q_ASSERT(!items
.isEmpty());
65 d
->m_capabilities
.setItems(items
);
66 d
->m_mimeType
= items
.first().mimetype();
67 d
->m_mimeGroup
= d
->m_mimeType
.left(d
->m_mimeType
.indexOf('/'));
68 d
->m_isDirectory
= items
.first().isDir();
69 d
->m_urlList
= items
.targetUrlList();
70 if (items
.count() > 1) {
71 KFileItemList::const_iterator kit
= items
.begin();
72 const KFileItemList::const_iterator kend
= items
.end();
73 for ( ; kit
!= kend
; ++kit
) {
74 const QString itemMimeType
= (*kit
).mimetype();
75 // Determine if common mimetype among all items
76 if (d
->m_mimeType
!= itemMimeType
) {
77 d
->m_mimeType
.clear();
78 if (d
->m_mimeGroup
!= itemMimeType
.left(itemMimeType
.indexOf('/')))
79 d
->m_mimeGroup
.clear(); // mimetype groups are different as well!
81 if (d
->m_isDirectory
&& !(*kit
).isDir())
82 d
->m_isDirectory
= false;
87 KFileItemList
KonqPopupMenuInformation::items() const
92 KUrl::List
KonqPopupMenuInformation::urlList() const
97 bool KonqPopupMenuInformation::isDirectory() const
99 return d
->m_isDirectory
;
102 void KonqPopupMenuInformation::setParentWidget(QWidget
* parentWidget
)
104 d
->m_parentWidget
= parentWidget
;
107 QWidget
* KonqPopupMenuInformation::parentWidget() const
109 return d
->m_parentWidget
;
112 QString
KonqPopupMenuInformation::mimeType() const
114 return d
->m_mimeType
;
117 QString
KonqPopupMenuInformation::mimeGroup() const
119 return d
->m_mimeGroup
;
122 KonqFileItemCapabilities
KonqPopupMenuInformation::capabilities() const
124 return d
->m_capabilities
;