Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Joao Oliveira
Okular
Commits
fb6e5405
Commit
fb6e5405
authored
Jan 03, 2005
by
Albert Astals Cid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save and read the bookmarks to/from a file when opening/closing a document
svn path=/trunk/kdegraphics/kpdf/; revision=375083
parent
ad1cc07c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
10 deletions
+107
-10
TODO
TODO
+1
-1
core/document.cpp
core/document.cpp
+104
-9
core/document.h
core/document.h
+2
-0
No files found.
TODO
View file @
fb6e5405
...
...
@@ -7,7 +7,6 @@ Legend:
(*) - Some parts of this item are already done
In progress:
-> Dom for bookmarks and saving/loading document settings.
-> Fix threaded generation. It's.. crashy..
Urgent fixes and items to get ready before 3.4 (special high-priority list):
...
...
@@ -91,6 +90,7 @@ More items (first items will enter 'In progress list' first):
-> FIX: single page mode: add a little margin on pageview (top-bottom edges)
Done (newest features come first):
-> ADD: Save bookmarks into a file so you they get recovered when opening the same file again (Albert)
-> FIX: searchline back to work
-> CHG: DocumentInfo is now a DomTree and the properties dialog is dynamically generated (Tobias)
-> ADD: Presentation transitions are loaded from the pdf files as well as fullscreen state (Tobias)
...
...
core/document.cpp
View file @
fb6e5405
...
...
@@ -12,6 +12,7 @@
#include <qdir.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qtextstream.h>
#include <qvaluevector.h>
#include <qtimer.h>
#include <qmap.h>
...
...
@@ -23,6 +24,7 @@
#include <kuserprofile.h>
#include <kmimetype.h>
#include <krun.h>
#include <kstandarddirs.h>
// local includes
#include "document.h"
...
...
@@ -50,6 +52,9 @@ class KPDFDocumentPrivate
// memory check/free timer
QTimer
*
memCheckTimer
;
// bookmark saver timer
QTimer
*
saveBookmarksTimer
;
// observers related (note: won't delete oservers)
QMap
<
int
,
class
ObserverData
*
>
observers
;
};
...
...
@@ -76,6 +81,8 @@ KPDFDocument::KPDFDocument()
d
->
searchPage
=
-
1
;
d
->
memCheckTimer
=
new
QTimer
(
this
);
connect
(
d
->
memCheckTimer
,
SIGNAL
(
timeout
()
),
this
,
SLOT
(
slotCheckMemory
()
)
);
d
->
saveBookmarksTimer
=
new
QTimer
(
this
);
connect
(
d
->
memCheckTimer
,
SIGNAL
(
timeout
()
),
this
,
SLOT
(
saveDocumentInfo
()
)
);
}
KPDFDocument
::~
KPDFDocument
()
...
...
@@ -90,12 +97,12 @@ bool KPDFDocument::openDocument( const QString & docFile )
// docFile is always local so we can use QFile on it
QFile
fileReadTest
(
docFile
);
if
(
!
fileReadTest
.
open
(
IO_ReadOnly
)
)
{
documentFileName
=
QString
::
null
;
return
false
;
}
fileReadTest
.
close
();
// reset internal status and frees memory
closeDocument
();
// create the generator based on the file's mimetype
KMimeType
::
Ptr
mime
=
KMimeType
::
findByPath
(
docFile
);
QString
mimeName
=
mime
->
name
();
...
...
@@ -121,12 +128,10 @@ bool KPDFDocument::openDocument( const QString & docFile )
// start memory check timer
d
->
memCheckTimer
->
start
(
1000
);
// check local directory for an overlay xml
// TODO import overlay layers from XML
// QString fileName = docFile.contains('/') ? docFile.section('/', -1, -1) : docFile;
// fileName = "kpdf/" + QString::number(fileSize) + "." + fileName + ".xml";
// QString localFN = locateLocal( "data", fileName );
// kdDebug() << "Using '" << localFN << "' as overlay descriptor." << endl;
// start bookmark saver timer
d
->
memCheckTimer
->
start
(
5
*
60
*
1000
);
loadDocumentInfo
();
// filter pages, setup observers and set the first page as current
if
(
pages_vector
.
size
()
>
0
)
...
...
@@ -139,6 +144,8 @@ bool KPDFDocument::openDocument( const QString & docFile )
void
KPDFDocument
::
closeDocument
()
{
saveDocumentInfo
();
// stop memory check timer
d
->
memCheckTimer
->
stop
();
...
...
@@ -623,6 +630,54 @@ int KPDFDocument::mFreeMemory()
#endif
}
void
KPDFDocument
::
loadDocumentInfo
()
{
QFile
fileReadTest
(
documentFileName
);
fileReadTest
.
open
(
IO_ReadOnly
);
QString
fileName
=
documentFileName
.
contains
(
'/'
)
?
documentFileName
.
section
(
'/'
,
-
1
,
-
1
)
:
documentFileName
;
fileName
=
"kpdf/"
+
QString
::
number
(
fileReadTest
.
size
())
+
"."
+
fileName
+
".xml"
;
fileReadTest
.
close
();
QString
localFN
=
locateLocal
(
"data"
,
fileName
);
kdDebug
()
<<
"Using '"
<<
localFN
<<
"' as document info file."
<<
endl
;
QFile
infoFile
(
localFN
);
if
(
infoFile
.
exists
()
&&
infoFile
.
open
(
IO_ReadOnly
)
)
{
QDomDocument
doc
(
"documentInfo"
);
if
(
!
doc
.
setContent
(
&
infoFile
)
)
{
kdDebug
()
<<
"Could not set content"
<<
endl
;
infoFile
.
close
();
return
;
}
QDomElement
root
=
doc
.
documentElement
();
if
(
root
.
tagName
()
!=
"documentInfo"
)
return
;
QDomNode
bookMarkList
=
root
.
firstChild
();
if
(
bookMarkList
.
isElement
()
&&
bookMarkList
.
toElement
().
tagName
()
!=
"bookmarkList"
)
return
;
QDomNode
n
=
bookMarkList
.
firstChild
();
QDomElement
e
;
int
pageNumber
;
bool
ok
;
while
(
!
n
.
isNull
()
)
{
if
(
n
.
isElement
()
)
{
e
=
n
.
toElement
();
if
(
e
.
tagName
()
!=
"page"
)
return
;
pageNumber
=
e
.
text
().
toInt
(
&
ok
);
if
(
ok
)
toggleBookmark
(
pageNumber
);
}
n
=
n
.
nextSibling
();
}
}
infoFile
.
close
();
}
QString
KPDFDocument
::
giveAbsolutePath
(
const
QString
&
fileName
)
{
if
(
documentFileName
.
isEmpty
()
)
...
...
@@ -689,6 +744,46 @@ void KPDFDocument::unHilightPages()
}
void
KPDFDocument
::
saveDocumentInfo
()
const
{
if
(
documentFileName
.
isNull
())
return
;
QFile
fileReadTest
(
documentFileName
);
fileReadTest
.
open
(
IO_ReadOnly
);
QString
fileName
=
documentFileName
.
contains
(
'/'
)
?
documentFileName
.
section
(
'/'
,
-
1
,
-
1
)
:
documentFileName
;
fileName
=
"kpdf/"
+
QString
::
number
(
fileReadTest
.
size
())
+
"."
+
fileName
+
".xml"
;
fileReadTest
.
close
();
QString
localFN
=
locateLocal
(
"data"
,
fileName
);
kdDebug
()
<<
"Using '"
<<
localFN
<<
"' as document info file for saving."
<<
endl
;
QFile
infoFile
(
localFN
);
if
(
infoFile
.
open
(
IO_WriteOnly
|
IO_Truncate
)
)
{
QDomDocument
doc
(
"documentInfo"
);
QDomElement
root
=
doc
.
createElement
(
"documentInfo"
);
doc
.
appendChild
(
root
);
QDomElement
bookmarkList
=
doc
.
createElement
(
"bookmarkList"
);
root
.
appendChild
(
bookmarkList
);
for
(
uint
i
=
0
;
i
<
pages_vector
.
count
()
;
i
++
)
{
if
(
pages_vector
[
i
]
->
attributes
()
&
KPDFPage
::
Bookmark
)
{
QDomElement
page
=
doc
.
createElement
(
"page"
);
page
.
appendChild
(
doc
.
createTextNode
(
QString
::
number
(
i
)
)
);
bookmarkList
.
appendChild
(
page
);
}
}
QString
xml
=
doc
.
toString
();
QTextStream
os
(
&
infoFile
);
os
<<
xml
;
}
infoFile
.
close
();
}
void
KPDFDocument
::
slotCheckMemory
()
{
// perform the memory check for 'free mem dependant' profiles only
...
...
core/document.h
View file @
fb6e5405
...
...
@@ -86,6 +86,7 @@ class KPDFDocument : public QObject // only for a private slot..
int
mTotalMemory
();
int
mFreeMemory
();
// more private functions
void
loadDocumentInfo
();
QString
giveAbsolutePath
(
const
QString
&
fileName
);
bool
openRelativeFile
(
const
QString
&
fileName
);
void
processPageList
(
bool
documentChanged
);
...
...
@@ -97,6 +98,7 @@ class KPDFDocument : public QObject // only for a private slot..
class
KPDFDocumentPrivate
*
d
;
private
slots
:
void
saveDocumentInfo
()
const
;
void
slotCheckMemory
();
void
slotGeneratedContents
(
int
id
,
int
pageNumber
);
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment