| 1 |
/* exported FlatsealResetButton */ |
| 2 |
|
| 3 |
/* resetButton.js |
| 4 |
* |
| 5 |
* Copyright 2020 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, Adw} = imports.gi; |
| 22 |
|
| 23 |
|
| 24 |
var FlatsealResetButton = GObject.registerClass({ |
| 25 |
GTypeName: 'FlatsealResetButton', |
| 26 |
}, class FlatsealResetButton extends Gtk.Button { |
| 27 |
_init(permissions) { |
| 28 |
super._init(); |
| 29 |
this._setup(permissions); |
| 30 |
} |
| 31 |
|
| 32 |
/* XXX Can't move this a .ui file for some reason */ |
| 33 |
_setup(permissions) { |
| 34 |
this._permissions = permissions; |
| 35 |
this._permissions.connect('changed', this._update.bind(this)); |
| 36 |
|
| 37 |
this.label = _('_Reset'); |
| 38 |
this.use_underline = true; |
| 39 |
this.sensitive = false; |
| 40 |
|
| 41 |
this.add_css_class('reset-button'); |
| 42 |
|
| 43 |
this.connect('clicked', this._clicked.bind(this)); |
| 44 |
} |
| 45 |
|
| 46 |
_clicked() { |
| 47 |
this._permissions.reset(); |
| 48 |
} |
| 49 |
|
| 50 |
_update(widget, overriden, unsupported) { |
| 51 |
this.sensitive = overriden; |
| 52 |
if (unsupported) { |
| 53 |
const content = new Adw.ButtonContent(); |
| 54 |
content.icon_name = 'dialog-warning-symbolic'; |
| 55 |
content.label = _('_Reset'); |
| 56 |
content.use_underline = true; |
| 57 |
this.set_child(content); |
| 58 |
|
| 59 |
/* XXX this makes the button look very inconsistent */ |
| 60 |
this.remove_css_class('image-text-button'); |
| 61 |
} else { |
| 62 |
this.label = _('_Reset'); |
| 63 |
} |
| 64 |
|
| 65 |
let text = _('No changes made to this application'); |
| 66 |
|
| 67 |
if (overriden) |
| 68 |
text = _('Reset this application permissions'); |
| 69 |
if (unsupported) |
| 70 |
text += _(', including changes not made with Flatseal'); |
| 71 |
|
| 72 |
this.set_tooltip_text(text); |
| 73 |
} |
| 74 |
}); |