[tuxdroid-svn] r5765 - in software_suite_v3/software/plugin/plugin-facebook/branches/october_releas
Status: Beta
Brought to you by:
ks156
From: jerome <c2m...@c2...> - 2009-10-23 14:05:08
|
Author: jerome Date: 2009-10-23 15:38:08 +0200 (Fri, 23 Oct 2009) New Revision: 5765 Modified: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/resources/plugin.xml software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookConnection.java software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/connection/BareBonesBrowserLaunch.java Log: * Forget to add first cycle stuff. * Imroved auto auth prompt. Modified: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/resources/plugin.xml =================================================================== --- software_suite_v3/software/plugin/plugin-facebook/branches/october_release/resources/plugin.xml 2009-10-23 12:06:17 UTC (rev 5764) +++ software_suite_v3/software/plugin/plugin-facebook/branches/october_release/resources/plugin.xml 2009-10-23 13:38:08 UTC (rev 5765) @@ -85,54 +85,12 @@ weekMask="true,true,true,true,true,true,true" weekMaskType="weekpart" - weekMaskVisible="true" + weekMaskVisible="false" - delay="00:01:00" + delay="00:05:00" delayMask="true,true,true" delayVisible="false" /> - <task - name="Start every x from full hour" - description="Start me every x (From full hour)" - command="check" - type="every x from full hour" - activated="false" - - weekMask="true,true,true,true,true,true,true" - weekMaskType="weekpart" - weekMaskVisible="true" - - date="0000/00/00" - dateVisible="false" - - hoursBegin="00:00:00" - hoursBeginMask="true,true,true" - hoursBeginVisible="false" - - hoursEnd="23:59:00" - hoursEndMask="true,true,true" - hoursEndVisible="false" - - delay="00:15:00" - delayType="quarters" - delayMask="true,true,false" - delayVisible="true" - /> - <task - name="Start daily at" - description="Start me daily" - command="check" - type="daily at" - activated="false" - - weekMask="true,true,true,true,true,true,true" - weekMaskType="weekpart" - weekMaskVisible="true" - - hoursBegin="07:00:00" - hoursBeginMask="true,true,false" - hoursBeginVisible="true" - /> </tasks> </plugin> Modified: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookConnection.java =================================================================== --- software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookConnection.java 2009-10-23 12:06:17 UTC (rev 5764) +++ software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookConnection.java 2009-10-23 13:38:08 UTC (rev 5765) @@ -23,7 +23,6 @@ package com.kysoh.plugins.facebook; import java.io.IOException; -import java.util.List; import com.google.code.facebookapi.FacebookException; import com.google.code.facebookapi.FacebookJsonRestClient; @@ -34,11 +33,7 @@ private FacebookJsonRestClient client; - //Auth options. - public static final byte AUTH_PUBLISH_FEEDS = 0; - public static final byte AUTH_READ_MAILBOX = 1; - /** * Try to get connected to fb with the old registered session. */ @@ -146,28 +141,15 @@ /** * Prompt for plugin facebook authorizations. */ - public static void promptAuthorizations(List<Byte> options) + public static void promptAuthorizations() { - //Adding default. - String rights = "read_stream,offline_access"; - - if(options.contains(FacebookConnection.AUTH_PUBLISH_FEEDS)) - { - rights += "," + "read_mailbox"; - } - - if(options.contains(FacebookConnection.AUTH_READ_MAILBOX)) - { - rights += "," + "publish_stream"; - } - - String url = "http://www.facebook.com/login.php?api_key=+" + + String url = "http://www.facebook.com/login.php?api_key=" + FacebookSessionUtils.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" + - "&req_perms=" + rights; + "&req_perms=read_stream,offline_access,read_mailbox,publish_stream"; BareBonesBrowserLaunch.openURL(url); } Modified: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java =================================================================== --- software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java 2009-10-23 12:06:17 UTC (rev 5764) +++ software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java 2009-10-23 13:38:08 UTC (rev 5765) @@ -425,4 +425,25 @@ return result; } + + + /** + * Return true if our plugin has fb rights. + * @return + */ + public boolean apiGrantedFullAcess() + { + //Trying to read mailbox that is the most important right to have. + String query = "SELECT thread_id FROM thread WHERE folder_id = 0"; + try + { + client.fql_query(query); + return true; + } + catch (FacebookException e) + { + //Return false in case of exception, prompt auth was never started. + return false; + } + } } Modified: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java =================================================================== --- software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java 2009-10-23 12:06:17 UTC (rev 5764) +++ software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java 2009-10-23 13:38:08 UTC (rev 5765) @@ -22,10 +22,7 @@ package com.kysoh.plugins.facebook; - -import java.util.ArrayList; import java.util.Hashtable; -import java.util.List; import java.util.Vector; import com.kysoh.tuxdroid.plugin.framework.plugin.SimplePlugin; @@ -39,6 +36,9 @@ private boolean check = false; private boolean throwed = false; + + private boolean secondCycle = false; + private FacebookFunctions functions; private FacebookDatasStruct facebookHistory; @@ -51,6 +51,7 @@ { throwed = true; this.throwResult(true); + this.throwMessage("Facebook"); } } @@ -62,7 +63,12 @@ { if (this.getCommand().equalsIgnoreCase("configure")) { - this.doConfigure(); + FacebookConnection facebook = new FacebookConnection(); + if ( facebook.Connect(this.configuration().getLogin(), this.configuration().getPassword()) ) + { + functions = new FacebookFunctions(facebook.getClient()); + this.doConfigure(functions); + } } else { @@ -75,24 +81,16 @@ /** * Configure facebook account access rights. */ - public void doConfigure() - { - List<Byte> options = new ArrayList<Byte>(); - + public void doConfigure(FacebookFunctions funct) + { //Adding publish stream auth if needed. - if(this.configuration().getUpdateStatus()) + if (!functions.apiGrantedFullAcess()) { - options.add(FacebookConnection.AUTH_PUBLISH_FEEDS); + //Prompt web browser for facebook permissions. + this.throwMessage("Please, allow me to access you Facebook account"); + FacebookConnection.promptAuthorizations(); + System.exit( 0 ); } - - //Adding read mailbox auth if needed. - if(this.configuration().getNotifyEmail()) - { - options.add(FacebookConnection.AUTH_READ_MAILBOX); - } - - //Prompt web browser for facebook permissions. - FacebookConnection.promptAuthorizations(options); } @@ -110,7 +108,14 @@ //History object. facebookHistory = new FacebookDatasStruct(this.configuration().getLogin()); + secondCycle = ( this.getCommand().equalsIgnoreCase("check") && facebookHistory.isFirstCycle() ) ? false : true; + //Checking auth. + if(this.getCommand().equalsIgnoreCase("run")) + { + this.doConfigure(functions); + } + //Updating user status. if(this.configuration().getUpdateStatus()) { @@ -174,7 +179,8 @@ } else { - this.throwMessage("An error occured trying to set your new status, please, try again later"); + this.throwMessage("An error occured trying to set your new status, please, allow me to acces your wall"); + doConfigure(functions); } } @@ -223,16 +229,18 @@ for(String sender : senders) { - - throwRes(); - if (emailsBySender.get(sender).intValue() == 1) + if(this.getCommand().equalsIgnoreCase("run") || secondCycle) { - this.throwMessage("One message from {0}", sender); + throwRes(); + if (emailsBySender.get(sender).intValue() == 1) + { + this.throwMessage("One message from {0}", sender); + } + else + { + this.throwMessage("{0} messages from {1}", sender, emailsBySender.get(sender)); + } } - else - { - this.throwMessage("{0} messages from {1}", sender, emailsBySender.get(sender)); - } } //Registering history. @@ -264,8 +272,12 @@ { throwRes(); this.facebookHistory.addFriendRequest(fid); - this.throwMessage("{0} request to be your friend", request); - said = true; + //Only throwing in the second cycle of check command or run. + if(this.getCommand().equalsIgnoreCase("run") || secondCycle) + { + this.throwMessage("{0} request to be your friend", request); + said = true; + } } } this.facebookHistory.registerStruct(); @@ -305,8 +317,12 @@ { throwRes(); this.facebookHistory.addGroupInvite(gid); - this.throwMessage("You are invited to the following group: {0}", group); - said = true; + //Only throwing in the second cycle of check command or run. + if(this.getCommand().equalsIgnoreCase("run") || secondCycle) + { + this.throwMessage("You are invited to the following group: {0}", group); + said = true; + } } } @@ -345,8 +361,12 @@ { throwRes(); this.facebookHistory.addEventInvite(functions.getEventID(event)); - this.throwMessage("You are invited to the following event: {0}", event); - said = true; + //Only throwing in the second cycle of check command or run. + if(this.getCommand().equalsIgnoreCase("run") || secondCycle) + { + this.throwMessage("You are invited to the following event: {0}", event); + said = true; + } } } Modified: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/connection/BareBonesBrowserLaunch.java =================================================================== --- software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/connection/BareBonesBrowserLaunch.java 2009-10-23 12:06:17 UTC (rev 5764) +++ software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/connection/BareBonesBrowserLaunch.java 2009-10-23 13:38:08 UTC (rev 5765) @@ -30,7 +30,10 @@ openURL.invoke(null, new Object[] {url}); } else if (osName.startsWith("Windows")) - Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); + { + Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); + p.waitFor(); + } else { //assume Unix or Linux String[] browsers = { |