| 1 | // -*- c-basic-offset: 2 -*- |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of Licq, an instant messaging client for UNIX. |
|---|
| 4 | * Copyright (C) 1999-2006 Licq developers |
|---|
| 5 | * |
|---|
| 6 | * Licq is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * Licq is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with Licq; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | // written by Graham Roff <graham@licq.org> |
|---|
| 22 | // Contributions by Dirk A. Mueller <dirk@licq.org> |
|---|
| 23 | |
|---|
| 24 | // ----------------------------------------------------------------------------- |
|---|
| 25 | #include "chatdlg.h" |
|---|
| 26 | |
|---|
| 27 | #include "config.h" |
|---|
| 28 | |
|---|
| 29 | #include <cctype> |
|---|
| 30 | #include <cstdlib> |
|---|
| 31 | #include <unistd.h> |
|---|
| 32 | |
|---|
| 33 | #include <QActionGroup> |
|---|
| 34 | #include <QApplication> |
|---|
| 35 | #include <QByteArray> |
|---|
| 36 | #include <QClipboard> |
|---|
| 37 | #include <QCloseEvent> |
|---|
| 38 | #include <QComboBox> |
|---|
| 39 | #include <QDateTime> |
|---|
| 40 | #include <QFontDatabase> |
|---|
| 41 | #include <QGridLayout> |
|---|
| 42 | #include <QGroupBox> |
|---|
| 43 | #include <QKeyEvent> |
|---|
| 44 | #include <QLabel> |
|---|
| 45 | #include <QList> |
|---|
| 46 | #include <QListWidget> |
|---|
| 47 | #include <QMenu> |
|---|
| 48 | #include <QMenuBar> |
|---|
| 49 | #include <QMouseEvent> |
|---|
| 50 | #include <QPainter> |
|---|
| 51 | #include <QPixmap> |
|---|
| 52 | #include <QSocketNotifier> |
|---|
| 53 | #include <QTextCodec> |
|---|
| 54 | #include <QTextStream> |
|---|
| 55 | #include <QToolBar> |
|---|
| 56 | #include <QToolButton> |
|---|
| 57 | |
|---|
| 58 | #ifdef USE_KDE |
|---|
| 59 | #include <kfiledialog.h> |
|---|
| 60 | #else |
|---|
| 61 | #include <QFileDialog> |
|---|
| 62 | #endif |
|---|
| 63 | |
|---|
| 64 | #include <licq_chat.h> |
|---|
| 65 | #include <licq_icqd.h> |
|---|
| 66 | #include <licq_log.h> |
|---|
| 67 | #include <licq_translate.h> |
|---|
| 68 | |
|---|
| 69 | #include "config/chat.h" |
|---|
| 70 | #include "config/general.h" |
|---|
| 71 | #include "config/iconmanager.h" |
|---|
| 72 | |
|---|
| 73 | #include "core/messagebox.h" |
|---|
| 74 | |
|---|
| 75 | #include "helpers/support.h" |
|---|
| 76 | #include "helpers/usercodec.h" |
|---|
| 77 | |
|---|
| 78 | using namespace LicqQtGui; |
|---|
| 79 | /* TRANSLATOR LicqQtGui::ChatDlg */ |
|---|
| 80 | |
|---|
| 81 | ChatDlgList ChatDlg::chatDlgs; |
|---|
| 82 | |
|---|
| 83 | static const int col_array[] = |
|---|
| 84 | { |
|---|
| 85 | 0x00, 0x00, 0x00, |
|---|
| 86 | 0x80, 0x00, 0x00, |
|---|
| 87 | 0x00, 0x80, 0x00, |
|---|
| 88 | 0x80, 0x80, 0x00, |
|---|
| 89 | 0x00, 0x00, 0x80, |
|---|
| 90 | 0x80, 0x00, 0x80, |
|---|
| 91 | 0x00, 0x80, 0x80, |
|---|
| 92 | 0x80, 0x80, 0x80, |
|---|
| 93 | 0xC0, 0xC0, 0xC0, |
|---|
| 94 | 0xFF, 0x00, 0x00, |
|---|
| 95 | 0x00, 0xFF, 0x00, |
|---|
| 96 | 0xFF, 0xFF, 0x00, |
|---|
| 97 | 0x00, 0x00, 0xFF, |
|---|
| 98 | 0xFF, 0x00, 0xFF, |
|---|
| 99 | 0x00, 0xFF, 0xFF, |
|---|
| 100 | 0xFF, 0xFF, 0xFF |
|---|
| 101 | }; |
|---|
| 102 | |
|---|
| 103 | #define NUM_COLORS sizeof(col_array)/sizeof(int)/3 |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | // --------------------------------------------------------------------------- |
|---|
| 107 | ChatDlg::ChatDlg(QString id, unsigned long ppid, QWidget* parent) |
|---|
| 108 | : QDialog(parent), |
|---|
| 109 | myId(id), |
|---|
| 110 | myPpid(ppid), |
|---|
| 111 | myAudio(true) |
|---|
| 112 | { |
|---|
| 113 | Support::setWidgetProps(this, "ChatDialog"); |
|---|
| 114 | setAttribute(Qt::WA_DeleteOnClose, true); |
|---|
| 115 | |
|---|
| 116 | sn = NULL; |
|---|
| 117 | |
|---|
| 118 | m_nMode = CHAT_PANE; |
|---|
| 119 | |
|---|
| 120 | setWindowTitle(tr("Licq - Chat")); |
|---|
| 121 | |
|---|
| 122 | // Pane mode setup |
|---|
| 123 | boxPane = new QGroupBox(); |
|---|
| 124 | paneLayout = new QGridLayout(boxPane); |
|---|
| 125 | remoteLayout = new QGridLayout(); |
|---|
| 126 | paneLayout->addLayout(remoteLayout, 0, 0); |
|---|
| 127 | lblRemote = new QLabel(tr("Remote - Not connected"), boxPane); |
|---|
| 128 | remoteLayout->addWidget(lblRemote, 0, 0); |
|---|
| 129 | remoteLayout->setRowStretch(1, 1); |
|---|
| 130 | |
|---|
| 131 | paneLayout->setRowMinimumHeight(1, 15); |
|---|
| 132 | |
|---|
| 133 | QGridLayout* llay = new QGridLayout(); |
|---|
| 134 | paneLayout->addLayout(llay, 2, 0); |
|---|
| 135 | lblLocal = new QLabel(boxPane); |
|---|
| 136 | mlePaneLocal = new ChatWindow(boxPane); |
|---|
| 137 | mlePaneLocal->setMinimumHeight(100); |
|---|
| 138 | mlePaneLocal->setMinimumWidth(150); |
|---|
| 139 | mlePaneLocal->setEnabled(false); |
|---|
| 140 | llay->addWidget(lblLocal, 0, 0); |
|---|
| 141 | llay->addWidget(mlePaneLocal, 1, 0); |
|---|
| 142 | llay->setRowStretch(1, 1); |
|---|
| 143 | |
|---|
| 144 | // IRC mode setup |
|---|
| 145 | boxIRC = new QGroupBox(); |
|---|
| 146 | QGridLayout* lay = new QGridLayout(boxIRC); |
|---|
| 147 | mleIRCRemote = new ChatWindow(boxIRC); |
|---|
| 148 | mleIRCRemote->setReadOnly(true); |
|---|
| 149 | mleIRCRemote->setMinimumHeight(100); |
|---|
| 150 | mleIRCRemote->setMinimumWidth(150); |
|---|
| 151 | lay->addWidget(mleIRCRemote, 0, 0); |
|---|
| 152 | lstUsers = new QListWidget(boxIRC); |
|---|
| 153 | lay->addWidget(lstUsers, 0, 1, 2, 1); |
|---|
| 154 | mleIRCLocal = new ChatWindow(boxIRC); |
|---|
| 155 | mleIRCLocal->setEnabled(false); |
|---|
| 156 | mleIRCLocal->setFixedHeight(mleIRCLocal->fontMetrics().lineSpacing() * 4); |
|---|
| 157 | lay->addWidget(mleIRCLocal, 1, 0); |
|---|
| 158 | lay->setRowStretch(0, 1); |
|---|
| 159 | lay->setColumnStretch(0, 1); |
|---|
| 160 | |
|---|
| 161 | // Generic setup |
|---|
| 162 | mnuMain = new QMenu(tr("Chat")); |
|---|
| 163 | QAction* chatAudio = mnuMain->addAction(tr("&Audio"), this, SLOT(slot_audio(bool)), Qt::ALT + Qt::Key_A); |
|---|
| 164 | chatAudio->setCheckable(true); |
|---|
| 165 | chatAudio->setChecked(myAudio); |
|---|
| 166 | mnuMain->addAction(tr("&Save Chat"), this, SLOT(slot_save()), Qt::ALT + Qt::Key_S); |
|---|
| 167 | mnuMain->addSeparator(); |
|---|
| 168 | mnuMain->addAction(tr("&Close Chat"), this, SLOT(close()), Qt::ALT + Qt::Key_Q); |
|---|
| 169 | mnuMode = new QMenu(tr("Mode")); |
|---|
| 170 | QActionGroup* modeGroup = new QActionGroup(this); |
|---|
| 171 | QAction* paneModeAction = modeGroup->addAction(tr("&Pane Mode")); |
|---|
| 172 | connect(paneModeAction, SIGNAL(triggered()), SLOT(SwitchToPaneMode())); |
|---|
| 173 | paneModeAction->setCheckable(true); |
|---|
| 174 | paneModeAction->setChecked(true); |
|---|
| 175 | QAction* ircModeAction = modeGroup->addAction(tr("&IRC Mode")); |
|---|
| 176 | connect(ircModeAction, SIGNAL(triggered()), SLOT(SwitchToIRCMode())); |
|---|
| 177 | ircModeAction->setCheckable(true); |
|---|
| 178 | mnuMode->addActions(modeGroup->actions()); |
|---|
| 179 | |
|---|
| 180 | QMenuBar* menuBar = new QMenuBar(this); |
|---|
| 181 | menuBar->addMenu(mnuMain); |
|---|
| 182 | menuBar->addMenu(mnuMode); |
|---|
| 183 | |
|---|
| 184 | // Toolbar |
|---|
| 185 | QToolBar* barChat = new QToolBar("label", this); |
|---|
| 186 | barChat->setIconSize(QSize(16, 16)); |
|---|
| 187 | |
|---|
| 188 | // ### FIXME: implement laughing |
|---|
| 189 | // tbtLaugh = new QToolButton(LeftArrow, barChat); |
|---|
| 190 | |
|---|
| 191 | tbtIgnore = barChat->addAction(IconManager::instance()->getIcon(IconManager::IgnoreIcon), tr("Ignore user settings")); |
|---|
| 192 | tbtIgnore->setToolTip(tr("Ignores user color settings")); |
|---|
| 193 | connect(tbtIgnore, SIGNAL(triggered()), SLOT(updateRemoteStyle())); |
|---|
| 194 | tbtIgnore->setCheckable(true); |
|---|
| 195 | |
|---|
| 196 | tbtBeep = barChat->addAction(IconManager::instance()->getIcon(IconManager::BeepIcon), tr("Beep")); |
|---|
| 197 | tbtBeep->setToolTip(tr("Sends a Beep to all recipients")); |
|---|
| 198 | connect(tbtBeep, SIGNAL(triggered()), SLOT(chatSendBeep())); |
|---|
| 199 | |
|---|
| 200 | barChat->addSeparator(); |
|---|
| 201 | |
|---|
| 202 | tbtFg = barChat->addAction(IconManager::instance()->getIcon(IconManager::TextColorIcon), tr("Foreground color")); |
|---|
| 203 | tbtFg->setToolTip(tr("Changes the foreground color")); |
|---|
| 204 | mnuFg = new QMenu(); |
|---|
| 205 | connect(mnuFg, SIGNAL(triggered(QAction*)), SLOT(changeFrontColor(QAction*))); |
|---|
| 206 | tbtFg->setMenu(mnuFg); |
|---|
| 207 | dynamic_cast<QToolButton*>(barChat->widgetForAction(tbtFg))->setPopupMode(QToolButton::InstantPopup); |
|---|
| 208 | |
|---|
| 209 | tbtBg = barChat->addAction(IconManager::instance()->getIcon(IconManager::BackColorIcon), tr("Background color")); |
|---|
| 210 | tbtBg->setToolTip(tr("Changes the background color")); |
|---|
| 211 | mnuBg = new QMenu(); |
|---|
| 212 | connect(mnuBg, SIGNAL(triggered(QAction*)), SLOT(changeBackColor(QAction*))); |
|---|
| 213 | tbtBg->setMenu(mnuBg); |
|---|
| 214 | dynamic_cast<QToolButton*>(barChat->widgetForAction(tbtBg))->setPopupMode(QToolButton::InstantPopup); |
|---|
| 215 | |
|---|
| 216 | for(unsigned int i = 0; i < NUM_COLORS; i++) |
|---|
| 217 | { |
|---|
| 218 | QPixmap pix(48, 14); |
|---|
| 219 | QPainter p(&pix); |
|---|
| 220 | QColor c (col_array[i*3+0], col_array[i*3+1], col_array[i*3+2]); |
|---|
| 221 | |
|---|
| 222 | pix.fill(c); |
|---|
| 223 | p.drawRect(0, 0, 48, 14); |
|---|
| 224 | |
|---|
| 225 | mnuBg->addAction(pix, QString())->setData(i); |
|---|
| 226 | QPixmap pixf(48, 14); |
|---|
| 227 | pixf.fill(palette().color(QPalette::Background)); |
|---|
| 228 | QPainter pf(&pixf); |
|---|
| 229 | pf.setPen(c); |
|---|
| 230 | pf.drawText(5, 12, QString("Abc")); |
|---|
| 231 | mnuFg->addAction(pixf, QString())->setData(i); |
|---|
| 232 | } |
|---|
| 233 | barChat->addSeparator(); |
|---|
| 234 | |
|---|
| 235 | tbtBold = barChat->addAction(IconManager::instance()->getIcon(IconManager::BoldIcon), tr("Bold")); |
|---|
| 236 | tbtBold->setToolTip(tr("Toggles Bold font")); |
|---|
| 237 | connect(tbtBold, SIGNAL(triggered()), SLOT(fontStyleChanged())); |
|---|
| 238 | tbtBold->setCheckable(true); |
|---|
| 239 | |
|---|
| 240 | tbtItalic = barChat->addAction(IconManager::instance()->getIcon(IconManager::ItalicIcon), tr("Italic")); |
|---|
| 241 | tbtItalic->setToolTip(tr("Toggles Italic font")); |
|---|
| 242 | connect(tbtItalic, SIGNAL(triggered()), SLOT(fontStyleChanged())); |
|---|
| 243 | tbtItalic->setCheckable(true); |
|---|
| 244 | |
|---|
| 245 | tbtUnderline = barChat->addAction(IconManager::instance()->getIcon(IconManager::UnderlineIcon), tr("Underline")); |
|---|
| 246 | tbtUnderline->setToolTip(tr("Toggles Underline font")); |
|---|
| 247 | connect(tbtUnderline, SIGNAL(triggered()), SLOT(fontStyleChanged())); |
|---|
| 248 | tbtUnderline->setCheckable(true); |
|---|
| 249 | |
|---|
| 250 | tbtStrikeOut = barChat->addAction(IconManager::instance()->getIcon(IconManager::StrikethroughIcon), tr("StrikeOut")); |
|---|
| 251 | tbtStrikeOut->setToolTip(tr("Toggles StrikeOut font")); |
|---|
| 252 | connect(tbtStrikeOut, SIGNAL(triggered()), SLOT(fontStyleChanged())); |
|---|
| 253 | tbtStrikeOut->setCheckable(true); |
|---|
| 254 | |
|---|
| 255 | barChat->addSeparator(); |
|---|
| 256 | |
|---|
| 257 | cmbFontSize = new QComboBox(); |
|---|
| 258 | barChat->addWidget(cmbFontSize); |
|---|
| 259 | cmbFontSize->setInsertPolicy(QComboBox::NoInsert); |
|---|
| 260 | //windows font size limit seems to be 1638 (tested 98, 2000) |
|---|
| 261 | cmbFontSize->setValidator(new QIntValidator(1, 1638, cmbFontSize)); |
|---|
| 262 | connect(cmbFontSize, SIGNAL(activated(const QString&)), SLOT(fontSizeChanged(const QString&))); |
|---|
| 263 | cmbFontSize->addItem(QString::number(font().pointSize())); |
|---|
| 264 | |
|---|
| 265 | QList<int> sizes = QFontDatabase::standardSizes(); |
|---|
| 266 | for(int i = 0; i < sizes.count(); i++) |
|---|
| 267 | if(sizes[i] != font().pointSize()) |
|---|
| 268 | cmbFontSize->addItem(QString::number(sizes[i])); |
|---|
| 269 | |
|---|
| 270 | QFontDatabase fb; |
|---|
| 271 | cmbFontName = new QComboBox(); |
|---|
| 272 | #if 0 |
|---|
| 273 | cmbFontName->setSizeLimit(15); |
|---|
| 274 | QStringList sl = fb.families(); |
|---|
| 275 | while(sl.at(55) != sl.end()) sl.remove(sl.at(55)); |
|---|
| 276 | #endif |
|---|
| 277 | // cmbFontName->setFixedSize(cmbFontName->sizeHint()); |
|---|
| 278 | cmbFontName->addItems(fb.families()); |
|---|
| 279 | barChat->addWidget(cmbFontName); |
|---|
| 280 | connect(cmbFontName, SIGNAL(activated(const QString&)), SLOT(fontNameChanged(const QString&))); |
|---|
| 281 | |
|---|
| 282 | barChat->addSeparator(); |
|---|
| 283 | |
|---|
| 284 | codec = QTextCodec::codecForLocale(); |
|---|
| 285 | |
|---|
| 286 | QString codec_name = QString::fromLatin1( codec->name() ).toLower(); // TODO: determine best codec |
|---|
| 287 | QMenu* popupEncoding = new QMenu; |
|---|
| 288 | QActionGroup* encodingsGroup = new QActionGroup(this); |
|---|
| 289 | connect(encodingsGroup, SIGNAL(triggered(QAction*)), SLOT(setEncoding(QAction*))); |
|---|
| 290 | |
|---|
| 291 | // populate the popup menu |
|---|
| 292 | for (UserCodec::encoding_t* it = &UserCodec::m_encodings[0]; it->encoding != NULL; ++it) |
|---|
| 293 | { |
|---|
| 294 | QTextCodec* check_codec = QTextCodec::codecForName(it->encoding); |
|---|
| 295 | |
|---|
| 296 | bool currentCodec = check_codec != NULL && QString::fromLatin1(check_codec->name()).toLower() == codec_name; |
|---|
| 297 | |
|---|
| 298 | if (!currentCodec && !Config::Chat::instance()->showAllEncodings() && !it->isMinimal) |
|---|
| 299 | continue; |
|---|
| 300 | |
|---|
| 301 | QAction* a = new QAction(UserCodec::nameForEncoding(it->encoding), encodingsGroup); |
|---|
| 302 | a->setCheckable(true); |
|---|
| 303 | a->setData(it->mib); |
|---|
| 304 | |
|---|
| 305 | if (currentCodec) |
|---|
| 306 | a->setChecked(true); |
|---|
| 307 | |
|---|
| 308 | if (currentCodec && !Config::Chat::instance()->showAllEncodings() && !it->isMinimal) |
|---|
| 309 | { |
|---|
| 310 | // if the current encoding does not appear in the minimal list |
|---|
| 311 | popupEncoding->insertSeparator(popupEncoding->actions()[0]); |
|---|
| 312 | popupEncoding->insertAction(popupEncoding->actions()[0], a); |
|---|
| 313 | } |
|---|
| 314 | else |
|---|
| 315 | { |
|---|
| 316 | popupEncoding->addAction(a); |
|---|
| 317 | } |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | tbtEncoding = barChat->addAction(IconManager::instance()->getIcon(IconManager::EncodingIcon), tr("Set Encoding")); |
|---|
| 322 | tbtEncoding->setMenu(popupEncoding); |
|---|
| 323 | dynamic_cast<QToolButton*>(barChat->widgetForAction(tbtEncoding))->setPopupMode(QToolButton::InstantPopup); |
|---|
| 324 | |
|---|
| 325 | // QWidget* dummy = new QWidget(barChat); |
|---|
| 326 | // barChat->setStretchableWidget(dummy); |
|---|
| 327 | |
|---|
| 328 | QGridLayout* g = new QGridLayout(this); |
|---|
| 329 | int ml, mt, mr, mb; |
|---|
| 330 | g->getContentsMargins(&ml, &mt, &mr, &mb); |
|---|
| 331 | g->setContentsMargins(ml, menuBar->height(), mr, mb); |
|---|
| 332 | g->addWidget(barChat, 0, 0); |
|---|
| 333 | g->addWidget(boxPane, 1, 0); |
|---|
| 334 | g->addWidget(boxIRC, 1, 0); |
|---|
| 335 | |
|---|
| 336 | SwitchToPaneMode(); |
|---|
| 337 | |
|---|
| 338 | // Add ourselves to the list |
|---|
| 339 | chatDlgs.push_back(this); |
|---|
| 340 | |
|---|
| 341 | // Create the chat manager using our font |
|---|
| 342 | QFontInfo fi(mlePaneLocal->font()); |
|---|
| 343 | QFontDatabase fd; //QFontInfo.fixedPitch returns incorrect info??? |
|---|
| 344 | unsigned char style = STYLE_DONTCARE; |
|---|
| 345 | |
|---|
| 346 | if (fd.isFixedPitch(fi.family(), fd.styleString(mlePaneLocal->font()))) |
|---|
| 347 | style |= STYLE_FIXEDxPITCH; |
|---|
| 348 | else |
|---|
| 349 | style |= STYLE_VARIABLExPITCH; |
|---|
| 350 | |
|---|
| 351 | unsigned char encoding = UserCodec::charsetForName(codec->name()); |
|---|
| 352 | //TODO in daemon |
|---|
| 353 | chatman = new CChatManager(gLicqDaemon, |
|---|
| 354 | myId.toULong(), fi.family().toLocal8Bit(), encoding, style, |
|---|
| 355 | fi.pointSize(), fi.bold(), fi.italic(), fi.underline(), fi.strikeOut()); |
|---|
| 356 | |
|---|
| 357 | sn = new QSocketNotifier(chatman->Pipe(), QSocketNotifier::Read); |
|---|
| 358 | connect(sn, SIGNAL(activated(int)), SLOT(slot_chat())); |
|---|
| 359 | |
|---|
| 360 | // But use the chat manager default colors |
|---|
| 361 | mlePaneLocal->setForeground(QColor(chatman->ColorFg()[0], |
|---|
| 362 | chatman->ColorFg()[1], chatman->ColorFg()[2])); |
|---|
| 363 | mlePaneLocal->setBackground(QColor(chatman->ColorBg()[0], |
|---|
| 364 | chatman->ColorBg()[1], chatman->ColorBg()[2])); |
|---|
| 365 | mleIRCLocal->setForeground(QColor(chatman->ColorFg()[0], |
|---|
| 366 | chatman->ColorFg()[1], chatman->ColorFg()[2])); |
|---|
| 367 | mleIRCLocal->setBackground(QColor(chatman->ColorBg()[0], |
|---|
| 368 | chatman->ColorBg()[1], chatman->ColorBg()[2])); |
|---|
| 369 | mleIRCRemote->setForeground(QColor(chatman->ColorFg()[0], |
|---|
| 370 | chatman->ColorFg()[1], chatman->ColorFg()[2])); |
|---|
| 371 | mleIRCRemote->setBackground(QColor(chatman->ColorBg()[0], |
|---|
| 372 | chatman->ColorBg()[1], chatman->ColorBg()[2])); |
|---|
| 373 | chatname = QString::fromLocal8Bit(chatman->Name()); |
|---|
| 374 | lstUsers->addItem(chatname); |
|---|
| 375 | lblLocal->setText(tr("Local - %1").arg(chatname)); |
|---|
| 376 | |
|---|
| 377 | setMinimumSize(400, 300); |
|---|
| 378 | resize(550, 475); |
|---|
| 379 | show(); |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | // ----------------------------------------------------------------------------- |
|---|
| 383 | |
|---|
| 384 | ChatDlg::~ChatDlg() |
|---|
| 385 | { |
|---|
| 386 | delete chatman; |
|---|
| 387 | |
|---|
| 388 | if (sn != NULL) delete sn; |
|---|
| 389 | sn = NULL; |
|---|
| 390 | |
|---|
| 391 | ChatDlgList::iterator iter; |
|---|
| 392 | for (iter = chatDlgs.begin(); iter != chatDlgs.end(); iter++) |
|---|
| 393 | { |
|---|
| 394 | if (this == *iter) |
|---|
| 395 | { |
|---|
| 396 | chatDlgs.erase(iter); |
|---|
| 397 | break; |
|---|
| 398 | } |
|---|
| 399 | } |
|---|
| 400 | } |
|---|
| 401 | |
|---|
| 402 | |
|---|
| 403 | // ----------------------------------------------------------------------------- |
|---|
| 404 | |
|---|
| 405 | void ChatDlg::fontSizeChanged(const QString& txt) |
|---|
| 406 | { |
|---|
| 407 | QFont f(mlePaneLocal->font()); |
|---|
| 408 | |
|---|
| 409 | int nNewSize = txt.toInt(); |
|---|
| 410 | if (nNewSize > 24) |
|---|
| 411 | nNewSize = 24; |
|---|
| 412 | |
|---|
| 413 | f.setPointSize(nNewSize); |
|---|
| 414 | |
|---|
| 415 | mlePaneLocal->setFont(f); |
|---|
| 416 | mleIRCLocal->setFont(f); |
|---|
| 417 | mleIRCRemote->setFont(f); |
|---|
| 418 | |
|---|
| 419 | // if ignoring style change the remote panes too |
|---|
| 420 | updateRemoteStyle(); |
|---|
| 421 | |
|---|
| 422 | // transmit to remote |
|---|
| 423 | QFontInfo fi(f); |
|---|
| 424 | chatman->ChangeFontSize(fi.pointSize()); |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | |
|---|
| 428 | // ----------------------------------------------------------------------------- |
|---|
| 429 | |
|---|
| 430 | void ChatDlg::fontNameChanged(const QString& txt) |
|---|
| 431 | { |
|---|
| 432 | QFont f(mlePaneLocal->font()); |
|---|
| 433 | |
|---|
| 434 | f.setFamily(txt); |
|---|
| 435 | |
|---|
| 436 | mlePaneLocal->setFont(f); |
|---|
| 437 | mleIRCLocal->setFont(f); |
|---|
| 438 | mleIRCRemote->setFont(f); |
|---|
| 439 | |
|---|
| 440 | // if ignoring style change the remote panes too |
|---|
| 441 | updateRemoteStyle(); |
|---|
| 442 | |
|---|
| 443 | // transmit to remote |
|---|
| 444 | sendFontInfo(); |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | // ----------------------------------------------------------------------------- |
|---|
| 448 | |
|---|
| 449 | void ChatDlg::sendFontInfo() |
|---|
| 450 | { |
|---|
| 451 | //FIXME can we get more precise style??? |
|---|
| 452 | QFontInfo fi(mlePaneLocal->font()); |
|---|
| 453 | QFontDatabase fd; //QFontInfo.fixedPitch returns incorrect info??? |
|---|
| 454 | unsigned char style = STYLE_DONTCARE; |
|---|
| 455 | |
|---|
| 456 | if (fd.isFixedPitch(fi.family(), fd.styleString(mlePaneLocal->font()))) |
|---|
| 457 | style |= STYLE_FIXEDxPITCH; |
|---|
| 458 | else |
|---|
| 459 | style |= STYLE_VARIABLExPITCH; |
|---|
| 460 | |
|---|
| 461 | unsigned char encoding = UserCodec::charsetForName(codec->name()); |
|---|
| 462 | |
|---|
| 463 | chatman->ChangeFontFamily(fi.family().toLocal8Bit(), encoding, style); |
|---|
| 464 | } |
|---|
| 465 | |
|---|
| 466 | // ----------------------------------------------------------------------------- |
|---|
| 467 | |
|---|
| 468 | void ChatDlg::fontStyleChanged() |
|---|
| 469 | { |
|---|
| 470 | QFont f(mlePaneLocal->font()); |
|---|
| 471 | |
|---|
| 472 | f.setBold(tbtBold->isChecked()); |
|---|
| 473 | f.setItalic(tbtItalic->isChecked()); |
|---|
| 474 | f.setUnderline(tbtUnderline->isChecked()); |
|---|
| 475 | f.setStrikeOut(tbtStrikeOut->isChecked()); |
|---|
| 476 | |
|---|
| 477 | mlePaneLocal->setFont(f); |
|---|
| 478 | mleIRCLocal->setFont(f); |
|---|
| 479 | mleIRCRemote->setFont(f); |
|---|
| 480 | |
|---|
| 481 | // if ignoring style change the remote panes too |
|---|
| 482 | updateRemoteStyle(); |
|---|
| 483 | |
|---|
| 484 | // transmit to remote |
|---|
| 485 | QFontInfo fi(f); |
|---|
| 486 | chatman->ChangeFontFace(fi.bold(), fi.italic(), fi.underline(), fi.strikeOut()); |
|---|
| 487 | } |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | // ----------------------------------------------------------------------------- |
|---|
| 491 | |
|---|
| 492 | void ChatDlg::chatSendBeep() |
|---|
| 493 | { |
|---|
| 494 | chatman->SendBeep(); |
|---|
| 495 | QApplication::beep(); |
|---|
| 496 | } |
|---|
| 497 | |
|---|
| 498 | // ----------------------------------------------------------------------------- |
|---|
| 499 | |
|---|
| 500 | void ChatDlg::changeFrontColor(QAction* action) |
|---|
| 501 | { |
|---|
| 502 | int i = action->data().toInt(); |
|---|
| 503 | if (i < 0) return; |
|---|
| 504 | |
|---|
| 505 | QColor color (col_array[i*3+0], col_array[i*3+1], col_array[i*3+2]); |
|---|
| 506 | |
|---|
| 507 | mlePaneLocal->setForeground(color); |
|---|
| 508 | mleIRCLocal->setForeground(color); |
|---|
| 509 | mleIRCRemote->setForeground(color); |
|---|
| 510 | |
|---|
| 511 | // if ignoring style change the remote panes too |
|---|
| 512 | updateRemoteStyle(); |
|---|
| 513 | |
|---|
| 514 | // sent to remote |
|---|
| 515 | chatman->ChangeColorFg(color.red(), color.green(), color.blue()); |
|---|
| 516 | } |
|---|
| 517 | |
|---|
| 518 | |
|---|
| 519 | // ----------------------------------------------------------------------------- |
|---|
| 520 | |
|---|
| 521 | void ChatDlg::changeBackColor(QAction* action) |
|---|
| 522 | { |
|---|
| 523 | int i = action->data().toInt(); |
|---|
| 524 | if (i < 0) return; |
|---|
| 525 | |
|---|
| 526 | QColor color (col_array[i*3+0], col_array[i*3+1], col_array[i*3+2]); |
|---|
| 527 | |
|---|
| 528 | mlePaneLocal->setBackground(color); |
|---|
| 529 | mleIRCLocal->setBackground(color); |
|---|
| 530 | mleIRCRemote->setBackground(color); |
|---|
| 531 | |
|---|
| 532 | // if ignoring style change the remote panes too |
|---|
| 533 | updateRemoteStyle(); |
|---|
| 534 | |
|---|
| 535 | // sent to remote |
|---|
| 536 | chatman->ChangeColorBg(color.red(), color.green(), color.blue()); |
|---|
| 537 | } |
|---|
| 538 | |
|---|
| 539 | // ----------------------------------------------------------------------------- |
|---|
| 540 | |
|---|
| 541 | void ChatDlg::updateRemoteStyle() |
|---|
| 542 | { |
|---|
| 543 | if(tbtIgnore->isChecked()) { |
|---|
| 544 | QColor fg(chatman->ColorFg()[0], chatman->ColorFg()[1], |
|---|
| 545 | chatman->ColorFg()[2]); |
|---|
| 546 | QColor bg(chatman->ColorBg()[0], chatman->ColorBg()[1], |
|---|
| 547 | chatman->ColorBg()[2]); |
|---|
| 548 | QFont f(mlePaneLocal->font()); |
|---|
| 549 | ChatUserWindowsList::iterator iter; |
|---|
| 550 | for (iter = chatUserWindows.begin(); iter != chatUserWindows.end(); iter++) |
|---|
| 551 | { |
|---|
| 552 | iter->w->setForeground(fg); |
|---|
| 553 | iter->w->setBackground(bg); |
|---|
| 554 | iter->w->setFont(f); |
|---|
| 555 | } |
|---|
| 556 | } |
|---|
| 557 | else { |
|---|
| 558 | ChatUserWindowsList::iterator iter; |
|---|
| 559 | for (iter = chatUserWindows.begin(); iter != chatUserWindows.end(); iter++) |
|---|
| 560 | { |
|---|
| 561 | QColor fg(iter->u->ColorFg()[0], iter->u->ColorFg()[1], |
|---|
| 562 | iter->u->ColorFg()[2]); |
|---|
| 563 | QColor bg(iter->u->ColorBg()[0], iter->u->ColorBg()[1], |
|---|
| 564 | iter->u->ColorBg()[2]); |
|---|
| 565 | QFont f(iter->w->font()); |
|---|
| 566 | f.setFixedPitch((iter->u->FontStyle() & 0x0F) == STYLE_FIXEDxPITCH); |
|---|
| 567 | |
|---|
| 568 | switch (iter->u->FontStyle() & 0xF0) |
|---|
| 569 | { |
|---|
| 570 | case STYLE_ROMAN: |
|---|
| 571 | f.setStyleHint(QFont::Serif); |
|---|
| 572 | break; |
|---|
| 573 | case STYLE_SWISS: |
|---|
| 574 | f.setStyleHint(QFont::SansSerif); |
|---|
| 575 | break; |
|---|
| 576 | case STYLE_DECORATIVE: |
|---|
| 577 | f.setStyleHint(QFont::Decorative); |
|---|
| 578 | break; |
|---|
| 579 | case STYLE_DONTCARE: |
|---|
| 580 | case STYLE_MODERN: |
|---|
| 581 | case STYLE_SCRIPT: |
|---|
| 582 | default: |
|---|
| 583 | f.setStyleHint(QFont::AnyStyle); |
|---|
| 584 | break; |
|---|
| 585 | } |
|---|
| 586 | f.setFamily(iter->u->FontFamily()); |
|---|
| 587 | f.setPointSize(iter->u->FontSize()); |
|---|
| 588 | f.setBold(iter->u->FontBold()); |
|---|
| 589 | f.setItalic(iter->u->FontItalic()); |
|---|
| 590 | f.setUnderline(iter->u->FontUnderline()); |
|---|
| 591 | f.setStrikeOut(iter->u->FontStrikeOut()); |
|---|
| 592 | iter->w->setForeground(fg); |
|---|
| 593 | iter->w->setBackground(bg); |
|---|
| 594 | iter->w->setFont(f); |
|---|
| 595 | } |
|---|
| 596 | } |
|---|
| 597 | } |
|---|
| 598 | |
|---|
| 599 | |
|---|
| 600 | //-----ChatDlg::StartAsServer------------------------------------------------ |
|---|
| 601 | bool ChatDlg::StartAsServer() |
|---|
| 602 | { |
|---|
| 603 | lblRemote->setText(tr("Remote - Waiting for joiners...")); |
|---|
| 604 | if (!chatman->StartAsServer()) return false; |
|---|
| 605 | return true; |
|---|
| 606 | } |
|---|
| 607 | |
|---|
| 608 | |
|---|
| 609 | |
|---|
| 610 | //-----ChatDlg::StartAsClient------------------------------------------------ |
|---|
| 611 | bool ChatDlg::StartAsClient(unsigned short nPort) |
|---|
| 612 | { |
|---|
| 613 | lblRemote->setText(tr("Remote - Connecting...")); |
|---|
| 614 | chatman->StartAsClient(nPort); |
|---|
| 615 | return true; |
|---|
| 616 | } |
|---|
| 617 | |
|---|
| 618 | |
|---|
| 619 | |
|---|
| 620 | //-----chatSend----------------------------------------------------------------- |
|---|
| 621 | void ChatDlg::chatSend(QKeyEvent* e) |
|---|
| 622 | { |
|---|
| 623 | switch (e->key()) |
|---|
| 624 | { |
|---|
| 625 | case Qt::Key_Enter: |
|---|
| 626 | case Qt::Key_Return: |
|---|
| 627 | { |
|---|
| 628 | if (m_nMode == CHAT_IRC) { |
|---|
| 629 | QString text = mleIRCLocal->toPlainText(); |
|---|
| 630 | if (text.right(1) == "\n") text.truncate(text.length()-1); |
|---|
| 631 | QByteArray encoded = codec->fromUnicode(text); |
|---|
| 632 | // send the data over the wire |
|---|
| 633 | char* c; |
|---|
| 634 | for (c = encoded.data(); *c; c++) |
|---|
| 635 | chatman->SendCharacter(*c); |
|---|
| 636 | |
|---|
| 637 | // even if the pane didn't trigger the event, |
|---|
| 638 | // we need to keep it updated |
|---|
| 639 | mlePaneLocal->appendNoNewLine("\n"); |
|---|
| 640 | // so you'll get some idea what your buddy sees (encoding-wise) |
|---|
| 641 | mleIRCRemote->append(chatname + "> " + codec->toUnicode(encoded)); |
|---|
| 642 | mleIRCRemote->GotoEnd(); |
|---|
| 643 | |
|---|
| 644 | mleIRCLocal->clear(); |
|---|
| 645 | } else { |
|---|
| 646 | // keep IRC updated anyway (encoding should be already properly represented) |
|---|
| 647 | mleIRCRemote->append(chatname + "> " + mlePaneLocal->lastLine()); |
|---|
| 648 | } |
|---|
| 649 | |
|---|
| 650 | chatman->SendNewline(); |
|---|
| 651 | break; |
|---|
| 652 | } |
|---|
| 653 | case Qt::Key_Backspace: |
|---|
| 654 | { |
|---|
| 655 | if (m_nMode == CHAT_IRC) { |
|---|
| 656 | mlePaneLocal->backspace(); // keep the pane updated |
|---|
| 657 | } |
|---|
| 658 | |
|---|
| 659 | if (m_nMode == CHAT_PANE) { |
|---|
| 660 | chatman->SendBackspace(); |
|---|
| 661 | } |
|---|
| 662 | |
|---|
| 663 | break; |
|---|
| 664 | } |
|---|
| 665 | case Qt::Key_Tab: |
|---|
| 666 | case Qt::Key_Backtab: |
|---|
| 667 | break; |
|---|
| 668 | |
|---|
| 669 | default: |
|---|
| 670 | { |
|---|
| 671 | QByteArray encoded = codec->fromUnicode(e->text()); |
|---|
| 672 | |
|---|
| 673 | // if in pane mode, send right away |
|---|
| 674 | if (m_nMode == CHAT_PANE) { |
|---|
| 675 | // for multibyte encodings |
|---|
| 676 | char* c; |
|---|
| 677 | for (c = encoded.data(); *c; c |
|---|