Search in sources :

Example 46 with Tag

use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.

the class BuddyPluginView method addBetaSubviews.

private void addBetaSubviews(boolean enable) {
    String[] views = { TableManager.TABLE_MYTORRENTS_ALL_BIG, TableManager.TABLE_MYTORRENTS_INCOMPLETE, TableManager.TABLE_MYTORRENTS_INCOMPLETE_BIG, TableManager.TABLE_MYTORRENTS_COMPLETE, "TagsView" };
    if (enable) {
        taggableLifecycleAdapter = new TaggableLifecycleAdapter() {

            @Override
            public void taggableTagged(TagType tag_type, Tag tag, Taggable taggable) {
                if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
                    DownloadManager dm = (DownloadManager) taggable;
                    for (BetaSubViewHolder h : beta_subviews.values()) {
                        h.tagsUpdated(dm);
                    }
                }
            }

            @Override
            public void taggableUntagged(TagType tag_type, Tag tag, Taggable taggable) {
                if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
                    DownloadManager dm = (DownloadManager) taggable;
                    for (BetaSubViewHolder h : beta_subviews.values()) {
                        h.tagsUpdated(dm);
                    }
                }
            }
        };
        TagManagerFactory.getTagManager().addTaggableLifecycleListener(Taggable.TT_DOWNLOAD, taggableLifecycleAdapter);
        UISWTViewEventListener listener = new UISWTViewEventListener() {

            @Override
            public boolean eventOccurred(UISWTViewEvent event) {
                UISWTView currentView = event.getView();
                switch(event.getType()) {
                    case UISWTViewEvent.TYPE_CREATE:
                        {
                            beta_subviews.put(currentView, new BetaSubViewHolder());
                            currentView.setDestroyOnDeactivate(false);
                            break;
                        }
                    case UISWTViewEvent.TYPE_INITIALIZE:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.initialise(event.getView(), (Composite) event.getData());
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_DATASOURCE_CHANGED:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.setDataSource(event.getData());
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_FOCUSGAINED:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.gotFocus();
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_FOCUSLOST:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.lostFocus();
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_DESTROY:
                        {
                            BetaSubViewHolder subview = beta_subviews.remove(currentView);
                            if (subview != null) {
                                subview.destroy();
                            }
                            break;
                        }
                }
                return true;
            }
        };
        for (String table_id : views) {
            ui_instance.addView(table_id, "azbuddy.ui.menu.chat", listener);
        }
        TableManager table_manager = plugin.getPluginInterface().getUIManager().getTableManager();
        TableCellRefreshListener msg_refresh_listener = new TableCellRefreshListener() {

            @Override
            public void refresh(TableCell _cell) {
                TableCellSWT cell = (TableCellSWT) _cell;
                Download dl = (Download) cell.getDataSource();
                if (dl == null) {
                    return;
                }
                List<ChatInstance> instances = BuddyPluginUtils.peekChatInstances(dl);
                boolean is_pending = false;
                for (ChatInstance instance : instances) {
                    if (instance.getMessageOutstanding()) {
                        is_pending = true;
                    }
                }
                Image graphic;
                String tooltip;
                int sort_order;
                if (is_pending) {
                    graphic = bs_chat_gray_text;
                    tooltip = MessageText.getString("TableColumn.header.chat.msg.out");
                    sort_order = 1;
                } else {
                    graphic = null;
                    tooltip = MessageText.getString("label.no.messages");
                    sort_order = 0;
                }
                cell.setMarginHeight(0);
                cell.setGraphic(graphic);
                cell.setToolTip(tooltip);
                cell.setSortValue(sort_order);
                cell.setCursorID(graphic == null ? SWT.CURSOR_ARROW : SWT.CURSOR_HAND);
            }
        };
        TableCellMouseListener msg_mouse_listener = new TableCellMouseListener() {

            @Override
            public void cellMouseTrigger(TableCellMouseEvent event) {
                if (event.eventType == TableCellMouseEvent.EVENT_MOUSEUP) {
                    TableCell cell = event.cell;
                    Download dl = (Download) cell.getDataSource();
                    if (dl != null) {
                        List<ChatInstance> instances = BuddyPluginUtils.peekChatInstances(dl);
                        for (ChatInstance instance : instances) {
                            if (instance.getMessageOutstanding()) {
                                try {
                                    BuddyPluginUtils.getBetaPlugin().showChat(instance);
                                } catch (Throwable e) {
                                    Debug.out(e);
                                }
                            }
                        }
                    }
                }
            }
        };
        columnMessagePending = new TableColumnCreationListener() {

            @Override
            public void tableColumnCreated(TableColumn result) {
                result.setAlignment(TableColumn.ALIGN_CENTER);
                result.setPosition(TableColumn.POSITION_LAST);
                result.setWidth(32);
                result.setRefreshInterval(TableColumn.INTERVAL_INVALID_ONLY);
                result.setType(TableColumn.TYPE_GRAPHIC);
                result.addCellRefreshListener(msg_refresh_listener);
                result.addCellMouseListener(msg_mouse_listener);
                result.setIconReference("dchat_gray", true);
                synchronized (columns) {
                    columns.add(result);
                }
            }
        };
        table_manager.registerColumn(Download.class, "azbuddy.ui.column.msgpending", columnMessagePending);
    } else {
        for (String table_id : views) {
            ui_instance.removeViews(table_id, "azbuddy.ui.menu.chat");
        }
        for (UISWTView entry : new ArrayList<>(beta_subviews.keySet())) {
            entry.closeView();
        }
        if (taggableLifecycleAdapter != null) {
            TagManagerFactory.getTagManager().removeTaggableLifecycleListener(Taggable.TT_DOWNLOAD, taggableLifecycleAdapter);
            taggableLifecycleAdapter = null;
        }
        beta_subviews.clear();
        if (columnMessagePending != null) {
            TableManager table_manager = plugin.getPluginInterface().getUIManager().getTableManager();
            table_manager.unregisterColumn(Download.class, "azbuddy.ui.column.msgpending", columnMessagePending);
            columnMessagePending = null;
            synchronized (columns) {
                columns.clear();
            }
        }
    }
}
Also used : ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) TaggableLifecycleAdapter(com.biglybt.core.tag.TaggableLifecycleAdapter) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) DownloadManager(com.biglybt.core.download.DownloadManager) TableCellMouseListener(com.biglybt.pif.ui.tables.TableCellMouseListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) TableCell(com.biglybt.pif.ui.tables.TableCell) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) TableManager(com.biglybt.pif.ui.tables.TableManager) Download(com.biglybt.pif.download.Download) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) TableColumn(com.biglybt.pif.ui.tables.TableColumn) Point(org.eclipse.swt.graphics.Point) TagType(com.biglybt.core.tag.TagType) UISWTView(com.biglybt.ui.swt.pif.UISWTView) TableCellRefreshListener(com.biglybt.pif.ui.tables.TableCellRefreshListener) TableCellMouseEvent(com.biglybt.pif.ui.tables.TableCellMouseEvent) Tag(com.biglybt.core.tag.Tag) Taggable(com.biglybt.core.tag.Taggable)

Example 47 with Tag

use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.

the class BuddyPlugin method getRSS.

public feedDetails getRSS(BuddyPluginBuddy buddy, String tag_or_category, String if_mod) throws BuddyPluginException {
    if (!buddy.isLocalRSSTagOrCategoryAuthorised(tag_or_category)) {
        throw (new BuddyPluginException("Unauthorised tag/category '" + tag_or_category + "'"));
    }
    buddy.localRSSTagOrCategoryRead(tag_or_category);
    Download[] downloads = plugin_interface.getDownloadManager().getDownloads();
    List<Download> selected_dls = new ArrayList<>();
    long fingerprint = 0;
    for (int i = 0; i < downloads.length; i++) {
        Download download = downloads[i];
        Torrent torrent = download.getTorrent();
        if (torrent == null) {
            continue;
        }
        boolean match = tag_or_category.equalsIgnoreCase("all");
        if (!match) {
            String dl_cat = download.getAttribute(ta_category);
            match = dl_cat != null && dl_cat.equals(tag_or_category);
        }
        if (!match) {
            try {
                List<Tag> tags = TagManagerFactory.getTagManager().getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, PluginCoreUtils.unwrap(download));
                for (Tag tag : tags) {
                    if (tag.getTagName(true).equals(tag_or_category)) {
                        match = true;
                        break;
                    }
                }
            } catch (Throwable e) {
            }
        }
        if (match) {
            if (!TorrentUtils.isReallyPrivate(PluginCoreUtils.unwrap(torrent))) {
                selected_dls.add(download);
                byte[] hash = torrent.getHash();
                int num = (hash[0] << 24) & 0xff000000 | (hash[1] << 16) & 0x00ff0000 | (hash[2] << 8) & 0x0000ff00 | hash[3] & 0x000000ff;
                fingerprint += num;
            }
        }
    }
    PluginConfig pc = plugin_interface.getPluginconfig();
    String feed_finger_key = "feed_finger.category." + tag_or_category;
    String feed_date_key = "feed_date.category." + tag_or_category;
    long existing_fingerprint = pc.getPluginLongParameter(feed_finger_key, 0);
    long feed_date = pc.getPluginLongParameter(feed_date_key, 0);
    long now = SystemTime.getCurrentTime();
    if (existing_fingerprint == fingerprint) {
        if (selected_dls.size() > 0) {
            if (now < feed_date || now - feed_date > FEED_UPDATE_MIN_MILLIS) {
                feed_date = now;
                pc.setPluginParameter(feed_date_key, feed_date);
            }
        }
    } else {
        pc.setPluginParameter(feed_finger_key, fingerprint);
        if (now <= feed_date) {
            feed_date++;
        } else {
            feed_date = now;
        }
        pc.setPluginParameter(feed_date_key, feed_date);
    }
    String last_modified = TimeFormatter.getHTTPDate(feed_date);
    if (if_mod != null && if_mod.equals(last_modified)) {
        return (new feedDetails(new byte[0], last_modified));
    }
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
        pw.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        pw.println("<rss version=\"2.0\" xmlns:vuze=\"http://www.vuze.com\">");
        pw.println("<channel>");
        pw.println("<title>" + escape(tag_or_category) + "</title>");
        Collections.sort(selected_dls, new Comparator<Download>() {

            @Override
            public int compare(Download d1, Download d2) {
                long added1 = getAddedTime(d1) / 1000;
                long added2 = getAddedTime(d2) / 1000;
                return ((int) (added2 - added1));
            }
        });
        pw.println("<pubDate>" + last_modified + "</pubDate>");
        for (int i = 0; i < selected_dls.size(); i++) {
            Download download = (Download) selected_dls.get(i);
            DownloadManager core_download = PluginCoreUtils.unwrap(download);
            Torrent torrent = download.getTorrent();
            String hash_str = Base32.encode(torrent.getHash());
            pw.println("<item>");
            pw.println("<title>" + escape(download.getName()) + "</title>");
            pw.println("<guid>" + hash_str + "</guid>");
            long added = core_download.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);
            pw.println("<pubDate>" + TimeFormatter.getHTTPDate(added) + "</pubDate>");
            pw.println("<vuze:size>" + torrent.getSize() + "</vuze:size>");
            pw.println("<vuze:assethash>" + hash_str + "</vuze:assethash>");
            String url = "azplug:?id=azbuddy&name=Friends&arg=";
            String arg = "pk=" + getPublicKey() + "&cat=" + tag_or_category + "&hash=" + Base32.encode(torrent.getHash());
            url += URLEncoder.encode(arg, "UTF-8");
            pw.println("<vuze:downloadurl>" + escape(url) + "</vuze:downloadurl>");
            DownloadScrapeResult scrape = download.getLastScrapeResult();
            if (scrape != null && scrape.getResponseType() == DownloadScrapeResult.RT_SUCCESS) {
                pw.println("<vuze:seeds>" + scrape.getSeedCount() + "</vuze:seeds>");
                pw.println("<vuze:peers>" + scrape.getNonSeedCount() + "</vuze:peers>");
            }
            pw.println("</item>");
        }
        pw.println("</channel>");
        pw.println("</rss>");
        pw.flush();
        return (new feedDetails(os.toByteArray(), last_modified));
    } catch (IOException e) {
        throw (new BuddyPluginException("", e));
    }
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) DownloadManager(com.biglybt.core.download.DownloadManager) PluginConfig(com.biglybt.pif.PluginConfig) Tag(com.biglybt.core.tag.Tag) Download(com.biglybt.pif.download.Download) DownloadScrapeResult(com.biglybt.pif.download.DownloadScrapeResult)

Example 48 with Tag

use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.

the class ShareHosterPlugin method addDownload.

private Download addDownload(ShareResource resource, final Torrent torrent, File torrent_file, File data_file) throws DownloadException {
    Map<String, String> properties = resource.getProperties();
    final List<String> networks = new ArrayList<>();
    final List<Tag> tags = new ArrayList<>();
    boolean force_networks = false;
    if (!COConfigurationManager.getBooleanParameter("Sharing Network Selection Global")) {
        force_networks = true;
        for (String net : AENetworkClassifier.AT_NETWORKS) {
            String config_name = "Sharing Network Selection Default." + net;
            if (COConfigurationManager.getBooleanParameter(config_name)) {
                networks.add(net);
            }
        }
    }
    if (properties != null) {
        String nets = properties.get(ShareManager.PR_NETWORKS);
        if (nets != null) {
            force_networks = true;
            networks.clear();
            String[] bits = nets.split(",");
            for (String bit : bits) {
                bit = AENetworkClassifier.internalise(bit.trim());
                if (bit != null) {
                    networks.add(bit);
                }
            }
        }
        String tags_str = properties.get(ShareManager.PR_TAGS);
        if (tags_str != null) {
            String[] bits = tags_str.split(",");
            TagManager tm = TagManagerFactory.getTagManager();
            for (String bit : bits) {
                try {
                    long tag_uid = Long.parseLong(bit.trim());
                    Tag tag = tm.lookupTagByUID(tag_uid);
                    if (tag != null) {
                        tags.add(tag);
                    }
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
        }
    }
    DownloadWillBeAddedListener dwbal = null;
    if (networks.size() > 0 || force_networks) {
        dwbal = new DownloadWillBeAddedListener() {

            @Override
            public void initialised(Download download) {
                if (Arrays.equals(download.getTorrentHash(), torrent.getHash())) {
                    PluginCoreUtils.unwrap(download).getDownloadState().setNetworks(networks.toArray(new String[networks.size()]));
                }
            }
        };
        download_manager.addDownloadWillBeAddedListener(dwbal);
    }
    try {
        Download download;
        if (resource.isPersistent()) {
            DownloadStub stub = download_manager.lookupDownloadStub(torrent.getHash());
            if (stub != null) {
                return (null);
            }
            try {
                torrent.setComplete(data_file);
            } catch (Throwable e) {
                Debug.out(e);
            }
            download = download_manager.addDownload(torrent, torrent_file, data_file);
        } else {
            download = download_manager.addNonPersistentDownload(torrent, torrent_file, data_file);
        }
        if (tags.size() > 0) {
            com.biglybt.core.download.DownloadManager dm = PluginCoreUtils.unwrap(download);
            for (Tag tag : tags) {
                tag.addTaggable(dm);
            }
        }
        return (download);
    } finally {
        if (dwbal != null) {
            download_manager.removeDownloadWillBeAddedListener(dwbal);
        }
    }
}
Also used : TagManager(com.biglybt.core.tag.TagManager) com.biglybt.pif.download(com.biglybt.pif.download) Tag(com.biglybt.core.tag.Tag)

Example 49 with Tag

use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.

the class BuddyPluginBeta method tagDownload.

public void tagDownload(Download download) {
    try {
        TagType tt = TagManagerFactory.getTagManager().getTagType(TagType.TT_DOWNLOAD_MANUAL);
        Tag tag = tt.getTag("tag.azbuddy.dchat.shares", false);
        if (tag == null) {
            tag = tt.createTag("tag.azbuddy.dchat.shares", true);
            tag.setCanBePublic(false);
            tag.setPublic(false);
        }
        tag.addTaggable(PluginCoreUtils.unwrap(download));
    } catch (Throwable e) {
        Debug.out(e);
    }
}
Also used : TagType(com.biglybt.core.tag.TagType) Tag(com.biglybt.core.tag.Tag)

Example 50 with Tag

use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.

the class ColumnTagXCode method refresh.

@Override
public void refresh(TableCell cell) {
    Tag tag = (Tag) cell.getDataSource();
    if (tag instanceof TagFeatureTranscode) {
        TagFeatureTranscode xcode = (TagFeatureTranscode) tag;
        if (xcode.supportsTagTranscode()) {
            String[] target_details = xcode.getTagTranscodeTarget();
            String target;
            if (target_details == null || target_details.length < 2) {
                target = "";
            } else {
                target = target_details[1];
            }
            if (!cell.setSortValue(target) && cell.isValid()) {
                return;
            }
            if (!cell.isShown()) {
                return;
            }
            cell.setText(target);
        }
    }
}
Also used : TagFeatureTranscode(com.biglybt.core.tag.TagFeatureTranscode) Tag(com.biglybt.core.tag.Tag)

Aggregations

Tag (com.biglybt.core.tag.Tag)55 DownloadManager (com.biglybt.core.download.DownloadManager)15 TagFeatureRateLimit (com.biglybt.core.tag.TagFeatureRateLimit)12 File (java.io.File)9 TagManager (com.biglybt.core.tag.TagManager)8 TagType (com.biglybt.core.tag.TagType)8 ArrayList (java.util.ArrayList)8 List (java.util.List)5 Core (com.biglybt.core.Core)4 CoreRunningListener (com.biglybt.core.CoreRunningListener)4 PEPeerManager (com.biglybt.core.peer.PEPeerManager)4 TagFeatureFileLocation (com.biglybt.core.tag.TagFeatureFileLocation)4 Point (org.eclipse.swt.graphics.Point)4 Category (com.biglybt.core.category.Category)3 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)3 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)3 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)3 TOTorrent (com.biglybt.core.torrent.TOTorrent)3 Download (com.biglybt.pif.download.Download)3 GlobalManager (com.biglybt.core.global.GlobalManager)2