source: SMSSender/lib/libdatatypes/src/business/BCGroup.cpp @ 43:10dd65d71f7f

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