File indexing completed on 2024-04-28 04:36:29
0001 /* 0002 SPDX-FileCopyrightText: 2001-2002 Matthias Hoelzer-Kluepfel <hoelzer@kde.org> 0003 SPDX-FileCopyrightText: 2001-2002 Bernd Gehrmann <bernd@kdevelop.org> 0004 SPDX-FileCopyrightText: 2001 Sandy Meier <smeier@kdevelop.org> 0005 SPDX-FileCopyrightText: 2002 Daniel Engelschalt <daniel.engelschalt@gmx.net> 0006 SPDX-FileCopyrightText: 2002 Simon Hausmann <hausmann@kde.org> 0007 SPDX-FileCopyrightText: 2002-2003 Roberto Raggi <roberto@kdevelop.org> 0008 SPDX-FileCopyrightText: 2003 Mario Scalas <mario.scalas@libero.it> 0009 SPDX-FileCopyrightText: 2003 Harald Fernengel <harry@kdevelop.org> 0010 SPDX-FileCopyrightText: 2003, 2006 Hamish Rodda <rodda@kde.org> 0011 SPDX-FileCopyrightText: 2004 Alexander Dymo <adymo@kdevelop.org> 0012 SPDX-FileCopyrightText: 2006 Adam Treat <treat@kde.org> 0013 0014 SPDX-License-Identifier: LGPL-2.0-or-later 0015 */ 0016 0017 #include "context.h" 0018 0019 #include <QList> 0020 #include <QMimeType> 0021 0022 namespace KDevelop 0023 { 0024 0025 class ContextPrivate 0026 { 0027 public: 0028 virtual ~ContextPrivate() = default; 0029 }; 0030 0031 Context::Context() 0032 : d_ptr(nullptr) 0033 {} 0034 0035 Context::Context(ContextPrivate* d) 0036 : d_ptr(d) 0037 {} 0038 0039 Context::~Context() = default; 0040 0041 bool Context::hasType( int aType ) const 0042 { 0043 return aType == this->type(); 0044 } 0045 0046 class FileContextPrivate : public ContextPrivate 0047 { 0048 public: 0049 explicit FileContextPrivate( const QList<QUrl> &urls ) 0050 : m_urls( urls ) 0051 {} 0052 0053 QList<QUrl> m_urls; 0054 }; 0055 0056 FileContext::FileContext( const QList<QUrl> &urls ) 0057 : Context(new FileContextPrivate(urls)) 0058 {} 0059 0060 FileContext::~FileContext() = default; 0061 0062 int FileContext::type() const 0063 { 0064 return Context::FileContext; 0065 } 0066 0067 QList<QUrl> FileContext::urls() const 0068 { 0069 Q_D(const FileContext); 0070 0071 return d->m_urls; 0072 } 0073 0074 class ProjectItemContextPrivate : public ContextPrivate 0075 { 0076 public: 0077 explicit ProjectItemContextPrivate( const QList<ProjectBaseItem*> &items ) 0078 : m_items( items ) 0079 {} 0080 0081 QList<ProjectBaseItem*> m_items; 0082 }; 0083 0084 ProjectItemContext::ProjectItemContext( const QList<ProjectBaseItem*> &items ) 0085 : Context(new ProjectItemContextPrivate(items)) 0086 {} 0087 0088 ProjectItemContext::~ProjectItemContext() = default; 0089 0090 int ProjectItemContext::type() const 0091 { 0092 return Context::ProjectItemContext; 0093 } 0094 0095 QList<ProjectBaseItem*> ProjectItemContext::items() const 0096 { 0097 Q_D(const ProjectItemContext); 0098 0099 return d->m_items; 0100 } 0101 0102 class OpenWithContextPrivate : public ContextPrivate 0103 { 0104 public: 0105 OpenWithContextPrivate(const QList<QUrl>& urls, const QMimeType& mimeType) 0106 : m_urls( urls ) 0107 , m_mimeType( mimeType ) 0108 {} 0109 0110 QList<QUrl> m_urls; 0111 QMimeType m_mimeType; 0112 }; 0113 0114 OpenWithContext::OpenWithContext(const QList<QUrl>& urls, const QMimeType& mimeType) 0115 : Context(new OpenWithContextPrivate(urls, mimeType)) 0116 { 0117 } 0118 0119 OpenWithContext::~OpenWithContext() = default; 0120 0121 int OpenWithContext::type() const 0122 { 0123 return Context::OpenWithContext; 0124 } 0125 0126 QList<QUrl> OpenWithContext::urls() const 0127 { 0128 Q_D(const OpenWithContext); 0129 0130 return d->m_urls; 0131 } 0132 0133 QMimeType OpenWithContext::mimeType() const 0134 { 0135 Q_D(const OpenWithContext); 0136 0137 return d->m_mimeType; 0138 } 0139 0140 } 0141