1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
$NetBSD: patch-ad,v 1.1 2009/09/03 01:29:34 joerg Exp $
--- src/gbemol-mpd.c.orig 2009-04-25 04:38:51.000000000 +0200
+++ src/gbemol-mpd.c
@@ -2,6 +2,7 @@
#include "gbemol-mpd.h"
#include "gbemol-marshal.h"
+#include "gbemol-utils.h"
/* Properties */
enum {
@@ -454,51 +455,31 @@ gboolean gbemol_mpd_connect (GbemolMpd*
obj->priv->conn = mpd_newConnection (obj->priv->host, obj->priv->port, obj->priv->timeout);
if (gbemol_mpd_finish_and_handle (obj))
- obj->priv->connected = FALSE;
- else
- {
- gbemol_mpd_get_not_commands_list (obj);
- if (obj->status)
- mpd_freeStatus (obj->status);
- obj->status = gbemol_mpd_get_status (obj);
- obj->priv->connected = TRUE;
- /* Emit a song-changed signal */
- g_signal_emit (obj, gbemol_mpd_signals [SONG_CHANGED_SIGNAL], 0, NULL);
- }
-
- return obj->priv->connected;
-}
-
-/* Connect */
-gboolean gbemol_mpd_connect_and_authenticate (GbemolMpd* obj)
-{
- if (obj->priv->conn)
- mpd_closeConnection (obj->priv->conn);
-
- obj->priv->conn = mpd_newConnection (obj->priv->host, obj->priv->port, obj->priv->timeout);
-
- if (gbemol_mpd_finish_and_handle (obj))
{
obj->priv->connected = FALSE;
return FALSE;
}
- else
- obj->priv->connected = TRUE;
- /* Not authenticated, yet connected, so return TRUE, but mark as disconnected */
- if (!gbemol_mpd_authenticate (obj))
- obj->priv->connected = FALSE;
- else
+ if (gbemol_cfg_get_bool("mpd", "use_auth"))
{
- gbemol_mpd_get_not_commands_list (obj);
- if (obj->status)
- mpd_freeStatus (obj->status);
- obj->status = gbemol_mpd_get_status (obj);
- /* Emit a song-changed signal */
- g_signal_emit (obj, gbemol_mpd_signals [SONG_CHANGED_SIGNAL], 0, NULL);
+ if (!obj->priv->pass)
+ obj->priv->pass = gbemol_cfg_get_string("mpd", "pass");
+ if (!obj->priv->pass || !gbemol_mpd_authenticate (obj))
+ {
+ obj->priv->connected = FALSE;
+ return FALSE;
+ }
}
- return TRUE;
+ gbemol_mpd_get_not_commands_list (obj);
+ if (obj->status)
+ mpd_freeStatus (obj->status);
+ obj->status = gbemol_mpd_get_status (obj);
+ obj->priv->connected = TRUE;
+ /* Emit a song-changed signal */
+ g_signal_emit (obj, gbemol_mpd_signals [SONG_CHANGED_SIGNAL], 0, NULL);
+
+ return obj->priv->connected;
}
void gbemol_mpd_disconnect (GbemolMpd *obj)
|