diff options
| author | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2013-10-13 11:05:53 +0000 |
|---|---|---|
| committer | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2013-10-13 11:05:53 +0000 |
| commit | 147b3241bde44240de2ea14623a44c6f4207e353 (patch) | |
| tree | e51074fe9643b6ff7b098b18f1d430c06b2ff540 /pica-client/contacts.cpp | |
| parent | b09a0605693b0a350f4ee1a08896d638ebdd23ef (diff) | |
| download | pica-pica-147b3241bde44240de2ea14623a44c6f4207e353.tar.gz pica-pica-147b3241bde44240de2ea14623a44c6f4207e353.zip | |
contacts now have type - temporary, regular, blacklisted. On incoming connections from previously unknown peers new temporary contact record will be created
git-svn-id: svn://localhost/project_picapica/trunk@278 fb96df88-216d-11de-830c-f3023f12d8ac
Diffstat (limited to 'pica-client/contacts.cpp')
| -rw-r--r-- | pica-client/contacts.cpp | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/pica-client/contacts.cpp b/pica-client/contacts.cpp index fb482d2..657ab12 100644 --- a/pica-client/contacts.cpp +++ b/pica-client/contacts.cpp @@ -35,14 +35,43 @@ QString Contacts::GetLastError() return lasterr.text(); } -void Contacts::Add(QByteArray id) +bool Contacts::Exists(QByteArray id) { QSqlQuery query; - query.prepare("insert into contacts (id, name, cert_pem, account_id) values (:id, NULL, NULL, :account_id)"); - query.bindValue(":id",id); + query.setForwardOnly(true); + query.prepare("select count(*) from contacts where account_id=:account_id and id=:id"); query.bindValue(":account_id",account_id_); + query.bindValue(":id", id); query.exec(); + lasterr=query.lastError(); + + query.next(); + if (query.value(0).toInt() == 1) + return true; + + return false; +} + +void Contacts::Add(QByteArray id, ContactType type) +{ + QSqlQuery query; + + if (!Exists(id)) + { + query.prepare("insert into contacts (id, name, cert_pem, account_id) values (:id, NULL, NULL, :account_id)"); + query.bindValue(":id",id); + query.bindValue(":account_id",account_id_); + query.exec(); + } + else + { + query.prepare("update contacts set type=:type where id=:id and account_id=:account_id"); + query.bindValue(":type", type); + query.bindValue(":id", id); + query.bindValue(":account_id", account_id_); + query.exec(); + } lasterr=query.lastError(); } @@ -59,15 +88,16 @@ void Contacts::Delete(QByteArray id) lasterr=query.lastError(); } -QList<Contacts::ContactRecord> Contacts::GetContacts() +QList<Contacts::ContactRecord> Contacts::GetContacts(ContactType type) { QList<ContactRecord> L; ContactRecord r; QSqlQuery query; query.setForwardOnly(true); - query.prepare("select id, name from contacts where account_id=:account_id"); + query.prepare("select id, name from contacts where account_id=:account_id and type=:type"); query.bindValue(":account_id",account_id_); + query.bindValue(":type", type); query.exec(); lasterr=query.lastError(); |
