Compare commits

..

3 Commits

Author SHA1 Message Date
d51f470428 Apply eslinst recommandations 2022-05-30 17:16:27 +02:00
d7263f491b Implement show all feature 2022-05-30 11:27:27 +02:00
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';
let _httpSession;
let _status;
let _ok_text;
const ExtensionUtils = imports.misc.extensionUtils;
const Lang = imports.lang;
const Main = imports.ui.main;
const Mainloop = imports.mainloop;
const Me = ExtensionUtils.getCurrentExtension();
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const ExtensionUtils = imports.misc.extensionUtils; // eslint-disable-line no-undef
const Lang = imports.lang; // eslint-disable-line no-undef
const Main = imports.ui.main; // eslint-disable-line no-undef
const Mainloop = imports.mainloop; // eslint-disable-line no-undef
const Me = ExtensionUtils.getCurrentExtension(); // eslint-disable-line no-undef
const PanelMenu = imports.ui.panelMenu; // eslint-disable-line no-undef
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 { 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_ACCOUNT = "org.gnome.shell.extensions.monito.account";
const SETTINGS_SCHEMA_ACCOUNT_PATH = "/org/gnome/shell/extensions/monito/account";
const Convenience = Me.imports.convenience;
const GenericServer = Me.imports.servers.genericserver.GenericServer;
const Icinga = Me.imports.servers.icinga.Icinga;
const Icinga2 = Me.imports.servers.icinga2.Icinga2;
const Icinga2API = Me.imports.servers.icinga2api.Icinga2API;
@ -78,8 +73,9 @@ class Indicator extends PanelMenu.Button {
this.namesBoxes = { };
this.boxes = { };
this.sortIcons = { };
this.showAll = false;
account_settings [ server ] = Preferences.getAccountSettings ( this.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.clutter_text.connect('activate', 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._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._buttonMenu.actor.add_child (this._prefsButton);
@ -224,6 +222,12 @@ class Indicator extends PanelMenu.Button {
this.serverLogic.recheckAll ( this._recheckButton );
}
changeShowAll ( )
{
this.showAll = ! this.showAll;
this.refreshUI ( );
}
updateStatus ( )
{
this.spinChildOf ( this._reloadButton );
@ -446,7 +450,8 @@ class Indicator extends PanelMenu.Button {
entry [ 'status_information' ].toLowerCase().includes ( this._searchString ) ) )
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' ) )
{
let _style = this.getStyleForRow ( entry.status.toLowerCase(), _row );
@ -472,11 +477,11 @@ class Indicator extends PanelMenu.Button {
this.account_settings.get_string ( 'service-replace' ) );
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' ),
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' )
{
if ( entry [ _col ] )
entry [ _col ] = '✔'; // … or ✅🗹 ?
entry [ _col ] = '✔';
else
entry [ _col ] = '';
}
@ -540,7 +545,7 @@ class Indicator extends PanelMenu.Button {
if (typeof ExtensionUtils.openPrefs === 'function') {
ExtensionUtils.openPrefs();
} else {
Util.spawn([
ExtensionUtils.spawn([
"gnome-shell-extension-prefs",
Me.uuid
]);
@ -550,7 +555,6 @@ class Indicator extends PanelMenu.Button {
_onSortColumnClick ( button ) {
let _sortOrder = Preferences.getSortOrder ( this.server );
let _columns = Preferences.getColumns ( this.server );
let _indexPlus = _sortOrder.indexOf ( button.column + '+' );
let _indexMinus = _sortOrder.indexOf ( button.column + '-' );
@ -577,7 +581,7 @@ class Indicator extends PanelMenu.Button {
_onExpandLabel ( e )
{
log ( "Monito: Click label " + e.original_text );
monitoLog ( "Monito: Click label " + e.original_text );
let temp = e.text;
e.text = e.original_text;
e.original_text = temp;
@ -617,22 +621,22 @@ class Indicator extends PanelMenu.Button {
try {
proc.wait_finish(result);
if ( ! proc.get_successful()) {
log ( 'Monito: the process failed' );
monitoLog ( 'Monito: the process failed' );
}
} catch (e) {
logError(e);
monitoLog(e);
} finally {
loop.quit();
}
});
} catch ( e ) {
log ( 'Monito err: ' + e.message );
monitoLog ( 'Monito err: ' + e.message );
Main.notifyError ( _('Unable to execute command: %s').format ( e.message ) );
}
this.stopChildSpin ( e.service.button );
}
_createButton ( sizeName, icon, data, callback ) {
_createButton ( sizeName, icon, data, callback, radiobutton = false ) {
let size = 24;
if ( sizeName == 'small' )
size = 24;
@ -640,7 +644,7 @@ class Indicator extends PanelMenu.Button {
size = 32;
let _text = '';
if ( ! data instanceof Object )
if ( ! ( data instanceof Object ) )
_text = data;
let button = new St.Button({
@ -657,6 +661,12 @@ class Indicator extends PanelMenu.Button {
});
button.prevIcon = icon;
if ( radiobutton )
{
button.toggle_mode = true;
button.set_checked ( true );
}
if ( data instanceof Object )
button.service = data;
@ -679,7 +689,7 @@ class Extension {
constructor(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.enable ( );
} ) );
@ -707,19 +717,24 @@ class Extension {
this._indicators[i].cancelTimeout();
this._indicators[i].destroy();
}
if ( this._connectId )
{
settings.disconnect( this._connectId );
this._connectId = null;
}
this._indicators = { };
}
}
function init(meta) {
function init(meta) { // eslint-disable-line no-unused-vars
return new Extension(meta.uuid);
}
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() {
monitoLog('initializing ${Me.metadata.name} Preferences');
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`
this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA);
this._columnsStores = { };
let mainVbox = new Gtk.Box( { orientation: Gtk.Orientation.VERTICAL } );
let mainWidget = new Gtk.Notebook( { } );
let prefsWidget = new Gtk.Grid({
// margin: 18,
column_spacing: 12,
row_spacing: 12,
column_homogeneous: false,
});
if ( this.gtkVersion < 4 )
prefsWidget.margin = 18;
this.prefWidgets = { };
// Add a simple title and add it to the prefsWidget
@ -165,12 +171,18 @@ function buildPrefsWidget() {
homogeneous: false, } );
monitoLog ( 'Box ' + this._accountsWidgetContainer );
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,
hexpand: 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
for ( var server_id of this.getServersList ( ) )
@ -179,7 +191,10 @@ function buildPrefsWidget() {
// Action Bar
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',
Gtk.IconSize.BUTTON );
@ -193,7 +208,10 @@ function buildPrefsWidget() {
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();
return mainVbox;
@ -245,7 +263,10 @@ function createAccountWidgets ( isActive )
this.prefWidgets = { };
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' ] )
{
@ -276,6 +297,8 @@ function createPrefWidgets ( noteBook, type, isActive )
visible: true,
column_homogeneous: false,
});
if ( this.gtkVersion < 4 )
grid.margin = 18;
noteBook.append_page ( grid, new Gtk.Label ( { label: _(type), } ) );
let y = 0;
@ -340,42 +363,52 @@ function createColumnsPrefTab ( noteBook, type, isActive )
visible: true,
column_homogeneous: false,
});
if ( this.gtkVersion < 4 )
grid.margin = 18;
noteBook.append_page ( grid, new Gtk.Label ( { label: _(type), } ) );
let _store = new Gtk.TreeStore();
_store.set_column_types([GObject.TYPE_STRING, GObject.TYPE_INT]);
_store.filter_new(null);
let _treeView = new Gtk.TreeView ( { model: _store,
headers_visible: true,
let _treeView = new Gtk.TreeView ( { headers_visible: true,
reorderable: true,
hexpand: true,
vexpand: true });
let columnNumbers = new Gtk.TreeViewColumn ( { title: _("Column") } );
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);
_treeView.append_column(columnNumbers);
let _colSize = new Gtk.TreeViewColumn ( { title: _("Size") } );
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);
_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));
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,
// margin: 5,
halign: Gtk.Align.START } );
row.set_child ( _label );
this.accountsChooser.append ( row );
this.accountsChooser.show_all(); // XXX Does not work in gtk4 ?
if ( this.gtkVersion == 4 )
{
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 )
{
log ( 'Monito: ' + msg );

View File

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