database.h 4.61 KB
Newer Older
1 2 3 4 5 6
/* See LICENSE file for license and copyright information */

#ifndef DATABASE_H
#define DATABASE_H

#include <stdbool.h>
7
#include <girara/types.h>
8
#include <glib-object.h>
9 10 11

#include "bookmarks.h"

12 13 14
typedef struct zathura_fileinfo_s {
  unsigned int current_page;
  unsigned int page_offset;
15
  double zoom;
16
  unsigned int rotation;
17
  unsigned int pages_per_row;
18
  bool page_right_to_left;
19
  char* first_page_column_list;
20 21
  double position_x;
  double position_y;
22 23
} zathura_fileinfo_t;

24
#define ZATHURA_TYPE_DATABASE \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
25
  (zathura_database_get_type())
26 27 28 29 30 31 32 33 34 35 36 37 38 39
#define ZATHURA_DATABASE(obj) \
  (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZATHURA_TYPE_DATABASE, ZathuraDatabase))
#define ZATHURA_IS_DATABASE(obj) \
  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZATHURA_TYPE_DATABASE))
#define ZATHURA_DATABASE_GET_INTERFACE(obj) \
  (G_TYPE_INSTANCE_GET_INTERFACE ((obj), ZATHURA_TYPE_DATABASE, ZathuraDatabaseInterface))

typedef struct _ZathuraDatabase          ZathuraDatabase;
typedef struct _ZathuraDatabaseInterface ZathuraDatabaseInterface;

struct _ZathuraDatabaseInterface
{
  GTypeInterface parent_iface;

Sebastian Ramacher's avatar
Sebastian Ramacher committed
40
  /* interface methods */
41
  bool (*add_bookmark)(ZathuraDatabase* db, const char* file, zathura_bookmark_t* bookmark);
42

43
  bool (*remove_bookmark)(ZathuraDatabase* db, const char* file, const char* id);
44

45 46
  girara_list_t* (*load_bookmarks)(ZathuraDatabase* db, const char* file);

47 48 49 50
  girara_list_t* (*load_jumplist)(ZathuraDatabase* db, const char* file);

  bool (*save_jumplist)(ZathuraDatabase* db, const char* file, girara_list_t* jumplist);

51
  bool (*set_fileinfo)(ZathuraDatabase* db, const char* file, zathura_fileinfo_t* file_info);
52

53
  bool (*get_fileinfo)(ZathuraDatabase* db, const char* file, zathura_fileinfo_t* file_info);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
54

55
  girara_list_t* (*get_recent_files)(ZathuraDatabase* db, int max, const char* basepath);
56 57
};

58
GType zathura_database_get_type(void) G_GNUC_CONST;
59

60 61
/**
 * Add or update bookmark in the database.
Moritz Lipp's avatar
Moritz Lipp committed
62
 *
63
 * @param db The database instance
64
 * @param file The file to which the bookmark belongs.
65 66 67
 * @param bookmark The bookmark instance.
 * @return true on success, false otherwise
 */
68 69
bool zathura_db_add_bookmark(zathura_database_t* db, const char* file,
    zathura_bookmark_t* bookmark);
70

71
/**
72
 * Remove a bookmark from the database.
Moritz Lipp's avatar
Moritz Lipp committed
73
 *
74
 * @param db The database instance
75
 * @param file The file to which the bookmark belongs.
Moritz Lipp's avatar
Moritz Lipp committed
76
 * @param id The id of the bookmark
77 78
 * @return true on success, false otherwise
 */
79 80
bool zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const
    char* id);
81

82 83
/**
 * Loads all bookmarks from the database belonging to a specific file.
Moritz Lipp's avatar
Moritz Lipp committed
84
 *
85 86 87 88
 * @param db The database instance.
 * @param file The file for which the bookmarks should be loaded.
 * @return List of zathura_bookmark_t* or NULL on failure.
 */
89 90
girara_list_t* zathura_db_load_bookmarks(zathura_database_t* db, const char*
    file);
91

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
/**
 * Load the jumplist belonging to the specified file from the database.
 *
 * @param db The database instance.
 * @param file The file to which the jumplist belongs.
 *
 * return A linked list constituting the jumplist of the specified file.
 */
girara_list_t* zathura_db_load_jumplist(ZathuraDatabase* db, const char* file);

/**
 * Save the jumplist belonging to the specified file to the database.
 *
 * @param db The database instance.
 * @param file The file to which the jumplist belongs.
 * @param jumplist The jumplist to be saved
 *
 * return true on success, false otherwise.
 */
bool zathura_db_save_jumplist(ZathuraDatabase* db, const char* file, girara_list_t* jumplist);

113 114
/**
 * Set file info (last site, ...) in the database.
Moritz Lipp's avatar
Moritz Lipp committed
115
 *
116
 * @param db The database instance
117
 * @param file The file to which the file info belongs.
118
 * @param file_info The file info
119 120
 * @return true on success, false otherwise.
 */
121 122
bool zathura_db_set_fileinfo(zathura_database_t* db, const char* file,
    zathura_fileinfo_t* file_info);
123

124
/* Get file info (last site, ...) from the database.
Moritz Lipp's avatar
Moritz Lipp committed
125
 *
126
 * @param db The database instance
127
 * @param file The file to which the file info belongs.
128
 * @param file_info The file info
129 130
 * @return true on success, false otherwise.
 */
131 132
bool zathura_db_get_fileinfo(zathura_database_t* db, const char* file,
    zathura_fileinfo_t* file_info);
133

Sebastian Ramacher's avatar
Sebastian Ramacher committed
134 135 136 137
/* Get a list of recent files from the database. The most recent file is listed
 * first.
 *
 * @param db The database instance
138 139
 * @param max The maximum number of recent files. If max is less than zero, now
 * limit is applied.
Sebastian Ramacher's avatar
Sebastian Ramacher committed
140 141
 * @return list of files
 */
142
girara_list_t* zathura_db_get_recent_files(zathura_database_t* db, int max, const char* basepath);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
143

144 145 146 147 148 149
/**
 * Create list of bookmarks.
 * @return empty list of bookmarks
 */
girara_list_t* bookmarks_list_new(void);

Sebastian Ramacher's avatar
Sebastian Ramacher committed
150

151
#endif // DATABASE_H