src/com/beem/project/beem/BeemService.java
changeset 326 c5f000965df8
parent 315 151b1b64f407
child 342 2b489d4a7917
--- a/src/com/beem/project/beem/BeemService.java	Wed Jul 01 16:21:16 2009 +0200
+++ b/src/com/beem/project/beem/BeemService.java	Wed Jul 01 17:51:06 2009 +0200
@@ -11,6 +11,7 @@
 import org.jivesoftware.smack.packet.Presence;
 import org.jivesoftware.smack.proxy.ProxyInfo;
 import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
+import org.jivesoftware.smack.util.StringUtils;
 
 import android.app.Notification;
 import android.app.NotificationManager;
@@ -31,9 +32,8 @@
 import com.beem.project.beem.ui.Subscription;
 
 /**
- * This class is for the Beem service. The connection to the xmpp server will be made asynchronously
- * when the service will start.
- * 
+ * This class is for the Beem service. The connection to the xmpp server will be made asynchronously when the service
+ * will start.
  * @author darisk
  */
 public class BeemService extends Service {
@@ -41,20 +41,20 @@
     /**
      * The id to use for status notification.
      */
-    public static final int         NOTIFICATION_STATUS_ID = 100;
+    public static final int NOTIFICATION_STATUS_ID = 100;
 
-    private NotificationManager     mNotificationManager;
-    private XmppConnectionAdapter   mConnection;
-    private SharedPreferences       mSettings;
-    private String                  mLogin;
-    private String                  mPassword;
-    private String                  mHost;
-    private String                  mService;
-    private int                     mPort;
+    private NotificationManager mNotificationManager;
+    private XmppConnectionAdapter mConnection;
+    private SharedPreferences mSettings;
+    private String mLogin;
+    private String mPassword;
+    private String mHost;
+    private String mService;
+    private int mPort;
     private ConnectionConfiguration mConnectionConfiguration;
-    private ProxyInfo               mProxyInfo;
-    private boolean                 mUseProxy;
-    private IXmppFacade.Stub        mBind;
+    private ProxyInfo mProxyInfo;
+    private boolean mUseProxy;
+    private IXmppFacade.Stub mBind;
 
     /**
      * Constructor.
@@ -157,10 +157,8 @@
 			    notif.flags = Notification.FLAG_AUTO_CANCEL;
 			    Intent intent = new Intent(BeemService.this, Subscription.class);
 			    intent.putExtra("from", from);
-			    notif
-			    .setLatestEventInfo(BeemService.this, from, "demande d'ajout de " + from,
-				PendingIntent.getActivity(BeemService.this, 0, intent,
-				    PendingIntent.FLAG_ONE_SHOT));
+			    notif.setLatestEventInfo(BeemService.this, from, "demande d'ajout de " + from,
+				PendingIntent.getActivity(BeemService.this, 0, intent, PendingIntent.FLAG_ONE_SHOT));
 			    int id = packet.hashCode();
 			    sendNotification(id, notif);
 			}
@@ -238,12 +236,17 @@
 	mPort = Integer.parseInt(mSettings.getString(getString(R.string.settings_key_xmpp_port), "5222"));
 
 	Log.i("BEEEMSERVICE", mLogin);
-	if (mHost.equals("talk.google.com"))
-	    mService = "gmail.com";
-	else
+	/*
+	 * Gestion pour gmail.
+	 */
+	if ("".equals(mHost)) {
+	    mHost = StringUtils.parseServer(mLogin);
 	    mService = null;
+	    mLogin = StringUtils.parseName(mLogin);
+	} else
+	    mService = StringUtils.parseServer(mLogin);
 	initConnectionConfig();
-	mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);	
+	mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
 	mConnection = new XmppConnectionAdapter(mConnectionConfiguration, mLogin, mPassword, this);
 	initRosterRequestListener();
 	mBind = new XmppFacade(mConnection, this);
@@ -276,11 +279,8 @@
 
     /**
      * Show a notification.
-     * 
-     * @param id
-     *            the id of the notification.
-     * @param notif
-     *            the notification to show
+     * @param id the id of the notification.
+     * @param notif the notification to show
      */
     public void sendNotification(int id, Notification notif) {
 	mNotificationManager.notify(id, notif);