| 1 |
/* exported FlatsealOverrideStatusIcon OverrideStatus */ |
| 2 |
|
| 3 |
/* overrideStatusIcon.js |
| 4 |
* |
| 5 |
* Copyright 2022 Martin Abente Lahaye |
| 6 |
* |
| 7 |
* This program is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation, either version 3 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
const {GObject, Gtk} = imports.gi; |
| 22 |
const {FlatsealOverrideStatus} = imports.models.overrideStatus; |
| 23 |
|
| 24 |
const OverrideStatusDescription = { |
| 25 |
global: _('Changed globally'), |
| 26 |
user: _('Changed by the user'), |
| 27 |
}; |
| 28 |
|
| 29 |
var FlatsealOverrideStatusIcon = GObject.registerClass({ |
| 30 |
GTypeName: 'FlatsealOverrideStatusIcon', |
| 31 |
Template: 'resource:///com/github/tchx84/Flatseal/widgets/overrideStatusIcon.ui', |
| 32 |
Properties: { |
| 33 |
status: GObject.ParamSpec.string( |
| 34 |
'status', |
| 35 |
'status', |
| 36 |
'status', |
| 37 |
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT, |
| 38 |
FlatsealOverrideStatus.ORIGINAL, |
| 39 |
), |
| 40 |
}, |
| 41 |
}, class FlatsealOverrideStatusIcon extends Gtk.Image { |
| 42 |
_init() { |
| 43 |
super._init({}); |
| 44 |
this._status = FlatsealOverrideStatus.ORIGINAL; |
| 45 |
} |
| 46 |
|
| 47 |
set status(status) { |
| 48 |
if (this._status === status) |
| 49 |
return; |
| 50 |
|
| 51 |
const context = this.get_style_context(); |
| 52 |
if (context.has_class(FlatsealOverrideStatus.USER)) |
| 53 |
context.remove_class(FlatsealOverrideStatus.USER); |
| 54 |
else if (context.has_class(FlatsealOverrideStatus.GLOBAL)) |
| 55 |
context.remove_class(FlatsealOverrideStatus.GLOBAL); |
| 56 |
|
| 57 |
this._status = status; |
| 58 |
if (status === FlatsealOverrideStatus.ORIGINAL) { |
| 59 |
this.set_tooltip_text(''); |
| 60 |
this.visible = false; |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
this.set_tooltip_text(OverrideStatusDescription[status]); |
| 65 |
this.visible = true; |
| 66 |
context.add_class(status); |
| 67 |
} |
| 68 |
|
| 69 |
get status() { |
| 70 |
return this._status; |
| 71 |
} |
| 72 |
}); |