30 #include "cadefs.h" |
30 #include "cadefs.h" |
31 #include "canotifier.h" |
31 #include "canotifier.h" |
32 #include "canotifier_p.h" |
32 #include "canotifier_p.h" |
33 #include "canotifiers.h" |
33 #include "canotifiers.h" |
34 |
34 |
|
35 #include "caclient_defines.h" |
35 #include "hswidgetregistryservice.h" |
36 #include "hswidgetregistryservice.h" |
36 |
37 |
37 const char *DATABASE_CONNECTION_NAME = "CaService"; |
38 const char *DATABASE_CONNECTION_NAME = "CaService"; |
38 const char *DATABASE_TYPE = "QSQLITE"; |
39 const char *DATABASE_TYPE = "QSQLITE"; |
39 const char *DATABASE_NAME = "castorage.db"; |
40 const char *DATABASE_NAME = "castorage.db"; |
45 |
46 |
46 //---------------------------------------------------------------------------- |
47 //---------------------------------------------------------------------------- |
47 // |
48 // |
48 //---------------------------------------------------------------------------- |
49 //---------------------------------------------------------------------------- |
49 CaClientProxy::CaClientProxy() : |
50 CaClientProxy::CaClientProxy() : |
50 mWidgetRegistryPath("hsresources/import/widgetregistry") |
51 mWidgetRegistryPath("private/20022F35/import/widgetregistry") |
51 { |
52 { |
52 } |
53 } |
53 |
54 |
54 //---------------------------------------------------------------------------- |
55 //---------------------------------------------------------------------------- |
55 // |
56 // |
276 ErrorCode CaClientProxy::removeData(const QList<int> &entryIdList) |
277 ErrorCode CaClientProxy::removeData(const QList<int> &entryIdList) |
277 { |
278 { |
278 qDebug() << "CaClientProxy::removeData" << "entryIdList: " |
279 qDebug() << "CaClientProxy::removeData" << "entryIdList: " |
279 << entryIdList; |
280 << entryIdList; |
280 |
281 |
281 QList<CaEntry *> entryList; |
282 QList< QSharedPointer<CaEntry> > entryList; |
282 getData(entryIdList, entryList); |
283 getData(entryIdList, entryList); |
283 QList<QList<int> > parentsIds; |
284 QList<QList<int> > parentsIds; |
284 foreach(CaEntry *entry, entryList) { |
285 foreach(QSharedPointer<CaEntry> entry, entryList) { |
285 QList<int> parentIds; |
286 QList<int> parentIds; |
286 GetParentsIds(QList<int>() << entry->id(), parentIds); |
287 GetParentsIds(QList<int>() << entry->id(), parentIds); |
287 parentsIds.append(parentIds); |
288 parentsIds.append(parentIds); |
288 } |
289 } |
289 |
290 |
484 |
485 |
485 //---------------------------------------------------------------------------- |
486 //---------------------------------------------------------------------------- |
486 // |
487 // |
487 //---------------------------------------------------------------------------- |
488 //---------------------------------------------------------------------------- |
488 ErrorCode CaClientProxy::getData(const QList<int> &entryIdList, |
489 ErrorCode CaClientProxy::getData(const QList<int> &entryIdList, |
489 QList<CaEntry *> &sourceList) |
490 QList< QSharedPointer<CaEntry> > &sourceList) |
490 { |
491 { |
491 qDebug() << "CaClientProxy::getData" << "entryIdList: " |
492 qDebug() << "CaClientProxy::getData" << "entryIdList: " |
492 << entryIdList; |
493 << entryIdList; |
493 |
494 |
494 QSqlDatabase db = dbConnection(); |
495 QSqlDatabase db = dbConnection(); |
505 success = query.exec(); |
506 success = query.exec(); |
506 if (success && query.next()) { |
507 if (success && query.next()) { |
507 qDebug() << query.executedQuery(); |
508 qDebug() << query.executedQuery(); |
508 int role = |
509 int role = |
509 query.value(query.record().indexOf("EN_ROLE")).toInt(); |
510 query.value(query.record().indexOf("EN_ROLE")).toInt(); |
510 CaEntry *entry = new CaEntry((EntryRole) role); |
511 QSharedPointer<CaEntry> entry (new CaEntry((EntryRole) role)); |
511 CaObjectAdapter::setId(*entry, |
512 CaObjectAdapter::setId(*entry, |
512 query.value(query.record().indexOf("ENTRY_ID")).toInt()); |
513 query.value(query.record().indexOf("ENTRY_ID")).toInt()); |
513 entry->setText(query.value( |
514 entry->setText(query.value( |
514 query.record().indexOf("EN_TEXT")).toString()); |
515 query.record().indexOf("EN_TEXT")).toString()); |
515 entry->setDescription(query.value( |
516 entry->setDescription(query.value( |
569 |
570 |
570 //---------------------------------------------------------------------------- |
571 //---------------------------------------------------------------------------- |
571 // |
572 // |
572 //---------------------------------------------------------------------------- |
573 //---------------------------------------------------------------------------- |
573 ErrorCode CaClientProxy::getData(const CaQuery &query, |
574 ErrorCode CaClientProxy::getData(const CaQuery &query, |
574 QList<CaEntry *> &sourceList) |
575 QList< QSharedPointer<CaEntry> > &sourceList) |
575 { |
576 { |
576 QList<int> entryIdList; |
577 QList<int> entryIdList; |
577 ErrorCode errorCode = getEntryIds(query, entryIdList); |
578 ErrorCode errorCode = getEntryIds(query, entryIdList); |
578 if (errorCode == NoErrorCode) { |
579 if (errorCode == NoErrorCode) { |
579 errorCode = getData(entryIdList, sourceList); |
580 errorCode = getData(entryIdList, sourceList); |
707 ErrorCode CaClientProxy::executeCommand(const CaEntry &entry, |
708 ErrorCode CaClientProxy::executeCommand(const CaEntry &entry, |
708 const QString &command) |
709 const QString &command) |
709 { |
710 { |
710 qDebug() << "CaClientProxy::executeCommand" << "entry id: " |
711 qDebug() << "CaClientProxy::executeCommand" << "entry id: " |
711 << entry.id() << "command: " << command; |
712 << entry.id() << "command: " << command; |
712 return NoErrorCode; |
713 |
|
714 ErrorCode result = NoErrorCode; |
|
715 if (command != caCmdOpen && command != QString("remove")) { |
|
716 result = UnknownErrorCode; |
|
717 } |
|
718 return result; |
713 } |
719 } |
714 |
720 |
715 //---------------------------------------------------------------------------- |
721 //---------------------------------------------------------------------------- |
716 // |
722 // |
717 //---------------------------------------------------------------------------- |
723 //---------------------------------------------------------------------------- |
718 ErrorCode CaClientProxy::touch(const CaEntry &entry) |
724 ErrorCode CaClientProxy::touch(const CaEntry &entry) |
719 { |
725 { |
720 const int id = entry.id(); |
726 int id = entry.id(); |
|
727 if (id <= 0) { |
|
728 const int uid = entry.attribute( |
|
729 QString(APPLICATION_UID_ATTRIBUTE_NAME)).toInt(); |
|
730 id = getEntryIdByUid(entry, uid); |
|
731 } |
721 |
732 |
722 qDebug() << "CaClientProxy::touch" << "id: " << id; |
733 qDebug() << "CaClientProxy::touch" << "id: " << id; |
723 |
734 |
724 QSqlDatabase db = dbConnection(); |
735 QSqlDatabase db = dbConnection(); |
725 QSqlQuery query(db); |
736 QSqlQuery query(db); |
740 } |
751 } |
741 |
752 |
742 ErrorCode error = NoErrorCode; |
753 ErrorCode error = NoErrorCode; |
743 if (success) { |
754 if (success) { |
744 query.exec("commit"); |
755 query.exec("commit"); |
745 QList<CaEntry *> entryList; |
756 QList< QSharedPointer<CaEntry> > entryList; |
746 if (getData(QList<int>() << id, entryList) == NoErrorCode) { |
757 if (getData(QList<int>() << id, entryList) == NoErrorCode) { |
747 QList<int> parentIds; |
758 QList<int> parentIds; |
748 GetParentsIds(QList<int>() << id, parentIds); |
759 GetParentsIds(QList<int>() << id, parentIds); |
749 CaNotifiers::Notify(*entryList[0], UpdateChangeType, parentIds); |
760 CaNotifiers::NotifyTouched(id); |
750 } |
761 } |
751 } else { |
762 } else { |
752 query.exec("rollback"); |
763 query.exec("rollback"); |
753 error = UnknownErrorCode; |
764 error = UnknownErrorCode; |
754 } |
765 } |
1016 parentIds.append(newParentIds); |
1027 parentIds.append(newParentIds); |
1017 GetParentsIds(newParentIds, parentIds); |
1028 GetParentsIds(newParentIds, parentIds); |
1018 } |
1029 } |
1019 return success; |
1030 return success; |
1020 } |
1031 } |
|
1032 |
|
1033 int CaClientProxy::getEntryIdByUid(const CaEntry &entry, const int uid) |
|
1034 { |
|
1035 int result = -1; |
|
1036 |
|
1037 QSqlQuery query(dbConnection()); |
|
1038 query.prepare("SELECT ENTRY_ID from CA_ENTRY where EN_UID=?"); |
|
1039 query.addBindValue(uid); |
|
1040 bool success = query.exec(); |
|
1041 |
|
1042 if (success && (query.first())) { |
|
1043 result = query.value(query.record().indexOf("ENTRY_ID")).toInt(); |
|
1044 } |
|
1045 |
|
1046 return result; |
|
1047 } |