2004-08-26 21:17:24 +00:00
/***************************************************************************
* Copyright ( C ) 2002 by Wilco Greven < greven @ kde . org > *
* Copyright ( C ) 2002 by Chris Cheney < ccheney @ cheney . cx > *
* Copyright ( C ) 2002 by Malcolm Hunter < malcolm . hunter @ gmx . co . uk > *
* Copyright ( C ) 2003 - 2004 by Christophe Devriese *
* < Christophe . Devriese @ student . kuleuven . ac . be > *
* Copyright ( C ) 2003 by Daniel Molkentin < molkentin @ kde . org > *
* Copyright ( C ) 2003 by Andy Goossens < andygoossens @ telenet . be > *
* Copyright ( C ) 2003 by Dirk Mueller < mueller @ kde . org > *
* Copyright ( C ) 2003 by Laurent Montel < montel @ kde . org > *
* Copyright ( C ) 2004 by Dominique Devriese < devriese @ kde . org > *
* Copyright ( C ) 2004 by Christoph Cullmann < crossfire @ babylon2k . de > *
* Copyright ( C ) 2004 by Henrique Pinto < stampede @ coltec . ufmg . br > *
* Copyright ( C ) 2004 by Waldo Bastian < bastian @ kde . org > *
2008-03-17 23:02:33 +00:00
* Copyright ( C ) 2004 - 2008 by Albert Astals Cid < aacid @ kde . org > *
2004-09-02 18:11:19 +00:00
* Copyright ( C ) 2004 by Antti Markus < antti . markus @ starman . ee > *
2004-08-26 21:17:24 +00:00
* *
* This program is free software ; you can redistribute it and / or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation ; either version 2 of the License , or *
* ( at your option ) any later version . *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-04-19 18:30:20 +00:00
# include "part.h"
2005-01-02 14:55:14 +00:00
// qt/kde includes
2007-01-05 19:02:39 +00:00
# include <qapplication.h>
2007-08-21 23:18:17 +00:00
# include <qfile.h>
2004-09-09 13:25:40 +00:00
# include <qlayout.h>
# include <qlabel.h>
2007-12-07 15:40:25 +00:00
# include <qtimer.h>
2007-10-15 23:01:27 +00:00
# include <QtGui/QPrinter>
# include <QtGui/QPrintDialog>
2010-09-03 21:30:30 +00:00
# include <QScrollBar>
2007-10-15 23:01:27 +00:00
2006-03-24 21:31:46 +00:00
# include <kvbox.h>
2007-03-07 18:15:00 +00:00
# include <kaboutapplicationdialog.h>
2002-08-30 09:14:01 +00:00
# include <kaction.h>
2006-05-13 14:59:50 +00:00
# include <kactioncollection.h>
2004-12-01 22:18:27 +00:00
# include <kdirwatch.h>
2006-12-19 12:23:43 +00:00
# include <kstandardaction.h>
2011-08-09 15:37:05 +00:00
# include <kpluginfactory.h>
2004-08-28 17:59:17 +00:00
# include <kfiledialog.h>
2011-10-25 20:21:22 +00:00
# include <kinputdialog.h>
2004-08-28 14:18:45 +00:00
# include <kmessagebox.h>
2004-09-09 13:25:40 +00:00
# include <knuminput.h>
2004-09-16 21:27:34 +00:00
# include <kio/netaccess.h>
2006-03-24 22:57:41 +00:00
# include <kmenu.h>
2004-12-04 23:23:18 +00:00
# include <kxmlguiclient.h>
# include <kxmlguifactory.h>
2006-05-22 14:02:24 +00:00
# include <kservicetypetrader.h>
2005-07-15 18:20:57 +00:00
# include <kstandarddirs.h>
2007-05-06 11:23:26 +00:00
# include <kstandardshortcut.h>
2006-10-16 17:57:44 +00:00
# include <ktemporaryfile.h>
2006-05-08 18:57:49 +00:00
# include <ktoggleaction.h>
2006-05-13 14:59:50 +00:00
# include <ktogglefullscreenaction.h>
2005-11-04 11:59:51 +00:00
# include <kio/job.h>
2006-08-05 10:35:03 +00:00
# include <kicon.h>
2007-01-12 23:54:26 +00:00
# include <kfilterdev.h>
2010-08-14 15:16:07 +00:00
# include <kfilterbase.h>
2009-12-26 16:23:36 +00:00
#if 0
2007-07-19 22:27:45 +00:00
# include <knewstuff2/engine.h>
2009-12-26 16:23:36 +00:00
# endif
2007-10-15 23:01:27 +00:00
# include <kdeprintdialog.h>
2007-10-18 20:25:33 +00:00
# include <kprintpreview.h>
2011-10-25 22:19:58 +00:00
# include <kbookmarkmenu.h>
2007-01-12 23:54:26 +00:00
2005-01-02 14:55:14 +00:00
// local includes
2007-03-10 23:45:12 +00:00
# include "aboutdata.h"
2008-04-01 09:10:46 +00:00
# include "extensions.h"
2005-01-02 14:29:37 +00:00
# include "ui/pageview.h"
# include "ui/toc.h"
2005-03-24 19:50:28 +00:00
# include "ui/searchwidget.h"
# include "ui/thumbnaillist.h"
# include "ui/side_reviews.h"
2005-01-26 10:42:07 +00:00
# include "ui/minibar.h"
2006-05-28 16:54:54 +00:00
# include "ui/embeddedfilesdialog.h"
2005-01-02 14:29:37 +00:00
# include "ui/propertiesdialog.h"
# include "ui/presentationwidget.h"
2006-10-15 19:37:14 +00:00
# include "ui/pagesizelabel.h"
2006-12-27 16:04:49 +00:00
# include "ui/bookmarklist.h"
2007-03-17 22:58:41 +00:00
# include "ui/findbar.h"
2007-08-06 17:24:10 +00:00
# include "ui/sidebar.h"
2007-12-03 00:17:12 +00:00
# include "ui/fileprinterpreview.h"
2007-12-24 15:02:32 +00:00
# include "ui/guiutils.h"
2005-01-02 14:29:37 +00:00
# include "conf/preferencesdialog.h"
2006-03-28 22:22:10 +00:00
# include "settings.h"
2011-09-10 17:15:52 +00:00
# include "core/action.h"
2012-06-13 13:33:49 +00:00
# include "core/annotations.h"
2007-01-13 17:28:54 +00:00
# include "core/bookmarkmanager.h"
2005-01-02 14:29:37 +00:00
# include "core/document.h"
2013-02-24 21:58:53 +00:00
# include "core/document_p.h"
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
# include "core/generator.h"
2005-01-02 14:29:37 +00:00
# include "core/page.h"
2007-11-26 21:43:54 +00:00
# include "core/fileprinter.h"
2003-06-28 01:59:03 +00:00
2008-06-07 21:08:41 +00:00
# include <cstdio>
2010-08-14 15:16:07 +00:00
# include <memory>
2008-06-07 21:08:41 +00:00
class FileKeeper
{
public :
FileKeeper ( )
: m_handle ( NULL )
{
}
~ FileKeeper ( )
{
}
void open ( const QString & path )
{
if ( ! m_handle )
m_handle = std : : fopen ( QFile : : encodeName ( path ) , " r " ) ;
}
void close ( )
{
if ( m_handle )
{
int ret = std : : fclose ( m_handle ) ;
Q_UNUSED ( ret )
m_handle = NULL ;
}
}
KTemporaryFile * copyToTemporary ( ) const
{
if ( ! m_handle )
return 0 ;
KTemporaryFile * retFile = new KTemporaryFile ;
retFile - > open ( ) ;
std : : rewind ( m_handle ) ;
int c = - 1 ;
do
{
c = std : : fgetc ( m_handle ) ;
if ( c = = EOF )
break ;
if ( ! retFile - > putChar ( ( char ) c ) )
break ;
} while ( ! feof ( m_handle ) ) ;
retFile - > flush ( ) ;
return retFile ;
}
private :
std : : FILE * m_handle ;
} ;
2012-05-23 21:43:44 +00:00
Okular : : PartFactory : : PartFactory ( )
: KPluginFactory ( okularAboutData ( " okular " , I18N_NOOP ( " Okular " ) ) )
{
}
Okular : : PartFactory : : ~ PartFactory ( )
{
}
QObject * Okular : : PartFactory : : create ( const char * iface , QWidget * parentWidget , QObject * parent , const QVariantList & args , const QString & keyword )
{
Q_UNUSED ( keyword ) ;
Okular : : Part * object = new Okular : : Part ( parentWidget , parent , args , componentData ( ) ) ;
object - > setReadWrite ( QLatin1String ( iface ) = = QLatin1String ( " KParts::ReadWritePart " ) ) ;
return object ;
}
K_EXPORT_PLUGIN ( Okular : : PartFactory ( ) )
2002-08-30 09:14:01 +00:00
2007-03-10 21:32:09 +00:00
static QAction * actionForExportFormat ( const Okular : : ExportFormat & format , QObject * parent = 0 )
{
QAction * act = new QAction ( format . description ( ) , parent ) ;
if ( ! format . icon ( ) . isNull ( ) )
{
act - > setIcon ( format . icon ( ) ) ;
}
return act ;
}
2007-07-29 00:55:17 +00:00
static QString compressedMimeFor ( const QString & mime_to_check )
{
2013-05-27 21:33:34 +00:00
// The compressedMimeMap is here in case you have a very old shared mime database
// that doesn't have inheritance info for things like gzeps, etc
// Otherwise the "is()" calls below are just good enough
2007-07-29 00:55:17 +00:00
static QHash < QString , QString > compressedMimeMap ;
2013-05-27 21:33:34 +00:00
static bool supportBzip = false ;
static bool supportXz = false ;
const QString app_gzip ( QString : : fromLatin1 ( " application/x-gzip " ) ) ;
const QString app_bzip ( QString : : fromLatin1 ( " application/x-bzip " ) ) ;
const QString app_xz ( QString : : fromLatin1 ( " application/x-xz " ) ) ;
2007-07-29 00:55:17 +00:00
if ( compressedMimeMap . isEmpty ( ) )
{
2010-08-14 15:16:07 +00:00
std : : auto_ptr < KFilterBase > f ;
2013-05-27 21:33:34 +00:00
compressedMimeMap [ QString : : fromLatin1 ( " image/x-gzeps " ) ] = app_gzip ;
2010-08-14 16:06:41 +00:00
// check we can read bzip2-compressed files
2013-05-27 21:33:34 +00:00
f . reset ( KFilterBase : : findFilterByMimeType ( app_bzip ) ) ;
2010-08-14 16:06:41 +00:00
if ( f . get ( ) )
{
2013-05-27 21:33:34 +00:00
supportBzip = true ;
2010-08-14 16:06:41 +00:00
compressedMimeMap [ QString : : fromLatin1 ( " application/x-bzpdf " ) ] = app_bzip ;
compressedMimeMap [ QString : : fromLatin1 ( " application/x-bzpostscript " ) ] = app_bzip ;
compressedMimeMap [ QString : : fromLatin1 ( " application/x-bzdvi " ) ] = app_bzip ;
compressedMimeMap [ QString : : fromLatin1 ( " image/x-bzeps " ) ] = app_bzip ;
}
2010-08-14 15:16:07 +00:00
// check we can read XZ-compressed files
2013-05-27 21:33:34 +00:00
f . reset ( KFilterBase : : findFilterByMimeType ( app_xz ) ) ;
2010-08-14 15:16:07 +00:00
if ( f . get ( ) )
{
2013-05-27 21:33:34 +00:00
supportXz = true ;
2010-08-14 15:16:07 +00:00
}
2007-07-29 00:55:17 +00:00
}
2008-11-11 18:48:40 +00:00
QHash < QString , QString > : : const_iterator it = compressedMimeMap . constFind ( mime_to_check ) ;
if ( it ! = compressedMimeMap . constEnd ( ) )
2007-07-29 00:55:17 +00:00
return it . value ( ) ;
2013-05-27 21:33:34 +00:00
KMimeType : : Ptr mime = KMimeType : : mimeType ( mime_to_check ) ;
2013-06-15 17:50:51 +00:00
if ( mime )
{
if ( mime - > is ( app_gzip ) )
return app_gzip ;
else if ( supportBzip & & mime - > is ( app_bzip ) )
return app_bzip ;
else if ( supportXz & & mime - > is ( app_xz ) )
return app_xz ;
}
2013-05-27 21:33:34 +00:00
2007-07-29 00:55:17 +00:00
return QString ( ) ;
}
2011-10-12 19:36:01 +00:00
static Okular : : EmbedMode detectEmbedMode ( QWidget * parentWidget , QObject * parent , const QVariantList & args )
2009-03-22 18:38:38 +00:00
{
Q_UNUSED ( parentWidget ) ;
if ( parent
& & ( parent - > objectName ( ) = = QLatin1String ( " okular::Shell " )
| | parent - > objectName ( ) = = QLatin1String ( " okular/okular__Shell " ) ) )
2011-10-12 19:36:01 +00:00
return Okular : : NativeShellMode ;
2009-03-22 18:38:38 +00:00
2009-03-23 15:40:09 +00:00
if ( parent
& & ( QByteArray ( " KHTMLPart " ) = = parent - > metaObject ( ) - > className ( ) ) )
2011-10-12 19:36:01 +00:00
return Okular : : KHTMLPartMode ;
2009-03-23 15:40:09 +00:00
2009-03-22 18:38:38 +00:00
Q_FOREACH ( const QVariant & arg , args )
{
if ( arg . type ( ) = = QVariant : : String )
{
2011-10-23 13:22:58 +00:00
if ( arg . toString ( ) = = QLatin1String ( " Print/Preview " ) )
{
2011-10-12 19:36:01 +00:00
return Okular : : PrintPreviewMode ;
2011-09-10 17:15:52 +00:00
}
2011-10-23 13:22:58 +00:00
else if ( arg . toString ( ) = = QLatin1String ( " ViewerWidget " ) )
{
2011-10-12 19:36:01 +00:00
return Okular : : ViewerWidgetMode ;
2011-09-10 17:15:52 +00:00
}
2009-03-22 18:38:38 +00:00
}
}
2011-10-12 19:36:01 +00:00
return Okular : : UnknownEmbedMode ;
2009-03-22 18:38:38 +00:00
}
2011-10-05 20:50:12 +00:00
static QString detectConfigFileName ( const QVariantList & args )
{
Q_FOREACH ( const QVariant & arg , args )
{
if ( arg . type ( ) = = QVariant : : String )
{
QString argString = arg . toString ( ) ;
int separatorIndex = argString . indexOf ( " = " ) ;
if ( separatorIndex > = 0 & & argString . left ( separatorIndex ) = = QLatin1String ( " ConfigFileName " ) )
{
return argString . mid ( separatorIndex + 1 ) ;
}
}
}
2011-10-23 13:22:58 +00:00
return QString ( ) ;
2011-10-05 20:50:12 +00:00
}
2008-06-07 21:08:41 +00:00
# undef OKULAR_KEEP_FILE_OPEN
# ifdef OKULAR_KEEP_FILE_OPEN
static bool keepFileOpen ( )
{
static bool keep_file_open = ! qgetenv ( " OKULAR_NO_KEEP_FILE_OPEN " ) . toInt ( ) ;
return keep_file_open ;
}
# endif
2012-09-25 19:26:44 +00:00
int Okular : : Part : : numberOfParts = 0 ;
2009-10-26 20:59:24 +00:00
namespace Okular
{
2006-05-08 18:57:49 +00:00
Part : : Part ( QWidget * parentWidget ,
2007-01-13 00:33:50 +00:00
QObject * parent ,
2012-05-23 21:43:44 +00:00
const QVariantList & args ,
KComponentData componentData )
: KParts : : ReadWritePart ( parent ) ,
2008-03-17 23:02:33 +00:00
m_tempfile ( 0 ) , m_fileWasRemoved ( false ) , m_showMenuBarAction ( 0 ) , m_showFullScreenAction ( 0 ) , m_actionsSearched ( false ) ,
2013-03-11 21:52:25 +00:00
m_cliPresentation ( false ) , m_cliPrint ( false ) , m_embedMode ( detectEmbedMode ( parentWidget , parent , args ) ) , m_generatorGuiClient ( 0 ) , m_keeper ( 0 )
2002-08-30 09:14:01 +00:00
{
2011-10-05 20:50:12 +00:00
// first, we check if a config file name has been specified
QString configFileName = detectConfigFileName ( args ) ;
2011-10-23 13:22:58 +00:00
if ( configFileName . isEmpty ( ) )
2007-08-21 23:18:17 +00:00
{
2011-10-05 20:50:12 +00:00
configFileName = KStandardDirs : : locateLocal ( " config " , " okularpartrc " ) ;
// first necessary step: copy the configuration from kpdf, if available
if ( ! QFile : : exists ( configFileName ) )
{
QString oldkpdfconffile = KStandardDirs : : locateLocal ( " config " , " kpdfpartrc " ) ;
if ( QFile : : exists ( oldkpdfconffile ) )
QFile : : copy ( oldkpdfconffile , configFileName ) ;
}
2007-08-21 23:18:17 +00:00
}
2011-10-05 20:50:12 +00:00
Okular : : Settings : : instance ( configFileName ) ;
2012-09-25 19:26:44 +00:00
numberOfParts + + ;
if ( numberOfParts = = 1 ) {
QDBusConnection : : sessionBus ( ) . registerObject ( " /okular " , this , QDBusConnection : : ExportScriptableSlots ) ;
} else {
QDBusConnection : : sessionBus ( ) . registerObject ( QString ( " /okular%1 " ) . arg ( numberOfParts ) , this , QDBusConnection : : ExportScriptableSlots ) ;
}
2007-01-13 00:33:50 +00:00
2010-08-20 16:07:36 +00:00
// connect the started signal to tell the job the mimetypes we like,
// and get some more information from it
2011-07-31 19:22:04 +00:00
connect ( this , SIGNAL ( started ( KIO : : Job * ) ) , this , SLOT ( slotJobStarted ( KIO : : Job * ) ) ) ;
2007-06-05 21:25:41 +00:00
// connect the completed signal so we can put the window caption when loading remote files
connect ( this , SIGNAL ( completed ( ) ) , this , SLOT ( setWindowTitleFromDocument ( ) ) ) ;
2011-07-31 19:22:04 +00:00
connect ( this , SIGNAL ( canceled ( QString ) ) , this , SLOT ( loadCancelled ( QString ) ) ) ;
2007-06-05 21:25:41 +00:00
2007-01-13 00:33:50 +00:00
// create browser extension (for printing when embedded into browser)
m_bExtension = new BrowserExtension ( this ) ;
2008-03-30 23:36:15 +00:00
// create live connect extension (for integrating with browser scripting)
new OkularLiveConnectExtension ( this ) ;
2007-01-13 00:33:50 +00:00
// we need an instance
2012-05-23 21:43:44 +00:00
setComponentData ( componentData ) ;
2007-01-13 00:33:50 +00:00
2010-03-17 19:37:52 +00:00
GuiUtils : : addIconLoader ( iconLoader ( ) ) ;
2007-12-24 15:02:32 +00:00
2008-11-21 11:45:00 +00:00
m_sidebar = new Sidebar ( parentWidget ) ;
setWidget ( m_sidebar ) ;
2007-08-06 17:24:10 +00:00
2007-01-13 00:33:50 +00:00
// build the document
2007-03-30 17:46:50 +00:00
m_document = new Okular : : Document ( widget ( ) ) ;
2011-07-31 19:22:04 +00:00
connect ( m_document , SIGNAL ( linkFind ( ) ) , this , SLOT ( slotFind ( ) ) ) ;
connect ( m_document , SIGNAL ( linkGoToPage ( ) ) , this , SLOT ( slotGoToPage ( ) ) ) ;
connect ( m_document , SIGNAL ( linkPresentation ( ) ) , this , SLOT ( slotShowPresentation ( ) ) ) ;
connect ( m_document , SIGNAL ( linkEndPresentation ( ) ) , this , SLOT ( slotHidePresentation ( ) ) ) ;
connect ( m_document , SIGNAL ( openUrl ( KUrl ) ) , this , SLOT ( openUrlFromDocument ( KUrl ) ) ) ;
connect ( m_document - > bookmarkManager ( ) , SIGNAL ( openUrl ( KUrl ) ) , this , SLOT ( openUrlFromBookmarks ( KUrl ) ) ) ;
connect ( m_document , SIGNAL ( close ( ) ) , this , SLOT ( close ( ) ) ) ;
2007-01-13 00:33:50 +00:00
2007-07-13 22:52:32 +00:00
if ( parent & & parent - > metaObject ( ) - > indexOfSlot ( QMetaObject : : normalizedSignature ( " slotQuit() " ) ) ! = - 1 )
2011-07-31 19:22:04 +00:00
connect ( m_document , SIGNAL ( quit ( ) ) , parent , SLOT ( slotQuit ( ) ) ) ;
2007-01-13 00:33:50 +00:00
else
2011-07-31 19:22:04 +00:00
connect ( m_document , SIGNAL ( quit ( ) ) , this , SLOT ( cannotQuit ( ) ) ) ;
2007-01-13 00:33:50 +00:00
// widgets: ^searchbar (toolbar containing label and SearchWidget)
// m_searchToolBar = new KToolBar( parentWidget, "searchBar" );
// m_searchToolBar->boxLayout()->setSpacing( KDialog::spacingHint() );
// QLabel * sLabel = new QLabel( i18n( "&Search:" ), m_searchToolBar, "kde toolbar widget" );
// m_searchWidget = new SearchWidget( m_searchToolBar, m_document );
// sLabel->setBuddy( m_searchWidget );
// m_searchToolBar->setStretchableWidget( m_searchWidget );
int tbIndex ;
// [left toolbox: Table of Contents] | []
2007-08-06 17:24:10 +00:00
m_toc = new TOC ( 0 , m_document ) ;
2011-07-31 19:22:04 +00:00
connect ( m_toc , SIGNAL ( hasTOC ( bool ) ) , this , SLOT ( enableTOC ( bool ) ) ) ;
2007-11-14 00:04:07 +00:00
tbIndex = m_sidebar - > addItem ( m_toc , KIcon ( QApplication : : isLeftToRight ( ) ? " format-justify-left " : " format-justify-right " ) , i18n ( " Contents " ) ) ;
2007-01-13 00:33:50 +00:00
enableTOC ( false ) ;
// [left toolbox: Thumbnails and Bookmarks] | []
2007-08-06 17:24:10 +00:00
KVBox * thumbsBox = new ThumbnailsBox ( 0 ) ;
2007-08-24 14:20:03 +00:00
thumbsBox - > setSpacing ( 6 ) ;
2007-01-13 00:33:50 +00:00
m_searchWidget = new SearchWidget ( thumbsBox , m_document ) ;
m_thumbnailList = new ThumbnailList ( thumbsBox , m_document ) ;
// ThumbnailController * m_tc = new ThumbnailController( thumbsBox, m_thumbnailList );
2011-07-31 19:22:04 +00:00
connect ( m_thumbnailList , SIGNAL ( urlDropped ( KUrl ) ) , SLOT ( openUrlFromDocument ( KUrl ) ) ) ;
connect ( m_thumbnailList , SIGNAL ( rightClick ( const Okular : : Page * , QPoint ) ) , this , SLOT ( slotShowMenu ( const Okular : : Page * , QPoint ) ) ) ;
2007-11-10 18:49:57 +00:00
tbIndex = m_sidebar - > addItem ( thumbsBox , KIcon ( " view-preview " ) , i18n ( " Thumbnails " ) ) ;
2007-08-06 17:24:10 +00:00
m_sidebar - > setCurrentIndex ( tbIndex ) ;
2007-01-13 00:33:50 +00:00
// [left toolbox: Reviews] | []
2008-09-22 22:58:32 +00:00
m_reviewsWidget = new Reviews ( 0 , m_document ) ;
m_sidebar - > addItem ( m_reviewsWidget , KIcon ( " draw-freehand " ) , i18n ( " Reviews " ) ) ;
2007-09-03 17:25:52 +00:00
m_sidebar - > setItemEnabled ( 2 , false ) ;
2007-01-13 00:33:50 +00:00
// [left toolbox: Bookmarks] | []
2008-09-22 22:58:32 +00:00
m_bookmarkList = new BookmarkList ( m_document , 0 ) ;
m_sidebar - > addItem ( m_bookmarkList , KIcon ( " bookmarks " ) , i18n ( " Bookmarks " ) ) ;
2007-09-03 17:25:52 +00:00
m_sidebar - > setItemEnabled ( 3 , false ) ;
2007-01-13 00:33:50 +00:00
// widgets: [../miniBarContainer] | []
2007-09-07 10:59:28 +00:00
# ifdef OKULAR_ENABLE_MINIBAR
2007-08-06 17:24:10 +00:00
QWidget * miniBarContainer = new QWidget ( 0 ) ;
m_sidebar - > setBottomWidget ( miniBarContainer ) ;
2007-01-13 00:33:50 +00:00
QVBoxLayout * miniBarLayout = new QVBoxLayout ( miniBarContainer ) ;
miniBarLayout - > setMargin ( 0 ) ;
// widgets: [../[spacer/..]] | []
miniBarLayout - > addItem ( new QSpacerItem ( 6 , 6 , QSizePolicy : : Fixed , QSizePolicy : : Fixed ) ) ;
// widgets: [../[../MiniBar]] | []
QFrame * bevelContainer = new QFrame ( miniBarContainer ) ;
bevelContainer - > setFrameStyle ( QFrame : : StyledPanel | QFrame : : Sunken ) ;
QVBoxLayout * bevelContainerLayout = new QVBoxLayout ( bevelContainer ) ;
bevelContainerLayout - > setMargin ( 4 ) ;
m_progressWidget = new ProgressWidget ( bevelContainer , m_document ) ;
bevelContainerLayout - > addWidget ( m_progressWidget ) ;
miniBarLayout - > addWidget ( bevelContainer ) ;
miniBarLayout - > addItem ( new QSpacerItem ( 6 , 6 , QSizePolicy : : Fixed , QSizePolicy : : Fixed ) ) ;
2007-09-07 10:59:28 +00:00
# endif
2007-01-13 00:33:50 +00:00
// widgets: [] | [right 'pageView']
2007-08-06 17:24:10 +00:00
QWidget * rightContainer = new QWidget ( 0 ) ;
m_sidebar - > setMainWidget ( rightContainer ) ;
2007-01-13 00:33:50 +00:00
QVBoxLayout * rightLayout = new QVBoxLayout ( rightContainer ) ;
rightLayout - > setMargin ( 0 ) ;
rightLayout - > setSpacing ( 0 ) ;
// KToolBar * rtb = new KToolBar( rightContainer, "mainToolBarSS" );
// rightLayout->addWidget( rtb );
m_topMessage = new PageViewTopMessage ( rightContainer ) ;
2007-12-03 06:27:42 +00:00
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 " ) ) ;
2011-07-31 19:22:04 +00:00
connect ( m_topMessage , SIGNAL ( action ( ) ) , this , SLOT ( slotShowEmbeddedFiles ( ) ) ) ;
2007-01-13 00:33:50 +00:00
rightLayout - > addWidget ( m_topMessage ) ;
2007-02-25 00:07:59 +00:00
m_formsMessage = new PageViewTopMessage ( rightContainer ) ;
rightLayout - > addWidget ( m_formsMessage ) ;
2007-01-13 00:33:50 +00:00
m_pageView = new PageView ( rightContainer , m_document ) ;
2013-02-24 21:58:53 +00:00
m_document - > d - > m_tiledObserver = m_pageView ;
2011-12-15 23:25:24 +00:00
QMetaObject : : invokeMethod ( m_pageView , " setFocus " , Qt : : QueuedConnection ) ; //usability setting
2007-08-06 17:24:10 +00:00
// m_splitter->setFocusProxy(m_pageView);
2011-07-31 19:22:04 +00:00
connect ( m_pageView , SIGNAL ( urlDropped ( KUrl ) ) , SLOT ( openUrlFromDocument ( KUrl ) ) ) ;
connect ( m_pageView , SIGNAL ( rightClick ( const Okular : : Page * , QPoint ) ) , this , SLOT ( slotShowMenu ( const Okular : : Page * , QPoint ) ) ) ;
connect ( m_document , SIGNAL ( error ( QString , int ) ) , m_pageView , SLOT ( errorMessage ( QString , int ) ) ) ;
connect ( m_document , SIGNAL ( warning ( QString , int ) ) , m_pageView , SLOT ( warningMessage ( QString , int ) ) ) ;
connect ( m_document , SIGNAL ( notice ( QString , int ) ) , m_pageView , SLOT ( noticeMessage ( QString , int ) ) ) ;
2011-10-23 13:22:58 +00:00
connect ( m_document , SIGNAL ( sourceReferenceActivated ( const QString & , int , int , bool * ) ) , this , SLOT ( slotHandleActivatedSourceReference ( const QString & , int , int , bool * ) ) ) ;
2007-01-13 00:33:50 +00:00
rightLayout - > addWidget ( m_pageView ) ;
2007-03-17 22:58:41 +00:00
m_findBar = new FindBar ( m_document , rightContainer ) ;
rightLayout - > addWidget ( m_findBar ) ;
2010-10-29 21:47:17 +00:00
m_bottomBar = new QWidget ( rightContainer ) ;
QHBoxLayout * bottomBarLayout = new QHBoxLayout ( m_bottomBar ) ;
m_pageSizeLabel = new PageSizeLabel ( m_bottomBar , m_document ) ;
2007-01-13 00:33:50 +00:00
bottomBarLayout - > setMargin ( 0 ) ;
bottomBarLayout - > setSpacing ( 0 ) ;
bottomBarLayout - > addWidget ( m_pageSizeLabel - > antiWidget ( ) ) ;
bottomBarLayout - > addItem ( new QSpacerItem ( 5 , 5 , QSizePolicy : : Expanding , QSizePolicy : : Minimum ) ) ;
2012-02-02 18:55:40 +00:00
m_miniBarLogic = new MiniBarLogic ( this , m_document ) ;
m_miniBar = new MiniBar ( m_bottomBar , m_miniBarLogic ) ;
2007-01-13 00:33:50 +00:00
bottomBarLayout - > addWidget ( m_miniBar ) ;
bottomBarLayout - > addItem ( new QSpacerItem ( 5 , 5 , QSizePolicy : : Expanding , QSizePolicy : : Minimum ) ) ;
bottomBarLayout - > addWidget ( m_pageSizeLabel ) ;
2010-10-29 21:47:17 +00:00
rightLayout - > addWidget ( m_bottomBar ) ;
2004-09-23 17:16:04 +00:00
2012-02-02 18:55:40 +00:00
m_pageNumberTool = new MiniBar ( 0 , m_miniBarLogic ) ;
2012-01-31 18:48:20 +00:00
2011-07-31 19:22:04 +00:00
connect ( m_findBar , SIGNAL ( forwardKeyPressEvent ( QKeyEvent * ) ) , m_pageView , SLOT ( externalKeyPressEvent ( QKeyEvent * ) ) ) ;
connect ( m_miniBar , SIGNAL ( forwardKeyPressEvent ( QKeyEvent * ) ) , m_pageView , SLOT ( externalKeyPressEvent ( QKeyEvent * ) ) ) ;
2012-07-12 18:46:24 +00:00
connect ( m_pageView , SIGNAL ( escPressed ( ) ) , m_findBar , SLOT ( resetSearch ( ) ) ) ;
2012-01-31 18:48:20 +00:00
connect ( m_pageNumberTool , SIGNAL ( forwardKeyPressEvent ( QKeyEvent * ) ) , m_pageView , SLOT ( externalKeyPressEvent ( QKeyEvent * ) ) ) ;
2011-06-08 05:47:57 +00:00
2012-01-17 22:46:37 +00:00
connect ( m_reviewsWidget , SIGNAL ( openAnnotationWindow ( Okular : : Annotation * , int ) ) ,
m_pageView , SLOT ( openAnnotationWindow ( Okular : : Annotation * , int ) ) ) ;
2007-01-13 00:33:50 +00:00
// add document observers
m_document - > addObserver ( this ) ;
m_document - > addObserver ( m_thumbnailList ) ;
m_document - > addObserver ( m_pageView ) ;
2008-04-27 11:17:05 +00:00
m_document - > registerView ( m_pageView ) ;
2007-01-13 00:33:50 +00:00
m_document - > addObserver ( m_toc ) ;
2012-02-02 18:55:40 +00:00
m_document - > addObserver ( m_miniBarLogic ) ;
2007-09-07 10:59:28 +00:00
# ifdef OKULAR_ENABLE_MINIBAR
2007-01-13 00:33:50 +00:00
m_document - > addObserver ( m_progressWidget ) ;
2007-09-07 10:59:28 +00:00
# endif
2008-09-22 22:58:32 +00:00
m_document - > addObserver ( m_reviewsWidget ) ;
2007-01-13 00:33:50 +00:00
m_document - > addObserver ( m_pageSizeLabel ) ;
2008-09-22 22:58:32 +00:00
m_document - > addObserver ( m_bookmarkList ) ;
2007-01-13 00:33:50 +00:00
2011-07-31 19:22:04 +00:00
connect ( m_document - > bookmarkManager ( ) , SIGNAL ( saved ( ) ) ,
this , SLOT ( slotRebuildBookmarkMenu ( ) ) ) ;
2008-02-05 17:36:04 +00:00
2011-10-12 19:36:01 +00:00
setupViewerActions ( ) ;
if ( m_embedMode ! = ViewerWidgetMode )
{
setupActions ( ) ;
}
2011-10-24 20:30:05 +00:00
else
{
setViewerShortcuts ( ) ;
}
2011-10-12 19:36:01 +00:00
// document watcher and reloader
m_watcher = new KDirWatch ( this ) ;
connect ( m_watcher , SIGNAL ( dirty ( QString ) ) , this , SLOT ( slotFileDirty ( QString ) ) ) ;
m_dirtyHandler = new QTimer ( this ) ;
m_dirtyHandler - > setSingleShot ( true ) ;
connect ( m_dirtyHandler , SIGNAL ( timeout ( ) ) , this , SLOT ( slotDoFileDirty ( ) ) ) ;
slotNewConfig ( ) ;
2013-05-28 10:46:27 +00:00
// keep us informed when the user changes settings
connect ( Okular : : Settings : : self ( ) , SIGNAL ( configChanged ( ) ) , this , SLOT ( slotNewConfig ( ) ) ) ;
2011-10-12 19:36:01 +00:00
// [SPEECH] check for KTTSD presence and usability
const KService : : Ptr kttsd = KService : : serviceByDesktopName ( " kttsd " ) ;
Okular : : Settings : : setUseKTTSD ( kttsd ) ;
Okular : : Settings : : self ( ) - > writeConfig ( ) ;
rebuildBookmarkMenu ( false ) ;
if ( m_embedMode = = ViewerWidgetMode ) {
// set the XML-UI resource file for the viewer mode
setXMLFile ( " part-viewermode.rc " ) ;
}
else
{
// set our main XML-UI resource file
setXMLFile ( " part.rc " ) ;
}
m_pageView - > setupBaseActions ( actionCollection ( ) ) ;
m_sidebar - > setSidebarVisibility ( false ) ;
if ( m_embedMode ! = PrintPreviewMode )
{
// now set up actions that are required for all remaining modes
m_pageView - > setupViewerActions ( actionCollection ( ) ) ;
// and if we are not in viewer mode, we want the full GUI
if ( m_embedMode ! = ViewerWidgetMode )
{
unsetDummyMode ( ) ;
}
}
// ensure history actions are in the correct state
updateViewActions ( ) ;
2011-10-23 09:17:04 +00:00
// also update the state of the actions in the page view
m_pageView - > updateActionState ( false , false , false ) ;
2011-10-12 19:36:01 +00:00
if ( m_embedMode = = NativeShellMode )
m_sidebar - > setAutoFillBackground ( false ) ;
# ifdef OKULAR_KEEP_FILE_OPEN
m_keeper = new FileKeeper ( ) ;
# endif
}
void Part : : setupViewerActions ( )
{
2007-01-13 00:33:50 +00:00
// ACTIONS
KActionCollection * ac = actionCollection ( ) ;
// Page Traversal actions
2011-07-31 19:22:04 +00:00
m_gotoPage = KStandardAction : : gotoPage ( this , SLOT ( slotGoToPage ( ) ) , ac ) ;
2011-10-24 20:30:05 +00:00
m_gotoPage - > setShortcut ( QKeySequence ( Qt : : CTRL + Qt : : Key_G ) ) ;
2007-01-13 00:33:50 +00:00
// dirty way to activate gotopage when pressing miniBar's button
2011-07-31 19:22:04 +00:00
connect ( m_miniBar , SIGNAL ( gotoPage ( ) ) , m_gotoPage , SLOT ( trigger ( ) ) ) ;
2012-01-31 18:48:20 +00:00
connect ( m_pageNumberTool , SIGNAL ( gotoPage ( ) ) , m_gotoPage , SLOT ( trigger ( ) ) ) ;
2007-01-13 00:33:50 +00:00
m_prevPage = KStandardAction : : prior ( this , SLOT ( slotPreviousPage ( ) ) , ac ) ;
2007-08-20 20:25:22 +00:00
m_prevPage - > setIconText ( i18nc ( " Previous page " , " Previous " ) ) ;
m_prevPage - > setToolTip ( i18n ( " Go back to the Previous Page " ) ) ;
2007-01-13 00:33:50 +00:00
m_prevPage - > setWhatsThis ( i18n ( " Moves to the previous page of the document " ) ) ;
m_prevPage - > setShortcut ( 0 ) ;
// dirty way to activate prev page when pressing miniBar's button
2011-07-31 19:22:04 +00:00
connect ( m_miniBar , SIGNAL ( prevPage ( ) ) , m_prevPage , SLOT ( trigger ( ) ) ) ;
2012-01-31 18:48:20 +00:00
connect ( m_pageNumberTool , SIGNAL ( prevPage ( ) ) , m_prevPage , SLOT ( trigger ( ) ) ) ;
2007-09-07 10:59:28 +00:00
# ifdef OKULAR_ENABLE_MINIBAR
2011-07-31 19:22:04 +00:00
connect ( m_progressWidget , SIGNAL ( prevPage ( ) ) , m_prevPage , SLOT ( trigger ( ) ) ) ;
2007-09-07 10:59:28 +00:00
# endif
2007-01-13 00:33:50 +00:00
m_nextPage = KStandardAction : : next ( this , SLOT ( slotNextPage ( ) ) , ac ) ;
2007-08-20 20:25:22 +00:00
m_nextPage - > setIconText ( i18nc ( " Next page " , " Next " ) ) ;
m_nextPage - > setToolTip ( i18n ( " Advance to the Next Page " ) ) ;
2007-01-13 00:33:50 +00:00
m_nextPage - > setWhatsThis ( i18n ( " Moves to the next page of the document " ) ) ;
m_nextPage - > setShortcut ( 0 ) ;
// dirty way to activate next page when pressing miniBar's button
2011-07-31 19:22:04 +00:00
connect ( m_miniBar , SIGNAL ( nextPage ( ) ) , m_nextPage , SLOT ( trigger ( ) ) ) ;
2012-01-31 18:48:20 +00:00
connect ( m_pageNumberTool , SIGNAL ( nextPage ( ) ) , m_nextPage , SLOT ( trigger ( ) ) ) ;
2007-09-07 10:59:28 +00:00
# ifdef OKULAR_ENABLE_MINIBAR
2011-07-31 19:22:04 +00:00
connect ( m_progressWidget , SIGNAL ( nextPage ( ) ) , m_nextPage , SLOT ( trigger ( ) ) ) ;
2007-09-07 10:59:28 +00:00
# endif
2007-01-13 00:33:50 +00:00
2011-07-31 19:22:04 +00:00
m_beginningOfDocument = KStandardAction : : firstPage ( this , SLOT ( slotGotoFirst ( ) ) , ac ) ;
2010-09-03 21:30:30 +00:00
ac - > addAction ( " first_page " , m_beginningOfDocument ) ;
m_beginningOfDocument - > setText ( i18n ( " Beginning of the document " ) ) ;
m_beginningOfDocument - > setWhatsThis ( i18n ( " Moves to the beginning of the document " ) ) ;
2007-01-13 00:33:50 +00:00
2011-07-31 19:22:04 +00:00
m_endOfDocument = KStandardAction : : lastPage ( this , SLOT ( slotGotoLast ( ) ) , ac ) ;
2010-09-03 21:30:30 +00:00
ac - > addAction ( " last_page " , m_endOfDocument ) ;
m_endOfDocument - > setText ( i18n ( " End of the document " ) ) ;
m_endOfDocument - > setWhatsThis ( i18n ( " Moves to the end of the document " ) ) ;
2007-01-13 00:33:50 +00:00
2007-06-17 09:45:59 +00:00
// we do not want back and next in history in the dummy mode
m_historyBack = 0 ;
m_historyNext = 0 ;
2007-01-13 00:33:50 +00:00
2011-07-31 19:22:04 +00:00
m_addBookmark = KStandardAction : : addBookmark ( this , SLOT ( slotAddBookmark ( ) ) , ac ) ;
2007-05-01 14:43:30 +00:00
m_addBookmarkText = m_addBookmark - > text ( ) ;
2007-05-01 16:38:35 +00:00
m_addBookmarkIcon = m_addBookmark - > icon ( ) ;
2007-05-01 14:43:30 +00:00
2011-10-25 20:21:22 +00:00
m_renameBookmark = ac - > addAction ( " rename_bookmark " ) ;
m_renameBookmark - > setText ( i18n ( " Rename Bookmark " ) ) ;
m_renameBookmark - > setIcon ( KIcon ( " edit-rename " ) ) ;
2012-03-26 18:01:01 +00:00
m_renameBookmark - > setWhatsThis ( i18n ( " Rename the current bookmark " ) ) ;
connect ( m_renameBookmark , SIGNAL ( triggered ( ) ) , this , SLOT ( slotRenameCurrentViewportBookmark ( ) ) ) ;
2011-10-25 20:21:22 +00:00
2007-01-13 00:33:50 +00:00
m_prevBookmark = ac - > addAction ( " previous_bookmark " ) ;
m_prevBookmark - > setText ( i18n ( " Previous Bookmark " ) ) ;
2007-12-03 06:27:42 +00:00
m_prevBookmark - > setIcon ( KIcon ( " go-up-search " ) ) ;
2012-03-26 18:01:01 +00:00
m_prevBookmark - > setWhatsThis ( i18n ( " Go to the previous bookmark " ) ) ;
2011-07-31 19:22:04 +00:00
connect ( m_prevBookmark , SIGNAL ( triggered ( ) ) , this , SLOT ( slotPreviousBookmark ( ) ) ) ;
2007-01-13 00:33:50 +00:00
m_nextBookmark = ac - > addAction ( " next_bookmark " ) ;
m_nextBookmark - > setText ( i18n ( " Next Bookmark " ) ) ;
2007-12-03 06:27:42 +00:00
m_nextBookmark - > setIcon ( KIcon ( " go-down-search " ) ) ;
2012-03-26 18:01:01 +00:00
m_nextBookmark - > setWhatsThis ( i18n ( " Go to the next bookmark " ) ) ;
2011-07-31 19:22:04 +00:00
connect ( m_nextBookmark , SIGNAL ( triggered ( ) ) , this , SLOT ( slotNextBookmark ( ) ) ) ;
2007-01-13 00:33:50 +00:00
2011-10-23 13:22:58 +00:00
m_copy = 0 ;
2007-01-13 00:33:50 +00:00
2011-10-23 13:22:58 +00:00
m_selectAll = 0 ;
2007-09-03 21:35:05 +00:00
2007-01-13 00:33:50 +00:00
// Find and other actions
2011-07-31 19:22:04 +00:00
m_find = KStandardAction : : find ( this , SLOT ( slotShowFindBar ( ) ) , ac ) ;
2011-10-24 20:30:05 +00:00
QList < QKeySequence > s = m_find - > shortcuts ( ) ;
s . append ( QKeySequence ( Qt : : Key_Slash ) ) ;
m_find - > setShortcuts ( s ) ;
2007-01-13 00:33:50 +00:00
m_find - > setEnabled ( false ) ;
2011-07-31 19:22:04 +00:00
m_findNext = KStandardAction : : findNext ( this , SLOT ( slotFindNext ( ) ) , ac ) ;
2007-01-13 00:33:50 +00:00
m_findNext - > setEnabled ( false ) ;
2011-07-31 19:22:04 +00:00
m_findPrev = KStandardAction : : findPrev ( this , SLOT ( slotFindPrev ( ) ) , ac ) ;
2009-02-14 17:11:29 +00:00
m_findPrev - > setEnabled ( false ) ;
2011-10-23 13:22:58 +00:00
m_saveCopyAs = 0 ;
m_saveAs = 0 ;
2007-10-07 23:09:08 +00:00
2011-07-31 19:22:04 +00:00
QAction * prefs = KStandardAction : : preferences ( this , SLOT ( slotPreferences ( ) ) , ac ) ;
2009-03-22 18:38:38 +00:00
if ( m_embedMode = = NativeShellMode )
2007-01-13 00:33:50 +00:00
{
2008-01-20 15:35:19 +00:00
prefs - > setText ( i18n ( " Configure Okular... " ) ) ;
2007-01-13 00:33:50 +00:00
}
else
{
2007-05-19 10:11:04 +00:00
// TODO: improve this message
2007-01-13 00:33:50 +00:00
prefs - > setText ( i18n ( " Configure Viewer... " ) ) ;
}
2007-10-07 23:09:08 +00:00
KAction * genPrefs = new KAction ( ac ) ;
ac - > addAction ( " options_configure_generators " , genPrefs ) ;
2011-10-12 19:36:01 +00:00
if ( m_embedMode = = ViewerWidgetMode )
{
genPrefs - > setText ( i18n ( " Configure Viewer Backends... " ) ) ;
}
2011-10-23 13:22:58 +00:00
else
{
2011-10-12 19:36:01 +00:00
genPrefs - > setText ( i18n ( " Configure Backends... " ) ) ;
}
2007-10-07 23:09:08 +00:00
genPrefs - > setIcon ( KIcon ( " configure " ) ) ;
2007-07-12 17:52:14 +00:00
genPrefs - > setEnabled ( m_document - > configurableGenerators ( ) > 0 ) ;
2011-07-31 19:22:04 +00:00
connect ( genPrefs , SIGNAL ( triggered ( bool ) ) , this , SLOT ( slotGeneratorPreferences ( ) ) ) ;
2007-01-13 00:33:50 +00:00
2011-07-31 19:22:04 +00:00
m_printPreview = KStandardAction : : printPreview ( this , SLOT ( slotPrintPreview ( ) ) , ac ) ;
2007-01-13 00:33:50 +00:00
m_printPreview - > setEnabled ( false ) ;
2011-10-23 13:22:58 +00:00
m_showLeftPanel = 0 ;
m_showBottomBar = 0 ;
2011-10-12 19:36:01 +00:00
m_showProperties = ac - > addAction ( " properties " ) ;
m_showProperties - > setText ( i18n ( " &Properties " ) ) ;
m_showProperties - > setIcon ( KIcon ( " document-properties " ) ) ;
connect ( m_showProperties , SIGNAL ( triggered ( ) ) , this , SLOT ( slotShowProperties ( ) ) ) ;
m_showProperties - > setEnabled ( false ) ;
2011-10-23 13:22:58 +00:00
m_showEmbeddedFiles = 0 ;
m_showPresentation = 0 ;
2011-10-12 19:36:01 +00:00
2011-10-23 13:22:58 +00:00
m_exportAs = 0 ;
m_exportAsMenu = 0 ;
m_exportAsText = 0 ;
m_exportAsDocArchive = 0 ;
2011-10-12 19:36:01 +00:00
m_aboutBackend = ac - > addAction ( " help_about_backend " ) ;
m_aboutBackend - > setText ( i18n ( " About Backend " ) ) ;
m_aboutBackend - > setEnabled ( false ) ;
connect ( m_aboutBackend , SIGNAL ( triggered ( ) ) , this , SLOT ( slotAboutBackend ( ) ) ) ;
KAction * reload = ac - > add < KAction > ( " file_reload " ) ;
reload - > setText ( i18n ( " Reloa&d " ) ) ;
reload - > setIcon ( KIcon ( " view-refresh " ) ) ;
reload - > setWhatsThis ( i18n ( " Reload the current document from disk. " ) ) ;
connect ( reload , SIGNAL ( triggered ( ) ) , this , SLOT ( slotReload ( ) ) ) ;
2011-10-24 20:30:05 +00:00
reload - > setShortcut ( KStandardShortcut : : reload ( ) ) ;
2011-10-12 19:36:01 +00:00
m_reload = reload ;
m_closeFindBar = new KAction ( i18n ( " Close &Find Bar " ) , ac ) ;
ac - > addAction ( " close_find_bar " , m_closeFindBar ) ;
connect ( m_closeFindBar , SIGNAL ( triggered ( ) ) , this , SLOT ( slotHideFindBar ( ) ) ) ;
widget ( ) - > addAction ( m_closeFindBar ) ;
2012-01-31 18:48:20 +00:00
KAction * pageno = new KAction ( i18n ( " Page Number " ) , ac ) ;
pageno - > setDefaultWidget ( m_pageNumberTool ) ;
ac - > addAction ( " page_number " , pageno ) ;
2011-10-12 19:36:01 +00:00
}
2011-10-24 20:30:05 +00:00
void Part : : setViewerShortcuts ( )
2011-10-12 19:36:01 +00:00
{
KActionCollection * ac = actionCollection ( ) ;
2011-10-24 20:30:05 +00:00
m_gotoPage - > setShortcut ( QKeySequence ( Qt : : CTRL + Qt : : ALT + Qt : : Key_G ) ) ;
m_find - > setShortcuts ( QList < QKeySequence > ( ) ) ;
m_findNext - > setShortcut ( QKeySequence ( ) ) ;
m_findPrev - > setShortcut ( QKeySequence ( ) ) ;
m_addBookmark - > setShortcut ( QKeySequence ( Qt : : CTRL + Qt : : ALT + Qt : : Key_B ) ) ;
m_beginningOfDocument - > setShortcut ( QKeySequence ( Qt : : CTRL + Qt : : ALT + Qt : : Key_Home ) ) ;
m_endOfDocument - > setShortcut ( QKeySequence ( Qt : : CTRL + Qt : : ALT + Qt : : Key_End ) ) ;
KAction * action = static_cast < KAction * > ( ac - > action ( " file_reload " ) ) ;
if ( action ) action - > setShortcuts ( QList < QKeySequence > ( ) < < QKeySequence ( Qt : : ALT + Qt : : Key_F5 ) ) ;
}
void Part : : setupActions ( )
{
KActionCollection * ac = actionCollection ( ) ;
2011-10-12 19:36:01 +00:00
m_copy = KStandardAction : : create ( KStandardAction : : Copy , m_pageView , SLOT ( copyTextSelection ( ) ) , ac ) ;
m_selectAll = KStandardAction : : selectAll ( m_pageView , SLOT ( selectAll ( ) ) , ac ) ;
m_saveCopyAs = KStandardAction : : saveAs ( this , SLOT ( slotSaveCopyAs ( ) ) , ac ) ;
m_saveCopyAs - > setText ( i18n ( " Save &Copy As... " ) ) ;
2011-11-21 22:34:59 +00:00
m_saveCopyAs - > setShortcut ( KShortcut ( ) ) ;
2011-10-12 19:36:01 +00:00
ac - > addAction ( " file_save_copy " , m_saveCopyAs ) ;
m_saveCopyAs - > setEnabled ( false ) ;
m_saveAs = KStandardAction : : saveAs ( this , SLOT ( slotSaveFileAs ( ) ) , ac ) ;
m_saveAs - > setEnabled ( false ) ;
2007-01-13 00:33:50 +00:00
m_showLeftPanel = ac - > add < KToggleAction > ( " show_leftpanel " ) ;
m_showLeftPanel - > setText ( i18n ( " Show &Navigation Panel " ) ) ;
2007-12-03 06:27:42 +00:00
m_showLeftPanel - > setIcon ( KIcon ( " view-sidetree " ) ) ;
2011-07-31 19:22:04 +00:00
connect ( m_showLeftPanel , SIGNAL ( toggled ( bool ) ) , this , SLOT ( slotShowLeftPanel ( ) ) ) ;
2007-08-04 17:42:06 +00:00
m_showLeftPanel - > setShortcut ( Qt : : Key_F7 ) ;
2007-01-13 00:33:50 +00:00
m_showLeftPanel - > setChecked ( Okular : : Settings : : showLeftPanel ( ) ) ;
slotShowLeftPanel ( ) ;
2010-10-29 21:47:17 +00:00
m_showBottomBar = ac - > add < KToggleAction > ( " show_bottombar " ) ;
m_showBottomBar - > setText ( i18n ( " Show &Page Bar " ) ) ;
2011-07-31 19:22:04 +00:00
connect ( m_showBottomBar , SIGNAL ( toggled ( bool ) ) , this , SLOT ( slotShowBottomBar ( ) ) ) ;
2010-10-29 21:47:17 +00:00
m_showBottomBar - > setChecked ( Okular : : Settings : : showBottomBar ( ) ) ;
slotShowBottomBar ( ) ;
2007-01-13 00:33:50 +00:00
m_showEmbeddedFiles = ac - > addAction ( " embedded_files " ) ;
m_showEmbeddedFiles - > setText ( i18n ( " &Embedded Files " ) ) ;
2007-12-08 14:57:24 +00:00
m_showEmbeddedFiles - > setIcon ( KIcon ( " mail-attachment " ) ) ;
2007-01-13 00:33:50 +00:00
connect ( m_showEmbeddedFiles , SIGNAL ( triggered ( ) ) , this , SLOT ( slotShowEmbeddedFiles ( ) ) ) ;
m_showEmbeddedFiles - > setEnabled ( false ) ;
m_exportAs = ac - > addAction ( " file_export_as " ) ;
m_exportAs - > setText ( i18n ( " E&xport As " ) ) ;
2007-10-02 16:23:28 +00:00
m_exportAs - > setIcon ( KIcon ( " document-export " ) ) ;
2008-09-22 22:58:32 +00:00
m_exportAsMenu = new QMenu ( ) ;
2011-07-31 19:22:04 +00:00
connect ( m_exportAsMenu , SIGNAL ( triggered ( QAction * ) ) , this , SLOT ( slotExportAs ( QAction * ) ) ) ;
2008-09-22 22:58:32 +00:00
m_exportAs - > setMenu ( m_exportAsMenu ) ;
m_exportAsText = actionForExportFormat ( Okular : : ExportFormat : : standardFormat ( Okular : : ExportFormat : : PlainText ) , m_exportAsMenu ) ;
m_exportAsMenu - > addAction ( m_exportAsText ) ;
2007-09-07 09:09:39 +00:00
m_exportAs - > setEnabled ( false ) ;
2007-01-13 00:33:50 +00:00
m_exportAsText - > setEnabled ( false ) ;
2008-11-16 01:23:31 +00:00
m_exportAsDocArchive = actionForExportFormat ( Okular : : ExportFormat (
i18nc ( " A document format, Okular-specific " , " Document Archive " ) ,
KMimeType : : mimeType ( " application/vnd.kde.okular-archive " ) ) , m_exportAsMenu ) ;
m_exportAsMenu - > addAction ( m_exportAsDocArchive ) ;
m_exportAsDocArchive - > setEnabled ( false ) ;
2007-01-13 00:33:50 +00:00
2011-10-12 19:36:01 +00:00
m_showPresentation = ac - > addAction ( " presentation " ) ;
m_showPresentation - > setText ( i18n ( " P&resentation " ) ) ;
m_showPresentation - > setIcon ( KIcon ( " view-presentation " ) ) ;
connect ( m_showPresentation , SIGNAL ( triggered ( ) ) , this , SLOT ( slotShowPresentation ( ) ) ) ;
m_showPresentation - > setShortcut ( QKeySequence ( Qt : : CTRL + Qt : : SHIFT + Qt : : Key_P ) ) ;
m_showPresentation - > setEnabled ( false ) ;
2007-05-06 11:23:26 +00:00
2011-10-12 19:36:01 +00:00
QAction * importPS = ac - > addAction ( " import_ps " ) ;
importPS - > setText ( i18n ( " &Import PostScript as PDF... " ) ) ;
importPS - > setIcon ( KIcon ( " document-import " ) ) ;
connect ( importPS , SIGNAL ( triggered ( ) ) , this , SLOT ( slotImportPSFile ( ) ) ) ;
#if 0
QAction * ghns = ac - > addAction ( " get_new_stuff " ) ;
ghns - > setText ( i18n ( " &Get Books From Internet... " ) ) ;
ghns - > setIcon ( KIcon ( " get-hot-new-stuff " ) ) ;
connect ( ghns , SIGNAL ( triggered ( ) ) , this , SLOT ( slotGetNewStuff ( ) ) ) ;
// TEMP, REMOVE ME!
ghns - > setShortcut ( Qt : : Key_G ) ;
# endif
2007-03-17 22:58:41 +00:00
2008-09-11 08:40:00 +00:00
KToggleAction * blackscreenAction = new KToggleAction ( i18n ( " Switch Blackscreen Mode " ) , ac ) ;
ac - > addAction ( " switch_blackscreen_mode " , blackscreenAction ) ;
blackscreenAction - > setShortcut ( QKeySequence ( Qt : : Key_B ) ) ;
blackscreenAction - > setIcon ( KIcon ( " view-presentation " ) ) ;
2012-06-07 14:35:13 +00:00
blackscreenAction - > setEnabled ( false ) ;
2008-09-11 08:40:00 +00:00
2008-11-29 13:50:37 +00:00
KToggleAction * drawingAction = new KToggleAction ( i18n ( " Toggle Drawing Mode " ) , ac ) ;
ac - > addAction ( " presentation_drawing_mode " , drawingAction ) ;
drawingAction - > setIcon ( KIcon ( " draw-freehand " ) ) ;
2012-06-07 14:35:13 +00:00
drawingAction - > setEnabled ( false ) ;
2008-11-29 13:50:37 +00:00
KAction * eraseDrawingAction = new KAction ( i18n ( " Erase Drawings " ) , ac ) ;
ac - > addAction ( " presentation_erase_drawings " , eraseDrawingAction ) ;
eraseDrawingAction - > setIcon ( KIcon ( " draw-eraser " ) ) ;
2012-06-07 14:35:13 +00:00
eraseDrawingAction - > setEnabled ( false ) ;
2013-05-28 21:55:10 +00:00
KAction * configureAnnotations = new KAction ( i18n ( " Configure Annotations... " ) , ac ) ;
ac - > addAction ( " options_configure_annotations " , configureAnnotations ) ;
configureAnnotations - > setIcon ( KIcon ( " configure " ) ) ;
connect ( configureAnnotations , SIGNAL ( triggered ( ) ) , this , SLOT ( slotAnnotationPreferences ( ) ) ) ;
2003-09-15 21:57:19 +00:00
}
2004-09-08 12:41:14 +00:00
Part : : ~ Part ( )
2003-09-15 21:09:49 +00:00
{
2010-03-17 19:37:52 +00:00
GuiUtils : : removeIconLoader ( iconLoader ( ) ) ;
2008-09-22 22:58:32 +00:00
m_document - > removeObserver ( this ) ;
2007-10-03 14:59:57 +00:00
if ( m_document - > isOpened ( ) )
2012-06-01 20:55:54 +00:00
Part : : closeUrl ( false ) ;
2007-10-03 14:59:57 +00:00
2006-02-18 12:06:52 +00:00
delete m_toc ;
delete m_pageView ;
delete m_thumbnailList ;
delete m_miniBar ;
2012-01-31 18:48:20 +00:00
delete m_pageNumberTool ;
2012-02-02 18:55:40 +00:00
delete m_miniBarLogic ;
2010-10-29 21:47:17 +00:00
delete m_bottomBar ;
2007-09-07 10:59:28 +00:00
# ifdef OKULAR_ENABLE_MINIBAR
2006-10-15 15:59:22 +00:00
delete m_progressWidget ;
2007-09-07 10:59:28 +00:00
# endif
2006-10-15 19:37:14 +00:00
delete m_pageSizeLabel ;
2008-09-22 22:58:32 +00:00
delete m_reviewsWidget ;
delete m_bookmarkList ;
2006-02-18 12:06:52 +00:00
2004-11-09 17:20:19 +00:00
delete m_document ;
2007-01-13 21:42:39 +00:00
delete m_tempfile ;
2007-01-13 17:28:54 +00:00
qDeleteAll ( m_bookmarkActions ) ;
2008-06-07 21:08:41 +00:00
2008-09-22 22:58:32 +00:00
delete m_exportAsMenu ;
2008-06-07 21:08:41 +00:00
# ifdef OKULAR_KEEP_FILE_OPEN
delete m_keeper ;
# endif
2003-09-15 21:09:49 +00:00
}
2007-01-13 00:33:50 +00:00
2007-01-04 00:20:50 +00:00
bool Part : : openDocument ( const KUrl & url , uint page )
{
Okular : : DocumentViewport vp ( page - 1 ) ;
2007-07-31 00:04:09 +00:00
vp . rePos . enabled = true ;
vp . rePos . normalizedX = 0 ;
vp . rePos . normalizedY = 0 ;
vp . rePos . pos = Okular : : DocumentViewport : : TopLeft ;
2007-01-04 00:20:50 +00:00
if ( vp . isValid ( ) )
m_document - > setNextDocumentViewport ( vp ) ;
return openUrl ( url ) ;
}
2007-01-13 00:33:50 +00:00
2007-01-04 00:20:50 +00:00
void Part : : startPresentation ( )
{
m_cliPresentation = true ;
}
2007-01-13 00:33:50 +00:00
2007-05-24 20:39:35 +00:00
QStringList Part : : supportedMimeTypes ( ) const
{
return m_document - > supportedMimeTypes ( ) ;
}
2007-07-25 10:08:38 +00:00
KUrl Part : : realUrl ( ) const
{
if ( ! m_realUrl . isEmpty ( ) )
return m_realUrl ;
return url ( ) ;
}
2011-09-10 17:15:52 +00:00
// ViewerInterface
2011-11-05 09:18:08 +00:00
void Part : : showSourceLocation ( const QString & fileName , int line , int column , bool showGraphically )
2011-09-10 17:15:52 +00:00
{
2011-11-08 08:25:36 +00:00
const QString u = QString ( " src:%1 %2 " ) . arg ( line + 1 ) . arg ( fileName ) ;
2011-10-31 21:41:50 +00:00
GotoAction action ( QString ( ) , u ) ;
m_document - > processAction ( & action ) ;
2011-11-05 09:18:08 +00:00
if ( showGraphically )
{
m_pageView - > setLastSourceLocationViewport ( m_document - > viewport ( ) ) ;
}
}
void Part : : clearLastShownSourceLocation ( )
{
m_pageView - > clearLastSourceLocationViewport ( ) ;
2011-09-10 17:15:52 +00:00
}
2011-11-05 09:40:12 +00:00
bool Part : : isWatchFileModeEnabled ( ) const
{
return ! m_watcher - > isStopped ( ) ;
}
2011-10-31 21:41:50 +00:00
void Part : : setWatchFileModeEnabled ( bool enabled )
2011-09-10 17:15:52 +00:00
{
2011-10-31 21:41:50 +00:00
if ( enabled & & m_watcher - > isStopped ( ) )
{
2011-09-10 17:15:52 +00:00
m_watcher - > startScan ( ) ;
}
2011-10-31 21:41:50 +00:00
else if ( ! enabled & & ! m_watcher - > isStopped ( ) )
2011-09-10 17:15:52 +00:00
{
m_dirtyHandler - > stop ( ) ;
m_watcher - > stopScan ( ) ;
}
}
2011-11-05 09:40:12 +00:00
bool Part : : areSourceLocationsShownGraphically ( ) const
{
2011-11-07 21:07:10 +00:00
return m_pageView - > areSourceLocationsShownGraphically ( ) ;
2011-11-05 09:40:12 +00:00
}
2011-10-31 21:41:50 +00:00
void Part : : setShowSourceLocationsGraphically ( bool show )
2011-10-17 19:56:45 +00:00
{
2011-11-07 21:07:10 +00:00
m_pageView - > setShowSourceLocationsGraphically ( show ) ;
2011-10-17 19:56:45 +00:00
}
2011-10-23 13:22:58 +00:00
void Part : : slotHandleActivatedSourceReference ( const QString & absFileName , int line , int col , bool * handled )
2011-09-10 17:15:52 +00:00
{
2011-10-31 21:41:50 +00:00
emit openSourceReference ( absFileName , line , col ) ;
if ( m_embedMode = = Okular : : ViewerWidgetMode )
{
2011-10-23 13:22:58 +00:00
* handled = true ;
2011-09-10 17:15:52 +00:00
}
}
2007-07-25 10:08:38 +00:00
2006-08-30 13:02:48 +00:00
void Part : : openUrlFromDocument ( const KUrl & url )
2005-11-04 11:59:51 +00:00
{
2009-03-22 18:38:38 +00:00
if ( m_embedMode = = PrintPreviewMode )
return ;
2007-06-05 20:49:00 +00:00
2011-08-10 09:15:37 +00:00
if ( KIO : : NetAccess : : exists ( url , KIO : : NetAccess : : SourceSide , widget ( ) ) )
{
m_bExtension - > openUrlNotify ( ) ;
m_bExtension - > setLocationBarUrl ( url . prettyUrl ( ) ) ;
openUrl ( url ) ;
} else {
KMessageBox : : error ( widget ( ) , i18n ( " Could not open '%1'. File does not exist " , url . pathOrUrl ( ) ) ) ;
}
2005-11-04 11:59:51 +00:00
}
2007-01-13 17:28:54 +00:00
void Part : : openUrlFromBookmarks ( const KUrl & _url )
{
KUrl url = _url ;
Okular : : DocumentViewport vp ( _url . htmlRef ( ) ) ;
if ( vp . isValid ( ) )
m_document - > setNextDocumentViewport ( vp ) ;
url . setHTMLRef ( QString ( ) ) ;
if ( m_document - > currentDocument ( ) = = url )
{
if ( vp . isValid ( ) )
m_document - > setViewport ( vp ) ;
}
else
openUrl ( url ) ;
}
2010-08-20 16:07:36 +00:00
void Part : : slotJobStarted ( KIO : : Job * job )
2005-11-04 11:59:51 +00:00
{
if ( job )
{
2007-01-28 15:46:10 +00:00
QStringList supportedMimeTypes = m_document - > supportedMimeTypes ( ) ;
job - > addMetaData ( " accept " , supportedMimeTypes . join ( " , " ) + " , */*;q=0.5 " ) ;
2010-08-20 16:20:17 +00:00
connect ( job , SIGNAL ( result ( KJob * ) ) , this , SLOT ( slotJobFinished ( KJob * ) ) ) ;
}
}
void Part : : slotJobFinished ( KJob * job )
{
if ( job - > error ( ) = = KIO : : ERR_USER_CANCELED )
{
m_pageView - > noticeMessage ( i18n ( " The loading of %1 has been canceled. " , realUrl ( ) . pathOrUrl ( ) ) ) ;
2005-11-04 11:59:51 +00:00
}
}
2007-06-05 21:25:41 +00:00
void Part : : loadCancelled ( const QString & reason )
{
emit setWindowCaption ( QString ( ) ) ;
2013-03-11 21:52:25 +00:00
resetStartArguments ( ) ;
2008-01-14 23:03:53 +00:00
// when m_viewportDirty.pageNumber != -1 we come from slotDoFileDirty
// so we don't want to show an ugly messagebox just because the document is
// taking more than usual to be recreated
if ( m_viewportDirty . pageNumber = = - 1 )
2007-06-05 21:25:41 +00:00
{
2008-01-14 23:03:53 +00:00
if ( ! reason . isEmpty ( ) )
{
KMessageBox : : error ( widget ( ) , i18n ( " Could not open %1. Reason: %2 " , url ( ) . prettyUrl ( ) , reason ) ) ;
}
2007-06-05 21:25:41 +00:00
}
}
void Part : : setWindowTitleFromDocument ( )
{
2008-11-29 14:36:14 +00:00
// If 'DocumentTitle' should be used, check if the document has one. If
// either case is false, use the file name.
2012-09-08 13:33:42 +00:00
QString title = Okular : : Settings : : displayDocumentNameOrPath ( ) = = Okular : : Settings : : EnumDisplayDocumentNameOrPath : : Path ? realUrl ( ) . pathOrUrl ( ) : realUrl ( ) . fileName ( ) ;
2008-11-29 14:36:14 +00:00
if ( Okular : : Settings : : displayDocumentTitle ( ) )
2007-06-05 21:25:41 +00:00
{
2008-11-29 14:36:14 +00:00
const QString docTitle = m_document - > metaData ( " DocumentTitle " ) . toString ( ) ;
if ( ! docTitle . isEmpty ( ) & & ! docTitle . trimmed ( ) . isEmpty ( ) )
{
title = docTitle ;
}
2007-06-05 21:25:41 +00:00
}
2008-11-29 14:36:14 +00:00
emit setWindowCaption ( title ) ;
2007-06-05 21:25:41 +00:00
}
2013-06-08 14:29:24 +00:00
KConfigDialog * Part : : slotGeneratorPreferences ( )
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
{
2013-05-28 19:10:50 +00:00
// Create dialog
2006-09-21 08:45:36 +00:00
KConfigDialog * dialog = new KConfigDialog ( m_pageView , " generator_prefs " , Okular : : Settings : : self ( ) ) ;
2013-05-28 19:10:50 +00:00
dialog - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
2013-05-28 10:58:23 +00:00
2011-10-12 19:36:01 +00:00
if ( m_embedMode = = ViewerWidgetMode )
{
dialog - > setCaption ( i18n ( " Configure Viewer Backends " ) ) ;
}
else
{
dialog - > setCaption ( i18n ( " Configure Backends " ) ) ;
}
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
2007-01-28 15:46:10 +00:00
m_document - > fillConfigDialog ( dialog ) ;
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
2013-05-28 19:10:50 +00:00
// Show it
2013-05-28 10:58:23 +00:00
dialog - > setWindowModality ( Qt : : ApplicationModal ) ;
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
dialog - > show ( ) ;
2013-06-08 14:29:24 +00:00
return dialog ;
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
}
2007-01-13 00:33:50 +00:00
2007-09-09 10:50:36 +00:00
void Part : : notifySetup ( const QVector < Okular : : Page * > & /*pages*/ , int setupFlags )
2007-01-13 17:28:54 +00:00
{
2007-09-09 10:50:36 +00:00
if ( ! ( setupFlags & Okular : : DocumentObserver : : DocumentChanged ) )
2007-01-13 17:28:54 +00:00
return ;
rebuildBookmarkMenu ( ) ;
2007-03-07 18:15:00 +00:00
updateAboutBackendAction ( ) ;
2012-07-25 00:29:49 +00:00
m_findBar - > resetSearch ( ) ;
2007-04-29 22:50:32 +00:00
m_searchWidget - > setEnabled ( m_document - > supportsSearching ( ) ) ;
2007-01-13 17:28:54 +00:00
}
2005-02-01 18:23:55 +00:00
void Part : : notifyViewportChanged ( bool /*smoothMove*/ )
2004-11-09 17:20:19 +00:00
{
2010-09-03 21:30:30 +00:00
updateViewActions ( ) ;
2004-11-09 17:20:19 +00:00
}
2007-05-01 14:43:30 +00:00
void Part : : notifyPageChanged ( int page , int flags )
2007-01-13 17:28:54 +00:00
{
2012-05-23 21:43:44 +00:00
if ( flags & Okular : : DocumentObserver : : NeedSaveAs )
setModified ( ) ;
2007-01-13 17:28:54 +00:00
if ( ! ( flags & Okular : : DocumentObserver : : Bookmark ) )
return ;
rebuildBookmarkMenu ( ) ;
2007-05-01 14:43:30 +00:00
if ( page = = m_document - > viewport ( ) . pageNumber )
updateBookmarksActions ( ) ;
2007-01-13 17:28:54 +00:00
}
2007-01-13 00:33:50 +00:00
2004-10-12 11:08:09 +00:00
void Part : : goToPage ( uint i )
{
2004-11-09 17:20:19 +00:00
if ( i < = m_document - > pages ( ) )
2005-01-09 23:37:07 +00:00
m_document - > setViewportPage ( i - 1 ) ;
2004-10-12 11:08:09 +00:00
}
2007-01-13 00:33:50 +00:00
2007-07-29 14:36:49 +00:00
void Part : : openDocument ( const QString & doc )
2004-10-12 11:08:09 +00:00
{
2007-07-29 14:36:49 +00:00
openUrl ( KUrl ( doc ) ) ;
2004-10-12 11:08:09 +00:00
}
2007-01-13 00:33:50 +00:00
2004-10-12 11:08:09 +00:00
uint Part : : pages ( )
{
2005-06-13 17:39:58 +00:00
return m_document - > pages ( ) ;
}
2007-01-13 00:33:50 +00:00
2005-06-13 17:39:58 +00:00
uint Part : : currentPage ( )
{
return m_document - > pages ( ) ? m_document - > currentPage ( ) + 1 : 0 ;
}
2007-01-13 00:33:50 +00:00
2007-07-29 14:36:49 +00:00
QString Part : : currentDocument ( )
2005-06-13 17:39:58 +00:00
{
2007-07-29 14:36:49 +00:00
return m_document - > currentDocument ( ) . pathOrUrl ( ) ;
2004-10-12 11:08:09 +00:00
}
2007-01-13 00:33:50 +00:00
2009-05-30 17:00:16 +00:00
QString Part : : documentMetaData ( const QString & metaData ) const
{
const Okular : : DocumentInfo * info = m_document - > documentInfo ( ) ;
if ( info )
{
QDomElement docElement = info - > documentElement ( ) ;
for ( QDomNode node = docElement . firstChild ( ) ; ! node . isNull ( ) ; node = node . nextSibling ( ) )
{
const QDomElement element = node . toElement ( ) ;
if ( metaData . compare ( element . tagName ( ) , Qt : : CaseInsensitive ) = = 0 )
return element . attribute ( " value " ) ;
}
}
return QString ( ) ;
}
2005-07-15 18:20:57 +00:00
bool Part : : slotImportPSFile ( )
{
2007-01-13 00:33:50 +00:00
QString app = KStandardDirs : : findExe ( " ps2pdf " ) ;
if ( app . isEmpty ( ) )
{
// TODO point the user to their distro packages?
2008-01-20 15:35:19 +00:00
KMessageBox : : error ( widget ( ) , i18n ( " The program \" ps2pdf \" was not found, so Okular can not import PS files using it. " ) , i18n ( " ps2pdf not found " ) ) ;
2007-01-13 00:33:50 +00:00
return false ;
}
2006-04-13 11:57:16 +00:00
2006-07-04 23:09:39 +00:00
KUrl url = KFileDialog : : getOpenUrl ( KUrl ( ) , " application/postscript " , this - > widget ( ) ) ;
2006-10-16 17:57:44 +00:00
if ( url . isLocalFile ( ) )
2005-07-15 18:20:57 +00:00
{
2006-10-16 17:57:44 +00:00
KTemporaryFile tf ;
tf . setSuffix ( " .pdf " ) ;
tf . setAutoRemove ( false ) ;
if ( ! tf . open ( ) )
return false ;
m_temporaryLocalFile = tf . fileName ( ) ;
2005-07-15 18:20:57 +00:00
tf . close ( ) ;
2006-10-16 17:57:44 +00:00
2010-01-08 15:29:38 +00:00
setLocalFilePath ( url . toLocalFile ( ) ) ;
2007-03-27 00:00:41 +00:00
QStringList args ;
QProcess * p = new QProcess ( ) ;
args < < url . toLocalFile ( ) < < m_temporaryLocalFile ;
2005-07-15 18:20:57 +00:00
m_pageView - > displayMessage ( i18n ( " Importing PS file as PDF (this may take a while)... " ) ) ;
2011-07-31 19:22:04 +00:00
connect ( p , SIGNAL ( finished ( int , QProcess : : ExitStatus ) ) , this , SLOT ( psTransformEnded ( int , QProcess : : ExitStatus ) ) ) ;
2007-03-27 00:00:41 +00:00
p - > start ( app , args ) ;
2005-07-15 18:20:57 +00:00
return true ;
}
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
2006-11-18 21:36:56 +00:00
m_temporaryLocalFile . clear ( ) ;
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
return false ;
2005-07-15 18:20:57 +00:00
}
2005-11-04 11:59:51 +00:00
2011-09-06 18:01:41 +00:00
static void addFileToWatcher ( KDirWatch * watcher , const QString & filePath )
{
if ( ! watcher - > contains ( filePath ) ) watcher - > addFile ( filePath ) ;
const QFileInfo fi ( filePath ) ;
if ( ! watcher - > contains ( fi . absolutePath ( ) ) ) watcher - > addDir ( fi . absolutePath ( ) ) ;
if ( fi . isSymLink ( ) ) watcher - > addFile ( fi . readLink ( ) ) ;
}
2007-01-13 00:33:50 +00:00
2004-09-09 13:25:40 +00:00
bool Part : : openFile ( )
2003-09-15 09:35:55 +00:00
{
2005-11-04 11:59:51 +00:00
KMimeType : : Ptr mime ;
2010-07-29 22:51:49 +00:00
QString fileNameToOpen = localFilePath ( ) ;
const bool isstdin = url ( ) . isLocalFile ( ) & & url ( ) . fileName ( KUrl : : ObeyTrailingSlash ) = = QLatin1String ( " - " ) ;
const QFileInfo fileInfo ( fileNameToOpen ) ;
if ( ! isstdin & & ! fileInfo . exists ( ) )
return false ;
2007-09-15 14:14:33 +00:00
if ( ! arguments ( ) . mimeType ( ) . isEmpty ( ) )
2005-11-04 11:59:51 +00:00
{
2007-08-10 18:10:44 +00:00
mime = KMimeType : : mimeType ( arguments ( ) . mimeType ( ) ) ;
2005-11-04 11:59:51 +00:00
}
2007-08-10 18:10:44 +00:00
if ( ! mime )
2005-11-04 11:59:51 +00:00
{
2010-07-29 22:51:49 +00:00
mime = KMimeType : : findByPath ( fileNameToOpen ) ;
2005-11-04 11:59:51 +00:00
}
2007-07-29 00:55:17 +00:00
bool isCompressedFile = false ;
bool uncompressOk = true ;
QString compressedMime = compressedMimeFor ( mime - > name ( ) ) ;
if ( compressedMime . isEmpty ( ) )
compressedMime = compressedMimeFor ( mime - > parentMimeType ( ) ) ;
if ( ! compressedMime . isEmpty ( ) )
{
isCompressedFile = true ;
uncompressOk = handleCompressed ( fileNameToOpen , localFilePath ( ) , compressedMime ) ;
mime = KMimeType : : findByPath ( fileNameToOpen ) ;
}
bool ok = false ;
2012-05-30 16:33:07 +00:00
isDocumentArchive = false ;
2007-07-29 00:55:17 +00:00
if ( uncompressOk )
{
2008-11-16 01:23:31 +00:00
if ( mime - > is ( " application/vnd.kde.okular-archive " ) )
2012-05-30 16:33:07 +00:00
{
2008-11-16 01:23:31 +00:00
ok = m_document - > openDocumentArchive ( fileNameToOpen , url ( ) ) ;
2012-05-30 16:33:07 +00:00
isDocumentArchive = true ;
}
2008-11-16 01:23:31 +00:00
else
2012-05-30 16:33:07 +00:00
{
2008-11-16 01:23:31 +00:00
ok = m_document - > openDocument ( fileNameToOpen , url ( ) , mime ) ;
2012-05-30 16:33:07 +00:00
}
2007-07-29 00:55:17 +00:00
}
2005-06-24 16:45:25 +00:00
bool canSearch = m_document - > supportsSearching ( ) ;
2005-01-27 17:31:07 +00:00
// update one-time actions
2012-09-04 18:04:01 +00:00
emit enableCloseAction ( ok ) ;
2005-06-24 16:45:25 +00:00
m_find - > setEnabled ( ok & & canSearch ) ;
m_findNext - > setEnabled ( ok & & canSearch ) ;
2009-02-14 17:11:29 +00:00
m_findPrev - > setEnabled ( ok & & canSearch ) ;
2012-05-30 16:33:07 +00:00
if ( m_saveAs ) m_saveAs - > setEnabled ( ok & & ( m_document - > canSaveChanges ( ) | | isDocumentArchive ) ) ;
2011-10-12 19:36:01 +00:00
if ( m_saveCopyAs ) m_saveCopyAs - > setEnabled ( ok ) ;
2008-03-31 20:51:05 +00:00
emit enablePrintAction ( ok & & m_document - > printingSupport ( ) ! = Okular : : Document : : NoPrinting ) ;
2007-11-26 21:43:54 +00:00
m_printPreview - > setEnabled ( ok & & m_document - > printingSupport ( ) ! = Okular : : Document : : NoPrinting ) ;
2005-02-02 18:18:26 +00:00
m_showProperties - > setEnabled ( ok ) ;
2006-10-03 10:11:16 +00:00
bool hasEmbeddedFiles = ok & & m_document - > embeddedFiles ( ) & & m_document - > embeddedFiles ( ) - > count ( ) > 0 ;
2011-10-12 19:36:01 +00:00
if ( m_showEmbeddedFiles ) m_showEmbeddedFiles - > setEnabled ( hasEmbeddedFiles ) ;
2007-02-23 10:54:30 +00:00
m_topMessage - > setVisible ( hasEmbeddedFiles ) ;
2012-11-02 11:32:44 +00:00
// Warn the user that XFA forms are not supported yet (NOTE: poppler generator only)
if ( ok & & m_document - > metaData ( " HasUnsupportedXfaForm " ) . toBool ( ) = = true )
{
m_formsMessage - > setup ( i18n ( " This document has XFA forms, which are currently <b>unsupported</b>. " ) , KIcon ( " dialog-warning " ) ) ;
m_formsMessage - > setVisible ( true ) ;
}
2007-06-05 20:49:00 +00:00
// m_pageView->toggleFormsAction() may be null on dummy mode
2012-11-02 11:32:44 +00:00
else if ( ok & & m_pageView - > toggleFormsAction ( ) & & m_pageView - > toggleFormsAction ( ) - > isEnabled ( ) )
{
m_formsMessage - > setup ( i18n ( " This document has forms. Click on the button to interact with them, or use View -> Show Forms. " ) ) ;
m_formsMessage - > setVisible ( true ) ;
}
else
{
m_formsMessage - > setVisible ( false ) ;
}
2011-10-12 19:36:01 +00:00
if ( m_showPresentation ) m_showPresentation - > setEnabled ( ok ) ;
2006-07-01 22:17:53 +00:00
if ( ok )
{
2011-10-12 19:36:01 +00:00
if ( m_exportAs )
2006-07-01 22:17:53 +00:00
{
2011-10-12 19:36:01 +00:00
m_exportFormats = m_document - > exportFormats ( ) ;
QList < Okular : : ExportFormat > : : ConstIterator it = m_exportFormats . constBegin ( ) ;
QList < Okular : : ExportFormat > : : ConstIterator itEnd = m_exportFormats . constEnd ( ) ;
QMenu * menu = m_exportAs - > menu ( ) ;
for ( ; it ! = itEnd ; + + it )
{
menu - > addAction ( actionForExportFormat ( * it ) ) ;
}
2006-07-01 22:17:53 +00:00
}
2007-07-29 00:55:17 +00:00
if ( isCompressedFile )
{
m_realUrl = url ( ) ;
}
2008-06-07 21:08:41 +00:00
# ifdef OKULAR_KEEP_FILE_OPEN
if ( keepFileOpen ( ) )
m_keeper - > open ( fileNameToOpen ) ;
# endif
2006-07-01 22:17:53 +00:00
}
2011-10-12 19:36:01 +00:00
if ( m_exportAsText ) m_exportAsText - > setEnabled ( ok & & m_document - > canExportToText ( ) ) ;
if ( m_exportAsDocArchive ) m_exportAsDocArchive - > setEnabled ( ok ) ;
if ( m_exportAs ) m_exportAs - > setEnabled ( ok ) ;
2005-01-27 17:31:07 +00:00
// update viewing actions
2005-02-02 18:18:26 +00:00
updateViewActions ( ) ;
2008-11-21 10:50:16 +00:00
2008-03-17 23:02:33 +00:00
m_fileWasRemoved = false ;
2005-01-01 15:44:44 +00:00
2005-01-27 17:31:07 +00:00
if ( ! ok )
{
// if can't open document, update windows so they display blank contents
2009-06-29 20:55:50 +00:00
m_pageView - > viewport ( ) - > update ( ) ;
2006-05-05 21:12:04 +00:00
m_thumbnailList - > update ( ) ;
2012-09-04 18:04:01 +00:00
setUrl ( KUrl ( ) ) ;
2005-01-27 17:31:07 +00:00
return false ;
}
// set the file to the fileWatcher
2008-03-17 23:02:33 +00:00
if ( url ( ) . isLocalFile ( ) )
{
2011-09-06 18:01:41 +00:00
addFileToWatcher ( m_watcher , localFilePath ( ) ) ;
2008-03-17 23:02:33 +00:00
}
2005-01-27 17:31:07 +00:00
2007-04-15 20:00:43 +00:00
// if the 'OpenTOC' flag is set, open the TOC
2011-12-27 23:49:44 +00:00
if ( m_document - > metaData ( " OpenTOC " ) . toBool ( ) & & m_sidebar - > isItemEnabled ( 0 ) & & ! m_sidebar - > isCollapsed ( ) )
2006-10-28 18:21:55 +00:00
{
2010-07-20 22:09:33 +00:00
const bool sidebarVisible = m_sidebar - > isSidebarVisible ( ) ;
2007-08-06 17:24:10 +00:00
m_sidebar - > setCurrentIndex ( 0 ) ;
2010-07-20 22:09:33 +00:00
m_sidebar - > setSidebarVisibility ( sidebarVisible ) ;
2006-10-28 18:21:55 +00:00
}
2007-01-04 00:20:50 +00:00
// if the 'StartFullScreen' flag is set, or the command line flag was
// specified, start presentation
if ( m_document - > metaData ( " StartFullScreen " ) . toBool ( ) | | m_cliPresentation )
2005-06-13 16:55:57 +00:00
{
2008-03-13 11:42:15 +00:00
bool goAheadWithPresentationMode = true ;
2007-01-04 00:20:50 +00:00
if ( ! m_cliPresentation )
2008-03-13 11:42:15 +00:00
{
2008-04-11 21:16:43 +00:00
const QString text = i18n ( " The document requested to be launched in presentation mode. \n "
2008-03-13 11:42:15 +00:00
" Do you want to allow it? " ) ;
const QString caption = i18n ( " Presentation Mode " ) ;
const KGuiItem yesItem = KGuiItem ( i18n ( " Allow " ) , " dialog-ok " , i18n ( " Allow the presentation mode " ) ) ;
const KGuiItem noItem = KGuiItem ( i18n ( " Do Not Allow " ) , " process-stop " , i18n ( " Do not allow the presentation mode " ) ) ;
const int result = KMessageBox : : questionYesNo ( widget ( ) , text , caption , yesItem , noItem ) ;
if ( result = = KMessageBox : : No )
goAheadWithPresentationMode = false ;
}
2007-01-04 00:20:50 +00:00
m_cliPresentation = false ;
2008-03-13 11:42:15 +00:00
if ( goAheadWithPresentationMode )
QMetaObject : : invokeMethod ( this , " slotShowPresentation " , Qt : : QueuedConnection ) ;
2005-06-13 16:55:57 +00:00
}
2007-08-28 23:17:00 +00:00
m_generatorGuiClient = factory ( ) ? m_document - > guiClient ( ) : 0 ;
if ( m_generatorGuiClient )
factory ( ) - > addClient ( m_generatorGuiClient ) ;
2013-03-11 21:52:25 +00:00
if ( m_cliPrint )
{
m_cliPrint = false ;
slotPrint ( ) ;
}
2005-01-27 17:31:07 +00:00
return true ;
2003-09-15 09:35:55 +00:00
}
2009-05-17 18:08:43 +00:00
bool Part : : openUrl ( const KUrl & _url )
2004-09-18 16:41:23 +00:00
{
2012-05-23 21:43:44 +00:00
// Close current document if any
if ( ! closeUrl ( ) )
return false ;
2009-05-17 18:08:43 +00:00
KUrl url ( _url ) ;
if ( url . hasHTMLRef ( ) )
{
const QString dest = url . htmlRef ( ) ;
bool ok = true ;
const int page = dest . toInt ( & ok ) ;
if ( ok )
{
Okular : : DocumentViewport vp ( page - 1 ) ;
vp . rePos . enabled = true ;
vp . rePos . normalizedX = 0 ;
vp . rePos . normalizedY = 0 ;
vp . rePos . pos = Okular : : DocumentViewport : : TopLeft ;
m_document - > setNextDocumentViewport ( vp ) ;
}
else
{
m_document - > setNextDocumentDestination ( dest ) ;
}
url . setHTMLRef ( QString ( ) ) ;
}
2006-08-30 13:02:48 +00:00
// this calls in sequence the 'closeUrl' and 'openFile' methods
2012-05-23 21:43:44 +00:00
bool openOk = KParts : : ReadWritePart : : openUrl ( url ) ;
2005-07-15 18:20:57 +00:00
2005-06-24 16:39:57 +00:00
if ( openOk )
2006-07-30 23:37:50 +00:00
{
2006-10-15 12:26:16 +00:00
m_viewportDirty . pageNumber = - 1 ;
2006-07-30 23:37:50 +00:00
2007-06-05 21:25:41 +00:00
setWindowTitleFromDocument ( ) ;
2006-07-30 23:37:50 +00:00
}
2010-08-20 16:20:17 +00:00
else
{
2013-03-11 21:52:25 +00:00
resetStartArguments ( ) ;
2010-08-20 16:20:17 +00:00
KMessageBox : : error ( widget ( ) , i18n ( " Could not open %1 " , url . pathOrUrl ( ) ) ) ;
}
2007-01-26 18:35:28 +00:00
2005-06-24 16:39:57 +00:00
return openOk ;
2004-09-18 16:41:23 +00:00
}
2012-05-23 21:43:44 +00:00
bool Part : : queryClose ( )
{
if ( ! isReadWrite ( ) | | ! isModified ( ) )
return true ;
2007-01-13 00:33:50 +00:00
2012-05-23 21:43:44 +00:00
const int res = KMessageBox : : warningYesNoCancel ( widget ( ) ,
i18n ( " Do you want to save your annotation changes or discard them? " ) ,
i18n ( " Close Document " ) ,
KStandardGuiItem : : saveAs ( ) ,
KStandardGuiItem : : discard ( ) ) ;
switch ( res )
{
case KMessageBox : : Yes : // Save as
slotSaveFileAs ( ) ;
return ! isModified ( ) ; // Only allow closing if file was really saved
case KMessageBox : : No : // Discard
return true ;
default : // Cancel
return false ;
}
}
bool Part : : closeUrl ( bool promptToSave )
2005-02-02 18:18:26 +00:00
{
2012-05-23 21:43:44 +00:00
if ( promptToSave & & ! queryClose ( ) )
return false ;
setModified ( false ) ;
2007-03-28 22:01:38 +00:00
if ( ! m_temporaryLocalFile . isNull ( ) & & m_temporaryLocalFile ! = localFilePath ( ) )
2005-07-15 18:20:57 +00:00
{
QFile : : remove ( m_temporaryLocalFile ) ;
2006-11-18 21:36:56 +00:00
m_temporaryLocalFile . clear ( ) ;
2005-07-15 18:20:57 +00:00
}
2005-11-04 11:59:51 +00:00
slotHidePresentation ( ) ;
2012-09-04 18:04:01 +00:00
emit enableCloseAction ( false ) ;
2005-02-02 18:18:26 +00:00
m_find - > setEnabled ( false ) ;
m_findNext - > setEnabled ( false ) ;
2009-02-14 17:11:29 +00:00
m_findPrev - > setEnabled ( false ) ;
2011-10-12 19:36:01 +00:00
if ( m_saveAs ) m_saveAs - > setEnabled ( false ) ;
if ( m_saveCopyAs ) m_saveCopyAs - > setEnabled ( false ) ;
2005-02-02 18:18:26 +00:00
m_printPreview - > setEnabled ( false ) ;
m_showProperties - > setEnabled ( false ) ;
2011-10-12 19:36:01 +00:00
if ( m_showEmbeddedFiles ) m_showEmbeddedFiles - > setEnabled ( false ) ;
if ( m_exportAs ) m_exportAs - > setEnabled ( false ) ;
if ( m_exportAsText ) m_exportAsText - > setEnabled ( false ) ;
if ( m_exportAsDocArchive ) m_exportAsDocArchive - > setEnabled ( false ) ;
2006-10-25 15:35:53 +00:00
m_exportFormats . clear ( ) ;
2011-10-12 19:36:01 +00:00
if ( m_exportAs )
2006-07-01 22:17:53 +00:00
{
2011-10-12 19:36:01 +00:00
QMenu * menu = m_exportAs - > menu ( ) ;
QList < QAction * > acts = menu - > actions ( ) ;
int num = acts . count ( ) ;
for ( int i = 2 ; i < num ; + + i )
{
menu - > removeAction ( acts . at ( i ) ) ;
delete acts . at ( i ) ;
}
2006-07-01 22:17:53 +00:00
}
2011-10-12 19:36:01 +00:00
if ( m_showPresentation ) m_showPresentation - > setEnabled ( false ) ;
2005-11-04 11:59:51 +00:00
emit setWindowCaption ( " " ) ;
emit enablePrintAction ( false ) ;
2007-07-25 10:08:38 +00:00
m_realUrl = KUrl ( ) ;
2008-01-01 15:59:18 +00:00
if ( url ( ) . isLocalFile ( ) )
2008-03-17 23:02:33 +00:00
{
2008-01-01 15:59:18 +00:00
m_watcher - > removeFile ( localFilePath ( ) ) ;
2008-03-17 23:02:33 +00:00
QFileInfo fi ( localFilePath ( ) ) ;
m_watcher - > removeDir ( fi . absolutePath ( ) ) ;
2011-07-05 23:31:06 +00:00
if ( fi . isSymLink ( ) ) m_watcher - > removeFile ( fi . readLink ( ) ) ;
2008-03-17 23:02:33 +00:00
}
m_fileWasRemoved = false ;
2007-08-28 23:17:00 +00:00
if ( m_generatorGuiClient )
factory ( ) - > removeClient ( m_generatorGuiClient ) ;
m_generatorGuiClient = 0 ;
2005-02-02 18:18:26 +00:00
m_document - > closeDocument ( ) ;
2005-11-04 11:59:51 +00:00
updateViewActions ( ) ;
2007-07-29 10:38:48 +00:00
delete m_tempfile ;
m_tempfile = 0 ;
2008-09-22 22:58:32 +00:00
if ( widget ( ) )
{
m_searchWidget - > clearText ( ) ;
m_topMessage - > setVisible ( false ) ;
m_formsMessage - > setVisible ( false ) ;
}
2008-06-07 21:08:41 +00:00
# ifdef OKULAR_KEEP_FILE_OPEN
m_keeper - > close ( ) ;
# endif
2012-05-23 21:43:44 +00:00
bool r = KParts : : ReadWritePart : : closeUrl ( ) ;
2011-09-09 20:59:59 +00:00
setUrl ( KUrl ( ) ) ;
return r ;
2005-02-02 18:18:26 +00:00
}
2012-05-23 21:43:44 +00:00
bool Part : : closeUrl ( )
{
return closeUrl ( true ) ;
}
2011-10-23 10:07:38 +00:00
void Part : : guiActivateEvent ( KParts : : GUIActivateEvent * event )
{
updateViewActions ( ) ;
2012-05-23 21:43:44 +00:00
KParts : : ReadWritePart : : guiActivateEvent ( event ) ;
2011-10-23 10:07:38 +00:00
}
2007-01-13 00:33:50 +00:00
2005-11-04 11:59:51 +00:00
void Part : : close ( )
{
2009-03-22 18:38:38 +00:00
if ( m_embedMode = = NativeShellMode )
2007-01-13 00:33:50 +00:00
{
closeUrl ( ) ;
}
2007-04-15 19:11:10 +00:00
else KMessageBox : : information ( widget ( ) , i18n ( " This link points to a close document action that does not work when using the embedded viewer. " ) , QString ( ) , " warnNoCloseIfNotInOkular " ) ;
2005-11-04 11:59:51 +00:00
}
2007-01-13 00:33:50 +00:00
2005-11-04 11:59:51 +00:00
void Part : : cannotQuit ( )
{
2007-04-15 19:11:10 +00:00
KMessageBox : : information ( widget ( ) , i18n ( " This link points to a quit application action that does not work when using the embedded viewer. " ) , QString ( ) , " warnNoQuitIfNotInOkular " ) ;
2005-11-04 11:59:51 +00:00
}
2007-01-13 00:33:50 +00:00
2005-03-12 15:39:04 +00:00
void Part : : slotShowLeftPanel ( )
2004-12-01 22:18:27 +00:00
{
2005-03-12 15:39:04 +00:00
bool showLeft = m_showLeftPanel - > isChecked ( ) ;
2006-09-21 08:45:36 +00:00
Okular : : Settings : : setShowLeftPanel ( showLeft ) ;
2007-05-23 21:59:12 +00:00
Okular : : Settings : : self ( ) - > writeConfig ( ) ;
2005-03-13 13:14:44 +00:00
// show/hide left panel
2007-08-06 17:24:10 +00:00
m_sidebar - > setSidebarVisibility ( showLeft ) ;
2005-11-04 11:59:51 +00:00
}
2010-10-29 21:47:17 +00:00
void Part : : slotShowBottomBar ( )
{
const bool showBottom = m_showBottomBar - > isChecked ( ) ;
Okular : : Settings : : setShowBottomBar ( showBottom ) ;
Okular : : Settings : : self ( ) - > writeConfig ( ) ;
// show/hide bottom bar
m_bottomBar - > setVisible ( showBottom ) ;
}
2007-01-13 00:33:50 +00:00
2008-03-17 23:02:33 +00:00
void Part : : slotFileDirty ( const QString & path )
2004-12-01 22:18:27 +00:00
{
2007-01-13 00:33:50 +00:00
// The beauty of this is that each start cancels the previous one.
// This means that timeout() is only fired when there have
// no changes to the file for the last 750 milisecs.
// This ensures that we don't update on every other byte that gets
// written to the file.
2008-03-17 23:02:33 +00:00
if ( path = = localFilePath ( ) )
2007-01-13 00:33:50 +00:00
{
2010-07-05 22:33:16 +00:00
// Only start watching the file in case if it wasn't removed
if ( QFile : : exists ( localFilePath ( ) ) )
m_dirtyHandler - > start ( 750 ) ;
2010-07-05 22:48:09 +00:00
else
m_fileWasRemoved = true ;
2007-01-13 00:33:50 +00:00
}
2008-03-17 23:02:33 +00:00
else
{
2011-07-05 02:16:57 +00:00
const QFileInfo fi ( localFilePath ( ) ) ;
2008-03-17 23:02:33 +00:00
if ( fi . absolutePath ( ) = = path )
{
// Our parent has been dirtified
if ( ! QFile : : exists ( localFilePath ( ) ) )
{
m_fileWasRemoved = true ;
}
else if ( m_fileWasRemoved & & QFile : : exists ( localFilePath ( ) ) )
{
// we need to watch the new file
m_watcher - > removeFile ( localFilePath ( ) ) ;
m_watcher - > addFile ( localFilePath ( ) ) ;
m_dirtyHandler - > start ( 750 ) ;
}
}
2013-07-19 22:29:08 +00:00
else if ( fi . isSymLink ( ) & & fi . readLink ( ) = = path )
2011-07-05 02:16:57 +00:00
{
if ( QFile : : exists ( fi . readLink ( ) ) )
m_dirtyHandler - > start ( 750 ) ;
else
m_fileWasRemoved = true ;
}
2008-03-17 23:02:33 +00:00
}
2004-12-01 22:18:27 +00:00
}
2007-01-13 00:33:50 +00:00
2005-01-27 17:31:07 +00:00
void Part : : slotDoFileDirty ( )
2004-12-01 22:18:27 +00:00
{
2013-01-18 17:02:07 +00:00
bool tocReloadPrepared = false ;
2013-01-15 00:17:14 +00:00
2005-06-24 16:39:57 +00:00
// do the following the first time the file is reloaded
2005-07-15 18:20:57 +00:00
if ( m_viewportDirty . pageNumber = = - 1 )
2005-06-24 16:39:57 +00:00
{
2012-11-30 22:24:19 +00:00
// store the url of the current document
m_oldUrl = url ( ) ;
2005-06-24 16:39:57 +00:00
// store the current viewport
2006-10-15 12:26:16 +00:00
m_viewportDirty = m_document - > viewport ( ) ;
2007-04-20 23:22:56 +00:00
// store the current toolbox pane
2007-08-06 17:24:10 +00:00
m_dirtyToolboxIndex = m_sidebar - > currentIndex ( ) ;
2007-11-01 17:52:47 +00:00
m_wasSidebarVisible = m_sidebar - > isSidebarVisible ( ) ;
2011-12-27 23:49:44 +00:00
m_wasSidebarCollapsed = m_sidebar - > isCollapsed ( ) ;
2007-04-20 23:22:56 +00:00
2006-10-15 12:26:16 +00:00
// store if presentation view was open
m_wasPresentationOpen = ( ( PresentationWidget * ) m_presentationWidget ! = 0 ) ;
2013-01-15 00:17:14 +00:00
// preserves the toc state after reload
2013-01-18 17:02:07 +00:00
m_toc - > prepareForReload ( ) ;
tocReloadPrepared = true ;
2005-06-24 16:39:57 +00:00
2011-06-25 22:14:04 +00:00
// store the page rotation
m_dirtyPageRotation = m_document - > rotation ( ) ;
2005-06-24 16:39:57 +00:00
// inform the user about the operation in progress
2012-12-01 00:16:59 +00:00
// TODO: Remove this line and integrate reload info in queryClose
2005-06-24 16:39:57 +00:00
m_pageView - > displayMessage ( i18n ( " Reloading the document... " ) ) ;
}
// close and (try to) reopen the document
2012-05-23 21:43:44 +00:00
if ( ! closeUrl ( ) )
2013-01-18 17:02:07 +00:00
{
2013-06-02 15:21:27 +00:00
m_viewportDirty . pageNumber = - 1 ;
2013-01-18 17:02:07 +00:00
if ( tocReloadPrepared )
{
m_toc - > rollbackReload ( ) ;
}
2012-05-23 21:43:44 +00:00
return ;
2013-01-18 17:02:07 +00:00
}
2013-01-15 00:17:14 +00:00
2013-01-18 17:02:07 +00:00
if ( tocReloadPrepared )
m_toc - > finishReload ( ) ;
2012-05-23 21:43:44 +00:00
2012-12-01 00:16:59 +00:00
// inform the user about the operation in progress
m_pageView - > displayMessage ( i18n ( " Reloading the document... " ) ) ;
2012-11-30 22:24:19 +00:00
if ( KParts : : ReadWritePart : : openUrl ( m_oldUrl ) )
2005-06-24 16:39:57 +00:00
{
2006-12-28 16:58:56 +00:00
// on successful opening, restore the previous viewport
2007-01-13 00:33:50 +00:00
if ( m_viewportDirty . pageNumber > = ( int ) m_document - > pages ( ) )
2005-07-15 18:20:57 +00:00
m_viewportDirty . pageNumber = ( int ) m_document - > pages ( ) - 1 ;
m_document - > setViewport ( m_viewportDirty ) ;
2012-11-30 22:24:19 +00:00
m_oldUrl = KUrl ( ) ;
2005-07-15 18:20:57 +00:00
m_viewportDirty . pageNumber = - 1 ;
2011-06-25 22:14:04 +00:00
m_document - > setRotation ( m_dirtyPageRotation ) ;
2011-12-27 23:49:44 +00:00
if ( m_sidebar - > currentIndex ( ) ! = m_dirtyToolboxIndex & & m_sidebar - > isItemEnabled ( m_dirtyToolboxIndex )
& & ! m_sidebar - > isCollapsed ( ) )
2007-04-20 23:22:56 +00:00
{
2007-08-06 17:24:10 +00:00
m_sidebar - > setCurrentIndex ( m_dirtyToolboxIndex ) ;
2007-04-20 23:22:56 +00:00
}
2007-11-01 17:52:47 +00:00
if ( m_sidebar - > isSidebarVisible ( ) ! = m_wasSidebarVisible )
{
2010-09-04 00:14:45 +00:00
m_sidebar - > setSidebarVisibility ( m_wasSidebarVisible ) ;
2007-11-01 17:52:47 +00:00
}
2011-12-27 23:49:44 +00:00
if ( m_sidebar - > isCollapsed ( ) ! = m_wasSidebarCollapsed )
{
m_sidebar - > setCollapsed ( m_wasSidebarCollapsed ) ;
}
2006-10-15 12:26:16 +00:00
if ( m_wasPresentationOpen ) slotShowPresentation ( ) ;
2007-11-26 21:43:54 +00:00
emit enablePrintAction ( true & & m_document - > printingSupport ( ) ! = Okular : : Document : : NoPrinting ) ;
2005-06-24 16:39:57 +00:00
}
else
{
2011-09-06 18:01:41 +00:00
// start watching the file again (since we dropped it on close)
addFileToWatcher ( m_watcher , localFilePath ( ) ) ;
2006-05-13 11:33:36 +00:00
m_dirtyHandler - > start ( 750 ) ;
2005-06-24 16:39:57 +00:00
}
2004-12-01 22:18:27 +00:00
}
2007-01-13 00:33:50 +00:00
2005-02-02 18:18:26 +00:00
void Part : : updateViewActions ( )
2003-09-14 21:49:26 +00:00
{
2005-02-02 18:18:26 +00:00
bool opened = m_document - > pages ( ) > 0 ;
if ( opened )
2004-11-09 17:20:19 +00:00
{
m_gotoPage - > setEnabled ( m_document - > pages ( ) > 1 ) ;
2010-09-03 21:30:30 +00:00
// Check if you are at the beginning or not
if ( m_document - > currentPage ( ) ! = 0 )
{
m_beginningOfDocument - > setEnabled ( true ) ;
m_prevPage - > setEnabled ( true ) ;
}
else
{
if ( m_pageView - > verticalScrollBar ( ) - > value ( ) ! = 0 )
{
// The page isn't at the very beginning
m_beginningOfDocument - > setEnabled ( true ) ;
}
else
{
// The page is at the very beginning of the document
m_beginningOfDocument - > setEnabled ( false ) ;
}
// The document is at the first page, you can go to a page before
m_prevPage - > setEnabled ( false ) ;
}
if ( m_document - > pages ( ) = = m_document - > currentPage ( ) + 1 )
{
// If you are at the end, disable go to next page
m_nextPage - > setEnabled ( false ) ;
if ( m_pageView - > verticalScrollBar ( ) - > value ( ) = = m_pageView - > verticalScrollBar ( ) - > maximum ( ) )
{
// If you are the end of the page of the last document, you can't go to the last page
m_endOfDocument - > setEnabled ( false ) ;
}
else
{
// Otherwise you can move to the endif
m_endOfDocument - > setEnabled ( true ) ;
}
}
else
{
// If you are not at the end, enable go to next page
m_nextPage - > setEnabled ( true ) ;
m_endOfDocument - > setEnabled ( true ) ;
}
2007-06-17 09:45:59 +00:00
if ( m_historyBack ) m_historyBack - > setEnabled ( ! m_document - > historyAtBegin ( ) ) ;
if ( m_historyNext ) m_historyNext - > setEnabled ( ! m_document - > historyAtEnd ( ) ) ;
2007-05-06 11:23:26 +00:00
m_reload - > setEnabled ( true ) ;
2011-10-12 19:36:01 +00:00
if ( m_copy ) m_copy - > setEnabled ( true ) ;
if ( m_selectAll ) m_selectAll - > setEnabled ( true ) ;
2004-11-09 17:20:19 +00:00
}
else
{
m_gotoPage - > setEnabled ( false ) ;
2010-09-03 21:30:30 +00:00
m_beginningOfDocument - > setEnabled ( false ) ;
m_endOfDocument - > setEnabled ( false ) ;
2004-11-09 17:20:19 +00:00
m_prevPage - > setEnabled ( false ) ;
m_nextPage - > setEnabled ( false ) ;
2007-06-17 09:45:59 +00:00
if ( m_historyBack ) m_historyBack - > setEnabled ( false ) ;
if ( m_historyNext ) m_historyNext - > setEnabled ( false ) ;
2007-05-06 11:23:26 +00:00
m_reload - > setEnabled ( false ) ;
2011-10-12 19:36:01 +00:00
if ( m_copy ) m_copy - > setEnabled ( false ) ;
if ( m_selectAll ) m_selectAll - > setEnabled ( false ) ;
2004-11-09 17:20:19 +00:00
}
2011-10-23 09:17:04 +00:00
if ( factory ( ) )
{
QWidget * menu = factory ( ) - > container ( " menu_okular_part_viewer " , this ) ;
2011-10-23 10:07:38 +00:00
if ( menu ) menu - > setEnabled ( opened ) ;
menu = factory ( ) - > container ( " view_orientation " , this ) ;
if ( menu ) menu - > setEnabled ( opened ) ;
2011-10-23 09:17:04 +00:00
}
2011-10-31 21:41:50 +00:00
emit viewerMenuStateChange ( opened ) ;
2011-10-23 09:17:04 +00:00
2007-05-01 14:43:30 +00:00
updateBookmarksActions ( ) ;
}
void Part : : updateBookmarksActions ( )
{
bool opened = m_document - > pages ( ) > 0 ;
if ( opened )
{
m_addBookmark - > setEnabled ( true ) ;
2012-03-26 18:01:01 +00:00
if ( m_document - > bookmarkManager ( ) - > isBookmarked ( m_document - > viewport ( ) ) )
2007-05-01 14:43:30 +00:00
{
m_addBookmark - > setText ( i18n ( " Remove Bookmark " ) ) ;
2008-01-03 19:55:37 +00:00
m_addBookmark - > setIcon ( KIcon ( " edit-delete-bookmark " ) ) ;
2011-10-25 20:21:22 +00:00
m_renameBookmark - > setEnabled ( true ) ;
2007-05-01 14:43:30 +00:00
}
else
{
m_addBookmark - > setText ( m_addBookmarkText ) ;
2007-05-01 16:38:35 +00:00
m_addBookmark - > setIcon ( m_addBookmarkIcon ) ;
2011-10-25 20:21:22 +00:00
m_renameBookmark - > setEnabled ( false ) ;
2007-05-01 14:43:30 +00:00
}
}
else
{
m_addBookmark - > setEnabled ( false ) ;
m_addBookmark - > setText ( m_addBookmarkText ) ;
2007-05-01 16:38:35 +00:00
m_addBookmark - > setIcon ( m_addBookmarkIcon ) ;
2011-10-25 20:21:22 +00:00
m_renameBookmark - > setEnabled ( false ) ;
2007-05-01 14:43:30 +00:00
}
2003-09-14 21:49:26 +00:00
}
2003-09-14 20:46:38 +00:00
2007-01-13 00:33:50 +00:00
2004-09-23 21:49:00 +00:00
void Part : : enableTOC ( bool enable )
{
2007-08-06 17:24:10 +00:00
m_sidebar - > setItemEnabled ( 0 , enable ) ;
2013-09-30 21:17:35 +00:00
// If present, show the TOC when a document is opened
2013-09-27 13:31:44 +00:00
if ( enable )
{
m_sidebar - > setCurrentIndex ( 0 ) ;
}
2004-09-23 21:49:00 +00:00
}
2008-02-05 17:36:04 +00:00
void Part : : slotRebuildBookmarkMenu ( )
{
rebuildBookmarkMenu ( ) ;
}
2007-01-13 00:33:50 +00:00
2007-03-17 22:58:41 +00:00
void Part : : slotShowFindBar ( )
{
m_findBar - > show ( ) ;
m_findBar - > focusAndSetCursor ( ) ;
2011-10-12 13:50:56 +00:00
m_closeFindBar - > setShortcut ( QKeySequence ( Qt : : Key_Escape ) ) ;
2007-03-17 22:58:41 +00:00
}
void Part : : slotHideFindBar ( )
{
2009-05-08 23:19:37 +00:00
if ( m_findBar - > maybeHide ( ) )
{
m_pageView - > setFocus ( ) ;
2011-10-12 13:50:56 +00:00
m_closeFindBar - > setShortcut ( QKeySequence ( /* None */ ) ) ;
2009-05-08 23:19:37 +00:00
}
2007-03-17 22:58:41 +00:00
}
2004-09-18 16:41:23 +00:00
//BEGIN go to page dialog
2006-09-21 08:45:36 +00:00
class GotoPageDialog : public KDialog
2003-09-14 20:46:38 +00:00
{
2007-01-13 00:33:50 +00:00
public :
GotoPageDialog ( QWidget * p , int current , int max ) : KDialog ( p )
{
setCaption ( i18n ( " Go to Page " ) ) ;
setButtons ( Ok | Cancel ) ;
setDefaultButton ( Ok ) ;
QWidget * w = new QWidget ( this ) ;
setMainWidget ( w ) ;
QVBoxLayout * topLayout = new QVBoxLayout ( w ) ;
topLayout - > setMargin ( 0 ) ;
topLayout - > setSpacing ( spacingHint ( ) ) ;
e1 = new KIntNumInput ( current , w ) ;
e1 - > setRange ( 1 , max ) ;
e1 - > setEditFocus ( true ) ;
2008-03-04 23:32:58 +00:00
e1 - > setSliderEnabled ( true ) ;
2007-01-13 00:33:50 +00:00
QLabel * label = new QLabel ( i18n ( " &Page: " ) , w ) ;
label - > setBuddy ( e1 ) ;
topLayout - > addWidget ( label ) ;
topLayout - > addWidget ( e1 ) ;
// A little bit extra space
topLayout - > addSpacing ( spacingHint ( ) ) ;
topLayout - > addStretch ( 10 ) ;
e1 - > setFocus ( ) ;
}
int getPage ( ) const
{
return e1 - > value ( ) ;
}
protected :
KIntNumInput * e1 ;
2004-09-09 13:25:40 +00:00
} ;
2004-09-18 16:41:23 +00:00
//END go to page dialog
2004-09-09 13:25:40 +00:00
void Part : : slotGoToPage ( )
{
2006-09-21 08:45:36 +00:00
GotoPageDialog pageDialog ( m_pageView , m_document - > currentPage ( ) + 1 , m_document - > pages ( ) ) ;
2004-11-09 17:20:19 +00:00
if ( pageDialog . exec ( ) = = QDialog : : Accepted )
2005-01-09 23:37:07 +00:00
m_document - > setViewportPage ( pageDialog . getPage ( ) - 1 ) ;
2002-08-30 09:14:01 +00:00
}
2007-01-13 00:33:50 +00:00
2004-09-09 13:25:40 +00:00
void Part : : slotPreviousPage ( )
2003-09-14 20:23:01 +00:00
{
2006-05-14 16:28:53 +00:00
if ( m_document - > isOpened ( ) & & ! ( m_document - > currentPage ( ) < 1 ) )
2005-01-09 23:37:07 +00:00
m_document - > setViewportPage ( m_document - > currentPage ( ) - 1 ) ;
2003-09-14 20:23:01 +00:00
}
2007-01-13 00:33:50 +00:00
2004-09-09 13:25:40 +00:00
void Part : : slotNextPage ( )
2003-09-14 20:23:01 +00:00
{
2005-11-04 11:59:51 +00:00
if ( m_document - > isOpened ( ) & & m_document - > currentPage ( ) < ( m_document - > pages ( ) - 1 ) )
2005-01-09 23:37:07 +00:00
m_document - > setViewportPage ( m_document - > currentPage ( ) + 1 ) ;
2004-09-09 13:25:40 +00:00
}
2007-01-13 00:33:50 +00:00
2004-09-11 15:59:32 +00:00
void Part : : slotGotoFirst ( )
2004-09-09 13:25:40 +00:00
{
2010-09-03 21:30:30 +00:00
if ( m_document - > isOpened ( ) ) {
2005-11-04 11:59:51 +00:00
m_document - > setViewportPage ( 0 ) ;
2010-09-03 21:30:30 +00:00
m_beginningOfDocument - > setEnabled ( false ) ;
}
2003-09-14 20:23:01 +00:00
}
2007-01-13 00:33:50 +00:00
2004-09-11 15:59:32 +00:00
void Part : : slotGotoLast ( )
2003-09-14 14:54:16 +00:00
{
2005-11-04 11:59:51 +00:00
if ( m_document - > isOpened ( ) )
2010-09-03 21:30:30 +00:00
{
DocumentViewport endPage ( m_document - > pages ( ) - 1 ) ;
endPage . rePos . enabled = true ;
endPage . rePos . normalizedX = 0 ;
endPage . rePos . normalizedY = 1 ;
endPage . rePos . pos = Okular : : DocumentViewport : : TopLeft ;
m_document - > setViewport ( endPage ) ;
m_endOfDocument - > setEnabled ( false ) ;
}
2003-09-14 14:54:16 +00:00
}
2007-01-13 00:33:50 +00:00
2005-01-27 17:31:07 +00:00
void Part : : slotHistoryBack ( )
{
m_document - > setPrevViewport ( ) ;
}
2007-01-13 00:33:50 +00:00
2005-01-27 17:31:07 +00:00
void Part : : slotHistoryNext ( )
{
m_document - > setNextViewport ( ) ;
}
2007-01-13 00:33:50 +00:00
2007-05-01 14:43:30 +00:00
void Part : : slotAddBookmark ( )
{
2012-03-26 18:01:01 +00:00
DocumentViewport vp = m_document - > viewport ( ) ;
if ( m_document - > bookmarkManager ( ) - > isBookmarked ( vp ) )
2007-05-01 14:43:30 +00:00
{
2012-03-26 18:01:01 +00:00
m_document - > bookmarkManager ( ) - > removeBookmark ( vp ) ;
2007-05-01 14:43:30 +00:00
}
else
{
2012-03-26 18:01:01 +00:00
m_document - > bookmarkManager ( ) - > addBookmark ( vp ) ;
2007-05-01 14:43:30 +00:00
}
}
2012-03-26 18:01:01 +00:00
void Part : : slotRenameBookmark ( const DocumentViewport & viewport )
2011-10-25 20:21:22 +00:00
{
2012-03-26 18:01:01 +00:00
Q_ASSERT ( m_document - > bookmarkManager ( ) - > isBookmarked ( viewport ) ) ;
if ( m_document - > bookmarkManager ( ) - > isBookmarked ( viewport ) )
2011-10-25 20:21:22 +00:00
{
2012-03-26 18:01:01 +00:00
KBookmark bookmark = m_document - > bookmarkManager ( ) - > bookmark ( viewport ) ;
2011-10-25 20:21:22 +00:00
const QString newName = KInputDialog : : getText ( i18n ( " Rename Bookmark " ) , i18n ( " Enter the new name of the bookmark: " ) , bookmark . fullText ( ) , 0 , widget ( ) ) ;
if ( ! newName . isEmpty ( ) )
{
m_document - > bookmarkManager ( ) - > renameBookmark ( & bookmark , newName ) ;
}
}
}
2007-05-01 14:43:30 +00:00
2011-10-25 22:19:58 +00:00
void Part : : slotRenameBookmarkFromMenu ( )
{
QAction * action = dynamic_cast < QAction * > ( sender ( ) ) ;
Q_ASSERT ( action ) ;
if ( action )
{
2012-03-26 18:01:01 +00:00
DocumentViewport vp ( action - > data ( ) . toString ( ) ) ;
slotRenameBookmark ( vp ) ;
2011-10-25 22:19:58 +00:00
}
}
2012-03-26 18:01:01 +00:00
void Part : : slotRenameCurrentViewportBookmark ( )
2011-10-25 22:19:58 +00:00
{
2012-03-26 18:01:01 +00:00
slotRenameBookmark ( m_document - > viewport ( ) ) ;
2011-10-25 22:19:58 +00:00
}
void Part : : slotAboutToShowContextMenu ( KMenu * /*menu*/ , QAction * action , QMenu * contextMenu )
{
const QList < QAction * > actions = contextMenu - > findChildren < QAction * > ( " OkularPrivateRenameBookmarkActions " ) ;
foreach ( QAction * a , actions )
{
contextMenu - > removeAction ( a ) ;
delete a ;
}
KBookmarkAction * ba = dynamic_cast < KBookmarkAction * > ( action ) ;
if ( ba ! = NULL )
{
QAction * separatorAction = contextMenu - > addSeparator ( ) ;
separatorAction - > setObjectName ( " OkularPrivateRenameBookmarkActions " ) ;
QAction * renameAction = contextMenu - > addAction ( KIcon ( " edit-rename " ) , i18n ( " Rename this Bookmark " ) , this , SLOT ( slotRenameBookmarkFromMenu ( ) ) ) ;
2012-03-26 18:01:01 +00:00
renameAction - > setData ( ba - > property ( " htmlRef " ) . toString ( ) ) ;
2011-10-25 22:19:58 +00:00
renameAction - > setObjectName ( " OkularPrivateRenameBookmarkActions " ) ;
}
}
2007-05-01 14:43:30 +00:00
2006-06-24 10:56:06 +00:00
void Part : : slotPreviousBookmark ( )
{
2012-03-26 18:01:01 +00:00
const KBookmark bookmark = m_document - > bookmarkManager ( ) - > previousBookmark ( m_document - > viewport ( ) ) ;
2006-06-24 10:56:06 +00:00
2012-03-26 18:01:01 +00:00
if ( ! bookmark . isNull ( ) )
2006-06-24 10:56:06 +00:00
{
2012-03-26 18:01:01 +00:00
DocumentViewport vp ( bookmark . url ( ) . htmlRef ( ) ) ;
m_document - > setViewport ( vp ) ;
2006-06-24 10:56:06 +00:00
}
}
2007-01-13 00:33:50 +00:00
2006-06-24 10:56:06 +00:00
void Part : : slotNextBookmark ( )
{
2012-03-26 18:01:01 +00:00
const KBookmark bookmark = m_document - > bookmarkManager ( ) - > nextBookmark ( m_document - > viewport ( ) ) ;
2006-06-24 10:56:06 +00:00
2012-03-26 18:01:01 +00:00
if ( ! bookmark . isNull ( ) )
2006-06-24 10:56:06 +00:00
{
2012-03-26 18:01:01 +00:00
DocumentViewport vp ( bookmark . url ( ) . htmlRef ( ) ) ;
m_document - > setViewport ( vp ) ;
2006-06-24 10:56:06 +00:00
}
}
2007-01-13 00:33:50 +00:00
2004-09-09 13:25:40 +00:00
void Part : : slotFind ( )
2003-09-14 14:54:16 +00:00
{
2007-03-17 22:58:41 +00:00
// when in presentation mode, there's already a search bar, taking care of
// the 'find' requests
if ( ( PresentationWidget * ) m_presentationWidget ! = 0 )
2007-04-20 19:45:33 +00:00
{
m_presentationWidget - > slotFind ( ) ;
}
else
{
slotShowFindBar ( ) ;
}
2003-09-14 21:53:40 +00:00
}
2007-01-13 00:33:50 +00:00
2004-09-09 13:25:40 +00:00
void Part : : slotFindNext ( )
2003-09-14 21:53:40 +00:00
{
2007-03-17 22:58:41 +00:00
if ( m_findBar - > isHidden ( ) )
slotShowFindBar ( ) ;
else
m_findBar - > findNext ( ) ;
2003-09-14 14:22:37 +00:00
}
2007-01-13 00:33:50 +00:00
2009-02-14 17:11:29 +00:00
void Part : : slotFindPrev ( )
{
if ( m_findBar - > isHidden ( ) )
slotShowFindBar ( ) ;
else
m_findBar - > findPrev ( ) ;
}
2012-05-23 21:43:44 +00:00
bool Part : : saveFile ( )
{
kDebug ( ) < < " Okular part doesn't support saving the file in the location from which it was opened " ;
return false ;
}
2009-02-14 17:11:29 +00:00
2004-09-08 12:41:14 +00:00
void Part : : slotSaveFileAs ( )
2004-08-28 17:59:17 +00:00
{
2009-03-22 18:38:38 +00:00
if ( m_embedMode = = PrintPreviewMode )
return ;
2007-06-05 20:49:00 +00:00
2012-06-13 13:33:49 +00:00
/* Show a warning before saving if the generator can't save annotations,
* unless we are going to save a . okular archive . */
2012-06-13 22:27:22 +00:00
if ( ! isDocumentArchive & & ! m_document - > canSaveChanges ( Document : : SaveAnnotationsCapability ) )
2012-06-13 13:33:49 +00:00
{
/* Search local annotations */
bool containsLocalAnnotations = false ;
const int pagecount = m_document - > pages ( ) ;
for ( int pageno = 0 ; pageno < pagecount ; + + pageno )
{
const Okular : : Page * page = m_document - > page ( pageno ) ;
foreach ( const Okular : : Annotation * ann , page - > annotations ( ) )
{
if ( ! ( ann - > flags ( ) & Okular : : Annotation : : External ) )
{
containsLocalAnnotations = true ;
break ;
}
}
if ( containsLocalAnnotations )
break ;
}
/* Don't show it if there are no local annotations */
if ( containsLocalAnnotations )
{
int res = KMessageBox : : warningContinueCancel ( widget ( ) , " Your annotations will not be exported. \n You can export the annotated document using File -> Export As -> Document Archive " ) ;
if ( res ! = KMessageBox : : Continue )
return ; // Canceled
}
}
2013-05-13 22:58:11 +00:00
KUrl saveUrl = KFileDialog : : getSaveUrl ( url ( ) ,
2009-12-26 18:48:42 +00:00
QString ( ) , widget ( ) , QString ( ) ,
KFileDialog : : ConfirmOverwrite ) ;
2008-03-11 23:40:59 +00:00
if ( ! saveUrl . isValid ( ) | | saveUrl . isEmpty ( ) )
return ;
2012-05-23 21:43:44 +00:00
saveAs ( saveUrl ) ;
}
bool Part : : saveAs ( const KUrl & saveUrl )
{
2009-09-13 21:11:37 +00:00
KTemporaryFile tf ;
QString fileName ;
if ( ! tf . open ( ) )
{
KMessageBox : : information ( widget ( ) , i18n ( " Could not open the temporary file for saving. " ) ) ;
2012-05-23 21:43:44 +00:00
return false ;
2009-09-13 21:11:37 +00:00
}
fileName = tf . fileName ( ) ;
tf . close ( ) ;
2008-03-11 23:40:59 +00:00
2009-10-19 23:00:52 +00:00
QString errorText ;
2012-05-30 16:33:07 +00:00
bool saved ;
if ( isDocumentArchive )
saved = m_document - > saveDocumentArchive ( fileName ) ;
else
saved = m_document - > saveChanges ( fileName , & errorText ) ;
if ( ! saved )
2009-09-13 21:11:37 +00:00
{
2009-10-19 23:00:52 +00:00
if ( errorText . isEmpty ( ) )
{
KMessageBox : : information ( widget ( ) , i18n ( " File could not be saved in '%1'. Try to save it to another location. " , fileName ) ) ;
}
else
{
KMessageBox : : information ( widget ( ) , i18n ( " File could not be saved in '%1'. %2 " , fileName , errorText ) ) ;
}
2012-05-23 21:43:44 +00:00
return false ;
2008-03-11 23:40:59 +00:00
}
2009-09-13 21:11:37 +00:00
KIO : : Job * copyJob = KIO : : file_copy ( fileName , saveUrl , - 1 , KIO : : Overwrite ) ;
if ( ! KIO : : NetAccess : : synchronousRun ( copyJob , widget ( ) ) )
2012-05-23 21:43:44 +00:00
{
2009-09-13 21:11:37 +00:00
KMessageBox : : information ( widget ( ) , i18n ( " File could not be saved in '%1'. Try to save it to another location. " , saveUrl . prettyUrl ( ) ) ) ;
2012-05-23 21:43:44 +00:00
return false ;
}
setModified ( false ) ;
return true ;
2008-03-11 23:40:59 +00:00
}
void Part : : slotSaveCopyAs ( )
{
2009-03-22 18:38:38 +00:00
if ( m_embedMode = = PrintPreviewMode )
return ;
2008-03-11 23:40:59 +00:00
2009-12-26 18:48:42 +00:00
KUrl saveUrl = KFileDialog : : getSaveUrl ( KUrl ( " kfiledialog:///okular/ " + url ( ) . fileName ( ) ) ,
QString ( ) , widget ( ) , QString ( ) ,
KFileDialog : : ConfirmOverwrite ) ;
2006-08-30 13:02:48 +00:00
if ( saveUrl . isValid ( ) & & ! saveUrl . isEmpty ( ) )
2004-11-05 01:52:48 +00:00
{
2008-06-07 21:08:41 +00:00
// make use of the already downloaded (in case of remote URLs) file,
// no point in downloading that again
KUrl srcUrl = KUrl : : fromPath ( localFilePath ( ) ) ;
KTemporaryFile * tempFile = 0 ;
// duh, our local file disappeared...
if ( ! QFile : : exists ( localFilePath ( ) ) )
{
if ( url ( ) . isLocalFile ( ) )
{
# ifdef OKULAR_KEEP_FILE_OPEN
// local file: try to get it back from the open handle on it
if ( ( tempFile = m_keeper - > copyToTemporary ( ) ) )
srcUrl = KUrl : : fromPath ( tempFile - > fileName ( ) ) ;
2008-06-21 10:54:27 +00:00
# else
2008-06-22 15:35:12 +00:00
const QString msg = i18n ( " Okular cannot copy %1 to the specified location. \n \n The document does not exist anymore. " , localFilePath ( ) ) ;
2008-06-21 10:54:27 +00:00
KMessageBox : : sorry ( widget ( ) , msg ) ;
return ;
2008-06-07 21:08:41 +00:00
# endif
}
else
{
// we still have the original remote URL of the document,
// so copy the document from there
srcUrl = url ( ) ;
}
}
KIO : : Job * copyJob = KIO : : file_copy ( srcUrl , saveUrl , - 1 , KIO : : Overwrite ) ;
2007-07-04 09:35:08 +00:00
if ( ! KIO : : NetAccess : : synchronousRun ( copyJob , widget ( ) ) )
2006-08-30 13:02:48 +00:00
KMessageBox : : information ( widget ( ) , i18n ( " File could not be saved in '%1'. Try to save it to another location. " , saveUrl . prettyUrl ( ) ) ) ;
2008-06-07 21:08:41 +00:00
delete tempFile ;
2004-11-05 01:52:48 +00:00
}
2004-04-15 18:36:43 +00:00
}
2007-01-13 00:33:50 +00:00
2005-04-16 00:25:26 +00:00
void Part : : slotGetNewStuff ( )
{
2009-12-26 16:23:36 +00:00
#if 0
2007-11-09 16:16:05 +00:00
KNS : : Engine engine ( widget ( ) ) ;
2007-07-19 22:27:45 +00:00
engine . init ( " okular.knsrc " ) ;
2005-04-16 00:25:26 +00:00
// show the modal dialog over pageview and execute it
2007-07-19 22:27:45 +00:00
KNS : : Entry : : List entries = engine . downloadDialogModal ( m_pageView ) ;
Q_UNUSED ( entries )
2009-12-26 16:23:36 +00:00
# endif
2005-04-16 00:25:26 +00:00
}
2007-01-13 00:33:50 +00:00
2004-10-27 14:15:27 +00:00
void Part : : slotPreferences ( )
2002-08-30 09:14:01 +00:00
{
2013-05-28 19:10:50 +00:00
// Create dialog
2011-10-12 19:36:01 +00:00
PreferencesDialog * dialog = new PreferencesDialog ( m_pageView , Okular : : Settings : : self ( ) , m_embedMode ) ;
2013-05-28 19:10:50 +00:00
dialog - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
// Show it
2004-10-27 14:15:27 +00:00
dialog - > show ( ) ;
}
2007-01-13 00:33:50 +00:00
2013-05-28 21:55:10 +00:00
void Part : : slotAnnotationPreferences ( )
{
// Create dialog
PreferencesDialog * dialog = new PreferencesDialog ( m_pageView , Okular : : Settings : : self ( ) , m_embedMode ) ;
dialog - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
// Show it
dialog - > switchToAnnotationsPage ( ) ;
dialog - > show ( ) ;
}
2004-10-27 14:15:27 +00:00
void Part : : slotNewConfig ( )
{
2008-04-13 13:15:15 +00:00
// Apply settings here. A good policy is to check whether the setting has
2004-10-29 13:33:51 +00:00
// changed before applying changes.
2005-03-12 15:39:04 +00:00
// Watch File
2011-09-10 17:15:52 +00:00
setWatchFileModeEnabled ( Okular : : Settings : : watchFile ( ) ) ;
2005-03-12 15:39:04 +00:00
2004-11-05 18:14:20 +00:00
// Main View (pageView)
2006-10-28 22:58:05 +00:00
m_pageView - > reparseConfig ( ) ;
2004-11-06 01:48:52 +00:00
2004-11-09 17:20:19 +00:00
// update document settings
m_document - > reparseConfig ( ) ;
2006-12-22 20:42:36 +00:00
// update TOC settings
2007-08-06 17:24:10 +00:00
if ( m_sidebar - > isItemEnabled ( 0 ) )
2006-12-22 20:42:36 +00:00
m_toc - > reparseConfig ( ) ;
2006-10-28 22:58:05 +00:00
// update ThumbnailList contents
2006-09-21 08:45:36 +00:00
if ( Okular : : Settings : : showLeftPanel ( ) & & ! m_thumbnailList - > isHidden ( ) )
2004-11-07 11:20:27 +00:00
m_thumbnailList - > updateWidgets ( ) ;
2009-11-19 17:26:41 +00:00
// update Reviews settings
if ( m_sidebar - > isItemEnabled ( 2 ) )
m_reviewsWidget - > reparseConfig ( ) ;
2011-08-09 15:59:49 +00:00
setWindowTitleFromDocument ( ) ;
2004-10-09 08:10:56 +00:00
}
2002-08-30 09:14:01 +00:00
2007-01-13 00:33:50 +00:00
2004-10-09 08:10:56 +00:00
void Part : : slotPrintPreview ( )
2002-09-02 21:56:00 +00:00
{
2004-11-09 17:20:19 +00:00
if ( m_document - > pages ( ) = = 0 ) return ;
2002-09-02 21:56:00 +00:00
2007-10-18 20:25:33 +00:00
QPrinter printer ;
2004-09-18 16:41:23 +00:00
2007-11-26 21:43:54 +00:00
// Native printing supports KPrintPreview, Postscript needs to use FilePrinterPreview
if ( m_document - > printingSupport ( ) = = Okular : : Document : : NativePrinting )
2004-10-09 08:10:56 +00:00
{
2007-11-26 21:43:54 +00:00
KPrintPreview previewdlg ( & printer , widget ( ) ) ;
setupPrint ( printer ) ;
doPrint ( printer ) ;
previewdlg . exec ( ) ;
2004-11-03 21:37:21 +00:00
}
2007-11-26 21:43:54 +00:00
else
2006-11-01 22:24:57 +00:00
{
2007-11-26 21:43:54 +00:00
// Generate a temp filename for Print to File, then release the file so generator can write to it
KTemporaryFile tf ;
tf . setAutoRemove ( true ) ;
tf . setSuffix ( " .ps " ) ;
tf . open ( ) ;
printer . setOutputFileName ( tf . fileName ( ) ) ;
tf . close ( ) ;
setupPrint ( printer ) ;
doPrint ( printer ) ;
if ( QFile : : exists ( printer . outputFileName ( ) ) )
{
Okular : : FilePrinterPreview previewdlg ( printer . outputFileName ( ) , widget ( ) ) ;
previewdlg . exec ( ) ;
}
2006-11-01 22:24:57 +00:00
}
2002-09-02 21:56:00 +00:00
}
2007-01-13 00:33:50 +00:00
2006-09-21 08:45:36 +00:00
void Part : : slotShowMenu ( const Okular : : Page * page , const QPoint & point )
2004-12-04 23:23:18 +00:00
{
2009-03-22 18:38:38 +00:00
if ( m_embedMode = = PrintPreviewMode )
return ;
2007-06-05 20:49:00 +00:00
2007-01-13 00:33:50 +00:00
bool reallyShow = false ;
if ( ! m_actionsSearched )
{
// the quest for options_show_menubar
KActionCollection * ac ;
QAction * act ;
if ( factory ( ) )
{
2011-10-25 22:19:58 +00:00
const QList < KXMLGUIClient * > clients ( factory ( ) - > clients ( ) ) ;
2007-01-13 00:33:50 +00:00
for ( int i = 0 ; ( ! m_showMenuBarAction | | ! m_showFullScreenAction ) & & i < clients . size ( ) ; + + i )
{
ac = clients . at ( i ) - > actionCollection ( ) ;
// show_menubar
act = ac - > action ( " options_show_menubar " ) ;
if ( act & & qobject_cast < KToggleAction * > ( act ) )
m_showMenuBarAction = qobject_cast < KToggleAction * > ( act ) ;
// fullscreen
act = ac - > action ( " fullscreen " ) ;
if ( act & & qobject_cast < KToggleFullScreenAction * > ( act ) )
m_showFullScreenAction = qobject_cast < KToggleFullScreenAction * > ( act ) ;
}
2006-03-24 22:57:41 +00:00
}
2007-01-13 00:33:50 +00:00
m_actionsSearched = true ;
}
KMenu * popup = new KMenu ( widget ( ) ) ;
2007-01-13 14:45:51 +00:00
QAction * addBookmark = 0 ;
QAction * removeBookmark = 0 ;
QAction * fitPageWidth = 0 ;
2007-01-13 00:33:50 +00:00
if ( page )
{
popup - > addTitle ( i18n ( " Page %1 " , page - > number ( ) + 1 ) ) ;
2012-03-26 18:01:01 +00:00
if ( m_document - > bookmarkManager ( ) - > isBookmarked ( m_document - > viewport ( ) ) )
2008-01-03 19:55:37 +00:00
removeBookmark = popup - > addAction ( KIcon ( " edit-delete-bookmark " ) , i18n ( " Remove Bookmark " ) ) ;
2007-01-13 14:45:51 +00:00
else
2007-03-08 21:41:46 +00:00
addBookmark = popup - > addAction ( KIcon ( " bookmark-new " ) , i18n ( " Add Bookmark " ) ) ;
2007-01-13 00:33:50 +00:00
if ( m_pageView - > canFitPageWidth ( ) )
2008-01-03 19:55:37 +00:00
fitPageWidth = popup - > addAction ( KIcon ( " zoom-fit-best " ) , i18n ( " Fit Width " ) ) ;
2007-01-13 00:33:50 +00:00
popup - > addAction ( m_prevBookmark ) ;
popup - > addAction ( m_nextBookmark ) ;
reallyShow = true ;
}
/*
//Albert says: I have not ported this as i don't see it does anything
if ( d - > mouseOnRect ) // and rect->objectType() == ObjectRect::Image ...
{
2007-03-08 21:41:46 +00:00
m_popup - > insertItem ( SmallIcon ( " document-save " ) , i18n ( " Save Image... " ) , 4 ) ;
2007-01-13 00:33:50 +00:00
m_popup - > setItemEnabled ( 4 , false ) ;
} */
if ( ( m_showMenuBarAction & & ! m_showMenuBarAction - > isChecked ( ) ) | | ( m_showFullScreenAction & & m_showFullScreenAction - > isChecked ( ) ) )
{
popup - > addTitle ( i18n ( " Tools " ) ) ;
if ( m_showMenuBarAction & & ! m_showMenuBarAction - > isChecked ( ) ) popup - > addAction ( m_showMenuBarAction ) ;
if ( m_showFullScreenAction & & m_showFullScreenAction - > isChecked ( ) ) popup - > addAction ( m_showFullScreenAction ) ;
reallyShow = true ;
}
if ( reallyShow )
{
QAction * res = popup - > exec ( point ) ;
if ( res )
{
2012-03-26 18:01:01 +00:00
if ( res = = addBookmark ) m_document - > bookmarkManager ( ) - > addBookmark ( m_document - > viewport ( ) ) ;
else if ( res = = removeBookmark ) m_document - > bookmarkManager ( ) - > removeBookmark ( m_document - > viewport ( ) ) ;
2007-01-13 00:33:50 +00:00
else if ( res = = fitPageWidth ) m_pageView - > fitPageWidth ( page - > number ( ) ) ;
}
}
delete popup ;
2004-12-04 23:23:18 +00:00
}
2007-01-13 00:33:50 +00:00
2004-12-05 22:47:32 +00:00
void Part : : slotShowProperties ( )
{
2007-01-13 00:33:50 +00:00
PropertiesDialog * d = new PropertiesDialog ( widget ( ) , m_document ) ;
d - > exec ( ) ;
delete d ;
2004-12-05 22:47:32 +00:00
}
2007-01-13 00:33:50 +00:00
2006-05-28 16:54:54 +00:00
void Part : : slotShowEmbeddedFiles ( )
{
2007-01-13 00:33:50 +00:00
EmbeddedFilesDialog * d = new EmbeddedFilesDialog ( widget ( ) , m_document ) ;
d - > exec ( ) ;
delete d ;
2006-05-28 16:54:54 +00:00
}
2007-01-13 00:33:50 +00:00
2004-12-17 17:14:46 +00:00
void Part : : slotShowPresentation ( )
{
2005-06-13 16:55:57 +00:00
if ( ! m_presentationWidget )
2006-06-25 16:34:11 +00:00
{
2008-11-29 13:50:37 +00:00
m_presentationWidget = new PresentationWidget ( widget ( ) , m_document , actionCollection ( ) ) ;
2006-06-25 16:34:11 +00:00
}
2004-12-17 17:14:46 +00:00
}
2007-01-13 00:33:50 +00:00
2005-04-07 09:53:15 +00:00
void Part : : slotHidePresentation ( )
{
if ( m_presentationWidget )
delete ( PresentationWidget * ) m_presentationWidget ;
}
2007-01-13 00:33:50 +00:00
2007-08-26 14:40:29 +00:00
void Part : : slotTogglePresentation ( )
{
if ( m_document - > isOpened ( ) )
{
if ( ! m_presentationWidget )
2008-11-29 13:50:37 +00:00
m_presentationWidget = new PresentationWidget ( widget ( ) , m_document , actionCollection ( ) ) ;
2007-08-26 14:40:29 +00:00
else delete ( PresentationWidget * ) m_presentationWidget ;
}
}
2008-09-22 22:18:07 +00:00
void Part : : reload ( )
{
if ( m_document - > isOpened ( ) )
{
slotReload ( ) ;
}
}
2013-03-11 21:52:25 +00:00
void Part : : enableStartWithPrint ( )
{
m_cliPrint = true ;
}
2008-09-22 22:18:07 +00:00
2007-03-07 18:15:00 +00:00
void Part : : slotAboutBackend ( )
{
const KComponentData * data = m_document - > componentData ( ) ;
if ( ! data )
return ;
2009-03-23 22:57:50 +00:00
KAboutData aboutData ( * data - > aboutData ( ) ) ;
if ( aboutData . programIconName ( ) . isEmpty ( ) | | aboutData . programIconName ( ) = = aboutData . appName ( ) )
{
if ( const Okular : : DocumentInfo * documentInfo = m_document - > documentInfo ( ) )
{
const QString mimeTypeName = documentInfo - > get ( " mimeType " ) ;
if ( ! mimeTypeName . isEmpty ( ) )
{
if ( KMimeType : : Ptr type = KMimeType : : mimeType ( mimeTypeName ) )
aboutData . setProgramIconName ( type - > iconName ( ) ) ;
}
}
}
KAboutApplicationDialog dlg ( & aboutData , widget ( ) ) ;
2007-03-07 18:15:00 +00:00
dlg . exec ( ) ;
}
2006-07-01 22:17:53 +00:00
void Part : : slotExportAs ( QAction * act )
{
QList < QAction * > acts = m_exportAs - > menu ( ) ? m_exportAs - > menu ( ) - > actions ( ) : QList < QAction * > ( ) ;
int id = acts . indexOf ( act ) ;
if ( ( id < 0 ) | | ( id > = acts . count ( ) ) )
return ;
2008-11-16 01:23:31 +00:00
QString filter ;
switch ( id )
{
case 0 :
filter = " text/plain " ;
break ;
case 1 :
filter = " application/vnd.kde.okular-archive " ;
break ;
default :
filter = m_exportFormats . at ( id - 2 ) . mimeType ( ) - > name ( ) ;
break ;
}
2009-12-26 18:48:42 +00:00
QString fileName = KFileDialog : : getSaveFileName ( url ( ) . isLocalFile ( ) ? url ( ) . directory ( ) : QString ( ) ,
filter , widget ( ) , QString ( ) ,
KFileDialog : : ConfirmOverwrite ) ;
2006-07-01 22:17:53 +00:00
if ( ! fileName . isEmpty ( ) )
{
2008-11-16 01:23:31 +00:00
bool saved = false ;
switch ( id )
{
case 0 :
saved = m_document - > exportToText ( fileName ) ;
break ;
case 1 :
saved = m_document - > saveDocumentArchive ( fileName ) ;
break ;
default :
saved = m_document - > exportTo ( fileName , m_exportFormats . at ( id - 2 ) ) ;
break ;
}
2006-07-01 22:17:53 +00:00
if ( ! saved )
KMessageBox : : information ( widget ( ) , i18n ( " File could not be saved in '%1'. Try to save it to another location. " , fileName ) ) ;
}
}
2007-01-13 00:33:50 +00:00
2007-05-06 11:23:26 +00:00
void Part : : slotReload ( )
{
// stop the dirty handler timer, otherwise we may conflict with the
// auto-refresh system
m_dirtyHandler - > stop ( ) ;
slotDoFileDirty ( ) ;
}
2004-10-09 08:10:56 +00:00
void Part : : slotPrint ( )
2004-01-02 17:46:06 +00:00
{
2004-11-09 17:20:19 +00:00
if ( m_document - > pages ( ) = = 0 ) return ;
2004-11-03 21:37:21 +00:00
2011-08-23 19:47:37 +00:00
# ifdef Q_WS_WIN
2011-08-22 20:56:56 +00:00
QPrinter printer ( QPrinter : : HighResolution ) ;
2011-08-23 19:47:37 +00:00
# else
QPrinter printer ;
# endif
2007-11-26 21:43:54 +00:00
QPrintDialog * printDialog = 0 ;
QWidget * printConfigWidget = 0 ;
2004-11-03 21:37:21 +00:00
2007-11-26 21:43:54 +00:00
// Must do certain QPrinter setup before creating QPrintDialog
setupPrint ( printer ) ;
2007-10-15 23:01:27 +00:00
2007-11-26 21:43:54 +00:00
// Create the Print Dialog with extra config widgets if required
if ( m_document - > canConfigurePrinter ( ) )
{
printConfigWidget = m_document - > printConfigurationWidget ( ) ;
}
if ( printConfigWidget )
{
printDialog = KdePrint : : createPrintDialog ( & printer , QList < QWidget * > ( ) < < printConfigWidget , widget ( ) ) ;
}
else
{
printDialog = KdePrint : : createPrintDialog ( & printer , widget ( ) ) ;
}
if ( printDialog )
{
// Set the available Print Range
printDialog - > setMinMax ( 1 , m_document - > pages ( ) ) ;
printDialog - > setFromTo ( 1 , m_document - > pages ( ) ) ;
// If the user has bookmarked pages for printing, then enable Selection
if ( ! m_document - > bookmarkedPageRange ( ) . isEmpty ( ) )
{
printDialog - > addEnabledOption ( QAbstractPrintDialog : : PrintSelection ) ;
}
2004-11-03 21:37:21 +00:00
2007-11-26 21:43:54 +00:00
// If the Document type doesn't support print to both PS & PDF then disable the Print Dialog option
if ( printDialog - > isOptionEnabled ( QAbstractPrintDialog : : PrintToFile ) & &
! m_document - > supportsPrintToFile ( ) )
{
printDialog - > setEnabledOptions ( printDialog - > enabledOptions ( ) ^ QAbstractPrintDialog : : PrintToFile ) ;
}
2010-06-04 08:25:25 +00:00
# if QT_VERSION >= KDE_MAKE_VERSION(4,7,0)
// Enable the Current Page option in the dialog.
if ( m_document - > pages ( ) > 1 & & currentPage ( ) > 0 )
{
printDialog - > setOption ( QAbstractPrintDialog : : PrintCurrentPage ) ;
}
# endif
2007-11-26 21:43:54 +00:00
if ( printDialog - > exec ( ) )
doPrint ( printer ) ;
2008-07-13 09:51:04 +00:00
delete printDialog ;
2007-11-26 21:43:54 +00:00
}
}
void Part : : setupPrint ( QPrinter & printer )
{
2011-06-05 22:40:22 +00:00
printer . setOrientation ( m_document - > orientation ( ) ) ;
2004-11-03 21:37:21 +00:00
2007-03-04 23:19:43 +00:00
// title
QString title = m_document - > metaData ( " DocumentTitle " ) . toString ( ) ;
if ( title . isEmpty ( ) )
{
title = m_document - > currentDocument ( ) . fileName ( ) ;
}
if ( ! title . isEmpty ( ) )
{
printer . setDocName ( title ) ;
}
2004-01-02 17:46:06 +00:00
}
2007-01-13 00:33:50 +00:00
2007-10-15 23:01:27 +00:00
void Part : : doPrint ( QPrinter & printer )
2004-01-02 17:46:06 +00:00
{
2007-01-02 22:37:55 +00:00
if ( ! m_document - > isAllowed ( Okular : : AllowPrint ) )
2004-11-03 21:37:21 +00:00
{
KMessageBox : : error ( widget ( ) , i18n ( " Printing this document is not allowed. " ) ) ;
return ;
}
2004-11-09 17:20:19 +00:00
if ( ! m_document - > print ( printer ) )
2004-11-03 21:37:21 +00:00
{
2010-04-14 23:07:27 +00:00
const QString error = m_document - > printError ( ) ;
if ( error . isEmpty ( ) )
{
KMessageBox : : error ( widget ( ) , i18n ( " Could not print the document. Unknown error. Please report to bugs.kde.org " ) ) ;
}
else
{
2010-04-16 21:21:40 +00:00
KMessageBox : : error ( widget ( ) , i18n ( " Could not print the document. Detailed error is \" %1 \" . Please report to bugs.kde.org " , error ) ) ;
2010-04-14 23:07:27 +00:00
}
2004-11-03 21:37:21 +00:00
}
2004-01-02 17:46:06 +00:00
}
2007-01-13 00:33:50 +00:00
2007-02-21 15:12:57 +00:00
void Part : : restoreDocument ( const KConfigGroup & group )
2004-11-01 21:56:08 +00:00
{
2007-10-22 18:21:51 +00:00
KUrl url ( group . readPathEntry ( " URL " , QString ( ) ) ) ;
2007-01-13 00:33:50 +00:00
if ( url . isValid ( ) )
{
2007-02-20 15:48:18 +00:00
QString viewport = group . readEntry ( " Viewport " ) ;
2007-01-13 00:33:50 +00:00
if ( ! viewport . isEmpty ( ) ) m_document - > setNextDocumentViewport ( Okular : : DocumentViewport ( viewport ) ) ;
openUrl ( url ) ;
}
2004-11-01 21:56:08 +00:00
}
2007-01-13 00:33:50 +00:00
2007-02-20 15:48:18 +00:00
void Part : : saveDocumentRestoreInfo ( KConfigGroup & group )
2004-11-01 21:56:08 +00:00
{
2007-02-20 15:48:18 +00:00
group . writePathEntry ( " URL " , url ( ) . url ( ) ) ;
group . writeEntry ( " Viewport " , m_document - > viewport ( ) . toString ( ) ) ;
2004-11-01 21:56:08 +00:00
}
2007-01-13 00:33:50 +00:00
2007-03-27 00:00:41 +00:00
void Part : : psTransformEnded ( int exit , QProcess : : ExitStatus status )
2005-07-15 18:20:57 +00:00
{
2007-03-27 00:00:41 +00:00
Q_UNUSED ( exit )
if ( status ! = QProcess : : NormalExit )
return ;
QProcess * senderobj = sender ( ) ? qobject_cast < QProcess * > ( sender ( ) ) : 0 ;
if ( senderobj )
{
senderobj - > close ( ) ;
senderobj - > deleteLater ( ) ;
}
2007-03-28 22:01:38 +00:00
setLocalFilePath ( m_temporaryLocalFile ) ;
openUrl ( m_temporaryLocalFile ) ;
m_temporaryLocalFile . clear ( ) ;
2005-07-15 18:20:57 +00:00
}
2007-01-13 00:33:50 +00:00
2007-06-05 20:49:00 +00:00
void Part : : unsetDummyMode ( )
{
2009-03-22 18:38:38 +00:00
if ( m_embedMode = = PrintPreviewMode )
return ;
2007-06-05 20:49:00 +00:00
2007-09-03 17:25:52 +00:00
m_sidebar - > setItemEnabled ( 2 , true ) ;
m_sidebar - > setItemEnabled ( 3 , true ) ;
2007-08-06 17:24:10 +00:00
m_sidebar - > setSidebarVisibility ( Okular : : Settings : : showLeftPanel ( ) ) ;
2007-06-05 20:49:00 +00:00
2007-06-17 09:45:59 +00:00
// add back and next in history
2011-07-31 19:22:04 +00:00
m_historyBack = KStandardAction : : documentBack ( this , SLOT ( slotHistoryBack ( ) ) , actionCollection ( ) ) ;
2007-06-17 09:45:59 +00:00
m_historyBack - > setWhatsThis ( i18n ( " Go to the place you were before " ) ) ;
2012-07-10 16:45:23 +00:00
connect ( m_pageView , SIGNAL ( mouseBackButtonClick ( ) ) , m_historyBack , SLOT ( trigger ( ) ) ) ;
2007-06-17 09:45:59 +00:00
2011-07-31 19:22:04 +00:00
m_historyNext = KStandardAction : : documentForward ( this , SLOT ( slotHistoryNext ( ) ) , actionCollection ( ) ) ;
2007-06-17 09:45:59 +00:00
m_historyNext - > setWhatsThis ( i18n ( " Go to the place you were after " ) ) ;
2012-07-10 16:45:23 +00:00
connect ( m_pageView , SIGNAL ( mouseForwardButtonClick ( ) ) , m_historyNext , SLOT ( trigger ( ) ) ) ;
2007-06-17 09:45:59 +00:00
2007-06-05 20:49:00 +00:00
m_pageView - > setupActions ( actionCollection ( ) ) ;
// attach the actions of the children widgets too
m_formsMessage - > setActionButton ( m_pageView - > toggleFormsAction ( ) ) ;
2011-11-01 21:13:20 +00:00
// ensure history actions are in the correct state
updateViewActions ( ) ;
2007-06-05 20:49:00 +00:00
}
2007-07-29 00:55:17 +00:00
bool Part : : handleCompressed ( QString & destpath , const QString & path , const QString & compressedMimetype )
2007-01-12 23:54:26 +00:00
{
2007-10-01 17:06:42 +00:00
m_tempfile = 0 ;
2007-01-12 23:54:26 +00:00
// we are working with a compressed file, decompressing
// temporary file for decompressing
2007-10-01 17:06:42 +00:00
KTemporaryFile * newtempfile = new KTemporaryFile ( ) ;
newtempfile - > setAutoRemove ( true ) ;
2007-01-12 23:54:26 +00:00
2007-10-01 17:06:42 +00:00
if ( ! newtempfile - > open ( ) )
2007-01-12 23:54:26 +00:00
{
2007-03-30 17:46:50 +00:00
KMessageBox : : error ( widget ( ) ,
2007-01-12 23:54:26 +00:00
i18n ( " <qt><strong>File Error!</strong> Could not create temporary file "
2007-01-13 00:33:50 +00:00
" <nobr><strong>%1</strong></nobr>.</qt> " ,
2007-10-01 17:06:42 +00:00
strerror ( newtempfile - > error ( ) ) ) ) ;
delete newtempfile ;
2007-01-13 00:33:50 +00:00
return false ;
2007-01-12 23:54:26 +00:00
}
// decompression filer
2007-07-29 00:55:17 +00:00
QIODevice * filterDev = KFilterDev : : deviceForFile ( path , compressedMimetype ) ;
2007-01-12 23:54:26 +00:00
if ( ! filterDev )
{
2007-10-01 17:06:42 +00:00
delete newtempfile ;
2007-01-12 23:54:26 +00:00
return false ;
}
if ( ! filterDev - > open ( QIODevice : : ReadOnly ) )
{
2007-03-30 17:46:50 +00:00
KMessageBox : : detailedError ( widget ( ) ,
2007-01-12 23:54:26 +00:00
i18n ( " <qt><strong>File Error!</strong> Could not open the file "
" <nobr><strong>%1</strong></nobr> for uncompression. "
" The file will not be loaded.</qt> " , path ) ,
i18n ( " <qt>This error typically occurs if you do "
2007-01-13 00:33:50 +00:00
" not have enough permissions to read the file. "
2007-01-12 23:54:26 +00:00
" You can check ownership and permissions if you "
2008-04-11 22:09:50 +00:00
" right-click on the file in the Dolphin "
" file manager and then choose the 'Properties' tab.</qt> " ) ) ;
2007-01-12 23:54:26 +00:00
2007-01-13 00:33:50 +00:00
delete filterDev ;
2007-10-01 17:06:42 +00:00
delete newtempfile ;
2007-01-13 00:33:50 +00:00
return false ;
2007-01-12 23:54:26 +00:00
}
2010-08-21 15:48:02 +00:00
char buf [ 65536 ] ;
2007-01-12 23:54:26 +00:00
int read = 0 , wrtn = 0 ;
2010-08-21 15:48:02 +00:00
while ( ( read = filterDev - > read ( buf , sizeof ( buf ) ) ) > 0 )
2007-01-12 23:54:26 +00:00
{
2010-08-21 15:48:02 +00:00
wrtn = newtempfile - > write ( buf , read ) ;
2007-01-12 23:54:26 +00:00
if ( read ! = wrtn )
break ;
}
delete filterDev ;
2007-10-01 17:06:42 +00:00
if ( ( read ! = 0 ) | | ( newtempfile - > size ( ) = = 0 ) )
2007-01-12 23:54:26 +00:00
{
2007-03-30 17:46:50 +00:00
KMessageBox : : detailedError ( widget ( ) ,
2007-01-12 23:54:26 +00:00
i18n ( " <qt><strong>File Error!</strong> Could not uncompress "
" the file <nobr><strong>%1</strong></nobr>. "
" The file will not be loaded.</qt> " , path ) ,
i18n ( " <qt>This error typically occurs if the file is corrupt. "
" If you want to be sure, try to decompress the file manually "
" using command-line tools.</qt> " ) ) ;
2007-10-01 17:06:42 +00:00
delete newtempfile ;
2007-01-12 23:54:26 +00:00
return false ;
}
2007-10-01 17:06:42 +00:00
m_tempfile = newtempfile ;
2007-07-29 00:55:17 +00:00
destpath = m_tempfile - > fileName ( ) ;
2007-01-12 23:54:26 +00:00
return true ;
}
2007-01-13 17:28:54 +00:00
void Part : : rebuildBookmarkMenu ( bool unplugActions )
{
if ( unplugActions )
{
unplugActionList ( " bookmarks_currentdocument " ) ;
qDeleteAll ( m_bookmarkActions ) ;
m_bookmarkActions . clear ( ) ;
}
KUrl u = m_document - > currentDocument ( ) ;
if ( u . isValid ( ) )
{
m_bookmarkActions = m_document - > bookmarkManager ( ) - > actionsForUrl ( u ) ;
}
2007-01-28 16:37:13 +00:00
bool havebookmarks = true ;
2007-01-13 17:28:54 +00:00
if ( m_bookmarkActions . isEmpty ( ) )
{
2007-01-28 16:37:13 +00:00
havebookmarks = false ;
2011-03-20 13:46:43 +00:00
QAction * a = new KAction ( 0 ) ;
2007-01-13 17:28:54 +00:00
a - > setText ( i18n ( " No Bookmarks " ) ) ;
a - > setEnabled ( false ) ;
m_bookmarkActions . append ( a ) ;
}
plugActionList ( " bookmarks_currentdocument " , m_bookmarkActions ) ;
2011-10-25 22:19:58 +00:00
if ( factory ( ) )
{
const QList < KXMLGUIClient * > clients ( factory ( ) - > clients ( ) ) ;
bool containerFound = false ;
for ( int i = 0 ; ! containerFound & & i < clients . size ( ) ; + + i )
{
QWidget * container = factory ( ) - > container ( " bookmarks " , clients [ i ] ) ;
if ( container & & container - > actions ( ) . contains ( m_bookmarkActions . first ( ) ) )
{
Q_ASSERT ( dynamic_cast < KMenu * > ( container ) ) ;
disconnect ( container , 0 , this , 0 ) ;
connect ( container , SIGNAL ( aboutToShowContextMenu ( KMenu * , QAction * , QMenu * ) ) , this , SLOT ( slotAboutToShowContextMenu ( KMenu * , QAction * , QMenu * ) ) ) ;
containerFound = true ;
}
}
}
2007-01-28 16:37:13 +00:00
m_prevBookmark - > setEnabled ( havebookmarks ) ;
m_nextBookmark - > setEnabled ( havebookmarks ) ;
2007-01-13 17:28:54 +00:00
}
2007-03-07 18:15:00 +00:00
void Part : : updateAboutBackendAction ( )
{
const KComponentData * data = m_document - > componentData ( ) ;
if ( data )
{
m_aboutBackend - > setEnabled ( true ) ;
}
else
{
m_aboutBackend - > setEnabled ( false ) ;
}
}
2013-03-11 21:52:25 +00:00
void Part : : resetStartArguments ( )
{
m_cliPrint = false ;
}
2012-05-23 21:43:44 +00:00
void Part : : setReadWrite ( bool readwrite )
{
m_document - > setAnnotationEditingEnabled ( readwrite ) ;
ReadWritePart : : setReadWrite ( readwrite ) ;
}
2009-10-26 20:59:24 +00:00
} // namespace Okular
2007-01-12 23:54:26 +00:00
2005-01-02 14:29:37 +00:00
# include "part.moc"
2008-03-17 23:02:33 +00:00
/* kate: replace-tabs on; indent-width 4; */