/soc/2012/michael/android: ffead588835d: dded the ability to add...

Michael Zangl michael at soc.pidgin.im
Sat Jul 7 03:34:14 EDT 2012


Changeset: ffead588835df4ee0038414eabbff790df651959
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-06-17 17:58 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/ffead588835d

Description:

dded the ability to add and remove accounts to the accountlist.

diffstat:

 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccount.java             |  11 ++
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountList.java         |   6 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountListListener.java |   7 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountManager.java      |  42 +++++++++-
 4 files changed, 62 insertions(+), 4 deletions(-)

diffs (141 lines):

diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccount.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccount.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccount.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccount.java
@@ -189,6 +189,17 @@
 
 	private native void setEnabled_native(boolean enabled);
 
+	/**
+	 * Creates a new purple account by calling purple_account_new.
+	 * <p>
+	 * This creates a new, unbound native object so be sure to free it somehow
+	 * or add it to the global list of accounts.
+	 * 
+	 * @param manager
+	 * @param name
+	 * @param protocol
+	 * @return A new purple account.
+	 */
 	protected static PurpleAccount newAccount(CoreManager manager, String name,
 			PurpleProtocolPlugin protocol) {
 		return new PurpleAccount(newAccount_native(name, protocol.getId()),
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountList.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountList.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountList.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountList.java
@@ -1,5 +1,7 @@
 package im.pidgin.libpurple.account;
 
+import im.pidgin.libpurple.plugin.PurpleProtocolPlugin;
+
 import java.util.List;
 
 /**
@@ -41,4 +43,8 @@
 	 * @return
 	 */
 	public List<PurpleAccount> getActiveAccounts();
+	
+	public PurpleAccount addAccount(String username, PurpleProtocolPlugin protocol);
+	
+	public void removeAccount(PurpleAccount account);
 }
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountListListener.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountListListener.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountListListener.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountListListener.java
@@ -14,4 +14,11 @@
 	 * @param account The account that was added.
 	 */
 	public void accountAdded(PurpleAccount account);
+	
+	/**
+	 * Called when an account was removed from the list.
+	 * 
+	 * @param account
+	 */
+	public void accountRemoved(PurpleAccount account);
 }
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountManager.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountManager.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountManager.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountManager.java
@@ -4,7 +4,9 @@
 import im.pidgin.libpurple.core.CoreManager;
 import im.pidgin.libpurple.glib.GList;
 import im.pidgin.libpurple.peering.PeerGenerator;
+import im.pidgin.libpurple.plugin.PurpleProtocolPlugin;
 
+import java.util.Hashtable;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -23,6 +25,8 @@
 
 	private final AccountListenerList accountListeners = new AccountListenerList();
 
+	private final Hashtable<Long, PurpleAccount> knownAccounts = new Hashtable<Long, PurpleAccount>();
+
 	public PurpleAccountManager(CoreManager manager) {
 		super(manager);
 	}
@@ -91,19 +95,24 @@
 	public List<PurpleAccount> getAllAccounts() {
 		return GList.fromNativeList(getAllAccounts_native(), this, false);
 	}
-	
+
 	private native long getAllAccounts_native();
 
 	@Override
 	public List<PurpleAccount> getActiveAccounts() {
 		return GList.fromNativeList(getActiveAccounts_native(), this, false);
 	}
-	
+
 	private native long getActiveAccounts_native();
 
 	@Override
 	public PurpleAccount getPeer(long pointer) {
-		return new PurpleAccount(pointer, getManager());
+		PurpleAccount purpleAccount = knownAccounts.get(pointer);
+		if (purpleAccount == null) {
+			purpleAccount = new PurpleAccount(pointer, getManager());
+			knownAccounts.put(pointer, purpleAccount);
+		}
+		return purpleAccount;
 	}
 
 	@Override
@@ -114,8 +123,33 @@
 	protected void notifyPropertiesChanged(PurpleAccount purpleAccount) {
 		accountListeners.notifyPropertiesChanged(purpleAccount);
 	}
-	
+
 	protected void notifyStatusChanged(PurpleAccount purpleAccount) {
 		accountListeners.notifyStatusChanged(purpleAccount);
 	}
+
+	@Override
+	public PurpleAccount addAccount(String username,
+			PurpleProtocolPlugin protocol) {
+		PurpleAccount account = PurpleAccount.newAccount(getManager(), username, protocol);
+		addAccount_native(account.getNativePointer());
+		return account;
+	}
+
+	/**
+	 * Calls purple_accounts_add(account);
+	 * @param nativePointer account
+	 */
+	private native void addAccount_native(long nativePointer);
+
+	@Override
+	public void removeAccount(PurpleAccount account) {
+		deleteAccount_native(account.getNativePointer());
+	}
+
+	/**
+	 * Calls purple_accounts_delete
+	 * @param nativePointer
+	 */
+	private native void deleteAccount_native(long nativePointer);
 }



More information about the Commits mailing list