Author: jerome
Date: 2010-02-26 15:04:00 +0100 (Fri, 26 Feb 2010)
New Revision: 6070

Modified:
   software_suite_v3/software/plugin/plugin-facebook/branches/new_login/pom.xml
   
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/resources/plugin.xml
   
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/FacebookConnection.java
   
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/FacebookFunctions.java
   
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/FacebookPlugin.java
   
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/configuration/FacebookDatasStruct.java
   
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/configuration/PluginFacebookConfiguration.java
   
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/connection/FacebookSessionUtils.java
Log:
* Fixed login stuff ( still need some tests ).

Modified: 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/pom.xml
===================================================================
--- 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/pom.xml    
    2010-02-22 12:31:57 UTC (rev 6069)
+++ 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/pom.xml    
    2010-02-26 14:04:00 UTC (rev 6070)
@@ -56,11 +56,36 @@
       <artifactId>facebook-java-api-schema</artifactId>
       <version>2.1.1</version>
     </dependency>
-    <dependency>
-      <groupId>commons-httpclient</groupId>
-      <artifactId>commons-httpclient</artifactId>
-      <version>3.1</version>
+       <dependency>
+      <groupId>org.lobobrowser</groupId>
+      <artifactId>lobo</artifactId>
+      <version>0.9.8</version>
     </dependency>
+       <dependency>
+      <groupId>org.lobobrowser</groupId>
+      <artifactId>lobo-pub</artifactId>
+      <version>0.9.8</version>
+    </dependency>
+       <dependency>
+      <groupId>org.lobobrowser.cobra</groupId>
+      <artifactId>cobra</artifactId>
+      <version>0.98.4</version>
+    </dependency>
+       <dependency>
+      <groupId>org.lobobrowser.cobra</groupId>
+      <artifactId>cobra-no-commons</artifactId>
+      <version>0.98.4</version>
+    </dependency>
+       <dependency>
+      <groupId>org.lobobrowser</groupId>
+      <artifactId>lobo-js</artifactId>
+      <version>0.0.1</version>
+    </dependency>
+       <dependency>
+      <groupId>org.lobobrowser</groupId>
+      <artifactId>lobo-primary</artifactId>
+      <version>0.0.1</version>
+    </dependency>
                
     </dependencies>
     
@@ -96,7 +121,8 @@
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
-                   <execution>
+                   
+                       <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
@@ -106,6 +132,41 @@
                            <outputDirectory>./libraries</outputDirectory>
                        </configuration>
                    </execution>
+                       
+                       <execution>
+            <id>copy-dependency</id>
+            <phase>package</phase>
+            <goals>
+              <goal>copy</goal>
+            </goals>
+            <configuration>
+                <artifactItems>
+                  <artifactItem>
+                     <groupId>org.lobobrowser.cobra</groupId>
+                     <artifactId>cobra</artifactId>
+                     <version>0.98.4</version>
+                  </artifactItem>
+                                 <artifactItem>
+                     <groupId>org.lobobrowser.cobra</groupId>
+                     <artifactId>cobra-no-commons</artifactId>
+                     <version>0.98.4</version>
+                  </artifactItem>
+                                 <artifactItem>
+                     <groupId>org.lobobrowser</groupId>
+                     <artifactId>lobo-js</artifactId>
+                     <version>0.0.1</version>
+                  </artifactItem>
+                                 <artifactItem>
+                     <groupId>org.lobobrowser</groupId>
+                     <artifactId>lobo-primary</artifactId>
+                     <version>0.0.1</version>
+                  </artifactItem>
+                 </artifactItems>
+               <outputDirectory>./libraries/ext</outputDirectory>
+            </configuration>
+          </execution>
+
+                       
                </executions>
            </plugin>
 
@@ -133,8 +194,12 @@
                         <exclude name="libraries/tuxdroid-plugin-java-kit*" />
                         <exclude name="libraries/karmalab-commons*" />
                         <exclude name="libraries/tuxdroid-java-api*" />
+                                               <exclude 
name="libraries/lobo-js*" />
+                                               <exclude 
name="libraries/lobo-primary*" />
+                                               <exclude 
name="libraries/cobra*" />
                     </zipfileset>
                                    <zipfileset dir="." 
includes="executables/*" />
+                                       <zipfileset dir="." 
includes="libraries/ext/*" />
                                </zip>
                            </tasks>
                        </configuration>

Modified: 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/resources/plugin.xml
===================================================================
--- 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/resources/plugin.xml
   2010-02-22 12:31:57 UTC (rev 6069)
+++ 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/resources/plugin.xml
   2010-02-26 14:04:00 UTC (rev 6070)
@@ -21,12 +21,6 @@
                        description="Login"
                        type="string"
                        defaultValue="your login" />
-        <parameter
-                       category="Gadget parameters"
-                       name="password"
-                       description="Password"
-                       type="password"
-                       defaultValue="your password" />
                <parameter
                        category="Gadget parameters"
                        name="notifyEmail"
@@ -70,7 +64,8 @@
                        description="Run to check your Facebook account" />
         <command
                        name="check"
-                       description="Check your Facebook account" />
+                       description="Check your Facebook account"
+               />
         <command
                        name="configure"
                        description="Configure Tux Droid Facebook permissions" 
/>

Modified: 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/FacebookConnection.java
===================================================================
--- 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/FacebookConnection.java
 2010-02-22 12:31:57 UTC (rev 6069)
+++ 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/FacebookConnection.java
 2010-02-26 14:04:00 UTC (rev 6070)
@@ -38,7 +38,7 @@
        /**
         * Try to get connected to fb with the old registered session.
         */
-       private boolean connectOldSession(String username, String password)
+       private boolean connectOldSession(String username)
        {
                try 
                {
@@ -47,11 +47,7 @@
                        //Checking username.
                        if(! 
username.equalsIgnoreCase(FacebookSessionUtils.getMail()))
                        {
-                               if(! 
password.equalsIgnoreCase(FacebookSessionUtils.getPass()))
-                               {
-                                       //then a new user has logged in.
-                                       return false;
-                               }
+                               return false;
                        }
                        
                        String sessionKey = 
FacebookSessionUtils.getSessionKey();
@@ -75,32 +71,37 @@
        
        
        
-       public boolean Connect(String username, String password) throws 
FacebookLoginException
+       public boolean Connect(String username) throws FacebookLoginException
        {
+               //Checking for unique Facebook login process stuff.
+               if(! 
FacebookSessionUtils.isSingletonProgram("FacebookConnectFrame"))
+               {
+                       return false;
+               }
+               
                FacebookSessionUtils.setMail(username);
-               FacebookSessionUtils.setPass(password);
                
                //Facebook connection stuff.
                
                try 
                {
                        //Returning if old session was still valid.
-                       if(this.connectOldSession(username, password))
+                       if(this.connectOldSession(username))
                        {
                                return true;
                        }
                        
                        FacebookSessionUtils.loadSession();
                        String sessionKey = 
FacebookSessionUtils.getValidSessionID( true );
-                       FacebookSessionUtils.registerSessionKey(sessionKey);
+                       FacebookSessionUtils.registerSessionKey();
                        
                        //Generate session secret, ready to pass to desktop app 
client
-                       String sessionSecret = 
FacebookSessionUtils.lastClientUsed.getCacheSessionSecret();
-                       
FacebookSessionUtils.registerSessionSecret(sessionSecret);
+                       String sessionSecret = 
FacebookSessionUtils.getSessionSecret();
+                       FacebookSessionUtils.registerSessionSecret();
                        
                        client =  new 
FacebookJsonRestClient(FacebookSessionUtils.api_key, sessionSecret, sessionKey);
                        
-                       if((sessionSecret == null) || (client == null))
+                       if((sessionSecret.equals("0")) || (client.equals(null)))
                        {
                                return false;
                        }
@@ -111,6 +112,7 @@
                } 
                catch (FacebookException e) 
                {
+                       e.printStackTrace();
                        if(e.getMessage().equalsIgnoreCase("invalid parameter"))
                        {
                                throw new FacebookLoginException();
@@ -118,7 +120,7 @@
                } 
                catch (IOException e) 
                {
-                       //e.printStackTrace();
+                       ;
                }
                
                return false;

Modified: 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/FacebookFunctions.java
===================================================================
--- 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/FacebookFunctions.java
  2010-02-22 12:31:57 UTC (rev 6069)
+++ 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/FacebookFunctions.java
  2010-02-26 14:04:00 UTC (rev 6070)
@@ -100,7 +100,7 @@
                        JSONObject messages = (JSONObject) 
notifications.get("messages");
                        return messages.getInt("unread");
                } 
-               catch (JSONException e) 
+               catch (Exception e) 
                {
                        ;
                }

Modified: 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/FacebookPlugin.java
===================================================================
--- 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/FacebookPlugin.java
     2010-02-22 12:31:57 UTC (rev 6069)
+++ 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/FacebookPlugin.java
     2010-02-26 14:04:00 UTC (rev 6070)
@@ -42,6 +42,8 @@
        private FacebookFunctions functions;
        private FacebookDatasStruct facebookHistory;
        
+       private String type = null;
+       
        /**
         * Throws the result in case of Check mode.
         */
@@ -67,7 +69,7 @@
                if (this.getCommand().equalsIgnoreCase("configure"))
                {
                        FacebookConnection facebook = new FacebookConnection();
-                       if ( facebook.Connect(this.configuration().getLogin(), 
this.configuration().getPassword()) )
+                       if ( facebook.Connect(this.configuration().getLogin()) )
                        {
                                functions = new 
FacebookFunctions(facebook.getClient());
                                this.doConfigure(functions);
@@ -99,12 +101,12 @@
        public void RunOrCheck()
        {
                FacebookConnection facebook = new FacebookConnection();
-               
+               type = this.getCommand().toUpperCase();
                boolean connected = false;
                
                try 
                {
-                       connected = 
facebook.Connect(this.configuration().getLogin(), 
this.configuration().getPassword());
+                       connected = 
facebook.Connect(this.configuration().getLogin());
                } 
                catch (FacebookLoginException e) 
                {
@@ -274,10 +276,18 @@
                    for(String request : f_requests)
                        {
                        String fid = functions.getFriendRequestID(request);
-                       if(! 
facebookHistory.isRegistered(FacebookDatasStruct.FRIENDS_QUERIES, fid))
+                       if(! 
facebookHistory.isRegistered(FacebookDatasStruct.FRIENDS_QUERIES, fid, type))
                        {
                                throwRes();
-                               this.facebookHistory.addFriendRequest(fid);
+                               if(this.getCommand().equalsIgnoreCase("check"))
+                               {
+                                       
this.facebookHistory.addFriendRequest(fid, "CHECK");
+                               }
+                               else
+                               {
+                                       
this.facebookHistory.addFriendRequest(fid, "CHECK");
+                                       
this.facebookHistory.addFriendRequest(fid, "RUN");
+                               }
                                //Only throwing in the second cycle of check 
command or run.
                                if(this.getCommand().equalsIgnoreCase("run") || 
secondCycle)
                                        {
@@ -319,10 +329,18 @@
                    for(String group : g_invites)
                        {
                        String gid = functions.getGroupID(group);
-                       if(! 
facebookHistory.isRegistered(FacebookDatasStruct.GROUP_INVITES, gid))
+                       if(! 
facebookHistory.isRegistered(FacebookDatasStruct.GROUP_INVITES, gid, type))
                                {
                            throwRes();
-                           this.facebookHistory.addGroupInvite(gid);
+                           if(this.getCommand().equalsIgnoreCase("check"))
+                               {
+                               this.facebookHistory.addGroupInvite(gid, 
"CHECK");
+                               }
+                           else
+                           {
+                               this.facebookHistory.addGroupInvite(gid, 
"CHECK");
+                               this.facebookHistory.addGroupInvite(gid, "RUN");
+                           }
                            //Only throwing in the second cycle of check 
command or run.
                                if(this.getCommand().equalsIgnoreCase("run") || 
secondCycle)
                                        {
@@ -363,10 +381,18 @@
                    for(String event : e_invites)
                        {
                        String eid = functions.getEventID( event );
-                       if(! 
facebookHistory.isRegistered(FacebookDatasStruct.EVENT_INVITE, eid))
+                       if(! 
facebookHistory.isRegistered(FacebookDatasStruct.EVENT_INVITE, eid, type))
                                {
                                throwRes();
-                           
this.facebookHistory.addEventInvite(functions.getEventID(event));
+                               if(this.getCommand().equalsIgnoreCase("check"))
+                               {
+                                       
this.facebookHistory.addEventInvite(functions.getEventID(event), "CHECK");
+                               }
+                               else
+                               {
+                                       
this.facebookHistory.addEventInvite(functions.getEventID(event), "CHECK");
+                                       
this.facebookHistory.addEventInvite(functions.getEventID(event), "RUN");
+                               }
                            //Only throwing in the second cycle of check 
command or run.
                                if(this.getCommand().equalsIgnoreCase("run") || 
secondCycle)
                                        {

Modified: 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/configuration/FacebookDatasStruct.java
===================================================================
--- 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/configuration/FacebookDatasStruct.java
  2010-02-22 12:31:57 UTC (rev 6069)
+++ 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/configuration/FacebookDatasStruct.java
  2010-02-26 14:04:00 UTC (rev 6070)
@@ -148,27 +148,27 @@
        /**
         * Add a reply to the reply hash table.
         */
-       public void addEventInvite(String event_id)
+       public void addEventInvite(String event_id, String type)
        {
-               this.vktStruct.add(new String("eid:" + event_id));
+               this.vktStruct.add(new String("eid:" + event_id + "_" + type));
        }
        
        
        /**
         * Add a status for selected friend.
         */
-       public void addFriendRequest(String request_id)
+       public void addFriendRequest(String request_id, String type)
        {
-               this.vktStruct.add(new String("fid:" + request_id));
+               this.vktStruct.add(new String("fid:" + request_id + "_" + 
type));
        }
        
        
        /**
         * Add a status for selected friend.
         */
-       public void addGroupInvite(String group_id)
+       public void addGroupInvite(String group_id, String type)
        {
-               this.vktStruct.add(new String("gid:" + group_id));
+               this.vktStruct.add(new String("gid:" + group_id + "_" + type));
        }
        
        
@@ -187,22 +187,46 @@
         * @param uuid.
         * @return
         */
-       public boolean isRegistered(byte list, String id)
+       public boolean isRegistered(byte list, String id, String type)
        {
                
                switch(list)
                {
                        case FacebookDatasStruct.FRIENDS_QUERIES:
-                               return vktStruct.contains("fid:" + id);
+                               if (type == "CHECK")
+                               {
+                                       return ( vktStruct.contains("fid:" + id 
+ "_" + "CHECK") ||
+                                                        
vktStruct.contains("fid:" + id + "_" + "RUN"));
+                               }
+                               else
+                               {
+                                       return vktStruct.contains("fid:" + id + 
"_" + type);
+                               }
                        
                        case FacebookDatasStruct.MESSAGES:
                            return vktStruct.contains("mes:" + id);
                                
                        case FacebookDatasStruct.GROUP_INVITES:
-                           return vktStruct.contains("gid:" + id);
+                               if (type == "CHECK")
+                               {
+                                       return (vktStruct.contains("gid:" + id+ 
"_" + "CHECK") ||
+                                               vktStruct.contains("gid:" + id+ 
"_" + "RUN"));
+                               }
+                               else
+                               {
+                                       return vktStruct.contains("gid:" + id+ 
"_" + type);
+                               }
                        
                        case FacebookDatasStruct.EVENT_INVITE:
-                           return vktStruct.contains("eid:" + id);
+                               if (type == "CHECK")
+                               {
+                                       return (vktStruct.contains("eid:" + id+ 
"_" + "CHECK") ||
+                                                       
vktStruct.contains("eid:" + id+ "_" + "RUN"));
+                               }
+                               else
+                               {
+                                       return vktStruct.contains("eid:" + id+ 
"_" + type);
+                               }
                        
                        default:
                                return false;

Modified: 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/configuration/PluginFacebookConfiguration.java
===================================================================
--- 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/configuration/PluginFacebookConfiguration.java
  2010-02-22 12:31:57 UTC (rev 6069)
+++ 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/configuration/PluginFacebookConfiguration.java
  2010-02-26 14:04:00 UTC (rev 6070)
@@ -27,7 +27,6 @@
 public class PluginFacebookConfiguration extends SimplePluginConfiguration{
                
        private String login = "";
-       private String password = "";
        
        private boolean showFriendRequests = true;
        private boolean showGroupsInvites = true;
@@ -99,26 +98,6 @@
        
        
        /**
-        * Return tthe user password.
-        * @return
-        */
-       public String getPassword()
-       {
-               return this.password;
-       }
-       
-       
-       /**
-        * Set the user password.
-        * @param aPassword
-        */
-       public void setPassword(String aPassword)
-       {
-               this.password = aPassword;
-       }
-       
-       
-       /**
         * Return true if user want to hear his email notifications.
         * @return
         */

Modified: 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/connection/FacebookSessionUtils.java
===================================================================
--- 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/connection/FacebookSessionUtils.java
    2010-02-22 12:31:57 UTC (rev 6069)
+++ 
software_suite_v3/software/plugin/plugin-facebook/branches/new_login/src/com/kysoh/plugins/facebook/connection/FacebookSessionUtils.java
    2010-02-26 14:04:00 UTC (rev 6070)
@@ -22,7 +22,7 @@
 
 package com.kysoh.plugins.facebook.connection;
 
-
+import java.awt.event.WindowEvent;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -30,16 +30,22 @@
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
 import java.util.Vector;
 
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpState;
-import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
+import javax.swing.ImageIcon;
+import javax.swing.JFrame;
 
+import org.lobobrowser.gui.FramePanel;
+import org.lobobrowser.main.PlatformInit;
+import org.lobobrowser.ua.NavigationEvent;
+import org.lobobrowser.ua.NavigationListener;
+import org.lobobrowser.ua.NavigationVetoException;
+
 import com.google.code.facebookapi.FacebookException;
 import com.google.code.facebookapi.FacebookXmlRestClient;
+import com.kysoh.plugins.facebook.FacebookPlugin;
 
 public class FacebookSessionUtils {
        
@@ -47,21 +53,26 @@
        public static String s_key   = "0314c8569f89d0411e5a4823372ae27a";
        
        protected static String mail = "";
-       protected static String pass = "";
        
        public static String lastTokenUsed;
        public static FacebookXmlRestClient lastClientUsed;
        
        
        private static SerializedVector sessionUtils = new SerializedVector();
+       
+       static boolean loggedIn = false;
+       static String session_key = null;
+       static String session_secret = null;
+       static JFrame frame;
+       static boolean waitFor = true;
 
+       private static File lockFile = null; 
        
        static
        {
                sessionUtils.add("0");
                sessionUtils.add("1");
                sessionUtils.add(mail);
-               sessionUtils.add(pass);
        }
        
        public static void setMail(String eMail)
@@ -71,42 +82,155 @@
        }
        
        
-       public static void setPass(String aPass)
-       {
-               pass = aPass;
-               sessionUtils.add(aPass);
-       }
-       
-       
        public static String getValidSessionID( boolean generateSessionSecret) 
                      throws IOException, FacebookException {
                
                
                FacebookXmlRestClient client = new FacebookXmlRestClient( 
api_key, s_key );
                String token = client.auth_createToken();
-
-               HttpClient http = new HttpClient();
-        http.setState(new HttpState());
-
-        final String LOGIN = "http://www.facebook.com/login.php";;
         
-        GetMethod get = new GetMethod(LOGIN + "?api_key=" + api_key + 
"&v=1.0&auth_token=" + token );
-        
-        http.executeMethod(get);
+               String url = "http://www.facebook.com/login.php?api_key="+ 
api_key + "&connect_display=popup&v=1.0"+
+        "&next=http://www.facebook.com/connect/login_success.html"; +
+        "&cancel_url=http://www.facebook.com/connect/login_failure.html&"+
+        "fbconnect=true&return_session=true&session_key_only=true&email=" + 
mail;
 
-        PostMethod post = new PostMethod(LOGIN);
-        post.addParameter(new NameValuePair("api_key", api_key));
-        post.addParameter(new NameValuePair("v", "1.0"));
-        post.addParameter(new NameValuePair("auth_token", token));
-        post.addParameter(new NameValuePair("email", mail));
-        post.addParameter(new NameValuePair("pass", pass));
 
-        http.executeMethod(post);
+               //Creating lobo browser panel.
+               try 
+               {
+                   PlatformInit.getInstance().initLogging(false);
+                   PlatformInit.getInstance().init(false, false);
+               } 
+               catch (Exception e2) {
+               ;
+               }
+               
+               frame = new JFrame();
+               frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+               frame.setSize(600, 400);
+               frame.setLocationRelativeTo(null);
+               
+               frame.setTitle("Facebook Connect ( Tux Droid )");
+               
+               FramePanel browser = new FramePanel();
+               
+               frame.getContentPane().add(browser);
+               
+               frame.setVisible(true);
+               frame.setAlwaysOnTop( true );
+               String loc = 
FacebookPlugin.class.getProtectionDomain().getCodeSource().getLocation().getPath();
+               loc = loc.substring(0, loc.lastIndexOf("/"));
+               File f = new File(loc + "/../resources/plugin.png");
+               ImageIcon img = new ImageIcon(f.getAbsolutePath());
+               frame.setIconImage(img.getImage());
+               
+               try 
+               {
+               browser.navigate(url);
+               } 
+               catch (MalformedURLException e1) 
+               {
+               ;
+               }
+               
+               // Add a navigation listener.
+               browser.addNavigationListener(new NavigationListener()
+               {
+               
+               @Override
+               public void beforeLocalNavigate(NavigationEvent arg0) throws 
NavigationVetoException 
+               {
+                       //login success ( login fail in all other cases ).
+                       
if(arg0.getURL().toString().contains("login_success.html"))
+                       {
+                               //System.out.println(arg0.getURL().toString());
+                               //Getting session key.
+                               
if(arg0.getURL().toString().contains("session_key"))
+                               {
+                                       loggedIn = true;
+                                       int bIdx = 
arg0.getURL().toString().indexOf("session_key");
+                                       session_key = 
arg0.getURL().toString().substring(bIdx);
+                                       
+                                       try 
+                                       {
+                                               //Re-encoding url.
+                                               session_key = 
java.net.URLDecoder.decode(session_key, "UTF-8");
+                                       } 
+                                       catch (UnsupportedEncodingException e) 
+                                       {
+                                               loggedIn = false;
+                                       }
+                                       String[] params = 
session_key.split(",");
+                                       
+                                       for (String str : params )
+                                       {
+                                               if (str.contains("session_key"))
+                                               {
+                                                       session_key = 
str.substring("session_key".length() + 3);
+                                                       session_key = 
session_key.substring(0, session_key.length() - 1);
+                                               }
+                                               
+                                               if(str.contains("secret"))
+                                               {
+                                                       session_secret = 
str.substring("secret".length() + 4);
+                                                       session_secret = 
session_secret.substring(0, session_secret.length() - 1);
+                                                       frame.dispose();
+                                                       waitFor = false;
+                                               }
+                                       } 
+                               }
+                               else
+                               {
+                                       loggedIn = false;
+                               }
+                       }
+               }
+               
+               @Override
+               public void beforeNavigate(NavigationEvent arg0) throws 
NavigationVetoException {
+                       ;
+               }
+               
+               @Override
+               public void beforeWindowOpen(NavigationEvent arg0) throws 
NavigationVetoException {
+                       ;
+               }
+               
+               });
+               
+               
+               frame.addWindowListener(new java.awt.event.WindowAdapter() 
+               {
+               public void windowClosing(WindowEvent e)
+               {
+                       waitFor = false;
+               }
+               });
+               
+               //Wait for navigator.
+               while(waitFor)
+               {
+               try 
+               {
+                       Thread.sleep(1000);
+               } 
+               catch (InterruptedException e) 
+               {
+                       ;
+               }
+               }
 
-               String sessionID = client.auth_getSession( token, 
generateSessionSecret );
                lastTokenUsed = token;
                lastClientUsed = client;
-               return sessionID;
+               registerSessionSecret();
+               registerSessionKey();
+               
+               if(FacebookSessionUtils.lockFile.exists())
+               {
+                       FacebookSessionUtils.lockFile.delete();
+               }
+               
+               return session_key;
        }
        
        
@@ -114,9 +238,9 @@
         * Register the last known session secret.
         * @param aSessionSecret
         */
-       public static void registerSessionSecret(String aSessionSecret)
+       public static void registerSessionSecret()
        {
-               sessionUtils.set(0, new String(aSessionSecret));
+               sessionUtils.set(0, new String(session_secret));
        }
        
        
@@ -142,22 +266,12 @@
        
        
        /**
-        * Return last used pass.
-        * @return
-        */
-       public static String getPass()
-       {
-               return (String) sessionUtils.get( 3 );
-       }
-       
-       
-       /**
         * Register the last known session key.
         * @param aSessionKey
         */
-       public static void registerSessionKey(String aSessionKey)
+       public static void registerSessionKey()
        {
-               sessionUtils.set(1, new String(aSessionKey));
+               sessionUtils.set(1, new String(session_key));
        }
        
        
@@ -167,6 +281,11 @@
         */
        public static String getSessionKey()
        {
+               if (sessionUtils.get(1) != null)
+               {
+                       session_key = sessionUtils.get(1);
+               }
+               
                return (String) sessionUtils.get( 1 );
        }
        
@@ -175,16 +294,15 @@
        /**
         * Load the serialized vector containing old session datas.
         */
-       public static void loadSession()
+       public static boolean loadSession()
        {
                try 
                {   
-                       File path = new File("");
-                   File session = new File( path.getAbsolutePath() + 
File.separator + "session_" + mail);
+                   File session = new File( getCachePath() );
                    
                    if(session.isFile())
                    {
-                       FileInputStream fichier = new 
FileInputStream("session_" + mail);  
+                       FileInputStream fichier = new 
FileInputStream(session.getAbsolutePath());  
                        ObjectInputStream ois = new ObjectInputStream(fichier);
                        sessionUtils = (SerializedVector) ois.readObject();  
                    }
@@ -194,7 +312,7 @@
                        sessionUtils.add("0");
                        sessionUtils.add("0");
                        sessionUtils.add(mail);
-                       sessionUtils.add(pass);
+                       return false;
                    }
                 }   
                 catch (java.io.IOException e) 
@@ -205,6 +323,7 @@
                 {  
                      e.printStackTrace();  
                 }  
+                return true;
        }
        
        
@@ -221,8 +340,7 @@
                
                try 
                {  
-                       File path = new File("");
-                   File session = new File( path.getAbsolutePath() + 
File.separator + "session_" + mail);
+                   File session = new File( getCachePath() );
                    FileOutputStream file = new 
FileOutputStream(session.getAbsolutePath());  
                    ObjectOutputStream oos = new ObjectOutputStream(file);  
                    oos.writeObject(sessionUtils);  
@@ -235,6 +353,13 @@
                 }  
        }
        
+       
+       public static String getCachePath()
+       {
+               File f = new File(System.getProperty("java.io.tmpdir") + 
"/session_" + mail);
+               return f.getAbsolutePath();
+       }
+       
        /**
         * Handle a serialized vector of vector<String>
         */
@@ -249,4 +374,29 @@
                }
                
        }
+       
+       
+       public static synchronized Boolean isSingletonProgram(String name)
+       {
+        Boolean statut = true;
+        String tmpdir = System.getProperty("java.io.tmpdir");
+        
+        File temporaryFile = new File(tmpdir + "/" + name +".tmp");
+        statut = !temporaryFile.exists();
+        
+        if(statut){
+            try 
+            {
+                               temporaryFile.createNewFile();
+                               temporaryFile.deleteOnExit();
+                               FacebookSessionUtils.lockFile = temporaryFile;
+                       } catch (IOException e) 
+                       {
+                               statut = true;
+                       }
+        }
+        
+        return statut;
+    }
+
 }


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to