Skip to content

Commit

Permalink
Fixed to loading Adium themes from zip archive
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Jul 6, 2024
1 parent f08f76f commit 5f192bd
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/chatviewcommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ QString ChatViewCommon::getMucNickColor(const QString &nick, bool isSelf)
return nickColors[it.value() % (nickColors.size() - 1)];
} while (false);

return QLatin1String("#000000"); // FIXME it's bad for fallback color
return qApp->palette().color(QPalette::Inactive, QPalette::WindowText).name();
}

void ChatViewCommon::addUser(const QString &nickname) { }
Expand Down
5 changes: 4 additions & 1 deletion src/chatviewtheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,10 @@ QVariantMap ChatViewJSLoader::checkFilesExist(const QStringList &files, const QS
QStringList ChatViewJSLoader::listFiles()
{
QScopedPointer<Theme::ResourceLoader> loader(Theme(theme).resourceLoader());
return loader->listAll();
if (loader) {
return loader->listAll();
}
return {};
}

QString ChatViewJSLoader::getFileContents(const QString &name) const { return QString(Theme(theme).loadData(name)); }
Expand Down
3 changes: 2 additions & 1 deletion src/chatviewthemeprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const QStringList ChatViewThemeProvider::themeIds() const
QString typeName = tDirInfo.fileName();
foreach (QFileInfo themeInfo,
QDir(tDirInfo.absoluteFilePath()).entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot)
+ QDir(tDirInfo.absoluteFilePath()).entryInfoList(QStringList("*.theme"), QDir::Files)) {
+ QDir(tDirInfo.absoluteFilePath())
.entryInfoList(QStringList { { "*.theme", "*.zip" } }, QDir::Files)) {
ret << (QString("%1/%2").arg(typeName, themeInfo.fileName()));
// qDebug("found theme: %s", qPrintable(QString("%1/%2").arg(typeName).arg(themeInfo.fileName())));
}
Expand Down
8 changes: 4 additions & 4 deletions src/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ QWidget *Theme::previewWidget() { return d->previewWidget(); }
bool Theme::isCompressed(const QFileInfo &fi)
{
QString sfx = fi.suffix();
return fi.isDir() && (sfx == QLatin1String("jisp") || sfx == QLatin1String("zip") || sfx == QLatin1String("theme"));
return fi.isFile()
&& (sfx == QLatin1String("jisp") || sfx == QLatin1String("zip") || sfx == QLatin1String("theme"));
}

bool Theme::isCompressed() const { return isCompressed(QFileInfo(d->filepath)); }
Expand Down Expand Up @@ -144,9 +145,8 @@ QByteArray Theme::loadData(const QString &fileName, const QString &themePath, bo
z.setCaseSensitivity(UnZip::CS_Insensitive);
}

QString n = fi.completeBaseName() + '/' + fileName;
if (!z.readFile(n, &ba)) {
n = "/" + fileName;
if (!z.readFile(fileName, &ba)) {
auto n = "/" + fileName;
if (loaded) {
*loaded = z.readFile(n, &ba);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/theme_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Theme::ResourceLoader *ThemePrivate::resourceLoader() const
}
#ifdef Theme_ZIP
else if (Theme::isCompressed(fi)) {
UnZip z;
UnZip z(fi.filePath());
if (z.open()) {
if (caseInsensitiveFS) {
z.setCaseSensitivity(UnZip::CS_Insensitive);
Expand Down
55 changes: 34 additions & 21 deletions themes/chatview/adium/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,36 @@ var adapter = {
loadTheme : function(style) {
//var chat = chat;
var loader = window.srvLoader;
var baseDir = "";
loader.toCache("variant", style);
//chat.console("DEBUG: loading " );
loader.setCaseInsensitiveFS(true);
loader.setPrepareSessionHtml(true);
loader.setHttpResourcePath("/Contents/Resources");
//chat.console("DEBUG: loading " + loader.themeId);
var resources = ["FileTransferRequest.html",
"Footer.html", "Header.html", "Status.html", "Topic.html", "Content.html",
"Incoming/Content.html", "Incoming/NextContent.html",
"Incoming/Context.html", "Incoming/NextContext.html",
"Outgoing/Content.html", "Outgoing/NextContent.html",
"Outgoing/Context.html", "Outgoing/NextContext.html"];

var toCache = {};
for (var i=0; i<resources.length; i++) {
toCache[resources[i]] = "Contents/Resources/" + resources[i];
}
loader.saveFilesToCache(toCache);

function gotFilesList(filesList) {
chat.console(filesList.join(","));
chat.util.loadXML("Contents/Info.plist", plistLoaded);
filesList = filesList.filter((path) => !(path.startsWith("__MACOSX") || path.startsWith(".") || path.endsWith("DS_Store")));
const value = filesList.find((path)=>path.split("/")[0].toLowerCase().endsWith("adiummessagestyle"));
if (value) {
baseDir = value.split("/")[0] + "/";
}
loader.setHttpResourcePath("/" + baseDir + "Contents/Resources");

//chat.console("DEBUG: loading " + loader.themeId);
var resources = ["FileTransferRequest.html",
"Footer.html", "Header.html", "Status.html", "Topic.html", "Content.html",
"Incoming/Content.html", "Incoming/NextContent.html",
"Incoming/Context.html", "Incoming/NextContext.html",
"Outgoing/Content.html", "Outgoing/NextContent.html",
"Outgoing/Context.html", "Outgoing/NextContext.html"];

var toCache = {};
for (var i=0; i<resources.length; i++) {
toCache[resources[i]] = baseDir + "Contents/Resources/" + resources[i];
}
loader.saveFilesToCache(toCache);

chat.console("Found base dir: " + value);
chat.util.loadXML(baseDir + "Contents/Info.plist", plistLoaded);
}

function plistLoaded(ipDoc)
Expand Down Expand Up @@ -98,11 +106,16 @@ var adapter = {
loader.setTransparent();
}

var resources = ["Incoming/buddy_icon.png", "Outgoing/buddy_icon.png", "incoming_icon.png", "outgoing_icon.png"];
var resources = [
"Incoming/buddy_icon.png",
"Outgoing/buddy_icon.png",
"incoming_icon.png",
"outgoing_icon.png"
];
if (chat.async) {
loader.checkFilesExist(resources, "Contents/Resources", resourcesListReady);
loader.checkFilesExist(resources, baseDir + "Contents/Resources", resourcesListReady);
} else {
resourcesListReady(loader.checkFilesExist(resources, "Contents/Resources"));
resourcesListReady(loader.checkFilesExist(resources, baseDir + "Contents/Resources"));
}
}

Expand All @@ -115,9 +128,9 @@ var adapter = {
avatars.outgoingImage = rlist["outgoing_icon.png"]? "outgoing_icon.png" : chat.server.psiDefaultAvatarUrl;
loader.toCache("avatars", avatars)
if (chat.async) {
loader.getFileContents("Contents/Resources/Template.html", baseHtmlLoaded);
loader.getFileContents(baseDir + "Contents/Resources/Template.html", baseHtmlLoaded);
} else {
baseHtmlLoaded(loader.getFileContents("Contents/Resources/Template.html"));
baseHtmlLoaded(loader.getFileContents(baseDir + "Contents/Resources/Template.html"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion themes/chatview/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ ${info}
}
},

listAllFiles : function(callback) {
listAllFiles : function(callback) {
if (chat.async) {
loader.listFiles(callback);
} else {
Expand Down

0 comments on commit 5f192bd

Please sign in to comment.