• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegraphics API Reference
  • KDE Home
  • Contact Us
 

okular

  • sources
  • kde-4.12
  • kdegraphics
  • okular
  • core
bookmarkmanager.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2006 by Pino Toscano <pino@kde.org> *
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 
10 #include "bookmarkmanager.h"
11 
12 // qt/kde includes
13 #include <qhash.h>
14 #include <qset.h>
15 #include <kbookmarkmanager.h>
16 #include <kbookmarkmenu.h>
17 #include <kdebug.h>
18 #include <kglobal.h>
19 #include <kstandarddirs.h>
20 
21 // local includes
22 #include "document_p.h"
23 #include "observer.h"
24 
25 using namespace Okular;
26 
27 #define foreachObserver( cmd ) {\
28  QSet< DocumentObserver * >::const_iterator it = d->document->m_observers.constBegin(), end = d->document->m_observers.constEnd();\
29  for ( ; it != end ; ++ it ) { (*it)-> cmd ; } }
30 
31 #define foreachObserverD( cmd ) {\
32  QSet< DocumentObserver * >::const_iterator it = document->m_observers.constBegin(), end = document->m_observers.constEnd();\
33  for ( ; it != end ; ++ it ) { (*it)-> cmd ; } }
34 
35 class OkularBookmarkAction : public KBookmarkAction
36 {
37  public:
38  OkularBookmarkAction( const Okular::DocumentViewport& vp, const KBookmark& bk, KBookmarkOwner* owner, QObject *parent )
39  : KBookmarkAction( bk, owner, parent )
40  {
41  if ( vp.isValid() )
42  setText( QString::number( vp.pageNumber + 1 ) + " - " + text() );
43  setProperty("pageNumber", vp.pageNumber + 1);
44  setProperty("htmlRef", bk.url().htmlRef());
45  }
46 
47  inline int pageNumber() const
48  {
49  return property("pageNumber").toInt();
50  }
51 
52  inline QString htmlRef() const
53  {
54  return property("htmlRef").toString();
55  }
56 };
57 
58 static inline bool documentViewportFuzzyCompare( const DocumentViewport &vp1, const DocumentViewport &vp2 )
59 {
60  bool equal = vp1.isValid() && vp2.isValid() &&
61  ( vp1.pageNumber == vp2.pageNumber ) &&
62  ( vp1.rePos.pos == vp2.rePos.pos );
63 
64  if ( !equal )
65  return false;
66 
67  if ( qAbs(vp1.rePos.normalizedX-vp2.rePos.normalizedX) >= 0.000001 )
68  return false;
69 
70  if ( qAbs(vp1.rePos.normalizedY-vp2.rePos.normalizedY) >= 0.000001 )
71  return false;
72 
73  return true;
74 }
75 
76 static inline bool bookmarkLessThan( const KBookmark &b1, const KBookmark &b2 )
77 {
78  DocumentViewport vp1( b1.url().htmlRef() );
79  DocumentViewport vp2( b2.url().htmlRef() );
80 
81  return vp1 < vp2;
82 }
83 
84 static inline bool okularBookmarkActionLessThan( QAction * a1, QAction * a2 )
85 {
86  DocumentViewport vp1( static_cast< OkularBookmarkAction * >( a1 )->htmlRef() );
87  DocumentViewport vp2( static_cast< OkularBookmarkAction * >( a2 )->htmlRef() );
88 
89  return vp1 < vp2;
90 }
91 
92 class BookmarkManager::Private : public KBookmarkOwner
93 {
94  public:
95  Private( BookmarkManager * qq )
96  : KBookmarkOwner(), q( qq ), document( 0 ), manager( 0 )
97  {
98  }
99 
100  ~Private()
101  {
102  knownFiles.clear();
103  // no need to delete the manager, it's automatically done by KBookmarkManager
104  // delete manager;
105  }
106 
107  virtual QString currentUrl() const;
108  virtual QString currentTitle() const;
109  virtual bool enableOption(BookmarkOption option) const;
110  virtual void openBookmark( const KBookmark & bm, Qt::MouseButtons, Qt::KeyboardModifiers );
111 
112  QHash<KUrl, QString>::iterator bookmarkFind( const KUrl& url, bool doCreate, KBookmarkGroup *result = 0);
113 
114  // slots
115  void _o_changed( const QString & groupAddress, const QString & caller );
116 
117  BookmarkManager * q;
118  KUrl url;
119  QHash<int,int> urlBookmarks;
120  DocumentPrivate * document;
121  QString file;
122  KBookmarkManager * manager;
123  QHash<KUrl, QString> knownFiles;
124 };
125 
126 static inline KUrl urlForGroup(const KBookmark &group)
127 {
128  if ( group.url().isValid() ) return group.url();
129  else return KUrl( group.fullText() );
130 }
131 
132 BookmarkManager::BookmarkManager( DocumentPrivate * document )
133  : QObject( document->m_parent ), d( new Private( this ) )
134 {
135  setObjectName( QLatin1String( "Okular::BookmarkManager" ) );
136 
137  d->document = document;
138 
139  d->file = KStandardDirs::locateLocal( "data", "okular/bookmarks.xml" );
140 
141  d->manager = KBookmarkManager::managerForFile( d->file, "okular" );
142  d->manager->setEditorOptions( KGlobal::caption(), false );
143  d->manager->setUpdate( true );
144  connect( d->manager, SIGNAL(changed(QString,QString)),
145  this, SLOT(_o_changed(QString,QString)) );
146 }
147 
148 BookmarkManager::~BookmarkManager()
149 {
150  delete d;
151 }
152 
153 //BEGIN Reimplementations from KBookmarkOwner
154 QString BookmarkManager::Private::currentUrl() const
155 {
156  return url.prettyUrl();
157 }
158 
159 QString BookmarkManager::Private::currentTitle() const
160 {
161  return url.isLocalFile() ? url.toLocalFile() : url.prettyUrl();
162 }
163 
164 bool BookmarkManager::Private::enableOption(BookmarkOption option) const
165 {
166  Q_UNUSED( option )
167  return false;
168 }
169 
170 void BookmarkManager::Private::openBookmark( const KBookmark & bm, Qt::MouseButtons, Qt::KeyboardModifiers )
171 {
172  emit q->openUrl( bm.url() );
173 }
174 //END Reimplementations from KBookmarkOwner
175 
176 void BookmarkManager::Private::_o_changed( const QString & groupAddress, const QString & caller )
177 {
178  Q_UNUSED( caller );
179  if ( groupAddress.isEmpty() )
180  return;
181 
182  KUrl referurl;
183  // first, try to find the bookmark group whom change notification was just received
184  QHash<KUrl, QString>::iterator it = knownFiles.begin(), itEnd = knownFiles.end();
185  for ( ; it != itEnd; ++it )
186  {
187  if ( it.value() == groupAddress )
188  {
189  referurl = it.key();
190  knownFiles.erase( it );
191  break;
192  }
193  }
194  if ( !referurl.isValid() )
195  {
196  const KBookmark bm = manager->findByAddress( groupAddress );
197  // better be safe than sorry
198  if ( bm.isNull() )
199  return;
200  Q_ASSERT( bm.isGroup() );
201  referurl = urlForGroup( bm );
202  }
203  Q_ASSERT( referurl.isValid() );
204  emit q->bookmarksChanged( referurl );
205  // case for the url representing the current document
206  // (this might happen if the same document is open in another place;
207  // in such case, make really sure to be in sync)
208  if ( referurl == url )
209  {
210  // save the old bookmarks for the current url
211  const QHash<int,int> oldUrlBookmarks = urlBookmarks;
212  // set the same url again, so we reload the information we have about it
213  q->setUrl( referurl );
214  // then notify the observers about the changes in the bookmarks
215  for ( int i = 0; i < qMax( oldUrlBookmarks.size(), urlBookmarks.size() ); i++ )
216  {
217  bool oldContains = oldUrlBookmarks.contains(i) && oldUrlBookmarks[i] > 0;
218  bool curContains = urlBookmarks.contains(i) && urlBookmarks[i] > 0;
219 
220  if ( oldContains != curContains )
221  {
222  foreachObserverD( notifyPageChanged( i, DocumentObserver::Bookmark ) );
223  }
224  else if ( oldContains && oldUrlBookmarks[i] != urlBookmarks[i] )
225  {
226  foreachObserverD( notifyPageChanged( i, DocumentObserver::Bookmark ) );
227  }
228 
229  }
230  }
231  emit q->saved();
232 }
233 
234 KUrl::List BookmarkManager::files() const
235 {
236  KUrl::List ret;
237  KBookmarkGroup group = d->manager->root();
238  for ( KBookmark bm = group.first(); !bm.isNull(); bm = group.next( bm ) )
239  {
240  if ( bm.isSeparator() || !bm.isGroup() )
241  continue;
242 
243  ret.append( urlForGroup( bm ) );
244  }
245  return ret;
246 }
247 
248 KBookmark::List BookmarkManager::bookmarks( const KUrl& url ) const
249 {
250  KBookmark::List ret;
251  KBookmarkGroup group = d->manager->root();
252  for ( KBookmark bm = group.first(); !bm.isNull(); bm = group.next( bm ) )
253  {
254  if ( !bm.isGroup() || urlForGroup( bm ) != url )
255  continue;
256 
257  KBookmarkGroup group = bm.toGroup();
258  for ( KBookmark b = group.first(); !b.isNull(); b = group.next( b ) )
259  {
260  if ( b.isSeparator() || b.isGroup() )
261  continue;
262 
263  ret.append( b );
264  }
265  break;
266  }
267 
268  return ret;
269 }
270 
271 KBookmark::List BookmarkManager::bookmarks() const
272 {
273  return bookmarks( d->url );
274 }
275 
276 KBookmark::List BookmarkManager::bookmarks( int page ) const
277 {
278  const KBookmark::List bmarks = bookmarks();
279  KBookmark::List ret;
280  foreach( const KBookmark &bm, bmarks )
281  {
282  DocumentViewport vp( bm.url().htmlRef() );
283  if ( vp.isValid() && vp.pageNumber == page )
284  {
285  ret.append(bm);
286  }
287  }
288 
289  return ret;
290 }
291 
292 KBookmark BookmarkManager::bookmark( int page ) const
293 {
294  const KBookmark::List bmarks = bookmarks();
295  foreach( const KBookmark &bm, bmarks )
296  {
297  DocumentViewport vp( bm.url().htmlRef() );
298  if ( vp.isValid() && vp.pageNumber == page )
299  {
300  return bm;
301  }
302  }
303  return KBookmark();
304 }
305 
306 KBookmark BookmarkManager::bookmark( const DocumentViewport &viewport ) const
307 {
308  if ( !viewport.isValid() || !isBookmarked( viewport.pageNumber ) )
309  return KBookmark();
310 
311  KBookmarkGroup thebg;
312  QHash<KUrl, QString>::iterator it = d->bookmarkFind( d->url, false, &thebg );
313  if ( it == d->knownFiles.end() )
314  return KBookmark();
315 
316  for ( KBookmark bm = thebg.first(); !bm.isNull(); bm = thebg.next( bm ) )
317  {
318  if ( bm.isSeparator() || bm.isGroup() )
319  continue;
320 
321  DocumentViewport vp( bm.url().htmlRef() );
322  if ( documentViewportFuzzyCompare( vp, viewport ) )
323  {
324  return bm;
325  }
326  }
327 
328  return KBookmark();
329 }
330 
331 void BookmarkManager::save() const
332 {
333  d->manager->emitChanged();
334  emit const_cast<BookmarkManager*>( this )->saved();
335 }
336 
337 QHash<KUrl, QString>::iterator BookmarkManager::Private::bookmarkFind( const KUrl& url, bool doCreate, KBookmarkGroup *result )
338 {
339  QHash<KUrl, QString>::iterator it = knownFiles.find( url );
340  if ( it == knownFiles.end() )
341  {
342  // if the url we want to add a new entry for is not in the hash of the
343  // known files, then first try to find the file among the top-level
344  // "folder" names
345  bool found = false;
346  KBookmarkGroup root = manager->root();
347  for ( KBookmark bm = root.first(); !found && !bm.isNull(); bm = root.next( bm ) )
348  {
349  if ( bm.isSeparator() || !bm.isGroup() )
350  continue;
351 
352  KUrl tmpurl( urlForGroup( bm ) );
353  if ( tmpurl == url )
354  {
355  // got it! place it the hash of known files
356  KBookmarkGroup bg = bm.toGroup();
357  it = knownFiles.insert( url, bg.address() );
358  found = true;
359  if ( result )
360  *result = bg;
361  break;
362  }
363  }
364  if ( !found && doCreate )
365  {
366  // folder not found :(
367  // then, in a single step create a new folder and add it in our cache :)
368  QString purl = url.isLocalFile() ? url.toLocalFile() : url.prettyUrl();
369  KBookmarkGroup newbg = root.createNewFolder( purl );
370  newbg.setUrl( url );
371  it = knownFiles.insert( url, newbg.address() );
372  if ( result )
373  *result = newbg;
374  }
375  }
376  else if ( result )
377  {
378  const KBookmark bm = manager->findByAddress( it.value() );
379  Q_ASSERT( bm.isGroup() );
380  *result = bm.toGroup();
381  }
382  return it;
383 }
384 
385 void BookmarkManager::addBookmark( int n )
386 {
387  if ( n >= 0 && n < (int)d->document->m_pagesVector.count() )
388  {
389  if ( setPageBookmark( n ) )
390  foreachObserver( notifyPageChanged( n, DocumentObserver::Bookmark ) );
391  }
392 }
393 
394 void BookmarkManager::addBookmark( const DocumentViewport &vp )
395 {
396  addBookmark( d->url, vp );
397 }
398 
399 bool BookmarkManager::addBookmark( const KUrl& referurl, const Okular::DocumentViewport& vp, const QString& title )
400 {
401  if ( !referurl.isValid() || !vp.isValid() )
402  return false;
403 
404  if ( vp.pageNumber < 0 || vp.pageNumber >= d->document->m_pagesVector.count() )
405  return false;
406 
407  KBookmarkGroup thebg;
408  QHash<KUrl, QString>::iterator it = d->bookmarkFind( referurl, true, &thebg );
409  Q_ASSERT( it != d->knownFiles.end() );
410 
411  int count = 0; // Number of bookmarks in the current page
412  bool found = false;
413  // Check if the bookmark already exists
414  for ( KBookmark bm = thebg.first(); !found && !bm.isNull(); bm = thebg.next( bm ) )
415  {
416  if ( bm.isSeparator() || bm.isGroup() )
417  continue;
418 
419  DocumentViewport bmViewport( bm.url().htmlRef() );
420  if ( bmViewport.isValid() && bmViewport.pageNumber == vp.pageNumber )
421  {
422  ++count;
423 
424  if ( documentViewportFuzzyCompare( bmViewport, vp ) )
425  found = true;
426  }
427  }
428 
429  if ( found )
430  return false;
431 
432  QString newtitle;
433  if ( title.isEmpty() )
434  {
435  // if we have no title specified for the new bookmark, then give it the
436  // name '#p' where p is the page number where the bookmark is located.
437  // if there's more than one bookmark per page, give the name '#p-n'
438  // where n is the index of this bookmark among the ones of its page.
439  if ( count > 0 )
440  newtitle = QString( "#%1-%2" ).arg( vp.pageNumber + 1 ).arg( count );
441  else
442  newtitle = QString( "#%1" ).arg( vp.pageNumber + 1 );
443  }
444  else
445  newtitle = title;
446 
447  KUrl newurl = referurl;
448  newurl.setHTMLRef( vp.toString() );
449  thebg.addBookmark( newtitle, newurl, QString() );
450  if ( referurl == d->document->m_url )
451  {
452  d->urlBookmarks[ vp.pageNumber ]++;
453  foreachObserver( notifyPageChanged( vp.pageNumber, DocumentObserver::Bookmark ) );
454  }
455  d->manager->emitChanged( thebg );
456  return true;
457 }
458 
459 void BookmarkManager::removeBookmark( int n )
460 {
461  if ( n >= 0 && n < (int)d->document->m_pagesVector.count() )
462  {
463  if ( removePageBookmark( n ) )
464  foreachObserver( notifyPageChanged( n, DocumentObserver::Bookmark ) );
465  }
466 }
467 
468 void BookmarkManager::removeBookmark( const DocumentViewport &vp )
469 {
470  int page = vp.pageNumber;
471  if ( page >= 0 && page < d->document->m_pagesVector.count() )
472  {
473  removeBookmark( d->url, bookmark( vp ) );
474  }
475 }
476 
477 void BookmarkManager::renameBookmark( KBookmark* bm, const QString& newName)
478 {
479  KBookmarkGroup thebg;
480  QHash<KUrl, QString>::iterator it = d->bookmarkFind( d->url, false, &thebg );
481  Q_ASSERT ( it != d->knownFiles.end() );
482  if ( it == d->knownFiles.end() )
483  return;
484 
485  bm->setFullText( newName );
486  d->manager->emitChanged( thebg );
487 }
488 
489 void BookmarkManager::renameBookmark( const KUrl& referurl, const QString& newName )
490 {
491  if ( !referurl.isValid() )
492  return;
493 
494  KBookmarkGroup thebg;
495  QHash<KUrl, QString>::iterator it = d->bookmarkFind( referurl, false, &thebg );
496  Q_ASSERT ( it != d->knownFiles.end() );
497  if ( it == d->knownFiles.end() )
498  return;
499 
500  thebg.setFullText( newName );
501  d->manager->emitChanged( thebg );
502 }
503 
504 QString BookmarkManager::titleForUrl( const KUrl& referurl ) const
505 {
506  KBookmarkGroup thebg;
507  QHash<KUrl, QString>::iterator it = d->bookmarkFind( referurl, false, &thebg );
508  Q_ASSERT( it != d->knownFiles.end() );
509 
510  return thebg.fullText();
511 }
512 
513 int BookmarkManager::removeBookmark( const KUrl& referurl, const KBookmark& bm )
514 {
515  if ( !referurl.isValid() || bm.isNull() || bm.isGroup() || bm.isSeparator() )
516  return -1;
517 
518  DocumentViewport vp( bm.url().htmlRef() );
519  if ( !vp.isValid() )
520  return -1;
521 
522  KBookmarkGroup thebg;
523  QHash<KUrl, QString>::iterator it = d->bookmarkFind( referurl, false, &thebg );
524  if ( it == d->knownFiles.end() )
525  return -1;
526 
527  thebg.deleteBookmark( bm );
528 
529  if ( referurl == d->document->m_url )
530  {
531  d->urlBookmarks[ vp.pageNumber ]--;
532  foreachObserver( notifyPageChanged( vp.pageNumber, DocumentObserver::Bookmark ) );
533  }
534  d->manager->emitChanged( thebg );
535 
536  return vp.pageNumber;
537 }
538 
539 void BookmarkManager::removeBookmarks( const KUrl& referurl, const KBookmark::List& list )
540 {
541  if ( !referurl.isValid() || list.isEmpty() )
542  return;
543 
544  KBookmarkGroup thebg;
545  QHash<KUrl, QString>::iterator it = d->bookmarkFind( referurl, false, &thebg );
546  if ( it == d->knownFiles.end() )
547  return;
548 
549  const QHash<int,int> oldUrlBookmarks = d->urlBookmarks;
550  bool deletedAny = false;
551  foreach ( const KBookmark & bm, list )
552  {
553  if ( bm.parentGroup() == thebg )
554  {
555  thebg.deleteBookmark( bm );
556  deletedAny = true;
557 
558  DocumentViewport vp( bm.url().htmlRef() );
559  if ( referurl == d->document->m_url )
560  {
561  d->urlBookmarks[ vp.pageNumber ]--;
562  }
563  }
564  }
565 
566  if ( referurl == d->document->m_url )
567  {
568  for ( int i = 0; i < qMax( oldUrlBookmarks.size(), d->urlBookmarks.size() ); i++ )
569  {
570  bool oldContains = oldUrlBookmarks.contains(i) && oldUrlBookmarks[i] > 0;
571  bool curContains = d->urlBookmarks.contains(i) && d->urlBookmarks[i] > 0;
572 
573  if ( oldContains != curContains )
574  {
575  foreachObserver( notifyPageChanged( i, DocumentObserver::Bookmark ) );
576  }
577  else if ( oldContains && oldUrlBookmarks[i] != d->urlBookmarks[i] )
578  {
579  foreachObserver( notifyPageChanged( i, DocumentObserver::Bookmark ) );
580  }
581  }
582  }
583  if ( deletedAny )
584  d->manager->emitChanged( thebg );
585 }
586 
587 QList< QAction * > BookmarkManager::actionsForUrl( const KUrl& url ) const
588 {
589  QList< QAction * > ret;
590  KBookmarkGroup group = d->manager->root();
591  for ( KBookmark bm = group.first(); !bm.isNull(); bm = group.next( bm ) )
592  {
593  if ( !bm.isGroup() || urlForGroup( bm ) != url )
594  continue;
595 
596  KBookmarkGroup group = bm.toGroup();
597  for ( KBookmark b = group.first(); !b.isNull(); b = group.next( b ) )
598  {
599  if ( b.isSeparator() || b.isGroup() )
600  continue;
601 
602  ret.append( new OkularBookmarkAction( DocumentViewport( b.url().htmlRef() ), b, d, 0 ) );
603  }
604  break;
605  }
606  qSort( ret.begin(), ret.end(), okularBookmarkActionLessThan );
607  return ret;
608 }
609 
610 void BookmarkManager::setUrl( const KUrl& url )
611 {
612  d->url = url;
613  d->urlBookmarks.clear();
614  KBookmarkGroup thebg;
615  QHash<KUrl, QString>::iterator it = d->bookmarkFind( url, false, &thebg );
616  if ( it != d->knownFiles.end() )
617  {
618  for ( KBookmark bm = thebg.first(); !bm.isNull(); bm = thebg.next( bm ) )
619  {
620  if ( bm.isSeparator() || bm.isGroup() )
621  continue;
622 
623  DocumentViewport vp( bm.url().htmlRef() );
624  if ( !vp.isValid() )
625  continue;
626 
627  d->urlBookmarks[ vp.pageNumber ]++;
628  }
629  }
630 }
631 
632 bool BookmarkManager::setPageBookmark( int page )
633 {
634  KBookmarkGroup thebg;
635  QHash<KUrl, QString>::iterator it = d->bookmarkFind( d->url, true, &thebg );
636  Q_ASSERT( it != d->knownFiles.end() );
637 
638  bool found = false;
639  bool added = false;
640  for ( KBookmark bm = thebg.first(); !found && !bm.isNull(); bm = thebg.next( bm ) )
641  {
642  if ( bm.isSeparator() || bm.isGroup() )
643  continue;
644 
645  DocumentViewport vp( bm.url().htmlRef() );
646  if ( vp.isValid() && vp.pageNumber == page )
647  found = true;
648 
649  }
650  if ( !found )
651  {
652  d->urlBookmarks[ page ]++;
653  DocumentViewport vp;
654  vp.pageNumber = page;
655  KUrl newurl = d->url;
656  newurl.setHTMLRef( vp.toString() );
657  thebg.addBookmark( QString::fromLatin1( "#" ) + QString::number( vp.pageNumber + 1 ), newurl, QString() );
658  added = true;
659  d->manager->emitChanged( thebg );
660  }
661  return added;
662 }
663 
664 bool BookmarkManager::removePageBookmark( int page )
665 {
666  KBookmarkGroup thebg;
667  QHash<KUrl, QString>::iterator it = d->bookmarkFind( d->url, false, &thebg );
668  if ( it == d->knownFiles.end() )
669  return false;
670 
671  bool found = false;
672  for ( KBookmark bm = thebg.first(); !found && !bm.isNull(); bm = thebg.next( bm ) )
673  {
674  if ( bm.isSeparator() || bm.isGroup() )
675  continue;
676 
677  DocumentViewport vp( bm.url().htmlRef() );
678  if ( vp.isValid() && vp.pageNumber == page )
679  {
680  found = true;
681  thebg.deleteBookmark( bm );
682  d->urlBookmarks[ page ]--;
683  d->manager->emitChanged( thebg );
684  }
685  }
686  return found;
687 }
688 
689 bool BookmarkManager::isBookmarked( int page ) const
690 {
691  return d->urlBookmarks.contains( page ) && d->urlBookmarks[ page ] > 0;
692 }
693 
694 bool BookmarkManager::isBookmarked( const DocumentViewport &viewport ) const
695 {
696  KBookmark bm = bookmark( viewport );
697 
698  return !bm.isNull();
699 }
700 
701 KBookmark BookmarkManager::nextBookmark( const DocumentViewport &viewport) const
702 {
703  KBookmark::List bmarks = bookmarks();
704  qSort( bmarks.begin(), bmarks.end(), bookmarkLessThan);
705 
706  KBookmark bookmark;
707  foreach ( const KBookmark &bm, bmarks )
708  {
709  DocumentViewport vp( bm.url().htmlRef() );
710  if ( viewport < vp )
711  {
712  bookmark = bm;
713  break;
714  }
715  }
716 
717  return bookmark;
718 }
719 
720 KBookmark BookmarkManager::previousBookmark( const DocumentViewport &viewport ) const
721 {
722  KBookmark::List bmarks = bookmarks();
723  qSort( bmarks.begin(), bmarks.end(), bookmarkLessThan );
724 
725  KBookmark bookmark;
726  for ( KBookmark::List::const_iterator it = bmarks.constEnd(); it != bmarks.constBegin(); --it )
727  {
728  KBookmark bm = *(it-1);
729  DocumentViewport vp( bm.url().htmlRef() );
730  if ( vp < viewport )
731  {
732  bookmark = bm;
733  break;
734  }
735  }
736 
737  return bookmark;
738 }
739 
740 #undef foreachObserver
741 #undef foreachObserverD
742 
743 #include "bookmarkmanager.moc"
744 
745 /* kate: replace-tabs on; indent-width 4; */
Okular::DocumentViewport::pos
Position pos
Definition: document.h:1054
Okular::BookmarkManager::removeBookmark
void removeBookmark(int page)
Remove a bookmark for the given page.
Definition: bookmarkmanager.cpp:459
bookmarkLessThan
static bool bookmarkLessThan(const KBookmark &b1, const KBookmark &b2)
Definition: bookmarkmanager.cpp:76
bookmarkmanager.h
Okular::BookmarkManager::bookmark
KBookmark bookmark(int page) const
Returns the bookmark for the given page of the document.
Definition: bookmarkmanager.cpp:292
Okular::BookmarkManager::nextBookmark
KBookmark nextBookmark(const DocumentViewport &viewport) const
Given a viewport, returns the next bookmark.
Definition: bookmarkmanager.cpp:701
foreachObserverD
#define foreachObserverD(cmd)
Definition: bookmarkmanager.cpp:31
Okular::BookmarkManager::bookmarks
KBookmark::List bookmarks() const
Returns the list of bookmarks for document.
Definition: bookmarkmanager.cpp:271
Okular::DocumentObserver::Bookmark
Bookmarks has been changed.
Definition: observer.h:43
Okular::BookmarkManager::openUrl
void openUrl(const KUrl &url)
The bookmark manager is requesting to open the specified url.
QObject
Okular::DocumentPrivate::m_pagesVector
QVector< Page * > m_pagesVector
Definition: document_p.h:249
observer.h
urlForGroup
static KUrl urlForGroup(const KBookmark &group)
Definition: bookmarkmanager.cpp:126
documentViewportFuzzyCompare
static bool documentViewportFuzzyCompare(const DocumentViewport &vp1, const DocumentViewport &vp2)
Definition: bookmarkmanager.cpp:58
Okular::BookmarkManager::Private
friend class Private
Definition: bookmarkmanager.h:193
okularBookmarkActionLessThan
static bool okularBookmarkActionLessThan(QAction *a1, QAction *a2)
Definition: bookmarkmanager.cpp:84
Okular::DocumentViewport::pageNumber
int pageNumber
The number of the page nearest the center of the viewport.
Definition: document.h:1035
Okular::DocumentViewport::rePos
struct Okular::DocumentViewport::@0 rePos
If 'rePos.enabled == true' then this structure contains the viewport center or top left depending on ...
Okular::BookmarkManager::titleForUrl
QString titleForUrl(const KUrl &referurl) const
Returns title for the referurl.
Definition: bookmarkmanager.cpp:504
foreachObserver
#define foreachObserver(cmd)
Definition: bookmarkmanager.cpp:27
Okular::DocumentPrivate
Definition: document_p.h:83
Okular::DocumentViewport::normalizedX
double normalizedX
Definition: document.h:1052
Okular::BookmarkManager::isBookmarked
bool isBookmarked(int page) const
Returns whether the given page is bookmarked.
Definition: bookmarkmanager.cpp:689
Okular::BookmarkManager::actionsForUrl
QList< QAction * > actionsForUrl(const KUrl &url) const
Returns a list of actions for the bookmarks of the specified url.
Definition: bookmarkmanager.cpp:587
Okular::BookmarkManager::save
void save() const
Forces to save the list of bookmarks.
Definition: bookmarkmanager.cpp:331
document_p.h
Okular::DocumentViewport::normalizedY
double normalizedY
Definition: document.h:1053
Okular::BookmarkManager::addBookmark
void addBookmark(int page)
Adds a bookmark for the given page.
Definition: bookmarkmanager.cpp:385
Okular::BookmarkManager::files
KUrl::List files() const
Returns the list of documents with bookmarks.
Definition: bookmarkmanager.cpp:234
Okular::BookmarkManager::saved
void saved()
This signal is emitted whenever bookmarks have been saved.
Okular::DocumentViewport
A view on the document.
Definition: document.h:1003
Okular::DocumentViewport::toString
QString toString() const
Returns the viewport as xml description.
Definition: document.cpp:4560
Okular::BookmarkManager::previousBookmark
KBookmark previousBookmark(const DocumentViewport &viewport) const
Given a viewport, returns the previous bookmark.
Definition: bookmarkmanager.cpp:720
Okular::BookmarkManager::renameBookmark
void renameBookmark(KBookmark *bm, const QString &newName)
Returns the bookmark given bookmark of the document.
Definition: bookmarkmanager.cpp:477
Okular::BookmarkManager::removeBookmarks
void removeBookmarks(const KUrl &referurl, const KBookmark::List &list)
Removes the bookmarks in list for the referurl specified.
Definition: bookmarkmanager.cpp:539
Okular::DocumentViewport::isValid
bool isValid() const
Returns whether the viewport is valid.
Definition: document.cpp:4576
Okular::BookmarkManager
Bookmarks manager utility.
Definition: bookmarkmanager.h:32
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:45:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okular

Skip menu "okular"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegraphics API Reference

Skip menu "kdegraphics API Reference"
  •     libkdcraw
  •     libkexiv2
  •     libkipi
  •     libksane
  • okular

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal