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 "messagelistutil_p.h"
11 #include "messagelistsettings.h"
12 
13 using namespace MessageList::Core;
14 
15 StorageModel::StorageModel(QObject *parent)
16  : QAbstractItemModel(parent)
17 {
18 }
19 
20 StorageModel::~StorageModel()
21 {
22 }
23 
25 {
26  return rowCount(QModelIndex());
27 }
28 
29 unsigned long StorageModel::preSelectedMessage() const
30 {
31  const QString storageModelId = id();
32  Q_ASSERT(!storageModelId.isEmpty());
33 
34  KConfigGroup conf(MessageListSettings::self()->config(),
35  MessageList::Util::storageModelSelectedMessageGroup());
36 
37  // QVariant supports unsigned int OR unsigned long long int, NOT unsigned long int... doh...
38  qulonglong defValue = 0;
39 
40  return conf.readEntry(MessageList::Util::messageUniqueIdConfigName().arg(storageModelId), defValue);
41 }
42 
43 void StorageModel::savePreSelectedMessage(unsigned long uniqueIdOfMessage)
44 {
45  const QString storageModelId = id();
46  if (storageModelId.isEmpty()) {
47  // This happens when deleting a collection, and this is called when switching away from it
48  return;
49  }
50 
51  KConfigGroup conf(MessageListSettings::self()->config(),
52  MessageList::Util::storageModelSelectedMessageGroup());
53 
54  if (uniqueIdOfMessage) {
55  // QVariant supports unsigned int OR unsigned long long int, NOT unsigned long int... doh...
56  qulonglong val = uniqueIdOfMessage;
57 
58  conf.writeEntry(MessageList::Util::messageUniqueIdConfigName().arg(storageModelId), val);
59  } else {
60  conf.deleteEntry(MessageList::Util::messageUniqueIdConfigName().arg(storageModelId));
61  }
62 }
void savePreSelectedMessage(unsigned long uniqueIdOfMessage)
Stores in the unique id of the last selected message for the specified StorageModel.
int initialUnreadRowCountGuess() const override
Returns (a guess for) the number of unread messages: must be pessimistic (i.e.
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
The implementation independent part of the MessageList library.
Definition: aggregation.h:21
QString id() const override
Returns an unique id for this Storage collection.
void deleteEntry(const QString &pKey, WriteConfigFlags pFlags=Normal)
unsigned long preSelectedMessage() const
Returns the unique id of the last selected message for this StorageModel.
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Nov 26 2020 23:12:19 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.