From b6d455a02bd338e9dc0faa09d4d8177ecd8d569a Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 10 Apr 2016 15:53:05 +0200 Subject: NOISSUE reorganize and document libraries --- api/gui/CMakeLists.txt | 28 + api/gui/DesktopServices.cpp | 149 +++++ api/gui/DesktopServices.h | 37 ++ api/gui/SkinUtils.cpp | 47 ++ api/gui/SkinUtils.h | 25 + api/gui/icons/IconList.cpp | 381 +++++++++++++ api/gui/icons/IconList.h | 85 +++ api/gui/icons/MMCIcon.cpp | 89 +++ api/gui/icons/MMCIcon.h | 55 ++ api/logic/AbstractCommonModel.cpp | 133 +++++ api/logic/AbstractCommonModel.h | 462 ++++++++++++++++ api/logic/BaseConfigObject.cpp | 103 ++++ api/logic/BaseConfigObject.h | 50 ++ api/logic/BaseInstaller.cpp | 61 ++ api/logic/BaseInstaller.h | 46 ++ api/logic/BaseInstance.cpp | 270 +++++++++ api/logic/BaseInstance.h | 243 ++++++++ api/logic/BaseVersion.h | 59 ++ api/logic/BaseVersionList.cpp | 104 ++++ api/logic/BaseVersionList.h | 126 +++++ api/logic/CMakeLists.txt | 344 ++++++++++++ api/logic/Commandline.cpp | 483 ++++++++++++++++ api/logic/Commandline.h | 252 +++++++++ api/logic/DefaultVariable.h | 35 ++ api/logic/Env.cpp | 222 ++++++++ api/logic/Env.h | 60 ++ api/logic/Exception.h | 34 ++ api/logic/FileSystem.cpp | 436 +++++++++++++++ api/logic/FileSystem.h | 123 ++++ api/logic/GZip.cpp | 115 ++++ api/logic/GZip.h | 12 + api/logic/InstanceList.cpp | 580 +++++++++++++++++++ api/logic/InstanceList.h | 187 +++++++ api/logic/Json.cpp | 272 +++++++++ api/logic/Json.h | 249 +++++++++ api/logic/MMCStrings.cpp | 76 +++ api/logic/MMCStrings.h | 10 + api/logic/MMCZip.cpp | 491 ++++++++++++++++ api/logic/MMCZip.h | 88 +++ api/logic/NullInstance.h | 90 +++ api/logic/QObjectPtr.h | 78 +++ api/logic/RWStorage.h | 60 ++ api/logic/RecursiveFileSystemWatcher.cpp | 111 ++++ api/logic/RecursiveFileSystemWatcher.h | 63 +++ api/logic/SeparatorPrefixTree.h | 298 ++++++++++ api/logic/TypeMagic.h | 37 ++ api/logic/Version.cpp | 140 +++++ api/logic/Version.h | 110 ++++ api/logic/java/JavaChecker.cpp | 159 ++++++ api/logic/java/JavaChecker.h | 54 ++ api/logic/java/JavaCheckerJob.cpp | 45 ++ api/logic/java/JavaCheckerJob.h | 84 +++ api/logic/java/JavaInstall.cpp | 28 + api/logic/java/JavaInstall.h | 38 ++ api/logic/java/JavaInstallList.cpp | 186 +++++++ api/logic/java/JavaInstallList.h | 71 +++ api/logic/java/JavaUtils.cpp | 219 ++++++++ api/logic/java/JavaUtils.h | 43 ++ api/logic/java/JavaVersion.cpp | 112 ++++ api/logic/java/JavaVersion.h | 30 + api/logic/launch/LaunchStep.cpp | 27 + api/logic/launch/LaunchStep.h | 48 ++ api/logic/launch/LaunchTask.cpp | 228 ++++++++ api/logic/launch/LaunchTask.h | 122 ++++ api/logic/launch/LoggedProcess.cpp | 163 ++++++ api/logic/launch/LoggedProcess.h | 76 +++ api/logic/launch/MessageLevel.cpp | 36 ++ api/logic/launch/MessageLevel.h | 28 + api/logic/launch/steps/CheckJava.cpp | 92 +++ api/logic/launch/steps/CheckJava.h | 41 ++ api/logic/launch/steps/LaunchMinecraft.cpp | 155 ++++++ api/logic/launch/steps/LaunchMinecraft.h | 48 ++ api/logic/launch/steps/ModMinecraftJar.cpp | 44 ++ api/logic/launch/steps/ModMinecraftJar.h | 39 ++ api/logic/launch/steps/PostLaunchCommand.cpp | 84 +++ api/logic/launch/steps/PostLaunchCommand.h | 39 ++ api/logic/launch/steps/PreLaunchCommand.cpp | 85 +++ api/logic/launch/steps/PreLaunchCommand.h | 39 ++ api/logic/launch/steps/TextPrint.cpp | 29 + api/logic/launch/steps/TextPrint.h | 43 ++ api/logic/launch/steps/Update.cpp | 50 ++ api/logic/launch/steps/Update.h | 41 ++ api/logic/minecraft/AssetsUtils.cpp | 230 ++++++++ api/logic/minecraft/AssetsUtils.h | 48 ++ api/logic/minecraft/GradleSpecifier.h | 129 +++++ api/logic/minecraft/JarMod.h | 12 + api/logic/minecraft/Library.cpp | 239 ++++++++ api/logic/minecraft/Library.h | 184 ++++++ api/logic/minecraft/MinecraftInstance.cpp | 369 ++++++++++++ api/logic/minecraft/MinecraftInstance.h | 69 +++ api/logic/minecraft/MinecraftProfile.cpp | 610 ++++++++++++++++++++ api/logic/minecraft/MinecraftProfile.h | 200 +++++++ api/logic/minecraft/MinecraftVersion.cpp | 215 +++++++ api/logic/minecraft/MinecraftVersion.h | 119 ++++ api/logic/minecraft/MinecraftVersionList.cpp | 591 ++++++++++++++++++++ api/logic/minecraft/MinecraftVersionList.h | 72 +++ api/logic/minecraft/Mod.cpp | 377 +++++++++++++ api/logic/minecraft/Mod.h | 134 +++++ api/logic/minecraft/ModList.cpp | 616 +++++++++++++++++++++ api/logic/minecraft/ModList.h | 160 ++++++ api/logic/minecraft/MojangDownloadInfo.h | 71 +++ api/logic/minecraft/MojangVersionFormat.cpp | 381 +++++++++++++ api/logic/minecraft/MojangVersionFormat.h | 25 + api/logic/minecraft/OpSys.cpp | 42 ++ api/logic/minecraft/OpSys.h | 37 ++ api/logic/minecraft/ParseUtils.cpp | 34 ++ api/logic/minecraft/ParseUtils.h | 11 + api/logic/minecraft/ProfilePatch.h | 104 ++++ api/logic/minecraft/ProfileStrategy.h | 35 ++ api/logic/minecraft/ProfileUtils.cpp | 191 +++++++ api/logic/minecraft/ProfileUtils.h | 25 + api/logic/minecraft/Rule.cpp | 93 ++++ api/logic/minecraft/Rule.h | 101 ++++ api/logic/minecraft/VersionBuildError.h | 58 ++ api/logic/minecraft/VersionFile.cpp | 60 ++ api/logic/minecraft/VersionFile.h | 195 +++++++ api/logic/minecraft/VersionFilterData.cpp | 75 +++ api/logic/minecraft/VersionFilterData.h | 32 ++ api/logic/minecraft/World.cpp | 385 +++++++++++++ api/logic/minecraft/World.h | 83 +++ api/logic/minecraft/WorldList.cpp | 355 ++++++++++++ api/logic/minecraft/WorldList.h | 125 +++++ api/logic/minecraft/auth/AuthSession.cpp | 30 + api/logic/minecraft/auth/AuthSession.h | 51 ++ api/logic/minecraft/auth/MojangAccount.cpp | 278 ++++++++++ api/logic/minecraft/auth/MojangAccount.h | 173 ++++++ api/logic/minecraft/auth/MojangAccountList.cpp | 427 ++++++++++++++ api/logic/minecraft/auth/MojangAccountList.h | 201 +++++++ api/logic/minecraft/auth/YggdrasilTask.cpp | 255 +++++++++ api/logic/minecraft/auth/YggdrasilTask.h | 150 +++++ .../minecraft/auth/flows/AuthenticateTask.cpp | 202 +++++++ api/logic/minecraft/auth/flows/AuthenticateTask.h | 46 ++ api/logic/minecraft/auth/flows/RefreshTask.cpp | 144 +++++ api/logic/minecraft/auth/flows/RefreshTask.h | 44 ++ api/logic/minecraft/auth/flows/ValidateTask.cpp | 61 ++ api/logic/minecraft/auth/flows/ValidateTask.h | 47 ++ api/logic/minecraft/forge/ForgeInstaller.cpp | 458 +++++++++++++++ api/logic/minecraft/forge/ForgeInstaller.h | 52 ++ api/logic/minecraft/forge/ForgeVersion.cpp | 55 ++ api/logic/minecraft/forge/ForgeVersion.h | 42 ++ api/logic/minecraft/forge/ForgeVersionList.cpp | 450 +++++++++++++++ api/logic/minecraft/forge/ForgeVersionList.h | 90 +++ api/logic/minecraft/forge/ForgeXzDownload.cpp | 358 ++++++++++++ api/logic/minecraft/forge/ForgeXzDownload.h | 59 ++ api/logic/minecraft/forge/LegacyForge.cpp | 56 ++ api/logic/minecraft/forge/LegacyForge.h | 25 + api/logic/minecraft/ftb/FTBPlugin.cpp | 395 +++++++++++++ api/logic/minecraft/ftb/FTBPlugin.h | 13 + api/logic/minecraft/ftb/FTBProfileStrategy.cpp | 128 +++++ api/logic/minecraft/ftb/FTBProfileStrategy.h | 21 + api/logic/minecraft/ftb/FTBVersion.h | 32 ++ api/logic/minecraft/ftb/LegacyFTBInstance.cpp | 27 + api/logic/minecraft/ftb/LegacyFTBInstance.h | 17 + api/logic/minecraft/ftb/OneSixFTBInstance.cpp | 138 +++++ api/logic/minecraft/ftb/OneSixFTBInstance.h | 30 + api/logic/minecraft/legacy/LegacyInstance.cpp | 453 +++++++++++++++ api/logic/minecraft/legacy/LegacyInstance.h | 142 +++++ api/logic/minecraft/legacy/LegacyUpdate.cpp | 393 +++++++++++++ api/logic/minecraft/legacy/LegacyUpdate.h | 70 +++ api/logic/minecraft/legacy/LwjglVersionList.cpp | 189 +++++++ api/logic/minecraft/legacy/LwjglVersionList.h | 156 ++++++ .../minecraft/liteloader/LiteLoaderInstaller.cpp | 142 +++++ .../minecraft/liteloader/LiteLoaderInstaller.h | 39 ++ .../minecraft/liteloader/LiteLoaderVersionList.cpp | 276 +++++++++ .../minecraft/liteloader/LiteLoaderVersionList.h | 119 ++++ api/logic/minecraft/onesix/OneSixInstance.cpp | 597 ++++++++++++++++++++ api/logic/minecraft/onesix/OneSixInstance.h | 117 ++++ .../minecraft/onesix/OneSixProfileStrategy.cpp | 418 ++++++++++++++ api/logic/minecraft/onesix/OneSixProfileStrategy.h | 26 + api/logic/minecraft/onesix/OneSixUpdate.cpp | 342 ++++++++++++ api/logic/minecraft/onesix/OneSixUpdate.h | 67 +++ api/logic/minecraft/onesix/OneSixVersionFormat.cpp | 225 ++++++++ api/logic/minecraft/onesix/OneSixVersionFormat.h | 22 + api/logic/net/ByteArrayDownload.cpp | 105 ++++ api/logic/net/ByteArrayDownload.h | 48 ++ api/logic/net/CacheDownload.cpp | 192 +++++++ api/logic/net/CacheDownload.h | 63 +++ api/logic/net/HttpMetaCache.cpp | 273 +++++++++ api/logic/net/HttpMetaCache.h | 125 +++++ api/logic/net/MD5EtagDownload.cpp | 155 ++++++ api/logic/net/MD5EtagDownload.h | 52 ++ api/logic/net/NetAction.h | 96 ++++ api/logic/net/NetJob.cpp | 125 +++++ api/logic/net/NetJob.h | 117 ++++ api/logic/net/PasteUpload.cpp | 99 ++++ api/logic/net/PasteUpload.h | 50 ++ api/logic/net/URLConstants.cpp | 16 + api/logic/net/URLConstants.h | 40 ++ api/logic/news/NewsChecker.cpp | 135 +++++ api/logic/news/NewsChecker.h | 107 ++++ api/logic/news/NewsEntry.cpp | 77 +++ api/logic/news/NewsEntry.h | 65 +++ api/logic/notifications/NotificationChecker.cpp | 130 +++++ api/logic/notifications/NotificationChecker.h | 63 +++ api/logic/pathmatcher/FSTreeMatcher.h | 21 + api/logic/pathmatcher/IPathMatcher.h | 12 + api/logic/pathmatcher/MultiMatcher.h | 31 ++ api/logic/pathmatcher/RegexpMatcher.h | 42 ++ api/logic/resources/Resource.cpp | 155 ++++++ api/logic/resources/Resource.h | 132 +++++ api/logic/resources/ResourceHandler.cpp | 28 + api/logic/resources/ResourceHandler.h | 36 ++ api/logic/resources/ResourceObserver.cpp | 55 ++ api/logic/resources/ResourceObserver.h | 73 +++ api/logic/resources/ResourceProxyModel.cpp | 89 +++ api/logic/resources/ResourceProxyModel.h | 39 ++ api/logic/screenshots/ImgurAlbumCreation.cpp | 90 +++ api/logic/screenshots/ImgurAlbumCreation.h | 44 ++ api/logic/screenshots/ImgurUpload.cpp | 114 ++++ api/logic/screenshots/ImgurUpload.h | 33 ++ api/logic/screenshots/Screenshot.h | 19 + api/logic/settings/INIFile.cpp | 151 +++++ api/logic/settings/INIFile.h | 38 ++ api/logic/settings/INISettingsObject.cpp | 107 ++++ api/logic/settings/INISettingsObject.h | 66 +++ api/logic/settings/OverrideSetting.cpp | 54 ++ api/logic/settings/OverrideSetting.h | 46 ++ api/logic/settings/PassthroughSetting.cpp | 66 +++ api/logic/settings/PassthroughSetting.h | 45 ++ api/logic/settings/Setting.cpp | 53 ++ api/logic/settings/Setting.h | 119 ++++ api/logic/settings/SettingsObject.cpp | 142 +++++ api/logic/settings/SettingsObject.h | 214 +++++++ api/logic/status/StatusChecker.cpp | 153 +++++ api/logic/status/StatusChecker.h | 60 ++ api/logic/tasks/SequentialTask.cpp | 55 ++ api/logic/tasks/SequentialTask.h | 31 ++ api/logic/tasks/Task.cpp | 88 +++ api/logic/tasks/Task.h | 96 ++++ api/logic/tasks/ThreadTask.cpp | 41 ++ api/logic/tasks/ThreadTask.h | 25 + api/logic/tools/BaseExternalTool.cpp | 41 ++ api/logic/tools/BaseExternalTool.h | 60 ++ api/logic/tools/BaseProfiler.cpp | 35 ++ api/logic/tools/BaseProfiler.h | 38 ++ api/logic/tools/JProfiler.cpp | 116 ++++ api/logic/tools/JProfiler.h | 15 + api/logic/tools/JVisualVM.cpp | 103 ++++ api/logic/tools/JVisualVM.h | 15 + api/logic/tools/MCEditTool.cpp | 124 +++++ api/logic/tools/MCEditTool.h | 26 + api/logic/trans/TranslationDownloader.cpp | 53 ++ api/logic/trans/TranslationDownloader.h | 32 ++ api/logic/updater/DownloadTask.cpp | 169 ++++++ api/logic/updater/DownloadTask.h | 95 ++++ api/logic/updater/GoUpdate.cpp | 215 +++++++ api/logic/updater/GoUpdate.h | 133 +++++ api/logic/updater/UpdateChecker.cpp | 269 +++++++++ api/logic/updater/UpdateChecker.h | 121 ++++ api/logic/wonko/BaseWonkoEntity.cpp | 39 ++ api/logic/wonko/BaseWonkoEntity.h | 51 ++ api/logic/wonko/WonkoIndex.cpp | 147 +++++ api/logic/wonko/WonkoIndex.h | 68 +++ api/logic/wonko/WonkoReference.cpp | 44 ++ api/logic/wonko/WonkoReference.h | 41 ++ api/logic/wonko/WonkoUtil.cpp | 47 ++ api/logic/wonko/WonkoUtil.h | 31 ++ api/logic/wonko/WonkoVersion.cpp | 102 ++++ api/logic/wonko/WonkoVersion.h | 83 +++ api/logic/wonko/WonkoVersionList.cpp | 283 ++++++++++ api/logic/wonko/WonkoVersionList.h | 92 +++ api/logic/wonko/format/WonkoFormat.cpp | 80 +++ api/logic/wonko/format/WonkoFormat.h | 54 ++ api/logic/wonko/format/WonkoFormatV1.cpp | 156 ++++++ api/logic/wonko/format/WonkoFormatV1.h | 30 + .../wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp | 117 ++++ .../wonko/tasks/BaseWonkoEntityLocalLoadTask.h | 81 +++ .../wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp | 126 +++++ .../wonko/tasks/BaseWonkoEntityRemoteLoadTask.h | 85 +++ 269 files changed, 33688 insertions(+) create mode 100644 api/gui/CMakeLists.txt create mode 100644 api/gui/DesktopServices.cpp create mode 100644 api/gui/DesktopServices.h create mode 100644 api/gui/SkinUtils.cpp create mode 100644 api/gui/SkinUtils.h create mode 100644 api/gui/icons/IconList.cpp create mode 100644 api/gui/icons/IconList.h create mode 100644 api/gui/icons/MMCIcon.cpp create mode 100644 api/gui/icons/MMCIcon.h create mode 100644 api/logic/AbstractCommonModel.cpp create mode 100644 api/logic/AbstractCommonModel.h create mode 100644 api/logic/BaseConfigObject.cpp create mode 100644 api/logic/BaseConfigObject.h create mode 100644 api/logic/BaseInstaller.cpp create mode 100644 api/logic/BaseInstaller.h create mode 100644 api/logic/BaseInstance.cpp create mode 100644 api/logic/BaseInstance.h create mode 100644 api/logic/BaseVersion.h create mode 100644 api/logic/BaseVersionList.cpp create mode 100644 api/logic/BaseVersionList.h create mode 100644 api/logic/CMakeLists.txt create mode 100644 api/logic/Commandline.cpp create mode 100644 api/logic/Commandline.h create mode 100644 api/logic/DefaultVariable.h create mode 100644 api/logic/Env.cpp create mode 100644 api/logic/Env.h create mode 100644 api/logic/Exception.h create mode 100644 api/logic/FileSystem.cpp create mode 100644 api/logic/FileSystem.h create mode 100644 api/logic/GZip.cpp create mode 100644 api/logic/GZip.h create mode 100644 api/logic/InstanceList.cpp create mode 100644 api/logic/InstanceList.h create mode 100644 api/logic/Json.cpp create mode 100644 api/logic/Json.h create mode 100644 api/logic/MMCStrings.cpp create mode 100644 api/logic/MMCStrings.h create mode 100644 api/logic/MMCZip.cpp create mode 100644 api/logic/MMCZip.h create mode 100644 api/logic/NullInstance.h create mode 100644 api/logic/QObjectPtr.h create mode 100644 api/logic/RWStorage.h create mode 100644 api/logic/RecursiveFileSystemWatcher.cpp create mode 100644 api/logic/RecursiveFileSystemWatcher.h create mode 100644 api/logic/SeparatorPrefixTree.h create mode 100644 api/logic/TypeMagic.h create mode 100644 api/logic/Version.cpp create mode 100644 api/logic/Version.h create mode 100644 api/logic/java/JavaChecker.cpp create mode 100644 api/logic/java/JavaChecker.h create mode 100644 api/logic/java/JavaCheckerJob.cpp create mode 100644 api/logic/java/JavaCheckerJob.h create mode 100644 api/logic/java/JavaInstall.cpp create mode 100644 api/logic/java/JavaInstall.h create mode 100644 api/logic/java/JavaInstallList.cpp create mode 100644 api/logic/java/JavaInstallList.h create mode 100644 api/logic/java/JavaUtils.cpp create mode 100644 api/logic/java/JavaUtils.h create mode 100644 api/logic/java/JavaVersion.cpp create mode 100644 api/logic/java/JavaVersion.h create mode 100644 api/logic/launch/LaunchStep.cpp create mode 100644 api/logic/launch/LaunchStep.h create mode 100644 api/logic/launch/LaunchTask.cpp create mode 100644 api/logic/launch/LaunchTask.h create mode 100644 api/logic/launch/LoggedProcess.cpp create mode 100644 api/logic/launch/LoggedProcess.h create mode 100644 api/logic/launch/MessageLevel.cpp create mode 100644 api/logic/launch/MessageLevel.h create mode 100644 api/logic/launch/steps/CheckJava.cpp create mode 100644 api/logic/launch/steps/CheckJava.h create mode 100644 api/logic/launch/steps/LaunchMinecraft.cpp create mode 100644 api/logic/launch/steps/LaunchMinecraft.h create mode 100644 api/logic/launch/steps/ModMinecraftJar.cpp create mode 100644 api/logic/launch/steps/ModMinecraftJar.h create mode 100644 api/logic/launch/steps/PostLaunchCommand.cpp create mode 100644 api/logic/launch/steps/PostLaunchCommand.h create mode 100644 api/logic/launch/steps/PreLaunchCommand.cpp create mode 100644 api/logic/launch/steps/PreLaunchCommand.h create mode 100644 api/logic/launch/steps/TextPrint.cpp create mode 100644 api/logic/launch/steps/TextPrint.h create mode 100644 api/logic/launch/steps/Update.cpp create mode 100644 api/logic/launch/steps/Update.h create mode 100644 api/logic/minecraft/AssetsUtils.cpp create mode 100644 api/logic/minecraft/AssetsUtils.h create mode 100644 api/logic/minecraft/GradleSpecifier.h create mode 100644 api/logic/minecraft/JarMod.h create mode 100644 api/logic/minecraft/Library.cpp create mode 100644 api/logic/minecraft/Library.h create mode 100644 api/logic/minecraft/MinecraftInstance.cpp create mode 100644 api/logic/minecraft/MinecraftInstance.h create mode 100644 api/logic/minecraft/MinecraftProfile.cpp create mode 100644 api/logic/minecraft/MinecraftProfile.h create mode 100644 api/logic/minecraft/MinecraftVersion.cpp create mode 100644 api/logic/minecraft/MinecraftVersion.h create mode 100644 api/logic/minecraft/MinecraftVersionList.cpp create mode 100644 api/logic/minecraft/MinecraftVersionList.h create mode 100644 api/logic/minecraft/Mod.cpp create mode 100644 api/logic/minecraft/Mod.h create mode 100644 api/logic/minecraft/ModList.cpp create mode 100644 api/logic/minecraft/ModList.h create mode 100644 api/logic/minecraft/MojangDownloadInfo.h create mode 100644 api/logic/minecraft/MojangVersionFormat.cpp create mode 100644 api/logic/minecraft/MojangVersionFormat.h create mode 100644 api/logic/minecraft/OpSys.cpp create mode 100644 api/logic/minecraft/OpSys.h create mode 100644 api/logic/minecraft/ParseUtils.cpp create mode 100644 api/logic/minecraft/ParseUtils.h create mode 100644 api/logic/minecraft/ProfilePatch.h create mode 100644 api/logic/minecraft/ProfileStrategy.h create mode 100644 api/logic/minecraft/ProfileUtils.cpp create mode 100644 api/logic/minecraft/ProfileUtils.h create mode 100644 api/logic/minecraft/Rule.cpp create mode 100644 api/logic/minecraft/Rule.h create mode 100644 api/logic/minecraft/VersionBuildError.h create mode 100644 api/logic/minecraft/VersionFile.cpp create mode 100644 api/logic/minecraft/VersionFile.h create mode 100644 api/logic/minecraft/VersionFilterData.cpp create mode 100644 api/logic/minecraft/VersionFilterData.h create mode 100644 api/logic/minecraft/World.cpp create mode 100644 api/logic/minecraft/World.h create mode 100644 api/logic/minecraft/WorldList.cpp create mode 100644 api/logic/minecraft/WorldList.h create mode 100644 api/logic/minecraft/auth/AuthSession.cpp create mode 100644 api/logic/minecraft/auth/AuthSession.h create mode 100644 api/logic/minecraft/auth/MojangAccount.cpp create mode 100644 api/logic/minecraft/auth/MojangAccount.h create mode 100644 api/logic/minecraft/auth/MojangAccountList.cpp create mode 100644 api/logic/minecraft/auth/MojangAccountList.h create mode 100644 api/logic/minecraft/auth/YggdrasilTask.cpp create mode 100644 api/logic/minecraft/auth/YggdrasilTask.h create mode 100644 api/logic/minecraft/auth/flows/AuthenticateTask.cpp create mode 100644 api/logic/minecraft/auth/flows/AuthenticateTask.h create mode 100644 api/logic/minecraft/auth/flows/RefreshTask.cpp create mode 100644 api/logic/minecraft/auth/flows/RefreshTask.h create mode 100644 api/logic/minecraft/auth/flows/ValidateTask.cpp create mode 100644 api/logic/minecraft/auth/flows/ValidateTask.h create mode 100644 api/logic/minecraft/forge/ForgeInstaller.cpp create mode 100644 api/logic/minecraft/forge/ForgeInstaller.h create mode 100644 api/logic/minecraft/forge/ForgeVersion.cpp create mode 100644 api/logic/minecraft/forge/ForgeVersion.h create mode 100644 api/logic/minecraft/forge/ForgeVersionList.cpp create mode 100644 api/logic/minecraft/forge/ForgeVersionList.h create mode 100644 api/logic/minecraft/forge/ForgeXzDownload.cpp create mode 100644 api/logic/minecraft/forge/ForgeXzDownload.h create mode 100644 api/logic/minecraft/forge/LegacyForge.cpp create mode 100644 api/logic/minecraft/forge/LegacyForge.h create mode 100644 api/logic/minecraft/ftb/FTBPlugin.cpp create mode 100644 api/logic/minecraft/ftb/FTBPlugin.h create mode 100644 api/logic/minecraft/ftb/FTBProfileStrategy.cpp create mode 100644 api/logic/minecraft/ftb/FTBProfileStrategy.h create mode 100644 api/logic/minecraft/ftb/FTBVersion.h create mode 100644 api/logic/minecraft/ftb/LegacyFTBInstance.cpp create mode 100644 api/logic/minecraft/ftb/LegacyFTBInstance.h create mode 100644 api/logic/minecraft/ftb/OneSixFTBInstance.cpp create mode 100644 api/logic/minecraft/ftb/OneSixFTBInstance.h create mode 100644 api/logic/minecraft/legacy/LegacyInstance.cpp create mode 100644 api/logic/minecraft/legacy/LegacyInstance.h create mode 100644 api/logic/minecraft/legacy/LegacyUpdate.cpp create mode 100644 api/logic/minecraft/legacy/LegacyUpdate.h create mode 100644 api/logic/minecraft/legacy/LwjglVersionList.cpp create mode 100644 api/logic/minecraft/legacy/LwjglVersionList.h create mode 100644 api/logic/minecraft/liteloader/LiteLoaderInstaller.cpp create mode 100644 api/logic/minecraft/liteloader/LiteLoaderInstaller.h create mode 100644 api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp create mode 100644 api/logic/minecraft/liteloader/LiteLoaderVersionList.h create mode 100644 api/logic/minecraft/onesix/OneSixInstance.cpp create mode 100644 api/logic/minecraft/onesix/OneSixInstance.h create mode 100644 api/logic/minecraft/onesix/OneSixProfileStrategy.cpp create mode 100644 api/logic/minecraft/onesix/OneSixProfileStrategy.h create mode 100644 api/logic/minecraft/onesix/OneSixUpdate.cpp create mode 100644 api/logic/minecraft/onesix/OneSixUpdate.h create mode 100644 api/logic/minecraft/onesix/OneSixVersionFormat.cpp create mode 100644 api/logic/minecraft/onesix/OneSixVersionFormat.h create mode 100644 api/logic/net/ByteArrayDownload.cpp create mode 100644 api/logic/net/ByteArrayDownload.h create mode 100644 api/logic/net/CacheDownload.cpp create mode 100644 api/logic/net/CacheDownload.h create mode 100644 api/logic/net/HttpMetaCache.cpp create mode 100644 api/logic/net/HttpMetaCache.h create mode 100644 api/logic/net/MD5EtagDownload.cpp create mode 100644 api/logic/net/MD5EtagDownload.h create mode 100644 api/logic/net/NetAction.h create mode 100644 api/logic/net/NetJob.cpp create mode 100644 api/logic/net/NetJob.h create mode 100644 api/logic/net/PasteUpload.cpp create mode 100644 api/logic/net/PasteUpload.h create mode 100644 api/logic/net/URLConstants.cpp create mode 100644 api/logic/net/URLConstants.h create mode 100644 api/logic/news/NewsChecker.cpp create mode 100644 api/logic/news/NewsChecker.h create mode 100644 api/logic/news/NewsEntry.cpp create mode 100644 api/logic/news/NewsEntry.h create mode 100644 api/logic/notifications/NotificationChecker.cpp create mode 100644 api/logic/notifications/NotificationChecker.h create mode 100644 api/logic/pathmatcher/FSTreeMatcher.h create mode 100644 api/logic/pathmatcher/IPathMatcher.h create mode 100644 api/logic/pathmatcher/MultiMatcher.h create mode 100644 api/logic/pathmatcher/RegexpMatcher.h create mode 100644 api/logic/resources/Resource.cpp create mode 100644 api/logic/resources/Resource.h create mode 100644 api/logic/resources/ResourceHandler.cpp create mode 100644 api/logic/resources/ResourceHandler.h create mode 100644 api/logic/resources/ResourceObserver.cpp create mode 100644 api/logic/resources/ResourceObserver.h create mode 100644 api/logic/resources/ResourceProxyModel.cpp create mode 100644 api/logic/resources/ResourceProxyModel.h create mode 100644 api/logic/screenshots/ImgurAlbumCreation.cpp create mode 100644 api/logic/screenshots/ImgurAlbumCreation.h create mode 100644 api/logic/screenshots/ImgurUpload.cpp create mode 100644 api/logic/screenshots/ImgurUpload.h create mode 100644 api/logic/screenshots/Screenshot.h create mode 100644 api/logic/settings/INIFile.cpp create mode 100644 api/logic/settings/INIFile.h create mode 100644 api/logic/settings/INISettingsObject.cpp create mode 100644 api/logic/settings/INISettingsObject.h create mode 100644 api/logic/settings/OverrideSetting.cpp create mode 100644 api/logic/settings/OverrideSetting.h create mode 100644 api/logic/settings/PassthroughSetting.cpp create mode 100644 api/logic/settings/PassthroughSetting.h create mode 100644 api/logic/settings/Setting.cpp create mode 100644 api/logic/settings/Setting.h create mode 100644 api/logic/settings/SettingsObject.cpp create mode 100644 api/logic/settings/SettingsObject.h create mode 100644 api/logic/status/StatusChecker.cpp create mode 100644 api/logic/status/StatusChecker.h create mode 100644 api/logic/tasks/SequentialTask.cpp create mode 100644 api/logic/tasks/SequentialTask.h create mode 100644 api/logic/tasks/Task.cpp create mode 100644 api/logic/tasks/Task.h create mode 100644 api/logic/tasks/ThreadTask.cpp create mode 100644 api/logic/tasks/ThreadTask.h create mode 100644 api/logic/tools/BaseExternalTool.cpp create mode 100644 api/logic/tools/BaseExternalTool.h create mode 100644 api/logic/tools/BaseProfiler.cpp create mode 100644 api/logic/tools/BaseProfiler.h create mode 100644 api/logic/tools/JProfiler.cpp create mode 100644 api/logic/tools/JProfiler.h create mode 100644 api/logic/tools/JVisualVM.cpp create mode 100644 api/logic/tools/JVisualVM.h create mode 100644 api/logic/tools/MCEditTool.cpp create mode 100644 api/logic/tools/MCEditTool.h create mode 100644 api/logic/trans/TranslationDownloader.cpp create mode 100644 api/logic/trans/TranslationDownloader.h create mode 100644 api/logic/updater/DownloadTask.cpp create mode 100644 api/logic/updater/DownloadTask.h create mode 100644 api/logic/updater/GoUpdate.cpp create mode 100644 api/logic/updater/GoUpdate.h create mode 100644 api/logic/updater/UpdateChecker.cpp create mode 100644 api/logic/updater/UpdateChecker.h create mode 100644 api/logic/wonko/BaseWonkoEntity.cpp create mode 100644 api/logic/wonko/BaseWonkoEntity.h create mode 100644 api/logic/wonko/WonkoIndex.cpp create mode 100644 api/logic/wonko/WonkoIndex.h create mode 100644 api/logic/wonko/WonkoReference.cpp create mode 100644 api/logic/wonko/WonkoReference.h create mode 100644 api/logic/wonko/WonkoUtil.cpp create mode 100644 api/logic/wonko/WonkoUtil.h create mode 100644 api/logic/wonko/WonkoVersion.cpp create mode 100644 api/logic/wonko/WonkoVersion.h create mode 100644 api/logic/wonko/WonkoVersionList.cpp create mode 100644 api/logic/wonko/WonkoVersionList.h create mode 100644 api/logic/wonko/format/WonkoFormat.cpp create mode 100644 api/logic/wonko/format/WonkoFormat.h create mode 100644 api/logic/wonko/format/WonkoFormatV1.cpp create mode 100644 api/logic/wonko/format/WonkoFormatV1.h create mode 100644 api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp create mode 100644 api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.h create mode 100644 api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp create mode 100644 api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.h (limited to 'api') diff --git a/api/gui/CMakeLists.txt b/api/gui/CMakeLists.txt new file mode 100644 index 00000000..1551a927 --- /dev/null +++ b/api/gui/CMakeLists.txt @@ -0,0 +1,28 @@ +project(MultiMC_logic) + +set(GUI_SOURCES + DesktopServices.h + DesktopServices.cpp + + # Icons + icons/MMCIcon.h + icons/MMCIcon.cpp + icons/IconList.h + icons/IconList.cpp + + SkinUtils.cpp + SkinUtils.h +) +################################ COMPILE ################################ + +add_library(MultiMC_gui SHARED ${GUI_SOURCES}) +set_target_properties(MultiMC_gui PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1) + +generate_export_header(MultiMC_gui) + +# Link +target_link_libraries(MultiMC_gui iconfix MultiMC_logic) +qt5_use_modules(MultiMC_gui Gui) + +# Mark and export headers +target_include_directories(MultiMC_gui PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") diff --git a/api/gui/DesktopServices.cpp b/api/gui/DesktopServices.cpp new file mode 100644 index 00000000..3154ea01 --- /dev/null +++ b/api/gui/DesktopServices.cpp @@ -0,0 +1,149 @@ +#include "DesktopServices.h" +#include +#include +#include +#include + +/** + * This shouldn't exist, but until QTBUG-9328 and other unreported bugs are fixed, it needs to be a thing. + */ +#if defined(Q_OS_LINUX) + +#include +#include +#include +#include + +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"); + + // open the URL + auto status = callable(); + + // 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; + } +} +#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())); + }; +#if defined(Q_OS_LINUX) + return IndirectOpen(f); +#else + return f(); +#endif +} + +bool openFile(const QString &path) +{ + qDebug() << "Opening file" << path; + auto f = [&]() + { + return QDesktopServices::openUrl(QUrl::fromLocalFile(path)); + }; +#if defined(Q_OS_LINUX) + return IndirectOpen(f); +#else + return f(); +#endif +} + +bool openFile(const QString &application, const QString &path, const QString &workingDirectory, qint64 *pid) +{ + 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); +#else + 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(' '); +#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); +#else + return QProcess::startDetached(application, args, workingDirectory, pid); +#endif +} + +bool openUrl(const QUrl &url) +{ + qDebug() << "Opening URL" << url.toString(); + auto f = [&]() + { + return QDesktopServices::openUrl(url); + }; +#if defined(Q_OS_LINUX) + return IndirectOpen(f); +#else + return f(); +#endif +} + +} diff --git a/api/gui/DesktopServices.h b/api/gui/DesktopServices.h new file mode 100644 index 00000000..9daf192a --- /dev/null +++ b/api/gui/DesktopServices.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include +#include "multimc_gui_export.h" + +/** + * This wraps around QDesktopServices and adds workarounds where needed + * Use this instead of QDesktopServices! + */ +namespace DesktopServices +{ + /** + * 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); + + /** + * 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 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 new file mode 100644 index 00000000..f69a1071 --- /dev/null +++ b/api/gui/SkinUtils.cpp @@ -0,0 +1,47 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "SkinUtils.h" +#include "net/HttpMetaCache.h" +#include "Env.h" + +#include +#include +#include +#include + +namespace SkinUtils +{ +/* + * Given a username, return a pixmap of the cached skin (if it exists), QPixmap() otherwise + */ +QPixmap getFaceFromCache(QString username, int height, int width) +{ + 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); + } + } + + return QPixmap(); +} +} diff --git a/api/gui/SkinUtils.h b/api/gui/SkinUtils.h new file mode 100644 index 00000000..29dcd6a6 --- /dev/null +++ b/api/gui/SkinUtils.h @@ -0,0 +1,25 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include "multimc_gui_export.h" + +namespace SkinUtils +{ +QPixmap MULTIMC_GUI_EXPORT getFaceFromCache(QString id, int height = 64, int width = 64); +} diff --git a/api/gui/icons/IconList.cpp b/api/gui/icons/IconList.cpp new file mode 100644 index 00000000..99def3b7 --- /dev/null +++ b/api/gui/icons/IconList.cpp @@ -0,0 +1,381 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "IconList.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_SIZE 1024 + +IconList::IconList(QString builtinPath, QString path, QObject *parent) : QAbstractListModel(parent) +{ + // add builtin icons + QDir instance_icons(builtinPath); + auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name); + for (auto file_info : file_info_list) + { + QString key = file_info.baseName(); + addIcon(key, key, file_info.absoluteFilePath(), MMCIcon::Builtin); + } + + 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(MMCIcon::FileBased)) + continue; + current_list.push_back(it.m_images[MMCIcon::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(MMCIcon::FileBased); + if (icons[idx].type() == MMCIcon::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(), MMCIcon::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[MMCIcon::FileBased].icon = icon; + dataChanged(index(idx), index(idx)); + emit iconUpdated(key); +} + +void IconList::SettingChanged(const Setting &setting, QVariant value) +{ + if(setting.id() != "IconsDir") + return; + + 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; + } +} + +void IconList::stopWatching() +{ + 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; +} +Qt::DropActions IconList::supportedDropActions() const +{ + return Qt::CopyAction; +} + +bool IconList::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, + 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; +} + +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; +} + +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(); + } +} + +int IconList::rowCount(const QModelIndex &parent) const +{ + return icons.size(); +} + +void IconList::installIcons(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") + continue; + + if (!QFile::copy(file, target)) + continue; + } +} + +bool IconList::iconFileExists(QString key) +{ + auto iconEntry = icon(key); + if(!iconEntry) + { + return false; + } + return iconEntry->has(MMCIcon::FileBased); +} + +const MMCIcon *IconList::icon(QString key) +{ + int iconIdx = getIconIndex(key); + if (iconIdx == -1) + return nullptr; + return &icons[iconIdx]; +} + +bool IconList::deleteIcon(QString key) +{ + int iconIdx = getIconIndex(key); + if (iconIdx == -1) + return false; + auto &iconEntry = icons[iconIdx]; + if (iconEntry.has(MMCIcon::FileBased)) + { + return QFile::remove(iconEntry.m_images[MMCIcon::FileBased].filename); + } + return false; +} + +bool IconList::addIcon(QString key, QString name, QString path, MMCIcon::Type type) +{ + // replace the icon even? is the input valid? + QIcon icon(path); + if (!icon.availableSizes().size()) + 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::reindex() +{ + name_index.clear(); + int i = 0; + for (auto &iter : icons) + { + name_index[iter.m_key] = i; + i++; + } +} + +QIcon IconList::getIcon(QString key) +{ + int icon_index = getIconIndex(key); + + if (icon_index != -1) + return icons[icon_index].icon(); + + // Fallback for icons that don't exist. + icon_index = getIconIndex("infinity"); + + if (icon_index != -1) + return icons[icon_index].icon(); + return QIcon(); +} + +QIcon IconList::getBigIcon(QString key) +{ + int icon_index = getIconIndex(key); + + if (icon_index == -1) + key = "infinity"; + + // Fallback for icons that don't exist. + icon_index = getIconIndex(key); + + if (icon_index == -1) + return QIcon(); + + QPixmap bigone = icons[icon_index].icon().pixmap(256,256).scaled(256,256); + return QIcon(bigone); +} + +int IconList::getIconIndex(QString key) +{ + if (key == "default") + key = "infinity"; + + auto iter = name_index.find(key); + if (iter != name_index.end()) + return *iter; + + return -1; +} + +//#include "IconList.moc" diff --git a/api/gui/icons/IconList.h b/api/gui/icons/IconList.h new file mode 100644 index 00000000..971db824 --- /dev/null +++ b/api/gui/icons/IconList.h @@ -0,0 +1,85 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include "MMCIcon.h" +#include "settings/Setting.h" +#include "Env.h" // there is a global icon list inside Env. + +#include "multimc_logic_export.h" + +class QFileSystemWatcher; + +class MULTIMC_LOGIC_EXPORT IconList : public QAbstractListModel +{ + Q_OBJECT +public: + explicit IconList(QString builtinPath, QString path, QObject *parent = 0); + virtual ~IconList() {}; + + QIcon getIcon(QString key); + QIcon getBigIcon(QString key); + int getIconIndex(QString key); + + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + + bool addIcon(QString key, QString name, QString path, MMCIcon::Type type); + bool deleteIcon(QString key); + bool iconFileExists(QString key); + + virtual QStringList mimeTypes() const; + virtual Qt::DropActions supportedDropActions() const; + virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, + const QModelIndex &parent); + virtual Qt::ItemFlags flags(const QModelIndex &index) const; + + void installIcons(QStringList iconFiles); + + const MMCIcon * icon(QString key); + + void startWatching(); + void stopWatching(); + +signals: + void iconUpdated(QString key); + +private: + // hide copy constructor + IconList(const IconList &) = delete; + // hide assign op + IconList &operator=(const IconList &) = delete; + void reindex(); + +public slots: + void directoryChanged(const QString &path); + +protected slots: + 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; +}; diff --git a/api/gui/icons/MMCIcon.cpp b/api/gui/icons/MMCIcon.cpp new file mode 100644 index 00000000..6b4eef39 --- /dev/null +++ b/api/gui/icons/MMCIcon.cpp @@ -0,0 +1,89 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MMCIcon.h" +#include + +MMCIcon::Type operator--(MMCIcon::Type &t, int) +{ + MMCIcon::Type temp = t; + switch (t) + { + case MMCIcon::Type::Builtin: + t = MMCIcon::Type::ToBeDeleted; + break; + case MMCIcon::Type::Transient: + t = MMCIcon::Type::Builtin; + break; + case MMCIcon::Type::FileBased: + t = MMCIcon::Type::Transient; + break; + default: + { + } + } + return temp; +} + +MMCIcon::Type MMCIcon::type() const +{ + return m_current_type; +} + +QString MMCIcon::name() const +{ + if (m_name.size()) + return m_name; + return m_key; +} + +bool MMCIcon::has(MMCIcon::Type _type) const +{ + return m_images[_type].present(); +} + +QIcon MMCIcon::icon() const +{ + if (m_current_type == Type::ToBeDeleted) + return QIcon(); + return m_images[m_current_type].icon; +} + +void MMCIcon::remove(Type rm_type) +{ + m_images[rm_type].filename = QString(); + m_images[rm_type].icon = QIcon(); + for (auto iter = rm_type; iter != Type::ToBeDeleted; iter--) + { + if (m_images[iter].present()) + { + m_current_type = iter; + return; + } + } + m_current_type = Type::ToBeDeleted; +} + +void MMCIcon::replace(MMCIcon::Type new_type, QIcon icon, QString path) +{ + QFileInfo foo(path); + if (new_type > m_current_type || m_current_type == MMCIcon::ToBeDeleted) + { + m_current_type = new_type; + } + m_images[new_type].icon = icon; + m_images[new_type].changed = foo.lastModified(); + m_images[new_type].filename = path; +} diff --git a/api/gui/icons/MMCIcon.h b/api/gui/icons/MMCIcon.h new file mode 100644 index 00000000..6f9617c2 --- /dev/null +++ b/api/gui/icons/MMCIcon.h @@ -0,0 +1,55 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include +#include + +#include "multimc_gui_export.h" + +struct MULTIMC_GUI_EXPORT MMCImage +{ + QIcon icon; + QString filename; + QDateTime changed; + bool present() const + { + return !icon.isNull(); + } +}; + +struct MULTIMC_GUI_EXPORT MMCIcon +{ + enum Type : unsigned + { + Builtin, + Transient, + FileBased, + ICONS_TOTAL, + ToBeDeleted + }; + QString m_key; + QString m_name; + MMCImage m_images[ICONS_TOTAL]; + Type m_current_type = ToBeDeleted; + + Type type() const; + QString name() const; + bool has(Type _type) const; + QIcon icon() const; + void remove(Type rm_type); + void replace(Type new_type, QIcon icon, QString path = QString()); +}; diff --git a/api/logic/AbstractCommonModel.cpp b/api/logic/AbstractCommonModel.cpp new file mode 100644 index 00000000..71d75829 --- /dev/null +++ b/api/logic/AbstractCommonModel.cpp @@ -0,0 +1,133 @@ +/* Copyright 2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AbstractCommonModel.h" + +BaseAbstractCommonModel::BaseAbstractCommonModel(const Qt::Orientation orientation, QObject *parent) + : QAbstractListModel(parent), m_orientation(orientation) +{ +} + +int BaseAbstractCommonModel::rowCount(const QModelIndex &parent) const +{ + return m_orientation == Qt::Horizontal ? entryCount() : size(); +} +int BaseAbstractCommonModel::columnCount(const QModelIndex &parent) const +{ + return m_orientation == Qt::Horizontal ? size() : entryCount(); +} +QVariant BaseAbstractCommonModel::data(const QModelIndex &index, int role) const +{ + if (!hasIndex(index.row(), index.column(), index.parent())) + { + return QVariant(); + } + const int i = m_orientation == Qt::Horizontal ? index.column() : index.row(); + const int entry = m_orientation == Qt::Horizontal ? index.row() : index.column(); + return formatData(i, role, get(i, entry, role)); +} +QVariant BaseAbstractCommonModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation != m_orientation && role == Qt::DisplayRole) + { + return entryTitle(section); + } + else + { + return QVariant(); + } +} +bool BaseAbstractCommonModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + const int i = m_orientation == Qt::Horizontal ? index.column() : index.row(); + const int entry = m_orientation == Qt::Horizontal ? index.row() : index.column(); + const bool result = set(i, entry, role, sanetizeData(i, role, value)); + if (result) + { + emit dataChanged(index, index, QVector() << role); + } + return result; +} +Qt::ItemFlags BaseAbstractCommonModel::flags(const QModelIndex &index) const +{ + if (!hasIndex(index.row(), index.column(), index.parent())) + { + return Qt::NoItemFlags; + } + + const int entry = m_orientation == Qt::Horizontal ? index.row() : index.column(); + if (canSet(entry)) + { + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEnabled; + } + else + { + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + } +} + +void BaseAbstractCommonModel::notifyAboutToAddObject(const int at) +{ + if (m_orientation == Qt::Horizontal) + { + beginInsertColumns(QModelIndex(), at, at); + } + else + { + beginInsertRows(QModelIndex(), at, at); + } +} +void BaseAbstractCommonModel::notifyObjectAdded() +{ + if (m_orientation == Qt::Horizontal) + { + endInsertColumns(); + } + else + { + endInsertRows(); + } +} +void BaseAbstractCommonModel::notifyAboutToRemoveObject(const int at) +{ + if (m_orientation == Qt::Horizontal) + { + beginRemoveColumns(QModelIndex(), at, at); + } + else + { + beginRemoveRows(QModelIndex(), at, at); + } +} +void BaseAbstractCommonModel::notifyObjectRemoved() +{ + if (m_orientation == Qt::Horizontal) + { + endRemoveColumns(); + } + else + { + endRemoveRows(); + } +} + +void BaseAbstractCommonModel::notifyBeginReset() +{ + beginResetModel(); +} +void BaseAbstractCommonModel::notifyEndReset() +{ + endResetModel(); +} diff --git a/api/logic/AbstractCommonModel.h b/api/logic/AbstractCommonModel.h new file mode 100644 index 00000000..31b86a23 --- /dev/null +++ b/api/logic/AbstractCommonModel.h @@ -0,0 +1,462 @@ +/* Copyright 2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include + +class BaseAbstractCommonModel : public QAbstractListModel +{ + Q_OBJECT +public: + explicit BaseAbstractCommonModel(const Qt::Orientation orientation, QObject *parent = nullptr); + + // begin QAbstractItemModel interface + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + bool setData(const QModelIndex &index, const QVariant &value, int role) override; + Qt::ItemFlags flags(const QModelIndex &index) const override; + // end QAbstractItemModel interface + + virtual int size() const = 0; + virtual int entryCount() const = 0; + + virtual QVariant formatData(const int index, int role, const QVariant &data) const { return data; } + virtual QVariant sanetizeData(const int index, int role, const QVariant &data) const { return data; } + +protected: + virtual QVariant get(const int index, const int entry, const int role) const = 0; + virtual bool set(const int index, const int entry, const int role, const QVariant &value) = 0; + virtual bool canSet(const int entry) const = 0; + virtual QString entryTitle(const int entry) const = 0; + + void notifyAboutToAddObject(const int at); + void notifyObjectAdded(); + void notifyAboutToRemoveObject(const int at); + void notifyObjectRemoved(); + void notifyBeginReset(); + void notifyEndReset(); + + const Qt::Orientation m_orientation; +}; + +template +class AbstractCommonModel : public BaseAbstractCommonModel +{ +public: + explicit AbstractCommonModel(const Qt::Orientation orientation) + : BaseAbstractCommonModel(orientation) {} + virtual ~AbstractCommonModel() {} + + int size() const override { return m_objects.size(); } + int entryCount() const override { return m_entries.size(); } + + void append(const Object &object) + { + notifyAboutToAddObject(size()); + m_objects.append(object); + notifyObjectAdded(); + } + void prepend(const Object &object) + { + notifyAboutToAddObject(0); + m_objects.prepend(object); + notifyObjectAdded(); + } + void insert(const Object &object, const int index) + { + if (index >= size()) + { + prepend(object); + } + else if (index <= 0) + { + append(object); + } + else + { + notifyAboutToAddObject(index); + m_objects.insert(index, object); + notifyObjectAdded(); + } + } + void remove(const int index) + { + notifyAboutToRemoveObject(index); + m_objects.removeAt(index); + notifyObjectRemoved(); + } + Object get(const int index) const + { + return m_objects.at(index); + } + +private: + friend class CommonModel; + QVariant get(const int index, const int entry, const int role) const override + { + if (m_entries.size() < entry || !m_entries[entry].second.contains(role)) + { + return QVariant(); + } + return m_entries[entry].second.value(role)->get(m_objects.at(index)); + } + bool set(const int index, const int entry, const int role, const QVariant &value) override + { + if (m_entries.size() < entry || !m_entries[entry].second.contains(role)) + { + return false; + } + IEntry *e = m_entries[entry].second.value(role); + if (!e->canSet()) + { + return false; + } + e->set(m_objects[index], value); + return true; + } + bool canSet(const int entry) const override + { + if (m_entries.size() < entry || !m_entries[entry].second.contains(Qt::EditRole)) + { + return false; + } + IEntry *e = m_entries[entry].second.value(Qt::EditRole); + return e->canSet(); + } + + QString entryTitle(const int entry) const override + { + return m_entries.at(entry).first; + } + +private: + struct IEntry + { + virtual ~IEntry() {} + virtual void set(Object &object, const QVariant &value) = 0; + virtual QVariant get(const Object &object) const = 0; + virtual bool canSet() const = 0; + }; + template + struct VariableEntry : public IEntry + { + typedef T (Object::*Member); + + explicit VariableEntry(Member member) + : m_member(member) {} + + void set(Object &object, const QVariant &value) override + { + object.*m_member = value.value(); + } + QVariant get(const Object &object) const override + { + return QVariant::fromValue(object.*m_member); + } + bool canSet() const override { return true; } + + private: + Member m_member; + }; + template + struct FunctionEntry : public IEntry + { + typedef T (Object::*Getter)() const; + typedef void (Object::*Setter)(T); + + explicit FunctionEntry(Getter getter, Setter setter) + : m_getter(m_getter), m_setter(m_setter) {} + + void set(Object &object, const QVariant &value) override + { + object.*m_setter(value.value()); + } + QVariant get(const Obj