-
-
Notifications
You must be signed in to change notification settings - Fork 78
Background: Use GLib.File instead of dealing with Paths #1711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,20 +17,20 @@ | |
|
|
||
| namespace Gala { | ||
| public class Animation : Object { | ||
| public string filename { get; construct; } | ||
| public string[] key_frame_files { get; private set; default = {}; } | ||
| public GLib.File file { get; construct; } | ||
| public GLib.GenericArray<GLib.File> key_frame_files { get; private set; default = new GLib.GenericArray<GLib.File> (); } | ||
| public double transition_progress { get; private set; default = 0.0; } | ||
| public double transition_duration { get; private set; default = 0.0; } | ||
| public bool loaded { get; private set; default = false; } | ||
|
|
||
| private Gnome.BGSlideShow? show = null; | ||
|
|
||
| public Animation (string filename) { | ||
| Object (filename: filename); | ||
| public Animation (GLib.File file) { | ||
| Object (file: file); | ||
| } | ||
|
|
||
| public async void load () { | ||
| show = new Gnome.BGSlideShow (filename); | ||
| show = new Gnome.BGSlideShow (file.get_path ()); | ||
|
|
||
| show.load_async (null, (obj, res) => { | ||
| loaded = true; | ||
|
|
@@ -42,7 +42,7 @@ namespace Gala { | |
| } | ||
|
|
||
| public void update (Meta.Rectangle monitor) { | ||
| string[] key_frame_files = {}; | ||
| var new_key_frame_files = new GLib.GenericArray<GLib.File> (); | ||
|
|
||
| if (show == null) | ||
| return; | ||
|
|
@@ -52,19 +52,21 @@ namespace Gala { | |
|
|
||
| double progress, duration; | ||
| bool is_fixed; | ||
| string file1, file2; | ||
| unowned string? file1, file2; | ||
| show.get_current_slide (monitor.width, monitor.height, out progress, out duration, out is_fixed, out file1, out file2); | ||
|
|
||
| transition_duration = duration; | ||
| transition_progress = progress; | ||
|
|
||
| if (file1 != null) | ||
| key_frame_files += file1; | ||
| if (file1 != null) { | ||
| new_key_frame_files.add (GLib.File.new_for_path (file1)); | ||
| } | ||
|
|
||
| if (file2 != null) | ||
| key_frame_files += file2; | ||
| if (file2 != null) { | ||
| new_key_frame_files.add (GLib.File.new_for_path (file2)); | ||
| } | ||
|
|
||
| this.key_frame_files = key_frame_files; | ||
| this.key_frame_files = new_key_frame_files; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't think the |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,39 +28,39 @@ namespace Gala { | |||||||||||
| public BackgroundSource background_source { get; construct; } | ||||||||||||
| public bool is_loaded { get; private set; default = false; } | ||||||||||||
| public GDesktop.BackgroundStyle style { get; construct; } | ||||||||||||
| public string? filename { get; construct; } | ||||||||||||
| public GLib.File? file { get; construct; } | ||||||||||||
| public Meta.Background background { get; private set; } | ||||||||||||
|
|
||||||||||||
| private Animation? animation = null; | ||||||||||||
| private Gee.HashMap<string,ulong> file_watches; | ||||||||||||
| private Gee.HashMap<GLib.File, ulong> file_watches; | ||||||||||||
| private Cancellable cancellable; | ||||||||||||
| private uint update_animation_timeout_id = 0; | ||||||||||||
|
|
||||||||||||
| private Gnome.WallClock clock; | ||||||||||||
| private ulong clock_timezone_handler = 0; | ||||||||||||
|
|
||||||||||||
| public Background (Meta.Display display, int monitor_index, string? filename, | ||||||||||||
| public Background (Meta.Display display, int monitor_index, GLib.File? file, | ||||||||||||
| BackgroundSource background_source, GDesktop.BackgroundStyle style) { | ||||||||||||
| Object (display: display, | ||||||||||||
| monitor_index: monitor_index, | ||||||||||||
| background_source: background_source, | ||||||||||||
| style: style, | ||||||||||||
| filename: filename); | ||||||||||||
| file: file); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| construct { | ||||||||||||
| background = new Meta.Background (display); | ||||||||||||
| background.set_data<unowned Background> ("delegate", this); | ||||||||||||
|
|
||||||||||||
| file_watches = new Gee.HashMap<string,ulong> (); | ||||||||||||
| file_watches = new Gee.HashMap<GLib.File, ulong> (); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||||||||||||
| cancellable = new Cancellable (); | ||||||||||||
|
|
||||||||||||
| background_source.changed.connect (settings_changed); | ||||||||||||
|
|
||||||||||||
| clock = new Gnome.WallClock (); | ||||||||||||
| clock_timezone_handler = clock.notify["timezone"].connect (() => { | ||||||||||||
| if (animation != null) { | ||||||||||||
| load_animation.begin (animation.filename); | ||||||||||||
| load_animation.begin (animation.file); | ||||||||||||
| } | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
|
|
@@ -121,18 +121,18 @@ namespace Gala { | |||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private void watch_file (string filename) { | ||||||||||||
| if (file_watches.has_key (filename)) | ||||||||||||
| private void watch_file (GLib.File file) { | ||||||||||||
| if (file_watches.has_key (file)) | ||||||||||||
| return; | ||||||||||||
|
Comment on lines
+125
to
126
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code style.
Suggested change
|
||||||||||||
|
|
||||||||||||
| var cache = BackgroundCache.get_default (); | ||||||||||||
|
|
||||||||||||
| cache.monitor_file (filename); | ||||||||||||
| cache.monitor_file (file); | ||||||||||||
|
|
||||||||||||
| file_watches[filename] = cache.file_changed.connect ((changed_file) => { | ||||||||||||
| if (changed_file == filename) { | ||||||||||||
| file_watches[file] = cache.file_changed.connect ((changed_file) => { | ||||||||||||
| if (changed_file == file) { | ||||||||||||
| var image_cache = Meta.BackgroundImageCache.get_default (); | ||||||||||||
| image_cache.purge (File.new_for_path (changed_file)); | ||||||||||||
| image_cache.purge (changed_file); | ||||||||||||
| changed (); | ||||||||||||
| } | ||||||||||||
| }); | ||||||||||||
|
|
@@ -145,13 +145,13 @@ namespace Gala { | |||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private void finish_animation (string[] files) { | ||||||||||||
| private void finish_animation (GLib.GenericArray<GLib.File> files) { | ||||||||||||
| set_loaded (); | ||||||||||||
|
|
||||||||||||
| if (files.length > 1) | ||||||||||||
| background.set_blend (File.new_for_path (files[0]), File.new_for_path (files[1]), animation.transition_progress, style); | ||||||||||||
| background.set_blend (files[0], files[1], animation.transition_progress, style); | ||||||||||||
| else if (files.length > 0) | ||||||||||||
| background.set_file (File.new_for_path (files[0]), style); | ||||||||||||
| background.set_file (files[0], style); | ||||||||||||
| else | ||||||||||||
| background.set_file (null, style); | ||||||||||||
|
|
||||||||||||
|
|
@@ -164,12 +164,12 @@ namespace Gala { | |||||||||||
| animation.update (display.get_monitor_geometry (monitor_index)); | ||||||||||||
| var files = animation.key_frame_files; | ||||||||||||
|
|
||||||||||||
| var cache = Meta.BackgroundImageCache.get_default (); | ||||||||||||
| unowned var cache = Meta.BackgroundImageCache.get_default (); | ||||||||||||
| var num_pending_images = files.length; | ||||||||||||
| for (var i = 0; i < files.length; i++) { | ||||||||||||
| watch_file (files[i]); | ||||||||||||
| foreach (unowned var file in files) { | ||||||||||||
| watch_file (file); | ||||||||||||
|
|
||||||||||||
| var image = cache.load (File.new_for_path (files[i])); | ||||||||||||
| var image = cache.load (file); | ||||||||||||
|
|
||||||||||||
| if (image.is_loaded ()) { | ||||||||||||
| num_pending_images--; | ||||||||||||
|
|
@@ -213,24 +213,24 @@ namespace Gala { | |||||||||||
| }); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private async void load_animation (string filename) { | ||||||||||||
| animation = yield BackgroundCache.get_default ().get_animation (filename); | ||||||||||||
| private async void load_animation (GLib.File file) { | ||||||||||||
| animation = yield BackgroundCache.get_default ().get_animation (file); | ||||||||||||
|
|
||||||||||||
| if (animation == null || cancellable.is_cancelled ()) { | ||||||||||||
| set_loaded (); | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| update_animation (); | ||||||||||||
| watch_file (filename); | ||||||||||||
| watch_file (file); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private void load_image (string filename) { | ||||||||||||
| background.set_file (File.new_for_path (filename), style); | ||||||||||||
| watch_file (filename); | ||||||||||||
| private void load_image (GLib.File file) { | ||||||||||||
| background.set_file (file, style); | ||||||||||||
| watch_file (file); | ||||||||||||
|
|
||||||||||||
| var cache = Meta.BackgroundImageCache.get_default (); | ||||||||||||
| var image = cache.load (File.new_for_path (filename)); | ||||||||||||
| var image = cache.load (file); | ||||||||||||
| if (image.is_loaded ()) | ||||||||||||
| set_loaded (); | ||||||||||||
| else { | ||||||||||||
|
|
@@ -242,20 +242,22 @@ namespace Gala { | |||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private void load_file (string filename) { | ||||||||||||
| if (filename.has_suffix (".xml")) | ||||||||||||
| load_animation.begin (filename); | ||||||||||||
| else | ||||||||||||
| load_image (filename); | ||||||||||||
| private inline void load_file (GLib.File file) { | ||||||||||||
| if (file.get_basename ().has_suffix (".xml")) { | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we should use |
||||||||||||
| load_animation.begin (file); | ||||||||||||
| } else { | ||||||||||||
| load_image (file); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private void load () { | ||||||||||||
| load_pattern (); | ||||||||||||
|
|
||||||||||||
| if (filename == null) | ||||||||||||
| if (file == null) { | ||||||||||||
| set_loaded (); | ||||||||||||
| else | ||||||||||||
| load_file (filename); | ||||||||||||
| } else { | ||||||||||||
| load_file (file); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private void settings_changed () { | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,26 +87,26 @@ namespace Gala { | |
| } | ||
|
|
||
| public Background get_background (int monitor_index) { | ||
| string? filename = null; | ||
| GLib.File? file = null; | ||
|
|
||
| var style = settings.get_enum ("picture-options"); | ||
| if (style != GDesktop.BackgroundStyle.NONE) { | ||
| var uri = settings.get_string ("picture-uri"); | ||
| if (Uri.parse_scheme (uri) != null) | ||
| filename = File.new_for_uri (uri).get_path (); | ||
| file = File.new_for_uri (uri); | ||
| else | ||
| filename = uri; | ||
| file = File.new_for_path (uri); | ||
| } | ||
|
|
||
| // Animated backgrounds are (potentially) per-monitor, since | ||
| // they can have variants that depend on the aspect ratio and | ||
| // size of the monitor; for other backgrounds we can use the | ||
| // same background object for all monitors. | ||
| if (filename == null || !filename.has_suffix (".xml")) | ||
| if (file == null || !file.get_basename ().has_suffix (".xml")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here, should check the mimetype instead of extension. |
||
| monitor_index = 0; | ||
|
|
||
| if (!backgrounds.has_key (monitor_index)) { | ||
| var background = new Background (display, monitor_index, filename, this, (GDesktop.BackgroundStyle) style); | ||
| var background = new Background (display, monitor_index, file, this, (GDesktop.BackgroundStyle) style); | ||
| background.changed.connect (background_changed); | ||
| backgrounds[monitor_index] = background; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be a GenericArray? given that we known that the max number of files we will use is 2, isn't a fixed array enough.