From ee2f583acd425a9f35187c4eb17cbf1b993b4f36 Mon Sep 17 00:00:00 2001 From: Alfredo Ramos Date: Tue, 23 Oct 2018 18:04:42 -0500 Subject: [PATCH] Fix some issues detected by Clazy (#384) * Fix old style connect * Fix unneeded QString memory allocations --- src/cli/commandlineparser.cpp | 28 ++-- src/cli/commandoption.cpp | 2 +- src/config/geneneralconf.cpp | 2 +- src/config/uicoloreditor.cpp | 4 +- src/config/visualseditor.cpp | 4 +- src/core/capturerequest.h | 2 +- src/core/controller.cpp | 2 +- src/core/controller.h | 2 +- src/main.cpp | 138 +++++++++--------- .../singleapplication/singleapplication.cpp | 2 +- src/tools/arrow/arrowtool.cpp | 2 +- src/tools/blur/blurtool.cpp | 2 +- src/tools/circle/circletool.cpp | 2 +- src/tools/copy/copytool.cpp | 2 +- src/tools/exit/exittool.cpp | 2 +- src/tools/imgur/imguruploader.cpp | 16 +- src/tools/imgur/imguruploadertool.cpp | 2 +- src/tools/launcher/applaunchertool.cpp | 2 +- src/tools/launcher/applauncherwidget.cpp | 10 +- src/tools/line/linetool.cpp | 2 +- src/tools/marker/markertool.cpp | 2 +- src/tools/move/movetool.cpp | 2 +- src/tools/pencil/penciltool.cpp | 2 +- src/tools/pin/pintool.cpp | 2 +- src/tools/rectangle/rectangletool.cpp | 2 +- src/tools/redo/redotool.cpp | 2 +- src/tools/save/savetool.cpp | 2 +- src/tools/selection/selectiontool.cpp | 2 +- src/tools/sizeindicator/sizeindicatortool.cpp | 2 +- src/tools/text/textconfig.cpp | 8 +- src/tools/text/texttool.cpp | 2 +- src/tools/text/textwidget.cpp | 4 +- src/tools/undo/undotool.cpp | 2 +- src/utils/confighandler.cpp | 76 +++++----- src/utils/dbusutils.cpp | 8 +- src/utils/desktopfileparse.cpp | 44 +++--- src/utils/desktopinfo.cpp | 20 +-- src/utils/filenamehandler.cpp | 10 +- src/utils/pathinfo.cpp | 10 +- src/utils/screengrabber.cpp | 4 +- src/utils/screenshotsaver.cpp | 8 +- src/utils/systemnotification.cpp | 2 +- src/widgets/capture/capturebutton.cpp | 2 +- src/widgets/capture/notifierbox.cpp | 2 +- src/widgets/infowindow.cpp | 4 +- src/widgets/loadspinner.cpp | 2 +- src/widgets/panel/sidepanelwidget.cpp | 6 +- src/widgets/panel/utilitypanel.cpp | 2 +- 48 files changed, 231 insertions(+), 231 deletions(-) mode change 100755 => 100644 src/tools/pin/pintool.cpp diff --git a/src/cli/commandlineparser.cpp b/src/cli/commandlineparser.cpp index 726f3847..17f7e20a 100644 --- a/src/cli/commandlineparser.cpp +++ b/src/cli/commandlineparser.cpp @@ -31,9 +31,9 @@ QTextStream out(stdout); QTextStream err(stderr); auto versionOption = CommandOption({"v", "version"}, - "Displays version information"); + QStringLiteral("Displays version information")); auto helpOption = CommandOption({"h", "help"}, - "Displays this help"); + QStringLiteral("Displays this help")); QString optionsToString(const QList &options, const QList &arguments) { @@ -43,7 +43,7 @@ QString optionsToString(const QList &options, // of every option at the same horizontal character position. for (auto const &option: options) { QStringList dashedOptions = option.dashedNames(); - QString joinedDashedOptions = dashedOptions.join(", "); + QString joinedDashedOptions = dashedOptions.join(QStringLiteral(", ")); if (!option.valueName().isEmpty()) { joinedDashedOptions += QStringLiteral(" <%1>") .arg(option.valueName()); @@ -61,20 +61,20 @@ QString optionsToString(const QList &options, // generate the text QString result; if(!dashedOptionList.isEmpty()) { - result += "Options:\n"; - QString linePadding = QString(" ").repeated(size + 4).prepend("\n"); + result += QLatin1String("Options:\n"); + QString linePadding = QStringLiteral(" ").repeated(size + 4).prepend("\n"); for (int i = 0; i < options.length(); ++i) { result += QStringLiteral(" %1 %2\n") .arg(dashedOptionList.at(i).leftJustified(size, ' ')) .arg(options.at(i).description() - .replace("\n", linePadding)); + .replace(QLatin1String("\n"), linePadding)); } if (!arguments.isEmpty()) { - result += "\n"; + result += QLatin1String("\n"); } } if (!arguments.isEmpty()) { - result += "Arguments:\n"; + result += QLatin1String("Arguments:\n"); } for (int i = 0; i < arguments.length(); ++i) { result += QStringLiteral(" %1 %2\n") @@ -121,14 +121,14 @@ bool CommandLineParser::processOptions(const QStringList &args, QString arg = *actualIt; bool ok = true; // track values - int equalsPos = arg.indexOf("="); + int equalsPos = arg.indexOf(QLatin1String("=")); QString valueStr; if (equalsPos != -1) { valueStr = arg.mid(equalsPos +1); // right arg = arg.mid(0, equalsPos); // left } // check format -x --xx... - bool isDoubleDashed = arg.startsWith("--"); + bool isDoubleDashed = arg.startsWith(QLatin1String("--")); ok = isDoubleDashed ? arg.length() > 3 : arg.length() == 2; if (!ok) { @@ -182,8 +182,8 @@ bool CommandLineParser::processOptions(const QStringList &args, ok = option.checkValue(valueStr); if (!ok) { QString err = option.errorMsg(); - if (!err.endsWith(".")) - err += "."; + if (!err.endsWith(QLatin1String("."))) + err += QLatin1String("."); out << err; return ok; } @@ -219,7 +219,7 @@ bool CommandLineParser::parse(const QStringList &args) { // process the other args for (; it != args.cend() && ok; ++it) { const QString &value = *it; - if (value.startsWith("-")) { + if (value.startsWith(QLatin1String("-"))) { ok = processOptions(args, it, actualNode); } else { @@ -326,7 +326,7 @@ void CommandLineParser::printHelp(QStringList args, const Node *node) { } QString argText = node->subNodes.isEmpty() ? "" : "[arguments]"; helpText += QStringLiteral("Usage: %1 [%2-options] %3\n\n") - .arg(args.join(" ")) + .arg(args.join(QStringLiteral(" "))) .arg(argName).arg(argText); // add command options and subarguments QList subArgs; diff --git a/src/cli/commandoption.cpp b/src/cli/commandoption.cpp index 1fcadfeb..089c4668 100644 --- a/src/cli/commandoption.cpp +++ b/src/cli/commandoption.cpp @@ -70,7 +70,7 @@ QString CommandOption::valueName() const { void CommandOption::setValue(const QString &value) { if (m_valueName.isEmpty()) { - m_valueName = "value"; + m_valueName = QLatin1String("value"); } m_value = value; } diff --git a/src/config/geneneralconf.cpp b/src/config/geneneralconf.cpp index 23e64d61..c8b9272c 100644 --- a/src/config/geneneralconf.cpp +++ b/src/config/geneneralconf.cpp @@ -99,7 +99,7 @@ void GeneneralConf::importConfiguration() { void GeneneralConf::exportFileConfiguration() { QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), - "flameshot.conf"); + QStringLiteral("flameshot.conf")); // Cancel button if (fileName.isNull()) { diff --git a/src/config/uicoloreditor.cpp b/src/config/uicoloreditor.cpp index 89afe1f3..a8313a1e 100644 --- a/src/config/uicoloreditor.cpp +++ b/src/config/uicoloreditor.cpp @@ -125,7 +125,7 @@ void UIcolorEditor::initButtons() { h2->addWidget(frame2); frame2->setFixedSize(frameSize, frameSize); m_labelContrast = new ClickableLabel(tr("Contrast Color"), this); - m_labelContrast->setStyleSheet("color : gray"); + m_labelContrast->setStyleSheet(QStringLiteral("color : gray")); h2->addWidget(m_labelContrast); m_vLayout->addLayout(h2); @@ -149,7 +149,7 @@ void UIcolorEditor::changeLastButton(CaptureButton *b) { if (m_lastButtonPressed != b) { m_lastButtonPressed = b; - QString offStyle("QLabel { color : gray; }"); + QString offStyle(QStringLiteral("QLabel { color : gray; }")); if (b == m_buttonMainColor) { m_colorWheel->setColor(m_uiColor); diff --git a/src/config/visualseditor.cpp b/src/config/visualseditor.cpp index f32aef48..bc8468f7 100644 --- a/src/config/visualseditor.cpp +++ b/src/config/visualseditor.cpp @@ -45,9 +45,9 @@ void VisualsEditor::initOpacitySlider() { connect(m_opacitySlider, &ExtendedSlider::modificationsEnded, this, &VisualsEditor::saveOpacity); QHBoxLayout *localLayout = new QHBoxLayout(); - localLayout->addWidget(new QLabel("0%")); + localLayout->addWidget(new QLabel(QStringLiteral("0%"))); localLayout->addWidget(m_opacitySlider); - localLayout->addWidget(new QLabel("100%")); + localLayout->addWidget(new QLabel(QStringLiteral("100%"))); QLabel *label = new QLabel(); QString labelMsg = tr("Opacity of area outside selection:") + " %1%"; diff --git a/src/core/capturerequest.h b/src/core/capturerequest.h index fc65c8b3..a84b437b 100644 --- a/src/core/capturerequest.h +++ b/src/core/capturerequest.h @@ -37,7 +37,7 @@ public: CaptureRequest(CaptureMode mode, const uint delay = 0, - const QString &path = "", + const QString &path = QLatin1String(""), const QVariant &data = QVariant(), ExportTask tasks = NO_TASK); diff --git a/src/core/controller.cpp b/src/core/controller.cpp index 459ec354..3d0e39a8 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -189,7 +189,7 @@ void Controller::enableTrayIcon() { trayIconMenu->addAction(quitAction); m_trayIcon = new QSystemTrayIcon(); - m_trayIcon->setToolTip("Flameshot"); + m_trayIcon->setToolTip(QStringLiteral("Flameshot")); m_trayIcon->setContextMenu(trayIconMenu); QIcon trayicon = QIcon::fromTheme("flameshot-tray", QIcon(":img/app/flameshot.png")); m_trayIcon->setIcon(trayicon); diff --git a/src/core/controller.h b/src/core/controller.h index 6d80a4b2..60e08b0f 100644 --- a/src/core/controller.h +++ b/src/core/controller.h @@ -55,7 +55,7 @@ public slots: void enableTrayIcon(); void disableTrayIcon(); void sendTrayNotification(const QString &text, - const QString &title = "Flameshot Info", + const QString &title = QStringLiteral("Flameshot Info"), const int timeout = 5000); void updateConfigComponents(); diff --git a/src/main.cpp b/src/main.cpp index 83fa1c1a..504dd459 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) { for (const QString &path: trPaths) { bool match = translator.load(QLocale(), - "Internationalization", "_", + QStringLiteral("Internationalization"), QStringLiteral("_"), path); if (match) { break; @@ -60,8 +60,8 @@ int main(int argc, char *argv[]) { app.installTranslator(&translator); app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); - app.setApplicationName("flameshot"); - app.setOrganizationName("Dharkael"); + app.setApplicationName(QStringLiteral("flameshot")); + app.setOrganizationName(QStringLiteral("Dharkael")); auto c = Controller::getInstance(); #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) @@ -71,8 +71,8 @@ int main(int argc, char *argv[]) { SystemNotification().sendMessage( QObject::tr("Unable to connect via DBus")); } - dbus.registerObject("/", c); - dbus.registerService("org.dharkael.Flameshot"); + dbus.registerObject(QStringLiteral("/"), c); + dbus.registerService(QStringLiteral("org.dharkael.Flameshot")); #endif // Exporting captures must be connected after the dbus interface // or the dbus signal gets blocked until we end the exports. @@ -85,66 +85,66 @@ int main(int argc, char *argv[]) { * CLI parsing | * ------------*/ QCoreApplication app(argc, argv); - app.setApplicationName("flameshot"); - app.setOrganizationName("Dharkael"); + app.setApplicationName(QStringLiteral("flameshot")); + app.setOrganizationName(QStringLiteral("Dharkael")); app.setApplicationVersion(qApp->applicationVersion()); CommandLineParser parser; // Add description parser.setDescription( - "Powerful yet simple to use screenshot software."); - parser.setGeneralErrorMessage("See 'flameshot --help'."); + QStringLiteral("Powerful yet simple to use screenshot software.")); + parser.setGeneralErrorMessage(QStringLiteral("See 'flameshot --help'.")); // Arguments - CommandArgument fullArgument("full", "Capture the entire desktop."); - CommandArgument guiArgument("gui", "Start a manual capture in GUI mode."); - CommandArgument configArgument("config", "Configure flameshot."); - CommandArgument screenArgument("screen", "Capture a single screen."); + CommandArgument fullArgument(QStringLiteral("full"), QStringLiteral("Capture the entire desktop.")); + CommandArgument guiArgument(QStringLiteral("gui"), QStringLiteral("Start a manual capture in GUI mode.")); + CommandArgument configArgument(QStringLiteral("config"), QStringLiteral("Configure flameshot.")); + CommandArgument screenArgument(QStringLiteral("screen"), QStringLiteral("Capture a single screen.")); // Options CommandOption pathOption( {"p", "path"}, - "Path where the capture will be saved", - "path"); + QStringLiteral("Path where the capture will be saved"), + QStringLiteral("path")); CommandOption clipboardOption( {"c", "clipboard"}, - "Save the capture to the clipboard"); + QStringLiteral("Save the capture to the clipboard")); CommandOption delayOption( {"d", "delay"}, - "Delay time in milliseconds", - "milliseconds"); + QStringLiteral("Delay time in milliseconds"), + QStringLiteral("milliseconds")); CommandOption filenameOption( {"f", "filename"}, - "Set the filename pattern", - "pattern"); + QStringLiteral("Set the filename pattern"), + QStringLiteral("pattern")); CommandOption trayOption( {"t", "trayicon"}, - "Enable or disable the trayicon", - "bool"); + QStringLiteral("Enable or disable the trayicon"), + QStringLiteral("bool")); CommandOption autostartOption( {"a", "autostart"}, - "Enable or disable run at startup", - "bool"); + QStringLiteral("Enable or disable run at startup"), + QStringLiteral("bool")); CommandOption showHelpOption( {"s", "showhelp"}, - "Show the help message in the capture mode", - "bool"); + QStringLiteral("Show the help message in the capture mode"), + QStringLiteral("bool")); CommandOption mainColorOption( {"m", "maincolor"}, - "Define the main UI color", - "color-code"); + QStringLiteral("Define the main UI color"), + QStringLiteral("color-code")); CommandOption contrastColorOption( {"k", "contrastcolor"}, - "Define the contrast UI color", - "color-code"); + QStringLiteral("Define the contrast UI color"), + QStringLiteral("color-code")); CommandOption rawImageOption( {"r", "raw"}, - "Print raw PNG capture"); + QStringLiteral("Print raw PNG capture")); CommandOption screenNumberOption( {"n", "number"}, - "Define the screen to capture,\ndefault: screen containing the cursor", - "Screen number", "-1"); + QStringLiteral("Define the screen to capture,\ndefault: screen containing the cursor"), + QStringLiteral("Screen number"), QStringLiteral("-1")); // Add checkers - auto colorChecker = [&parser](const QString &colorCode) -> bool { + auto colorChecker = [](const QString &colorCode) -> bool { QColor parsedColor(colorCode); return parsedColor.isValid() && parsedColor.alphaF() == 1.0; }; @@ -156,15 +156,15 @@ int main(int argc, char *argv[]) { "- Named colors like 'blue' or 'red'\n" "You may need to escape the '#' sign as in '\\#FFF'"; - const QString delayErr = "Invalid delay, it must be higher than 0"; - const QString numberErr = "Invalid screen number, it must be non negative"; - auto numericChecker = [&parser](const QString &delayValue) -> bool { + const QString delayErr = QStringLiteral("Invalid delay, it must be higher than 0"); + const QString numberErr = QStringLiteral("Invalid screen number, it must be non negative"); + auto numericChecker = [](const QString &delayValue) -> bool { int value = delayValue.toInt(); return value >= 0; }; - const QString pathErr = "Invalid path, it must be a real path in the system"; - auto pathChecker = [&parser, pathErr](const QString &pathValue) -> bool { + const QString pathErr = QStringLiteral("Invalid path, it must be a real path in the system"); + auto pathChecker = [pathErr](const QString &pathValue) -> bool { bool res = QDir(pathValue).exists(); if (!res) { SystemNotification().sendMessage(QObject::tr(pathErr.toLatin1().data())); @@ -172,9 +172,9 @@ int main(int argc, char *argv[]) { return res; }; - const QString booleanErr = "Invalid value, it must be defined as 'true' or 'false'"; - auto booleanChecker = [&parser](const QString &value) -> bool { - return value == "true" || value == "false"; + const QString booleanErr = QStringLiteral("Invalid value, it must be defined as 'true' or 'false'"); + auto booleanChecker = [](const QString &value) -> bool { + return value == QLatin1String("true") || value == QLatin1String("false"); }; contrastColorOption.addChecker(colorChecker, colorErr); @@ -220,8 +220,8 @@ int main(int argc, char *argv[]) { uint id = req.id(); // Send message - QDBusMessage m = QDBusMessage::createMethodCall("org.dharkael.Flameshot", - "/", "", "graphicCapture"); + QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"), + QStringLiteral("/"), QLatin1String(""), QStringLiteral("graphicCapture")); m << pathValue << delay << id; QDBusConnection sessionBus = QDBusConnection::sessionBus(); dbusUtils.checkDBusConnection(sessionBus); @@ -248,10 +248,10 @@ int main(int argc, char *argv[]) { QTextStream out(stdout); out << "Invalid format, set where to save the content with one of " << "the following flags:\n " - << pathOption.dashedNames().join(", ") << "\n " - << rawImageOption.dashedNames().join(", ") << "\n " - << clipboardOption.dashedNames().join(", ") << "\n\n"; - parser.parse(QStringList() << argv[0] << "full" << "-h"); + << pathOption.dashedNames().join(QStringLiteral(", ")) << "\n " + << rawImageOption.dashedNames().join(QStringLiteral(", ")) << "\n " + << clipboardOption.dashedNames().join(QStringLiteral(", ")) << "\n\n"; + parser.parse(QStringList() << argv[0] << QStringLiteral("full") << QStringLiteral("-h")); goto finish; } @@ -266,8 +266,8 @@ int main(int argc, char *argv[]) { DBusUtils dbusUtils; // Send message - QDBusMessage m = QDBusMessage::createMethodCall("org.dharkael.Flameshot", - "/", "", "fullScreen"); + QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"), + QStringLiteral("/"), QLatin1String(""), QStringLiteral("fullScreen")); m << pathValue << toClipboard << delay << id; QDBusConnection sessionBus = QDBusConnection::sessionBus(); dbusUtils.checkDBusConnection(sessionBus); @@ -287,7 +287,7 @@ int main(int argc, char *argv[]) { } else if (parser.isSet(screenArgument)) { // SCREEN QString numberStr = parser.value(screenNumberOption); - int number = numberStr.startsWith("-") ? -1 : numberStr.toInt(); + int number = numberStr.startsWith(QLatin1String("-")) ? -1 : numberStr.toInt(); QString pathValue = parser.value(pathOption); int delay = parser.value(delayOption).toInt(); bool toClipboard = parser.isSet(clipboardOption); @@ -297,10 +297,10 @@ int main(int argc, char *argv[]) { QTextStream out(stdout); out << "Invalid format, set where to save the content with one of " << "the following flags:\n " - << pathOption.dashedNames().join(", ") << "\n " - << rawImageOption.dashedNames().join(", ") << "\n " - << clipboardOption.dashedNames().join(", ") << "\n\n"; - parser.parse(QStringList() << argv[0] << "screen" << "-h"); + << pathOption.dashedNames().join(QStringLiteral(", ")) << "\n " + << rawImageOption.dashedNames().join(QStringLiteral(", ")) << "\n " + << clipboardOption.dashedNames().join(QStringLiteral(", ")) << "\n\n"; + parser.parse(QStringList() << argv[0] << QStringLiteral("screen") << QStringLiteral("-h")); goto finish; } @@ -316,8 +316,8 @@ int main(int argc, char *argv[]) { DBusUtils dbusUtils; // Send message - QDBusMessage m = QDBusMessage::createMethodCall("org.dharkael.Flameshot", - "/", "", "captureScreen"); + QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"), + QStringLiteral("/"), QLatin1String(""), QStringLiteral("captureScreen")); m << number << pathValue << toClipboard << delay << id; QDBusConnection sessionBus = QDBusConnection::sessionBus(); dbusUtils.checkDBusConnection(sessionBus); @@ -346,11 +346,11 @@ int main(int argc, char *argv[]) { mainColor || contrastColor); ConfigHandler config; if (autostart) { - QDBusMessage m = QDBusMessage::createMethodCall("org.dharkael.Flameshot", - "/", "", "autostartEnabled"); - if (parser.value(autostartOption) == "false") { + QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"), + QStringLiteral("/"), QLatin1String(""), QStringLiteral("autostartEnabled")); + if (parser.value(autostartOption) == QLatin1String("false")) { m << false; - } else if (parser.value(autostartOption) == "true") { + } else if (parser.value(autostartOption) == QLatin1String("true")) { m << true; } QDBusConnection sessionBus = QDBusConnection::sessionBus(); @@ -370,11 +370,11 @@ int main(int argc, char *argv[]) { .arg(fh.parsedPattern()); } if (tray) { - QDBusMessage m = QDBusMessage::createMethodCall("org.dharkael.Flameshot", - "/", "", "trayIconEnabled"); - if (parser.value(trayOption) == "false") { + QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"), + QStringLiteral("/"), QLatin1String(""), QStringLiteral("trayIconEnabled")); + if (parser.value(trayOption) == QLatin1String("false")) { m << false; - } else if (parser.value(trayOption) == "true") { + } else if (parser.value(trayOption) == QLatin1String("true")) { m << true; } QDBusConnection sessionBus = QDBusConnection::sessionBus(); @@ -385,9 +385,9 @@ int main(int argc, char *argv[]) { sessionBus.call(m); } if (help) { - if (parser.value(showHelpOption) == "false") { + if (parser.value(showHelpOption) == QLatin1String("false")) { config.setShowHelp(false); - } else if (parser.value(showHelpOption) == "true") { + } else if (parser.value(showHelpOption) == QLatin1String("true")) { config.setShowHelp(true); } } @@ -404,8 +404,8 @@ int main(int argc, char *argv[]) { // Open gui when no options if (!someFlagSet) { - QDBusMessage m = QDBusMessage::createMethodCall("org.dharkael.Flameshot", - "/", "", "openConfig"); + QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"), + QStringLiteral("/"), QLatin1String(""), QStringLiteral("openConfig")); QDBusConnection sessionBus = QDBusConnection::sessionBus(); if (!sessionBus.isConnected()) { SystemNotification().sendMessage( diff --git a/src/third-party/singleapplication/singleapplication.cpp b/src/third-party/singleapplication/singleapplication.cpp index 8ddb48c0..f452e70d 100644 --- a/src/third-party/singleapplication/singleapplication.cpp +++ b/src/third-party/singleapplication/singleapplication.cpp @@ -107,7 +107,7 @@ void SingleApplicationPrivate::genBlockServerName( int timeout ) #endif #ifdef Q_OS_UNIX QProcess process; - process.start( "whoami" ); + process.start( QStringLiteral("whoami") ); if( process.waitForFinished( timeout ) && process.exitCode() == QProcess::NormalExit) { appData.addData( process.readLine() ); diff --git a/src/tools/arrow/arrowtool.cpp b/src/tools/arrow/arrowtool.cpp index cdec49d6..fd6e88b4 100644 --- a/src/tools/arrow/arrowtool.cpp +++ b/src/tools/arrow/arrowtool.cpp @@ -81,7 +81,7 @@ QString ArrowTool::name() const { } QString ArrowTool::nameID() { - return ""; + return QLatin1String(""); } QString ArrowTool::description() const { diff --git a/src/tools/blur/blurtool.cpp b/src/tools/blur/blurtool.cpp index 0ea63f55..934ce489 100644 --- a/src/tools/blur/blurtool.cpp +++ b/src/tools/blur/blurtool.cpp @@ -35,7 +35,7 @@ QString BlurTool::name() const { } QString BlurTool::nameID() { - return ""; + return QLatin1String(""); } QString BlurTool::description() const { diff --git a/src/tools/circle/circletool.cpp b/src/tools/circle/circletool.cpp index 387c6efb..f7bd4985 100644 --- a/src/tools/circle/circletool.cpp +++ b/src/tools/circle/circletool.cpp @@ -35,7 +35,7 @@ QString CircleTool::name() const { } QString CircleTool::nameID() { - return ""; + return QLatin1String(""); } QString CircleTool::description() const { diff --git a/src/tools/copy/copytool.cpp b/src/tools/copy/copytool.cpp index 268d0b72..a998679f 100644 --- a/src/tools/copy/copytool.cpp +++ b/src/tools/copy/copytool.cpp @@ -36,7 +36,7 @@ QString CopyTool::name() const { } QString CopyTool::nameID() { - return ""; + return QLatin1String(""); } QString CopyTool::description() const { diff --git a/src/tools/exit/exittool.cpp b/src/tools/exit/exittool.cpp index e4661c33..9bcf0a49 100644 --- a/src/tools/exit/exittool.cpp +++ b/src/tools/exit/exittool.cpp @@ -35,7 +35,7 @@ QString ExitTool::name() const { } QString ExitTool::nameID() { - return ""; + return QLatin1String(""); } QString ExitTool::description() const { diff --git a/src/tools/imgur/imguruploader.cpp b/src/tools/imgur/imguruploader.cpp index c6bece91..d0cbe57a 100644 --- a/src/tools/imgur/imguruploader.cpp +++ b/src/tools/imgur/imguruploader.cpp @@ -72,10 +72,10 @@ void ImgurUploader::handleReply(QNetworkReply *reply) { if (reply->error() == QNetworkReply::NoError) { QJsonDocument response = QJsonDocument::fromJson(reply->readAll()); QJsonObject json = response.object(); - QJsonObject data = json["data"].toObject(); - m_imageURL.setUrl(data["link"].toString()); - m_deleteImageURL.setUrl(QString("https://imgur.com/delete/%1").arg( - data["deletehash"].toString())); + QJsonObject data = json[QStringLiteral("data")].toObject(); + m_imageURL.setUrl(data[QStringLiteral("link")].toString()); + m_deleteImageURL.setUrl(QStringLiteral("https://imgur.com/delete/%1").arg( + data[QStringLiteral("deletehash")].toString())); onUploadOk(); } else { m_infoLabel->setText(reply->errorString()); @@ -101,16 +101,16 @@ void ImgurUploader::upload() { m_pixmap.save(&buffer, "PNG"); QUrlQuery urlQuery; - urlQuery.addQueryItem("title", "flameshot_screenshot"); + urlQuery.addQueryItem(QStringLiteral("title"), QStringLiteral("flameshot_screenshot")); QString description = FileNameHandler().parsedPattern(); - urlQuery.addQueryItem("description", description); + urlQuery.addQueryItem(QStringLiteral("description"), description); - QUrl url("https://api.imgur.com/3/image"); + QUrl url(QStringLiteral("https://api.imgur.com/3/image")); url.setQuery(urlQuery); QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/application/x-www-form-urlencoded"); - request.setRawHeader("Authorization", QString("Client-ID %1").arg(IMGUR_CLIENT_ID).toUtf8()); + request.setRawHeader("Authorization", QStringLiteral("Client-ID %1").arg(IMGUR_CLIENT_ID).toUtf8()); m_NetworkAM->post(request, byteArray); } diff --git a/src/tools/imgur/imguruploadertool.cpp b/src/tools/imgur/imguruploadertool.cpp index 428e3db6..86e0cc27 100644 --- a/src/tools/imgur/imguruploadertool.cpp +++ b/src/tools/imgur/imguruploadertool.cpp @@ -36,7 +36,7 @@ QString ImgurUploaderTool::name() const { } QString ImgurUploaderTool::nameID() { - return ""; + return QLatin1String(""); } QString ImgurUploaderTool::description() const { diff --git a/src/tools/launcher/applaunchertool.cpp b/src/tools/launcher/applaunchertool.cpp index 15c4b992..b47bb729 100644 --- a/src/tools/launcher/applaunchertool.cpp +++ b/src/tools/launcher/applaunchertool.cpp @@ -35,7 +35,7 @@ QString AppLauncher::name() const { } QString AppLauncher::nameID() { - return ""; + return QLatin1String(""); } QString AppLauncher::description() const { diff --git a/src/tools/launcher/applauncherwidget.cpp b/src/tools/launcher/applauncherwidget.cpp index 9edccae4..6902cfa6 100644 --- a/src/tools/launcher/applauncherwidget.cpp +++ b/src/tools/launcher/applauncherwidget.cpp @@ -61,7 +61,7 @@ AppLauncherWidget::AppLauncherWidget(const QPixmap &p, QWidget *parent): QDir appsDirLocal(dirLocal); m_parser.processDirectory(appsDirLocal); - QString dir = "/usr/share/applications/"; + QString dir = QStringLiteral("/usr/share/applications/"); QDir appsDir(dir); m_parser.processDirectory(appsDir); @@ -173,9 +173,9 @@ void AppLauncherWidget::initListWidget() { const QVector &appList = m_appsMap[cat]; addAppsToListWidget(itemsWidget, appList); - m_tabWidget->addTab(itemsWidget, QIcon::fromTheme(iconName), ""); + m_tabWidget->addTab(itemsWidget, QIcon::fromTheme(iconName), QLatin1String("")); m_tabWidget->setTabToolTip(m_tabWidget->count(), cat); - if (cat == "Graphics") { + if (cat == QLatin1String("Graphics")) { m_tabWidget->setCurrentIndex(m_tabWidget->count() -1); } } @@ -199,7 +199,7 @@ void AppLauncherWidget::initAppMap() { // Unify multimedia. QVector multimediaList; QStringList multimediaNames; - multimediaNames << "AudioVideo" << "Audio" << "Video"; + multimediaNames << QStringLiteral("AudioVideo") << QStringLiteral("Audio") << QStringLiteral("Video"); for (const QString &name : multimediaNames) { if(!m_appsMap.contains(name)) { continue; @@ -211,7 +211,7 @@ void AppLauncherWidget::initAppMap() { } m_appsMap.remove(name); } - m_appsMap.insert("Multimedia", multimediaList); + m_appsMap.insert(QStringLiteral("Multimedia"), multimediaList); } void AppLauncherWidget::configureListView(QListWidget *widget) { diff --git a/src/tools/line/linetool.cpp b/src/tools/line/linetool.cpp index e1a1755e..f69fb8c9 100644 --- a/src/tools/line/linetool.cpp +++ b/src/tools/line/linetool.cpp @@ -43,7 +43,7 @@ QString LineTool::name() const { } QString LineTool::nameID() { - return ""; + return QLatin1String(""); } QString LineTool::description() const { diff --git a/src/tools/marker/markertool.cpp b/src/tools/marker/markertool.cpp index 42800b02..3a7e96e6 100644 --- a/src/tools/marker/markertool.cpp +++ b/src/tools/marker/markertool.cpp @@ -43,7 +43,7 @@ QString MarkerTool::name() const { } QString MarkerTool::nameID() { - return ""; + return QLatin1String(""); } QString MarkerTool::description() const { diff --git a/src/tools/move/movetool.cpp b/src/tools/move/movetool.cpp index 08e902fb..aa4fab64 100644 --- a/src/tools/move/movetool.cpp +++ b/src/tools/move/movetool.cpp @@ -35,7 +35,7 @@ QString MoveTool::name() const { } QString MoveTool::nameID() { - return ""; + return QLatin1String(""); } QString MoveTool::description() const { diff --git a/src/tools/pencil/penciltool.cpp b/src/tools/pencil/penciltool.cpp index 7b01c5b2..0810a3b1 100644 --- a/src/tools/pencil/penciltool.cpp +++ b/src/tools/pencil/penciltool.cpp @@ -31,7 +31,7 @@ QString PencilTool::name() const { } QString PencilTool::nameID() { - return ""; + return QLatin1String(""); } QString PencilTool::description() const { diff --git a/src/tools/pin/pintool.cpp b/src/tools/pin/pintool.cpp old mode 100755 new mode 100644 index f56c4ea2..e5a5256d --- a/src/tools/pin/pintool.cpp +++ b/src/tools/pin/pintool.cpp @@ -35,7 +35,7 @@ QString PinTool::name() const { } QString PinTool::nameID() { - return ""; + return QLatin1String(""); } QString PinTool::description() const { diff --git a/src/tools/rectangle/rectangletool.cpp b/src/tools/rectangle/rectangletool.cpp index fa9c483b..e36f43d4 100644 --- a/src/tools/rectangle/rectangletool.cpp +++ b/src/tools/rectangle/rectangletool.cpp @@ -35,7 +35,7 @@ QString RectangleTool::name() const { } QString RectangleTool::nameID() { - return ""; + return QLatin1String(""); } QString RectangleTool::description() const { diff --git a/src/tools/redo/redotool.cpp b/src/tools/redo/redotool.cpp index ee8a8c03..8446f7b8 100644 --- a/src/tools/redo/redotool.cpp +++ b/src/tools/redo/redotool.cpp @@ -35,7 +35,7 @@ QString RedoTool::name() const { } QString RedoTool::nameID() { - return ""; + return QLatin1String(""); } QString RedoTool::description() const { diff --git a/src/tools/save/savetool.cpp b/src/tools/save/savetool.cpp index ec7027fc..3b7a83b2 100644 --- a/src/tools/save/savetool.cpp +++ b/src/tools/save/savetool.cpp @@ -36,7 +36,7 @@ QString SaveTool::name() const { } QString SaveTool::nameID() { - return ""; + return QLatin1String(""); } QString SaveTool::description() const { diff --git a/src/tools/selection/selectiontool.cpp b/src/tools/selection/selectiontool.cpp index c1c4222a..cc9cdfe3 100644 --- a/src/tools/selection/selectiontool.cpp +++ b/src/tools/selection/selectiontool.cpp @@ -39,7 +39,7 @@ QString SelectionTool::name() const { } QString SelectionTool::nameID() { - return ""; + return QLatin1String(""); } QString SelectionTool::description() const { diff --git a/src/tools/sizeindicator/sizeindicatortool.cpp b/src/tools/sizeindicator/sizeindicatortool.cpp index 047f7551..bae76618 100644 --- a/src/tools/sizeindicator/sizeindicatortool.cpp +++ b/src/tools/sizeindicator/sizeindicatortool.cpp @@ -35,7 +35,7 @@ QString SizeIndicatorTool::name() const { } QString SizeIndicatorTool::nameID() { - return ""; + return QLatin1String(""); } QString SizeIndicatorTool::description() const { diff --git a/src/tools/text/textconfig.cpp b/src/tools/text/textconfig.cpp index 357fa041..d7f455e7 100644 --- a/src/tools/text/textconfig.cpp +++ b/src/tools/text/textconfig.cpp @@ -42,28 +42,28 @@ TextConfig::TextConfig(QWidget *parent) : QWidget(parent) { PathInfo::blackIconPath(); m_strikeOutButton = new QPushButton( - QIcon(iconPrefix + "format_strikethrough.svg"), ""); + QIcon(iconPrefix + "format_strikethrough.svg"), QLatin1String("")); m_strikeOutButton->setCheckable(true); connect(m_strikeOutButton, &QPushButton::clicked, this, &TextConfig::fontStrikeOutChanged); m_strikeOutButton->setToolTip(tr("StrikeOut")); m_underlineButton = new QPushButton( - QIcon(iconPrefix + "format_underlined.svg"), ""); + QIcon(iconPrefix + "format_underlined.svg"), QLatin1String("")); m_underlineButton->setCheckable(true); connect(m_underlineButton, &QPushButton::clicked, this, &TextConfig::fontUnderlineChanged); m_underlineButton->setToolTip(tr("Underline")); m_weightButton = new QPushButton( - QIcon(iconPrefix + "format_bold.svg"), ""); + QIcon(iconPrefix + "format_bold.svg"), QLatin1String("")); m_weightButton->setCheckable(true); connect(m_weightButton, &QPushButton::clicked, this, &TextConfig::weightButtonPressed); m_weightButton->setToolTip(tr("Bold")); m_italicButton = new QPushButton( - QIcon(iconPrefix + "format_italic.svg"), ""); + QIcon(iconPrefix + "format_italic.svg"), QLatin1String("")); m_italicButton->setCheckable(true); connect(m_italicButton, &QPushButton::clicked, this, &TextConfig::fontItalicChanged); diff --git a/src/tools/text/texttool.cpp b/src/tools/text/texttool.cpp index 6688dc95..db4a541d 100644 --- a/src/tools/text/texttool.cpp +++ b/src/tools/text/texttool.cpp @@ -51,7 +51,7 @@ QString TextTool::name() const { } QString TextTool::nameID() { - return ""; + return QLatin1String(""); } QString TextTool::description() const { diff --git a/src/tools/text/textwidget.cpp b/src/tools/text/textwidget.cpp index 100b4c71..a25085f0 100644 --- a/src/tools/text/textwidget.cpp +++ b/src/tools/text/textwidget.cpp @@ -18,7 +18,7 @@ #include "textwidget.h" TextWidget::TextWidget(QWidget *parent) : QTextEdit(parent) { - setStyleSheet("TextWidget { background: transparent; }"); + setStyleSheet(QStringLiteral("TextWidget { background: transparent; }")); connect(this, &TextWidget::textChanged, this, &TextWidget::adjustSize); connect(this, &TextWidget::textChanged, @@ -61,7 +61,7 @@ void TextWidget::setFontPointSize(qreal s) { } void TextWidget::setTextColor(const QColor &c) { - QString s("TextWidget { background: transparent; color: %1; }"); + QString s(QStringLiteral("TextWidget { background: transparent; color: %1; }")); setStyleSheet(s.arg(c.name())); } diff --git a/src/tools/undo/undotool.cpp b/src/tools/undo/undotool.cpp index 1d1d791d..71e62242 100644 --- a/src/tools/undo/undotool.cpp +++ b/src/tools/undo/undotool.cpp @@ -35,7 +35,7 @@ QString UndoTool::name() const { } QString UndoTool::nameID() { - return ""; + return QLatin1String(""); } QString UndoTool::description() const { diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index 6eef22a0..a30c4124 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -27,13 +27,13 @@ ConfigHandler::ConfigHandler(){ QVector ConfigHandler::getButtons() { QVector buttons; - if (m_settings.contains("buttons")) { + if (m_settings.contains(QStringLiteral("buttons"))) { // TODO: remove toList in v1.0 QVector buttonsInt = - m_settings.value("buttons").value >().toVector(); + m_settings.value(QStringLiteral("buttons")).value >().toVector(); bool modified = normalizeButtons(buttonsInt); if (modified) { - m_settings.setValue("buttons", QVariant::fromValue(buttonsInt.toList())); + m_settings.setValue(QStringLiteral("buttons"), QVariant::fromValue(buttonsInt.toList())); } buttons = fromIntToButton(buttonsInt); } else { @@ -69,7 +69,7 @@ void ConfigHandler::setButtons(const QVector &buttons QVector l = fromButtonToInt(buttons); normalizeButtons(l); // TODO: remove toList in v1.0 - m_settings.setValue("buttons", QVariant::fromValue(l.toList())); + m_settings.setValue(QStringLiteral("buttons"), QVariant::fromValue(l.toList())); } QVector ConfigHandler::getUserColors() { @@ -86,8 +86,8 @@ QVector ConfigHandler::getUserColors() { Qt::darkMagenta }; - if (m_settings.contains("userColors")) { - for (const QString &hex : m_settings.value("userColors").toStringList()) { + if (m_settings.contains(QStringLiteral("userColors"))) { + for (const QString &hex : m_settings.value(QStringLiteral("userColors")).toStringList()) { if (QColor::isValidColor(hex)) { colors.append(QColor(hex)); } @@ -110,22 +110,22 @@ void ConfigHandler::setUserColors(const QVector &l) { hexColors.append(color.name()); } - m_settings.setValue("userColors", QVariant::fromValue(hexColors)); + m_settings.setValue(QStringLiteral("userColors"), QVariant::fromValue(hexColors)); } QString ConfigHandler::savePathValue() { - return m_settings.value("savePath").toString(); + return m_settings.value(QStringLiteral("savePath")).toString(); } void ConfigHandler::setSavePath(const QString &savePath) { - m_settings.setValue("savePath", savePath); + m_settings.setValue(QStringLiteral("savePath"), savePath); } QColor ConfigHandler::uiMainColorValue() { QColor res = QColor(116, 0, 150); - if (m_settings.contains("uiColor")) { - QString hex = m_settings.value("uiColor").toString(); + if (m_settings.contains(QStringLiteral("uiColor"))) { + QString hex = m_settings.value(QStringLiteral("uiColor")).toString(); if (QColor::isValidColor(hex)) { res = QColor(hex); @@ -135,14 +135,14 @@ QColor ConfigHandler::uiMainColorValue() { } void ConfigHandler::setUIMainColor(const QColor &c) { - m_settings.setValue("uiColor", c.name()); + m_settings.setValue(QStringLiteral("uiColor"), c.name()); } QColor ConfigHandler::uiContrastColorValue() { QColor res = QColor(86, 0, 120); - if (m_settings.contains("contastUiColor")) { - QString hex = m_settings.value("contastUiColor").toString(); + if (m_settings.contains(QStringLiteral("contastUiColor"))) { + QString hex = m_settings.value(QStringLiteral("contastUiColor")).toString(); if (QColor::isValidColor(hex)) { res = QColor(hex); @@ -153,14 +153,14 @@ QColor ConfigHandler::uiContrastColorValue() { } void ConfigHandler::setUIContrastColor(const QColor &c) { - m_settings.setValue("contastUiColor", c.name()); + m_settings.setValue(QStringLiteral("contastUiColor"), c.name()); } QColor ConfigHandler::drawColorValue() { QColor res(Qt::red); - if (m_settings.contains("drawColor")) { - QString hex = m_settings.value("drawColor").toString(); + if (m_settings.contains(QStringLiteral("drawColor"))) { + QString hex = m_settings.value(QStringLiteral("drawColor")).toString(); if (QColor::isValidColor(hex)) { res = QColor(hex); @@ -171,71 +171,71 @@ QColor ConfigHandler::drawColorValue() { } void ConfigHandler::setDrawColor(const QColor &c) { - m_settings.setValue("drawColor", c.name()); + m_settings.setValue(QStringLiteral("drawColor"), c.name()); } bool ConfigHandler::showHelpValue() { bool res = true; - if (m_settings.contains("showHelp")) { - res = m_settings.value("showHelp").toBool(); + if (m_settings.contains(QStringLiteral("showHelp"))) { + res = m_settings.value(QStringLiteral("showHelp")).toBool(); } return res; } void ConfigHandler::setShowHelp(const bool showHelp) { - m_settings.setValue("showHelp", showHelp); + m_settings.setValue(QStringLiteral("showHelp"), showHelp); } bool ConfigHandler::desktopNotificationValue() { bool res = true; - if (m_settings.contains("showDesktopNotification")) { - res = m_settings.value("showDesktopNotification").toBool(); + if (m_settings.contains(QStringLiteral("showDesktopNotification"))) { + res = m_settings.value(QStringLiteral("showDesktopNotification")).toBool(); } return res; } void ConfigHandler::setDesktopNotification(const bool showDesktopNotification) { - m_settings.setValue("showDesktopNotification", showDesktopNotification); + m_settings.setValue(QStringLiteral("showDesktopNotification"), showDesktopNotification); } QString ConfigHandler::filenamePatternValue() { - return m_settings.value("filenamePattern").toString(); + return m_settings.value(QStringLiteral("filenamePattern")).toString(); } void ConfigHandler::setFilenamePattern(const QString &pattern) { - return m_settings.setValue("filenamePattern", pattern); + return m_settings.setValue(QStringLiteral("filenamePattern"), pattern); } bool ConfigHandler::disabledTrayIconValue() { bool res = false; - if (m_settings.contains("disabledTrayIcon")) { - res = m_settings.value("disabledTrayIcon").toBool(); + if (m_settings.contains(QStringLiteral("disabledTrayIcon"))) { + res = m_settings.value(QStringLiteral("disabledTrayIcon")).toBool(); } return res; } void ConfigHandler::setDisabledTrayIcon(const bool disabledTrayIcon) { - m_settings.setValue("disabledTrayIcon", disabledTrayIcon); + m_settings.setValue(QStringLiteral("disabledTrayIcon"), disabledTrayIcon); } int ConfigHandler::drawThicknessValue() { int res = 0; - if (m_settings.contains("drawThickness")) { - res = m_settings.value("drawThickness").toInt(); + if (m_settings.contains(QStringLiteral("drawThickness"))) { + res = m_settings.value(QStringLiteral("drawThickness")).toInt(); } return res; } void ConfigHandler::setdrawThickness(const int thickness) { - m_settings.setValue("drawThickness", thickness); + m_settings.setValue(QStringLiteral("drawThickness"), thickness); } bool ConfigHandler::keepOpenAppLauncherValue() { - return m_settings.value("keepOpenAppLauncher").toBool(); + return m_settings.value(QStringLiteral("keepOpenAppLauncher")).toBool(); } void ConfigHandler::setKeepOpenAppLauncher(const bool keepOpen) { - m_settings.setValue("keepOpenAppLauncher", keepOpen); + m_settings.setValue(QStringLiteral("keepOpenAppLauncher"), keepOpen); } bool ConfigHandler::startupLaunchValue() { @@ -283,15 +283,15 @@ void ConfigHandler::setStartupLaunch(const bool start) { int ConfigHandler::contrastOpacityValue() { int opacity = 190; - if (m_settings.contains("contrastOpacity")) { - opacity = m_settings.value("contrastOpacity").toInt(); + if (m_settings.contains(QStringLiteral("contrastOpacity"))) { + opacity = m_settings.value(QStringLiteral("contrastOpacity")).toInt(); opacity = qBound(0, opacity, 255); } return opacity; } void ConfigHandler::setContrastOpacity(const int transparency) { - m_settings.setValue("contrastOpacity", transparency); + m_settings.setValue(QStringLiteral("contrastOpacity"), transparency); } void ConfigHandler::setDefaults() { @@ -305,7 +305,7 @@ void ConfigHandler::setAllTheButtons() { buttons << static_cast(t); } // TODO: remove toList in v1.0 - m_settings.setValue("buttons", QVariant::fromValue(buttons.toList())); + m_settings.setValue(QStringLiteral("buttons"), QVariant::fromValue(buttons.toList())); } QString ConfigHandler::configFilePath() const { diff --git a/src/utils/dbusutils.cpp b/src/utils/dbusutils.cpp index d9bb6405..87b3c657 100644 --- a/src/utils/dbusutils.cpp +++ b/src/utils/dbusutils.cpp @@ -27,13 +27,13 @@ DBusUtils::DBusUtils(QObject *parent) : QObject(parent) { void DBusUtils::connectPrintCapture(QDBusConnection &session, uint id) { m_id = id; // captureTaken - session.connect("org.dharkael.Flameshot", - "/", "", "captureTaken", + session.connect(QStringLiteral("org.dharkael.Flameshot"), + QStringLiteral("/"), QLatin1String(""), QStringLiteral("captureTaken"), this, SLOT(captureTaken(uint, QByteArray))); // captureFailed - session.connect("org.dharkael.Flameshot", - "/", "", "captureFailed", + session.connect(QStringLiteral("org.dharkael.Flameshot"), + QStringLiteral("/"), QLatin1String(""), QStringLiteral("captureFailed"), this, SLOT(captureFailed(uint))); } diff --git a/src/utils/desktopfileparse.cpp b/src/utils/desktopfileparse.cpp index 8a5e986f..e9397530 100644 --- a/src/utils/desktopfileparse.cpp +++ b/src/utils/desktopfileparse.cpp @@ -30,7 +30,7 @@ DesktopFileParser::DesktopFileParser() { m_localeNameShort = QStringLiteral("Name[%1]").arg(localeShort); m_localeDescriptionShort = QStringLiteral("Comment[%1]") .arg(localeShort); - m_defaultIcon = QIcon::fromTheme("application-x-executable"); + m_defaultIcon = QIcon::fromTheme(QStringLiteral("application-x-executable")); } DesktopAppData DesktopFileParser::parseDesktopFile( @@ -48,62 +48,62 @@ DesktopAppData DesktopFileParser::parseDesktopFile( bool isApplication = false; QTextStream in(&file); // enter the desktop entry definition - while (!in.atEnd() && in.readLine() != "[Desktop Entry]") { + while (!in.atEnd() && in.readLine() != QLatin1String("[Desktop Entry]")) { } // start parsing while (!in.atEnd()) { QString line = in.readLine(); - if (line.startsWith("Icon")) { + if (line.startsWith(QLatin1String("Icon"))) { res.icon = QIcon::fromTheme( - line.mid(line.indexOf("=")+1).trimmed(), + line.mid(line.indexOf(QLatin1String("="))+1).trimmed(), m_defaultIcon); } - else if (!nameLocaleSet && line.startsWith("Name")) { + else if (!nameLocaleSet && line.startsWith(QLatin1String("Name"))) { if (line.startsWith(m_localeName) || line.startsWith(m_localeNameShort)) { - res.name = line.mid(line.indexOf("=")+1).trimmed(); + res.name = line.mid(line.indexOf(QLatin1String("="))+1).trimmed(); nameLocaleSet = true; - } else if (line.startsWith("Name=")) { - res.name = line.mid(line.indexOf("=")+1).trimmed(); + } else if (line.startsWith(QLatin1String("Name="))) { + res.name = line.mid(line.indexOf(QLatin1String("="))+1).trimmed(); } } - else if (!descriptionLocaleSet && line.startsWith("Comment")) { + else if (!descriptionLocaleSet && line.startsWith(QLatin1String("Comment"))) { if (line.startsWith(m_localeDescription) || line.startsWith(m_localeDescriptionShort)) { - res.description = line.mid(line.indexOf("=")+1).trimmed(); + res.description = line.mid(line.indexOf(QLatin1String("="))+1).trimmed(); descriptionLocaleSet = true; - } else if (line.startsWith("Comment=")) { - res.description = line.mid(line.indexOf("=")+1).trimmed(); + } else if (line.startsWith(QLatin1String("Comment="))) { + res.description = line.mid(line.indexOf(QLatin1String("="))+1).trimmed(); } } - else if (line.startsWith("Exec")) { - if (line.contains("%")) { - res.exec = line.mid(line.indexOf("=")+1) + else if (line.startsWith(QLatin1String("Exec"))) { + if (line.contains(QLatin1String("%"))) { + res.exec = line.mid(line.indexOf(QLatin1String("="))+1) .trimmed(); } else { ok = false; break; } } - else if (line.startsWith("Type")) { - if (line.contains("Application")) { + else if (line.startsWith(QLatin1String("Type"))) { + if (line.contains(QLatin1String("Application"))) { isApplication = true; } } - else if (line.startsWith("Categories")) { - res.categories = line.mid(line.indexOf("=")+1).split(";"); + else if (line.startsWith(QLatin1String("Categories"))) { + res.categories = line.mid(line.indexOf(QLatin1String("="))+1).split(QStringLiteral(";")); } - else if (line == "NoDisplay=true") { + else if (line == QLatin1String("NoDisplay=true")) { ok = false; break; } - else if (line == "Terminal=true") { + else if (line == QLatin1String("Terminal=true")) { res.showInTerminal = true; } // ignore the other entries - else if (line.startsWith("[")) { + else if (line.startsWith(QLatin1String("["))) { break; } } diff --git a/src/utils/desktopinfo.cpp b/src/utils/desktopinfo.cpp index 4751164e..f306bc5e 100644 --- a/src/utils/desktopinfo.cpp +++ b/src/utils/desktopinfo.cpp @@ -20,26 +20,26 @@ DesktopInfo::DesktopInfo() { auto e = QProcessEnvironment::systemEnvironment(); - XDG_CURRENT_DESKTOP = e.value("XDG_CURRENT_DESKTOP"); - XDG_SESSION_TYPE = e.value("XDG_SESSION_TYPE"); - WAYLAND_DISPLAY = e.value("WAYLAND_DISPLAY"); - KDE_FULL_SESSION = e.value("KDE_FULL_SESSION"); - GNOME_DESKTOP_SESSION_ID = e.value("GNOME_DESKTOP_SESSION_ID"); - DESKTOP_SESSION = e.value("DESKTOP_SESSION"); + XDG_CURRENT_DESKTOP = e.value(QStringLiteral("XDG_CURRENT_DESKTOP")); + XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE")); + WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY")); + KDE_FULL_SESSION = e.value(QStringLiteral("KDE_FULL_SESSION")); + GNOME_DESKTOP_SESSION_ID = e.value(QStringLiteral("GNOME_DESKTOP_SESSION_ID")); + DESKTOP_SESSION = e.value(QStringLiteral("DESKTOP_SESSION")); } bool DesktopInfo::waylandDectected() { - return XDG_SESSION_TYPE == "wayland" || - WAYLAND_DISPLAY.contains("wayland", Qt::CaseInsensitive); + return XDG_SESSION_TYPE == QLatin1String("wayland") || + WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive); } DesktopInfo::WM DesktopInfo::windowManager() { DesktopInfo::WM res = DesktopInfo::OTHER; - if (XDG_CURRENT_DESKTOP.contains("GNOME", Qt::CaseInsensitive) || + if (XDG_CURRENT_DESKTOP.contains(QLatin1String("GNOME"), Qt::CaseInsensitive) || !GNOME_DESKTOP_SESSION_ID.isEmpty()) { res = DesktopInfo::GNOME; - } else if (!KDE_FULL_SESSION.isEmpty() || DESKTOP_SESSION == "kde-plasma") { + } else if (!KDE_FULL_SESSION.isEmpty() || DESKTOP_SESSION == QLatin1String("kde-plasma")) { res = DesktopInfo::KDE; } return res; diff --git a/src/utils/filenamehandler.cpp b/src/utils/filenamehandler.cpp index d31bcfd6..f2f52596 100644 --- a/src/utils/filenamehandler.cpp +++ b/src/utils/filenamehandler.cpp @@ -33,7 +33,7 @@ QString FileNameHandler::parsedPattern() { QString FileNameHandler::parseFilename(const QString &name) { QString res = name; if (name.isEmpty()) { - res = "%F_%H-%M"; + res = QLatin1String("%F_%H-%M"); } std::time_t t = std::time(NULL); @@ -45,7 +45,7 @@ QString FileNameHandler::parseFilename(const QString &name) { free(tempData); // add the parsed pattern in a correct format for the filesystem - res = res.replace("/", "⁄").replace(":", "-"); + res = res.replace(QLatin1String("/"), QStringLiteral("⁄")).replace(QLatin1String(":"), QLatin1String("-")); return res; } @@ -87,14 +87,14 @@ char * FileNameHandler::QStringTocharArr(const QString &s) { void FileNameHandler::fixPath(QString &directory, QString &filename) { // add '/' at the end of the directory - if (!directory.endsWith("/")) { - directory += "/"; + if (!directory.endsWith(QLatin1String("/"))) { + directory += QLatin1String("/"); } // add numeration in case of repeated filename in the directory // find unused name adding _n where n is a number QFileInfo checkFile(directory + filename + ".png"); if (checkFile.exists()) { - filename += "_"; + filename += QLatin1String("_"); int i = 1; while (true) { checkFile.setFile( diff --git a/src/utils/pathinfo.cpp b/src/utils/pathinfo.cpp index a8bbaa5f..5d2cb2aa 100644 --- a/src/utils/pathinfo.cpp +++ b/src/utils/pathinfo.cpp @@ -21,11 +21,11 @@ #include const QString PathInfo::whiteIconPath() { - return ":/img/material/white/"; + return QStringLiteral(":/img/material/white/"); } const QString PathInfo::blackIconPath() { - return ":/img/material/black/"; + return QStringLiteral(":/img/material/black/"); } QStringList PathInfo::translationsPaths() { @@ -34,10 +34,10 @@ QStringList PathInfo::translationsPaths() { QString trPath = QDir::toNativeSeparators(binaryPath + "/translations") ; #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) return QStringList() - << QString(APP_PREFIX) + "/share/flameshot/translations" + << QStringLiteral(APP_PREFIX) + "/share/flameshot/translations" << trPath - << "/usr/share/flameshot/translations" - << "/usr/local/share/flameshot/translations"; + << QStringLiteral("/usr/share/flameshot/translations") + << QStringLiteral("/usr/local/share/flameshot/translations"); #elif defined(Q_OS_WIN) return QStringList() << trPath; diff --git a/src/utils/screengrabber.cpp b/src/utils/screengrabber.cpp index 44801951..90a83f3c 100644 --- a/src/utils/screengrabber.cpp +++ b/src/utils/screengrabber.cpp @@ -47,7 +47,7 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool &ok) { QDBusInterface gnomeInterface(QStringLiteral("org.gnome.Shell"), QStringLiteral("/org/gnome/Shell/Screenshot"), QStringLiteral("org.gnome.Shell.Screenshot")); - QDBusReply reply = gnomeInterface.call("Screenshot", false, false, path); + QDBusReply reply = gnomeInterface.call(QStringLiteral("Screenshot"), false, false, path); if (reply.value()) { res = QPixmap(path); QFile dbusResult(path); @@ -61,7 +61,7 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool &ok) { QDBusInterface kwinInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QStringLiteral("org.kde.kwin.Screenshot")); - QDBusReply reply = kwinInterface.call("screenshotFullscreen"); + QDBusReply reply = kwinInterface.call(QStringLiteral("screenshotFullscreen")); res = QPixmap(reply.value()); if (!res.isNull()) { QFile dbusResult(reply.value()); diff --git a/src/utils/screenshotsaver.cpp b/src/utils/screenshotsaver.cpp index 3c5cb6e9..5ac5badd 100644 --- a/src/utils/screenshotsaver.cpp +++ b/src/utils/screenshotsaver.cpp @@ -38,7 +38,7 @@ bool ScreenshotSaver::saveToFilesystem(const QPixmap &capture, const QString &path) { QString completePath = FileNameHandler().generateAbsolutePath(path); - completePath += ".png"; + completePath += QLatin1String(".png"); bool ok = capture.save(completePath); QString saveMessage; @@ -66,14 +66,14 @@ bool ScreenshotSaver::saveToFilesystemGUI(const QPixmap &capture) { break; } - if (!savePath.endsWith(".png")) { - savePath += ".png"; + if (!savePath.endsWith(QLatin1String(".png"))) { + savePath += QLatin1String(".png"); } ok = capture.save(savePath); if (ok) { - QString pathNoFile = savePath.left(savePath.lastIndexOf("/")); + QString pathNoFile = savePath.left(savePath.lastIndexOf(QLatin1String("/"))); ConfigHandler().setSavePath(pathNoFile); QString msg = QObject::tr("Capture saved as ") + savePath; SystemNotification().sendMessage(msg); diff --git a/src/utils/systemnotification.cpp b/src/utils/systemnotification.cpp index ac92f6fe..c35a4574 100644 --- a/src/utils/systemnotification.cpp +++ b/src/utils/systemnotification.cpp @@ -47,7 +47,7 @@ void SystemNotification::sendMessage( << QStringList() //actions << QVariantMap() //hints << timeout; //timeout - m_interface->callWithArgumentList(QDBus::AutoDetect, "Notify", args); + m_interface->callWithArgumentList(QDBus::AutoDetect, QStringLiteral("Notify"), args); #else auto c = Controller::getInstance(); c->sendTrayNotification(text, title, timeout); diff --git a/src/widgets/capture/capturebutton.cpp b/src/widgets/capture/capturebutton.cpp index 6d2af48d..71022dde 100644 --- a/src/widgets/capture/capturebutton.cpp +++ b/src/widgets/capture/capturebutton.cpp @@ -129,7 +129,7 @@ void CaptureButton::animatedShow() { if(!isVisible()) { show(); m_emergeAnimation->start(); - connect(m_emergeAnimation, &QPropertyAnimation::finished, this, [this](){ + connect(m_emergeAnimation, &QPropertyAnimation::finished, this, [](){ }); } } diff --git a/src/widgets/capture/notifierbox.cpp b/src/widgets/capture/notifierbox.cpp index a060267c..fbd43c9d 100644 --- a/src/widgets/capture/notifierbox.cpp +++ b/src/widgets/capture/notifierbox.cpp @@ -63,5 +63,5 @@ void NotifierBox::showMessage(const QString &msg) { void NotifierBox::showColor(const QColor &color) { Q_UNUSED(color); - m_message = ""; + m_message = QLatin1String(""); } diff --git a/src/widgets/infowindow.cpp b/src/widgets/infowindow.cpp index 28600472..b39fe293 100644 --- a/src/widgets/infowindow.cpp +++ b/src/widgets/infowindow.cpp @@ -121,7 +121,7 @@ void InfoWindow::initLabels() { QLabel *licenseTitleLabel = new QLabel(tr("License"), this); licenseTitleLabel->setAlignment(Qt::AlignHCenter); m_layout->addWidget(licenseTitleLabel); - QLabel *licenseLabel = new QLabel("GPLv3+", this); + QLabel *licenseLabel = new QLabel(QStringLiteral("GPLv3+"), this); licenseLabel->setAlignment(Qt::AlignHCenter); m_layout->addWidget(licenseLabel); m_layout->addStretch(); @@ -129,7 +129,7 @@ void InfoWindow::initLabels() { QLabel *versionTitleLabel = new QLabel(tr("Version"), this); versionTitleLabel->setAlignment(Qt::AlignHCenter); m_layout->addWidget(versionTitleLabel); - QString versionMsg = "Flameshot " + QString(APP_VERSION) + "\nCompiled with Qt " + QString versionMsg = "Flameshot " + QStringLiteral(APP_VERSION) + "\nCompiled with Qt " + QT_VERSION_STR; QLabel *versionLabel = new QLabel(versionMsg, this); versionLabel->setAlignment(Qt::AlignHCenter); diff --git a/src/widgets/loadspinner.cpp b/src/widgets/loadspinner.cpp index 44478ad5..470d813b 100644 --- a/src/widgets/loadspinner.cpp +++ b/src/widgets/loadspinner.cpp @@ -32,7 +32,7 @@ LoadSpinner::LoadSpinner(QWidget *parent) : updateFrame(); // init timer m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), this, SLOT(rotate())); + connect(m_timer, &QTimer::timeout, this, &LoadSpinner::rotate); m_timer->setInterval(30); } diff --git a/src/widgets/panel/sidepanelwidget.cpp b/src/widgets/panel/sidepanelwidget.cpp index 47cbc88a..f8072968 100644 --- a/src/widgets/panel/sidepanelwidget.cpp +++ b/src/widgets/panel/sidepanelwidget.cpp @@ -78,7 +78,7 @@ SidePanelWidget::SidePanelWidget(QPixmap *p, QWidget *parent) : QString modifier = isDark ? PathInfo::whiteIconPath() : PathInfo::blackIconPath(); QIcon grabIcon(modifier + "colorize.svg"); - m_colorGrabButton = new QPushButton(grabIcon, ""); + m_colorGrabButton = new QPushButton(grabIcon, QLatin1String("")); updateGrabButton(false); connect(m_colorGrabButton, &QPushButton::pressed, this, &SidePanelWidget::colorGrabberActivated); @@ -96,7 +96,7 @@ SidePanelWidget::SidePanelWidget(QPixmap *p, QWidget *parent) : void SidePanelWidget::updateColor(const QColor &c) { m_color = c; m_colorLabel->setStyleSheet( - QString("QLabel { background-color : %1; }").arg(c.name())); + QStringLiteral("QLabel { background-color : %1; }").arg(c.name())); m_colorWheel->setColor(m_color); } @@ -109,7 +109,7 @@ void SidePanelWidget::updateThickness(const int &t) void SidePanelWidget::updateColorNoWheel(const QColor &c) { m_color = c; m_colorLabel->setStyleSheet( - QString("QLabel { background-color : %1; }").arg(c.name())); + QStringLiteral("QLabel { background-color : %1; }").arg(c.name())); } void SidePanelWidget::updateCurrentThickness() diff --git a/src/widgets/panel/utilitypanel.cpp b/src/widgets/panel/utilitypanel.cpp index 48b4a7aa..a17fe9dd 100644 --- a/src/widgets/panel/utilitypanel.cpp +++ b/src/widgets/panel/utilitypanel.cpp @@ -98,7 +98,7 @@ void UtilityPanel::initInternalPanel() { QColor bgColor = palette().background().color(); bgColor.setAlphaF(0.0); - m_internalPanel->setStyleSheet(QString("QScrollArea {background-color: %1}") + m_internalPanel->setStyleSheet(QStringLiteral("QScrollArea {background-color: %1}") .arg(bgColor.name())); m_internalPanel->hide(); }