1
1
public class Planner : Adw .Application {
2
- public MainWindow main_window;
3
-
4
- public static Planner _instance = null ;
5
- public static Planner instance {
6
- get {
7
- if (_instance == null ) {
8
- _instance = new Planner ();
9
- }
10
- return _instance;
11
- }
12
- }
13
-
14
- private static bool run_in_background = false ;
15
- private static bool version = false ;
16
- private static bool clear_database = false ;
17
- private static string lang = " " ;
18
-
19
- private Xdp . Portal ? portal = null ;
20
-
21
- private const OptionEntry [] PLANNER_OPTIONS = {
22
- { " version" , ' v' , 0 , OptionArg . NONE , ref version, " Display version number" , null },
23
- { " reset" , ' r' , 0 , OptionArg . NONE , ref clear_database, " Reset Planner" , null },
24
- { " background" , ' b' , 0 , OptionArg . NONE , out run_in_background, " Run the Application in background" , null },
25
- { " lang" , ' l' , 0 , OptionArg . STRING , ref lang, " Open Planner in a specific language" , " LANG" },
26
- { null }
27
- };
28
-
29
- construct {
30
- application_id = " io.github.alainm23.planify" ;
31
- flags |= ApplicationFlags . HANDLES_OPEN ;
32
-
33
- Intl . setlocale (LocaleCategory . ALL , " " );
34
- string langpack_dir = Path . build_filename (Constants . INSTALL_PREFIX , " share" , " locale" );
35
- Intl . bindtextdomain (Constants . GETTEXT_PACKAGE , langpack_dir);
36
- Intl . bind_textdomain_codeset (Constants . GETTEXT_PACKAGE , " UTF-8" );
37
- Intl . textdomain (Constants . GETTEXT_PACKAGE );
38
-
39
- add_main_option_entries (PLANNER_OPTIONS );
40
- create_dir_with_parents (" /io.github.alainm23.planify" );
41
- }
42
-
43
- protected override void activate () {
44
- if (lang != " " ) {
45
- GLib . Environment . set_variable (" LANGUAGE" , lang, true );
46
- }
47
-
48
- if (version) {
49
- print (" %s\n " . printf (Constants . VERSION ));
50
- return ;
51
- }
52
-
53
- if (main_window != null ) {
54
- main_window. show ();
55
- return ;
56
- }
57
-
58
- main_window = new MainWindow (this );
59
-
60
- Services . Settings . get_default (). settings. bind (" window-height" , main_window, " default-height" , SettingsBindFlags . DEFAULT );
61
- Services . Settings . get_default (). settings. bind (" window-width" , main_window, " default-width" , SettingsBindFlags . DEFAULT );
62
-
63
- if (Services . Settings . get_default (). settings. get_boolean (" window-maximized" )) {
64
- main_window. maximize ();
65
- }
66
-
67
- if (! run_in_background) {
68
- main_window. show ();
69
- }
70
-
71
- Services . Settings . get_default (). settings. bind (" window-maximized" , main_window, " maximized" , SettingsBindFlags . SET );
72
-
73
- var provider = new Gtk .CssProvider ();
74
- provider. load_from_resource (" /io/github/alainm23/planify/index.css" );
75
- Gtk . StyleContext . add_provider_for_display (
76
- Gdk . Display . get_default (), provider, Gtk . STYLE_PROVIDER_PRIORITY_APPLICATION
77
- );
78
-
79
- Util . get_default (). update_theme ();
80
-
81
- if (Services . Settings . get_default (). settings. get_string (" version" ) != Constants . VERSION ) {
82
- Services . Settings . get_default (). settings. set_string (" version" , Constants . VERSION );
83
- }
84
-
85
- if (clear_database) {
86
- Util . get_default (). clear_database (_(" Are you sure you want to reset all?" ),
87
- _(" The process removes all stored information without the possibility of undoing it." ));
88
- }
89
- }
90
-
91
- public async bool ask_for_background (Xdp .BackgroundFlags flags = Xdp .BackgroundFlags .AUTOSTART ) {
92
- const string [] DAEMON_COMMAND = { " io.github.alainm23.planify" , " --background" };
93
- if (portal == null ) {
94
- portal = new Xdp .Portal ();
95
- }
96
-
97
- string reason = _(
98
- " Planify will automatically start when this device turns on " +
99
- " and run when its window is closed so that it can send to-do notifications."
100
- );
101
- var command = new GenericArray<unowned string> (2 );
102
- foreach (unowned var arg in DAEMON_COMMAND ) {
103
- command. add (arg);
104
- }
105
-
106
- var window = Xdp . parent_new_gtk (active_window);
107
-
108
- try {
109
- return yield portal. request_background (window, reason, command, flags, null );
110
- } catch (Error e) {
111
- warning (" Error during portal request: %s " , e. message);
112
- return e is IOError . FAILED ;
113
- }
114
- }
115
-
116
- public void create_dir_with_parents (string dir ) {
117
- string path = Environment . get_user_data_dir () + dir;
118
- File tmp = File . new_for_path (path);
119
- if (tmp. query_file_type (0 ) != FileType . DIRECTORY ) {
120
- GLib . DirUtils . create_with_parents (path, 0775 );
121
- }
122
- }
123
-
124
- public static int main (string [] args ) {
125
- Planner app = Planner . instance;
126
- return app. run (args);
127
- }
2
+ public MainWindow main_window;
3
+
4
+ public static Planner _instance = null ;
5
+ public static Planner instance {
6
+ get {
7
+ if (_instance == null ) {
8
+ _instance = new Planner ();
9
+ }
10
+ return _instance;
11
+ }
12
+ }
13
+
14
+ private static bool run_in_background = false ;
15
+ private static bool version = false ;
16
+ private static bool clear_database = false ;
17
+ private static string lang = " " ;
18
+
19
+ private Xdp . Portal ? portal = null ;
20
+
21
+ private const OptionEntry [] PLANNER_OPTIONS = {
22
+ { " version" , ' v' , 0 , OptionArg . NONE , ref version, " Display version number" , null },
23
+ { " reset" , ' r' , 0 , OptionArg . NONE , ref clear_database, " Reset Planner" , null },
24
+ { " background" , ' b' , 0 , OptionArg . NONE , out run_in_background, " Run the Application in background" , null },
25
+ { " lang" , ' l' , 0 , OptionArg . STRING , ref lang, " Open Planner in a specific language" , " LANG" },
26
+ { null }
27
+ };
28
+
29
+ construct {
30
+ application_id = " io.github.alainm23.planify" ;
31
+ flags |= ApplicationFlags . HANDLES_OPEN ;
32
+
33
+ Intl . setlocale (LocaleCategory . ALL , " " );
34
+ string langpack_dir = Path . build_filename (Constants . INSTALL_PREFIX , " share" , " locale" );
35
+ Intl . bindtextdomain (Constants . GETTEXT_PACKAGE , langpack_dir);
36
+ Intl . bind_textdomain_codeset (Constants . GETTEXT_PACKAGE , " UTF-8" );
37
+ Intl . textdomain (Constants . GETTEXT_PACKAGE );
38
+
39
+ add_main_option_entries (PLANNER_OPTIONS );
40
+ create_dir_with_parents (" /io.github.alainm23.planify" );
41
+ }
42
+
43
+ protected override void activate () {
44
+ if (lang != " " ) {
45
+ GLib . Environment . set_variable (" LANGUAGE" , lang, true );
46
+ }
47
+
48
+ if (version) {
49
+ print (" %s\n " . printf (Constants . VERSION ));
50
+ return ;
51
+ }
52
+
53
+ if (main_window != null ) {
54
+ main_window. show ();
55
+ return ;
56
+ }
57
+
58
+ main_window = new MainWindow (this );
59
+
60
+ Services . Settings . get_default (). settings. bind (" window-height" , main_window, " default-height" , SettingsBindFlags . DEFAULT );
61
+ Services . Settings . get_default (). settings. bind (" window-width" , main_window, " default-width" , SettingsBindFlags . DEFAULT );
62
+
63
+ if (Services . Settings . get_default (). settings. get_boolean (" window-maximized" )) {
64
+ main_window. maximize ();
65
+ }
66
+
67
+ if (! run_in_background) {
68
+ main_window. show ();
69
+ }
70
+
71
+ Services . Settings . get_default (). settings. bind (" window-maximized" , main_window, " maximized" , SettingsBindFlags . SET );
72
+
73
+ var provider = new Gtk .CssProvider ();
74
+ provider. load_from_resource (" /io/github/alainm23/planify/index.css" );
75
+ Gtk . StyleContext . add_provider_for_display (
76
+ Gdk . Display . get_default (), provider, Gtk . STYLE_PROVIDER_PRIORITY_APPLICATION
77
+ );
78
+
79
+ Util . get_default (). update_theme ();
80
+
81
+ if (Services . Settings . get_default (). settings. get_string (" version" ) != Constants . VERSION ) {
82
+ Services . Settings . get_default (). settings. set_string (" version" , Constants . VERSION );
83
+ }
84
+
85
+ if (clear_database) {
86
+ Util . get_default (). clear_database (_(" Are you sure you want to reset all?" ),
87
+ _(" The process removes all stored information without the possibility of undoing it." ));
88
+ }
89
+ }
90
+
91
+ public async bool ask_for_background (Xdp .BackgroundFlags flags = Xdp .BackgroundFlags .AUTOSTART ) {
92
+ const string [] DAEMON_COMMAND = { " io.github.alainm23.planify" , " --background" };
93
+ if (portal == null ) {
94
+ portal = new Xdp .Portal ();
95
+ }
96
+
97
+ string reason = _(
98
+ " Planify will automatically start when this device turns on " +
99
+ " and run when its window is closed so that it can send to-do notifications."
100
+ );
101
+ var command = new GenericArray<unowned string> (2 );
102
+ foreach (unowned var arg in DAEMON_COMMAND ) {
103
+ command. add (arg);
104
+ }
105
+
106
+ var window = Xdp . parent_new_gtk (active_window);
107
+
108
+ try {
109
+ return yield portal. request_background (window, reason, command, flags, null );
110
+ } catch (Error e) {
111
+ warning (" Error during portal request: %s " , e. message);
112
+ return e is IOError . FAILED ;
113
+ }
114
+ }
115
+
116
+ public void create_dir_with_parents (string dir ) {
117
+ string path = Environment . get_user_data_dir () + dir;
118
+ File tmp = File . new_for_path (path);
119
+ if (tmp. query_file_type (0 ) != FileType . DIRECTORY ) {
120
+ GLib . DirUtils . create_with_parents (path, 0775 );
121
+ }
122
+ }
123
+
124
+ public static int main (string [] args ) {
125
+ Planner app = Planner . instance;
126
+ return app. run (args);
127
+ }
128
128
}
0 commit comments