summaryrefslogtreecommitdiffstats
blob: 5a9bc4406a68c82f1665cdb03f2d4b47d5394c34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Copyright (c) 2010 Isode Limited..
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include "QtChatTheme.h"

#include <QFile>
#include <qdebug.h>

namespace Swift {

/**
 * Load Adium themes, as http://trac.adium.im/wiki/CreatingMessageStyles
 */
QtChatTheme::QtChatTheme(const QString& themePath) : qrc_(themePath.isEmpty()), themePath_(qrc_ ? ":/themes/Default/" : themePath + "/Contents/Resources/") {
	QString fileNames[EndMarker];
	fileNames[Header] = "Header.html";
	fileNames[Footer] = "Footer.html";
	fileNames[Content] = "Content.html";
	fileNames[Status] = "Status.html";
	fileNames[Topic] = "Topic.html";
	fileNames[FileTransferRequest] = "FileTransferRequest.html";
	fileNames[IncomingContent] = "Incoming/Content.html";
	fileNames[IncomingNextContent] = "Incoming/NextContent.html";
	fileNames[IncomingContext] = "Incoming/Context.html";
	fileNames[IncomingNextContext] = "Incoming/NextContext.html";
	fileNames[OutgoingContent] = "Outgoing/Content.html";
	fileNames[OutgoingNextContent] = "Outgoing/NextContent.html";
	fileNames[OutgoingContext] = "Outgoing/Context.html";
	fileNames[OutgoingNextContext] = "Outgoing/NextContext.html";
	fileNames[Template] = "Template.html";
	fileNames[MainCSS] = "main.css";
	fileNames[TemplateDefault] = ":/themes/Template.html";
	for (int i = 0; i < EndMarker; i++) {
		QString source;
		QFile sourceFile((i != TemplateDefault ? themePath_ : "") + fileNames[i]);
		if (sourceFile.exists() && sourceFile.open(QIODevice::ReadOnly)) {
			source = sourceFile.readAll();
			sourceFile.close();
		} else {
			//qWarning() << "Couldn't load file " << sourceFile.fileName();
		}
		fileContents_.append(source);
	}

	/* Fallbacks */
	if (fileContents_[Template].isEmpty()) fileContents_[Template] = fileContents_[TemplateDefault];
	if (fileContents_[Status].isEmpty()) fileContents_[Status] = fileContents_[Content];
	if (fileContents_[IncomingContent].isEmpty()) fileContents_[IncomingContent] = fileContents_[Content];
	if (fileContents_[IncomingNextContent].isEmpty()) fileContents_[IncomingNextContent] = fileContents_[IncomingContent];
	if (fileContents_[FileTransferRequest].isEmpty()) fileContents_[FileTransferRequest] = fileContents_[Status];
	if (fileContents_[IncomingContext].isEmpty()) fileContents_[IncomingContext] = fileContents_[IncomingContent];
	if (fileContents_[IncomingNextContext].isEmpty()) fileContents_[IncomingNextContext] = fileContents_[IncomingNextContent];
	if (fileContents_[OutgoingContent].isEmpty()) fileContents_[OutgoingContent] = fileContents_[IncomingContent];
	if (fileContents_[OutgoingContext].isEmpty()) fileContents_[OutgoingContext] = fileContents_[OutgoingContent];
	if (fileContents_[OutgoingNextContent].isEmpty()) fileContents_[OutgoingNextContent] = fileContents_[OutgoingContent];
	if (fileContents_[OutgoingNextContext].isEmpty()) fileContents_[OutgoingNextContext] = fileContents_[OutgoingNextContent];

}

QString QtChatTheme::getBase() const {
	return qrc_ ? "qrc" + themePath_ : "file://" + themePath_;
}

}