summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-06-28 21:35:52 +0200
committerJörg Frings-Fürst <debian@jff.email>2023-06-28 21:35:52 +0200
commitb86540b743f1a87a163ffb811c8fe22a01fefa38 (patch)
treeb47cb3bb83c2377234226fb3987ab3320a987dd9 /src/util
parentac6e0b731b9f0b2efd392e3309a5c07e2a66adad (diff)
parente905d8e16eec152d19797937f13ba3cf4b8f8aca (diff)
Merge branch 'release/debian/0.32.1-1'debian/0.32.1-1
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Util.vala2
-rw-r--r--src/util/file.vala26
-rw-r--r--src/util/image.vala8
-rw-r--r--src/util/misc.vala30
-rw-r--r--src/util/string.vala14
-rw-r--r--src/util/system.vala5
-rw-r--r--src/util/ui.vala11
7 files changed, 44 insertions, 52 deletions
diff --git a/src/util/Util.vala b/src/util/Util.vala
index b87ea3a..45943d7 100644
--- a/src/util/Util.vala
+++ b/src/util/Util.vala
@@ -8,6 +8,8 @@ namespace Util {
// Use these file attributes when loading file information for a complete FileInfo objects
public const string FILE_ATTRIBUTES = "standard::*,time::*,id::file,id::filesystem,etag::value";
+ public const int64 USEC_PER_SEC = 1000000;
+
public void init() throws Error {
}
diff --git a/src/util/file.vala b/src/util/file.vala
index c1ee06d..652a141 100644
--- a/src/util/file.vala
+++ b/src/util/file.vala
@@ -31,9 +31,11 @@ public bool claim_file(File file) throws Error {
// same or similar as what has been requested (adds numerals to the end of the name until a unique
// one has been found). The file may exist when this function returns, and it should be
// overwritten. It does *not* attempt to create the parent directory, however.
+// The used parameter allows you to pass in a collection of names which should be deemed to be
+// already claimed but which may not yet exist in the file system.
//
// This function is thread-safe.
-public File? generate_unique_file(File dir, string basename, out bool collision) throws Error {
+public File? generate_unique_file(File dir, string basename, out bool collision, Gee.Collection<string>? used = null) throws Error {
// create the file to atomically "claim" it
File file = dir.get_child(basename);
if (claim_file(file)) {
@@ -51,7 +53,9 @@ public File? generate_unique_file(File dir, string basename, out bool collision)
// generate a unique filename
for (int ctr = 1; ctr < int.MAX; ctr++) {
string new_name = (ext != null) ? "%s_%d.%s".printf(name, ctr, ext) : "%s_%d".printf(name, ctr);
-
+ if (used != null && used.contains(new_name)) {
+ continue;
+ }
file = dir.get_child(new_name);
if (claim_file(file))
return file;
@@ -151,11 +155,11 @@ public void delete_all_files(File dir, Gee.Set<string>? exceptions = null, Progr
}
}
-public time_t query_file_modified(File file) throws Error {
+public DateTime query_file_modified(File file) throws Error {
FileInfo info = file.query_info(FileAttribute.TIME_MODIFIED, FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
null);
- return info.get_modification_time().tv_sec;
+ return info.get_modification_date_time();
}
public bool query_is_directory(File file) {
@@ -199,20 +203,6 @@ public string? get_file_info_id(FileInfo info) {
return info.get_attribute_string(FileAttribute.ID_FILE);
}
-// Breaks a uint64 skip amount into several smaller skips.
-public void skip_uint64(InputStream input, uint64 skip_amount) throws GLib.Error {
- while (skip_amount > 0) {
- // skip() throws an error if the amount is too large, so check against ssize_t.MAX
- if (skip_amount >= ssize_t.MAX) {
- input.skip(ssize_t.MAX);
- skip_amount -= ssize_t.MAX;
- } else {
- input.skip((size_t) skip_amount);
- skip_amount = 0;
- }
- }
-}
-
// Returns the number of files (and/or directories) within a directory.
public uint64 count_files_in_directory(File dir) throws GLib.Error {
if (!query_is_directory(dir))
diff --git a/src/util/image.vala b/src/util/image.vala
index 0a30339..95ac998 100644
--- a/src/util/image.vala
+++ b/src/util/image.vala
@@ -343,7 +343,7 @@ private Cairo.Surface get_background_surface() {
string color_b;
var config = Config.Facade.get_instance();
- var type = config.get_transparent_background_type();
+ var type = "checkered"; //config.get_transparent_background_type();
switch (type) {
case "checkered":
color_a = "#808080";
@@ -386,7 +386,8 @@ public void paint_pixmap_with_background (Cairo.Context ctx, Gdk.Pixbuf pixbuf,
}
Gdk.cairo_set_source_pixbuf(ctx, pixbuf, x, y);
- ctx.paint();
+ ctx.rectangle(x, y, pixbuf.width , pixbuf.height);
+ ctx.fill();
}
// Force an axially-aligned box to be inside a rotated rectangle.
@@ -422,3 +423,6 @@ Box clamp_inside_rotated_image(Box src, int img_w, int img_h, double angle_deg,
src.right + right_offset, src.bottom + bottom_offset);
}
+double degrees_to_radians(double theta) {
+ return (theta * (GLib.Math.PI / 180.0));
+}
diff --git a/src/util/misc.vala b/src/util/misc.vala
index 6111ea3..2106621 100644
--- a/src/util/misc.vala
+++ b/src/util/misc.vala
@@ -54,22 +54,12 @@ public bool int_value_equals(Value a, Value b) {
return (int) a == (int) b;
}
-public ulong timeval_to_ms(TimeVal time_val) {
- return (((ulong) time_val.tv_sec) * 1000) + (((ulong) time_val.tv_usec) / 1000);
-}
-
public ulong now_ms() {
- return timeval_to_ms(TimeVal());
-}
-
-public ulong now_sec() {
- TimeVal time_val = TimeVal();
-
- return time_val.tv_sec;
+ return (ulong) (GLib.get_real_time() / 1000);
}
-public inline time_t now_time_t() {
- return (time_t) now_sec();
+public int64 now_sec() {
+ return (ulong) (GLib.get_real_time() / Util.USEC_PER_SEC);
}
public string md5_file(File file) throws Error {
@@ -216,14 +206,16 @@ public Gee.List<MediaSource>? unserialize_media_sources(uchar* serialized, int s
return list;
}
-public string format_local_datespan(Time from_date, Time to_date) {
+public string format_local_datespan(DateTime from_date, DateTime to_date) {
string from_format, to_format;
// Ticket #3240 - Change the way date ranges are pretty-
// printed if the start and end date occur on consecutive days.
- if (from_date.year == to_date.year) {
+ if (from_date.get_year() == to_date.get_year()) {
// are these consecutive dates?
- if ((from_date.month == to_date.month) && (from_date.day == (to_date.day - 1))) {
+ // get_day_of_year() looks like it saves a bit of code, but then we would
+ // not recognize the change of months
+ if ((from_date.get_month() == to_date.get_month()) && (from_date.get_day_of_month() == (to_date.get_day_of_month() - 1))) {
// Yes; display like so: Sat, July 4 - 5, 20X6
from_format = Resources.get_start_multiday_span_format_string();
to_format = Resources.get_end_multiday_span_format_string();
@@ -244,7 +236,7 @@ public string format_local_datespan(Time from_date, Time to_date) {
to_date.format(to_format)));
}
-public string format_local_date(Time date) {
+public string format_local_date(DateTime date) {
return String.strip_leading_zeroes(date.format(Resources.get_long_date_format_string()));
}
@@ -273,7 +265,9 @@ public class OneShotScheduler {
}
public void at_idle() {
- at_priority_idle(Priority.DEFAULT_IDLE);
+ // needs to be lower (higher priority) than Clutter.PRIORITY_REDRAW which is
+ // set at Priority.HIGH_IDLE + 50
+ at_priority_idle(Priority.HIGH_IDLE + 40);
}
public void at_priority_idle(int priority) {
diff --git a/src/util/string.vala b/src/util/string.vala
index bf7e605..89424d0 100644
--- a/src/util/string.vala
+++ b/src/util/string.vala
@@ -13,13 +13,13 @@ public inline bool is_string_empty(string? s) {
}
// utf8 case sensitive compare
-public int utf8_cs_compare(void *a, void *b) {
- return ((string) a).collate((string) b);
+public int utf8_cs_compare(string a, string b) {
+ return a.collate(b);
}
// utf8 case insensitive compare
-public int utf8_ci_compare(void *a, void *b) {
- return ((string) a).down().collate(((string) b).down());
+public int utf8_ci_compare(string a, string b) {
+ return a.down().collate(b.down());
}
// utf8 array to string
@@ -145,7 +145,7 @@ public string? prepare_input_text(string? text, PrepareInputTextOptions options,
// Using composed form rather than GLib's default (decomposed) as NFC is the preferred form in
// Linux and WWW. More importantly, Pango seems to have serious problems displaying decomposed
// forms of Korean language glyphs (and perhaps others). See:
- // http://trac.yorba.org/ticket/2952
+ // https://bugzilla.gnome.org/show_bug.cgi?id=716914
if ((options & PrepareInputTextOptions.NORMALIZE) != 0)
prepped = prepped.normalize(-1, NormalizeMode.NFC);
@@ -237,6 +237,8 @@ public string remove_diacritics(string istring) {
case UnicodeType.ENCLOSING_MARK:
// Ignore those
continue;
+ default:
+ break;
}
builder.append_unichar(ch);
}
@@ -255,7 +257,7 @@ public string to_hex_string(string str) {
// A note on the collated_* and precollated_* methods:
//
-// A bug report (http://trac.yorba.org/ticket/3152) indicated that two different Hirigana characters
+// A bug report (https://bugzilla.gnome.org/show_bug.cgi?id=717135) indicated that two different Hirigana characters
// as Tag names would trigger an assertion. Investigation showed that the characters' collation
// keys computed as equal when the locale was set to anything but the default locale (C) or
// Japanese. A related bug was that another hash table was using str_equal, which does not use
diff --git a/src/util/system.vala b/src/util/system.vala
index 1e69304..48e2cc9 100644
--- a/src/util/system.vala
+++ b/src/util/system.vala
@@ -6,7 +6,7 @@
// Return the directory in which Shotwell is installed, or null if uninstalled.
File? get_sys_install_dir(File exec_dir) {
- // Assume that if the ui folder lives next to the binary, we runn in-tree
+ // Assume that if the ui folder lives next to the binary, we run in-tree
File child = exec_dir.get_child("ui");
if (!FileUtils.test(child.get_path(), FileTest.IS_DIR | FileTest.EXISTS)) {
@@ -39,7 +39,8 @@ async void show_file_in_filemanager(File file) throws Error {
DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
DBusProxyFlags.DO_NOT_CONNECT_SIGNALS);
var id = "%s_%s_%d_%s".printf(Environment.get_prgname(), Environment.get_host_name(),
- Posix.getpid(), TimeVal().to_iso8601());
+ Posix.getpid(),
+ GLib.get_monotonic_time().to_string());
yield manager.show_items({file.get_uri()}, id);
} catch (Error e) {
warning("Failed to launch file manager using DBus, using fall-back: %s", e.message);
diff --git a/src/util/ui.vala b/src/util/ui.vala
index 6d32738..bdc7157 100644
--- a/src/util/ui.vala
+++ b/src/util/ui.vala
@@ -60,7 +60,7 @@ public Gdk.Rectangle get_adjustment_page(Gtk.Adjustment hadj, Gtk.Adjustment vad
}
// Verifies that only the mask bits are set in the modifier field, disregarding mouse and
-// key modifers that are not normally of concern (i.e. Num Lock, Caps Lock, etc.). Mask can be
+// key modifiers that are not normally of concern (i.e. Num Lock, Caps Lock, etc.). Mask can be
// one or more bits set, but should only consist of these values:
// * Gdk.ModifierType.SHIFT_MASK
// * Gdk.ModifierType.CONTROL_MASK
@@ -87,16 +87,15 @@ public bool has_only_key_modifier(Gdk.ModifierType field, Gdk.ModifierType mask)
}
bool is_pointer_over(Gdk.Window window) {
- Gdk.DeviceManager? devmgr = window.get_display().get_device_manager();
- if (devmgr == null) {
- debug("No device for display");
+ var seat = window.get_display().get_default_seat();
+ if (seat == null) {
+ debug("No seat for display");
return false;
}
int x, y;
- devmgr.get_client_pointer().get_position(null, out x, out y);
- //gdk_device_get_position(devmgr.get_client_pointer(), null, out x, out y);
+ seat.get_pointer().get_position(null, out x, out y);
return x >= 0 && y >= 0 && x < window.get_width() && y < window.get_height();
}