| 1 | // ePDFView - Dumb Test Document Observer. |
|---|
| 2 | // Copyright (C) 2006 Emma's Software. |
|---|
| 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 2 of the License, or |
|---|
| 7 | // (at your option) 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 17 | |
|---|
| 18 | #include <epdfview.h> |
|---|
| 19 | #include "DumbDocumentObserver.h" |
|---|
| 20 | |
|---|
| 21 | G_LOCK_DEFINE_STATIC (Searching); |
|---|
| 22 | |
|---|
| 23 | using namespace ePDFView; |
|---|
| 24 | |
|---|
| 25 | DumbDocumentObserver::DumbDocumentObserver (): |
|---|
| 26 | IDocumentObserver () |
|---|
| 27 | { |
|---|
| 28 | m_CurrentPage = 0; |
|---|
| 29 | m_Error = NULL; |
|---|
| 30 | m_FindMatchRect = NULL; |
|---|
| 31 | m_NotifiedError = FALSE; |
|---|
| 32 | m_NotifiedPassword = FALSE; |
|---|
| 33 | m_NotifiedLoad = FALSE; |
|---|
| 34 | m_NotifiedPageRotated = FALSE; |
|---|
| 35 | m_NotifiedPageZoomed = FALSE; |
|---|
| 36 | m_NotifiedReload = FALSE; |
|---|
| 37 | G_LOCK (Searching); |
|---|
| 38 | m_Searching = FALSE; |
|---|
| 39 | G_UNLOCK (Searching); |
|---|
| 40 | m_Zoom = 0.0; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | DumbDocumentObserver::~DumbDocumentObserver () |
|---|
| 44 | { |
|---|
| 45 | setLoadError (NULL); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | void |
|---|
| 49 | DumbDocumentObserver::notifyFindChanged (DocumentRectangle *matchRect) |
|---|
| 50 | { |
|---|
| 51 | m_FindMatchRect = matchRect; |
|---|
| 52 | G_LOCK (Searching); |
|---|
| 53 | m_Searching = FALSE; |
|---|
| 54 | G_UNLOCK (Searching); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | void |
|---|
| 58 | DumbDocumentObserver::notifyFindFinished () |
|---|
| 59 | { |
|---|
| 60 | G_LOCK (Searching); |
|---|
| 61 | m_Searching = FALSE; |
|---|
| 62 | G_UNLOCK (Searching); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | void |
|---|
| 66 | DumbDocumentObserver::notifyFindStarted () |
|---|
| 67 | { |
|---|
| 68 | G_LOCK (Searching); |
|---|
| 69 | m_Searching = TRUE; |
|---|
| 70 | G_UNLOCK (Searching); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | void |
|---|
| 74 | DumbDocumentObserver::notifyLoad () |
|---|
| 75 | { |
|---|
| 76 | m_NotifiedLoad = TRUE; |
|---|
| 77 | m_CurrentPage = 1; |
|---|
| 78 | m_Zoom = 1.0; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | void |
|---|
| 82 | DumbDocumentObserver::notifyLoadError (const GError *error) |
|---|
| 83 | { |
|---|
| 84 | setLoadError (error); |
|---|
| 85 | m_NotifiedError = TRUE; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | void |
|---|
| 89 | DumbDocumentObserver::notifyLoadPassword (const gchar *fileName, |
|---|
| 90 | gboolean reload, |
|---|
| 91 | const GError *error) |
|---|
| 92 | { |
|---|
| 93 | setLoadError (error); |
|---|
| 94 | m_NotifiedPassword = TRUE; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | void |
|---|
| 98 | DumbDocumentObserver::notifyPageChanged (gint pageNum) |
|---|
| 99 | { |
|---|
| 100 | m_CurrentPage = pageNum; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | void |
|---|
| 104 | DumbDocumentObserver::notifyPageRotated (gint rotation) |
|---|
| 105 | { |
|---|
| 106 | m_NotifiedPageRotated = TRUE; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | void |
|---|
| 110 | DumbDocumentObserver::notifyPageZoomed (gdouble zoom) |
|---|
| 111 | { |
|---|
| 112 | m_NotifiedPageZoomed = TRUE; |
|---|
| 113 | m_Zoom = zoom; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | void |
|---|
| 117 | DumbDocumentObserver::notifyReload (void) |
|---|
| 118 | { |
|---|
| 119 | m_NotifiedReload = TRUE; |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | //////////////////////////////////////////////////////////////// |
|---|
| 123 | // Test purposes methods. |
|---|
| 124 | //////////////////////////////////////////////////////////////// |
|---|
| 125 | |
|---|
| 126 | DocumentRectangle * |
|---|
| 127 | DumbDocumentObserver::getFindMatchRect () |
|---|
| 128 | { |
|---|
| 129 | return m_FindMatchRect; |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | gint |
|---|
| 133 | DumbDocumentObserver::getCurrentPage (void) |
|---|
| 134 | { |
|---|
| 135 | return m_CurrentPage; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | const GError * |
|---|
| 139 | DumbDocumentObserver::getLoadError (void) |
|---|
| 140 | { |
|---|
| 141 | return m_Error; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | gdouble |
|---|
| 145 | DumbDocumentObserver::getZoom (void) |
|---|
| 146 | { |
|---|
| 147 | return m_Zoom; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | gboolean |
|---|
| 151 | DumbDocumentObserver::isStillSearching (void) |
|---|
| 152 | { |
|---|
| 153 | G_LOCK (Searching); |
|---|
| 154 | gboolean searching = m_Searching; |
|---|
| 155 | G_UNLOCK (Searching); |
|---|
| 156 | return searching; |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | gboolean |
|---|
| 160 | DumbDocumentObserver::loadFinished (void) |
|---|
| 161 | { |
|---|
| 162 | return m_NotifiedError || m_NotifiedPassword || m_NotifiedLoad || |
|---|
| 163 | m_NotifiedReload; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | gboolean |
|---|
| 167 | DumbDocumentObserver::notifiedError (void) |
|---|
| 168 | { |
|---|
| 169 | gboolean notified = m_NotifiedError; |
|---|
| 170 | m_NotifiedError = FALSE; |
|---|
| 171 | return notified; |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | gboolean |
|---|
| 175 | DumbDocumentObserver::notifiedLoaded (void) |
|---|
| 176 | { |
|---|
| 177 | gboolean notified = m_NotifiedLoad; |
|---|
| 178 | m_NotifiedLoad = FALSE; |
|---|
| 179 | return notified; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | gboolean |
|---|
| 183 | DumbDocumentObserver::notifiedPassword (void) |
|---|
| 184 | { |
|---|
| 185 | gboolean notified = m_NotifiedPassword; |
|---|
| 186 | m_NotifiedPassword = FALSE; |
|---|
| 187 | return notified; |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | gboolean |
|---|
| 191 | DumbDocumentObserver::notifiedRotation (void) |
|---|
| 192 | { |
|---|
| 193 | gboolean notified = m_NotifiedPageRotated; |
|---|
| 194 | m_NotifiedPageRotated = FALSE; |
|---|
| 195 | return notified; |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | gboolean |
|---|
| 199 | DumbDocumentObserver::notifiedZoom (void) |
|---|
| 200 | { |
|---|
| 201 | gboolean notified = m_NotifiedPageZoomed; |
|---|
| 202 | m_NotifiedPageZoomed = FALSE; |
|---|
| 203 | return notified; |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | void |
|---|
| 207 | DumbDocumentObserver::setLoadError (const GError *error) |
|---|
| 208 | { |
|---|
| 209 | if ( NULL != m_Error ) |
|---|
| 210 | { |
|---|
| 211 | g_error_free (m_Error); |
|---|
| 212 | } |
|---|
| 213 | if ( NULL != error ) |
|---|
| 214 | { |
|---|
| 215 | m_Error = g_error_copy (error); |
|---|
| 216 | } |
|---|
| 217 | } |
|---|