From eec6f88ccd3acad97a858abb6365084a8f257aa4 Mon Sep 17 00:00:00 2001 From: mirkobrombin Date: Sat, 11 Mar 2023 22:02:27 +0100 Subject: [PATCH] add hostname view also set the new-user-only flag in the user section --- debian/vanilla-first-setup.substvars | 2 + recipe.json | 7 +- vanilla_first_setup/defaults/hostname.py | 90 +++++++++++++++++++ vanilla_first_setup/defaults/meson.build | 1 + vanilla_first_setup/gtk/default-hostname.ui | 45 ++++++++++ vanilla_first_setup/utils/builder.py | 2 + .../vanilla-first-setup.gresource.xml | 1 + 7 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 debian/vanilla-first-setup.substvars create mode 100644 vanilla_first_setup/defaults/hostname.py create mode 100644 vanilla_first_setup/gtk/default-hostname.ui diff --git a/debian/vanilla-first-setup.substvars b/debian/vanilla-first-setup.substvars new file mode 100644 index 0000000..e6b63de --- /dev/null +++ b/debian/vanilla-first-setup.substvars @@ -0,0 +1,2 @@ +misc:Depends=dconf-gsettings-backend | gsettings-backend +misc:Pre-Depends= diff --git a/recipe.json b/recipe.json index 53df8c0..85d5436 100644 --- a/recipe.json +++ b/recipe.json @@ -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", diff --git a/vanilla_first_setup/defaults/hostname.py b/vanilla_first_setup/defaults/hostname.py new file mode 100644 index 0000000..71c2b55 --- /dev/null +++ b/vanilla_first_setup/defaults/hostname.py @@ -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 . + +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}(? + + + + diff --git a/vanilla_first_setup/utils/builder.py b/vanilla_first_setup/utils/builder.py index e02d932..6e5dc4f 100644 --- a/vanilla_first_setup/utils/builder.py +++ b/vanilla_first_setup/utils/builder.py @@ -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 diff --git a/vanilla_first_setup/vanilla-first-setup.gresource.xml b/vanilla_first_setup/vanilla-first-setup.gresource.xml index 7cbad4b..64e94fd 100644 --- a/vanilla_first_setup/vanilla-first-setup.gresource.xml +++ b/vanilla_first_setup/vanilla-first-setup.gresource.xml @@ -12,6 +12,7 @@ gtk/default-theme.ui gtk/default-welcome.ui gtk/default-user.ui + gtk/default-hostname.ui gtk/layout-preferences.ui gtk/layout-yes-no.ui