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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
/* museeq - a Qt client to museekd
*
* Copyright (C) 2003-2004 Hyriand <hyriand@thegraveyard.org>
* Copyright 2008 little blue poney <lbponey@users.sourceforge.net>
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "museeq.h"
#include "mainwin.h"
#include "aclineedit.h"
#include "privatechat.h"
#include "privatechats.h"
#include "codeccombo.h"
#include "chatpanel.h"
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QTextStream>
#define _TIME QString("<span style='"+museeq->mFontTime+";color:"+museeq->mColorTime+"'>") + QDateTime::currentDateTime().toString("hh:mm:ss") + "</span> "
#define _TIMES QDateTime::currentDateTime().toTime_t ()
PrivateChat::PrivateChat(const QString& _t, QWidget* _p, const char* _n)
: UserWidget(_t, _p, _n) {
MainLayout = new QVBoxLayout(this);
mChatPanel = new ChatPanel(QString::null, this);
MainLayout->addWidget(mChatPanel);
connect(mChatPanel, SIGNAL(send(const QString&)), this, SLOT(slotSend(const QString&)));
mStatus = 3;
mChatPanel->boxLayout()->addWidget(new CodecCombo("encoding.users", user(), mChatPanel->box(), "encoding"));
}
void PrivateChat::status(const QString& _u, uint _s) {
if (_s == mStatus)
return;
else
mStatus = _s;
if (! museeq->isIgnored(_u)) {
QString l = "";
if(_s == 0)
l += tr("%1 is offline").arg(_u);
else if(_s == 1)
l += tr("%1 is away").arg(_u);
else if(_s == 2)
l += tr("%1 is online").arg(_u);
mChatPanel->append(_TIMES, l);
}
}
void PrivateChat::append(uint dir, uint ts, const QString& _u, const QString& _l) {
if(dir == 0)
{
mChatPanel->append(ts, _u, _l);
if (_l.contains(museeq->nickname()))
emit highlight(2);
else
emit highlight(1);
logMessage(_u, ts, _u, _l);
}
else if (dir == 1)
{
mChatPanel->append(ts, museeq->nickname(), _l);
logMessage(_u, ts, museeq->nickname(), _l);
}
}
/* Write add local timestamp to chat message before writing to disk */
void PrivateChat::logMessage(const QString& user, const QString& speaker, const QString& _l) {
logMessage(user, _TIMES, speaker, _l);
}
/* Write chat message to disk */
void PrivateChat::logMessage(const QString& user, uint ts, const QString& speaker, const QString& _l) {
if (! museeq->mLogPrivate) {
return;
}
if (! museeq->mPrivateLogDir.isEmpty() and QDir(museeq->mPrivateLogDir).exists() ) {
QFile logfile ( museeq->mPrivateLogDir+"/"+user);
if (! logfile.open(QIODevice::WriteOnly | QIODevice::Append)) {
museeq->output(QString("Write Error: could not write to: " +museeq->mPrivateLogDir+"/"+user));
return;
}
QDateTime _t;
_t.setTime_t(ts);
QTextStream textstream( &logfile );
textstream << _t.toString() << " [" << speaker << "]\t" << _l << "\n";
logfile.close();
} else {
museeq->output(QString("Write Error: directory doesn't exist: " +museeq->mPrivateLogDir+"/"));
}
}
void PrivateChat::slotSend(const QString& line_) {
QString line = line_;
if (line.isEmpty())
return;
if(line.startsWith("//")) {
line = line.mid(1);
} else if(line[0] == '/') {
QStringList s;
QString cmd("");
if(line.length() > 1)
{
s = line.mid(1).split(' ', QString::KeepEmptyParts);
cmd = s[0].toLower();
s.pop_front();
}
if(cmd == "me") {
museeq->sayPrivate(user(), line);
mChatPanel->append(QString::null, line);
} else if(cmd == "ip" ) {
if (s.empty())
museeq->mainwin()->showIPDialog(user());
else
museeq->mainwin()->showIPDialog(s.join(" "));
} else if((cmd == "c" || cmd == "chat") && s.empty())
museeq->mainwin()->changeCMode();
else if(cmd == "pm" || cmd == "private") {
if(! s.empty())
museeq->mainwin()->showPrivateChat(s.join(" "));
else
museeq->mainwin()->changePMode();
} else if(cmd == "transfers" || cmd == "transfer")
museeq->mainwin()->changeTMode();
else if(cmd == "clear")
mChatPanel->clear();
else if(cmd == "s" || cmd == "search") {
if(! s.empty())
museeq->mainwin()->startSearch(s.join(" "));
else
museeq->mainwin()->changeSMode();
} else if(cmd == "u" || cmd == "userinfo") {
if(! s.empty())
museeq->mainwin()->showUserInfo(s.join(" "));
else
museeq->mainwin()->showUserInfo(user());
} else if(cmd == "b" || cmd == "browse") {
if(! s.empty())
museeq->mainwin()->showBrowser(s.join(" "));
else
museeq->mainwin()->showBrowser(user());
} else if(cmd == "commands")
museeq->mainwin()->displayCommandsDialog();
else if(cmd == "about")
museeq->mainwin()->displayAboutDialog();
else if(cmd == "help")
museeq->mainwin()->displayHelpDialog();
else if(cmd == "ban" && s.empty())
museeq->addBanned(user(), "");
else if(cmd == "unban" && s.empty())
museeq->removeBanned(user());
else if(cmd == "ignore" && s.empty())
museeq->addIgnored(user(), "");
else if(cmd == "unignore" && s.empty())
museeq->removeIgnored(user());
else if(cmd == "buddy" && s.empty())
museeq->addBuddy(user(), "");
else if(cmd == "unbuddy" && s.empty())
museeq->removeBuddy(user());
else if(cmd == "trust" && s.empty())
museeq->addTrusted(user(), "");
else if(cmd == "distrust" && s.empty())
museeq->removeTrusted(user());
else if(cmd == "slap" && s.empty()) {
museeq->sayPrivate(user(), "/me slaps "+user()+" around with a large trout");
mChatPanel->append(QString::null, "/me slaps "+user()+" around with a large trout");
} else if((cmd == "j" || cmd == "join") && ! s.empty())
museeq->joinRoom(s.join(" "));
else if((cmd == "jp" || cmd == "joinpriv") && ! s.empty()) // Private room
museeq->joinRoom(s.join(" "), true);
else if(cmd == "settings")
museeq->mainwin()->changeSettings();
else if(cmd == "log")
museeq->mainwin()->toggleLog();
else if(cmd == "ticker" || cmd == "tickers" || cmd == "t")
museeq->mainwin()->toggleTickers();
else if(cmd == "colors" || cmd == "fonts" || cmd == "f")
museeq->mainwin()->changeColors();
else if(cmd == "p" || cmd== "part" || cmd == "l" || cmd == "leave") {
if(! s.empty())
museeq->leaveRoom(s.join(" "));
}
else
mChatPanel->entry()->setText(line);
return;
}
museeq->sayPrivate(user(), line);
QStringList lines = line.split("\n");
QStringList::iterator it, end = lines.end();
for(it = lines.begin(); it != end; ++it) {
logMessage(user(), museeq->nickname(), *it);
mChatPanel->append(QString::null, *it);
}
}
|