File indexing completed on 2024-12-15 04:54:40

0001 /******************************************************************************
0002  *
0003  *  SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  *
0007  *******************************************************************************/
0008 
0009 #include "core/storagemodelbase.h"
0010 #include "messagelistsettings.h"
0011 #include "messagelistutil_p.h"
0012 
0013 using namespace MessageList::Core;
0014 
0015 StorageModel::StorageModel(QObject *parent)
0016     : QAbstractItemModel(parent)
0017 {
0018 }
0019 
0020 StorageModel::~StorageModel() = default;
0021 
0022 int StorageModel::initialUnreadRowCountGuess() const
0023 {
0024     return rowCount(QModelIndex());
0025 }
0026 
0027 unsigned long StorageModel::preSelectedMessage() const
0028 {
0029     const QString storageModelId = id();
0030     Q_ASSERT(!storageModelId.isEmpty());
0031 
0032     KConfigGroup conf(MessageListSettings::self()->config(), MessageList::Util::storageModelSelectedMessageGroup());
0033 
0034     // QVariant supports unsigned int OR unsigned long long int, NOT unsigned long int... doh...
0035     qulonglong defValue = 0;
0036 
0037     return conf.readEntry(MessageList::Util::messageUniqueIdConfigName().arg(storageModelId), defValue);
0038 }
0039 
0040 void StorageModel::savePreSelectedMessage(unsigned long uniqueIdOfMessage)
0041 {
0042     const QString storageModelId = id();
0043     if (storageModelId.isEmpty()) {
0044         // This happens when deleting a collection, and this is called when switching away from it
0045         return;
0046     }
0047 
0048     KConfigGroup conf(MessageListSettings::self()->config(), MessageList::Util::storageModelSelectedMessageGroup());
0049 
0050     if (uniqueIdOfMessage) {
0051         // QVariant supports unsigned int OR unsigned long long int, NOT unsigned long int... doh...
0052         qulonglong val = uniqueIdOfMessage;
0053 
0054         conf.writeEntry(MessageList::Util::messageUniqueIdConfigName().arg(storageModelId), val);
0055     } else {
0056         conf.deleteEntry(MessageList::Util::messageUniqueIdConfigName().arg(storageModelId));
0057     }
0058 }
0059 
0060 #include "moc_storagemodelbase.cpp"