libtelepathy/tsrc/src/telepathygabblepresencetest.cpp
changeset 10 59927b2d3b75
parent 0 d0f3a028347a
equal deleted inserted replaced
0:d0f3a028347a 10:59927b2d3b75
     1 /*
       
     2 * Copyright (c) 2008 - 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    Used for Presence Test Cases
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20  
       
    21 // INCLUDE FILES
       
    22 #include "telepathygabblepresencetest.h"
       
    23 #include "telepathygabbletestdata.h"
       
    24 
       
    25 //-----------------------------------------------------------------------------
       
    26 // function_name	: CTestData
       
    27 // description     	: Constructor
       
    28 // Returns          : None
       
    29 //-----------------------------------------------------------------------------
       
    30 
       
    31 CTelepathyGabblePresenceTest::CTelepathyGabblePresenceTest()
       
    32     {
       
    33     }
       
    34     
       
    35 //-----------------------------------------------------------------------------
       
    36 // function_name	: ConstructL
       
    37 // description     	: Constructor
       
    38 // Returns          : None
       
    39 //-----------------------------------------------------------------------------
       
    40 
       
    41 void CTelepathyGabblePresenceTest::ConstructL()
       
    42 	{
       
    43  	
       
    44 	}
       
    45 
       
    46 //-----------------------------------------------------------------------------
       
    47 // function_name	: NewL
       
    48 // description     	: Constructor
       
    49 // Returns          : None
       
    50 //-----------------------------------------------------------------------------
       
    51 CTelepathyGabblePresenceTest* CTelepathyGabblePresenceTest::NewL()
       
    52     {
       
    53     
       
    54 	CTelepathyGabblePresenceTest* self = new(ELeave) CTelepathyGabblePresenceTest;
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();    
       
    57     CleanupStack::Pop();
       
    58     return self;
       
    59     }
       
    60 
       
    61 //-----------------------------------------------------------------------------
       
    62 // function_name	: ~CTelepathyGabblePresenceTest
       
    63 // description     	: destructor
       
    64 // Returns          : None
       
    65 //-----------------------------------------------------------------------------
       
    66 CTelepathyGabblePresenceTest::~CTelepathyGabblePresenceTest()
       
    67 {
       
    68 	
       
    69 }
       
    70 
       
    71 
       
    72 //-----------------------------------------------------------------------------
       
    73 // function_name	: ~CTestData
       
    74 // description     	: destructor
       
    75 // Returns          : None
       
    76 //-----------------------------------------------------------------------------
       
    77 TelepathyPresenceState CTelepathyGabblePresenceTest::telepathy_presence_state_from_str (const gchar *str)
       
    78 {
       
    79 	char temp[25];
       
    80 	strcpy(temp,str);
       
    81 	//roster_log_handler("telepathy_telepathy_presence_state_from_str");
       
    82 	//roster_log_handler(temp);
       
    83 
       
    84 	if (strcmp (str, "available") == 0) {
       
    85 		return TELEPATHY_PRESENCE_STATE_AVAILABLE;
       
    86 	} else if ((strcmp (str, "dnd") == 0) || (strcmp (str, "busy") == 0)) {
       
    87 		return TELEPATHY_PRESENCE_STATE_BUSY;
       
    88 	} else if ((strcmp (str, "away") == 0) || (strcmp (str, "brb") == 0)) {
       
    89 		return TELEPATHY_PRESENCE_STATE_AWAY;
       
    90 	} else if (strcmp (str, "xa") == 0) {
       
    91 		return TELEPATHY_PRESENCE_STATE_EXT_AWAY;
       
    92 	} else if (strcmp (str, "hidden") == 0) {
       
    93 		return TELEPATHY_PRESENCE_STATE_HIDDEN;
       
    94 	} else if (strcmp (str, "offline") == 0) {
       
    95 		return TELEPATHY_PRESENCE_STATE_UNAVAILABLE;
       
    96 	} 
       
    97 
       
    98 	return TELEPATHY_PRESENCE_STATE_AVAILABLE;
       
    99 }
       
   100 
       
   101 //-----------------------------------------------------------------------------
       
   102 // function_name	: ~CTestData
       
   103 // description     	: destructor
       
   104 // Returns          : None
       
   105 //-----------------------------------------------------------------------------
       
   106 //vinod: gossip_telepathy_contacts_send_presence
       
   107 void
       
   108 CTelepathyGabblePresenceTest::telepathy_contacts_send_presence (DBusGProxy *pres_iface,
       
   109 					 TelepathyPresence *presence/*CTestData *aTestData*/)
       
   110 {
       
   111 	GHashTable          *status_ids;
       
   112 	GHashTable          *status_options;
       
   113 	const gchar         *status_id;
       
   114 	const gchar         *message;
       
   115 	TelepathyPresenceState  presence_state;
       
   116 	GError              *error = NULL;
       
   117 	GValue               value_message = {0, };
       
   118 	
       
   119 	//iTpConn = aTestData->GetTpConn();
       
   120 
       
   121 	//g_return_if_fail (contacts != NULL);
       
   122 	//g_return_if_fail (GOSSIP_IS_PRESENCE (presence));
       
   123 
       
   124 	if (!pres_iface) {
       
   125 		return;
       
   126 	}
       
   127 
       
   128 	status_ids = g_hash_table_new_full (g_str_hash,
       
   129 					    g_str_equal,
       
   130 					    g_free,
       
   131 					    (GDestroyNotify) g_hash_table_destroy);
       
   132 	status_options = g_hash_table_new_full (g_str_hash,
       
   133 						g_str_equal,
       
   134 						NULL,
       
   135 						(GDestroyNotify) g_value_unset);
       
   136 
       
   137 	presence_state = telepathy_presence_get_state (presence);
       
   138 	status_id = telepathy_presence_state_to_str (presence_state);
       
   139 	message = telepathy_presence_get_status (presence);
       
   140 
       
   141 	if (message) {
       
   142 		g_value_init (&value_message, G_TYPE_STRING);
       
   143 		g_value_set_string (&value_message, message);
       
   144 		g_hash_table_insert (status_options, (gpointer)"message", &value_message);
       
   145 	}
       
   146 
       
   147 	g_hash_table_insert (status_ids,
       
   148 			     g_strdup (status_id),
       
   149 			     status_options);
       
   150 
       
   151 	//Sync way: gossip_debug (DEBUG_DOMAIN, "sending presence...");
       
   152 	if (! (DBUS_G_PROXY(pres_iface),
       
   153 						status_ids,
       
   154 						&error)) {
       
   155 		//gossip_debug ("Could not set presence: %s", error->message);
       
   156 		//roster_log_handler("Could not set presence\n");
       
   157 		g_clear_error (&error);
       
   158 	}
       
   159 	//Async way
       
   160 /*tp_conn_iface_presence_set_status_async(DBUS_G_PROXY(pres_iface),
       
   161 						status_ids,
       
   162 						,
       
   163 						NULL );
       
   164 */
       
   165 	g_hash_table_destroy (status_ids);
       
   166 }
       
   167 
       
   168 //-----------------------------------------------------------------------------
       
   169 // function_name	: telepathy_presences_foreach
       
   170 // description     	: destructor
       
   171 // Returns          : None
       
   172 //-----------------------------------------------------------------------------
       
   173 void
       
   174 CTelepathyGabblePresenceTest::telepathy_presences_foreach (gpointer *key,
       
   175 		      gpointer        *value,
       
   176 		      TelepathyPresence **presence)
       
   177 {
       
   178 	TelepathyPresenceState state;
       
   179 	const gchar        *message;
       
   180 	char temp[100];
       
   181 
       
   182 	*presence = telepathy_presence_new();
       
   183 
       
   184 	//roster_log_handler("telepathy_presences_foreach");
       
   185 //	roster_log_handler(key);
       
   186 
       
   187 	state = telepathy_presence_state_from_str((const gchar *)key);
       
   188 
       
   189 	telepathy_presence_set_state(*presence, state);
       
   190 
       
   191 	message = g_value_get_string((GValue *)
       
   192 				     g_hash_table_lookup((GHashTable *)
       
   193 							 value, "message"));
       
   194 	strcpy(temp,message);
       
   195 	//roster_log_handler(temp);
       
   196 		
       
   197 }
       
   198 
       
   199 //-----------------------------------------------------------------------------
       
   200 // function_name	: telepathy_presence_handle_foreach
       
   201 // description     	: destructor
       
   202 // Returns          : None
       
   203 //-----------------------------------------------------------------------------
       
   204 void
       
   205 CTelepathyGabblePresenceTest::telepathy_presence_handle_foreach (gpointer *key,
       
   206 		      gpointer        *value)
       
   207 {
       
   208 	gint                 handle_id;
       
   209 	GHashTable          *presences_hash;
       
   210 	GValue              *gvalue;
       
   211 	gboolean             new_item;
       
   212 	GObject		       *contact;
       
   213 	GObject      *presence;
       
   214 	gchar              **handle_name;
       
   215 	GArray              *handles;
       
   216 
       
   217 	CTestData* atestData;
       
   218 
       
   219 	handle_id = GPOINTER_TO_INT(key);
       
   220 	
       
   221 	handles = g_array_new (FALSE, FALSE, sizeof (gint));
       
   222 	g_array_append_val (handles, handle_id);
       
   223 	tp_conn_inspect_handles(DBUS_G_PROXY(atestData->GetTpConn()),
       
   224 			       TP_CONN_HANDLE_TYPE_CONTACT, handles,
       
   225 			       &handle_name, NULL);
       
   226 	
       
   227 	gvalue = g_value_array_get_nth((GValueArray *) value, 1);
       
   228 	
       
   229 	presences_hash = (GHashTable *) g_value_get_boxed(gvalue);
       
   230 	
       
   231 	g_hash_table_foreach(presences_hash,
       
   232 			     (GHFunc) telepathy_presences_foreach, &presence);
       
   233 }
       
   234 
       
   235 //-----------------------------------------------------------------------------
       
   236 // function_name	: ~CTestData
       
   237 // description     	: destructor
       
   238 // Returns          : None
       
   239 //-----------------------------------------------------------------------------
       
   240 void CTelepathyGabblePresenceTest::telepathy_presence_handler(DBusGProxy      *proxy,
       
   241 			   GHashTable      *handle_hash)
       
   242 {
       
   243 	//GObject      *presence;
       
   244 	TelepathyPresence        *presence;
       
   245 	TelepathyPresenceState state;
       
   246 	GSList *data = NULL;
       
   247 	//vinod: setting the new presence status
       
   248 	presence = telepathy_presence_new();
       
   249 	//here am hard coding the value, this can be taken from ximpfw
       
   250 	state = telepathy_presence_state_from_str("dnd");   
       
   251 	telepathy_presence_set_state(presence, state);
       
   252 	//vinod
       
   253 	//roster_log_handler("telepathy_presence_handler callback\n");
       
   254 	g_hash_table_foreach(handle_hash, (GHFunc) telepathy_presence_handle_foreach, data);
       
   255 
       
   256 
       
   257  //vinod: call telepathy_set_presence method here 
       
   258  telepathy_contacts_send_presence(proxy, presence);
       
   259 
       
   260 }
       
   261 
       
   262 //  End of File