~renatofilho/ubuntu-docviewer-app/no-file-hint

« back to all changes in this revision

Viewing changes to src/plugin/libreofficetoolkit-qml-plugin/lodocument.cpp

  • Committer: Stefano Verzegnassi
  • Date: 2015-11-22 17:28:09 UTC
  • mfrom: (202 lo-viewer)
  • mto: This revision was merged to the branch mainline in revision 207.
  • Revision ID: stefano92.100@gmail.com-20151122172809-ozk6xf1q0ef7tl2x
Merged 'reboot' - Fixed conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include <LibreOfficeKit/LibreOfficeKitInit.h>
27
27
#include <LibreOfficeKit/LibreOfficeKit.hxx>
28
28
 
29
 
// TODO: Error management
30
 
 
31
29
#ifdef DEBUG_TILE_BENCHMARK
32
30
#include <QElapsedTimer>
33
31
#endif
37
35
LODocument::LODocument()
38
36
  : m_path("")
39
37
  , m_currentPart(-1)
 
38
  , m_error(LibreOfficeError::NoError)
40
39
  , m_document(nullptr)
41
40
{
42
41
    // This space is intentionally empty.
58
57
    Q_EMIT pathChanged();
59
58
 
60
59
    // Load the new document
61
 
    this->loadDocument(m_path);
 
60
    loadDocument(m_path);
62
61
}
63
62
 
64
63
int LODocument::currentPart() {
78
77
}
79
78
 
80
79
// Load the document
81
 
bool LODocument::loadDocument(const QString &pathName)
 
80
void LODocument::loadDocument(const QString &pathName)
82
81
{
83
82
    qDebug() << "Loading document...";
 
83
    setError(LibreOfficeError::NoError);
84
84
 
85
85
    if (pathName.isEmpty()) {
86
86
        qDebug() << "Can't load the document, path is empty.";
87
 
        return false;
88
 
    }
89
 
 
 
87
        return;
 
88
    }
 
89
 
 
90
 
 
91
    /* Get LibreOffice path */
 
92
    const char* loPath = Config::getLibreOfficePath();
 
93
 
 
94
    if (loPath == NULL) {
 
95
        setError(LibreOfficeError::LibreOfficeNotFound);
 
96
        return;
 
97
    }
 
98
 
 
99
 
 
100
    /* Load LibreOffice */
90
101
    if (!s_office)
91
 
        s_office = lok::lok_cpp_init(Config::getLibreOfficePath(),
92
 
                                     Config::getLibreOfficeProfilePath());
93
 
 
 
102
        s_office = lok::lok_cpp_init(loPath, Config::getLibreOfficeProfilePath());
 
103
 
 
104
    if (s_office == NULL) {
 
105
        setError(LibreOfficeError::LibreOfficeNotInitialized);
 
106
        qDebug() << "[lok-qml]: LibreOffice not initialized.";
 
107
        return;
 
108
    }
 
109
 
 
110
 
 
111
    /* Load the document */
94
112
    m_document = s_office->documentLoad(m_path.toUtf8().constData());
95
113
 
 
114
    if (m_document == NULL) {
 
115
        setError(LibreOfficeError::DocumentNotLoaded);
 
116
        qDebug() << "[lok-qml]: Document not loaded.";
 
117
        return;
 
118
    }
 
119
 
 
120
 
 
121
    /* Do the further initialization */
96
122
    m_docType = DocumentType(m_document->getDocumentType());
97
123
    Q_EMIT documentTypeChanged();
98
124
 
101
127
    m_document->initializeForRendering();
102
128
    qDebug() << "Document loaded successfully !";
103
129
 
104
 
    return true;
 
130
    return;
 
131
}
 
132
 
 
133
void LODocument::setError(const LibreOfficeError::Error &error)
 
134
{
 
135
    if (m_error == error)
 
136
        return;
 
137
 
 
138
    m_error = error;
 
139
    Q_EMIT errorChanged();
105
140
}
106
141
 
107
142
// Return the type of the loaded document (e.g. text document,
210
245
 
211
246
    return QString::fromUtf8(m_document->getPartName(index));
212
247
}
213
 
 
 
248
 
 
249
LibreOfficeError::Error LODocument::error() const
 
250
{
 
251
    return m_error;
 
252
}
 
253
 
214
254
// TODO: Is there some documentation on safe formats or filterOptions that can
215
255
// be used?
216
256
bool LODocument::saveAs(QString url, QString format = QString(), QString filterOptions = QString())