Example #1
0
    def __add_account(self, sourcesList):
        module_name = sourcesList.currentItem().text()
        module_slug = sourcesList.currentItem().slug

        if module_slug not in modules.modules:
            pass  # TODO

        account = modules.create_object(module_slug)

        if not account.authenticate():
            # TODO do something else than failing silently
            return False

        accounts = QSettings()
        accounts.beginGroup("accounts")
        if account.getId() in accounts.childKeys():
            errorMsg = QMessageBox(
                QMessageBox.Critical, "Account already exists",
                "This account already exists. Please delete it first.",
                QMessageBox.Ok, self)
            errorMsg.show()
            return

        self.account_added.emit(account)
        self.close()
Example #2
0
    def delete_app_from_folder(self, appid: str, folder: str):
        assert "/" not in folder
        settings = QSettings()
        settings.beginGroup(f"apps/_folder/{folder}")

        for key in settings.childKeys():
            if appid == settings.value(key):
                settings.remove(key)
                self.app_change.emit()
                return
Example #3
0
def load_default_external_links():
    """Load default external DB links if the list is empty"""
    app_settings = QSettings()
    app_settings.beginGroup("plugins/variant_view/links")

    # If no value: add default values
    if not app_settings.childKeys():
        for db_name, db_url in cm.WEBSITES_URLS.items():
            app_settings.setValue(db_name, db_url)
    app_settings.endGroup()
Example #4
0
    def all_apps(self) -> Iterator[Tuple[str, AppManifest]]:
        settings = QSettings()
        settings.beginGroup("apps")
        for appid in settings.childKeys():
            if appid.startswith("_"):
                continue

            manifest = json.loads(settings.value(appid))
            yield appid, manifest

        settings.endGroup()
Example #5
0
    def __init__(self):
        super().__init__()
        self.setWindowTitle("muSync - Accounts")
        self.setModal(True)

        dialogLayout = QVBoxLayout(self)

        accountsList = QListWidget()
        accountsList.setObjectName("accountsList")
        dialogLayout.addWidget(accountsList)

        buttonsLayout = QHBoxLayout()
        addButton = QPushButton(QIcon.fromTheme("list-resource-add"),
                                "&Add account")
        addButton.clicked.connect(lambda: self.__show_modules())
        buttonsLayout.addWidget(addButton)
        delButton = QPushButton(QIcon.fromTheme("edit-delete"),
                                "&Remove account")
        delButton.clicked.connect(lambda: self.__del_account(accountsList))
        delButton.setDisabled(True)
        buttonsLayout.addWidget(delButton)
        okButton = QPushButton(QIcon.fromTheme("dialog-ok"), "&Select account")
        okButton.clicked.connect(lambda: self.__select_account(accountsList))
        okButton.setDisabled(True)
        buttonsLayout.addWidget(okButton)
        cancelButton = QPushButton(QIcon.fromTheme("dialog-cancel"), "&Cancel")
        cancelButton.clicked.connect(self.close)
        buttonsLayout.addWidget(cancelButton)
        dialogLayout.addLayout(buttonsLayout)
        accountsList.itemSelectionChanged.connect(lambda: okButton.setDisabled(
            True if accountsList.selectedIndexes() == [] else False))
        accountsList.itemSelectionChanged.connect(
            lambda: delButton.setDisabled(True if accountsList.selectedIndexes(
            ) == [] else False))

        accounts = QSettings()
        accounts.beginGroup("accounts")
        for account_id in accounts.childKeys():
            module_name = accounts.value(account_id)

            if module_name not in modules.modules:
                pass  # TODO

            account = modules.create_object(module_name)
            account.setId(account_id)
            account.initialize()

            accountListItem = QListWidgetItem(account.getName())
            accountListItem.account = account
            accountsList.addItem(accountListItem)

        accountsList.itemDoubleClicked.connect(
            lambda: self.__select_account(accountsList))
    def update_locations(self):
        self.locations_table.setUpdatesEnabled(False)
        self.locations_table.setRowCount(0)

        for i in range(2):
            if i == 0:
                if self.scope() == QSettings.SystemScope:
                    continue

                actualScope = QSettings.UserScope
            else:
                actualScope = QSettings.SystemScope

            for j in range(2):
                if j == 0:
                    if not self.application():
                        continue

                    actualApplication = self.application()
                else:
                    actualApplication = ''

                settings = QSettings(self.format(), actualScope,
                                     self.organization(), actualApplication)

                row = self.locations_table.rowCount()
                self.locations_table.setRowCount(row + 1)

                item0 = QTableWidgetItem()
                item0.setText(settings.fileName())

                item1 = QTableWidgetItem()
                disable = not (settings.childKeys() or settings.childGroups())

                if row == 0:
                    if settings.isWritable():
                        item1.setText("Read-write")
                        disable = False
                    else:
                        item1.setText("Read-only")
                    self.button_box.button(QDialogButtonBox.Ok).setDisabled(disable)
                else:
                    item1.setText("Read-only fallback")

                if disable:
                    item0.setFlags(item0.flags() & ~Qt.ItemIsEnabled)
                    item1.setFlags(item1.flags() & ~Qt.ItemIsEnabled)

                self.locations_table.setItem(row, 0, item0)
                self.locations_table.setItem(row, 1, item1)

        self.locations_table.setUpdatesEnabled(True)
Example #7
0
    def add_app_to_folder(self, appid: str, folder: str = "", _emit=True):
        assert "/" not in folder
        settings = QSettings()
        settings.beginGroup(f"apps/_folder/{folder}")

        last_id = 0
        for key in settings.childKeys():
            if "_" in key:
                continue

            last_id = max(int(key), last_id)
            if appid == settings.value(key):
                settings.endGroup()
                return

        keys = [int(x) for x in settings.childKeys() if "_" not in x]
        last_id = max(keys) if keys else 0
        settings.endGroup()

        settings.setValue(f"apps/_folder/{folder}/{last_id + 1}", appid)

        if _emit:
            self.app_change.emit()
Example #8
0
File: store.py Project: whs/runekit
    def list_app(self, root: str) -> Iterator[Tuple[str, Union[AppManifest, None]]]:
        settings = QSettings()

        settings.beginGroup(f"apps/_folder/" + root)
        for key in settings.childGroups():
            yield key, None
        for key in settings.childKeys():
            try:
                int(key)
            except ValueError:
                continue

            appid = settings.value(key)
            yield appid, self[appid]
Example #9
0
    def rmdir(self, folder: str):
        assert folder
        assert "/" not in folder

        settings = QSettings()
        settings.beginGroup(f"apps/_folder/{folder}")

        for key in settings.childKeys():
            if "_" in key:
                continue

            try:
                int(key)
            except ValueError:
                continue

            self.add_app_to_folder(settings.value(key), "", _emit=False)

        settings.remove("")
        self.app_change.emit()