Skip to content
Snippets Groups Projects
Commit 3765c89f authored by akiraohgaki's avatar akiraohgaki
Browse files

C++11 style

parent 51320032
No related branches found
No related tags found
No related merge requests found
CONFIG += c++11
QT += \
core \
gui \
......
......@@ -22,19 +22,19 @@ QJsonObject ConfigHandler::getAppConfigApplication()
QJsonObject ConfigHandler::getAppConfigInstallTypes()
{
if (appConfigInstallTypes_.isEmpty()) {
QJsonObject installTypes = appConfig_.get("install_types");
for (const QString &key : installTypes.keys()) {
QJsonObject installtype = installTypes[key].toObject();
auto installTypes = appConfig_.get("install_types");
for (const auto &key : installTypes.keys()) {
auto installtype = installTypes[key].toObject();
installtype["destination"] = convertPathString(installtype["destination"].toString());
installtype["generic_destination"] = convertPathString(installtype["generic_destination"].toString());
installTypes[key] = installtype;
}
QJsonObject installTypesAlias = appConfig_.get("install_types_alias");
for (const QString &key : installTypesAlias.keys()) {
QJsonObject installTypeAlias = installTypesAlias[key].toObject();
QString baseKey = installTypeAlias["base"].toString();
auto installTypesAlias = appConfig_.get("install_types_alias");
for (const auto &key : installTypesAlias.keys()) {
auto installTypeAlias = installTypesAlias[key].toObject();
auto baseKey = installTypeAlias["base"].toString();
if (installTypes.contains(baseKey)) {
QJsonObject installType = installTypes[baseKey].toObject();
auto installType = installTypes[baseKey].toObject();
installType["base"] = baseKey;
installType["name"] = installTypeAlias["name"].toString();
installTypes[key] = installType;
......@@ -98,14 +98,14 @@ bool ConfigHandler::setUsrConfigProvidersProvider(const QString &providerKey, co
"_providerfile": "https://example.com/ocs/providers.xml"
}
*/
QJsonObject providers = getUsrConfigProviders();
auto providers = getUsrConfigProviders();
providers[providerKey] = object;
return setUsrConfigProviders(providers);
}
bool ConfigHandler::removeUsrConfigProvidersProvider(const QString &providerKey)
{
QJsonObject providers = getUsrConfigProviders();
auto providers = getUsrConfigProviders();
providers.remove(providerKey);
return setUsrConfigProviders(providers);
}
......@@ -126,21 +126,21 @@ bool ConfigHandler::setUsrConfigCategoriesProvider(const QString &providerKey, c
}
}
*/
QJsonObject categories = getUsrConfigCategories();
auto categories = getUsrConfigCategories();
categories[providerKey] = object;
return setUsrConfigCategories(categories);
}
bool ConfigHandler::removeUsrConfigCategoriesProvider(const QString &providerKey)
{
QJsonObject categories = getUsrConfigCategories();
auto categories = getUsrConfigCategories();
categories.remove(providerKey);
return setUsrConfigCategories(categories);
}
bool ConfigHandler::setUsrConfigCategoriesInstallType(const QString &providerKey, const QString &categoryKey, const QString &installType)
{
QJsonObject categories = getUsrConfigCategories();
auto categories = getUsrConfigCategories();
QJsonObject providerCategories;
if (categories.contains(providerKey)) {
providerCategories = categories[providerKey].toObject();
......@@ -171,21 +171,21 @@ bool ConfigHandler::setUsrConfigInstalledItemsItem(const QString &itemKey, const
"installed_at": 1483658977219
}
*/
QJsonObject installedItems = getUsrConfigInstalledItems();
auto installedItems = getUsrConfigInstalledItems();
installedItems[itemKey] = object;
return setUsrConfigInstalledItems(installedItems);
}
bool ConfigHandler::removeUsrConfigInstalledItemsItem(const QString &itemKey)
{
QJsonObject installedItems = getUsrConfigInstalledItems();
auto installedItems = getUsrConfigInstalledItems();
installedItems.remove(itemKey);
return setUsrConfigInstalledItems(installedItems);
}
QString ConfigHandler::convertPathString(const QString &path)
{
QString newPath = path;
auto newPath = path;
if (newPath.contains("$HOME")) {
newPath.replace("$HOME", qtlib::Dir::homePath());
}
......
......@@ -30,7 +30,7 @@ void ItemHandler::getItem(const QString &command, const QString &url, const QStr
const QString &providerKey, const QString &contentId)
{
// Use URL as unique key for metadata, network resource, and installed item
QString itemKey = url;
auto itemKey = url;
QJsonObject metadata;
metadata["command"] = command;
......@@ -48,7 +48,7 @@ void ItemHandler::getItem(const QString &command, const QString &url, const QStr
QJsonObject result;
result["metadata"] = metadata;
QJsonObject itemMetadataSet = metadataSet();
auto itemMetadataSet = metadataSet();
if (itemMetadataSet.contains(itemKey)) {
result["status"] = QString("error_downloadstart");
......@@ -60,7 +60,7 @@ void ItemHandler::getItem(const QString &command, const QString &url, const QStr
itemMetadataSet[itemKey] = metadata;
setMetadataSet(itemMetadataSet);
qtlib::NetworkResource *resource = new qtlib::NetworkResource(itemKey, QUrl(url), true, this);
auto *resource = new qtlib::NetworkResource(itemKey, QUrl(url), true, this);
connect(resource, &qtlib::NetworkResource::downloadProgress, this, &ItemHandler::downloadProgress);
connect(resource, &qtlib::NetworkResource::finished, this, &ItemHandler::networkResourceFinished);
resource->get();
......@@ -128,14 +128,14 @@ void ItemHandler::uninstall(const QString &itemKey)
result["message"] = tr("Uninstalling");
emit uninstallStarted(result);
QJsonObject installedItem = configHandler_->getUsrConfigInstalledItems()[itemKey].toObject();
QString installType = installedItem["install_type"].toString();
auto installedItem = configHandler_->getUsrConfigInstalledItems()[itemKey].toObject();
auto installType = installedItem["install_type"].toString();
qtlib::Dir destDir;
#ifdef QTLIB_UNIX
destDir.setPath(configHandler_->getAppConfigInstallTypes()[installType].toObject()["destination"].toString());
for (const QJsonValue &filename : installedItem["files"].toArray()) {
for (const auto &filename : installedItem["files"].toArray()) {
QFileInfo fileInfo(destDir.path() + "/" + filename.toString());
// plasmapkg: Installation process has should be saved plasmapkg into destination directory
......@@ -180,7 +180,7 @@ void ItemHandler::uninstall(const QString &itemKey)
#else
destDir.setPath(configHandler_->getAppConfigInstallTypes()[installType].toObject()["generic_destination"].toString());
for (const QJsonValue &filename : installedItem["files"].toArray()) {
for (const auto &filename : installedItem["files"].toArray()) {
QFileInfo fileInfo(destDir.path() + "/" + filename.toString());
if (fileInfo.isDir()) {
qtlib::Dir(fileInfo.filePath()).remove();
......@@ -200,10 +200,10 @@ void ItemHandler::uninstall(const QString &itemKey)
void ItemHandler::networkResourceFinished(qtlib::NetworkResource *resource)
{
QString itemKey = resource->id();
auto itemKey = resource->id();
QJsonObject itemMetadataSet = metadataSet();
QJsonObject metadata = itemMetadataSet[itemKey].toObject();
auto itemMetadataSet = metadataSet();
auto metadata = itemMetadataSet[itemKey].toObject();
QJsonObject result;
result["metadata"] = metadata;
......@@ -238,10 +238,10 @@ void ItemHandler::setMetadataSet(const QJsonObject &metadataSet)
void ItemHandler::saveDownloadedFile(qtlib::NetworkResource *resource)
{
QString itemKey = resource->id();
auto itemKey = resource->id();
QJsonObject itemMetadataSet = metadataSet();
QJsonObject metadata = itemMetadataSet[itemKey].toObject();
auto itemMetadataSet = metadataSet();
auto metadata = itemMetadataSet[itemKey].toObject();
itemMetadataSet.remove(itemKey);
setMetadataSet(itemMetadataSet);
......@@ -252,8 +252,8 @@ void ItemHandler::saveDownloadedFile(qtlib::NetworkResource *resource)
result["message"] = tr("Saving");
emit saveStarted(result);
QString filename = metadata["filename"].toString();
QString installType = metadata["install_type"].toString();
auto filename = metadata["filename"].toString();
auto installType = metadata["install_type"].toString();
qtlib::Dir destDir(configHandler_->getAppConfigInstallTypes()[installType].toObject()["destination"].toString());
destDir.make();
......@@ -277,10 +277,10 @@ void ItemHandler::saveDownloadedFile(qtlib::NetworkResource *resource)
void ItemHandler::installDownloadedFile(qtlib::NetworkResource *resource)
{
// Installation pre-process
QString itemKey = resource->id();
auto itemKey = resource->id();
QJsonObject itemMetadataSet = metadataSet();
QJsonObject metadata = itemMetadataSet[itemKey].toObject();
auto itemMetadataSet = metadataSet();
auto metadata = itemMetadataSet[itemKey].toObject();
itemMetadataSet.remove(itemKey);
setMetadataSet(itemMetadataSet);
......@@ -291,10 +291,10 @@ void ItemHandler::installDownloadedFile(qtlib::NetworkResource *resource)
result["message"] = tr("Saving");
emit saveStarted(result);
QString filename = metadata["filename"].toString();
QString installType = metadata["install_type"].toString();
auto filename = metadata["filename"].toString();
auto installType = metadata["install_type"].toString();
QString prefix = configHandler_->getAppConfigApplication()["id"].toString() + "_" + filename;
auto prefix = configHandler_->getAppConfigApplication()["id"].toString() + "_" + filename;
qtlib::Dir tempDir(qtlib::Dir::tempPath() + "/" + prefix);
tempDir.make();
qtlib::Dir tempDestDir(tempDir.path() + "/dest");
......@@ -392,7 +392,7 @@ void ItemHandler::installDownloadedFile(qtlib::NetworkResource *resource)
destDir.make();
QJsonArray installedFiles;
for (const QFileInfo &fileInfo : tempDestDir.list()) {
for (const auto &fileInfo : tempDestDir.list()) {
installedFiles.append(QJsonValue(fileInfo.fileName()));
if (fileInfo.isDir()) {
qtlib::Dir(fileInfo.filePath()).move(destDir.path() + "/" + fileInfo.fileName());
......
......@@ -13,13 +13,13 @@ OcsApiHandler::OcsApiHandler(ConfigHandler *configHandler, QObject *parent)
bool OcsApiHandler::addProviders(const QString &providerFileUrl)
{
QJsonArray providers = qtlib::OcsApi::getProviderFile(QUrl(providerFileUrl));
auto providers = qtlib::OcsApi::getProviderFile(QUrl(providerFileUrl));
if (!providers.isEmpty()) {
for (const QJsonValue &providerValue : providers) {
QJsonObject provider = providerValue.toObject();
for (const auto &providerValue : providers) {
auto provider = providerValue.toObject();
if (provider.contains("location")) {
// Use location (API base URL) as unique key
QString providerKey = provider["location"].toString();
auto providerKey = provider["location"].toString();
if (configHandler_->setUsrConfigProvidersProvider(providerKey, provider)) {
updateCategories(providerKey, true);
}
......@@ -41,9 +41,9 @@ bool OcsApiHandler::removeProvider(const QString &providerKey)
bool OcsApiHandler::updateAllCategories(bool force)
{
QJsonObject providers = configHandler_->getUsrConfigProviders();
auto providers = configHandler_->getUsrConfigProviders();
if (!providers.isEmpty()) {
for (const QString &providerKey : providers.keys()) {
for (const auto &providerKey : providers.keys()) {
updateCategories(providerKey, force);
}
return true;
......@@ -53,14 +53,14 @@ bool OcsApiHandler::updateAllCategories(bool force)
bool OcsApiHandler::updateCategories(const QString &providerKey, bool force)
{
QJsonObject providers = configHandler_->getUsrConfigProviders();
auto providers = configHandler_->getUsrConfigProviders();
if (!providers.contains(providerKey)) {
return false;
}
QString baseUrl = providers[providerKey].toObject()["location"].toString();
QJsonObject response = qtlib::OcsApi(baseUrl, QUrl(baseUrl)).getContentCategories();
auto baseUrl = providers[providerKey].toObject()["location"].toString();
auto response = qtlib::OcsApi(baseUrl, QUrl(baseUrl)).getContentCategories();
if (!response.contains("data")) {
return false;
......@@ -69,7 +69,7 @@ bool OcsApiHandler::updateCategories(const QString &providerKey, bool force)
// Data type variation workaround, convert object to array
QJsonArray responseData;
if (response["data"].isObject()) {
for (const QJsonValue &dataValue : response["data"].toObject()) {
for (const auto &dataValue : response["data"].toObject()) {
responseData.append(dataValue);
}
}
......@@ -77,17 +77,17 @@ bool OcsApiHandler::updateCategories(const QString &providerKey, bool force)
responseData = response["data"].toArray();
}
QJsonObject installTypes = configHandler_->getAppConfigInstallTypes();
auto installTypes = configHandler_->getAppConfigInstallTypes();
QJsonObject categories = configHandler_->getUsrConfigCategories();
auto categories = configHandler_->getUsrConfigCategories();
QJsonObject providerCategories;
if (!force && categories.contains(providerKey)) {
providerCategories = categories[providerKey].toObject();
}
QJsonObject newProviderCategories;
for (const QJsonValue &dataValue : responseData) {
QJsonObject data = dataValue.toObject();
for (const auto &dataValue : responseData) {
auto data = dataValue.toObject();
// Data type variation workaround, convert int to string
QString id;
......@@ -99,9 +99,9 @@ bool OcsApiHandler::updateCategories(const QString &providerKey, bool force)
}
// Use category id as unique key
QString categoryKey = id;
auto categoryKey = id;
QString name = data["name"].toString();
auto name = data["name"].toString();
// display_name: Not compatible to legacy OCS-API
if (data.contains("display_name") && data["display_name"].toString() != "") {
name = data["display_name"].toString();
......@@ -113,7 +113,7 @@ bool OcsApiHandler::updateCategories(const QString &providerKey, bool force)
parentId = data["parent_id"].toString();
}
QString installType = configHandler_->getAppConfigApplication()["options"].toObject()["default_install_type"].toString();
auto installType = configHandler_->getAppConfigApplication()["options"].toObject()["default_install_type"].toString();
if (!force && providerCategories.contains(categoryKey)) {
installType = providerCategories[categoryKey].toObject()["install_type"].toString();
}
......@@ -150,23 +150,23 @@ QJsonObject OcsApiHandler::getContents(const QString &providerKeys, const QStrin
categoryKeyList = categoryKeys.split(",");
}
QJsonObject providers = configHandler_->getUsrConfigProviders();
QJsonObject categories = configHandler_->getUsrConfigCategories();
auto providers = configHandler_->getUsrConfigProviders();
auto categories = configHandler_->getUsrConfigCategories();
for (const QString &providerKey : providers.keys()) {
for (const auto &providerKey : providers.keys()) {
if (!providerKeyList.isEmpty() && !providerKeyList.contains(providerKey)) {
continue;
}
QStringList categoryIdList;
QJsonObject providerCategories = categories[providerKey].toObject();
for (const QString &categoryKey : providerCategories.keys()) {
auto providerCategories = categories[providerKey].toObject();
for (const auto &categoryKey : providerCategories.keys()) {
if (!categoryKeyList.isEmpty() && !categoryKeyList.contains(categoryKey)) {
continue;
}
categoryIdList.append(providerCategories[categoryKey].toObject()["id"].toString());
}
if (!categoryIdList.isEmpty()) {
QString baseUrl = providers[providerKey].toObject()["location"].toString();
auto baseUrl = providers[providerKey].toObject()["location"].toString();
QUrlQuery query;
// categories: Comma-separated list is not compatible to legacy OCS-API
//query.addQueryItem("categories", categoryIdList.join(","));
......@@ -195,9 +195,9 @@ QJsonObject OcsApiHandler::getContents(const QString &providerKeys, const QStrin
QJsonObject OcsApiHandler::getContent(const QString &providerKey, const QString &contentId)
{
QJsonObject response;
QJsonObject providers = configHandler_->getUsrConfigProviders();
auto providers = configHandler_->getUsrConfigProviders();
if (providers.contains(providerKey)) {
QString baseUrl = providers[providerKey].toObject()["location"].toString();
auto baseUrl = providers[providerKey].toObject()["location"].toString();
response = qtlib::OcsApi(baseUrl, QUrl(baseUrl)).getContentData(contentId);
}
return response;
......
......@@ -42,7 +42,7 @@ bool SystemHandler::isMobileDevice()
bool SystemHandler::openUrl(const QString &url)
{
QString path = url;
auto path = url;
path.replace("file://localhost", "", Qt::CaseInsensitive);
path.replace("file://", "", Qt::CaseInsensitive);
......@@ -91,7 +91,7 @@ QString SystemHandler::desktopEnvironment()
bool SystemHandler::isApplicableType(const QString &installType)
{
QString desktop = desktopEnvironment();
auto desktop = desktopEnvironment();
if (installType == "wallpapers"
&& (desktop == "kde" || desktop == "gnome" || desktop == "xfce")) {
......@@ -139,11 +139,11 @@ bool SystemHandler::applyFile(const QString &path, const QString &installType)
#ifdef QTLIB_UNIX
bool SystemHandler::applyWallpaper(const QString &path)
{
QString desktop = desktopEnvironment();
auto desktop = desktopEnvironment();
if (desktop == "kde") {
// plasma5.6+
QDBusMessage message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript");
auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript");
QVariantList arguments;
QString script;
......@@ -158,7 +158,7 @@ bool SystemHandler::applyWallpaper(const QString &path)
arguments << QVariant(script);
message.setArguments(arguments);
QDBusMessage reply = QDBusConnection::sessionBus().call(message);
auto reply = QDBusConnection::sessionBus().call(message);
if (reply.type() == QDBusMessage::ErrorMessage) {
qWarning() << reply.errorMessage();
......@@ -167,16 +167,15 @@ bool SystemHandler::applyWallpaper(const QString &path)
return true;
}
else if (desktop == "gnome") {
QStringList arguments;
// gnome3
arguments << "set" << "org.gnome.desktop.background" << "picture-uri" << "file://" + path;
QStringList arguments{"set", "org.gnome.desktop.background", "picture-uri", "file://" + path};
return QProcess::startDetached("gsettings", arguments);
// gnome2
//arguments << "--type=string" << "--set" << "/desktop/gnome/background/picture_filename" << path;
//QStringList arguments{"--type=string", "--set", "/desktop/gnome/background/picture_filename", path};
//return QProcess::startDetached("gconftool-2", arguments);
}
else if (desktop == "xfce") {
QDBusMessage message = QDBusMessage::createMethodCall("org.xfce.Xfconf", "/org/xfce/Xfconf", "org.xfce.Xfconf", "SetProperty");
auto message = QDBusMessage::createMethodCall("org.xfce.Xfconf", "/org/xfce/Xfconf", "org.xfce.Xfconf", "SetProperty");
QVariantList arguments;
QString channelValue = "xfce4-desktop";
......@@ -187,7 +186,7 @@ bool SystemHandler::applyWallpaper(const QString &path)
arguments << QVariant(channelValue) << QVariant(propertyValue) << QVariant::fromValue(valueValue);
message.setArguments(arguments);
QDBusMessage reply = QDBusConnection::sessionBus().call(message);
auto reply = QDBusConnection::sessionBus().call(message);
if (reply.type() == QDBusMessage::ErrorMessage) {
qWarning() << reply.errorMessage();
......@@ -202,7 +201,7 @@ bool SystemHandler::applyIcon(const QString &path)
{
qDebug() << path;
QString desktop = desktopEnvironment();
auto desktop = desktopEnvironment();
if (desktop == "kde") {
}
......@@ -217,7 +216,7 @@ bool SystemHandler::applyCursor(const QString &path)
{
qDebug() << path;
QString desktop = desktopEnvironment();
auto desktop = desktopEnvironment();
if (desktop == "kde") {
}
......@@ -232,7 +231,7 @@ bool SystemHandler::applyWindowTheme(const QString &path)
{
qDebug() << path;
QString desktop = desktopEnvironment();
auto desktop = desktopEnvironment();
if (desktop == "kde") {
}
......
......@@ -15,8 +15,8 @@ int main(int argc, char *argv[])
// Init
QGuiApplication app(argc, argv); // This is backend program, but need GUI module
ConfigHandler *configHandler = new ConfigHandler();
QJsonObject appConfigApplication = configHandler->getAppConfigApplication();
auto *configHandler = new ConfigHandler();
auto appConfigApplication = configHandler->getAppConfigApplication();
app.setApplicationName(appConfigApplication["name"].toString());
app.setApplicationVersion(appConfigApplication["version"].toString());
......@@ -42,10 +42,10 @@ int main(int argc, char *argv[])
clParser.process(app);
int port = clParser.value(clOptionPort).toInt();
auto port = clParser.value(clOptionPort).toInt();
// Setup websocket server
WebSocketServer *wsServer = new WebSocketServer(configHandler, appConfigApplication["id"].toString(), port, &app);
auto *wsServer = new WebSocketServer(configHandler, appConfigApplication["id"].toString(), port, &app);
QObject::connect(wsServer, &WebSocketServer::stopped, &app, &QCoreApplication::quit);
if (wsServer->start()) {
......
......@@ -74,7 +74,7 @@ QUrl WebSocketServer::serverUrl()
void WebSocketServer::wsNewConnection()
{
QWebSocket *wsClient = wsServer_->nextPendingConnection();
auto *wsClient = wsServer_->nextPendingConnection();
connect(wsClient, &QWebSocket::disconnected, this, &WebSocketServer::wsDisconnected);
connect(wsClient, &QWebSocket::textMessageReceived, this, &WebSocketServer::wsTextMessageReceived);
connect(wsClient, &QWebSocket::binaryMessageReceived, this, &WebSocketServer::wsBinaryMessageReceived);
......@@ -83,7 +83,7 @@ void WebSocketServer::wsNewConnection()
void WebSocketServer::wsDisconnected()
{
QWebSocket *wsClient = qobject_cast<QWebSocket *>(sender());
auto *wsClient = qobject_cast<QWebSocket *>(sender());
if (wsClient) {
wsClients_.removeAll(wsClient);
wsClient->deleteLater();
......@@ -92,11 +92,11 @@ void WebSocketServer::wsDisconnected()
void WebSocketServer::wsTextMessageReceived(const QString &message)
{
QWebSocket *wsClient = qobject_cast<QWebSocket *>(sender());
auto *wsClient = qobject_cast<QWebSocket *>(sender());
if (wsClient) {
qtlib::Json json(message.toUtf8());
if (json.isObject()) {
QJsonObject object = json.toObject();
auto object = json.toObject();
receiveMessage(object["id"].toString(), object["func"].toString(), object["data"].toArray());
}
}
......@@ -104,11 +104,11 @@ void WebSocketServer::wsTextMessageReceived(const QString &message)
void WebSocketServer::wsBinaryMessageReceived(const QByteArray &message)
{
QWebSocket *wsClient = qobject_cast<QWebSocket *>(sender());
auto *wsClient = qobject_cast<QWebSocket *>(sender());
if (wsClient) {
qtlib::Json json(message);
if (json.isObject()) {
QJsonObject object = json.toObject();
auto object = json.toObject();
receiveMessage(object["id"].toString(), object["func"].toString(), object["data"].toArray());
}
}
......@@ -343,10 +343,10 @@ void WebSocketServer::sendMessage(const QString &id, const QString &func, const
object["func"] = func;
object["data"] = data;
QByteArray binaryMessage = qtlib::Json(object).toJson();
QString textMessage = QString::fromUtf8(binaryMessage);
auto binaryMessage = qtlib::Json(object).toJson();
auto textMessage = QString::fromUtf8(binaryMessage);
for (QWebSocket *wsClient : wsClients_) {
for (auto *wsClient : wsClients_) {
wsClient->sendTextMessage(textMessage);
//wsClient->sendBinaryMessage(binaryMessage);
}
......
......@@ -10,9 +10,7 @@ TARGET = ocs-manager
TEMPLATE = app
CONFIG += \
c++11 \
console
CONFIG += console
CONFIG -= app_bundle
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment