source: SMSSender/lib/libdatatypes/src/sgoup.cpp @ 71:415b45c71663

3.0
Last change on this file since 71:415b45c71663 was 71:415b45c71663, checked in by Sämy Zehnder <saemy.zehnder@…>, 12 years ago
  • Reorganized all the libraries. libinterfaces and libgateways are removed now and libdatatypes contains now all these files.
File size: 2.4 KB
Line 
1/*
2 * BCGroup.cpp
3 *
4 *  Created on: Jun 20, 2009
5 *      Author: saemy
6 */
7
8#include "sgroup.h"
9
10SGroup::SGroup()
11  : id_(-1)
12  , name_("")
13  , image_(QImage())
14{
15    eventMapper_ = new SGroupEventMapper(this);
16}
17
18SGroupEventMapper* SGroup::eventMapper() const {
19    return eventMapper_;
20}
21IGroupEvents* SGroup::groupEvents() const {
22    return static_cast<IGroupEvents*>(eventMapper());
23}
24
25
26int SGroup::id() const{
27    return id_;
28}
29QString SGroup::name() const{
30    return name_;
31}
32QImage SGroup::image() const{
33    return image_;
34}
35QSet<IContact*> SGroup::contacts() const{
36    return contactList_.values().toSet();
37}
38
39
40void SGroup::setId(int id){
41    if (id_ == id) return;
42
43    int oldId = id_;
44    id_ = id;
45
46    emit groupEvents()->idChanged(oldId, id);
47    emit groupEvents()->dataChanged();
48}
49void SGroup::setName(const QString& name){
50    SET_IF_DIFFERENT(name_, name.trimmed());
51    emit groupEvents()->dataChanged();
52}
53void SGroup::setImage(const QImage& image){
54    SET_IF_DIFFERENT(image_, image);
55    emit groupEvents()->dataChanged();
56}
57void SGroup::setContacts(const QSet<IContact*>& contacts){
58    foreach (IContact* contact, contactList_) {
59        if (!contacts.contains(contact))
60            removeContactFromList(contact);
61    }
62    foreach (IContact* contact, contacts) {
63        addContactToList(contact);
64    }
65}
66void SGroup::addContact(IContact* contact){
67    addContactToList(contact);
68}
69void SGroup::removeContact(int contactId){
70    removeContact(contactList_[contactId]);
71}
72void SGroup::removeContact(IContact* contact){
73    removeContactFromList(contact);
74}
75
76
77void SGroup::addContactToList(IContact* contact) {
78    if ((contact == NULL) || contactList_.contains(contact->id()))
79        return;
80
81    connect(contact->eventMapper(), SIGNAL(idChanged(int, int)),
82            this, SLOT(contactIdChanged(int, int)));
83
84    contactList_.insert(contact->id(), contact);
85    emit groupEvents()->contactAdded(contact);
86}
87void SGroup::removeContactFromList(IContact* contact) {
88    if ((contact == NULL) || !contactList_.contains(contact->id()))
89        return;
90
91    disconnect(contact->eventMapper(), SIGNAL(idChanged(int, int)),
92               this, SLOT(contactIdChanged(int, int)));
93
94    contactList_.remove(contact->id());
95    emit groupEvents()->contactRemoved(contact);
96}
97
98
99void SGroup::contactIdChanged(int oldId, int newId) {
100    IContact* contact = contactList_.take(oldId);
101    if (contact != NULL)
102        contactList_.insert(newId, contact);
103}
Note: See TracBrowser for help on using the repository browser.