• Skip to content
  • Skip to link menu
KDE API Documentation - emaillistmodel.cpp Source File (KPeople)
  • KDE Home
  • Contact Us
 

KPeople

  • frameworks
  • kpeople
  • src
  • widgets
  • plugins
emaillistmodel.cpp
1 /*
2  Copyright 2014 Nilesh Suthar <nileshsuthar@live.in>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "emaillistmodel.h"
20 
21 #include <QDebug>
22 #include <KGlobal>
23 #include <KLocale>
24 
25 EmailListModel::EmailListModel(QObject *parent) : QAbstractListModel(parent)
26 {
27 }
28 
29 int EmailListModel::rowCount(const QModelIndex &parent) const
30 {
31  Q_UNUSED(parent)
32  return emailList.count();
33 }
34 
35 QVariant EmailListModel::data(const QModelIndex &index, int role) const
36 {
37 
38  if (!index.isValid()) {
39  return QVariant();
40  }
41 
42  EmailItem mail = emailList.at(index.row());
43 
44  switch (role) {
45  case SubjectRole:
46  if (mail.subject == "") {
47  mail.subject = i18n("No Subject");
48  }
49  mail.subject.replace('\n', ' ');
50  return mail.subject;
51 
52  case BodyRole:
53  mail.body.replace('\n', ' ');
54  return mail.body;
55 
56  case TimeRole:
57  return KGlobal::locale()->formatDateTime(mail.date.dateTime(), KLocale::FancyShortDate);
58  }
59  return QVariant();
60 }
61 
62 void EmailListModel::addEmail(const EmailItem &mail)
63 {
64  beginInsertRows(QModelIndex(), emailList.count(), emailList.count());
65  emailList << mail;
66  endInsertRows();
67 }
68 
69 QUrl EmailListModel::getItemUrl(int row)
70 {
71  return emailList.at(row).url;
72 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Fri Feb 13 2015 15:16:39 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KPeople

Skip menu "KPeople"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List

Class Picker

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal