updatechannel.cpp
1 //------------------------------------------------------------------------------
2 // updatechannel.h
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2012 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "updatechannel.h"
24 
25 #include <cassert>
26 
27 #if defined(Q_OS_WIN32)
28 #define UPDATE_PLATFORM "win32"
29 #elif defined(Q_OS_MAC)
30 #define UPDATE_PLATFORM "macosx"
31 #else
32 #ifdef WITH_AUTOUPDATES
33 #error "No platform for updater!"
34 #else
35 #define UPDATE_PLATFORM "none"
36 #endif
37 #endif
38 
39 const QString CHANNEL_BETA = "beta";
40 const QString CHANNEL_STABLE = "stable";
41 
42 UpdateChannel::UpdateChannel(const QString& name)
43 {
44  this->channelName = name;
45 }
46 
48 {
49  this->channelName = other.channelName;
50 }
51 
52 QList<UpdateChannel> UpdateChannel::allChannels()
53 {
54  QList<UpdateChannel> list;
55  list << mkStable();
56  list << mkBeta();
57  return list;
58 }
59 
61 {
62  QList<UpdateChannel> channels = allChannels();
63  foreach (const UpdateChannel& channel, channels)
64  {
65  if (channel.name() == name)
66  {
67  return channel;
68  }
69  }
70  return UpdateChannel();
71 }
72 
74 {
75  return UpdateChannel(CHANNEL_BETA);
76 }
77 
79 {
80  return UpdateChannel(CHANNEL_STABLE);
81 }
82 
83 bool UpdateChannel::operator==(const UpdateChannel& other) const
84 {
85  return this->channelName == other.channelName;
86 }
87 
88 bool UpdateChannel::isNull() const
89 {
90  return this->channelName.isNull();
91 }
92 
93 QString UpdateChannel::name() const
94 {
95  assert(!isNull() && "UpdateChannel::name() on a null object");
96  return this->channelName;
97 }
98 
99 QString UpdateChannel::translatedDescription() const
100 {
101  assert(!isNull() && "UpdateChannel::translatedDescription() on a null object");
102  if (channelName == CHANNEL_BETA)
103  {
104  return UpdateChannelTr::tr(
105  "Beta versions have newer features but they "
106  "are untested. Releases on this update channel "
107  "are more often and are suggested for users "
108  "who want newest functionalities and minor bug fixes "
109  "as soon as they become implemented and available."
110  );
111  }
112  else if (channelName == CHANNEL_STABLE)
113  {
114  return UpdateChannelTr::tr(
115  "Stable versions are released rarely. They cover "
116  "many changes at once and these changes are more certain "
117  "to work correctly. Critical bug fixes are also provided "
118  "through this channel."
119  );
120  }
121  else
122  {
123  return channelName;
124  }
125 }
126 
127 QString UpdateChannel::translatedName() const
128 {
129  assert(!isNull() && "UpdateChannel::translatedName() on a null object");
130  if (channelName == CHANNEL_BETA)
131  {
132  return UpdateChannelTr::tr("Beta");
133  }
134  else if (channelName == CHANNEL_STABLE)
135  {
136  return UpdateChannelTr::tr("Stable");
137  }
138  else
139  {
140  return channelName;
141  }
142 }
143 
145 {
146  return QString("update-info_%1_%2.js").arg(UPDATE_PLATFORM).arg(channelName);
147 }
static UpdateChannel fromName(const QString &name)
Creates object from its internal name.
static QList< UpdateChannel > allChannels()
List of all available channels.
QString versionDataFileName() const
Full name of "update-info*.js" file for given channel and platform.
UpdateChannel()
Creates a null object.
Definition: updatechannel.h:77
static UpdateChannel mkStable()
Creates "stable" channel object.
static UpdateChannel mkBeta()
Creates "beta" channel object.