import QtQuick import QtQuick.Controls import QtQuick.Layouts // Диалог настройки провайдера синхронизации с пошаговой инструкцией, // проверкой соединения и каталогом ошибок (ErrorCatalog в SyncManager). Dialog { id: root property int providerIndex: -1 property string providerName: "" property bool connected: false signal saved(int index) readonly property bool isGit: providerIndex <= 2 title: qsTr("Подключение: %1").arg(providerName) z: 100 modal: false width: 640 height: 520 anchors.centerIn: parent closePolicy: Dialog.CloseOnEscape | Dialog.CloseOnPressOutside function defaultUrl() { switch (root.providerIndex) { case 0: return "https://github.com" case 1: return "https://gitlab.com" case 2: return "http://localhost:3000" case 3: return "https://nextcloud.local/remote.php/dav/files/USER" default: return "http://127.0.0.1:8384" } } function tokenName() { switch (root.providerIndex) { case 0: return qsTr("Токен GitHub (Personal Access Token)") case 1: return qsTr("Токен GitLab (PRIVATE-TOKEN)") case 2: return qsTr("Токен Gitea (Personal Access Token)") case 3: return qsTr("Пароль от Nextcloud") default: return qsTr("API-ключ Syncthing") } } Component.onCompleted: { urlField.text = defaultUrl() } ColumnLayout { anchors.fill: parent spacing: 10 // Инструкция Rectangle { Layout.fillWidth: true Layout.preferredHeight: 150 color: "#f4f6fa" radius: 6 Flickable { anchors.fill: parent anchors.margins: 8 ScrollBar.vertical: ScrollBar {} clip: true contentWidth: width contentHeight: instText.implicitHeight Text { id: instText width: parent.width wrapMode: Text.Wrap textFormat: Text.MarkdownText color: "#333" text: root.providerIndex === 0 ? "**Как подключить GitHub:**\n\n" + "1. Создайте токен: [github.com/settings/tokens](https://github.com/settings/tokens) — scope **repo** (классический) или Fine-grained с правом **Contents: Read and write**.\n" + "2. Создайте **пустой** репозиторий (без README/.gitignore — иначе конфликт истории): New repository.\n" + "3. Вставьте токен ниже и нажмите «Проверить».\n" + "4. Альтернатива — SSH-ключ (Подключение → SSH, доступно в Фазе 11)." : root.providerIndex === 1 ? "**Как подключить GitLab:**\n\n" + "1. Токен: Настройки → Access Tokens — scope **api** (или **read_repository** + **write_repository**).\n" + "2. Создайте **пустой** репозиторий в своём аккаунте/группе.\n" + "3. Для self-hosted: укажите адрес инстанса, например http://gitlab.local. Вставьте токен и нажмите «Проверить».\n" + "4. Альтернатива — SSH-ключ (доступно в Фазе 11)." : root.providerIndex === 2 ? "**Как подключить Gitea:**\n\n" + "1. Токен: Настройки аккаунта → Приложения → **Создать новый токен** (scope **repo**).\n" + "2. Создайте **пустой** репозиторий на своём инстансе.\n" + "3. Укажите адрес инстанса (например http://localhost:3000), вставьте токен и нажмите «Проверить».\n" + "4. Альтернатива — SSH-ключ (доступно в Фазе 11)." : root.providerIndex === 3 ? "**Как подключить Nextcloud (WebDAV):**\n\n" + "1. Откройте приложение Files, создайте папку для синхронизации (например **Flora**).\n" + "2. Адрес WebDAV: https://ВАШ_ХОСТ/remote.php/dav/files/ВАШ_ЛОГИН/\n" + "3. Укажите логин и пароль аккаунта Nextcloud и нажмите «Проверить».\n" + "4. Рекомендуется создать пароль приложения в Настройках → Безопасность." : "**Как подключить Syncthing:**\n\n" + "1. Установите и запустите Syncthing на этом устройстве.\n" + "2. API-ключ: Действия → Настройки → Показывать расширенное → API-ключ.\n" + "3. Адрес API по умолчанию: http://127.0.0.1:8384. Вставьте ключ и нажмите «Проверить».\n" + "4. Затем добавьте папку хранилища в Syncthing как обычную папку." } } } // Поля ColumnLayout { Layout.fillWidth: true spacing: 6 Label { text: qsTr("Адрес сервера") } TextField { id: urlField; Layout.fillWidth: true } Label { visible: root.providerIndex === 3 text: qsTr("Логин (для WebDAV):") } TextField { id: userField Layout.fillWidth: true visible: root.providerIndex === 3 placeholderText: qsTr("Логин Nextcloud") } Label { text: tokenName() } TextField { id: tokenField Layout.fillWidth: true echoMode: TextInput.Password placeholderText: qsTr("Вставьте значение") } } // Результат / ошибка Label { id: resultLabel Layout.fillWidth: true wrapMode: Text.Wrap visible: text.length > 0 color: root.connected ? "green" : "#b00020" } Item { Layout.fillHeight: true } RowLayout { Layout.fillWidth: true Button { text: qsTr("Отмена") onClicked: root.reject() } Item { Layout.fillWidth: true } Button { text: qsTr("Проверить соединение") enabled: tokenField.text.length > 0 && !syncManager.busy onClicked: { resultLabel.text = "" root.connected = false syncManager.testConnection(root.providerIndex, urlField.text, userField.text, tokenField.text) } } Button { text: qsTr("Сохранить") enabled: root.connected onClicked: { settingsStore.addProvider(root.providerName, { url: urlField.text, user: userField.text, token: tokenField.text, }) root.saved(root.providerIndex) root.accept() } } } } Connections { target: syncManager function onConnectionResult(provider, ok, code, title, hint, raw) { if (provider !== root.providerIndex) return root.connected = ok resultLabel.text = ok ? qsTr("Соединение установлено. Нажмите «Сохранить».") : title + (hint && hint.length > 0 ? "\n" + hint : "") } } }