Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize strings #14

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions src/mat/defappmatcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "matglobals.h"

#include "xdgdesktopfile.h"
#include "xdgmacros.h"
#include "xdgmimeapps.h"

#include <QCommandLineOption>
Expand All @@ -32,6 +31,8 @@

#include <iostream>

using namespace Qt::Literals::StringLiterals;

enum DefAppCommandMode {
CommandModeGetDefApp,
CommandModeSetDefApp
Expand All @@ -48,13 +49,13 @@ struct DefAppData {
static CommandLineParseResult parseCommandLine(QCommandLineParser *parser, DefAppData *data, QString *errorMessage)
{
parser->clearPositionalArguments();
parser->setApplicationDescription(QL1S("Get/Set the default application for a mimetype"));
parser->setApplicationDescription(u"Get/Set the default application for a mimetype"_s);

parser->addPositionalArgument(QL1S("defapp"), QSL("mimetype(s)"),
parser->addPositionalArgument(u"defapp"_s, u"mimetype(s)"_s,
QCoreApplication::tr("[mimetype(s)...]"));

const QCommandLineOption defAppNameOption(QStringList() << QSL("s") << QSL("set"),
QSL("Application to be set as default"), QSL("app name"));
const QCommandLineOption defAppNameOption(QStringList() << u"s"_s << u"set"_s,
u"Application to be set as default"_s, u"app name"_s);

parser->addOption(defAppNameOption);
const QCommandLineOption helpOption = parser->addHelpOption();
Expand All @@ -69,7 +70,7 @@ static CommandLineParseResult parseCommandLine(QCommandLineParser *parser, DefAp
return CommandLineVersionRequested;
}

if (parser->isSet(helpOption) || parser->isSet(QSL("help-all"))) {
if (parser->isSet(helpOption) || parser->isSet(u"help-all"_s)) {
return CommandLineHelpRequested;
}

Expand All @@ -80,21 +81,21 @@ static CommandLineParseResult parseCommandLine(QCommandLineParser *parser, DefAp
defAppName = parser->value(defAppNameOption);

if (isDefAppNameSet && defAppName.isEmpty()) {
*errorMessage = QSL("No application name");
*errorMessage = u"No application name"_s;
return CommandLineError;
}

QStringList mimeTypes = parser->positionalArguments();

if (mimeTypes.size() < 2) {
*errorMessage = QSL("MimeType missing");
*errorMessage = u"MimeType missing"_s;
return CommandLineError;
}

mimeTypes.removeAt(0);

if (!isDefAppNameSet && mimeTypes.size() > 1) {
*errorMessage = QSL("Only one mimeType, please");
*errorMessage = u"Only one mimeType, please"_s;
return CommandLineError;
}

Expand All @@ -106,8 +107,8 @@ static CommandLineParseResult parseCommandLine(QCommandLineParser *parser, DefAp
}

DefAppMatCommand::DefAppMatCommand(QCommandLineParser *parser)
: MatCommandInterface(QL1S("defapp"),
QL1S("Get/Set the default application for a mimetype"),
: MatCommandInterface(u"defapp"_s,
u"Get/Set the default application for a mimetype"_s,
parser)
{
Q_CHECK_PTR(parser);
Expand Down Expand Up @@ -148,22 +149,22 @@ int DefAppMatCommand::run(const QStringList & /*arguments*/)
std::cout << qPrintable(XdgDesktopFile::id(defApp->fileName())) << "\n";
delete defApp;
} else {
// std::cout << qPrintable(QSL("No default application for '%1'\n").arg(mimeType));
// std::cout << qPrintable(u"No default application for '%1'\n"_s.arg(mimeType));
}
} else { // Set default App
XdgDesktopFile app;
if (!app.load(data.defAppName)) {
std::cerr << qPrintable(QSL("Could not find find '%1'\n").arg(data.defAppName));
std::cerr << qPrintable(u"Could not find find '%1'\n"_s.arg(data.defAppName));
return EXIT_FAILURE;
}

XdgMimeApps apps;
for (const QString &mimeType : std::as_const(data.mimeTypes)) {
if (!apps.setDefaultApp(mimeType, app)) {
std::cerr << qPrintable(QSL("Could not set '%1' as default for '%2'\n").arg(app.fileName(), mimeType));
std::cerr << qPrintable(u"Could not set '%1' as default for '%2'\n"_s.arg(app.fileName(), mimeType));
success = false;
} else {
std::cout << qPrintable(QSL("Set '%1' as default for '%2'\n").arg(app.fileName(), mimeType));
std::cout << qPrintable(u"Set '%1' as default for '%2'\n"_s.arg(app.fileName(), mimeType));
}
}
}
Expand Down
35 changes: 18 additions & 17 deletions src/mat/defemailclientmatcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "defemailclientmatcommand.h"

#include "matglobals.h"
#include "xdgmacros.h"
#include "xdgdefaultapps.h"
#include "xdgdesktopfile.h"

Expand All @@ -34,6 +33,8 @@

#include <iostream>

using namespace Qt::Literals::StringLiterals;

enum DefEmailClientCommandMode {
CommandModeGetDefEmailClient,
CommandModeSetDefEmailClient,
Expand All @@ -50,15 +51,15 @@ struct DefEmailClientData {
static CommandLineParseResult parseCommandLine(QCommandLineParser *parser, DefEmailClientData *data, QString *errorMessage)
{
parser->clearPositionalArguments();
parser->setApplicationDescription(QL1S("Get/Set the default email client"));
parser->setApplicationDescription(u"Get/Set the default email client"_s);

parser->addPositionalArgument(QL1S("def-email-client"), QL1S());
parser->addPositionalArgument(u"def-email-client"_s, ""_L1);

const QCommandLineOption defEmailClientNameOption(QStringList() << QSL("s") << QSL("set"),
QSL("Email Client to be set as default"), QSL("email client"));
const QCommandLineOption defEmailClientNameOption(QStringList() << u"s"_s << u"set"_s,
u"Email Client to be set as default"_s, u"email client"_s);

const QCommandLineOption listAvailableOption(QStringList() << QSL("l") << QSL("list-available"),
QSL("List available email clients"));
const QCommandLineOption listAvailableOption(QStringList() << u"l"_s << u"list-available"_s,
u"List available email clients"_s);

parser->addOption(defEmailClientNameOption);
parser->addOption(listAvailableOption);
Expand All @@ -74,7 +75,7 @@ static CommandLineParseResult parseCommandLine(QCommandLineParser *parser, DefEm
return CommandLineVersionRequested;
}

if (parser->isSet(helpOption) || parser->isSet(QSL("help-all"))) {
if (parser->isSet(helpOption) || parser->isSet(u"help-all"_s)) {
return CommandLineHelpRequested;
}

Expand All @@ -89,18 +90,18 @@ static CommandLineParseResult parseCommandLine(QCommandLineParser *parser, DefEm
posArgs.removeAt(0);

if (isDefEmailClientNameSet && !posArgs.empty()) {
*errorMessage = QSL("Extra arguments given: ");
errorMessage->append(posArgs.join(QLatin1Char(',')));
*errorMessage = u"Extra arguments given: "_s;
errorMessage->append(posArgs.join(u','));
return CommandLineError;
}

if (!isDefEmailClientNameSet && !posArgs.empty()) {
*errorMessage = QSL("To set the default email client use the -s/--set option");
*errorMessage = u"To set the default email client use the -s/--set option"_s;
return CommandLineError;
}

if (isListAvailableSet && (isDefEmailClientNameSet || !posArgs.empty())) {
*errorMessage = QSL("list-available can't be used with other options and doesn't take arguments");
*errorMessage = u"list-available can't be used with other options and doesn't take arguments"_s;
return CommandLineError;
}

Expand All @@ -115,8 +116,8 @@ static CommandLineParseResult parseCommandLine(QCommandLineParser *parser, DefEm
}

DefEmailClientMatCommand::DefEmailClientMatCommand(QCommandLineParser *parser)
: MatCommandInterface(QL1S("def-email-client"),
QSL("Get/Set the default email client"),
: MatCommandInterface(u"def-email-client"_s,
u"Get/Set the default email client"_s,
parser)
{
Q_CHECK_PTR(parser);
Expand Down Expand Up @@ -167,13 +168,13 @@ int DefEmailClientMatCommand::run(const QStringList & /*arguments*/)
XdgDesktopFile toSetDefEmailClient;
if (toSetDefEmailClient.load(data.defEmailClientName)) {
if (XdgDefaultApps::setEmailClient(toSetDefEmailClient)) {
std::cout << qPrintable(QSL("Set '%1' as the default email client\n").arg(toSetDefEmailClient.fileName()));
std::cout << qPrintable(u"Set '%1' as the default email client\n"_s.arg(toSetDefEmailClient.fileName()));
} else {
std::cerr << qPrintable(QSL("Could not set '%1' as the default email client\n").arg(toSetDefEmailClient.fileName()));
std::cerr << qPrintable(u"Could not set '%1' as the default email client\n"_s.arg(toSetDefEmailClient.fileName()));
success = false;
}
} else { // could not load application file
std::cerr << qPrintable(QSL("Could not find find '%1'\n").arg(data.defEmailClientName));
std::cerr << qPrintable(u"Could not find find '%1'\n"_s.arg(data.defEmailClientName));
success = false;
}
}
Expand Down
35 changes: 18 additions & 17 deletions src/mat/deffilemanagermatcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "deffilemanagermatcommand.h"

#include "matglobals.h"
#include "xdgmacros.h"
#include "xdgdefaultapps.h"
#include "xdgdesktopfile.h"

Expand All @@ -34,6 +33,8 @@

#include <iostream>

using namespace Qt::Literals::StringLiterals;

enum DefFileManagerCommandMode {
CommandModeGetDefFileManager,
CommandModeSetDefFileManager,
Expand All @@ -50,15 +51,15 @@ struct DefFileManagerData {
static CommandLineParseResult parseCommandLine(QCommandLineParser *parser, DefFileManagerData *data, QString *errorMessage)
{
parser->clearPositionalArguments();
parser->setApplicationDescription(QL1S("Get/Set the default file manager"));
parser->setApplicationDescription(u"Get/Set the default file manager"_s);

parser->addPositionalArgument(QL1S("def-file-manager"), QL1S());
parser->addPositionalArgument(u"def-file-manager"_s, ""_L1);

const QCommandLineOption defFileManagerNameOption(QStringList() << QSL("s") << QSL("set"),
QSL("File Manager to be set as default"), QSL("file manager"));
const QCommandLineOption defFileManagerNameOption(QStringList() << u"s"_s << u"set"_s,
u"File Manager to be set as default"_s, u"file manager"_s);

const QCommandLineOption listAvailableOption(QStringList() << QSL("l") << QSL("list-available"),
QSL("List available file managers"));
const QCommandLineOption listAvailableOption(QStringList() << u"l"_s << u"list-available"_s,
u"List available file managers"_s);

parser->addOption(defFileManagerNameOption);
parser->addOption(listAvailableOption);
Expand All @@ -74,7 +75,7 @@ static CommandLineParseResult parseCommandLine(QCommandLineParser *parser, DefFi
return CommandLineVersionRequested;
}

if (parser->isSet(helpOption) || parser->isSet(QSL("help-all"))) {
if (parser->isSet(helpOption) || parser->isSet(u"help-all"_s)) {
return CommandLineHelpRequested;
}

Expand All @@ -89,18 +90,18 @@ static CommandLineParseResult parseCommandLine(QCommandLineParser *parser, DefFi
posArgs.removeAt(0);

if (isDefFileManagerNameSet && !posArgs.empty()) {
*errorMessage = QSL("Extra arguments given: ");
errorMessage->append(posArgs.join(QLatin1Char(',')));
*errorMessage = u"Extra arguments given: "_s;
errorMessage->append(posArgs.join(u','));
return CommandLineError;
}

if (!isDefFileManagerNameSet && !posArgs.empty()) {
*errorMessage = QSL("To set the default file manager use the -s/--set option");
*errorMessage = u"To set the default file manager use the -s/--set option"_s;
return CommandLineError;
}

if (isListAvailableSet && (isDefFileManagerNameSet || !posArgs.empty())) {
*errorMessage = QSL("list-available can't be used with other options and doesn't take arguments");
*errorMessage = u"list-available can't be used with other options and doesn't take arguments"_s;
return CommandLineError;
}

Expand All @@ -115,8 +116,8 @@ static CommandLineParseResult parseCommandLine(QCommandLineParser *parser, DefFi
}

DefFileManagerMatCommand::DefFileManagerMatCommand(QCommandLineParser *parser)
: MatCommandInterface(QL1S("def-file-manager"),
QSL("Get/Set the default file manager"),
: MatCommandInterface(u"def-file-manager"_s,
u"Get/Set the default file manager"_s,
parser)
{
Q_CHECK_PTR(parser);
Expand Down Expand Up @@ -167,13 +168,13 @@ int DefFileManagerMatCommand::run(const QStringList & /*arguments*/)
XdgDesktopFile toSetDefFileManager;
if (toSetDefFileManager.load(data.defFileManagerName)) {
if (XdgDefaultApps::setFileManager(toSetDefFileManager)) {
std::cout << qPrintable(QSL("Set '%1' as the default file manager\n").arg(toSetDefFileManager.fileName()));
std::cout << qPrintable(u"Set '%1' as the default file manager\n"_s.arg(toSetDefFileManager.fileName()));
} else {
std::cerr << qPrintable(QSL("Could not set '%1' as the default file manager\n").arg(toSetDefFileManager.fileName()));
std::cerr << qPrintable(u"Could not set '%1' as the default file manager\n"_s.arg(toSetDefFileManager.fileName()));
success = false;
}
} else { // could not load application file
std::cerr << qPrintable(QSL("Could not find find '%1'\n").arg(data.defFileManagerName));
std::cerr << qPrintable(u"Could not find find '%1'\n"_s.arg(data.defFileManagerName));
success = false;
}
}
Expand Down
Loading