Search in sources :

Example 1 with Application

use of ch.cyberduck.core.local.Application in project cyberduck by iterate-ch.

the class LaunchServicesSchemeHandler method getAllHandlers.

@Override
public List<Application> getAllHandlers(final String scheme) {
    final List<Application> handlers = new ArrayList<Application>();
    final NSArray applications = LaunchServicesLibrary.library.LSCopyApplicationURLsForURL(NSURL.URLWithString(String.format("%s:/", scheme)), LaunchServicesLibrary.kLSRolesAll);
    NSEnumerator ordered = applications.objectEnumerator();
    NSObject next;
    while (((next = ordered.nextObject()) != null)) {
        final NSURL url = Rococoa.cast(next, NSURL.class);
        final NSBundle bundle = NSBundle.bundleWithPath(url.path());
        if (null == bundle) {
            log.warn(String.format("Failure loading bundle for path %s", url.path()));
            continue;
        }
        final Application application = applicationFinder.getDescription(bundle.bundleIdentifier());
        if (applicationFinder.isInstalled(application)) {
            handlers.add(application);
        }
    }
    return handlers;
}
Also used : NSEnumerator(ch.cyberduck.binding.foundation.NSEnumerator) NSObject(ch.cyberduck.binding.foundation.NSObject) NSBundle(ch.cyberduck.binding.foundation.NSBundle) NSArray(ch.cyberduck.binding.foundation.NSArray) ArrayList(java.util.ArrayList) NSURL(ch.cyberduck.binding.foundation.NSURL) Application(ch.cyberduck.core.local.Application)

Example 2 with Application

use of ch.cyberduck.core.local.Application in project cyberduck by iterate-ch.

the class LaunchServicesSchemeHandler method getDefaultHandler.

/**
 * See ApplicationServices/ApplicationServices.h#LSCopyDefaultHandlerForURLScheme
 *
 * @param scheme The protocol identifier
 * @return The bundle identifier for the application registered as the default handler for this scheme
 */
@Override
public Application getDefaultHandler(final String scheme) {
    final ObjCObjectByReference error = new ObjCObjectByReference();
    final NSURL url = LaunchServicesLibrary.library.LSCopyDefaultApplicationURLForURL(NSURL.URLWithString(String.format("%s:/", scheme)), LaunchServicesLibrary.kLSRolesAll, error);
    if (url != null) {
        final NSBundle bundle = NSBundle.bundleWithPath(url.path());
        if (null == bundle) {
            log.warn(String.format("Failure loading bundle for path %s", url.path()));
            return Application.notfound;
        }
        final Application application = applicationFinder.getDescription(bundle.bundleIdentifier());
        if (applicationFinder.isInstalled(application)) {
            return application;
        }
    }
    return Application.notfound;
}
Also used : NSBundle(ch.cyberduck.binding.foundation.NSBundle) NSURL(ch.cyberduck.binding.foundation.NSURL) ObjCObjectByReference(org.rococoa.ObjCObjectByReference) Application(ch.cyberduck.core.local.Application)

Example 3 with Application

use of ch.cyberduck.core.local.Application in project cyberduck by iterate-ch.

the class EditorFactory method getEditors.

/**
 * @param filename File type
 * @return Installed applications suitable to edit the given file type. Does always include the default editor set
 * in the Preferences
 */
public static List<Application> getEditors(final String filename) {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Find installed editors for file %s", filename));
    }
    final List<Application> editors = new ArrayList<>(finder.findAll(filename));
    // Add the application set as the default editor in the Preferences to be always
    // included in the list of available editors.
    final Application defaultEditor = getDefaultEditor();
    if (finder.isInstalled(defaultEditor)) {
        if (!editors.contains(defaultEditor)) {
            editors.add(defaultEditor);
        }
    }
    return editors;
}
Also used : ArrayList(java.util.ArrayList) Application(ch.cyberduck.core.local.Application)

Example 4 with Application

use of ch.cyberduck.core.local.Application in project cyberduck by iterate-ch.

the class DefaultWatchEditorTest method testNotfound.

@Test(expected = NoSuchFileException.class)
public void testNotfound() throws Exception {
    final DefaultWatchEditor editor = new DefaultWatchEditor(new Host(new TestProtocol()), new Path("/remote", EnumSet.of(Path.Type.file)), new DisabledListProgressListener());
    editor.watch(new Application("com.app"), new Local(System.getProperty("java.io.tmpdir") + "/notfound", UUID.randomUUID().toString()), new DisabledFileWatcherListener(), new DisabledApplicationQuitCallback());
}
Also used : Path(ch.cyberduck.core.Path) TestProtocol(ch.cyberduck.core.TestProtocol) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) DisabledFileWatcherListener(ch.cyberduck.core.local.DisabledFileWatcherListener) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) Application(ch.cyberduck.core.local.Application) DisabledApplicationQuitCallback(ch.cyberduck.core.local.DisabledApplicationQuitCallback) Test(org.junit.Test)

Example 5 with Application

use of ch.cyberduck.core.local.Application in project cyberduck by iterate-ch.

the class MainController method applicationDidFinishLaunching.

/**
 * Sent by the default notification center after the application has been launched and initialized but before it has
 * received its first event. aNotification is always an ApplicationDidFinishLaunchingNotification. You can retrieve
 * the NSApplication object in question by sending object to aNotification. The delegate can implement this method
 * to perform further initialization. If the user started up the application by double-clicking a file, the delegate
 * receives the applicationOpenFile message before receiving applicationDidFinishLaunching.
 * (applicationWillFinishLaunching is sent before applicationOpenFile.)
 */
@Override
public void applicationDidFinishLaunching(NSNotification notification) {
    // Opt-in of automatic window tabbing
    NSWindow.setAllowsAutomaticWindowTabbing(true);
    // Load main menu
    this.loadBundle();
    // Open default windows
    if (preferences.getBoolean("browser.open.untitled")) {
        final BrowserController c = newDocument();
        c.window().makeKeyAndOrderFront(null);
    }
    if (preferences.getBoolean("queue.window.open.default")) {
        TransferController c = TransferControllerFactory.get();
        c.window().makeKeyAndOrderFront(null);
    }
    if (preferences.getBoolean("browser.serialize")) {
        this.background(new AbstractBackgroundAction<Void>() {

            @Override
            public Void run() throws BackgroundException {
                sessions.load();
                return null;
            }

            @Override
            public void cleanup() {
                for (Host host : sessions) {
                    if (log.isInfoEnabled()) {
                        log.info(String.format("New browser for saved session %s", host));
                    }
                    final BrowserController browser = newDocument(true, host.getUuid());
                    browser.mount(host);
                }
                sessions.clear();
            }
        });
    }
    final AbstractHostCollection bookmarks = BookmarkCollection.defaultCollection();
    // Load all bookmarks in background
    this.background(new AbstractBackgroundAction<Void>() {

        @Override
        public Void run() throws BackgroundException {
            bookmarks.load();
            bookmarksSemaphore.countDown();
            return null;
        }

        @Override
        public void cleanup() {
            if (preferences.getBoolean("browser.open.untitled")) {
                if (preferences.getProperty("browser.open.bookmark.default") != null) {
                    openDefaultBookmark(newDocument());
                }
            }
            // Set delegate for NSService
            NSApplication.sharedApplication().setServicesProvider(MainController.this.id());
        }
    });
    this.background(new AbstractBackgroundAction<Void>() {

        @Override
        public Void run() throws BackgroundException {
            final HistoryCollection history = HistoryCollection.defaultCollection();
            history.load();
            return null;
        }
    });
    this.background(new AbstractBackgroundAction<Void>() {

        @Override
        public Void run() throws BackgroundException {
            final TransferCollection transfers = TransferCollection.defaultCollection();
            transfers.load();
            return null;
        }
    });
    final Rendezvous bonjour = RendezvousFactory.instance();
    bonjour.addListener(new NotificationRendezvousListener(bonjour));
    if (preferences.getBoolean("defaulthandler.reminder") && preferences.getInteger("uses") > 0) {
        if (!SchemeHandlerFactory.get().isDefaultHandler(Arrays.asList(Scheme.ftp.name(), Scheme.ftps.name(), Scheme.sftp.name()), new Application(preferences.getProperty("application.identifier")))) {
            final NSAlert alert = NSAlert.alert(LocaleFactory.localizedString("Set Cyberduck as default application for FTP and SFTP locations?", "Configuration"), LocaleFactory.localizedString("As the default application, Cyberduck will open when you click on FTP or SFTP links " + "in other applications, such as your web browser. You can change this setting in the Preferences later.", "Configuration"), // default
            LocaleFactory.localizedString("Change", "Configuration"), // other
            null, LocaleFactory.localizedString("Cancel", "Configuration"));
            alert.setAlertStyle(NSAlert.NSInformationalAlertStyle);
            alert.setShowsSuppressionButton(true);
            alert.suppressionButton().setTitle(LocaleFactory.localizedString("Don't ask again", "Configuration"));
            int choice = new AlertSheetReturnCodeMapper().getOption(alert.runModal());
            if (alert.suppressionButton().state() == NSCell.NSOnState) {
                // Never show again.
                preferences.setProperty("defaulthandler.reminder", false);
            }
            if (choice == SheetCallback.DEFAULT_OPTION) {
                SchemeHandlerFactory.get().setDefaultHandler(new Application(preferences.getProperty("application.identifier")), Arrays.asList(Scheme.ftp.name(), Scheme.ftps.name(), Scheme.sftp.name()));
            }
        }
    }
    // NSWorkspace notifications are posted to a notification center provided by
    // the NSWorkspace object, instead of going through the application’s default
    // notification center as most notifications do. To receive NSWorkspace notifications,
    // your application must register an observer with the NSWorkspace notification center.
    workspace.notificationCenter().addObserver(this.id(), Foundation.selector("workspaceWillPowerOff:"), NSWorkspace.WorkspaceWillPowerOffNotification, null);
    workspace.notificationCenter().addObserver(this.id(), Foundation.selector("workspaceWillLogout:"), NSWorkspace.WorkspaceSessionDidResignActiveNotification, null);
    workspace.notificationCenter().addObserver(this.id(), Foundation.selector("workspaceWillSleep:"), NSWorkspace.WorkspaceWillSleepNotification, null);
    NSNotificationCenter.defaultCenter().addObserver(this.id(), Foundation.selector("applicationWillRestartAfterUpdate:"), "SUUpdaterWillRestartNotificationName", null);
    this.background(new AbstractBackgroundAction<Void>() {

        @Override
        public Void run() {
            bonjour.init();
            return null;
        }
    });
    // Import thirdparty bookmarks.
    this.background(new ImporterBackgroundAction(bookmarks, bookmarksSemaphore));
    final CrashReporter reporter = CrashReporter.create();
    if (log.isInfoEnabled()) {
        log.info("Check for crash report");
    }
    reporter.checkForCrash(preferences.getProperty("website.crash"));
    if (updater.hasUpdatePrivileges()) {
        if (preferences.getBoolean("update.check")) {
            final long next = preferences.getLong("update.check.timestamp") + preferences.getLong("update.check.interval") * 1000;
            if (next < System.currentTimeMillis()) {
                updater.check(true);
            }
            updater.register();
        }
    }
    if (preferences.getBoolean("profiles.discovery.updater.enable")) {
        // Synchronize and register timer
        profiles.register();
    }
    // Register OAuth handler
    final String handler = preferences.getProperty("oauth.handler.scheme");
    if (log.isInfoEnabled()) {
        log.info(String.format("Register OAuth handler %s", handler));
    }
    SchemeHandlerFactory.get().setDefaultHandler(new Application(preferences.getProperty("application.identifier")), Collections.singletonList(handler));
    NSAppleEventManager.sharedAppleEventManager().setEventHandler_andSelector_forEventClass_andEventID(this.id(), Foundation.selector("handleGetURLEvent:withReplyEvent:"), kInternetEventClass, kAEGetURL);
}
Also used : Rendezvous(ch.cyberduck.core.bonjour.Rendezvous) NotificationRendezvousListener(ch.cyberduck.core.bonjour.NotificationRendezvousListener) NSAttributedString(ch.cyberduck.binding.foundation.NSAttributedString) NSAlert(ch.cyberduck.binding.application.NSAlert) Application(ch.cyberduck.core.local.Application) NSApplication(ch.cyberduck.binding.application.NSApplication) AlertSheetReturnCodeMapper(ch.cyberduck.binding.application.AlertSheetReturnCodeMapper) BackgroundException(ch.cyberduck.core.exception.BackgroundException)

Aggregations

Application (ch.cyberduck.core.local.Application)20 Test (org.junit.Test)6 NSAttributedString (ch.cyberduck.binding.foundation.NSAttributedString)4 NSMutableAttributedString (ch.cyberduck.binding.foundation.NSMutableAttributedString)3 NSURL (ch.cyberduck.binding.foundation.NSURL)3 Path (ch.cyberduck.core.Path)3 ArrayList (java.util.ArrayList)3 Action (ch.cyberduck.binding.Action)2 NSImage (ch.cyberduck.binding.application.NSImage)2 NSBundle (ch.cyberduck.binding.foundation.NSBundle)2 NSObject (ch.cyberduck.binding.foundation.NSObject)2 Host (ch.cyberduck.core.Host)2 Local (ch.cyberduck.core.Local)2 TestProtocol (ch.cyberduck.core.TestProtocol)2 BackgroundException (ch.cyberduck.core.exception.BackgroundException)2 ApplicationFinder (ch.cyberduck.core.local.ApplicationFinder)2 DisabledApplicationQuitCallback (ch.cyberduck.core.local.DisabledApplicationQuitCallback)2 DisabledFileWatcherListener (ch.cyberduck.core.local.DisabledFileWatcherListener)2 LaunchServicesApplicationFinder (ch.cyberduck.core.local.LaunchServicesApplicationFinder)2 DefaultMainAction (ch.cyberduck.core.threading.DefaultMainAction)2