diff --git a/OSVUploadr/pom.xml b/OSVUploadr/pom.xml
index 2c11fee..8a4557e 100644
--- a/OSVUploadr/pom.xml
+++ b/OSVUploadr/pom.xml
@@ -3,7 +3,7 @@
4.0.0
ca.osmcanada
OSVUploadr
- 0.1.2-ALPHA
+ 0.1.2.1-ALPHA
jar
diff --git a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.java b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.java
index 045dca1..6eb1daa 100644
--- a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.java
+++ b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.java
@@ -68,6 +68,10 @@ public class JPMain extends javax.swing.JPanel {
* Creates new form JPMain
*/
public JPMain() {
+ try{
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+ }
+ catch(Exception ex){}
initComponents();
}
@@ -79,7 +83,8 @@ public String GetOSMUser() throws IOException{
final OAuth1RequestToken requestToken = service.getRequestToken();
String url = service.getAuthorizationUrl(requestToken);
- java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
+ Helper.OpenBrowser(java.net.URI.create(url));
+ //java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
String pin_code = JOptionPane.showInputDialog(null, "Authorization window has opened, please paste authorization code below once authorized.\nWith out the \".\" at the end", "Authorization Required", JOptionPane.INFORMATION_MESSAGE);
final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, pin_code);
final OAuthRequest request = new OAuthRequest(Verb.GET, BASE_URL + "api/0.6/user/details", service);
diff --git a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/Utils/Helper.java b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/Utils/Helper.java
index 152d8e2..3c99450 100644
--- a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/Utils/Helper.java
+++ b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/Utils/Helper.java
@@ -11,16 +11,41 @@
import com.drew.metadata.Metadata;
import com.drew.metadata.exif.ExifSubIFDDirectory;
import com.drew.metadata.exif.GpsDirectory;
+import java.awt.Desktop;
import java.io.File;
+import java.net.URI;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
+import java.util.ArrayList;
+import java.util.List;
+import java.io.IOException;
/**
*
* @author Jamie Nadeau
*/
public final class Helper {
+ public static enum EnumOS {
+ linux, macos, solaris, unknown, windows;
+
+ public boolean isLinux() {
+
+ return this == linux || this == solaris;
+ }
+
+
+ public boolean isMac() {
+
+ return this == macos;
+ }
+
+
+ public boolean isWindows() {
+
+ return this == windows;
+ }
+ }
public static long getFileTime(File f){
try{
@@ -72,4 +97,120 @@ public static ImageProperties getImageProperties(File f){
return null;
}
+ public static Boolean OpenBrowser(URI uri){
+ try{
+ boolean supportsBrowse = false;
+ if(!Desktop.isDesktopSupported()){
+ supportsBrowse = false;
+ if(!Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)){
+ supportsBrowse = false;
+ }
+ }
+
+ if(supportsBrowse){
+ Desktop.getDesktop().browse(uri);
+ }
+ else{
+ EnumOS os = getOs();
+ if (os.isLinux()) {
+ if (runCommand("kde-open", "%s", uri.toString())) return true;
+ if (runCommand("gnome-open", "%s", uri.toString())) return true;
+ if (runCommand("xdg-open", "%s", uri.toString())) return true;
+ }
+
+ if (os.isMac()) {
+ if (runCommand("open", "%s", uri.toString())) return true;
+ }
+
+ if (os.isWindows()) {
+ if (runCommand("explorer", "%s", uri.toString())) return true;
+ }
+ }
+ }
+ catch(Exception ex){
+ Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, null, ex);
+ return false;
+ }
+ return false;
+ }
+
+ private static boolean runCommand(String command, String args, String file) {
+
+ logOut("Trying to exec:\n cmd = " + command + "\n args = " + args + "\n %s = " + file);
+
+ String[] parts = prepareCommand(command, args, file);
+
+ try {
+ Process p = Runtime.getRuntime().exec(parts);
+ if (p == null) return false;
+
+ try {
+ int retval = p.exitValue();
+ if (retval == 0) {
+ logOut("Process ended immediately.");
+ return false;
+ } else {
+ logOut("Process crashed.");
+ return false;
+ }
+ } catch (IllegalThreadStateException itse) {
+ logOut("Process is running.");
+ return true;
+ }
+ } catch (IOException e) {
+ Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, null, e);
+ return false;
+ }
+ }
+
+
+ private static String[] prepareCommand(String command, String args, String file) {
+
+ List parts = new ArrayList();
+ parts.add(command);
+
+ if (args != null) {
+ for (String s : args.split(" ")) {
+ s = String.format(s, file); // put in the filename thing
+
+ parts.add(s.trim());
+ }
+ }
+
+ return parts.toArray(new String[parts.size()]);
+ }
+
+ public static EnumOS getOs() {
+
+ String s = System.getProperty("os.name").toLowerCase();
+
+ if (s.contains("win")) {
+ return EnumOS.windows;
+ }
+
+ if (s.contains("mac")) {
+ return EnumOS.macos;
+ }
+
+ if (s.contains("solaris")) {
+ return EnumOS.solaris;
+ }
+
+ if (s.contains("sunos")) {
+ return EnumOS.solaris;
+ }
+
+ if (s.contains("linux")) {
+ return EnumOS.linux;
+ }
+
+ if (s.contains("unix")) {
+ return EnumOS.linux;
+ } else {
+ return EnumOS.unknown;
+ }
+ }
+ private static void logOut(String msg) {
+ System.out.println(msg);
+ }
}