File indexing completed on 2025-01-05 04:47:00
0001 /* 0002 SPDX-FileCopyrightText: 2011 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "exception.h" 0010 #include "query.h" 0011 0012 namespace Akonadi 0013 { 0014 namespace Server 0015 { 0016 class PartType; 0017 0018 AKONADI_EXCEPTION_MAKE_INSTANCE(PartTypeException); 0019 0020 /** 0021 * Methods for dealing with the PartType table. 0022 */ 0023 namespace PartTypeHelper 0024 { 0025 /** 0026 * Retrieve (or create) PartType for the given fully qualified name. 0027 * @param fqName Fully qualified name (NS:NAME). 0028 * @throws PartTypeException 0029 */ 0030 PartType fromFqName(const QString &fqName); 0031 0032 /** 0033 * Convenience overload of the above. 0034 */ 0035 PartType fromFqName(const QByteArray &fqName); 0036 0037 /** 0038 * Retrieve (or create) PartType for the given namespace and type name. 0039 * @param ns Namespace 0040 * @param typeName Part type name. 0041 * @throws PartTypeException 0042 */ 0043 PartType fromFqName(const QString &ns, const QString &typeName); 0044 0045 /** 0046 * Returns a query condition that matches the given part. 0047 * @param fqName fully-qualified part type name 0048 * @throws PartTypeException 0049 */ 0050 Query::Condition conditionFromFqName(const QString &fqName); 0051 0052 /** 0053 * Returns a query condition that matches the given part type list. 0054 * @param fqNames fully qualified part type name list 0055 * @throws PartTypeException 0056 */ 0057 Query::Condition conditionFromFqNames(const QStringList &fqNames); 0058 0059 /** 0060 * Convenience overload for the above. 0061 */ 0062 template<template<typename> class T> 0063 Query::Condition conditionFromFqNames(const T<QByteArray> &fqNames) 0064 { 0065 Query::Condition c; 0066 c.setSubQueryMode(Query::Or); 0067 for (const QByteArray &fqName : fqNames) { 0068 c.addCondition(conditionFromFqName(QLatin1StringView(fqName))); 0069 } 0070 return c; 0071 } 0072 0073 /** 0074 * Parses a fully qualified part type name into namespace/name. 0075 * @param fqName fully-qualified part type name 0076 * @throws PartTypeException if @p fqName does not match the NS:NAME schema 0077 * @internal 0078 */ 0079 std::pair<QString, QString> parseFqName(const QString &fqName); 0080 0081 /** 0082 * Returns full part name 0083 */ 0084 QString fullName(const PartType &type); 0085 0086 } // namespace PartTypeHelper 0087 0088 } // namespace Server 0089 } // namespace Akonadi