File: base-view.vala

package info (click to toggle)
gnome-taquin 3.38.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,184 kB
  • sloc: xml: 81; python: 11; makefile: 6
file content (142 lines) | stat: -rw-r--r-- 4,786 bytes parent folder | download | duplicates (2)
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
/*
  This file is part of GNOME Taquin

  GNOME Taquin 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.

  GNOME Taquin 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 GNOME Taquin.  If not, see <https://www.gnu.org/licenses/>.
*/

using Gtk;

[GtkTemplate (ui = "/org/gnome/Taquin/ui/base-view.ui")]
private class BaseView : Stack, AdaptativeWidget
{
    [GtkChild] protected Grid main_grid;

    internal virtual bool handle_copy_text (out string copy_text)
    {
        if (in_window_about)
            return about_list.handle_copy_text (out copy_text); // TODO copying logo...
        else
            return BaseWindow.no_copy_text (out copy_text);
    }

    internal virtual void close_popovers () {}

    /*\
    * * adaptative stuff
    \*/

    protected AdaptativeWidget.WindowSize saved_window_size { protected get; private set; default = AdaptativeWidget.WindowSize.START_SIZE; }
    protected virtual void set_window_size (AdaptativeWidget.WindowSize new_size)
    {
        saved_window_size = new_size;
        if (about_list_created)
            about_list.set_window_size (new_size);
        if (notifications_revealer_created)
            notifications_revealer.set_window_size (new_size);
    }

    /*\
    * * in-window modes
    \*/

    internal virtual void show_default_view ()
    {
        if (in_window_about)
        {
            in_window_about = false;
            set_visible_child (notifications_overlay);   // or set_visible_child_name ("main-view");
        }
        else
            assert_not_reached ();
    }

    internal virtual bool is_in_in_window_mode ()
    {
        return in_window_about;
    }

    /*\
    * * in-window about
    \*/

    protected bool in_window_about { protected get; private set; default = false; }

    private bool about_list_created = false;
    private AboutList about_list;

    internal void create_about_list (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)
    {
        about_list = new AboutList (/* needs shadows   */ false,
                                    /* big placeholder */ true,
                                    ref artists, ref authors, ref comments, ref copyright, ref documenters, ref logo_icon_name, ref program_name, ref translator_credits, ref version, ref website, ref website_label);
        about_list.set_window_size (saved_window_size);
        about_list.show ();
        add (about_list);
        about_list_created = true;
    }

    internal void show_about_view ()
        requires (about_list_created == true)
        requires (in_window_about == false)
    {
        about_list.reset ();
        set_visible_child (about_list);
        in_window_about = true;
    }

    /*\
    * * notifications
    \*/

    [GtkChild] private Overlay notifications_overlay;

    private bool notifications_revealer_created = false;
    private NotificationsRevealer notifications_revealer;

    private void create_notifications_revealer ()
    {
        notifications_revealer = new NotificationsRevealer ();
        notifications_revealer.set_window_size (saved_window_size);
        notifications_revealer.show ();
        notifications_overlay.add_overlay (notifications_revealer);
        notifications_overlay.set_overlay_pass_through (notifications_revealer, true);
        notifications_revealer_created = true;
    }

    internal void show_notification (string notification)
    {
        if (!notifications_revealer_created)
            create_notifications_revealer ();

        notifications_revealer.show_notification (notification);
    }

    internal void hide_notification ()
    {
        if (!notifications_revealer_created)
            return;

        notifications_revealer.hide_notification ();
    }
}