Welcome to mirror list, hosted at ThFree Co, Russian Federation.

updateinfo.cpp « updater « src - github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7554a0d1182787331280225360370100c8fe51f1 (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
// This file is generated by kxml_compiler from occinfo.xml.
// All changes you do to this file will be lost.

#include "updateinfo.h"

#include <QtDebug>
#include <QFile>
#include <QDomDocument>
#include <QtCore/QtDebug>
#include <QtCore/QFile>

namespace Mirall {

void UpdateInfo::setVersion( const QString &v )
{
  mVersion = v;
}

QString UpdateInfo::version() const
{
  return mVersion;
}

void UpdateInfo::setVersionString( const QString &v )
{
  mVersionString = v;
}

QString UpdateInfo::versionString() const
{
  return mVersionString;
}

void UpdateInfo::setWeb( const QString &v )
{
  mWeb = v;
}

QString UpdateInfo::web() const
{
  return mWeb;
}

void UpdateInfo::setDownloadUrl( const QString &v )
{
  mDownloadUrl = v;
}

QString UpdateInfo::downloadUrl() const
{
  return mDownloadUrl;
}

UpdateInfo UpdateInfo::parseElement( const QDomElement &element, bool *ok )
{
  if ( element.tagName() != QLatin1String("owncloudclient") ) {
    qCritical() << "Expected 'owncloudclient', got '" << element.tagName() << "'.";
    if ( ok ) *ok = false;
    return UpdateInfo();
  }

  UpdateInfo result = UpdateInfo();

  QDomNode n;
  for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
    QDomElement e = n.toElement();
    if ( e.tagName() == QLatin1String("version") ) {
      result.setVersion( e.text() );
    }
    else if ( e.tagName() == QLatin1String("versionstring") ) {
      result.setVersionString( e.text() );
    }
    else if ( e.tagName() == QLatin1String("web") ) {
      result.setWeb( e.text() );
    }
    else if ( e.tagName() == QLatin1String("downloadurl") ) {
        result.setDownloadUrl( e.text() );
    }
  }


  if ( ok ) *ok = true;
  return result;
}

void UpdateInfo::writeElement( QXmlStreamWriter &xml )
{
  xml.writeStartElement( QLatin1String("owncloudclient") );
  if ( !version().isEmpty() ) {
    xml.writeTextElement(  QLatin1String("version"), version() );
  }
  if ( !versionString().isEmpty() ) {
    xml.writeTextElement(  QLatin1String("versionstring"), versionString() );
  }
  if ( !web().isEmpty() ) {
    xml.writeTextElement(  QLatin1String("web"), web() );
  }
  if ( !downloadUrl().isEmpty() ) {
    xml.writeTextElement(  QLatin1String("downloadurl"), web() );
  }
  xml.writeEndElement();
}

UpdateInfo UpdateInfo::parseFile( const QString &filename, bool *ok )
{
  QFile file( filename );
  if ( !file.open( QIODevice::ReadOnly ) ) {
    qCritical() << "Unable to open file '" << filename << "'";
    if ( ok ) *ok = false;
    return UpdateInfo();
  }

  QString errorMsg;
  int errorLine, errorCol;
  QDomDocument doc;
  if ( !doc.setContent( &file, false, &errorMsg, &errorLine, &errorCol ) ) {
    qCritical() << errorMsg << " at " << errorLine << "," << errorCol;
    if ( ok ) *ok = false;
    return UpdateInfo();
  }

  bool documentOk;
  UpdateInfo c = parseElement( doc.documentElement(), &documentOk );
  if ( ok ) {
    *ok = documentOk;
  }
  return c;
}

UpdateInfo UpdateInfo::parseString( const QString &xml, bool *ok )
{
  QString errorMsg;
  int errorLine, errorCol;
  QDomDocument doc;
  if ( !doc.setContent( xml, false, &errorMsg, &errorLine, &errorCol ) ) {
    qCritical() << errorMsg << " at " << errorLine << "," << errorCol;
    if ( ok ) *ok = false;
    return UpdateInfo();
  }

  bool documentOk;
  UpdateInfo c = parseElement( doc.documentElement(), &documentOk );
  if ( ok ) {
    *ok = documentOk;
  }
  return c;
}

bool UpdateInfo::writeFile( const QString &filename )
{
  QFile file( filename );
  if ( !file.open( QIODevice::WriteOnly ) ) {
    qCritical() << "Unable to open file '" << filename << "'";
    return false;
  }

  QXmlStreamWriter xml( &file );
  xml.setAutoFormatting( true );
  xml.setAutoFormattingIndent( 2 );
  xml.writeStartDocument( QLatin1String("1.0") );
  writeElement( xml );
  xml.writeEndDocument();
  file.close();

  return true;
}

} // namespace Mirall