Completed chat implemention
[dashstudio.git] / src / shell / comm / chatwindow.cpp
blobf00a65f234a5955c4dc6c74448b5803423f6c042
1 /***************************************************************************
2 * Copyright (C) 2007 by David Cuadrado *
3 * krawek@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
22 #include "chatwindow.h"
24 #include <QTextDocument>
26 #include <dgui/iconloader.h>
28 #include "ui_chatwindow.h"
30 ChatWindow::ChatWindow(QWidget *parent)
31 : QDialog(parent)
33 ui = new Ui::ChatWindow;
34 ui->setupUi(this);
36 QFont font = ui->area->document()->defaultFont();
37 font.setPointSize(12);
38 ui->area->document()->setDefaultFont(font);
40 ui->nicks->setFont(font);
42 connect(ui->text, SIGNAL(returnPressed()), this, SLOT(onEditFinished()));
46 ChatWindow::~ChatWindow()
48 delete ui;
51 void ChatWindow::addMessage(const QString &from, const QString &text)
53 ui->area->append(QString("<%1> ").arg(from));
54 ui->area->insertHtml(replaceText(text));
57 void ChatWindow::addNotice(const QString &from, const QString &text)
59 ui->area->append(tr("<b>***Notice from %1:</b> ").arg(from));
60 ui->area->insertHtml(replaceText(text));
63 void ChatWindow::addWall(const QString &from, const QString &text)
65 ui->area->append(tr("<b>***Attention: %1 says:</b> ").arg(from));
66 ui->area->insertHtml(replaceText(text));
69 void ChatWindow::onEditFinished()
71 QString text = ui->text->text();
72 ui->text->clear();
74 int type = Chat;
76 if( ui->type->currentIndex() == 1 )
78 type = Notice;
80 else if(ui->type->currentIndex() == 2 )
82 type = Wall;
85 if( ! text.isEmpty() )
87 emit sendText(text, type);
91 QString ChatWindow::replaceText(const QString &text)
93 QString rich = Qt::escape(text);
95 rich = rich.replace("o:)", QString("<img width=\"22\" height=\"22\" src=\"")+ DGui::IconLoader::self()->path("face-angel.svg") +"\" />");
96 rich = rich.replace(":'(", QString("<img width=\"22\" height=\"22\" src=\"")+ DGui::IconLoader::self()->path("face-crying.svg") +"\" />");
97 rich = rich.replace("}:)", QString("<img width=\"22\" height=\"22\" src=\"")+ DGui::IconLoader::self()->path("face-devilish.svg") +"\" />");
98 rich = rich.replace("8)", QString("<img width=\"22\" height=\"22\" src=\"")+ DGui::IconLoader::self()->path("face-glasses.svg") +"\" />");
99 rich = rich.replace(":D", QString("<img width=\"22\" height=\"22\" src=\"")+ DGui::IconLoader::self()->path("face-grin.svg") +"\" />");
100 rich = rich.replace(":*)", QString("<img width=\"22\" height=\"22\" src=\"")+ DGui::IconLoader::self()->path("face-kiss.svg") +"\" />");
101 rich = rich.replace(":(|)", QString("<img width=\"22\" height=\"22\" src=\"")+ DGui::IconLoader::self()->path("face-monkey.svg") +"\" />");
102 rich = rich.replace(":|", QString("<img width=\"22\" height=\"22\" src=\"")+ DGui::IconLoader::self()->path("face-plain.svg") +"\" />");
103 rich = rich.replace(":(", QString("<img width=\"22\" height=\"22\" src=\"")+ DGui::IconLoader::self()->path("face-sad.svg") +"\" />");
104 rich = rich.replace(":]", QString("<img width=\"22\" height=\"22\" src=\"")+ DGui::IconLoader::self()->path("face-smile-big.svg") +"\" />");
105 rich = rich.replace(":o", QString("<img width=\"22\" height=\"22\" src=\"")+ DGui::IconLoader::self()->path("face-surprise.svg") +"\" />");
106 rich = rich.replace(";)", QString("<img width=\"22\" height=\"22\" src=\"")+ DGui::IconLoader::self()->path("face-wink.svg") +"\" />");
107 rich = rich.replace(":)", QString("<img width=\"22\" height=\"22\" src=\"")+ DGui::IconLoader::self()->path("face-smile.svg") +"\" />");
110 return rich;
113 void ChatWindow::addUsers(const QStringList & logins)
115 ui->nicks->addItems(logins);
116 foreach(QString login, logins)
118 ui->area->append(tr("<b>***Connected:</b> %1").arg(login));
122 void ChatWindow::removeUser(const QString & login)
124 QList<QListWidgetItem *> items = ui->nicks->findItems(login , Qt::MatchFixedString );
125 if(!items.isEmpty())
127 QListWidgetItem *toRemove = items.first();
128 ui->nicks->takeItem(ui->nicks->row(toRemove));
129 delete toRemove;
130 ui->area->append(tr("<b>***Disconnected:</b> %1").arg(login));