mirror of
https://github.com/kiwix/java-libkiwix.git
synced 2025-09-11 08:08:46 -04:00
Add bookmark wrapper.
This commit is contained in:
parent
06638d46b8
commit
7c95917a52
@ -50,6 +50,7 @@ add_library(
|
|||||||
libkiwix/kiwixicu.cpp
|
libkiwix/kiwixicu.cpp
|
||||||
libkiwix/kiwixserver.cpp
|
libkiwix/kiwixserver.cpp
|
||||||
libkiwix/library.cpp
|
libkiwix/library.cpp
|
||||||
|
libkiwix/bookmark.cpp
|
||||||
libkiwix/manager.cpp
|
libkiwix/manager.cpp
|
||||||
libkiwix/illustration.cpp
|
libkiwix/illustration.cpp
|
||||||
)
|
)
|
||||||
|
72
lib/src/main/cpp/libkiwix/bookmark.cpp
Normal file
72
lib/src/main/cpp/libkiwix/bookmark.cpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Matthieu Gautier <mgautier@kymeria.fr>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
#include "org_kiwix_libkiwix_Bookmark.h"
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
#include "bookmark.h"
|
||||||
|
|
||||||
|
#define NATIVE_TYPE kiwix::Bookmark
|
||||||
|
#define TYPENAME libkiwix_Bookmark
|
||||||
|
#include <macros.h>
|
||||||
|
|
||||||
|
METHOD0(void, setNativeBookmark)
|
||||||
|
{
|
||||||
|
SET_PTR(std::make_shared<NATIVE_TYPE>());
|
||||||
|
}
|
||||||
|
|
||||||
|
DISPOSE
|
||||||
|
|
||||||
|
GETTER(jstring, getBookId)
|
||||||
|
|
||||||
|
GETTER(jstring, getBookTitle)
|
||||||
|
|
||||||
|
GETTER(jstring, getUrl)
|
||||||
|
|
||||||
|
GETTER(jstring, getTitle)
|
||||||
|
|
||||||
|
GETTER(jstring, getLanguage)
|
||||||
|
|
||||||
|
GETTER(jstring, getDate)
|
||||||
|
|
||||||
|
METHOD(void, setBookId, jstring bookId) {
|
||||||
|
THIS->setBookId(TO_C(bookId));
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(void, setBookTitle, jstring bookTitle) {
|
||||||
|
THIS->setBookTitle(TO_C(bookTitle));
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(void, setUrl, jstring url) {
|
||||||
|
THIS->setUrl(TO_C(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(void, setTitle, jstring title) {
|
||||||
|
THIS->setTitle(TO_C(title));
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(void, setLanguage, jstring lang) {
|
||||||
|
THIS->setLanguage(TO_C(lang));
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(void, setDate, jstring date) {
|
||||||
|
THIS->setDate(TO_C(date));
|
||||||
|
}
|
@ -64,6 +64,9 @@ METHOD(jboolean, removeBookById, jstring id) {
|
|||||||
METHOD(jboolean, writeToFile, jstring path) {
|
METHOD(jboolean, writeToFile, jstring path) {
|
||||||
return TO_JNI(THIS->writeToFile(TO_C(path)));
|
return TO_JNI(THIS->writeToFile(TO_C(path)));
|
||||||
}
|
}
|
||||||
|
METHOD(jboolean, writeBookmarksToFile, jstring path) {
|
||||||
|
return TO_JNI(THIS->writeBookmarksToFile(TO_C(path)));
|
||||||
|
}
|
||||||
|
|
||||||
METHOD(jint, getBookCount, jboolean localBooks, jboolean remoteBooks) {
|
METHOD(jint, getBookCount, jboolean localBooks, jboolean remoteBooks) {
|
||||||
return TO_JNI(THIS->getBookCount(TO_C(localBooks), TO_C(remoteBooks)));
|
return TO_JNI(THIS->getBookCount(TO_C(localBooks), TO_C(remoteBooks)));
|
||||||
@ -80,3 +83,23 @@ GETTER(jobjectArray, getBooksLanguages)
|
|||||||
GETTER(jobjectArray, getBooksCategories)
|
GETTER(jobjectArray, getBooksCategories)
|
||||||
GETTER(jobjectArray, getBooksCreators)
|
GETTER(jobjectArray, getBooksCreators)
|
||||||
GETTER(jobjectArray, getBooksPublishers)
|
GETTER(jobjectArray, getBooksPublishers)
|
||||||
|
|
||||||
|
METHOD(void, addBookmark, jobject bookmark) {
|
||||||
|
auto cBookmark = getPtr<kiwix::Bookmark>(env, bookmark);
|
||||||
|
THIS->addBookmark(*cBookmark);
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(jboolean, removeBookmark, jstring zimId, jstring url) {
|
||||||
|
return TO_JNI(THIS->removeBookmark(TO_C(zimId), TO_C(url)));
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(jobjectArray, getBookmarks, jboolean onlyValidBookmarks) {
|
||||||
|
auto bookmarks = THIS->getBookmarks(TO_C(onlyValidBookmarks));
|
||||||
|
jobjectArray retArray = createArray(env, bookmarks.size(), "org/kiwix/libkiwix/Bookmark");
|
||||||
|
size_t index = 0;
|
||||||
|
for (auto bookmark: bookmarks) {
|
||||||
|
auto wrapper = BUILD_WRAPPER("org/kiwix/libkiwx/Bookmark", bookmark);
|
||||||
|
env->SetObjectArrayElement(retArray, index++, wrapper);
|
||||||
|
}
|
||||||
|
return retArray;
|
||||||
|
}
|
||||||
|
53
lib/src/main/java/org/kiwix/libkiwix/Bookmark.java
Normal file
53
lib/src/main/java/org/kiwix/libkiwix/Bookmark.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.kiwix.libkiwix;
|
||||||
|
|
||||||
|
public class Bookmark
|
||||||
|
{
|
||||||
|
public Bookmark() {
|
||||||
|
setNativeBookmark();
|
||||||
|
}
|
||||||
|
|
||||||
|
public native void setBookId(String bookId);
|
||||||
|
public native void setBookTitle(String bookTitle);
|
||||||
|
public native void setUrl(String url);
|
||||||
|
public native void setTitle(String title);
|
||||||
|
public native void setLanguage(String language);
|
||||||
|
public native void setDate(String Date);
|
||||||
|
|
||||||
|
public native String getBookId();
|
||||||
|
public native String getBookTitle();
|
||||||
|
public native String getUrl();
|
||||||
|
public native String getTitle();
|
||||||
|
public native String getLanguage();
|
||||||
|
public native String getDate();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void finalize() { dispose(); }
|
||||||
|
|
||||||
|
|
||||||
|
///--------- The wrapper thing
|
||||||
|
// To delete our native wrapper
|
||||||
|
public native void dispose();
|
||||||
|
|
||||||
|
// A pointer (as a long) to a native Handle
|
||||||
|
private native void setNativeBookmark();
|
||||||
|
private long nativeHandle;
|
||||||
|
}
|
@ -23,6 +23,7 @@ import org.kiwix.libzim.Archive;
|
|||||||
import org.kiwix.libzim.Searcher;
|
import org.kiwix.libzim.Searcher;
|
||||||
import org.kiwix.libkiwix.Book;
|
import org.kiwix.libkiwix.Book;
|
||||||
import org.kiwix.libkiwix.JNIKiwixException;
|
import org.kiwix.libkiwix.JNIKiwixException;
|
||||||
|
import org.kiwix.libkiwix.Bookmark;
|
||||||
|
|
||||||
public class Library
|
public class Library
|
||||||
{
|
{
|
||||||
@ -41,6 +42,7 @@ public class Library
|
|||||||
public native boolean removeBookById(String id);
|
public native boolean removeBookById(String id);
|
||||||
|
|
||||||
public native boolean writeToFile(String path);
|
public native boolean writeToFile(String path);
|
||||||
|
public native boolean writeBookmarksToFile(String path);
|
||||||
|
|
||||||
public native int getBookCount(boolean localBooks, boolean remoteBooks);
|
public native int getBookCount(boolean localBooks, boolean remoteBooks);
|
||||||
|
|
||||||
@ -52,6 +54,10 @@ public class Library
|
|||||||
public native String[] getBooksCreators();
|
public native String[] getBooksCreators();
|
||||||
public native String[] getBooksPublishers();
|
public native String[] getBooksPublishers();
|
||||||
|
|
||||||
|
public native void addBookmark(Bookmark bookmark);
|
||||||
|
public native boolean removeBookmark(String zimId, String url);
|
||||||
|
public native Bookmark[] getBookmarks(boolean onlyValidBookmarks);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() { dispose(); }
|
protected void finalize() { dispose(); }
|
||||||
private native void setNativeHandler();
|
private native void setNativeHandler();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user