Skip to content

Commit

Permalink
Merge pull request #1 from prithvitewatia/dm_branch
Browse files Browse the repository at this point in the history
Created basic working download manager
  • Loading branch information
prithvitewatia authored Oct 22, 2022
2 parents ff89392 + 584840c commit 1d34def
Show file tree
Hide file tree
Showing 12 changed files with 375 additions and 54 deletions.
8 changes: 8 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

Copyright 2022 Prithvi singh

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Download Manager

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)


A simple tool to manage all your downloads. Just add a downloadable URL of a file,
and you are good to go.

### Usage Examples

![Download manager](https://github.com/prithvitewatia/DownloadManager/src/main/resources/img/DownloadManager.png)

### Feedback

Write your suggestions to [email protected] .
Follow me on [Linkedin](https://www.linkedin.com/in/prithvi-singh-tewatia-0161b5171/).
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>dev.prithvis.downloadmanager/dev.prithvis.downloadmanager.HelloApplication
<mainClass>dev.prithvis.downloadmanager/dev.prithvis.downloadmanager.MainDownload
</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/dev/prithvis/downloadmanager/DownloadManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package dev.prithvis.downloadmanager;

import dev.prithvis.downloadmanager.config.DownloadThread;
import dev.prithvis.downloadmanager.models.FileInfo;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class DownloadManager {
public final System.Logger LOGGER=System.getLogger(this.getClass().getName());
@FXML
private TableView<FileInfo> downloadTable;

@FXML
private TextField download_url_text_field;

@FXML
private TextField file_name_field;

@FXML
private TextField save_location_field;

@FXML
void downloadButtonClicked(ActionEvent event) {
String urlTextField=this.download_url_text_field.getText().trim();
String downloadLocation=this.save_location_field.getText().trim();
String filename=this.file_name_field.getText().trim();
String status="STARTED";
String action="OPEN";
DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("MMMM-dd-yyyy");
LocalDate dateNow= LocalDate.now();
String date= dateNow.format(dateTimeFormatter);
FileInfo file=new FileInfo(downloadLocation,filename,urlTextField,status,action,date);
LOGGER.log(System.Logger.Level.INFO,"Download file with info "+file+" started");
DownloadThread thread=new DownloadThread(file,this);
this.downloadTable.getItems().add(file);
thread.start();
this.download_url_text_field.setText("");
this.file_name_field.setText("");
}
@FXML
public void initialize(){
TableColumn<FileInfo,String> location= (TableColumn<FileInfo, String>) this.downloadTable.getColumns().get(0);
TableColumn<FileInfo,String> fileName= (TableColumn<FileInfo, String>) this.downloadTable.getColumns().get(1);
TableColumn<FileInfo,String> downloadUrl= (TableColumn<FileInfo, String>) this.downloadTable.getColumns().get(2);
TableColumn<FileInfo,String> status= (TableColumn<FileInfo, String>) this.downloadTable.getColumns().get(3);
TableColumn<FileInfo,String> action= (TableColumn<FileInfo, String>) this.downloadTable.getColumns().get(4);
TableColumn<FileInfo,String> addedOn= (TableColumn<FileInfo, String>) this.downloadTable.getColumns().get(5);

location.setCellValueFactory(p -> p.getValue().locationProperty());
fileName.setCellValueFactory(p -> p.getValue().nameProperty());
downloadUrl.setCellValueFactory(p -> p.getValue().urlProperty());
status.setCellValueFactory(p -> p.getValue().statusProperty());
action.setCellValueFactory(p -> p.getValue().actionProperty());
addedOn.setCellValueFactory(p -> p.getValue().addedOnProperty());

LOGGER.log(System.Logger.Level.DEBUG,"Initialized table");
}
public void updateTable(){
this.downloadTable.refresh();
}
}
23 changes: 0 additions & 23 deletions src/main/java/dev/prithvis/downloadmanager/HelloApplication.java

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/java/dev/prithvis/downloadmanager/HelloController.java

This file was deleted.

29 changes: 29 additions & 0 deletions src/main/java/dev/prithvis/downloadmanager/MainDownload.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dev.prithvis.downloadmanager;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.ResourceBundle;

public class MainDownload extends Application {
public final System.Logger LOGGER= System.getLogger(this.getClass().getName());
@Override
public void start(Stage stage) throws IOException {
ResourceBundle resourceBundle=ResourceBundle.getBundle("application");
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/download-manager.fxml"),resourceBundle);
Parent root = loader.load();
LOGGER.log(System.Logger.Level.INFO,"Started application");
Scene scene = new Scene(root,800,600);
stage.setTitle("Download Manager");
stage.setScene(scene);
stage.show();
}

public static void main(String[] args) {
launch(args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package dev.prithvis.downloadmanager.config;

import dev.prithvis.downloadmanager.DownloadManager;
import dev.prithvis.downloadmanager.models.FileInfo;

import java.io.IOException;
import java.net.URL;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class DownloadThread extends Thread{
public FileInfo file;
public final System.Logger LOGGER=System.getLogger(this.getClass().getName());
private final DownloadManager manager;
public DownloadThread(FileInfo file,DownloadManager manager){
this.file=file;
this.manager=manager;
}
@Override
public void run(){
this.file.setStatus("DOWNLOADING");
this.manager.updateTable();
try {
Files.copy((new URL(this.file.getUrl()).openStream()), Paths.get(file.getLocation(), file.getName()));
this.file.setStatus("DOWNLOADED");
LOGGER.log(System.Logger.Level.INFO,String.format("%s downloaded at %s",
file.getName(),file.getLocation()));
}catch (FileAlreadyExistsException fileAlreadyExistsException){
this.file.setStatus("SKIPPED");
LOGGER.log(System.Logger.Level.WARNING,String.format("%s already exists at %s.Skipping download"
,file.getName(),file.getLocation()));
}
catch (IOException e) {
this.file.setStatus("FAILED");
LOGGER.log(System.Logger.Level.ERROR,String.format("Download of %s failed because of %s",
file.getName(),e.getMessage()));
throw new RuntimeException(e);
}
this.manager.updateTable();
LOGGER.log(System.Logger.Level.INFO,String.format("Download of %s completed",
file.getName()));
}
}
100 changes: 100 additions & 0 deletions src/main/java/dev/prithvis/downloadmanager/models/FileInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package dev.prithvis.downloadmanager.models;

import javafx.beans.property.SimpleStringProperty;


public class FileInfo {
private final SimpleStringProperty location=new SimpleStringProperty();
private final SimpleStringProperty name=new SimpleStringProperty();
private final SimpleStringProperty url=new SimpleStringProperty();
private final SimpleStringProperty status=new SimpleStringProperty();
private final SimpleStringProperty action=new SimpleStringProperty();
private final SimpleStringProperty addedOn=new SimpleStringProperty();

public FileInfo(String downloadLocation, String filename, String urlTextField, String status, String action, String date) {
this.setLocation(downloadLocation);
this.setName(filename);
this.setUrl(urlTextField);
this.setStatus(status);
this.setAction(action);
this.setAddedOn(date);
}

public String getLocation() {
return location.get();
}

public SimpleStringProperty locationProperty() {
return location;
}

public void setLocation(String location) {
this.location.set(location);
}

public String getName() {
return name.get();
}

public SimpleStringProperty nameProperty() {
return name;
}

public void setName(String name) {
this.name.set(name);
}

public String getUrl() {
return url.get();
}

public SimpleStringProperty urlProperty() {
return url;
}

public void setUrl(String url) {
this.url.set(url);
}

public String getStatus() {
return status.get();
}

public SimpleStringProperty statusProperty() {
return status;
}

public void setStatus(String status) {
this.status.set(status);
}

public String getAddedOn() {
return addedOn.get();
}

public SimpleStringProperty addedOnProperty() {
return addedOn;
}

public void setAddedOn(String addedOn) {
this.addedOn.set(addedOn);
}

public String getAction() {
return action.get();
}

public SimpleStringProperty actionProperty() {
return action;
}

public void setAction(String action) {
this.action.set(action);
}

@Override
public String toString() {
return "name=" + name.get() +
",location=" + location.get();
}
}
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DOWNLOAD_PATH=/Users/prithvisingh/Documents/Downloads

16 changes: 0 additions & 16 deletions src/main/resources/dev/prithvis/downloadmanager/hello-view.fxml

This file was deleted.

Loading

0 comments on commit 1d34def

Please sign in to comment.