File: gnome-klotski.vala

package info (click to toggle)
gnome-klotski 1:3.32.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,500 kB
  • sloc: xml: 101; python: 11; sh: 7; makefile: 6
file content (134 lines) | stat: -rw-r--r-- 4,415 bytes parent folder | download
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
/*
 * Copyright (C) 2010-2013 Robert Ancell
 *
 * 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. See http://www.gnu.org/copyleft/gpl.html the full text of the
 * license.
 */

using Gtk;

public class Klotski : Gtk.Application
{
    private const OptionEntry [] option_entries =
    {
        { "version", 'v', 0, OptionArg.NONE, null, N_("Print release version and exit"), null },
        { null }
    };

    private const GLib.ActionEntry action_entries [] =
    {
        {"scores", scores_cb},
        {"help", help_cb},
        {"about", about_cb},
        {"quit", quit_cb}
    };

    /*\
    * * Application init
    \*/

    public static int main (string [] args)
    {
        Intl.setlocale (LocaleCategory.ALL, "");
        Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
        Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
        Intl.textdomain (GETTEXT_PACKAGE);

        Klotski app = new Klotski ();
        return app.run (args);
    }

    public Klotski ()
    {
        Object (application_id: "org.gnome.Klotski", flags: ApplicationFlags.FLAGS_NONE);

        add_main_option_entries (option_entries);
    }

    protected override int handle_local_options (GLib.VariantDict options)
    {
        if (options.contains ("version"))
        {
            /* NOTE: Is not translated so can be easily parsed */
            stdout.printf ("%1$s %2$s\n", "gnome-klotski", VERSION);
            return Posix.EXIT_SUCCESS;
        }
        return -1;
    }

    protected override void startup ()
    {
        base.startup ();

        Environment.set_application_name (_("Klotski"));
        Window.set_default_icon_name ("org.gnome.Klotski");

        add_action_entries (action_entries, this);

        add_window (new KlotskiWindow ());

        // set_accels_for_action ("win.start-game", {"<Primary>n"}); /* or <Primary>r ? or both ? */
        set_accels_for_action ("win.prev-puzzle", {"Up"});       // TODO
        set_accels_for_action ("win.next-puzzle", {"Down"});     // TODO a weird behaviour exists when you first change puzzle pack, then go to
        set_accels_for_action ("win.prev-pack", {"Page_Up"});    // TODO the first/last one, click on a puzzle, and immediatly hit Up or Down arrows.
        set_accels_for_action ("win.next-pack", {"Page_Down"});  // TODO that makes these keybindings sometimes act strangely, but they’re good.

        set_accels_for_action ("app.quit", {"<Primary>q"});
    }

    protected override void activate ()
    {
        get_active_window ().present ();
    }

    /*\
    * * App-menu callbacks
    \*/

    private void scores_cb ()
    {
        ((KlotskiWindow) get_active_window ()).show_scores ();
    }

    private void help_cb ()
    {
        try
        {
            show_uri (get_active_window ().get_screen (), "help:gnome-klotski", get_current_event_time ());
        }
        catch (Error e)
        {
            warning ("Failed to show help: %s", e.message);
        }
    }

    private void about_cb ()
    {
        const string authors [] = { "Lars Rydlinge (original author)", "Robert Ancell (port to vala)", "John Cheetham (port to vala)", null };
        const string documenters [] = { "Andrew Sobala", null };

        show_about_dialog (get_active_window (),
                           "program-name", _("Klotski"),
                           "version", VERSION,
                           "comments", _("Sliding block puzzles"),
                           "copyright",
                             "Copyright © 1999–2008 Lars Rydlinge\n"+
                             "Copyright © 2014–2016 Michael Catanzaro\n"+
                             "Copyright © 2015 Arnaud Bonatti\n",
                           "license-type", License.GPL_3_0,
                           "authors", authors,
                           "documenters", documenters,
                           "translator-credits", _("translator-credits"),
                           "logo-icon-name", "org.gnome.Klotski",
                           "website", "https://wiki.gnome.org/Apps/Klotski",
                           null);
    }

    private void quit_cb ()
    {
        get_active_window ().destroy ();
    }
}