Skip to content

Commit 59614d2

Browse files
committed
- added flexibility on changing path for batch links
1 parent 86c0033 commit 59614d2

7 files changed

Lines changed: 105 additions & 30 deletions

File tree

.github/workflows/ci_cd.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ on:
44
branches:
55
- main
66
env:
7-
VERSION: 1.4.6
8-
EXT_VERSION: 1.0
7+
VERSION: 1.4.7
8+
EXT_VERSION: 1.1
99
NAME: BitKip
1010
jobs:
1111
build-windows:

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group 'io.beanvortex'
11-
version '1.4.6'
11+
version '1.4.7'
1212
sourceCompatibility = '21'
1313
targetCompatibility = '21'
1414
mainClassName = 'io.beanvortex.bitkip.BitKip'

builders/linux-installer/application/BitKip.desktop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Desktop Entry]
22
Name=BitKip
3-
Version=1.4.6
3+
Version=1.4.7
44
Comment=Free download manager
55
Keywords=download,java,app
66
Exec=/usr/share/BitKip/bin/BitKip

src/main/java/io/beanvortex/bitkip/config/AppConfigs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
public class AppConfigs {
1919

20-
public static final String VERSION = "1.4.6";
20+
public static final String VERSION = "1.4.7";
2121

2222
public static final String dataPath = System.getProperty("user.home")
2323
+ File.separator + "Documents"

src/main/java/io/beanvortex/bitkip/controllers/BatchList.java

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
package io.beanvortex.bitkip.controllers;
22

33
import io.beanvortex.bitkip.BitKip;
4+
import io.beanvortex.bitkip.config.AppConfigs;
45
import io.beanvortex.bitkip.models.*;
56
import io.beanvortex.bitkip.repo.DownloadsRepo;
67
import io.beanvortex.bitkip.task.LinkDataTask;
78
import io.beanvortex.bitkip.utils.Defaults;
9+
import io.beanvortex.bitkip.utils.DownloadUtils;
810
import io.beanvortex.bitkip.utils.FxUtils;
911
import io.beanvortex.bitkip.utils.LinkTableUtils;
1012
import io.beanvortex.bitkip.config.observers.QueueObserver;
1113
import javafx.collections.FXCollections;
14+
import javafx.event.ActionEvent;
1215
import javafx.fxml.FXML;
13-
import javafx.scene.control.Button;
14-
import javafx.scene.control.ComboBox;
15-
import javafx.scene.control.TableView;
16+
import javafx.scene.control.*;
1617
import javafx.scene.image.Image;
1718
import javafx.stage.Stage;
19+
import lombok.AllArgsConstructor;
20+
import lombok.Getter;
21+
import lombok.Setter;
1822
import org.kordamp.ikonli.javafx.FontIcon;
1923

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

3438
public class BatchList implements QueueObserver {
39+
40+
@FXML
41+
private TextField locationField;
42+
@FXML
43+
private CheckBox lastLocationCheck;
3544
@FXML
3645
private ComboBox<QueueModel> comboQueue;
3746
@FXML
38-
private Button addBtn,newQueue;
47+
private Button addBtn, newQueue, openLocation;
3948
@FXML
4049
private TableView<LinkModel> linkTable;
4150

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

4756

57+
@AllArgsConstructor
58+
@Getter
59+
@Setter
60+
public static class LocationData {
61+
private TextField locationField;
62+
private String firstPath;
63+
private boolean change;
64+
65+
public void revertPath() {
66+
locationField.setText(firstPath);
67+
}
68+
}
69+
70+
private LocationData location;
71+
4872
@Override
49-
public void initialize(URL location, ResourceBundle resources) {
73+
public void initialize(URL l, ResourceBundle resources) {
5074
addBtn.requestFocus();
5175
addBtn.setDisable(true);
5276
comboQueue.setDisable(true);
5377
newQueue.setGraphic(new FontIcon());
78+
location = new LocationData(locationField, null, true);
5479
}
5580

5681

@@ -64,6 +89,14 @@ public void setData(List<LinkModel> links) {
6489
this.links = links;
6590
linkTableUtils = new LinkTableUtils(linkTable, links, comboQueue, stage);
6691
linkTableUtils.tableInits();
92+
location.setFirstPath(links.get(0).getPath());
93+
locationField.setText(location.getFirstPath());
94+
locationField.textProperty().addListener((o, ol, n) -> {
95+
if (location.isChange()) {
96+
links.forEach(l -> l.setPath(n));
97+
linkTableUtils.refreshTable();
98+
} else location.setChange(true);
99+
});
67100
fetchLinksData(links);
68101
initQueueCombo();
69102
}
@@ -107,7 +140,7 @@ private void initQueueCombo() {
107140
var selectedItem = comboQueue.getSelectionModel().getSelectedItem();
108141
if (selectedItem.getName().equals(customQueue.getName()))
109142
return;
110-
linkTableUtils.changeQueues(selectedItem);
143+
linkTableUtils.changeQueues(selectedItem, location);
111144
});
112145
}
113146

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

190224
}
225+
226+
@FXML
227+
private void onSelectLocation(ActionEvent e) {
228+
var path = DownloadUtils.selectLocation(FxUtils.getStageFromEvent(e));
229+
if (path != null)
230+
locationField.setText(path);
231+
// DownloadUtils.handleError(() -> DownloadUtils.checkIfFileIsOKToSave(locationField.getText(),
232+
// null, null, addBtn, null, lastLocationCheck), null);
233+
}
234+
235+
@FXML
236+
private void onLastLocationCheck() {
237+
if (lastLocationCheck.isSelected())
238+
locationField.setText(AppConfigs.lastSavedDir);
239+
else
240+
locationField.setText(location.getFirstPath());
241+
}
242+
191243
}

src/main/java/io/beanvortex/bitkip/utils/LinkTableUtils.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.beanvortex.bitkip.utils;
22

3+
import io.beanvortex.bitkip.controllers.BatchList;
34
import io.beanvortex.bitkip.models.LinkModel;
45
import io.beanvortex.bitkip.models.QueueModel;
56
import javafx.collections.FXCollections;
@@ -47,33 +48,39 @@ public void tableInits() {
4748
var resumeCol = new TableColumn<LinkModel, String>("Resumable");
4849
queuesCol = new TableColumn<>("Queue");
4950
var linkCol = new TableColumn<LinkModel, String>("Link");
51+
var pathCol = new TableColumn<LinkModel, String>("Path");
5052

5153
nameCol.setPrefWidth(300);
5254
sizeCol.setPrefWidth(90);
5355
chunksCol.setPrefWidth(70);
5456
resumeCol.setPrefWidth(90);
5557
queuesCol.setPrefWidth(120);
5658
linkCol.setPrefWidth(200);
59+
pathCol.setPrefWidth(200);
5760
nameCol.setSortType(TableColumn.SortType.DESCENDING);
5861

59-
List<TableColumn<LinkModel, ?>> listOfColumns = List.of(nameCol, sizeCol, chunksCol, resumeCol, queuesCol, linkCol);
62+
List<TableColumn<LinkModel, ?>> listOfColumns = List.of(nameCol, sizeCol, chunksCol, resumeCol,
63+
queuesCol, linkCol, pathCol);
6064
table.getColumns().addAll(listOfColumns);
6165
nameCol.setCellValueFactory(new PropertyValueFactory<>("name"));
6266
sizeCol.setCellValueFactory(new PropertyValueFactory<>("sizeString"));
6367
chunksCol.setCellValueFactory(new PropertyValueFactory<>("chunks"));
6468
resumeCol.setCellValueFactory(new PropertyValueFactory<>("resumableString"));
6569
linkCol.setCellValueFactory(new PropertyValueFactory<>("uri"));
70+
pathCol.setCellValueFactory(new PropertyValueFactory<>("path"));
6671
queuesCol.setCellValueFactory(new PropertyValueFactory<>("queuesString"));
6772

6873
linkCol.setCellFactory(TextFieldTableCell.forTableColumn());
6974
linkCol.setOnEditCommit(e -> e.getTableView().getItems().get(e.getTablePosition().getRow()).setUri(e.getNewValue()));
75+
pathCol.setCellFactory(TextFieldTableCell.forTableColumn());
76+
pathCol.setOnEditCommit(e -> e.getTableView().getItems().get(e.getTablePosition().getRow()).setPath(e.getNewValue()));
7077
nameCol.setCellFactory(TextFieldTableCell.forTableColumn());
7178
nameCol.setOnEditCommit(e -> e.getTableView().getItems().get(e.getTablePosition().getRow()).setName(e.getNewValue()));
7279
var queuesToShow = getQueues().stream()
7380
.filter(qm -> qm.getName().equals(ALL_DOWNLOADS_QUEUE) || !staticQueueNames.contains(qm.getName()))
7481
.toList();
7582
queuesCol.setCellFactory(p -> new ComboBoxTableCell<>(FXCollections.observableArrayList(queuesToShow)));
76-
queuesCol.setOnEditCommit(e -> changeLinkQueues(e.getRowValue(), e.getNewValue(), true));
83+
queuesCol.setOnEditCommit(e -> changeLinkQueues(e.getRowValue(), e.getNewValue(), null, true));
7784

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

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

156-
public void changeQueues(QueueModel queue) {
157-
table.getItems().forEach(lm -> changeLinkQueues(lm, queue, false));
163+
public void changeQueues(QueueModel queue, BatchList.LocationData location) {
164+
location.setChange(false);
165+
table.getItems().forEach(lm -> changeLinkQueues(lm, queue, location, false));
158166
refreshTable();
159167
}
160168

161-
public void changeLinkQueues(LinkModel lm, QueueModel newQueue, boolean fromTable) {
169+
public void changeLinkQueues(LinkModel lm, QueueModel newQueue, BatchList.LocationData location, boolean fromTable) {
162170
var queues = lm.getQueues()
163171
.stream().filter(qm -> staticQueueNames.contains(qm.getName()))
164172
.toList();
@@ -167,16 +175,20 @@ public void changeLinkQueues(LinkModel lm, QueueModel newQueue, boolean fromTabl
167175
lm.setPath(lm.getSelectedPath());
168176
if (fromTable)
169177
comboQueue.getSelectionModel().select(comboQueue.getItems().size() - 1);
170-
if (!newQueue.getName().equals(ALL_DOWNLOADS_QUEUE)) {
171-
if (newQueue.hasFolder()) {
172-
var folder = new File(queuesPath + newQueue.getName());
173-
var path = folder.getAbsolutePath();
174-
if (!path.endsWith(File.separator))
175-
path += File.separator;
176-
lm.setPath(path);
177-
}
178+
if (!newQueue.getName().equals(ALL_DOWNLOADS_QUEUE))
178179
lm.getQueues().add(newQueue);
179-
}
180180

181+
if (newQueue.hasFolder()) {
182+
var folder = new File(queuesPath + newQueue.getName());
183+
var path = folder.getAbsolutePath();
184+
if (!path.endsWith(File.separator))
185+
path += File.separator;
186+
lm.setPath(path);
187+
if (location != null)
188+
location.getLocationField().setText(path);
189+
} else if (location != null) {
190+
location.revertPath();
191+
lm.setPath(location.getFirstPath());
192+
}
181193
}
182194
}

src/main/resources/io/beanvortex/bitkip/fxml/batchList.fxml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,22 @@
2121
<HBox maxWidth="2" minWidth="2" styleClass="csm_toolbar"/>
2222
</HBox>
2323

24-
<HBox spacing="5" alignment="CENTER_LEFT">
25-
<Label text="Change queue for all"/>
26-
<ComboBox fx:id="comboQueue"/>
27-
<Button fx:id="newQueue" onAction="#onNewQueue"/>
28-
</HBox>
24+
<VBox styleClass="padding_5" spacing="10">
25+
<HBox spacing="5" alignment="CENTER_LEFT">
26+
<Label text="Change queue for all"/>
27+
<ComboBox fx:id="comboQueue"/>
28+
<Button fx:id="newQueue" onAction="#onNewQueue"/>
29+
</HBox>
30+
31+
<VBox spacing="10">
32+
<HBox spacing="15" alignment="CENTER">
33+
<Label text="Location :" minWidth="60" styleClass="bold"/>
34+
<TextField fx:id="locationField" HBox.hgrow="ALWAYS"/>
35+
<Button fx:id="openLocation" onAction="#onSelectLocation"/>
36+
</HBox>
37+
<CheckBox text="Use the last selected location" fx:id="lastLocationCheck" onAction="#onLastLocationCheck"/>
38+
</VBox>
39+
</VBox>
2940

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

0 commit comments

Comments
 (0)