progress.*: cosmetix
[k8lowj.git] / src / journalstore.c
blob9c575b8fc301035dc4dabc719e55197bdbc49a70
1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
3 */
4 #include "glib-all.h"
6 #include <errno.h>
8 #include "conf.h"
9 #include "journalstore.h"
12 gboolean journal_store_find_relative (JournalStore *js, gint itemid, int *ritemid, int dir, GError *err) {
13 time_t when = journal_store_lookup_entry_time(js, itemid);
14 return journal_store_find_relative_by_time(js, when, ritemid, dir, err);
18 char *journal_store_get_lastsync (JournalStore *js) {
19 char *filename;
20 char *sync = NULL;
21 if (journal_store_get_invalid(js)) {
22 /* the journalstore was invalid; we need to resync. */
23 return NULL;
25 filename = conf_make_account_path(journal_store_get_account(js), "lastsync");
26 if (g_file_get_contents(filename, &sync, NULL, NULL)) {
27 g_strchomp(sync);
28 } else {
29 sync = NULL;
31 g_free(filename);
32 return sync;
36 gboolean journal_store_put_lastsync (JournalStore *js, const char *lastsync, GError **err) {
37 char *filename = conf_make_account_path(journal_store_get_account(js), "lastsync");
38 FILE *f = fopen(filename, "w");
39 if (f == NULL) {
40 g_set_error(err, 0, 0, _("Can't open '%s': %s"), filename, g_strerror(errno));
41 g_free(filename);
42 return FALSE;
44 fprintf(f, "%s\n", lastsync);
45 fclose(f);
46 g_free(filename);
47 return TRUE;