void History::add(Message *msg, const QString &type) { QByteArray line = "["; line += type.toUtf8(); line += "]\n"; line += msg->save(); line += '\n'; if (msg->getFlags() & MESSAGE_TEMP) { if (s_tempMsg == NULL) s_tempMsg = new MAP_MSG; msg_save ms; ms.msg = line; ms.contact = msg->contact(); ms.client = msg->client(); s_tempMsg->insert(MAP_MSG::value_type(++s_tempId, ms)); msg->setId(s_tempId); return; } if (!line.isEmpty() && line.at(line.length() - 1) != '\n') line += '\n'; QString name = msg->client(); if (name.isEmpty()) name = QString::number(msg->contact()); QString f_name = QString(HISTORY_PATH).append(name); f_name = user_file(f_name); Contact *contact = getContacts()->contact(msg->contact()); SIM::PropertyHubPtr data; if (contact) data = contact->getUserData("history"); if (!data.isNull() && data->value("CutSize").toBool()) { QFileInfo fInfo(f_name); if (fInfo.exists() && (fInfo.size() >= data->value("MaxSize").toInt() * 0x100000 + CUT_BLOCK)) { int pos = fInfo.size() - data->value("MaxSize").toUInt() * 0x100000 + line.size(); if (pos < 0) pos = 0; del(f_name, msg->contact(), pos, false); } } QFile f(f_name); if (!f.open(QIODevice::ReadWrite | QIODevice::Append)) { log(L_ERROR, "Can't open %s", qPrintable(f_name)); return; } qint64 id = f.pos(); f.write(line); msg->setId(id); }
void Test::userDataManipulation() { SIM::UserDataPtr data = SIM::UserData::create(); SIM::PropertyHubPtr hub = data->getUserData("nonexistant"); QVERIFY(hub.isNull()); hub = data->createUserData("alpha"); QVERIFY(!hub.isNull()); hub->setValue("foo", 12); QCOMPARE(hub->value("foo").toInt(), 12); SIM::PropertyHubPtr anotherhub = data->getUserData("alpha"); QCOMPARE(anotherhub->value("foo").toInt(), 12); hub.clear(); anotherhub.clear(); data->destroyUserData("alpha"); hub = data->getUserData("alpha"); QVERIFY(hub.isNull()); }
bool OSDPlugin::processEvent(Event *e) { OSDRequest osd; switch (e->type()){ case eEventContact: { EventContact *ec = static_cast<EventContact*>(e); Contact *contact = ec->contact(); if (contact->getIgnore()) break; switch(ec->action()) { case EventContact::eOnline: { osd.contact = contact->id(); osd.type = OSD_ALERTONLINE; m_queue.push_back(osd); processQueue(); break; } case EventContact::eStatus: { SIM::PropertyHubPtr data = contact->getUserData("OSD"); if(!data.isNull()) { unsigned style = 0; QSet<QString> wrkIcons; QString statusIcon; contact->contactInfo(style, statusIcon, &wrkIcons); if (wrkIcons.contains("typing")){ if (!m_typing.contains(contact->id())) { m_typing += contact->id(); osd.contact = contact->id(); osd.type = OSD_TYPING; m_queue.push_back(osd); processQueue(); } }else{ m_typing.remove(contact->id()); if ((m_request.type == OSD_TYPING) && (m_request.contact == contact->id())){ m_timer->stop(); bTimerActive=false; m_timer->start(100); bTimerActive=true; } } } break; } default: break; } break; } case eEventMessageReceived: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) break; SIM::PropertyHubPtr data = contact->getUserData("OSD"); if(data.isNull()) break; osd.contact = msg->contact(); CorePlugin* core = GET_CorePlugin(); if (!core->unread.empty()) bHaveUnreadMessages=true; if (msg->type() == MessageStatus) { StatusMessage *smsg = (StatusMessage*)msg; switch (smsg->getStatus()) { case STATUS_AWAY: osd.type = OSD_ALERTAWAY; break; case STATUS_NA: osd.type = OSD_ALERTNA; break; case STATUS_DND: osd.type = OSD_ALERTDND; break; case STATUS_OCCUPIED: /* STATUS_OCCUPIED, took over from contacts.h! */ osd.type = OSD_ALERTOCCUPIED; break; case STATUS_FFC: osd.type = OSD_ALERTFFC; break; case STATUS_OFFLINE: osd.type = OSD_ALERTOFFLINE; break; case STATUS_ONLINE: osd.type = OSD_NONE; return false; default: log(L_DEBUG,"OSD: Unknown status %ld",smsg->getStatus()); osd.type = OSD_NONE; return false; } m_queue.push_back(osd); processQueue(); }else{ osd.type = OSD_MESSAGE; if ((m_request.type == OSD_MESSAGE) && (m_request.contact == msg->contact())){ m_queue.push_front(osd); m_timer->stop(); bTimerActive=false; m_timer->start(100);bTimerActive=true; }else{ m_queue.push_back(osd); processQueue(); } } break; } case eEventMessageDeleted: case eEventMessageRead: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) break; SIM::PropertyHubPtr data = contact->getUserData("OSD"); if (data.isNull()) break; osd.contact = msg->contact(); CorePlugin* core = GET_CorePlugin(); if (core->unread.empty()) bHaveUnreadMessages=false; if (msg->type() == MessageStatus) { StatusMessage *smsg = (StatusMessage*)msg; switch (smsg->getStatus()) { case STATUS_AWAY: osd.type = OSD_ALERTAWAY; break; case STATUS_NA: osd.type = OSD_ALERTNA; break; case STATUS_DND: osd.type = OSD_ALERTDND; break; case STATUS_OCCUPIED: /* STATUS_OCCUPIED, took over from contacts.h! */ osd.type = OSD_ALERTOCCUPIED; break; case STATUS_FFC: osd.type = OSD_ALERTFFC; break; case STATUS_OFFLINE: osd.type = OSD_ALERTOFFLINE; break; case STATUS_ONLINE: osd.type = OSD_NONE; return false; default: log(L_DEBUG,"OSD: Unknown status %ld",smsg->getStatus()); osd.type = OSD_NONE; return false; } m_queue.push_back(osd); processQueue(); }else{ osd.type = OSD_MESSAGE; if ((m_request.type == OSD_MESSAGE) && (m_request.contact == msg->contact())){ m_queue.push_front(osd); m_timer->stop(); bTimerActive=false; m_timer->start(100);bTimerActive=true; }else{ m_queue.push_back(osd); processQueue(); } } break; } default: break; } return false; }
bool MsgEdit::sendMessage(Message *msg) { if (m_retry.msg){ delete m_retry.msg; m_retry.msg = NULL; } if (m_msg){ delete msg; if (EventMessageCancel(m_msg).process()) m_msg = NULL; stopSend(false); return false; } bool bClose = true; if (CorePlugin::instance()->getContainerMode()){ bClose = false; Command cmd; cmd->id = CmdSendClose; cmd->param = this; EventCommandWidget eWidget(cmd); eWidget.process(); QToolButton *btnClose = qobject_cast<QToolButton*>(eWidget.widget()); if (btnClose) bClose = btnClose->isChecked(); } CorePlugin::instance()->setValue("CloseSend", bClose); Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ SIM::PropertyHubPtr data = contact->getUserData("translit"); if (!data.isNull() && data->value("Translit").toBool()) msg->setFlags(msg->getFlags() | MESSAGE_TRANSLIT); } msg->setFlags(msg->getFlags() | m_flags); m_flags = 0; if (m_userWnd->m_list){ if( !m_userWnd->m_list->isHaveSelected() ) return false; multiply = m_userWnd->m_list->selected(); msg->setContact( multiply.first() ); multiply.pop_front(); msg->setClient(NULL); if( multiply.count() > 0 ) msg->setFlags(msg->getFlags() | MESSAGE_MULTIPLY); }else if (!m_resource.isEmpty()){ void *data = NULL; Client *c = client(data, true, false, msg->contact(), true); if (c){ QString resources = c->resources(data); while (!resources.isEmpty()){ QString res = getToken(resources, ';'); getToken(res, ','); if (m_resource == res){ msg->setResource(m_resource); break; } } } } editLostFocus(); Command cmd; cmd->id = CmdSend; cmd->text = I18N_NOOP("Cancel"); cmd->icon = "cancel"; cmd->flags = BTN_PICT; cmd->param = this; EventCommandChange(cmd).process(); m_msg = msg; return send(); }
bool MsgEdit::processEvent(Event *e) { switch (e->type()) { case eEventContact: { EventContact *ec = static_cast<EventContact*>(e); if (ec->contact()->id() != m_userWnd->m_id) break; adjustType(); break; } case eEventClientChanged: { adjustType(); break; } case eEventMessageReceived: { EventMessage *em = static_cast<EventMessage*>(e); Message *msg = em->msg(); if (msg->getFlags() & MESSAGE_NOVIEW) return false; if ((msg->contact() == m_userWnd->id()) && (msg->type() != MessageStatus)){ if (CorePlugin::instance()->getContainerMode()){ bool bSetFocus = false; if (topLevelWidget() && topLevelWidget()->inherits("Container")){ Container *container = static_cast<Container*>(topLevelWidget()); if (container->wnd() == m_userWnd) bSetFocus = true; } setMessage(msg, bSetFocus); }else{ if (m_edit->isReadOnly()) QTimer::singleShot(0, this, SLOT(setupNext())); } } break; } case eEventRealSendMessage: { EventRealSendMessage *ersm = static_cast<EventRealSendMessage*>(e); if (ersm->edit() == this){ sendMessage(ersm->msg()); return true; } break; } case eEventCheckCommandState: { EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e); CommandDef *cmd = ecs->cmd(); if ((cmd->param == (TextEdit*)m_edit) && (cmd->id == CmdTranslit)){ Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ SIM::PropertyHubPtr data = contact->getUserData("translit"); if(!data.isNull()) { cmd->flags &= ~COMMAND_CHECKED; if (data->value("Translit").toBool()) cmd->flags |= COMMAND_CHECKED; // FIXME: return true; missing here? } } return false; } if ((cmd->menu_id != MenuTextEdit) || (cmd->param != (TextEdit*)m_edit)) return false; cmd->flags &= ~(COMMAND_CHECKED | COMMAND_DISABLED); switch (cmd->id){ case CmdUndo: if (m_edit->isReadOnly()) return false; if (!m_edit->document()->isUndoAvailable()) cmd->flags |= COMMAND_DISABLED; return true; case CmdRedo: if (m_edit->isReadOnly()) return false; if (!m_edit->document()->isRedoAvailable()) cmd->flags |= COMMAND_DISABLED; return true; case CmdCut: if (m_edit->isReadOnly()) return false; case CmdCopy: if (m_edit->textCursor().selectedText().isEmpty()) cmd->flags |= COMMAND_DISABLED; return true; case CmdPaste: if (m_edit->isReadOnly()) return false; if (QApplication::clipboard()->text().isEmpty()) cmd->flags |= COMMAND_DISABLED; return true; case CmdClear: if (m_edit->isReadOnly()) return false; case CmdSelectAll: if (m_edit->toPlainText().isEmpty()) cmd->flags |= COMMAND_DISABLED; return true; } break; } case eEventCommandExec: { EventCommandExec *ece = static_cast<EventCommandExec*>(e); CommandDef *cmd = ece->cmd(); #if defined(USE_KDE) #if KDE_IS_VERSION(3,2,0) if (cmd->id == CmdEnableSpell){ m_edit->setCheckSpellingEnabled(cmd->flags & COMMAND_CHECKED); return false; } else if ((cmd->id == CmdSpell) && (cmd->param == this)){ m_edit->checkSpelling(); return true; } else #endif #endif if ((cmd->id == CmdSmile) && (cmd->param == this)){ EventCommandWidget eWidget(cmd); eWidget.process(); QToolButton *btnSmile = qobject_cast<QToolButton*>(eWidget.widget()); if (btnSmile){ SmilePopup *popup = new SmilePopup(this); connect(popup, SIGNAL(insert(const QString &)), this, SLOT(insertSmile(const QString &))); QPoint p = CToolButton::popupPos(btnSmile, popup); popup->move(p); popup->show(); } return true; } else if ((cmd->id == CmdTranslit) && (cmd->param == this)){ Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ SIM::PropertyHubPtr data = contact->getUserData("translit", true); data->setValue("Translit", ((cmd->flags & COMMAND_CHECKED) != 0)); } return true; } else if ((cmd->id == CmdMultiply) && (cmd->param == this)){ m_userWnd->showListView((cmd->flags & COMMAND_CHECKED) != 0); return true; } else if ((cmd->bar_id == ToolBarMsgEdit) && m_edit->isReadOnly() && (cmd->param == this)){ switch (cmd->id){ case CmdMsgAnswer:{ Message *msg = new Message(MessageGeneric); msg->setContact(m_userWnd->id()); msg->setClient(m_client); EventOpenMessage(msg).process(); delete msg; } case CmdNextMessage: QTimer::singleShot(0, this, SLOT(goNext())); break; } } else if ((cmd->menu_id != MenuTextEdit) || (cmd->param != this)) return false; switch (cmd->id){ case CmdUndo: m_edit->undo(); return true; case CmdRedo: m_edit->redo(); return true; case CmdCut: m_edit->cut(); return true; case CmdCopy: m_edit->copy(); return true; case CmdPaste: m_edit->paste(); return true; case CmdClear: m_edit->clear(); return true; case CmdSelectAll: m_edit->selectAll(); return true; } break; }