Коммит b8db0b7c создал по автору OMP Education's avatar OMP Education
Просмотр файлов

[Structure] Implement the Aurora OS Share API Example application

владелец edef5081
.apptool
.DS_Store
.mb2
.vscode
CMakeCache.txt
CMakeFiles
Makefile
QtCreatorDeployment.txt
RPMS
cmake_install.cmake
install_manifest.txt
*.autosave
*.list
*.md.backup
*.moc
*.o
*.pro.user*
*.qm
*~
*_autogen
CMakeLists.txt.user*
moc_*.cpp
ru.auroraos.AuroraOsShareApiExample
......@@ -8,3 +8,5 @@
* Developer, 2022
* Vladislav Larionov
* Reviewer, 2023
* Evgeniy Samohin, <e.samohin@omp.ru>
* Maintainer, 2023
# Aurora OS Share API Example
Example of using Share API for Aurora OS.
To implement the example [Share API](https://community.omprussia.ru/documentation/software_development/reference/share.html) documentation was used.
The application allows to share files with other applications and accept files from other applications.
The supported file types are images and PDF-documents.
The main page of the application is a file list of the user file system.
The user can navigate through directories and see images and PDF-documents. Files of other types are hidden.
The context menu is invoked by long pressing on a file in the list and contains single item "Share".
The "Share" item allows to open a system dialog for selecting an application or a device to share the file.
Besides the application can accept files and information about them from other applications.
To test this, invoke the "Share" context menu item in a side application and select "Aurora OS Share API Example" in the list of available applications.
As the result the application "Aurora OS Share API Example" will be run. If it was already running it will be activated and the "Accepted files" page with
information about the accepted files will be opened.
To implement the "Share" function the [ShareAction](https://community.omprussia.ru/documentation/software_development/reference/share/shareaction.html) component was used.
Its using is described in the `MainPage.qml` file.
To implement accepting file from side applications the [ShareProvider](https://community.omprussia.ru/documentation/software_development/reference/share/shareprovider.html)
component and [the description of an example of its implementation](https://community.omprussia.ru/documentation/software_development/reference/share/example.html) were used.
it is worth to pay attention on the specification of the `ru.auroraos.ShareApi.desktop` file on the `X-Share-Methods`, `X-Maemo-Service`, `X-Maemo-Method` fields
and on the `[X-Share Method ...]` block specification. In the `main()` DBus-service registration was added. This is necessary to be able to activate the application.
The `ShareProvider` components are declared in the `ApplicationWindow` and describe the `onTriggered` handler.
## Terms of Use and Participation
The source code of the project is provided under [the license](LICENSE.BSD-3-Clause.md),
which allows its use in third-party applications.
The [contributor agreement](CONTRIBUTING.md) documents the rights granted by contributors
of the Open Mobile Platform.
Information about the contributors is specified in the [AUTHORS](AUTHORS.md) file.
[Code of conduct](CODE_OF_CONDUCT.md) is a current set of rules of the Open Mobile
Platform which informs you how we expect the members of the community will interact
while contributing and communicating.
## Project Structure
The project has a standard structure of an application based on C++ and QML for Aurora OS.
* **[ru.auroraos.ShareApi.pro](ru.auroraos.ShareApi.pro)** file
describes the project structure for the qmake build system.
* **[icons](icons)** directory contains the application icons for different screen resolutions.
* **[qml](qml)** directory contains the QML source code and the UI resources.
* **[cover](qml/cover)** directory contains the application cover implementations.
* **[icons](qml/icons)** directory contains the additional custom UI icons.
* **[pages](qml/pages)** directory contains the application pages.
* **[ShareApi.qml](qml/ShareApi.qml)** file
provides the application window implementation.
* **[rpm](rpm)** directory contains the rpm-package build settings.
* **[ru.auroraos.ShareApi.spec](rpm/ru.auroraos.ShareApi.spec)** file is used by rpmbuild tool.
* **[src](src)** directory contains the C++ source code.
* **[ru.auroraos.ShareApi.cpp](src/ru.auroraos.ShareApi.cpp)** file is the application entry point.
* **[translations](translations)** directory contains the UI translation files.
* **[ru.auroraos.ShareApi.desktop](ru.auroraos.ShareApi.desktop)** file
defines the display and parameters for launching the application.
## Compatibility
The project is compatible with all the current versions of the Aurora OS.
## Screenshots
![screenshots](screenshots/screenshots.png)
## This document in Russian / Перевод этого документа на русский язык
- [README.ru.md](README.ru.md)
# Aurora OS Share API Example
Приложение демонстрирует использование Share API для ОС Аврора.
Для реализации примера использовалась документация на [Share API](https://community.omprussia.ru/documentation/software_development/reference/share.html).
Приложение позволяет как делиться файлами с другими приложениями, так и принимать их от других приложений.
Поддерживаемые типы файлов: изображения и PDF-документы.
Главная страница приложения — список файлов файловой системы пользователя.
Пользователь может перемещаться по каталогам и видеть изображения и PDF-документы, файлы других типов пользователю не показываются.
Контекстное меню вызывается по долгому нажатию на файл в списке и содержит один пункт "Поделиться".
Пункт "Поделиться" позволяет вызвать системный диалог выбора приложения или устройства, с которым можно поделиться данным файлом.
Кроме того, приложение может принимать файлы и информацию о них от других приложений.
Для тестирования этого необходимо вызвать меню "Поделиться" в стороннем приложении и выбрать "Aurora OS Share API Example" в списке доступных.
В результате приложение "Aurora OS Share API Example" будет запущено, либо активировано, если оно уже было запущено, и откроется страница "Принятые файлы"
с информацией о принятых файлах.
Для реализации функции "Поделиться" использовался компонент [ShareAction](https://community.omprussia.ru/documentation/software_development/reference/share/shareaction.html),
его использование описано в файле `MainPage.qml`.
Для реализации приема файлов от сторонних приложений использовался компонент [ShareProvider](https://community.omprussia.ru/documentation/software_development/reference/share/shareprovider.html)
и [описание примера его реализации](https://community.omprussia.ru/documentation/software_development/reference/share/example.html). Стоит обратить внимание на описание
файла `ru.auroraos.ShareApi.desktop`, а именно на поля `X-Share-Methods`, `X-Maemo-Service`, `X-Maemo-Method`, а также на описание
блоков `[X-Share Method ...]`. В функцию `main()` была добавлена регистрация DBus-службы приложения. Это необходимо для возможности активации приложения.
Компоненты `ShareProvider` объявляются в `ApplicationWindow` и описывают обработчик `onTriggered`.
## Условия использования и участия
Исходный код проекта предоставляется по [лицензии](LICENSE.BSD-3-Clause.md),
которая позволяет использовать его в сторонних приложениях.
[Соглашение участника](CONTRIBUTING.md) регламентирует права,
предоставляемые участниками компании «Открытая Мобильная Платформа».
Информация об участниках указана в файле [AUTHORS](AUTHORS.md).
[Кодекс поведения](CODE_OF_CONDUCT.md) — это действующий набор правил
компании «Открытая Мобильная Платформа»,
который информирует об ожиданиях по взаимодействию между членами сообщества при общении и работе над проектами.
## Структура проекта
Проект имеет стандартную структуру приложения на базе C++ и QML для ОС Аврора.
* Файл **[ru.auroraos.ShareApi.pro](ru.auroraos.ShareApi.pro)**
описывает структуру проекта для системы сборки qmake.
* Каталог **[icons](icons)** содержит иконки приложения для поддерживаемых разрешений экрана.
* Каталог **[qml](qml)** содержит исходный код на QML и ресурсы интерфейса пользователя.
* Каталог **[cover](qml/cover)** содержит реализации обложек приложения.
* Каталог **[icons](qml/icons)** содержит дополнительные иконки интерфейса пользователя.
* Каталог **[pages](qml/pages)** содержит страницы приложения.
* Файл **[ShareApi.qml](qml/ShareApi.qml)**
предоставляет реализацию окна приложения.
* Каталог **[rpm](rpm)** содержит настройки сборки rpm-пакета.
* Файл **[ru.auroraos.ShareApi.spec](rpm/ru.auroraos.ShareApi.spec)**
используется инструментом rpmbuild.
* Каталог **[src](src)** содержит исходный код на C++.
* Файл **[main.cpp](src/main.cpp)** является точкой входа в приложение.
* Каталог **[translations](translations)** содержит файлы перевода интерфейса пользователя.
* Файл **[ru.auroraos.ShareApi.desktop](ru.auroraos.ShareApi.desktop)**
определяет отображение и параметры запуска приложения.
## Совместимость
Проект совместим с актуальными версиями ОС Аврора.
## Снимки экранов
![screenshots](screenshots/screenshots.png)
## This document in English
- [README.md](README.md)
/*******************************************************************************
**
** Copyright (C) 2022 ru.auroraos
**
** This file is part of the Example of using Share API for Aurora OS project.
**
** Redistribution and use in source and binary forms,
** with or without modification, are permitted provided
** that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer
** in the documentation and/or other materials provided with the distribution.
** * Neither the name of the copyright holder nor the names of its contributors
** may be used to endorse or promote products derived from this software
** without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
** FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
** OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS;
** OR BUSINESS INTERRUPTION)
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
** EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
*******************************************************************************/
import QtQuick 2.0
import Sailfish.Silica 1.0
ApplicationWindow {
objectName: "applicationWindow"
initialPage: Qt.resolvedUrl("pages/MainPage.qml")
cover: Qt.resolvedUrl("cover/DefaultCoverPage.qml")
allowedOrientations: defaultAllowedOrientations
}
\ Нет новой строки в конце файла
// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
import QtQuick 2.0
import Sailfish.Silica 1.0
import Sailfish.Share 1.0
ApplicationWindow {
id: appWindow
objectName: "applicationWindow"
initialPage: Qt.resolvedUrl("pages/MainPage.qml")
cover: Qt.resolvedUrl("cover/DefaultCoverPage.qml")
allowedOrientations: defaultAllowedOrientations
ShareProvider {
method: "images"
capabilities: ["image/*"]
onTriggered: {
appWindow.activate();
console.log("Image(s):");
console.log(JSON.stringify(resources));
pageStack.push(Qt.resolvedUrl("pages/ShareProviderPage.qml"), {
"sharedFiles": resources,
"type": "image"
});
}
}
ShareProvider {
method: "documents"
capabilities: ["application/pdf"]
onTriggered: {
appWindow.activate();
console.log("PDF(s):");
console.log(JSON.stringify(resources));
pageStack.push(Qt.resolvedUrl("pages/ShareProviderPage.qml"), {
"sharedFiles": resources,
"type": "pdf"
});
}
}
}
/*******************************************************************************
**
** Copyright (C) 2022 ru.auroraos
**
** This file is part of the Example of using Share API for Aurora OS project.
**
** Redistribution and use in source and binary forms,
** with or without modification, are permitted provided
** that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer
** in the documentation and/or other materials provided with the distribution.
** * Neither the name of the copyright holder nor the names of its contributors
** may be used to endorse or promote products derived from this software
** without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
** FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
** OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS;
** OR BUSINESS INTERRUPTION)
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
** EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
*******************************************************************************/
// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
import QtQuick 2.0
import Sailfish.Silica 1.0
......@@ -43,11 +8,8 @@ CoverBackground {
CoverPlaceholder {
objectName: "placeholder"
text: qsTr("Aurora OS Share API Example")
icon {
source: Qt.resolvedUrl("../icons/AuroraOsShareApiExample.svg")
sourceSize { width: icon.width; height: icon.height }
}
icon.source: Qt.resolvedUrl("../icons/ShareApi.svg")
text: qsTr("Aurora OS Share API")
forceFit: true
}
}
<svg width="86" height="86" viewBox="0 0 87 87" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0.615723 30.0852C0.615723 14.9298 0.615723 9.47699 5.32391 4.7688C10.0321 0.0606079 15.4849 0.0606079 32.7653 0.0606079H54.4662C71.7465 0.0606079 77.1993 0.0606079 81.9075 4.7688C86.6157 9.47699 86.6157 14.9298 86.6157 32.2101V53.9111C86.6157 71.1914 86.6157 76.6442 81.9075 81.3524C77.1993 86.0606 71.7465 86.0606 54.4662 86.0606H32.7652C15.4849 86.0606 10.0321 86.0606 5.32391 81.3524C0.615723 76.6442 0.615723 71.1914 0.615723 53.9111V30.0852Z" fill="url(#paint0_radial_601_2547)"/>
<g filter="url(#filter0_i_601_2547)">
<path d="M29.0393 32.7944C25.1816 35.6837 22.8045 39.5085 21.9081 44.269C21.4699 46.601 21.418 48.9402 21.7526 51.2866C21.7697 51.4047 21.7426 51.416 21.6714 51.3204C20.5559 49.8099 19.5757 48.2111 18.7307 46.5239C17.9922 45.0495 17.4182 43.4953 17.0088 41.8613C18.6031 39.835 20.376 38.0977 22.3274 36.6495C24.2789 35.2012 28.9852 32.8007 29.0393 32.7944Z" fill="white" fill-opacity="0.2"/>
</g>
<path fill-rule="evenodd" clip-rule="evenodd" d="M29.0384 32.7952C29.0387 32.795 29.039 32.7949 29.0392 32.7948C29.1069 32.7491 29.1739 32.7032 29.2406 32.6574C29.5176 32.4671 29.7901 32.28 30.0943 32.1306C30.5127 31.9239 30.9196 31.7056 31.3254 31.488C31.9075 31.1757 32.4871 30.8647 33.0945 30.5913C36.322 29.1412 39.8578 28.2931 43.3612 27.8982C43.4045 27.8927 43.4257 27.9117 43.4248 27.955C43.4185 28.7079 43.4166 29.5191 43.4194 30.3884C43.4203 30.9917 43.4297 31.3411 43.4478 31.4367C43.7021 32.7758 45.0818 33.4684 46.314 32.8935C52.7563 29.8879 59.181 26.894 65.5881 23.9119C66.8704 23.3153 67.2099 21.753 66.2901 20.7345C66.1052 20.5298 65.7558 20.3079 65.2418 20.069C58.5164 16.9452 52.2603 14.0343 46.4737 11.3362C46.1734 11.1964 45.906 11.1108 45.6715 11.0792C44.488 10.9182 43.4572 11.8232 43.4342 12.9865C43.4135 14.0794 43.4126 15.1507 43.4315 16.2004C43.4318 16.2348 43.4208 16.2683 43.4002 16.2955C43.3796 16.3227 43.3507 16.3421 43.3179 16.3505C39.7595 17.2532 36.276 18.4566 32.8673 19.9608C28.8472 21.7354 24.9069 24.0755 21.8066 27.1055C20.4972 28.3851 19.4155 29.7585 18.5616 31.2257C16.6814 34.4522 16.1637 37.9976 17.0087 41.8616C17.0087 41.8616 17.0088 41.8615 17.0088 41.8615C17.0088 41.8615 17.0088 41.8614 17.0088 41.8614C18.6031 39.8351 20.376 38.0978 22.3274 36.6496C24.2789 35.2013 28.9852 32.8008 29.0393 32.7945C29.039 32.7947 29.0387 32.795 29.0384 32.7952Z" fill="url(#paint1_radial_601_2547)"/>
<g filter="url(#filter1_i_601_2547)">
<path d="M57.3982 53.3268C61.2559 50.4375 63.633 46.6127 64.5294 41.8522C64.9676 39.5202 65.0195 37.181 64.6849 34.8346C64.6678 34.7165 64.6949 34.7052 64.7661 34.8008C65.8816 36.3113 66.8618 37.9101 67.7068 39.5973C68.4453 41.0717 69.0193 42.6259 69.4287 44.2599C67.8344 46.2862 66.0615 48.0235 64.1101 49.4717C62.1586 50.92 57.4523 53.3205 57.3982 53.3268Z" fill="white" fill-opacity="0.2"/>
</g>
<path fill-rule="evenodd" clip-rule="evenodd" d="M57.3991 53.326C57.3988 53.3262 57.3985 53.3263 57.3983 53.3264C57.3306 53.3721 57.2636 53.4181 57.1969 53.4638C56.9199 53.6541 56.6474 53.8412 56.3432 53.9906C55.9248 54.1973 55.5179 54.4156 55.1121 54.6333C54.53 54.9455 53.9504 55.2565 53.343 55.5299C50.1155 56.98 46.5797 57.8281 43.0763 58.2231C43.033 58.2285 43.0118 58.2095 43.0127 58.1663C43.019 57.4133 43.0209 56.6021 43.0181 55.7328C43.0172 55.1295 43.0078 54.7801 42.9897 54.6845C42.7354 53.3454 41.3557 52.6528 40.1235 53.2277C33.6812 56.2333 27.2565 59.2272 20.8494 62.2093C19.5671 62.8059 19.2276 64.3682 20.1474 65.3867C20.3323 65.5914 20.6817 65.8133 21.1957 66.0522C27.9211 69.176 34.1772 72.0869 39.9638 74.785C40.2641 74.9248 40.5315 75.0105 40.766 75.042C41.9495 75.203 42.9803 74.2981 43.0033 73.1348C43.024 72.0418 43.0249 70.9705 43.006 69.9208C43.0057 69.8864 43.0167 69.853 43.0373 69.8257C43.0579 69.7985 43.0868 69.7792 43.1196 69.7707C46.678 68.868 50.1615 67.6646 53.5702 66.1605C57.5903 64.3858 61.5306 62.0457 64.6309 59.0157C65.9403 57.7361 67.022 56.3627 67.8759 54.8955C69.7561 51.669 70.2738 48.1237 69.4288 44.2596C69.4288 44.2596 69.4287 44.2597 69.4287 44.2597C69.4287 44.2598 69.4287 44.2598 69.4287 44.2599C67.8344 46.2861 66.0615 48.0234 64.1101 49.4716C62.1586 50.9199 57.4523 53.3204 57.3982 53.3267C57.3985 53.3265 57.3988 53.3263 57.3991 53.326Z" fill="url(#paint2_radial_601_2547)"/>
<defs>
<filter id="filter0_i_601_2547" x="17.0088" y="32.7944" width="12.0308" height="18.5901" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
<feOffset/>
<feGaussianBlur stdDeviation="3"/>
<feComposite in2="hardAlpha" operator="arithmetic" k2="-1" k3="1"/>
<feColorMatrix type="matrix" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.9 0"/>
<feBlend mode="normal" in2="shape" result="effect1_innerShadow_601_2547"/>
</filter>
<filter id="filter1_i_601_2547" x="57.3979" y="34.7367" width="12.0308" height="18.5901" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
<feOffset/>
<feGaussianBlur stdDeviation="3"/>
<feComposite in2="hardAlpha" operator="arithmetic" k2="-1" k3="1"/>
<feColorMatrix type="matrix" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.9 0"/>
<feBlend mode="normal" in2="shape" result="effect1_innerShadow_601_2547"/>
</filter>
<radialGradient id="paint0_radial_601_2547" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(85.1157 84.0606) rotate(-136.606) scale(151.38)">
<stop stop-color="#F3030E"/>
<stop offset="0.46875" stop-color="#F10078"/>
<stop offset="1" stop-color="#6A72C8"/>
<stop offset="1" stop-color="#8702DB"/>
</radialGradient>
<radialGradient id="paint1_radial_601_2547" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(23.8895 39.9487) rotate(-22.7474) scale(42.4104 25.3863)">
<stop offset="0.510417" stop-color="white"/>
<stop offset="1" stop-color="white" stop-opacity="0.8"/>
</radialGradient>
<radialGradient id="paint2_radial_601_2547" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(62.548 46.1725) rotate(157.253) scale(42.4104 25.3863)">
<stop offset="0.510417" stop-color="white"/>
<stop offset="1" stop-color="white" stop-opacity="0.8"/>
</radialGradient>
</defs>
</svg>
/*******************************************************************************
**
** Copyright (C) 2022 ru.auroraos
**
** This file is part of the Example of using Share API for Aurora OS project.
**
** Redistribution and use in source and binary forms,
** with or without modification, are permitted provided
** that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer
** in the documentation and/or other materials provided with the distribution.
** * Neither the name of the copyright holder nor the names of its contributors
** may be used to endorse or promote products derived from this software
** without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
** FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
** OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS;
** OR BUSINESS INTERRUPTION)
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
** EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
*******************************************************************************/
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
import QtQuick 2.0
import Sailfish.Silica 1.0
......
/*******************************************************************************
**
** Copyright (C) 2022 ru.auroraos
**
** This file is part of the Example of using Share API for Aurora OS project.
**
** Redistribution and use in source and binary forms,
** with or without modification, are permitted provided
** that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer
** in the documentation and/or other materials provided with the distribution.
** * Neither the name of the copyright holder nor the names of its contributors
** may be used to endorse or promote products derived from this software
** without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
** FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
** OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS;
** OR BUSINESS INTERRUPTION)
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
** EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
*******************************************************************************/
// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
import QtQuick 2.0
import Sailfish.Silica 1.0
import Sailfish.Share 1.0
import Qt.labs.folderlistmodel 2.1
import ru.auroraos.ShareApi 1.0
Page {
property string currentFolder: StandardPaths.home
property string returnFolder: currentFolder.replace("file://", "").split("/").length > 3
? currentFolder.substring(0, currentFolder.lastIndexOf("/"))
: ""
objectName: "mainPage"
allowedOrientations: Orientation.All
PageHeader {
objectName: "pageHeader"
title: qsTr("Aurora OS Share API Example")
extraContent.children: [
IconButton {
objectName: "aboutButton"
icon.source: "image://theme/icon-m-about"
anchors.verticalCenter: parent.verticalCenter
ShareAction {
id: shareAction
title: qsTr("Share")
}
FolderListModel {
id: folderModel
folder: currentFolder
showDirsFirst: true
nameFilters: ["*.png", "*.jpeg", "*.jpg", "*.pdf"]
}
SilicaFlickable {
anchors.fill: parent
PageHeader {
id: pageHeader
title: returnFolder.length > 0 ? currentFolder.replace("file://", "").replace(StandardPaths.home + "/", "")
: qsTr("Share API")
extraContent.children: [
IconButton {
objectName: "aboutButton"
icon.source: "image://theme/icon-m-about"
anchors.verticalCenter: parent.verticalCenter
visible: !returnButton.visible
onClicked: pageStack.push(Qt.resolvedUrl("AboutPage.qml"))
}
]
}
BackgroundItem {
id: returnButton
anchors {
top: pageHeader.bottom
left: parent.left
right: parent.right
bottomMargin: Theme.paddingMedium
}
contentHeight: Theme.itemSizeMedium
highlighted: pressed
visible: returnFolder.length > 0
Icon {
id: returnIcon
anchors {
left: parent.left
verticalCenter: parent.verticalCenter
leftMargin: Theme.horizontalPageMargin
}
source: "image://theme/icon-m-back"
}
Label {
id: label
anchors {
left: returnIcon.right
right: parent.right
verticalCenter: parent.verticalCenter
leftMargin: Theme.paddingMedium
rightMargin: Theme.horizontalPageMargin
}
text: qsTr("Back")
}
onClicked: {
currentFolder = returnFolder;
}
}
SilicaListView {
anchors {
left: parent.left
right: parent.right
top: returnButton.visible ? returnButton.bottom : pageHeader.bottom
bottom: parent.bottom
}
clip: true
model: folderModel
delegate: ListItem {
id: listItem
width: parent.width
contentHeight: Theme.itemSizeMedium
Image {
id: itemIcon
anchors {
left: parent.left
verticalCenter: parent.verticalCenter
leftMargin: Theme.horizontalPageMargin
}
sourceSize {
height: Theme.itemSizeSmall
width: Theme.itemSizeSmall
}
source: if (folderModel.isFolder(model.index)) {
return "image://theme/icon-m-folder?" + (pressed ? Theme.highlightColor
: Theme.primaryColor);
} else if (MimeTypeManager.mimeTypeForFile(model.filePath).indexOf("pdf") !== -1) {
return "image://theme/icon-m-file-pdf-dark";
} else {
return model.filePath || "";
}
}
Label {
anchors {
left: itemIcon.right
right: parent.right
verticalCenter: parent.verticalCenter
rightMargin: Theme.horizontalPageMargin
leftMargin: Theme.paddingMedium
}
text: model.fileName
}
menu: ContextMenu {
hasContent: !folderModel.isFolder(model.index)
MenuItem {
text: qsTr("Share")
onClicked: {
shareAction.resources = [model.filePath];
shareAction.mimeType = MimeTypeManager.mimeTypeForFile(model.filePath);
shareAction.trigger();
}
}
}
onClicked: {
if (folderModel.isFolder(index)) {
currentFolder = folderModel.folder + "/" + model.fileName;
}
}
}
onClicked: pageStack.push(Qt.resolvedUrl("AboutPage.qml"))
VerticalScrollDecorator {
}
]
}
}
}
// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
import QtQuick 2.0
import Sailfish.Silica 1.0
import Sailfish.Share 1.0
Page {
property var sharedFiles: []
property string type: ""
objectName: "shareProviderPage"
allowedOrientations: Orientation.All
SilicaListView {
anchors.fill: parent
header: PageHeader {
objectName: "pageHeader"
title: qsTr("Shared files (%1):").arg(type)
}
clip: true
model: sharedFiles
delegate: ListItem {
Column {
anchors {
left: parent.left
right: parent.right
leftMargin: Theme.horizontalPageMargin
rightMargin: Theme.horizontalPageMargin
}
spacing: Theme.paddingMedium
Label {
anchors {
left: parent.left
right: parent.right
}
text: qsTr("Name: %1").arg(modelData.name)
wrapMode: Text.Wrap
}
Label {
anchors {
left: parent.left
right: parent.right
}
text: qsTr("Object Name: %1").arg(modelData.objectName)
wrapMode: Text.Wrap
}
Label {
anchors {
left: parent.left
right: parent.right
}
text: qsTr("Type: %1").arg(resourceTypeToString(modelData.type))
wrapMode: Text.Wrap
}
Label {
anchors {
left: parent.left
right: parent.right
}
text: qsTr("File path: %1").arg(modelData.filePath)
wrapMode: Text.Wrap
}
}
Separator {
}
}
VerticalScrollDecorator {
}
}
function resourceTypeToString(type) {
switch (type) {
case ShareResource.FilePathType:
return "ShareResource.FilePathType";
case ShareResource.StringDataType:
return "ShareResource.StringDataType";
default:
return "Unknown resource type: %1".arg(type);
}
}
}
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать