|
19 | 19 | */
|
20 | 20 |
|
21 | 21 | use adw::prelude::AdwDialogExt;
|
22 |
| -use gtk::prelude::*; |
23 | 22 | use adw::subclass::prelude::*;
|
| 23 | +use gtk::prelude::*; |
24 | 24 | use gtk::{gio, glib};
|
25 | 25 |
|
26 |
| -use crate::config::VERSION; |
27 | 26 | use crate::ShutterWindow;
|
| 27 | +use crate::config::VERSION; |
28 | 28 |
|
29 | 29 | mod imp {
|
30 |
| - use super::*; |
| 30 | + use super::*; |
| 31 | + |
| 32 | + #[derive(Debug, Default)] |
| 33 | + pub struct ShutterApplication {} |
31 | 34 |
|
32 |
| - #[derive(Debug, Default)] |
33 |
| - pub struct ShutterApplication {} |
| 35 | + #[glib::object_subclass] |
| 36 | + impl ObjectSubclass for ShutterApplication { |
| 37 | + type ParentType = adw::Application; |
| 38 | + type Type = super::ShutterApplication; |
34 | 39 |
|
35 |
| - #[glib::object_subclass] |
36 |
| - impl ObjectSubclass for ShutterApplication { |
37 |
| - const NAME: &'static str = "ShutterApplication"; |
38 |
| - type Type = super::ShutterApplication; |
39 |
| - type ParentType = adw::Application; |
40 |
| - } |
| 40 | + const NAME: &'static str = "ShutterApplication"; |
| 41 | + } |
41 | 42 |
|
42 |
| - impl ObjectImpl for ShutterApplication { |
43 |
| - fn constructed(&self) { |
44 |
| - self.parent_constructed(); |
45 |
| - let obj = self.obj(); |
46 |
| - obj.setup_gactions(); |
47 |
| - obj.set_accels_for_action("app.quit", &["<primary>q"]); |
48 |
| - } |
49 |
| - } |
| 43 | + impl ObjectImpl for ShutterApplication { |
| 44 | + fn constructed(&self) { |
| 45 | + self.parent_constructed(); |
| 46 | + let obj = self.obj(); |
| 47 | + obj.setup_gactions(); |
| 48 | + obj.set_accels_for_action("app.quit", &["<primary>q"]); |
| 49 | + } |
| 50 | + } |
50 | 51 |
|
51 |
| - impl ApplicationImpl for ShutterApplication { |
52 |
| - // We connect to the activate callback to create a window when the application |
53 |
| - // has been launched. Additionally, this callback notifies us when the user |
54 |
| - // tries to launch a "second instance" of the application. When they try |
55 |
| - // to do that, we'll just present any existing window. |
56 |
| - fn activate(&self) { |
57 |
| - let application = self.obj(); |
58 |
| - // Get the current window or create one if necessary |
59 |
| - let window = if let Some(window) = application.active_window() { |
60 |
| - window |
61 |
| - } else { |
62 |
| - let window = ShutterWindow::new(&*application); |
63 |
| - window.upcast() |
64 |
| - }; |
| 52 | + impl ApplicationImpl for ShutterApplication { |
| 53 | + // We connect to the activate callback to create a window when the application |
| 54 | + // has been launched. Additionally, this callback notifies us when the user |
| 55 | + // tries to launch a "second instance" of the application. When they try |
| 56 | + // to do that, we'll just present any existing window. |
| 57 | + fn activate(&self) { |
| 58 | + let application = self.obj(); |
| 59 | + // Get the current window or create one if necessary |
| 60 | + let window = if let Some(window) = application.active_window() { |
| 61 | + window |
| 62 | + } else { |
| 63 | + let window = ShutterWindow::new(&*application); |
| 64 | + window.upcast() |
| 65 | + }; |
65 | 66 |
|
66 |
| - // Ask the window manager/compositor to present the window |
67 |
| - window.present(); |
68 |
| - } |
69 |
| - } |
| 67 | + // Ask the window manager/compositor to present the window |
| 68 | + window.present(); |
| 69 | + } |
| 70 | + } |
70 | 71 |
|
71 |
| - impl GtkApplicationImpl for ShutterApplication {} |
72 |
| - impl AdwApplicationImpl for ShutterApplication {} |
73 |
| - } |
| 72 | + impl GtkApplicationImpl for ShutterApplication {} |
| 73 | + impl AdwApplicationImpl for ShutterApplication {} |
| 74 | +} |
74 | 75 |
|
75 | 76 | glib::wrapper! {
|
76 |
| - pub struct ShutterApplication(ObjectSubclass<imp::ShutterApplication>) |
77 |
| - @extends gio::Application, gtk::Application, adw::Application, |
78 |
| - @implements gio::ActionGroup, gio::ActionMap; |
| 77 | + pub struct ShutterApplication(ObjectSubclass<imp::ShutterApplication>) |
| 78 | + @extends gio::Application, gtk::Application, adw::Application, |
| 79 | + @implements gio::ActionGroup, gio::ActionMap; |
79 | 80 | }
|
80 | 81 |
|
81 | 82 | impl ShutterApplication {
|
82 |
| - pub fn new(application_id: &str, flags: &gio::ApplicationFlags) -> Self { |
83 |
| - glib::Object::builder() |
84 |
| - .property("application-id", application_id) |
85 |
| - .property("flags", flags) |
86 |
| - .build() |
87 |
| - } |
| 83 | + pub fn new(application_id: &str, flags: &gio::ApplicationFlags) -> Self { |
| 84 | + glib::Object::builder() |
| 85 | + .property("application-id", application_id) |
| 86 | + .property("flags", flags) |
| 87 | + .build() |
| 88 | + } |
88 | 89 |
|
89 |
| - fn setup_gactions(&self) { |
90 |
| - let quit_action = gio::ActionEntry::builder("quit") |
91 |
| - .activate(move |app: &Self, _, _| app.quit()) |
92 |
| - .build(); |
93 |
| - let about_action = gio::ActionEntry::builder("about") |
94 |
| - .activate(move |app: &Self, _, _| app.show_about()) |
95 |
| - .build(); |
96 |
| - self.add_action_entries([quit_action, about_action]); |
97 |
| - } |
| 90 | + fn setup_gactions(&self) { |
| 91 | + let quit_action = gio::ActionEntry::builder("quit") |
| 92 | + .activate(move |app: &Self, _, _| app.quit()) |
| 93 | + .build(); |
| 94 | + let about_action = gio::ActionEntry::builder("about") |
| 95 | + .activate(move |app: &Self, _, _| app.show_about()) |
| 96 | + .build(); |
| 97 | + self.add_action_entries([quit_action, about_action]); |
| 98 | + } |
98 | 99 |
|
99 |
| - fn show_about(&self) { |
100 |
| - let window = self.active_window().unwrap(); |
101 |
| - let about = adw::AboutDialog::builder() |
102 |
| - .application_icon("shutter") |
103 |
| - // TODO remove extra icons |
104 |
| - .application_icon("org.shutter-project.Shutter") |
105 |
| - .application_icon("shutter") |
106 |
| - .version(VERSION) |
107 |
| - .website("https://shutter-project.org") |
108 |
| - .issue_url("https://github.com/shutter-project/shutter/issues") |
109 |
| - .license_type(gtk::License::Gpl30) |
110 |
| - .artists(String::from_utf8(gio::resources_lookup_data("/org/shutter-project/Shutter/credits/art", gio::ResourceLookupFlags::empty()).expect("no artist data").to_vec()).expect("can't convert artists to utf8").lines().collect::<Vec<_>>()) |
111 |
| - .developers(String::from_utf8(gio::resources_lookup_data("/org/shutter-project/Shutter/credits/dev", gio::ResourceLookupFlags::empty()).expect("no dev data").to_vec()).expect("can't convert devs to utf8").lines().collect::<Vec<_>>()) |
112 |
| - .copyright(String::from_utf8(gio::resources_lookup_data("/org/shutter-project/Shutter/credits/copyright", gio::ResourceLookupFlags::empty()).expect("no copyright data").to_vec()).expect("can't convert copyright to utf8")) |
113 |
| - .build(); |
| 100 | + fn show_about(&self) { |
| 101 | + let window = self.active_window().unwrap(); |
| 102 | + let about = adw::AboutDialog::builder() |
| 103 | + .application_icon("shutter") |
| 104 | + // TODO remove extra icons |
| 105 | + .application_icon("org.shutter-project.Shutter") |
| 106 | + .application_icon("shutter") |
| 107 | + .version(VERSION) |
| 108 | + .website("https://shutter-project.org") |
| 109 | + .issue_url("https://github.com/shutter-project/shutter/issues") |
| 110 | + .license_type(gtk::License::Gpl30) |
| 111 | + .artists( |
| 112 | + String::from_utf8( |
| 113 | + gio::resources_lookup_data( |
| 114 | + "/org/shutter-project/Shutter/credits/art", |
| 115 | + gio::ResourceLookupFlags::empty(), |
| 116 | + ) |
| 117 | + .expect("no artist data") |
| 118 | + .to_vec(), |
| 119 | + ) |
| 120 | + .expect("can't convert artists to utf8") |
| 121 | + .lines() |
| 122 | + .collect::<Vec<_>>(), |
| 123 | + ) |
| 124 | + .developers( |
| 125 | + String::from_utf8( |
| 126 | + gio::resources_lookup_data( |
| 127 | + "/org/shutter-project/Shutter/credits/dev", |
| 128 | + gio::ResourceLookupFlags::empty(), |
| 129 | + ) |
| 130 | + .expect("no dev data") |
| 131 | + .to_vec(), |
| 132 | + ) |
| 133 | + .expect("can't convert devs to utf8") |
| 134 | + .lines() |
| 135 | + .collect::<Vec<_>>(), |
| 136 | + ) |
| 137 | + .copyright( |
| 138 | + String::from_utf8( |
| 139 | + gio::resources_lookup_data( |
| 140 | + "/org/shutter-project/Shutter/credits/copyright", |
| 141 | + gio::ResourceLookupFlags::empty(), |
| 142 | + ) |
| 143 | + .expect("no copyright data") |
| 144 | + .to_vec(), |
| 145 | + ) |
| 146 | + .expect("can't convert copyright to utf8"), |
| 147 | + ) |
| 148 | + .build(); |
114 | 149 |
|
115 |
| - about.present(Some(&window)); |
116 |
| - } |
| 150 | + about.present(Some(&window)); |
| 151 | + } |
117 | 152 | }
|
0 commit comments