2007-11-14 22:18:48 -05:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006, crypton
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include <QtGui>
|
|
|
|
|
|
|
|
#include "PopupChatDialog.h"
|
|
|
|
|
|
|
|
#include <QTextCodec>
|
|
|
|
#include <QTextEdit>
|
|
|
|
#include <QToolBar>
|
|
|
|
#include <QTextCursor>
|
|
|
|
#include <QTextList>
|
2008-03-29 14:21:17 -04:00
|
|
|
#include <QString>
|
|
|
|
#include <QtDebug>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QHashIterator>
|
2008-01-25 03:49:40 -05:00
|
|
|
|
|
|
|
#include "rsiface/rspeers.h"
|
2008-02-04 12:55:59 -05:00
|
|
|
#include "rsiface/rsmsgs.h"
|
2008-01-25 03:49:40 -05:00
|
|
|
|
2008-04-12 10:19:08 -04:00
|
|
|
#define appDir QApplication::applicationDirPath()
|
2008-01-25 03:49:40 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* Define the format used for displaying the date and time */
|
|
|
|
#define DATETIME_FMT "MMM dd hh:mm:ss"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
|
|
/** Default constructor */
|
|
|
|
PopupChatDialog::PopupChatDialog(std::string id, std::string name,
|
|
|
|
QWidget *parent, Qt::WFlags flags)
|
|
|
|
: QMainWindow(parent, flags), dialogId(id), dialogName(name),
|
|
|
|
lastChatTime(0), lastChatName("")
|
2008-03-21 13:30:15 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
/* Invoke Qt Designer generated QObject setup routine */
|
|
|
|
ui.setupUi(this);
|
2008-03-21 13:30:15 -04:00
|
|
|
|
2008-03-29 14:21:17 -04:00
|
|
|
loadEmoticons();
|
|
|
|
|
2008-04-12 10:19:08 -04:00
|
|
|
styleHtm = appDir + "/style/chat/default.htm";
|
|
|
|
|
2008-03-21 13:30:15 -04:00
|
|
|
/* Hide ToolBox frame */
|
|
|
|
showAvatarFrame(true);
|
|
|
|
connect(ui.avatarFrameButton, SIGNAL(toggled(bool)), this, SLOT(showAvatarFrame(bool)));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-03-31 17:02:12 -04:00
|
|
|
connect(ui.chattextEdit, SIGNAL(textChanged ( ) ), this, SLOT(checkChat( ) ));
|
2008-03-21 13:30:15 -04:00
|
|
|
|
|
|
|
connect(ui.sendButton, SIGNAL(clicked( ) ), this, SLOT(sendChat( ) ));
|
2008-03-22 21:13:09 -04:00
|
|
|
|
2008-03-26 21:29:04 -04:00
|
|
|
connect(ui.textboldButton, SIGNAL(clicked()), this, SLOT(setFont()));
|
|
|
|
connect(ui.textunderlineButton, SIGNAL(clicked()), this, SLOT(setFont()));
|
|
|
|
connect(ui.textitalicButton, SIGNAL(clicked()), this, SLOT(setFont()));
|
|
|
|
connect(ui.fontButton, SIGNAL(clicked()), this, SLOT(getFont()));
|
|
|
|
connect(ui.colorButton, SIGNAL(clicked()), this, SLOT(setColor()));
|
2008-03-29 14:21:17 -04:00
|
|
|
connect(ui.emoteiconButton, SIGNAL(clicked()), this, SLOT(smileyWidget()));
|
2008-04-12 10:19:08 -04:00
|
|
|
connect(ui.styleButton, SIGNAL(clicked()), SLOT(changeStyle()));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
// Create the status bar
|
|
|
|
std::ostringstream statusstr;
|
|
|
|
statusstr << "Chatting with: " << dialogName << " !!! " << id;
|
|
|
|
statusBar()->showMessage(QString::fromStdString(statusstr.str()));
|
|
|
|
ui.textBrowser->setOpenExternalLinks ( false );
|
|
|
|
|
2008-03-22 11:01:51 -04:00
|
|
|
QString title = QString::fromStdString(name) + " :" + tr(" RetroShare - Chat") ;
|
2008-03-21 13:30:15 -04:00
|
|
|
setWindowTitle(title);
|
|
|
|
|
|
|
|
//set the default avatar
|
2008-03-22 15:11:32 -04:00
|
|
|
//ui.avatarlabel->setPixmap(QPixmap(":/images/retrosharelogo1.png"));
|
2008-03-21 13:30:15 -04:00
|
|
|
|
2008-03-22 11:01:51 -04:00
|
|
|
setWindowIcon(QIcon(QString(":/images/rstray3.png")));
|
2008-03-26 21:29:04 -04:00
|
|
|
|
2008-03-21 13:30:15 -04:00
|
|
|
ui.textboldButton->setIcon(QIcon(QString(":/images/edit-bold.png")));
|
|
|
|
ui.textunderlineButton->setIcon(QIcon(QString(":/images/edit-underline.png")));
|
2008-03-22 21:13:09 -04:00
|
|
|
ui.textitalicButton->setIcon(QIcon(QString(":/images/edit-italic.png")));
|
|
|
|
ui.fontButton->setIcon(QIcon(QString(":/images/fonts.png")));
|
2008-03-29 14:21:17 -04:00
|
|
|
ui.emoteiconButton->setIcon(QIcon(QString(":/images/emoticons/kopete/kopete020.png")));
|
2008-04-12 10:19:08 -04:00
|
|
|
ui.styleButton->setIcon(QIcon(QString(":/images/looknfeel.png")));
|
2008-03-22 21:13:09 -04:00
|
|
|
|
2008-03-26 21:29:04 -04:00
|
|
|
ui.textboldButton->setCheckable(true);
|
|
|
|
ui.textunderlineButton->setCheckable(true);
|
|
|
|
ui.textitalicButton->setCheckable(true);
|
2008-04-12 10:19:08 -04:00
|
|
|
|
|
|
|
/*Disabled style Button when will switch style RetroShare will crash need to be fix */
|
|
|
|
ui.styleButton->setEnabled(false);
|
2008-03-26 21:29:04 -04:00
|
|
|
|
|
|
|
/*QMenu * fontmenu = new QMenu();
|
2008-03-22 22:21:17 -04:00
|
|
|
fontmenu->addAction(ui.actionBold);
|
|
|
|
fontmenu->addAction(ui.actionUnderline);
|
|
|
|
fontmenu->addAction(ui.actionItalic);
|
|
|
|
fontmenu->addAction(ui.actionStrike);
|
2008-03-26 21:29:04 -04:00
|
|
|
ui.fontButton->setMenu(fontmenu);*/
|
2008-04-05 08:14:49 -04:00
|
|
|
|
|
|
|
mCurrentColor = Qt::black;
|
|
|
|
mCurrentFont = QFont("Comic Sans MS", 12);
|
|
|
|
|
|
|
|
colorChanged(mCurrentColor);
|
|
|
|
setFont();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-03-21 13:30:15 -04:00
|
|
|
/** Destructor. */
|
|
|
|
PopupChatDialog::~PopupChatDialog()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Overloads the default show() slot so we can set opacity*/
|
|
|
|
|
|
|
|
void PopupChatDialog::show()
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!this->isVisible()) {
|
|
|
|
QMainWindow::show();
|
|
|
|
} else {
|
2008-03-23 10:55:05 -04:00
|
|
|
QMainWindow::activateWindow();
|
2007-11-14 22:18:48 -05:00
|
|
|
setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
|
|
|
|
QMainWindow::raise();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupChatDialog::closeEvent (QCloseEvent * event)
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupChatDialog::updateChat()
|
|
|
|
{
|
|
|
|
/* get chat off queue */
|
|
|
|
|
|
|
|
/* write it out */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-05-17 13:40:22 -04:00
|
|
|
void PopupChatDialog::addChatMsg(ChatInfo *ci)
|
|
|
|
{
|
|
|
|
//QTextBrowser *msgWidget = ui.textBrowser;
|
|
|
|
|
|
|
|
//QString message = msgWidget->toHtml();
|
|
|
|
|
|
|
|
|
|
|
|
/* add in lines at the bottom */
|
|
|
|
//QString extraTxt;
|
2008-01-25 03:49:40 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
bool offline = true;
|
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
{
|
|
|
|
RsPeerDetails detail;
|
|
|
|
if (!rsPeers->getPeerDetails(dialogId, detail))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
std::cerr << "WARNING CANNOT GET PEER INFO!!!!" << std::endl;
|
|
|
|
}
|
2008-01-25 03:49:40 -05:00
|
|
|
else if (detail.state & RS_PEER_STATE_CONNECTED)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
offline = false;
|
|
|
|
}
|
2008-01-25 03:49:40 -05:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
if (offline)
|
|
|
|
{
|
|
|
|
QString line = "<br>\n<span style=\"color:#1D84C9\"><strong> ----- PEER OFFLINE (Chat will be lost) -----</strong></span> \n<br>";
|
|
|
|
|
2008-05-17 13:40:22 -04:00
|
|
|
//extraTxt += line;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2008-05-17 13:40:22 -04:00
|
|
|
|
2008-03-21 10:56:41 -04:00
|
|
|
QString timestamp = "[" + QDateTime::currentDateTime().toString("hh:mm:ss") + "]";
|
2008-05-17 13:40:22 -04:00
|
|
|
QString name = QString::fromStdString(ci ->name);
|
|
|
|
//QString line = "<span style=\"color:#C00000\"><strong>" + timestamp + "</strong></span>" +
|
|
|
|
// "<span style=\"color:#2D84C9\"><strong>" + " " + name + "</strong></span>";
|
|
|
|
//extraTxt += line;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-05-17 13:40:22 -04:00
|
|
|
QString message = QString::fromStdWString(ci -> msg);
|
2008-01-26 08:08:28 -05:00
|
|
|
|
2008-05-17 13:40:22 -04:00
|
|
|
//currenttxt += extraTxt;
|
|
|
|
|
|
|
|
QHashIterator<QString, QString> i(smileys);
|
2008-03-29 14:21:17 -04:00
|
|
|
while(i.hasNext())
|
|
|
|
{
|
|
|
|
i.next();
|
2008-05-17 13:40:22 -04:00
|
|
|
message.replace(i.key(), "<img src=\"" + i.value() + "\">");
|
|
|
|
}
|
2008-04-12 10:19:08 -04:00
|
|
|
history /*<< nickColor << color << font << fontSize*/ << timestamp << name << message;
|
|
|
|
|
|
|
|
QString formatMsg = loadEmptyStyle()/*.replace(nickColor)
|
|
|
|
.replace(color)
|
|
|
|
.replace(font)
|
|
|
|
.replace(fontSize)*/
|
|
|
|
.replace("%timestamp%", timestamp)
|
|
|
|
.replace("%name%", name)
|
|
|
|
.replace("%message%", message);
|
|
|
|
|
|
|
|
ui.textBrowser->setHtml(ui.textBrowser->toHtml() + formatMsg + "\n");
|
2008-05-17 13:40:22 -04:00
|
|
|
|
2008-04-12 10:19:08 -04:00
|
|
|
QTextCursor cursor = ui.textBrowser->textCursor();
|
|
|
|
cursor.movePosition(QTextCursor::End);
|
|
|
|
ui.textBrowser->setTextCursor(cursor);
|
2008-01-26 08:08:28 -05:00
|
|
|
|
2008-04-12 10:19:08 -04:00
|
|
|
//QScrollBar *qsb = ui.textBrowser->verticalScrollBar();
|
|
|
|
//qsb -> setValue(qsb->maximum());
|
2008-01-26 08:08:28 -05:00
|
|
|
}
|
|
|
|
|
2008-03-31 17:02:12 -04:00
|
|
|
void PopupChatDialog::checkChat()
|
|
|
|
{
|
|
|
|
/* if <return> at the end of the text -> we can send it! */
|
|
|
|
QTextEdit *chatWidget = ui.chattextEdit;
|
|
|
|
std::string txt = chatWidget->toPlainText().toStdString();
|
|
|
|
if ('\n' == txt[txt.length()-1])
|
|
|
|
{
|
|
|
|
//std::cerr << "Found <return> found at end of :" << txt << ": should send!";
|
|
|
|
//std::cerr << std::endl;
|
|
|
|
if (txt.length()-1 == txt.find('\n')) /* only if on first line! */
|
|
|
|
{
|
|
|
|
/* should remove last char ... */
|
|
|
|
sendChat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//std::cerr << "No <return> found in :" << txt << ":";
|
|
|
|
//std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-26 08:08:28 -05:00
|
|
|
|
|
|
|
void PopupChatDialog::sendChat()
|
|
|
|
{
|
2008-03-26 21:29:04 -04:00
|
|
|
QTextEdit *chatWidget = ui.chattextEdit;
|
2008-01-26 08:08:28 -05:00
|
|
|
|
2008-03-29 14:21:17 -04:00
|
|
|
ChatInfo ci;
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-26 08:08:28 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
rsiface->lockData(); /* Lock Interface */
|
|
|
|
const RsConfig &conf = rsiface->getConfig();
|
|
|
|
|
|
|
|
ci.rsid = conf.ownId;
|
|
|
|
ci.name = conf.ownName;
|
|
|
|
|
|
|
|
rsiface->unlockData(); /* Unlock Interface */
|
|
|
|
}
|
|
|
|
|
2008-03-26 21:29:04 -04:00
|
|
|
ci.msg = chatWidget->toHtml().toStdWString();
|
2007-11-14 22:18:48 -05:00
|
|
|
ci.chatflags = RS_CHAT_PRIVATE;
|
|
|
|
|
2008-05-17 13:40:22 -04:00
|
|
|
std::cout << "PopupChatDialog:sendChat " << styleHtm.toStdString() << std::endl;
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
addChatMsg(&ci);
|
|
|
|
|
|
|
|
/* put proper destination */
|
|
|
|
ci.rsid = dialogId;
|
|
|
|
ci.name = dialogName;
|
|
|
|
|
2008-02-04 12:55:59 -05:00
|
|
|
rsMsgs -> ChatSend(ci);
|
2008-04-05 08:14:49 -04:00
|
|
|
chatWidget ->clear();
|
|
|
|
setFont();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* redraw send list */
|
|
|
|
}
|
|
|
|
|
2008-03-21 13:30:15 -04:00
|
|
|
/**
|
|
|
|
Toggles the ToolBox on and off, changes toggle button text
|
|
|
|
*/
|
|
|
|
void PopupChatDialog::showAvatarFrame(bool show)
|
|
|
|
{
|
|
|
|
if (show) {
|
|
|
|
ui.avatarframe->setVisible(true);
|
|
|
|
ui.avatarFrameButton->setChecked(true);
|
|
|
|
ui.avatarFrameButton->setToolTip(tr("Hide Avatar"));
|
|
|
|
ui.avatarFrameButton->setIcon(QIcon(tr(":images/hide_toolbox_frame.png")));
|
|
|
|
} else {
|
|
|
|
ui.avatarframe->setVisible(false);
|
|
|
|
ui.avatarFrameButton->setChecked(false);
|
|
|
|
ui.avatarFrameButton->setToolTip(tr("Show Avatar"));
|
|
|
|
ui.avatarFrameButton->setIcon(QIcon(tr(":images/show_toolbox_frame.png")));
|
|
|
|
}
|
2008-04-05 08:14:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupChatDialog::setColor()
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
QRgb color = QColorDialog::getRgba(ui.chattextEdit->textColor().rgba(), &ok, this);
|
|
|
|
if (ok) {
|
|
|
|
mCurrentColor = QColor(color);
|
|
|
|
colorChanged(mCurrentColor);
|
|
|
|
}
|
|
|
|
setFont();
|
|
|
|
}
|
|
|
|
|
2008-03-26 21:29:04 -04:00
|
|
|
void PopupChatDialog::colorChanged(const QColor &c)
|
|
|
|
{
|
|
|
|
QPixmap pix(16, 16);
|
|
|
|
pix.fill(c);
|
|
|
|
ui.colorButton->setIcon(pix);
|
|
|
|
}
|
|
|
|
|
2008-04-05 08:14:49 -04:00
|
|
|
void PopupChatDialog::getFont()
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
mCurrentFont = QFontDialog::getFont(&ok, mCurrentFont, this);
|
|
|
|
setFont();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupChatDialog::setFont()
|
|
|
|
{
|
|
|
|
|
|
|
|
mCurrentFont.setBold(ui.textboldButton->isChecked());
|
|
|
|
mCurrentFont.setUnderline(ui.textunderlineButton->isChecked());
|
|
|
|
mCurrentFont.setItalic(ui.textitalicButton->isChecked());
|
|
|
|
|
|
|
|
ui.chattextEdit->setFont(mCurrentFont);
|
|
|
|
ui.chattextEdit->setTextColor(mCurrentColor);
|
|
|
|
|
|
|
|
ui.chattextEdit->setFocus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-03-29 14:21:17 -04:00
|
|
|
void PopupChatDialog::loadEmoticons()
|
|
|
|
{
|
|
|
|
QDir smdir(QApplication::applicationDirPath() + "/emoticons/kopete");
|
|
|
|
//QDir smdir(":/gui/images/emoticons/kopete");
|
|
|
|
QFileInfoList sminfo = smdir.entryInfoList(QStringList() << "*.gif" << "*.png", QDir::Files, QDir::Name);
|
|
|
|
foreach(QFileInfo info, sminfo)
|
|
|
|
{
|
|
|
|
QString smcode = info.fileName().replace(".gif", "");
|
|
|
|
QString smstring;
|
|
|
|
for(int i = 0; i < 9; i+=3)
|
|
|
|
{
|
|
|
|
smstring += QString((char)smcode.mid(i,3).toInt());
|
|
|
|
}
|
|
|
|
//qDebug(smstring.toAscii());
|
|
|
|
smileys.insert(smstring, info.absoluteFilePath());
|
|
|
|
}
|
|
|
|
}
|
2008-03-23 10:55:05 -04:00
|
|
|
|
2008-03-29 14:21:17 -04:00
|
|
|
void PopupChatDialog::smileyWidget()
|
|
|
|
{
|
|
|
|
qDebug("MainWindow::smileyWidget()");
|
|
|
|
QWidget *smWidget = new QWidget;
|
2008-04-03 17:32:45 -04:00
|
|
|
smWidget->setWindowTitle("Emoticons");
|
2008-03-29 14:21:17 -04:00
|
|
|
smWidget->setWindowIcon(QIcon(QString(":/images/rstray3.png")));
|
|
|
|
smWidget->setFixedSize(256,256);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int x = 0, y = 0;
|
|
|
|
|
|
|
|
QHashIterator<QString, QString> i(smileys);
|
|
|
|
while(i.hasNext())
|
|
|
|
{
|
|
|
|
i.next();
|
|
|
|
QPushButton *smButton = new QPushButton("", smWidget);
|
|
|
|
smButton->setGeometry(x*24, y*24, 24,24);
|
|
|
|
smButton->setIconSize(QSize(24,24));
|
|
|
|
smButton->setIcon(QPixmap(i.value()));
|
|
|
|
smButton->setToolTip(i.key());
|
|
|
|
++x;
|
|
|
|
if(x > 4)
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
connect(smButton, SIGNAL(clicked()), this, SLOT(addSmiley()));
|
|
|
|
}
|
|
|
|
|
|
|
|
smWidget->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupChatDialog::addSmiley()
|
|
|
|
{
|
|
|
|
ui.chattextEdit->setText(ui.chattextEdit->toHtml() + qobject_cast<QPushButton*>(sender())->toolTip());
|
|
|
|
}
|
2008-04-12 10:19:08 -04:00
|
|
|
|
|
|
|
QString PopupChatDialog::loadEmptyStyle()
|
|
|
|
{
|
2008-05-17 13:40:22 -04:00
|
|
|
std::cout << "PopupChatDialog:loadEmptyStyle " << styleHtm.toStdString() << std::endl;
|
2008-04-12 10:19:08 -04:00
|
|
|
QString ret;
|
|
|
|
QFile file(styleHtm);
|
2008-05-17 13:40:22 -04:00
|
|
|
//file.open(QIODevice::ReadOnly);
|
|
|
|
if (file.open(QIODevice::ReadOnly)) {
|
|
|
|
ret = file.readAll();
|
|
|
|
file.close();
|
|
|
|
QString styleTmp = styleHtm;
|
|
|
|
QString styleCss = styleTmp.remove(styleHtm.lastIndexOf("."), styleHtm.length()-styleHtm.lastIndexOf(".")) + ".css";
|
|
|
|
qDebug() << styleCss.toAscii();
|
|
|
|
QFile css(styleCss);
|
|
|
|
QString tmp;
|
|
|
|
if (css.open(QIODevice::ReadOnly)) {
|
|
|
|
tmp = css.readAll();
|
|
|
|
css.close();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::cerr << "PopupChatDialog:loadEmptyStyle " << "Missing file of default css " << std::endl;
|
|
|
|
tmp = "";
|
|
|
|
}
|
|
|
|
ret.replace("%css-style%", tmp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::cerr << "PopupChatDialog:loadEmptyStyle " << "Missing file of default style " << std::endl;
|
|
|
|
ret="%timestamp% %name% \n %message% ";
|
|
|
|
return ret;
|
|
|
|
}
|
2008-04-12 10:19:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupChatDialog::changeStyle()
|
|
|
|
{
|
|
|
|
QString newStyle = QFileDialog::getOpenFileName(this, tr("Open Style"),
|
|
|
|
appDir + "/style/chat/",
|
|
|
|
tr("Styles (*.htm)"));
|
|
|
|
if(!newStyle.isEmpty())
|
|
|
|
{
|
|
|
|
QString wholeChat;
|
|
|
|
styleHtm = newStyle;
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < history.size(); i+=4)
|
|
|
|
{
|
|
|
|
QString formatMsg = loadEmptyStyle();
|
|
|
|
wholeChat += formatMsg.replace("%timestamp%", history.at(i+1))
|
|
|
|
.replace("%name%", history.at(i+2))
|
|
|
|
.replace("%message%", history.at(i+3)) + "\n";
|
|
|
|
}
|
|
|
|
ui.textBrowser->setHtml(wholeChat);
|
|
|
|
}
|
|
|
|
QTextCursor cursor = ui.textBrowser->textCursor();
|
|
|
|
cursor.movePosition(QTextCursor::End);
|
|
|
|
ui.textBrowser->setTextCursor(cursor);
|
|
|
|
}
|