1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
22 #include "draftstore.h"
31 draft_store_each_header(DraftStore
*ds
, LJEntry
*entry
,
32 DraftStoreHeaderFunc func
, gpointer data
) {
38 dir
= g_dir_open(ds
->path
, 0, NULL
);
42 for (filename
= g_dir_read_name(dir
);
44 filename
= g_dir_read_name(dir
)) {
45 path
= g_build_filename(ds
->path
, filename
, NULL
);
46 e
= lj_entry_new_from_filename(path
, LJ_ENTRY_FILE_XML
, NULL
, NULL
);
47 if (e
&& e
->time
.tm_year
== 0) {
50 e
->time
= *localtime(&statbuf
.st_mtime
);
55 entry
->itemid
= e
->itemid
;
56 entry
->subject
= e
->subject
; e
->subject
= NULL
;
57 entry
->security
= e
->security
;
58 entry
->time
= e
->time
;
60 func(ds
, entry
, data
);
61 g_free(entry
->subject
);
63 entry
->subject
= NULL
;
70 draft_store_make_path(DraftStore
*ds
, int itemid
) {
71 char *filename
, *path
;
72 filename
= g_strdup_printf("%d", -itemid
);
73 path
= g_build_filename(ds
->path
, filename
, NULL
);
79 draft_store_get_entry(DraftStore
*ds
, int itemid
, GError
**err
) {
82 path
= draft_store_make_path(ds
, itemid
);
83 e
= lj_entry_new_from_filename(path
, LJ_ENTRY_FILE_XML
, NULL
, NULL
);
89 draft_store_put_entry(DraftStore
*ds
, LJEntry
*entry
, GError
**err
) {
92 if (!verify_path(ds
->path
, TRUE
, err
))
94 path
= draft_store_make_path(ds
, entry
->itemid
);
95 ret
= lj_entry_to_xml_file(entry
, path
, NULL
);
101 draft_store_remove_entry(DraftStore
*ds
, int itemid
, GError
**err
) {
103 path
= draft_store_make_path(ds
, itemid
);
104 if (unlink(path
) < 0)
110 draft_store_find_itemid(DraftStore
*ds
) {
116 pathlen
= strlen(ds
->path
);
117 pathbuf
= g_new0(char, pathlen
+5);
118 strcpy(pathbuf
, ds
->path
);
119 for (itemid
= 1; itemid
< 100; itemid
++) {
120 g_snprintf(pathbuf
+pathlen
, 5, "/%d", itemid
);
121 if (stat(pathbuf
, &statbuf
) < 0 && errno
== ENOENT
) {
132 draft_store_new(JamAccount
*acc
) {
135 ds
= g_new0(DraftStore
, 1);
136 ds
->path
= conf_make_account_path(acc
, "drafts");
142 draft_store_free(DraftStore
*ds
) {