From bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 15 Jul 2018 14:51:05 +0200 Subject: NOISSUE tabs -> spaces --- api/gui/CMakeLists.txt | 24 +- api/gui/DesktopServices.cpp | 174 +- api/gui/DesktopServices.h | 40 +- api/gui/SkinUtils.cpp | 24 +- api/gui/icons/IconList.cpp | 578 +++--- api/gui/icons/IconList.h | 72 +- api/gui/icons/MMCIcon.cpp | 108 +- api/gui/icons/MMCIcon.h | 36 +- api/logic/BaseInstaller.cpp | 36 +- api/logic/BaseInstaller.h | 18 +- api/logic/BaseInstance.cpp | 240 +-- api/logic/BaseInstance.h | 398 ++-- api/logic/BaseInstanceProvider.h | 64 +- api/logic/BaseVersion.h | 54 +- api/logic/BaseVersionList.cpp | 86 +- api/logic/BaseVersionList.h | 134 +- api/logic/CMakeLists.txt | 748 ++++---- api/logic/Commandline.cpp | 730 ++++---- api/logic/Commandline.h | 324 ++-- api/logic/DefaultVariable.h | 54 +- api/logic/Env.cpp | 208 +-- api/logic/Env.h | 38 +- api/logic/Exception.h | 36 +- api/logic/FileSystem.cpp | 634 +++---- api/logic/FileSystem.h | 50 +- api/logic/FileSystem_test.cpp | 274 +-- api/logic/Filter.cpp | 16 +- api/logic/Filter.h | 30 +- api/logic/FolderInstanceProvider.cpp | 726 ++++---- api/logic/FolderInstanceProvider.h | 88 +- api/logic/GZip.cpp | 208 +-- api/logic/GZip.h | 4 +- api/logic/GZip_test.cpp | 74 +- api/logic/InstanceCopyTask.cpp | 64 +- api/logic/InstanceCopyTask.h | 20 +- api/logic/InstanceCreationTask.cpp | 34 +- api/logic/InstanceCreationTask.h | 10 +- api/logic/InstanceImportTask.cpp | 676 +++---- api/logic/InstanceImportTask.h | 52 +- api/logic/InstanceList.cpp | 460 ++--- api/logic/InstanceList.h | 118 +- api/logic/InstanceTask.h | 82 +- api/logic/Json.cpp | 268 +-- api/logic/Json.h | 160 +- api/logic/LoggedProcess.cpp | 214 +-- api/logic/LoggedProcess.h | 70 +- api/logic/MMCStrings.cpp | 126 +- api/logic/MMCStrings.h | 2 +- api/logic/MMCZip.cpp | 398 ++-- api/logic/MMCZip.h | 68 +- api/logic/MessageLevel.cpp | 54 +- api/logic/MessageLevel.h | 20 +- api/logic/NullInstance.h | 140 +- api/logic/ProblemProvider.h | 52 +- api/logic/QObjectPtr.h | 104 +- api/logic/RWStorage.h | 108 +- api/logic/RecursiveFileSystemWatcher.cpp | 142 +- api/logic/RecursiveFileSystemWatcher.h | 80 +- api/logic/SeparatorPrefixTree.h | 544 +++--- api/logic/Usable.h | 58 +- api/logic/Version.cpp | 94 +- api/logic/Version.h | 176 +- api/logic/Version_test.cpp | 96 +- api/logic/icons/IIconList.h | 24 +- api/logic/java/JavaChecker.cpp | 250 +-- api/logic/java/JavaChecker.h | 66 +- api/logic/java/JavaCheckerJob.cpp | 32 +- api/logic/java/JavaCheckerJob.h | 52 +- api/logic/java/JavaInstall.cpp | 28 +- api/logic/java/JavaInstall.h | 48 +- api/logic/java/JavaInstallList.cpp | 222 +-- api/logic/java/JavaInstallList.h | 58 +- api/logic/java/JavaUtils.cpp | 514 +++--- api/logic/java/JavaUtils.h | 12 +- api/logic/java/JavaVersion.cpp | 164 +- api/logic/java/JavaVersion.h | 68 +- api/logic/java/JavaVersion_test.cpp | 194 +- api/logic/java/launch/CheckJava.cpp | 194 +- api/logic/java/launch/CheckJava.h | 28 +- api/logic/launch/LaunchStep.cpp | 12 +- api/logic/launch/LaunchStep.h | 30 +- api/logic/launch/LaunchTask.cpp | 324 ++-- api/logic/launch/LaunchTask.h | 134 +- api/logic/launch/LogModel.cpp | 218 +-- api/logic/launch/LogModel.h | 70 +- api/logic/launch/steps/PostLaunchCommand.cpp | 94 +- api/logic/launch/steps/PostLaunchCommand.h | 26 +- api/logic/launch/steps/PreLaunchCommand.cpp | 96 +- api/logic/launch/steps/PreLaunchCommand.h | 26 +- api/logic/launch/steps/TextPrint.cpp | 18 +- api/logic/launch/steps/TextPrint.h | 18 +- api/logic/launch/steps/Update.cpp | 84 +- api/logic/launch/steps/Update.h | 22 +- api/logic/meta/BaseEntity.cpp | 200 +-- api/logic/meta/BaseEntity.h | 52 +- api/logic/meta/Index.cpp | 162 +- api/logic/meta/Index.h | 48 +- api/logic/meta/Index_test.cpp | 52 +- api/logic/meta/JsonFormat.cpp | 258 +-- api/logic/meta/JsonFormat.h | 42 +- api/logic/meta/Version.cpp | 104 +- api/logic/meta/Version.h | 136 +- api/logic/meta/VersionList.cpp | 276 +-- api/logic/meta/VersionList.h | 116 +- api/logic/minecraft/AssetsUtils.cpp | 340 ++-- api/logic/minecraft/AssetsUtils.h | 20 +- api/logic/minecraft/Component.cpp | 604 +++---- api/logic/minecraft/Component.h | 138 +- api/logic/minecraft/ComponentList.cpp | 1896 ++++++++++---------- api/logic/minecraft/ComponentList.h | 138 +- api/logic/minecraft/ComponentList_p.h | 44 +- api/logic/minecraft/ComponentUpdateTask.cpp | 1120 ++++++------ api/logic/minecraft/ComponentUpdateTask.h | 30 +- api/logic/minecraft/ComponentUpdateTask_p.h | 32 +- api/logic/minecraft/GradleSpecifier.h | 266 +-- api/logic/minecraft/GradleSpecifier_test.cpp | 126 +- api/logic/minecraft/LaunchProfile.cpp | 324 ++-- api/logic/minecraft/LaunchProfile.h | 140 +- api/logic/minecraft/Library.cpp | 538 +++--- api/logic/minecraft/Library.h | 330 ++-- api/logic/minecraft/Library_test.cpp | 498 ++--- api/logic/minecraft/MinecraftInstance.cpp | 1410 +++++++-------- api/logic/minecraft/MinecraftInstance.h | 174 +- api/logic/minecraft/MinecraftLoadAndCheck.cpp | 50 +- api/logic/minecraft/MinecraftLoadAndCheck.h | 20 +- api/logic/minecraft/MinecraftUpdate.cpp | 234 +-- api/logic/minecraft/MinecraftUpdate.h | 32 +- api/logic/minecraft/Mod.cpp | 572 +++--- api/logic/minecraft/Mod.h | 228 +-- api/logic/minecraft/ModsModel.cpp | 548 +++--- api/logic/minecraft/ModsModel.h | 152 +- api/logic/minecraft/MojangDownloadInfo.h | 110 +- api/logic/minecraft/MojangVersionFormat.cpp | 578 +++--- api/logic/minecraft/MojangVersionFormat.h | 20 +- api/logic/minecraft/MojangVersionFormat_test.cpp | 76 +- api/logic/minecraft/OneSixVersionFormat.cpp | 650 +++---- api/logic/minecraft/OneSixVersionFormat.h | 28 +- api/logic/minecraft/OpSys.cpp | 36 +- api/logic/minecraft/OpSys.h | 8 +- api/logic/minecraft/ParseUtils.cpp | 36 +- api/logic/minecraft/ParseUtils_test.cpp | 56 +- api/logic/minecraft/ProfileUtils.cpp | 264 +-- api/logic/minecraft/Rule.cpp | 106 +- api/logic/minecraft/Rule.h | 94 +- api/logic/minecraft/SimpleModList.cpp | 552 +++--- api/logic/minecraft/SimpleModList.h | 152 +- api/logic/minecraft/SimpleModList_test.cpp | 70 +- api/logic/minecraft/SkinUpload.cpp | 80 +- api/logic/minecraft/SkinUpload.h | 32 +- api/logic/minecraft/VersionFile.cpp | 68 +- api/logic/minecraft/VersionFile.h | 118 +- api/logic/minecraft/VersionFilterData.cpp | 104 +- api/logic/minecraft/VersionFilterData.h | 24 +- api/logic/minecraft/World.cpp | 560 +++--- api/logic/minecraft/World.h | 102 +- api/logic/minecraft/WorldList.cpp | 510 +++--- api/logic/minecraft/WorldList.h | 174 +- api/logic/minecraft/auth/AuthSession.cpp | 32 +- api/logic/minecraft/auth/AuthSession.h | 70 +- api/logic/minecraft/auth/MojangAccount.cpp | 442 ++--- api/logic/minecraft/auth/MojangAccount.h | 170 +- api/logic/minecraft/auth/MojangAccountList.cpp | 682 +++---- api/logic/minecraft/auth/MojangAccountList.h | 304 ++-- api/logic/minecraft/auth/YggdrasilTask.cpp | 356 ++-- api/logic/minecraft/auth/YggdrasilTask.h | 212 +-- .../minecraft/auth/flows/AuthenticateTask.cpp | 312 ++-- api/logic/minecraft/auth/flows/AuthenticateTask.h | 14 +- api/logic/minecraft/auth/flows/RefreshTask.cpp | 188 +- api/logic/minecraft/auth/flows/RefreshTask.h | 12 +- api/logic/minecraft/auth/flows/ValidateTask.cpp | 32 +- api/logic/minecraft/auth/flows/ValidateTask.h | 12 +- api/logic/minecraft/forge/ForgeXzDownload.cpp | 640 +++---- api/logic/minecraft/forge/ForgeXzDownload.h | 46 +- api/logic/minecraft/launch/ClaimAccount.cpp | 20 +- api/logic/minecraft/launch/ClaimAccount.h | 22 +- .../launch/CreateServerResourcePacksFolder.cpp | 14 +- .../launch/CreateServerResourcePacksFolder.h | 16 +- api/logic/minecraft/launch/DirectJavaLaunch.cpp | 196 +- api/logic/minecraft/launch/DirectJavaLaunch.h | 38 +- api/logic/minecraft/launch/ExtractNatives.cpp | 120 +- api/logic/minecraft/launch/ExtractNatives.h | 18 +- api/logic/minecraft/launch/LauncherPartLaunch.cpp | 292 +-- api/logic/minecraft/launch/LauncherPartLaunch.h | 42 +- api/logic/minecraft/launch/ModMinecraftJar.cpp | 90 +- api/logic/minecraft/launch/ModMinecraftJar.h | 20 +- api/logic/minecraft/launch/PrintInstanceInfo.h | 18 +- api/logic/minecraft/legacy/LegacyInstance.cpp | 226 +-- api/logic/minecraft/legacy/LegacyInstance.h | 216 +-- api/logic/minecraft/legacy/LegacyModList.cpp | 262 +-- api/logic/minecraft/legacy/LegacyModList.h | 28 +- api/logic/minecraft/legacy/LegacyUpgradeTask.cpp | 200 +-- api/logic/minecraft/legacy/LegacyUpgradeTask.h | 18 +- api/logic/minecraft/testdata/lib-native-arch.json | 88 +- api/logic/minecraft/testdata/lib-native.json | 100 +- api/logic/minecraft/testdata/lib-simple.json | 18 +- api/logic/minecraft/update/AssetUpdateTask.cpp | 124 +- api/logic/minecraft/update/AssetUpdateTask.h | 22 +- api/logic/minecraft/update/FMLLibrariesTask.cpp | 190 +- api/logic/minecraft/update/FMLLibrariesTask.h | 22 +- api/logic/minecraft/update/FoldersTask.cpp | 20 +- api/logic/minecraft/update/FoldersTask.h | 10 +- api/logic/minecraft/update/LibrariesTask.cpp | 124 +- api/logic/minecraft/update/LibrariesTask.h | 18 +- api/logic/modplatform/flame/FileResolvingTask.cpp | 202 +-- api/logic/modplatform/flame/FileResolvingTask.h | 24 +- api/logic/modplatform/flame/PackManifest.cpp | 88 +- api/logic/modplatform/flame/PackManifest.h | 64 +- api/logic/modplatform/ftb/FtbPackFetchTask.cpp | 168 +- api/logic/modplatform/ftb/FtbPackFetchTask.h | 28 +- api/logic/modplatform/ftb/FtbPackInstallTask.cpp | 280 +-- api/logic/modplatform/ftb/FtbPackInstallTask.h | 46 +- api/logic/modplatform/ftb/PackHelpers.h | 40 +- api/logic/net/ByteArraySink.h | 88 +- api/logic/net/ChecksumValidator.h | 76 +- api/logic/net/Download.cpp | 406 ++--- api/logic/net/Download.h | 60 +- api/logic/net/FileSink.cpp | 138 +- api/logic/net/FileSink.h | 24 +- api/logic/net/HttpMetaCache.cpp | 366 ++-- api/logic/net/HttpMetaCache.h | 152 +- api/logic/net/MetaCacheSink.cpp | 74 +- api/logic/net/MetaCacheSink.h | 14 +- api/logic/net/Mode.h | 4 +- api/logic/net/NetAction.h | 132 +- api/logic/net/NetJob.cpp | 312 ++-- api/logic/net/NetJob.h | 96 +- api/logic/net/PasteUpload.cpp | 128 +- api/logic/net/PasteUpload.h | 62 +- api/logic/net/Sink.h | 102 +- api/logic/net/URLConstants.cpp | 4 +- api/logic/net/Validator.h | 12 +- api/logic/news/NewsChecker.cpp | 144 +- api/logic/news/NewsChecker.h | 116 +- api/logic/news/NewsEntry.cpp | 72 +- api/logic/news/NewsEntry.h | 52 +- api/logic/notifications/NotificationChecker.cpp | 158 +- api/logic/notifications/NotificationChecker.h | 74 +- api/logic/pathmatcher/FSTreeMatcher.h | 18 +- api/logic/pathmatcher/IPathMatcher.h | 6 +- api/logic/pathmatcher/MultiMatcher.h | 42 +- api/logic/pathmatcher/RegexpMatcher.h | 66 +- api/logic/screenshots/ImgurAlbumCreation.cpp | 112 +- api/logic/screenshots/ImgurAlbumCreation.h | 46 +- api/logic/screenshots/ImgurUpload.cpp | 160 +- api/logic/screenshots/ImgurUpload.h | 28 +- api/logic/screenshots/Screenshot.h | 16 +- api/logic/settings/INIFile.cpp | 180 +- api/logic/settings/INIFile.h | 16 +- api/logic/settings/INIFile_test.cpp | 96 +- api/logic/settings/INISettingsObject.cpp | 108 +- api/logic/settings/INISettingsObject.h | 48 +- api/logic/settings/OverrideSetting.cpp | 28 +- api/logic/settings/OverrideSetting.h | 18 +- api/logic/settings/PassthroughSetting.cpp | 58 +- api/logic/settings/PassthroughSetting.h | 18 +- api/logic/settings/Setting.cpp | 32 +- api/logic/settings/Setting.h | 146 +- api/logic/settings/SettingsObject.cpp | 140 +- api/logic/settings/SettingsObject.h | 312 ++-- api/logic/status/StatusChecker.cpp | 166 +- api/logic/status/StatusChecker.h | 36 +- api/logic/tasks/SequentialTask.cpp | 56 +- api/logic/tasks/SequentialTask.h | 22 +- api/logic/tasks/Task.cpp | 144 +- api/logic/tasks/Task.h | 98 +- api/logic/tools/BaseExternalTool.cpp | 10 +- api/logic/tools/BaseExternalTool.h | 34 +- api/logic/tools/BaseProfiler.cpp | 24 +- api/logic/tools/BaseProfiler.h | 20 +- api/logic/tools/JProfiler.cpp | 114 +- api/logic/tools/JProfiler.h | 10 +- api/logic/tools/JVisualVM.cpp | 98 +- api/logic/tools/JVisualVM.h | 10 +- api/logic/tools/MCEditTool.cpp | 84 +- api/logic/tools/MCEditTool.h | 12 +- api/logic/translations/TranslationsModel.cpp | 458 ++--- api/logic/translations/TranslationsModel.h | 48 +- api/logic/updater/DownloadTask.cpp | 182 +- api/logic/updater/DownloadTask.h | 110 +- api/logic/updater/DownloadTask_test.cpp | 336 ++-- api/logic/updater/GoUpdate.cpp | 382 ++-- api/logic/updater/GoUpdate.h | 138 +- api/logic/updater/UpdateChecker.cpp | 398 ++-- api/logic/updater/UpdateChecker.h | 168 +- api/logic/updater/UpdateChecker_test.cpp | 242 +-- api/logic/updater/testdata/1.json | 82 +- api/logic/updater/testdata/2.json | 58 +- api/logic/updater/testdata/channels.json | 42 +- api/logic/updater/testdata/errorChannels.json | 42 +- api/logic/updater/testdata/garbageChannels.json | 40 +- api/logic/updater/testdata/index.json | 14 +- api/logic/updater/testdata/noChannels.json | 6 +- api/logic/updater/testdata/oneChannel.json | 18 +- 293 files changed, 22660 insertions(+), 22660 deletions(-) (limited to 'api') diff --git a/api/gui/CMakeLists.txt b/api/gui/CMakeLists.txt index 9a6ede25..ad116a43 100644 --- a/api/gui/CMakeLists.txt +++ b/api/gui/CMakeLists.txt @@ -1,17 +1,17 @@ project(MultiMC_gui LANGUAGES CXX) set(GUI_SOURCES - DesktopServices.h - DesktopServices.cpp + DesktopServices.h + DesktopServices.cpp - # Icons - icons/MMCIcon.h - icons/MMCIcon.cpp - icons/IconList.h - icons/IconList.cpp + # Icons + icons/MMCIcon.h + icons/MMCIcon.cpp + icons/IconList.h + icons/IconList.cpp - SkinUtils.cpp - SkinUtils.h + SkinUtils.cpp + SkinUtils.h ) ################################ COMPILE ################################ @@ -28,7 +28,7 @@ target_include_directories(MultiMC_gui PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${C # Install it install( - TARGETS MultiMC_gui - RUNTIME DESTINATION ${LIBRARY_DEST_DIR} - LIBRARY DESTINATION ${LIBRARY_DEST_DIR} + TARGETS MultiMC_gui + RUNTIME DESTINATION ${LIBRARY_DEST_DIR} + LIBRARY DESTINATION ${LIBRARY_DEST_DIR} ) \ No newline at end of file diff --git a/api/gui/DesktopServices.cpp b/api/gui/DesktopServices.cpp index 3154ea01..5368ddc8 100644 --- a/api/gui/DesktopServices.cpp +++ b/api/gui/DesktopServices.cpp @@ -17,132 +17,132 @@ template bool IndirectOpen(T callable, qint64 *pid_forked = nullptr) { - auto pid = fork(); - if(pid_forked) - { - if(pid > 0) - *pid_forked = pid; - else - *pid_forked = 0; - } - if(pid == -1) - { - qWarning() << "IndirectOpen failed to fork: " << errno; - return false; - } - // child - do the stuff - if(pid == 0) - { - // unset all this garbage so it doesn't get passed to the child process - qunsetenv("LD_PRELOAD"); - qunsetenv("LD_LIBRARY_PATH"); - qunsetenv("LD_DEBUG"); - qunsetenv("QT_PLUGIN_PATH"); - qunsetenv("QT_FONTPATH"); + auto pid = fork(); + if(pid_forked) + { + if(pid > 0) + *pid_forked = pid; + else + *pid_forked = 0; + } + if(pid == -1) + { + qWarning() << "IndirectOpen failed to fork: " << errno; + return false; + } + // child - do the stuff + if(pid == 0) + { + // unset all this garbage so it doesn't get passed to the child process + qunsetenv("LD_PRELOAD"); + qunsetenv("LD_LIBRARY_PATH"); + qunsetenv("LD_DEBUG"); + qunsetenv("QT_PLUGIN_PATH"); + qunsetenv("QT_FONTPATH"); - // open the URL - auto status = callable(); + // open the URL + auto status = callable(); - // detach from the parent process group. - setsid(); + // detach from the parent process group. + setsid(); - // die. now. do not clean up anything, it would just hang forever. - _exit(status ? 0 : 1); - } - else - { - //parent - assume it worked. - int status; - while (waitpid(pid, &status, 0)) - { - if(WIFEXITED(status)) - { - return WEXITSTATUS(status) == 0; - } - if(WIFSIGNALED(status)) - { - return false; - } - } - return true; - } + // die. now. do not clean up anything, it would just hang forever. + _exit(status ? 0 : 1); + } + else + { + //parent - assume it worked. + int status; + while (waitpid(pid, &status, 0)) + { + if(WIFEXITED(status)) + { + return WEXITSTATUS(status) == 0; + } + if(WIFSIGNALED(status)) + { + return false; + } + } + return true; + } } #endif namespace DesktopServices { bool openDirectory(const QString &path, bool ensureExists) { - qDebug() << "Opening directory" << path; - QDir parentPath; - QDir dir(path); - if (!dir.exists()) - { - parentPath.mkpath(dir.absolutePath()); - } - auto f = [&]() - { - return QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath())); - }; + qDebug() << "Opening directory" << path; + QDir parentPath; + QDir dir(path); + if (!dir.exists()) + { + parentPath.mkpath(dir.absolutePath()); + } + auto f = [&]() + { + return QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath())); + }; #if defined(Q_OS_LINUX) - return IndirectOpen(f); + return IndirectOpen(f); #else - return f(); + return f(); #endif } bool openFile(const QString &path) { - qDebug() << "Opening file" << path; - auto f = [&]() - { - return QDesktopServices::openUrl(QUrl::fromLocalFile(path)); - }; + qDebug() << "Opening file" << path; + auto f = [&]() + { + return QDesktopServices::openUrl(QUrl::fromLocalFile(path)); + }; #if defined(Q_OS_LINUX) - return IndirectOpen(f); + return IndirectOpen(f); #else - return f(); + return f(); #endif } bool openFile(const QString &application, const QString &path, const QString &workingDirectory, qint64 *pid) { - qDebug() << "Opening file" << path << "using" << application; + qDebug() << "Opening file" << path << "using" << application; #if defined(Q_OS_LINUX) - // FIXME: the pid here is fake. So if something depends on it, it will likely misbehave - return IndirectOpen([&]() - { - return QProcess::startDetached(application, QStringList() << path, workingDirectory); - }, pid); + // FIXME: the pid here is fake. So if something depends on it, it will likely misbehave + return IndirectOpen([&]() + { + return QProcess::startDetached(application, QStringList() << path, workingDirectory); + }, pid); #else - return QProcess::startDetached(application, QStringList() << path, workingDirectory, pid); + return QProcess::startDetached(application, QStringList() << path, workingDirectory, pid); #endif } bool run(const QString &application, const QStringList &args, const QString &workingDirectory, qint64 *pid) { - qDebug() << "Running" << application << "with args" << args.join(' '); + qDebug() << "Running" << application << "with args" << args.join(' '); #if defined(Q_OS_LINUX) - // FIXME: the pid here is fake. So if something depends on it, it will likely misbehave - return IndirectOpen([&]() - { - return QProcess::startDetached(application, args, workingDirectory); - }, pid); + // FIXME: the pid here is fake. So if something depends on it, it will likely misbehave + return IndirectOpen([&]() + { + return QProcess::startDetached(application, args, workingDirectory); + }, pid); #else - return QProcess::startDetached(application, args, workingDirectory, pid); + return QProcess::startDetached(application, args, workingDirectory, pid); #endif } bool openUrl(const QUrl &url) { - qDebug() << "Opening URL" << url.toString(); - auto f = [&]() - { - return QDesktopServices::openUrl(url); - }; + qDebug() << "Opening URL" << url.toString(); + auto f = [&]() + { + return QDesktopServices::openUrl(url); + }; #if defined(Q_OS_LINUX) - return IndirectOpen(f); + return IndirectOpen(f); #else - return f(); + return f(); #endif } diff --git a/api/gui/DesktopServices.h b/api/gui/DesktopServices.h index f64a62c5..606fa52c 100644 --- a/api/gui/DesktopServices.h +++ b/api/gui/DesktopServices.h @@ -10,28 +10,28 @@ */ namespace DesktopServices { - /** - * Open a file in whatever application is applicable - */ - MULTIMC_GUI_EXPORT bool openFile(const QString &path); + /** + * Open a file in whatever application is applicable + */ + MULTIMC_GUI_EXPORT bool openFile(const QString &path); - /** - * Open a file in the specified application - */ - MULTIMC_GUI_EXPORT bool openFile(const QString &application, const QString &path, const QString & workingDirectory = QString(), qint64 *pid = 0); + /** + * Open a file in the specified application + */ + MULTIMC_GUI_EXPORT bool openFile(const QString &application, const QString &path, const QString & workingDirectory = QString(), qint64 *pid = 0); - /** - * Run an application - */ - MULTIMC_GUI_EXPORT bool run(const QString &application,const QStringList &args, const QString & workingDirectory = QString(), qint64 *pid = 0); + /** + * Run an application + */ + MULTIMC_GUI_EXPORT bool run(const QString &application,const QStringList &args, const QString & workingDirectory = QString(), qint64 *pid = 0); - /** - * Open a directory - */ - MULTIMC_GUI_EXPORT bool openDirectory(const QString &path, bool ensureExists = false); + /** + * Open a directory + */ + MULTIMC_GUI_EXPORT bool openDirectory(const QString &path, bool ensureExists = false); - /** - * Open the URL, most likely in a browser. Maybe. - */ - MULTIMC_GUI_EXPORT bool openUrl(const QUrl &url); + /** + * Open the URL, most likely in a browser. Maybe. + */ + MULTIMC_GUI_EXPORT bool openUrl(const QUrl &url); } diff --git a/api/gui/SkinUtils.cpp b/api/gui/SkinUtils.cpp index 3950cbc0..79edb4b9 100644 --- a/api/gui/SkinUtils.cpp +++ b/api/gui/SkinUtils.cpp @@ -29,19 +29,19 @@ namespace SkinUtils */ QPixmap getFaceFromCache(QString username, int height, int width) { - QFile fskin(ENV.metacache() - ->resolveEntry("skins", username + ".png") - ->getFullPath()); + QFile fskin(ENV.metacache() + ->resolveEntry("skins", username + ".png") + ->getFullPath()); - if (fskin.exists()) - { - QPixmap skin(fskin.fileName()); - if(!skin.isNull()) - { - return skin.copy(8, 8, 8, 8).scaled(height, width, Qt::KeepAspectRatio); - } - } + if (fskin.exists()) + { + QPixmap skin(fskin.fileName()); + if(!skin.isNull()) + { + return skin.copy(8, 8, 8, 8).scaled(height, width, Qt::KeepAspectRatio); + } + } - return QPixmap(); + return QPixmap(); } } diff --git a/api/gui/icons/IconList.cpp b/api/gui/icons/IconList.cpp index 997a03db..870b347e 100644 --- a/api/gui/icons/IconList.cpp +++ b/api/gui/icons/IconList.cpp @@ -27,394 +27,394 @@ IconList::IconList(const QStringList &builtinPaths, QString path, QObject *parent) : QAbstractListModel(parent) { - QSet builtinNames; - - // add builtin icons - for(auto & builtinPath: builtinPaths) - { - QDir instance_icons(builtinPath); - auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name); - for (auto file_info : file_info_list) - { - builtinNames.insert(file_info.baseName()); - } - } - for(auto & builtinName : builtinNames) - { - addThemeIcon(builtinName); - } - - m_watcher.reset(new QFileSystemWatcher()); - is_watching = false; - connect(m_watcher.get(), SIGNAL(directoryChanged(QString)), - SLOT(directoryChanged(QString))); - connect(m_watcher.get(), SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString))); - - directoryChanged(path); + QSet builtinNames; + + // add builtin icons + for(auto & builtinPath: builtinPaths) + { + QDir instance_icons(builtinPath); + auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name); + for (auto file_info : file_info_list) + { + builtinNames.insert(file_info.baseName()); + } + } + for(auto & builtinName : builtinNames) + { + addThemeIcon(builtinName); + } + + m_watcher.reset(new QFileSystemWatcher()); + is_watching = false; + connect(m_watcher.get(), SIGNAL(directoryChanged(QString)), + SLOT(directoryChanged(QString))); + connect(m_watcher.get(), SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString))); + + directoryChanged(path); } void IconList::directoryChanged(const QString &path) { - QDir new_dir (path); - if(m_dir.absolutePath() != new_dir.absolutePath()) - { - m_dir.setPath(path); - m_dir.refresh(); - if(is_watching) - stopWatching(); - startWatching(); - } - if(!m_dir.exists()) - if(!FS::ensureFolderPathExists(m_dir.absolutePath())) - return; - m_dir.refresh(); - auto new_list = m_dir.entryList(QDir::Files, QDir::Name); - for (auto it = new_list.begin(); it != new_list.end(); it++) - { - QString &foo = (*it); - foo = m_dir.filePath(foo); - } - auto new_set = new_list.toSet(); - QList current_list; - for (auto &it : icons) - { - if (!it.has(IconType::FileBased)) - continue; - current_list.push_back(it.m_images[IconType::FileBased].filename); - } - QSet current_set = current_list.toSet(); - - QSet to_remove = current_set; - to_remove -= new_set; - - QSet to_add = new_set; - to_add -= current_set; - - for (auto remove : to_remove) - { - qDebug() << "Removing " << remove; - QFileInfo rmfile(remove); - QString key = rmfile.baseName(); - int idx = getIconIndex(key); - if (idx == -1) - continue; - icons[idx].remove(IconType::FileBased); - if (icons[idx].type() == IconType::ToBeDeleted) - { - beginRemoveRows(QModelIndex(), idx, idx); - icons.remove(idx); - reindex(); - endRemoveRows(); - } - else - { - dataChanged(index(idx), index(idx)); - } - m_watcher->removePath(remove); - emit iconUpdated(key); - } - - for (auto add : to_add) - { - qDebug() << "Adding " << add; - QFileInfo addfile(add); - QString key = addfile.baseName(); - if (addIcon(key, QString(), addfile.filePath(), IconType::FileBased)) - { - m_watcher->addPath(add); - emit iconUpdated(key); - } - } + QDir new_dir (path); + if(m_dir.absolutePath() != new_dir.absolutePath()) + { + m_dir.setPath(path); + m_dir.refresh(); + if(is_watching) + stopWatching(); + startWatching(); + } + if(!m_dir.exists()) + if(!FS::ensureFolderPathExists(m_dir.absolutePath())) + return; + m_dir.refresh(); + auto new_list = m_dir.entryList(QDir::Files, QDir::Name); + for (auto it = new_list.begin(); it != new_list.end(); it++) + { + QString &foo = (*it); + foo = m_dir.filePath(foo); + } + auto new_set = new_list.toSet(); + QList current_list; + for (auto &it : icons) + { + if (!it.has(IconType::FileBased)) + continue; + current_list.push_back(it.m_images[IconType::FileBased].filename); + } + QSet current_set = current_list.toSet(); + + QSet to_remove = current_set; + to_remove -= new_set; + + QSet to_add = new_set; + to_add -= current_set; + + for (auto remove : to_remove) + { + qDebug() << "Removing " << remove; + QFileInfo rmfile(remove); + QString key = rmfile.baseName(); + int idx = getIconIndex(key); + if (idx == -1) + continue; + icons[idx].remove(IconType::FileBased); + if (icons[idx].type() == IconType::ToBeDeleted) + { + beginRemoveRows(QModelIndex(), idx, idx); + icons.remove(idx); + reindex(); + endRemoveRows(); + } + else + { + dataChanged(index(idx), index(idx)); + } + m_watcher->removePath(remove); + emit iconUpdated(key); + } + + for (auto add : to_add) + { + qDebug() << "Adding " << add; + QFileInfo addfile(add); + QString key = addfile.baseName(); + if (addIcon(key, QString(), addfile.filePath(), IconType::FileBased)) + { + m_watcher->addPath(add); + emit iconUpdated(key); + } + } } void IconList::fileChanged(const QString &path) { - qDebug() << "Checking " << path; - QFileInfo checkfile(path); - if (!checkfile.exists()) - return; - QString key = checkfile.baseName(); - int idx = getIconIndex(key); - if (idx == -1) - return; - QIcon icon(path); - if (!icon.availableSizes().size()) - return; - - icons[idx].m_images[IconType::FileBased].icon = icon; - dataChanged(index(idx), index(idx)); - emit iconUpdated(key); + qDebug() << "Checking " << path; + QFileInfo checkfile(path); + if (!checkfile.exists()) + return; + QString key = checkfile.baseName(); + int idx = getIconIndex(key); + if (idx == -1) + return; + QIcon icon(path); + if (!icon.availableSizes().size()) + return; + + icons[idx].m_images[IconType::FileBased].icon = icon; + dataChanged(index(idx), index(idx)); + emit iconUpdated(key); } void IconList::SettingChanged(const Setting &setting, QVariant value) { - if(setting.id() != "IconsDir") - return; + if(setting.id() != "IconsDir") + return; - directoryChanged(value.toString()); + directoryChanged(value.toString()); } void IconList::startWatching() { - auto abs_path = m_dir.absolutePath(); - FS::ensureFolderPathExists(abs_path); - is_watching = m_watcher->addPath(abs_path); - if (is_watching) - { - qDebug() << "Started watching " << abs_path; - } - else - { - qDebug() << "Failed to start watching " << abs_path; - } + auto abs_path = m_dir.absolutePath(); + FS::ensureFolderPathExists(abs_path); + is_watching = m_watcher->addPath(abs_path); + if (is_watching) + { + qDebug() << "Started watching " << abs_path; + } + else + { + qDebug() << "Failed to start watching " << abs_path; + } } void IconList::stopWatching() { - m_watcher->removePaths(m_watcher->files()); - m_watcher->removePaths(m_watcher->directories()); - is_watching = false; + m_watcher->removePaths(m_watcher->files()); + m_watcher->removePaths(m_watcher->directories()); + is_watching = false; } QStringList IconList::mimeTypes() const { - QStringList types; - types << "text/uri-list"; - return types; + QStringList types; + types << "text/uri-list"; + return types; } Qt::DropActions IconList::supportedDropActions() const { - return Qt::CopyAction; + return Qt::CopyAction; } bool IconList::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, - const QModelIndex &parent) + const QModelIndex &parent) { - if (action == Qt::IgnoreAction) - return true; - // check if the action is supported - if (!data || !(action & supportedDropActions())) - return false; - - // files dropped from outside? - if (data->hasUrls()) - { - auto urls = data->urls(); - QStringList iconFiles; - for (auto url : urls) - { - // only local files may be dropped... - if (!url.isLocalFile()) - continue; - iconFiles += url.toLocalFile(); - } - installIcons(iconFiles); - return true; - } - return false; + if (action == Qt::IgnoreAction) + return true; + // check if the action is supported + if (!data || !(action & supportedDropActions())) + return false; + + // files dropped from outside? + if (data->hasUrls()) + { + auto urls = data->urls(); + QStringList iconFiles; + for (auto url : urls) + { + // only local files may be dropped... + if (!url.isLocalFile()) + continue; + iconFiles += url.toLocalFile(); + } + installIcons(iconFiles); + return true; + } + return false; } Qt::ItemFlags IconList::flags(const QModelIndex &index) const { - Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index); - if (index.isValid()) - return Qt::ItemIsDropEnabled | defaultFlags; - else - return Qt::ItemIsDropEnabled | defaultFlags; + Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index); + if (index.isValid()) + return Qt::ItemIsDropEnabled | defaultFlags; + else + return Qt::ItemIsDropEnabled | defaultFlags; } QVariant IconList::data(const QModelIndex &index, int role) const { - if (!index.isValid()) - return QVariant(); - - int row = index.row(); - - if (row < 0 || row >= icons.size()) - return QVariant(); - - switch (role) - { - case Qt::DecorationRole: - return icons[row].icon(); - case Qt::DisplayRole: - return icons[row].name(); - case Qt::UserRole: - return icons[row].m_key; - default: - return QVariant(); - } + if (!index.isValid()) + return QVariant(); + + int row = index.row(); + + if (row < 0 || row >= icons.size()) + return QVariant(); + + switch (role) + { + case Qt::DecorationRole: + return icons[row].icon(); + case Qt::DisplayRole: + return icons[row].name(); + case Qt::UserRole: + return icons[row].m_key; + default: + return QVariant(); + } } int IconList::rowCount(const QModelIndex &parent) const { - return icons.size(); + return icons.size(); } void IconList::installIcons(const QStringList &iconFiles) { - for (QString file : iconFiles) - { - QFileInfo fileinfo(file); - if (!fileinfo.isReadable() || !fileinfo.isFile()) - continue; - QString target = FS::PathCombine(m_dir.dirName(), fileinfo.fileName()); - - QString suffix = fileinfo.suffix(); - if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico" && suffix != "svg") - continue; - - if (!QFile::copy(file, target)) - continue; - } + for (QString file : iconFiles) + { + QFileInfo fileinfo(file); + if (!fileinfo.isReadable() || !fileinfo.isFile()) + continue; + QString target = FS::PathCombine(m_dir.dirName(), fileinfo.fileName()); + + QString suffix = fileinfo.suffix(); + if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico" && suffix != "svg") + continue; + + if (!QFile::copy(file, target)) + continue; + } } void IconList::installIcon(const QString &file, const QString &name) { - QFileInfo fileinfo(file); - if(!fileinfo.isReadable() || !fileinfo.isFile()) - return; + QFileInfo fileinfo(file); + if(!fileinfo.isReadable() || !fileinfo.isFile()) + return; - QString target = FS::PathCombine(m_dir.dirName(), name); + QString target = FS::PathCombine(m_dir.dirName(), name); - QFile::copy(file, target); + QFile::copy(file, target); } bool IconList::iconFileExists(const QString &key) const { - auto iconEntry = icon(key); - if(!iconEntry) - { - return false; - } - return iconEntry->has(IconType::FileBased); + auto iconEntry = icon(key); + if(!iconEntry) + { + return false; + } + return iconEntry->has(IconType::FileBased); } const MMCIcon *IconList::icon(const QString &key) const { - int iconIdx = getIconIndex(key); - if (iconIdx == -1) - return nullptr; - return &icons[iconIdx]; + int iconIdx = getIconIndex(key); + if (iconIdx == -1) + return nullptr; + return &icons[iconIdx]; } bool IconList::deleteIcon(const QString &key) { - int iconIdx = getIconIndex(key); - if (iconIdx == -1) - return false; - auto &iconEntry = icons[iconIdx]; - if (iconEntry.has(IconType::FileBased)) - { - return QFile::remove(iconEntry.m_images[IconType::FileBased].filename); - } - return false; + int iconIdx = getIconIndex(key); + if (iconIdx == -1) + return false; + auto &iconEntry = icons[iconIdx]; + if (iconEntry.has(IconType::FileBased)) + { + return QFile::remove(iconEntry.m_images[IconType::FileBased].filename); + } + return false; } bool IconList::addThemeIcon(const QString& key) { - auto iter = name_index.find(key); - if (iter != name_index.end()) - { - auto &oldOne = icons[*iter]; - oldOne.replace(Builtin, key); - dataChanged(index(*iter), index(*iter)); - return true; - } - else - { - // add a new icon - beginInsertRows(QModelIndex(), icons.size(), icons.size()); - { - MMCIcon mmc_icon; - mmc_icon.m_name = key; - mmc_icon.m_key = key; - mmc_icon.replace(Builtin, key); - icons.push_back(mmc_icon); - name_index[key] = icons.size() - 1; - } - endInsertRows(); - return true; - } + auto iter = name_index.find(key); + if (iter != name_index.end()) + { + auto &oldOne = icons[*iter]; + oldOne.replace(Builtin, key); + dataChanged(index(*iter), index(*iter)); + return true; + } + else + { + // add a new icon + beginInsertRows(QModelIndex(), icons.size(), icons.size()); + { + MMCIcon mmc_icon; + mmc_icon.m_name = key; + mmc_icon.m_key = key; + mmc_icon.replace(Builtin, key); + icons.push_back(mmc_icon); + name_index[key] = icons.size() - 1; + } + endInsertRows(); + return true; + } } bool IconList::addIcon(const QString &key, const QString &name, const QString &path, const IconType type) { - // replace the icon even? is the input valid? - QIcon icon(path); - if (icon.isNull()) - return false; - auto iter = name_index.find(key); - if (iter != name_index.end()) - { - auto &oldOne = icons[*iter]; - oldOne.replace(type, icon, path); - dataChanged(index(*iter), index(*iter)); - return true; - } - else - { - // add a new icon - beginInsertRows(QModelIndex(), icons.size(), icons.size()); - { - MMCIcon mmc_icon; - mmc_icon.m_name = name; - mmc_icon.m_key = key; - mmc_icon.replace(type, icon, path); - icons.push_back(mmc_icon); - name_index[key] = icons.size() - 1; - } - endInsertRows(); - return true; - } + // replace the icon even? is the input valid? + QIcon icon(path); + if (icon.isNull()) + return false; + auto iter = name_index.find(key); + if (iter != name_index.end()) + { + auto &oldOne = icons[*iter]; + oldOne.replace(type, icon, path); + dataChanged(index(*iter), index(*iter)); + return true; + } + else + { + // add a new icon + beginInsertRows(QModelIndex(), icons.size(), icons.size()); + { + MMCIcon mmc_icon; + mmc_icon.m_name = name; + mmc_icon.m_key = key; + mmc_icon.replace(type, icon, path); + icons.push_back(mmc_icon); + name_index[key] = icons.size() - 1; + } + endInsertRows(); + return true; + } } void IconList::saveIcon(const QString &key, const QString &path, const char * format) const { - auto icon = getIcon(key); - auto pixmap = icon.pixmap(128, 128); - pixmap.save(path, format); + auto icon = getIcon(key); + auto pixmap = icon.pixmap(128, 128); + pixmap.save(path, format); } void IconList::reindex() { - name_index.clear(); - int i = 0; - for (auto &iter : icons) - { - name_index[iter.m_key] = i; - i++; - } + name_index.clear(); + int i = 0; + for (auto &iter : icons) + { + name_index[iter.m_key] = i; + i++; + } } QIcon IconList::getIcon(const QString &key) const { - int icon_index = getIconIndex(key); + int icon_index = getIconIndex(key); - if (icon_index != -1) - return icons[icon_index].icon(); + if (icon_index != -1) + return icons[icon_index].icon(); - // Fallback for icons that don't exist. - icon_index = getIconIndex("infinity"); + // Fallback for icons that don't exist. + icon_index = getIconIndex("infinity"); - if (icon_index != -1) - return icons[icon_index].icon(); - return QIcon(); + if (icon_index != -1) + return icons[icon_index].icon(); + return QIcon(); } int IconList::getIconIndex(const QString &key) const { - auto iter = name_index.find(key == "default" ? "infinity" : key); - if (iter != name_index.end()) - return *iter; + auto iter = name_index.find(key == "default" ? "infinity" : key); + if (iter != name_index.end()) + return *iter; - return -1; + return -1; } QString IconList::getDirectory() const { - return m_dir.absolutePath(); + return m_dir.absolutePath(); } //#include "IconList.moc" diff --git a/api/gui/icons/IconList.h b/api/gui/icons/IconList.h index fad3336f..97ed3956 100644 --- a/api/gui/icons/IconList.h +++ b/api/gui/icons/IconList.h @@ -32,57 +32,57 @@ class QFileSystemWatcher; class MULTIMC_GUI_EXPORT IconList : public QAbstractListModel, public IIconList { - Q_OBJECT + Q_OBJECT public: - explicit IconList(const QStringList &builtinPaths, QString path, QObject *parent = 0); - virtual ~IconList() {}; + explicit IconList(const QStringList &builtinPaths, QString path, QObject *parent = 0); + virtual ~IconList() {}; - QIcon getIcon(const QString &key) const; - int getIconIndex(const QString &key) const; - QString getDirectory() const; + QIcon getIcon(const QString &key) const; + int getIconIndex(const QString &key) const; + QString getDirectory() const; - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; - bool addThemeIcon(const QString &key); - bool addIcon(const QString &key, const QString &name, const QString &path, const IconType type) override; - void saveIcon(const QString &key, const QString &path, const char * format) const override; - bool deleteIcon(const QString &key) override; - bool iconFileExists(const QString &key) const override; + bool addThemeIcon(const QString &key); + bool addIcon(const QString &key, const QString &name, const QString &path, const IconType type) override; + void saveIcon(const QString &key, const QString &path, const char * format) const override; + bool deleteIcon(const QString &key) override; + bool iconFileExists(const QString &key) const override; - virtual QStringList mimeTypes() const override; - virtual Qt::DropActions supportedDropActions() const override; - virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; - virtual Qt::ItemFlags flags(const QModelIndex &index) const override; + virtual QStringList mimeTypes() const override; + virtual Qt::DropActions supportedDropActions() const override; + virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; + virtual Qt::ItemFlags flags(const QModelIndex &index) const override; - void installIcons(const QStringList &iconFiles) override; - void installIcon(const QString &file, const QString &name) override; + void installIcons(const QStringList &iconFiles) override; + void installIcon(const QString &file, const QString &name) override; - const MMCIcon * icon(const QString &key) const; + const MMCIcon * icon(const QString &key) const; - void startWatching(); - void stopWatching(); + void startWatching(); + void stopWatching(); signals: - void iconUpdated(QString key); + void iconUpdated(QString key); private: - // hide copy constructor - IconList(const IconList &) = delete; - // hide assign op - IconList &operator=(const IconList &) = delete; - void reindex(); + // hide copy constructor + IconList(const IconList &) = delete; + // hide assign op + IconList &operator=(const IconList &) = delete; + void reindex(); public slots: - void directoryChanged(const QString &path); + void directoryChanged(const QString &path); protected slots: - void fileChanged(const QString &path); - void SettingChanged(const Setting & setting, QVariant value); + void fileChanged(const QString &path); + void SettingChanged(const Setting & setting, QVariant value); private: - std::shared_ptr m_watcher; - bool is_watching; - QMap name_index; - QVector icons; - QDir m_dir; + std::shared_ptr m_watcher; + bool is_watching; + QMap name_index; + QVector icons; + QDir m_dir; }; diff --git a/api/gui/icons/MMCIcon.cpp b/api/gui/icons/MMCIcon.cpp index 92518e01..a5ab548e 100644 --- a/api/gui/icons/MMCIcon.cpp +++ b/api/gui/icons/MMCIcon.cpp @@ -19,86 +19,86 @@ IconType operator--(IconType &t, int) { - IconType temp = t; - switch (t) - { - case IconType::Builtin: - t = IconType::ToBeDeleted; - break; - case IconType::Transient: - t = IconType::Builtin; - break; - case IconType::FileBased: - t = IconType::Transient; - break; - default: - { - } - } - return temp; + IconType temp = t; + switch (t) + { + case IconType::Builtin: + t = IconType::ToBeDeleted; + break; + case IconType::Transient: + t = IconType::Builtin; + break; + case IconType::FileBased: + t = IconType::Transient; + break; + default: + { + } + } + return temp; } IconType MMCIcon::type() const { - return m_current_type; + return m_current_type; } QString MMCIcon::name() const { - if (m_name.size()) - return m_name; - return m_key; + if (m_name.size()) + return m_name; + return m_key; } bool MMCIcon::has(IconType _type) const { - return m_images[_type].present(); + return m_images[_type].present(); } QIcon MMCIcon::icon() const { - if (m_current_type == IconType::ToBeDeleted) - return QIcon(); - auto & icon = m_images[m_current_type].icon; - if(!icon.isNull()) - return icon; - // FIXME: inject this. - return XdgIcon::fromTheme(m_images[m_current_type].key); + if (m_current_type == IconType::ToBeDeleted) + return QIcon(); + auto & icon = m_images[m_current_type].icon; + if(!icon.isNull()) + return icon; + // FIXME: inject this. + return XdgIcon::fromTheme(m_images[m_current_type].key); } void MMCIcon::remove(IconType rm_type) { - m_images[rm_type].filename = QString(); - m_images[rm_type].icon = QIcon(); - for (auto iter = rm_type; iter != IconType::ToBeDeleted; iter--) - { - if (m_images[iter].present()) - { - m_current_type = iter; - return; - } - } - m_current_type = IconType::ToBeDeleted; + m_images[rm_type].filename = QString(); + m_images[rm_type].icon = QIcon(); + for (auto iter = rm_type; iter != IconType::ToBeDeleted; iter--) + { + if (m_images[iter].present()) + { + m_current_type = iter; + return; + } + } + m_current_type = IconType::ToBeDeleted; } void MMCIcon::replace(IconType new_type, QIcon icon, QString path) { - if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted) - { - m_current_type = new_type; - } - m_images[new_type].icon = icon; - m_images[new_type].filename = path; - m_images[new_type].key = QString(); + if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted) + { + m_current_type = new_type; + } + m_images[new_type].icon = icon; + m_images[new_type].filename = path; + m_images[new_type].key = QString(); } void MMCIcon::replace(IconType new_type, const QString& key) { - if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted) - { - m_current_type = new_type; - } - m_images[new_type].icon = QIcon(); - m_images[new_type].filename = QString(); - m_images[new_type].key = key; + if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted) + { + m_current_type = new_type; + } + m_images[new_type].icon = QIcon(); + m_images[new_type].filename = QString(); + m_images[new_type].key = key; } diff --git a/api/gui/icons/MMCIcon.h b/api/gui/icons/MMCIcon.h index 8c6752ea..d7618bee 100644 --- a/api/gui/icons/MMCIcon.h +++ b/api/gui/icons/MMCIcon.h @@ -23,27 +23,27 @@ struct MULTIMC_GUI_EXPORT MMCImage { - QIcon icon; - QString key; - QString filename; - bool present() const - { - return !icon.isNull() || !key.isEmpty(); - } + QIcon icon; + QString key; + QString filename; + bool present() const + { + return !icon.isNull() || !key.isEmpty(); + } }; struct MULTIMC_GUI_EXPORT MMCIcon { - QString m_key; - QString m_name; - MMCImage m_images[ICONS_TOTAL]; - IconType m_current_type = ToBeDeleted; + QString m_key; + QString m_name; + MMCImage m_images[ICONS_TOTAL]; + IconType m_current_type = ToBeDeleted; - IconType type() const; - QString name() const; - bool has(IconType _type) const; - QIcon icon() const; - void remove(IconType rm_type); - void replace(IconType new_type, QIcon icon, QString path = QString()); - void replace(IconType new_type, const QString &key); + IconType type() const; + QString name() const; + bool has(IconType _type) const; + QIcon icon() const; + void remove(IconType rm_type); + void replace(IconType new_type, QIcon icon, QString path = QString()); + void replace(IconType new_type, const QString &key); }; diff --git a/api/logic/BaseInstaller.cpp b/api/logic/BaseInstaller.cpp index 51f66293..e25683a9 100644 --- a/api/logic/BaseInstaller.cpp +++ b/api/logic/BaseInstaller.cpp @@ -25,37 +25,37 @@ BaseInstaller::BaseInstaller() bool BaseInstaller::isApplied(MinecraftInstance *on) { - return QFile::exists(filename(on->instanceRoot())); + return QFile::exists(filename(on->instanceRoot())); } bool BaseInstaller::add(MinecraftInstance *to) { - if (!patchesDir(to->instanceRoot()).exists()) - { - QDir(to->instanceRoot()).mkdir("patches"); - } - - if (isApplied(to)) - { - if (!remove(to)) - { - return false; - } - } - - return true; + if (!patchesDir(to->instanceRoot()).exists()) + { + QDir(to->instanceRoot()).mkdir("patches"); + } + + if (isApplied(to)) + { + if (!remove(to)) + { + return false; + } + } + + return true; } bool BaseInstaller::remove(MinecraftInstance *from) { - return QFile::remove(filename(from->instanceRoot())); + return QFile::remove(filename(from->instanceRoot())); } QString BaseInstaller::filename(const QString &root) const { - return patchesDir(root).absoluteFilePath(id() + ".json"); + return patchesDir(root).absoluteFilePath(id() + ".json"); } QDir BaseInstaller::patchesDir(const QString &root) const { - return QDir(root + "/patches/"); + return QDir(root + "/patches/"); } diff --git a/api/logic/BaseInstaller.h b/api/logic/BaseInstaller.h index afe11d55..121d35ef 100644 --- a/api/logic/BaseInstaller.h +++ b/api/logic/BaseInstaller.h @@ -30,17 +30,17 @@ typedef std::shared_ptr BaseVersionPtr; class MULTIMC_LOGIC_EXPORT BaseInstaller { public: - BaseInstaller(); - virtual ~BaseInstaller(){}; - bool isApplied(MinecraftInstance *on); + BaseInstaller(); + virtual ~BaseInstaller(){}; + bool isApplied(MinecraftInstance *on); - virtual bool add(MinecraftInstance *to); - virtual bool remove(MinecraftInstance *from); + virtual bool add(MinecraftInstance *to); + virtual bool remove(MinecraftInstance *from); - virtual Task *createInstallTask(MinecraftInstance *instance, BaseVersionPtr version, QObject *parent) = 0; + virtual Task *createInstallTask(MinecraftInstance *instance, BaseVersionPtr version, QObject *parent) = 0; protected: - virtual QString id() const = 0; - QString filename(const QString &root) const; - QDir patchesDir(const QString &root) const; + virtual QString id() const = 0; + QString filename(const QString &root) const; + QDir patchesDir(const QString &root) const; }; diff --git a/api/logic/BaseInstance.cpp b/api/logic/BaseInstance.cpp index 7e652e0d..c81b70c6 100644 --- a/api/logic/BaseInstance.cpp +++ b/api/logic/BaseInstance.cpp @@ -27,281 +27,281 @@ #include "Commandline.h" BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) - : QObject() + : QObject() { - m_settings = settings; - m_rootDir = rootDir; + m_settings = settings; + m_rootDir = rootDir; - m_settings->registerSetting("name", "Unnamed Instance"); - m_settings->registerSetting("iconKey", "default"); - m_settings->registerSetting("notes", ""); - m_settings->registerSetting("lastLaunchTime", 0); - m_settings->registerSetting("totalTimePlayed", 0); + m_settings->registerSetting("name", "Unnamed Instance"); + m_settings->registerSetting("iconKey", "default"); + m_settings->registerSetting("notes", ""); + m_settings->registerSetting("lastLaunchTime", 0); + m_settings->registerSetting("totalTimePlayed", 0); - // Custom Commands - auto commandSetting = m_settings->registerSetting({"OverrideCommands","OverrideLaunchCmd"}, false); - m_settings->registerOverride(globalSettings->getSetting("PreLaunchCommand"), commandSetting); - m_settings->registerOverride(globalSettings->getSetting("WrapperCommand"), commandSetting); - m_settings->registerOverride(globalSettings->getSetting("PostExitCommand"), commandSetting); + // Custom Commands + auto commandSetting = m_settings->registerSetting({"OverrideCommands","OverrideLaunchCmd"}, false); + m_settings->registerOverride(globalSettings->getSetting("PreLaunchCommand"), commandSetting); + m_settings->registerOverride(globalSettings->getSetting("WrapperCommand"), commandSetting); + m_settings->registerOverride(globalSettings->getSetting("PostExitCommand"), commandSetting); - // Console - auto consoleSetting = m_settings->registerSetting("OverrideConsole", false); - m_settings->registerOverride(globalSettings->getSetting("ShowConsole"), consoleSetting); - m_settings->registerOverride(globalSettings->getSetting("AutoCloseConsole"), consoleSetting); - m_settings->registerOverride(globalSettings->getSetting("ShowConsoleOnError"), consoleSetting); - m_settings->registerOverride(globalSettings->getSetting("LogPrePostOutput"), consoleSetting); + // Console + auto consoleSetting = m_settings->registerSetting("OverrideConsole", false); + m_settings->registerOverride(globalSettings->getSetting("ShowConsole"), consoleSetting); + m_settings->registerOverride(globalSettings->getSetting("AutoCloseConsole"), consoleSetting); + m_settings->registerOverride(globalSettings->getSetting("ShowConsoleOnError"), consoleSetting); + m_settings->registerOverride(globalSettings->getSetting("LogPrePostOutput"), consoleSetting); - m_settings->registerPassthrough(globalSettings->getSetting("ConsoleMaxLines"), nullptr); - m_settings->registerPassthrough(globalSettings->getSetting("ConsoleOverflowStop"), nullptr); + m_settings->registerPassthrough(globalSettings->getSetting("ConsoleMaxLines"), nullptr); + m_settings->registerPassthrough(globalSettings->getSetting("ConsoleOverflowStop"), nullptr); } QString BaseInstance::getPreLaunchCommand() { - return settings()->get("PreLaunchCommand").toString(); + return settings()->get("PreLaunchCommand").toString(); } QString BaseInstance::getWrapperCommand() { - return settings()->get("WrapperCommand").toString(); + return settings()->get("WrapperCommand").toString(); } QString BaseInstance::getPostExitCommand() { - return settings()->get("PostExitCommand").toString(); + return settings()->get("PostExitCommand").toString(); } int BaseInstance::getConsoleMaxLines() const { - auto lineSetting = settings()->getSetting("ConsoleMaxLines"); - bool conversionOk = false; - int maxLines = lineSetting->get().toInt(&conversionOk); - if(!conversionOk) - { - maxLines = lineSetting->defValue().toInt(); - qWarning() << "ConsoleMaxLines has nonsensical value, defaulting to" << maxLines; - } - return maxLines; + auto lineSetting = settings()->getSetting("ConsoleMaxLines"); + bool conversionOk = false; + int maxLines = lineSetting->get().toInt(&conversionOk); + if(!conversionOk) + { + maxLines = lineSetting->defValue().toInt(); + qWarning() << "ConsoleMaxLines has nonsensical value, defaulting to" << maxLines; + } + return maxLines; } bool BaseInstance::shouldStopOnConsoleOverflow() const { - return settings()->get("ConsoleOverflowStop").toBool(); + return settings()->get("ConsoleOverflowStop").toBool(); } void BaseInstance::iconUpdated(QString key) { - if(iconKey() == key) - { - emit propertiesChanged(this); - } + if(iconKey() == key) + { + emit propertiesChanged(this); + } } void BaseInstance::invalidate() { - changeStatus(Status::Gone); - qDebug() << "Instance" << id() << "has been invalidated."; + changeStatus(Status::Gone); + qDebug() << "Instance" << id() << "has been invalidated."; } void BaseInstance::nuke() { - changeStatus(Status::Gone); - qDebug() << "Instance" << id() << "has been deleted by MultiMC."; - FS::deletePath(instanceRoot()); + changeStatus(Status::Gone); + qDebug() << "Instance" << id() << "has been deleted by MultiMC."; + FS::deletePath(instanceRoot()); } void BaseInstance::changeStatus(BaseInstance::Status newStatus) { - Status status = currentStatus(); - if(status != newStatus) - { - m_status = newStatus; - emit statusChanged(status, newStatus); - } + Status status = currentStatus(); + if(status != newStatus) + { + m_status = newStatus; + emit statusChanged(status, newStatus); + } } BaseInstance::Status BaseInstance::currentStatus() const { - return m_status; + return m_status; } QString BaseInstance::id() const { - return QFileInfo(instanceRoot()).fileName(); + return QFileInfo(instanceRoot()).fileName(); } bool BaseInstance::isRunning() const { - return m_isRunning; + return m_isRunning; } void BaseInstance::setRunning(bool running) { - if(running == m_isRunning) - return; + if(running == m_isRunning) + return; - m_isRunning = running; + m_isRunning = running; - if(running) - { - m_timeStarted = QDateTime::currentDateTime(); - } - else - { - qint64 current = settings()->get("totalTimePlayed").toLongLong(); - QDateTime timeEnded = QDateTime::currentDateTime(); - settings()->set("totalTimePlayed", current + m_timeStarted.secsTo(timeEnded)); - emit propertiesChanged(this); - } + if(running) + { + m_timeStarted = QDateTime::currentDateTime(); + } + else + { + qint64 current = settings()->get("totalTimePlayed").toLongLong(); + QDateTime timeEnded = QDateTime::currentDateTime(); + settings()->set("totalTimePlayed", current + m_timeStarted.secsTo(timeEnded)); + emit propertiesChanged(this); + } - emit runningStatusChanged(running); + emit runningStatusChanged(running); } int64_t BaseInstance::totalTimePlayed() const { - qint64 current = settings()->get("totalTimePlayed").toLongLong(); - if(m_isRunning) - { - QDateTime timeNow = QDateTime::currentDateTime(); - return current + m_timeStarted.secsTo(timeNow); - } - return current; + qint64 current = settings()->get("totalTimePlayed").toLongLong(); + if(m_isRunning) + { + QDateTime timeNow = QDateTime::currentDateTime(); + return current + m_timeStarted.secsTo(timeNow); + } + return current; } void BaseInstance::resetTimePlayed() { - settings()->reset("totalTimePlayed")