From ec0dcf024f29f1322dd598c5fd8f4b573f9fe533 Mon Sep 17 00:00:00 2001 From: Flavio Date: Thu, 10 Jan 2013 14:52:43 +0100 Subject: [PATCH] QLatin1String --- src/main.cpp | 14 ++++---- src/qtsingleapplication/qtlocalpeer.cpp | 2 +- src/updatechecker.cpp | 4 +-- src/utils.cpp | 2 +- src/video.cpp | 2 +- src/video.h | 6 +++- src/videomimedata.cpp | 2 +- src/ytcategories.cpp | 4 +-- src/ytfeedreader.cpp | 43 +++++++++++++------------ src/ytsuggester.cpp | 2 +- 10 files changed, 43 insertions(+), 38 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3804183..399e6f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -65,17 +65,17 @@ int main(int argc, char **argv) { #endif QtSingleApplication app(argc, argv); - QString message = app.arguments().size() > 1 ? app.arguments().at(1) : ""; - if (message == "--help") { + QString message = app.arguments().size() > 1 ? app.arguments().at(1) : QString(); + if (message == QLatin1String("--help")) { MainWindow::printHelp(); return 0; } if (app.sendMessage(message)) return 0; - app.setApplicationName(Constants::NAME); - app.setOrganizationName(Constants::ORG_NAME); - app.setOrganizationDomain(Constants::ORG_DOMAIN); + app.setApplicationName(QLatin1String(Constants::NAME)); + app.setOrganizationName(QLatin1String(Constants::ORG_NAME)); + app.setOrganizationDomain(QLatin1String(Constants::ORG_DOMAIN)); app.setWheelScrollLines(1); app.setAttribute(Qt::AA_DontShowIconsInMenus); @@ -149,11 +149,11 @@ int main(int argc, char **argv) { app.setActivationWindow(&mainWin, true); // all string literals are UTF-8 - QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); + // QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); if (app.arguments().size() > 1) { QString query = app.arguments().at(1); - if (query.startsWith("--")) { + if (query.startsWith(QLatin1String("--"))) { mainWin.messageReceived(query); return 0; } else { diff --git a/src/qtsingleapplication/qtlocalpeer.cpp b/src/qtsingleapplication/qtlocalpeer.cpp index e7db47d..7e968df 100644 --- a/src/qtsingleapplication/qtlocalpeer.cpp +++ b/src/qtsingleapplication/qtlocalpeer.cpp @@ -84,7 +84,7 @@ QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId) #endif prefix = id.section(QLatin1Char('/'), -1); } - prefix.remove(QRegExp("[^a-zA-Z]")); + prefix.remove(QRegExp(QLatin1String("[^a-zA-Z]"))); prefix.truncate(6); QByteArray idc = id.toUtf8(); diff --git a/src/updatechecker.cpp b/src/updatechecker.cpp index c98a836..fc794d3 100644 --- a/src/updatechecker.cpp +++ b/src/updatechecker.cpp @@ -57,10 +57,10 @@ bool UpdateCheckerStreamReader::read(QByteArray data) { while (!atEnd()) { readNext(); if (isStartElement()) { - if (name() == "release") { + if (name() == QLatin1String("release")) { while (!atEnd()) { readNext(); - if (isStartElement() && name() == "version") { + if (isStartElement() && name() == QLatin1String("version")) { QString remoteVersion = readElementText(); qDebug() << remoteVersion << QString(Constants::VERSION); m_needUpdate = remoteVersion != QString(Constants::VERSION); diff --git a/src/utils.cpp b/src/utils.cpp index 3973a6b..01b03b3 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -14,7 +14,7 @@ QIcon getIcon(const QString &name) { QIcon Utils::icon(const QString &name) { #ifdef Q_WS_X11 QString themeName = qApp->property("style").toString(); - if (themeName == "Ambiance") + if (themeName == QLatin1String("Ambiance")) return icon(QStringList() << name + "-symbolic" << name); else return getIcon(name); #else diff --git a/src/video.cpp b/src/video.cpp index 9cb9017..bedfee9 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -98,7 +98,7 @@ void Video::getVideoInfo() { // Get Video Token QUrl videoInfoUrl = QUrl(QString( - "http://www.youtube.com/get_video_info?video_id=%1%2&ps=default&eurl=&gl=US&hl=en" + "https://www.youtube.com/get_video_info?video_id=%1%2&ps=default&eurl=&gl=US&hl=en" ).arg(videoId, elTypes.at(elIndex))); QObject *reply = The::http()->get(videoInfoUrl); diff --git a/src/video.h b/src/video.h index 7fd1cb9..f5b7574 100644 --- a/src/video.h +++ b/src/video.h @@ -52,7 +52,11 @@ public: void loadStreamUrl(); QUrl getStreamUrl() { return m_streamUrl; } - QString id() { return videoId; } + QString id() const { return videoId; } + + bool operator==(const Video &other) const { + return videoId == other.id(); + } signals: void gotThumbnail(); diff --git a/src/videomimedata.cpp b/src/videomimedata.cpp index 38998f2..619c7d1 100644 --- a/src/videomimedata.cpp +++ b/src/videomimedata.cpp @@ -9,5 +9,5 @@ QStringList VideoMimeData::formats() const { } bool VideoMimeData::hasFormat( const QString &mimeType ) const { - return mimeType == "application/x-minitube-video"; + return mimeType == QLatin1String("application/x-minitube-video"); } diff --git a/src/ytcategories.cpp b/src/ytcategories.cpp index 2e5bab4..92e2dbc 100644 --- a/src/ytcategories.cpp +++ b/src/ytcategories.cpp @@ -25,11 +25,11 @@ void YTCategories::parseCategories(QByteArray bytes) { QXmlStreamReader xml(bytes); while (!xml.atEnd()) { xml.readNext(); - if (xml.isStartElement() && xml.name() == "category") { + if (xml.isStartElement() && xml.name() == QLatin1String("category")) { QString term = xml.attributes().value("term").toString(); QString label = xml.attributes().value("label").toString(); while(xml.readNextStartElement()) - if (xml.name() == "assignable") { + if (xml.name() == QLatin1String("assignable")) { YTCategory category; category.term = term; category.label = label; diff --git a/src/ytfeedreader.cpp b/src/ytfeedreader.cpp index 342e9eb..2551d84 100644 --- a/src/ytfeedreader.cpp +++ b/src/ytfeedreader.cpp @@ -4,11 +4,11 @@ YTFeedReader::YTFeedReader(const QByteArray &bytes) : QXmlStreamReader(bytes) { while (!atEnd()) { readNext(); - if (isStartElement() && name() == "entry") { + if (isStartElement() && name() == QLatin1String("entry")) { readEntry(); - } else if (name() == "link" + } else if (name() == QLatin1String("link") && attributes().value("rel").toString() - == "http://schemas.google.com/g/2006#spellcorrection") { + == QLatin1String("http://schemas.google.com/g/2006#spellcorrection")) { suggestions << attributes().value("title").toString(); } } @@ -27,62 +27,63 @@ void YTFeedReader::readEntry() { qDebug() << attribute.name() << ":" << attribute.value(); */ - if (isEndElement() && name() == "entry") break; + if (isEndElement() && name() == QLatin1String("entry")) break; if (isStartElement()) { - if (name() == "link" - && attributes().value("rel").toString() == "alternate" - && attributes().value("type").toString() == "text/html" + if (name() == QLatin1String("link") + && attributes().value("rel").toString() == QLatin1String("alternate") + && attributes().value("type").toString() == QLatin1String("text/html") ) { QString webpage = attributes().value("href").toString(); webpage.remove("&feature=youtube_gdata"); video->setWebpage(QUrl(webpage)); - } else if (name() == "author") { + } else if (name() == QLatin1String("author")) { while(readNextStartElement()) - if (name() == "name") { + if (name() == QLatin1String("name")) { QString author = readElementText(); video->setAuthor(author); - } else if (name() == "uri") { + } else if (name() == QLatin1String("uri")) { QString uri = readElementText(); int i = uri.lastIndexOf('/'); if (i != -1) uri = uri.mid(i+1); video->setAuthorUri(uri); } else skipCurrentElement(); - } else if (name() == "published") { + } else if (name() == QLatin1String("published")) { video->setPublished(QDateTime::fromString(readElementText(), Qt::ISODate)); - } else if (namespaceUri() == "http://gdata.youtube.com/schemas/2007" - && name() == "statistics") { + } else if (namespaceUri() == QLatin1String("http://gdata.youtube.com/schemas/2007") + && name() == QLatin1String("statistics")) { QString viewCount = attributes().value("viewCount").toString(); video->setViewCount(viewCount.toInt()); } - else if (namespaceUri() == "http://search.yahoo.com/mrss/" && name() == "group") { + else if (namespaceUri() == QLatin1String("http://search.yahoo.com/mrss/") + && name() == QLatin1String("group")) { // read media group while (!atEnd()) { readNext(); - if (isEndElement() && name() == "group") break; + if (isEndElement() && name() == QLatin1String("group")) break; if (isStartElement()) { - if (name() == "thumbnail") { + if (name() == QLatin1String("thumbnail")) { // qDebug() << "Thumb: " << attributes().value("url").toString(); QStringRef name = attributes().value("yt:name"); - if (name == "default") + if (name == QLatin1String("default")) video->setThumbnailUrl( attributes().value("url").toString()); - else if (name == "hqdefault") + else if (name == QLatin1String("hqdefault")) video->setMediumThumbnailUrl( attributes().value("url").toString()); } - else if (name() == "title") { + else if (name() == QLatin1String("title")) { QString title = readElementText(); // qDebug() << "Title: " << title; video->setTitle(title); } - else if (name() == "description") { + else if (name() == QLatin1String("description")) { QString desc = readElementText(); // qDebug() << "Description: " << desc; video->setDescription(desc); } - else if (name() == "duration") { + else if (name() == QLatin1String("duration")) { QString duration = attributes().value("seconds").toString(); // qDebug() << "Duration: " << duration; video->setDuration(duration.toInt()); diff --git a/src/ytsuggester.cpp b/src/ytsuggester.cpp index 6d1226e..b0693d8 100644 --- a/src/ytsuggester.cpp +++ b/src/ytsuggester.cpp @@ -39,7 +39,7 @@ void YTSuggester::handleNetworkData(QByteArray response) { while (!xml.atEnd()) { xml.readNext(); if (xml.tokenType() == QXmlStreamReader::StartElement) { - if (xml.name() == "suggestion") { + if (xml.name() == QLatin1String("suggestion")) { QStringRef str = xml.attributes().value("data"); choices << str.toString(); } -- 2.39.5