BACKENDS: Add support for qualified game IDs in taskbar icons

This commit is contained in:
SupSuper 2020-09-09 01:57:57 +01:00
parent 5a35089aa5
commit 28ecec9662
5 changed files with 56 additions and 84 deletions

View file

@ -42,8 +42,6 @@ public:
virtual void clearError();
private:
Common::String getIconPath(const Common::String&);
void initApplicationIconView();
void clearApplicationIconView();

View file

@ -27,8 +27,6 @@
#if defined(MACOSX) && defined(USE_TASKBAR)
#include "backends/taskbar/macosx/macosx-taskbar.h"
#include "common/config-manager.h"
#include "common/file.h"
#include "backends/platform/sdl/macosx/macosx-compat.h"
#include <AppKit/NSApplication.h>
#include <AppKit/NSImage.h>
@ -119,7 +117,7 @@ void MacOSXTaskbarManager::setOverlayIcon(const Common::String &name, const Comm
return;
}
Common::String path = getIconPath(name);
Common::String path = getIconPath(name, ".png");
if (path.empty())
return;
@ -208,38 +206,6 @@ void MacOSXTaskbarManager::clearError() {
return;
}
Common::String MacOSXTaskbarManager::getIconPath(const Common::String& target) {
// We first try to look for a iconspath configuration variable then
// fallback to the extra path
//
// Icons can be either in a subfolder named "icons" or directly in the path
Common::String iconsPath = ConfMan.get("iconspath");
Common::String extraPath = ConfMan.get("extrapath");
#define TRY_ICON_PATH(path) { \
Common::FSNode node((path)); \
if (node.exists()) \
return (path); \
}
if (!iconsPath.empty()) {
TRY_ICON_PATH(iconsPath + "/" + target + ".png");
TRY_ICON_PATH(iconsPath + "/" + ConfMan.get("gameid") + ".png");
TRY_ICON_PATH(iconsPath + "/icons/" + target + ".png");
TRY_ICON_PATH(iconsPath + "/icons/" + ConfMan.get("gameid") + ".png");
}
if (!extraPath.empty()) {
TRY_ICON_PATH(extraPath + "/" + target + ".png");
TRY_ICON_PATH(extraPath + "/" + ConfMan.get("gameid") + ".png");
TRY_ICON_PATH(extraPath + "/icons/" + target + ".png");
TRY_ICON_PATH(extraPath + "/icons/" + ConfMan.get("gameid") + ".png");
}
return "";
}
void MacOSXTaskbarManager::addRecent(const Common::String &name, const Common::String &description) {
//warning("[MacOSXTaskbarManager::addRecent] Adding recent list entry: %s (%s)", name.c_str(), description.c_str());
@ -258,7 +224,7 @@ void MacOSXTaskbarManager::addRecent(const Common::String &name, const Common::S
[dict setObject:(NSString *)desc forKey:@"description"];
// Icon
Common::String iconPath = getIconPath(name);
Common::String iconPath = getIconPath(name, ".png");
if (!iconPath.empty()) {
CFStringRef icon = CFStringCreateWithCString(0, iconPath.c_str(), kCFStringEncodingASCII);
[dict setObject:(NSString *)icon forKey:@"icon"];

View file

@ -65,9 +65,7 @@
#include "backends/platform/sdl/win32/win32-window.h"
#include "backends/platform/sdl/win32/win32_wrapper.h"
#include "common/config-manager.h"
#include "common/textconsole.h"
#include "common/file.h"
// System.Title property key, values taken from http://msdn.microsoft.com/en-us/library/bb787584.aspx
const PROPERTYKEY PKEY_Title = { /* fmtid = */ { 0xF29F85E0, 0x4FF9, 0x1068, { 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9 } }, /* propID = */ 2 };
@ -120,7 +118,7 @@ void Win32TaskbarManager::setOverlayIcon(const Common::String &name, const Commo
}
// Compute full icon path
Common::String path = getIconPath(name);
Common::String path = getIconPath(name, ".ico");
if (path.empty())
return;
@ -293,7 +291,7 @@ void Win32TaskbarManager::addRecent(const Common::String &name, const Common::St
link->SetPath(path);
link->SetArguments(game);
Common::String iconPath = getIconPath(name);
Common::String iconPath = getIconPath(name, ".ico");
if (iconPath.empty()) {
link->SetIconLocation(path, 0); // No game-specific icon available
} else {
@ -335,36 +333,4 @@ void Win32TaskbarManager::clearError() {
setProgressState(kTaskbarNoProgress);
}
Common::String Win32TaskbarManager::getIconPath(Common::String target) {
// We first try to look for a iconspath configuration variable then
// fallback to the extra path
//
// Icons can be either in a subfolder named "icons" or directly in the path
Common::String iconsPath = ConfMan.get("iconspath");
Common::String extraPath = ConfMan.get("extrapath");
#define TRY_ICON_PATH(path) { \
Common::FSNode node((path)); \
if (node.exists()) \
return (path); \
}
if (!iconsPath.empty()) {
TRY_ICON_PATH(iconsPath + "/" + target + ".ico");
TRY_ICON_PATH(iconsPath + "/" + ConfMan.get("gameid") + ".ico");
TRY_ICON_PATH(iconsPath + "/icons/" + target + ".ico");
TRY_ICON_PATH(iconsPath + "/icons/" + ConfMan.get("gameid") + ".ico");
}
if (!extraPath.empty()) {
TRY_ICON_PATH(extraPath + "/" + target + ".ico");
TRY_ICON_PATH(extraPath + "/" + ConfMan.get("gameid") + ".ico");
TRY_ICON_PATH(extraPath + "/icons/" + target + ".ico");
TRY_ICON_PATH(extraPath + "/icons/" + ConfMan.get("gameid") + ".ico");
}
return "";
}
#endif

View file

@ -52,15 +52,6 @@ private:
// Count handling
HICON _icon;
int _count;
/**
* Get the path to an icon for the game
*
* @param target The game target
*
* @return The icon path (or "" if no icon was found)
*/
Common::String getIconPath(Common::String target);
};
#endif

View file

@ -24,10 +24,13 @@
#define COMMON_TASKBAR_MANAGER_H
#include "common/scummsys.h"
#include "common/str.h"
#if defined(USE_TASKBAR)
#include "common/str.h"
#include "common/config-manager.h"
#include "common/file.h"
namespace Common {
/**
@ -134,6 +137,54 @@ public:
* Clears the error notification
*/
virtual void clearError() {}
protected:
/**
* Get the path to an icon for the game
*
* @param target The game target
* @param extension The icon extension
* @return The icon path (or "" if no icon was found)
*/
Common::String getIconPath(const Common::String &target, const Common::String &extension) {
// We first try to look for a iconspath configuration variable then
// fallback to the extra path
//
// Icons can be either in a subfolder named "icons" or directly in the path
Common::String iconsPath = ConfMan.get("iconspath");
Common::String extraPath = ConfMan.get("extrapath");
Common::String targetIcon = target + extension;
Common::String qualifiedIcon = ConfMan.get("engineid") + "-" + ConfMan.get("gameid") + extension;
Common::String gameIcon = ConfMan.get("gameid") + extension;
#define TRY_ICON_PATH(path) { \
Common::FSNode node((path)); \
if (node.exists()) \
return (path); \
}
if (!iconsPath.empty()) {
TRY_ICON_PATH(iconsPath + "/" + targetIcon);
TRY_ICON_PATH(iconsPath + "/" + qualifiedIcon);
TRY_ICON_PATH(iconsPath + "/" + gameIcon);
TRY_ICON_PATH(iconsPath + "/icons/" + targetIcon);
TRY_ICON_PATH(iconsPath + "/icons/" + qualifiedIcon);
TRY_ICON_PATH(iconsPath + "/icons/" + gameIcon);
}
if (!extraPath.empty()) {
TRY_ICON_PATH(extraPath + "/" + targetIcon);
TRY_ICON_PATH(extraPath + "/" + qualifiedIcon);
TRY_ICON_PATH(extraPath + "/" + gameIcon);
TRY_ICON_PATH(extraPath + "/icons/" + targetIcon);
TRY_ICON_PATH(extraPath + "/icons/" + qualifiedIcon);
TRY_ICON_PATH(extraPath + "/icons/" + gameIcon);
}
#undef TRY_ICON_PATH
return "";
}
};
} // End of namespace Common