summaryrefslogtreecommitdiffstats
path: root/kipi-plugins/gpssync/kmlexport.h
blob: 0dc32f25528b9c309d0b1715a7ba6820a6f7a661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* ============================================================
 *
 * This file is a part of kipi-plugins project
 * http://www.kipi-plugins.org
 *
 * Date        : 2006-05-16
 * Description : a tool to export GPS data to KML file.
 *
 * Copyright (C) 2006-2007 by Stephane Pontier <shadow dot walker at free dot fr>
 *
 * 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, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * ============================================================ */

#ifndef KIPIKMLEXPORTKMLEXPORT_H
#define KIPIKMLEXPORTKMLEXPORT_H

// Qt includes.

#include <qcolor.h>
#include <qdir.h>
#include <qdom.h>

// Local includes.

#include "kmlgpsdataparser.h"

class QImage;

namespace KIPI 
{
    class BatchProgressDialog;
    class Interface;
}

namespace KIPIGPSSyncPlugin 
{

/**
Exporter to KML

	@author KIPI dev. team
*/
class kmlExport
{

public:

    kmlExport(KIPI::Interface* interface);
    ~kmlExport();

    bool createDir(QDir dir);

    /*! generate the kml element for pictures with tumbnails
     *  @param interface the kipi interface
     *  @param KURL the URL of the picture
     *  @param kmlAlbum the album used
     */
    void generateImagesthumb(KIPI::Interface* interface, const KURL&, QDomElement &kmlAlbum);

    /*! Produce a web-friendly file name
     *  otherwise, while google earth works fine, maps.google.com may not find pictures and thumbnail
     *  thank htmlexport
     *  @param the filename
     *  @return the webifyed filename
     */
    QString webifyFileName(const QString &fileName);

    /*! Generate a square thumbnail from @fullImage of @size x @size pixels
     *  @param fullImage the original image
     *  @param size the size of the thumbnail
     *  @return the thumbnail
     */
    QImage generateSquareThumbnail(const QImage& fullImage, int size);

    /*! Generate a square thumbnail from @fullImage of @size x @size pixels
     *  with a white border
     *  @param fullImage the original image
     *  @param size the size of the thumbnail
     *  @return the thumbnail
     */
    QImage generateBorderedThumbnail(const QImage& fullImage, int size);
    void   addTrack(QDomElement &kmlAlbum);
    void   generate();
    int    getConfig();

public:

    bool             m_localTarget;
    bool             m_optimize_googlemap;
    bool             m_GPXtracks;

    int              m_iconSize;
    int              m_googlemapSize;
    int              m_size;
    int              m_altitudeMode;
    int              m_TimeZone;
    int              m_LineWidth;
    int              m_GPXOpacity;
    int              m_GPXAltitudeMode;

    /** directory used in kmldocument structure */
    QString          m_imageDir;
    QString          m_GPXFile;
    QString          m_UrlDestDir;

    /** temporary directory where everything will be created */
    QString          m_tempDestDir;

    /** directory selected by user*/
    QString          m_baseDestDir;

    QString          m_imgdir;
    QString          m_KMLFileName;

    QColor           m_GPXColor;

    KIPI::Interface *m_interface;

private:

    /*! the root document, used to create all QDomElements */
    QDomDocument              *kmlDocument;

    /*! the GPS parsed data */
    KMLGPSDataParser           m_gpxParser;

    KIPI::BatchProgressDialog *m_progressDialog;

private:

    void logInfo(const QString& msg);
    void logError(const QString& msg);
    void logWarning(const QString& msg);

    /*!
     *  \fn KIPIKMLExport::kmlExport::addKmlElement(QDomElement target, QString tag)
     *  Add a new element
     *  @param target the parent element to which add the element
     *  @param tag the new element name
     *  @return the New element
     */
    QDomElement addKmlElement(QDomElement &target, QString tag)
    {
        QDomElement kmlElement = kmlDocument->createElement( tag );
        target.appendChild( kmlElement );
        return kmlElement;
    }

    /*!
     *  \fn KIPIKMLExport::kmlExport::addKmlTextElement(QDomElement target, QString tag, QString text)
     *  Add a new element with a text
     *  @param target the parent element to which add the element
     *  @param tag the new element name
     *  @param text the text content of the new element
     *  @return the New element
     */
    QDomElement addKmlTextElement(QDomElement &target, QString tag, QString text)
    {
        QDomElement kmlElement  = kmlDocument->createElement( tag );
        target.appendChild( kmlElement );
        QDomText kmlTextElement = kmlDocument->createTextNode( text );
        kmlElement.appendChild( kmlTextElement );
        return kmlElement;
    }

    /*!
     *  \fn KIPIKMLExport::kmlExport::addKmlHtmlElement(QDomElement target, QString tag, QString text)
     *  Add a new element with html content (html entities are escaped and text is wrapped in a CDATA section)
     *  @param target the parent element to which add the element
     *  @param tag the new element name
     *  @param text the HTML content of the new element
     *  @return the New element
     */
    QDomElement addKmlHtmlElement(QDomElement &target, QString tag, QString text)
    {
        QDomElement kmlElement  = kmlDocument->createElement( tag );
        target.appendChild( kmlElement );
        QDomText kmlTextElement = kmlDocument->createCDATASection( text );
        kmlElement.appendChild( kmlTextElement );
        return kmlElement;
    }
};

} // namespace KIPIGPSSyncPlugin

#endif // KIPIKMLEXPORTKMLEXPORT_H