| 1 |
/* onboarding-dialog.vala |
| 2 |
* |
| 3 |
* Copyright (C) Red Hat, Inc |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
* Author: Felipe Borges <[email protected]> |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
using Gtk; |
| 23 |
using Hdy; |
| 24 |
|
| 25 |
namespace Connections { |
| 26 |
[GtkTemplate (ui = "/org/gnome/Connections/ui/onboarding-dialog.ui")] |
| 27 |
private class OnboardingDialog : Hdy.Window { |
| 28 |
[GtkChild] |
| 29 |
private unowned Carousel paginator; |
| 30 |
[GtkChild] |
| 31 |
private unowned Button go_back_button; |
| 32 |
[GtkChild] |
| 33 |
private unowned Button go_next_button; |
| 34 |
[GtkChild] |
| 35 |
private unowned Button close_button; |
| 36 |
|
| 37 |
private GLib.List<unowned OnboardingDialogPage> pages; |
| 38 |
|
| 39 |
construct { |
| 40 |
pages = new GLib.List<unowned OnboardingDialogPage> (); |
| 41 |
|
| 42 |
OnboardingDialogPage? onboarding_page = null; |
| 43 |
foreach (var page in paginator.get_children ()) { |
| 44 |
assert (page is OnboardingDialogPage); |
| 45 |
|
| 46 |
onboarding_page = page as OnboardingDialogPage; |
| 47 |
pages.append (onboarding_page); |
| 48 |
} |
| 49 |
|
| 50 |
on_position_changed (); |
| 51 |
} |
| 52 |
|
| 53 |
public OnboardingDialog (Window window) { |
| 54 |
set_transient_for (window); |
| 55 |
} |
| 56 |
|
| 57 |
[GtkCallback] |
| 58 |
private bool on_key_pressed (Gtk.Widget widget, Gdk.EventKey event) { |
| 59 |
if (event.keyval == Gdk.Key.Escape) { |
| 60 |
close (); |
| 61 |
return true; |
| 62 |
} |
| 63 |
|
| 64 |
return false; |
| 65 |
} |
| 66 |
|
| 67 |
[GtkCallback] |
| 68 |
private void on_next_button_clicked () { |
| 69 |
var index = (int) Math.round (paginator.position) + 1; |
| 70 |
if (index >= pages.length ()) |
| 71 |
return; |
| 72 |
|
| 73 |
paginator.scroll_to (pages.nth_data (index)); |
| 74 |
} |
| 75 |
|
| 76 |
[GtkCallback] |
| 77 |
private void on_back_button_clicked () { |
| 78 |
var index = (int) Math.round (paginator.position) - 1; |
| 79 |
if (index < 0) |
| 80 |
return; |
| 81 |
|
| 82 |
paginator.scroll_to (pages.nth_data (index)); |
| 83 |
} |
| 84 |
|
| 85 |
[GtkCallback] |
| 86 |
private void on_position_changed () { |
| 87 |
var position = (int)paginator.position; |
| 88 |
|
| 89 |
bool is_first_page = (position == 0); |
| 90 |
bool is_last_page = (position == (pages.length () - 1)); |
| 91 |
|
| 92 |
go_back_button.visible = !is_first_page; |
| 93 |
go_next_button.visible = !is_last_page; |
| 94 |
|
| 95 |
close_button.visible = is_first_page || is_last_page; |
| 96 |
close_button.label = is_first_page ? _("_No Thanks") : _("_Close"); |
| 97 |
} |
| 98 |
} |
| 99 |
} |