Skip to content

Commit

Permalink
- added flexibility on changing path for batch links
Browse files Browse the repository at this point in the history
  • Loading branch information
BeanVortex committed May 11, 2024
1 parent 86c0033 commit 59614d2
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci_cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
branches:
- main
env:
VERSION: 1.4.6
EXT_VERSION: 1.0
VERSION: 1.4.7
EXT_VERSION: 1.1
NAME: BitKip
jobs:
build-windows:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group 'io.beanvortex'
version '1.4.6'
version '1.4.7'
sourceCompatibility = '21'
targetCompatibility = '21'
mainClassName = 'io.beanvortex.bitkip.BitKip'
Expand Down
2 changes: 1 addition & 1 deletion builders/linux-installer/application/BitKip.desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Desktop Entry]
Name=BitKip
Version=1.4.6
Version=1.4.7
Comment=Free download manager
Keywords=download,java,app
Exec=/usr/share/BitKip/bin/BitKip
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/beanvortex/bitkip/config/AppConfigs.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class AppConfigs {

public static final String VERSION = "1.4.6";
public static final String VERSION = "1.4.7";

public static final String dataPath = System.getProperty("user.home")
+ File.separator + "Documents"
Expand Down
64 changes: 58 additions & 6 deletions src/main/java/io/beanvortex/bitkip/controllers/BatchList.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package io.beanvortex.bitkip.controllers;

import io.beanvortex.bitkip.BitKip;
import io.beanvortex.bitkip.config.AppConfigs;
import io.beanvortex.bitkip.models.*;
import io.beanvortex.bitkip.repo.DownloadsRepo;
import io.beanvortex.bitkip.task.LinkDataTask;
import io.beanvortex.bitkip.utils.Defaults;
import io.beanvortex.bitkip.utils.DownloadUtils;
import io.beanvortex.bitkip.utils.FxUtils;
import io.beanvortex.bitkip.utils.LinkTableUtils;
import io.beanvortex.bitkip.config.observers.QueueObserver;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TableView;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.kordamp.ikonli.javafx.FontIcon;

import java.io.File;
Expand All @@ -32,10 +36,15 @@
import static io.beanvortex.bitkip.config.observers.QueueSubject.getQueues;

public class BatchList implements QueueObserver {

@FXML
private TextField locationField;
@FXML
private CheckBox lastLocationCheck;
@FXML
private ComboBox<QueueModel> comboQueue;
@FXML
private Button addBtn,newQueue;
private Button addBtn, newQueue, openLocation;
@FXML
private TableView<LinkModel> linkTable;

Expand All @@ -45,12 +54,28 @@ public class BatchList implements QueueObserver {
private static final QueueModel customQueue = new QueueModel("CUSTOM", false);


@AllArgsConstructor
@Getter
@Setter
public static class LocationData {
private TextField locationField;
private String firstPath;
private boolean change;

public void revertPath() {
locationField.setText(firstPath);
}
}

private LocationData location;

@Override
public void initialize(URL location, ResourceBundle resources) {
public void initialize(URL l, ResourceBundle resources) {
addBtn.requestFocus();
addBtn.setDisable(true);
comboQueue.setDisable(true);
newQueue.setGraphic(new FontIcon());
location = new LocationData(locationField, null, true);
}


Expand All @@ -64,6 +89,14 @@ public void setData(List<LinkModel> links) {
this.links = links;
linkTableUtils = new LinkTableUtils(linkTable, links, comboQueue, stage);
linkTableUtils.tableInits();
location.setFirstPath(links.get(0).getPath());
locationField.setText(location.getFirstPath());
locationField.textProperty().addListener((o, ol, n) -> {
if (location.isChange()) {
links.forEach(l -> l.setPath(n));
linkTableUtils.refreshTable();
} else location.setChange(true);
});
fetchLinksData(links);
initQueueCombo();
}
Expand Down Expand Up @@ -107,7 +140,7 @@ private void initQueueCombo() {
var selectedItem = comboQueue.getSelectionModel().getSelectedItem();
if (selectedItem.getName().equals(customQueue.getName()))
return;
linkTableUtils.changeQueues(selectedItem);
linkTableUtils.changeQueues(selectedItem, location);
});
}

Expand All @@ -119,6 +152,7 @@ private void errorLog(Throwable err) {
@Override
public void initAfterStage() {
updateTheme(stage.getScene());
openLocation.setGraphic(new FontIcon());
stage.widthProperty().addListener((ob, o, n) -> linkTable.setPrefWidth(n.doubleValue() + 90));
var logoPath = BitKip.getResource("icons/logo.png");
if (logoPath != null) {
Expand Down Expand Up @@ -188,4 +222,22 @@ public void onNewQueue() {
FxUtils.newQueueStage();

}

@FXML
private void onSelectLocation(ActionEvent e) {
var path = DownloadUtils.selectLocation(FxUtils.getStageFromEvent(e));
if (path != null)
locationField.setText(path);
// DownloadUtils.handleError(() -> DownloadUtils.checkIfFileIsOKToSave(locationField.getText(),
// null, null, addBtn, null, lastLocationCheck), null);
}

@FXML
private void onLastLocationCheck() {
if (lastLocationCheck.isSelected())
locationField.setText(AppConfigs.lastSavedDir);
else
locationField.setText(location.getFirstPath());
}

}
40 changes: 26 additions & 14 deletions src/main/java/io/beanvortex/bitkip/utils/LinkTableUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.beanvortex.bitkip.utils;

import io.beanvortex.bitkip.controllers.BatchList;
import io.beanvortex.bitkip.models.LinkModel;
import io.beanvortex.bitkip.models.QueueModel;
import javafx.collections.FXCollections;
Expand Down Expand Up @@ -47,33 +48,39 @@ public void tableInits() {
var resumeCol = new TableColumn<LinkModel, String>("Resumable");
queuesCol = new TableColumn<>("Queue");
var linkCol = new TableColumn<LinkModel, String>("Link");
var pathCol = new TableColumn<LinkModel, String>("Path");

nameCol.setPrefWidth(300);
sizeCol.setPrefWidth(90);
chunksCol.setPrefWidth(70);
resumeCol.setPrefWidth(90);
queuesCol.setPrefWidth(120);
linkCol.setPrefWidth(200);
pathCol.setPrefWidth(200);
nameCol.setSortType(TableColumn.SortType.DESCENDING);

List<TableColumn<LinkModel, ?>> listOfColumns = List.of(nameCol, sizeCol, chunksCol, resumeCol, queuesCol, linkCol);
List<TableColumn<LinkModel, ?>> listOfColumns = List.of(nameCol, sizeCol, chunksCol, resumeCol,
queuesCol, linkCol, pathCol);
table.getColumns().addAll(listOfColumns);
nameCol.setCellValueFactory(new PropertyValueFactory<>("name"));
sizeCol.setCellValueFactory(new PropertyValueFactory<>("sizeString"));
chunksCol.setCellValueFactory(new PropertyValueFactory<>("chunks"));
resumeCol.setCellValueFactory(new PropertyValueFactory<>("resumableString"));
linkCol.setCellValueFactory(new PropertyValueFactory<>("uri"));
pathCol.setCellValueFactory(new PropertyValueFactory<>("path"));
queuesCol.setCellValueFactory(new PropertyValueFactory<>("queuesString"));

linkCol.setCellFactory(TextFieldTableCell.forTableColumn());
linkCol.setOnEditCommit(e -> e.getTableView().getItems().get(e.getTablePosition().getRow()).setUri(e.getNewValue()));
pathCol.setCellFactory(TextFieldTableCell.forTableColumn());
pathCol.setOnEditCommit(e -> e.getTableView().getItems().get(e.getTablePosition().getRow()).setPath(e.getNewValue()));
nameCol.setCellFactory(TextFieldTableCell.forTableColumn());
nameCol.setOnEditCommit(e -> e.getTableView().getItems().get(e.getTablePosition().getRow()).setName(e.getNewValue()));
var queuesToShow = getQueues().stream()
.filter(qm -> qm.getName().equals(ALL_DOWNLOADS_QUEUE) || !staticQueueNames.contains(qm.getName()))
.toList();
queuesCol.setCellFactory(p -> new ComboBoxTableCell<>(FXCollections.observableArrayList(queuesToShow)));
queuesCol.setOnEditCommit(e -> changeLinkQueues(e.getRowValue(), e.getNewValue(), true));
queuesCol.setOnEditCommit(e -> changeLinkQueues(e.getRowValue(), e.getNewValue(), null, true));

table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

Expand Down Expand Up @@ -153,12 +160,13 @@ public void updateQueues() {
queuesCol.setCellFactory(p -> new ComboBoxTableCell<>(FXCollections.observableArrayList(queuesToShow)));
}

public void changeQueues(QueueModel queue) {
table.getItems().forEach(lm -> changeLinkQueues(lm, queue, false));
public void changeQueues(QueueModel queue, BatchList.LocationData location) {
location.setChange(false);
table.getItems().forEach(lm -> changeLinkQueues(lm, queue, location, false));
refreshTable();
}

public void changeLinkQueues(LinkModel lm, QueueModel newQueue, boolean fromTable) {
public void changeLinkQueues(LinkModel lm, QueueModel newQueue, BatchList.LocationData location, boolean fromTable) {
var queues = lm.getQueues()
.stream().filter(qm -> staticQueueNames.contains(qm.getName()))
.toList();
Expand All @@ -167,16 +175,20 @@ public void changeLinkQueues(LinkModel lm, QueueModel newQueue, boolean fromTabl
lm.setPath(lm.getSelectedPath());
if (fromTable)
comboQueue.getSelectionModel().select(comboQueue.getItems().size() - 1);
if (!newQueue.getName().equals(ALL_DOWNLOADS_QUEUE)) {
if (newQueue.hasFolder()) {
var folder = new File(queuesPath + newQueue.getName());
var path = folder.getAbsolutePath();
if (!path.endsWith(File.separator))
path += File.separator;
lm.setPath(path);
}
if (!newQueue.getName().equals(ALL_DOWNLOADS_QUEUE))
lm.getQueues().add(newQueue);
}

if (newQueue.hasFolder()) {
var folder = new File(queuesPath + newQueue.getName());
var path = folder.getAbsolutePath();
if (!path.endsWith(File.separator))
path += File.separator;
lm.setPath(path);
if (location != null)
location.getLocationField().setText(path);
} else if (location != null) {
location.revertPath();
lm.setPath(location.getFirstPath());
}
}
}
21 changes: 16 additions & 5 deletions src/main/resources/io/beanvortex/bitkip/fxml/batchList.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,22 @@
<HBox maxWidth="2" minWidth="2" styleClass="csm_toolbar"/>
</HBox>

<HBox spacing="5" alignment="CENTER_LEFT">
<Label text="Change queue for all"/>
<ComboBox fx:id="comboQueue"/>
<Button fx:id="newQueue" onAction="#onNewQueue"/>
</HBox>
<VBox styleClass="padding_5" spacing="10">
<HBox spacing="5" alignment="CENTER_LEFT">
<Label text="Change queue for all"/>
<ComboBox fx:id="comboQueue"/>
<Button fx:id="newQueue" onAction="#onNewQueue"/>
</HBox>

<VBox spacing="10">
<HBox spacing="15" alignment="CENTER">
<Label text="Location :" minWidth="60" styleClass="bold"/>
<TextField fx:id="locationField" HBox.hgrow="ALWAYS"/>
<Button fx:id="openLocation" onAction="#onSelectLocation"/>
</HBox>
<CheckBox text="Use the last selected location" fx:id="lastLocationCheck" onAction="#onLastLocationCheck"/>
</VBox>
</VBox>

<HBox alignment="BOTTOM_CENTER" style="-fx-padding: 15 0 15 0">
<HBox spacing="20" alignment="CENTER">
Expand Down

0 comments on commit 59614d2

Please sign in to comment.