Skip to content

Commit

Permalink
Added VNC-file export
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaOonk committed Jul 16, 2021
1 parent ef2bd7b commit 3eb713e
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 22 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.lucaoonk.Virt_Commander</groupId>
<artifactId>Virt_Commander</artifactId>
<packaging>jar</packaging>
<version>0.5.1</version>
<version>0.5.2</version>
<name>Virt_Commander</name>
<url>http://maven.apache.org</url>

Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.lucaoonk.Virt_Commander.Backend.Controllers.VNCConnection;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
import java.util.UUID;

public class ConnectionData {

private String FriendlyName;
private String ip;
private Enum<connectionTypes> connectionType;


public enum connectionTypes{
TCP,
UDP
}

public ConnectionData(){
this.connectionType = connectionTypes.TCP;
}

public void setFriendlyName(String friendlyName){
this.FriendlyName = friendlyName;
}

public void setIP(String ip){
this.ip = ip;
}

public void setConnectionType(Enum<connectionTypes> connectionType){
this.connectionType = connectionType;
}

public String getFriendlyName(){
return this.FriendlyName;
}
public String getIP(){
return this.ip;
}
public Enum<connectionTypes> getConnectionType(){
return this.connectionType;
}

public void export(String location) throws IOException {

StringBuilder connection = new StringBuilder();
FileWriter connectionFile;
try{
connectionFile= new FileWriter(location);
if(this.getConnectionType().equals(ConnectionData.connectionTypes.TCP)){

connection.append("ConnMethod=tcp\n");

}else{
if(this.getConnectionType().equals(ConnectionData.connectionTypes.UDP)){

connection.append("ConnMethod=udp\n");

}
}

connection.append("ConnTime="+Calendar.getInstance().getTime()+"\n");

connection.append("FriendlyName="+this.getFriendlyName()+"\n");
connection.append("Host="+this.getIP()+"\n");
connection.append("RelativePtr=0\n");
connection.append("Uuid="+UUID.randomUUID()+"\n");

connectionFile.write(connection.toString());
connectionFile.close();
} catch (Exception e) {
//TODO: handle exception
}


}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.lucaoonk.Virt_Commander.Backend.Controllers.VNCConnection;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
import java.util.UUID;

public class ConnectionFileHandler {

private ConnectionData connectionData;

public ConnectionFileHandler(ConnectionData connectionData) {

this.connectionData = connectionData;

}

public void export(String location) throws IOException {

StringBuilder connection = new StringBuilder();
FileWriter connectionFile;
try{
connectionFile= new FileWriter(location);
if(connectionData.getConnectionType().equals(ConnectionData.connectionTypes.TCP)){

connection.append("ConnMethod=tcp\n");

}else{
if(connectionData.getConnectionType().equals(ConnectionData.connectionTypes.UDP)){

connection.append("ConnMethod=udp\n");

}
}

connection.append("ConnTime="+Calendar.getInstance().getTime()+"\n");

connection.append("FriendlyName="+connectionData.getFriendlyName()+"\n");
connection.append("Host="+connectionData.getIP()+"\n");
connection.append("RelativePtr=0\n");
connection.append("Uuid="+UUID.randomUUID()+"\n");

connectionFile.write(connection.toString());
connectionFile.close();
} catch (Exception e) {
//TODO: handle exception
}


}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.lucaoonk.Virt_Commander.Backend.Controllers.VNCConnection;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

import com.lucaoonk.Virt_Commander.Backend.Objects.VM;

public class VNCConnection {

private VM vm;

public VNCConnection(VM vm){
this.vm = vm;
}

public void connect(){

System.out.println("Triggerd VNC connect");

String location = System.getProperty("user.home") + "/Desktop/Virt_Commander-VNC/";
String vncConnectFile = location+vm.getDomain()+".vnc";
ConnectionData data = new ConnectionData();
data.setFriendlyName(vm.getDomain());
data.setIP(vm.vncIP+":"+vm.vncPort);

try {
File file = new File(vncConnectFile);
file.getParentFile().mkdirs();

data.export(vncConnectFile);
System.out.println("VNC file: "+vncConnectFile);


} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Context {
public MainContent mainContent;
public JFrame mainJFrame;
public String defaultSaveLocation;
private static final String versionString = "0.5.1";
private static final String versionString = "0.5.2";
public Boolean checkForUpdates;
private String applicationDefaultSaveLocation;
public Integer windowHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.lucaoonk.Virt_Commander.Backend.Objects.Context;
import com.lucaoonk.Virt_Commander.ui.MainFrame;

import org.json.simple.JSONObject;
Expand Down
47 changes: 46 additions & 1 deletion src/main/java/com/lucaoonk/Virt_Commander/ui/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.awt.desktop.SystemEventListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.net.URI;
import java.util.concurrent.TimeUnit;

Expand All @@ -29,7 +31,7 @@
import com.lucaoonk.Virt_Commander.UpdateChecker.UpdateChecker;


public class MainFrame extends JFrame implements ActionListener, SystemEventListener{
public class MainFrame extends JFrame implements ActionListener, SystemEventListener, WindowListener{

/**
*
Expand Down Expand Up @@ -69,6 +71,7 @@ public void init() throws Exception {
this.context.loadingStatus = "Initializing Local";
localInit();
}
mainFrame.addWindowListener(this);
}

private void localInit() throws Exception{
Expand Down Expand Up @@ -255,4 +258,46 @@ public void actionPerformed(ActionEvent e) {

}

@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub

}

@Override
public void windowClosing(WindowEvent e) {

MainFrame.exitProgram();
}

@Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub

}

@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub

}

@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub

}

@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub

}

@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub

}

}
Loading

0 comments on commit 3eb713e

Please sign in to comment.