Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set hostname #113

Merged
merged 23 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d9d2a39
Add SystemView
meisenzahl Aug 7, 2021
d40906c
Set previous view
meisenzahl Aug 7, 2021
755a525
Set hostname
meisenzahl Aug 7, 2021
cbfc247
Add SystemView to POTFILES
meisenzahl Aug 7, 2021
8e96561
Read hostname from D-Bus interface
meisenzahl Aug 8, 2021
3c023e3
AccountView: Set hostname
meisenzahl Aug 8, 2021
e0bc9bb
AccountView: Increase spacing to hostname
meisenzahl Aug 9, 2021
4d5b3f4
Utils: set static hostname
meisenzahl Aug 9, 2021
188a30e
Utils: Set pretty hostname and generate valid static hostname
meisenzahl Aug 9, 2021
be5e553
AccountView: Validate hostname
meisenzahl Aug 10, 2021
87c6411
Utils: Show dialog on error
meisenzahl Aug 10, 2021
cb5e6b7
Merge branch 'master' into set-hostname
cassidyjames Aug 12, 2021
90f45bb
Merge branch 'master' into set-hostname
meisenzahl Aug 12, 2021
5d18695
AccountView: Set hostname after entry is mapped
meisenzahl Aug 12, 2021
3a05e6c
AccountView: Check if hostname is valid to finish setup
meisenzahl Aug 12, 2021
40de890
Merge branch 'set-hostname' of github.com:elementary/initial-setup in…
meisenzahl Aug 12, 2021
c4cafdc
Update 49-io.elementary.initial-setup.pkla
danirabbit Aug 12, 2021
420d53b
Update io.elementary.initial-setup.appdata.xml.in
danirabbit Aug 12, 2021
91b5627
Update 49-io.elementary.initial-setup.pkla
danirabbit Aug 12, 2021
86490cb
Update Utils.vala
danirabbit Aug 12, 2021
9f97092
Apply suggestions from code review
meisenzahl Aug 12, 2021
7dbfc16
Merge branch 'master' into set-hostname
cassidyjames Aug 16, 2021
1211371
Update io.elementary.initial-setup.appdata.xml.in
cassidyjames Aug 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,44 @@ namespace Utils {

return username;
}

[DBus (name = "org.freedesktop.hostname1")]
interface HostnameInterface : Object {
public abstract string static_hostname { owned get; }

public abstract void set_static_hostname (string hostname, bool interactive) throws GLib.Error;
}

private static HostnameInterface? hostname_interface_instance;
private static void get_hostname_interface_instance () {
if (hostname_interface_instance == null) {
try {
hostname_interface_instance = Bus.get_proxy_sync (
BusType.SYSTEM,
"org.freedesktop.hostname1",
"/org/freedesktop/hostname1"
);
} catch (GLib.Error e) {
warning ("%s", e.message);
}
}
}

public static string get_hostname () {
get_hostname_interface_instance ();

return hostname_interface_instance.static_hostname;
}

public static bool set_hostname (string hostname) {
try {
get_hostname_interface_instance ();
hostname_interface_instance.set_static_hostname (hostname, false);
} catch (GLib.Error e) {
warning ("Could not set hostname: %s", e.message);
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

return true;
}
}
22 changes: 22 additions & 0 deletions src/Views/AccountView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ public class Installer.AccountView : AbstractInstallerView {
confirm_entry_revealer = new ErrorRevealer (".");
confirm_entry_revealer.label_widget.get_style_context ().add_class (Gtk.STYLE_CLASS_ERROR);

var hostname_label = new Granite.HeaderLabel (_("Device name")) {
margin_top = 16
};

var hostname_entry = new Gtk.Entry () {
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
hexpand = true,
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
text = Utils.get_hostname ()
};

var hostname_info = new Gtk.Label (_("Visible to other devices when sharing, e.g. with Bluetooth or over the network.")) {
max_width_chars = 60,
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
margin_bottom = 18,
wrap = true,
xalign = 0
};
hostname_info.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);

var form_grid = new Gtk.Grid ();
form_grid.row_spacing = 3;
form_grid.valign = Gtk.Align.CENTER;
Expand All @@ -91,6 +108,9 @@ public class Installer.AccountView : AbstractInstallerView {
form_grid.attach (confirm_label, 0, 10, 1, 1);
form_grid.attach (confirm_entry, 0, 11, 1, 1);
form_grid.attach (confirm_entry_revealer, 0, 12, 1, 1);
form_grid.attach (hostname_label, 0, 13, 1, 1);
form_grid.attach (hostname_entry, 0, 14, 1, 1);
form_grid.attach (hostname_info, 0, 15, 1, 1);

content_area.attach (avatar, 0, 0);
content_area.attach (title_label, 0, 1, 1, 1);
Expand Down Expand Up @@ -136,6 +156,8 @@ public class Installer.AccountView : AbstractInstallerView {

created = Utils.create_new_user (fullname, username, password);

Utils.set_hostname (hostname_entry.text);

next_step ();
});

Expand Down