From 0f726c30f5f11990d325bc5e55015c42c80cd9d2 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 1 Dec 2017 22:16:24 +0400 Subject: fixed code style on all source files (*.c *.cpp *.h) using astyle --style=allman --lineend=linux --indent=tab --pad-oper --- pica-client/contacts.cpp | 214 +++++++++++++++++++++++------------------------ 1 file changed, 107 insertions(+), 107 deletions(-) (limited to 'pica-client/contacts.cpp') diff --git a/pica-client/contacts.cpp b/pica-client/contacts.cpp index 0ae0338..44bce24 100644 --- a/pica-client/contacts.cpp +++ b/pica-client/contacts.cpp @@ -4,180 +4,180 @@ //#include Contacts::Contacts(QString storage, QByteArray user_account_id) - : account_id_(user_account_id) + : account_id_(user_account_id) { - dbconn=QSqlDatabase::addDatabase("QSQLITE"); - dbconn.setDatabaseName(storage); + dbconn = QSqlDatabase::addDatabase("QSQLITE"); + dbconn.setDatabaseName(storage); - if (!dbconn.open()) - { - lasterr=dbconn.lastError(); - return; - } + if (!dbconn.open()) + { + lasterr = dbconn.lastError(); + return; + } //check if table contacts exists //... - QSqlQuery query; + QSqlQuery query; - query.exec("PRAGMA foreign_keys=ON;"); + query.exec("PRAGMA foreign_keys=ON;"); - //check result, if foreign keys support is on + //check result, if foreign keys support is on } bool Contacts::isOK() { - return !lasterr.isValid(); + return !lasterr.isValid(); } QString Contacts::GetLastError() { - return lasterr.text(); + return lasterr.text(); } bool Contacts::Exists(QByteArray id) { - QSqlQuery query; + QSqlQuery query; - 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.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; + query.next(); + if (query.value(0).toInt() == 1) + return true; - return false; + 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, type) values (:id, NULL, NULL, :account_id, :type)"); - query.bindValue(":id",id); - query.bindValue(":account_id",account_id_); - query.bindValue(":type", type); - 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(); + QSqlQuery query; + + if (!Exists(id)) + { + query.prepare("insert into contacts (id, name, cert_pem, account_id, type) values (:id, NULL, NULL, :account_id, :type)"); + query.bindValue(":id", id); + query.bindValue(":account_id", account_id_); + query.bindValue(":type", type); + 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(); } void Contacts::Delete(QByteArray id) { - QSqlQuery query; + QSqlQuery query; - query.prepare("delete from contacts where id=:id and account_id=:account_id"); - query.bindValue(":id",id); - query.bindValue(":account_id",account_id_); - query.exec(); + query.prepare("delete from contacts where id=:id and account_id=:account_id"); + query.bindValue(":id", id); + query.bindValue(":account_id", account_id_); + query.exec(); - lasterr=query.lastError(); + lasterr = query.lastError(); } QList Contacts::GetContacts(ContactType type) { - QList L; - ContactRecord r; - QSqlQuery query; - - query.setForwardOnly(true); - 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(); - - if (lasterr.isValid()) - return L; - - while(query.next()) - { - r.id=query.value(0).toByteArray(); - r.name=query.value(1).toString(); - //CSTRL.append(" ("+query.value(0).toString()+") "+query.value(1).toString()); - L< L; + ContactRecord r; + QSqlQuery query; + + query.setForwardOnly(true); + 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(); + + if (lasterr.isValid()) + return L; + + while(query.next()) + { + r.id = query.value(0).toByteArray(); + r.name = query.value(1).toString(); + //CSTRL.append(" ("+query.value(0).toString()+") "+query.value(1).toString()); + L << r; + } + + return L; } QString Contacts::GetContactCert(QByteArray id) { - QSqlQuery query; + QSqlQuery query; - query.prepare("select cert_pem from contacts where id=:id and account_id=:account_id"); - query.bindValue(":id",id); - query.bindValue(":account_id",account_id_); - query.exec(); + query.prepare("select cert_pem from contacts where id=:id and account_id=:account_id"); + query.bindValue(":id", id); + query.bindValue(":account_id", account_id_); + query.exec(); - lasterr=query.lastError(); + lasterr = query.lastError(); - if (lasterr.isValid()) - return QString::null; + if (lasterr.isValid()) + return QString::null; - query.next(); + query.next(); - return query.value(0).toString(); + return query.value(0).toString(); } QString Contacts::GetContactName(QByteArray id) { - QSqlQuery query; + QSqlQuery query; - query.prepare("select name from contacts where id=:id and account_id=:account_id"); - query.bindValue(":id",id); - query.bindValue(":account_id",account_id_); - query.exec(); + query.prepare("select name from contacts where id=:id and account_id=:account_id"); + query.bindValue(":id", id); + query.bindValue(":account_id", account_id_); + query.exec(); - lasterr=query.lastError(); + lasterr = query.lastError(); - if (lasterr.isValid()) - return QString::null; + if (lasterr.isValid()) + return QString::null; - query.next(); + query.next(); - return query.value(0).toString(); + return query.value(0).toString(); } void Contacts::SetContactCert(QByteArray id, QString &cert_pem) { - QSqlQuery query; + QSqlQuery query; - query.prepare("update contacts set cert_pem=:cert_pem where id=:id and account_id=:account_id"); - query.bindValue(":cert_pem",cert_pem); - query.bindValue(":id",id); - query.bindValue(":account_id",account_id_); - query.exec(); + query.prepare("update contacts set cert_pem=:cert_pem where id=:id and account_id=:account_id"); + query.bindValue(":cert_pem", cert_pem); + query.bindValue(":id", id); + query.bindValue(":account_id", account_id_); + query.exec(); - lasterr=query.lastError(); + lasterr = query.lastError(); } void Contacts::SetContactName(QByteArray id, QString name) { - QSqlQuery query; + QSqlQuery query; - query.prepare("update contacts set name=:name where id=:id and account_id=:account_id"); - query.bindValue(":name",name); - query.bindValue(":id",id); - query.bindValue(":account_id",account_id_); - query.exec(); + query.prepare("update contacts set name=:name where id=:id and account_id=:account_id"); + query.bindValue(":name", name); + query.bindValue(":id", id); + query.bindValue(":account_id", account_id_); + query.exec(); - lasterr=query.lastError(); + lasterr = query.lastError(); } -- cgit v1.2.1