updatechannel.cpp
1 //------------------------------------------------------------------------------
2 // updatechannel.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; 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_DARWIN)
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  for (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 UpdateChannel &UpdateChannel::operator=(const UpdateChannel &other)
89 {
90  channelName = other.channelName;
91  return *this;
92 }
93 
94 bool UpdateChannel::isNull() const
95 {
96  return this->channelName.isNull();
97 }
98 
99 QString UpdateChannel::name() const
100 {
101  assert(!isNull() && "UpdateChannel::name() on a null object");
102  return this->channelName;
103 }
104 
105 QString UpdateChannel::translatedDescription() const
106 {
107  assert(!isNull() && "UpdateChannel::translatedDescription() on a null object");
108  if (channelName == CHANNEL_BETA)
109  {
110  return UpdateChannelTr::tr(
111  "Beta versions have newer features but they "
112  "are untested. Releases on this update channel "
113  "are more often and are suggested for users "
114  "who want newest functionalities and minor bug fixes "
115  "as soon as they become implemented and available."
116  );
117  }
118  else if (channelName == CHANNEL_STABLE)
119  {
120  return UpdateChannelTr::tr(
121  "Stable versions are released rarely. They cover "
122  "many changes at once and these changes are more certain "
123  "to work correctly. Critical bug fixes are also provided "
124  "through this channel."
125  );
126  }
127  else
128  {
129  return channelName;
130  }
131 }
132 
133 QString UpdateChannel::translatedName() const
134 {
135  assert(!isNull() && "UpdateChannel::translatedName() on a null object");
136  if (channelName == CHANNEL_BETA)
137  {
138  return UpdateChannelTr::tr("Beta");
139  }
140  else if (channelName == CHANNEL_STABLE)
141  {
142  return UpdateChannelTr::tr("Stable");
143  }
144  else
145  {
146  return channelName;
147  }
148 }
149 
151 {
152  return QString("update-info_%1_%2.js").arg(UPDATE_PLATFORM).arg(channelName);
153 }