1 /****************************************************************************** 2 * 3 * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net> 4 * 5 * SPDX-License-Identifier: GPL-2.0-or-later 6 * 7 *******************************************************************************/ 8 9 #include "core/storagemodelbase.h" 10 #include "messagelistsettings.h" 11 #include "messagelistutil_p.h" 12 13 using namespace MessageList::Core; 14 StorageModel(QObject * parent)15StorageModel::StorageModel(QObject *parent) 16 : QAbstractItemModel(parent) 17 { 18 } 19 ~StorageModel()20StorageModel::~StorageModel() 21 { 22 } 23 initialUnreadRowCountGuess() const24int StorageModel::initialUnreadRowCountGuess() const 25 { 26 return rowCount(QModelIndex()); 27 } 28 preSelectedMessage() const29unsigned long StorageModel::preSelectedMessage() const 30 { 31 const QString storageModelId = id(); 32 Q_ASSERT(!storageModelId.isEmpty()); 33 34 KConfigGroup conf(MessageListSettings::self()->config(), MessageList::Util::storageModelSelectedMessageGroup()); 35 36 // QVariant supports unsigned int OR unsigned long long int, NOT unsigned long int... doh... 37 qulonglong defValue = 0; 38 39 return conf.readEntry(MessageList::Util::messageUniqueIdConfigName().arg(storageModelId), defValue); 40 } 41 savePreSelectedMessage(unsigned long uniqueIdOfMessage)42void StorageModel::savePreSelectedMessage(unsigned long uniqueIdOfMessage) 43 { 44 const QString storageModelId = id(); 45 if (storageModelId.isEmpty()) { 46 // This happens when deleting a collection, and this is called when switching away from it 47 return; 48 } 49 50 KConfigGroup conf(MessageListSettings::self()->config(), MessageList::Util::storageModelSelectedMessageGroup()); 51 52 if (uniqueIdOfMessage) { 53 // QVariant supports unsigned int OR unsigned long long int, NOT unsigned long int... doh... 54 qulonglong val = uniqueIdOfMessage; 55 56 conf.writeEntry(MessageList::Util::messageUniqueIdConfigName().arg(storageModelId), val); 57 } else { 58 conf.deleteEntry(MessageList::Util::messageUniqueIdConfigName().arg(storageModelId)); 59 } 60 } 61