Skip to content
This repository has been archived by the owner on Aug 14, 2022. It is now read-only.

Support installing engines #5

Merged
merged 28 commits into from
Oct 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1842b01
Just fetched stuff from the locale plug
ryonakano Aug 15, 2019
c543ab3
Update dependencies for Travis
ryonakano Aug 15, 2019
f51fe11
Merge branch 'master' into installation-and-uninstallation
ryonakano Aug 23, 2019
4154b0d
Add InstallList
ryonakano Aug 24, 2019
0a375e2
Add install_dialog
ryonakano Aug 24, 2019
ce7447d
Make languages and engines in the lists clickable
ryonakano Sep 5, 2019
721d6fb
Merge branch 'master' into installation-and-uninstallation
ryonakano Sep 23, 2019
88db28c
Show engines by languages
ryonakano Sep 23, 2019
6e760f7
No separations depened on locales
ryonakano Sep 23, 2019
e31a2cd
Coding style
ryonakano Sep 23, 2019
319d60a
Correct frame size
ryonakano Sep 23, 2019
1eaf93a
Merge latest changes in the locale Plug
ryonakano Oct 1, 2019
36d44f5
Handle installing engines
ryonakano Oct 5, 2019
331763c
Merge branch 'master' into installation-and-uninstallation
ryonakano Oct 5, 2019
4c3e993
Merge branch 'master' into installation-and-uninstallation
ryonakano Oct 5, 2019
4d02c35
Make the install_button insensitive by default
ryonakano Oct 18, 2019
1fcac03
Merge branch 'master' into installation-and-uninstallation
ryonakano Oct 18, 2019
957eb99
aptd-client: Update code style
ryonakano Oct 18, 2019
d74a7cd
Remove unused
ryonakano Oct 18, 2019
443b6af
Update copyright header notation
ryonakano Oct 19, 2019
b7d48fe
Dialog primary text should be sentence case
ryonakano Oct 19, 2019
802ed9a
Add the newly added files to POTFILES
ryonakano Oct 19, 2019
c4f18e7
Merge branch 'master' into installation-and-uninstallation
ryonakano Oct 20, 2019
d358bd2
Namespace as a part of the class name
ryonakano Oct 20, 2019
36df13e
Fix a long line
ryonakano Oct 20, 2019
4447734
Move dialog files into the Dialogs folder
ryonakano Oct 20, 2019
2fceca7
Add ProgressDialog
ryonakano Oct 20, 2019
665085b
Fix ambiguous variable name
ryonakano Oct 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ if(ibus_dep.version().version_compare('>=1.5.19'))
endif

shared_module(meson.project_name(),
'src/Dialogs/InstallEngineDialog.vala',
'src/Dialogs/ProgressDialog.vala',
'src/Installer/aptd-client.vala',
'src/Installer/InstallList.vala',
'src/Installer/UbuntuInstaller.vala',
'src/Views/EnginesListView.vala',
'src/Views/EnginesRow.vala',
'src/Views/LanguagesRow.vala',
'src/Views/SettingsView.vala',
'src/Widgets/AddEnginesPopover.vala',
'src/AddEnginesList.vala',
Expand Down
2 changes: 2 additions & 0 deletions po/POTFILES
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
src/Installer/InstallList.vala
src/Views/EnginesListView.vala
src/Views/SettingsView.vala
src/Widgets/AddEnginesPopover.vala
src/Widgets/InstallEngineDialog.vala
src/Plug.vala
135 changes: 135 additions & 0 deletions src/Dialogs/InstallEngineDialog.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright 2019 Ryo Nakano
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/

public class InputMethod.InstallEngineDialog : Granite.MessageDialog {
private InstallList? engines_filter;

public InstallEngineDialog (Gtk.Window parent) {
Object (
primary_text: _("Choose an engine to install"),
secondary_text: _("Select an engine from the list to install and use."),
image_icon: new ThemedIcon ("dialog-information"),
transient_for: parent,
buttons: Gtk.ButtonsType.CANCEL
);
}

construct {
var languages_list = new Gtk.ListBox ();
languages_list.activate_on_single_click = true;
languages_list.expand = true;
languages_list.selection_mode = Gtk.SelectionMode.NONE;

foreach (var language in InstallList.get_all ()) {
var lang = new LanguagesRow (language);
languages_list.add (lang);
}

var back_button = new Gtk.Button.with_label (_("Languages"));
back_button.halign = Gtk.Align.START;
back_button.margin = 6;
back_button.get_style_context ().add_class (Granite.STYLE_CLASS_BACK_BUTTON);

var language_title = new Gtk.Label ("");

var language_header = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
language_header.pack_start (back_button);
language_header.set_center_widget (language_title);

var listbox = new Gtk.ListBox ();
listbox.expand = true;
listbox.set_filter_func (filter_function);
listbox.set_sort_func (sort_function);

foreach (var language in InstallList.get_all ()) {
foreach (var engine in language.get_components ()) {
listbox.add (new EnginesRow (engine));
}
}

var scrolled = new Gtk.ScrolledWindow (null, null);
scrolled.add (listbox);

var engine_list_grid = new Gtk.Grid ();
engine_list_grid.orientation = Gtk.Orientation.VERTICAL;
engine_list_grid.get_style_context ().add_class (Gtk.STYLE_CLASS_VIEW);
engine_list_grid.add (language_header);
engine_list_grid.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
engine_list_grid.add (scrolled);

var stack = new Gtk.Stack ();
stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
stack.width_request = 300;
stack.height_request = 200;
stack.add (languages_list);
stack.add (engine_list_grid);

var frame = new Gtk.Frame (null);
frame.add (stack);

custom_bin.add (frame);

var install_button = add_button (_("Install"), Gtk.ResponseType.OK);
install_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
install_button.sensitive = false;

show_all ();

languages_list.row_activated.connect ((row) => {
stack.visible_child = engine_list_grid;
language_title.label = ((LanguagesRow) row).language.get_name ();
engines_filter = ((LanguagesRow) row).language;
listbox.invalidate_filter ();
var adjustment = scrolled.get_vadjustment ();
adjustment.set_value (adjustment.lower);
});

back_button.clicked.connect (() => {
stack.visible_child = languages_list;
install_button.sensitive = false;
});

listbox.selected_rows_changed.connect (() => {
foreach (var engines_row in listbox.get_children ()) {
((EnginesRow) engines_row).selected = false;
}
((EnginesRow) listbox.get_selected_row ()).selected = true;
install_button.sensitive = true;
});

response.connect ((response_id) => {
if (response_id == Gtk.ResponseType.OK) {
string engine_to_install = ((EnginesRow) listbox.get_selected_row ()).engine_name;
Installer.UbuntuInstaller.get_default ().install (engine_to_install);
}
});
}

[CCode (instance_pos = -1)]
private bool filter_function (Gtk.ListBoxRow row) {
if (InstallList.get_language_from_engine_name (((EnginesRow) row).engine_name) == engines_filter) {
return true;
}

return false;
}

[CCode (instance_pos = -1)]
private int sort_function (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) {
return ((EnginesRow) row1).engine_name.collate (((EnginesRow) row1).engine_name);
}
}
80 changes: 80 additions & 0 deletions src/Dialogs/ProgressDialog.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2011-2019 elementary, Inc. (https://elementary.io)
* 2019 Ryo Nakano
*
* This program is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/

public class InputMethod.ProgressDialog : Gtk.Dialog {
public int progress {
set {
if (value >= 100) {
destroy ();
}

progress_bar.fraction = value / 100.0;
}
}

private Gtk.ProgressBar progress_bar;

construct {
var image = new Gtk.Image.from_icon_name ("preferences-desktop-locale", Gtk.IconSize.DIALOG);
image.valign = Gtk.Align.START;

unowned Installer.UbuntuInstaller installer = Installer.UbuntuInstaller.get_default ();

var primary_label = new Gtk.Label (null);
primary_label.max_width_chars = 50;
primary_label.wrap = true;
primary_label.xalign = 0;
primary_label.get_style_context ().add_class (Granite.STYLE_CLASS_PRIMARY_LABEL);

switch (installer.transaction_mode) {
case Installer.UbuntuInstaller.TransactionMode.INSTALL:
primary_label.label = _("Installing %s").printf (installer.engine_to_address);
break;
case Installer.UbuntuInstaller.TransactionMode.REMOVE:
primary_label.label = _("Removing %s").printf (installer.engine_to_address);
break;
}

progress_bar = new Gtk.ProgressBar ();
progress_bar.width_request = 300;
progress_bar.hexpand = true;
progress_bar.valign = Gtk.Align.START;

var cancel_button = (Gtk.Button) add_button (_("Cancel"), 0);

installer.bind_property ("install-cancellable", cancel_button, "sensitive");

var grid = new Gtk.Grid ();
grid.column_spacing = 12;
grid.row_spacing = 6;
grid.margin = 6;
grid.attach (image, 0, 0, 1, 2);
grid.attach (primary_label, 1, 0);
grid.attach (progress_bar, 1, 1);
grid.show_all ();

border_width = 6;
deletable = false;
get_content_area ().add (grid);

cancel_button.clicked.connect (() => {
installer.cancel_install ();
destroy ();
});
}
}
69 changes: 69 additions & 0 deletions src/Installer/InstallList.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2019 Ryo Nakano
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/

public enum InputMethod.InstallList {
JA,
KO,
ZH;

public string get_name () {
switch (this) {
case JA:
return _("Japanese");
case KO:
return _("Korean");
case ZH:
return _("Chinese");
default:
assert_not_reached ();
}
}

public string[] get_components () {
switch (this) {
case JA:
return { "ibus-mozc" };
case KO:
return { "ibus-hangul" };
case ZH:
return { "ibus-cangjie", "ibus-chewing", "ibus-pinyin" };
default:
assert_not_reached ();
}
}

public static InstallList get_language_from_engine_name (string engine_name) {
switch (engine_name) {
case "ibus-mozc":
return JA;
case "ibus-hangul":
return KO;
case "ibus-cangjie":
return ZH;
case "ibus-chewing":
return ZH;
case "ibus-pinyin":
return ZH;
default:
assert_not_reached ();
}
}

public static InstallList[] get_all () {
return { JA, KO, ZH };
}
}
Loading