Fix copying the current repo to the clipboard. By@real-yfprojects (#1313)

This commit is contained in:
yfprojects 2022-05-22 07:32:57 +00:00 committed by GitHub
parent efe710540a
commit 4b6d080f05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 8 deletions

View File

@ -1,6 +1,8 @@
import os
from pathlib import PurePath
from PyQt5 import QtCore, uic
from PyQt5.QtCore import QMimeData, QUrl
from PyQt5.QtWidgets import QApplication, QMenu, QMessageBox
from vorta.store.models import ArchiveModel, BackupProfileMixin, RepoModel
@ -266,12 +268,21 @@ class RepoTab(RepoBase, RepoUI, BackupProfileMixin):
self.init_repo_stats()
def copy_URL_action(self):
if self.repoSelector.currentIndex() > 2:
URL = self.repoSelector.currentText()
QApplication.clipboard().setText(URL)
selected_repo_id = self.repoSelector.currentData()
if not selected_repo_id:
# QComboBox is empty
return
repo = RepoModel.get(id=selected_repo_id)
url = repo.url
data = QMimeData()
if not repo.is_remote_repo():
path = PurePath(url)
data.setUrls([QUrl(path.as_uri())])
data.setText(str(path))
else:
msg = QMessageBox()
msg.setStandardButtons(QMessageBox.Ok)
msg.setParent(self, QtCore.Qt.Sheet)
msg.setText(self.tr("Select a repository from the dropdown first."))
msg.show()
data.setText(url)
QApplication.clipboard().setMimeData(data)