summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2019-07-08 16:00:30 +0200
committerSimon Rettberg2019-07-08 16:00:30 +0200
commit4eb0886e94a130e631e5bf97b9a634847541b6a5 (patch)
tree01b3eee86a18fad3ab94a3147c9fe43556adb979 /src
parentGet rid of ImgType, use string directly (diff)
downloadvmchooser2-4eb0886e94a130e631e5bf97b9a634847541b6a5.tar.gz
vmchooser2-4eb0886e94a130e631e5bf97b9a634847541b6a5.tar.xz
vmchooser2-4eb0886e94a130e631e5bf97b9a634847541b6a5.zip
vsession.*: Use QStringLiteral for most C-Strings
Some things like searching feel a bit sluggish; try to get rid of repeated QString creation and destruction.
Diffstat (limited to 'src')
-rw-r--r--src/vsession.cpp66
-rw-r--r--src/vsession.h20
2 files changed, 43 insertions, 43 deletions
diff --git a/src/vsession.cpp b/src/vsession.cpp
index eae6ee9..41098b7 100644
--- a/src/vsession.cpp
+++ b/src/vsession.cpp
@@ -88,9 +88,9 @@ void VSession::addNodeWithAttribute(const QString& nodeName,
}
QIcon VSession::icon() const {
- QString icon(getAttribute("icon"));
+ QString icon(getAttribute(QStringLiteral("icon")));
SessionsIconHolder *iconHolder = SessionsIconHolder::get();
- if (icon.startsWith("http://") || icon.startsWith("https://")) {
+ if (icon.startsWith(QStringLiteral("http://")) || icon.startsWith(QStringLiteral("https://"))) {
// try to load icon from url
QIcon url_icon(iconHolder->getIcon(QUrl(icon)));
if (!url_icon.isNull())
@@ -103,7 +103,7 @@ QIcon VSession::icon() const {
return res_icon;
}
// Everything failed, try to guess the OS
- QString os(getAttribute("os", "param").toLower());
+ QString os(this->os().toLower());
os = os.replace(cleanNameRegex, QString());
if (!os.isEmpty()) {
// Now try known good OS names via .startsWith()
@@ -117,10 +117,10 @@ QIcon VSession::icon() const {
return iconHolder->getIcon(map.icon);
}
// Running out of ideas...
- if (os.startsWith("win"))
- return iconHolder->getIcon("windows");
- if (os.contains("linux"))
- return iconHolder->getIcon("linux");
+ if (os.startsWith(QStringLiteral("win")))
+ return iconHolder->getIcon(QStringLiteral("windows"));
+ if (os.contains(QStringLiteral("linux")))
+ return iconHolder->getIcon(QStringLiteral("linux"));
}
// Fallback to generic virtualizer icon (if found)
return iconHolder->getIcon(virtualizer());
@@ -132,16 +132,16 @@ QString VSession::toXml() const {
QDomNode xmlNode = doc.createProcessingInstruction(
"xml", "version=\"1.0\" encoding=\"UTF-8\"");
doc.insertBefore(xmlNode, doc.firstChild());
- QString image(this->getAttribute("image_name"));
- QDomElement path = doc.firstChildElement("settings")
- .firstChildElement("eintrag")
- .appendChild(doc.createElement("image_path"))
+ QString image(this->getAttribute(QStringLiteral("image_name")));
+ QDomElement path = doc.firstChildElement(QStringLiteral("settings"))
+ .firstChildElement(QStringLiteral("eintrag"))
+ .appendChild(doc.createElement(QStringLiteral("image_path")))
.toElement();
if (QFileInfo(image).isRelative()) {
// make path to image absolute
- path.setAttribute("param", Config::get(Config::BASEDIR) + "/" + image);
+ path.setAttribute(QStringLiteral("param"), Config::get(Config::BASEDIR) + "/" + image);
} else {
- path.setAttribute("param", image);
+ path.setAttribute(QStringLiteral("param"), image);
}
return doc.toString();
}
@@ -156,10 +156,10 @@ QList<QString> VSession::keywords() const {
}
void VSession::readKeywords() {
- QDomNode keywordsNode = eintrag_.namedItem("keywords");
- for (QDomElement el(keywordsNode.firstChildElement("keyword"));
+ QDomNode keywordsNode = eintrag_.namedItem(QStringLiteral("keywords"));
+ for (QDomElement el(keywordsNode.firstChildElement(QStringLiteral("keyword")));
!el.isNull();
- el = el.nextSiblingElement("keyword")) {
+ el = el.nextSiblingElement(QStringLiteral("keyword"))) {
this->keywords_.append(el.text());
}
}
@@ -168,7 +168,7 @@ bool VSession::containsKeywords(const QList<QString>& keywords) const {
for (int j = 0; j < keywords.length(); ++j) {
if (!this->shortDescription().contains(keywords[j], Qt::CaseInsensitive)
&& !this->description().contains(keywords[j], Qt::CaseInsensitive)
- && !this->getAttribute("creator", "param").contains(keywords[j], Qt::CaseInsensitive)) {
+ && !this->getAttribute(QStringLiteral("creator"), QStringLiteral("param")).contains(keywords[j], Qt::CaseInsensitive)) {
bool match = false;
for (int i = 0; i < this->keywords().length(); ++i) {
if (this->keywords()[i].contains(keywords[j], Qt::CaseInsensitive)) {
@@ -188,7 +188,7 @@ QString VSession::getNodeText(const QString& nodeName) const {
}
bool VSession::isActive() const {
- QString value(getAttribute("active"));
+ QString value(getAttribute(QStringLiteral("active")));
// Is disabled completely
if (value.compare("false") == 0) {
if (g_debugMode) qDebug() << "'" << shortDescription() << "' not active. Reason: active == false";
@@ -196,12 +196,12 @@ bool VSession::isActive() const {
}
// Filter by LDAP data
if (!UserLdapData::isEmpty()) {
- QDomElement el(eintrag_.namedItem("filters").firstChildElement("filter"));
+ QDomElement el(eintrag_.namedItem(QStringLiteral("filters")).firstChildElement(QStringLiteral("filter")));
if (!el.isNull()) {
- for (; !el.isNull(); el = el.nextSiblingElement("filter")) {
- if (el.attribute("type") != "LDAP")
+ for (; !el.isNull(); el = el.nextSiblingElement(QStringLiteral("filter"))) {
+ if (el.attribute(QStringLiteral("type")) != QStringLiteral("LDAP"))
continue;
- if (UserLdapData::isAllowed(el.firstChildElement("key").text(), el.firstChildElement("value").text()))
+ if (UserLdapData::isAllowed(el.firstChildElement(QStringLiteral("key")).text(), el.firstChildElement(QStringLiteral("value")).text()))
return true;
}
return false;
@@ -213,15 +213,15 @@ bool VSession::isActive() const {
bool VSession::isLocked() const {
// default to false
- return getAttribute("locked").compare("true") == 0;
+ return getAttribute(QStringLiteral("locked")).compare(QStringLiteral("true")) == 0;
}
bool VSession::isValid() const {
- return !getAttribute("image_name").isEmpty();
+ return !getAttribute(QStringLiteral("image_name")).isEmpty();
}
int VSession::priority() const {
- int prio = getAttribute("priority").toInt();
+ int prio = getAttribute(QStringLiteral("priority")).toInt();
if (g_templateHandling == TEMPLATES_BUMP && isTemplate()) {
prio -= 500;
}
@@ -237,7 +237,7 @@ bool VSession::run() const {
return false;
}
if (g_debugMode) {
- qDebug() << "Sarting session " << this->getAttribute("short_description", "param") << " ...";
+ qDebug() << "Sarting session " << shortDescription() << " ...";
}
if (g_noVtx && needsVtx()) {
@@ -248,13 +248,13 @@ bool VSession::run() const {
" error message while the virtualizer is initializing."));
}
- QString command = getAttribute("command");
+ QString command = getAttribute(QStringLiteral("command"));
if (!command.isEmpty()) {
return QProcess::startDetached(command);
}
// write xml to temporary file
- QTemporaryFile tmpfile(QDir::tempPath() + "/vmchooser-XXXXXX.xml");
+ QTemporaryFile tmpfile(QDir::tempPath() + QStringLiteral("/vmchooser-XXXXXX.xml"));
if (!tmpfile.open() ||
tmpfile.write(this->toXml().toUtf8()) == -1) {
qDebug() << "Error writing xml to file" << tmpfile.fileName();
@@ -335,10 +335,10 @@ QList<Session*> VSession::readXmlFile(const QString& filepath) {
UserLdapData::init();
- QDomElement settingsNode = doc.firstChildElement("settings");
- for (QDomElement el(settingsNode.firstChildElement("eintrag"));
+ QDomElement settingsNode = doc.firstChildElement(QStringLiteral("settings"));
+ for (QDomElement el(settingsNode.firstChildElement(QStringLiteral("eintrag")));
!el.isNull();
- el = el.nextSiblingElement("eintrag")) {
+ el = el.nextSiblingElement(QStringLiteral("eintrag"))) {
VSession* e = new VSession;
if (e->init(el) && e->isActive()) {
e->readKeywords();
@@ -352,8 +352,8 @@ QList<Session*> VSession::readXmlFile(const QString& filepath) {
bool VSession::needsVtx() const {
QString type = virtualizer();
- return (type == VMWARE && os().endsWith("-64"))
- || (type == VIRTUALBOX && os().endsWith("_64")); // Vbox 6.x DOES support 32bit VMs without VT-x, but if
+ return (type == VMWARE && os().endsWith(QStringLiteral("-64")))
+ || (type == VIRTUALBOX && os().endsWith(QStringLiteral("_64"))); // Vbox 6.x DOES support 32bit VMs without VT-x, but if
// the config enables any feature that cannot work without VT-x, it will silently enable it and then fail to start (i.e. IOAPIC)
// TODO: qemu-kvm, ...
}
diff --git a/src/vsession.h b/src/vsession.h
index ad81833..609884e 100644
--- a/src/vsession.h
+++ b/src/vsession.h
@@ -19,37 +19,37 @@ class VSession : public Session {
int priority() const;
bool isTemplate() const {
- return getAttribute("is_template").toInt() != 0;
+ return getAttribute(QStringLiteral("is_template")).toInt() != 0;
}
bool isForLocation() const {
- return getAttribute("for_location").toInt() != 0;
+ return getAttribute(QStringLiteral("for_location")).toInt() != 0;
}
bool canEdit() const {
- return getAttribute("allow_edit").toInt() != 0;
+ return getAttribute(QStringLiteral("allow_edit")).toInt() != 0;
}
QString virtualizer() const {
- return getAttribute(QLatin1String("virtualmachine"));
+ return getAttribute(QStringLiteral("virtualmachine"));
}
QString shortDescription() const {
- return getAttribute("short_description");
+ return getAttribute(QStringLiteral("short_description"));
}
QString description() const {
- return getAttribute("long_description");
+ return getAttribute(QStringLiteral("long_description"));
}
QIcon icon() const;
QString os() const {
- return getAttribute("os");
+ return getAttribute(QStringLiteral("os"));
}
QString uuid() const {
- return getAttribute("uuid");
+ return getAttribute(QStringLiteral("uuid"));
}
SectionType section() const {
@@ -66,14 +66,14 @@ class VSession : public Session {
QVariant foregroundRole() const;
QString getAttribute(const QString& nodeName,
- const QString& attribute = "param") const;
+ const QString& attribute = QStringLiteral("param")) const;
QList<QString> keywords() const;
bool containsKeywords(const QList<QString>& keywords) const;
QString getNodeText(const QString& nodeName) const;
void addNodeWithAttribute(const QString& nodeName,
const QString& value,
- const QString& attribute = "param",
+ const QString& attribute = QStringLiteral("param"),
bool replace = true);
QString toXml() const;