After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 734946 - Implement GContentType on OSX
Implement GContentType on OSX
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other Mac OS
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
: 781642 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2014-08-17 13:52 UTC by Patrick Griffis (tingping)
Modified: 2018-01-05 11:05 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[PATCH] Implement GContentType on OSX (16.57 KB, patch)
2014-08-17 13:52 UTC, Patrick Griffis (tingping)
none Details | Review
[PATCH] GLib - Fix GContentType usage (1.55 KB, patch)
2014-08-17 13:54 UTC, Patrick Griffis (tingping)
committed Details | Review
[PATCH] Gtk3 - Fix GContentType usage (8.00 KB, patch)
2014-08-17 13:54 UTC, Patrick Griffis (tingping)
reviewed Details | Review
[PATCH] Gtk2 - Fix GContentType usage (2.42 KB, patch)
2014-08-17 13:55 UTC, Patrick Griffis (tingping)
committed Details | Review
Create g_content_type_is_mime_type() (3.36 KB, patch)
2014-08-21 09:03 UTC, Patrick Griffis (tingping)
none Details | Review
Create g_content_type_is_mime_type() (3.36 KB, patch)
2014-08-21 09:11 UTC, Patrick Griffis (tingping)
reviewed Details | Review
Gtk3 - Improve GContentType usage (6.77 KB, patch)
2014-08-21 10:15 UTC, Patrick Griffis (tingping)
committed Details | Review
Implement GContentType on OSX (15.80 KB, patch)
2014-08-21 10:45 UTC, Patrick Griffis (tingping)
committed Details | Review
Create g_content_type_is_mime_type() (3.33 KB, patch)
2014-08-21 10:45 UTC, Patrick Griffis (tingping)
committed Details | Review
Implement GContentType on OS X (15.16 KB, patch)
2017-03-09 11:44 UTC, Matthias Clasen
none Details | Review
gtk osx build fix (1.54 KB, patch)
2017-03-14 20:04 UTC, Christoph Reiter (lazka)
committed Details | Review
gosxappinfo: Fix launching default applications (972 bytes, patch)
2017-03-15 05:25 UTC, Patrick Griffis (tingping)
committed Details | Review
gosxappinfo: fix typo in url_escape_hostname (775 bytes, patch)
2017-03-15 07:41 UTC, Christoph Reiter (lazka)
committed Details | Review
gosxappinfo: fix typo in g_osx_app_info_launch_internal (923 bytes, patch)
2017-03-30 23:57 UTC, Rafal Luzynski
none Details | Review
gosxappinfo: Fix get_default_for_type() on 10.10+ (2.41 KB, patch)
2017-03-31 00:18 UTC, Patrick Griffis (tingping)
committed Details | Review
gosxappinfo: Special case x-scheme-handler (2.40 KB, patch)
2017-03-31 00:19 UTC, Patrick Griffis (tingping)
committed Details | Review
gosxappinfo: fix typo in g_osx_app_info_launch_internal (v2) (1.09 KB, patch)
2017-03-31 09:18 UTC, Rafal Luzynski
committed Details | Review
Verify presence of new interface (782 bytes, patch)
2017-04-24 05:44 UTC, Daniel Macks
committed Details | Review
Add missing function for OS X (1.19 KB, patch)
2017-04-24 05:58 UTC, Daniel Macks
committed Details | Review

Description Patrick Griffis (tingping) 2014-08-17 13:52:40 UTC
Created attachment 283645 [details] [review]
[PATCH] Implement GContentType on OSX

Implements GContentType using UTI's on OSX. This closes bug #543129 .

I based the name of the file off of the gsettings backend so let me know if you would prefer a different naming scheme. I plan on implementing a few more things on OSX.

I also will attach some patches that fix usage of this API in glib and gtk.
Comment 1 Patrick Griffis (tingping) 2014-08-17 13:54:21 UTC
Created attachment 283646 [details] [review]
[PATCH] GLib - Fix GContentType usage
Comment 2 Patrick Griffis (tingping) 2014-08-17 13:54:52 UTC
Created attachment 283647 [details] [review]
[PATCH] Gtk3 - Fix GContentType usage
Comment 3 Patrick Griffis (tingping) 2014-08-17 13:55:22 UTC
Created attachment 283648 [details] [review]
[PATCH] Gtk2 - Fix GContentType usage
Comment 4 Matthias Clasen 2014-08-17 15:13:12 UTC
Review of attachment 283646 [details] [review]:

Ok
Comment 5 Matthias Clasen 2014-08-17 15:18:20 UTC
Review of attachment 283647 [details] [review]:

This is a little annoying to do everywhere; maybe we should introduce some convenience api like g_content_type_is_mime() ?
Comment 6 Patrick Griffis (tingping) 2014-08-18 00:37:26 UTC
> This is a little annoying to do everywhere; maybe we should introduce some
> convenience api like g_content_type_is_mime() ?

That would indeed be cleaner, would you like me to add a patch for that here?
Comment 7 Matthias Clasen 2014-08-20 22:52:15 UTC
(In reply to comment #6)
 
> That would indeed be cleaner, would you like me to add a patch for that here?

that would be nice
Comment 8 Patrick Griffis (tingping) 2014-08-21 09:03:14 UTC
Created attachment 284064 [details] [review]
Create g_content_type_is_mime_type()
Comment 9 Patrick Griffis (tingping) 2014-08-21 09:11:53 UTC
Created attachment 284065 [details] [review]
Create g_content_type_is_mime_type()
Comment 10 Emmanuele Bassi (:ebassi) 2014-08-21 09:33:56 UTC
Review of attachment 284065 [details] [review]:

looks good, except for annotation and coding style issues.

::: gio/gcontenttype-win32.c
@@ +135,3 @@
+                             const gchar *mime_type)
+{
+    gchar *content_type;

coding style: wrong indentation level.

::: gio/gcontenttype.c
@@ +175,3 @@
+ *     %FALSE otherwise.
+ *
+ * Since: 2.40

this should be "Since: 2.42"

@@ +181,3 @@
+                             const gchar *mime_type)
+{
+    return g_content_type_is_a (type, mime_type);

coding style: wrong indentation level; this should be indented by 2 spaces.

::: gio/gcontenttype.h
@@ +36,3 @@
 gboolean g_content_type_is_a              (const gchar  *type,
                                            const gchar  *supertype);
+GLIB_AVAILABLE_IN_2_40

this should be GLIB_AVAILABLE_IN_2_42.

::: gio/gnextstepcontenttype.c
@@ +132,2 @@
 gboolean
+g_content_type_is_mime_type (const gchar *type, const gchar *mime_type)

coding style: arguments should go on separate lines.

@@ +133,3 @@
+g_content_type_is_mime_type (const gchar *type, const gchar *mime_type)
+{
+    gchar *content_type;

coding style: wrong indentation level.
Comment 11 Patrick Griffis (tingping) 2014-08-21 10:15:46 UTC
Created attachment 284069 [details] [review]
Gtk3 - Improve GContentType usage
Comment 12 Patrick Griffis (tingping) 2014-08-21 10:45:21 UTC
Created attachment 284077 [details] [review]
Implement GContentType on OSX
Comment 13 Patrick Griffis (tingping) 2014-08-21 10:45:50 UTC
Created attachment 284078 [details] [review]
Create g_content_type_is_mime_type()
Comment 14 Allison Karlitskaya (desrt) 2015-01-05 03:46:11 UTC
Review of attachment 284077 [details] [review]:

A few comments:

I'm concerned about the amount of TODO here.

Also concerned about the #if 0 section.

I don't think it makes sense to call this "nextstep" since unlike the settings backend, this won't work on GNUstep or other NS implementations.

There are some style issues remaining: trailing whitespace and incorrect GNU style.  The first curly after an if() gets intended and its content indented again, like so:


  if (this)
    {
      that;
    }
  else
    {
      other;
    }

I also don't like the hardcoding in g_content_type_from_mime_type().  If we need those because various bits of our platform (particularly GIO itself) want to get the system-specific representation for things like "directory", "symlink", etc. then probably we should handle that with some sort of enumeration that acts as a public declaration of the (more or less) magic values that we support.  The gdk-pixbuf case is a bit more difficult: are there valid mime types in apple's database that we could be using instead of the ones that we use today?

I'm also concerned about people getting burned by the assumption that #ifdef G_OS_UNIX, mimetype == contenttype.

All that being said, overall this seems like something that we should add, and I'm pleasantly surprised by how small it is.
Comment 15 Allison Karlitskaya (desrt) 2015-01-05 03:47:40 UTC
Review of attachment 284078 [details] [review]:

I get the impression that this is intended to be used for things like .is_a("inode/directory"), in which case I think it would be better to also base this on the enumeration idea I mentioned in the previous review.  Might also be useful to keep this variant as well, though.
Comment 16 Patrick Griffis (tingping) 2015-01-05 04:03:09 UTC
>I'm concerned about the amount of TODO here.

From a quick `ack` neither g_content_type_guess_for_tree() nor g_content_types_get_registered() are used once in GLib or Gtk so while likely possible to do I did not see a ton of value in it when I wrote it at the time.

>Also concerned about the #if 0 section.

That section was a proof-of-concept on getting the real icons for each application. The issue here is a "bug" in gdk-pixbuf that .icns files are not loaded properly. The code could be removed and the functionality it could provide never existed pre this patch anyway.

>I also don't like the hardcoding in g_content_type_from_mime_type() ... then probably we should handle that with some sort of enumeration that acts as a public declaration of the (more or less) magic values that we support.

I agree that I'd rather it not exist. Hardcoding the handful of wildcard values I think is a fairly maintainable solution, but ensuring or at least documenting only those special values are guaranteed to be supported by every platform is a good idea.

>The gdk-pixbuf case is a bit more difficult: are there valid mime types in apple's database that we could be using instead of the ones that we use today?

IIRC, no. They are non-standard types so either we handle them by hand or let it fail.

>I'm also concerned about people getting burned by the assumption that #ifdef G_OS_UNIX, mimetype == contenttype.

They already make this assumption on Windows where this was already not true as you can tell by my various patches.
I'm not sure what you can do more than document it.
Comment 17 Matthias Clasen 2017-03-09 04:09:37 UTC
Comment on attachment 284078 [details] [review]
Create g_content_type_is_mime_type()

Fixed up the review comments and pushed

Attachment 284078 [details] pushed as fe1a749 - Create g_content_type_is_mime_type()
Comment 18 Matthias Clasen 2017-03-09 11:44:39 UTC
Created attachment 347546 [details] [review]
Implement GContentType on OS X

Use CoreServices APIs to implement most of GContentType
on OS X. Based on a patch by Patrick Griffis.
Comment 19 Matthias Clasen 2017-03-09 11:45:01 UTC
Fixed up formatting, and renamed to gcontenttype-osx.c
Comment 20 Matthias Clasen 2017-03-09 12:18:55 UTC
It does not quite work, though:

I get a bunch of testsuite failures with this, and crashes in my application that is trying to use g_app_info_launch_default_for_uri
Comment 21 Matthias Clasen 2017-03-09 12:41:49 UTC
turns out the crash I was seeing was due to some sporadic use of _g_unix_content_type_unalias and _g_unix_content_type_get_parents outside of gcontenttype.c.
Comment 22 Patrick Griffis (tingping) 2017-03-09 14:32:28 UTC
I believe no matter what some of the tests will fail, OSX simply doesn't have all of the types a linux machine knows. Though I don't have an OSX install handy any more to see exactly what is failing.
Comment 23 Philip Withnall 2017-03-09 14:56:33 UTC
(In reply to Patrick Griffis (tingping) from comment #22)
> I believe no matter what some of the tests will fail, OSX simply doesn't
> have all of the types a linux machine knows. Though I don't have an OSX
> install handy any more to see exactly what is failing.

Then those tests need changing or explicitly skipping (g_test_skip()).
Comment 24 Patrick Griffis (tingping) 2017-03-09 15:00:49 UTC
Yea. Also just for future readers since Matthias was looking into this. This was part of my work implementing GAppInfo on OSX (which is functional): https://github.com/TingPing/glib/commits/tingping/osx-gappinfo
Comment 25 Matthias Clasen 2017-03-10 02:55:14 UTC
I've pushed a version of this work to the osx-appinfo branch, with fixed annotations, formatting and a few fixes here and there. It has been build and tested on OS X, and my app can now successfully launch both a mailto: and a
https:// url, so I'm satisfied that this is useful enough to merge.

Review would still be appreciated.
Comment 26 Patrick Griffis (tingping) 2017-03-10 03:22:35 UTC
> +#if 0
> +  /* This deprecates LSFindApplicationForInfo in 10.10+ */
> +  app_url = LSCopyApplicationURLsForBundleIdentifier (bundle_id, kLSRolesAll);
> +#endif

It might be time to conditionally use that if targeting a new enough sdk. It might already be removed in 10.11+ (what are you testing on?). It has been a while so I forget the details of detecting that.

> #define G_NEXTSTEP_APP_INFO(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_NEXTSTEP_APP_INFO, GNextstepAppInfo))

Should probably use the new macros.

We also didn't settle on the Nextstep name just wanted to make sure everybody was happy with that.
Comment 27 Matthias Clasen 2017-03-10 03:27:45 UTC
testing on 10.12.3, and yes, that function does trigger a deprecation warning
Comment 28 Matthias Clasen 2017-03-10 03:28:27 UTC
I just didn't feel like deciding if it should be cocoa or osx for the name, so I left it at nextstep...
Comment 29 Emmanuele Bassi (:ebassi) 2017-03-10 11:52:34 UTC
I thought we used 'nextstep' for things that could be shared with GNUstep; 'osx' for things that would only work on macOS; and 'cocoa' for things written in Objective C.

Honestly, I think we should probably pick a naming scheme and stick to it, and I'd probably drop any pretension of working with GNUstep.
Comment 30 Matthias Clasen 2017-03-10 11:55:12 UTC
That sounds like osx it is, in this case, then ?

I'm happy to do the renaming if thats the consensus.
Comment 31 Emmanuele Bassi (:ebassi) 2017-03-10 11:55:26 UTC
+#if 0
+  /* This deprecates LSFindApplicationForInfo in 10.10+ */
+  app_url = LSCopyApplicationURLsForBundleIdentifier (bundle_id, kLSRolesAll);
+#endif

I agree with Patrick: this should be replaced with a compile time check for macOS ≥ 10.10.
Comment 32 Matthias Clasen 2017-03-10 12:35:36 UTC
Here is one thing that will probably come up quite a bit when we land this:

gtkapplicationwindow.c:34:10: fatal error: 'gio/gdesktopappinfo.h' not found

The code has:

#ifdef HAVE_GIO_UNIX
#include <gio/gdesktopappinfo.h>
#endif
Comment 33 Patrick Griffis (tingping) 2017-03-10 17:39:44 UTC
+1 to just calling it `osx`, its clear what it is for.

(In reply to Matthias Clasen from comment #32)
> Here is one thing that will probably come up quite a bit when we land this:
> 
> gtkapplicationwindow.c:34:10: fatal error: 'gio/gdesktopappinfo.h' not found
> 
> The code has:
> 
> #ifdef HAVE_GIO_UNIX
> #include <gio/gdesktopappinfo.h>
> #endif

OSX is always going to be a bit messy in this area, either it behaves exactly like on unix or it diverges with its own backends like this. I was never sure the best solution to that.

On a slightly related note I was always interested in having G_OS_OSX or such to allow more clean osx specific code than __APPLE__ but that doesn't help existing assumptions.
Comment 34 Matthias Clasen 2017-03-11 15:31:40 UTC
Pushed a new version of the branch which has the rename to osx, and uses LSLSCopyApplicationURLsForBundleIdentifier

While the latter has been compiled on the OS X machine I have here, I'd like some review on my blind use of apis there...
Comment 35 Patrick Griffis (tingping) 2017-03-11 20:44:06 UTC
(In reply to Matthias Clasen from comment #34)
> Pushed a new version of the branch which has the rename to osx, and uses
> LSLSCopyApplicationURLsForBundleIdentifier
> 
> While the latter has been compiled on the OS X machine I have here, I'd like
> some review on my blind use of apis there...


> +      app_url = CFArrayGetValueAtIndex (urls, 0);

So I do wonder about this fact: "The order of elements in the array is undefined."

Mentioned in the docs: https://developer.apple.com/reference/coreservices/1449290-lscopyapplicationurlsforbundleid?language=objc

In practice you probably only have one application for the bundle but I just wonder if we should make the return value deterministic by sorting it or something?
Comment 36 Patrick Griffis (tingping) 2017-03-11 20:48:49 UTC
As for how to sort it we probably want to prioritize bundles in the users home to system wide ones. Beyond that I don't know.
Comment 37 Matthias Clasen 2017-03-12 16:32:19 UTC
hmm, this is starting to go further beyond my level of familiarity with osx.
Comment 38 Patrick Griffis (tingping) 2017-03-12 17:23:12 UTC
What is currently there should be acceptable, that is just an edge case that would be nice to explicitly handle.
Comment 39 Matthias Clasen 2017-03-13 14:40:40 UTC
Attachment 284077 [details] pushed as 3953d85 - Implement GContentType on OSX
Comment 40 Christoph Reiter (lazka) 2017-03-14 20:04:13 UTC
Created attachment 347950 [details] [review]
gtk osx build fix

I'm hitting the above mentioned error message when building on osx:

gtkapplicationwindow.c:34:10: fatal error: 'gio/gdesktopappinfo.h' not found

Patrick suggested the attached fix on IRC. Since I don't know what the problem is I'm attaching it here. I can only say that it fixes the build for me.

maybe it helps
Comment 41 Patrick Griffis (tingping) 2017-03-15 05:25:55 UTC
Created attachment 347983 [details] [review]
gosxappinfo: Fix launching default applications

Fix opening default applications which lazka ran into (If you could test this lazka).
Comment 42 Christoph Reiter (lazka) 2017-03-15 07:41:56 UTC
Created attachment 347989 [details] [review]
gosxappinfo: fix typo in url_escape_hostname

Works! But the passed url was corrupt; turned out to be a typo in url_escape_hostname. Fix attached.
Comment 43 Matthias Clasen 2017-03-30 13:53:28 UTC
Review of attachment 347983 [details] [review]:

sounds right
Comment 44 Matthias Clasen 2017-03-30 13:56:51 UTC
Review of attachment 347989 [details] [review]:

hmm, ok
Comment 45 Patrick Griffis (tingping) 2017-03-30 14:11:15 UTC
Attachment 347983 [details] pushed as 392bd59 - gosxappinfo: Fix launching default applications
Attachment 347989 [details] pushed as c20ab77 - gosxappinfo: fix typo in url_escape_hostname
Comment 46 Rafal Luzynski 2017-03-30 17:28:13 UTC
gio/gosxappinfo.c:

445  if ((ret = LSOpenFromURLSpec (urlspec, NULL)))
446    {
447      /* TODO: Better error codes */
448      g_set_error (error, G_IO_ERR, G_IO_ERROR_FAILED,

I guess you meant G_IO_ERROR [1] rather than G_IO_ERR [2].

[1] https://developer.gnome.org/gio/stable/gio-GIOError.html#G-IO-ERROR:CAPS
[2] https://developer.gnome.org/glib/stable/glib-IO-Channels.html#GIOCondition
Comment 47 Rafal Luzynski 2017-03-30 23:57:19 UTC
Created attachment 349020 [details] [review]
gosxappinfo: fix typo in g_osx_app_info_launch_internal
Comment 48 Patrick Griffis (tingping) 2017-03-31 00:15:04 UTC
Review of attachment 349020 [details] [review]:

This fails because you need to include "gioerror.h" for the definition.
Comment 49 Patrick Griffis (tingping) 2017-03-31 00:18:38 UTC
Created attachment 349022 [details] [review]
gosxappinfo: Fix get_default_for_type() on 10.10+
Comment 50 Patrick Griffis (tingping) 2017-03-31 00:19:06 UTC
Created attachment 349023 [details] [review]
gosxappinfo: Special case x-scheme-handler
Comment 51 Rafal Luzynski 2017-03-31 09:18:11 UTC
Created attachment 349029 [details] [review]
gosxappinfo: fix typo in g_osx_app_info_launch_internal (v2)

(In reply to Patrick Griffis (tingping) from comment #48)
> This fails because you need to include "gioerror.h" for the definition.

Here it is corrected.
Comment 52 Rafal Luzynski 2017-04-04 10:12:02 UTC
John has suggested in bug 780725 comment 2 to reopen the bug since there are still some patches to be applied.
Comment 53 Daniel Macks 2017-04-24 03:04:39 UTC
The g_content_type_is_mime_type is present in gcontenttype.h and implemented in both the generic gcontenttype.c and the platform-specific gcontenttype-win32.c but not in gosxcontenttype.c.

Since it's just a wrapper around g_content_type_is_a, which is implemented in gosxcontenttype.c, should be easy enough to do. But I notice that the win32 variant is has some actual parameter-checking and string-dup whereas the generic is literally just a pass-through, so I didn't want to write an osx variant until I knew something about the basis for this implementation difference...
Comment 54 Daniel Macks 2017-04-24 03:06:01 UTC
*** Bug 781642 has been marked as a duplicate of this bug. ***
Comment 55 Patrick Griffis (tingping) 2017-04-24 03:26:03 UTC
(In reply to Daniel Macks from comment #53)
> The g_content_type_is_mime_type is present in gcontenttype.h and implemented
> in both the generic gcontenttype.c and the platform-specific
> gcontenttype-win32.c but not in gosxcontenttype.c.
> 
> Since it's just a wrapper around g_content_type_is_a, which is implemented
> in gosxcontenttype.c, should be easy enough to do. But I notice that the
> win32 variant is has some actual parameter-checking and string-dup whereas
> the generic is literally just a pass-through, so I didn't want to write an
> osx variant until I knew something about the basis for this implementation
> difference...


The OSX implementation should be the exact same as the Win32 one. The Unix one is a direct wrapper because on Unix mimetype == contenttype.
Comment 56 Daniel Macks 2017-04-24 05:44:42 UTC
Created attachment 350279 [details] [review]
Verify presence of new interface
Comment 57 Daniel Macks 2017-04-24 05:58:42 UTC
Created attachment 350280 [details] [review]
Add missing function for OS X

...but it fails selftest of Comment #56:

GLib-GIO:ERROR:contenttype.c:147:test_subtype: assertion failed: (g_content_type_is_mime_type (xml, plain))
Comment 58 Patrick Griffis (tingping) 2017-04-24 23:53:13 UTC
Review of attachment 350280 [details] [review]:

Looks good.
Comment 59 Matthias Clasen 2017-04-27 13:28:44 UTC
Review of attachment 350279 [details] [review]:

ok
Comment 60 Matthias Clasen 2017-04-27 13:50:40 UTC
Review of attachment 350279 [details] [review]:

ok
Comment 61 Matthias Clasen 2017-04-27 13:51:00 UTC
Review of attachment 350280 [details] [review]:

sure
Comment 62 Patrick Griffis (tingping) 2017-04-28 10:38:58 UTC
Attachment 349022 [details] pushed as fac83e0 - gosxappinfo: Fix get_default_for_type() on 10.10+
Attachment 349023 [details] pushed as 0c4dd4a - gosxappinfo: Special case x-scheme-handler
Comment 63 hfp 2017-05-08 18:47:14 UTC
some included patches cause failures. see https://bugzilla.gnome.org/show_bug.cgi?id=782180