database.h 4.58 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
  char* first_page_column_list;
19 20
  double position_x;
  double position_y;
21 22
} zathura_fileinfo_t;

23
#define ZATHURA_TYPE_DATABASE \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
24
  (zathura_database_get_type())
25 26 27 28 29 30 31 32 33 34 35 36 37 38
#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
39
  /* interface methods */
40
  bool (*add_bookmark)(ZathuraDatabase* db, const char* file, zathura_bookmark_t* bookmark);
41

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

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

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

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

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

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

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

57
GType zathura_database_get_type(void) G_GNUC_CONST;
58

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

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

81 82
/**
 * Loads all bookmarks from the database belonging to a specific file.
Moritz Lipp's avatar
Moritz Lipp committed
83
 *
84 85 86 87
 * @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.
 */
88 89
girara_list_t* zathura_db_load_bookmarks(zathura_database_t* db, const char*
    file);
90

91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
/**
 * 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);

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

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

Sebastian Ramacher's avatar
Sebastian Ramacher committed
133 134 135 136
/* Get a list of recent files from the database. The most recent file is listed
 * first.
 *
 * @param db The database instance
137 138
 * @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
139 140
 * @return list of files
 */
141
girara_list_t* zathura_db_get_recent_files(zathura_database_t* db, int max, const char* basepath);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
142

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

Sebastian Ramacher's avatar
Sebastian Ramacher committed
149

150
#endif // DATABASE_H