summaryrefslogtreecommitdiffstats
path: root/pica-client/contacts.cpp
diff options
context:
space:
mode:
authorAnton <anton@picapica>2017-12-01 22:16:24 +0400
committerAnton <anton@picapica>2017-12-01 22:16:24 +0400
commit0f726c30f5f11990d325bc5e55015c42c80cd9d2 (patch)
treef8c9b83cc440dd3a2f43285dc35199435f6e2701 /pica-client/contacts.cpp
parentac041927bc0c82e33acaa9e15fd46ecca0b77172 (diff)
downloadpica-pica-0f726c30f5f11990d325bc5e55015c42c80cd9d2.tar.gz
pica-pica-0f726c30f5f11990d325bc5e55015c42c80cd9d2.zip
fixed code style on all source files (*.c *.cpp *.h) using astyle --style=allman --lineend=linux --indent=tab --pad-oper
Diffstat (limited to 'pica-client/contacts.cpp')
-rw-r--r--pica-client/contacts.cpp214
1 files changed, 107 insertions, 107 deletions
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 <QMessageBox>
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::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 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;
+ QList<ContactRecord> 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();
}