Compare commits

...

3 Commits

Author SHA1 Message Date
Benjamin Drieu d51f470428 Apply eslinst recommandations 2022-05-30 17:16:27 +02:00
Benjamin Drieu d7263f491b Implement show all feature 2022-05-30 11:27:27 +02:00
Benjamin Drieu 4e21919d2e Implement GTK+3/4 compatibility 2022-05-30 11:27:11 +02:00
3 changed files with 132 additions and 58 deletions

View File

@ -24,29 +24,24 @@
const GETTEXT_DOMAIN = 'monito'; const GETTEXT_DOMAIN = 'monito';
let _httpSession;
let _status; let _status;
let _ok_text;
const ExtensionUtils = imports.misc.extensionUtils; const ExtensionUtils = imports.misc.extensionUtils; // eslint-disable-line no-undef
const Lang = imports.lang; const Lang = imports.lang; // eslint-disable-line no-undef
const Main = imports.ui.main; const Main = imports.ui.main; // eslint-disable-line no-undef
const Mainloop = imports.mainloop; const Mainloop = imports.mainloop; // eslint-disable-line no-undef
const Me = ExtensionUtils.getCurrentExtension(); const Me = ExtensionUtils.getCurrentExtension(); // eslint-disable-line no-undef
const PanelMenu = imports.ui.panelMenu; const PanelMenu = imports.ui.panelMenu; // eslint-disable-line no-undef
const PopupMenu = imports.ui.popupMenu; const PopupMenu = imports.ui.popupMenu; // eslint-disable-line no-undef
const Gettext = imports.gettext.domain(GETTEXT_DOMAIN); const Gettext = imports.gettext.domain(GETTEXT_DOMAIN); // eslint-disable-line no-undef
const _ = Gettext.gettext; const _ = Gettext.gettext;
const { GObject, St, Clutter, Gio, GLib, Pango } = imports.gi; const { GObject, St, Clutter, Gio, GLib, Pango } = imports.gi; // eslint-disable-line no-undef
const SETTINGS_SCHEMA = "org.gnome.shell.extensions.monito"; const SETTINGS_SCHEMA = "org.gnome.shell.extensions.monito";
const SETTINGS_SCHEMA_ACCOUNT = "org.gnome.shell.extensions.monito.account";
const SETTINGS_SCHEMA_ACCOUNT_PATH = "/org/gnome/shell/extensions/monito/account";
const Convenience = Me.imports.convenience; const Convenience = Me.imports.convenience;
const GenericServer = Me.imports.servers.genericserver.GenericServer;
const Icinga = Me.imports.servers.icinga.Icinga; const Icinga = Me.imports.servers.icinga.Icinga;
const Icinga2 = Me.imports.servers.icinga2.Icinga2; const Icinga2 = Me.imports.servers.icinga2.Icinga2;
const Icinga2API = Me.imports.servers.icinga2api.Icinga2API; const Icinga2API = Me.imports.servers.icinga2api.Icinga2API;
@ -78,8 +73,9 @@ class Indicator extends PanelMenu.Button {
this.namesBoxes = { }; this.namesBoxes = { };
this.boxes = { }; this.boxes = { };
this.sortIcons = { }; this.sortIcons = { };
this.showAll = false;
account_settings [ server ] = Preferences.getAccountSettings ( this.server ); account_settings [ server ] = Preferences.getAccountSettings ( this.server );
this.account_settings = account_settings [ server ]; this.account_settings = account_settings [ server ];
@ -165,9 +161,11 @@ class Indicator extends PanelMenu.Button {
this._searchField.connect('secondary-icon-clicked', Lang.bind(this, this._onSearchFieldActivate ) ); this._searchField.connect('secondary-icon-clicked', Lang.bind(this, this._onSearchFieldActivate ) );
this._searchField.clutter_text.connect('activate', Lang.bind(this, this._onSearchFieldActivate ) ); this._searchField.clutter_text.connect('activate', Lang.bind(this, this._onSearchFieldActivate ) );
this._searchField.clutter_text.connect('text-changed', Lang.bind(this, this._onSearchFieldActivate ) ); this._searchField.clutter_text.connect('text-changed', Lang.bind(this, this._onSearchFieldActivate ) );
this._buttonMenu.actor.add_child (this._searchField); this._buttonMenu.actor.add_child (this._searchField);
this._showAllButton = this._createButton ( 'big', 'view-reveal-symbolic', _('Show all'), this.changeShowAll, true );
this._buttonMenu.actor.add_child (this._showAllButton );
this._prefsButton = this._createButton ( 'big', 'preferences-system-symbolic', _('Preferences'), this._onPreferencesActivate ); this._prefsButton = this._createButton ( 'big', 'preferences-system-symbolic', _('Preferences'), this._onPreferencesActivate );
this._buttonMenu.actor.add_child (this._prefsButton); this._buttonMenu.actor.add_child (this._prefsButton);
@ -224,6 +222,12 @@ class Indicator extends PanelMenu.Button {
this.serverLogic.recheckAll ( this._recheckButton ); this.serverLogic.recheckAll ( this._recheckButton );
} }
changeShowAll ( )
{
this.showAll = ! this.showAll;
this.refreshUI ( );
}
updateStatus ( ) updateStatus ( )
{ {
this.spinChildOf ( this._reloadButton ); this.spinChildOf ( this._reloadButton );
@ -446,7 +450,8 @@ class Indicator extends PanelMenu.Button {
entry [ 'status_information' ].toLowerCase().includes ( this._searchString ) ) ) entry [ 'status_information' ].toLowerCase().includes ( this._searchString ) ) )
continue; continue;
if ( ( ! _status [ 'WARNING' ] && ! _status [ 'CRITICAL' ] && ! _status [ 'UNKNOWN' ] && entry.status == 'OK' ) || if ( this.showAll ||
( ! _status [ 'WARNING' ] && ! _status [ 'CRITICAL' ] && ! _status [ 'UNKNOWN' ] && entry.status == 'OK' ) ||
( ( _status [ 'WARNING' ] || _status [ 'CRITICAL' ] || _status [ 'UNKNOWN' ] ) && entry.status != 'OK' ) ) ( ( _status [ 'WARNING' ] || _status [ 'CRITICAL' ] || _status [ 'UNKNOWN' ] ) && entry.status != 'OK' ) )
{ {
let _style = this.getStyleForRow ( entry.status.toLowerCase(), _row ); let _style = this.getStyleForRow ( entry.status.toLowerCase(), _row );
@ -472,11 +477,11 @@ class Indicator extends PanelMenu.Button {
this.account_settings.get_string ( 'service-replace' ) ); this.account_settings.get_string ( 'service-replace' ) );
else if ( _col == 'status_information' && this.account_settings.get_string ( 'status-info-match' ) ) else if ( _col == 'status_information' && this.account_settings.get_string ( 'status-info-match' ) )
entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'status-info-match' ), 'i' ), entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'status-info-match' ), 'i' ),
this.account_settings.get_string ( 'status-info-replace' ) ) . replace ( new RegExp ( "\n.*" ), "" ); this.account_settings.get_string ( 'status-info-replace' ) ) . replace ( new RegExp ( "\\n.*" ), "" );
else if ( _col == 'has_been_acknowledged' ) else if ( _col == 'has_been_acknowledged' )
{ {
if ( entry [ _col ] ) if ( entry [ _col ] )
entry [ _col ] = '✔'; // … or ✅🗹 ? entry [ _col ] = '✔';
else else
entry [ _col ] = ''; entry [ _col ] = '';
} }
@ -540,7 +545,7 @@ class Indicator extends PanelMenu.Button {
if (typeof ExtensionUtils.openPrefs === 'function') { if (typeof ExtensionUtils.openPrefs === 'function') {
ExtensionUtils.openPrefs(); ExtensionUtils.openPrefs();
} else { } else {
Util.spawn([ ExtensionUtils.spawn([
"gnome-shell-extension-prefs", "gnome-shell-extension-prefs",
Me.uuid Me.uuid
]); ]);
@ -550,7 +555,6 @@ class Indicator extends PanelMenu.Button {
_onSortColumnClick ( button ) { _onSortColumnClick ( button ) {
let _sortOrder = Preferences.getSortOrder ( this.server ); let _sortOrder = Preferences.getSortOrder ( this.server );
let _columns = Preferences.getColumns ( this.server );
let _indexPlus = _sortOrder.indexOf ( button.column + '+' ); let _indexPlus = _sortOrder.indexOf ( button.column + '+' );
let _indexMinus = _sortOrder.indexOf ( button.column + '-' ); let _indexMinus = _sortOrder.indexOf ( button.column + '-' );
@ -577,7 +581,7 @@ class Indicator extends PanelMenu.Button {
_onExpandLabel ( e ) _onExpandLabel ( e )
{ {
log ( "Monito: Click label " + e.original_text ); monitoLog ( "Monito: Click label " + e.original_text );
let temp = e.text; let temp = e.text;
e.text = e.original_text; e.text = e.original_text;
e.original_text = temp; e.original_text = temp;
@ -617,22 +621,22 @@ class Indicator extends PanelMenu.Button {
try { try {
proc.wait_finish(result); proc.wait_finish(result);
if ( ! proc.get_successful()) { if ( ! proc.get_successful()) {
log ( 'Monito: the process failed' ); monitoLog ( 'Monito: the process failed' );
} }
} catch (e) { } catch (e) {
logError(e); monitoLog(e);
} finally { } finally {
loop.quit(); loop.quit();
} }
}); });
} catch ( e ) { } catch ( e ) {
log ( 'Monito err: ' + e.message ); monitoLog ( 'Monito err: ' + e.message );
Main.notifyError ( _('Unable to execute command: %s').format ( e.message ) ); Main.notifyError ( _('Unable to execute command: %s').format ( e.message ) );
} }
this.stopChildSpin ( e.service.button ); this.stopChildSpin ( e.service.button );
} }
_createButton ( sizeName, icon, data, callback ) { _createButton ( sizeName, icon, data, callback, radiobutton = false ) {
let size = 24; let size = 24;
if ( sizeName == 'small' ) if ( sizeName == 'small' )
size = 24; size = 24;
@ -640,7 +644,7 @@ class Indicator extends PanelMenu.Button {
size = 32; size = 32;
let _text = ''; let _text = '';
if ( ! data instanceof Object ) if ( ! ( data instanceof Object ) )
_text = data; _text = data;
let button = new St.Button({ let button = new St.Button({
@ -657,6 +661,12 @@ class Indicator extends PanelMenu.Button {
}); });
button.prevIcon = icon; button.prevIcon = icon;
if ( radiobutton )
{
button.toggle_mode = true;
button.set_checked ( true );
}
if ( data instanceof Object ) if ( data instanceof Object )
button.service = data; button.service = data;
@ -679,7 +689,7 @@ class Extension {
constructor(uuid) { constructor(uuid) {
this._uuid = uuid; this._uuid = uuid;
settings.connect("changed::servers", Lang.bind ( this, function(stgs, key) { this._connectId = settings.connect("changed::servers", Lang.bind ( this, function() {
this.disable ( ); this.disable ( );
this.enable ( ); this.enable ( );
} ) ); } ) );
@ -707,19 +717,24 @@ class Extension {
this._indicators[i].cancelTimeout(); this._indicators[i].cancelTimeout();
this._indicators[i].destroy(); this._indicators[i].destroy();
} }
if ( this._connectId )
{
settings.disconnect( this._connectId );
this._connectId = null;
}
this._indicators = { }; this._indicators = { };
} }
} }
function init(meta) { function init(meta) { // eslint-disable-line no-unused-vars
return new Extension(meta.uuid); return new Extension(meta.uuid);
} }
function monitoLog ( msg ) function monitoLog ( msg )
{ {
log ( 'Monito: ' + msg ); log ( 'Monito: ' + msg ); // eslint-disable-line no-undef
} }

107
prefs.js
View File

@ -83,6 +83,8 @@ const prefs = [
function init() { function init() {
monitoLog('initializing ${Me.metadata.name} Preferences'); monitoLog('initializing ${Me.metadata.name} Preferences');
this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA); this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA);
this.gtkVersion = Gtk.get_major_version();
} }
@ -93,17 +95,21 @@ function buildPrefsWidget() {
// Copy the same GSettings code from `extension.js` // Copy the same GSettings code from `extension.js`
this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA); this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA);
this._columnsStores = { };
let mainVbox = new Gtk.Box( { orientation: Gtk.Orientation.VERTICAL } ); let mainVbox = new Gtk.Box( { orientation: Gtk.Orientation.VERTICAL } );
let mainWidget = new Gtk.Notebook( { } ); let mainWidget = new Gtk.Notebook( { } );
let prefsWidget = new Gtk.Grid({ let prefsWidget = new Gtk.Grid({
// margin: 18,
column_spacing: 12, column_spacing: 12,
row_spacing: 12, row_spacing: 12,
column_homogeneous: false, column_homogeneous: false,
}); });
if ( this.gtkVersion < 4 )
prefsWidget.margin = 18;
this.prefWidgets = { }; this.prefWidgets = { };
// Add a simple title and add it to the prefsWidget // Add a simple title and add it to the prefsWidget
@ -165,12 +171,18 @@ function buildPrefsWidget() {
homogeneous: false, } ); homogeneous: false, } );
monitoLog ( 'Box ' + this._accountsWidgetContainer ); monitoLog ( 'Box ' + this._accountsWidgetContainer );
monitoLog ( 'Func ' + this._accountsWidgetContainer.pack_start ); monitoLog ( 'Func ' + this._accountsWidgetContainer.pack_start );
this._accountsWidgetContainer.append(accountsChooserContainer, true, true, 0); if ( this.gtkVersion == 4 )
this._accountsWidgetContainer.append(accountsChooserContainer, true, true, 0);
else
this._accountsWidgetContainer.add(accountsChooserContainer, true, true, 0);
this.accountsChooser = new Gtk.ListBox ( { valign: Gtk.Align.FILL, this.accountsChooser = new Gtk.ListBox ( { valign: Gtk.Align.FILL,
hexpand: true, hexpand: true,
vexpand: true } ); vexpand: true } );
accountsChooserContainer.append(this.accountsChooser, true, true, 0); if ( this.gtkVersion == 4 )
accountsChooserContainer.append(this.accountsChooser, true, true, 0);
else
accountsChooserContainer.add(this.accountsChooser, true, true, 0);
// Account list // Account list
for ( var server_id of this.getServersList ( ) ) for ( var server_id of this.getServersList ( ) )
@ -179,7 +191,10 @@ function buildPrefsWidget() {
// Action Bar // Action Bar
let accountsChooserActionBar = new Gtk.ActionBar ( { valign: Gtk.Align.END } ); let accountsChooserActionBar = new Gtk.ActionBar ( { valign: Gtk.Align.END } );
accountsChooserContainer.append(accountsChooserActionBar, true, true, 0); if ( this.gtkVersion == 4 )
accountsChooserContainer.append(accountsChooserActionBar, true, true, 0);
else
accountsChooserContainer.add(accountsChooserActionBar, true, true, 0);
let accountCreateButton = Gtk.Button.new_from_icon_name ( 'list-add', let accountCreateButton = Gtk.Button.new_from_icon_name ( 'list-add',
Gtk.IconSize.BUTTON ); Gtk.IconSize.BUTTON );
@ -193,7 +208,10 @@ function buildPrefsWidget() {
this.createAccountWidgets ( false ) ; this.createAccountWidgets ( false ) ;
mainVbox.append(mainWidget, true, true, 0); if ( this.gtkVersion == 4 )
mainVbox.append(mainWidget, true, true, 0);
else
mainVbox.add(mainWidget);
mainVbox.show_all(); mainVbox.show_all();
return mainVbox; return mainVbox;
@ -245,7 +263,10 @@ function createAccountWidgets ( isActive )
this.prefWidgets = { }; this.prefWidgets = { };
this._accountsWidget = new Gtk.Notebook( { } ); this._accountsWidget = new Gtk.Notebook( { } );
this._accountsWidgetContainer.append(this._accountsWidget, true, true, 0); if ( this.gtkVersion == 4 )
this._accountsWidgetContainer.append(this._accountsWidget, true, true, 0);
else
this._accountsWidgetContainer.add(this._accountsWidget);
for ( var _tab of [ 'Settings', 'Columns', 'Colors', 'Filters', 'Replacements' ] ) for ( var _tab of [ 'Settings', 'Columns', 'Colors', 'Filters', 'Replacements' ] )
{ {
@ -276,6 +297,8 @@ function createPrefWidgets ( noteBook, type, isActive )
visible: true, visible: true,
column_homogeneous: false, column_homogeneous: false,
}); });
if ( this.gtkVersion < 4 )
grid.margin = 18;
noteBook.append_page ( grid, new Gtk.Label ( { label: _(type), } ) ); noteBook.append_page ( grid, new Gtk.Label ( { label: _(type), } ) );
let y = 0; let y = 0;
@ -340,42 +363,52 @@ function createColumnsPrefTab ( noteBook, type, isActive )
visible: true, visible: true,
column_homogeneous: false, column_homogeneous: false,
}); });
if ( this.gtkVersion < 4 )
grid.margin = 18;
noteBook.append_page ( grid, new Gtk.Label ( { label: _(type), } ) ); noteBook.append_page ( grid, new Gtk.Label ( { label: _(type), } ) );
let _store = new Gtk.TreeStore(); let _treeView = new Gtk.TreeView ( { headers_visible: true,
_store.set_column_types([GObject.TYPE_STRING, GObject.TYPE_INT]);
_store.filter_new(null);
let _treeView = new Gtk.TreeView ( { model: _store,
headers_visible: true,
reorderable: true, reorderable: true,
hexpand: true, hexpand: true,
vexpand: true }); vexpand: true });
let columnNumbers = new Gtk.TreeViewColumn ( { title: _("Column") } ); let columnNumbers = new Gtk.TreeViewColumn ( { title: _("Column") } );
let rendererNumbers = new Gtk.CellRendererText ( { editable: true } ); let rendererNumbers = new Gtk.CellRendererText ( { editable: true } );
columnNumbers.append(rendererNumbers, true); if ( this.gtkVersion == 4 )
columnNumbers.append(rendererNumbers, true);
else
columnNumbers.pack_start(rendererNumbers, true);
columnNumbers.add_attribute(rendererNumbers, 'text', 0); columnNumbers.add_attribute(rendererNumbers, 'text', 0);
_treeView.append_column(columnNumbers); _treeView.append_column(columnNumbers);
let _colSize = new Gtk.TreeViewColumn ( { title: _("Size") } ); let _colSize = new Gtk.TreeViewColumn ( { title: _("Size") } );
let _colRenderer = new Gtk.CellRendererText ( { editable: true } ); let _colRenderer = new Gtk.CellRendererText ( { editable: true } );
_colSize.append(_colRenderer, true); if ( this.gtkVersion == 4 )
_colSize.append(_colRenderer, true);
else
_colSize.pack_start(_colRenderer, true);
_colSize.add_attribute(_colRenderer, 'text', 1); _colSize.add_attribute(_colRenderer, 'text', 1);
_treeView.append_column(_colSize); _treeView.append_column(_colSize);
let _item = _store.append(null);
_store.set_value(_item, 0, 'prout' );
_store.set_value(_item, 1, 2 );
_item = _store.append(null);
_store.set_value(_item, 0, 'bar' );
_store.set_value(_item, 1, 1 );
// _treeView.connect('row-activated', this._editPath.bind(this)); // _treeView.connect('row-activated', this._editPath.bind(this));
grid.attach ( _treeView, 0, 1, 1, 1 ); grid.attach ( _treeView, 0, 1, 1, 1 );
// Action Bar
let rowsChooserActionBar = new Gtk.ActionBar ( { valign: Gtk.Align.END } );
let rowCreateButton = Gtk.Button.new_from_icon_name ( 'list-add',
Gtk.IconSize.BUTTON );
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 );
rowRemoveButton.connect ( 'clicked', Lang.bind ( this, this.removeColumnRow ) );
grid.attach ( columnsChooserActionBar, 0, 2, 1, 1 );
} }
@ -446,9 +479,18 @@ function addAccountLine ( server_id )
hexpand: true, hexpand: true,
// margin: 5, // margin: 5,
halign: Gtk.Align.START } ); halign: Gtk.Align.START } );
row.set_child ( _label ); if ( this.gtkVersion == 4 )
this.accountsChooser.append ( row ); {
this.accountsChooser.show_all(); // XXX Does not work in gtk4 ? row.set_child ( _label );
this.accountsChooser.append ( row );
}
else
{
_label.margin = 5;
row.add ( _label );
this.accountsChooser.add ( row );
this.accountsChooser.show_all();
}
} }
@ -496,6 +538,21 @@ function setColor ( color )
} }
function createColumnRow ( ) {
monitoLog ( '> Create column row' );
_item = _store.append(null);
_store.set_value(_item, 0, 'bar' );
_store.set_value(_item, 1, 1 );
}
function removeColumnRow ( ) {
monitoLog ( '> Remove column row' );
}
function monitoLog ( msg ) function monitoLog ( msg )
{ {
log ( 'Monito: ' + msg ); log ( 'Monito: ' + msg );

View File

@ -48,9 +48,11 @@ class Icinga extends GenericServer {
super.prepareHttp ( ); super.prepareHttp ( );
let message = Soup.form_request_new_from_hash ( 'GET', this.urlcgi, { 'jsonoutput': '' } ); let message = Soup.form_request_new_from_hash ( 'GET', this.urlcgi, { 'jsonoutput': '' } );
message.request_headers.append ( 'Accept', 'application/json' ); if ( message )
{
this.authenticateAndSend ( message ); message.request_headers.append ( 'Accept', 'application/json' );
this.authenticateAndSend ( message );
}
} }
recheck ( entry ) recheck ( entry )