delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / workspace / plasma / dataengines / weather / ions / ion.cpp
blobe7912d48767839d7b23d29e4460cc7bfe3a0e436
1 /*****************************************************************************
2 * Copyright (C) 2007-2008 by Shawn Starr <shawn.starr@rogers.com> *
3 * *
4 * This library is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Library General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2 of the License, or (at your option) any later version. *
8 * *
9 * This library is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Library General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Library General Public License *
15 * along with this library; see the file COPYING.LIB. If not, write to *
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301, USA. *
18 *****************************************************************************/
20 #include "ion.h"
21 #include "ion.moc"
23 class IonInterface::Private : public QObject
25 public:
26 Private(IonInterface *i)
27 : ion(i),
28 initialized(false) {}
30 int ref;
31 IonInterface *ion;
32 bool initialized;
35 IonInterface::IonInterface(QObject *parent, const QVariantList &args)
36 : Plasma::DataEngine(parent, args),
37 d(new Private(this))
39 // Initialize the loaded ion with a reference count of 0.
40 d->ref = 0;
43 // Increment reference counter
44 void IonInterface::ref()
46 ++d->ref;
49 // Decrement reference counter
50 void IonInterface::deref()
52 --d->ref;
55 // Check if Ion is used
56 bool IonInterface::isUsed() const
58 return d->ref != 0;
61 /**
62 * If the ion is not initialized just set the initial data source up even if it's empty, we'll retry once the initialization is done
64 bool IonInterface::sourceRequestEvent(const QString &source)
66 kDebug() << "sourceRequested()";
67 if (d->initialized) {
68 return updateIonSource(source);
69 } else {
70 setData(source, Plasma::DataEngine::Data());
73 return true;
76 /**
77 * Update the ion's datasource. Triggered when a Plasma::DataEngine::connectSource() timeout occurs.
79 bool IonInterface::updateSourceEvent(const QString& source)
81 kDebug() << "updateSource()";
82 if (d->initialized) {
83 return updateIonSource(source);
86 return false;
89 /**
90 * Set the ion to make sure it is ready to get real data.
92 void IonInterface::setInitialized(bool initialized)
94 d->initialized = initialized;
96 if (d->initialized) {
97 foreach(const QString &source, sources()) {
98 updateSourceEvent(source);
104 * Return wind direction svg element to display in applet when given a wind direction.
106 QString IonInterface::getWindDirectionIcon(const QMap<QString, WindDirections> &windDirList, const QString& windDirection)
108 switch (windDirList[windDirection.toLower()]) {
109 case N:
110 return "N";
111 case NNE:
112 return "NNE";
113 case NE:
114 return "NE";
115 case ENE:
116 return "ENE";
117 case E:
118 return "E";
119 case SSE:
120 return "SSE";
121 case SE:
122 return "SE";
123 case ESE:
124 return "ESE";
125 case S:
126 return "S";
127 case NNW:
128 return "NNW";
129 case NW:
130 return "NW";
131 case WNW:
132 return "WNW";
133 case W:
134 return "W";
135 case SSW:
136 return "SSW";
137 case SW:
138 return "SW";
139 case WSW:
140 return "WSW";
141 case VR:
142 return "N/A"; // For now, we'll make a variable wind icon later on
145 // No icon available, use 'X'
146 return "N/A";
150 * Return weather icon to display in an applet when given a condition.
152 QString IonInterface::getWeatherIcon(const QMap<QString, ConditionIcons> &conditionList, const QString& condition)
154 switch (conditionList[condition.toLower()]) {
155 case ClearDay:
156 return "weather-clear";
157 case FewCloudsDay:
158 return "weather-few-clouds";
159 case PartlyCloudyDay:
160 return "weather-clouds";
161 case Overcast:
162 return "weather-many-clouds";
163 case Rain:
164 return "weather-showers";
165 case LightRain:
166 return "weather-showers-scattered";
167 case Showers:
168 return "weather-showers-scattered";
169 case ChanceShowersDay:
170 return "weather-showers-scattered-day";
171 case ChanceShowersNight:
172 return "weather-showers-scattered-night";
173 case ChanceSnowDay:
174 return "weather-snow-scattered-day";
175 case ChanceSnowNight:
176 return "weather-snow-scattered-night";
177 case Thunderstorm:
178 return "weather-storm";
179 case Hail:
180 return "weather-hail";
181 case Snow:
182 return "weather-snow";
183 case LightSnow:
184 return "weather-snow-scattered";
185 case Flurries:
186 return "weather-snow-scattered";
187 case RainSnow:
188 return "weather-snow-rain";
189 case FewCloudsNight:
190 return "weather-few-clouds-night";
191 case PartlyCloudyNight:
192 return "weather-clouds-night";
193 case ClearNight:
194 return "weather-clear-night";
195 case Mist:
196 return "weather-mist";
197 case Haze:
198 return "weather-mist";
199 case FreezingRain:
200 return "weather-freezing-rain";
201 case FreezingDrizzle:
202 return "weather-freezing-rain";
203 case ChanceThunderstormDay:
204 return "weather-scattered-storms-day";
205 case ChanceThunderstormNight:
206 return "weather-scattered-storms-night";
207 case NotAvailable:
208 return "weather-none-available";
210 return "weather-none-available";