mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-03 02:50:07 -05:00
Styles for public chat, private chat and history.
RetroShare has a standard style for each type, but the user can define their own styles. The external directories "style/public", "style/private" and "style/history" are scanned for subdirs with user defined style informations. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3453 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
452faffa4b
commit
6bd6c50502
@ -202,7 +202,7 @@ PeersDialog::PeersDialog(QWidget *parent)
|
||||
mCurrentFont.fromString(Settings->valueFromGroup("Chat", QString::fromUtf8("ChatScreenFont")).toString());
|
||||
ui.lineEdit->setFont(mCurrentFont);
|
||||
|
||||
style.setStylePath(":/qss/chat/public");
|
||||
style.setStyleFromSettings(ChatStyle::TYPE_PUBLIC);
|
||||
style.loadEmoticons();
|
||||
|
||||
setChatInfo(tr("Welcome to RetroShare's group chat."), QString::fromUtf8("blue"));
|
||||
|
@ -26,9 +26,13 @@
|
||||
#include <QFile>
|
||||
#include <QIcon>
|
||||
#include <QPushButton>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "ChatStyle.h"
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
#include "gui/notifyqt.h"
|
||||
|
||||
enum enumGetStyle
|
||||
{
|
||||
@ -39,8 +43,11 @@ enum enumGetStyle
|
||||
};
|
||||
|
||||
/* Default constructor */
|
||||
ChatStyle::ChatStyle()
|
||||
ChatStyle::ChatStyle() : QObject()
|
||||
{
|
||||
m_styleType = TYPE_UNKNOWN;
|
||||
|
||||
connect(NotifyQt::getInstance(), SIGNAL(chatStyleChanged(int)), SLOT(styleChanged(int)));
|
||||
}
|
||||
|
||||
/* Destructor. */
|
||||
@ -48,14 +55,51 @@ ChatStyle::~ChatStyle()
|
||||
{
|
||||
}
|
||||
|
||||
void ChatStyle::setStylePath(QString path)
|
||||
void ChatStyle::styleChanged(int styleType)
|
||||
{
|
||||
stylePath = path;
|
||||
if (stylePath.right(1) != "/" && stylePath.right(1) != "\\") {
|
||||
stylePath += "/";
|
||||
if (m_styleType == styleType) {
|
||||
setStyleFromSettings(m_styleType);
|
||||
}
|
||||
}
|
||||
|
||||
bool ChatStyle::setStylePath(QString stylePath)
|
||||
{
|
||||
m_styleType = TYPE_UNKNOWN;
|
||||
|
||||
m_styleDir.setPath(QApplication::applicationDirPath());
|
||||
if (m_styleDir.cd(stylePath) == false) {
|
||||
m_styleDir = QDir("");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatStyle::setStyleFromSettings(enumStyleType styleType)
|
||||
{
|
||||
QString stylePath;
|
||||
|
||||
switch (styleType) {
|
||||
case TYPE_PUBLIC:
|
||||
Settings->getPublicChatStyle(stylePath);
|
||||
break;
|
||||
case TYPE_PRIVATE:
|
||||
Settings->getPrivateChatStyle(stylePath);
|
||||
break;
|
||||
case TYPE_HISTORY:
|
||||
Settings->getHistoryChatStyle(stylePath);
|
||||
break;
|
||||
case TYPE_UNKNOWN:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = setStylePath(stylePath);
|
||||
|
||||
m_styleType = styleType;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ChatStyle::loadEmoticons()
|
||||
{
|
||||
QString sm_codes;
|
||||
@ -204,27 +248,27 @@ void ChatStyle::showSmileyWidget(QWidget *parent, QWidget *button, const char *s
|
||||
smWidget->show();
|
||||
}
|
||||
|
||||
static QString getStyle(QString &stylePath, enumGetStyle type)
|
||||
static QString getStyle(QDir &styleDir, enumGetStyle type)
|
||||
{
|
||||
QString style;
|
||||
|
||||
if (stylePath.isEmpty()) {
|
||||
if (styleDir == QDir("")) {
|
||||
return "";
|
||||
}
|
||||
|
||||
QFile fileHtml;
|
||||
switch (type) {
|
||||
case GETSTYLE_INCOMING:
|
||||
fileHtml.setFileName(stylePath + "incoming.htm");
|
||||
fileHtml.setFileName(QFileInfo(styleDir, "incoming.htm").absoluteFilePath());
|
||||
break;
|
||||
case GETSTYLE_OUTGOING:
|
||||
fileHtml.setFileName(stylePath + "outgoing.htm");
|
||||
fileHtml.setFileName(QFileInfo(styleDir, "outgoing.htm").absoluteFilePath());
|
||||
break;
|
||||
case GETSTYLE_HINCOMING:
|
||||
fileHtml.setFileName(stylePath + "hincoming.htm");
|
||||
fileHtml.setFileName(QFileInfo(styleDir, "hincoming.htm").absoluteFilePath());
|
||||
break;
|
||||
case GETSTYLE_HOUTGOING:
|
||||
fileHtml.setFileName(stylePath + "houtgoing.htm");
|
||||
fileHtml.setFileName(QFileInfo(styleDir, "houtgoing.htm").absoluteFilePath());
|
||||
break;
|
||||
default:
|
||||
return "";
|
||||
@ -234,7 +278,7 @@ static QString getStyle(QString &stylePath, enumGetStyle type)
|
||||
style = fileHtml.readAll();
|
||||
fileHtml.close();
|
||||
|
||||
QFile fileCss(stylePath + "main.css");
|
||||
QFile fileCss(QFileInfo(styleDir, "main.css").absoluteFilePath());
|
||||
QString css;
|
||||
if (fileCss.open(QIODevice::ReadOnly)) {
|
||||
css = fileCss.readAll();
|
||||
@ -273,22 +317,22 @@ QString ChatStyle::formatMessage(enumFormatMessage type, QString &name, QDateTim
|
||||
|
||||
switch (type) {
|
||||
case FORMATMSG_INCOMING:
|
||||
style = getStyle(stylePath, GETSTYLE_INCOMING);
|
||||
style = getStyle(m_styleDir, GETSTYLE_INCOMING);
|
||||
break;
|
||||
case FORMATMSG_OUTGOING:
|
||||
style = getStyle(stylePath, GETSTYLE_OUTGOING);
|
||||
style = getStyle(m_styleDir, GETSTYLE_OUTGOING);
|
||||
break;
|
||||
case FORMATMSG_HINCOMING:
|
||||
style = getStyle(stylePath, GETSTYLE_HINCOMING);
|
||||
style = getStyle(m_styleDir, GETSTYLE_HINCOMING);
|
||||
break;
|
||||
case FORMATMSG_HOUTGOING:
|
||||
style = getStyle(stylePath, GETSTYLE_HOUTGOING);
|
||||
style = getStyle(m_styleDir, GETSTYLE_HOUTGOING);
|
||||
break;
|
||||
}
|
||||
|
||||
if (style.isEmpty()) {
|
||||
// default style
|
||||
style = "%timestamp% %name% \n %message% ";
|
||||
style = "<table width='100%'><tr><td><b>%name%</b></td><td width='130' align='right'>%timestamp%</td></tr></table><table width='100%'><tr><td>%message%</td></tr></table>";
|
||||
}
|
||||
|
||||
unsigned int formatFlag = 0;
|
||||
@ -339,3 +383,155 @@ QString ChatStyle::formatMessage(enumFormatMessage type, QString &name, QDateTim
|
||||
|
||||
return formatMsg;
|
||||
}
|
||||
|
||||
static bool getStyleInfo(QString stylePath, QString stylePathRelative, ChatStyleInfo &info)
|
||||
{
|
||||
// Initialize info
|
||||
info = ChatStyleInfo();
|
||||
|
||||
QFileInfo file(stylePath, "info.xml");
|
||||
|
||||
QFile xmlFile(file.filePath());
|
||||
if (xmlFile.open(QIODevice::ReadOnly) == false) {
|
||||
// No info file found
|
||||
return false;
|
||||
}
|
||||
|
||||
QDir dir(QApplication::applicationDirPath());
|
||||
|
||||
QXmlStreamReader reader;
|
||||
reader.setDevice(&xmlFile);
|
||||
|
||||
while (reader.atEnd() == false) {
|
||||
reader.readNext();
|
||||
if (reader.isStartElement()) {
|
||||
if (reader.name() == "RetroShare_Style") {
|
||||
if (reader.attributes().value("version") == "1.0") {
|
||||
info.stylePath = stylePathRelative;
|
||||
continue;
|
||||
}
|
||||
// Not the right format of the xml file;
|
||||
return false ;
|
||||
}
|
||||
|
||||
if (info.stylePath.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (reader.name() == "style") {
|
||||
// read style information
|
||||
while (reader.atEnd() == false) {
|
||||
reader.readNext();
|
||||
if (reader.isEndElement()) {
|
||||
if (reader.name() == "style") {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (reader.isStartElement()) {
|
||||
if (reader.name() == "name") {
|
||||
info.styleName = reader.readElementText();
|
||||
continue;
|
||||
}
|
||||
if (reader.name() == "description") {
|
||||
info.styleDescription = reader.readElementText();
|
||||
continue;
|
||||
}
|
||||
// ingore all other entries
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (reader.name() == "author") {
|
||||
// read author information
|
||||
while (reader.atEnd() == false) {
|
||||
reader.readNext();
|
||||
if (reader.isEndElement()) {
|
||||
if (reader.name() == "author") {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (reader.isStartElement()) {
|
||||
if (reader.name() == "name") {
|
||||
info.authorName = reader.readElementText();
|
||||
continue;
|
||||
}
|
||||
if (reader.name() == "email") {
|
||||
info.authorEmail = reader.readElementText();
|
||||
continue;
|
||||
}
|
||||
// ingore all other entries
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// ingore all other entries
|
||||
}
|
||||
}
|
||||
|
||||
if (reader.hasError()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (info.stylePath.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*static*/ bool ChatStyle::getAvailableStyles(enumStyleType styleType, QList<ChatStyleInfo> &styles)
|
||||
{
|
||||
styles.clear();
|
||||
|
||||
ChatStyleInfo standardInfo;
|
||||
QString stylePath;
|
||||
|
||||
switch (styleType) {
|
||||
case TYPE_PUBLIC:
|
||||
if (getStyleInfo(":/qss/chat/public", ":/qss/chat/public", standardInfo)) {
|
||||
standardInfo.styleDescription = tr("Standard style for public chat");
|
||||
styles.append(standardInfo);
|
||||
}
|
||||
stylePath = "style/public";
|
||||
break;
|
||||
case TYPE_PRIVATE:
|
||||
if (getStyleInfo(":/qss/chat/private", ":/qss/chat/private", standardInfo)) {
|
||||
standardInfo.styleDescription = tr("Standard style for private chat");
|
||||
styles.append(standardInfo);
|
||||
}
|
||||
stylePath = "style/private";
|
||||
break;
|
||||
case TYPE_HISTORY:
|
||||
if (getStyleInfo(":/qss/chat/history", ":/qss/chat/history", standardInfo)) {
|
||||
standardInfo.styleDescription = tr("Standard style for history");
|
||||
styles.append(standardInfo);
|
||||
}
|
||||
stylePath = "style/history";
|
||||
break;
|
||||
case TYPE_UNKNOWN:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
// application path
|
||||
QDir applicationDir(QApplication::applicationDirPath());
|
||||
QDir dir(QApplication::applicationDirPath());
|
||||
if (dir.cd(stylePath) == false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// get all style directories
|
||||
QFileInfoList dirList = dir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name);
|
||||
|
||||
// iterate style directories and get info
|
||||
for (QFileInfoList::iterator dir = dirList.begin(); dir != dirList.end(); dir++) {
|
||||
ChatStyleInfo info;
|
||||
if (getStyleInfo(dir->absoluteFilePath(), applicationDir.relativeFilePath(dir->absoluteFilePath()), info)) {
|
||||
styles.append(info);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
#include <QHash>
|
||||
#include <QMetaType>
|
||||
|
||||
#include "HandleRichText.h"
|
||||
|
||||
@ -37,8 +38,25 @@
|
||||
#define CHAT_FORMATTEXT_EMBED_SMILEYS 1
|
||||
#define CHAT_FORMATTEXT_EMBED_LINKS 2
|
||||
|
||||
class ChatStyle
|
||||
class ChatStyleInfo
|
||||
{
|
||||
public:
|
||||
ChatStyleInfo() {}
|
||||
|
||||
public:
|
||||
QString stylePath;
|
||||
QString styleName;
|
||||
QString styleDescription;
|
||||
QString authorName;
|
||||
QString authorEmail;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(ChatStyleInfo)
|
||||
|
||||
class ChatStyle : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum enumFormatMessage
|
||||
{
|
||||
@ -48,6 +66,14 @@ public:
|
||||
FORMATMSG_HOUTGOING
|
||||
};
|
||||
|
||||
enum enumStyleType
|
||||
{
|
||||
TYPE_UNKNOWN,
|
||||
TYPE_PUBLIC,
|
||||
TYPE_PRIVATE,
|
||||
TYPE_HISTORY
|
||||
};
|
||||
|
||||
QHash<QString, QString> smileys;
|
||||
|
||||
public:
|
||||
@ -56,16 +82,22 @@ public:
|
||||
/* Default destructor */
|
||||
~ChatStyle();
|
||||
|
||||
void setStylePath(QString path);
|
||||
bool setStylePath(QString stylePath);
|
||||
bool setStyleFromSettings(enumStyleType styleType);
|
||||
void loadEmoticons();
|
||||
|
||||
QString formatMessage(enumFormatMessage type, QString &name, QDateTime ×tamp, QString &message, unsigned int flag);
|
||||
QString formatText(QString &message, unsigned int flag);
|
||||
|
||||
void showSmileyWidget(QWidget *parent, QWidget *button, const char *slotAddMethod);
|
||||
static bool getAvailableStyles(enumStyleType styleType, QList<ChatStyleInfo> &styles);
|
||||
|
||||
private slots:
|
||||
void styleChanged(int styleType);
|
||||
|
||||
private:
|
||||
QString stylePath;
|
||||
enumStyleType m_styleType;
|
||||
QDir m_styleDir;
|
||||
|
||||
/** store default information for embedding HTML */
|
||||
RsChat::EmbedInHtmlAhref defEmbedAhref;
|
||||
|
@ -99,7 +99,7 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name,
|
||||
m_bInsertOnVisible = true;
|
||||
|
||||
last_status_send_time = 0 ;
|
||||
style.setStylePath(":/qss/chat/private");
|
||||
style.setStyleFromSettings(ChatStyle::TYPE_PRIVATE);
|
||||
style.loadEmoticons();
|
||||
|
||||
/* Hide or show the frames */
|
||||
|
@ -70,7 +70,7 @@ ImHistoryBrowser::ImHistoryBrowser(bool isPrivateChatIn, IMHistoryKeeper &histKe
|
||||
embedSmileys = Settings->valueFromGroup(QString("Chat"), QString::fromUtf8("Emoteicons_GroupChat"), true).toBool();
|
||||
}
|
||||
|
||||
style.setStylePath(":/qss/chat/history");
|
||||
style.setStyleFromSettings(ChatStyle::TYPE_HISTORY);
|
||||
style.loadEmoticons();
|
||||
|
||||
ui.listWidget->setItemDelegate(new IMHistoryItemDelegate);
|
||||
|
@ -451,18 +451,23 @@
|
||||
<file>images/window_fullscreen.png</file>
|
||||
<file>images/window_nofullscreen.png</file>
|
||||
<file>layouts/default.ui</file>
|
||||
<file>qss/chat/private/info.xml</file>
|
||||
<file>qss/chat/private/incoming.htm</file>
|
||||
<file>qss/chat/private/outgoing.htm</file>
|
||||
<file>qss/chat/private/hincoming.htm</file>
|
||||
<file>qss/chat/private/houtgoing.htm</file>
|
||||
<file>qss/chat/private/main.css</file>
|
||||
<file>qss/chat/public/info.xml</file>
|
||||
<file>qss/chat/public/incoming.htm</file>
|
||||
<file>qss/chat/public/outgoing.htm</file>
|
||||
<file>qss/chat/public/hincoming.htm</file>
|
||||
<file>qss/chat/public/houtgoing.htm</file>
|
||||
<file>qss/chat/public/main.css</file>
|
||||
<file>qss/chat/history/info.xml</file>
|
||||
<file>qss/chat/history/incoming.htm</file>
|
||||
<file>qss/chat/history/outgoing.htm</file>
|
||||
<file>qss/chat/history/hincoming.htm</file>
|
||||
<file>qss/chat/history/houtgoing.htm</file>
|
||||
<file>qss/chat/history/main.css</file>
|
||||
<file>smileys/angry.png</file>
|
||||
<file>smileys/beer.png</file>
|
||||
|
@ -399,7 +399,12 @@ void NotifyQt::UpdateGUI()
|
||||
}
|
||||
#endif // MINIMAL_RSGUI
|
||||
}
|
||||
|
||||
|
||||
void NotifyQt::notifyChatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType)
|
||||
{
|
||||
emit chatStyleChanged(styleType);
|
||||
}
|
||||
|
||||
//void NotifyQt::displaySearch()
|
||||
//{
|
||||
// iface->lockData(); /* Lock Interface */
|
||||
|
@ -15,7 +15,7 @@ class ChatDialog;
|
||||
class MessagesDialog;
|
||||
class ChannelsDialog;
|
||||
class MessengerWindow;
|
||||
struct TurtleFileInfo ;
|
||||
struct TurtleFileInfo;
|
||||
|
||||
//class NotifyQt: public NotifyBase, public QObject
|
||||
class NotifyQt: public QObject, public NotifyBase
|
||||
@ -47,6 +47,9 @@ class NotifyQt: public QObject, public NotifyBase
|
||||
|
||||
virtual std::string askForPassword(const std::string& key_details,bool prev_is_bad) ;
|
||||
|
||||
/* Notify from GUI */
|
||||
void notifyChatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType);
|
||||
|
||||
signals:
|
||||
// It's beneficial to send info to the GUI using signals, because signals are thread-safe
|
||||
// as they get queued by Qt.
|
||||
@ -75,6 +78,9 @@ class NotifyQt: public QObject, public NotifyBase
|
||||
void publicChatChanged(int type) const ;
|
||||
void privateChatChanged(int type) const ;
|
||||
|
||||
/* Notify from GUI */
|
||||
void chatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType);
|
||||
|
||||
public slots:
|
||||
|
||||
void UpdateGUI(); /* called by timer */
|
||||
|
15
retroshare-gui/src/gui/qss/chat/history/hincoming.htm
Normal file
15
retroshare-gui/src/gui/qss/chat/history/hincoming.htm
Normal file
@ -0,0 +1,15 @@
|
||||
<style type="text/css">
|
||||
%css-style%
|
||||
</style>
|
||||
<table class='hincomingTable' width='100%'>
|
||||
<tr>
|
||||
<td class='header hincomingHeader'>%name%</td>
|
||||
<td width='130' align='right' class='time hincomingTime'>[%timestamp%]</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table class='hincomingTable' width='100%'>
|
||||
<tr>
|
||||
<td>%message%</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -5,10 +5,9 @@
|
||||
<tr>
|
||||
<td class='header incomingHeader'>%name%</td>
|
||||
<td width='130' align='right' class='time incomingTime'>[%timestamp%]</td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
<table class='incomingTable' width="100%">
|
||||
<table class='incomingTable' width='100%'>
|
||||
<tr>
|
||||
<td>%message%</td>
|
||||
</tr>
|
||||
|
12
retroshare-gui/src/gui/qss/chat/history/info.xml
Normal file
12
retroshare-gui/src/gui/qss/chat/history/info.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE RetroShare_StyleInfo>
|
||||
<RetroShare_Style version="1.0">
|
||||
<style>
|
||||
<name>RetroShare</name>
|
||||
<description>The description is defined in ChatStyle.cpp for translation</description>
|
||||
</style>
|
||||
<author>
|
||||
<name>RetroShare Team</name>
|
||||
<email></email>
|
||||
</author>
|
||||
</RetroShare_Style>
|
@ -31,25 +31,29 @@
|
||||
color: #244578;
|
||||
}
|
||||
|
||||
.hincomingHeader {
|
||||
.hincomingTable{
|
||||
background-color:#dfedff;
|
||||
}
|
||||
|
||||
.hincomingHeader {
|
||||
border-color:#fafafa #d1dfef #d1dfef #fafafa;
|
||||
color: #295b07;
|
||||
}
|
||||
|
||||
.hincomingTime {
|
||||
background-color:#dfedff;
|
||||
color: #295b07;
|
||||
}
|
||||
|
||||
.houtgoingHeader {
|
||||
.houtgoingTable{
|
||||
background-color:#f5f5f5;
|
||||
}
|
||||
|
||||
.houtgoingHeader {
|
||||
border-color:#fafafa #e3e3e3 #e3e3e3 #fafafa;
|
||||
color: #244578;
|
||||
}
|
||||
|
||||
.houtgoingTime {
|
||||
background-color:#f5f5f5;
|
||||
color: #244578;
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,9 @@
|
||||
<tr>
|
||||
<td class='header outgoingHeader'>%name%</td>
|
||||
<td width='130' align='right' class='time outgoingTime'>[%timestamp%]</td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
<table class='outgoingTable' width="100%">
|
||||
<table class='outgoingTable' width='100%'>
|
||||
<tr>
|
||||
<td>%message%</td>
|
||||
</tr>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<td width='130' align='right' class='time'>%timestamp%</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table width="100%">
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td>%message%</td>
|
||||
</tr>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<td width='130' align='right' class='time'>%timestamp%</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table width="100%">
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td>%message%</td>
|
||||
</tr>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<td width='130' align='right' class='time'>%timestamp%</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table width="100%">
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td>%message%</td>
|
||||
</tr>
|
||||
|
12
retroshare-gui/src/gui/qss/chat/private/info.xml
Normal file
12
retroshare-gui/src/gui/qss/chat/private/info.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE RetroShare_StyleInfo>
|
||||
<RetroShare_Style version="1.0">
|
||||
<style>
|
||||
<name>RetroShare</name>
|
||||
<description>The description is defined in ChatStyle.cpp for translation</description>
|
||||
</style>
|
||||
<author>
|
||||
<name>RetroShare Team</name>
|
||||
<email></email>
|
||||
</author>
|
||||
</RetroShare_Style>
|
@ -7,7 +7,7 @@
|
||||
<td width='130' align='right' class='time'>%timestamp%</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table width="100%">
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td>%message%</td>
|
||||
</tr>
|
||||
|
12
retroshare-gui/src/gui/qss/chat/public/info.xml
Normal file
12
retroshare-gui/src/gui/qss/chat/public/info.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE RetroShare_StyleInfo>
|
||||
<RetroShare_Style version="1.0">
|
||||
<style>
|
||||
<name>RetroShare</name>
|
||||
<description>The description is defined in ChatStyle.cpp for translation</description>
|
||||
</style>
|
||||
<author>
|
||||
<name>RetroShare Team</name>
|
||||
<email></email>
|
||||
</author>
|
||||
</RetroShare_Style>
|
@ -20,19 +20,60 @@
|
||||
****************************************************************/
|
||||
|
||||
#include <QFontDialog>
|
||||
#include <time.h>
|
||||
|
||||
#include "ChatPage.h"
|
||||
|
||||
#include "gui/chat/ChatStyle.h"
|
||||
#include "gui/notifyqt.h"
|
||||
#include "rsharesettings.h"
|
||||
|
||||
static QString loadStyleInfo(ChatStyle::enumStyleType type, QListWidget *listWidget)
|
||||
{
|
||||
QList<ChatStyleInfo> styles;
|
||||
QList<ChatStyleInfo>::iterator style;
|
||||
QListWidgetItem *item;
|
||||
QListWidgetItem *activeItem = NULL;
|
||||
|
||||
QString stylePath;
|
||||
|
||||
switch (type) {
|
||||
case ChatStyle::TYPE_PUBLIC:
|
||||
Settings->getPublicChatStyle(stylePath);
|
||||
break;
|
||||
case ChatStyle::TYPE_PRIVATE:
|
||||
Settings->getPrivateChatStyle(stylePath);
|
||||
break;
|
||||
case ChatStyle::TYPE_HISTORY:
|
||||
Settings->getHistoryChatStyle(stylePath);
|
||||
break;
|
||||
case ChatStyle::TYPE_UNKNOWN:
|
||||
return "";
|
||||
}
|
||||
|
||||
ChatStyle::getAvailableStyles(type, styles);
|
||||
for (style = styles.begin(); style != styles.end(); style++) {
|
||||
item = new QListWidgetItem(style->styleName);
|
||||
item->setData(Qt::UserRole, qVariantFromValue(*style));
|
||||
listWidget->addItem(item);
|
||||
|
||||
if (style->stylePath == stylePath) {
|
||||
activeItem = item;
|
||||
}
|
||||
}
|
||||
|
||||
listWidget->setCurrentItem(activeItem);
|
||||
|
||||
return stylePath;
|
||||
}
|
||||
|
||||
/** Constructor */
|
||||
ChatPage::ChatPage(QWidget * parent, Qt::WFlags flags)
|
||||
: ConfigPage(parent, flags)
|
||||
{
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
ui.setupUi(this);
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
ui.setupUi(this);
|
||||
|
||||
/* Hide platform specific features */
|
||||
/* Hide platform specific features */
|
||||
#ifdef Q_WS_WIN
|
||||
|
||||
#endif
|
||||
@ -59,6 +100,34 @@ ChatPage::save(QString &errmsg)
|
||||
|
||||
Settings->setChatSendMessageWithCtrlReturn(ui.sendMessageWithCtrlReturn->isChecked());
|
||||
|
||||
ChatStyleInfo info;
|
||||
QListWidgetItem *item = ui.publicList->currentItem();
|
||||
if (item) {
|
||||
info = qVariantValue<ChatStyleInfo>(item->data(Qt::UserRole));
|
||||
if (publicStylePath != info.stylePath) {
|
||||
Settings->setPublicChatStyle(info.stylePath);
|
||||
NotifyQt::getInstance()->notifyChatStyleChanged(ChatStyle::TYPE_PUBLIC);
|
||||
}
|
||||
}
|
||||
|
||||
item = ui.privateList->currentItem();
|
||||
if (item) {
|
||||
info = qVariantValue<ChatStyleInfo>(item->data(Qt::UserRole));
|
||||
if (privateStylePath != info.stylePath) {
|
||||
Settings->setPrivateChatStyle(info.stylePath);
|
||||
NotifyQt::getInstance()->notifyChatStyleChanged(ChatStyle::TYPE_PRIVATE);
|
||||
}
|
||||
}
|
||||
|
||||
item = ui.historyList->currentItem();
|
||||
if (item) {
|
||||
info = qVariantValue<ChatStyleInfo>(item->data(Qt::UserRole));
|
||||
if (historyStylePath != info.stylePath) {
|
||||
Settings->setHistoryChatStyle(info.stylePath);
|
||||
NotifyQt::getInstance()->notifyChatStyleChanged(ChatStyle::TYPE_HISTORY);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -80,6 +149,11 @@ ChatPage::load()
|
||||
|
||||
ui.labelChatFontPreview->setText(fontTempChat.rawName());
|
||||
ui.labelChatFontPreview->setFont(fontTempChat);
|
||||
|
||||
/* Load styles */
|
||||
publicStylePath = loadStyleInfo(ChatStyle::TYPE_PUBLIC, ui.publicList);
|
||||
privateStylePath = loadStyleInfo(ChatStyle::TYPE_PRIVATE, ui.privateList);
|
||||
historyStylePath = loadStyleInfo(ChatStyle::TYPE_HISTORY, ui.historyList);
|
||||
}
|
||||
|
||||
bool ChatPage::emotePrivatChat() const {
|
||||
@ -107,3 +181,91 @@ void ChatPage::on_pushButtonChangeChatFont_clicked()
|
||||
ui.labelChatFontPreview->setFont(fontTempChat);
|
||||
}
|
||||
}
|
||||
|
||||
void ChatPage::setPreviewMessages(QString &stylePath, QTextBrowser *textBrowser)
|
||||
{
|
||||
ChatStyle style;
|
||||
style.setStylePath(stylePath);
|
||||
style.loadEmoticons();
|
||||
|
||||
textBrowser->clear();
|
||||
|
||||
QString nameIncoming = "Incoming";
|
||||
QString nameOutgoing = "Outgoing";
|
||||
QDateTime timestmp = QDateTime::fromTime_t(time(NULL));
|
||||
QTextEdit textEdit;
|
||||
QString message;
|
||||
|
||||
textEdit.setText(tr("Incoming message in history"));
|
||||
message = textEdit.toHtml();
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_HINCOMING, nameIncoming, timestmp, message, CHAT_FORMATTEXT_EMBED_SMILEYS));
|
||||
textEdit.setText(tr("Outgoing message in history"));
|
||||
message = textEdit.toHtml();
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_HOUTGOING, nameOutgoing, timestmp, message, CHAT_FORMATTEXT_EMBED_SMILEYS));
|
||||
textEdit.setText(tr("Incoming message"));
|
||||
message = textEdit.toHtml();
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_INCOMING, nameIncoming, timestmp, message, CHAT_FORMATTEXT_EMBED_SMILEYS));
|
||||
textEdit.setText(tr("Outgoing message"));
|
||||
message = textEdit.toHtml();
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_OUTGOING, nameOutgoing, timestmp, message, CHAT_FORMATTEXT_EMBED_SMILEYS));
|
||||
}
|
||||
|
||||
void ChatPage::on_publicList_currentRowChanged(int currentRow)
|
||||
{
|
||||
if (currentRow != -1) {
|
||||
QListWidgetItem *item = ui.publicList->item(currentRow);
|
||||
ChatStyleInfo info = qVariantValue<ChatStyleInfo>(item->data(Qt::UserRole));
|
||||
setPreviewMessages(info.stylePath, ui.publicPreview);
|
||||
|
||||
QString author = info.authorName;
|
||||
if (info.authorEmail.isEmpty() == false) {
|
||||
author += " (" + info.authorEmail + ")";
|
||||
}
|
||||
ui.publicAuthor->setText(author);
|
||||
ui.publicDescription->setText(info.styleDescription);
|
||||
} else {
|
||||
ui.publicPreview->clear();
|
||||
ui.publicAuthor->clear();
|
||||
ui.publicDescription->clear();
|
||||
}
|
||||
}
|
||||
|
||||
void ChatPage::on_privateList_currentRowChanged(int currentRow)
|
||||
{
|
||||
if (currentRow != -1) {
|
||||
QListWidgetItem *item = ui.privateList->item(currentRow);
|
||||
ChatStyleInfo info = qVariantValue<ChatStyleInfo>(item->data(Qt::UserRole));
|
||||
setPreviewMessages(info.stylePath, ui.privatePreview);
|
||||
|
||||
QString author = info.authorName;
|
||||
if (info.authorEmail.isEmpty() == false) {
|
||||
author += " (" + info.authorEmail + ")";
|
||||
}
|
||||
ui.privateAuthor->setText(author);
|
||||
ui.privateDescription->setText(info.styleDescription);
|
||||
} else {
|
||||
ui.privatePreview->clear();
|
||||
ui.privateAuthor->clear();
|
||||
ui.privateDescription->clear();
|
||||
}
|
||||
}
|
||||
|
||||
void ChatPage::on_historyList_currentRowChanged(int currentRow)
|
||||
{
|
||||
if (currentRow != -1) {
|
||||
QListWidgetItem *item = ui.historyList->item(currentRow);
|
||||
ChatStyleInfo info = qVariantValue<ChatStyleInfo>(item->data(Qt::UserRole));
|
||||
setPreviewMessages(info.stylePath, ui.historyPreview);
|
||||
|
||||
QString author = info.authorName;
|
||||
if (info.authorEmail.isEmpty() == false) {
|
||||
author += " (" + info.authorEmail + ")";
|
||||
}
|
||||
ui.historyAuthor->setText(author);
|
||||
ui.historyDescription->setText(info.styleDescription);
|
||||
} else {
|
||||
ui.historyPreview->clear();
|
||||
ui.historyAuthor->clear();
|
||||
ui.historyDescription->clear();
|
||||
}
|
||||
}
|
||||
|
@ -48,9 +48,17 @@ class ChatPage : public ConfigPage
|
||||
|
||||
private slots:
|
||||
void on_pushButtonChangeChatFont_clicked();
|
||||
void on_publicList_currentRowChanged(int currentRow);
|
||||
void on_privateList_currentRowChanged(int currentRow);
|
||||
void on_historyList_currentRowChanged(int currentRow);
|
||||
|
||||
private:
|
||||
void closeEvent (QCloseEvent * event);
|
||||
void setPreviewMessages(QString &stylePath, QTextBrowser *textBrowser);
|
||||
|
||||
QString publicStylePath;
|
||||
QString privateStylePath;
|
||||
QString historyStylePath;
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::ChatPage ui;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -299,6 +299,36 @@ void RshareSettings::setChatSendMessageWithCtrlReturn(bool bValue)
|
||||
setValueToGroup("Chat", "SendMessageWithCtrlReturn", bValue);
|
||||
}
|
||||
|
||||
void RshareSettings::getPublicChatStyle(QString &stylePath)
|
||||
{
|
||||
stylePath = valueFromGroup("Chat", "StylePublic", ":/qss/chat/public").toString();
|
||||
}
|
||||
|
||||
void RshareSettings::setPublicChatStyle(QString stylePath)
|
||||
{
|
||||
setValueToGroup("Chat", "StylePublic", stylePath);
|
||||
}
|
||||
|
||||
void RshareSettings::getPrivateChatStyle(QString &stylePath)
|
||||
{
|
||||
stylePath = valueFromGroup("Chat", "StylePrivate", ":/qss/chat/private").toString();
|
||||
}
|
||||
|
||||
void RshareSettings::setPrivateChatStyle(QString stylePath)
|
||||
{
|
||||
setValueToGroup("Chat", "StylePrivate", stylePath);
|
||||
}
|
||||
|
||||
void RshareSettings::getHistoryChatStyle(QString &stylePath)
|
||||
{
|
||||
stylePath = valueFromGroup("Chat", "StyleHistory", ":/qss/chat/history").toString();
|
||||
}
|
||||
|
||||
void RshareSettings::setHistoryChatStyle(QString stylePath)
|
||||
{
|
||||
setValueToGroup("Chat", "StyleHistory", stylePath);
|
||||
}
|
||||
|
||||
/** Returns true if RetroShare is set to run on system boot. */
|
||||
bool
|
||||
RshareSettings::runRetroshareOnBoot()
|
||||
|
@ -83,7 +83,6 @@ public:
|
||||
|
||||
/** set the chat avatar. Returns a null image if no avatar is saved. */
|
||||
void setChatAvatar(const QImage&) ;
|
||||
|
||||
|
||||
/* Get the destination log file. */
|
||||
QString getLogFile();
|
||||
@ -122,7 +121,17 @@ public:
|
||||
|
||||
bool getChatSendMessageWithCtrlReturn();
|
||||
void setChatSendMessageWithCtrlReturn(bool bValue);
|
||||
|
||||
|
||||
/* chat styles */
|
||||
void getPublicChatStyle(QString &stylePath);
|
||||
void setPublicChatStyle(QString stylePath);
|
||||
|
||||
void getPrivateChatStyle(QString &stylePath);
|
||||
void setPrivateChatStyle(QString stylePath);
|
||||
|
||||
void getHistoryChatStyle(QString &stylePath);
|
||||
void setHistoryChatStyle(QString stylePath);
|
||||
|
||||
//! Save placement, state and size information of a window.
|
||||
void saveWidgetInformation(QWidget *widget);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user