~ubuntu-branches/ubuntu/wily/udj-desktop-client/wily

« back to all changes in this revision

Viewing changes to src/ParticipantsModel.cpp

  • Committer: Package Import Robot
  • Author(s): Nathan Handler
  • Date: 2012-11-14 15:29:07 UTC
  • mfrom: (1.2.1) (4.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20121114152907-8uj9bwcima77vu28
Tags: 0.6.3-1
* New upstream release
* debian/copyright: Add stanzas for new upstream files
* debian/rules:
  - Do not install ./usr/share/doc/udj/UDJ.1
  - Remove /usr/share/doc/udj directory if it is empty
* debian/control:
  - Bump Standards-Version to 3.9.4 (no changes)
  - Use my @debian.org address for the Maintainer field

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2011 Kurtis L. Nusbaum
 
3
 * 
 
4
 * This file is part of UDJ.
 
5
 * 
 
6
 * UDJ is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 * 
 
11
 * UDJ is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with UDJ.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
#include "ParticipantsModel.hpp"
 
20
#include "DataStore.hpp"
 
21
#include "Logger.hpp"
 
22
 
 
23
 
 
24
namespace UDJ{
 
25
 
 
26
ParticipantsModel::ParticipantsModel(DataStore* dataStore, QObject *parent)
 
27
  :QStandardItemModel(parent),
 
28
  dataStore(dataStore)
 
29
{
 
30
  setHeaders();
 
31
  connect(
 
32
    dataStore,
 
33
    SIGNAL(newParticipantList(const QVariantList&)),
 
34
    this,
 
35
    SLOT(onNewParticipantList(const QVariantList&)));
 
36
}
 
37
 
 
38
 
 
39
void ParticipantsModel::onNewParticipantList(const QVariantList& newParticipants){
 
40
  removeRows(0, rowCount());
 
41
  setHeaders();
 
42
  QVariantMap participant;
 
43
  for(int i=0; i<newParticipants.size(); ++i){
 
44
    participant = newParticipants.at(i).toMap();
 
45
    QStandardItem *newId = new QStandardItem(participant["id"].toString());
 
46
    QStandardItem *newUsername = new QStandardItem(participant["username"].toString());
 
47
    QStandardItem *newFirstName = new QStandardItem(
 
48
        getAttrWithDefault(participant,"first_name", "Unknown"));
 
49
    QStandardItem *newLastName = new QStandardItem(
 
50
        getAttrWithDefault(participant,"last_name", "Unknown"));
 
51
    QList<QStandardItem*> newRow;
 
52
    newRow << newId << newUsername << newFirstName << newLastName;
 
53
    appendRow(newRow);
 
54
  }
 
55
}
 
56
 
 
57
QString ParticipantsModel::getAttrWithDefault(
 
58
    const QVariantMap& user,
 
59
    const QString& attr,
 
60
    const QString& defaultValue)
 
61
{
 
62
  QString value = user[attr].toString();
 
63
  if(value == ""){
 
64
    return defaultValue;
 
65
  }
 
66
  return value;
 
67
}
 
68
 
 
69
void ParticipantsModel::setHeaders(){
 
70
  QStringList headers;
 
71
  headers << tr("Id") << tr("Username") << tr("First Name") << tr("Last Name");
 
72
  setHorizontalHeaderLabels(headers);
 
73
}
 
74
 
 
75
} // end namespace