Messagelib

storagemodelbase.cpp
1 /******************************************************************************
2  *
3  * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <[email protected]>
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 
15 StorageModel::StorageModel(QObject *parent)
16  : QAbstractItemModel(parent)
17 {
18 }
19 
20 StorageModel::~StorageModel() = default;
21 
23 {
24  return rowCount(QModelIndex());
25 }
26 
27 unsigned long StorageModel::preSelectedMessage() const
28 {
29  const QString storageModelId = id();
30  Q_ASSERT(!storageModelId.isEmpty());
31 
32  KConfigGroup conf(MessageListSettings::self()->config(), MessageList::Util::storageModelSelectedMessageGroup());
33 
34  // QVariant supports unsigned int OR unsigned long long int, NOT unsigned long int... doh...
35  qulonglong defValue = 0;
36 
37  return conf.readEntry(MessageList::Util::messageUniqueIdConfigName().arg(storageModelId), defValue);
38 }
39 
40 void StorageModel::savePreSelectedMessage(unsigned long uniqueIdOfMessage)
41 {
42  const QString storageModelId = id();
43  if (storageModelId.isEmpty()) {
44  // This happens when deleting a collection, and this is called when switching away from it
45  return;
46  }
47 
48  KConfigGroup conf(MessageListSettings::self()->config(), MessageList::Util::storageModelSelectedMessageGroup());
49 
50  if (uniqueIdOfMessage) {
51  // QVariant supports unsigned int OR unsigned long long int, NOT unsigned long int... doh...
52  qulonglong val = uniqueIdOfMessage;
53 
54  conf.writeEntry(MessageList::Util::messageUniqueIdConfigName().arg(storageModelId), val);
55  } else {
56  conf.deleteEntry(MessageList::Util::messageUniqueIdConfigName().arg(storageModelId));
57  }
58 }
QString readEntry(const char *key, const char *aDefault=nullptr) const
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
unsigned long preSelectedMessage() const
Returns the unique id of the last selected message for this StorageModel.
void deleteEntry(const char *key, WriteConfigFlags pFlags=Normal)
int initialUnreadRowCountGuess() const override
Returns (a guess for) the number of unread messages: must be pessimistic (i.e.
QString id() const override
Returns an unique id for this Storage collection.
bool isEmpty() const const
void savePreSelectedMessage(unsigned long uniqueIdOfMessage)
Stores in the unique id of the last selected message for the specified StorageModel.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu May 19 2022 03:53:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.