Replacing widget handle with tizenid in property DAO
[framework/web/wrt-commons.git] / modules / widget_dao / dao / widget_dao_read_only.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * This file contains the declaration of widget dao class.
18  *
19  * @file    widget_dao_read_only.cpp
20  * @author  Yang Jie (jie2.yang@samsung.com)
21  * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
22  * @author  Pawel Sikorski (p.sikorski@samsung.com)
23  * @version 1.0
24  * @brief   This file contains the declaration of widget dao
25  */
26 #include <stddef.h>
27 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
28
29 #include <sstream>
30 #include <dpl/foreach.h>
31 #include <dpl/sstream.h>
32 #include <dpl/wrt-dao-ro/global_config.h>
33 #include <dpl/wrt-dao-ro/webruntime_database.h>
34 #include <dpl/wrt-dao-ro/WrtDatabase.h>
35 #include <dpl/wrt-dao-ro/widget_config.h>
36 #include <dpl/wrt-dao-ro/feature_dao_read_only.h>
37 #include <orm_generator_wrt.h>
38 #include <LanguageTagsProvider.h>
39
40 namespace WrtDB {
41
42 //TODO in current solution in each getter there exists a check
43 //"IsWidgetInstalled". Maybe it should be verified, if it could be done
44 //differently  (check in WidgetDAOReadOnly constructor)
45
46 #define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN          Try
47
48 #define SQL_CONNECTION_EXCEPTION_HANDLER_END(message)           \
49     Catch(DPL::DB::SqlConnection::Exception::Base) {                \
50         LogError(message);                                      \
51         ReThrowMsg(WidgetDAOReadOnly::Exception::DatabaseError, \
52                    message);                                    \
53     }
54
55 #define CHECK_WIDGET_EXISTENCE(macro_transaction, macro_handle)          \
56     if (!WidgetDAOReadOnly::isWidgetInstalled(macro_handle))             \
57     {                                                                    \
58         macro_transaction.Commit();                                      \
59         LogWarning("Cannot find widget. Handle: " << macro_handle);      \
60         ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,           \
61                  "Cannot find widget. Handle: " << macro_handle);        \
62     }
63
64
65 typedef DPL::DB::ORM::wrt::WidgetInfo::Row WidgetInfoRow;
66 typedef DPL::DB::ORM::wrt::WidgetFeature::widget_feature_id::ColumnType
67     WidgetFeatureId;
68 typedef DPL::DB::ORM::wrt::WidgetSecuritySettings::Row
69     WidgetSecuritySettingsRow;
70
71 namespace {
72
73 using namespace DPL::DB::ORM;
74 using namespace DPL::DB::ORM::wrt;
75
76 WidgetInfoRow getWidgetInfoRow(int widgetHandle)
77 {
78     LogDebug("Getting WidgetInfo row. Handle: " << widgetHandle);
79     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
80     {
81         WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
82         select->Where(Equals<WidgetInfo::app_id>(widgetHandle));
83
84         WidgetInfo::Select::RowList rows = select->GetRowList();
85         if (rows.empty()) {
86             ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
87                      "Cannot find widget. Handle: " << widgetHandle);
88         }
89         return rows.front();
90     }
91     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in GetWidgetInfoRow")
92 }
93
94 WidgetSecuritySettingsRow getWidgetSecuritySettingsRow(int widgetHandle)
95 {
96     LogDebug("Getting WidgetSecuritySettings row. Handle: " << widgetHandle);
97     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
98     {
99         using namespace DPL::DB::ORM;
100         using namespace DPL::DB::ORM::wrt;
101         WRT_DB_SELECT(select, WidgetSecuritySettings, &WrtDatabase::interface())
102         select->Where(Equals<WidgetSecuritySettings::app_id>(widgetHandle));
103
104         WidgetSecuritySettings::Select::RowList rows = select->GetRowList();
105         if (rows.empty()) {
106             ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
107                      "Cannot find widget. Handle: " << widgetHandle);
108         }
109         return rows.front();
110     }
111     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getWidgetSecuritySettingsRow")
112 }
113
114 const int MAX_TIZENID_LENGTH = 10;
115
116 WidgetPkgName getPkgNameByHandle(const DbWidgetHandle handle)
117 {
118     LogDebug("Getting WidgetPkgName by DbWidgetHandle: " << handle);
119
120     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
121     {
122         WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
123         select->Where(Equals<WidgetInfo::app_id>(handle));
124         WidgetInfo::Select::RowList rowList = select->GetRowList();
125
126         if (rowList.empty()) {
127             ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
128                  "Failed to get widget by package name");
129         }
130         DPL::OptionalString pkgname = rowList.front().Get_pkgname();
131         if(pkgname.IsNull()){
132             ThrowMsg(WidgetDAOReadOnly::Exception::DatabaseError,
133                     "PkgName is null for this widget");
134         }
135         return *pkgname;
136
137     }
138     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle")
139
140     ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
141                      "Failed to get widget by handle");
142 }
143 } // namespace
144
145
146 IWacSecurity::~IWacSecurity()
147 {
148 }
149
150 WidgetDAOReadOnly::WidgetDAOReadOnly(DbWidgetHandle widgetHandle) :
151     m_widgetHandle(widgetHandle)
152 {
153 }
154
155 WidgetDAOReadOnly::WidgetDAOReadOnly(DPL::OptionalString widgetGUID) :
156     m_widgetHandle(WidgetDAOReadOnly::getHandle(widgetGUID))
157 {
158 }
159
160 WidgetDAOReadOnly::WidgetDAOReadOnly(DPL::String pkgName) :
161     m_widgetHandle(WidgetDAOReadOnly::getHandle(pkgName))
162 {
163
164 }
165
166 WidgetDAOReadOnly::~WidgetDAOReadOnly()
167 {
168 }
169
170 DbWidgetHandle WidgetDAOReadOnly::getHandle() const
171 {
172     return m_widgetHandle;
173 }
174
175 DbWidgetHandle WidgetDAOReadOnly::getHandle(const WidgetGUID GUID)
176 {
177     LogDebug("Getting WidgetHandle by GUID [" << GUID << "]");
178
179     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
180     {
181         WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
182         select->Where(Equals<WidgetInfo::widget_id>(GUID));
183         WidgetInfo::Select::RowList rowList = select->GetRowList();
184
185         if (rowList.empty()) {
186             ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
187                  "Failed to get widget by guid");
188         }
189         return rowList.front().Get_app_id();
190     }
191     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle")
192
193     ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
194                      "Failed to get widget by guid");
195 }
196
197 DbWidgetHandle WidgetDAOReadOnly::getHandle(const DPL::String pkgName)
198 {
199     LogDebug("Getting WidgetHandle by Package Name [" << pkgName << "]");
200
201     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
202     {
203         WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
204         select->Where(Equals<WidgetInfo::pkgname>(pkgName));
205         WidgetInfo::Select::RowList rowList = select->GetRowList();
206
207         if (rowList.empty()) {
208             ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
209                  "Failed to get widget by package name");
210         }
211         return rowList.front().Get_app_id();
212     }
213     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle")
214
215     ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
216                      "Failed to get widget by package name");
217 }
218
219 WidgetPkgName WidgetDAOReadOnly::getPkgName() const
220 {
221     return getPkgNameByHandle(m_widgetHandle);
222 }
223
224 WidgetPkgName WidgetDAOReadOnly::getPkgName(const WidgetGUID GUID)
225 {
226     return getPkgNameByHandle(getHandle(GUID));
227 }
228
229 WidgetPkgName WidgetDAOReadOnly::getPkgName(const DbWidgetHandle handle)
230 {
231     return getPkgNameByHandle(handle);
232 }
233
234 PropertyDAOReadOnly::WidgetPropertyKeyList
235 WidgetDAOReadOnly::getPropertyKeyList() const
236 {
237     return PropertyDAOReadOnly::GetPropertyKeyList(getPkgName());
238 }
239
240 PropertyDAOReadOnly::WidgetPreferenceList
241 WidgetDAOReadOnly::getPropertyList() const
242 {
243     return PropertyDAOReadOnly::GetPropertyList(getPkgName());
244 }
245
246 PropertyDAOReadOnly::WidgetPropertyValue WidgetDAOReadOnly::getPropertyValue(
247         const PropertyDAOReadOnly::WidgetPropertyKey &key) const
248 {
249     return PropertyDAOReadOnly::GetPropertyValue(getPkgName(), key);
250 }
251
252 DPL::OptionalInt WidgetDAOReadOnly::checkPropertyReadFlag(
253         const PropertyDAOReadOnly::WidgetPropertyKey &key) const
254 {
255     return PropertyDAOReadOnly::CheckPropertyReadFlag(getPkgName(), key);
256 }
257
258 DPL::String WidgetDAOReadOnly::getPath() const
259 {
260     DPL::String path = *getWidgetInstalledPath();
261     DPL::String srcPath = DPL::FromUTF8String(GlobalConfig::GetWidgetSrcPath());
262
263     path += srcPath + L"/";
264
265     return path;
266 }
267
268 DPL::String WidgetDAOReadOnly::getFullPath() const
269 {
270     return L"file://" + getPath();
271 }
272
273 WidgetLocalizedInfo
274         WidgetDAOReadOnly::getLocalizedInfo(const DPL::String& languageTag)
275         const
276 {
277     LogDebug("Getting Localized Info. Handle: " << m_widgetHandle);
278     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
279     {
280         ScopedTransaction transaction(&WrtDatabase::interface());
281         CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
282
283         WRT_DB_SELECT(select, LocalizedWidgetInfo, &WrtDatabase::interface())
284         select->Where(
285             And(Equals<LocalizedWidgetInfo::app_id>(m_widgetHandle),
286                 Equals<LocalizedWidgetInfo::widget_locale>(languageTag)));
287         LocalizedWidgetInfo::Row info = select->GetSingleRow();
288         WidgetLocalizedInfo result;
289
290         result.name = info.Get_widget_name();
291         result.shortName = info.Get_widget_shortname();
292         result.description = info.Get_widget_description();
293         result.license = info.Get_widget_license();
294         result.licenseHref = info.Get_widget_license_href();
295
296         transaction.Commit();
297         return result;
298     }
299     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get localized info")
300 }
301
302 DbWidgetFeatureSet WidgetDAOReadOnly::getFeaturesList() const
303 {
304     LogDebug("Getting FeaturesList. Handle: " << m_widgetHandle);
305     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
306     {
307         ScopedTransaction transaction(&WrtDatabase::interface());
308         CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
309
310         WRT_DB_SELECT(select, WidgetFeature, &WrtDatabase::interface())
311         select->Where(Equals<WidgetFeature::app_id>(m_widgetHandle));
312
313         DbWidgetFeatureSet resultSet;
314         typedef std::list<WidgetFeature::Row> RowList;
315         RowList list = select->GetRowList();
316
317         for (RowList::iterator i = list.begin(); i != list.end(); ++i) {
318             DbWidgetFeature feature;
319             feature.name = i->Get_name();
320             feature.required = i->Get_required();
321             feature.rejected = i->Get_rejected();
322             feature.params = getFeatureParams(i->Get_widget_feature_id());
323             FeatureDAOReadOnly featureDao(DPL::ToUTF8String(i->Get_name()));
324             feature.pluginId = featureDao.GetPluginHandle();
325             resultSet.insert(feature);
326         }
327         transaction.Commit();
328         return resultSet;
329     }
330     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get features list")
331 }
332
333 WidgetParamMap WidgetDAOReadOnly::getFeatureParams(int id)
334 {
335     WidgetFeatureId widgetFeatureId(id);
336     LogDebug("Getting feature Params. featureId: " << widgetFeatureId);
337     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
338     {
339         WRT_DB_SELECT(select, FeatureParam, &WrtDatabase::interface())
340         select->Where(Equals<FeatureParam::widget_feature_id>(
341                           widgetFeatureId));
342
343         WidgetParamMap resultMap;
344         typedef std::list<FeatureParam::Row> RowList;
345         RowList list = select->GetRowList();
346
347         FOREACH(i, list)
348             resultMap.insert(std::make_pair(i->Get_name(), i->Get_value()));
349
350         return resultMap;
351     }
352     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get feature params")
353 }
354
355 bool WidgetDAOReadOnly::hasFeature(const std::string& featureName) const
356 {
357     LogDebug(
358         "Checking if widget has feature: " << featureName << ". Handle: " <<
359         m_widgetHandle);
360     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
361     {
362         ScopedTransaction transaction(&WrtDatabase::interface());
363         CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
364
365         WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
366         select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
367                           Equals<wrt::WidgetFeature::name>(
368                               DPL::FromUTF8String(featureName))));
369
370         wrt::WidgetFeature::Select::RowList rows = select->GetRowList();
371         transaction.Commit();
372         return !rows.empty();
373     }
374     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to check for feature")
375 }
376
377 HostList WidgetDAOReadOnly::getAccessHostList() const
378 {
379     LogDebug("Getting AccessHostList. Handle: " << m_widgetHandle);
380     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
381     {
382         ScopedTransaction transaction(&WrtDatabase::interface());
383         CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
384
385         WRT_DB_SELECT(select, WidgetAccessHost, &WrtDatabase::interface())
386         select->Where(Equals<WidgetAccessHost::app_id>(m_widgetHandle));
387         std::list<WidgetAccessHost::host::ColumnType> values =
388             select->GetValueList<WidgetAccessHost::host>();
389         HostList ret;
390         FOREACH(it, values)
391         ret.push_back(DPL::ToUTF8String(*it));
392
393         transaction.Commit();
394         return ret;
395     }
396     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get access host list")
397 }
398
399 bool WidgetDAOReadOnly::getAccessNetworkMode() const
400 {
401     //TODO there is no column access_network
402     //it was removed in "Widget localization overhaul
403     return true;
404 }
405
406 DbWidgetHandleList WidgetDAOReadOnly::getHandleList()
407 {
408     LogDebug("Getting DbWidgetHandle List");
409     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
410     {
411         WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
412         return select->GetValueList<WidgetInfo::app_id>();
413     }
414     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get handle list")
415 }
416
417 WidgetPkgNameList WidgetDAOReadOnly::getPkgnameList()
418 {
419     LogDebug("Getting Pkgname List");
420     WidgetPkgNameList_TEMPORARY_API pkgnameList_TEMPORARY_API = getPkgnameList_TEMPORARY_API();
421     WidgetPkgNameList pkgnameList;
422     FOREACH(it,pkgnameList_TEMPORARY_API ){
423         pkgnameList.push_back(DPL::Optional<WidgetPkgName>(*it));
424     }
425     return pkgnameList;
426 }
427
428 WidgetPkgNameList_TEMPORARY_API WidgetDAOReadOnly::getPkgnameList_TEMPORARY_API()
429 {
430     LogDebug("Getting Pkgname List ");
431     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
432     {
433         WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
434         return select->GetValueList<WidgetInfo::pkgname>();
435     }
436     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get Pkgname list")
437 }
438
439 DbWidgetDAOReadOnlyList WidgetDAOReadOnly::getWidgetList()
440 {
441     LogDebug("Getting DbWidget List");
442     DbWidgetDAOReadOnlyList list;
443     FOREACH(iterator, getHandleList()) {
444         list.push_back(WidgetDAOReadOnlyPtr(new WidgetDAOReadOnly(*iterator)));
445     }
446     return list;
447 }
448
449 bool WidgetDAOReadOnly::isWidgetInstalled(DbWidgetHandle handle)
450 {
451     LogDebug("Checking if widget exist. Handle: " << handle);
452     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
453     {
454         WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
455         select->Where(Equals<WidgetInfo::app_id>(handle));
456
457         WidgetInfo::Select::RowList rows = select->GetRowList();
458
459         return !rows.empty();
460     }
461     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to check if widget exist")
462 }
463
464 bool WidgetDAOReadOnly::isWidgetInstalled(const WidgetPkgName & pkgName)
465 {
466     LogDebug("Checking if widget exist. package name " << pkgName);
467     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
468     {
469         WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
470         select->Where(Equals<WidgetInfo::pkgname>(pkgName));
471
472         WidgetInfo::Select::RowList rows = select->GetRowList();
473
474         return !rows.empty();
475     }
476     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to check if widget exist")
477 }
478
479 ExternalLocationList WidgetDAOReadOnly::getWidgetExternalLocations() const
480 {
481     LogDebug("Getting WidgetExtranalFiles List");
482     ExternalLocationList result;
483     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
484     {
485         WRT_DB_SELECT(select, WidgetExternalLocations, &WrtDatabase::interface());
486         select->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
487         WidgetExternalLocations::Select::RowList rows = select->GetRowList();
488         FOREACH(it, rows)
489         {
490             result.push_back(DPL::ToUTF8String(it->Get_path()));
491         }
492     }
493     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get handle list")
494     return result;
495 }
496
497 CertificateChainList WidgetDAOReadOnly::getWidgetCertificate(
498         CertificateSource source) const
499 {
500     WRT_DB_SELECT(select, WidgetCertificate, &WrtDatabase::interface())
501     select->Where(
502         And(
503             Equals<WidgetCertificate::app_id>(m_widgetHandle),
504             Equals<WidgetCertificate::cert_source>(source)));
505
506     std::list<WidgetCertificate::Row> chainList = select->GetRowList();
507
508     CertificateChainList result;
509
510     FOREACH(iter, chainList)
511         result.push_back(DPL::ToUTF8String(iter->Get_encoded_chain()));
512     return result;
513 }
514
515 DbWidgetSize WidgetDAOReadOnly::getPreferredSize() const
516 {
517     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
518
519     DbWidgetSize size;
520     size.width = row.Get_widget_width();
521     size.height = row.Get_widget_height();
522
523     LogDebug("Return size wxh = " <<
524              (!!size.width ? *size.width : -1) << " x " <<
525              (!!size.height ? *size.height : -1));
526
527     return size;
528 }
529
530 WidgetType WidgetDAOReadOnly::getWidgetType() const
531 {
532     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
533     DPL::OptionalInt result = row.Get_widget_type();
534     return WidgetType(static_cast<AppType>(*result));
535 }
536
537 WidgetGUID WidgetDAOReadOnly::getGUID() const
538 {
539     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
540     return row.Get_widget_id();
541 }
542
543 DPL::OptionalString WidgetDAOReadOnly::getPkgname() const
544 {
545     return DPL::OptionalString(getPkgname_TEMPORARY_API());
546 }
547
548 WidgetPkgName WidgetDAOReadOnly::getPkgname_TEMPORARY_API() const
549 {
550     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
551     return row.Get_pkgname();
552 }
553
554 DPL::OptionalString WidgetDAOReadOnly::getDefaultlocale() const
555 {
556     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
557     return row.Get_defaultlocale();
558 }
559
560 DPL::Optional<DPL::String> WidgetDAOReadOnly::getVersion() const
561 {
562     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
563     return row.Get_widget_version();
564 }
565
566 DPL::Optional<DPL::String> WidgetDAOReadOnly::getAuthorName() const
567 {
568     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
569     return row.Get_author_name();
570 }
571
572 DPL::Optional<DPL::String> WidgetDAOReadOnly::getAuthorEmail() const
573 {
574     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
575     return row.Get_author_email();
576 }
577
578 DPL::Optional<DPL::String> WidgetDAOReadOnly::getAuthorHref() const
579 {
580     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
581     return row.Get_author_href();
582 }
583
584 DPL::Optional<DPL::String> WidgetDAOReadOnly::getMinimumWacVersion() const
585 {
586     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
587     return row.Get_min_version();
588 }
589
590 std::string WidgetDAOReadOnly::getShareHref() const
591 {
592     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
593     {
594         WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
595         select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
596         WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
597
598         if (rows.empty()) {
599             ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
600                      "Cannot find widget. Handle: " << m_widgetHandle);
601         }
602
603         DPL::Optional<DPL::String> value = rows.front().Get_share_href();
604         std::string ret = "";
605         if (!value.IsNull()) {
606             ret = DPL::ToUTF8String(*value);
607         }
608         return ret;
609     }
610     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get share HREF")
611 }
612
613 bool WidgetDAOReadOnly::getBackSupported() const
614 {
615     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
616     return row.Get_back_supported();
617 }
618
619 bool WidgetDAOReadOnly::isRecognized() const
620 {
621     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
622     DPL::OptionalInt result = row.Get_recognized();
623     if (result.IsNull()) {
624         return false;
625     }
626     return static_cast<bool>(*result);
627 }
628
629 bool WidgetDAOReadOnly::isWacSigned() const
630 {
631     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
632     DPL::OptionalInt result = row.Get_wac_signed();
633     if (result.IsNull()) {
634         return false;
635     }
636     return static_cast<bool>(*result);
637 }
638
639 bool WidgetDAOReadOnly::isDistributorSigned() const
640 {
641     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
642     DPL::OptionalInt result = row.Get_distributor_signed();
643     if (result.IsNull()) {
644         return false;
645     }
646     return static_cast<bool>(*result);
647 }
648
649 bool WidgetDAOReadOnly::isTrusted() const
650 {
651     // SP-2100
652     // widget with verified distributor signature is trusted
653     return isDistributorSigned();
654 }
655
656 bool WidgetDAOReadOnly::isTestWidget() const
657 {
658     Try {
659         WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
660         select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
661
662         WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
663         if (rows.empty()) {
664             ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
665                      "Cannot find widget. Handle: " << m_widgetHandle);
666         }
667
668         return static_cast<bool>(rows.front().Get_test_widget());
669     }
670     Catch(DPL::DB::SqlConnection::Exception::Base){
671         ReThrowMsg(WidgetDAOReadOnly::Exception::DatabaseError,
672                    "Failed to check IsTestWidget");
673     }
674 }
675
676 bool WidgetDAOReadOnly::getWebkitPluginsRequired() const
677 {
678     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
679     DPL::OptionalInt ret = row.Get_webkit_plugins_required();
680
681     if (ret.IsNull() || *ret == 0) { return false; } else { return true; }
682 }
683
684 time_t WidgetDAOReadOnly::getInstallTime() const
685 {
686     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
687     {
688         WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
689         select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
690
691         WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
692         if (rows.empty()) {
693             ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
694                      "Cannot find widget. Handle: " << m_widgetHandle);
695         }
696
697         return static_cast<time_t>(*rows.front().Get_install_time());
698     }
699     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get widdget install time")
700 }
701
702 DPL::OptionalString WidgetDAOReadOnly::getSplashImgSrc() const
703 {
704     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
705     {
706         WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
707         select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
708
709         WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
710         if (rows.empty()) {
711             ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
712                      "Cannot find widget. Handle: " << m_widgetHandle);
713         }
714
715         DPL::OptionalString value = rows.front().Get_splash_img_src();
716         if (value.IsNull()) {
717             return DPL::OptionalString::Null;
718         }
719
720         return DPL::OptionalString(getPath() + *value);
721     }
722     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get splash image path")
723 }
724
725 WidgetDAOReadOnly::WidgetLocalizedIconList WidgetDAOReadOnly::getLocalizedIconList() const
726 {
727     //TODO check widget existance??
728     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
729     {
730         WRT_DB_SELECT(select, WidgetLocalizedIcon, &WrtDatabase::interface())
731         select->Where(Equals<WidgetLocalizedIcon::app_id>(m_widgetHandle));
732
733         std::list<WidgetLocalizedIcon::Row> list =
734                 select->GetRowList();
735         WidgetLocalizedIconList ret;
736         FOREACH(it,list)
737         {
738             WidgetLocalizedIconRow icon = {it->Get_app_id(),
739                                            it->Get_icon_id(),
740                                            it->Get_widget_locale()};
741             ret.push_back(icon);
742         }
743         return ret;
744     }
745     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get icon data")
746 }
747
748 WidgetDAOReadOnly::WidgetIconList WidgetDAOReadOnly::getIconList() const
749 {
750     //TODO check widget existance
751     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
752     {
753         WRT_DB_SELECT(select, wrt::WidgetIcon, &WrtDatabase::interface())
754         select->Where(Equals<wrt::WidgetIcon::app_id>(m_widgetHandle));
755
756         std::list<WidgetIcon::Row> list =
757                 select->GetRowList();
758         WidgetIconList ret;
759         FOREACH(it,list)
760         {
761             WidgetIconRow icon = {it->Get_icon_id(),
762                                   it->Get_app_id(),
763                                   it->Get_icon_src(),
764                                   it->Get_icon_width(),
765                                   it->Get_icon_height()};
766             ret.push_back(icon);
767         }
768         return ret;
769     }
770     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get icon data")
771 }
772
773 WidgetDAOReadOnly::LocalizedStartFileList WidgetDAOReadOnly::getLocalizedStartFileList() const
774 {
775     //TODO check widget existance
776     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
777     {
778         WRT_DB_SELECT(select, WidgetLocalizedStartFile, &WrtDatabase::interface())
779         select->Where(Equals<WidgetLocalizedStartFile::app_id>(
780                           m_widgetHandle));
781         select->OrderBy("start_file_id ASC");
782
783         std::list<WidgetLocalizedStartFile::Row> list =
784                 select->GetRowList();
785         LocalizedStartFileList ret;
786         FOREACH(it,list)
787         {
788             WidgetLocalizedStartFileRow file = {it->Get_start_file_id(),
789                                                 it->Get_app_id(),
790                                                 it->Get_widget_locale(),
791                                                 it->Get_type(),
792                                                 it->Get_encoding()};
793             ret.push_back(file);
794         }
795         return ret;
796     }
797     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get start file list data")
798 }
799
800 WidgetDAOReadOnly::WidgetStartFileList WidgetDAOReadOnly::getStartFileList() const
801 {
802     //TODO check widget existance
803     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
804     {
805         WRT_DB_SELECT(select, WidgetStartFile, &WrtDatabase::interface())
806         select->Where(Equals<WidgetStartFile::app_id>(m_widgetHandle));
807         select->OrderBy("start_file_id ASC");
808
809         std::list<WidgetStartFile::Row> list =
810                 select->GetRowList();
811         WidgetStartFileList ret;
812         FOREACH(it,list)
813         {
814             WidgetStartFileRow file = {it->Get_start_file_id(),
815                                        it->Get_app_id(),
816                                        it->Get_src()};
817             ret.push_back(file);
818         }
819         return ret;
820     }
821     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get start file list data")
822 }
823
824 WindowModeList WidgetDAOReadOnly::getWindowModes() const
825 {
826     //TODO check widget existance
827     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
828     {
829         WRT_DB_SELECT(select, WidgetWindowModes, &WrtDatabase::interface())
830         select->Where(Equals<WidgetWindowModes::app_id>(m_widgetHandle));
831
832         return select->GetValueList<WidgetWindowModes::window_mode>();
833     }
834     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get window modes")
835 }
836
837 std::string WidgetDAOReadOnly::getBaseFolder() const
838 {
839     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
840     DPL::Optional<DPL::String> ret = row.Get_base_folder();
841     std::string baseFolder;
842     if (!ret.IsNull()) {
843         baseFolder = DPL::ToUTF8String(*ret);
844     }
845
846     if (!baseFolder.empty()) {
847         baseFolder += "/";
848     }
849
850     return baseFolder;
851 }
852
853 WidgetCertificateDataList WidgetDAOReadOnly::getCertificateDataList() const
854 {
855     //TODO check widget existance
856     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
857     {
858         WRT_DB_SELECT(select, WidgetCertificateFingerprint, &WrtDatabase::interface())
859         select->Where(Equals<WidgetCertificateFingerprint::app_id>(
860                           m_widgetHandle));
861         select->OrderBy("chainid");
862         WidgetCertificateFingerprint::Select::RowList rows =
863             select->GetRowList();
864
865         WidgetCertificateDataList outlCertificateData;
866         FOREACH(it, rows)
867         {
868             WidgetCertificateData data;
869
870             data.owner =
871                 static_cast <WidgetCertificateData::Owner>(it->Get_owner());
872             data.type =
873                 static_cast <WidgetCertificateData::Type>(it->Get_type());
874             data.chainId = it->Get_chainid();
875             DPL::Optional<DPL::String> md5 = it->Get_md5_fingerprint();
876             data.strMD5Fingerprint =
877                 md5.IsNull() ? "" : DPL::ToUTF8String(*md5);
878             DPL::Optional<DPL::String> sha1 = it->Get_sha1_fingerprint();
879             data.strSHA1Fingerprint =
880                 sha1.IsNull() ? "" : DPL::ToUTF8String(*sha1);
881             DPL::Optional<DPL::String> cname = it->Get_common_name();
882             data.strCommonName =
883                 cname.IsNull() ? DPL::FromUTF8String("") : *cname;
884
885             outlCertificateData.push_back(data);
886         }
887         return outlCertificateData;
888     }
889     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get fingerprint list")
890 }
891
892 FingerPrintList WidgetDAOReadOnly::getKeyFingerprints(
893         WidgetCertificateData::Owner owner,
894         WidgetCertificateData::Type type) const
895 {
896     //TODO check widget existance
897     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
898     {
899         WRT_DB_SELECT(select, WidgetCertificateFingerprint, &WrtDatabase::interface())
900         select->Where(And(And(
901             Equals<WidgetCertificateFingerprint::app_id>(m_widgetHandle),
902             Equals<WidgetCertificateFingerprint::owner>(owner)),
903             Equals<WidgetCertificateFingerprint::type>(type)));
904
905         WidgetCertificateFingerprint::Select::RowList rows =
906             select->GetRowList();
907
908         FingerPrintList keys;
909         FOREACH(it, rows)
910         {
911             DPL::Optional<DPL::String> sha1 = it->Get_sha1_fingerprint();
912             if (!sha1.IsNull()) {
913                 keys.push_back(DPL::ToUTF8String(*sha1));
914             }
915             DPL::Optional<DPL::String> md5 = it->Get_md5_fingerprint();
916             if (!md5.IsNull()) {
917                 keys.push_back(DPL::ToUTF8String(*md5));
918             }
919         }
920         return keys;
921     }
922     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get fingerprint list")
923 }
924
925 WidgetCertificateCNList WidgetDAOReadOnly::getKeyCommonNameList(
926         WidgetCertificateData::Owner owner,
927         WidgetCertificateData::Type type) const
928 {
929     //TODO check widget existance
930     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
931     {
932         WRT_DB_SELECT(select, WidgetCertificateFingerprint, &WrtDatabase::interface())
933         select->Where(And(And(
934             Equals<WidgetCertificateFingerprint::app_id>(m_widgetHandle),
935             Equals<WidgetCertificateFingerprint::owner>(owner)),
936             Equals<WidgetCertificateFingerprint::type>(type)));
937
938         WidgetCertificateFingerprint::Select::RowList rows =
939             select->GetRowList();
940
941         WidgetCertificateCNList out;
942         FOREACH(it, rows)
943         {
944             DPL::Optional<DPL::String> cname = it->Get_common_name();
945             out.push_back(cname.IsNull() ? "" : DPL::ToUTF8String(*cname));
946         }
947         return out;
948     }
949     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get key common name")
950 }
951
952 ResourceAttributeList WidgetDAOReadOnly::getResourceAttribute(
953         const std::string &resourceId) const
954 {
955     WRT_DB_SELECT(select, WidgetFeature, &WrtDatabase::interface())
956     select->Where(And(Equals<WidgetFeature::app_id>(m_widgetHandle),
957                       Equals<WidgetFeature::name>(
958                           DPL::FromUTF8String(resourceId))));
959
960     std::list<WidgetFeature::Row> list = select->GetRowList();
961     ResourceAttributeList result;
962     if (!list.empty()) {
963         int widgetFeatureId = list.begin()->Get_widget_feature_id();
964         WidgetParamMap map = getFeatureParams(widgetFeatureId);
965
966         FOREACH(i, map)
967             result.push_back(DPL::ToUTF8String(i->first));
968     }
969     return result;
970 }
971
972 void WidgetDAOReadOnly::getWidgetAccessInfo(
973         WidgetAccessInfoList& outAccessInfoList) const
974 {
975     //TODO check widget existance
976     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
977     {
978         WRT_DB_SELECT(select, WidgetWARPInfo, &WrtDatabase::interface())
979         select->Where(Equals<WidgetWARPInfo::app_id>(m_widgetHandle));
980
981         WidgetWARPInfo::Select::RowList rows = select->GetRowList();
982
983         FOREACH(it, rows)
984         {
985             WidgetAccessInfo info;
986
987             info.strIRI = it->Get_iri();
988             DPL::OptionalInt access = it->Get_subdomain_access();
989             if (access.IsNull() || 0 == *access) {
990                 info.bSubDomains = false;
991             } else if (1 == *access) {
992                 info.bSubDomains = true;
993             }
994
995             outAccessInfoList.push_back(info);
996         }
997     }
998     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get accessinfo list")
999 }
1000
1001 LanguageTags WidgetDAOReadOnly::getLanguageTags() const
1002 {
1003     //TODO check widget existance
1004     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1005     {
1006         WRT_DB_SELECT(select, LocalizedWidgetInfo, &WrtDatabase::interface())
1007         select->Where(Equals<LocalizedWidgetInfo::app_id>(m_widgetHandle));
1008         return select->GetValueList<LocalizedWidgetInfo::widget_locale>();
1009     }
1010     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get language tags")
1011 }
1012
1013 LanguageTags WidgetDAOReadOnly::getIconLanguageTags() const
1014 {
1015     //TODO check widget existance
1016     WRT_DB_SELECT(select, WidgetLocalizedIcon, &WrtDatabase::interface())
1017     select->Where(Equals<WidgetLocalizedIcon::app_id>(m_widgetHandle));
1018     select->Distinct();
1019     return select->GetValueList<WidgetLocalizedIcon::widget_locale>();
1020 }
1021
1022 std::string WidgetDAOReadOnly::getCookieDatabasePath() const
1023 {
1024     using namespace WrtDB::WidgetConfig;
1025     std::ostringstream path;
1026
1027     WidgetPkgName pkgname = getPkgname_TEMPORARY_API();
1028
1029     path << GetWidgetPersistentStoragePath(pkgname);
1030     path << "/";
1031     path << GlobalConfig::GetCookieDatabaseFile();
1032
1033     return path.str();
1034 }
1035
1036 std::string WidgetDAOReadOnly::getPrivateLocalStoragePath() const
1037 {
1038     std::ostringstream path;
1039     WidgetPkgName pkgname = getPkgname_TEMPORARY_API();
1040     path << WidgetConfig::GetWidgetWebLocalStoragePath(pkgname);
1041     path << "/";
1042
1043     return path.str();
1044 }
1045
1046 void WidgetDAOReadOnly::getWidgetSettings(
1047         WidgetSettings& outWidgetSettings) const
1048 {
1049     //TODO check widget existance
1050     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1051     {
1052         WRT_DB_SELECT(select, SettingsList, &WrtDatabase::interface())
1053         select->Where(Equals<SettingsList::appId>(m_widgetHandle));
1054
1055         SettingsList::Select::RowList rows = select->GetRowList();
1056
1057         FOREACH(it, rows)
1058         {
1059             WidgetSetting info;
1060
1061             info.settingName = it->Get_settingName();
1062             info.settingValue = it->Get_settingValue();
1063             outWidgetSettings.push_back(info);
1064         }
1065     }
1066     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get settings list")
1067 }
1068
1069 void WidgetDAOReadOnly::getAppServiceList(
1070         WidgetApplicationServiceList& outAppServiceList) const
1071 {
1072     LogDebug("Getting getAppServiceList. Handle: " << m_widgetHandle);
1073     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1074     {
1075         ScopedTransaction transaction(&WrtDatabase::interface());
1076         CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
1077
1078         WRT_DB_SELECT(select, ApplicationServiceInfo, &WrtDatabase::interface())
1079         select->Where(Equals<ApplicationServiceInfo::app_id>(m_widgetHandle));
1080
1081         ApplicationServiceInfo::Select::RowList rows = select->GetRowList();
1082
1083         if (rows.empty()) {
1084             LogDebug("Application Service list is empty. Handle: " <<
1085                      m_widgetHandle);
1086         }
1087
1088         FOREACH(it, rows) {
1089             WidgetApplicationService ret;
1090             ret.src = it->Get_src();
1091             ret.operation = it->Get_operation();
1092             ret.scheme = it->Get_scheme();
1093             ret.mime = it->Get_mime();
1094             outAppServiceList.push_back(ret);
1095         }
1096
1097         transaction.Commit();
1098     }
1099     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get access host list")
1100 }
1101
1102 PackagingType WidgetDAOReadOnly::getPackagingType() const
1103 {
1104     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
1105     DPL::OptionalInt result = row.Get_pkg_type();
1106     return PackagingType(static_cast<PkgType>(*result));
1107 }
1108
1109 void WidgetDAOReadOnly::getEncryptedFileList(EncryptedFileList& filesList) const
1110 {
1111     //TODO check widget existance
1112     WRT_DB_SELECT(select, EncryptedResourceList, &WrtDatabase::interface())
1113     select->Where(Equals<EncryptedResourceList::app_id>(m_widgetHandle));
1114
1115     typedef std::list<EncryptedResourceList::Row> RowList;
1116     RowList list = select->GetRowList();
1117
1118     FOREACH(it, list) {
1119         EncryptedFileInfo info;
1120         info.fileName = it->Get_resource();
1121         info.fileSize = it->Get_size();
1122         filesList.insert(info);
1123     }
1124 }
1125
1126 DPL::OptionalString WidgetDAOReadOnly::getBackgroundPage() const
1127 {
1128     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1129     {
1130         WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
1131         select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
1132
1133         WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
1134         if (rows.empty()) {
1135             ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
1136                      "Cannot find widget. Handle: " << m_widgetHandle);
1137         }
1138
1139         return rows.front().Get_background_page();
1140     }
1141     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get background page")
1142 }
1143
1144 WidgetPkgName WidgetDAOReadOnly::generateTizenId() {
1145     std::string allowed("0123456789"
1146         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1147         "abcdefghijklmnopqrstuvwxyz");
1148     WidgetPkgName tizenId;
1149     tizenId.resize(MAX_TIZENID_LENGTH);
1150     do {
1151     for (int i = 0; i < MAX_TIZENID_LENGTH; ++i) {
1152         tizenId[i] = allowed[rand() % allowed.length()];
1153     }
1154     } while (isWidgetInstalled(tizenId));
1155     return tizenId;
1156 }
1157
1158 SettingsType WidgetDAOReadOnly::getSecurityPopupUsage(void) const
1159 {
1160     WidgetSecuritySettingsRow row =
1161         getWidgetSecuritySettingsRow(m_widgetHandle);
1162     DPL::OptionalInt result = row.Get_security_popup_usage();
1163     return static_cast<SettingsType>(*result);
1164 }
1165
1166 SettingsType WidgetDAOReadOnly::getGeolocationUsage(void) const
1167 {
1168     WidgetSecuritySettingsRow row =
1169         getWidgetSecuritySettingsRow(m_widgetHandle);
1170     DPL::OptionalInt result = row.Get_geolocation_usage();
1171     return static_cast<SettingsType>(*result);
1172 }
1173
1174 SettingsType WidgetDAOReadOnly::getWebNotificationUsage(void) const
1175 {
1176     WidgetSecuritySettingsRow row =
1177         getWidgetSecuritySettingsRow(m_widgetHandle);
1178     DPL::OptionalInt result = row.Get_web_notification_usage();
1179     return static_cast<SettingsType>(*result);
1180 }
1181
1182 SettingsType WidgetDAOReadOnly::getWebDatabaseUsage(void) const
1183 {
1184     WidgetSecuritySettingsRow row =
1185         getWidgetSecuritySettingsRow(m_widgetHandle);
1186     DPL::OptionalInt result = row.Get_web_database_usage();
1187     return static_cast<SettingsType>(*result);
1188 }
1189
1190 SettingsType WidgetDAOReadOnly::getFileSystemUsage(void) const
1191 {
1192     WidgetSecuritySettingsRow row =
1193         getWidgetSecuritySettingsRow(m_widgetHandle);
1194     DPL::OptionalInt result = row.Get_file_system_usage();
1195     return static_cast<SettingsType>(*result);
1196 }
1197
1198 DPL::OptionalString WidgetDAOReadOnly::getWidgetInstalledPath() const
1199 {
1200     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1201     {
1202         using namespace DPL::DB::ORM;
1203         using namespace DPL::DB::ORM::wrt;
1204         WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
1205         select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
1206
1207         WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
1208         if (rows.empty()) {
1209             ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
1210                      "Cannot find widget. Handle: " << m_widgetHandle);
1211         }
1212
1213         return rows.front().Get_installed_path();
1214     }
1215     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get widdget installed path")
1216 }
1217 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1218 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END
1219 #undef CHECK_WIDGET_EXISTENCE
1220
1221 } // namespace WrtDB