Search in sources :

Example 1 with CoreLifecycleAdapter

use of com.biglybt.core.CoreLifecycleAdapter in project BiglyBT by BiglySoftware.

the class UI method coreCreated.

@Override
public void coreCreated(Core core) {
    super.coreCreated(core);
    if (core.isStarted()) {
        startUI();
        return;
    }
    core.addLifecycleListener(new CoreLifecycleAdapter() {

        @Override
        public void started(Core core) {
            startUI();
        }
    });
}
Also used : CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) Core(com.biglybt.core.Core)

Example 2 with CoreLifecycleAdapter

use of com.biglybt.core.CoreLifecycleAdapter in project BiglyBT by BiglySoftware.

the class DeviceManagerImpl method initWithCore.

void initWithCore(final Core _core) {
    synchronized (this) {
        if (core != null) {
            return;
        }
        core = _core;
    }
    try {
        od_manual_ta = PluginInitializer.getDefaultInterface().getTorrentManager().getPluginAttribute("device.manager.od.ta.manual");
        rss_publisher = new DeviceManagerRSSFeed(this);
        // need to pick up auto-search early on
        COConfigurationManager.addAndFireParameterListeners(new String[] { AUTO_SEARCH_CONFIG_KEY, AUTO_HIDE_OLD_CONFIG_KEY }, new ParameterListener() {

            @Override
            public void parameterChanged(String name) {
                auto_search = COConfigurationManager.getBooleanParameter(AUTO_SEARCH_CONFIG_KEY, true);
                auto_hide_old_days = COConfigurationManager.getIntParameter(AUTO_HIDE_OLD_CONFIG_KEY, AUTO_HIDE_OLD_DAYS_DEFAULT);
            }
        });
        // init tivo before upnp as upnp init completion starts up tivo
        tivo_manager = new DeviceTivoManager(this);
        upnp_manager = new DeviceManagerUPnPImpl(this);
        loadConfig();
        new DeviceiTunesManager(this);
        drive_manager = new DeviceDriveManager(this);
        transcode_manager = new TranscodeManagerImpl(this);
        transcode_manager.initialise();
        core.addLifecycleListener(new CoreLifecycleAdapter() {

            @Override
            public void stopping(Core core) {
                synchronized (DeviceManagerImpl.this) {
                    if (config_dirty || config_unclean) {
                        saveConfig();
                    }
                    closing = true;
                    transcode_manager.close();
                    DeviceImpl[] devices = getDevices();
                    for (DeviceImpl device : devices) {
                        device.close();
                    }
                }
            }
        });
        upnp_manager.initialise();
        SimpleTimer.addPeriodicEvent("DeviceManager:update", DEVICE_UPDATE_PERIOD, new TimerEventPerformer() {

            private int tick_count = 0;

            @Override
            public void perform(TimerEvent event) {
                List<DeviceImpl> copy;
                tick_count++;
                transcode_manager.updateStatus(tick_count);
                synchronized (DeviceManagerImpl.this) {
                    if (device_list.size() == 0) {
                        return;
                    }
                    copy = new ArrayList<>(device_list);
                }
                for (DeviceImpl device : copy) {
                    device.updateStatus(tick_count);
                }
                if (auto_hide_old_days > 0 && tick_count % DEVICE_AUTO_HIDE_CHECK_TICKS == 0) {
                    long now = SystemTime.getCurrentTime();
                    int num_hidden = 0;
                    for (DeviceImpl device : copy) {
                        if (device.isLivenessDetectable() && !device.isTagged()) {
                            int type = device.getType();
                            if (type == Device.DT_CONTENT_DIRECTORY) {
                            } else if (type == Device.DT_MEDIA_RENDERER) {
                                DeviceMediaRenderer rend = (DeviceMediaRenderer) device;
                                if (rend.getRendererSpecies() != DeviceMediaRenderer.RS_OTHER) {
                                    continue;
                                }
                            } else {
                                continue;
                            }
                            long age = now - device.getLastSeen();
                            if (age > auto_hide_old_days * 24 * 60 * 60 * 1000L) {
                                if (!device.isHidden()) {
                                    log("Auto-hiding '" + device.getName() + "'");
                                    device.setHidden(true);
                                    device.setAutoHidden(true);
                                    num_hidden++;
                                }
                            } else {
                                if (device.isHidden() && device.isAutoHidden()) {
                                    log("Auto-showing '" + device.getName() + "'");
                                    device.setAutoHidden(false);
                                    device.setHidden(false);
                                }
                            }
                        }
                    }
                    if (num_hidden > 0) {
                        Logger.log(new LogAlert(true, LogAlert.AT_INFORMATION, MessageText.getString("device.autohide.alert", new String[] { String.valueOf(num_hidden), String.valueOf(auto_hide_old_days) })));
                    }
                }
            }
        });
        initialized = true;
        listeners.dispatch(LT_INITIALIZED, null);
        core.addPowerManagementListener(this);
    } finally {
        init_sem.releaseForever();
    }
}
Also used : CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) LogAlert(com.biglybt.core.logging.LogAlert) ParameterListener(com.biglybt.core.config.ParameterListener) Core(com.biglybt.core.Core)

Example 3 with CoreLifecycleAdapter

use of com.biglybt.core.CoreLifecycleAdapter in project BiglyBT by BiglySoftware.

the class TagManagerImpl method init.

private void init() {
    if (!enabled) {
        return;
    }
    Core core = CoreFactory.getSingleton();
    final TagPropertyTrackerHandler auto_tracker = new TagPropertyTrackerHandler(core, this);
    untagged_handler = new TagPropertyUntaggedHandler(core, this);
    new TagPropertyTrackerTemplateHandler(core, this);
    constraint_handler = new TagPropertyConstraintHandler(core, this);
    core.addLifecycleListener(new CoreLifecycleAdapter() {

        @Override
        public void started(Core core) {
            core.getPluginManager().getDefaultPluginInterface().getDownloadManager().getGlobalDownloadEventNotifier().addCompletionListener(TagManagerImpl.this);
        }

        @Override
        public void componentCreated(Core core, CoreComponent component) {
            if (component instanceof GlobalManager) {
                GlobalManager global_manager = (GlobalManager) component;
                global_manager.addDownloadManagerInitialisationAdapter(new DownloadManagerInitialisationAdapter() {

                    @Override
                    public int getActions() {
                        return (ACT_ASSIGNS_TAGS);
                    }

                    @Override
                    public void initialised(DownloadManager manager, boolean for_seeding) {
                        com.biglybt.core.disk.DiskManagerFileInfo[] files = manager.getDiskManagerFileInfoSet().getFiles();
                        for (com.biglybt.core.disk.DiskManagerFileInfo file : files) {
                            if (file.getTorrentFile().getPathComponents().length == 1) {
                                String name = file.getTorrentFile().getRelativePath().toLowerCase(Locale.US);
                                if (name.equals("index.html") || name.equals("index.htm")) {
                                    TagType tt = TagManagerFactory.getTagManager().getTagType(TagType.TT_DOWNLOAD_MANUAL);
                                    String tag_name = "Websites";
                                    Tag tag = tt.getTag(tag_name, true);
                                    try {
                                        if (tag == null) {
                                            tag = tt.createTag(tag_name, true);
                                        }
                                        if (!tag.hasTaggable(manager)) {
                                            tag.addTaggable(manager);
                                            tag.setDescription(MessageText.getString("tag.website.desc"));
                                        }
                                    } catch (Throwable e) {
                                        Debug.out(e);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                });
                global_manager.addDownloadManagerInitialisationAdapter(new DownloadManagerInitialisationAdapter() {

                    @Override
                    public int getActions() {
                        return (ACT_PROCESSES_TAGS);
                    }

                    @Override
                    public void initialised(DownloadManager manager, boolean for_seeding) {
                        if (for_seeding) {
                            return;
                        }
                        // perform any auto-tagging - note that auto-tags aren't applied to the download
                        // yet
                        List<Tag> auto_tags = auto_tracker.getTagsForDownload(manager);
                        Set<Tag> tags = new HashSet<>(getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, manager));
                        tags.addAll(auto_tags);
                        if (tags.size() == 0) {
                            // pick up untagged tags here as they haven't been added yet :(
                            tags.addAll(untagged_handler.getUntaggedTags());
                        }
                        if (tags.size() > 0) {
                            List<Tag> sl_tags = new ArrayList<>();
                            for (Tag tag : tags) {
                                TagFeatureFileLocation fl = (TagFeatureFileLocation) tag;
                                if (fl.supportsTagInitialSaveFolder()) {
                                    File save_loc = fl.getTagInitialSaveFolder();
                                    if (save_loc != null) {
                                        sl_tags.add(tag);
                                    }
                                }
                            }
                            if (sl_tags.size() > 0) {
                                if (sl_tags.size() > 1) {
                                    Collections.sort(sl_tags, new Comparator<Tag>() {

                                        @Override
                                        public int compare(Tag o1, Tag o2) {
                                            return (o1.getTagID() - o2.getTagID());
                                        }
                                    });
                                }
                                TagFeatureFileLocation tag = (TagFeatureFileLocation) sl_tags.get(0);
                                long options = tag.getTagInitialSaveOptions();
                                boolean set_data = (options & TagFeatureFileLocation.FL_DATA) != 0;
                                boolean set_torrent = (options & TagFeatureFileLocation.FL_TORRENT) != 0;
                                File new_loc = tag.getTagInitialSaveFolder();
                                if (set_data) {
                                    File old_loc = manager.getSaveLocation();
                                    if (!new_loc.equals(old_loc)) {
                                        manager.setTorrentSaveDir(new_loc.getAbsolutePath());
                                    }
                                }
                                if (set_torrent) {
                                    File old_torrent_file = new File(manager.getTorrentFileName());
                                    if (old_torrent_file.exists()) {
                                        try {
                                            manager.setTorrentFile(new_loc, old_torrent_file.getName());
                                        } catch (Throwable e) {
                                            Debug.out(e);
                                        }
                                    }
                                }
                            }
                        }
                    }
                });
            }
        }

        @Override
        public void stopped(Core core) {
            destroy();
        }
    });
    SimpleTimer.addPeriodicEvent("TM:Sync", 30 * 1000, new TimerEventPerformer() {

        @Override
        public void perform(TimerEvent event) {
            for (TagType tt : tag_types) {
                ((TagTypeBase) tt).sync();
            }
        }
    });
}
Also used : CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) DownloadManager(com.biglybt.core.download.DownloadManager) GlobalManager(com.biglybt.core.global.GlobalManager) CoreComponent(com.biglybt.core.CoreComponent) Core(com.biglybt.core.Core) DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) DownloadManagerInitialisationAdapter(com.biglybt.core.download.DownloadManagerInitialisationAdapter) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File)

Example 4 with CoreLifecycleAdapter

use of com.biglybt.core.CoreLifecycleAdapter in project BiglyBT by BiglySoftware.

the class PlatformManagerImpl method startup.

@Override
public void startup(Core _core) throws PlatformManagerException {
    synchronized (this) {
        core = _core;
        if (prevent_computer_sleep_pending) {
            prevent_computer_sleep_pending = false;
            setPreventComputerSleep(true);
        }
    }
    core.addLifecycleListener(new CoreLifecycleAdapter() {

        @Override
        public void stopping(Core core) {
            synchronized (PlatformManagerImpl.this) {
                try {
                    setPreventComputerSleep(false);
                } catch (Throwable e) {
                }
                core = null;
            }
        }
    });
}
Also used : CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) Core(com.biglybt.core.Core)

Example 5 with CoreLifecycleAdapter

use of com.biglybt.core.CoreLifecycleAdapter in project BiglyBT by BiglySoftware.

the class UI method coreCreated.

@Override
public void coreCreated(Core core) {
    super.coreCreated(core);
    UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
    if (uiFunctions != null) {
        openQueuedTorrents();
    } else {
        core.addLifecycleListener(new CoreLifecycleAdapter() {

            @Override
            public void componentCreated(Core core, CoreComponent component) {
                if (component instanceof UIFunctionsSWT) {
                    openQueuedTorrents();
                    core.removeLifecycleListener(this);
                }
            }
        });
    }
}
Also used : CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) UIFunctions(com.biglybt.ui.UIFunctions) CoreComponent(com.biglybt.core.CoreComponent) Core(com.biglybt.core.Core)

Aggregations

Core (com.biglybt.core.Core)12 CoreLifecycleAdapter (com.biglybt.core.CoreLifecycleAdapter)12 CoreComponent (com.biglybt.core.CoreComponent)2 DownloadManager (com.biglybt.core.download.DownloadManager)2 TimerEvent (com.biglybt.core.util.TimerEvent)2 TimerEventPerformer (com.biglybt.core.util.TimerEventPerformer)2 TimerEventPeriodic (com.biglybt.core.util.TimerEventPeriodic)2 BufferedLabel (com.biglybt.ui.swt.components.BufferedLabel)2 IntParameter (com.biglybt.ui.swt.config.IntParameter)2 Parameter (com.biglybt.ui.swt.config.Parameter)2 ParameterChangeAdapter (com.biglybt.ui.swt.config.ParameterChangeAdapter)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Point (org.eclipse.swt.graphics.Point)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 CoreException (com.biglybt.core.CoreException)1 COConfigurationManager (com.biglybt.core.config.COConfigurationManager)1 ParameterListener (com.biglybt.core.config.ParameterListener)1 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)1