summaryrefslogtreecommitdiff
path: root/libview
diff options
context:
space:
mode:
authorrootavish <[email protected]>2014-07-29 19:57:02 +0530
committerrootavish <[email protected]>2014-07-29 19:57:02 +0530
commit60b002aab6c2ee610377d46208ee16dda1e94fc3 (patch)
treee7d41d29ac9ccb32e1b6163b766c34f4d30ad74b /libview
parent57a3618d9254364157a12df39caebbf9247d5aca (diff)
downloadatril-60b002aab6c2ee610377d46208ee16dda1e94fc3.tar.bz2
atril-60b002aab6c2ee610377d46208ee16dda1e94fc3.tar.xz
Searching single pages in epub
..and other fixing other bugs that were present once the webview was added, like the escape key command etc. Will look to refactor the thumbnails into ev-web-view.c. In the next commit I'll extend this search over the entire document.Also will incorporate document index(table of contents).
Diffstat (limited to 'libview')
-rw-r--r--libview/ev-document-model.c11
-rw-r--r--libview/ev-jobs.c40
-rw-r--r--libview/ev-jobs.h1
-rw-r--r--libview/ev-web-view.c117
-rw-r--r--libview/ev-web-view.h27
5 files changed, 167 insertions, 29 deletions
diff --git a/libview/ev-document-model.c b/libview/ev-document-model.c
index 00ce782b..dbf0477f 100644
--- a/libview/ev-document-model.c
+++ b/libview/ev-document-model.c
@@ -106,15 +106,8 @@ ev_document_model_set_property (GObject *object,
ev_document_model_set_page (model, g_value_get_int (value));
break;
case PROP_ROTATION:
- {
- if ( model->document->iswebdocument == TRUE ) {
- model->rotation=0;
- }
- else {
- ev_document_model_set_rotation (model, g_value_get_int (value));
- }
- break;
- }
+ ev_document_model_set_rotation (model, g_value_get_int (value));
+ break;
case PROP_INVERTED_COLORS:
if ( model->document->iswebdocument == TRUE ) {
atril_web_document_set_inverted_colors(model,g_value_get_boolean(value));
diff --git a/libview/ev-jobs.c b/libview/ev-jobs.c
index 884baabc..155990e9 100644
--- a/libview/ev-jobs.c
+++ b/libview/ev-jobs.c
@@ -1349,6 +1349,10 @@ ev_job_find_dispose (GObject *object)
g_free (job->pages);
job->pages = NULL;
}
+
+ if (job->results) {
+ g_free(job->results);
+ }
(* G_OBJECT_CLASS (ev_job_find_parent_class)->dispose) (object);
}
@@ -1360,7 +1364,6 @@ ev_job_find_run (EvJob *job)
EvDocumentFind *find = EV_DOCUMENT_FIND (job->document);
EvPage *ev_page;
GList *matches;
-
ev_debug_message (DEBUG_JOBS, NULL);
/* Do not block the main loop */
@@ -1374,16 +1377,26 @@ ev_job_find_run (EvJob *job)
#endif
ev_page = ev_document_get_page (job->document, job_find->current_page);
- matches = ev_document_find_find_text (find, ev_page, job_find->text,
- job_find->case_sensitive);
+
+ if (job->document->iswebdocument) {
+ job_find->has_results = ev_document_find_check_for_hits(find, ev_page, job_find->text,
+ job_find->case_sensitive);
+ }else {
+ matches = ev_document_find_find_text (find, ev_page, job_find->text,
+ job_find->case_sensitive);
+ }
+
g_object_unref (ev_page);
ev_document_doc_mutex_unlock ();
- if (!job_find->has_results)
+ if (!job_find->has_results && !job->document->iswebdocument) {
job_find->has_results = (matches != NULL);
-
- job_find->pages[job_find->current_page] = matches;
+ }
+
+ if (job->document->iswebdocument == FALSE) {
+ job_find->pages[job_find->current_page] = matches;
+ }
g_signal_emit (job_find, job_find_signals[FIND_UPDATED], 0, job_find->current_page);
job_find->current_page = (job_find->current_page + 1) % job_find->n_pages;
@@ -1433,7 +1446,13 @@ ev_job_find_new (EvDocument *document,
job->start_page = start_page;
job->current_page = start_page;
job->n_pages = n_pages;
- job->pages = g_new0 (GList *, n_pages);
+
+ if (document->iswebdocument) {
+ job->results = g_malloc0 (sizeof(guint) *n_pages);
+ }
+ else {
+ job->pages = g_new0 (GList *, n_pages);
+ }
job->text = g_strdup (text);
job->case_sensitive = case_sensitive;
job->has_results = FALSE;
@@ -1445,7 +1464,12 @@ gint
ev_job_find_get_n_results (EvJobFind *job,
gint page)
{
- return g_list_length (job->pages[page]);
+ if (EV_JOB(job)->document->iswebdocument) {
+ return job->results[page];
+ }
+ else {
+ return g_list_length (job->pages[page]);
+ }
}
gdouble
diff --git a/libview/ev-jobs.h b/libview/ev-jobs.h
index 39fa4433..87365672 100644
--- a/libview/ev-jobs.h
+++ b/libview/ev-jobs.h
@@ -365,6 +365,7 @@ struct _EvJobFind
gint current_page;
gint n_pages;
GList **pages;
+ guint *results;
gchar *text;
gboolean case_sensitive;
gboolean has_results;
diff --git a/libview/ev-web-view.c b/libview/ev-web-view.c
index a1caba36..6b134a0c 100644
--- a/libview/ev-web-view.c
+++ b/libview/ev-web-view.c
@@ -31,11 +31,21 @@
#include "ev-web-view.h"
#include "ev-document-model.h"
+#include "ev-jobs.h"
#define EV_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_WEB_VIEW, EvWebViewClass))
#define EV_IS_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EV_TYPE_WEB_VIEW))
#define EV_WEB_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EV_TYPE_WEB_VIEW, EvWebViewClass))
+typedef struct _SearchParams {
+ gboolean case_sensitive;
+ guint page_current;
+ gboolean search_jump;
+ gchar* search_string;
+ guint on_result;
+ guint n_results;
+}SearchParams;
+
struct _EvWebView
{
WebKitWebView web_view;
@@ -44,6 +54,7 @@ struct _EvWebView
gint current_page;
gboolean inverted_colors ;
gboolean fullscreen;
+ SearchParams *search;
};
struct _EvWebViewClass
@@ -116,8 +127,11 @@ ev_web_view_init (EvWebView *webview)
webview->current_page = 0;
- webview->fullscreen = FALSE;
+ webview->search = g_new0(SearchParams, 1);
+
+ webview->search->search_jump = TRUE ;
+ webview->fullscreen = FALSE;
}
static void
@@ -294,6 +308,7 @@ ev_web_view_next_page (EvWebView *webview)
if (page < n_pages) {
ev_document_model_set_page (webview->model, page);
EvPage *webpage = ev_document_get_page(webview->document,page);
+ webview->current_page = page ;
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview),(gchar*)webpage->backend_page);
return TRUE;
} else if (page == n_pages) {
@@ -341,18 +356,116 @@ ev_web_view_handle_link(EvWebView *webview,EvLink *link)
}
+/* Searching */
void
ev_web_view_find_next(EvWebView *webview)
{
-
+ /*First search for the next item on the current page*/
+ webkit_web_view_search_text (WEBKIT_WEB_VIEW(webview),
+ webview->search->search_string,
+ webview->search->case_sensitive,
+ TRUE,
+ FALSE);
}
void
ev_web_view_find_previous(EvWebView *webview)
{
+ webkit_web_view_search_text (WEBKIT_WEB_VIEW(webview),
+ webview->search->search_string,
+ webview->search->case_sensitive,
+ FALSE,
+ TRUE);
+}
+
+void
+ev_web_view_find_set_highlight_search(EvWebView *webview, gboolean visible)
+{
+ webkit_web_view_set_highlight_text_matches(WEBKIT_WEB_VIEW(webview),visible);
+}
+typedef struct _FindCBStruct {
+ EvJobFind *job;
+ gint page;
+}FindCBStruct;
+
+static void
+find_page_change_cb(WebKitWebView *webview,
+ WebKitWebFrame *webframe,
+ FindCBStruct *findcbs)
+{
+ findcbs->job->results[findcbs->page] = webkit_web_view_mark_text_matches(WEBKIT_WEB_VIEW(webview),
+ findcbs->job->text,
+ findcbs->job->case_sensitive,
+ 0);
+ ev_web_view_find_set_highlight_search(webview, TRUE);
+
+ webkit_web_view_search_text (WEBKIT_WEB_VIEW(webview),
+ findcbs->job->text,
+ findcbs->job->case_sensitive,
+ TRUE,
+ FALSE);
+}
+void
+ev_web_view_find_changed(EvWebView *webview, gint page_found_on,EvJobFind *job)
+{
+ if (job->has_results == FALSE)
+ return;
+
+ if (webview->search->search_jump == TRUE) {
+
+ webview->search->on_result = 1;
+ webview->search->case_sensitive = job->case_sensitive;
+ webview->search->search_string = g_strdup(job->text);
+ webview->search->search_jump = FALSE;
+
+ if (page_found_on != webview->current_page) {
+ ev_web_view_change_page(webview, page_found_on);
+
+ FindCBStruct *findstruct = g_new0 (FindCBStruct, 1);
+ findstruct->job = job;
+ findstruct->page = page_found_on;
+
+ g_signal_connect(WEBKIT_WEB_VIEW(webview),"document-load-finished",G_CALLBACK(find_page_change_cb),findstruct);
+ }
+ else {
+ job->results[webview->current_page] = webkit_web_view_mark_text_matches(WEBKIT_WEB_VIEW(webview),
+ job->text,
+ job->case_sensitive,
+ 0);
+
+ ev_web_view_find_set_highlight_search(webview, TRUE);
+ }
+ }
+}
+
+void
+ev_web_view_find_search_changed(EvWebView *webview)
+{
+ ev_web_view_find_set_highlight_search(webview,FALSE);
+ webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW(webview));
+ webview->search->search_jump = TRUE;
+}
+
+void
+ev_web_view_find_cancel(EvWebView *webview)
+{
+ ev_web_view_find_set_highlight_search(webview,FALSE);
+ webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW(webview));
+}
+
+void
+ev_web_view_empty_search(EvWebView *webview)
+{
+ SearchParams *search = webview->search ;
+ search->case_sensitive = FALSE;
+ if (search->search_string)
+ g_free(search->search_string);
+ search->search_string = NULL;
+ search->search_jump = TRUE ;
}
+/* Selection */
gboolean
ev_web_view_get_has_selection(EvWebView *webview)
{
diff --git a/libview/ev-web-view.h b/libview/ev-web-view.h
index 2c920434..aa2d5492 100644
--- a/libview/ev-web-view.h
+++ b/libview/ev-web-view.h
@@ -28,7 +28,7 @@
#include <gtk/gtk.h>
#include <atril-document.h>
-
+#include "ev-jobs.h"
#include "ev-document-model.h"
#include <glib-object.h>
G_BEGIN_DECLS
@@ -44,30 +44,37 @@ typedef struct _EvWebViewClass EvWebViewClass;
GType ev_web_view_get_type (void) G_GNUC_CONST;
GtkWidget* ev_web_view_new (void);
+
void ev_web_view_set_model (EvWebView *webview,
EvDocumentModel *model);
-void ev_web_view_reload (EvWebView *webview);
-void
-ev_web_view_reload_page (EvWebView *webview,
+
+void ev_web_view_reload (EvWebView *webview);
+
+void ev_web_view_reload_page (EvWebView *webview,
gint page);
/* Navigation */
gboolean ev_web_view_next_page (EvWebView *webview);
gboolean ev_web_view_previous_page (EvWebView *webview);
-/*Sidebar links*/
+/* Sidebar links */
void ev_web_view_handle_link (EvWebView *webview, EvLink* link);
-/*Searching*/
-void ev_web_view_find_next (EvWebView *webview);
-void ev_web_view_find_previous (EvWebView *webview);
+/* Searching */
+void ev_web_view_find_next (EvWebView *webview);
+void ev_web_view_find_previous (EvWebView *webview);
+void ev_web_view_find_changed (EvWebView *webview, gint page_found_on,EvJobFind *job);
+void ev_web_view_find_search_changed (EvWebView *webview);
+void ev_web_view_find_cancel (EvWebView *webview);
+void ev_web_view_find_set_highlight_search (EvWebView *webview,gboolean visible);
+void ev_web_view_empty_search (EvWebView *webview);
-/*Selection*/
+/* Selection */
gboolean ev_web_view_get_has_selection (EvWebView *webview);
void ev_web_view_select_all (EvWebView *webview);
void ev_web_view_copy (EvWebView *webview);
-/*Zoom control*/
+/* Zoom control */
gboolean ev_web_view_zoom_in (EvWebView *webview);
gboolean ev_web_view_zoom_out (EvWebView *webview);