* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Authors: Xavier Claessens <xclaesse@gmail.com>
*/
#include <libmissioncontrol/mc-enum-types.h>
#include "empathy-idle.h"
-#include "empathy-utils.h"
+#include "empathy-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
#include "empathy-debug.h"
DBusGProxy *gs_proxy;
DBusGProxy *nm_proxy;
- McPresence state;
+ TpConnectionPresenceType state;
gchar *status;
- McPresence flash_state;
+ TpConnectionPresenceType flash_state;
gboolean auto_away;
gboolean use_nm;
- McPresence away_saved_state;
- McPresence nm_saved_state;
+ TpConnectionPresenceType away_saved_state;
+ TpConnectionPresenceType nm_saved_state;
+ gchar *nm_saved_status;
gboolean is_idle;
gboolean nm_connected;
static void
idle_presence_changed_cb (MissionControl *mc,
- McPresence state,
+ TpConnectionPresenceType state,
gchar *status,
EmpathyIdle *idle)
{
g_free (priv->status);
priv->state = state;
priv->status = NULL;
- if (!G_STR_EMPTY (status)) {
+ if (!EMP_STR_EMPTY (status)) {
priv->status = g_strdup (status);
}
priv = GET_PRIV (idle);
DEBUG ("Going to extended autoaway");
- empathy_idle_set_state (idle, MC_PRESENCE_EXTENDED_AWAY);
+ empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY);
priv->ext_away_timeout = 0;
return FALSE;
is_idle ? "yes" : "no");
if (!priv->auto_away ||
- (priv->nm_saved_state == MC_PRESENCE_UNSET &&
- (priv->state <= MC_PRESENCE_OFFLINE ||
- priv->state == MC_PRESENCE_HIDDEN))) {
+ (priv->nm_saved_state == TP_CONNECTION_PRESENCE_TYPE_UNSET &&
+ (priv->state <= TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
+ priv->state == TP_CONNECTION_PRESENCE_TYPE_HIDDEN))) {
/* We don't want to go auto away OR we explicitely asked to be
* offline, nothing to do here */
priv->is_idle = is_idle;
}
if (is_idle && !priv->is_idle) {
- McPresence new_state;
+ TpConnectionPresenceType new_state;
/* We are now idle */
idle_ext_away_start (idle);
- if (priv->nm_saved_state != MC_PRESENCE_UNSET) {
+ if (priv->nm_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
/* We are disconnected, when coming back from away
* we want to restore the presence before the
* disconnection. */
priv->away_saved_state = priv->state;
}
- new_state = MC_PRESENCE_AWAY;
- if (priv->state == MC_PRESENCE_EXTENDED_AWAY) {
- new_state = MC_PRESENCE_EXTENDED_AWAY;
+ new_state = TP_CONNECTION_PRESENCE_TYPE_AWAY;
+ if (priv->state == TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY) {
+ new_state = TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY;
}
DEBUG ("Going to autoaway. Saved state=%d, new state=%d",
idle_ext_away_stop (idle);
- if (priv->away_saved_state == MC_PRESENCE_AWAY ||
- priv->away_saved_state == MC_PRESENCE_EXTENDED_AWAY) {
- priv->away_saved_state = MC_PRESENCE_AVAILABLE;
+ if (priv->away_saved_state == TP_CONNECTION_PRESENCE_TYPE_AWAY ||
+ priv->away_saved_state == TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY) {
+ priv->away_saved_state = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
new_status = NULL;
} else {
new_status = priv->status;
priv->away_saved_state,
new_status);
- priv->away_saved_state = MC_PRESENCE_UNSET;
+ priv->away_saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
}
priv->is_idle = is_idle;
priv = GET_PRIV (idle);
- if (!priv->use_nm) {
+ if (!priv->use_nm
+ || priv->nm_saved_state == TP_CONNECTION_PRESENCE_TYPE_UNSET) {
return;
}
if (old_nm_connected && !new_nm_connected) {
/* We are no more connected */
- DEBUG ("Disconnected: Save state %d", priv->state);
+ DEBUG ("Disconnected: Save state %d (%s)",
+ priv->state, priv->status);
priv->nm_saved_state = priv->state;
- empathy_idle_set_state (idle, MC_PRESENCE_OFFLINE);
+ g_free (priv->nm_saved_status);
+ priv->nm_saved_status = g_strdup (priv->status);
+ empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
}
else if (!old_nm_connected && new_nm_connected) {
/* We are now connected */
- DEBUG ("Reconnected: Restore state %d", priv->nm_saved_state);
- empathy_idle_set_state (idle, priv->nm_saved_state);
- priv->nm_saved_state = MC_PRESENCE_UNSET;
+ DEBUG ("Reconnected: Restore state %d (%s)",
+ priv->nm_saved_state, priv->nm_saved_status);
+ empathy_idle_set_presence (idle,
+ priv->nm_saved_state,
+ priv->nm_saved_status);
+ priv->nm_saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
+ g_free (priv->nm_saved_status);
+ priv->nm_saved_status = NULL;
}
priv->nm_connected = new_nm_connected;
(type, n_props, props);
idle_singleton = EMPATHY_IDLE (retval);
- g_object_add_weak_pointer (retval, (gpointer *) &idle_singleton);
+ g_object_add_weak_pointer (retval, (gpointer) &idle_singleton);
}
return retval;
g_object_class_install_property (object_class,
PROP_STATE,
- g_param_spec_enum ("state",
+ g_param_spec_uint ("state",
"state",
"state",
- MC_TYPE_PRESENCE,
- MC_PRESENCE_AVAILABLE,
+ 0, NUM_TP_CONNECTION_PRESENCE_TYPES,
+ TP_CONNECTION_PRESENCE_TYPE_UNSET,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_STATUS,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_FLASH_STATE,
- g_param_spec_enum ("flash-state",
+ g_param_spec_uint ("flash-state",
"flash-state",
"flash-state",
- MC_TYPE_PRESENCE,
- MC_PRESENCE_UNSET,
+ 0, NUM_TP_CONNECTION_PRESENCE_TYPES,
+ TP_CONNECTION_PRESENCE_TYPE_UNSET,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
g_type_class_add_private (object_class, sizeof (EmpathyIdlePriv));
}
+static TpConnectionPresenceType
+empathy_idle_get_actual_presence (EmpathyIdle *idle, GError **error)
+{
+ McPresence presence;
+ EmpathyIdlePriv *priv = GET_PRIV (idle);
+
+ presence = mission_control_get_presence_actual (priv->mc, error);
+
+ switch (presence) {
+ case MC_PRESENCE_OFFLINE:
+ return TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
+ case MC_PRESENCE_AVAILABLE:
+ return TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
+ case MC_PRESENCE_AWAY:
+ return TP_CONNECTION_PRESENCE_TYPE_AWAY;
+ case MC_PRESENCE_EXTENDED_AWAY:
+ return TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY;
+ case MC_PRESENCE_HIDDEN:
+ return TP_CONNECTION_PRESENCE_TYPE_HIDDEN;
+ case MC_PRESENCE_DO_NOT_DISTURB:
+ return TP_CONNECTION_PRESENCE_TYPE_BUSY;
+ default:
+ return TP_CONNECTION_PRESENCE_TYPE_UNSET;
+ }
+}
+
static void
empathy_idle_init (EmpathyIdle *idle)
{
idle->priv = priv;
priv->is_idle = FALSE;
- priv->mc = empathy_mission_control_new ();
- priv->state = mission_control_get_presence_actual (priv->mc, &error);
+ priv->mc = empathy_mission_control_dup_singleton ();
+ priv->state = empathy_idle_get_actual_presence (idle, &error);
if (error) {
DEBUG ("Error getting actual presence: %s", error->message);
- priv->state = MC_PRESENCE_UNSET;
+ priv->state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
g_clear_error (&error);
}
priv->status = mission_control_get_presence_message_actual (priv->mc, &error);
- if (error || G_STR_EMPTY (priv->status)) {
+ if (error || EMP_STR_EMPTY (priv->status)) {
g_free (priv->status);
priv->status = NULL;
return g_object_new (EMPATHY_TYPE_IDLE, NULL);
}
-McPresence
+TpConnectionPresenceType
empathy_idle_get_state (EmpathyIdle *idle)
{
EmpathyIdlePriv *priv;
void
empathy_idle_set_state (EmpathyIdle *idle,
- McPresence state)
+ TpConnectionPresenceType state)
{
EmpathyIdlePriv *priv;
empathy_idle_set_presence (idle, priv->state, status);
}
-McPresence
+TpConnectionPresenceType
empathy_idle_get_flash_state (EmpathyIdle *idle)
{
EmpathyIdlePriv *priv;
void
empathy_idle_set_flash_state (EmpathyIdle *idle,
- McPresence state)
+ TpConnectionPresenceType state)
{
EmpathyIdlePriv *priv;
priv->flash_state = state;
- if (state == MC_PRESENCE_UNSET) {
+ if (state == TP_CONNECTION_PRESENCE_TYPE_UNSET) {
}
g_object_notify (G_OBJECT (idle), "flash-state");
}
+static void
+empathy_idle_do_set_presence (EmpathyIdle *idle,
+ TpConnectionPresenceType state,
+ const gchar *status)
+{
+ McPresence mc_state = MC_PRESENCE_UNSET;
+ EmpathyIdlePriv *priv = GET_PRIV (idle);
+
+ switch (state) {
+ case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
+ mc_state = MC_PRESENCE_OFFLINE;
+ break;
+ case TP_CONNECTION_PRESENCE_TYPE_AVAILABLE:
+ mc_state = MC_PRESENCE_AVAILABLE;
+ break;
+ case TP_CONNECTION_PRESENCE_TYPE_AWAY:
+ mc_state = MC_PRESENCE_AWAY;
+ break;
+ case TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY:
+ mc_state = MC_PRESENCE_EXTENDED_AWAY;
+ break;
+ case TP_CONNECTION_PRESENCE_TYPE_HIDDEN:
+ mc_state = MC_PRESENCE_HIDDEN;
+ break;
+ case TP_CONNECTION_PRESENCE_TYPE_BUSY:
+ mc_state = MC_PRESENCE_DO_NOT_DISTURB;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ mission_control_set_presence (priv->mc, mc_state, status, NULL, NULL);
+}
+
void
empathy_idle_set_presence (EmpathyIdle *idle,
- McPresence state,
+ TpConnectionPresenceType state,
const gchar *status)
{
EmpathyIdlePriv *priv;
if (tp_strdiff (priv->status, status)) {
g_free (priv->status);
priv->status = NULL;
- if (!G_STR_EMPTY (status)) {
+ if (!EMP_STR_EMPTY (status)) {
priv->status = g_strdup (status);
}
g_object_notify (G_OBJECT (idle), "status");
return;
}
- mission_control_set_presence (priv->mc, state, status, NULL, NULL);
+ empathy_idle_do_set_presence (idle, state, status);
}
gboolean
idle_nm_state_change_cb (priv->nm_proxy, nm_status, idle);
} else {
priv->nm_connected = TRUE;
- if (priv->nm_saved_state != MC_PRESENCE_UNSET) {
+ if (priv->nm_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
empathy_idle_set_state (idle, priv->nm_saved_state);
}
- priv->nm_saved_state = MC_PRESENCE_UNSET;
+ priv->nm_saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
}
g_object_notify (G_OBJECT (idle), "use-nm");