Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
2f0eaca0
Commit
2f0eaca0
authored
Aug 03, 2011
by
ivan.ilyin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added subset adaptor for cff import (stubs only for now)
parent
245999ac
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
311 additions
and
0 deletions
+311
-0
UBCFFSubsetAdaptor.cpp
src/adaptors/UBCFFSubsetAdaptor.cpp
+22
-0
UBCFFSubsetAdaptor.h
src/adaptors/UBCFFSubsetAdaptor.h
+27
-0
UBImportCFF.cpp
src/adaptors/UBImportCFF.cpp
+229
-0
UBImportCFF.h
src/adaptors/UBImportCFF.h
+30
-0
UBDocumentManager.cpp
src/core/UBDocumentManager.cpp
+3
-0
No files found.
src/adaptors/UBCFFSubsetAdaptor.cpp
0 → 100644
View file @
2f0eaca0
#include "UBCFFSubsetAdaptor.h"
#include "document/UBDocumentProxy.h"
UBCFFSubsetAdaptor
::
UBCFFSubsetAdaptor
()
{
}
void
UBCFFSubsetAdaptor
::
ConvertCFFFileToUbz
(
QString
&
cffSourceFolder
,
QString
&
destinationFolder
)
{
//TODO create document proxy for destination file
// create document proxy with destination folder
// fill document proxy metadata
// create persistance manager to save data using proxy
// create UBCFFSubsetReader and make it parse cffSourceFolder
}
UBCFFSubsetAdaptor
::
UBCFFSubsetReader
::
UBCFFSubsetReader
(
UBDocumentProxy
*
proxy
)
:
mReader
(),
mProxy
(
proxy
)
{
//TODO parse
}
src/adaptors/UBCFFSubsetAdaptor.h
0 → 100644
View file @
2f0eaca0
#ifndef UBCFFSUBSETADAPTOR_H
#define UBCFFSUBSETADAPTOR_H
#include <QtXml>
#include <QString>
class
UBDocumentProxy
;
class
UBCFFSubsetAdaptor
{
public
:
UBCFFSubsetAdaptor
();
static
void
ConvertCFFFileToUbz
(
QString
&
cffSourceFolder
,
QString
&
destinationFolder
);
private
:
class
UBCFFSubsetReader
{
public
:
UBCFFSubsetReader
(
UBDocumentProxy
*
proxy
);
QXmlStreamReader
mReader
;
UBDocumentProxy
*
mProxy
;
};
};
#endif // UBCFFSUBSETADAPTOR_H
src/adaptors/UBImportCFF.cpp
0 → 100644
View file @
2f0eaca0
#include <QDir>
#include "UBImportCFF.h"
#include "document/UBDocumentProxy.h"
#include "core/UBApplication.h"
#include "core/UBPersistenceManager.h"
#include "core/UBDocumentManager.h"
#include "domain/UBGraphicsPDFItem.h"
#include "pdf/PDFRenderer.h"
#include "core/memcheck.h"
#include "core/UBPersistenceManager.h"
#include "UBCFFSubsetAdaptor.h"
#include "quazip.h"
#include "quazipfile.h"
#include "quazipfileinfo.h"
UBImportCFF
::
UBImportCFF
(
QObject
*
parent
)
:
UBImportAdaptor
(
parent
)
{
// NOOP
}
UBImportCFF
::~
UBImportCFF
()
{
// NOOP
}
QStringList
UBImportCFF
::
supportedExtentions
()
{
return
QStringList
(
"iwb"
);
}
QString
UBImportCFF
::
importFileFilter
()
{
QString
filter
=
tr
(
"Common File Format ("
);
QStringList
formats
=
supportedExtentions
();
bool
isFirst
=
true
;
foreach
(
QString
format
,
formats
)
{
if
(
isFirst
)
isFirst
=
false
;
else
filter
.
append
(
" "
);
filter
.
append
(
"*."
+
format
);
}
filter
.
append
(
")"
);
return
filter
;
}
bool
UBImportCFF
::
addFileToDocument
(
UBDocumentProxy
*
pDocument
,
const
QFile
&
pFile
)
{
//TODO add cff file import here
/* int res = UBDocumentManager::documentManager()->addImageAsPageToDocument(QStringList(QFileInfo(pFile).absoluteFilePath()), pDocument);
if (res == 0)
{
UBApplication::showMessage(tr("Image import failed."));
return false;
}
else
{
UBApplication::showMessage(tr("Image import successful."));
return true;
}*/
return
true
;
}
QString
UBImportCFF
::
expandFileToDir
(
const
QFile
&
pZipFile
,
const
QString
&
pDir
)
{
QDir
rootDir
(
pDir
);
QuaZip
zip
(
pZipFile
.
fileName
());
if
(
!
zip
.
open
(
QuaZip
::
mdUnzip
))
{
qWarning
()
<<
"Import failed. Cause zip.open(): "
<<
zip
.
getZipError
();
return
""
;
}
zip
.
setFileNameCodec
(
"UTF-8"
);
QuaZipFileInfo
info
;
QuaZipFile
file
(
&
zip
);
// TODO UB 4.x implement a mechanism that can replace an existing
// document based on the UID of the document.
bool
createNewDocument
=
true
;
QString
documentRootFolder
;
// first we search the metadata.rdf to check the document properties
for
(
bool
more
=
zip
.
goToFirstFile
();
more
;
more
=
zip
.
goToNextFile
())
{
if
(
!
zip
.
getCurrentFileInfo
(
&
info
))
{
qWarning
()
<<
"Import failed. Cause: getCurrentFileInfo(): "
<<
zip
.
getZipError
();
return
""
;
}
QFileInfo
currentFileInfo
(
pDir
+
"/"
+
file
.
getActualFileName
());
}
if
(
createNewDocument
)
documentRootFolder
=
UBPersistenceManager
::
persistenceManager
()
->
generateUniqueDocumentPath
();
QFile
out
;
char
c
;
for
(
bool
more
=
zip
.
goToFirstFile
();
more
;
more
=
zip
.
goToNextFile
())
{
if
(
!
zip
.
getCurrentFileInfo
(
&
info
))
{
//TOD UB 4.3 O display error to user or use crash reporter
qWarning
()
<<
"Import failed. Cause: getCurrentFileInfo(): "
<<
zip
.
getZipError
();
return
""
;
}
if
(
!
file
.
open
(
QIODevice
::
ReadOnly
))
{
qWarning
()
<<
"Import failed. Cause: file.open(): "
<<
zip
.
getZipError
();
return
""
;
}
if
(
file
.
getZipError
()
!=
UNZ_OK
)
{
qWarning
()
<<
"Import failed. Cause: file.getFileName(): "
<<
zip
.
getZipError
();
return
""
;
}
QString
newFileName
=
documentRootFolder
+
"/"
+
file
.
getActualFileName
();
QFileInfo
newFileInfo
(
newFileName
);
rootDir
.
mkpath
(
newFileInfo
.
absolutePath
());
out
.
setFileName
(
newFileName
);
out
.
open
(
QIODevice
::
WriteOnly
);
// Slow like hell (on GNU/Linux at least), but it is not my fault.
// Not ZIP/UNZIP package's fault either.
// The slowest thing here is out.putChar(c).
QByteArray
outFileContent
=
file
.
readAll
();
if
(
out
.
write
(
outFileContent
)
==
-
1
)
{
qWarning
()
<<
"Import failed. Cause: Unable to write file"
;
out
.
close
();
return
""
;
}
while
(
file
.
getChar
(
&
c
))
out
.
putChar
(
c
);
out
.
close
();
if
(
file
.
getZipError
()
!=
UNZ_OK
)
{
qWarning
()
<<
"Import failed. Cause: "
<<
zip
.
getZipError
();
return
""
;
}
if
(
!
file
.
atEnd
())
{
qWarning
()
<<
"Import failed. Cause: read all but not EOF"
;
return
""
;
}
file
.
close
();
if
(
file
.
getZipError
()
!=
UNZ_OK
)
{
qWarning
()
<<
"Import failed. Cause: file.close(): "
<<
file
.
getZipError
();
return
""
;
}
}
zip
.
close
();
if
(
zip
.
getZipError
()
!=
UNZ_OK
)
{
qWarning
()
<<
"Import failed. Cause: zip.close(): "
<<
zip
.
getZipError
();
return
""
;
}
return
documentRootFolder
;
}
UBDocumentProxy
*
UBImportCFF
::
importFile
(
const
QFile
&
pFile
,
const
QString
&
pGroup
)
{
Q_UNUSED
(
pGroup
);
// group is defined in the imported file
QFileInfo
fi
(
pFile
);
UBApplication
::
showMessage
(
tr
(
"Importing file %1..."
).
arg
(
fi
.
baseName
()),
true
);
// first unzip the file to the correct place
//TODO create temporary path for iwb file content
QString
path
=
QDir
::
tempPath
();
QString
documentRootFolder
=
expandFileToDir
(
pFile
,
path
);
if
(
documentRootFolder
.
isEmpty
())
documentRootFolder
=
pFile
.
fileName
();
else
documentRootFolder
=
path
.
append
(
"
\\
content.xml"
);
if
(
!
documentRootFolder
.
length
()){
UBApplication
::
showMessage
(
tr
(
"Import of file %1 failed."
).
arg
(
fi
.
baseName
()));
return
0
;
}
else
{
//TODO convert expanded CFF file content to ubz destination folder
QString
temporaryFolder
=
QDir
::
tempPath
();
UBCFFSubsetAdaptor
::
ConvertCFFFileToUbz
(
documentRootFolder
,
temporaryFolder
);
// create document proxy for destination folder and return
UBDocumentProxy
*
newDocument
=
UBPersistenceManager
::
persistenceManager
()
->
createDocumentFromDir
(
temporaryFolder
);
UBApplication
::
showMessage
(
tr
(
"Import successful."
));
return
newDocument
;
}
}
src/adaptors/UBImportCFF.h
0 → 100644
View file @
2f0eaca0
#ifndef UBIMPORTCFF_H
#define UBIMPORTCFF_H
#include <QtGui>
#include "UBImportAdaptor.h"
class
UBDocumentProxy
;
class
UBImportCFF
:
public
UBImportAdaptor
{
Q_OBJECT
;
public
:
UBImportCFF
(
QObject
*
parent
=
0
);
virtual
~
UBImportCFF
();
virtual
QStringList
supportedExtentions
();
virtual
QString
importFileFilter
();
virtual
bool
addFileToDocument
(
UBDocumentProxy
*
pDocument
,
const
QFile
&
pFile
);
//base class method override
virtual
UBDocumentProxy
*
importFile
(
const
QFile
&
pFile
,
const
QString
&
pGroup
);
private
:
virtual
QString
expandFileToDir
(
const
QFile
&
pZipFile
,
const
QString
&
pDir
);
};
#endif // UBIMPORTCFF_H
src/core/UBDocumentManager.cpp
View file @
2f0eaca0
...
...
@@ -17,6 +17,7 @@
#include "adaptors/UBImportDocument.h"
#include "adaptors/UBImportPDF.h"
#include "adaptors/UBImportImage.h"
#include "adaptors/UBImportCFF.h"
#include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsSvgItem.h"
...
...
@@ -67,6 +68,8 @@ UBDocumentManager::UBDocumentManager(QObject *parent)
mImportAdaptors
.
append
(
pdfImport
);
UBImportImage
*
imageImport
=
new
UBImportImage
(
this
);
mImportAdaptors
.
append
(
imageImport
);
UBImportCFF
*
cffImport
=
new
UBImportCFF
(
this
);
mImportAdaptors
.
append
(
cffImport
);
}
...
...
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