• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "delete_callback.h"
16 
17 #include "media_file_utils.h"
18 #include "medialibrary_napi_utils.h"
19 #include "userfile_client.h"
20 
21 using namespace std;
22 using namespace OHOS::DataShare;
23 
24 namespace OHOS {
25 namespace Media {
26 #ifdef HAS_ACE_ENGINE_PART
DeleteCallback(Ace::UIContent * uiContent)27 DeleteCallback::DeleteCallback(Ace::UIContent* uiContent)
28 {
29     this->uiContent = uiContent;
30 }
31 #else
32 DeleteCallback::DeleteCallback() {}
33 #endif
34 
OnRelease(int32_t releaseCode)35 void DeleteCallback::OnRelease(int32_t releaseCode)
36 {
37     CloseModalUIExtension();
38 }
39 
OnResult(int32_t resultCode,const OHOS::AAFwk::Want & result)40 void DeleteCallback::OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result)
41 {
42     if (resultCode == DELETE_CODE_SUCCESS) {
43         this->resultCode_ = resultCode;
44         string trashUri = PAH_TRASH_PHOTO;
45         MediaLibraryNapiUtils::UriAppendKeyValue(trashUri, API_VERSION, to_string(MEDIA_API_VERSION_V10));
46         Uri updateAssetUri(trashUri);
47         DataSharePredicates predicates;
48         predicates.In(MediaColumn::MEDIA_ID, this->uris_);
49         DataShareValuesBucket valuesBucket;
50         valuesBucket.Put(MediaColumn::MEDIA_DATE_TRASHED, MediaFileUtils::UTCTimeSeconds());
51         int32_t changedRows = UserFileClient::Update(updateAssetUri, predicates, valuesBucket);
52         if (changedRows < 0) {
53             this->resultCode_ = JS_INNER_FAIL;
54         }
55     } else {
56         this->resultCode_ = JS_ERR_PERMISSION_DENIED;
57     }
58     SendMessageBack();
59 }
60 
OnError(int32_t code,const string & name,const string & message)61 void DeleteCallback::OnError(int32_t code, const string& name, const string& message)
62 {
63     this->resultCode_ = JS_INNER_FAIL;
64     SendMessageBack();
65 }
66 
OnReceive(const OHOS::AAFwk::WantParams & request)67 void DeleteCallback::OnReceive(const OHOS::AAFwk::WantParams& request)
68 {
69     NAPI_INFO_LOG("OnReceive enter.");
70 }
71 
SetSessionId(int32_t sessionId)72 void DeleteCallback::SetSessionId(int32_t sessionId)
73 {
74     this->sessionId_ = sessionId;
75 }
76 
SetUris(vector<string> uris)77 void DeleteCallback::SetUris(vector<string> uris)
78 {
79     this->uris_.assign(uris.begin(), uris.end());
80 }
81 
SetFunc()82 void DeleteCallback::SetFunc() {}
83 
SendMessageBack()84 void DeleteCallback::SendMessageBack()
85 {
86     CloseModalUIExtension();
87 }
88 
CloseModalUIExtension()89 void DeleteCallback::CloseModalUIExtension()
90 {
91 #ifdef HAS_ACE_ENGINE_PART
92     if (this->uiContent != nullptr) {
93         uiContent->CloseModalUIExtension(this->sessionId_);
94     }
95 #endif
96 }
97 } // namespace Media
98 } // namespace OHOS