Example #1
0
def test_load_settings_from_cheatcode(tmpdir_factory, monkeypatch):
    pkgdir = os.path.join(str(tmpdir_factory.getbasetemp()), 'pkgdir')
    providers_path = os.path.join(pkgdir, 'resources', 'providers')
    os.makedirs(providers_path)
    with open(os.path.join(providers_path, 'test-test.json'), 'w') as f:
        f.write('{"introducer": "pb://"}')
    monkeypatch.setattr('gridsync.invite.pkgdir', pkgdir)
    settings = load_settings_from_cheatcode('test-test')
    assert settings['introducer'] == 'pb://'
Example #2
0
def test_load_settings_from_cheatcode(tmpdir_factory, monkeypatch):
    pkgdir = os.path.join(str(tmpdir_factory.getbasetemp()), "pkgdir")
    providers_path = os.path.join(pkgdir, "resources", "providers")
    os.makedirs(providers_path)
    with open(os.path.join(providers_path, "test-test.json"), "w") as f:
        f.write('{"introducer": "pb://"}')
    monkeypatch.setattr("gridsync.invite.pkgdir", pkgdir)
    settings = load_settings_from_cheatcode("test-test")
    assert settings["introducer"] == "pb://"
Example #3
0
    def __init__(self, parent=None):
        super(WelcomeWidget, self).__init__()
        self.parent = parent

        application_settings = global_settings["application"]
        logo_icon = application_settings.get("logo_icon")
        if logo_icon:
            icon_file = logo_icon
            icon_size = 288
        else:
            icon_file = application_settings.get("tray_icon")
            icon_size = 220

        self.icon = QLabel()
        self.icon.setPixmap(Pixmap(icon_file, icon_size))
        self.icon.setAlignment(Qt.AlignCenter)

        self.slogan = QLabel("<i>{}</i>".format(
            application_settings.get("description", "")))
        self.slogan.setFont(Font(12))
        p = self.palette()
        dimmer_grey = BlendedColor(p.windowText().color(),
                                   p.window().color()).name()
        self.slogan.setStyleSheet("color: {}".format(dimmer_grey))
        self.slogan.setAlignment(Qt.AlignCenter)
        if logo_icon:
            self.slogan.hide()

        self.invite_code_widget = InviteCodeWidget(self)
        self.lineedit = self.invite_code_widget.lineedit

        self.connect_button = QPushButton("Connect")

        try:
            default_code = global_settings["connection"]["default"]
        except KeyError:
            default_code = ""
        grid_settings = load_settings_from_cheatcode(default_code)
        if grid_settings:
            self.invite_code_widget.hide()
            nickname = grid_settings.get("nickname")
            if nickname:
                font = Font(11)
                self.connect_button.setFont(font)
                self.connect_button.setFixedHeight(32)
                self.connect_button.setText(f"Connect to {nickname}")
                self.connect_button.clicked.connect(
                    lambda: self.parent.go(default_code, grid_settings))
            primary_color = grid_settings.get("color-1")
            if primary_color:
                self.connect_button.setStyleSheet(
                    f"background: {primary_color}; color: white")
            else:
                self.connect_button.setStyleSheet(
                    "background: green; color: white")
        else:
            self.connect_button.hide()

        self.message = QLabel()
        self.message.setStyleSheet("color: red")
        self.message.setAlignment(Qt.AlignCenter)
        self.message.hide()

        self.restore_link = QLabel()
        self.restore_link.setText("<a href>Restore from Recovery Key...</a>")
        self.restore_link.setFont(Font(9))
        self.restore_link.setAlignment(Qt.AlignCenter)

        self.configure_link = QLabel()
        self.configure_link.setText("<a href>Manual configuration...</a>")
        self.configure_link.setFont(Font(9))
        self.configure_link.setAlignment(Qt.AlignCenter)

        self.preferences_button = QPushButton()
        self.preferences_button.setIcon(QIcon(resource("preferences.png")))
        self.preferences_button.setStyleSheet("border: 0px; padding: 0px;")
        self.preferences_button.setToolTip("Preferences...")
        self.preferences_button.setFocusPolicy(Qt.NoFocus)

        links_grid = QGridLayout()
        links_grid.addItem(QSpacerItem(0, 0, 0, QSizePolicy.Expanding), 1, 1)
        links_grid.addWidget(self.restore_link, 2, 1)
        links_grid.addItem(QSpacerItem(0, 0, 0, QSizePolicy.Expanding), 3, 1)
        links_grid.addWidget(self.configure_link, 4, 1)
        links_grid.addItem(QSpacerItem(0, 0, 0, QSizePolicy.Expanding), 5, 1)

        prefs_layout = QGridLayout()
        prefs_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, 0), 1, 1)
        prefs_layout.addWidget(self.preferences_button, 1, 2)

        layout = QGridLayout(self)
        layout.addItem(QSpacerItem(0, 0, 0, QSizePolicy.Expanding), 0, 0)
        layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, 0), 1, 1)
        layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, 0), 1, 2)
        layout.addWidget(self.icon, 1, 3)
        layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, 0), 1, 4)
        layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, 0), 1, 5)
        layout.addWidget(self.slogan, 2, 3)
        layout.addItem(QSpacerItem(0, 0, 0, QSizePolicy.Expanding), 3, 1)
        layout.addWidget(self.invite_code_widget, 4, 2, 1, 3)
        layout.addWidget(self.connect_button, 4, 2, 1, 3)
        layout.addWidget(self.message, 5, 3)
        layout.addItem(QSpacerItem(0, 0, 0, QSizePolicy.Minimum), 6, 1)
        layout.addLayout(links_grid, 7, 3)
        layout.addItem(QSpacerItem(0, 0, 0, QSizePolicy.Minimum), 8, 1)
        layout.addItem(QSpacerItem(0, 0, 0, QSizePolicy.Expanding), 9, 1)
        layout.addLayout(prefs_layout, 10, 1, 1, 5)
Example #4
0
def test_load_settings_from_cheatcode_none(tmpdir_factory, monkeypatch):
    pkgdir = os.path.join(str(tmpdir_factory.getbasetemp()), 'pkgdir-empty')
    monkeypatch.setattr('gridsync.invite.pkgdir', pkgdir)
    assert load_settings_from_cheatcode('test-test') is None