Commit 274d8301 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Compile WelcomeMode with QT_NO_CAST_FROM_ASCII.



- Add missing QLatin1String
- Replace QString::left() by QString::truncate()
- Sanitize eed model code

Change-Id: I3c3b71d8395b7019db662b8aaecf7d1647881a80
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@nokia.com>
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@nokia.com>
parent f5884383
......@@ -51,12 +51,24 @@ QString shortenHtml(QString html)
{
html.replace(QLatin1String("<a"), QLatin1String("<i"));
html.replace(QLatin1String("</a"), QLatin1String("</i"));
uint firstParaEndXhtml = (uint) html.indexOf(QLatin1String("</p>"));
uint firstParaEndHtml = (uint) html.indexOf(QLatin1String("<p>"), html.indexOf(QLatin1String("<p>"))+1);
uint firstParaEndBr = (uint) html.indexOf(QLatin1String("<br"));
uint firstParaEnd = qMin(firstParaEndXhtml, firstParaEndHtml);
firstParaEnd = qMin(firstParaEnd, firstParaEndBr);
return html.left(firstParaEnd);
int firstParaEnd = html.indexOf(QLatin1String("</p>")); // XHTML
if (firstParaEnd < 0) {
const QString paraStart = QLatin1String("<p>");
firstParaEnd = html.indexOf(paraStart);
if (firstParaEnd > 0)
firstParaEnd = html.indexOf(paraStart, firstParaEnd + paraStart.size());
}
const int firstParaEndBr = html.indexOf(QLatin1String("<br"));
int truncationPos = html.size();
if (firstParaEnd > 0 && firstParaEnd < truncationPos)
truncationPos = firstParaEnd;
if (firstParaEndBr > 0 && firstParaEndBr < truncationPos)
truncationPos = firstParaEndBr;
if (truncationPos < html.size())
html.truncate(truncationPos);
return html;
}
class RssReader {
......@@ -76,8 +88,10 @@ public:
else if (streamReader.name() == QLatin1String("pubDate")) {
QString dateStr = streamReader.readElementText();
// fixme: honor time zone!
dateStr = dateStr.left(dateStr.indexOf('+')-1);
item.pubDate = QDateTime::fromString(dateStr, "ddd, dd MMM yyyy HH:mm:ss");
const int plusPos = dateStr.indexOf(QLatin1Char('+'));
if (plusPos > 0)
dateStr.truncate(plusPos - 1);
item.pubDate = QDateTime::fromString(dateStr, QLatin1String("ddd, dd MMM yyyy HH:mm:ss"));
}
else if (streamReader.name() == QLatin1String("description"))
item.description = shortenHtml(streamReader.readElementText());
......
......@@ -190,16 +190,16 @@ bool sortFunction(Utils::IWelcomePage * a, Utils::IWelcomePage *b)
void WelcomeMode::facilitateQml(QDeclarativeEngine *engine)
{
static const char feedGroupName[] = "Feeds";
const QString feedGroupName = QLatin1String("Feeds");
MultiFeedRssModel *rssModel = new MultiFeedRssModel(this);
QSettings *settings = Core::ICore::instance()->settings();
if (settings->childGroups().contains(feedGroupName)) {
int size = settings->beginReadArray(feedGroupName);
for (int i = 0; i < size; ++i)
{
const QString url = QLatin1String("url");
for (int i = 0; i < size; ++i) {
settings->setArrayIndex(i);
rssModel->addFeed(settings->value("url").toString());
rssModel->addFeed(settings->value(url).toString());
}
settings->endArray();
} else {
......@@ -207,7 +207,7 @@ void WelcomeMode::facilitateQml(QDeclarativeEngine *engine)
rssModel->addFeed(QLatin1String("http://feeds.feedburner.com/TheQtBlog?format=xml"));
}
engine->rootContext()->setContextProperty("aggregatedFeedsModel", rssModel);
engine->rootContext()->setContextProperty(QLatin1String("aggregatedFeedsModel"), rssModel);
}
void WelcomeMode::initPlugins()
......@@ -216,7 +216,7 @@ void WelcomeMode::initPlugins()
setActivePlugin(settings->value(QLatin1String(currentPageSettingsKeyC)).toInt());
QDeclarativeContext *ctx = m_welcomePage->rootContext();
ctx->setContextProperty("welcomeMode", this);
ctx->setContextProperty(QLatin1String("welcomeMode"), this);
QList<Utils::IWelcomePage*> plugins = PluginManager::instance()->getObjects<Utils::IWelcomePage>();
qSort(plugins.begin(), plugins.end(), &sortFunction);
......@@ -238,11 +238,11 @@ void WelcomeMode::initPlugins()
m_pluginList.append(plugin);
}
ctx->setContextProperty("pagesModel", QVariant::fromValue(m_pluginList));
ctx->setContextProperty(QLatin1String("pagesModel"), QVariant::fromValue(m_pluginList));
// finally, load the root page
m_welcomePage->setSource(
QUrl::fromLocalFile(Core::ICore::instance()->resourcePath() + "/welcomescreen/welcomescreen.qml"));
QUrl::fromLocalFile(Core::ICore::instance()->resourcePath() + QLatin1String("/welcomescreen/welcomescreen.qml")));
}
QString WelcomeMode::platform() const
......@@ -273,7 +273,7 @@ void WelcomeMode::welcomePluginAdded(QObject *obj)
m_pluginList.insert(insertPos, plugin);
// update model through reset
QDeclarativeContext *ctx = m_welcomePage->rootContext();
ctx->setContextProperty("pagesModel", QVariant::fromValue(m_pluginList));
ctx->setContextProperty(QLatin1String("pagesModel"), QVariant::fromValue(m_pluginList));
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment