mirror of
https://github.com/mirror/jdownloader.git
synced 2024-11-27 05:50:51 +00:00
*General*
- MergeSameNamedPackagesAction: updated to also work in downloadlist refs #90420 - MergeToPackageAction: eliminated some duplicated code - MenuManagerDownloadTableContext: added MergeSameNamedPackagesAction next to SplitPackagesByHost git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@49486 ebf7c1c2-ba36-0410-9fe8-c592906822b4 Former-commit-id: 9e16e5785db027a5e450f3c4dd1c3a3c8442dd9b
This commit is contained in:
parent
94b501d875
commit
e41b9fcfa5
@ -1,10 +1,9 @@
|
||||
package org.jdownloader.gui.views.downloads.action;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.HashSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.appwork.utils.Regex;
|
||||
import org.appwork.utils.StringUtils;
|
||||
import org.appwork.utils.event.queue.QueueAction;
|
||||
import org.appwork.utils.swing.dialog.Dialog;
|
||||
@ -23,6 +22,7 @@ import org.jdownloader.gui.views.linkgrabber.contextmenu.NewPackageDialog;
|
||||
import org.jdownloader.translate._JDT;
|
||||
|
||||
import jd.controlling.downloadcontroller.DownloadController;
|
||||
import jd.controlling.packagecontroller.AbstractNode;
|
||||
import jd.plugins.DownloadLink;
|
||||
import jd.plugins.FilePackage;
|
||||
|
||||
@ -119,24 +119,9 @@ public class MergeToPackageAction extends CustomizableTableContextAppAction<File
|
||||
newPackage.setExpanded(isExpandNewPackage());
|
||||
newPackage.setName(name);
|
||||
newPackage.setDownloadDirectory(PackagizerController.replaceDynamicTags(downloadFolder, name, newPackage));
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final HashSet<String> commentDups = new HashSet<String>();
|
||||
for (PackageView<FilePackage, DownloadLink> pv : sel.getPackageViews()) {
|
||||
final String comment = pv.getPackage().getComment();
|
||||
if (StringUtils.isNotEmpty(comment)) {
|
||||
final String[] commentLines = Regex.getLines(comment);
|
||||
for (final String commentLine : commentLines) {
|
||||
if (StringUtils.isNotEmpty(commentLine) && commentDups.add(commentLine)) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append("\r\n");
|
||||
}
|
||||
sb.append(commentLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sb.length() > 0) {
|
||||
newPackage.setComment(sb.toString());
|
||||
final String mergedComment = mergePackageComments(sel.getPackageViews());
|
||||
if (!StringUtils.isEmpty(mergedComment)) {
|
||||
newPackage.setComment(mergedComment);
|
||||
}
|
||||
switch (getLocation()) {
|
||||
case AFTER_SELECTION:
|
||||
@ -170,22 +155,10 @@ public class MergeToPackageAction extends CustomizableTableContextAppAction<File
|
||||
|
||||
/** Merges comments of multiple packages into one string. */
|
||||
public static String mergePackageComments(final List<PackageView<FilePackage, DownloadLink>> packages) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final HashSet<String> commentDups = new HashSet<String>();
|
||||
final List<AbstractNode> filepackages = new ArrayList<AbstractNode>();
|
||||
for (PackageView<FilePackage, DownloadLink> pv : packages) {
|
||||
final String comment = pv.getPackage().getComment();
|
||||
if (StringUtils.isNotEmpty(comment)) {
|
||||
final String[] commentLines = Regex.getLines(comment);
|
||||
for (final String commentLine : commentLines) {
|
||||
if (StringUtils.isNotEmpty(commentLine) && commentDups.add(commentLine)) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append("\r\n");
|
||||
}
|
||||
sb.append(commentLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
filepackages.add(pv.getPackage());
|
||||
}
|
||||
return sb.toString();
|
||||
return org.jdownloader.gui.views.linkgrabber.contextmenu.MergeToPackageAction.mergePackageComments(filepackages);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,5 @@
|
||||
package org.jdownloader.gui.views.downloads.contextmenumanager;
|
||||
|
||||
import jd.plugins.DownloadLink;
|
||||
import jd.plugins.FilePackage;
|
||||
|
||||
import org.appwork.utils.os.CrossSystem;
|
||||
import org.appwork.utils.swing.EDTRunner;
|
||||
import org.jdownloader.controlling.contextmenu.ActionData;
|
||||
@ -56,12 +53,16 @@ import org.jdownloader.gui.views.downloads.context.submenu.PriorityMenuContainer
|
||||
import org.jdownloader.gui.views.downloads.context.submenu.SettingsMenuContainer;
|
||||
import org.jdownloader.gui.views.downloads.table.DownloadsTable;
|
||||
import org.jdownloader.gui.views.downloads.table.DownloadsTableModel;
|
||||
import org.jdownloader.gui.views.linkgrabber.actions.MergeSameNamedPackagesAction;
|
||||
import org.jdownloader.gui.views.linkgrabber.bottombar.IncludedSelectionSetup;
|
||||
import org.jdownloader.gui.views.linkgrabber.contextmenu.AddContainerContextMenuAction;
|
||||
import org.jdownloader.gui.views.linkgrabber.contextmenu.AddLinksContextMenuAction;
|
||||
import org.jdownloader.gui.views.linkgrabber.contextmenu.SortAction;
|
||||
import org.jdownloader.settings.GraphicalUserInterfaceSettings.DeleteFileOptions;
|
||||
|
||||
import jd.plugins.DownloadLink;
|
||||
import jd.plugins.FilePackage;
|
||||
|
||||
public class MenuManagerDownloadTableContext extends ContextMenuManager<FilePackage, DownloadLink> {
|
||||
private static final MenuManagerDownloadTableContext INSTANCE = new MenuManagerDownloadTableContext();
|
||||
|
||||
@ -91,7 +92,6 @@ public class MenuManagerDownloadTableContext extends ContextMenuManager<FilePack
|
||||
mr.add(AddLinksContextMenuAction.class);
|
||||
mr.add(AddContainerContextMenuAction.class);
|
||||
mr.add(new SeparatorData());
|
||||
// mr.add()
|
||||
mr.add(createSettingsMenu());
|
||||
mr.add(new SeparatorData());
|
||||
mr.add(new DownloadsTablePluginLink());
|
||||
@ -142,6 +142,7 @@ public class MenuManagerDownloadTableContext extends ContextMenuManager<FilePack
|
||||
more.add(new SeparatorData());
|
||||
more.add(new MenuItemData(new ActionData(MergeToPackageAction.class)));
|
||||
more.add(new MenuItemData(new ActionData(SplitPackagesByHost.class)));
|
||||
more.add(new MenuItemData(new ActionData(MergeSameNamedPackagesAction.class)));
|
||||
more.add(new MenuItemData(new ActionData(RunCheckSumAction.class)));
|
||||
more.add(new MenuItemData(new ActionData(ConfirmHashValuesDownloadAction.class)));
|
||||
more.add(new MenuItemData(new ActionData(CreateDLCAction.class)));
|
||||
|
@ -26,6 +26,7 @@ import jd.controlling.downloadcontroller.DownloadController;
|
||||
import jd.controlling.linkcollector.LinkCollector;
|
||||
import jd.controlling.linkcrawler.CrawledLink;
|
||||
import jd.controlling.linkcrawler.CrawledPackage;
|
||||
import jd.controlling.packagecontroller.AbstractNode;
|
||||
import jd.controlling.packagecontroller.AbstractPackageNode;
|
||||
import jd.gui.swing.jdgui.MainTabbedPane;
|
||||
import jd.plugins.FilePackage;
|
||||
@ -52,7 +53,6 @@ public class MergeSameNamedPackagesAction extends CustomizableTableContextAppAct
|
||||
*
|
||||
*/
|
||||
public MergeSameNamedPackagesAction() {
|
||||
// TODO: Find a suitable symbol
|
||||
super(true, true);
|
||||
// setSmallIcon(new BadgeIcon("logo/dlc", "autoMerge", 32, 24, 2, 6));
|
||||
setName(_GUI.T.MergeSameNamedPackagesAction_());
|
||||
@ -71,23 +71,8 @@ public class MergeSameNamedPackagesAction extends CustomizableTableContextAppAct
|
||||
if (!isEnabled()) {
|
||||
return;
|
||||
}
|
||||
// TODO: Remove uglyness
|
||||
try {
|
||||
final Map<String, List<Object>> dupes = new HashMap<String, List<Object>>();
|
||||
final List<?> pckages;
|
||||
final boolean isLinkgrabber;
|
||||
if (MainTabbedPane.getInstance().isDownloadView()) {
|
||||
pckages = DownloadController.getInstance().getPackages();
|
||||
isLinkgrabber = false;
|
||||
} else if (MainTabbedPane.getInstance().isLinkgrabberView()) {
|
||||
final LinkCollector lc = LinkCollector.getInstance();
|
||||
pckages = lc.getPackages();
|
||||
isLinkgrabber = true;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
final boolean caseInsensitive = isMatchPackageNamesCaseInsensitive();
|
||||
boolean foundDupes = false;
|
||||
final SelectionInfo<?, ?> sel = getSelection();
|
||||
/* If user has selected a package, only collect duplicates of name of selected package. */
|
||||
Map<String, Object> selectedPackagesMap = null;
|
||||
@ -109,8 +94,30 @@ public class MergeSameNamedPackagesAction extends CustomizableTableContextAppAct
|
||||
}
|
||||
selectedPackagesMap.put(compareName, crawledpackage);
|
||||
}
|
||||
if (selectedPackagesMap.isEmpty()) {
|
||||
/* Do nothing */
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (Object pckage : pckages) {
|
||||
final Map<String, List<AbstractNode>> dupes = new HashMap<String, List<AbstractNode>>();
|
||||
final List<AbstractNode> packages = new ArrayList<AbstractNode>();
|
||||
final boolean isLinkgrabber;
|
||||
if (MainTabbedPane.getInstance().isDownloadView()) {
|
||||
isLinkgrabber = false;
|
||||
for (final FilePackage item : DownloadController.getInstance().getPackages()) {
|
||||
packages.add(item);
|
||||
}
|
||||
} else if (MainTabbedPane.getInstance().isLinkgrabberView()) {
|
||||
isLinkgrabber = true;
|
||||
for (final CrawledPackage item : LinkCollector.getInstance().getPackages()) {
|
||||
packages.add(item);
|
||||
}
|
||||
} else {
|
||||
/* This should never happen */
|
||||
return;
|
||||
}
|
||||
boolean foundDupes = false;
|
||||
for (final AbstractNode pckage : packages) {
|
||||
String packagename;
|
||||
if (isLinkgrabber) {
|
||||
packagename = ((CrawledPackage) pckage).getName();
|
||||
@ -124,12 +131,12 @@ public class MergeSameNamedPackagesAction extends CustomizableTableContextAppAct
|
||||
/* Only search dupes for selected package(s) */
|
||||
continue;
|
||||
}
|
||||
List<Object> thisdupeslist = dupes.get(packagename);
|
||||
List<AbstractNode> thisdupeslist = dupes.get(packagename);
|
||||
if (thisdupeslist != null) {
|
||||
/* We got at least two packages with the same name */
|
||||
foundDupes = true;
|
||||
} else {
|
||||
thisdupeslist = new ArrayList<Object>();
|
||||
thisdupeslist = new ArrayList<AbstractNode>();
|
||||
dupes.put(packagename, thisdupeslist);
|
||||
}
|
||||
thisdupeslist.add(pckage);
|
||||
@ -143,30 +150,40 @@ public class MergeSameNamedPackagesAction extends CustomizableTableContextAppAct
|
||||
@Override
|
||||
protected Void run() throws RuntimeException {
|
||||
/* Merge dupes */
|
||||
final Iterator<Entry<String, List<Object>>> dupes_iterator = dupes.entrySet().iterator();
|
||||
final Iterator<Entry<String, List<AbstractNode>>> dupes_iterator = dupes.entrySet().iterator();
|
||||
while (dupes_iterator.hasNext()) {
|
||||
final Entry<String, List<Object>> entry = dupes_iterator.next();
|
||||
final Entry<String, List<AbstractNode>> entry = dupes_iterator.next();
|
||||
// final String packagename = entry.getKey();
|
||||
final List<Object> thisdupes = entry.getValue();
|
||||
final List<AbstractNode> thisdupes = entry.getValue();
|
||||
if (thisdupes.size() == 1) {
|
||||
/* We need at least two packages to be able to merge them. */
|
||||
continue;
|
||||
}
|
||||
/* Merge comments of all packages so we don't lose any information. */
|
||||
if (isLinkgrabber) {
|
||||
final List<CrawledPackage> linkgrabberdupes = new ArrayList<CrawledPackage>();
|
||||
for (final Object thisdupe : thisdupes) {
|
||||
linkgrabberdupes.add((CrawledPackage) thisdupe);
|
||||
final List<CrawledPackage> casteddupes = new ArrayList<CrawledPackage>();
|
||||
for (final AbstractNode thisdupe : thisdupes) {
|
||||
casteddupes.add((CrawledPackage) thisdupe);
|
||||
}
|
||||
final String mergedComments = MergeToPackageAction.mergeCrawledPackageListComments(linkgrabberdupes);
|
||||
final String mergedComments = MergeToPackageAction.mergePackageComments(thisdupes);
|
||||
/* Pick package to merge the others into */
|
||||
final CrawledPackage target = (CrawledPackage) thisdupes.remove(0);
|
||||
if (!StringUtils.isEmpty(mergedComments)) {
|
||||
target.setComment(mergedComments);
|
||||
}
|
||||
LinkCollector.getInstance().merge(target, linkgrabberdupes, MergePosition.BOTTOM);
|
||||
LinkCollector.getInstance().merge(target, casteddupes, MergePosition.BOTTOM);
|
||||
} else {
|
||||
// TODO
|
||||
final List<FilePackage> casteddupes = new ArrayList<FilePackage>();
|
||||
for (final AbstractNode thisdupe : thisdupes) {
|
||||
casteddupes.add((FilePackage) thisdupe);
|
||||
}
|
||||
final String mergedComments = MergeToPackageAction.mergePackageComments(thisdupes);
|
||||
/* Pick package to merge the others into */
|
||||
final FilePackage target = (FilePackage) thisdupes.remove(0);
|
||||
if (!StringUtils.isEmpty(mergedComments)) {
|
||||
target.setComment(mergedComments);
|
||||
}
|
||||
DownloadController.getInstance().merge(target, casteddupes, MergePosition.BOTTOM);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -2,7 +2,6 @@ package org.jdownloader.gui.views.linkgrabber.contextmenu;
|
||||
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import org.appwork.utils.DebugMode;
|
||||
import org.appwork.utils.os.CrossSystem;
|
||||
import org.jdownloader.controlling.contextmenu.ActionData;
|
||||
import org.jdownloader.controlling.contextmenu.ContextMenuManager;
|
||||
@ -94,6 +93,7 @@ public class MenuManagerLinkgrabberTableContext extends ContextMenuManager<Crawl
|
||||
mr.add(new SeparatorData());
|
||||
mr.add(createSettingsSubmenu());
|
||||
mr.add(SortAction.class);
|
||||
mr.add(MergeSameNamedPackagesAction.class);
|
||||
mr.add(EnabledAction.class);
|
||||
mr.add(new SeparatorData());
|
||||
mr.add(CheckStatusAction.class);
|
||||
@ -114,9 +114,6 @@ public class MenuManagerLinkgrabberTableContext extends ContextMenuManager<Crawl
|
||||
opt.add(CollapseExpandContextAction.class);
|
||||
opt.add(CopyGenericContextAction.class);
|
||||
opt.add(ConfirmHashValuesLinkgrabberAction.class);
|
||||
if (DebugMode.TRUE_IN_IDE_ELSE_FALSE) {
|
||||
opt.add(MergeSameNamedPackagesAction.class);
|
||||
}
|
||||
return mr;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,8 @@ import org.jdownloader.translate._JDT;
|
||||
import jd.controlling.linkcollector.LinkCollector;
|
||||
import jd.controlling.linkcrawler.CrawledLink;
|
||||
import jd.controlling.linkcrawler.CrawledPackage;
|
||||
import jd.controlling.packagecontroller.AbstractNode;
|
||||
import jd.plugins.FilePackage;
|
||||
|
||||
public class MergeToPackageAction extends CustomizableTableContextAppAction<CrawledPackage, CrawledLink> implements ActionContext {
|
||||
/**
|
||||
@ -157,19 +159,24 @@ public class MergeToPackageAction extends CustomizableTableContextAppAction<Craw
|
||||
|
||||
/** Merges comments of multiple packages into one string. */
|
||||
public static String mergePackageViewListComments(final List<PackageView<CrawledPackage, CrawledLink>> packages) {
|
||||
final List<CrawledPackage> crawledpackagelist = new ArrayList<CrawledPackage>();
|
||||
final List<AbstractNode> crawledpackagelist = new ArrayList<AbstractNode>();
|
||||
for (PackageView<CrawledPackage, CrawledLink> pv : packages) {
|
||||
crawledpackagelist.add(pv.getPackage());
|
||||
}
|
||||
return mergeCrawledPackageListComments(crawledpackagelist);
|
||||
return mergePackageComments(crawledpackagelist);
|
||||
}
|
||||
|
||||
/** Merges comments of given packages into one string. */
|
||||
public static String mergeCrawledPackageListComments(final List<CrawledPackage> packages) {
|
||||
public static String mergePackageComments(final List<AbstractNode> packages) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final HashSet<String> commentDups = new HashSet<String>();
|
||||
for (final CrawledPackage cp : packages) {
|
||||
final String comment = cp.getComment();
|
||||
for (final AbstractNode cp : packages) {
|
||||
final String comment;
|
||||
if (cp instanceof CrawledPackage) {
|
||||
comment = ((CrawledPackage) cp).getComment();
|
||||
} else {
|
||||
comment = ((FilePackage) cp).getComment();
|
||||
}
|
||||
if (StringUtils.isNotEmpty(comment)) {
|
||||
final String[] commentLines = Regex.getLines(comment);
|
||||
for (final String commentLine : commentLines) {
|
||||
|
Loading…
Reference in New Issue
Block a user