/soc/2012/michael/android: a43ce3f0e238: dded some more account ...

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


Changeset: a43ce3f0e238005ae108a6cd1974fd8497a4d003
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-06-16 18:32 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/a43ce3f0e238

Description:

dded some more account functionality and wrappers that send function calls to native functions.

diffstat:

 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/AccountListenerList.java   |   16 +-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccount.java         |  200 +++++++++-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountList.java     |   13 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountListener.java |   10 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountManager.java  |   37 +-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java              |    4 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/PeeredPurpleManaged.java      |    4 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/PurpleInstance.java           |    5 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/glib/GList.java                    |    7 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/peering/Peered.java                |    2 +-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/plugin/PurplePlugin.java           |    3 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/plugin/PurpleProtocolPlugin.java   |    3 +-
 12 files changed, 298 insertions(+), 6 deletions(-)

diffs (truncated from 453 to 300 lines):

diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/AccountListenerList.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/AccountListenerList.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/AccountListenerList.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/AccountListenerList.java
@@ -11,13 +11,25 @@
 	private final LinkedList<PurpleAccountListener> listeners = new LinkedList<PurpleAccountListener>();
 
 	@Override
-	public void addAccountListener(PurpleAccountListener listener) {
+	public synchronized void addAccountListener(PurpleAccountListener listener) {
 		listeners.add(listener);
 	}
 	
 	@Override
-	public void removeAccountListener(PurpleAccountListener listener) {
+	public synchronized void removeAccountListener(PurpleAccountListener listener) {
 		listeners.remove(listener);
 	}
+
+	public synchronized void notifyPropertiesChanged(PurpleAccount purpleAccount) {
+		for (PurpleAccountListener l : listeners) {
+			l.accountPropertiesChanged(purpleAccount);
+		}
+	}
+
+	public synchronized void notifyStatusChanged(PurpleAccount purpleAccount) {
+		for (PurpleAccountListener l : listeners) {
+			l.accountStatusChanged(purpleAccount);
+		}
+	}
 }
 
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
@@ -1,11 +1,209 @@
 package im.pidgin.libpurple.account;
 
+import im.pidgin.libpurple.core.CoreManager;
+import im.pidgin.libpurple.core.PeeredPurpleManaged;
+import im.pidgin.libpurple.core.thread.AbstractWaitableRunnable;
+import im.pidgin.libpurple.plugin.PurpleProtocolPlugin;
+
 /**
  * This is an account of libpurple.
  * 
  * @author michaelz
  * 
  */
-public final class PurpleAccount {
+public final class PurpleAccount extends PeeredPurpleManaged {
 
+	/**
+	 * Listeners that just listen to us.
+	 */
+	private final AccountListenerList individualAccountListeners = new AccountListenerList();
+
+	public PurpleAccount(long nativePointer, CoreManager manager) {
+		super(nativePointer, manager);
+	}
+
+	@Override
+	protected long getNativePointer() {
+		/* just to change visibility */
+		return super.getNativePointer();
+	}
+
+	/**
+	 * Gets the username of the account
+	 * 
+	 * @return
+	 */
+	public String getUsername() {
+		return getUsername_native();
+	}
+
+	private native String getUsername_native();
+
+	/**
+	 * Sets the username of the account, that is the name the account has on the
+	 * server
+	 * 
+	 * @param name
+	 *            The username
+	 */
+	public void setUsername(final String name) {
+		getManager().getThread().schedule(new AbstractWaitableRunnable() {
+			@Override
+			protected void execute() {
+				setUsername_native(name);
+			}
+		});
+		notifyPropertiesChanged();
+	}
+
+	private native void setUsername_native(String name);
+
+	/**
+	 * Gets the Alias of the account
+	 * 
+	 * @return
+	 */
+	public String getAlias() {
+		return getAlias_native();
+	}
+
+	private native String getAlias_native();
+
+	/**
+	 * Sets the Alias of the account, that is the name that should be used in
+	 * the User interface.
+	 * 
+	 * @param name
+	 *            The Alias
+	 */
+	public void setAlias(final String name) {
+		getManager().getThread().schedule(new AbstractWaitableRunnable() {
+			@Override
+			protected void execute() {
+				setAlias_native(name);
+			}
+		});
+		notifyPropertiesChanged();
+	}
+
+	private native void setAlias_native(String name);
+
+	/**
+	 * Gets the Password of the account
+	 * 
+	 * @return
+	 */
+	public String getPassword() {
+		return getPassword_native();
+	}
+
+	private native String getPassword_native();
+
+	/**
+	 * Sets the Password of the account
+	 * 
+	 * @param password
+	 *            The Password or null to reset the password.
+	 */
+	public void setPassword(final String password) {
+		getManager().getThread().schedule(new AbstractWaitableRunnable() {
+			@Override
+			protected void execute() {
+				setPassword_native(password);
+			}
+		});
+		notifyPropertiesChanged();
+	}
+
+	private native void setPassword_native(String password);
+
+	/**
+	 * Gets the remember password state for this account.
+	 * 
+	 * @return ture if the password should be remembered.
+	 */
+	public boolean getRememberPassword() {
+		return getRememberPassword_native();
+	}
+
+	private native boolean getRememberPassword_native();
+
+	/**
+	 * Sets if the password should be remembered
+	 * 
+	 * @param remember
+	 *            true if libpurple should store the password
+	 */
+	public void setRememberPassword(final boolean remember) {
+		getManager().getThread().schedule(new AbstractWaitableRunnable() {
+			@Override
+			protected void execute() {
+				setRememberPassword_native(remember);
+			}
+		});
+		notifyPropertiesChanged();
+	}
+
+	private native void setRememberPassword_native(boolean remember);
+
+	/**
+	 * Registers the account on the server.
+	 */
+	public void register() {
+		getManager().getThread().schedule(new AbstractWaitableRunnable() {
+			@Override
+			protected void execute() {
+				register_native();
+			}
+		});
+	}
+
+	private native void register_native();
+
+	/**
+	 * Gets the enabled status of the account
+	 * 
+	 * @return ture if the account is enabled
+	 */
+	public boolean isEnabled() {
+		return isEnabled_native();
+	}
+
+	private native boolean isEnabled_native();
+
+	/**
+	 * Enables or disables the account
+	 * 
+	 * @param enabled
+	 *            The new enabled state of the account
+	 */
+	public void setEnabled(final boolean enabled) {
+		getManager().getThread().schedule(new AbstractWaitableRunnable() {
+			@Override
+			protected void execute() {
+				setEnabled_native(enabled);
+			}
+		});
+		notifyStatusChanged();
+	}
+
+	private native void setEnabled_native(boolean enabled);
+
+	protected static PurpleAccount newAccount(CoreManager manager, String name,
+			PurpleProtocolPlugin protocol) {
+		return new PurpleAccount(newAccount_native(name, protocol.getId()),
+				manager);
+	}
+
+	private native static long newAccount_native(String name, String protocolId);
+
+	private void notifyPropertiesChanged() {
+		individualAccountListeners.notifyPropertiesChanged(this);
+		getManager().getAccountList().notifyPropertiesChanged(this);
+	}
+
+	private void notifyStatusChanged() {
+		individualAccountListeners.notifyStatusChanged(this);
+		getManager().getAccountList().notifyStatusChanged(this);
+	}
 }
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 java.util.List;
+
 /**
  * THis is an account list that is part of a purple instance.
  * <p>
@@ -28,4 +30,15 @@
 	 *            The listener.
 	 */
 	public void removeAccountListener(PurpleAccountListListener listener);
+	
+	/**
+	 * Gets a list of all Accounts
+	 */
+	public List<PurpleAccount> getAllAccounts();
+	
+	/**
+	 * Gets a list of accounts that are currently marked as active.
+	 * @return
+	 */
+	public List<PurpleAccount> getActiveAccounts();
 }
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountListener.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountListener.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountListener.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountListener.java
@@ -6,5 +6,15 @@
  *
  */
 public interface PurpleAccountListener {
+	/**
+	 * Called when the status of the account changed
+	 * @param account
+	 */
 	void accountStatusChanged(PurpleAccount account);
+	
+	/**
+	 * Called when the properties of the account were changed
+	 * @param account The changed account.
+	 */
+	void accountPropertiesChanged(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
@@ -2,8 +2,11 @@
 
 import im.pidgin.libpurple.core.AbstractPurpleManaged;
 import im.pidgin.libpurple.core.CoreManager;
+import im.pidgin.libpurple.glib.GList;
+import im.pidgin.libpurple.peering.PeerGenerator;



More information about the Commits mailing list