https://bugs.kde.org/show_bug.cgi?id=432336

            Bug ID: 432336
           Summary: Add Open With menu entry under macOS as under Linux
                    and Windows
           Product: digikam
           Version: 7.2.0
          Platform: macOS (DMG)
                OS: macOS
            Status: REPORTED
          Severity: wishlist
          Priority: NOR
         Component: Usability-Menus
          Assignee: digikam-bugs-n...@kde.org
          Reporter: caulier.gil...@gmail.com
  Target Milestone: ---

See this ObjectiveC code below from Robert Lindsay send through users mailing
list to get a list of macOS application from a file extension. GUI must provide
a dialog to show this list and allow user to select right one. Code explain
also how to call macOS SDK to invoke target application.

// ---------------------------------
//      given a filename extension "extension", here's how to find all of the
//      applications known to the OS who can open files of that type.

CFStringRef                     uti = NULL;
CFArrayRef                      bundleIDs = NULL;
CFMutableArrayRef       applications = NULL;

applications = CFArrayCreateMutable(kCFAllocatorDefault, 0);

//      Make a UTI from a filename extension
uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
                                                                               
        extension,
                                                                               
        nil);

if (NULL != uti)
{
        //      get a list of all of the application bundle IDs that know how
to handle this:
        bundleIDs = LSCopyAllRoleHandlersForContentType(uti, kLSRolesViewer |
kLSRolesEditor);
}

if (NULL != bundleIDs)
{
        //      find all the available applications with this bundle ID
        //      getting the display name and version is left as an exercise for
the reader.

        const CFIndex   count = CFArrayGetCount(bundleIDs);

        for (CFIndex i = 0; i < count; i++)
        {
                CFArrayRef      appsForBundleID = NULL;

                appsForBundleID =
LSCopyApplicationURLsForBundleIdentifier(bundleID, NULL);
                if (NULL != appsForBundleID)
                {
                        //
                        //      you could call CFURLResourceIsReachable() on
each item before adding
                        //      it to the big array of qualified applications.
                        //

                        CFArrayAppendArray(applications, appsForBundleID,
CFRangeMake(0, CFArrayGetCount(appsForBundleID)));

                        CFRelease(appsForBundleID);
                }
        }
}

//      "applications" now has an array of ALL of the possible applications 
//      when finished. Given a UI to choose one, you can then call 
//      LSOpenFromURLSpec() to open your file with a specific application.

//      when you're finished, don't forget to release the resources or you'll
leak memory
CFRelease(uti);
CFRelease(bundleIDs);
CFRelease(applications);

// ------------------------------

Gilles Caulier

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to