add hostname view

also set the new-user-only flag in the user section
main
mirkobrombin 2 years ago
parent e2c80ac5ea
commit eec6f88ccd

@ -0,0 +1,2 @@
misc:Depends=dconf-gsettings-backend | gsettings-backend
misc:Pre-Depends=

@ -51,7 +51,12 @@
"template": "theme"
},
"user": {
"template": "user"
"template": "user",
"new-user-only": true
},
"hostname": {
"template": "hostname",
"new-user-only": true
},
"packages": {
"template": "preferences",

@ -0,0 +1,90 @@
# hostname.py
#
# Copyright 2022 mirkobrombin
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundationat version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import time
import re, subprocess, shutil
from gi.repository import Gtk, Gio, GLib, Adw
@Gtk.Template(resource_path='/io/github/vanilla-os/FirstSetup/gtk/default-hostname.ui')
class VanillaDefaultHostname(Adw.Bin):
__gtype_name__ = 'VanillaDefaultHostname'
btn_next = Gtk.Template.Child()
hostname_entry = Gtk.Template.Child()
hostname = ""
def __init__(self, window, distro_info, key, step, **kwargs):
super().__init__(**kwargs)
self.__window = window
self.__distro_info = distro_info
self.__key = key
self.__step = step
self.__verify_continue()
# signals
self.btn_next.connect("clicked", self.__on_btn_next_clicked)
self.hostname_entry.connect('changed', self.__on_hostname_entry_changed)
@property
def step_id(self):
return self.__key
def __on_btn_next_clicked(self, widget):
self.__window.next()
def get_finals(self):
return {
"vars": {
"create": True
},
"funcs": [
{
"if": "create",
"type": "command",
"commands": [
"hostnamectl set-hostname " + self.hostname
]
}
]
}
def __on_hostname_entry_changed(self, *args):
_hostname = self.hostname_entry.get_text()
if self.__validate_hostname(_hostname):
self.hostname = _hostname
self.hostname_entry.remove_css_class('error')
self.__verify_continue()
return
self.__window.toast("Hostname cannot contain special characters. Please choose another hostname.")
self.hostname_entry.add_css_class('error')
self.hostname = ""
self.__verify_continue()
def __validate_hostname(self, hostname):
if len(hostname) > 50:
return False
allowed = re.compile("(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE)
return all(allowed.match(x) for x in hostname.split("."))
def __verify_continue(self):
self.btn_next.set_sensitive(self.hostname != "")

@ -6,6 +6,7 @@ sources = [
'welcome.py',
'theme.py',
'user.py',
'hostname.py',
'applications.py',
'conn_check.py'
]

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<template class="VanillaDefaultHostname" parent="AdwBin">
<property name="halign">fill</property>
<property name="valign">center</property>
<property name="hexpand">true</property>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="AdwStatusPage" id="status_page">
<property name="icon-name">computer-symbolicz</property>
<property name="title" translatable="true">Device Details</property>
<property name="description" translatable="true">Provide details about your device</property>
<child>
<object class="AdwPreferencesPage">
<child>
<object class="AdwPreferencesGroup">
<child>
<object class="AdwEntryRow" id="hostname_entry">
<property name="title" translatable="true">Device Name</property>
<property name="input-purpose">name</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton" id="btn_next">
<property name="halign">center</property>
<property name="label" translatable="true">Next</property>
<style>
<class name="pill"/>
<class name="suggested-action"/>
</style>
</object>
</child>
</object>
</child>
</template>
</interface>

@ -25,6 +25,7 @@ from vanilla_first_setup.defaults.conn_check import VanillaDefaultConnCheck
from vanilla_first_setup.defaults.welcome import VanillaDefaultWelcome
from vanilla_first_setup.defaults.theme import VanillaDefaultTheme
from vanilla_first_setup.defaults.user import VanillaDefaultUser
from vanilla_first_setup.defaults.hostname import VanillaDefaultHostname
from vanilla_first_setup.layouts.preferences import VanillaLayoutPreferences
from vanilla_first_setup.layouts.yes_no import VanillaLayoutYesNo
@ -39,6 +40,7 @@ templates = {
"welcome": VanillaDefaultWelcome,
"theme": VanillaDefaultTheme,
"user": VanillaDefaultUser,
"hostname": VanillaDefaultHostname,
"preferences": VanillaLayoutPreferences,
"yes-no": VanillaLayoutYesNo,
"applications": VanillaLayoutApplications

@ -12,6 +12,7 @@
<file>gtk/default-theme.ui</file>
<file>gtk/default-welcome.ui</file>
<file>gtk/default-user.ui</file>
<file>gtk/default-hostname.ui</file>
<file>gtk/layout-preferences.ui</file>
<file>gtk/layout-yes-no.ui</file>

Loading…
Cancel
Save