00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00026
00027
00028
00029
00030 #include <liberipc/eripc.h>
00031 #include <liberipc/eripcpagebar.h>
00032 #include "browserTypes.h"
00033 #include "pagebar.h"
00034 #include "indexFileHandler.h"
00035 #include "browserLog.h"
00036 #include "erbusy.h"
00037
00038 static erClientChannel_t erPagebarChannel;
00039
00040
00041 void pagebar_init()
00042 {
00043 BR_PAGEBARPRINTF("entry");
00044 erIpcStartClient(ER_PAGEBAR_CHANNEL, &erPagebarChannel);
00045 pbReset(erPagebarChannel, ER_XHTML_VIEWER_UA_ID);
00046 }
00047
00048
00049 void pagebar_goto_page(int page)
00050 {
00051 BR_PAGEBARPRINTF("entry %d", page);
00052 pbSetCurrentPage(erPagebarChannel, ER_XHTML_VIEWER_UA_ID, page);
00053 }
00054
00055
00056 void pagebar_set_pagecount(int count)
00057 {
00058 BR_PAGEBARPRINTF("entry %d", count);
00059 pbSetPageCount(erPagebarChannel, ER_XHTML_VIEWER_UA_ID, count);
00060
00061 }
00062
00063
00064 void pagebar_set_offset(int offset)
00065 {
00066 BR_PAGEBARPRINTF("entry %d", offset);
00067 pbSetCurrentPageOffset(erPagebarChannel, ER_XHTML_VIEWER_UA_ID, offset);
00068 }
00069
00070
00071 void pagebar_redraw()
00072 {
00073 BR_PAGEBARPRINTF("redraw");
00074 pbRedraw(erPagebarChannel, ER_XHTML_VIEWER_UA_ID);
00075 }
00076
00077 void browser_pagebar_page_selected(int pagenumber, Ereader *browser)
00078 {
00079 gchar *location = NULL;
00080 gchar *pointer;
00081
00082 BR_PAGEBARPRINTF("number %d -- Ereader pointer 0x%x ", pagenumber, (unsigned int) browser);
00083
00084 if (pagenumber > 0)
00085 {
00086 location = index_file_get_page_location(&browser->pageStatus->index, browser->pageStatus->currentType, pagenumber);
00087
00088 if (location)
00089 {
00090 gchar *absolute_new_location;
00091 gchar *end;
00092 int length;
00093
00094 BR_PAGEBARPRINTF("gtk_moz_embed_load_url %s", location);
00095
00096 end = strrchr(browser->pageStatus->manifestFile, '/');
00097
00098 if (end)
00099 {
00100
00101 length = (end - browser->pageStatus->manifestFile) + 1;
00102
00103 BR_PAGEBARPRINTF("path lenght %d", length);
00104
00105 absolute_new_location = (char *) g_malloc0(length + strlen(location));
00106
00107 memcpy(absolute_new_location, browser->pageStatus->manifestFile, length);
00108
00109 BR_PAGEBARPRINTF("location %s", location);
00110 BR_PAGEBARPRINTF("absolute_new_location %s", absolute_new_location);
00111
00112 strcat(absolute_new_location, location);
00113
00114 BR_PAGEBARPRINTF("gtk_moz_embed_load_url %s [%d]", absolute_new_location, strlen(absolute_new_location));
00115
00116 BR_LOGPRINTF("BUSY ON");
00117 erbusy_blink();
00118 gtk_moz_embed_load_url(GTK_MOZ_EMBED(browser->mozEmbed), absolute_new_location);
00119
00120
00121 g_free(absolute_new_location);
00122 }
00123 }
00124 else
00125 {
00126 BR_PAGEBARPRINTF("location = null");
00127
00128
00129
00130 }
00131 }
00132 else
00133 {
00134 BR_PAGEBARPRINTF("invalid pagenumber %d", pagenumber);
00135 }
00136
00137 }
00138
00139 BrowserPageStatus *browser_create_page_status(void)
00140 {
00141 BrowserPageStatus *pageStatus = NULL;
00142
00143
00144 pageStatus = g_new0(BrowserPageStatus, 1);
00145
00146 if (pageStatus)
00147 {
00148 pageStatus->currentType = g_strdup(INIT_PAGE_TYPE);
00149 pageStatus->currentPage = -1;
00150 pageStatus->pageCount = -1;
00151 }
00152
00153 BR_PAGEBARPRINTF("0x%x", pageStatus);
00154
00155 return pageStatus;
00156 }
00157
00158
00159 void browser_destroy_page_status(BrowserPageStatus * pageStatus)
00160 {
00161 BR_PAGEBARPRINTF("entry 0x%x", pageStatus);
00162
00163 if (pageStatus)
00164 {
00165 if (pageStatus->index.pagelist)
00166 {
00167 index_file_close(&pageStatus->index);
00168 }
00169 if (pageStatus->currentType)
00170 {
00171
00172 g_free(pageStatus->currentType);
00173 }
00174
00175 g_free(pageStatus);
00176 }
00177 }
00178
00179 gboolean browser_set_page_status_indexfile(BrowserPageStatus * pageStatus, char *indexfile)
00180 {
00181 gboolean returnValue = FALSE;
00182
00183 BR_PAGEBARPRINTF("entry 0x%x file %s", pageStatus, indexfile);
00184
00185 if (pageStatus && indexfile)
00186 {
00187
00188 if (pageStatus->index.pagelist)
00189 {
00190 index_file_close(&pageStatus->index);
00191 }
00192
00193 if (0 == index_file_init(indexfile, &pageStatus->index))
00194 {
00195 pageStatus->manifestFile = indexfile;
00196 returnValue = TRUE;
00197 }
00198 }
00199 else
00200 {
00201 BR_ERRORPRINTF("input parameter == NULL");
00202 }
00203 return returnValue;
00204 }
00205
00206
00207 gboolean page_status_handle_type_update(BrowserPageStatus * pageStatus, gchar * pageType)
00208 {
00209 gint result = -1;
00210
00211 if (*pageType)
00212 {
00213 BR_PAGEBARPRINTF("currentType %s --> type %s", pageStatus->currentType, pageType);
00214
00215 if (pageStatus->currentType)
00216 {
00217 result = strcmp(pageStatus->currentType, pageType);
00218 }
00219
00220 if (result == 0)
00221 {
00222 BR_PAGEBARPRINTF("no type update");
00223 BR_PAGEBARPRINTF("no page bar update needed => new page number => returning FALSE!!!");
00224 return FALSE;
00225
00226 }
00227 else
00228 {
00229 BR_PAGEBARPRINTF("type update from %s to %s", pageStatus->currentType, pageType);
00230
00231 if (pageStatus->currentType)
00232 {
00233 g_free(pageStatus->currentType);
00234 pageStatus->currentType = NULL;
00235 }
00236
00237 pageStatus->currentType = g_strdup(pageType);
00238
00239 BR_PAGEBARPRINTF("page bar update needed (%s) => new page bar, new page number => returning TRUE !!!", pageStatus->currentType);
00240 return TRUE;
00241 }
00242 }
00243
00244 return TRUE;
00245 }