-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.cpp
115 lines (99 loc) · 3.01 KB
/
account.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/************************************************
*
* Copyright © 2009-2010 Florian Staudacher
*
*
* This file is part of FSugar.
*
* FSugar is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FSugar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FSugar. If not, see <http://www.gnu.org/licenses/>.
*
***********************************************/
#include <QtGui>
#include "sugarcrm.h"
#include "abstractitem.h"
#include "account.h"
#include "note.h"
#include "notesmodel.h"
Account::Account(QObject *parent) :
AbstractItem(parent)
{
type = "Accounts";
}
bool Account::operator<(const Account *other) const
{
qDebug() << "comparing accounts" << name << "and" << other->name;
if(name < other->name)
return true;
return false;
}
void Account::save()
{
crm->updateAccount(id, name, description, address_street, address_city,
address_postalcode, address_country, phone_office,
phone_fax, phone_alternate, email, website, category);
}
void Account::getChildren()
{
AbstractItem::getChildren();
getContacts();
}
void Account::getContacts()
{
contacts.clear();
connect(crm, SIGNAL(dataAvailable(QString)),
this, SLOT(populateContacts(QString)));
crm->getEntryList("Contacts",
QString("account_id = \"%1\"").arg(id),
"last_name",
0,
"",
70,
0);
}
void Account::openEmail()
{
useAttribute(email, "email");
}
void Account::gotoWebsite()
{
useAttribute(website, "website");
}
void Account::populateContacts(const QString _id)
{
if(_id.isEmpty()) emit contactsAvailable();
if(_id != id) return;
contacts.clear();
QMap<QString, QMap<QString, QString> >::const_iterator i = crm->entries->begin();
while (i != crm->entries->end()) {
Contact *tmp = new Contact();
tmp->id = i.value().value("id");
tmp->firstName = i.value().value("first_name");
tmp->lastName = i.value().value("last_name");
tmp->description = i.value().value("description");
tmp->phoneWork = i.value().value("phone_work");
tmp->phoneFax = i.value().value("phone_fax");
tmp->phoneHome = i.value().value("phone_home");
tmp->phoneMobile = i.value().value("phone_mobile");
tmp->email1 = i.value().value("email1");
tmp->email2 = i.value().value("email2");
tmp->addressStreet = i.value().value("primary_address_street");
tmp->addressCity = i.value().value("primary_address_city");
tmp->addressPostalcode = i.value().value("primary_address_postalcode");
tmp->addressCountry = i.value().value("primary_address_country");
contacts.append(tmp);
i++;
}
emit contactsAvailable();
}