From 6e83fc331b8efd4860e14096bd8a1ffbbcab1c76 Mon Sep 17 00:00:00 2001 From: Benjamin Drieu Date: Tue, 28 Mar 2023 21:21:49 +0200 Subject: [PATCH] Port to GTK4 & Gnome-Shell 42 --- metadata.json | 2 +- prefs.js | 57 ++++++++++++++++++++++++++-------------- servers/genericserver.js | 2 +- servers/icinga.js | 2 +- servers/icinga2.js | 2 +- servers/icinga2api.js | 2 +- 6 files changed, 42 insertions(+), 25 deletions(-) diff --git a/metadata.json b/metadata.json index 7dfcff8..2480bd5 100644 --- a/metadata.json +++ b/metadata.json @@ -3,6 +3,6 @@ "description": "Checks for various monitoring servers (Icinga & Icinga2 at the moment)", "uuid": "monito@drieu.org", "shell-version": [ - "40" + "42" ] } diff --git a/prefs.js b/prefs.js index 7bfbb7f..879f771 100644 --- a/prefs.js +++ b/prefs.js @@ -100,6 +100,7 @@ function init() { this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA); this.gtkVersion = Gtk.get_major_version(); + monitoLog ( 'GTK version is ' + this.gtkVersion ); } @@ -204,28 +205,27 @@ function buildPrefsWidget() { // Action Bar let accountsChooserActionBar = new Gtk.ActionBar ( { valign: Gtk.Align.END } ); - if ( this.gtkVersion == 4 ) - accountsChooserContainer.append(accountsChooserActionBar, true, true, 0); - else - accountsChooserContainer.add(accountsChooserActionBar); + this.addToContainer ( accountsChooserContainer, accountsChooserActionBar ); let accountCreateButton = Gtk.Button.new_from_icon_name ( 'list-add', Gtk.IconSize.BUTTON ); - accountsChooserActionBar.add ( accountCreateButton ); + accountsChooserActionBar.pack_start(accountCreateButton, true); + //this.addToContainer ( accountsChooserActionBar, accountCreateButton ); accountCreateButton.connect ( 'clicked', Lang.bind ( this, this.createAccount ) ); let accountRemoveButton = Gtk.Button.new_from_icon_name ( 'list-remove', Gtk.IconSize.BUTTON ); - accountsChooserActionBar.add ( accountRemoveButton ); + accountsChooserActionBar.pack_start(accountRemoveButton, true); +// this.addToContainer ( accountsChooserActionBar, accountRemoveButton ); accountRemoveButton.connect ( 'clicked', Lang.bind ( this, this.removeAccount ) ); this.createAccountWidgets ( false ) ; + this.addToContainer ( mainVbox, mainWidget ); if ( this.gtkVersion == 4 ) - mainVbox.append(mainWidget, true, true, 0); + mainVbox.set_visible(true); else - mainVbox.add(mainWidget); - mainVbox.show_all(); + mainVbox.show_all(); return mainVbox; } @@ -300,7 +300,10 @@ function createAccountWidgets ( isActive ) } ) ); - this._accountsWidget.show_all(); + if ( this.gtkVersion == 4 ) + this._accountsWidget.set_visible(true); + else + this._accountsWidget.show_all(); } @@ -396,9 +399,9 @@ function createColumnsPrefTab ( noteBook, type, isActive ) this.ColumnNameRenderer.connect("edited", onComboChanged) this.ColumnNameRenderer.col = 0; if ( this.gtkVersion == 4 ) - columnNumbers.append(this.ColumnNameRenderer, true); - else columnNumbers.pack_start(this.ColumnNameRenderer, true); + else + columnNumbers.append(this.ColumnNameRenderer, true); columnNumbers.add_attribute(this.ColumnNameRenderer, 'text', 0); this.treeView.append_column(columnNumbers); this.ColumnNameRenderer.connect('edited', Lang.bind ( this, this.editColumn ) ); @@ -406,10 +409,10 @@ function createColumnsPrefTab ( noteBook, type, isActive ) let _colSize = new Gtk.TreeViewColumn ( { title: _("Size") } ); let _colRenderer = new Gtk.CellRendererSpin ( { adjustment: new Gtk.Adjustment ( { lower: 0, upper: 999, step_increment: 1, page_increment: 10 } ), editable: true } ); - if ( this.gtkVersion == 4 ) - _colSize.append(_colRenderer, true); - else - _colSize.pack_start(_colRenderer, true); +// if ( this.gtkVersion == 4 ) +// _colSize.append(_colRenderer, true); +// else + _colSize.pack_start(_colRenderer, true); _colSize.add_attribute(_colRenderer, 'text', 1); this.treeView.append_column(_colSize); _colRenderer.col = 1; @@ -424,12 +427,14 @@ function createColumnsPrefTab ( noteBook, type, isActive ) let rowCreateButton = Gtk.Button.new_from_icon_name ( 'list-add', Gtk.IconSize.BUTTON ); - rowsChooserActionBar.add ( rowCreateButton ); + rowsChooserActionBar.pack_start(rowCreateButton, true); +// rowsChooserActionBar.add ( rowCreateButton ); rowCreateButton.connect ( 'clicked', Lang.bind ( this, this.createColumnRow ) ); let rowRemoveButton = Gtk.Button.new_from_icon_name ( 'list-remove', Gtk.IconSize.BUTTON ); - rowsChooserActionBar.add ( rowRemoveButton ); + rowsChooserActionBar.pack_start(rowRemoveButton, true); +// rowsChooserActionBar.add ( rowRemoveButton ); rowRemoveButton.connect ( 'clicked', Lang.bind ( this, this.removeColumnRow ) ); grid.attach ( rowsChooserActionBar, 0, 2, 1, 1 ); @@ -448,7 +453,7 @@ function onComboChanged(widget, path, text) function activateAccountRow ( ) { if ( this._accountsWidget ) - this._accountsWidget.destroy ( ); + this._accountsWidgetContainer.remove ( this._accountsWidget ); this.createAccountWidgets ( true ); this.store = new Gtk.ListStore(); @@ -543,7 +548,10 @@ function addAccountLine ( server_id ) _label.margin = 5; row.add ( _label ); this.accountsChooser.add ( row ); - this.accountsChooser.show_all(); + if ( this.gtkVersion >= 4 ) + this.accountsChooser.set_visible(true); + else + this.accountsChooser.show_all(); } } @@ -660,6 +668,15 @@ function editColumn ( widget, path, text ) } +function addToContainer ( parent, child ) +{ + if ( this.gtkVersion == 4 ) + parent.append(child, true, true, 0); + else + parent.add(child); +} + + function monitoLog ( msg ) { log ( 'Monito: ' + msg ); diff --git a/servers/genericserver.js b/servers/genericserver.js index 2acceff..8e52ccf 100644 --- a/servers/genericserver.js +++ b/servers/genericserver.js @@ -29,7 +29,7 @@ const Me = ExtensionUtils.getCurrentExtension(); const Preferences = Me.imports.prefs; -class GenericServer { +var GenericServer = class { constructor ( _server, _extension, _serverType = 'Generic' ) { diff --git a/servers/icinga.js b/servers/icinga.js index e6c163d..5ef991b 100644 --- a/servers/icinga.js +++ b/servers/icinga.js @@ -32,7 +32,7 @@ const GenericServer = Me.imports.servers.genericserver.GenericServer; let _httpSession; -class Icinga extends GenericServer { +var Icinga = class extends GenericServer { constructor ( _server, extension ) { super(_server, extension, 'Icinga'); } diff --git a/servers/icinga2.js b/servers/icinga2.js index e07d8f0..b9795f9 100644 --- a/servers/icinga2.js +++ b/servers/icinga2.js @@ -30,7 +30,7 @@ const Preferences = Me.imports.prefs; const GenericServer = Me.imports.servers.genericserver.GenericServer; -class Icinga2 extends GenericServer { +var Icinga2 = class extends GenericServer { constructor ( _server, extension ) { super(_server, extension, 'Icinga2'); diff --git a/servers/icinga2api.js b/servers/icinga2api.js index 34e4d97..7be0ea4 100644 --- a/servers/icinga2api.js +++ b/servers/icinga2api.js @@ -30,7 +30,7 @@ const Preferences = Me.imports.prefs; const GenericServer = Me.imports.servers.genericserver.GenericServer; -class Icinga2API extends GenericServer { +var Icinga2API = class extends GenericServer { constructor ( _server, extension ) { super(_server, extension, 'Icinga2 API');