aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--data/empathy.schemas.in15
-rw-r--r--libempathy-gtk/empathy-preferences.c6
-rw-r--r--libempathy-gtk/empathy-preferences.glade50
-rw-r--r--libempathy-gtk/empathy-preferences.h1
-rw-r--r--libempathy-gtk/empathy-status-icon.c30
-rw-r--r--libempathy/empathy-idle.c149
-rw-r--r--libempathy/empathy-idle.h6
8 files changed, 179 insertions, 89 deletions
diff --git a/ChangeLog b/ChangeLog
index 1976f8f01..178e9afa8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-12-06 Xavier Claessens <xclaesse@gmail.com>
+
+ * data/empathy.schemas.in:
+ * libempathy-gtk/empathy-preferences.c:
+ * libempathy-gtk/empathy-preferences.glade:
+ * libempathy-gtk/empathy-preferences.h:
+ * libempathy-gtk/empathy-status-icon.c:
+ * libempathy/empathy-idle.c:
+ * libempathy/empathy-idle.h: Add a preference option to disable/enable
+ NM support.
+
2007-12-05 Xavier Claessens <xclaesse@gmail.com>
* libempathy-gtk/empathy-contact-list-view.c:
diff --git a/data/empathy.schemas.in b/data/empathy.schemas.in
index 72ee4405e..732464867 100644
--- a/data/empathy.schemas.in
+++ b/data/empathy.schemas.in
@@ -276,6 +276,21 @@
</locale>
</schema>
+ <schema>
+ <key>/schemas/apps/empathy/use_nm</key>
+ <applyto>/apps/empathy/use_nm</applyto>
+ <owner>empathy</owner>
+ <type>bool</type>
+ <default>true</default>
+ <locale name="C">
+ <short>Checks if NetworkManager should be used</short>
+ <long>
+ Whether or not the network manager should be used to automatically
+ disconnect/reconnect.
+ </long>
+ </locale>
+ </schema>
+
</schemalist>
</gconfschemafile>
diff --git a/libempathy-gtk/empathy-preferences.c b/libempathy-gtk/empathy-preferences.c
index a8b52954d..14ee8f763 100644
--- a/libempathy-gtk/empathy-preferences.c
+++ b/libempathy-gtk/empathy-preferences.c
@@ -50,6 +50,7 @@ typedef struct {
GtkWidget *combobox_chat_theme;
GtkWidget *checkbutton_theme_chat_room;
GtkWidget *checkbutton_separate_chat_windows;
+ GtkWidget *checkbutton_use_nm;
GtkWidget *radiobutton_contact_list_sort_by_name;
GtkWidget *radiobutton_contact_list_sort_by_state;
@@ -178,6 +179,10 @@ preferences_setup_widgets (EmpathyPreferences *preferences)
preferences->checkbutton_separate_chat_windows);
preferences_hookup_toggle_button (preferences,
+ EMPATHY_PREFS_USE_NM,
+ preferences->checkbutton_use_nm);
+
+ preferences_hookup_toggle_button (preferences,
EMPATHY_PREFS_UI_SHOW_AVATARS,
preferences->checkbutton_show_avatars);
@@ -939,6 +944,7 @@ empathy_preferences_show (GtkWindow *parent)
"combobox_chat_theme", &preferences->combobox_chat_theme,
"checkbutton_theme_chat_room", &preferences->checkbutton_theme_chat_room,
"checkbutton_separate_chat_windows", &preferences->checkbutton_separate_chat_windows,
+ "checkbutton_use_nm", &preferences->checkbutton_use_nm,
"radiobutton_contact_list_sort_by_name", &preferences->radiobutton_contact_list_sort_by_name,
"radiobutton_contact_list_sort_by_state", &preferences->radiobutton_contact_list_sort_by_state,
"checkbutton_sounds_for_messages", &preferences->checkbutton_sounds_for_messages,
diff --git a/libempathy-gtk/empathy-preferences.glade b/libempathy-gtk/empathy-preferences.glade
index 73cb66d5f..5c3321197 100644
--- a/libempathy-gtk/empathy-preferences.glade
+++ b/libempathy-gtk/empathy-preferences.glade
@@ -209,16 +209,48 @@
<property name="right_padding">0</property>
<child>
- <widget class="GtkCheckButton" id="checkbutton_separate_chat_windows">
+ <widget class="GtkVBox" id="vbox218">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">_Open new chats in separate windows</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">False</property>
- <property name="inconsistent">False</property>
- <property name="draw_indicator">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkCheckButton" id="checkbutton_separate_chat_windows">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">_Open new chats in separate windows</property>
+ <property name="use_underline">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ <property name="active">False</property>
+ <property name="inconsistent">False</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkCheckButton" id="checkbutton_use_nm">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">_Use network manager</property>
+ <property name="use_underline">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ <property name="active">False</property>
+ <property name="inconsistent">False</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
</widget>
</child>
</widget>
diff --git a/libempathy-gtk/empathy-preferences.h b/libempathy-gtk/empathy-preferences.h
index 39c2994c1..e4cf122bc 100644
--- a/libempathy-gtk/empathy-preferences.h
+++ b/libempathy-gtk/empathy-preferences.h
@@ -50,6 +50,7 @@ G_BEGIN_DECLS
#define EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM EMPATHY_PREFS_PATH "/contacts/sort_criterium"
#define EMPATHY_PREFS_HINTS_CLOSE_MAIN_WINDOW EMPATHY_PREFS_PATH "/hints/close_main_window"
#define EMPATHY_PREFS_SALUT_ACCOUNT_CREATED EMPATHY_PREFS_PATH "/accounts/salut_created"
+#define EMPATHY_PREFS_USE_NM EMPATHY_PREFS_PATH "/use_nm"
GtkWidget * empathy_preferences_show (GtkWindow *parent);
diff --git a/libempathy-gtk/empathy-status-icon.c b/libempathy-gtk/empathy-status-icon.c
index 4421ddc85..cca41d5dd 100644
--- a/libempathy-gtk/empathy-status-icon.c
+++ b/libempathy-gtk/empathy-status-icon.c
@@ -140,6 +140,19 @@ static void status_icon_event_free (StatusIconEvent *event
G_DEFINE_TYPE (EmpathyStatusIcon, empathy_status_icon, G_TYPE_OBJECT);
static void
+status_icon_notify_use_nm_cb (EmpathyConf *conf,
+ const gchar *key,
+ gpointer user_data)
+{
+ EmpathyStatusIconPriv *priv = GET_PRIV (user_data);
+ gboolean use_nm;
+
+ if (empathy_conf_get_bool (conf, key, &use_nm)) {
+ empathy_idle_set_use_nm (priv->idle, use_nm);
+ }
+}
+
+static void
empathy_status_icon_class_init (EmpathyStatusIconClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -154,13 +167,11 @@ empathy_status_icon_init (EmpathyStatusIcon *icon)
{
EmpathyStatusIconPriv *priv;
GList *pendings, *l;
+ gboolean use_nm;
priv = GET_PRIV (icon);
priv->icon = gtk_status_icon_new ();
- priv->idle = empathy_idle_new ();
- empathy_idle_set_auto_away (priv->idle, TRUE);
- empathy_idle_set_auto_disconnect (priv->idle, TRUE);
priv->manager = empathy_contact_manager_new ();
priv->mc = empathy_mission_control_new ();
priv->text_filter = empathy_filter_new ("org.gnome.Empathy.ChatFilter",
@@ -169,6 +180,19 @@ empathy_status_icon_init (EmpathyStatusIcon *icon)
MC_FILTER_PRIORITY_DIALOG,
MC_FILTER_FLAG_INCOMING);
+ /* Setup EmpathyIdle */
+ priv->idle = empathy_idle_new ();
+ empathy_conf_get_bool (empathy_conf_get (),
+ EMPATHY_PREFS_USE_NM,
+ &use_nm);
+ empathy_conf_notify_add (empathy_conf_get (),
+ EMPATHY_PREFS_USE_NM,
+ status_icon_notify_use_nm_cb,
+ icon);
+ empathy_idle_set_auto_away (priv->idle, TRUE);
+ empathy_idle_set_use_nm (priv->idle, use_nm);
+
+
status_icon_create_menu (icon);
status_icon_idle_notify_cb (icon);
diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c
index da04b57fc..10d5b7bde 100644
--- a/libempathy/empathy-idle.c
+++ b/libempathy/empathy-idle.c
@@ -53,15 +53,18 @@ struct _EmpathyIdlePriv {
MissionControl *mc;
DBusGProxy *gs_proxy;
DBusGProxy *nm_proxy;
+
McPresence state;
- McPresence flash_state;
gchar *status;
- McPresence saved_state;
- gchar *saved_status;
+ McPresence flash_state;
+ gboolean auto_away;
+ gboolean use_nm;
+
+ McPresence away_saved_state;
+ McPresence nm_saved_state;
+
gboolean is_idle;
gboolean nm_connected;
- gboolean auto_away;
- gboolean auto_disconnect;
guint ext_away_timeout;
};
@@ -95,7 +98,7 @@ enum {
PROP_STATUS,
PROP_FLASH_STATE,
PROP_AUTO_AWAY,
- PROP_AUTO_DISCONNECT
+ PROP_USE_NM
};
G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT)
@@ -142,10 +145,10 @@ empathy_idle_class_init (EmpathyIdleClass *klass)
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
- PROP_AUTO_DISCONNECT,
- g_param_spec_boolean ("auto-disconnect",
- "Automatic set presence to offline",
- "Should it set presence to offline if NM is disconnected",
+ PROP_USE_NM,
+ g_param_spec_boolean ("use-nm",
+ "Use Network Manager",
+ "Set presence according to Network Manager",
FALSE,
G_PARAM_READWRITE));
@@ -198,39 +201,11 @@ empathy_idle_init (EmpathyIdle *idle)
"org.freedesktop.NetworkManager");
}
if (priv->nm_proxy) {
- guint nm_status;
-
dbus_g_proxy_add_signal (priv->nm_proxy, "StateChange",
G_TYPE_UINT, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->nm_proxy, "StateChange",
G_CALLBACK (idle_nm_state_change_cb),
idle, NULL);
- dbus_g_proxy_call (priv->nm_proxy, "state",
- &error,
- G_TYPE_INVALID,
- G_TYPE_UINT, &nm_status,
- G_TYPE_INVALID);
-
- if (error) {
- /* Can't get actual status, NM is not working. */
- empathy_debug (DEBUG_DOMAIN,
- "Couldn't get NM state: %s",
- error->message);
- g_clear_error (&error);
- g_object_unref (priv->nm_proxy);
- priv->nm_proxy = NULL;
- priv->nm_connected = TRUE;
- } else {
- priv->nm_connected = (nm_status == NM_STATE_CONNECTED);
-
- empathy_debug (DEBUG_DOMAIN, "NetworkManager connected: %s",
- priv->nm_connected ? "Yes" : "No");
- }
-
- if (!priv->nm_connected) {
- priv->saved_state = priv->state;
- priv->saved_status = g_strdup (priv->status);
- }
} else {
empathy_debug (DEBUG_DOMAIN, "Failed to get nm proxy");
priv->nm_connected = TRUE;
@@ -245,7 +220,6 @@ idle_finalize (GObject *object)
priv = GET_PRIV (object);
g_free (priv->status);
- g_free (priv->saved_status);
g_object_unref (priv->mc);
if (priv->gs_proxy) {
@@ -280,8 +254,8 @@ idle_get_property (GObject *object,
case PROP_AUTO_AWAY:
g_value_set_boolean (value, empathy_idle_get_auto_away (idle));
break;
- case PROP_AUTO_DISCONNECT:
- g_value_set_boolean (value, empathy_idle_get_auto_disconnect (idle));
+ case PROP_USE_NM:
+ g_value_set_boolean (value, empathy_idle_get_use_nm (idle));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -314,6 +288,9 @@ idle_set_property (GObject *object,
case PROP_AUTO_AWAY:
empathy_idle_set_auto_away (idle, g_value_get_boolean (value));
break;
+ case PROP_USE_NM:
+ empathy_idle_set_use_nm (idle, g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -421,12 +398,7 @@ empathy_idle_set_presence (EmpathyIdle *idle,
status, state);
if (!priv->nm_connected) {
- empathy_debug (DEBUG_DOMAIN,
- "NM not connected, saving requested presence");
-
- g_free (priv->saved_status);
- priv->saved_state = state;
- priv->saved_status = g_strdup (status);
+ empathy_debug (DEBUG_DOMAIN, "NM not connected");
return;
}
@@ -462,22 +434,53 @@ empathy_idle_set_auto_away (EmpathyIdle *idle,
}
gboolean
-empathy_idle_get_auto_disconnect (EmpathyIdle *idle)
+empathy_idle_get_use_nm (EmpathyIdle *idle)
{
EmpathyIdlePriv *priv = GET_PRIV (idle);
- return priv->auto_disconnect;
+ return priv->use_nm;
}
void
-empathy_idle_set_auto_disconnect (EmpathyIdle *idle,
- gboolean auto_disconnect)
+empathy_idle_set_use_nm (EmpathyIdle *idle,
+ gboolean use_nm)
{
EmpathyIdlePriv *priv = GET_PRIV (idle);
- priv->auto_disconnect = auto_disconnect;
+ if (!priv->nm_proxy || use_nm == priv->use_nm) {
+ return;
+ }
+
+ priv->use_nm = use_nm;
- g_object_notify (G_OBJECT (idle), "auto-disconnect");
+ if (use_nm) {
+ guint nm_status;
+ GError *error = NULL;
+
+ dbus_g_proxy_call (priv->nm_proxy, "state",
+ &error,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &nm_status,
+ G_TYPE_INVALID);
+
+ if (error) {
+ empathy_debug (DEBUG_DOMAIN,
+ "Couldn't get NM state: %s",
+ error->message);
+ g_clear_error (&error);
+ nm_status = NM_STATE_CONNECTED;
+ }
+
+ idle_nm_state_change_cb (priv->nm_proxy, nm_status, idle);
+ } else {
+ if (!priv->nm_connected) {
+ empathy_idle_set_state (idle, priv->nm_saved_state);
+ }
+ priv->nm_connected = TRUE;
+ priv->nm_saved_state = MC_PRESENCE_UNSET;
+ }
+
+ g_object_notify (G_OBJECT (idle), "use-nm");
}
static void
@@ -529,16 +532,14 @@ idle_session_idle_changed_cb (DBusGProxy *gs_proxy,
/* We are now idle */
if (priv->state == MC_PRESENCE_AWAY ||
- priv->state == MC_PRESENCE_EXTENDED_AWAY) {
+ priv->state == MC_PRESENCE_EXTENDED_AWAY) {
/* User set away manually, when coming back we restore
* default presence. */
new_state = priv->state;
- priv->saved_state = MC_PRESENCE_AVAILABLE;
- priv->saved_status = NULL;
+ priv->away_saved_state = MC_PRESENCE_AVAILABLE;
} else {
new_state = MC_PRESENCE_AWAY;
- priv->saved_state = priv->state;
- priv->saved_status = g_strdup (priv->status);
+ priv->away_saved_state = priv->state;
}
empathy_debug (DEBUG_DOMAIN, "Going to autoaway");
@@ -549,16 +550,18 @@ idle_session_idle_changed_cb (DBusGProxy *gs_proxy,
/* We are no more idle, restore state */
idle_ext_away_stop (idle);
- empathy_debug (DEBUG_DOMAIN, "Restoring state to %d %s",
- priv->saved_state,
- priv->saved_status);
+ empathy_debug (DEBUG_DOMAIN, "Restoring state to %d",
+ priv->away_saved_state);
- empathy_idle_set_presence (idle,
- priv->saved_state,
- priv->saved_status);
+ if (priv->nm_connected) {
+ empathy_idle_set_state (idle, priv->away_saved_state);
+ } else {
+ /* We can't restore state now, will do when NM gets
+ * connected. */
+ priv->nm_saved_state = priv->away_saved_state;
+ }
- g_free (priv->saved_status);
- priv->saved_status = NULL;
+ priv->away_saved_state = MC_PRESENCE_UNSET;
}
priv->is_idle = is_idle;
@@ -573,18 +576,17 @@ idle_nm_state_change_cb (DBusGProxy *proxy,
priv = GET_PRIV (idle);
- empathy_debug (DEBUG_DOMAIN, "New network state (%d)", state);
+ empathy_debug (DEBUG_DOMAIN, "New network state (%d), in use = %s",
+ state, priv->use_nm ? "Yes" : "No");
- if (!priv->auto_disconnect) {
+ if (!priv->use_nm) {
return;
}
if (state != NM_STATE_CONNECTED && priv->nm_connected) {
/* We are no more connected */
idle_ext_away_stop (idle);
- g_free (priv->saved_status);
- priv->saved_state = priv->state;
- priv->saved_status = g_strdup (priv->status);
+ priv->nm_saved_state = priv->state;
empathy_idle_set_state (idle, MC_PRESENCE_OFFLINE);
priv->nm_connected = FALSE;
@@ -592,9 +594,8 @@ idle_nm_state_change_cb (DBusGProxy *proxy,
else if (state == NM_STATE_CONNECTED && !priv->nm_connected) {
/* We are now connected */
priv->nm_connected = TRUE;
- empathy_idle_set_presence (idle,
- priv->saved_state,
- priv->saved_status);
+ empathy_idle_set_state (idle, priv->nm_saved_state);
+ priv->nm_saved_state = MC_PRESENCE_UNSET;
}
}
diff --git a/libempathy/empathy-idle.h b/libempathy/empathy-idle.h
index ee9faacc5..cccd8b68e 100644
--- a/libempathy/empathy-idle.h
+++ b/libempathy/empathy-idle.h
@@ -64,9 +64,9 @@ void empathy_idle_set_presence (EmpathyIdle *idle,
gboolean empathy_idle_get_auto_away (EmpathyIdle *idle);
void empathy_idle_set_auto_away (EmpathyIdle *idle,
gboolean auto_away);
-gboolean empathy_idle_get_auto_disconnect (EmpathyIdle *idle);
-void empathy_idle_set_auto_disconnect (EmpathyIdle *idle,
- gboolean auto_disconnect);
+gboolean empathy_idle_get_use_nm (EmpathyIdle *idle);
+void empathy_idle_set_use_nm (EmpathyIdle *idle,
+ gboolean use_nm);
G_END_DECLS