diff --git a/retroshare-gui/src/gui/ApplicationWindow.cpp b/retroshare-gui/src/gui/ApplicationWindow.cpp index 60c3d16e9..3aa81d38f 100644 --- a/retroshare-gui/src/gui/ApplicationWindow.cpp +++ b/retroshare-gui/src/gui/ApplicationWindow.cpp @@ -83,6 +83,7 @@ #define IMAGE_NEWSFEED ":/images/konqsidebar_news24.png" #define IMAGE_LINKS ":/images/ktorrent.png" #define IMAGE_MESSAGES ":/images/evolution.png" +#define IMAGE_BLOGS ":/images/konversation.png" /* Keys for UI Preferences */ @@ -132,7 +133,7 @@ ApplicationWindow::ApplicationWindow(QWidget* parent, Qt::WFlags flags) BlogDialog *blogDialog = NULL; ui.stackPages->add(blogDialog = new BlogDialog(ui.stackPages), - createPageAction(QIcon(IMAGE_NETWORK), tr("Blog Feed"), grp)); + createPageAction(QIcon(IMAGE_BLOGS), tr("Blog Feed"), grp)); ChannelFeed *channelFeed = NULL; ui.stackPages->add(channelFeed = new ChannelFeed(ui.stackPages), diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 698991e38..c890c33cc 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -86,6 +86,7 @@ #define IMAGE_ADDSHARE ":/images/directoryadd_24x24_shadow.png" #define IMAGE_OPTIONS ":/images/settings.png" #define IMAGE_QUIT ":/images/exit_24x24.png" +#define IMAGE_UNFINISHED ":/images/underconstruction.png" /* Keys for UI Preferences */ #define UI_PREF_PROMPT_ON_QUIT "UIOptions/ConfirmOnQuit" @@ -212,11 +213,11 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags) connect(transfersDialog, SIGNAL(playFiles( QStringList )), this, SLOT(playFiles( QStringList ))); #ifdef RS_RELEASE_VERSION - //addAction(new QAction(QIcon(IMAGE_BLOCK), tr("Unfinished"), ui.toolBar), SLOT(showApplWindow())); + //addAction(new QAction(QIcon(IMAGE_UNFINISHED), tr("Unfinished"), ui.toolBar), SLOT(showApplWindow())); #else - addAction(new QAction(QIcon(IMAGE_BLOCK), tr("Unfinished"), ui.toolBar), SLOT(showApplWindow())); + addAction(new QAction(QIcon(IMAGE_UNFINISHED), tr("Unfinished"), ui.toolBar), SLOT(showApplWindow())); toolAct = ui.toolBarservice->toggleViewAction(); toolAct->setText("Service"); diff --git a/retroshare-gui/src/gui/chat/ChatDialog.cpp b/retroshare-gui/src/gui/chat/ChatDialog.cpp new file mode 100644 index 000000000..dd713322e --- /dev/null +++ b/retroshare-gui/src/gui/chat/ChatDialog.cpp @@ -0,0 +1,440 @@ +/**************************************************************** + * 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 + +#include "PopupChatDialog.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rsiface/rspeers.h" +#include "rsiface/rsmsgs.h" +#define appDir QApplication::applicationDirPath() + + +/* Define the format used for displaying the date and time */ +#define DATETIME_FMT "MMM dd hh:mm:ss" + +#include + + +/** 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("") + +{ + /* Invoke Qt Designer generated QObject setup routine */ + ui.setupUi(this); + + loadEmoticons(); + + styleHtm = appDir + "/style/chat/default.htm"; + + + /* Hide ToolBox frame */ + showAvatarFrame(true); + connect(ui.avatarFrameButton, SIGNAL(toggled(bool)), this, SLOT(showAvatarFrame(bool))); + + //connect(ui.chattextEdit, SIGNAL(returnPressed( ) ), this, SLOT(sendChat( ) )); + connect(ui.chattextEdit, SIGNAL(textChanged ( ) ), this, SLOT(checkChat( ) )); + + connect(ui.sendButton, SIGNAL(clicked( ) ), this, SLOT(sendChat( ) )); + + 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())); + connect(ui.emoteiconButton, SIGNAL(clicked()), this, SLOT(smileyWidget())); + connect(ui.styleButton, SIGNAL(clicked()), SLOT(changeStyle())); + + + // Create the status bar + std::ostringstream statusstr; + statusstr << "Chatting with: " << dialogName << " !!! " << id; + statusBar()->showMessage(QString::fromStdString(statusstr.str())); + ui.textBrowser->setOpenExternalLinks ( false ); + + QString title = QString::fromStdString(name) + " :" + tr(" RetroShare - Chat") ; + setWindowTitle(title); + + //set the default avatar + //ui.avatarlabel->setPixmap(QPixmap(":/images/retrosharelogo1.png")); + + setWindowIcon(QIcon(QString(":/images/rstray3.png"))); + + ui.textboldButton->setIcon(QIcon(QString(":/images/edit-bold.png"))); + ui.textunderlineButton->setIcon(QIcon(QString(":/images/edit-underline.png"))); + ui.textitalicButton->setIcon(QIcon(QString(":/images/edit-italic.png"))); + ui.fontButton->setIcon(QIcon(QString(":/images/fonts.png"))); + ui.emoteiconButton->setIcon(QIcon(QString(":/images/emoticons/kopete/kopete020.png"))); + + ui.textboldButton->setCheckable(true); + ui.textunderlineButton->setCheckable(true); + ui.textitalicButton->setCheckable(true); + + /*QMenu * fontmenu = new QMenu(); + fontmenu->addAction(ui.actionBold); + fontmenu->addAction(ui.actionUnderline); + fontmenu->addAction(ui.actionItalic); + fontmenu->addAction(ui.actionStrike); + ui.fontButton->setMenu(fontmenu);*/ + + QPixmap pxm(24,24); + pxm.fill(Qt::black); + ui.colorButton->setIcon(pxm); + + QFont font = QFont("Comic Sans MS", 10); + +} + +/** Destructor. */ +PopupChatDialog::~PopupChatDialog() +{ + +} + +/** + Overloads the default show() slot so we can set opacity*/ + +void PopupChatDialog::show() +{ + + if(!this->isVisible()) { + QMainWindow::show(); + } else { + QMainWindow::activateWindow(); + 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 */ + +} + + +void PopupChatDialog::addChatMsg(ChatInfo *ci) +{ + QTextEdit *msgWidget = ui.textBrowser; + + QString currenttxt = msgWidget->toHtml(); + + + /* add in lines at the bottom */ + QString extraTxt; + + + bool offline = true; + + { + RsPeerDetails detail; + if (!rsPeers->getPeerDetails(dialogId, detail)) + { + std::cerr << "WARNING CANNOT GET PEER INFO!!!!" << std::endl; + } + else if (detail.state & RS_PEER_STATE_CONNECTED) + { + offline = false; + } + } + + if (offline) + { + QString line = "
\n ----- PEER OFFLINE (Chat will be lost) ----- \n
"; + + extraTxt += line; + } + + + QString timestamp = "[" + QDateTime::currentDateTime().toString("hh:mm:ss") + "]"; + QString name = QString::fromStdString(ci->name); + //QString line = "" + timestamp + "" + + // "" + " " + name + ""; + + //extraTxt += line; + + + extraTxt += QString::fromStdWString(ci -> msg); + + currenttxt += extraTxt; + + QHashIterator i(smileys); + while(i.hasNext()) + { + i.next(); + currenttxt.replace(i.key(), ""); + } + history /*<< nickColor << color << font << fontSize*/ << timestamp << name << extraTxt; + + QString formatMsg = loadEmptyStyle()/*.replace(nickColor) + .replace(color) + .replace(font) + .replace(fontSize)*/ + .replace("%timestamp%", timestamp) + .replace("%name%", name) + .replace("%extraTxt%", extraTxt); + //chat->setHtml(chat->toHtml() + formatMsg + "\n"); + + msgWidget->setHtml(formatMsg + "\n"); + + QTextCursor cursor = msgWidget->textCursor(); + cursor.movePosition(QTextCursor::End); + msgWidget->setTextCursor(cursor); + + QScrollBar *qsb = msgWidget->verticalScrollBar(); + qsb -> setValue(qsb->maximum()); +} + +void PopupChatDialog::checkChat() +{ + /* if 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 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 found in :" << txt << ":"; + //std::cerr << std::endl; + } +} + + +void PopupChatDialog::sendChat() +{ + QTextEdit *chatWidget = ui.chattextEdit; + + ChatInfo ci; + + + + + { + rsiface->lockData(); /* Lock Interface */ + const RsConfig &conf = rsiface->getConfig(); + + ci.rsid = conf.ownId; + ci.name = conf.ownName; + + rsiface->unlockData(); /* Unlock Interface */ + } + + ci.msg = chatWidget->toHtml().toStdWString(); + ci.chatflags = RS_CHAT_PRIVATE; + + addChatMsg(&ci); + + /* put proper destination */ + ci.rsid = dialogId; + ci.name = dialogName; + + rsMsgs -> ChatSend(ci); + chatWidget ->clear(); + + /* redraw send list */ +} + +/** + 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"))); + } +} + +void PopupChatDialog::setColor() +{ + bool ok; + QRgb color = QColorDialog::getRgba(ui.chattextEdit->textColor().rgba(), &ok, this); + if (ok) { + + currentColor = QColor(color); + ui.chattextEdit->setTextColor(currentColor); + colorChanged(currentColor); + } + ui.chattextEdit->setFocus(); + QTextCursor cursor = ui.chattextEdit->textCursor(); +} + +void PopupChatDialog::colorChanged(const QColor &c) +{ + QPixmap pix(16, 16); + pix.fill(c); + ui.colorButton->setIcon(pix); +} + +void PopupChatDialog::getFont() +{ + bool ok; + QFont font = QFontDialog::getFont(&ok, QFont(ui.chattextEdit->toHtml()), this); + if (ok) { + ui.chattextEdit->setFont(font); + } +} + +void PopupChatDialog::setFont() +{ + QFont font = QFont("Comic Sans MS", 10); + font.setBold(ui.textboldButton->isChecked()); + font.setUnderline(ui.textunderlineButton->isChecked()); + font.setItalic(ui.textitalicButton->isChecked()); + ui.chattextEdit->setFont(font); +} + +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()); + } +} + +void PopupChatDialog::smileyWidget() +{ + qDebug("MainWindow::smileyWidget()"); + QWidget *smWidget = new QWidget; + smWidget->setWindowTitle("Emoteicons"); + smWidget->setWindowIcon(QIcon(QString(":/images/rstray3.png"))); + smWidget->setFixedSize(256,256); + + + + int x = 0, y = 0; + + QHashIterator 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(sender())->toolTip()); +} + +QString PopupChatDialog::loadEmptyStyle() +{ + QString ret; + QFile file(styleHtm); + 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); + css.open(QIODevice::ReadOnly); + QString tmp = css.readAll(); + css.close(); + ret.replace("%css-style%", tmp); + return ret; +} + +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("%extraTxt%", history.at(i+3)) + "\n"; + } + ui.chattextEdit->setHtml(wholeChat); + } + QTextCursor cursor = ui.chattextEdit->textCursor(); + cursor.movePosition(QTextCursor::End); + ui.chattextEdit->setTextCursor(cursor); +} diff --git a/retroshare-gui/src/gui/images.qrc b/retroshare-gui/src/gui/images.qrc index 8dd16a62f..b6198b014 100644 --- a/retroshare-gui/src/gui/images.qrc +++ b/retroshare-gui/src/gui/images.qrc @@ -140,6 +140,7 @@ images/kdmconfig.png images/konsole.png images/konqsidebar_news24.png + images/konversation.png images/ksysguard.png images/ktorrent.png images/ktorrent32.png @@ -228,6 +229,7 @@ images/user/identitylightgrey24.png images/user/agt_forum24.png images/up.png + images/underconstruction.png images/user.png images/webcache_24x24.png layouts/default.ui diff --git a/retroshare-gui/src/gui/images/konversation.png b/retroshare-gui/src/gui/images/konversation.png new file mode 100644 index 000000000..7b9299718 Binary files /dev/null and b/retroshare-gui/src/gui/images/konversation.png differ diff --git a/retroshare-gui/src/gui/images/underconstruction.png b/retroshare-gui/src/gui/images/underconstruction.png new file mode 100644 index 000000000..af754a98c Binary files /dev/null and b/retroshare-gui/src/gui/images/underconstruction.png differ