Commit 8a7c2ad6 authored by Pino Toscano's avatar Pino Toscano

As requested by our usability expert Florian, add a Bookmarks menu with the...

As requested by our usability expert Florian, add a Bookmarks menu with the bookmarks in the current document, if any.

svn path=/trunk/playground/graphics/okular/; revision=622995
parent e3992fb6
...@@ -222,6 +222,28 @@ int BookmarkManager::removeBookmark( const KUrl& referurl, const KBookmark& bm ) ...@@ -222,6 +222,28 @@ int BookmarkManager::removeBookmark( const KUrl& referurl, const KBookmark& bm )
return vp.pageNumber; return vp.pageNumber;
} }
QList< QAction * > BookmarkManager::actionsForUrl( const KUrl& url ) const
{
QList< QAction * > ret;
KBookmarkGroup group = d->manager->root();
for ( KBookmark bm = group.first(); !bm.isNull(); bm = group.next( bm ) )
{
if ( !bm.isGroup() || KUrl( bm.fullText() ) != url )
continue;
KBookmarkGroup group = bm.toGroup();
for ( KBookmark b = group.first(); !b.isNull(); b = group.next( b ) )
{
if ( b.isSeparator() || b.isGroup() )
continue;
ret.append( new KBookmarkAction( b, d, 0 ) );
}
break;
}
return ret;
}
void BookmarkManager::setUrl( const KUrl& url ) void BookmarkManager::setUrl( const KUrl& url )
{ {
d->url = url; d->url = url;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "okular_export.h" #include "okular_export.h"
class QAction;
class KUrl; class KUrl;
namespace Okular { namespace Okular {
...@@ -55,6 +56,14 @@ class OKULAR_EXPORT BookmarkManager : public QObject ...@@ -55,6 +56,14 @@ class OKULAR_EXPORT BookmarkManager : public QObject
*/ */
int removeBookmark( const KUrl& referurl, const KBookmark& bm ); int removeBookmark( const KUrl& referurl, const KBookmark& bm );
/**
* Returns a list of actions for the bookmarks of the specified @p url.
*
* @note the actions will have no parents, so you have to delete them
* yourself
*/
QList< QAction* > actionsForUrl( const KUrl& url ) const;
Q_SIGNALS: Q_SIGNALS:
/** /**
* The bookmark manager is requesting to open the specified @p url. * The bookmark manager is requesting to open the specified @p url.
......
...@@ -575,7 +575,6 @@ Document::Document( QHash<QString, Generator*> * generators ) ...@@ -575,7 +575,6 @@ Document::Document( QHash<QString, Generator*> * generators )
: d( new Private( this, generators ) ) : d( new Private( this, generators ) )
{ {
d->m_bookmarkManager = new BookmarkManager( this ); d->m_bookmarkManager = new BookmarkManager( this );
connect( d->m_bookmarkManager, SIGNAL( openUrl( const KUrl & ) ), this, SIGNAL( openUrl( const KUrl & ) ) );
} }
Document::~Document() Document::~Document()
......
...@@ -71,6 +71,7 @@ ...@@ -71,6 +71,7 @@
#include "ui/bookmarklist.h" #include "ui/bookmarklist.h"
#include "conf/preferencesdialog.h" #include "conf/preferencesdialog.h"
#include "settings.h" #include "settings.h"
#include "core/bookmarkmanager.h"
#include "core/document.h" #include "core/document.h"
#include "core/generator.h" #include "core/generator.h"
#include "core/page.h" #include "core/page.h"
...@@ -108,6 +109,7 @@ m_searchStarted(false), m_cliPresentation(false) ...@@ -108,6 +109,7 @@ m_searchStarted(false), m_cliPresentation(false)
connect( m_document, SIGNAL( linkPresentation() ), this, SLOT( slotShowPresentation() ) ); connect( m_document, SIGNAL( linkPresentation() ), this, SLOT( slotShowPresentation() ) );
connect( m_document, SIGNAL( linkEndPresentation() ), this, SLOT( slotHidePresentation() ) ); connect( m_document, SIGNAL( linkEndPresentation() ), this, SLOT( slotHidePresentation() ) );
connect( m_document, SIGNAL( openUrl(const KUrl &) ), this, SLOT( openUrlFromDocument(const KUrl &) ) ); connect( m_document, SIGNAL( openUrl(const KUrl &) ), this, SLOT( openUrlFromDocument(const KUrl &) ) );
connect( m_document->bookmarkManager(), SIGNAL( openUrl(const KUrl &) ), this, SLOT( openUrlFromBookmarks(const KUrl &) ) );
connect( m_document, SIGNAL( close() ), this, SLOT( close() ) ); connect( m_document, SIGNAL( close() ), this, SLOT( close() ) );
if ( parent && parent->metaObject()->indexOfSlot( SLOT( slotQuit() ) ) != -1 ) if ( parent && parent->metaObject()->indexOfSlot( SLOT( slotQuit() ) ) != -1 )
...@@ -403,6 +405,8 @@ m_searchStarted(false), m_cliPresentation(false) ...@@ -403,6 +405,8 @@ m_searchStarted(false), m_cliPresentation(false)
Okular::Settings::setUseKTTSD( !offers.isEmpty() ); Okular::Settings::setUseKTTSD( !offers.isEmpty() );
Okular::Settings::writeConfig(); Okular::Settings::writeConfig();
rebuildBookmarkMenu( false );
// set our XML-UI resource file // set our XML-UI resource file
setXMLFile("part.rc"); setXMLFile("part.rc");
// //
...@@ -426,6 +430,8 @@ Part::~Part() ...@@ -426,6 +430,8 @@ Part::~Part()
if (m_tempfile) if (m_tempfile)
delete m_tempfile; delete m_tempfile;
qDeleteAll( m_bookmarkActions );
} }
...@@ -451,6 +457,22 @@ void Part::openUrlFromDocument(const KUrl &url) ...@@ -451,6 +457,22 @@ void Part::openUrlFromDocument(const KUrl &url)
openUrl(url); openUrl(url);
} }
void Part::openUrlFromBookmarks(const KUrl &_url)
{
KUrl url = _url;
Okular::DocumentViewport vp( _url.htmlRef() );
if ( vp.isValid() )
m_document->setNextDocumentViewport( vp );
url.setHTMLRef( QString() );
if ( m_document->currentDocument() == url )
{
if ( vp.isValid() )
m_document->setViewport( vp );
}
else
openUrl( url );
}
void Part::supportedMimetypes() void Part::supportedMimetypes()
{ {
...@@ -555,6 +577,14 @@ void Part::slotGeneratorPreferences( ) ...@@ -555,6 +577,14 @@ void Part::slotGeneratorPreferences( )
} }
void Part::notifySetup( const QVector< Okular::Page * > & /*pages*/, bool documentChanged )
{
if ( !documentChanged )
return;
rebuildBookmarkMenu();
}
void Part::notifyViewportChanged( bool /*smoothMove*/ ) void Part::notifyViewportChanged( bool /*smoothMove*/ )
{ {
// update actions if the page is changed // update actions if the page is changed
...@@ -567,6 +597,14 @@ void Part::notifyViewportChanged( bool /*smoothMove*/ ) ...@@ -567,6 +597,14 @@ void Part::notifyViewportChanged( bool /*smoothMove*/ )
} }
} }
void Part::notifyPageChanged( int /*page*/, int flags )
{
if ( !(flags & Okular::DocumentObserver::Bookmark ) )
return;
rebuildBookmarkMenu();
}
void Part::goToPage(uint i) void Part::goToPage(uint i)
{ {
...@@ -1543,6 +1581,33 @@ bool Part::handleCompressed(KUrl & url, const QString &path, const KMimeType::Pt ...@@ -1543,6 +1581,33 @@ bool Part::handleCompressed(KUrl & url, const QString &path, const KMimeType::Pt
return true; return true;
} }
void Part::rebuildBookmarkMenu( bool unplugActions )
{
if ( unplugActions )
{
unplugActionList( "bookmarks_currentdocument" );
qDeleteAll( m_bookmarkActions );
m_bookmarkActions.clear();
}
KUrl u = m_document->currentDocument();
if ( u.isValid() )
{
m_bookmarkActions = m_document->bookmarkManager()->actionsForUrl( u );
}
if ( m_bookmarkActions.isEmpty() )
{
QAction * a = new QAction( 0 );
a->setText( i18n( "No Bookmarks" ) );
a->setEnabled( false );
m_bookmarkActions.append( a );
}
for ( int i = 0; i < m_bookmarkActions.count(); ++i )
{
actionCollection()->addAction( QString( "bookmark_action_%1" ).arg( i ), m_bookmarkActions.at(i) );
}
plugActionList( "bookmarks_currentdocument", m_bookmarkActions );
}
/* /*
* BrowserExtension class * BrowserExtension class
......
...@@ -85,7 +85,9 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi ...@@ -85,7 +85,9 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
// inherited from DocumentObserver // inherited from DocumentObserver
uint observerId() const { return PART_ID; } uint observerId() const { return PART_ID; }
void notifySetup( const QVector< Okular::Page * > &pages, bool documentChanged );
void notifyViewportChanged( bool smoothMove ); void notifyViewportChanged( bool smoothMove );
void notifyPageChanged( int page, int flags );
static KAboutData* createAboutData(); static KAboutData* createAboutData();
...@@ -119,6 +121,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi ...@@ -119,6 +121,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
protected slots: protected slots:
// connected to actions // connected to actions
void openUrlFromDocument(const KUrl &url); void openUrlFromDocument(const KUrl &url);
void openUrlFromBookmarks(const KUrl &url);
void slotGoToPage(); void slotGoToPage();
void slotHistoryBack(); void slotHistoryBack();
void slotHistoryNext(); void slotHistoryNext();
...@@ -158,6 +161,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi ...@@ -158,6 +161,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
void doPrint( KPrinter& printer ); void doPrint( KPrinter& printer );
void fillGenerators(); void fillGenerators();
bool handleCompressed(KUrl & url, const QString &path, const KMimeType::Ptr mimetype); bool handleCompressed(KUrl & url, const QString &path, const KMimeType::Ptr mimetype);
void rebuildBookmarkMenu( bool unplugActions = true );
KTemporaryFile *m_tempfile; KTemporaryFile *m_tempfile;
// the document // the document
...@@ -222,6 +226,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi ...@@ -222,6 +226,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
QStringList m_supportedMimeTypes; QStringList m_supportedMimeTypes;
KSelectAction * m_confGens; KSelectAction * m_confGens;
QList<Okular::ExportFormat> m_exportFormats; QList<Okular::ExportFormat> m_exportFormats;
QList<QAction*> m_bookmarkActions;
bool m_cliPresentation; bool m_cliPresentation;
private slots: private slots:
......
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="okular_part" version="20"> <kpartgui name="okular_part" version="21">
<MenuBar> <MenuBar>
<Menu name="file"><text>&amp;File</text> <Menu name="file"><text>&amp;File</text>
<Action name="get_new_stuff" group="file_open"/> <Action name="get_new_stuff" group="file_open"/>
...@@ -47,6 +47,9 @@ ...@@ -47,6 +47,9 @@
<Separator/> <Separator/>
<Action name="goto_page"/> <Action name="goto_page"/>
</Menu> </Menu>
<Menu name="okular_bookmarks"><text>&amp;Bookmarks</text>
<ActionList name="bookmarks_currentdocument" />
</Menu>
<Menu name="mouseMode"><text>&amp;Tools</text> <Menu name="mouseMode"><text>&amp;Tools</text>
<Action name="mouse_drag"/> <Action name="mouse_drag"/>
<Action name="mouse_zoom"/> <Action name="mouse_zoom"/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment