27 #include <qapplication.h>
32 #include <QtGui/QPrinter>
33 #include <QtGui/QPrintDialog>
37 #include <kaboutapplicationdialog.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>
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>
59 #include <kfilterdev.h>
60 #include <kfilterbase.h>
62 #include <knewstuff2/engine.h>
64 #include <kdeprintdialog.h>
65 #include <kprintpreview.h>
66 #include <kbookmarkmenu.h>
67 #include <kpassworddialog.h>
73 #include "ui/pageview.h"
75 #include "ui/searchwidget.h"
76 #include "ui/thumbnaillist.h"
77 #include "ui/side_reviews.h"
78 #include "ui/minibar.h"
79 #include "ui/embeddedfilesdialog.h"
80 #include "ui/propertiesdialog.h"
81 #include "ui/presentationwidget.h"
82 #include "ui/pagesizelabel.h"
83 #include "ui/bookmarklist.h"
84 #include "ui/findbar.h"
85 #include "ui/sidebar.h"
86 #include "ui/fileprinterpreview.h"
87 #include "ui/guiutils.h"
88 #include "conf/preferencesdialog.h"
113 void open(
const QString & path )
123 int ret = std::fclose( m_handle );
129 KTemporaryFile* copyToTemporary()
const
134 KTemporaryFile * retFile =
new KTemporaryFile;
137 std::rewind( m_handle );
141 c = std::fgetc( m_handle );
144 if ( !retFile->putChar( (
char)c ) )
146 }
while ( !feof( m_handle ) );
154 std::FILE * m_handle;
168 Q_UNUSED ( keyword );
180 if ( !format.icon().isNull() )
193 static bool supportBzip =
false;
194 static bool supportXz =
false;
198 if ( compressedMimeMap.
isEmpty() )
200 std::auto_ptr< KFilterBase > f;
203 f.reset( KFilterBase::findFilterByMimeType( app_bzip ) );
213 f.reset( KFilterBase::findFilterByMimeType( app_xz ) );
220 if ( it != compressedMimeMap.
constEnd() )
223 KMimeType::Ptr mime = KMimeType::mimeType( mime_to_check );
226 if ( mime->is( app_gzip ) )
228 else if ( supportBzip && mime->is( app_bzip ) )
230 else if ( supportXz && mime->is( app_xz ) )
239 Q_UNUSED( parentWidget );
250 Q_FOREACH (
const QVariant &arg, args )
252 if ( arg.
type() == QVariant::String )
270 Q_FOREACH (
const QVariant &arg, args )
272 if ( arg.
type() == QVariant::String )
275 int separatorIndex = argString.
indexOf(
"=" );
276 if ( separatorIndex >= 0 && argString.
left( separatorIndex ) ==
QLatin1String(
"ConfigFileName" ) )
278 return argString.
mid( separatorIndex + 1 );
286 #undef OKULAR_KEEP_FILE_OPEN
288 #ifdef OKULAR_KEEP_FILE_OPEN
289 static bool keepFileOpen()
291 static bool keep_file_open = !qgetenv(
"OKULAR_NO_KEEP_FILE_OPEN").toInt();
292 return keep_file_open;
296 int Okular::Part::numberOfParts = 0;
303 const QVariantList &args,
304 KComponentData componentData )
305 : KParts::ReadWritePart(parent),
306 m_tempfile( 0 ), m_fileWasRemoved( false ), m_showMenuBarAction( 0 ), m_showFullScreenAction( 0 ), m_actionsSearched( false ),
307 m_cliPresentation(false), m_cliPrint(false), m_embedMode(
detectEmbedMode(parentWidget, parent, args)), m_generatorGuiClient(0), m_keeper( 0 )
311 if ( configFileName.
isEmpty() )
313 configFileName = KStandardDirs::locateLocal(
"config",
"okularpartrc" );
317 QString oldkpdfconffile = KStandardDirs::locateLocal(
"config",
"kpdfpartrc" );
322 Okular::Settings::instance( configFileName );
325 if (numberOfParts == 1) {
333 connect(
this, SIGNAL(started(KIO::Job*)),
this, SLOT(
slotJobStarted(KIO::Job*)));
345 setComponentData( componentData );
347 GuiUtils::addIconLoader( iconLoader() );
349 m_sidebar =
new Sidebar( parentWidget );
350 setWidget( m_sidebar );
355 connect( m_document, SIGNAL(linkFind()),
this, SLOT(
slotFind()) );
356 connect( m_document, SIGNAL(linkGoToPage()),
this, SLOT(
slotGoToPage()) );
361 connect( m_document, SIGNAL(
close()),
this, SLOT(
close()) );
364 connect( m_document, SIGNAL(quit()), parent, SLOT(slotQuit()) );
366 connect( m_document, SIGNAL(quit()),
this, SLOT(
cannotQuit()) );
377 m_toc =
new TOC( 0, m_document );
378 connect( m_toc, SIGNAL(hasTOC(
bool)),
this, SLOT(
enableTOC(
bool)) );
379 tbIndex = m_sidebar->addItem( m_toc, KIcon(
QApplication::isLeftToRight() ?
"format-justify-left" :
"format-justify-right"), i18n(
"Contents") );
383 KVBox * thumbsBox =
new ThumbnailsBox( 0 );
384 thumbsBox->setSpacing( 6 );
385 m_searchWidget =
new SearchWidget( thumbsBox, m_document );
386 m_thumbnailList =
new ThumbnailList( thumbsBox, m_document );
389 tbIndex = m_sidebar->addItem( thumbsBox, KIcon(
"view-preview" ), i18n(
"Thumbnails") );
390 m_sidebar->setCurrentIndex( tbIndex );
393 m_reviewsWidget =
new Reviews( 0, m_document );
394 m_sidebar->addItem( m_reviewsWidget, KIcon(
"draw-freehand"), i18n(
"Reviews") );
395 m_sidebar->setItemEnabled( 2,
false );
398 m_bookmarkList =
new BookmarkList( m_document, 0 );
399 m_sidebar->addItem( m_bookmarkList, KIcon(
"bookmarks"), i18n(
"Bookmarks") );
400 m_sidebar->setItemEnabled( 3,
false );
403 #ifdef OKULAR_ENABLE_MINIBAR
405 m_sidebar->setBottomWidget( miniBarContainer );
409 miniBarLayout->
addItem(
new QSpacerItem( 6, 6, QSizePolicy::Fixed, QSizePolicy::Fixed ) );
411 QFrame * bevelContainer =
new QFrame( miniBarContainer );
412 bevelContainer->
setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
415 m_progressWidget =
new ProgressWidget( bevelContainer, m_document );
416 bevelContainerLayout->
addWidget( m_progressWidget );
417 miniBarLayout->
addWidget( bevelContainer );
418 miniBarLayout->
addItem(
new QSpacerItem( 6, 6, QSizePolicy::Fixed, QSizePolicy::Fixed ) );
423 m_sidebar->setMainWidget( rightContainer );
429 m_topMessage =
new KMessageWidget( rightContainer );
430 m_topMessage->setVisible(
false );
431 m_topMessage->setWordWrap(
true );
432 m_topMessage->setMessageType( KMessageWidget::Information );
433 m_topMessage->setText( i18n(
"This document has embedded files. <a href=\"okular:/embeddedfiles\">Click here to see them</a> or go to File -> Embedded Files." ) );
434 m_topMessage->setIcon( KIcon(
"mail-attachment" ) );
437 m_formsMessage =
new KMessageWidget( rightContainer );
438 m_formsMessage->setVisible(
false );
439 m_formsMessage->setWordWrap(
true );
440 m_formsMessage->setMessageType( KMessageWidget::Information );
441 rightLayout->
addWidget( m_formsMessage );
442 m_infoMessage =
new KMessageWidget( rightContainer );
443 m_infoMessage->setVisible(
false );
444 m_infoMessage->setWordWrap(
true );
445 m_infoMessage->setMessageType( KMessageWidget::Information );
447 m_infoTimer =
new QTimer();
449 connect( m_infoTimer, SIGNAL(timeout()), m_infoMessage, SLOT(animatedHide()) );
450 m_pageView =
new PageView( rightContainer, m_document );
457 connect( m_document, SIGNAL(sourceReferenceActivated(
const QString&,
int,
int,
bool*)),
this, SLOT(slotHandleActivatedSourceReference(
const QString&,
int,
int,
bool*)) );
459 m_findBar =
new FindBar( m_document, rightContainer );
461 m_bottomBar =
new QWidget( rightContainer );
463 m_pageSizeLabel =
new PageSizeLabel( m_bottomBar, m_document );
466 bottomBarLayout->
addItem(
new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
467 m_miniBarLogic =
new MiniBarLogic(
this, m_document );
468 m_miniBar =
new MiniBar( m_bottomBar, m_miniBarLogic );
470 bottomBarLayout->
addWidget( m_pageSizeLabel );
473 m_pageNumberTool =
new MiniBar( 0, m_miniBarLogic );
475 connect( m_findBar, SIGNAL(forwardKeyPressEvent(
QKeyEvent*)), m_pageView, SLOT(externalKeyPressEvent(
QKeyEvent*)));
476 connect( m_findBar, SIGNAL(onCloseButtonPressed()), m_pageView, SLOT(setFocus()));
477 connect( m_miniBar, SIGNAL(forwardKeyPressEvent(
QKeyEvent*)), m_pageView, SLOT(externalKeyPressEvent(
QKeyEvent*)));
478 connect( m_pageView, SIGNAL(escPressed()), m_findBar, SLOT(resetSearch()) );
479 connect( m_pageNumberTool, SIGNAL(forwardKeyPressEvent(
QKeyEvent*)), m_pageView, SLOT(externalKeyPressEvent(
QKeyEvent*)));
491 #ifdef OKULAR_ENABLE_MINIBAR
501 setupViewerActions();
509 setViewerShortcuts();
513 m_watcher =
new KDirWatch(
this );
515 m_dirtyHandler =
new QTimer(
this );
517 connect( m_dirtyHandler, SIGNAL(timeout()),
this, SLOT(
slotDoFileDirty()) );
522 connect( Okular::Settings::self(), SIGNAL(configChanged()),
this, SLOT(
slotNewConfig()) );
525 const KService::Ptr kttsd = KService::serviceByDesktopName(
"kttsd");
526 Okular::Settings::setUseKTTSD( kttsd );
527 Okular::Settings::self()->writeConfig();
529 rebuildBookmarkMenu(
false );
533 setXMLFile(
"part-viewermode.rc");
538 setXMLFile(
"part.rc");
541 m_pageView->setupBaseActions( actionCollection() );
543 m_sidebar->setSidebarVisibility(
false );
547 m_pageView->setupViewerActions( actionCollection() );
559 m_pageView->updateActionState(
false,
false,
false );
562 m_sidebar->setAutoFillBackground(
false );
564 #ifdef OKULAR_KEEP_FILE_OPEN
565 m_keeper =
new FileKeeper();
569 void Part::setupViewerActions()
572 KActionCollection * ac = actionCollection();
575 m_gotoPage = KStandardAction::gotoPage(
this, SLOT(
slotGoToPage()), ac );
576 m_gotoPage->setShortcut(
QKeySequence(Qt::CTRL + Qt::Key_G) );
578 connect( m_miniBar, SIGNAL(gotoPage()), m_gotoPage, SLOT(trigger()) );
579 connect( m_pageNumberTool, SIGNAL(gotoPage()), m_gotoPage, SLOT(trigger()) );
582 m_prevPage->setIconText( i18nc(
"Previous page",
"Previous" ) );
583 m_prevPage->setToolTip( i18n(
"Go back to the Previous Page" ) );
584 m_prevPage->setWhatsThis( i18n(
"Moves to the previous page of the document" ) );
585 m_prevPage->setShortcut( 0 );
587 connect( m_miniBar, SIGNAL(prevPage()), m_prevPage, SLOT(trigger()) );
588 connect( m_pageNumberTool, SIGNAL(prevPage()), m_prevPage, SLOT(trigger()) );
589 #ifdef OKULAR_ENABLE_MINIBAR
590 connect( m_progressWidget, SIGNAL(prevPage()), m_prevPage, SLOT(trigger()) );
593 m_nextPage = KStandardAction::next(
this, SLOT(
slotNextPage()), ac );
594 m_nextPage->setIconText( i18nc(
"Next page",
"Next" ) );
595 m_nextPage->setToolTip( i18n(
"Advance to the Next Page" ) );
596 m_nextPage->setWhatsThis( i18n(
"Moves to the next page of the document" ) );
597 m_nextPage->setShortcut( 0 );
599 connect( m_miniBar, SIGNAL(nextPage()), m_nextPage, SLOT(trigger()) );
600 connect( m_pageNumberTool, SIGNAL(nextPage()), m_nextPage, SLOT(trigger()) );
601 #ifdef OKULAR_ENABLE_MINIBAR
602 connect( m_progressWidget, SIGNAL(nextPage()), m_nextPage, SLOT(trigger()) );
605 m_beginningOfDocument = KStandardAction::firstPage(
this, SLOT(
slotGotoFirst()), ac );
606 ac->addAction(
"first_page", m_beginningOfDocument);
607 m_beginningOfDocument->setText(i18n(
"Beginning of the document"));
608 m_beginningOfDocument->setWhatsThis( i18n(
"Moves to the beginning of the document" ) );
610 m_endOfDocument = KStandardAction::lastPage(
this, SLOT(
slotGotoLast()), ac );
611 ac->addAction(
"last_page",m_endOfDocument);
612 m_endOfDocument->setText(i18n(
"End of the document"));
613 m_endOfDocument->setWhatsThis( i18n(
"Moves to the end of the document" ) );
619 m_addBookmark = KStandardAction::addBookmark(
this, SLOT(
slotAddBookmark()), ac );
620 m_addBookmarkText = m_addBookmark->text();
621 m_addBookmarkIcon = m_addBookmark->icon();
623 m_renameBookmark = ac->addAction(
"rename_bookmark");
624 m_renameBookmark->setText(i18n(
"Rename Bookmark" ));
625 m_renameBookmark->setIcon(KIcon(
"edit-rename" ));
626 m_renameBookmark->setWhatsThis( i18n(
"Rename the current bookmark" ) );
629 m_prevBookmark = ac->addAction(
"previous_bookmark");
630 m_prevBookmark->setText(i18n(
"Previous Bookmark" ));
631 m_prevBookmark->setIcon(KIcon(
"go-up-search" ));
632 m_prevBookmark->setWhatsThis( i18n(
"Go to the previous bookmark" ) );
635 m_nextBookmark = ac->addAction(
"next_bookmark");
636 m_nextBookmark->setText(i18n(
"Next Bookmark" ));
637 m_nextBookmark->setIcon(KIcon(
"go-down-search" ));
638 m_nextBookmark->setWhatsThis( i18n(
"Go to the next bookmark" ) );
639 connect( m_nextBookmark, SIGNAL(triggered()),
this, SLOT(
slotNextBookmark()) );
649 m_find->setShortcuts( s );
650 m_find->setEnabled(
false );
652 m_findNext = KStandardAction::findNext(
this, SLOT(
slotFindNext()), ac);
653 m_findNext->setEnabled(
false );
655 m_findPrev = KStandardAction::findPrev(
this, SLOT(
slotFindPrev()), ac );
656 m_findPrev->setEnabled(
false );
664 prefs->
setText( i18n(
"Configure Okular..." ) );
669 prefs->
setText( i18n(
"Configure Viewer..." ) );
672 KAction * genPrefs =
new KAction( ac );
673 ac->addAction(
"options_configure_generators", genPrefs);
676 genPrefs->setText( i18n(
"Configure Viewer Backends..." ) );
680 genPrefs->setText( i18n(
"Configure Backends..." ) );
682 genPrefs->setIcon( KIcon(
"configure" ) );
686 m_printPreview = KStandardAction::printPreview(
this, SLOT(
slotPrintPreview()), ac );
687 m_printPreview->setEnabled(
false );
692 m_showProperties = ac->addAction(
"properties");
693 m_showProperties->setText(i18n(
"&Properties"));
694 m_showProperties->setIcon(KIcon(
"document-properties"));
696 m_showProperties->setEnabled(
false );
698 m_showEmbeddedFiles = 0;
699 m_showPresentation = 0;
704 m_exportAsDocArchive = 0;
706 m_aboutBackend = ac->addAction(
"help_about_backend");
707 m_aboutBackend->setText(i18n(
"About Backend"));
708 m_aboutBackend->setEnabled(
false );
709 connect(m_aboutBackend, SIGNAL(triggered()),
this, SLOT(
slotAboutBackend()));
711 KAction *
reload = ac->add<KAction>(
"file_reload" );
712 reload->setText( i18n(
"Reloa&d" ) );
713 reload->setIcon( KIcon(
"view-refresh" ) );
714 reload->setWhatsThis( i18n(
"Reload the current document from disk." ) );
715 connect( reload, SIGNAL(triggered()),
this, SLOT(
slotReload()) );
716 reload->setShortcut( KStandardShortcut::reload() );
719 m_closeFindBar = ac->addAction(
"close_find_bar",
this, SLOT(
slotHideFindBar()) );
720 m_closeFindBar->setText( i18n(
"Close &Find Bar") );
721 m_closeFindBar->setShortcut(
QKeySequence(Qt::Key_Escape) );
722 m_closeFindBar->setEnabled(
false );
724 KAction *pageno =
new KAction( i18n(
"Page Number" ), ac );
725 pageno->setDefaultWidget( m_pageNumberTool );
726 ac->addAction(
"page_number", pageno );
729 void Part::setViewerShortcuts()
731 KActionCollection * ac = actionCollection();
733 m_gotoPage->setShortcut(
QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_G) );
739 m_addBookmark->setShortcut(
QKeySequence( Qt::CTRL + Qt::ALT + Qt::Key_B ) );
741 m_beginningOfDocument->setShortcut(
QKeySequence( Qt::CTRL + Qt::ALT + Qt::Key_Home ) );
742 m_endOfDocument->setShortcut(
QKeySequence( Qt::CTRL + Qt::ALT + Qt::Key_End ) );
744 KAction *action =
static_cast<KAction*
>( ac->action(
"file_reload" ) );
748 void Part::setupActions()
750 KActionCollection * ac = actionCollection();
752 m_copy = KStandardAction::create( KStandardAction::Copy, m_pageView, SLOT(copyTextSelection()), ac );
754 m_selectAll = KStandardAction::selectAll( m_pageView, SLOT(selectAll()), ac );
756 m_saveCopyAs = KStandardAction::saveAs(
this, SLOT(
slotSaveCopyAs()), ac );
757 m_saveCopyAs->setText( i18n(
"Save &Copy As..." ) );
758 m_saveCopyAs->setShortcut( KShortcut() );
759 ac->addAction(
"file_save_copy", m_saveCopyAs );
760 m_saveCopyAs->setEnabled(
false );
762 m_saveAs = KStandardAction::saveAs(
this, SLOT(
slotSaveFileAs()), ac );
763 m_saveAs->setEnabled(
false );
765 m_showLeftPanel = ac->add<KToggleAction>(
"show_leftpanel");
766 m_showLeftPanel->setText(i18n(
"Show &Navigation Panel"));
767 m_showLeftPanel->setIcon(KIcon(
"view-sidetree" ));
768 connect( m_showLeftPanel, SIGNAL(toggled(
bool)),
this, SLOT(
slotShowLeftPanel()) );
769 m_showLeftPanel->setShortcut( Qt::Key_F7 );
770 m_showLeftPanel->setChecked( Okular::Settings::showLeftPanel() );
773 m_showBottomBar = ac->add<KToggleAction>(
"show_bottombar");
774 m_showBottomBar->setText(i18n(
"Show &Page Bar"));
775 connect( m_showBottomBar, SIGNAL(toggled(
bool)),
this, SLOT(
slotShowBottomBar()) );
776 m_showBottomBar->setChecked( Okular::Settings::showBottomBar() );
779 m_showEmbeddedFiles = ac->addAction(
"embedded_files");
780 m_showEmbeddedFiles->setText(i18n(
"&Embedded Files"));
781 m_showEmbeddedFiles->setIcon( KIcon(
"mail-attachment" ) );
783 m_showEmbeddedFiles->setEnabled(
false );
785 m_exportAs = ac->addAction(
"file_export_as");
786 m_exportAs->setText(i18n(
"E&xport As"));
787 m_exportAs->setIcon( KIcon(
"document-export" ) );
788 m_exportAsMenu =
new QMenu();
790 m_exportAs->setMenu( m_exportAsMenu );
792 m_exportAsMenu->
addAction( m_exportAsText );
793 m_exportAs->setEnabled(
false );
796 i18nc(
"A document format, Okular-specific",
"Document Archive" ),
797 KMimeType::mimeType(
"application/vnd.kde.okular-archive" ) ), m_exportAsMenu );
798 m_exportAsMenu->
addAction( m_exportAsDocArchive );
801 m_showPresentation = ac->addAction(
"presentation");
802 m_showPresentation->setText(i18n(
"P&resentation"));
803 m_showPresentation->setIcon( KIcon(
"view-presentation" ) );
805 m_showPresentation->setShortcut(
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_P ) );
806 m_showPresentation->setEnabled(
false );
808 QAction * importPS = ac->addAction(
"import_ps");
809 importPS->
setText(i18n(
"&Import PostScript as PDF..."));
810 importPS->
setIcon(KIcon(
"document-import"));
813 QAction * ghns = ac->addAction(
"get_new_stuff");
814 ghns->
setText(i18n(
"&Get Books From Internet..."));
815 ghns->
setIcon(KIcon(
"get-hot-new-stuff"));
821 KToggleAction *blackscreenAction =
new KToggleAction( i18n(
"Switch Blackscreen Mode" ), ac );
822 ac->addAction(
"switch_blackscreen_mode", blackscreenAction );
823 blackscreenAction->setShortcut(
QKeySequence( Qt::Key_B ) );
824 blackscreenAction->setIcon( KIcon(
"view-presentation" ) );
825 blackscreenAction->setEnabled(
false );
827 KToggleAction *drawingAction =
new KToggleAction( i18n(
"Toggle Drawing Mode" ), ac );
828 ac->addAction(
"presentation_drawing_mode", drawingAction );
829 drawingAction->setIcon( KIcon(
"draw-freehand" ) );
830 drawingAction->setEnabled(
false );
832 KAction *eraseDrawingAction =
new KAction( i18n(
"Erase Drawings" ), ac );
833 ac->addAction(
"presentation_erase_drawings", eraseDrawingAction );
834 eraseDrawingAction->setIcon( KIcon(
"draw-eraser" ) );
835 eraseDrawingAction->setEnabled(
false );
837 KAction *configureAnnotations =
new KAction( i18n(
"Configure Annotations..." ), ac );
838 ac->addAction(
"options_configure_annotations", configureAnnotations );
839 configureAnnotations->setIcon( KIcon(
"configure" ) );
840 connect(configureAnnotations, SIGNAL(triggered()),
this, SLOT(slotAnnotationPreferences()));
842 KAction *playPauseAction =
new KAction( i18n(
"Play/Pause Presentation" ), ac );
843 ac->addAction(
"presentation_play_pause", playPauseAction );
844 playPauseAction->setEnabled(
false );
849 GuiUtils::removeIconLoader( iconLoader() );
857 delete m_thumbnailList;
859 delete m_pageNumberTool;
860 delete m_miniBarLogic;
862 #ifdef OKULAR_ENABLE_MINIBAR
863 delete m_progressWidget;
865 delete m_pageSizeLabel;
866 delete m_reviewsWidget;
867 delete m_bookmarkList;
874 qDeleteAll( m_bookmarkActions );
876 delete m_exportAsMenu;
878 #ifdef OKULAR_KEEP_FILE_OPEN
899 m_cliPresentation =
true;
911 if ( !m_realUrl.isEmpty() )
924 if( showGraphically )
926 m_pageView->setLastSourceLocationViewport( m_document->
viewport() );
932 m_pageView->clearLastSourceLocationViewport();
937 return !m_watcher->isStopped();
942 if ( enabled && m_watcher->isStopped() )
944 m_watcher->startScan();
946 else if( !enabled && !m_watcher->isStopped() )
948 m_dirtyHandler->
stop();
949 m_watcher->stopScan();
955 return m_pageView->areSourceLocationsShownGraphically();
960 m_pageView->setShowSourceLocationsGraphically(show);
965 return Okular::Settings::self()->shellOpenFileInTabs();
968 void Part::slotHandleActivatedSourceReference(
const QString& absFileName,
int line,
int col,
bool *handled)
982 if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, widget()))
984 m_bExtension->openUrlNotify();
985 m_bExtension->setLocationBarUrl(url.prettyUrl());
988 KMessageBox::error( widget(), i18n(
"Could not open '%1'. File does not exist", url.pathOrUrl() ) );
1010 if ( urls.isEmpty() )
1027 job->addMetaData(
"accept", supportedMimeTypes.
join(
", ") +
", */*;q=0.5");
1029 connect(job, SIGNAL(result(KJob*)),
this, SLOT(
slotJobFinished(KJob*)));
1035 if ( job->error() == KIO::ERR_USER_CANCELED )
1037 m_pageView->displayMessage( i18n(
"The loading of %1 has been canceled.",
realUrl().pathOrUrl() ) );
1043 emit setWindowCaption(
QString() );
1044 resetStartArguments();
1053 KMessageBox::error( widget(), i18n(
"Could not open %1. Reason: %2", url().prettyUrl(), reason ) );
1062 QString title = Okular::Settings::displayDocumentNameOrPath() == Okular::Settings::EnumDisplayDocumentNameOrPath::Path ?
realUrl().pathOrUrl() :
realUrl().fileName();
1064 if ( Okular::Settings::displayDocumentTitle() )
1073 emit setWindowCaption( title );
1079 KConfigDialog * dialog =
new KConfigDialog( m_pageView,
"generator_prefs", Okular::Settings::self() );
1080 dialog->setAttribute( Qt::WA_DeleteOnClose );
1084 dialog->setCaption( i18n(
"Configure Viewer Backends" ) );
1088 dialog->setCaption( i18n(
"Configure Backends" ) );
1094 dialog->setWindowModality( Qt::ApplicationModal );
1106 rebuildBookmarkMenu();
1107 updateAboutBackendAction();
1108 m_findBar->resetSearch();
1125 rebuildBookmarkMenu();
1133 if ( i <= m_document->
pages() )
1146 return m_document->
pages();
1171 if ( metaData.
compare( element.
tagName(), Qt::CaseInsensitive ) == 0 )
1182 QString app = KStandardDirs::findExe(
"ps2pdf" );
1186 KMessageBox::error( widget(), i18n(
"The program \"ps2pdf\" was not found, so Okular can not import PS files using it." ), i18n(
"ps2pdf not found") );
1190 KUrl url = KFileDialog::getOpenUrl( KUrl(),
"application/postscript", this->widget() );
1191 if ( url.isLocalFile() )
1194 tf.setSuffix(
".pdf" );
1195 tf.setAutoRemove(
false );
1198 m_temporaryLocalFile = tf.fileName();
1201 setLocalFilePath( url.toLocalFile() );
1204 args << url.toLocalFile() << m_temporaryLocalFile;
1205 m_pageView->displayMessage(i18n(
"Importing PS file as PDF (this may take a while)..."));
1206 connect(p, SIGNAL(finished(
int,QProcess::ExitStatus)),
this, SLOT(
psTransformEnded(
int,QProcess::ExitStatus)));
1207 p->
start(app, args);
1211 m_temporaryLocalFile.
clear();
1217 if ( !watcher->contains( filePath ) ) watcher->addFile(filePath);
1226 bool uncompressOk =
true;
1227 KMimeType::Ptr mime = mimeA;
1228 QString fileNameToOpen = fileNameToOpenA;
1230 if ( compressedMime.
isEmpty() )
1232 if ( !compressedMime.
isEmpty() )
1234 *isCompressedFile =
true;
1235 uncompressOk = handleCompressed( fileNameToOpen, localFilePath(), compressedMime );
1236 mime = KMimeType::findByPath( fileNameToOpen );
1240 *isCompressedFile =
false;
1243 isDocumentArchive =
false;
1246 if ( mime->is(
"application/vnd.kde.okular-archive" ) )
1249 isDocumentArchive =
true;
1253 openResult = m_document->
openDocument( fileNameToOpen, url(), mime );
1257 QString walletName, walletFolder, walletKey;
1258 m_document->
walletDataForFile(fileNameToOpen, &walletName, &walletFolder, &walletKey);
1259 bool firstInput =
true;
1260 bool triedWallet =
false;
1261 KWallet::Wallet * wallet = 0;
1268 if ( !triedWallet && !walletKey.
isNull() )
1270 const WId parentwid = widget()->effectiveWinId();
1271 wallet = KWallet::Wallet::openWallet( walletName, parentwid );
1275 if ( !wallet->hasFolder( walletFolder ) )
1276 wallet->createFolder( walletFolder );
1277 wallet->setFolder( walletFolder );
1281 if ( !wallet->readPassword( walletKey, retrievedPass ) )
1282 password = retrievedPass;
1292 prompt = i18n(
"Please enter the password to read the document:" );
1294 prompt = i18n(
"Incorrect password. Try again:" );
1298 KPasswordDialog dlg( widget(), wallet ? KPasswordDialog::ShowKeepPassword : KPasswordDialog::KPasswordDialogFlags() );
1299 dlg.setCaption( i18n(
"Document Password" ) );
1300 dlg.setPrompt( prompt );
1303 password = dlg.password();
1305 keep = dlg.keepPassword();
1309 if ( mime->is(
"application/vnd.kde.okular-archive" ) )
1312 isDocumentArchive =
true;
1316 openResult = m_document->
openDocument( fileNameToOpen, url(), mime, password );
1322 wallet->writePassword( walletKey, password );
1333 QString fileNameToOpen = localFilePath();
1334 const bool isstdin = url().isLocalFile() && url().fileName( KUrl::ObeyTrailingSlash ) ==
QLatin1String(
"-" );
1335 const QFileInfo fileInfo( fileNameToOpen );
1336 if ( !isstdin && !fileInfo.
exists() )
1338 KMimeType::Ptr pathMime = KMimeType::findByPath( fileNameToOpen );
1339 if ( !arguments().mimeType().isEmpty() )
1341 KMimeType::Ptr argMime = KMimeType::mimeType( arguments().mimeType() );
1346 if ( argMime->is( pathMime->name() ) )
1350 else if ( pathMime->is( argMime->name() ) )
1356 mimes << pathMime << argMime;
1359 if (mimes[0]->name() ==
"text/plain") {
1360 KMimeType::Ptr contentMime = KMimeType::findByFileContent( fileNameToOpen );
1369 KMimeType::Ptr mime;
1371 bool isCompressedFile =
false;
1374 openResult = doOpenFile( mime, fileNameToOpen, &isCompressedFile );
1383 m_find->setEnabled( ok && canSearch );
1384 m_findNext->setEnabled( ok && canSearch );
1385 m_findPrev->setEnabled( ok && canSearch );
1386 if( m_saveAs ) m_saveAs->setEnabled( ok && (m_document->
canSaveChanges() || isDocumentArchive) );
1387 if( m_saveCopyAs ) m_saveCopyAs->setEnabled( ok );
1390 m_showProperties->setEnabled( ok );
1392 if ( m_showEmbeddedFiles ) m_showEmbeddedFiles->setEnabled( hasEmbeddedFiles );
1393 m_topMessage->setVisible( hasEmbeddedFiles && Okular::Settings::showOSD() );
1396 if ( ok && m_document->
metaData(
"HasUnsupportedXfaForm" ).
toBool() == true )
1398 m_formsMessage->setText( i18n(
"This document has XFA forms, which are currently <b>unsupported</b>." ) );
1399 m_formsMessage->setIcon( KIcon(
"dialog-warning" ) );
1400 m_formsMessage->setMessageType( KMessageWidget::Warning );
1401 m_formsMessage->setVisible(
true );
1404 else if ( ok && m_pageView->toggleFormsAction() && m_pageView->toggleFormsAction()->isEnabled() )
1406 m_formsMessage->setText( i18n(
"This document has forms. Click on the button to interact with them, or use View -> Show Forms." ) );
1407 m_formsMessage->setMessageType( KMessageWidget::Information );
1408 m_formsMessage->setVisible(
true );
1412 m_formsMessage->setVisible(
false );
1415 if ( m_showPresentation ) m_showPresentation->setEnabled( ok );
1423 QMenu *menu = m_exportAs->menu();
1424 for ( ; it != itEnd; ++it )
1429 if ( isCompressedFile )
1433 #ifdef OKULAR_KEEP_FILE_OPEN
1434 if ( keepFileOpen() )
1435 m_keeper->open( fileNameToOpen );
1439 if ( m_exportAsDocArchive ) m_exportAsDocArchive->
setEnabled( ok );
1440 if ( m_exportAs ) m_exportAs->setEnabled( ok );
1445 m_fileWasRemoved =
false;
1450 m_pageView->viewport()->update();
1451 m_thumbnailList->update();
1457 if ( url().isLocalFile() )
1463 if ( m_document->
metaData(
"OpenTOC" ).
toBool() && m_sidebar->isItemEnabled( 0 ) && !m_sidebar->isCollapsed() && m_sidebar->currentIndex() != 0 )
1465 m_sidebar->setCurrentIndex( 0, Sidebar::DoNotUncollapseIfCollapsed );
1469 if ( m_document->
metaData(
"StartFullScreen" ).
toBool() || m_cliPresentation )
1471 bool goAheadWithPresentationMode =
true;
1472 if ( !m_cliPresentation )
1474 const QString text = i18n(
"The document requested to be launched in presentation mode.\n"
1475 "Do you want to allow it?" );
1476 const QString caption = i18n(
"Presentation Mode" );
1477 const KGuiItem yesItem = KGuiItem( i18n(
"Allow" ),
"dialog-ok", i18n(
"Allow the presentation mode" ) );
1478 const KGuiItem noItem = KGuiItem( i18n(
"Do Not Allow" ),
"process-stop", i18n(
"Do not allow the presentation mode" ) );
1479 const int result = KMessageBox::questionYesNo( widget(), text, caption, yesItem, noItem );
1480 if ( result == KMessageBox::No )
1481 goAheadWithPresentationMode =
false;
1483 m_cliPresentation =
false;
1484 if ( goAheadWithPresentationMode )
1487 m_generatorGuiClient = factory() ? m_document->
guiClient() : 0;
1488 if ( m_generatorGuiClient )
1489 factory()->addClient( m_generatorGuiClient );
1505 if ( url.hasHTMLRef() )
1507 const QString dest = url.htmlRef();
1509 const int page = dest.
toInt( &ok );
1527 bool openOk = KParts::ReadWritePart::openUrl( url );
1537 resetStartArguments();
1538 KMessageBox::error( widget(), i18n(
"Could not open %1", url.pathOrUrl() ) );
1546 if ( !isReadWrite() || !isModified() )
1549 const int res = KMessageBox::warningYesNoCancel( widget(),
1550 i18n(
"Do you want to save your annotation changes or discard them?" ),
1551 i18n(
"Close Document" ),
1552 KStandardGuiItem::saveAs(),
1553 KStandardGuiItem::discard() );
1557 case KMessageBox::Yes:
1559 return !isModified();
1560 case KMessageBox::No:
1572 setModified(
false );
1574 if (!m_temporaryLocalFile.
isNull() && m_temporaryLocalFile != localFilePath())
1577 m_temporaryLocalFile.
clear();
1582 m_find->setEnabled(
false );
1583 m_findNext->setEnabled(
false );
1584 m_findPrev->setEnabled(
false );
1585 if( m_saveAs ) m_saveAs->setEnabled(
false );
1586 if( m_saveCopyAs ) m_saveCopyAs->setEnabled(
false );
1587 m_printPreview->setEnabled(
false );
1588 m_showProperties->setEnabled(
false );
1589 if ( m_showEmbeddedFiles ) m_showEmbeddedFiles->setEnabled(
false );
1590 if ( m_exportAs ) m_exportAs->setEnabled(
false );
1591 if ( m_exportAsText ) m_exportAsText->
setEnabled(
false );
1592 if ( m_exportAsDocArchive ) m_exportAsDocArchive->
setEnabled(
false );
1593 m_exportFormats.clear();
1596 QMenu *menu = m_exportAs->menu();
1598 int num = acts.
count();
1599 for (
int i = 2; i < num; ++i )
1605 if ( m_showPresentation ) m_showPresentation->setEnabled(
false );
1606 emit setWindowCaption(
"");
1609 if ( url().isLocalFile() )
1611 m_watcher->removeFile( localFilePath() );
1616 m_fileWasRemoved =
false;
1617 if ( m_generatorGuiClient )
1618 factory()->removeClient( m_generatorGuiClient );
1619 m_generatorGuiClient = 0;
1626 m_searchWidget->clearText();
1627 m_topMessage->setVisible(
false );
1628 m_formsMessage->setVisible(
false );
1630 #ifdef OKULAR_KEEP_FILE_OPEN
1633 bool r = KParts::ReadWritePart::closeUrl();
1648 KParts::ReadWritePart::guiActivateEvent(event);
1657 else KMessageBox::information( widget(), i18n(
"This link points to a close document action that does not work when using the embedded viewer." ),
QString(),
"warnNoCloseIfNotInOkular" );
1663 KMessageBox::information( widget(), i18n(
"This link points to a quit application action that does not work when using the embedded viewer." ),
QString(),
"warnNoQuitIfNotInOkular" );
1669 bool showLeft = m_showLeftPanel->isChecked();
1670 Okular::Settings::setShowLeftPanel( showLeft );
1671 Okular::Settings::self()->writeConfig();
1673 m_sidebar->setSidebarVisibility( showLeft );
1678 const bool showBottom = m_showBottomBar->isChecked();
1679 Okular::Settings::setShowBottomBar( showBottom );
1680 Okular::Settings::self()->writeConfig();
1682 m_bottomBar->setVisible( showBottom );
1692 if ( path == localFilePath() )
1696 m_dirtyHandler->
start( 750 );
1698 m_fileWasRemoved =
true;
1708 m_fileWasRemoved =
true;
1710 else if (m_fileWasRemoved &&
QFile::exists(localFilePath()))
1713 m_watcher->removeFile(localFilePath());
1714 m_watcher->addFile(localFilePath());
1715 m_dirtyHandler->
start( 750 );
1721 m_dirtyHandler->
start( 750 );
1723 m_fileWasRemoved =
true;
1731 bool tocReloadPrepared =
false;
1740 m_viewportDirty = m_document->
viewport();
1743 m_dirtyToolboxIndex = m_sidebar->currentIndex();
1744 m_wasSidebarVisible = m_sidebar->isSidebarVisible();
1745 m_wasSidebarCollapsed = m_sidebar->isCollapsed();
1748 m_wasPresentationOpen = ((PresentationWidget*)m_presentationWidget != 0);
1751 m_toc->prepareForReload();
1752 tocReloadPrepared =
true;
1755 m_dirtyPageRotation = m_document->
rotation();
1759 m_pageView->displayMessage( i18n(
"Reloading the document...") );
1767 if ( tocReloadPrepared )
1769 m_toc->rollbackReload();
1774 if ( tocReloadPrepared )
1775 m_toc->finishReload();
1778 m_pageView->displayMessage( i18n(
"Reloading the document...") );
1780 if ( KParts::ReadWritePart::openUrl( m_oldUrl ) )
1789 if ( m_sidebar->currentIndex() != m_dirtyToolboxIndex && m_sidebar->isItemEnabled( m_dirtyToolboxIndex )
1790 && !m_sidebar->isCollapsed() )
1792 m_sidebar->setCurrentIndex( m_dirtyToolboxIndex );
1794 if ( m_sidebar->isSidebarVisible() != m_wasSidebarVisible )
1796 m_sidebar->setSidebarVisibility( m_wasSidebarVisible );
1798 if ( m_sidebar->isCollapsed() != m_wasSidebarCollapsed )
1800 m_sidebar->setCollapsed( m_wasSidebarCollapsed );
1809 m_dirtyHandler->
start( 750 );
1816 bool opened = m_document->
pages() > 0;
1819 m_gotoPage->setEnabled( m_document->
pages() > 1 );
1824 m_beginningOfDocument->setEnabled(
true );
1825 m_prevPage->setEnabled(
true );
1829 if (m_pageView->verticalScrollBar()->value() != 0)
1832 m_beginningOfDocument->setEnabled(
true );
1837 m_beginningOfDocument->setEnabled(
false );
1840 m_prevPage->setEnabled(
false );
1846 m_nextPage->setEnabled(
false );
1847 if (m_pageView->verticalScrollBar()->value() == m_pageView->verticalScrollBar()->maximum())
1850 m_endOfDocument->setEnabled(
false );
1855 m_endOfDocument->setEnabled(
true );
1861 m_nextPage->setEnabled(
true );
1862 m_endOfDocument->setEnabled(
true );
1865 if (m_historyBack) m_historyBack->setEnabled( !m_document->
historyAtBegin() );
1866 if (m_historyNext) m_historyNext->setEnabled( !m_document->
historyAtEnd() );
1867 m_reload->setEnabled(
true );
1868 if (m_copy) m_copy->setEnabled(
true );
1869 if (m_selectAll) m_selectAll->setEnabled(
true );
1873 m_gotoPage->setEnabled(
false );
1874 m_beginningOfDocument->setEnabled(
false );
1875 m_endOfDocument->setEnabled(
false );
1876 m_prevPage->setEnabled(
false );
1877 m_nextPage->setEnabled(
false );
1878 if (m_historyBack) m_historyBack->setEnabled(
false );
1879 if (m_historyNext) m_historyNext->setEnabled(
false );
1880 m_reload->setEnabled(
false );
1881 if (m_copy) m_copy->setEnabled(
false );
1882 if (m_selectAll) m_selectAll->setEnabled(
false );
1887 QWidget *menu = factory()->container(
"menu_okular_part_viewer",
this);
1890 menu = factory()->container(
"view_orientation",
this);
1901 bool opened = m_document->
pages() > 0;
1904 m_addBookmark->setEnabled(
true );
1907 m_addBookmark->setText( i18n(
"Remove Bookmark" ) );
1908 m_addBookmark->setIcon( KIcon(
"edit-delete-bookmark" ) );
1909 m_renameBookmark->setEnabled(
true );
1913 m_addBookmark->setText( m_addBookmarkText );
1914 m_addBookmark->setIcon( m_addBookmarkIcon );
1915 m_renameBookmark->setEnabled(
false );
1920 m_addBookmark->setEnabled(
false );
1921 m_addBookmark->setText( m_addBookmarkText );
1922 m_addBookmark->setIcon( m_addBookmarkIcon );
1923 m_renameBookmark->setEnabled(
false );
1930 m_sidebar->setItemEnabled(0, enable);
1933 if ( enable && m_sidebar->currentIndex() != 0 )
1935 m_sidebar->setCurrentIndex( 0, Sidebar::DoNotUncollapseIfCollapsed );
1941 rebuildBookmarkMenu();
1947 m_findBar->focusAndSetCursor();
1948 m_closeFindBar->setEnabled(
true );
1953 if ( m_findBar->maybeHide() )
1955 m_pageView->setFocus();
1956 m_closeFindBar->setEnabled(
false );
1961 class GotoPageDialog :
public KDialog
1964 GotoPageDialog(
QWidget *p,
int current,
int max) : KDialog(p)
1966 setCaption(i18n(
"Go to Page"));
1967 setButtons(Ok | Cancel);
1968 setDefaultButton(Ok);
1976 e1 =
new KIntNumInput(current, w);
1977 e1->setRange(1, max);
1978 e1->setEditFocus(
true);
1979 e1->setSliderEnabled(
true);
2003 GotoPageDialog pageDialog( m_pageView, m_document->
currentPage() + 1, m_document->
pages() );
2004 if ( pageDialog.exec() == QDialog::Accepted )
2027 m_beginningOfDocument->setEnabled(
false );
2038 endPage.rePos.normalizedX = 0;
2039 endPage.rePos.normalizedY = 1;
2042 m_endOfDocument->setEnabled(
false);
2078 const QString newName = KInputDialog::getText( i18n(
"Rename Bookmark" ), i18n(
"Enter the new name of the bookmark:" ), bookmark.fullText(), 0, widget());
2093 slotRenameBookmark( vp );
2099 slotRenameBookmark( m_document->
viewport() );
2111 KBookmarkAction *ba =
dynamic_cast<KBookmarkAction*
>(action);
2115 separatorAction->
setObjectName(
"OkularPrivateRenameBookmarkActions");
2117 renameAction->
setData(ba->property(
"htmlRef").toString());
2118 renameAction->
setObjectName(
"OkularPrivateRenameBookmarkActions");
2126 if ( !bookmark.isNull() )
2138 if ( !bookmark.isNull() )
2150 if ( (PresentationWidget*)m_presentationWidget != 0 )
2152 m_presentationWidget->slotFind();
2163 if (m_findBar->isHidden())
2166 m_findBar->findNext();
2172 if (m_findBar->isHidden())
2175 m_findBar->findPrev();
2180 kDebug() <<
"Okular part doesn't support saving the file in the location from which it was opened";
2194 bool containsLocalAnnotations =
false;
2195 const int pagecount = m_document->
pages();
2197 for (
int pageno = 0; pageno < pagecount; ++pageno )
2204 containsLocalAnnotations =
true;
2208 if ( containsLocalAnnotations )
2213 if ( containsLocalAnnotations )
2215 int res = KMessageBox::warningContinueCancel( widget(), i18n(
"Your annotations will not be exported.\nYou can export the annotated document using File -> Export As -> Document Archive") );
2216 if ( res != KMessageBox::Continue )
2221 KUrl saveUrl = KFileDialog::getSaveUrl( url(),
2223 KFileDialog::ConfirmOverwrite );
2224 if ( !saveUrl.isValid() || saveUrl.isEmpty() )
2236 KMessageBox::information( widget(), i18n(
"Could not open the temporary file for saving." ) );
2239 fileName = tf.fileName();
2245 if ( isDocumentArchive )
2248 saved = m_document->
saveChanges( fileName, &errorText );
2254 KMessageBox::information( widget(), i18n(
"File could not be saved in '%1'. Try to save it to another location.", fileName ) );
2258 KMessageBox::information( widget(), i18n(
"File could not be saved in '%1'. %2", fileName, errorText ) );
2263 KIO::Job *copyJob = KIO::file_copy( fileName, saveUrl, -1, KIO::Overwrite );
2264 if ( !KIO::NetAccess::synchronousRun( copyJob, widget() ) )
2266 KMessageBox::information( widget(), i18n(
"File could not be saved in '%1'. Try to save it to another location.", saveUrl.prettyUrl() ) );
2270 setModified(
false );
2280 KUrl saveUrl = KFileDialog::getSaveUrl( KUrl(
"kfiledialog:///okular/" + url().fileName()),
2282 KFileDialog::ConfirmOverwrite );
2283 if ( saveUrl.isValid() && !saveUrl.isEmpty() )
2287 KUrl srcUrl = KUrl::fromPath( localFilePath() );
2288 KTemporaryFile * tempFile = 0;
2292 if ( url().isLocalFile() )
2294 #ifdef OKULAR_KEEP_FILE_OPEN
2296 if ( ( tempFile = m_keeper->copyToTemporary() ) )
2297 srcUrl = KUrl::fromPath( tempFile->fileName() );
2299 const QString msg = i18n(
"Okular cannot copy %1 to the specified location.\n\nThe document does not exist anymore.", localFilePath() );
2300 KMessageBox::sorry( widget(), msg );
2312 KIO::Job *copyJob = KIO::file_copy( srcUrl, saveUrl, -1, KIO::Overwrite );
2313 if ( !KIO::NetAccess::synchronousRun( copyJob, widget() ) )
2314 KMessageBox::information( widget(), i18n(
"File could not be saved in '%1'. Try to save it to another location.", saveUrl.prettyUrl() ) );
2324 KNS::Engine engine(widget());
2325 engine.init(
"okular.knsrc" );
2327 KNS::Entry::List entries = engine.downloadDialogModal( m_pageView );
2336 PreferencesDialog * dialog =
new PreferencesDialog( m_pageView, Okular::Settings::self(), m_embedMode );
2337 dialog->setAttribute( Qt::WA_DeleteOnClose );
2344 void Part::slotAnnotationPreferences()
2347 PreferencesDialog * dialog =
new PreferencesDialog( m_pageView, Okular::Settings::self(), m_embedMode );
2348 dialog->setAttribute( Qt::WA_DeleteOnClose );
2351 dialog->switchToAnnotationsPage();
2365 m_pageView->reparseConfig();
2371 if ( m_sidebar->isItemEnabled(0) )
2372 m_toc->reparseConfig();
2375 if ( Okular::Settings::showLeftPanel() && !m_thumbnailList->isHidden() )
2376 m_thumbnailList->updateWidgets();
2379 if ( m_sidebar->isItemEnabled(2) )
2380 m_reviewsWidget->reparseConfig();
2388 if (m_document->
pages() == 0)
return;
2395 KPrintPreview previewdlg( &printer, widget() );
2396 setupPrint( printer );
2404 tf.setAutoRemove(
true );
2405 tf.setSuffix(
".ps" );
2409 setupPrint( printer );
2413 Okular::FilePrinterPreview previewdlg( printer.
outputFileName(), widget() );
2425 bool reallyShow =
false;
2428 if (!m_actionsSearched)
2431 KActionCollection *ac;
2437 for(
int i = 0 ; (!m_showMenuBarAction || !m_showFullScreenAction) && i < clients.
size(); ++i)
2439 ac = clients.
at(i)->actionCollection();
2441 act = ac->action(
"options_show_menubar");
2442 if (act && qobject_cast<KToggleAction*>(act))
2443 m_showMenuBarAction = qobject_cast<KToggleAction*>(act);
2445 act = ac->action(
"fullscreen");
2446 if (act && qobject_cast<KToggleFullScreenAction*>(act))
2447 m_showFullScreenAction = qobject_cast<KToggleFullScreenAction*>(act);
2450 m_actionsSearched =
true;
2453 KMenu *popup =
new KMenu( widget() );
2459 popup->addTitle( i18n(
"Page %1", page->
number() + 1 ) );
2462 removeBookmark = popup->addAction( KIcon(
"edit-delete-bookmark"), i18n(
"Remove Bookmark") );
2464 addBookmark = popup->addAction( KIcon(
"bookmark-new"), i18n(
"Add Bookmark") );
2465 if ( m_pageView->canFitPageWidth() )
2466 fitPageWidth = popup->addAction( KIcon(
"zoom-fit-best"), i18n(
"Fit Width") );
2467 popup->addAction( m_prevBookmark );
2468 popup->addAction( m_nextBookmark );
2479 if ((m_showMenuBarAction && !m_showMenuBarAction->isChecked()) || (m_showFullScreenAction && m_showFullScreenAction->isChecked()))
2481 popup->addTitle( i18n(
"Tools" ) );
2482 if (m_showMenuBarAction && !m_showMenuBarAction->isChecked()) popup->addAction(m_showMenuBarAction);
2483 if (m_showFullScreenAction && m_showFullScreenAction->isChecked()) popup->addAction(m_showFullScreenAction);
2490 QAction *res = popup->exec(point);
2493 if (res == addBookmark)
2500 else if (res == removeBookmark)
2507 else if (res == fitPageWidth)
2509 m_pageView->fitPageWidth( page->
number() );
2519 PropertiesDialog *d =
new PropertiesDialog(widget(), m_document);
2527 EmbeddedFilesDialog *d =
new EmbeddedFilesDialog(widget(), m_document);
2535 if ( !m_presentationWidget )
2537 m_presentationWidget =
new PresentationWidget( widget(), m_document, actionCollection() );
2544 if ( m_presentationWidget )
2545 delete (PresentationWidget*) m_presentationWidget;
2553 if ( !m_presentationWidget )
2554 m_presentationWidget =
new PresentationWidget( widget(), m_document, actionCollection() );
2555 else delete (PresentationWidget*) m_presentationWidget;
2579 KAboutData aboutData( *data->aboutData() );
2581 if ( aboutData.programIconName().isEmpty() || aboutData.programIconName() == aboutData.appName() )
2585 const QString mimeTypeName = documentInfo->get(
"mimeType");
2586 if ( !mimeTypeName.
isEmpty() )
2588 if ( KMimeType::Ptr type = KMimeType::mimeType( mimeTypeName ) )
2589 aboutData.setProgramIconName( type->iconName() );
2594 KAboutApplicationDialog dlg( &aboutData, widget() );
2603 if ( (
id < 0 ) || (
id >= acts.
count() ) )
2610 filter =
"text/plain";
2613 filter =
"application/vnd.kde.okular-archive";
2616 filter = m_exportFormats.at(
id - 2 ).mimeType()->name();
2619 QString fileName = KFileDialog::getSaveFileName( url().isLocalFile() ? url().directory() :
QString(),
2621 KFileDialog::ConfirmOverwrite );
2634 saved = m_document->
exportTo( fileName, m_exportFormats.at(
id - 2 ) );
2638 KMessageBox::information( widget(), i18n(
"File could not be saved in '%1'. Try to save it to another location.", fileName ) );
2647 m_dirtyHandler->
stop();
2655 if (m_document->
pages() == 0)
return;
2658 QPrinter printer(QPrinter::HighResolution);
2663 QWidget *printConfigWidget = 0;
2666 setupPrint( printer );
2673 if ( printConfigWidget )
2675 printDialog = KdePrint::createPrintDialog( &printer,
QList<QWidget*>() << printConfigWidget, widget() );
2679 printDialog = KdePrint::createPrintDialog( &printer, widget() );
2696 if ( printDialog->
isOptionEnabled( QAbstractPrintDialog::PrintToFile ) &&
2702 #if QT_VERSION >= KDE_MAKE_VERSION(4,7,0)
2706 printDialog->
setOption( QAbstractPrintDialog::PrintCurrentPage );
2710 if ( printDialog->
exec() )
2717 void Part::setupPrint(
QPrinter &printer )
2734 void Part::doPrint(
QPrinter &printer)
2738 KMessageBox::error(widget(), i18n(
"Printing this document is not allowed."));
2742 if (!m_document->
print(printer))
2747 KMessageBox::error(widget(), i18n(
"Could not print the document. Unknown error. Please report to bugs.kde.org"));
2751 KMessageBox::error(widget(), i18n(
"Could not print the document. Detailed error is \"%1\". Please report to bugs.kde.org", error));
2759 KUrl url ( group.readPathEntry(
"URL",
QString() ) );
2760 if ( url.isValid() )
2762 QString viewport = group.readEntry(
"Viewport" );
2771 group.writePathEntry(
"URL", url().url() );
2779 if ( status != QProcess::NormalExit )
2782 QProcess *senderobj = sender() ? qobject_cast<
QProcess * >( sender() ) : 0;
2789 setLocalFilePath( m_temporaryLocalFile );
2790 openUrl( m_temporaryLocalFile );
2791 m_temporaryLocalFile.
clear();
2797 if ( !Okular::Settings::showOSD() )
2799 if (messageType == KMessageWidget::Error)
2801 KMessageBox::error( widget(), message );
2808 m_infoMessage->animatedHide();
2813 duration = 500 + 100 * message.
length();
2815 m_infoTimer->
start( duration );
2816 m_infoMessage->setText( message );
2817 m_infoMessage->setMessageType( messageType );
2818 m_infoMessage->setVisible(
true );
2835 m_pageView->displayMessage( message,
QString(), PageViewMessage::Info, duration );
2839 void Part::unsetDummyMode()
2844 m_sidebar->setItemEnabled( 2,
true );
2845 m_sidebar->setItemEnabled( 3,
true );
2846 m_sidebar->setSidebarVisibility( Okular::Settings::showLeftPanel() );
2849 m_historyBack = KStandardAction::documentBack(
this, SLOT(
slotHistoryBack()), actionCollection() );
2850 m_historyBack->setWhatsThis( i18n(
"Go to the place you were before" ) );
2851 connect(m_pageView, SIGNAL(mouseBackButtonClick()), m_historyBack, SLOT(trigger()));
2853 m_historyNext = KStandardAction::documentForward(
this, SLOT(
slotHistoryNext()), actionCollection());
2854 m_historyNext->setWhatsThis( i18n(
"Go to the place you were after" ) );
2855 connect(m_pageView, SIGNAL(mouseForwardButtonClick()), m_historyNext, SLOT(trigger()));
2857 m_pageView->setupActions( actionCollection() );
2860 m_formsMessage->addAction( m_pageView->toggleFormsAction() );
2861 m_formsMessage->setVisible( m_pageView->toggleFormsAction() != 0 );
2868 bool Part::handleCompressed(
QString &destpath,
const QString &path,
const QString &compressedMimetype )
2874 KTemporaryFile *newtempfile =
new KTemporaryFile();
2875 newtempfile->setAutoRemove(
true);
2877 if ( !newtempfile->open() )
2879 KMessageBox::error( widget(),
2880 i18n(
"<qt><strong>File Error!</strong> Could not create temporary file "
2881 "<nobr><strong>%1</strong></nobr>.</qt>",
2882 strerror(newtempfile->error())));
2888 QIODevice* filterDev = KFilterDev::deviceForFile( path, compressedMimetype );
2895 if ( !filterDev->
open(QIODevice::ReadOnly) )
2897 KMessageBox::detailedError( widget(),
2898 i18n(
"<qt><strong>File Error!</strong> Could not open the file "
2899 "<nobr><strong>%1</strong></nobr> for uncompression. "
2900 "The file will not be loaded.</qt>", path),
2901 i18n(
"<qt>This error typically occurs if you do "
2902 "not have enough permissions to read the file. "
2903 "You can check ownership and permissions if you "
2904 "right-click on the file in the Dolphin "
2905 "file manager and then choose the 'Properties' tab.</qt>"));
2913 int read = 0, wrtn = 0;
2915 while ((read = filterDev->
read(buf,
sizeof(buf))) > 0)
2917 wrtn = newtempfile->
write(buf, read);
2922 if ((read != 0) || (newtempfile->size() == 0))
2924 KMessageBox::detailedError(widget(),
2925 i18n(
"<qt><strong>File Error!</strong> Could not uncompress "
2926 "the file <nobr><strong>%1</strong></nobr>. "
2927 "The file will not be loaded.</qt>", path ),
2928 i18n(
"<qt>This error typically occurs if the file is corrupt. "
2929 "If you want to be sure, try to decompress the file manually "
2930 "using command-line tools.</qt>"));
2934 m_tempfile = newtempfile;
2935 destpath = m_tempfile->fileName();
2939 void Part::rebuildBookmarkMenu(
bool unplugActions )
2941 if ( unplugActions )
2943 unplugActionList(
"bookmarks_currentdocument" );
2944 qDeleteAll( m_bookmarkActions );
2945 m_bookmarkActions.
clear();
2952 bool havebookmarks =
true;
2953 if ( m_bookmarkActions.
isEmpty() )
2955 havebookmarks =
false;
2956 QAction * a =
new KAction( 0 );
2957 a->
setText( i18n(
"No Bookmarks" ) );
2959 m_bookmarkActions.
append( a );
2961 plugActionList(
"bookmarks_currentdocument", m_bookmarkActions );
2966 bool containerFound =
false;
2967 for (
int i = 0; !containerFound && i < clients.size(); ++i)
2969 QWidget *container = factory()->container(
"bookmarks", clients[i]);
2972 Q_ASSERT(dynamic_cast<KMenu*>(container));
2973 disconnect(container, 0,
this, 0);
2975 containerFound =
true;
2980 m_prevBookmark->setEnabled( havebookmarks );
2981 m_nextBookmark->setEnabled( havebookmarks );
2984 void Part::updateAboutBackendAction()
2989 m_aboutBackend->setEnabled(
true );
2993 m_aboutBackend->setEnabled(
false );
2997 void Part::resetStartArguments()
3005 ReadWritePart::setReadWrite( readwrite );
void setText(const QString &text)
void removeBookmark(int page)
Remove a bookmark for the given page.
void reparseConfig()
Reparses and applies the configuration.
QList< ExportFormat > exportFormats() const
Returns the list of supported export formats.
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
static QString detectConfigFileName(const QVariantList &args)
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.
void setFromTo(int from, int to)
Q_SCRIPTABLE void slotPrintPreview()
void loadCancelled(const QString &reason)
void setViewport(const DocumentViewport &viewport, DocumentObserver *excludeObserver=0, bool smoothMove=false)
Sets the current document viewport to the given viewport.
KBookmark bookmark(int page) const
Returns the bookmark for the given page of the document.
void setMinMax(int min, int max)
Native Cross-Platform Printing.
EmbedMode
Describes the possible embedding modes of the part.
void setOutputFileName(const QString &fileName)
QString attribute(const QString &name, const QString &defValue) const
KBookmark nextBookmark(const DocumentViewport &viewport) const
Given a viewport, returns the next bookmark.
void handleDroppedUrls(const KUrl::List &urls)
bool canConfigurePrinter() const
Returns whether the document can configure the printer itself.
BookmarkManager * bookmarkManager() const
Returns the bookmark manager of the document.
uint pages() const
Returns the number of pages of the document.
Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page)
bool supportsPrintToFile() const
Returns whether the document supports printing to both PDF and PS files.
Q_SCRIPTABLE QString documentMetaData(const QString &metaData) const
virtual QObject * create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword)
void setIcon(const QIcon &icon)
const T & at(int i) const
int number() const
Returns the number of the page in the document.
bool exportToText(const QString &fileName) const
Exports the document as ASCII text and saves it under fileName.
KConfigDialog * slotGeneratorPreferences()
KUrl currentDocument() const
Returns the url of the currently opened document.
void startPresentation()
Start the presentation mode.
void updateBookmarksActions()
bool registerObject(const QString &path, QObject *object, QFlags< QDBusConnection::RegisterOption > options)
void displayInfoMessage(const QString &message, KMessageWidget::MessageType messageType=KMessageWidget::Information, int duration=-1)
bool print(QPrinter &printer)
Prints the document to the given printer.
bool areSourceLocationsShownGraphically() const
Returns true iff source locations are shown graphically.
void clearLastShownSourceLocation()
Clear the source location that was set last in the viewer.
void slotAboutToShowContextMenu(KMenu *menu, QAction *action, QMenu *contextMenu)
const_iterator constFind(const Key &key) const
QDBusConnection sessionBus()
QStringList supportedMimeTypes() const
Returns the list with the supported MIME types.
QDomElement documentElement() const
void slotExportAs(QAction *)
void warningMessage(const QString &message, int duration=-1)
QString join(const QString &separator) const
void setOption(PrintDialogOption option, bool on)
Bookmarks has been changed.
void noticeMessage(const QString &message, int duration=-1)
void setFrameStyle(int style)
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
void addSpacing(int size)
void setWatchFileModeEnabled(bool enable)
Allows to enable or disable the watch file mode.
bool copy(const QString &newName)
Can save annotation changes.
void slotRenameBookmarkFromMenu()
void setNextViewport()
Sets the current document viewport to the previous viewport in the viewport history.
void psTransformEnded(int, QProcess::ExitStatus)
QString printError() const
Returns the last print error in case print() failed.
bool isOpened() const
Returns whether the document is currently opened.
OpenResult
Describes the result of an open document operation.
int indexOf(const T &value, int from) const
void addEnabledOption(PrintDialogOption option)
Rotation rotation() const
Returns the current rotation of the document.
void removeObserver(DocumentObserver *observer)
Unregisters the given observer for the document.
void setBuddy(QWidget *buddy)
QDomElement toElement() const
QList< T > findChildren(const QString &name) const
void slotPreviousBookmark()
QString outputFileName() const
static QAction * actionForExportFormat(const Okular::ExportFormat &format, QObject *parent=0)
QWidget * printConfigurationWidget() const
Returns a custom printer configuration page or 0 if no custom printer configuration page is available...
const Page * page(int number) const
Returns the page object for the given page number or 0 if the number is out of range.
void slotRenameCurrentViewportBookmark()
void mimeTypeChanged(KMimeType::Ptr mimeType)
void saveDocumentRestoreInfo(KConfigGroup &group)
int count(const T &value) const
Q_SCRIPTABLE uint pages()
Set along with Annotations when Save As is needed or annotation changes will be lost.
void slotShowMenu(const Okular::Page *page, const QPoint &point)
void append(const T &value)
bool saveAs(const KUrl &saveUrl)
const_iterator constEnd() const
void enableCloseAction(bool enable)
bool openDocument(const KUrl &url, uint page)
Open the document at the specified url at page page.
bool isAllowed(Permission action) const
Returns whether the given action is allowed in the document.
void guiActivateEvent(KParts::GUIActivateEvent *event)
void setReadWrite(bool readwrite)
void slotHidePresentation()
void enablePrintAction(bool enable)
const DocumentInfo * documentInfo() const
Returns the meta data of the document or 0 if no meta data are available.
void notifySetup(const QVector< Okular::Page * > &pages, int setupFlags)
This method is called whenever the document is initialized or reconstructed.
void setRotation(int rotation)
This slot is called whenever the user changes the rotation of the document.
int toInt(bool *ok, int base) const
virtual void addItem(QLayoutItem *item)
int flags() const
Returns the flags of the annotation.
bool canSaveChanges(SaveCapability cap) const
Returns whether it's possible to save a given category of changes to another document.
QString bookmarkedPageRange() const
Returns the range of the bookmarked.pages.
The Goto action changes the viewport to another page or loads an external document.
void setWindowTitleFromDocument()
bool saveDocumentArchive(const QString &fileName)
Saves a document archive.
Q_SCRIPTABLE void slotFind()
void slotShowProperties()
void setDocName(const QString &name)
Collector for all the data belonging to a page.
qint64 read(char *data, qint64 maxSize)
Q_SCRIPTABLE QString currentDocument()
void closeDocument()
Closes the document.
bool openUrl(const KUrl &url)
Q_SCRIPTABLE void slotGotoFirst()
void setMargin(int margin)
bool isOptionEnabled(PrintDialogOption option) const
int pageNumber
The number of the page nearest the center of the viewport.
const KComponentData * componentData() const
Returns the component data associated with the generator.
struct Okular::DocumentViewport::@0 rePos
If 'rePos.enabled == true' then this structure contains the viewport center or top left depending on ...
PrintingType printingSupport() const
Returns what sort of printing the document supports: Native, Postscript, None.
Q_SCRIPTABLE void slotPreviousPage()
void setData(const QVariant &userData)
QLinkedList< Annotation * > annotations() const
Returns the list of annotations of the page.
void openUrlFromDocument(const KUrl &url)
Q_SCRIPTABLE uint currentPage()
void errorMessage(const QString &message, int duration=0)
void setShortcut(const QKeySequence &shortcut)
const DocumentViewport & viewport() const
Returns the current viewport of the document.
bool contains(const T &value) const
A DOM tree containing information about the document.
void slotShowEmbeddedFiles()
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...
void setOrientation(Orientation orientation)
void setPrevViewport()
Sets the current document viewport to the next viewport in the viewport history.
void setEnabledOptions(QFlags< QAbstractPrintDialog::PrintDialogOption > options)
The document is a new document.
Allows to print the document.
OpenResult openDocument(const QString &docFile, const KUrl &url, const KMimeType::Ptr &mime, const QString &password=QString())
Opens the document.
bool isBookmarked(int page) const
Returns whether the given page is bookmarked.
static void addFileToWatcher(KDirWatch *watcher, const QString &filePath)
QList< QAction * > actionsForUrl(const KUrl &url) const
Returns a list of actions for the bookmarks of the specified url.
void setNextDocumentViewport(const DocumentViewport &viewport)
Sets the next viewport in the viewport history.
void openSourceReference(const QString &absFileName, int line, int column)
void setAnnotationEditingEnabled(bool enable)
Control annotation editing (creation, modification and removal), which is enabled by default...
Q_SCRIPTABLE Q_NOREPLY void enableStartWithPrint()
void slotFileDirty(const QString &)
static Okular::EmbedMode detectEmbedMode(QWidget *parentWidget, QObject *parent, const QVariantList &args)
QDomNode firstChild() const
void slotShowPresentation()
QString mid(int position, int n) const
KXMLGUIClient * guiClient()
Returns the gui client of the generator, if it provides one.
static QString compressedMimeFor(const QString &mime_to_check)
bool historyAtBegin() const
Returns whether the document history is at the begin.
int configurableGenerators() const
Returns the number of generators that have a configuration widget.
Q_SCRIPTABLE void slotTogglePresentation()
bool exportTo(const QString &fileName, const ExportFormat &format) const
Exports the document in the given format and saves it under fileName.
void addStretch(int stretch)
bool isWatchFileModeEnabled() const
Returns true iff the watch file mode is enabled.
Annotation struct holds properties shared by all annotations.
bool canExportToText() const
Returns whether the document supports the export to ASCII text.
void urlsDropped(const KUrl::List &urls)
bool openNewFilesInTabs() const
Should the shell that supports tabs pen new files in tabs?
void restoreDocument(const KConfigGroup &group)
void setShowSourceLocationsGraphically(bool show)
Allows to control whether source locations are shown graphically, or not.
void enableTOC(bool enable)
void addBookmark(int page)
Adds a bookmark for the given page.
Q_SCRIPTABLE void slotPreferences()
bool historyAtEnd() const
Returns whether the document history is at the end.
void showSourceLocation(const QString &fileName, int line, int column, bool showGraphically=true)
Show the specified source location centrally in the viewer.
Q_SCRIPTABLE void slotNextPage()
void setNextDocumentDestination(const QString &namedDestination)
Sets the next namedDestination in the viewport history.
void openUrlFromBookmarks(const KUrl &url)
QString left(int n) const
qint64 write(const char *data, qint64 maxSize)
QString fromLatin1(const char *str, int size)
void viewerMenuStateChange(bool enabled)
bool saveChanges(const QString &fileName)
Save the document and the optional changes to it to the specified fileName.
void registerView(View *view)
Register the specified view for the current document.
void prepend(const T &value)
void notifyPageChanged(int page, int flags)
This method is called whenever the content on page described by the passed flags has been changed...
QStringList supportedMimeTypes() const
Return a list with the supported mimetypes.
void notifyViewportChanged(bool smoothMove)
This method is called whenever the viewport has been changed.
void addObserver(DocumentObserver *observer)
Registers a new observer for the document.
void slotRebuildBookmarkMenu()
void fillConfigDialog(KConfigDialog *dialog)
Fill the KConfigDialog dialog with the setting pages of the generators.
QString toString() const
Returns the viewport as xml description.
bool supportsSearching() const
Returns whether the document supports searching.
KBookmark previousBookmark(const DocumentViewport &viewport) const
Given a viewport, returns the previous bookmark.
void processAction(const Action *action)
Processes the given action.
Relative to the top left corner of the page.
KAboutData okularAboutData(const char *name, const char *iname)
QString absolutePath() const
QPrinter::Orientation orientation() const
Returns the orientation of the document (for printing purposes).
void renameBookmark(KBookmark *bm, const QString &newName)
Returns the bookmark given bookmark of the document.
PrintDialogOptions enabledOptions() const
int compare(const QString &other) const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Q_SCRIPTABLE Q_NOREPLY void reload()
const QList< EmbeddedFile * > * embeddedFiles() const
Returns the list of embedded files or 0 if no embedded files are available.
Q_SCRIPTABLE void slotGotoLast()
void start(const QString &program, const QStringList &arguments, QFlags< QIODevice::OpenModeFlag > mode)
void setSpacing(int spacing)
bool isValid() const
Returns whether the viewport is valid.
QByteArray encodeName(const QString &fileName)
void slotJobStarted(KIO::Job *job)
void setViewportPage(int page, DocumentObserver *excludeObserver=0, bool smoothMove=false)
Sets the current document viewport to the given page.
void walletDataForFile(const QString &fileName, QString *walletName, QString *walletFolder, QString *walletKey) const
Returns which wallet data to use to read/write the password for the given fileName.
void slotJobFinished(KJob *job)
OpenResult openDocumentArchive(const QString &docFile, const KUrl &url, const QString &password=QString())
Opens a document archive.
void setSingleShot(bool singleShot)
uint currentPage() const
Returns the number of the current page.