Port to GTK4 & Gnome-Shell 42

This commit is contained in:
Benjamin Drieu 2023-03-28 21:21:49 +02:00
parent d987193ac6
commit 6e83fc331b
6 changed files with 42 additions and 25 deletions

View File

@ -3,6 +3,6 @@
"description": "Checks for various monitoring servers (Icinga & Icinga2 at the moment)",
"uuid": "monito@drieu.org",
"shell-version": [
"40"
"42"
]
}

View File

@ -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,27 +205,26 @@ 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();
return mainVbox;
@ -300,6 +300,9 @@ function createAccountWidgets ( isActive )
} ) );
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,9 +409,9 @@ 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
// 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);
@ -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,6 +548,9 @@ function addAccountLine ( server_id )
_label.margin = 5;
row.add ( _label );
this.accountsChooser.add ( row );
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 );

View File

@ -29,7 +29,7 @@ const Me = ExtensionUtils.getCurrentExtension();
const Preferences = Me.imports.prefs;
class GenericServer {
var GenericServer = class {
constructor ( _server, _extension, _serverType = 'Generic' )
{

View File

@ -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');
}

View File

@ -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');

View File

@ -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');