/* public static File getPrimaryFile(Download d) { DiskManagerFileInfo info = getPrimaryFileInfo(d); if ( info == null ){ return( null ); }else{ return( info.getFile( true )); } } public static int getPrimaryFileIndex(DownloadManager dm ){ return( getPrimaryFileIndex( PluginCoreUtils.wrap( dm ))); } public static int getPrimaryFileIndex(Download d) { DiskManagerFileInfo info = getPrimaryFileInfo(d); if ( info == null ){ return( -1 ); }else{ return( info.getIndex()); } } public static DiskManagerFileInfo getPrimaryFileInfo(Download d) { long size = d.getTorrent().getSize(); DiskManagerFileInfo[] infos = d.getDiskManagerFileInfo(); for(int i = 0; i < infos.length ; i++) { DiskManagerFileInfo info = infos[i]; if ( info.isSkipped() || info.isDeleted()){ continue; } if( info.getLength() > (long)fileSizeThreshold * size / 100l) { return info; } } return null; } */ public static boolean isExternallyPlayable(Download d, int file_index, boolean complete_only) { int primary_file_index = -1; if (file_index == -1) { DownloadManager dm = PluginCoreUtils.unwrap(d); if (dm == null) { return (false); } DiskManagerFileInfo file = null; try { file = PluginCoreUtils.wrap(dm.getDownloadState().getPrimaryFile()); } catch (DownloadException e) { return false; } if (file == null) { return (false); } if (file.getDownloaded() != file.getLength()) { if (complete_only || getMediaServerContentURL(file) == null) { return (false); } } primary_file_index = file.getIndex(); } else { DiskManagerFileInfo file = d.getDiskManagerFileInfo(file_index); if (file.getDownloaded() != file.getLength()) { if (complete_only || getMediaServerContentURL(file) == null) { return (false); } } primary_file_index = file_index; } if (primary_file_index == -1) { return false; } return (isExternallyPlayable(d.getDiskManagerFileInfo()[primary_file_index])); }
public boolean eventOccurred(UISWTViewEvent event) { if (listener == null) { UISWTViewEventListener eventListener = null; synchronized (UISWTViewEventListenerHolder.this) { int type = event.getType(); if (type == UISWTViewEvent.TYPE_CREATE) { try { eventListener = cla.newInstance(); UISWTView view = event.getView(); if (eventListener instanceof UISWTViewCoreEventListener) { if (view instanceof UISWTViewCore) { UISWTViewCore coreView = (UISWTViewCore) view; coreView.setUseCoreDataSource(true); } } if (mapSWTViewToEventListener == null) { mapSWTViewToEventListener = new HashMap<UISWTView, UISWTViewEventListener>(); } mapSWTViewToEventListener.put(view, eventListener); if (datasource != null) { if (view instanceof UISWTViewImpl) { UISWTViewImpl swtView = (UISWTViewImpl) view; swtView.triggerEventRaw( UISWTViewEvent.TYPE_DATASOURCE_CHANGED, PluginCoreUtils.convert( datasource, ((UISWTViewImpl) view).useCoreDataSource())); } else { view.triggerEvent(UISWTViewEvent.TYPE_DATASOURCE_CHANGED, datasource); } } } catch (Exception e) { Debug.out(e); return false; } } else if (mapSWTViewToEventListener != null) { if (type == UISWTViewEvent.TYPE_DESTROY) { eventListener = mapSWTViewToEventListener.remove(event.getView()); } else { eventListener = mapSWTViewToEventListener.get(event.getView()); } } } if (eventListener == null) { return false; } return eventListener.eventOccurred(event); } else if (event.getType() == UISWTViewEvent.TYPE_CREATE && (listener instanceof UISWTViewCoreEventListener)) { if (event.getView() instanceof UISWTViewCore) { UISWTViewCore coreView = (UISWTViewCore) event.getView(); coreView.setUseCoreDataSource(true); } } return (listener.eventOccurred(event)); }
/** @deprecated */ public static int getPrimaryFileIndex(Download dl) { EnhancedDownloadManager edm = DownloadManagerEnhancer.getSingleton().getEnhancedDownload(PluginCoreUtils.unwrap(dl)); if (edm == null) { return -1; } return edm.getPrimaryFileIndex(); }
public void triggerTabViewsDataSourceChanged(boolean sendParent) { if (tabViews == null || tabViews.size() == 0) { return; } if (sendParent) { for (int i = 0; i < tabViews.size(); i++) { UISWTViewCore view = tabViews.get(i); if (view != null) { view.triggerEvent(UISWTViewEvent.TYPE_DATASOURCE_CHANGED, tv.getParentDataSource()); } } return; } // Set Data Object for all tabs. Object[] dataSourcesCore = tv.getSelectedDataSources(true); Object[] dataSourcesPlugin = null; for (int i = 0; i < tabViews.size(); i++) { UISWTViewCore view = tabViews.get(i); if (view != null) { if (view.useCoreDataSource()) { view.triggerEvent( UISWTViewEvent.TYPE_DATASOURCE_CHANGED, dataSourcesCore.length == 0 ? tv.getParentDataSource() : dataSourcesCore); } else { if (dataSourcesPlugin == null) { dataSourcesPlugin = tv.getSelectedDataSources(false); } view.triggerEvent( UISWTViewEvent.TYPE_DATASOURCE_CHANGED, dataSourcesPlugin.length == 0 ? PluginCoreUtils.convert(tv.getParentDataSource(), false) : dataSourcesPlugin); } } } }
public void triggerTabViewDataSourceChanged(UISWTViewCore view) { if (view != null) { view.triggerEvent(UISWTViewEvent.TYPE_DATASOURCE_CHANGED, tv.getParentDataSource()); if (view.useCoreDataSource()) { Object[] dataSourcesCore = tv.getSelectedDataSources(true); if (dataSourcesCore.length > 0) { view.triggerEvent( UISWTViewEvent.TYPE_DATASOURCE_CHANGED, dataSourcesCore.length == 0 ? tv.getParentDataSource() : dataSourcesCore); } } else { Object[] dataSourcesPlugin = tv.getSelectedDataSources(false); if (dataSourcesPlugin.length > 0) { view.triggerEvent( UISWTViewEvent.TYPE_DATASOURCE_CHANGED, dataSourcesPlugin.length == 0 ? PluginCoreUtils.convert(tv.getParentDataSource(), false) : dataSourcesPlugin); } } } }