File indexing completed on 2024-11-24 04:44:20
0001 /* 0002 SPDX-FileCopyrightText: 2009 Bertjan Broeksema <broeksema@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "deleteditemsattribute.h" 0008 0009 DeletedItemsAttribute::DeletedItemsAttribute() = default; 0010 0011 DeletedItemsAttribute::DeletedItemsAttribute(const DeletedItemsAttribute &other) 0012 : Akonadi::Attribute() 0013 { 0014 if (&other == this) { 0015 return; 0016 } 0017 0018 mDeletedItemOffsets = other.mDeletedItemOffsets; 0019 } 0020 0021 DeletedItemsAttribute::~DeletedItemsAttribute() = default; 0022 0023 void DeletedItemsAttribute::addDeletedItemOffset(quint64 offset) 0024 { 0025 mDeletedItemOffsets.insert(offset); 0026 } 0027 0028 DeletedItemsAttribute *DeletedItemsAttribute::clone() const 0029 { 0030 return new DeletedItemsAttribute(*this); 0031 } 0032 0033 QSet<quint64> DeletedItemsAttribute::deletedItemOffsets() const 0034 { 0035 return mDeletedItemOffsets; 0036 } 0037 0038 KMBox::MBoxEntry::List DeletedItemsAttribute::deletedItemEntries() const 0039 { 0040 KMBox::MBoxEntry::List entries; 0041 entries.reserve(mDeletedItemOffsets.count()); 0042 for (quint64 offset : std::as_const(mDeletedItemOffsets)) { 0043 entries << KMBox::MBoxEntry(offset); 0044 } 0045 0046 return entries; 0047 } 0048 0049 void DeletedItemsAttribute::deserialize(const QByteArray &data) 0050 { 0051 const QList<QByteArray> offsets = data.split(','); 0052 mDeletedItemOffsets.clear(); 0053 mDeletedItemOffsets.reserve(offsets.count()); 0054 for (const QByteArray &offset : offsets) { 0055 mDeletedItemOffsets.insert(offset.toULongLong()); 0056 } 0057 } 0058 0059 QByteArray DeletedItemsAttribute::serialized() const 0060 { 0061 QByteArray serialized; 0062 0063 for (quint64 offset : std::as_const(mDeletedItemOffsets)) { 0064 serialized += QByteArray::number(offset) + ','; 0065 } 0066 0067 serialized.chop(1); // Remove the last ',' 0068 0069 return serialized; 0070 } 0071 0072 int DeletedItemsAttribute::offsetCount() const 0073 { 0074 return mDeletedItemOffsets.size(); 0075 } 0076 0077 QByteArray DeletedItemsAttribute::type() const 0078 { 0079 static const QByteArray sType("DeletedMboxItems"); 0080 return sType; 0081 } 0082 0083 bool DeletedItemsAttribute::operator==(const DeletedItemsAttribute &other) const 0084 { 0085 return mDeletedItemOffsets == other.deletedItemOffsets(); 0086 }