Skip to content

Commit

Permalink
Merge branch 'feature/conan-remote-tab-widget' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
afri-bit committed Nov 29, 2021
2 parents 9a1a5a8 + 51edecc commit b63a25b
Show file tree
Hide file tree
Showing 16 changed files with 1,279 additions and 153 deletions.
5 changes: 5 additions & 0 deletions conanguide/data/conan_remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ConanRemote:
def __init__(self, name: str, url: str, ssl: bool):
self.name = name
self.url = url
self.ssl = ssl
34 changes: 34 additions & 0 deletions conanguide/ui/controller/tab/remote/conan_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

from conanguide.api.conan_api import ConanApi

from conanguide.data.conan_remote import ConanRemote


class ConanRemoteListController:
"""
Controller class to control view and model of the conan remote list
"""

def __init__(self, view: QtWidgets.QTableView, conan_api: ConanApi):
self.view = view
self.conan_api = conan_api
Expand All @@ -16,6 +19,7 @@ def __init__(self, view: QtWidgets.QTableView, conan_api: ConanApi):
self.view.setModel(self.model)
self.view.horizontalHeader().setStretchLastSection(False)
self.view.setShowGrid(True)
self.view.setSortingEnabled(True)

self.header_width = []

Expand All @@ -33,8 +37,11 @@ def update(self):

for remote in remote_list:
item_name = QStandardItem(remote.name)
item_name.setEditable(False)
item_url = QStandardItem(remote.url)
item_url.setEditable(False)
item_ssl = QStandardItem(str(remote.verify_ssl))
item_ssl.setEditable(False)

self.model.appendRow([item_name, item_url, item_ssl])

Expand All @@ -60,4 +67,31 @@ def __set_column_width(self):
for i in range(0, len(self.header_width)):
self.view.setColumnWidth(i, self.header_width[i])

def get_selected_item(self) -> ConanRemote or None:
row_index = self.view.currentIndex().row()

if row_index > -1:
return ConanRemote(self.model.index(row_index, 0).data(),
self.model.index(row_index, 1).data(),
True if self.model.index(row_index, 2).data() == "True" else False)
else:
return None

def add_remote(self, remote: ConanRemote):
self.conan_api.remote_add(remote.name, remote.url, verify_ssl=remote.ssl)

item_name = QStandardItem(remote.name)
item_name.setEditable(False)
item_url = QStandardItem(remote.url)
item_url.setEditable(False)
item_ssl = QStandardItem(str(remote.ssl))
item_ssl.setEditable(False)

self.model.appendRow([item_name, item_url, item_ssl])

def remove_selected_remote(self):
selected_remote = self.get_selected_item()

self.conan_api.remote_remove(selected_remote.name)

self.model.removeRow(self.view.currentIndex().row())
52 changes: 52 additions & 0 deletions conanguide/ui/controller/tab/remote/conan_remote_reference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from PySide2 import QtWidgets
from PySide2.QtGui import QStandardItemModel, QStandardItem

from conanguide.api.conan_api import ConanApi


class ConanRemoteReferenceListController:
"""
Controller class to control view and model of the conan remote list
"""

def __init__(self, view: QtWidgets.QListView, conan_api: ConanApi):
self.view = view
self.conan_api = conan_api

self.model = QStandardItemModel()
self.view.setModel(self.model)

def update(self, remote_name: str):
"""
This method provides list of recipes thats are referenced to the given remote name.
The conan API method 'remote_list_ref' gives a dictionary with recipe name as key and remote name as value. In
this method we will make a list of key based on the value of the dictionary. Basically this is a reverse search
of an dictionary.
:param remote_name: Remote name
"""
self.model.clear()

# Get the reference list from the conan API
remote_reference = self.conan_api.remote_list_ref()

# Put the key and values into a list
recipe_keys = list(remote_reference.keys())
remote_values = list(remote_reference.values())

# Get the index numbers into a list where the value is matched to the given remote name
index_list = [i for i, j in enumerate(remote_values) if j == remote_name]

# Finally based on the index list, we will get the keys from dictionary. This list will contain the recipes
# that are referenced to the given remote name
recipe_reference_list = [recipe_keys[i] for i in index_list]

# Feed the list of recipe to the QlistView widget
for recipe in recipe_reference_list:
item = QStandardItem(recipe)
item.setEditable(False)

self.model.appendRow(item)

def clear(self):
self.model.clear()
Empty file.
70 changes: 70 additions & 0 deletions conanguide/ui/dialog/edit/remote/edit_remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from conanguide.ui.dialog.edit.remote.edit_remote_ui import Ui_DialogEditRemote

from PySide2.QtCore import Slot

from PySide2 import QtWidgets, QtCore


class DialogEditRemote(QtWidgets.QDialog, Ui_DialogEditRemote):
def __init__(self, title: str, list_name: list, name="", url="", ssl=True, edit_mode=False, *args, obj=None,
**kwargs):
super(DialogEditRemote, self).__init__(*args, **kwargs)
self.setupUi(self)

self.title = title
self.list_name = list_name
self.name = name
self.url = url
self.ssl = ssl
self.edit_mode = edit_mode

self.setWindowTitle(title)

self.lineEditName.setText(self.name)
self.lineEditName.textChanged.connect(self._on_edit_text_name)

self.lineEditURL.setText(self.url)

self.checkBoxVerifySSL.setChecked(self.ssl)

if self.edit_mode:
self.btnOK.setEnabled(True)
else:
self.btnOK.setEnabled(False)

self.setWindowFlag(QtCore.Qt.WindowContextHelpButtonHint, False)

@Slot()
def on_btnOK_clicked(self):
self.accept()
self.close()

@Slot()
def on_btnCancel_clicked(self):
self.close()

@property
def remote_name(self) -> str:
return self.lineEditName.text()

@property
def remote_url(self) -> str:
return self.lineEditURL.text()

@property
def remote_ssl(self) -> bool:
return self.checkBoxVerifySSL.isChecked()

def _on_edit_text_name(self):
if self.lineEditName.text() == "":
self.btnOK.setEnabled(False)
elif self.lineEditName.text() == self.name and self.lineEditName.text() != "":
self.btnOK.setEnabled(False)
self.labelInfo.setText("Choose another name.")
else:
if self.lineEditName.text() in self.list_name:
self.labelInfo.setText("Name already exists.")
self.btnOK.setEnabled(False)
else:
self.labelInfo.setText("")
self.btnOK.setEnabled(True)
Loading

0 comments on commit b63a25b

Please sign in to comment.