• 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
part.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2002 by Wilco Greven <greven@kde.org> *
3  * Copyright (C) 2002 by Chris Cheney <ccheney@cheney.cx> *
4  * Copyright (C) 2002 by Malcolm Hunter <malcolm.hunter@gmx.co.uk> *
5  * Copyright (C) 2003-2004 by Christophe Devriese *
6  * <Christophe.Devriese@student.kuleuven.ac.be> *
7  * Copyright (C) 2003 by Daniel Molkentin <molkentin@kde.org> *
8  * Copyright (C) 2003 by Andy Goossens <andygoossens@telenet.be> *
9  * Copyright (C) 2003 by Dirk Mueller <mueller@kde.org> *
10  * Copyright (C) 2003 by Laurent Montel <montel@kde.org> *
11  * Copyright (C) 2004 by Dominique Devriese <devriese@kde.org> *
12  * Copyright (C) 2004 by Christoph Cullmann <crossfire@babylon2k.de> *
13  * Copyright (C) 2004 by Henrique Pinto <stampede@coltec.ufmg.br> *
14  * Copyright (C) 2004 by Waldo Bastian <bastian@kde.org> *
15  * Copyright (C) 2004-2008 by Albert Astals Cid <aacid@kde.org> *
16  * Copyright (C) 2004 by Antti Markus <antti.markus@starman.ee> *
17  * *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or *
21  * (at your option) any later version. *
22  ***************************************************************************/
23 
24 #include "part.h"
25 
26 // qt/kde includes
27 #include <qapplication.h>
28 #include <qfile.h>
29 #include <qlayout.h>
30 #include <qlabel.h>
31 #include <qtimer.h>
32 #include <QtGui/QPrinter>
33 #include <QtGui/QPrintDialog>
34 #include <QScrollBar>
35 
36 #include <kvbox.h>
37 #include <kaboutapplicationdialog.h>
38 #include <kaction.h>
39 #include <kactioncollection.h>
40 #include <kdirwatch.h>
41 #include <kstandardaction.h>
42 #include <kpluginfactory.h>
43 #include <kfiledialog.h>
44 #include <kinputdialog.h>
45 #include <kmessagebox.h>
46 #include <knuminput.h>
47 #include <kio/netaccess.h>
48 #include <kmenu.h>
49 #include <kxmlguiclient.h>
50 #include <kxmlguifactory.h>
51 #include <kservicetypetrader.h>
52 #include <kstandarddirs.h>
53 #include <kstandardshortcut.h>
54 #include <ktemporaryfile.h>
55 #include <ktoggleaction.h>
56 #include <ktogglefullscreenaction.h>
57 #include <kio/job.h>
58 #include <kicon.h>
59 #include <kfilterdev.h>
60 #include <kfilterbase.h>
61 #if 0
62 #include <knewstuff2/engine.h>
63 #endif
64 #include <kdeprintdialog.h>
65 #include <kprintpreview.h>
66 #include <kbookmarkmenu.h>
67 
68 // local includes
69 #include "aboutdata.h"
70 #include "extensions.h"
71 #include "ui/pageview.h"
72 #include "ui/toc.h"
73 #include "ui/searchwidget.h"
74 #include "ui/thumbnaillist.h"
75 #include "ui/side_reviews.h"
76 #include "ui/minibar.h"
77 #include "ui/embeddedfilesdialog.h"
78 #include "ui/propertiesdialog.h"
79 #include "ui/presentationwidget.h"
80 #include "ui/pagesizelabel.h"
81 #include "ui/bookmarklist.h"
82 #include "ui/findbar.h"
83 #include "ui/sidebar.h"
84 #include "ui/fileprinterpreview.h"
85 #include "ui/guiutils.h"
86 #include "conf/preferencesdialog.h"
87 #include "settings.h"
88 #include "core/action.h"
89 #include "core/annotations.h"
90 #include "core/bookmarkmanager.h"
91 #include "core/document.h"
92 #include "core/document_p.h"
93 #include "core/generator.h"
94 #include "core/page.h"
95 #include "core/fileprinter.h"
96 
97 #include <cstdio>
98 #include <memory>
99 
100 class FileKeeper
101 {
102  public:
103  FileKeeper()
104  : m_handle( NULL )
105  {
106  }
107 
108  ~FileKeeper()
109  {
110  }
111 
112  void open( const QString & path )
113  {
114  if ( !m_handle )
115  m_handle = std::fopen( QFile::encodeName( path ), "r" );
116  }
117 
118  void close()
119  {
120  if ( m_handle )
121  {
122  int ret = std::fclose( m_handle );
123  Q_UNUSED( ret )
124  m_handle = NULL;
125  }
126  }
127 
128  KTemporaryFile* copyToTemporary() const
129  {
130  if ( !m_handle )
131  return 0;
132 
133  KTemporaryFile * retFile = new KTemporaryFile;
134  retFile->open();
135 
136  std::rewind( m_handle );
137  int c = -1;
138  do
139  {
140  c = std::fgetc( m_handle );
141  if ( c == EOF )
142  break;
143  if ( !retFile->putChar( (char)c ) )
144  break;
145  } while ( !feof( m_handle ) );
146 
147  retFile->flush();
148 
149  return retFile;
150  }
151 
152  private:
153  std::FILE * m_handle;
154 };
155 
156 Okular::PartFactory::PartFactory()
157 : KPluginFactory(okularAboutData( "okular", I18N_NOOP( "Okular" ) ))
158 {
159 }
160 
161 Okular::PartFactory::~PartFactory()
162 {
163 }
164 
165 QObject *Okular::PartFactory::create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword)
166 {
167  Q_UNUSED ( keyword );
168 
169  Okular::Part *object = new Okular::Part( parentWidget, parent, args, componentData() );
170  object->setReadWrite( QLatin1String(iface) == QLatin1String("KParts::ReadWritePart") );
171  return object;
172 }
173 
174 K_EXPORT_PLUGIN( Okular::PartFactory() )
175 
176 static QAction* actionForExportFormat( const Okular::ExportFormat& format, QObject *parent = 0 )
177 {
178  QAction *act = new QAction( format.description(), parent );
179  if ( !format.icon().isNull() )
180  {
181  act->setIcon( format.icon() );
182  }
183  return act;
184 }
185 
186 static QString compressedMimeFor( const QString& mime_to_check )
187 {
188  // The compressedMimeMap is here in case you have a very old shared mime database
189  // that doesn't have inheritance info for things like gzeps, etc
190  // Otherwise the "is()" calls below are just good enough
191  static QHash< QString, QString > compressedMimeMap;
192  static bool supportBzip = false;
193  static bool supportXz = false;
194  const QString app_gzip( QString::fromLatin1( "application/x-gzip" ) );
195  const QString app_bzip( QString::fromLatin1( "application/x-bzip" ) );
196  const QString app_xz( QString::fromLatin1( "application/x-xz" ) );
197  if ( compressedMimeMap.isEmpty() )
198  {
199  std::auto_ptr< KFilterBase > f;
200  compressedMimeMap[ QString::fromLatin1( "image/x-gzeps" ) ] = app_gzip;
201  // check we can read bzip2-compressed files
202  f.reset( KFilterBase::findFilterByMimeType( app_bzip ) );
203  if ( f.get() )
204  {
205  supportBzip = true;
206  compressedMimeMap[ QString::fromLatin1( "application/x-bzpdf" ) ] = app_bzip;
207  compressedMimeMap[ QString::fromLatin1( "application/x-bzpostscript" ) ] = app_bzip;
208  compressedMimeMap[ QString::fromLatin1( "application/x-bzdvi" ) ] = app_bzip;
209  compressedMimeMap[ QString::fromLatin1( "image/x-bzeps" ) ] = app_bzip;
210  }
211  // check we can read XZ-compressed files
212  f.reset( KFilterBase::findFilterByMimeType( app_xz ) );
213  if ( f.get() )
214  {
215  supportXz = true;
216  }
217  }
218  QHash< QString, QString >::const_iterator it = compressedMimeMap.constFind( mime_to_check );
219  if ( it != compressedMimeMap.constEnd() )
220  return it.value();
221 
222  KMimeType::Ptr mime = KMimeType::mimeType( mime_to_check );
223  if ( mime )
224  {
225  if ( mime->is( app_gzip ) )
226  return app_gzip;
227  else if ( supportBzip && mime->is( app_bzip ) )
228  return app_bzip;
229  else if ( supportXz && mime->is( app_xz ) )
230  return app_xz;
231  }
232 
233  return QString();
234 }
235 
236 static Okular::EmbedMode detectEmbedMode( QWidget *parentWidget, QObject *parent, const QVariantList &args )
237 {
238  Q_UNUSED( parentWidget );
239 
240  if ( parent
241  && ( parent->objectName() == QLatin1String( "okular::Shell" )
242  || parent->objectName() == QLatin1String( "okular/okular__Shell" ) ) )
243  return Okular::NativeShellMode;
244 
245  if ( parent
246  && ( QByteArray( "KHTMLPart" ) == parent->metaObject()->className() ) )
247  return Okular::KHTMLPartMode;
248 
249  Q_FOREACH ( const QVariant &arg, args )
250  {
251  if ( arg.type() == QVariant::String )
252  {
253  if ( arg.toString() == QLatin1String( "Print/Preview" ) )
254  {
255  return Okular::PrintPreviewMode;
256  }
257  else if ( arg.toString() == QLatin1String( "ViewerWidget" ) )
258  {
259  return Okular::ViewerWidgetMode;
260  }
261  }
262  }
263 
264  return Okular::UnknownEmbedMode;
265 }
266 
267 static QString detectConfigFileName( const QVariantList &args )
268 {
269  Q_FOREACH ( const QVariant &arg, args )
270  {
271  if ( arg.type() == QVariant::String )
272  {
273  QString argString = arg.toString();
274  int separatorIndex = argString.indexOf( "=" );
275  if ( separatorIndex >= 0 && argString.left( separatorIndex ) == QLatin1String( "ConfigFileName" ) )
276  {
277  return argString.mid( separatorIndex + 1 );
278  }
279  }
280  }
281 
282  return QString();
283 }
284 
285 #undef OKULAR_KEEP_FILE_OPEN
286 
287 #ifdef OKULAR_KEEP_FILE_OPEN
288 static bool keepFileOpen()
289 {
290  static bool keep_file_open = !qgetenv("OKULAR_NO_KEEP_FILE_OPEN").toInt();
291  return keep_file_open;
292 }
293 #endif
294 
295 int Okular::Part::numberOfParts = 0;
296 
297 namespace Okular
298 {
299 
300 Part::Part(QWidget *parentWidget,
301 QObject *parent,
302 const QVariantList &args,
303 KComponentData componentData )
304 : KParts::ReadWritePart(parent),
305 m_tempfile( 0 ), m_fileWasRemoved( false ), m_showMenuBarAction( 0 ), m_showFullScreenAction( 0 ), m_actionsSearched( false ),
306 m_cliPresentation(false), m_cliPrint(false), m_embedMode(detectEmbedMode(parentWidget, parent, args)), m_generatorGuiClient(0), m_keeper( 0 )
307 {
308  // first, we check if a config file name has been specified
309  QString configFileName = detectConfigFileName( args );
310  if ( configFileName.isEmpty() )
311  {
312  configFileName = KStandardDirs::locateLocal( "config", "okularpartrc" );
313  // first necessary step: copy the configuration from kpdf, if available
314  if ( !QFile::exists( configFileName ) )
315  {
316  QString oldkpdfconffile = KStandardDirs::locateLocal( "config", "kpdfpartrc" );
317  if ( QFile::exists( oldkpdfconffile ) )
318  QFile::copy( oldkpdfconffile, configFileName );
319  }
320  }
321  Okular::Settings::instance( configFileName );
322 
323  numberOfParts++;
324  if (numberOfParts == 1) {
325  QDBusConnection::sessionBus().registerObject("/okular", this, QDBusConnection::ExportScriptableSlots);
326  } else {
327  QDBusConnection::sessionBus().registerObject(QString("/okular%1").arg(numberOfParts), this, QDBusConnection::ExportScriptableSlots);
328  }
329 
330  // connect the started signal to tell the job the mimetypes we like,
331  // and get some more information from it
332  connect(this, SIGNAL(started(KIO::Job*)), this, SLOT(slotJobStarted(KIO::Job*)));
333 
334  // connect the completed signal so we can put the window caption when loading remote files
335  connect(this, SIGNAL(completed()), this, SLOT(setWindowTitleFromDocument()));
336  connect(this, SIGNAL(canceled(QString)), this, SLOT(loadCancelled(QString)));
337 
338  // create browser extension (for printing when embedded into browser)
339  m_bExtension = new BrowserExtension(this);
340  // create live connect extension (for integrating with browser scripting)
341  new OkularLiveConnectExtension( this );
342 
343  // we need an instance
344  setComponentData( componentData );
345 
346  GuiUtils::addIconLoader( iconLoader() );
347 
348  m_sidebar = new Sidebar( parentWidget );
349  setWidget( m_sidebar );
350 
351  // build the document
352  m_document = new Okular::Document(widget());
353  connect( m_document, SIGNAL(linkFind()), this, SLOT(slotFind()) );
354  connect( m_document, SIGNAL(linkGoToPage()), this, SLOT(slotGoToPage()) );
355  connect( m_document, SIGNAL(linkPresentation()), this, SLOT(slotShowPresentation()) );
356  connect( m_document, SIGNAL(linkEndPresentation()), this, SLOT(slotHidePresentation()) );
357  connect( m_document, SIGNAL(openUrl(KUrl)), this, SLOT(openUrlFromDocument(KUrl)) );
358  connect( m_document->bookmarkManager(), SIGNAL(openUrl(KUrl)), this, SLOT(openUrlFromBookmarks(KUrl)) );
359  connect( m_document, SIGNAL(close()), this, SLOT(close()) );
360 
361  if ( parent && parent->metaObject()->indexOfSlot( QMetaObject::normalizedSignature( "slotQuit()" ) ) != -1 )
362  connect( m_document, SIGNAL(quit()), parent, SLOT(slotQuit()) );
363  else
364  connect( m_document, SIGNAL(quit()), this, SLOT(cannotQuit()) );
365  // widgets: ^searchbar (toolbar containing label and SearchWidget)
366  // m_searchToolBar = new KToolBar( parentWidget, "searchBar" );
367  // m_searchToolBar->boxLayout()->setSpacing( KDialog::spacingHint() );
368  // QLabel * sLabel = new QLabel( i18n( "&Search:" ), m_searchToolBar, "kde toolbar widget" );
369  // m_searchWidget = new SearchWidget( m_searchToolBar, m_document );
370  // sLabel->setBuddy( m_searchWidget );
371  // m_searchToolBar->setStretchableWidget( m_searchWidget );
372 
373  int tbIndex;
374  // [left toolbox: Table of Contents] | []
375  m_toc = new TOC( 0, m_document );
376  connect( m_toc, SIGNAL(hasTOC(bool)), this, SLOT(enableTOC(bool)) );
377  tbIndex = m_sidebar->addItem( m_toc, KIcon(QApplication::isLeftToRight() ? "format-justify-left" : "format-justify-right"), i18n("Contents") );
378  enableTOC( false );
379 
380  // [left toolbox: Thumbnails and Bookmarks] | []
381  KVBox * thumbsBox = new ThumbnailsBox( 0 );
382  thumbsBox->setSpacing( 6 );
383  m_searchWidget = new SearchWidget( thumbsBox, m_document );
384  m_thumbnailList = new ThumbnailList( thumbsBox, m_document );
385  // ThumbnailController * m_tc = new ThumbnailController( thumbsBox, m_thumbnailList );
386  connect( m_thumbnailList, SIGNAL(urlDropped(KUrl)), SLOT(openUrlFromDocument(KUrl)) );
387  connect( m_thumbnailList, SIGNAL(rightClick(const Okular::Page*,QPoint)), this, SLOT(slotShowMenu(const Okular::Page*,QPoint)) );
388  tbIndex = m_sidebar->addItem( thumbsBox, KIcon( "view-preview" ), i18n("Thumbnails") );
389  m_sidebar->setCurrentIndex( tbIndex );
390 
391  // [left toolbox: Reviews] | []
392  m_reviewsWidget = new Reviews( 0, m_document );
393  m_sidebar->addItem( m_reviewsWidget, KIcon("draw-freehand"), i18n("Reviews") );
394  m_sidebar->setItemEnabled( 2, false );
395 
396  // [left toolbox: Bookmarks] | []
397  m_bookmarkList = new BookmarkList( m_document, 0 );
398  m_sidebar->addItem( m_bookmarkList, KIcon("bookmarks"), i18n("Bookmarks") );
399  m_sidebar->setItemEnabled( 3, false );
400 
401  // widgets: [../miniBarContainer] | []
402 #ifdef OKULAR_ENABLE_MINIBAR
403  QWidget * miniBarContainer = new QWidget( 0 );
404  m_sidebar->setBottomWidget( miniBarContainer );
405  QVBoxLayout * miniBarLayout = new QVBoxLayout( miniBarContainer );
406  miniBarLayout->setMargin( 0 );
407  // widgets: [../[spacer/..]] | []
408  miniBarLayout->addItem( new QSpacerItem( 6, 6, QSizePolicy::Fixed, QSizePolicy::Fixed ) );
409  // widgets: [../[../MiniBar]] | []
410  QFrame * bevelContainer = new QFrame( miniBarContainer );
411  bevelContainer->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
412  QVBoxLayout * bevelContainerLayout = new QVBoxLayout( bevelContainer );
413  bevelContainerLayout->setMargin( 4 );
414  m_progressWidget = new ProgressWidget( bevelContainer, m_document );
415  bevelContainerLayout->addWidget( m_progressWidget );
416  miniBarLayout->addWidget( bevelContainer );
417  miniBarLayout->addItem( new QSpacerItem( 6, 6, QSizePolicy::Fixed, QSizePolicy::Fixed ) );
418 #endif
419 
420  // widgets: [] | [right 'pageView']
421  QWidget * rightContainer = new QWidget( 0 );
422  m_sidebar->setMainWidget( rightContainer );
423  QVBoxLayout * rightLayout = new QVBoxLayout( rightContainer );
424  rightLayout->setMargin( 0 );
425  rightLayout->setSpacing( 0 );
426  // KToolBar * rtb = new KToolBar( rightContainer, "mainToolBarSS" );
427  // rightLayout->addWidget( rtb );
428  m_topMessage = new PageViewTopMessage( rightContainer );
429  m_topMessage->setup( i18n( "This document has embedded files. <a href=\"okular:/embeddedfiles\">Click here to see them</a> or go to File -> Embedded Files." ), KIcon( "mail-attachment" ) );
430  connect( m_topMessage, SIGNAL(action()), this, SLOT(slotShowEmbeddedFiles()) );
431  rightLayout->addWidget( m_topMessage );
432  m_formsMessage = new PageViewTopMessage( rightContainer );
433  rightLayout->addWidget( m_formsMessage );
434  m_pageView = new PageView( rightContainer, m_document );
435  m_document->d->m_tiledObserver = m_pageView;
436  QMetaObject::invokeMethod( m_pageView, "setFocus", Qt::QueuedConnection ); //usability setting
437 // m_splitter->setFocusProxy(m_pageView);
438  connect( m_pageView, SIGNAL(urlDropped(KUrl)), SLOT(openUrlFromDocument(KUrl)));
439  connect( m_pageView, SIGNAL(rightClick(const Okular::Page*,QPoint)), this, SLOT(slotShowMenu(const Okular::Page*,QPoint)) );
440  connect( m_document, SIGNAL(error(QString,int)), m_pageView, SLOT(errorMessage(QString,int)) );
441  connect( m_document, SIGNAL(warning(QString,int)), m_pageView, SLOT(warningMessage(QString,int)) );
442  connect( m_document, SIGNAL(notice(QString,int)), m_pageView, SLOT(noticeMessage(QString,int)) );
443  connect( m_document, SIGNAL(sourceReferenceActivated(const QString&,int,int,bool*)), this, SLOT(slotHandleActivatedSourceReference(const QString&,int,int,bool*)) );
444  rightLayout->addWidget( m_pageView );
445  m_findBar = new FindBar( m_document, rightContainer );
446  rightLayout->addWidget( m_findBar );
447  m_bottomBar = new QWidget( rightContainer );
448  QHBoxLayout * bottomBarLayout = new QHBoxLayout( m_bottomBar );
449  m_pageSizeLabel = new PageSizeLabel( m_bottomBar, m_document );
450  bottomBarLayout->setMargin( 0 );
451  bottomBarLayout->setSpacing( 0 );
452  bottomBarLayout->addWidget( m_pageSizeLabel->antiWidget() );
453  bottomBarLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
454  m_miniBarLogic = new MiniBarLogic( this, m_document );
455  m_miniBar = new MiniBar( m_bottomBar, m_miniBarLogic );
456  bottomBarLayout->addWidget( m_miniBar );
457  bottomBarLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
458  bottomBarLayout->addWidget( m_pageSizeLabel );
459  rightLayout->addWidget( m_bottomBar );
460 
461  m_pageNumberTool = new MiniBar( 0, m_miniBarLogic );
462 
463  connect( m_findBar, SIGNAL(forwardKeyPressEvent(QKeyEvent*)), m_pageView, SLOT(externalKeyPressEvent(QKeyEvent*)));
464  connect( m_miniBar, SIGNAL(forwardKeyPressEvent(QKeyEvent*)), m_pageView, SLOT(externalKeyPressEvent(QKeyEvent*)));
465  connect( m_pageView, SIGNAL(escPressed()), m_findBar, SLOT(resetSearch()) );
466  connect( m_pageNumberTool, SIGNAL(forwardKeyPressEvent(QKeyEvent*)), m_pageView, SLOT(externalKeyPressEvent(QKeyEvent*)));
467 
468  connect( m_reviewsWidget, SIGNAL(openAnnotationWindow(Okular::Annotation*,int)),
469  m_pageView, SLOT(openAnnotationWindow(Okular::Annotation*,int)) );
470 
471  // add document observers
472  m_document->addObserver( this );
473  m_document->addObserver( m_thumbnailList );
474  m_document->addObserver( m_pageView );
475  m_document->registerView( m_pageView );
476  m_document->addObserver( m_toc );
477  m_document->addObserver( m_miniBarLogic );
478 #ifdef OKULAR_ENABLE_MINIBAR
479  m_document->addObserver( m_progressWidget );
480 #endif
481  m_document->addObserver( m_reviewsWidget );
482  m_document->addObserver( m_pageSizeLabel );
483  m_document->addObserver( m_bookmarkList );
484 
485  connect( m_document->bookmarkManager(), SIGNAL(saved()),
486  this, SLOT(slotRebuildBookmarkMenu()) );
487 
488  setupViewerActions();
489 
490  if ( m_embedMode != ViewerWidgetMode )
491  {
492  setupActions();
493  }
494  else
495  {
496  setViewerShortcuts();
497  }
498 
499  // document watcher and reloader
500  m_watcher = new KDirWatch( this );
501  connect( m_watcher, SIGNAL(dirty(QString)), this, SLOT(slotFileDirty(QString)) );
502  m_dirtyHandler = new QTimer( this );
503  m_dirtyHandler->setSingleShot( true );
504  connect( m_dirtyHandler, SIGNAL(timeout()),this, SLOT(slotDoFileDirty()) );
505 
506  slotNewConfig();
507 
508  // keep us informed when the user changes settings
509  connect( Okular::Settings::self(), SIGNAL(configChanged()), this, SLOT(slotNewConfig()) );
510 
511  // [SPEECH] check for KTTSD presence and usability
512  const KService::Ptr kttsd = KService::serviceByDesktopName("kttsd");
513  Okular::Settings::setUseKTTSD( kttsd );
514  Okular::Settings::self()->writeConfig();
515 
516  rebuildBookmarkMenu( false );
517 
518  if ( m_embedMode == ViewerWidgetMode ) {
519  // set the XML-UI resource file for the viewer mode
520  setXMLFile("part-viewermode.rc");
521  }
522  else
523  {
524  // set our main XML-UI resource file
525  setXMLFile("part.rc");
526  }
527 
528  m_pageView->setupBaseActions( actionCollection() );
529 
530  m_sidebar->setSidebarVisibility( false );
531  if ( m_embedMode != PrintPreviewMode )
532  {
533  // now set up actions that are required for all remaining modes
534  m_pageView->setupViewerActions( actionCollection() );
535  // and if we are not in viewer mode, we want the full GUI
536  if ( m_embedMode != ViewerWidgetMode )
537  {
538  unsetDummyMode();
539  }
540  }
541 
542  // ensure history actions are in the correct state
543  updateViewActions();
544 
545  // also update the state of the actions in the page view
546  m_pageView->updateActionState( false, false, false );
547 
548  if ( m_embedMode == NativeShellMode )
549  m_sidebar->setAutoFillBackground( false );
550 
551 #ifdef OKULAR_KEEP_FILE_OPEN
552  m_keeper = new FileKeeper();
553 #endif
554 }
555 
556 void Part::setupViewerActions()
557 {
558  // ACTIONS
559  KActionCollection * ac = actionCollection();
560 
561  // Page Traversal actions
562  m_gotoPage = KStandardAction::gotoPage( this, SLOT(slotGoToPage()), ac );
563  m_gotoPage->setShortcut( QKeySequence(Qt::CTRL + Qt::Key_G) );
564  // dirty way to activate gotopage when pressing miniBar's button
565  connect( m_miniBar, SIGNAL(gotoPage()), m_gotoPage, SLOT(trigger()) );
566  connect( m_pageNumberTool, SIGNAL(gotoPage()), m_gotoPage, SLOT(trigger()) );
567 
568  m_prevPage = KStandardAction::prior(this, SLOT(slotPreviousPage()), ac);
569  m_prevPage->setIconText( i18nc( "Previous page", "Previous" ) );
570  m_prevPage->setToolTip( i18n( "Go back to the Previous Page" ) );
571  m_prevPage->setWhatsThis( i18n( "Moves to the previous page of the document" ) );
572  m_prevPage->setShortcut( 0 );
573  // dirty way to activate prev page when pressing miniBar's button
574  connect( m_miniBar, SIGNAL(prevPage()), m_prevPage, SLOT(trigger()) );
575  connect( m_pageNumberTool, SIGNAL(prevPage()), m_prevPage, SLOT(trigger()) );
576 #ifdef OKULAR_ENABLE_MINIBAR
577  connect( m_progressWidget, SIGNAL(prevPage()), m_prevPage, SLOT(trigger()) );
578 #endif
579 
580  m_nextPage = KStandardAction::next(this, SLOT(slotNextPage()), ac );
581  m_nextPage->setIconText( i18nc( "Next page", "Next" ) );
582  m_nextPage->setToolTip( i18n( "Advance to the Next Page" ) );
583  m_nextPage->setWhatsThis( i18n( "Moves to the next page of the document" ) );
584  m_nextPage->setShortcut( 0 );
585  // dirty way to activate next page when pressing miniBar's button
586  connect( m_miniBar, SIGNAL(nextPage()), m_nextPage, SLOT(trigger()) );
587  connect( m_pageNumberTool, SIGNAL(nextPage()), m_nextPage, SLOT(trigger()) );
588 #ifdef OKULAR_ENABLE_MINIBAR
589  connect( m_progressWidget, SIGNAL(nextPage()), m_nextPage, SLOT(trigger()) );
590 #endif
591 
592  m_beginningOfDocument = KStandardAction::firstPage( this, SLOT(slotGotoFirst()), ac );
593  ac->addAction("first_page", m_beginningOfDocument);
594  m_beginningOfDocument->setText(i18n( "Beginning of the document"));
595  m_beginningOfDocument->setWhatsThis( i18n( "Moves to the beginning of the document" ) );
596 
597  m_endOfDocument = KStandardAction::lastPage( this, SLOT(slotGotoLast()), ac );
598  ac->addAction("last_page",m_endOfDocument);
599  m_endOfDocument->setText(i18n( "End of the document"));
600  m_endOfDocument->setWhatsThis( i18n( "Moves to the end of the document" ) );
601 
602  // we do not want back and next in history in the dummy mode
603  m_historyBack = 0;
604  m_historyNext = 0;
605 
606  m_addBookmark = KStandardAction::addBookmark( this, SLOT(slotAddBookmark()), ac );
607  m_addBookmarkText = m_addBookmark->text();
608  m_addBookmarkIcon = m_addBookmark->icon();
609 
610  m_renameBookmark = ac->addAction("rename_bookmark");
611  m_renameBookmark->setText(i18n( "Rename Bookmark" ));
612  m_renameBookmark->setIcon(KIcon( "edit-rename" ));
613  m_renameBookmark->setWhatsThis( i18n( "Rename the current bookmark" ) );
614  connect( m_renameBookmark, SIGNAL(triggered()), this, SLOT(slotRenameCurrentViewportBookmark()) );
615 
616  m_prevBookmark = ac->addAction("previous_bookmark");
617  m_prevBookmark->setText(i18n( "Previous Bookmark" ));
618  m_prevBookmark->setIcon(KIcon( "go-up-search" ));
619  m_prevBookmark->setWhatsThis( i18n( "Go to the previous bookmark" ) );
620  connect( m_prevBookmark, SIGNAL(triggered()), this, SLOT(slotPreviousBookmark()) );
621 
622  m_nextBookmark = ac->addAction("next_bookmark");
623  m_nextBookmark->setText(i18n( "Next Bookmark" ));
624  m_nextBookmark->setIcon(KIcon( "go-down-search" ));
625  m_nextBookmark->setWhatsThis( i18n( "Go to the next bookmark" ) );
626  connect( m_nextBookmark, SIGNAL(triggered()), this, SLOT(slotNextBookmark()) );
627 
628  m_copy = 0;
629 
630  m_selectAll = 0;
631 
632  // Find and other actions
633  m_find = KStandardAction::find( this, SLOT(slotShowFindBar()), ac );
634  QList<QKeySequence> s = m_find->shortcuts();
635  s.append( QKeySequence( Qt::Key_Slash ) );
636  m_find->setShortcuts( s );
637  m_find->setEnabled( false );
638 
639  m_findNext = KStandardAction::findNext( this, SLOT(slotFindNext()), ac);
640  m_findNext->setEnabled( false );
641 
642  m_findPrev = KStandardAction::findPrev( this, SLOT(slotFindPrev()), ac );
643  m_findPrev->setEnabled( false );
644 
645  m_saveCopyAs = 0;
646  m_saveAs = 0;
647 
648  QAction * prefs = KStandardAction::preferences( this, SLOT(slotPreferences()), ac);
649  if ( m_embedMode == NativeShellMode )
650  {
651  prefs->setText( i18n( "Configure Okular..." ) );
652  }
653  else
654  {
655  // TODO: improve this message
656  prefs->setText( i18n( "Configure Viewer..." ) );
657  }
658 
659  KAction * genPrefs = new KAction( ac );
660  ac->addAction("options_configure_generators", genPrefs);
661  if ( m_embedMode == ViewerWidgetMode )
662  {
663  genPrefs->setText( i18n( "Configure Viewer Backends..." ) );
664  }
665  else
666  {
667  genPrefs->setText( i18n( "Configure Backends..." ) );
668  }
669  genPrefs->setIcon( KIcon( "configure" ) );
670  genPrefs->setEnabled( m_document->configurableGenerators() > 0 );
671  connect( genPrefs, SIGNAL(triggered(bool)), this, SLOT(slotGeneratorPreferences()) );
672 
673  m_printPreview = KStandardAction::printPreview( this, SLOT(slotPrintPreview()), ac );
674  m_printPreview->setEnabled( false );
675 
676  m_showLeftPanel = 0;
677  m_showBottomBar = 0;
678 
679  m_showProperties = ac->addAction("properties");
680  m_showProperties->setText(i18n("&Properties"));
681  m_showProperties->setIcon(KIcon("document-properties"));
682  connect(m_showProperties, SIGNAL(triggered()), this, SLOT(slotShowProperties()));
683  m_showProperties->setEnabled( false );
684 
685  m_showEmbeddedFiles = 0;
686  m_showPresentation = 0;
687 
688  m_exportAs = 0;
689  m_exportAsMenu = 0;
690  m_exportAsText = 0;
691  m_exportAsDocArchive = 0;
692 
693  m_aboutBackend = ac->addAction("help_about_backend");
694  m_aboutBackend->setText(i18n("About Backend"));
695  m_aboutBackend->setEnabled( false );
696  connect(m_aboutBackend, SIGNAL(triggered()), this, SLOT(slotAboutBackend()));
697 
698  KAction *reload = ac->add<KAction>( "file_reload" );
699  reload->setText( i18n( "Reloa&d" ) );
700  reload->setIcon( KIcon( "view-refresh" ) );
701  reload->setWhatsThis( i18n( "Reload the current document from disk." ) );
702  connect( reload, SIGNAL(triggered()), this, SLOT(slotReload()) );
703  reload->setShortcut( KStandardShortcut::reload() );
704  m_reload = reload;
705 
706  m_closeFindBar = new KAction( i18n( "Close &Find Bar" ), ac );
707  ac->addAction("close_find_bar", m_closeFindBar);
708  connect(m_closeFindBar, SIGNAL(triggered()), this, SLOT(slotHideFindBar()));
709  widget()->addAction(m_closeFindBar);
710 
711  KAction *pageno = new KAction( i18n( "Page Number" ), ac );
712  pageno->setDefaultWidget( m_pageNumberTool );
713  ac->addAction( "page_number", pageno );
714 }
715 
716 void Part::setViewerShortcuts()
717 {
718  KActionCollection * ac = actionCollection();
719 
720  m_gotoPage->setShortcut( QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_G) );
721  m_find->setShortcuts( QList<QKeySequence>() );
722 
723  m_findNext->setShortcut( QKeySequence() );
724  m_findPrev->setShortcut( QKeySequence() );
725 
726  m_addBookmark->setShortcut( QKeySequence( Qt::CTRL + Qt::ALT + Qt::Key_B ) );
727 
728  m_beginningOfDocument->setShortcut( QKeySequence( Qt::CTRL + Qt::ALT + Qt::Key_Home ) );
729  m_endOfDocument->setShortcut( QKeySequence( Qt::CTRL + Qt::ALT + Qt::Key_End ) );
730 
731  KAction *action = static_cast<KAction*>( ac->action( "file_reload" ) );
732  if( action ) action->setShortcuts( QList<QKeySequence>() << QKeySequence( Qt::ALT + Qt::Key_F5 ) );
733 }
734 
735 void Part::setupActions()
736 {
737  KActionCollection * ac = actionCollection();
738 
739  m_copy = KStandardAction::create( KStandardAction::Copy, m_pageView, SLOT(copyTextSelection()), ac );
740 
741  m_selectAll = KStandardAction::selectAll( m_pageView, SLOT(selectAll()), ac );
742 
743  m_saveCopyAs = KStandardAction::saveAs( this, SLOT(slotSaveCopyAs()), ac );
744  m_saveCopyAs->setText( i18n( "Save &Copy As..." ) );
745  m_saveCopyAs->setShortcut( KShortcut() );
746  ac->addAction( "file_save_copy", m_saveCopyAs );
747  m_saveCopyAs->setEnabled( false );
748 
749  m_saveAs = KStandardAction::saveAs( this, SLOT(slotSaveFileAs()), ac );
750  m_saveAs->setEnabled( false );
751 
752  m_showLeftPanel = ac->add<KToggleAction>("show_leftpanel");
753  m_showLeftPanel->setText(i18n( "Show &Navigation Panel"));
754  m_showLeftPanel->setIcon(KIcon( "view-sidetree" ));
755  connect( m_showLeftPanel, SIGNAL(toggled(bool)), this, SLOT(slotShowLeftPanel()) );
756  m_showLeftPanel->setShortcut( Qt::Key_F7 );
757  m_showLeftPanel->setChecked( Okular::Settings::showLeftPanel() );
758  slotShowLeftPanel();
759 
760  m_showBottomBar = ac->add<KToggleAction>("show_bottombar");
761  m_showBottomBar->setText(i18n( "Show &Page Bar"));
762  connect( m_showBottomBar, SIGNAL(toggled(bool)), this, SLOT(slotShowBottomBar()) );
763  m_showBottomBar->setChecked( Okular::Settings::showBottomBar() );
764  slotShowBottomBar();
765 
766  m_showEmbeddedFiles = ac->addAction("embedded_files");
767  m_showEmbeddedFiles->setText(i18n("&Embedded Files"));
768  m_showEmbeddedFiles->setIcon( KIcon( "mail-attachment" ) );
769  connect(m_showEmbeddedFiles, SIGNAL(triggered()), this, SLOT(slotShowEmbeddedFiles()));
770  m_showEmbeddedFiles->setEnabled( false );
771 
772  m_exportAs = ac->addAction("file_export_as");
773  m_exportAs->setText(i18n("E&xport As"));
774  m_exportAs->setIcon( KIcon( "document-export" ) );
775  m_exportAsMenu = new QMenu();
776  connect(m_exportAsMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotExportAs(QAction*)));
777  m_exportAs->setMenu( m_exportAsMenu );
778  m_exportAsText = actionForExportFormat( Okular::ExportFormat::standardFormat( Okular::ExportFormat::PlainText ), m_exportAsMenu );
779  m_exportAsMenu->addAction( m_exportAsText );
780  m_exportAs->setEnabled( false );
781  m_exportAsText->setEnabled( false );
782  m_exportAsDocArchive = actionForExportFormat( Okular::ExportFormat(
783  i18nc( "A document format, Okular-specific", "Document Archive" ),
784  KMimeType::mimeType( "application/vnd.kde.okular-archive" ) ), m_exportAsMenu );
785  m_exportAsMenu->addAction( m_exportAsDocArchive );
786  m_exportAsDocArchive->setEnabled( false );
787 
788  m_showPresentation = ac->addAction("presentation");
789  m_showPresentation->setText(i18n("P&resentation"));
790  m_showPresentation->setIcon( KIcon( "view-presentation" ) );
791  connect(m_showPresentation, SIGNAL(triggered()), this, SLOT(slotShowPresentation()));
792  m_showPresentation->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_P ) );
793  m_showPresentation->setEnabled( false );
794 
795  QAction * importPS = ac->addAction("import_ps");
796  importPS->setText(i18n("&Import PostScript as PDF..."));
797  importPS->setIcon(KIcon("document-import"));
798  connect(importPS, SIGNAL(triggered()), this, SLOT(slotImportPSFile()));
799 #if 0
800  QAction * ghns = ac->addAction("get_new_stuff");
801  ghns->setText(i18n("&Get Books From Internet..."));
802  ghns->setIcon(KIcon("get-hot-new-stuff"));
803  connect(ghns, SIGNAL(triggered()), this, SLOT(slotGetNewStuff()));
804  // TEMP, REMOVE ME!
805  ghns->setShortcut( Qt::Key_G );
806 #endif
807 
808  KToggleAction *blackscreenAction = new KToggleAction( i18n( "Switch Blackscreen Mode" ), ac );
809  ac->addAction( "switch_blackscreen_mode", blackscreenAction );
810  blackscreenAction->setShortcut( QKeySequence( Qt::Key_B ) );
811  blackscreenAction->setIcon( KIcon( "view-presentation" ) );
812  blackscreenAction->setEnabled( false );
813 
814  KToggleAction *drawingAction = new KToggleAction( i18n( "Toggle Drawing Mode" ), ac );
815  ac->addAction( "presentation_drawing_mode", drawingAction );
816  drawingAction->setIcon( KIcon( "draw-freehand" ) );
817  drawingAction->setEnabled( false );
818 
819  KAction *eraseDrawingAction = new KAction( i18n( "Erase Drawings" ), ac );
820  ac->addAction( "presentation_erase_drawings", eraseDrawingAction );
821  eraseDrawingAction->setIcon( KIcon( "draw-eraser" ) );
822  eraseDrawingAction->setEnabled( false );
823 
824  KAction *configureAnnotations = new KAction( i18n( "Configure Annotations..." ), ac );
825  ac->addAction( "options_configure_annotations", configureAnnotations );
826  configureAnnotations->setIcon( KIcon( "configure" ) );
827  connect(configureAnnotations, SIGNAL(triggered()), this, SLOT(slotAnnotationPreferences()));
828 }
829 
830 Part::~Part()
831 {
832  GuiUtils::removeIconLoader( iconLoader() );
833  m_document->removeObserver( this );
834 
835  if ( m_document->isOpened() )
836  Part::closeUrl( false );
837 
838  delete m_toc;
839  delete m_pageView;
840  delete m_thumbnailList;
841  delete m_miniBar;
842  delete m_pageNumberTool;
843  delete m_miniBarLogic;
844  delete m_bottomBar;
845 #ifdef OKULAR_ENABLE_MINIBAR
846  delete m_progressWidget;
847 #endif
848  delete m_pageSizeLabel;
849  delete m_reviewsWidget;
850  delete m_bookmarkList;
851 
852  delete m_document;
853 
854  delete m_tempfile;
855 
856  qDeleteAll( m_bookmarkActions );
857 
858  delete m_exportAsMenu;
859 
860 #ifdef OKULAR_KEEP_FILE_OPEN
861  delete m_keeper;
862 #endif
863 }
864 
865 
866 bool Part::openDocument(const KUrl& url, uint page)
867 {
868  Okular::DocumentViewport vp( page - 1 );
869  vp.rePos.enabled = true;
870  vp.rePos.normalizedX = 0;
871  vp.rePos.normalizedY = 0;
872  vp.rePos.pos = Okular::DocumentViewport::TopLeft;
873  if ( vp.isValid() )
874  m_document->setNextDocumentViewport( vp );
875  return openUrl( url );
876 }
877 
878 
879 void Part::startPresentation()
880 {
881  m_cliPresentation = true;
882 }
883 
884 
885 QStringList Part::supportedMimeTypes() const
886 {
887  return m_document->supportedMimeTypes();
888 }
889 
890 
891 KUrl Part::realUrl() const
892 {
893  if ( !m_realUrl.isEmpty() )
894  return m_realUrl;
895 
896  return url();
897 }
898 
899 // ViewerInterface
900 
901 void Part::showSourceLocation(const QString& fileName, int line, int column, bool showGraphically)
902 {
903  const QString u = QString( "src:%1 %2" ).arg( line + 1 ).arg( fileName );
904  GotoAction action( QString(), u );
905  m_document->processAction( &action );
906  if( showGraphically )
907  {
908  m_pageView->setLastSourceLocationViewport( m_document->viewport() );
909  }
910 }
911 
912 void Part::clearLastShownSourceLocation()
913 {
914  m_pageView->clearLastSourceLocationViewport();
915 }
916 
917 bool Part::isWatchFileModeEnabled() const
918 {
919  return !m_watcher->isStopped();
920 }
921 
922 void Part::setWatchFileModeEnabled(bool enabled)
923 {
924  if ( enabled && m_watcher->isStopped() )
925  {
926  m_watcher->startScan();
927  }
928  else if( !enabled && !m_watcher->isStopped() )
929  {
930  m_dirtyHandler->stop();
931  m_watcher->stopScan();
932  }
933 }
934 
935 bool Part::areSourceLocationsShownGraphically() const
936 {
937  return m_pageView->areSourceLocationsShownGraphically();
938 }
939 
940 void Part::setShowSourceLocationsGraphically(bool show)
941 {
942  m_pageView->setShowSourceLocationsGraphically(show);
943 }
944 
945 void Part::slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled)
946 {
947  emit openSourceReference( absFileName, line, col );
948  if ( m_embedMode == Okular::ViewerWidgetMode )
949  {
950  *handled = true;
951  }
952 }
953 
954 void Part::openUrlFromDocument(const KUrl &url)
955 {
956  if ( m_embedMode == PrintPreviewMode )
957  return;
958 
959  if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, widget()))
960  {
961  m_bExtension->openUrlNotify();
962  m_bExtension->setLocationBarUrl(url.prettyUrl());
963  openUrl(url);
964  } else {
965  KMessageBox::error( widget(), i18n("Could not open '%1'. File does not exist", url.pathOrUrl() ) );
966  }
967 }
968 
969 void Part::openUrlFromBookmarks(const KUrl &_url)
970 {
971  KUrl url = _url;
972  Okular::DocumentViewport vp( _url.htmlRef() );
973  if ( vp.isValid() )
974  m_document->setNextDocumentViewport( vp );
975  url.setHTMLRef( QString() );
976  if ( m_document->currentDocument() == url )
977  {
978  if ( vp.isValid() )
979  m_document->setViewport( vp );
980  }
981  else
982  openUrl( url );
983 }
984 
985 void Part::slotJobStarted(KIO::Job *job)
986 {
987  if (job)
988  {
989  QStringList supportedMimeTypes = m_document->supportedMimeTypes();
990  job->addMetaData("accept", supportedMimeTypes.join(", ") + ", */*;q=0.5");
991 
992  connect(job, SIGNAL(result(KJob*)), this, SLOT(slotJobFinished(KJob*)));
993  }
994 }
995 
996 void Part::slotJobFinished(KJob *job)
997 {
998  if ( job->error() == KIO::ERR_USER_CANCELED )
999  {
1000  m_pageView->noticeMessage( i18n( "The loading of %1 has been canceled.", realUrl().pathOrUrl() ) );
1001  }
1002 }
1003 
1004 void Part::loadCancelled(const QString &reason)
1005 {
1006  emit setWindowCaption( QString() );
1007  resetStartArguments();
1008 
1009  // when m_viewportDirty.pageNumber != -1 we come from slotDoFileDirty
1010  // so we don't want to show an ugly messagebox just because the document is
1011  // taking more than usual to be recreated
1012  if (m_viewportDirty.pageNumber == -1)
1013  {
1014  if (!reason.isEmpty())
1015  {
1016  KMessageBox::error( widget(), i18n("Could not open %1. Reason: %2", url().prettyUrl(), reason ) );
1017  }
1018  }
1019 }
1020 
1021 void Part::setWindowTitleFromDocument()
1022 {
1023  // If 'DocumentTitle' should be used, check if the document has one. If
1024  // either case is false, use the file name.
1025  QString title = Okular::Settings::displayDocumentNameOrPath() == Okular::Settings::EnumDisplayDocumentNameOrPath::Path ? realUrl().pathOrUrl() : realUrl().fileName();
1026 
1027  if ( Okular::Settings::displayDocumentTitle() )
1028  {
1029  const QString docTitle = m_document->metaData( "DocumentTitle" ).toString();
1030  if ( !docTitle.isEmpty() && !docTitle.trimmed().isEmpty() )
1031  {
1032  title = docTitle;
1033  }
1034  }
1035 
1036  emit setWindowCaption( title );
1037 }
1038 
1039 KConfigDialog * Part::slotGeneratorPreferences( )
1040 {
1041  // Create dialog
1042  KConfigDialog * dialog = new KConfigDialog( m_pageView, "generator_prefs", Okular::Settings::self() );
1043  dialog->setAttribute( Qt::WA_DeleteOnClose );
1044 
1045  if( m_embedMode == ViewerWidgetMode )
1046  {
1047  dialog->setCaption( i18n( "Configure Viewer Backends" ) );
1048  }
1049  else
1050  {
1051  dialog->setCaption( i18n( "Configure Backends" ) );
1052  }
1053 
1054  m_document->fillConfigDialog( dialog );
1055 
1056  // Show it
1057  dialog->setWindowModality( Qt::ApplicationModal );
1058  dialog->show();
1059 
1060  return dialog;
1061 }
1062 
1063 
1064 void Part::notifySetup( const QVector< Okular::Page * > & /*pages*/, int setupFlags )
1065 {
1066  if ( !( setupFlags & Okular::DocumentObserver::DocumentChanged ) )
1067  return;
1068 
1069  rebuildBookmarkMenu();
1070  updateAboutBackendAction();
1071  m_findBar->resetSearch();
1072  m_searchWidget->setEnabled( m_document->supportsSearching() );
1073 }
1074 
1075 void Part::notifyViewportChanged( bool /*smoothMove*/ )
1076 {
1077  updateViewActions();
1078 }
1079 
1080 void Part::notifyPageChanged( int page, int flags )
1081 {
1082  if ( flags & Okular::DocumentObserver::NeedSaveAs )
1083  setModified();
1084 
1085  if ( !(flags & Okular::DocumentObserver::Bookmark ) )
1086  return;
1087 
1088  rebuildBookmarkMenu();
1089  if ( page == m_document->viewport().pageNumber )
1090  updateBookmarksActions();
1091 }
1092 
1093 
1094 void Part::goToPage(uint i)
1095 {
1096  if ( i <= m_document->pages() )
1097  m_document->setViewportPage( i - 1 );
1098 }
1099 
1100 
1101 void Part::openDocument( const QString &doc )
1102 {
1103  openUrl( KUrl( doc ) );
1104 }
1105 
1106 
1107 uint Part::pages()
1108 {
1109  return m_document->pages();
1110 }
1111 
1112 
1113 uint Part::currentPage()
1114 {
1115  return m_document->pages() ? m_document->currentPage() + 1 : 0;
1116 }
1117 
1118 
1119 QString Part::currentDocument()
1120 {
1121  return m_document->currentDocument().pathOrUrl();
1122 }
1123 
1124 
1125 QString Part::documentMetaData( const QString &metaData ) const
1126 {
1127  const Okular::DocumentInfo * info = m_document->documentInfo();
1128  if ( info )
1129  {
1130  QDomElement docElement = info->documentElement();
1131  for ( QDomNode node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() )
1132  {
1133  const QDomElement element = node.toElement();
1134  if ( metaData.compare( element.tagName(), Qt::CaseInsensitive ) == 0 )
1135  return element.attribute( "value" );
1136  }
1137  }
1138 
1139  return QString();
1140 }
1141 
1142 
1143 bool Part::slotImportPSFile()
1144 {
1145  QString app = KStandardDirs::findExe( "ps2pdf" );
1146  if ( app.isEmpty() )
1147  {
1148  // TODO point the user to their distro packages?
1149  KMessageBox::error( widget(), i18n( "The program \"ps2pdf\" was not found, so Okular can not import PS files using it." ), i18n("ps2pdf not found") );
1150  return false;
1151  }
1152 
1153  KUrl url = KFileDialog::getOpenUrl( KUrl(), "application/postscript", this->widget() );
1154  if ( url.isLocalFile() )
1155  {
1156  KTemporaryFile tf;
1157  tf.setSuffix( ".pdf" );
1158  tf.setAutoRemove( false );
1159  if ( !tf.open() )
1160  return false;
1161  m_temporaryLocalFile = tf.fileName();
1162  tf.close();
1163 
1164  setLocalFilePath( url.toLocalFile() );
1165  QStringList args;
1166  QProcess *p = new QProcess();
1167  args << url.toLocalFile() << m_temporaryLocalFile;
1168  m_pageView->displayMessage(i18n("Importing PS file as PDF (this may take a while)..."));
1169  connect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(psTransformEnded(int,QProcess::ExitStatus)));
1170  p->start(app, args);
1171  return true;
1172  }
1173 
1174  m_temporaryLocalFile.clear();
1175  return false;
1176 }
1177 
1178 static void addFileToWatcher( KDirWatch *watcher, const QString &filePath)
1179 {
1180  if ( !watcher->contains( filePath ) ) watcher->addFile(filePath);
1181  const QFileInfo fi(filePath);
1182  if ( !watcher->contains( fi.absolutePath() ) ) watcher->addDir(fi.absolutePath());
1183  if ( fi.isSymLink() ) watcher->addFile( fi.readLink() );
1184 }
1185 
1186 bool Part::openFile()
1187 {
1188  KMimeType::Ptr mime;
1189  QString fileNameToOpen = localFilePath();
1190  const bool isstdin = url().isLocalFile() && url().fileName( KUrl::ObeyTrailingSlash ) == QLatin1String( "-" );
1191  const QFileInfo fileInfo( fileNameToOpen );
1192  if ( !isstdin && !fileInfo.exists() )
1193  return false;
1194  if ( !arguments().mimeType().isEmpty() )
1195  {
1196  mime = KMimeType::mimeType( arguments().mimeType() );
1197  }
1198  if ( !mime )
1199  {
1200  mime = KMimeType::findByPath( fileNameToOpen );
1201  }
1202  bool isCompressedFile = false;
1203  bool uncompressOk = true;
1204  QString compressedMime = compressedMimeFor( mime->name() );
1205  if ( compressedMime.isEmpty() )
1206  compressedMime = compressedMimeFor( mime->parentMimeType() );
1207  if ( !compressedMime.isEmpty() )
1208  {
1209  isCompressedFile = true;
1210  uncompressOk = handleCompressed( fileNameToOpen, localFilePath(), compressedMime );
1211  mime = KMimeType::findByPath( fileNameToOpen );
1212  }
1213  bool ok = false;
1214  isDocumentArchive = false;
1215  if ( uncompressOk )
1216  {
1217  if ( mime->is( "application/vnd.kde.okular-archive" ) )
1218  {
1219  ok = m_document->openDocumentArchive( fileNameToOpen, url() );
1220  isDocumentArchive = true;
1221  }
1222  else
1223  {
1224  ok = m_document->openDocument( fileNameToOpen, url(), mime );
1225  }
1226  }
1227  bool canSearch = m_document->supportsSearching();
1228 
1229  // update one-time actions
1230  emit enableCloseAction( ok );
1231  m_find->setEnabled( ok && canSearch );
1232  m_findNext->setEnabled( ok && canSearch );
1233  m_findPrev->setEnabled( ok && canSearch );
1234  if( m_saveAs ) m_saveAs->setEnabled( ok && (m_document->canSaveChanges() || isDocumentArchive) );
1235  if( m_saveCopyAs ) m_saveCopyAs->setEnabled( ok );
1236  emit enablePrintAction( ok && m_document->printingSupport() != Okular::Document::NoPrinting );
1237  m_printPreview->setEnabled( ok && m_document->printingSupport() != Okular::Document::NoPrinting );
1238  m_showProperties->setEnabled( ok );
1239  bool hasEmbeddedFiles = ok && m_document->embeddedFiles() && m_document->embeddedFiles()->count() > 0;
1240  if ( m_showEmbeddedFiles ) m_showEmbeddedFiles->setEnabled( hasEmbeddedFiles );
1241  m_topMessage->setVisible( hasEmbeddedFiles && Okular::Settings::showOSD() );
1242 
1243  // Warn the user that XFA forms are not supported yet (NOTE: poppler generator only)
1244  if ( ok && m_document->metaData( "HasUnsupportedXfaForm" ).toBool() == true )
1245  {
1246  m_formsMessage->setup( i18n( "This document has XFA forms, which are currently <b>unsupported</b>." ), KIcon( "dialog-warning" ) );
1247  m_formsMessage->setVisible( true );
1248  }
1249  // m_pageView->toggleFormsAction() may be null on dummy mode
1250  else if ( ok && m_pageView->toggleFormsAction() && m_pageView->toggleFormsAction()->isEnabled() )
1251  {
1252  m_formsMessage->setup( i18n( "This document has forms. Click on the button to interact with them, or use View -> Show Forms." ) );
1253  m_formsMessage->setVisible( true );
1254  }
1255  else
1256  {
1257  m_formsMessage->setVisible( false );
1258  }
1259 
1260  if ( m_showPresentation ) m_showPresentation->setEnabled( ok );
1261  if ( ok )
1262  {
1263  if ( m_exportAs )
1264  {
1265  m_exportFormats = m_document->exportFormats();
1266  QList<Okular::ExportFormat>::ConstIterator it = m_exportFormats.constBegin();
1267  QList<Okular::ExportFormat>::ConstIterator itEnd = m_exportFormats.constEnd();
1268  QMenu *menu = m_exportAs->menu();
1269  for ( ; it != itEnd; ++it )
1270  {
1271  menu->addAction( actionForExportFormat( *it ) );
1272  }
1273  }
1274  if ( isCompressedFile )
1275  {
1276  m_realUrl = url();
1277  }
1278 #ifdef OKULAR_KEEP_FILE_OPEN
1279  if ( keepFileOpen() )
1280  m_keeper->open( fileNameToOpen );
1281 #endif
1282  }
1283  if ( m_exportAsText ) m_exportAsText->setEnabled( ok && m_document->canExportToText() );
1284  if ( m_exportAsDocArchive ) m_exportAsDocArchive->setEnabled( ok );
1285  if ( m_exportAs ) m_exportAs->setEnabled( ok );
1286 
1287  // update viewing actions
1288  updateViewActions();
1289 
1290  m_fileWasRemoved = false;
1291 
1292  if ( !ok )
1293  {
1294  // if can't open document, update windows so they display blank contents
1295  m_pageView->viewport()->update();
1296  m_thumbnailList->update();
1297  setUrl( KUrl() );
1298  return false;
1299  }
1300 
1301  // set the file to the fileWatcher
1302  if ( url().isLocalFile() )
1303  {
1304  addFileToWatcher( m_watcher, localFilePath() );
1305  }
1306 
1307  // if the 'OpenTOC' flag is set, open the TOC
1308  if ( m_document->metaData( "OpenTOC" ).toBool() && m_sidebar->isItemEnabled( 0 ) && !m_sidebar->isCollapsed() )
1309  {
1310  m_sidebar->setCurrentIndex( 0, Sidebar::DoNotUncollapseIfCollapsed );
1311  }
1312  // if the 'StartFullScreen' flag is set, or the command line flag was
1313  // specified, start presentation
1314  if ( m_document->metaData( "StartFullScreen" ).toBool() || m_cliPresentation )
1315  {
1316  bool goAheadWithPresentationMode = true;
1317  if ( !m_cliPresentation )
1318  {
1319  const QString text = i18n( "The document requested to be launched in presentation mode.\n"
1320  "Do you want to allow it?" );
1321  const QString caption = i18n( "Presentation Mode" );
1322  const KGuiItem yesItem = KGuiItem( i18n( "Allow" ), "dialog-ok", i18n( "Allow the presentation mode" ) );
1323  const KGuiItem noItem = KGuiItem( i18n( "Do Not Allow" ), "process-stop", i18n( "Do not allow the presentation mode" ) );
1324  const int result = KMessageBox::questionYesNo( widget(), text, caption, yesItem, noItem );
1325  if ( result == KMessageBox::No )
1326  goAheadWithPresentationMode = false;
1327  }
1328  m_cliPresentation = false;
1329  if ( goAheadWithPresentationMode )
1330  QMetaObject::invokeMethod( this, "slotShowPresentation", Qt::QueuedConnection );
1331  }
1332  m_generatorGuiClient = factory() ? m_document->guiClient() : 0;
1333  if ( m_generatorGuiClient )
1334  factory()->addClient( m_generatorGuiClient );
1335  if ( m_cliPrint )
1336  {
1337  m_cliPrint = false;
1338  slotPrint();
1339  }
1340  return true;
1341 }
1342 
1343 bool Part::openUrl(const KUrl &_url)
1344 {
1345  // Close current document if any
1346  if ( !closeUrl() )
1347  return false;
1348 
1349  KUrl url( _url );
1350  if ( url.hasHTMLRef() )
1351  {
1352  const QString dest = url.htmlRef();
1353  bool ok = true;
1354  const int page = dest.toInt( &ok );
1355  if ( ok )
1356  {
1357  Okular::DocumentViewport vp( page - 1 );
1358  vp.rePos.enabled = true;
1359  vp.rePos.normalizedX = 0;
1360  vp.rePos.normalizedY = 0;
1361  vp.rePos.pos = Okular::DocumentViewport::TopLeft;
1362  m_document->setNextDocumentViewport( vp );
1363  }
1364  else
1365  {
1366  m_document->setNextDocumentDestination( dest );
1367  }
1368  url.setHTMLRef( QString() );
1369  }
1370 
1371  // this calls in sequence the 'closeUrl' and 'openFile' methods
1372  bool openOk = KParts::ReadWritePart::openUrl( url );
1373 
1374  if ( openOk )
1375  {
1376  m_viewportDirty.pageNumber = -1;
1377 
1378  setWindowTitleFromDocument();
1379  }
1380  else
1381  {
1382  resetStartArguments();
1383  KMessageBox::error( widget(), i18n("Could not open %1", url.pathOrUrl() ) );
1384  }
1385 
1386  return openOk;
1387 }
1388 
1389 bool Part::queryClose()
1390 {
1391  if ( !isReadWrite() || !isModified() )
1392  return true;
1393 
1394  const int res = KMessageBox::warningYesNoCancel( widget(),
1395  i18n( "Do you want to save your annotation changes or discard them?" ),
1396  i18n( "Close Document" ),
1397  KStandardGuiItem::saveAs(),
1398  KStandardGuiItem::discard() );
1399 
1400  switch ( res )
1401  {
1402  case KMessageBox::Yes: // Save as
1403  slotSaveFileAs();
1404  return !isModified(); // Only allow closing if file was really saved
1405  case KMessageBox::No: // Discard
1406  return true;
1407  default: // Cancel
1408  return false;
1409  }
1410 }
1411 
1412 bool Part::closeUrl(bool promptToSave)
1413 {
1414  if ( promptToSave && !queryClose() )
1415  return false;
1416 
1417  setModified( false );
1418 
1419  if (!m_temporaryLocalFile.isNull() && m_temporaryLocalFile != localFilePath())
1420  {
1421  QFile::remove( m_temporaryLocalFile );
1422  m_temporaryLocalFile.clear();
1423  }
1424 
1425  slotHidePresentation();
1426  emit enableCloseAction( false );
1427  m_find->setEnabled( false );
1428  m_findNext->setEnabled( false );
1429  m_findPrev->setEnabled( false );
1430  if( m_saveAs ) m_saveAs->setEnabled( false );
1431  if( m_saveCopyAs ) m_saveCopyAs->setEnabled( false );
1432  m_printPreview->setEnabled( false );
1433  m_showProperties->setEnabled( false );
1434  if ( m_showEmbeddedFiles ) m_showEmbeddedFiles->setEnabled( false );
1435  if ( m_exportAs ) m_exportAs->setEnabled( false );
1436  if ( m_exportAsText ) m_exportAsText->setEnabled( false );
1437  if ( m_exportAsDocArchive ) m_exportAsDocArchive->setEnabled( false );
1438  m_exportFormats.clear();
1439  if ( m_exportAs )
1440  {
1441  QMenu *menu = m_exportAs->menu();
1442  QList<QAction*> acts = menu->actions();
1443  int num = acts.count();
1444  for ( int i = 2; i < num; ++i )
1445  {
1446  menu->removeAction( acts.at(i) );
1447  delete acts.at(i);
1448  }
1449  }
1450  if ( m_showPresentation ) m_showPresentation->setEnabled( false );
1451  emit setWindowCaption("");
1452  emit enablePrintAction(false);
1453  m_realUrl = KUrl();
1454  if ( url().isLocalFile() )
1455  {
1456  m_watcher->removeFile( localFilePath() );
1457  QFileInfo fi(localFilePath());
1458  m_watcher->removeDir( fi.absolutePath() );
1459  if ( fi.isSymLink() ) m_watcher->removeFile( fi.readLink() );
1460  }
1461  m_fileWasRemoved = false;
1462  if ( m_generatorGuiClient )
1463  factory()->removeClient( m_generatorGuiClient );
1464  m_generatorGuiClient = 0;
1465  m_document->closeDocument();
1466  updateViewActions();
1467  delete m_tempfile;
1468  m_tempfile = 0;
1469  if ( widget() )
1470  {
1471  m_searchWidget->clearText();
1472  m_topMessage->setVisible( false );
1473  m_formsMessage->setVisible( false );
1474  }
1475 #ifdef OKULAR_KEEP_FILE_OPEN
1476  m_keeper->close();
1477 #endif
1478  bool r = KParts::ReadWritePart::closeUrl();
1479  setUrl(KUrl());
1480 
1481  return r;
1482 }
1483 
1484 bool Part::closeUrl()
1485 {
1486  return closeUrl( true );
1487 }
1488 
1489 void Part::guiActivateEvent(KParts::GUIActivateEvent *event)
1490 {
1491  updateViewActions();
1492 
1493  KParts::ReadWritePart::guiActivateEvent(event);
1494 }
1495 
1496 void Part::close()
1497 {
1498  if ( m_embedMode == NativeShellMode )
1499  {
1500  closeUrl();
1501  }
1502  else KMessageBox::information( widget(), i18n( "This link points to a close document action that does not work when using the embedded viewer." ), QString(), "warnNoCloseIfNotInOkular" );
1503 }
1504 
1505 
1506 void Part::cannotQuit()
1507 {
1508  KMessageBox::information( widget(), i18n( "This link points to a quit application action that does not work when using the embedded viewer." ), QString(), "warnNoQuitIfNotInOkular" );
1509 }
1510 
1511 
1512 void Part::slotShowLeftPanel()
1513 {
1514  bool showLeft = m_showLeftPanel->isChecked();
1515  Okular::Settings::setShowLeftPanel( showLeft );
1516  Okular::Settings::self()->writeConfig();
1517  // show/hide left panel
1518  m_sidebar->setSidebarVisibility( showLeft );
1519 }
1520 
1521 void Part::slotShowBottomBar()
1522 {
1523  const bool showBottom = m_showBottomBar->isChecked();
1524  Okular::Settings::setShowBottomBar( showBottom );
1525  Okular::Settings::self()->writeConfig();
1526  // show/hide bottom bar
1527  m_bottomBar->setVisible( showBottom );
1528 }
1529 
1530 void Part::slotFileDirty( const QString& path )
1531 {
1532  // The beauty of this is that each start cancels the previous one.
1533  // This means that timeout() is only fired when there have
1534  // no changes to the file for the last 750 milisecs.
1535  // This ensures that we don't update on every other byte that gets
1536  // written to the file.
1537  if ( path == localFilePath() )
1538  {
1539  // Only start watching the file in case if it wasn't removed
1540  if (QFile::exists(localFilePath()))
1541  m_dirtyHandler->start( 750 );
1542  else
1543  m_fileWasRemoved = true;
1544  }
1545  else
1546  {
1547  const QFileInfo fi(localFilePath());
1548  if ( fi.absolutePath() == path )
1549  {
1550  // Our parent has been dirtified
1551  if (!QFile::exists(localFilePath()))
1552  {
1553  m_fileWasRemoved = true;
1554  }
1555  else if (m_fileWasRemoved && QFile::exists(localFilePath()))
1556  {
1557  // we need to watch the new file
1558  m_watcher->removeFile(localFilePath());
1559  m_watcher->addFile(localFilePath());
1560  m_dirtyHandler->start( 750 );
1561  }
1562  }
1563  else if ( fi.isSymLink() && fi.readLink() == path )
1564  {
1565  if ( QFile::exists( fi.readLink() ))
1566  m_dirtyHandler->start( 750 );
1567  else
1568  m_fileWasRemoved = true;
1569  }
1570  }
1571 }
1572 
1573 
1574 void Part::slotDoFileDirty()
1575 {
1576  bool tocReloadPrepared = false;
1577 
1578  // do the following the first time the file is reloaded
1579  if ( m_viewportDirty.pageNumber == -1 )
1580  {
1581  // store the url of the current document
1582  m_oldUrl = url();
1583 
1584  // store the current viewport
1585  m_viewportDirty = m_document->viewport();
1586 
1587  // store the current toolbox pane
1588  m_dirtyToolboxIndex = m_sidebar->currentIndex();
1589  m_wasSidebarVisible = m_sidebar->isSidebarVisible();
1590  m_wasSidebarCollapsed = m_sidebar->isCollapsed();
1591 
1592  // store if presentation view was open
1593  m_wasPresentationOpen = ((PresentationWidget*)m_presentationWidget != 0);
1594 
1595  // preserves the toc state after reload
1596  m_toc->prepareForReload();
1597  tocReloadPrepared = true;
1598 
1599  // store the page rotation
1600  m_dirtyPageRotation = m_document->rotation();
1601 
1602  // inform the user about the operation in progress
1603  // TODO: Remove this line and integrate reload info in queryClose
1604  m_pageView->displayMessage( i18n("Reloading the document...") );
1605  }
1606 
1607  // close and (try to) reopen the document
1608  if ( !closeUrl() )
1609  {
1610  m_viewportDirty.pageNumber = -1;
1611 
1612  if ( tocReloadPrepared )
1613  {
1614  m_toc->rollbackReload();
1615  }
1616  return;
1617  }
1618 
1619  if ( tocReloadPrepared )
1620  m_toc->finishReload();
1621 
1622  // inform the user about the operation in progress
1623  m_pageView->displayMessage( i18n("Reloading the document...") );
1624 
1625  if ( KParts::ReadWritePart::openUrl( m_oldUrl ) )
1626  {
1627  // on successful opening, restore the previous viewport
1628  if ( m_viewportDirty.pageNumber >= (int) m_document->pages() )
1629  m_viewportDirty.pageNumber = (int) m_document->pages() - 1;
1630  m_document->setViewport( m_viewportDirty );
1631  m_oldUrl = KUrl();
1632  m_viewportDirty.pageNumber = -1;
1633  m_document->setRotation( m_dirtyPageRotation );
1634  if ( m_sidebar->currentIndex() != m_dirtyToolboxIndex && m_sidebar->isItemEnabled( m_dirtyToolboxIndex )
1635  && !m_sidebar->isCollapsed() )
1636  {
1637  m_sidebar->setCurrentIndex( m_dirtyToolboxIndex );
1638  }
1639  if ( m_sidebar->isSidebarVisible() != m_wasSidebarVisible )
1640  {
1641  m_sidebar->setSidebarVisibility( m_wasSidebarVisible );
1642  }
1643  if ( m_sidebar->isCollapsed() != m_wasSidebarCollapsed )
1644  {
1645  m_sidebar->setCollapsed( m_wasSidebarCollapsed );
1646  }
1647  if (m_wasPresentationOpen) slotShowPresentation();
1648  emit enablePrintAction(true && m_document->printingSupport() != Okular::Document::NoPrinting);
1649  }
1650  else
1651  {
1652  // start watching the file again (since we dropped it on close)
1653  addFileToWatcher( m_watcher, localFilePath() );
1654  m_dirtyHandler->start( 750 );
1655  }
1656 }
1657 
1658 
1659 void Part::updateViewActions()
1660 {
1661  bool opened = m_document->pages() > 0;
1662  if ( opened )
1663  {
1664  m_gotoPage->setEnabled( m_document->pages() > 1 );
1665 
1666  // Check if you are at the beginning or not
1667  if (m_document->currentPage() != 0)
1668  {
1669  m_beginningOfDocument->setEnabled( true );
1670  m_prevPage->setEnabled( true );
1671  }
1672  else
1673  {
1674  if (m_pageView->verticalScrollBar()->value() != 0)
1675  {
1676  // The page isn't at the very beginning
1677  m_beginningOfDocument->setEnabled( true );
1678  }
1679  else
1680  {
1681  // The page is at the very beginning of the document
1682  m_beginningOfDocument->setEnabled( false );
1683  }
1684  // The document is at the first page, you can go to a page before
1685  m_prevPage->setEnabled( false );
1686  }
1687 
1688  if (m_document->pages() == m_document->currentPage() + 1 )
1689  {
1690  // If you are at the end, disable go to next page
1691  m_nextPage->setEnabled( false );
1692  if (m_pageView->verticalScrollBar()->value() == m_pageView->verticalScrollBar()->maximum())
1693  {
1694  // If you are the end of the page of the last document, you can't go to the last page
1695  m_endOfDocument->setEnabled( false );
1696  }
1697  else
1698  {
1699  // Otherwise you can move to the endif
1700  m_endOfDocument->setEnabled( true );
1701  }
1702  }
1703  else
1704  {
1705  // If you are not at the end, enable go to next page
1706  m_nextPage->setEnabled( true );
1707  m_endOfDocument->setEnabled( true );
1708  }
1709 
1710  if (m_historyBack) m_historyBack->setEnabled( !m_document->historyAtBegin() );
1711  if (m_historyNext) m_historyNext->setEnabled( !m_document->historyAtEnd() );
1712  m_reload->setEnabled( true );
1713  if (m_copy) m_copy->setEnabled( true );
1714  if (m_selectAll) m_selectAll->setEnabled( true );
1715  }
1716  else
1717  {
1718  m_gotoPage->setEnabled( false );
1719  m_beginningOfDocument->setEnabled( false );
1720  m_endOfDocument->setEnabled( false );
1721  m_prevPage->setEnabled( false );
1722  m_nextPage->setEnabled( false );
1723  if (m_historyBack) m_historyBack->setEnabled( false );
1724  if (m_historyNext) m_historyNext->setEnabled( false );
1725  m_reload->setEnabled( false );
1726  if (m_copy) m_copy->setEnabled( false );
1727  if (m_selectAll) m_selectAll->setEnabled( false );
1728  }
1729 
1730  if ( factory() )
1731  {
1732  QWidget *menu = factory()->container("menu_okular_part_viewer", this);
1733  if (menu) menu->setEnabled( opened );
1734 
1735  menu = factory()->container("view_orientation", this);
1736  if (menu) menu->setEnabled( opened );
1737  }
1738  emit viewerMenuStateChange( opened );
1739 
1740  updateBookmarksActions();
1741 }
1742 
1743 
1744 void Part::updateBookmarksActions()
1745 {
1746  bool opened = m_document->pages() > 0;
1747  if ( opened )
1748  {
1749  m_addBookmark->setEnabled( true );
1750  if ( m_document->bookmarkManager()->isBookmarked( m_document->viewport() ) )
1751  {
1752  m_addBookmark->setText( i18n( "Remove Bookmark" ) );
1753  m_addBookmark->setIcon( KIcon( "edit-delete-bookmark" ) );
1754  m_renameBookmark->setEnabled( true );
1755  }
1756  else
1757  {
1758  m_addBookmark->setText( m_addBookmarkText );
1759  m_addBookmark->setIcon( m_addBookmarkIcon );
1760  m_renameBookmark->setEnabled( false );
1761  }
1762  }
1763  else
1764  {
1765  m_addBookmark->setEnabled( false );
1766  m_addBookmark->setText( m_addBookmarkText );
1767  m_addBookmark->setIcon( m_addBookmarkIcon );
1768  m_renameBookmark->setEnabled( false );
1769  }
1770 }
1771 
1772 
1773 void Part::enableTOC(bool enable)
1774 {
1775  m_sidebar->setItemEnabled(0, enable);
1776 
1777  // If present, show the TOC when a document is opened
1778  if ( enable )
1779  {
1780  m_sidebar->setCurrentIndex( 0, Sidebar::DoNotUncollapseIfCollapsed );
1781  }
1782 }
1783 
1784 void Part::slotRebuildBookmarkMenu()
1785 {
1786  rebuildBookmarkMenu();
1787 }
1788 
1789 void Part::slotShowFindBar()
1790 {
1791  m_findBar->show();
1792  m_findBar->focusAndSetCursor();
1793  m_closeFindBar->setShortcut( QKeySequence( Qt::Key_Escape ) );
1794 }
1795 
1796 void Part::slotHideFindBar()
1797 {
1798  if ( m_findBar->maybeHide() )
1799  {
1800  m_pageView->setFocus();
1801  m_closeFindBar->setShortcut( QKeySequence( /* None */ ) );
1802  }
1803 }
1804 
1805 //BEGIN go to page dialog
1806 class GotoPageDialog : public KDialog
1807 {
1808  public:
1809  GotoPageDialog(QWidget *p, int current, int max) : KDialog(p)
1810  {
1811  setCaption(i18n("Go to Page"));
1812  setButtons(Ok | Cancel);
1813  setDefaultButton(Ok);
1814 
1815  QWidget *w = new QWidget(this);
1816  setMainWidget(w);
1817 
1818  QVBoxLayout *topLayout = new QVBoxLayout(w);
1819  topLayout->setMargin(0);
1820  topLayout->setSpacing(spacingHint());
1821  e1 = new KIntNumInput(current, w);
1822  e1->setRange(1, max);
1823  e1->setEditFocus(true);
1824  e1->setSliderEnabled(true);
1825 
1826  QLabel *label = new QLabel(i18n("&Page:"), w);
1827  label->setBuddy(e1);
1828  topLayout->addWidget(label);
1829  topLayout->addWidget(e1);
1830  // A little bit extra space
1831  topLayout->addSpacing(spacingHint());
1832  topLayout->addStretch(10);
1833  e1->setFocus();
1834  }
1835 
1836  int getPage() const
1837  {
1838  return e1->value();
1839  }
1840 
1841  protected:
1842  KIntNumInput *e1;
1843 };
1844 //END go to page dialog
1845 
1846 void Part::slotGoToPage()
1847 {
1848  GotoPageDialog pageDialog( m_pageView, m_document->currentPage() + 1, m_document->pages() );
1849  if ( pageDialog.exec() == QDialog::Accepted )
1850  m_document->setViewportPage( pageDialog.getPage() - 1 );
1851 }
1852 
1853 
1854 void Part::slotPreviousPage()
1855 {
1856  if ( m_document->isOpened() && !(m_document->currentPage() < 1) )
1857  m_document->setViewportPage( m_document->currentPage() - 1 );
1858 }
1859 
1860 
1861 void Part::slotNextPage()
1862 {
1863  if ( m_document->isOpened() && m_document->currentPage() < (m_document->pages() - 1) )
1864  m_document->setViewportPage( m_document->currentPage() + 1 );
1865 }
1866 
1867 
1868 void Part::slotGotoFirst()
1869 {
1870  if ( m_document->isOpened() ) {
1871  m_document->setViewportPage( 0 );
1872  m_beginningOfDocument->setEnabled( false );
1873  }
1874 }
1875 
1876 
1877 void Part::slotGotoLast()
1878 {
1879  if ( m_document->isOpened() )
1880  {
1881  DocumentViewport endPage(m_document->pages() -1 );
1882  endPage.rePos.enabled = true;
1883  endPage.rePos.normalizedX = 0;
1884  endPage.rePos.normalizedY = 1;
1885  endPage.rePos.pos = Okular::DocumentViewport::TopLeft;
1886  m_document->setViewport(endPage);
1887  m_endOfDocument->setEnabled(false);
1888  }
1889 }
1890 
1891 
1892 void Part::slotHistoryBack()
1893 {
1894  m_document->setPrevViewport();
1895 }
1896 
1897 
1898 void Part::slotHistoryNext()
1899 {
1900  m_document->setNextViewport();
1901 }
1902 
1903 
1904 void Part::slotAddBookmark()
1905 {
1906  DocumentViewport vp = m_document->viewport();
1907  if ( m_document->bookmarkManager()->isBookmarked( vp ) )
1908  {
1909  m_document->bookmarkManager()->removeBookmark( vp );
1910  }
1911  else
1912  {
1913  m_document->bookmarkManager()->addBookmark( vp );
1914  }
1915 }
1916 
1917 void Part::slotRenameBookmark( const DocumentViewport &viewport )
1918 {
1919  Q_ASSERT(m_document->bookmarkManager()->isBookmarked( viewport ));
1920  if ( m_document->bookmarkManager()->isBookmarked( viewport ) )
1921  {
1922  KBookmark bookmark = m_document->bookmarkManager()->bookmark( viewport );
1923  const QString newName = KInputDialog::getText( i18n( "Rename Bookmark" ), i18n( "Enter the new name of the bookmark:" ), bookmark.fullText(), 0, widget());
1924  if (!newName.isEmpty())
1925  {
1926  m_document->bookmarkManager()->renameBookmark(&bookmark, newName);
1927  }
1928  }
1929 }
1930 
1931 void Part::slotRenameBookmarkFromMenu()
1932 {
1933  QAction *action = dynamic_cast<QAction *>(sender());
1934  Q_ASSERT( action );
1935  if ( action )
1936  {
1937  DocumentViewport vp( action->data().toString() );
1938  slotRenameBookmark( vp );
1939  }
1940 }
1941 
1942 void Part::slotRenameCurrentViewportBookmark()
1943 {
1944  slotRenameBookmark( m_document->viewport() );
1945 }
1946 
1947 void Part::slotAboutToShowContextMenu(KMenu * /*menu*/, QAction *action, QMenu *contextMenu)
1948 {
1949  const QList<QAction*> actions = contextMenu->findChildren<QAction*>("OkularPrivateRenameBookmarkActions");
1950  foreach(QAction *a, actions)
1951  {
1952  contextMenu->removeAction(a);
1953  delete a;
1954  }
1955 
1956  KBookmarkAction *ba = dynamic_cast<KBookmarkAction*>(action);
1957  if (ba != NULL)
1958  {
1959  QAction *separatorAction = contextMenu->addSeparator();
1960  separatorAction->setObjectName("OkularPrivateRenameBookmarkActions");
1961  QAction *renameAction = contextMenu->addAction( KIcon( "edit-rename" ), i18n( "Rename this Bookmark" ), this, SLOT(slotRenameBookmarkFromMenu()) );
1962  renameAction->setData(ba->property("htmlRef").toString());
1963  renameAction->setObjectName("OkularPrivateRenameBookmarkActions");
1964  }
1965 }
1966 
1967 void Part::slotPreviousBookmark()
1968 {
1969  const KBookmark bookmark = m_document->bookmarkManager()->previousBookmark( m_document->viewport() );
1970 
1971  if ( !bookmark.isNull() )
1972  {
1973  DocumentViewport vp( bookmark.url().htmlRef() );
1974  m_document->setViewport( vp );
1975  }
1976 }
1977 
1978 
1979 void Part::slotNextBookmark()
1980 {
1981  const KBookmark bookmark = m_document->bookmarkManager()->nextBookmark( m_document->viewport() );
1982 
1983  if ( !bookmark.isNull() )
1984  {
1985  DocumentViewport vp( bookmark.url().htmlRef() );
1986  m_document->setViewport( vp );
1987  }
1988 }
1989 
1990 
1991 void Part::slotFind()
1992 {
1993  // when in presentation mode, there's already a search bar, taking care of
1994  // the 'find' requests
1995  if ( (PresentationWidget*)m_presentationWidget != 0 )
1996  {
1997  m_presentationWidget->slotFind();
1998  }
1999  else
2000  {
2001  slotShowFindBar();
2002  }
2003 }
2004 
2005 
2006 void Part::slotFindNext()
2007 {
2008  if (m_findBar->isHidden())
2009  slotShowFindBar();
2010  else
2011  m_findBar->findNext();
2012 }
2013 
2014 
2015 void Part::slotFindPrev()
2016 {
2017  if (m_findBar->isHidden())
2018  slotShowFindBar();
2019  else
2020  m_findBar->findPrev();
2021 }
2022 
2023 bool Part::saveFile()
2024 {
2025  kDebug() << "Okular part doesn't support saving the file in the location from which it was opened";
2026  return false;
2027 }
2028 
2029 void Part::slotSaveFileAs()
2030 {
2031  if ( m_embedMode == PrintPreviewMode )
2032  return;
2033 
2034  /* Show a warning before saving if the generator can't save annotations,
2035  * unless we are going to save a .okular archive. */
2036  if ( !isDocumentArchive && !m_document->canSaveChanges( Document::SaveAnnotationsCapability ) )
2037  {
2038  /* Search local annotations */
2039  bool containsLocalAnnotations = false;
2040  const int pagecount = m_document->pages();
2041 
2042  for ( int pageno = 0; pageno < pagecount; ++pageno )
2043  {
2044  const Okular::Page *page = m_document->page( pageno );
2045  foreach ( const Okular::Annotation *ann, page->annotations() )
2046  {
2047  if ( !(ann->flags() & Okular::Annotation::External) )
2048  {
2049  containsLocalAnnotations = true;
2050  break;
2051  }
2052  }
2053  if ( containsLocalAnnotations )
2054  break;
2055  }
2056 
2057  /* Don't show it if there are no local annotations */
2058  if ( containsLocalAnnotations )
2059  {
2060  int res = KMessageBox::warningContinueCancel( widget(), i18n("Your annotations will not be exported.\nYou can export the annotated document using File -> Export As -> Document Archive") );
2061  if ( res != KMessageBox::Continue )
2062  return; // Canceled
2063  }
2064  }
2065 
2066  KUrl saveUrl = KFileDialog::getSaveUrl( url(),
2067  QString(), widget(), QString(),
2068  KFileDialog::ConfirmOverwrite );
2069  if ( !saveUrl.isValid() || saveUrl.isEmpty() )
2070  return;
2071 
2072  saveAs( saveUrl );
2073 }
2074 
2075 bool Part::saveAs( const KUrl & saveUrl )
2076 {
2077  KTemporaryFile tf;
2078  QString fileName;
2079  if ( !tf.open() )
2080  {
2081  KMessageBox::information( widget(), i18n("Could not open the temporary file for saving." ) );
2082  return false;
2083  }
2084  fileName = tf.fileName();
2085  tf.close();
2086 
2087  QString errorText;
2088  bool saved;
2089 
2090  if ( isDocumentArchive )
2091  saved = m_document->saveDocumentArchive( fileName );
2092  else
2093  saved = m_document->saveChanges( fileName, &errorText );
2094 
2095  if ( !saved )
2096  {
2097  if (errorText.isEmpty())
2098  {
2099  KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) );
2100  }
2101  else
2102  {
2103  KMessageBox::information( widget(), i18n("File could not be saved in '%1'. %2", fileName, errorText ) );
2104  }
2105  return false;
2106  }
2107 
2108  KIO::Job *copyJob = KIO::file_copy( fileName, saveUrl, -1, KIO::Overwrite );
2109  if ( !KIO::NetAccess::synchronousRun( copyJob, widget() ) )
2110  {
2111  KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", saveUrl.prettyUrl() ) );
2112  return false;
2113  }
2114 
2115  setModified( false );
2116  return true;
2117 }
2118 
2119 
2120 void Part::slotSaveCopyAs()
2121 {
2122  if ( m_embedMode == PrintPreviewMode )
2123  return;
2124 
2125  KUrl saveUrl = KFileDialog::getSaveUrl( KUrl("kfiledialog:///okular/" + url().fileName()),
2126  QString(), widget(), QString(),
2127  KFileDialog::ConfirmOverwrite );
2128  if ( saveUrl.isValid() && !saveUrl.isEmpty() )
2129  {
2130  // make use of the already downloaded (in case of remote URLs) file,
2131  // no point in downloading that again
2132  KUrl srcUrl = KUrl::fromPath( localFilePath() );
2133  KTemporaryFile * tempFile = 0;
2134  // duh, our local file disappeared...
2135  if ( !QFile::exists( localFilePath() ) )
2136  {
2137  if ( url().isLocalFile() )
2138  {
2139 #ifdef OKULAR_KEEP_FILE_OPEN
2140  // local file: try to get it back from the open handle on it
2141  if ( ( tempFile = m_keeper->copyToTemporary() ) )
2142  srcUrl = KUrl::fromPath( tempFile->fileName() );
2143 #else
2144  const QString msg = i18n( "Okular cannot copy %1 to the specified location.\n\nThe document does not exist anymore.", localFilePath() );
2145  KMessageBox::sorry( widget(), msg );
2146  return;
2147 #endif
2148  }
2149  else
2150  {
2151  // we still have the original remote URL of the document,
2152  // so copy the document from there
2153  srcUrl = url();
2154  }
2155  }
2156 
2157  KIO::Job *copyJob = KIO::file_copy( srcUrl, saveUrl, -1, KIO::Overwrite );
2158  if ( !KIO::NetAccess::synchronousRun( copyJob, widget() ) )
2159  KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", saveUrl.prettyUrl() ) );
2160 
2161  delete tempFile;
2162  }
2163 }
2164 
2165 
2166 void Part::slotGetNewStuff()
2167 {
2168 #if 0
2169  KNS::Engine engine(widget());
2170  engine.init( "okular.knsrc" );
2171  // show the modal dialog over pageview and execute it
2172  KNS::Entry::List entries = engine.downloadDialogModal( m_pageView );
2173  Q_UNUSED( entries )
2174 #endif
2175 }
2176 
2177 
2178 void Part::slotPreferences()
2179 {
2180  // Create dialog
2181  PreferencesDialog * dialog = new PreferencesDialog( m_pageView, Okular::Settings::self(), m_embedMode );
2182  dialog->setAttribute( Qt::WA_DeleteOnClose );
2183 
2184  // Show it
2185  dialog->show();
2186 }
2187 
2188 
2189 void Part::slotAnnotationPreferences()
2190 {
2191  // Create dialog
2192  PreferencesDialog * dialog = new PreferencesDialog( m_pageView, Okular::Settings::self(), m_embedMode );
2193  dialog->setAttribute( Qt::WA_DeleteOnClose );
2194 
2195  // Show it
2196  dialog->switchToAnnotationsPage();
2197  dialog->show();
2198 }
2199 
2200 
2201 void Part::slotNewConfig()
2202 {
2203  // Apply settings here. A good policy is to check whether the setting has
2204  // changed before applying changes.
2205 
2206  // Watch File
2207  setWatchFileModeEnabled(Okular::Settings::watchFile());
2208 
2209  // Main View (pageView)
2210  m_pageView->reparseConfig();
2211 
2212  // update document settings
2213  m_document->reparseConfig();
2214 
2215  // update TOC settings
2216  if ( m_sidebar->isItemEnabled(0) )
2217  m_toc->reparseConfig();
2218 
2219  // update ThumbnailList contents
2220  if ( Okular::Settings::showLeftPanel() && !m_thumbnailList->isHidden() )
2221  m_thumbnailList->updateWidgets();
2222 
2223  // update Reviews settings
2224  if ( m_sidebar->isItemEnabled(2) )
2225  m_reviewsWidget->reparseConfig();
2226 
2227  setWindowTitleFromDocument ();
2228 }
2229 
2230 
2231 void Part::slotPrintPreview()
2232 {
2233  if (m_document->pages() == 0) return;
2234 
2235  QPrinter printer;
2236 
2237  // Native printing supports KPrintPreview, Postscript needs to use FilePrinterPreview
2238  if ( m_document->printingSupport() == Okular::Document::NativePrinting )
2239  {
2240  KPrintPreview previewdlg( &printer, widget() );
2241  setupPrint( printer );
2242  doPrint( printer );
2243  previewdlg.exec();
2244  }
2245  else
2246  {
2247  // Generate a temp filename for Print to File, then release the file so generator can write to it
2248  KTemporaryFile tf;
2249  tf.setAutoRemove( true );
2250  tf.setSuffix( ".ps" );
2251  tf.open();
2252  printer.setOutputFileName( tf.fileName() );
2253  tf.close();
2254  setupPrint( printer );
2255  doPrint( printer );
2256  if ( QFile::exists( printer.outputFileName() ) )
2257  {
2258  Okular::FilePrinterPreview previewdlg( printer.outputFileName(), widget() );
2259  previewdlg.exec();
2260  }
2261  }
2262 }
2263 
2264 
2265 void Part::slotShowMenu(const Okular::Page *page, const QPoint &point)
2266 {
2267  if ( m_embedMode == PrintPreviewMode )
2268  return;
2269 
2270  bool reallyShow = false;
2271  const bool currentPage = page && page->number() == m_document->viewport().pageNumber;
2272 
2273  if (!m_actionsSearched)
2274  {
2275  // the quest for options_show_menubar
2276  KActionCollection *ac;
2277  QAction *act;
2278 
2279  if (factory())
2280  {
2281  const QList<KXMLGUIClient*> clients(factory()->clients());
2282  for(int i = 0 ; (!m_showMenuBarAction || !m_showFullScreenAction) && i < clients.size(); ++i)
2283  {
2284  ac = clients.at(i)->actionCollection();
2285  // show_menubar
2286  act = ac->action("options_show_menubar");
2287  if (act && qobject_cast<KToggleAction*>(act))
2288  m_showMenuBarAction = qobject_cast<KToggleAction*>(act);
2289  // fullscreen
2290  act = ac->action("fullscreen");
2291  if (act && qobject_cast<KToggleFullScreenAction*>(act))
2292  m_showFullScreenAction = qobject_cast<KToggleFullScreenAction*>(act);
2293  }
2294  }
2295  m_actionsSearched = true;
2296  }
2297 
2298  KMenu *popup = new KMenu( widget() );
2299  QAction *addBookmark = 0;
2300  QAction *removeBookmark = 0;
2301  QAction *fitPageWidth = 0;
2302  if (page)
2303  {
2304  popup->addTitle( i18n( "Page %1", page->number() + 1 ) );
2305  if ( ( !currentPage && m_document->bookmarkManager()->isBookmarked( page->number() ) ) ||
2306  ( currentPage && m_document->bookmarkManager()->isBookmarked( m_document->viewport() ) ) )
2307  removeBookmark = popup->addAction( KIcon("edit-delete-bookmark"), i18n("Remove Bookmark") );
2308  else
2309  addBookmark = popup->addAction( KIcon("bookmark-new"), i18n("Add Bookmark") );
2310  if ( m_pageView->canFitPageWidth() )
2311  fitPageWidth = popup->addAction( KIcon("zoom-fit-best"), i18n("Fit Width") );
2312  popup->addAction( m_prevBookmark );
2313  popup->addAction( m_nextBookmark );
2314  reallyShow = true;
2315  }
2316  /*
2317  //Albert says: I have not ported this as i don't see it does anything
2318  if ( d->mouseOnRect ) // and rect->objectType() == ObjectRect::Image ...
2319  {
2320  m_popup->insertItem( SmallIcon("document-save"), i18n("Save Image..."), 4 );
2321  m_popup->setItemEnabled( 4, false );
2322  }*/
2323 
2324  if ((m_showMenuBarAction && !m_showMenuBarAction->isChecked()) || (m_showFullScreenAction && m_showFullScreenAction->isChecked()))
2325  {
2326  popup->addTitle( i18n( "Tools" ) );
2327  if (m_showMenuBarAction && !m_showMenuBarAction->isChecked()) popup->addAction(m_showMenuBarAction);
2328  if (m_showFullScreenAction && m_showFullScreenAction->isChecked()) popup->addAction(m_showFullScreenAction);
2329  reallyShow = true;
2330 
2331  }
2332 
2333  if (reallyShow)
2334  {
2335  QAction *res = popup->exec(point);
2336  if (res)
2337  {
2338  if (res == addBookmark)
2339  {
2340  if (currentPage)
2341  m_document->bookmarkManager()->addBookmark( m_document->viewport() );
2342  else
2343  m_document->bookmarkManager()->addBookmark( page->number() );
2344  }
2345  else if (res == removeBookmark)
2346  {
2347  if (currentPage)
2348  m_document->bookmarkManager()->removeBookmark( m_document->viewport() );
2349  else
2350  m_document->bookmarkManager()->removeBookmark( page->number() );
2351  }
2352  else if (res == fitPageWidth)
2353  {
2354  m_pageView->fitPageWidth( page->number() );
2355  }
2356  }
2357  }
2358  delete popup;
2359 }
2360 
2361 
2362 void Part::slotShowProperties()
2363 {
2364  PropertiesDialog *d = new PropertiesDialog(widget(), m_document);
2365  d->exec();
2366  delete d;
2367 }
2368 
2369 
2370 void Part::slotShowEmbeddedFiles()
2371 {
2372  EmbeddedFilesDialog *d = new EmbeddedFilesDialog(widget(), m_document);
2373  d->exec();
2374  delete d;
2375 }
2376 
2377 
2378 void Part::slotShowPresentation()
2379 {
2380  if ( !m_presentationWidget )
2381  {
2382  m_presentationWidget = new PresentationWidget( widget(), m_document, actionCollection() );
2383  }
2384 }
2385 
2386 
2387 void Part::slotHidePresentation()
2388 {
2389  if ( m_presentationWidget )
2390  delete (PresentationWidget*) m_presentationWidget;
2391 }
2392 
2393 
2394 void Part::slotTogglePresentation()
2395 {
2396  if ( m_document->isOpened() )
2397  {
2398  if ( !m_presentationWidget )
2399  m_presentationWidget = new PresentationWidget( widget(), m_document, actionCollection() );
2400  else delete (PresentationWidget*) m_presentationWidget;
2401  }
2402 }
2403 
2404 
2405 void Part::reload()
2406 {
2407  if ( m_document->isOpened() )
2408  {
2409  slotReload();
2410  }
2411 }
2412 
2413 void Part::enableStartWithPrint()
2414 {
2415  m_cliPrint = true;
2416 }
2417 
2418 void Part::slotAboutBackend()
2419 {
2420  const KComponentData *data = m_document->componentData();
2421  if ( !data )
2422  return;
2423 
2424  KAboutData aboutData( *data->aboutData() );
2425 
2426  if ( aboutData.programIconName().isEmpty() || aboutData.programIconName() == aboutData.appName() )
2427  {
2428  if ( const Okular::DocumentInfo *documentInfo = m_document->documentInfo() )
2429  {
2430  const QString mimeTypeName = documentInfo->get("mimeType");
2431  if ( !mimeTypeName.isEmpty() )
2432  {
2433  if ( KMimeType::Ptr type = KMimeType::mimeType( mimeTypeName ) )
2434  aboutData.setProgramIconName( type->iconName() );
2435  }
2436  }
2437  }
2438 
2439  KAboutApplicationDialog dlg( &aboutData, widget() );
2440  dlg.exec();
2441 }
2442 
2443 
2444 void Part::slotExportAs(QAction * act)
2445 {
2446  QList<QAction*> acts = m_exportAs->menu() ? m_exportAs->menu()->actions() : QList<QAction*>();
2447  int id = acts.indexOf( act );
2448  if ( ( id < 0 ) || ( id >= acts.count() ) )
2449  return;
2450 
2451  QString filter;
2452  switch ( id )
2453  {
2454  case 0:
2455  filter = "text/plain";
2456  break;
2457  case 1:
2458  filter = "application/vnd.kde.okular-archive";
2459  break;
2460  default:
2461  filter = m_exportFormats.at( id - 2 ).mimeType()->name();
2462  break;
2463  }
2464  QString fileName = KFileDialog::getSaveFileName( url().isLocalFile() ? url().directory() : QString(),
2465  filter, widget(), QString(),
2466  KFileDialog::ConfirmOverwrite );
2467  if ( !fileName.isEmpty() )
2468  {
2469  bool saved = false;
2470  switch ( id )
2471  {
2472  case 0:
2473  saved = m_document->exportToText( fileName );
2474  break;
2475  case 1:
2476  saved = m_document->saveDocumentArchive( fileName );
2477  break;
2478  default:
2479  saved = m_document->exportTo( fileName, m_exportFormats.at( id - 2 ) );
2480  break;
2481  }
2482  if ( !saved )
2483  KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) );
2484  }
2485 }
2486 
2487 
2488 void Part::slotReload()
2489 {
2490  // stop the dirty handler timer, otherwise we may conflict with the
2491  // auto-refresh system
2492  m_dirtyHandler->stop();
2493 
2494  slotDoFileDirty();
2495 }
2496 
2497 
2498 void Part::slotPrint()
2499 {
2500  if (m_document->pages() == 0) return;
2501 
2502 #ifdef Q_WS_WIN
2503  QPrinter printer(QPrinter::HighResolution);
2504 #else
2505  QPrinter printer;
2506 #endif
2507  QPrintDialog *printDialog = 0;
2508  QWidget *printConfigWidget = 0;
2509 
2510  // Must do certain QPrinter setup before creating QPrintDialog
2511  setupPrint( printer );
2512 
2513  // Create the Print Dialog with extra config widgets if required
2514  if ( m_document->canConfigurePrinter() )
2515  {
2516  printConfigWidget = m_document->printConfigurationWidget();
2517  }
2518  if ( printConfigWidget )
2519  {
2520  printDialog = KdePrint::createPrintDialog( &printer, QList<QWidget*>() << printConfigWidget, widget() );
2521  }
2522  else
2523  {
2524  printDialog = KdePrint::createPrintDialog( &printer, widget() );
2525  }
2526 
2527  if ( printDialog )
2528  {
2529 
2530  // Set the available Print Range
2531  printDialog->setMinMax( 1, m_document->pages() );
2532  printDialog->setFromTo( 1, m_document->pages() );
2533 
2534  // If the user has bookmarked pages for printing, then enable Selection
2535  if ( !m_document->bookmarkedPageRange().isEmpty() )
2536  {
2537  printDialog->addEnabledOption( QAbstractPrintDialog::PrintSelection );
2538  }
2539 
2540  // If the Document type doesn't support print to both PS & PDF then disable the Print Dialog option
2541  if ( printDialog->isOptionEnabled( QAbstractPrintDialog::PrintToFile ) &&
2542  !m_document->supportsPrintToFile() )
2543  {
2544  printDialog->setEnabledOptions( printDialog->enabledOptions() ^ QAbstractPrintDialog::PrintToFile );
2545  }
2546 
2547 #if QT_VERSION >= KDE_MAKE_VERSION(4,7,0)
2548  // Enable the Current Page option in the dialog.
2549  if ( m_document->pages() > 1 && currentPage() > 0 )
2550  {
2551  printDialog->setOption( QAbstractPrintDialog::PrintCurrentPage );
2552  }
2553 #endif
2554 
2555  if ( printDialog->exec() )
2556  doPrint( printer );
2557  delete printDialog;
2558  }
2559 }
2560 
2561 
2562 void Part::setupPrint( QPrinter &printer )
2563 {
2564  printer.setOrientation(m_document->orientation());
2565 
2566  // title
2567  QString title = m_document->metaData( "DocumentTitle" ).toString();
2568  if ( title.isEmpty() )
2569  {
2570  title = m_document->currentDocument().fileName();
2571  }
2572  if ( !title.isEmpty() )
2573  {
2574  printer.setDocName( title );
2575  }
2576 }
2577 
2578 
2579 void Part::doPrint(QPrinter &printer)
2580 {
2581  if (!m_document->isAllowed(Okular::AllowPrint))
2582  {
2583  KMessageBox::error(widget(), i18n("Printing this document is not allowed."));
2584  return;
2585  }
2586 
2587  if (!m_document->print(printer))
2588  {
2589  const QString error = m_document->printError();
2590  if (error.isEmpty())
2591  {
2592  KMessageBox::error(widget(), i18n("Could not print the document. Unknown error. Please report to bugs.kde.org"));
2593  }
2594  else
2595  {
2596  KMessageBox::error(widget(), i18n("Could not print the document. Detailed error is \"%1\". Please report to bugs.kde.org", error));
2597  }
2598  }
2599 }
2600 
2601 
2602 void Part::restoreDocument(const KConfigGroup &group)
2603 {
2604  KUrl url ( group.readPathEntry( "URL", QString() ) );
2605  if ( url.isValid() )
2606  {
2607  QString viewport = group.readEntry( "Viewport" );
2608  if (!viewport.isEmpty()) m_document->setNextDocumentViewport( Okular::DocumentViewport( viewport ) );
2609  openUrl( url );
2610  }
2611 }
2612 
2613 
2614 void Part::saveDocumentRestoreInfo(KConfigGroup &group)
2615 {
2616  group.writePathEntry( "URL", url().url() );
2617  group.writeEntry( "Viewport", m_document->viewport().toString() );
2618 }
2619 
2620 
2621 void Part::psTransformEnded(int exit, QProcess::ExitStatus status)
2622 {
2623  Q_UNUSED( exit )
2624  if ( status != QProcess::NormalExit )
2625  return;
2626 
2627  QProcess *senderobj = sender() ? qobject_cast< QProcess * >( sender() ) : 0;
2628  if ( senderobj )
2629  {
2630  senderobj->close();
2631  senderobj->deleteLater();
2632  }
2633 
2634  setLocalFilePath( m_temporaryLocalFile );
2635  openUrl( m_temporaryLocalFile );
2636  m_temporaryLocalFile.clear();
2637 }
2638 
2639 
2640 void Part::unsetDummyMode()
2641 {
2642  if ( m_embedMode == PrintPreviewMode )
2643  return;
2644 
2645  m_sidebar->setItemEnabled( 2, true );
2646  m_sidebar->setItemEnabled( 3, true );
2647  m_sidebar->setSidebarVisibility( Okular::Settings::showLeftPanel() );
2648 
2649  // add back and next in history
2650  m_historyBack = KStandardAction::documentBack( this, SLOT(slotHistoryBack()), actionCollection() );
2651  m_historyBack->setWhatsThis( i18n( "Go to the place you were before" ) );
2652  connect(m_pageView, SIGNAL(mouseBackButtonClick()), m_historyBack, SLOT(trigger()));
2653 
2654  m_historyNext = KStandardAction::documentForward( this, SLOT(slotHistoryNext()), actionCollection());
2655  m_historyNext->setWhatsThis( i18n( "Go to the place you were after" ) );
2656  connect(m_pageView, SIGNAL(mouseForwardButtonClick()), m_historyNext, SLOT(trigger()));
2657 
2658  m_pageView->setupActions( actionCollection() );
2659 
2660  // attach the actions of the children widgets too
2661  m_formsMessage->setActionButton( m_pageView->toggleFormsAction() );
2662 
2663  // ensure history actions are in the correct state
2664  updateViewActions();
2665 }
2666 
2667 
2668 bool Part::handleCompressed( QString &destpath, const QString &path, const QString &compressedMimetype )
2669 {
2670  m_tempfile = 0;
2671 
2672  // we are working with a compressed file, decompressing
2673  // temporary file for decompressing
2674  KTemporaryFile *newtempfile = new KTemporaryFile();
2675  newtempfile->setAutoRemove(true);
2676 
2677  if ( !newtempfile->open() )
2678  {
2679  KMessageBox::error( widget(),
2680  i18n("<qt><strong>File Error!</strong> Could not create temporary file "
2681  "<nobr><strong>%1</strong></nobr>.</qt>",
2682  strerror(newtempfile->error())));
2683  delete newtempfile;
2684  return false;
2685  }
2686 
2687  // decompression filer
2688  QIODevice* filterDev = KFilterDev::deviceForFile( path, compressedMimetype );
2689  if (!filterDev)
2690  {
2691  delete newtempfile;
2692  return false;
2693  }
2694 
2695  if ( !filterDev->open(QIODevice::ReadOnly) )
2696  {
2697  KMessageBox::detailedError( widget(),
2698  i18n("<qt><strong>File Error!</strong> Could not open the file "
2699  "<nobr><strong>%1</strong></nobr> for uncompression. "
2700  "The file will not be loaded.</qt>", path),
2701  i18n("<qt>This error typically occurs if you do "
2702  "not have enough permissions to read the file. "
2703  "You can check ownership and permissions if you "
2704  "right-click on the file in the Dolphin "
2705  "file manager and then choose the 'Properties' tab.</qt>"));
2706 
2707  delete filterDev;
2708  delete newtempfile;
2709  return false;
2710  }
2711 
2712  char buf[65536];
2713  int read = 0, wrtn = 0;
2714 
2715  while ((read = filterDev->read(buf, sizeof(buf))) > 0)
2716  {
2717  wrtn = newtempfile->write(buf, read);
2718  if ( read != wrtn )
2719  break;
2720  }
2721  delete filterDev;
2722  if ((read != 0) || (newtempfile->size() == 0))
2723  {
2724  KMessageBox::detailedError(widget(),
2725  i18n("<qt><strong>File Error!</strong> Could not uncompress "
2726  "the file <nobr><strong>%1</strong></nobr>. "
2727  "The file will not be loaded.</qt>", path ),
2728  i18n("<qt>This error typically occurs if the file is corrupt. "
2729  "If you want to be sure, try to decompress the file manually "
2730  "using command-line tools.</qt>"));
2731  delete newtempfile;
2732  return false;
2733  }
2734  m_tempfile = newtempfile;
2735  destpath = m_tempfile->fileName();
2736  return true;
2737 }
2738 
2739 void Part::rebuildBookmarkMenu( bool unplugActions )
2740 {
2741  if ( unplugActions )
2742  {
2743  unplugActionList( "bookmarks_currentdocument" );
2744  qDeleteAll( m_bookmarkActions );
2745  m_bookmarkActions.clear();
2746  }
2747  KUrl u = m_document->currentDocument();
2748  if ( u.isValid() )
2749  {
2750  m_bookmarkActions = m_document->bookmarkManager()->actionsForUrl( u );
2751  }
2752  bool havebookmarks = true;
2753  if ( m_bookmarkActions.isEmpty() )
2754  {
2755  havebookmarks = false;
2756  QAction * a = new KAction( 0 );
2757  a->setText( i18n( "No Bookmarks" ) );
2758  a->setEnabled( false );
2759  m_bookmarkActions.append( a );
2760  }
2761  plugActionList( "bookmarks_currentdocument", m_bookmarkActions );
2762 
2763  if (factory())
2764  {
2765  const QList<KXMLGUIClient*> clients(factory()->clients());
2766  bool containerFound = false;
2767  for (int i = 0; !containerFound && i < clients.size(); ++i)
2768  {
2769  QWidget *container = factory()->container("bookmarks", clients[i]);
2770  if (container && container->actions().contains(m_bookmarkActions.first()))
2771  {
2772  Q_ASSERT(dynamic_cast<KMenu*>(container));
2773  disconnect(container, 0, this, 0);
2774  connect(container, SIGNAL(aboutToShowContextMenu(KMenu*,QAction*,QMenu*)), this, SLOT(slotAboutToShowContextMenu(KMenu*,QAction*,QMenu*)));
2775  containerFound = true;
2776  }
2777  }
2778  }
2779 
2780  m_prevBookmark->setEnabled( havebookmarks );
2781  m_nextBookmark->setEnabled( havebookmarks );
2782 }
2783 
2784 void Part::updateAboutBackendAction()
2785 {
2786  const KComponentData *data = m_document->componentData();
2787  if ( data )
2788  {
2789  m_aboutBackend->setEnabled( true );
2790  }
2791  else
2792  {
2793  m_aboutBackend->setEnabled( false );
2794  }
2795 }
2796 
2797 void Part::resetStartArguments()
2798 {
2799  m_cliPrint = false;
2800 }
2801 
2802 void Part::setReadWrite(bool readwrite)
2803 {
2804  m_document->setAnnotationEditingEnabled( readwrite );
2805  ReadWritePart::setReadWrite( readwrite );
2806 }
2807 
2808 } // namespace Okular
2809 
2810 #include "part.moc"
2811 
2812 /* kate: replace-tabs on; indent-width 4; */
Okular::Part::slotShowBottomBar
void slotShowBottomBar()
Definition: part.cpp:1521
generator.h
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
Okular::Document::reparseConfig
void reparseConfig()
Reparses and applies the configuration.
Definition: document.cpp:2474
Okular::Document::exportFormats
QList< ExportFormat > exportFormats() const
Returns the list of supported export formats.
Definition: document.cpp:2722
Okular::OkularLiveConnectExtension
Definition: extensions.h:36
detectConfigFileName
static QString detectConfigFileName(const QVariantList &args)
Definition: part.cpp:267
Okular::Part::queryClose
bool queryClose()
Definition: part.cpp:1389
Okular::Part::Part
Part(QWidget *parentWidget, QObject *parent, const QVariantList &args, KComponentData componentData)
If one element of 'args' contains one of the strings "Print/Preview" or "ViewerWidget", the part will be set up in the corresponding mode.
Definition: part.cpp:300
Okular::Part::slotPrintPreview
Q_SCRIPTABLE void slotPrintPreview()
Definition: part.cpp:2231
Okular::Document::NoPrinting
Printing Not Supported.
Definition: document.h:555
Okular::Part::slotPrint
void slotPrint()
Definition: part.cpp:2498
Okular::Part::slotFindPrev
void slotFindPrev()
Definition: part.cpp:2015
Okular::Part::loadCancelled
void loadCancelled(const QString &reason)
Definition: part.cpp:1004
Okular::PartFactory::~PartFactory
virtual ~PartFactory()
Definition: part.cpp:161
Okular::Document::setViewport
void setViewport(const DocumentViewport &viewport, DocumentObserver *excludeObserver=0, bool smoothMove=false)
Sets the current document viewport to the given viewport.
Definition: document.cpp:3128
Okular::Part::saveFile
bool saveFile()
Definition: part.cpp:2023
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::Document::NativePrinting
Native Cross-Platform Printing.
Definition: document.h:556
Okular::EmbedMode
EmbedMode
Describes the possible embedding modes of the part.
Definition: part.h:79
Okular::BookmarkManager::nextBookmark
KBookmark nextBookmark(const DocumentViewport &viewport) const
Given a viewport, returns the next bookmark.
Definition: bookmarkmanager.cpp:701
Okular::Document::canConfigurePrinter
bool canConfigurePrinter() const
Returns whether the document can configure the printer itself.
Definition: document.cpp:2518
Okular::Document::bookmarkManager
BookmarkManager * bookmarkManager() const
Returns the bookmark manager of the document.
Definition: document.cpp:3493
Okular::Document::pages
uint pages() const
Returns the number of pages of the document.
Definition: document.cpp:2652
Okular::Part::goToPage
Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page)
Definition: part.cpp:1094
Okular::ExportFormat::PlainText
Plain text.
Definition: generator.h:147
Okular::Document::supportsPrintToFile
bool supportsPrintToFile() const
Returns whether the document supports printing to both PDF and PS files.
Definition: document.cpp:3854
Okular::Part::slotGetNewStuff
void slotGetNewStuff()
Definition: part.cpp:2166
Okular::Part::documentMetaData
Q_SCRIPTABLE QString documentMetaData(const QString &metaData) const
Definition: part.cpp:1125
Okular::PartFactory::create
virtual QObject * create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword)
Definition: part.cpp:165
Okular::Page::number
int number() const
Returns the number of the page in the document.
Definition: page.cpp:160
QWidget
Okular::Document::exportToText
bool exportToText(const QString &fileName) const
Exports the document as ASCII text and saves it under fileName.
Definition: document.cpp:2710
Okular::Part::slotGeneratorPreferences
KConfigDialog * slotGeneratorPreferences()
Definition: part.cpp:1039
Okular::Document::currentDocument
KUrl currentDocument() const
Returns the url of the currently opened document.
Definition: document.cpp:2657
Okular::Part::startPresentation
void startPresentation()
Start the presentation mode.
Definition: part.cpp:879
Okular::Part::updateBookmarksActions
void updateBookmarksActions()
Definition: part.cpp:1744
Okular::KHTMLPartMode
Definition: part.h:84
Okular::Document::print
bool print(QPrinter &printer)
Prints the document to the given printer.
Definition: document.cpp:3859
Okular::Part::areSourceLocationsShownGraphically
bool areSourceLocationsShownGraphically() const
Returns true iff source locations are shown graphically.
Definition: part.cpp:935
Okular::Part::clearLastShownSourceLocation
void clearLastShownSourceLocation()
Clear the source location that was set last in the viewer.
Definition: part.cpp:912
Okular::Part::slotAboutToShowContextMenu
void slotAboutToShowContextMenu(KMenu *menu, QAction *action, QMenu *contextMenu)
Definition: part.cpp:1947
Okular::Part::slotDoFileDirty
void slotDoFileDirty()
Definition: part.cpp:1574
Okular::Document::supportedMimeTypes
QStringList supportedMimeTypes() const
Returns the list with the supported MIME types.
Definition: document.cpp:3950
Okular::Part::slotExportAs
void slotExportAs(QAction *)
Definition: part.cpp:2444
Okular::PartFactory
Definition: part.h:341
Okular::DocumentViewport::enabled
bool enabled
Definition: document.h:1051
Okular::DocumentObserver::Bookmark
Bookmarks has been changed.
Definition: observer.h:43
Okular::ViewerWidgetMode
Definition: part.h:85
QObject
Okular::Part::setWatchFileModeEnabled
void setWatchFileModeEnabled(bool enable)
Allows to enable or disable the watch file mode.
Definition: part.cpp:922
Okular::Document::SaveAnnotationsCapability
Can save annotation changes.
Definition: document.h:619
page.h
Okular::Document::openDocument
bool openDocument(const QString &docFile, const KUrl &url, const KMimeType::Ptr &mime)
Opens the document.
Definition: document.cpp:2060
Okular::Part::slotAboutBackend
void slotAboutBackend()
Definition: part.cpp:2418
Okular::Part::slotRenameBookmarkFromMenu
void slotRenameBookmarkFromMenu()
Definition: part.cpp:1931
Okular::Part::cannotQuit
void cannotQuit()
Definition: part.cpp:1506
Okular::Document::setNextViewport
void setNextViewport()
Sets the current document viewport to the previous viewport in the viewport history.
Definition: document.cpp:3208
Okular::Part::psTransformEnded
void psTransformEnded(int, QProcess::ExitStatus)
Definition: part.cpp:2621
Okular::Document::printError
QString printError() const
Returns the last print error in case print() failed.
Definition: document.cpp:3864
Okular::Document::isOpened
bool isOpened() const
Returns whether the document is currently opened.
Definition: document.cpp:2513
Okular::Document::rotation
Rotation rotation() const
Returns the current rotation of the document.
Definition: document.cpp:2751
Okular::Document::removeObserver
void removeObserver(DocumentObserver *observer)
Unregisters the given observer for the document.
Definition: document.cpp:2444
Okular::Part::slotPreviousBookmark
void slotPreviousBookmark()
Definition: part.cpp:1967
Okular::Part::slotNewConfig
void slotNewConfig()
Definition: part.cpp:2201
Okular::PartFactory::PartFactory
PartFactory()
Definition: part.cpp:156
actionForExportFormat
static QAction * actionForExportFormat(const Okular::ExportFormat &format, QObject *parent=0)
Definition: part.cpp:176
Okular::Document::printConfigurationWidget
QWidget * printConfigurationWidget() const
Returns a custom printer configuration page or 0 if no custom printer configuration page is available...
Definition: document.cpp:3901
Okular::Part::~Part
~Part()
Definition: part.cpp:830
Okular::ExportFormat::standardFormat
static ExportFormat standardFormat(StandardExportFormat type)
Builds a standard format for the specified type .
Definition: generator.cpp:582
Okular::Document::page
const Page * page(int number) const
Returns the page object for the given page number or 0 if the number is out of range.
Definition: document.cpp:2619
Okular::Part::closeUrl
bool closeUrl()
Definition: part.cpp:1484
Okular::Part::slotRenameCurrentViewportBookmark
void slotRenameCurrentViewportBookmark()
Definition: part.cpp:1942
Okular::Part::saveDocumentRestoreInfo
void saveDocumentRestoreInfo(KConfigGroup &group)
Definition: part.cpp:2614
Okular::Part::pages
Q_SCRIPTABLE uint pages()
Definition: part.cpp:1107
Okular::DocumentObserver::NeedSaveAs
Set along with Annotations when Save As is needed or annotation changes will be lost.
Definition: observer.h:48
Okular::Part::slotShowMenu
void slotShowMenu(const Okular::Page *page, const QPoint &point)
Definition: part.cpp:2265
Okular::Part::saveAs
bool saveAs(const KUrl &saveUrl)
Definition: part.cpp:2075
Okular::Part::enableCloseAction
void enableCloseAction(bool enable)
Okular::Part::slotReload
void slotReload()
Definition: part.cpp:2488
Okular::Part::openDocument
bool openDocument(const KUrl &url, uint page)
Open the document at the specified url at page page.
Definition: part.cpp:866
Okular::Document::isAllowed
bool isAllowed(Permission action) const
Returns whether the given action is allowed in the document.
Definition: document.cpp:2662
Okular::Part::guiActivateEvent
void guiActivateEvent(KParts::GUIActivateEvent *event)
Definition: part.cpp:1489
Okular::Part::setReadWrite
void setReadWrite(bool readwrite)
Definition: part.cpp:2802
Okular::Part::slotHidePresentation
void slotHidePresentation()
Definition: part.cpp:2387
Okular::Part::enablePrintAction
void enablePrintAction(bool enable)
Okular::Document::documentInfo
const DocumentInfo * documentInfo() const
Returns the meta data of the document or 0 if no meta data are available.
Definition: document.cpp:2529
Okular::Part::notifySetup
void notifySetup(const QVector< Okular::Page * > &pages, int setupFlags)
This method is called whenever the document is initialized or reconstructed.
Definition: part.cpp:1064
action.h
annotations.h
Okular::Document::setRotation
void setRotation(int rotation)
This slot is called whenever the user changes the rotation of the document.
Definition: document.cpp:4426
Okular::Annotation::External
Is stored external.
Definition: annotations.h:134
Okular::Annotation::flags
int flags() const
Returns the flags of the annotation.
Definition: annotations.cpp:593
Okular::PrintPreviewMode
Definition: part.h:83
Okular::Document::canSaveChanges
bool canSaveChanges(SaveCapability cap) const
Returns whether it's possible to save a given category of changes to another document.
Definition: document.cpp:4002
Okular::Document::bookmarkedPageRange
QString bookmarkedPageRange() const
Returns the range of the bookmarked.pages.
Definition: document.cpp:3514
Okular::GotoAction
The Goto action changes the viewport to another page or loads an external document.
Definition: action.h:115
Okular::Part::setWindowTitleFromDocument
void setWindowTitleFromDocument()
Definition: part.cpp:1021
Okular::Document::saveDocumentArchive
bool saveDocumentArchive(const QString &fileName)
Saves a document archive.
Definition: document.cpp:4180
aboutdata.h
extensions.h
Okular::Part
This is a "Part".
Definition: part.h:96
Okular::Part::slotFind
Q_SCRIPTABLE void slotFind()
Definition: part.cpp:1991
Okular::Part::slotShowProperties
void slotShowProperties()
Definition: part.cpp:2362
Okular::Document
The Document.
Definition: document.h:84
Okular::Page
Collector for all the data belonging to a page.
Definition: page.h:49
Okular::Part::currentDocument
Q_SCRIPTABLE QString currentDocument()
Definition: part.cpp:1119
Okular::Document::closeDocument
void closeDocument()
Closes the document.
Definition: document.cpp:2294
document.h
Okular::Part::slotHideFindBar
void slotHideFindBar()
Definition: part.cpp:1796
Okular::Part::openUrl
bool openUrl(const KUrl &url)
Definition: part.cpp:1343
Okular::Part::slotGotoFirst
Q_SCRIPTABLE void slotGotoFirst()
Definition: part.cpp:1868
Okular::Part::close
void close()
Definition: part.cpp:1496
Okular::Part::slotShowLeftPanel
void slotShowLeftPanel()
Definition: part.cpp:1512
Okular::Part::slotGoToPage
void slotGoToPage()
Definition: part.cpp:1846
Okular::DocumentViewport::pageNumber
int pageNumber
The number of the page nearest the center of the viewport.
Definition: document.h:1035
Okular::Document::componentData
const KComponentData * componentData() const
Returns the component data associated with the generator.
Definition: document.cpp:3971
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::Document::printingSupport
PrintingType printingSupport() const
Returns what sort of printing the document supports: Native, Postscript, None.
Definition: document.cpp:3832
Okular::Part::slotPreviousPage
Q_SCRIPTABLE void slotPreviousPage()
Definition: part.cpp:1854
Okular::Page::annotations
QLinkedList< Annotation * > annotations() const
Returns the list of annotations of the page.
Definition: page.cpp:492
Okular::Part::openUrlFromDocument
void openUrlFromDocument(const KUrl &url)
Definition: part.cpp:954
Okular::Part::currentPage
Q_SCRIPTABLE uint currentPage()
Definition: part.cpp:1113
Okular::Document::viewport
const DocumentViewport & viewport() const
Returns the current viewport of the document.
Definition: document.cpp:2624
Okular::Part::slotAddBookmark
void slotAddBookmark()
Definition: part.cpp:1904
Okular::DocumentInfo
A DOM tree containing information about the document.
Definition: document.h:1073
Okular::Part::slotShowEmbeddedFiles
void slotShowEmbeddedFiles()
Definition: part.cpp:2370
Okular::Document::metaData
QVariant metaData(const QString &key, const QVariant &option=QVariant()) const
Returns the meta data for the given key and option or an empty variant if the key doesn't exists...
Definition: document.cpp:2746
Okular::Document::setPrevViewport
void setPrevViewport()
Sets the current document viewport to the next viewport in the viewport history.
Definition: document.cpp:3191
Okular::DocumentObserver::DocumentChanged
The document is a new document.
Definition: observer.h:55
Okular::AllowPrint
Allows to print the document.
Definition: global.h:24
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::Part::slotNextBookmark
void slotNextBookmark()
Definition: part.cpp:1979
Okular::Part::slotFindNext
void slotFindNext()
Definition: part.cpp:2006
Okular::addFileToWatcher
static void addFileToWatcher(KDirWatch *watcher, const QString &filePath)
Definition: part.cpp:1178
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::Document::setNextDocumentViewport
void setNextDocumentViewport(const DocumentViewport &viewport)
Sets the next viewport in the viewport history.
Definition: document.cpp:3227
Okular::Part::openSourceReference
void openSourceReference(const QString &absFileName, int line, int column)
Okular::Document::setAnnotationEditingEnabled
void setAnnotationEditingEnabled(bool enable)
Control annotation editing (creation, modification and removal), which is enabled by default...
Definition: document.cpp:4288
Okular::Part::enableStartWithPrint
Q_SCRIPTABLE Q_NOREPLY void enableStartWithPrint()
Definition: part.cpp:2413
Okular::Part::slotFileDirty
void slotFileDirty(const QString &)
Definition: part.cpp:1530
detectEmbedMode
static Okular::EmbedMode detectEmbedMode(QWidget *parentWidget, QObject *parent, const QVariantList &args)
Definition: part.cpp:236
document_p.h
Okular::Part::slotShowPresentation
void slotShowPresentation()
Definition: part.cpp:2378
Okular::Document::guiClient
KXMLGUIClient * guiClient()
Returns the gui client of the generator, if it provides one.
Definition: document.cpp:2283
compressedMimeFor
static QString compressedMimeFor(const QString &mime_to_check)
Definition: part.cpp:186
Okular::Document::historyAtBegin
bool historyAtBegin() const
Returns whether the document history is at the begin.
Definition: document.cpp:2736
Okular::Document::configurableGenerators
int configurableGenerators() const
Returns the number of generators that have a configuration widget.
Definition: document.cpp:3943
Okular::Part::slotTogglePresentation
Q_SCRIPTABLE void slotTogglePresentation()
Definition: part.cpp:2394
Okular::DocumentViewport::normalizedY
double normalizedY
Definition: document.h:1053
Okular::Document::exportTo
bool exportTo(const QString &fileName, const ExportFormat &format) const
Exports the document in the given format and saves it under fileName.
Definition: document.cpp:2731
Okular::Part::openFile
bool openFile()
Definition: part.cpp:1186
Okular::Part::isWatchFileModeEnabled
bool isWatchFileModeEnabled() const
Returns true iff the watch file mode is enabled.
Definition: part.cpp:917
Okular::ExportFormat
Defines an entry for the export menu.
Definition: generator.h:75
Okular::Annotation
Annotation struct holds properties shared by all annotations.
Definition: annotations.h:90
Okular::Document::canExportToText
bool canExportToText() const
Returns whether the document supports the export to ASCII text.
Definition: document.cpp:2701
Okular::Part::restoreDocument
void restoreDocument(const KConfigGroup &group)
Definition: part.cpp:2602
Okular::Part::setShowSourceLocationsGraphically
void setShowSourceLocationsGraphically(bool show)
Allows to control whether source locations are shown graphically, or not.
Definition: part.cpp:940
Okular::Part::realUrl
KUrl realUrl() const
Definition: part.cpp:891
Okular::Part::enableTOC
void enableTOC(bool enable)
Definition: part.cpp:1773
Okular::BookmarkManager::addBookmark
void addBookmark(int page)
Adds a bookmark for the given page.
Definition: bookmarkmanager.cpp:385
Okular::Part::slotPreferences
Q_SCRIPTABLE void slotPreferences()
Definition: part.cpp:2178
Okular::Document::historyAtEnd
bool historyAtEnd() const
Returns whether the document history is at the end.
Definition: document.cpp:2741
Okular::Part::showSourceLocation
void showSourceLocation(const QString &fileName, int line, int column, bool showGraphically=true)
Show the specified source location centrally in the viewer.
Definition: part.cpp:901
Okular::Part::slotNextPage
Q_SCRIPTABLE void slotNextPage()
Definition: part.cpp:1861
Okular::Part::slotHistoryNext
void slotHistoryNext()
Definition: part.cpp:1898
fileprinter.h
Okular::Document::setNextDocumentDestination
void setNextDocumentDestination(const QString &namedDestination)
Sets the next namedDestination in the viewport history.
Definition: document.cpp:3232
Okular::Part::openUrlFromBookmarks
void openUrlFromBookmarks(const KUrl &url)
Definition: part.cpp:969
Okular::Part::viewerMenuStateChange
void viewerMenuStateChange(bool enabled)
Okular::Document::saveChanges
bool saveChanges(const QString &fileName)
Save the document and the optional changes to it to the specified fileName.
Definition: document.cpp:4019
Okular::Part::slotHistoryBack
void slotHistoryBack()
Definition: part.cpp:1892
Okular::Document::registerView
void registerView(View *view)
Register the specified view for the current document.
Definition: document.cpp:4040
Okular::Part::notifyPageChanged
void notifyPageChanged(int page, int flags)
This method is called whenever the content on page described by the passed flags has been changed...
Definition: part.cpp:1080
Okular::Part::supportedMimeTypes
QStringList supportedMimeTypes() const
Return a list with the supported mimetypes.
Definition: part.cpp:885
Okular::Part::notifyViewportChanged
void notifyViewportChanged(bool smoothMove)
This method is called whenever the viewport has been changed.
Definition: part.cpp:1075
Okular::DocumentViewport
A view on the document.
Definition: document.h:1003
Okular::Document::addObserver
void addObserver(DocumentObserver *observer)
Registers a new observer for the document.
Definition: document.cpp:2431
Okular::Part::slotRebuildBookmarkMenu
void slotRebuildBookmarkMenu()
Definition: part.cpp:1784
Okular::Document::fillConfigDialog
void fillConfigDialog(KConfigDialog *dialog)
Fill the KConfigDialog dialog with the setting pages of the generators.
Definition: document.cpp:3912
Okular::UnknownEmbedMode
Definition: part.h:81
Okular::Part::slotSaveCopyAs
void slotSaveCopyAs()
Definition: part.cpp:2120
Okular::DocumentViewport::toString
QString toString() const
Returns the viewport as xml description.
Definition: document.cpp:4560
Okular::Document::supportsSearching
bool supportsSearching() const
Returns whether the document supports searching.
Definition: document.cpp:2675
Okular::Part::slotSaveFileAs
void slotSaveFileAs()
Definition: part.cpp:2029
Okular::BookmarkManager::previousBookmark
KBookmark previousBookmark(const DocumentViewport &viewport) const
Given a viewport, returns the previous bookmark.
Definition: bookmarkmanager.cpp:720
Okular::Document::processAction
void processAction(const Action *action)
Processes the given action.
Definition: document.cpp:3560
Okular::BrowserExtension
Definition: extensions.h:21
Okular::DocumentViewport::TopLeft
Relative to the top left corner of the page.
Definition: document.h:1043
okularAboutData
KAboutData okularAboutData(const char *name, const char *iname)
Definition: aboutdata.h:17
Okular::Part::slotShowFindBar
void slotShowFindBar()
Definition: part.cpp:1789
Okular::Document::orientation
QPrinter::Orientation orientation() const
Returns the orientation of the document (for printing purposes).
Definition: document.cpp:4266
Okular::BookmarkManager::renameBookmark
void renameBookmark(KBookmark *bm, const QString &newName)
Returns the bookmark given bookmark of the document.
Definition: bookmarkmanager.cpp:477
Okular::DocumentPrivate::m_tiledObserver
DocumentObserver * m_tiledObserver
Definition: document_p.h:215
Okular::Part::reload
Q_SCRIPTABLE Q_NOREPLY void reload()
Definition: part.cpp:2405
KPluginFactory
Okular::Part::slotImportPSFile
bool slotImportPSFile()
Definition: part.cpp:1143
Okular::Document::embeddedFiles
const QList< EmbeddedFile * > * embeddedFiles() const
Returns the list of embedded files or 0 if no embedded files are available.
Definition: document.cpp:2614
Okular::NativeShellMode
Definition: part.h:82
Okular::Part::slotGotoLast
Q_SCRIPTABLE void slotGotoLast()
Definition: part.cpp:1877
Okular::DocumentViewport::isValid
bool isValid() const
Returns whether the viewport is valid.
Definition: document.cpp:4576
Okular::Document::openDocumentArchive
bool openDocumentArchive(const QString &docFile, const KUrl &url)
Opens a document archive.
Definition: document.cpp:4084
part.h
Okular::Part::slotJobStarted
void slotJobStarted(KIO::Job *job)
Definition: part.cpp:985
Okular::Document::setViewportPage
void setViewportPage(int page, DocumentObserver *excludeObserver=0, bool smoothMove=false)
Sets the current document viewport to the given page.
Definition: document.cpp:3116
Okular::Part::slotJobFinished
void slotJobFinished(KJob *job)
Definition: part.cpp:996
Okular::Part::updateViewActions
void updateViewActions()
Definition: part.cpp:1659
Okular::Document::currentPage
uint currentPage() const
Returns the number of the current page.
Definition: document.cpp:2647
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:45:03 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