1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Gaal Yahas <gaal@forum2.org>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
17 jam_host_get_stock_icon(JamHost
*host
) {
18 return JAM_HOST_GET_CLASS(host
)->get_stock_icon();
22 jam_host_get_account_by_username(JamHost
*host
,
23 const char *username
, gboolean create
) {
24 JamAccount
*acc
= NULL
;
26 for (l
= host
->accounts
; l
!= NULL
; l
= l
->next
) {
28 if (strcmp(username
, jam_account_get_username(acc
)) == 0)
31 /* this is a previously-unknown account. */
33 return JAM_HOST_GET_CLASS(host
)->make_account(host
, username
);
39 jam_host_add_account(JamHost
*host
, JamAccount
*acc
) {
41 host
->accounts
= g_slist_append(host
->accounts
, acc
);
45 parseuserdir(const char *dirname
, void *host
) {
46 return conf_parsedirxml(dirname
, (conf_parsedirxml_fn
)jam_account_from_xml
, host
);
50 jam_host_from_xml(xmlDocPtr doc
, xmlNodePtr node
, void *data
) {
52 char *username
= NULL
;
56 xmlChar
*protocol
= xmlGetProp(node
, BAD_CAST
"protocol");
57 if (!protocol
|| xmlStrcmp(protocol
, BAD_CAST
"livejournal") == 0) {
58 host
= JAM_HOST(jam_host_lj_new(lj_server_new(NULL
)));
59 #ifdef blogger_punted_for_this_release
60 } else if (xmlStrcmp(protocol
, BAD_CAST
"blogger") == 0) {
61 host
= JAM_HOST(jam_host_blogger_new());
64 g_error("unknown protocol '%s'\n", protocol
);
66 if (protocol
) xmlFree(protocol
);
67 klass
= JAM_HOST_GET_CLASS(host
);
69 for (node
= node
->xmlChildrenNode
; node
!= NULL
; node
= node
->next
) {
70 XML_GET_STR("name", host
->name
)
71 XML_GET_STR("currentuser", username
)
72 XML_GET_SUB(host
, klass
->load_xml
)
73 XML_GET_END("jam_host_from_xml")
76 userspath
= g_build_filename(data
, "users", NULL
);
77 host
->accounts
= conf_parsedirlist(userspath
, parseuserdir
, host
);
80 /* after we've parsed all of the users, scan for the current one. */
82 host
->lastaccount
= jam_host_get_account_by_username(host
, username
, FALSE
);
90 jam_host_write(JamHost
*host
, GError
**err
) {
94 xmlNodePtr servernode
;
98 path
= g_build_filename(app
.conf_dir
, "servers", host
->name
, "conf.xml", NULL
);
99 if (!verify_path(path
, FALSE
, err
))
102 jam_xmlNewDoc(&doc
, &servernode
, "server");
104 xmlNewTextChild(servernode
, NULL
, BAD_CAST
"name", BAD_CAST host
->name
);
106 for (l
= host
->accounts
; l
!= NULL
; l
= l
->next
) {
107 JamAccount
*acc
= l
->data
;
108 if (!jam_account_write(acc
, &terr
)) {
109 g_printerr("Error writing account: %s\n", terr
->message
);
115 if (host
->lastaccount
)
116 xmlNewTextChild(servernode
, NULL
, BAD_CAST
"currentuser",
117 BAD_CAST
jam_account_get_username(host
->lastaccount
));
119 JAM_HOST_GET_CLASS(host
)->save_xml(host
, servernode
);
121 if (xmlSaveFormatFile(path
, doc
, TRUE
) < 0) {
122 g_set_error(err
, 0, 0, "xmlSaveFormatFile error saving to %s.\n", path
);
128 if (path
) g_free(path
);
129 if (doc
) xmlFreeDoc(doc
);
135 jam_host_get_type(void) {
136 static GType new_type
= 0;
138 const GTypeInfo new_info
= {
139 sizeof(JamHostClass
),
149 new_type
= g_type_register_static(G_TYPE_OBJECT
,
150 "JamHost", &new_info
, G_TYPE_FLAG_ABSTRACT
);
156 /* protocol functions. */
158 jam_host_do_post(JamHost
*host
, NetContext
*ctx
, void *doc
, GError
**err
) {
160 ctx
->title(ctx
, _("Submitting Entry"));
161 return JAM_HOST_GET_CLASS(host
)->do_post(host
, ctx
, doc
, err
);
165 jam_host_do_edit(JamHost
*host
, NetContext
*ctx
, void *doc
, GError
**err
) {
167 ctx
->title(ctx
, _("Saving Changes"));
168 return JAM_HOST_GET_CLASS(host
)->do_edit(host
, ctx
, doc
, err
);
172 jam_host_do_delete(JamHost
*host
, NetContext
*ctx
, void *doc
, GError
**err
) {
174 ctx
->title(ctx
, _("Deleting Entry"));
175 return JAM_HOST_GET_CLASS(host
)->do_delete(host
, ctx
, doc
, err
);