Skip to content

Commit 7c95917

Browse files
committed
Add bookmark wrapper.
1 parent 06638d4 commit 7c95917

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed

lib/src/main/cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ add_library(
5050
libkiwix/kiwixicu.cpp
5151
libkiwix/kiwixserver.cpp
5252
libkiwix/library.cpp
53+
libkiwix/bookmark.cpp
5354
libkiwix/manager.cpp
5455
libkiwix/illustration.cpp
5556
)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (C) 2020 Matthieu Gautier <mgautier@kymeria.fr>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
20+
21+
#include <jni.h>
22+
#include "org_kiwix_libkiwix_Bookmark.h"
23+
24+
#include "utils.h"
25+
#include "bookmark.h"
26+
27+
#define NATIVE_TYPE kiwix::Bookmark
28+
#define TYPENAME libkiwix_Bookmark
29+
#include <macros.h>
30+
31+
METHOD0(void, setNativeBookmark)
32+
{
33+
SET_PTR(std::make_shared<NATIVE_TYPE>());
34+
}
35+
36+
DISPOSE
37+
38+
GETTER(jstring, getBookId)
39+
40+
GETTER(jstring, getBookTitle)
41+
42+
GETTER(jstring, getUrl)
43+
44+
GETTER(jstring, getTitle)
45+
46+
GETTER(jstring, getLanguage)
47+
48+
GETTER(jstring, getDate)
49+
50+
METHOD(void, setBookId, jstring bookId) {
51+
THIS->setBookId(TO_C(bookId));
52+
}
53+
54+
METHOD(void, setBookTitle, jstring bookTitle) {
55+
THIS->setBookTitle(TO_C(bookTitle));
56+
}
57+
58+
METHOD(void, setUrl, jstring url) {
59+
THIS->setUrl(TO_C(url));
60+
}
61+
62+
METHOD(void, setTitle, jstring title) {
63+
THIS->setTitle(TO_C(title));
64+
}
65+
66+
METHOD(void, setLanguage, jstring lang) {
67+
THIS->setLanguage(TO_C(lang));
68+
}
69+
70+
METHOD(void, setDate, jstring date) {
71+
THIS->setDate(TO_C(date));
72+
}

lib/src/main/cpp/libkiwix/library.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ METHOD(jboolean, removeBookById, jstring id) {
6464
METHOD(jboolean, writeToFile, jstring path) {
6565
return TO_JNI(THIS->writeToFile(TO_C(path)));
6666
}
67+
METHOD(jboolean, writeBookmarksToFile, jstring path) {
68+
return TO_JNI(THIS->writeBookmarksToFile(TO_C(path)));
69+
}
6770

6871
METHOD(jint, getBookCount, jboolean localBooks, jboolean remoteBooks) {
6972
return TO_JNI(THIS->getBookCount(TO_C(localBooks), TO_C(remoteBooks)));
@@ -80,3 +83,23 @@ GETTER(jobjectArray, getBooksLanguages)
8083
GETTER(jobjectArray, getBooksCategories)
8184
GETTER(jobjectArray, getBooksCreators)
8285
GETTER(jobjectArray, getBooksPublishers)
86+
87+
METHOD(void, addBookmark, jobject bookmark) {
88+
auto cBookmark = getPtr<kiwix::Bookmark>(env, bookmark);
89+
THIS->addBookmark(*cBookmark);
90+
}
91+
92+
METHOD(jboolean, removeBookmark, jstring zimId, jstring url) {
93+
return TO_JNI(THIS->removeBookmark(TO_C(zimId), TO_C(url)));
94+
}
95+
96+
METHOD(jobjectArray, getBookmarks, jboolean onlyValidBookmarks) {
97+
auto bookmarks = THIS->getBookmarks(TO_C(onlyValidBookmarks));
98+
jobjectArray retArray = createArray(env, bookmarks.size(), "org/kiwix/libkiwix/Bookmark");
99+
size_t index = 0;
100+
for (auto bookmark: bookmarks) {
101+
auto wrapper = BUILD_WRAPPER("org/kiwix/libkiwx/Bookmark", bookmark);
102+
env->SetObjectArrayElement(retArray, index++, wrapper);
103+
}
104+
return retArray;
105+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
20+
package org.kiwix.libkiwix;
21+
22+
public class Bookmark
23+
{
24+
public Bookmark() {
25+
setNativeBookmark();
26+
}
27+
28+
public native void setBookId(String bookId);
29+
public native void setBookTitle(String bookTitle);
30+
public native void setUrl(String url);
31+
public native void setTitle(String title);
32+
public native void setLanguage(String language);
33+
public native void setDate(String Date);
34+
35+
public native String getBookId();
36+
public native String getBookTitle();
37+
public native String getUrl();
38+
public native String getTitle();
39+
public native String getLanguage();
40+
public native String getDate();
41+
42+
@Override
43+
protected void finalize() { dispose(); }
44+
45+
46+
///--------- The wrapper thing
47+
// To delete our native wrapper
48+
public native void dispose();
49+
50+
// A pointer (as a long) to a native Handle
51+
private native void setNativeBookmark();
52+
private long nativeHandle;
53+
}

lib/src/main/java/org/kiwix/libkiwix/Library.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.kiwix.libzim.Searcher;
2424
import org.kiwix.libkiwix.Book;
2525
import org.kiwix.libkiwix.JNIKiwixException;
26+
import org.kiwix.libkiwix.Bookmark;
2627

2728
public class Library
2829
{
@@ -41,6 +42,7 @@ public Library()
4142
public native boolean removeBookById(String id);
4243

4344
public native boolean writeToFile(String path);
45+
public native boolean writeBookmarksToFile(String path);
4446

4547
public native int getBookCount(boolean localBooks, boolean remoteBooks);
4648

@@ -52,6 +54,10 @@ public Library()
5254
public native String[] getBooksCreators();
5355
public native String[] getBooksPublishers();
5456

57+
public native void addBookmark(Bookmark bookmark);
58+
public native boolean removeBookmark(String zimId, String url);
59+
public native Bookmark[] getBookmarks(boolean onlyValidBookmarks);
60+
5561
@Override
5662
protected void finalize() { dispose(); }
5763
private native void setNativeHandler();

0 commit comments

Comments
 (0)