1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
|
/*
This file is part of Dconf Editor
Dconf Editor is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Dconf Editor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Dconf Editor. If not, see <https://www.gnu.org/licenses/>.
*/
using Gtk;
private class AboutList : OverlayedList
{
// same as about dialog; skipped: wrap_license, license, logo
[CCode (notify = false)] public string [] artists { private get; protected construct; default = {}; }
[CCode (notify = false)] public string [] authors { private get; protected construct; default = {}; }
[CCode (notify = false)] public string comments { private get; protected construct; default = ""; }
[CCode (notify = false)] public string copyright { private get; protected construct; default = ""; }
[CCode (notify = false)] public string [] documenters { private get; protected construct; default = {}; }
[CCode (notify = false)] private License license_type { private get { return License.GPL_3_0; }} // forced, 2/3
[CCode (notify = false)] public string logo_icon_name { private get; protected construct; default = ""; }
[CCode (notify = false)] public string program_name { private get; protected construct; default = ""; }
[CCode (notify = false)] public string translator_credits { private get; protected construct; default = ""; }
[CCode (notify = false)] public string version { private get; protected construct; default = ""; }
[CCode (notify = false)] public string website { private get; protected construct; default = ""; }
[CCode (notify = false)] public string website_label { private get; protected construct; default = ""; }
construct
{
install_action_entries ();
main_list_box.selection_mode = SelectionMode.NONE;
get_style_context ().add_class ("about-list");
/* Translators: on really small windows, the about dialog is replaced by an in-window view; here is the label of one of two buttons that have the same role as the stack switcher in the usual about dialog, the second is "Credits" */
first_mode_name = _("About");
/* Translators: on really small windows, the about dialog is replaced by an in-window view; here is the label of one of two buttons that have the same role as the stack switcher in the usual about dialog, the first is "About" */
second_mode_name = _("Credits");
change_editability (true);
show_apropos (ref main_list_store);
}
internal AboutList (bool needs_shadows,
bool big_placeholder,
ref string [] artists,
ref string [] authors,
ref string comments,
ref string copyright,
ref string [] documenters,
ref string logo_icon_name,
ref string program_name,
ref string translator_credits,
ref string version,
ref string website,
ref string website_label)
{
Object (needs_shadows : needs_shadows,
big_placeholder : big_placeholder,
edit_mode_action_prefix : "about",
artists: artists, authors: authors, comments: comments, copyright: copyright, documenters: documenters, logo_icon_name: logo_icon_name, program_name: program_name, translator_credits: translator_credits, version: version, website: website, website_label: website_label);
}
internal override void reset ()
{
edit_mode_action.set_state (false);
show_apropos (ref main_list_store);
scroll_top ();
}
/*\
* * Action entries
\*/
SimpleAction edit_mode_action;
private void install_action_entries ()
{
SimpleActionGroup action_group = new SimpleActionGroup ();
action_group.add_action_entries (action_entries, this);
insert_action_group ("about", action_group);
edit_mode_action = (SimpleAction) action_group.lookup_action ("set-edit-mode");
}
private const GLib.ActionEntry [] action_entries =
{
{ "set-edit-mode", set_edit_mode, "b", "false" }
};
private void set_edit_mode (SimpleAction action, Variant? variant)
requires (variant != null)
{
bool new_state = ((!) variant).get_boolean ();
action.set_state (new_state);
if (new_state)
show_credits (ref main_list_store);
else
show_apropos (ref main_list_store);
}
private inline void show_apropos (ref GLib.ListStore main_list_store)
{
main_list_store.remove_all ();
if (program_name == "")
assert_not_reached ();
if (logo_icon_name != "")
main_list_store.append (new AboutListItem.from_icon_name (logo_icon_name, program_name));
AboutListItem program = new AboutListItem.from_label (program_name, "bold-label");
main_list_store.append (program);
if (version != "")
main_list_store.append (new AboutListItem.from_label (version));
if (comments != "")
main_list_store.append (new AboutListItem.from_label (comments));
if (website != "")
main_list_store.append (new AboutListItem.from_link (website, website_label)); // website_label can be empty
if (copyright != "")
main_list_store.append (new AboutListItem.from_label (copyright, "small-label"));
// forced, 3/3 // TODO support all licenses type
if (license_type != License.GPL_3_0)
assert_not_reached ();
/* Translators: on really small windows, the about dialog is replaced by an in-window view; here is the label of the link to the GPL license; TODO better text, as in the usual about dialog */
main_list_store.append (new AboutListItem.from_link ("https://www.gnu.org/licenses/gpl-3.0.html", _("GNU General Public License\nversion 3 or later")));
program.grab_focus ();
}
private inline void show_credits (ref GLib.ListStore main_list_store)
{
main_list_store.remove_all ();
if (program_name == "")
assert_not_reached ();
if (logo_icon_name != "")
main_list_store.append (new AboutListItem.from_icon_name (logo_icon_name, program_name));
AboutListItem program = new AboutListItem.from_label (program_name, "bold-label");
main_list_store.append (program);
if (authors.length > 0)
{
string authors_string = get_multiline_string_from_string_array (authors);
/* Translators: on really small windows, the about dialog is replaced by an in-window view; here is the header of the programmers names */
main_list_store.append (new AboutListItem.with_title (authors_string, _("Creators")));
}
if (documenters.length > 0)
{
string documenters_string = get_multiline_string_from_string_array (documenters);
/* Translators: on really small windows, the about dialog is replaced by an in-window view; here is the header of the documenters names */
// main_list_store.append (new AboutListItem.with_title (documenters_string, _("Documenters")));
}
if (translator_credits != "")
/* Translators: on really small windows, the about dialog is replaced by an in-window view; here is the header of the translators names */
main_list_store.append (new AboutListItem.with_title (translator_credits, _("Translators")));
if (artists.length > 0)
{
string artists_string = get_multiline_string_from_string_array (artists);
/* Translators: on really small windows, the about dialog is replaced by an in-window view; here is the header of the pictural artists names */
// main_list_store.append (new AboutListItem.with_title (artists_string, _("Artists")));
}
program.grab_focus ();
}
private static string get_multiline_string_from_string_array (string [] string_array)
{
if (string_array.length <= 0)
return "";
string multiline_string = "";
uint position = 0;
uint max_position = string_array.length - 1;
foreach (string string_item in string_array)
{
multiline_string += string_item;
if (position < max_position)
multiline_string += "\n";
position++;
}
return multiline_string;
}
}
private class AboutListItem : OverlayedListRow
{
[CCode (notify = false)] public string copy_text { internal get; construct; default = ""; }
internal override bool handle_copy_text (out string text)
{
text = copy_text;
return true;
}
internal AboutListItem.from_label (string text, string? css_class = null)
{
Object (copy_text: text);
Label label = new Label (text);
label.visible = true;
label.hexpand = true;
label.wrap_mode = Pango.WrapMode.WORD_CHAR;
label.wrap = true;
label.justify = Justification.CENTER;
label.selectable = true;
label.can_focus = false;
if (css_class != null)
label.get_style_context ().add_class ((!) css_class);
add (label);
}
internal AboutListItem.from_icon_name (string icon_name, string copy_text)
{
Object (copy_text: copy_text);
Image image = new Image.from_icon_name (icon_name, IconSize.DIALOG);
image.pixel_size = 128;
image.visible = true;
image.hexpand = true;
add (image);
}
internal AboutListItem.from_link (string link, string text_or_empty) // TODO do not allow button focus, and activate it on row activation
{
Object (copy_text: link);
LinkButton button;
if (text_or_empty == "")
button = new LinkButton (link);
else
button = new LinkButton.with_label (link, text_or_empty);
button.visible = true;
button.hexpand = true;
Widget? widget = button.get_child ();
if (widget == null || !(((!) widget) is Label))
assert_not_reached ();
Label label = (Label) (!) widget;
label.wrap_mode = Pango.WrapMode.WORD_CHAR;
label.wrap = true;
label.justify = Justification.CENTER;
add (button);
}
internal AboutListItem.with_title (string text, string title)
{
Object (copy_text: text);
Grid grid = new Grid ();
grid.orientation = Orientation.VERTICAL;
grid.visible = true;
add (grid);
Label label = new Label (title);
label.visible = true;
label.hexpand = true;
label.wrap_mode = Pango.WrapMode.WORD_CHAR;
label.wrap = true;
label.get_style_context ().add_class ("bold-label");
grid.add (label);
label = new Label (text);
label.visible = true;
label.hexpand = true;
label.wrap_mode = Pango.WrapMode.WORD_CHAR;
label.wrap = true;
label.selectable = true;
label.get_style_context ().add_class ("small-label");
label.justify = Justification.CENTER;
grid.add (label);
}
}
|