@ -151,8 +151,25 @@ class FileKeeper
std : : FILE * m_handle ;
} ;
K_PLUGIN_FACTORY ( okularPartFactory , registerPlugin < Okular : : Part > ( ) ; )
K_EXPORT_PLUGIN ( okularPartFactory ( okularAboutData ( " okular " , I18N_NOOP ( " Okular " ) ) ) )
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 ( ) )
static QAction * actionForExportFormat ( const Okular : : ExportFormat & format , QObject * parent = 0 )
{
@ -264,8 +281,9 @@ namespace Okular
Part : : Part ( QWidget * parentWidget ,
QObject * parent ,
const QVariantList & args )
: KParts : : ReadOnlyPart ( parent ) ,
const QVariantList & args ,
KComponentData componentData )
: KParts : : ReadWritePart ( parent ) ,
m_tempfile ( 0 ) , m_fileWasRemoved ( false ) , m_showMenuBarAction ( 0 ) , m_showFullScreenAction ( 0 ) , m_actionsSearched ( false ) ,
m_cliPresentation ( false ) , m_embedMode ( detectEmbedMode ( parentWidget , parent , args ) ) , m_generatorGuiClient ( 0 ) , m_keeper ( 0 )
{
@ -300,7 +318,7 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
new OkularLiveConnectExtension ( this ) ;
// we need an instance
setComponentData ( okularPartFactory : : componentData ( ) ) ;
setComponentData ( componentData ) ;
GuiUtils : : addIconLoader ( iconLoader ( ) ) ;
@ -1025,6 +1043,9 @@ void Part::notifyViewportChanged( bool /*smoothMove*/ )
void Part : : notifyPageChanged ( int page , int flags )
{
if ( flags & Okular : : DocumentObserver : : NeedSaveAs )
setModified ( ) ;
if ( ! ( flags & Okular : : DocumentObserver : : Bookmark ) )
return ;
@ -1258,6 +1279,10 @@ bool Part::openFile()
bool Part : : openUrl ( const KUrl & _url )
{
// Close current document if any
if ( ! closeUrl ( ) )
return false ;
KUrl url ( _url ) ;
if ( url . hasHTMLRef ( ) )
{
@ -1281,7 +1306,7 @@ bool Part::openUrl(const KUrl &_url)
}
// this calls in sequence the 'closeUrl' and 'openFile' methods
bool openOk = KParts : : ReadOnly Part : : openUrl ( url ) ;
bool openOk = KParts : : ReadWrite Part : : openUrl ( url ) ;
if ( openOk )
{
@ -1297,9 +1322,36 @@ bool Part::openUrl(const KUrl &_url)
return openOk ;
}
bool Part : : queryClose ( )
{
if ( ! isReadWrite ( ) | | ! isModified ( ) )
return true ;
bool Part : : closeUrl ( )
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 )
{
if ( promptToSave & & ! queryClose ( ) )
return false ;
setModified ( false ) ;
if ( ! m_temporaryLocalFile . isNull ( ) & & m_temporaryLocalFile ! = localFilePath ( ) )
{
QFile : : remove ( m_temporaryLocalFile ) ;
@ -1358,17 +1410,22 @@ bool Part::closeUrl()
# ifdef OKULAR_KEEP_FILE_OPEN
m_keeper - > close ( ) ;
# endif
bool r = KParts : : ReadOnly Part : : closeUrl ( ) ;
bool r = KParts : : ReadWrite Part : : closeUrl ( ) ;
setUrl ( KUrl ( ) ) ;
return r ;
}
bool Part : : closeUrl ( )
{
return closeUrl ( true ) ;
}
void Part : : guiActivateEvent ( KParts : : GUIActivateEvent * event )
{
updateViewActions ( ) ;
KParts : : ReadOnlyPart : : guiActivateEvent ( event ) ;
KParts : : ReadWrite Part : : guiActivateEvent ( event ) ;
}
void Part : : close ( )
@ -1473,7 +1530,12 @@ void Part::slotDoFileDirty()
}
// close and (try to) reopen the document
if ( KParts : : ReadOnlyPart : : openUrl ( url ( ) ) )
KUrl oldUrl = url ( ) ;
if ( ! closeUrl ( ) )
return ;
if ( KParts : : ReadWritePart : : openUrl ( oldUrl ) )
{
// on successful opening, restore the previous viewport
if ( m_viewportDirty . pageNumber > = ( int ) m_document - > pages ( ) )
@ -1864,6 +1926,11 @@ void Part::slotFindPrev()
m_findBar - > findPrev ( ) ;
}
bool Part : : saveFile ( )
{
kDebug ( ) < < " Okular part doesn't support saving the file in the location from which it was opened " ;
return false ;
}
void Part : : slotSaveFileAs ( )
{
@ -1876,12 +1943,17 @@ void Part::slotSaveFileAs()
if ( ! saveUrl . isValid ( ) | | saveUrl . isEmpty ( ) )
return ;
saveAs ( saveUrl ) ;
}
bool Part : : saveAs ( const KUrl & saveUrl )
{
KTemporaryFile tf ;
QString fileName ;
if ( ! tf . open ( ) )
{
KMessageBox : : information ( widget ( ) , i18n ( " Could not open the temporary file for saving. " ) ) ;
return ;
return false ;
}
fileName = tf . fileName ( ) ;
tf . close ( ) ;
@ -1897,12 +1969,18 @@ void Part::slotSaveFileAs()
{
KMessageBox : : information ( widget ( ) , i18n ( " File could not be saved in '%1'. %2 " , fileName , errorText ) ) ;
}
return ;
return false ;
}
KIO : : Job * copyJob = KIO : : file_copy ( fileName , saveUrl , - 1 , KIO : : Overwrite ) ;
if ( ! KIO : : NetAccess : : synchronousRun ( copyJob , widget ( ) ) )
{
KMessageBox : : information ( widget ( ) , i18n ( " File could not be saved in '%1'. Try to save it to another location. " , saveUrl . prettyUrl ( ) ) ) ;
return false ;
}
setModified ( false ) ;
return true ;
}
@ -2577,6 +2655,12 @@ void Part::updateAboutBackendAction()
}
}
void Part : : setReadWrite ( bool readwrite )
{
m_document - > setAnnotationEditingEnabled ( readwrite ) ;
ReadWritePart : : setReadWrite ( readwrite ) ;
}
} // namespace Okular
# include "part.moc"