void Container::init() { if (m_bInit) return; QFrame *frm = new QFrame(this, "container"); setCentralWidget(frm); connect(CorePlugin::m_plugin, SIGNAL(modeChanged()), this, SLOT(modeChanged())); QVBoxLayout *lay = new QVBoxLayout(frm); m_wnds = new QWidgetStack(frm); m_wnds->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); lay->addWidget(m_wnds); m_tabSplitter = new Splitter(frm); m_tabSplitter->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum)); m_tabBar = new UserTabBar(m_tabSplitter); m_tabBar->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding)); m_tabBar->hide(); m_bInit = true; m_status = new ContainerStatus(m_tabSplitter); lay->addWidget(m_tabSplitter); connect(m_tabBar, SIGNAL(selected(int)), this, SLOT(contactSelected(int))); connect(this, SIGNAL(toolBarPositionChanged(QToolBar*)), this, SLOT(toolbarChanged(QToolBar*))); connect(m_status, SIGNAL(sizeChanged(int)), this, SLOT(statusChanged(int))); m_accel = new QAccel(this); connect(m_accel, SIGNAL(activated(int)), this, SLOT(accelActivated(int))); setupAccel(); showBar(); for (list<UserWnd*>::iterator it = m_childs.begin(); it != m_childs.end(); ++it) addUserWnd((*it), false); m_childs.clear(); string windows = getWindows(); while (!windows.empty()){ unsigned long id = strtoul(getToken(windows, ',').c_str(), NULL, 10); Contact *contact = getContacts()->contact(id); if (contact == NULL) continue; Buffer config; const char *cfg = getWndConfig(id); if (cfg && *cfg){ config << "[Title]\n" << cfg; config.setWritePos(0); config.getSection(); } addUserWnd(new UserWnd(id, &config, false, true), true); } if (m_tabBar->count() == 0) QTimer::singleShot(0, this, SLOT(close())); setWindows(NULL); clearWndConfig(); m_tabBar->raiseTab(getActiveWindow()); show(); }
QWidget *ForwardPlugin::createConfigWindow(QWidget *parent) { return new ForwardConfig(parent, getContacts()->getUserData(user_data_id), this); }
void *ForwardPlugin::processEvent(Event *e) { if (e->type() == EventMessageReceived){ Message *msg = (Message*)(e->param()); if (msg->type() == MessageStatus) return NULL; QString text = msg->getPlainText(); if (text.isEmpty()) return NULL; if (msg->type() == MessageSMS){ SMSMessage *sms = static_cast<SMSMessage*>(msg); QString phone = sms->getPhone(); bool bMyPhone = false; ForwardUserData *data = (ForwardUserData*)(getContacts()->getUserData(user_data_id)); if (data->Phone.ptr) bMyPhone = ContactList::cmpPhone(phone.toUtf8(), data->Phone.ptr); if (!bMyPhone){ Group *grp; ContactList::GroupIterator it; while ((grp = ++it) != NULL){ data = (ForwardUserData*)(grp->userData.getUserData(user_data_id, false)); if (data && data->Phone.ptr){ bMyPhone = ContactList::cmpPhone(phone.toUtf8(), data->Phone.ptr); break; } } } if (!bMyPhone){ Contact *contact; ContactList::ContactIterator it; while ((contact = ++it) != NULL){ data = (ForwardUserData*)(contact->userData.getUserData(user_data_id, false)); if (data && data->Phone.ptr){ bMyPhone = ContactList::cmpPhone(phone.toUtf8(), data->Phone.ptr); break; } } } if (bMyPhone){ int n = text.find(": "); if (n > 0){ QString name = text.left(n); QString msg_text = text.mid(n + 2); Contact *contact; ContactList::ContactIterator it; while ((contact = ++it) != NULL){ if (contact->getName() == name){ Message *msg = new Message(MessageGeneric); msg->setContact(contact->id()); msg->setText(msg_text); void *data; ClientDataIterator it(contact->clientData); while ((data = ++it) != NULL){ if (it.client()->send(msg, data)) break; } if (data == NULL) delete msg; return e->param(); } } } } } Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) return NULL; ForwardUserData *data = (ForwardUserData*)(contact->getUserData(user_data_id)); if ((data == NULL) || (data->Phone.ptr == NULL) || (*data->Phone.ptr == 0)) return NULL; unsigned status = core->getManualStatus(); if ((status == STATUS_AWAY) || (status == STATUS_NA)){ text = contact->getName() + ": " + text; unsigned flags = MESSAGE_NOHISTORY; if (data->Send1st.bValue) flags |= MESSAGE_1ST_PART; if (data->Translit.bValue) flags |= MESSAGE_TRANSLIT; SMSMessage *m = new SMSMessage; m->setPhone(QString::fromUtf8(data->Phone.ptr)); m->setText(text); m->setFlags(flags); unsigned i; for (i = 0; i < getContacts()->nClients(); i++){ Client *client = getContacts()->getClient(i); if (client->send(m, NULL)) break; } if (i >= getContacts()->nClients()) delete m; } } return NULL; }
JabberPlugin::JabberPlugin(unsigned base, Buffer *cfg) : Plugin(base) { #if defined(WIN32) && (COMPAT_QT_VERSION < 0x030000) qInitJpeg(); #endif plugin = this; load_data(jabberData, &data, cfg); JabberPacket = registerType(); getContacts()->addPacketType(JabberPacket, jabber_descr.text, true); IconDef icon; icon.name = "Jabber"; icon.xpm = jabber; Event eIcon(EventAddIcon, &icon); eIcon.process(); icon.name = "reg"; icon.xpm = reg; eIcon.process(); icon.name = "connect"; icon.xpm = connect_xpm; icon.system = "connect_established"; eIcon.process(); Event eMenuSearch(EventMenuCreate, (void*)MenuSearchResult); eMenuSearch.process(); Event eMenuGroups(EventMenuCreate, (void*)MenuJabberGroups); eMenuGroups.process(); Event eMenuBrowser(EventMenuCreate, (void*)MenuBrowser); eMenuBrowser.process(); Event eToolbar(EventToolbarCreate, (void*)BarBrowser); eToolbar.process(); Command cmd; cmd->id = CmdJabberMessage; cmd->text = I18N_NOOP("&Message"); cmd->icon = "message"; cmd->menu_id = MenuSearchResult; cmd->menu_grp = 0x1000; cmd->flags = COMMAND_DEFAULT; Event eCmd(EventCommandCreate, cmd); eCmd.process(); cmd->id = CmdBrowseInfo; cmd->text = I18N_NOOP("User &info"); cmd->icon = "info"; cmd->menu_grp = 0x1001; eCmd.process(); cmd->id = CmdGroups; cmd->text = I18N_NOOP("&Add to group"); cmd->icon = NULL; cmd->menu_grp = 0x1002; cmd->popup_id = MenuJabberGroups; eCmd.process(); cmd->id = CmdGroups; cmd->text = "_"; cmd->menu_id = MenuJabberGroups; cmd->popup_id = 0; cmd->flags = COMMAND_CHECK_STATE; eCmd.process(); cmd->id = CmdBack; cmd->text = I18N_NOOP("&Back"); cmd->icon = "1leftarrow"; cmd->bar_grp = 0x1000; cmd->bar_id = BarBrowser; cmd->menu_id = 0; cmd->flags = COMMAND_CHECK_STATE; eCmd.process(); cmd->id = CmdForward; cmd->text = I18N_NOOP("&Next"); cmd->icon = "1rightarrow"; cmd->bar_grp = 0x1001; eCmd.process(); cmd->id = CmdUrl; cmd->text = I18N_NOOP("JID"); cmd->icon = "run"; cmd->bar_grp = 0x2000; cmd->flags = BTN_COMBO_CHECK; eCmd.process(); cmd->id = CmdNode; cmd->text = I18N_NOOP("Node"); cmd->bar_grp = 0x2001; cmd->flags = BTN_COMBO | BTN_NO_BUTTON; eCmd.process(); cmd->id = CmdBrowseSearch; cmd->text = I18N_NOOP("&Search"); cmd->icon = "find"; cmd->bar_grp = 0x3000; cmd->flags = COMMAND_CHECK_STATE; eCmd.process(); cmd->id = CmdRegister; cmd->text = I18N_NOOP("&Register"); cmd->icon = "reg"; cmd->bar_grp = 0x3001; cmd->flags = COMMAND_CHECK_STATE; eCmd.process(); cmd->id = CmdBrowseInfo; cmd->text = I18N_NOOP("Info"); cmd->icon = "info"; cmd->bar_grp = 0x3010; eCmd.process(); cmd->id = CmdBrowseConfigure; cmd->text = I18N_NOOP("Configure"); cmd->icon = "configure"; cmd->bar_grp = 0x3020; eCmd.process(); cmd->id = CmdBrowseMode; cmd->text = I18N_NOOP("Browser mode"); cmd->icon = "configure"; cmd->bar_grp = 0x5000; cmd->flags = COMMAND_DEFAULT; cmd->popup_id = MenuBrowser; eCmd.process(); cmd->id = CmdOneLevel; cmd->text = I18N_NOOP("Load one level"); cmd->icon = NULL; cmd->bar_id = 0; cmd->bar_grp = 0; cmd->menu_id = MenuBrowser; cmd->menu_grp = 0x1000; cmd->popup_id = 0; cmd->flags = COMMAND_CHECK_STATE; eCmd.process(); cmd->id = CmdAllLevels; cmd->text = I18N_NOOP("Load all levels"); cmd->menu_grp = 0x1001; eCmd.process(); cmd->id = CmdModeDisco; cmd->text = "Discovery"; cmd->menu_grp = 0x2000; eCmd.process(); cmd->id = CmdModeBrowse; cmd->text = "Browse"; cmd->menu_grp = 0x2001; eCmd.process(); cmd->id = CmdModeAgents; cmd->text = "Agents"; cmd->menu_grp = 0x2002; eCmd.process(); m_protocol = new JabberProtocol(this); registerMessages(); }
void SearchDialog::fillClients() { vector<ClientWidget> widgets = m_widgets; m_widgets.clear(); m_search->cmbClients->clear(); unsigned nClients = 0; int current = -1; int defCurrent = -1; for (unsigned i = 0; i < getContacts()->nClients(); i++){ Client *client = getContacts()->getClient(i); QWidget *search = client->searchWindow(m_search->wndCondition); if (search == NULL) continue; unsigned n; for (n = 0; n < widgets.size(); n++){ if ((widgets[n].client != client) || !widgets[n].name.isEmpty()) continue; delete search; search = widgets[n].widget; widgets[n].widget = NULL; break; } if (n >= widgets.size()) m_search->wndCondition->addWidget(search, ++m_id); m_search->cmbClients->insertItem(Pict(client->protocol()->description()->icon), CorePlugin::m_plugin->clientName(client)); ClientWidget cw; cw.client = client; cw.widget = search; m_widgets.push_back(cw); if (search == m_current) current = m_widgets.size() - 1; if (client->protocol()->description()->flags & PROTOCOL_SEARCH) nClients++; if (client->name() == CorePlugin::m_plugin->getSearchClient()) defCurrent = m_widgets.size() - 1; } if (nClients > 1){ unsigned n; QWidget *search = NULL; for (n = 0; n < widgets.size(); n++){ if (widgets[n].client == (Client*)(-1)){ search = widgets[n].widget; widgets[n].widget = NULL; break; } } if (search == NULL){ search = new SearchAll(m_search->wndCondition); m_search->wndCondition->addWidget(new SearchAll(m_search->wndCondition), ++m_id); } m_search->cmbClients->insertItem(Pict("find"), i18n("All networks")); ClientWidget cw; cw.client = (Client*)(-1); cw.widget = search; m_widgets.push_back(cw); if ((search == m_current) || ((m_current == NULL) && (current < 0) && (defCurrent < 0))) current = m_widgets.size() - 1; } unsigned n; QWidget *search = NULL; for (n = 0; n < widgets.size(); n++){ if (widgets[n].client == NULL){ search = widgets[n].widget; widgets[n].widget = NULL; break; } } if (search == NULL){ search = new NonIM(m_search->wndCondition); m_search->wndCondition->addWidget(search, ++m_id); } m_search->cmbClients->insertItem(Pict("nonim"), i18n("Non-IM contact")); ClientWidget cw; cw.client = NULL; cw.widget = search; m_widgets.push_back(cw); if (search == m_current) current = m_widgets.size() - 1; if (m_update->isActive()){ m_update->stop(); }else if (m_result){ m_result->viewport()->setUpdatesEnabled(false); } for (n = 0; n < widgets.size(); n++){ if (widgets[n].name.isEmpty()) continue; unsigned i; for (i = 0; i < m_widgets.size(); i++) if (widgets[n].client == m_widgets[i].client) break; if (i >= m_widgets.size()) continue; m_search->cmbClients->insertItem(Pict(widgets[n].client->protocol()->description()->icon), widgets[n].name); m_widgets.push_back(widgets[n]); widgets[n].widget = NULL; } for (n = 0; n < widgets.size(); n++){ if (widgets[n].widget){ if (widgets[n].widget == m_active) searchDone(m_active); if (widgets[n].widget == m_current) m_current = NULL; for (QListViewItem *item = m_result->firstChild(); item; ){ QListViewItem *next = item->nextSibling(); if ((QWidget*)(item->text(COL_SEARCH_WND).toUInt()) == widgets[n].widget) delete item; if (next == NULL) break; item = next; } delete widgets[n].widget; } } if (current == -1) current = defCurrent; if (current == -1) current = 0; m_search->cmbClients->setCurrentItem(current); clientActivated(current); setStatus(); m_update->start(500); }
void *MsgEdit::processEvent(Event *e) { if (e->type() == EventMessageReceived){ Message *msg = (Message*)(e->param()); if ((msg->contact() == m_userWnd->id()) && (msg->type() != MessageStatus)){ if (CorePlugin::m_plugin->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())); } } } if (e->type() == EventRealSendMessage){ MsgSend *s = (MsgSend*)(e->param()); if (s->edit == this){ sendMessage(s->msg); return e->param(); } } if (e->type() == EventCheckState){ CommandDef *cmd = (CommandDef*)(e->param()); if ((cmd->param == this) && (cmd->id == CmdTranslit)){ Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ TranslitUserData *data = (TranslitUserData*)(contact->getUserData(CorePlugin::m_plugin->translit_data_id)); if (data){ cmd->flags &= ~COMMAND_CHECKED; if (data->Translit) cmd->flags |= COMMAND_CHECKED; } } return NULL; } if ((cmd->menu_id != MenuTextEdit) || (cmd->param != this)) return NULL; cmd->flags &= ~(COMMAND_CHECKED | COMMAND_DISABLED); switch (cmd->id){ case CmdUndo: if (m_edit->isReadOnly()) return NULL; if (!m_edit->isUndoAvailable()) cmd->flags |= COMMAND_DISABLED; return e->param(); case CmdRedo: if (m_edit->isReadOnly()) return NULL; if (!m_edit->isRedoAvailable()) cmd->flags |= COMMAND_DISABLED; return e->param(); case CmdCut: if (m_edit->isReadOnly()) return NULL; case CmdCopy: if (!m_edit->hasSelectedText()) cmd->flags |= COMMAND_DISABLED; return e->param(); case CmdPaste: if (m_edit->isReadOnly()) return NULL; if (QApplication::clipboard()->text().isEmpty()) cmd->flags |= COMMAND_DISABLED; return e->param(); case CmdClear: if (m_edit->isReadOnly()) return NULL; case CmdSelectAll: if (m_edit->text().isEmpty()) cmd->flags |= COMMAND_DISABLED; return e->param(); } return NULL; } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); if ((cmd->id == CmdSmile) && (cmd->param == this)){ Event eBtn(EventCommandWidget, cmd); QToolButton *btnSmile = (QToolButton*)(eBtn.process()); if (btnSmile){ SmilePopup *popup = new SmilePopup(this); QSize s = popup->minimumSizeHint(); popup->resize(s); connect(popup, SIGNAL(insert(int)), this, SLOT(insertSmile(int))); QPoint p = CToolButton::popupPos(btnSmile, popup); popup->move(p); popup->show(); } return e->param(); }
bool MsgEdit::sendMessage(Message *msg) { if (m_retry.msg){ delete m_retry.msg; m_retry.msg = NULL; } if (m_msg){ delete msg; Event e(EventMessageCancel, m_msg); if (e.process()) m_msg = NULL; stopSend(false); return false; } bool bClose = true; if (CorePlugin::m_plugin->getContainerMode()){ bClose = false; Command cmd; cmd->id = CmdSendClose; cmd->param = this; Event e(EventCommandWidget, cmd); QToolButton *btnClose = (QToolButton*)(e.process()); if (btnClose) bClose = btnClose->isOn(); } CorePlugin::m_plugin->setCloseSend(bClose); Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ TranslitUserData *data = (TranslitUserData*)(contact->getUserData(CorePlugin::m_plugin->translit_data_id)); if (data && data->Translit) msg->setFlags(msg->getFlags() | MESSAGE_TRANSLIT); } msg->setFlags(msg->getFlags() | m_flags); m_flags = 0; if (m_userWnd->m_list){ multiply = m_userWnd->m_list->selected; if (multiply.empty()) return false; multiply_it = multiply.begin(); msg->setContact(*multiply_it); msg->setClient(NULL); ++multiply_it; if (multiply_it != multiply.end()) msg->setFlags(msg->getFlags() | MESSAGE_MULTIPLY); } editLostFocus(); Command cmd; cmd->id = CmdSend; cmd->text = I18N_NOOP("Cancel"); cmd->icon = "cancel"; cmd->flags = BTN_PICT; cmd->param = this; Event eCmd(EventCommandChange, cmd); eCmd.process(); m_msg = msg; return send(); }
void OSDConfig::apply() { apply(getContacts()->getUserData(m_plugin->user_data_id)); }
void CMessageBrokerControllerPhone::processRequest(Json::Value& root) { DBG_MSG(("CMessageBrokerControllerPhone::processRequest()\n")); if (getControllersName() == getDestinationComponentName(root)) { Json::Value response; response["jsonrpc"] = root["jsonrpc"]; response["id"] = root["id"]; if ("makeCall" == getMethodName(root)) { if (root.isMember("params")) { Json::Value params = root["params"]; if (params.isMember("phoneNumber") && params["phoneNumber"].isString()) { makeCall(params["phoneNumber"].asString(), response); } else { DBG_MSG_ERROR(("Wrong params!\n")); prepareErrorMessage(NsMessageBroker::INVALID_PARAMS, "Wrong params!", response); } } else { DBG_MSG_ERROR(("Not possible to parse phone number!\n")); prepareErrorMessage(NsMessageBroker::INVALID_PARAMS, "Not possible to parse phone number!", response); } } else if ("endCall" == getMethodName(root)) { endCall(root["params"].asString(), response); } else if ("holdCall" == getMethodName(root)) { holdCall(root["params"].asString(), response); } else if ("getContacts" == getMethodName(root)) { if (root.isMember("params")) { Json::Value params = root["params"]; if (params.isMember("firstLetter") && params["firstLetter"].isString() && params.isMember("offset") && params["offset"].isInt() && params.isMember("numberOfItems") && params["numberOfItems"].isInt()) { getContacts(params["firstLetter"].asString(), params["offset"].asInt(), params["numberOfItems"].asInt(), response); } else { DBG_MSG_ERROR(("Wrong params of getContacts()!\n")); prepareErrorMessage(NsMessageBroker::INVALID_PARAMS, "Wrong params of getContacts()!", response); } } else { DBG_MSG_ERROR(("Params is not an object!\n")); prepareErrorMessage(NsMessageBroker::INVALID_PARAMS, "Params is not an object!", response); } } else if ("getHistory" == getMethodName(root)) { if (root.isMember("params")) { Json::Value params = root["params"]; if (params.isMember("typeOfContacts") && params["typeOfContacts"].isString() && params.isMember("offset") && params["offset"].isInt() && params.isMember("numberOfItems") && params["numberOfItems"].isInt()) { getHistory(params["typeOfContacts"].asString(), params["offset"].asInt(), params["numberOfItems"].asInt(), response); } else { DBG_MSG_ERROR(("Wrong params of getHistory()!\n")); prepareErrorMessage(NsMessageBroker::INVALID_PARAMS, "Wrong params of getHistory()!", response); } } else { DBG_MSG_ERROR(("Params is not an object!\n")); prepareErrorMessage(NsMessageBroker::INVALID_PARAMS, "Params is not an object!", response); } } else { DBG_MSG_ERROR(("Method has not been found!\n")); Json::Value err; err["code"] = NsMessageBroker::INVALID_REQUEST; err["message"] = "Method has not been found."; response["error"] = err; } sendJsonMessage(response); } else { DBG_MSG_ERROR(("Wrong message destination!\n")); } }
void HistoryConfig::apply() { bool bChanged = false; if (tabStyle->currentPage() == source){ int cur = cmbStyle->currentItem(); if (m_bDirty && (cur >= 0)) m_styles[cur].text = unquoteText(edtStyle->text()); } for (unsigned i = 0; i < m_styles.size(); i++){ if (m_styles[i].text.isEmpty() || !m_styles[i].bCustom) continue; if ((int)i == cmbStyle->currentItem()) bChanged = true; string name = STYLES; name += QFile::encodeName(m_styles[i].name); name += EXT; name = user_file(name.c_str()); QFile f(QFile::decodeName((name + BACKUP_SUFFIX).c_str())); // use backup file for this ... if (f.open(IO_WriteOnly | IO_Truncate)){ string s; s = m_styles[i].text.utf8(); f.writeBlock(s.c_str(), s.length()); const int status = f.status(); #if QT_VERSION >= 0x030200 const QString errorMessage = f.errorString(); #else const QString errorMessage = "write file fail"; #endif f.close(); if (status != IO_Ok) { log(L_ERROR, "IO error during writting to file %s : %s", (const char*)f.name().local8Bit(), (const char*)errorMessage.local8Bit()); } else { // rename to normal file QFileInfo fileInfo(f.name()); QString desiredFileName = fileInfo.fileName(); desiredFileName = desiredFileName.left(desiredFileName.length() - strlen(BACKUP_SUFFIX)); #ifdef WIN32 fileInfo.dir().remove(desiredFileName); #endif if (!fileInfo.dir().rename(fileInfo.fileName(), desiredFileName)) { log(L_ERROR, "Can't rename file %s to %s", (const char*)fileInfo.fileName().local8Bit(), (const char*)desiredFileName.local8Bit()); } } }else{ log(L_WARN, "Can't create %s", name.c_str()); } } int cur = cmbStyle->currentItem(); if ((cur >= 0) && m_styles.size() && (m_styles[cur].bChanged || (m_styles[cur].name != QFile::decodeName(CorePlugin::m_plugin->getHistoryStyle())))){ CorePlugin::m_plugin->setHistoryStyle(QFile::encodeName(m_styles[cur].name)); bChanged = true; delete CorePlugin::m_plugin->historyXSL; CorePlugin::m_plugin->historyXSL = new XSL(m_styles[cur].name); } if (chkOwn->isChecked() != CorePlugin::m_plugin->getOwnColors()){ bChanged = true; CorePlugin::m_plugin->setOwnColors(chkOwn->isChecked()); } if (chkSmile->isChecked() != CorePlugin::m_plugin->getUseSmiles()){ bChanged = true; CorePlugin::m_plugin->setUseSmiles(chkSmile->isChecked()); } CorePlugin::m_plugin->setHistoryPage(atol(cmbPage->lineEdit()->text().latin1())); if (bChanged){ Event e(EventHistoryConfig); e.process(); fillPreview(); } HistoryUserData *data = (HistoryUserData*)(getContacts()->getUserData(CorePlugin::m_plugin->history_data_id)); data->CutDays = chkDays->isChecked(); data->CutSize = chkSize->isChecked(); data->Days = atol(edtDays->text()); data->MaxSize = atol(edtSize->text()); }
QString UserWnd::getName() { Contact *contact = getContacts()->contact(m_id); return contact->getName(); }
void MainInfo::apply() { getEncoding(); Contact *contact = m_contact; if (contact == NULL) { contact = getContacts()->owner(); contact->setPhoneStatus(cmbStatus->currentItem()); } contact->setNotes(edtNotes->text()); QListViewItem *item; QString mails; for (item = lstMails->firstChild(); item; item = item->nextSibling()) { if (mails.length()) mails += ";"; mails += quoteChars(item->text(MAIL_ADDRESS), ";/"); mails += "/"; mails += item->text(MAIL_PROTO); } contact->setEMails(mails); QString phones; for (item = lstPhones->firstChild(); item; item = item->nextSibling()) { if (phones.length()) phones += ";"; phones += quoteChars(item->text(PHONE_NUMBER), ";/,"); phones += ","; phones += quoteChars(item->text(PHONE_TYPE_ASIS), ";/,"); phones += ","; phones += item->text(PHONE_ICON); if (m_contact) { if (!item->text(PHONE_ACTIVE).isEmpty()) phones += ",1"; } else { if (item->text(PHONE_NUMBER) == cmbCurrent->currentText()) phones += ",1"; } phones += "/"; phones += item->text(PHONE_PROTO); } contact->setPhones(phones); QString firstName = contact->getFirstName(); QString lastName = contact->getLastName(); if (firstName != edtFirstName->text()) contact->setFirstName(edtFirstName->text(), NULL); if (lastName != edtLastName->text()) contact->setLastName(edtLastName->text(), NULL); QString name = cmbDisplay->lineEdit()->text(); if (name.isEmpty()) { name = edtFirstName->text(); if (!edtLastName->text().isEmpty()) { if (!name.isEmpty()) { name += " "; name += edtLastName->text(); } } } contact->setName(name); Event e(EventContactChanged, contact); e.process(); }
void *NavigatePlugin::processEvent(Event *e) { if (e->type() == EventGoURL){ string url = (const char*)(e->param()); string proto; if (url.length() == 0) return NULL; int n = url.find(':'); if (n < 0){ proto = "http"; url = proto + "://" + url; }else{ proto = url.substr(0, n); if ((proto != "http") && (proto != "https") && (proto != "ftp") && (proto != "file") && (proto != "mailto")) return NULL; } #ifdef WIN32 ShellExecuteA(NULL, NULL, url.c_str(), NULL, NULL, SW_SHOWNORMAL); #else ExecParam execParam; if (proto == "mailto"){ execParam.cmd = getMailer(); url = url.substr(proto.length() + 1); }else{ execParam.cmd = getBrowser(); } execParam.arg = url.c_str(); Event eExec(EventExec, &execParam); eExec.process(); #endif return e->param(); } if (e->type() == EventEncodeText){ QString *text = (QString*)(e->param()); *text = parseUrl(*text); return e->param(); } if (e->type() == EventCheckState){ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdMail){ Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact == NULL) return NULL; QString mails = contact->getEMails(); if (mails.length() == 0) return NULL; int nMails = 0; while (mails.length()){ getToken(mails, ';'); nMails++; } cmd->popup_id = (nMails <= 1) ? 0 : MenuMail; return e->param(); } if (cmd->id == CmdMailList){ Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact == NULL) return NULL; QString mails = contact->getEMails(); if (mails.length() == 0) return NULL; int nMails = 0; while (mails.length()){ getToken(mails, ';'); nMails++; } CommandDef *cmds = new CommandDef[nMails + 1]; unsigned n = 0; mails = contact->getEMails(); while (mails.length()){ QString mail = getToken(mails, ';', false); mail = getToken(mail, '/'); cmds[n] = *cmd; cmds[n].id = CmdMailList + n; cmds[n].flags = COMMAND_DEFAULT; cmds[n].text_wrk = strdup(mail.utf8()); n++; } memset(&cmds[n], 0, sizeof(CommandDef)); cmd->param = cmds; cmd->flags |= COMMAND_RECURSIVE; return e->param(); } } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdMail){ QString mail; Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact) mail = contact->getEMails(); mail = getToken(mail, ';', false); mail = getToken(mail, '/'); if (mail.length()){ string addr = "mailto:"; addr += mail.local8Bit(); Event eMail(EventGoURL, (void*)addr.c_str()); eMail.process(); } return e->param(); } if (cmd->menu_id == MenuMail){ unsigned n = cmd->id - CmdMailList; QString mails; Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact) mails = contact->getEMails(); while (mails.length()){ QString mail = getToken(mails, ';', false); if (n-- == 0){ mail = getToken(mail, '/'); if (mail.length()){ string addr = "mailto:"; addr += mail.local8Bit(); Event eMail(EventGoURL, (void*)addr.c_str()); eMail.process(); } break; } } return e->param(); } } return NULL; }
void *Container::processEvent(Event *e) { if (m_tabBar == NULL) return NULL; UserWnd *userWnd; Contact *contact; CommandDef *cmd; Message *msg; switch (e->type()){ case EventMessageReceived: msg = (Message*)(e->param()); if (msg->type() == MessageStatus){ contact = getContacts()->contact(msg->contact()); if (contact) contactChanged(contact); return NULL; } if (msg->getFlags() & MESSAGE_NOVIEW) return NULL; if (CorePlugin::m_plugin->getContainerMode()){ if (isActiveWindow() && !isMinimized()){ userWnd = m_tabBar->currentWnd(); if (userWnd && (userWnd->id() == msg->contact())) userWnd->markAsRead(); }else{ msg = (Message*)(e->param()); userWnd = wnd(msg->contact()); if (userWnd) QTimer::singleShot(0, this, SLOT(flash())); } } case EventMessageRead: msg = (Message*)(e->param()); userWnd = wnd(msg->contact()); if (userWnd){ bool bBold = false; for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ if ((*it).contact != msg->contact()) continue; bBold = true; break; } m_tabBar->setBold(msg->contact(), bBold); } break; case EventActiveContact: if (!isActiveWindow()) return NULL; userWnd = m_tabBar->currentWnd(); if (userWnd) return (void*)(userWnd->id()); break; case EventContactDeleted: contact = (Contact*)(e->param()); userWnd = wnd(contact->id()); if (userWnd) removeUserWnd(userWnd); break; case EventContactChanged: contact = (Contact*)(e->param()); userWnd = wnd(contact->id()); if (userWnd){ if (contact->getIgnore()){ removeUserWnd(userWnd); break; } m_tabBar->changeTab(contact->id()); contactChanged(contact); } case EventClientsChanged: setupAccel(); break; case EventContactStatus: contact = (Contact*)(e->param()); userWnd = m_tabBar->wnd(contact->id()); if (userWnd){ unsigned style = 0; string wrkIcons; const char *statusIcon = NULL; contact->contactInfo(style, statusIcon, &wrkIcons); bool bTyping = false; while (!wrkIcons.empty()){ if (getToken(wrkIcons, ',') == "typing"){ bTyping = true; break; } } if (userWnd->m_bTyping != bTyping){ userWnd->m_bTyping = bTyping; if (bTyping){ userWnd->setStatus(g_i18n("%1 is typing", contact) .arg(contact->getName())); }else{ userWnd->setStatus(""); } userWnd = m_tabBar->currentWnd(); if (userWnd && (contact->id() == userWnd->id())) m_status->message(userWnd->status()); } } break; case EventContactClient: contactChanged((Contact*)(e->param())); break; case EventInit: init(); break; case EventCommandExec: cmd = (CommandDef*)(e->param()); userWnd = m_tabBar->currentWnd(); if (userWnd && ((unsigned)(cmd->param) == userWnd->id())){ if (cmd->menu_id == MenuContainerContact){ m_tabBar->raiseTab(cmd->id); return e->param(); } if (cmd->id == CmdClose){ delete userWnd; return e->param(); } if (cmd->id == CmdInfo){ CommandDef c = *cmd; c.menu_id = MenuContact; c.param = (void*)userWnd->id(); Event eExec(EventCommandExec, &c); eExec.process(); return e->param(); } } break; case EventCheckState: cmd = (CommandDef*)(e->param()); userWnd = m_tabBar->currentWnd(); if (userWnd && ((unsigned)(cmd->param) == userWnd->id()) && (cmd->menu_id == MenuContainerContact) && (cmd->id == CmdContainerContacts)){ list<UserWnd*> userWnds = m_tabBar->windows(); CommandDef *cmds = new CommandDef[userWnds.size() + 1]; memset(cmds, 0, sizeof(CommandDef) * (userWnds.size() + 1)); unsigned n = 0; for (list<UserWnd*>::iterator it = userWnds.begin(); it != userWnds.end(); ++it){ cmds[n].id = (*it)->id(); cmds[n].flags = COMMAND_DEFAULT; cmds[n].text_wrk = strdup((*it)->getName().utf8()); cmds[n].icon = (*it)->getIcon(); cmds[n].text = "_"; cmds[n].menu_id = n + 1; if (n < sizeof(accels) / sizeof(const char*)) cmds[n].accel = accels[n]; if (*it == m_tabBar->currentWnd()) cmds[n].flags |= COMMAND_CHECKED; n++; } cmd->param = cmds; cmd->flags |= COMMAND_RECURSIVE; return e->param(); } break; } return NULL; }
bool MsgEdit::sendMessage(Message *msg) { if (m_retry.msg){ delete m_retry.msg; m_retry.msg = NULL; } if (m_msg){ delete msg; Event e(EventMessageCancel, m_msg); if (e.process()) m_msg = NULL; stopSend(false); return false; } bool bClose = true; if (CorePlugin::m_plugin->getContainerMode()){ bClose = false; Command cmd; cmd->id = CmdSendClose; cmd->param = this; Event e(EventCommandWidget, cmd); QToolButton *btnClose = (QToolButton*)(e.process()); if (btnClose) bClose = btnClose->isOn(); } CorePlugin::m_plugin->setCloseSend(bClose); Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ TranslitUserData *data = (TranslitUserData*)(contact->getUserData(CorePlugin::m_plugin->translit_data_id)); if (data && data->Translit.bValue) msg->setFlags(msg->getFlags() | MESSAGE_TRANSLIT); } msg->setFlags(msg->getFlags() | m_flags); m_flags = 0; if (m_userWnd->m_list){ multiply = m_userWnd->m_list->selected; if (multiply.empty()) return false; multiply_it = multiply.begin(); msg->setContact(*multiply_it); msg->setClient(NULL); ++multiply_it; if (multiply_it != multiply.end()) 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){ string resources = c->resources(data); while (!resources.empty()){ string res = getToken(resources, ';'); getToken(res, ','); if (m_resource == QString::fromUtf8(res.c_str())){ 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; Event eCmd(EventCommandChange, cmd); eCmd.process(); m_msg = msg; return send(); }
void *NavigatePlugin::processEvent(Event *e) { #ifdef WIN32 if (e->type() == EventGetURL){ string *url = (string*)(e->param()); *url = getCurrentUrl(); return e->param(); } #endif if (e->type() == EventGoURL){ string url = (const char*)(e->param()); string proto; if (url.length() == 0) return NULL; int n = url.find(':'); if (n < 0){ proto = "http"; url = proto + "://" + url; }else{ proto = url.substr(0, n); if ((proto != "http") && (proto != "https") && (proto != "ftp") && (proto != "file") && (proto != "mailto")) return NULL; } #ifdef WIN32 bool bExec = false; if (getNewWindow()){ string key_name = proto; key_name += "\\Shell\\Open"; RegEntry rp(HKEY_CLASSES_ROOT, key_name.c_str()); string prg = rp.value("command"); string action = rp.value("ddeexec"); string topic = rp.value("ddeexec\\Topic"); string server = rp.value("ddeexec\\Application"); if (!action.empty()){ int pos = action.find("%1"); if (pos >= 0) action = action.substr(0, pos) + url + action.substr(pos + 2); pos = prg.find("%1"); if (pos >= 0) prg = prg.substr(0, pos) + url + prg.substr(pos + 2); if (!prg.empty()){ STARTUPINFOA si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); if (CreateProcessA(NULL, (char*)prg.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)){ WaitForInputIdle(pi.hProcess, INFINITE); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } DDEbase b; DDEconversation conv(server.c_str(), topic.c_str()); if (conv.Execute(action.c_str())) bExec = true; } } if (!bExec) ShellExecuteA(NULL, NULL, url.c_str(), NULL, NULL, SW_SHOWNORMAL); #else ExecParam execParam; if (proto == "mailto"){ execParam.cmd = getMailer(); url = url.substr(proto.length() + 1); }else{ execParam.cmd = getBrowser(); } execParam.arg = url.c_str(); Event eExec(EventExec, &execParam); eExec.process(); #endif return e->param(); } if (e->type() == EventEncodeText){ QString *text = (QString*)(e->param()); *text = parseUrl(*text); return e->param(); } if (e->type() == EventCheckState){ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdMail){ Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact == NULL) return NULL; QString mails = contact->getEMails(); if (mails.length() == 0) return NULL; int nMails = 0; while (mails.length()){ getToken(mails, ';'); nMails++; } cmd->popup_id = (nMails <= 1) ? 0 : MenuMail; return e->param(); } if (cmd->id == CmdMailList){ Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact == NULL) return NULL; QString mails = contact->getEMails(); if (mails.length() == 0) return NULL; int nMails = 0; while (mails.length()){ getToken(mails, ';'); nMails++; } CommandDef *cmds = new CommandDef[nMails + 1]; unsigned n = 0; mails = contact->getEMails(); while (mails.length()){ QString mail = getToken(mails, ';', false); mail = getToken(mail, '/'); cmds[n] = *cmd; cmds[n].id = CmdMailList + n; cmds[n].flags = COMMAND_DEFAULT; cmds[n].text_wrk = strdup(mail.utf8()); n++; } memset(&cmds[n], 0, sizeof(CommandDef)); cmd->param = cmds; cmd->flags |= COMMAND_RECURSIVE; return e->param(); } } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdMail){ QString mail; Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact) mail = contact->getEMails(); mail = getToken(mail, ';', false); mail = getToken(mail, '/'); if (mail.length()){ string addr = "mailto:"; addr += mail.local8Bit(); Event eMail(EventGoURL, (void*)addr.c_str()); eMail.process(); } return e->param(); } if (cmd->menu_id == MenuMail){ unsigned n = cmd->id - CmdMailList; QString mails; Contact *contact = getContacts()->contact((unsigned long)(cmd->param)); if (contact) mails = contact->getEMails(); while (mails.length()){ QString mail = getToken(mails, ';', false); if (n-- == 0){ mail = getToken(mail, '/'); if (mail.length()){ string addr = "mailto:"; addr += mail.local8Bit(); Event eMail(EventGoURL, (void*)addr.c_str()); eMail.process(); } break; } } return e->param(); } } return NULL; }
bool MsgEdit::send() { unsigned i; Contact *contact = getContacts()->contact(m_msg->contact()); string client_str = m_msg->client(); bool bSent = false; void *data = NULL; if (contact){ Event e(EventMessageSend, m_msg); e.process(); if (client_str.empty()){ m_type = m_msg->type(); Client *c = client(data, true, false, m_msg->contact(), (m_msg->getFlags() & MESSAGE_MULTIPLY) == 0); if (c){ m_msg->setClient(c->dataName(data).c_str()); bSent = c->send(m_msg, data); }else{ data = NULL; for (i = 0; i < getContacts()->nClients(); i++){ Client *client = getContacts()->getClient(i); if (client->send(m_msg, NULL)){ bSent = true; break; } } } }else{ ClientDataIterator it(contact->clientData); while ((data = ++it) != NULL){ if (it.client()->dataName(data) == client_str){ if (it.client()->send(m_msg, data)) bSent = true; break; } } } } if (bSent){ if (data){ time_t now; time(&now); ((clientData*)data)->LastSend.value = now; } }else{ if (m_msg){ delete m_msg; m_msg = NULL; } stopSend(); CToolButton *btnSend = NULL; Command cmd; cmd->id = CmdSend; cmd->param = this; Event e(EventCommandWidget, cmd); btnSend = (CToolButton*)(e.process()); QWidget *msgWidget = btnSend; if (msgWidget == NULL) msgWidget = this; BalloonMsg::message(i18n("No such client for send message"), msgWidget); return false; } return true; }
void MainInfo::fill() { Contact *contact = m_contact; if (contact == NULL) contact = getContacts()->owner(); QString firstName = contact->getFirstName(); firstName = getToken(firstName, '/'); edtFirstName->setText(firstName); QString lastName = contact->getLastName(); lastName = getToken(lastName, '/'); edtLastName->setText(lastName); cmbDisplay->clear(); QString name = contact->getName(); if (name.length()) cmbDisplay->insertItem(name); if (firstName.length() && lastName.length()){ cmbDisplay->insertItem(firstName + " " + lastName); cmbDisplay->insertItem(lastName + " " + firstName); } if (firstName.length()) cmbDisplay->insertItem(firstName); if (lastName.length()) cmbDisplay->insertItem(lastName); cmbDisplay->lineEdit()->setText(contact->getName()); edtNotes->setText(contact->getNotes()); QString mails = contact->getEMails(); lstMails->clear(); while (mails.length()){ QString mailItem = getToken(mails, ';', false); QString mail = getToken(mailItem, '/'); QListViewItem *item = new QListViewItem(lstMails); item->setText(MAIL_ADDRESS, mail); item->setText(MAIL_PROTO, mailItem); item->setPixmap(MAIL_ADDRESS, Pict("mail_generic")); if ((m_contact == NULL) && mailItem.isEmpty()) item->setText(MAIL_PUBLISH, i18n("Yes")); } mailSelectionChanged(); QString phones = contact->getPhones(); lstPhones->clear(); unsigned n = 1; cmbCurrent->clear(); cmbCurrent->insertItem(""); while (phones.length()){ QString number; QString type; unsigned icon = 0; QString proto; QString phone = getToken(phones, ';', false); QString phoneItem = getToken(phone, '/', false); proto = phone; number = getToken(phoneItem, ','); type = getToken(phoneItem, ','); if (!phoneItem.isEmpty()) icon = atol(getToken(phoneItem, ',').latin1()); QListViewItem *item = new QListViewItem(lstPhones); fillPhoneItem(item, number, type, icon, proto); cmbCurrent->insertItem(number); if (!phoneItem.isEmpty()){ item->setText(PHONE_ACTIVE, "1"); cmbCurrent->setCurrentItem(n); } n++; } connect(lstPhones, SIGNAL(selectionChanged()), this, SLOT(phoneSelectionChanged())); phoneSelectionChanged(); }
bool MsgEdit::setMessage(Message *msg, bool bSetFocus) { m_type = msg->type(); unsigned type = m_type; m_bReceived = msg->getFlags() & MESSAGE_RECEIVED; QObject *processor = NULL; MsgReceived *rcv = NULL; if (m_bReceived){ if ((msg->getFlags() & MESSAGE_OPEN) || (CorePlugin::m_plugin->getContainerMode() == 0)){ rcv = new MsgReceived(this, msg, true); processor = rcv; }else{ if (m_recvProcessor == NULL){ rcv = new MsgReceived(this, msg, false); m_recvProcessor = rcv; } } }else{ QObject *(*create)(MsgEdit *custom, Message *msg) = NULL; for (;;){ CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(type); if (cmd == NULL) return false; MessageDef *def = (MessageDef*)(cmd->param); if (def == NULL) return false; create = def->generate; if (create) break; if (def->base_type == 0) return false; type = def->base_type; } if (create){ m_userWnd->setStatus(""); processor = create(this, msg); } } if (processor){ if (m_recvProcessor){ delete m_recvProcessor; m_recvProcessor = NULL; } if (m_processor){ delete m_processor; m_processor = NULL; } m_processor = processor; } if (msg->client()){ m_client = msg->client(); }else{ m_client = ""; } Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ Event e(EventContactClient, contact); e.process(); } m_bar->checkState(); if (rcv) rcv->init(); Command cmd; cmd->id = CmdMultiply; cmd->flags = COMMAND_DEFAULT; cmd->param = this; if (msg->getFlags() & MESSAGE_FORWARD){ cmd->flags = COMMAND_CHECKED; m_userWnd->showListView(true); } Event eChange(EventCommandChecked, cmd); eChange.process(); if (m_processor && bSetFocus) QTimer::singleShot(0, m_processor, SLOT(init())); return true; }
void *Container::processEvent(Event *e) { UserWnd *userWnd; Contact *contact; CommandDef *cmd; Message *msg; switch (e->type()){ case EventMessageReceived: msg = (Message*)(e->param()); if (msg->type() == MessageStatus){ contact = getContacts()->contact(msg->contact()); if (contact) contactChanged(contact); return NULL; } if (CorePlugin::m_plugin->getContainerMode()){ if (isActiveWindow()){ userWnd = m_tabBar->currentWnd(); if (userWnd && (userWnd->id() == msg->contact())) userWnd->markAsRead(); } #ifdef WIN32 if (!isActiveWindow()){ msg = (Message*)(e->param()); userWnd = wnd(msg->contact()); if (userWnd){ if (!initFlash){ HINSTANCE hLib = GetModuleHandleA("user32"); if (hLib != NULL) (DWORD&)FlashWindowEx = (DWORD)GetProcAddress(hLib,"FlashWindowEx"); initFlash = true; } if (FlashWindowEx){ FLASHWINFO fInfo; fInfo.cbSize = sizeof(fInfo); fInfo.dwFlags = 0x0E; fInfo.hwnd = winId(); fInfo.uCount = 0; FlashWindowEx(&fInfo); } } } #endif } case EventMessageRead: msg = (Message*)(e->param()); userWnd = wnd(msg->contact()); if (userWnd){ bool bBold = false; for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ if ((*it).contact != msg->contact()) continue; bBold = true; break; } m_tabBar->setBold(msg->contact(), bBold); } break; case EventActiveContact: if (!isActiveWindow()) return NULL; userWnd = m_tabBar->currentWnd(); if (userWnd) return (void*)(userWnd->id()); break; case EventContactDeleted: contact = (Contact*)(e->param()); userWnd = wnd(contact->id()); if (userWnd) removeUserWnd(userWnd); break; case EventContactChanged: contact = (Contact*)(e->param()); userWnd = wnd(contact->id()); if (userWnd){ if (contact->getIgnore()){ removeUserWnd(userWnd); break; } m_tabBar->changeTab(contact->id()); contactChanged(contact); } case EventClientsChanged: setupAccel(); break; case EventContactStatus: contact = (Contact*)(e->param()); userWnd = m_tabBar->wnd(contact->id()); if (userWnd){ unsigned style = 0; string wrkIcons; const char *statusIcon = NULL; contact->contactInfo(style, statusIcon, &wrkIcons); bool bTyping = false; while (!wrkIcons.empty()){ if (getToken(wrkIcons, ',') == "typing"){ bTyping = true; break; } } if (userWnd->m_bTyping != bTyping){ userWnd->m_bTyping = bTyping; if (bTyping){ userWnd->setStatus(i18n("Contact typed message")); }else{ userWnd->setStatus(""); } userWnd = m_tabBar->currentWnd(); if (userWnd && (contact->id() == userWnd->id())) m_status->message(userWnd->status()); } } break; case EventContactClient: contactChanged((Contact*)(e->param())); break; case EventInit: init(); break; case EventCommandExec: cmd = (CommandDef*)(e->param()); userWnd = m_tabBar->currentWnd(); if (userWnd && ((unsigned)(cmd->param) == userWnd->id())){ if (cmd->menu_id == MenuContainerContact){ m_tabBar->raiseTab(cmd->id); return e->param(); } if (cmd->id == CmdClose){ delete userWnd; return e->param(); } if (cmd->id == CmdInfo){ CommandDef c = *cmd; c.menu_id = MenuContact; c.param = (void*)userWnd->id(); Event eExec(EventCommandExec, &c); eExec.process(); return e->param(); } } break; case EventCheckState: cmd = (CommandDef*)(e->param()); userWnd = m_tabBar->currentWnd(); if (userWnd && ((unsigned)(cmd->param) == userWnd->id()) && (cmd->menu_id == MenuContainerContact) && (cmd->id == CmdContainerContacts)){ list<UserWnd*> userWnds = m_tabBar->windows(); CommandDef *cmds = new CommandDef[userWnds.size() + 1]; memset(cmds, 0, sizeof(CommandDef) * (userWnds.size() + 1)); unsigned n = 0; for (list<UserWnd*>::iterator it = userWnds.begin(); it != userWnds.end(); ++it){ cmds[n].id = (*it)->id(); cmds[n].flags = COMMAND_DEFAULT; cmds[n].text_wrk = strdup((*it)->getName().utf8()); cmds[n].icon = (*it)->getIcon(); cmds[n].text = "_"; cmds[n].menu_id = n + 1; if (n < sizeof(accels) / sizeof(const char*)) cmds[n].accel = accels[n]; if (*it == m_tabBar->currentWnd()) cmds[n].flags |= COMMAND_CHECKED; n++; } cmd->param = cmds; cmd->flags |= COMMAND_RECURSIVE; return e->param(); } break; } return NULL; }
MSNPlugin::~MSNPlugin() { getContacts()->removePacketType(MSNPacket); delete m_protocol; }
void HistoryConfig::fillPreview() { m_bDirty = false; int cur = cmbStyle->currentItem(); if (cur < 0) return; XSL *xsl = new XSL(m_styles[cur].name); if (!m_styles[cur].text.isEmpty()) xsl->setXSL(m_styles[cur].text); Contact *contact = getContacts()->contact(0, true); contact->setName("Buddy"); contact->setTemporary(true); edtPreview->clear(); edtPreview->setXSL(xsl); time_t now; time(&now); bool saveSmiles = CorePlugin::m_plugin->getUseSmiles(); bool saveOwn = CorePlugin::m_plugin->getOwnColors(); CorePlugin::m_plugin->setUseSmiles(chkSmile->isChecked()); CorePlugin::m_plugin->setOwnColors(chkOwn->isChecked()); Message m1; m1.setId((unsigned)(-1)); m1.setFlags(MESSAGE_RECEIVED | MESSAGE_LIST); m1.setText(i18n("Hi! ;)")); m1.setTime(now - 360); m1.setContact(contact->id()); edtPreview->addMessage(&m1); Message m2; m2.setId((unsigned)(-2)); m2.setText(i18n("Hi!")); m2.setTime(now - 300); m2.setContact(contact->id()); edtPreview->addMessage(&m2); Message m3; m3.setId((unsigned)(-3)); m3.setText(i18n("<b><font color=\"#FF0000\">C</font><font color=\"#FFFF00\">olored</font></b> message")); m3.setTime(now - 120); m3.setFlags(MESSAGE_SECURE | MESSAGE_URGENT | MESSAGE_RICHTEXT); m3.setBackground(0xC0C0C0); m3.setForeground(0x008000); m3.setContact(contact->id()); edtPreview->addMessage(&m3); Message m4; m4.setId((unsigned)(-4)); m4.setText(i18n("New message")); m4.setFlags(MESSAGE_RECEIVED); m4.setTime(now - 60); m4.setContact(contact->id()); edtPreview->addMessage(&m4, true); StatusMessage m5; m5.setId((unsigned)(-5)); m5.setStatus(STATUS_OFFLINE); m5.setTime(now); m5.setContact(contact->id()); if (getContacts()->nClients()) m5.setClient((getContacts()->getClient(0)->name() + ".").c_str()); edtPreview->addMessage(&m5); delete contact; CorePlugin::m_plugin->setUseSmiles(saveSmiles); CorePlugin::m_plugin->setOwnColors(saveOwn); }
QString MsgViewBase::messageText(Message *msg) { QString color; unsigned long c_sender = 0x800000; unsigned long c_receiver = 0x000080; unsigned long c_send = 0x000000; unsigned long c_receive = 0x000000; if (CorePlugin::m_plugin->getOwnColors()) { c_send = (CorePlugin::m_plugin->getColorSend()) & 0xFFFFFF; c_receive = (CorePlugin::m_plugin->getColorReceive()) & 0xFFFFFF; c_sender = (CorePlugin::m_plugin->getColorSender()) & 0xFFFFFF; c_receiver = (CorePlugin::m_plugin->getColorReceiver())& 0xFFFFFF; } color.sprintf(FONT_FORMAT, ((msg->getFlags() & MESSAGE_RECEIVED) ? c_receiver : c_sender)); const char *icon = "message"; const CommandDef *def = CorePlugin::m_plugin->messageTypes.find(msg->type()); if (def) icon = def->icon; QString contactName; Client *client = NULL; Contact *contact = getContacts()->contact(msg->contact()); if (contact){ ClientDataIterator it(contact->clientData); void *data; while ((data = ++it) != NULL){ if (it.client()->dataName(data) == msg->client()){ client = it.client(); break; } } } if (msg->type() == MessageStatus){ icon = "empty"; StatusMessage *sm = static_cast<StatusMessage*>(msg); if (client == NULL) client = getContacts()->getClient(0); if (client){ for (def = client->protocol()->statusList(); def->text; def++){ if (def->id == sm->getStatus()){ icon = def->icon; break; } } } } bool bUnread = false; if (msg->getFlags() & MESSAGE_RECEIVED){ if (contact) contactName = contact->getName(); for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ msg_id &m = (*it); if ((m.id == msg->id()) && (m.contact == msg->contact()) && (m.client == msg->client())){ bUnread = true; break; } } }else{ if (client) contactName = client->ownerName(); if (contactName.isEmpty()) contactName = getContacts()->owner()->getName(); } if (contactName.isEmpty()) contactName = "???"; QString id = QString::number(msg->id()); id += ","; if (msg->getBackground() != msg->getForeground()) id += QString::number(msg->getBackground() & 0xFFFFFF); string client_str; if (msg->client()) client_str = msg->client(); if (!client_str.empty()){ id += ","; id += quoteText(client_str.c_str()); } QString icons; if (msg->getFlags() & MESSAGE_SECURE) icons += "<img src=\"icon:encrypted\">"; if (msg->getFlags() & MESSAGE_URGENT) icons += "<img src=\"icon:urgentmsg\">"; if (msg->getFlags() & MESSAGE_LIST) icons += "<img src=\"icon:listmsg\">"; QString s = QString("<p><nobr>" "<a href=\"msg://%1\"><img src=\"icon:%2\"></a>%3" " %4<font color=\"#%5\">%6</font> " "<font size=-1>%7</font>%8" "</nobr></p>") .arg(id) .arg(icon) .arg(icons) .arg(bUnread ? "<b>" : "") .arg(color) .arg(quoteString(contactName)) .arg(formatTime(msg->getTime())) .arg(bUnread ? "</b>" : ""); if (msg->type() != MessageStatus){ QString msgText = msg->presentation(); // replace font color if we use own colors // some of the incoming messages are saved as html with an extra <font> - tag // so we need to replace until no more <font> - tag is found // this behaviour should be checked! if (CorePlugin::m_plugin->getOwnColors()) { int pos = msgText.find("font color=\"#",0); while (pos != -1) { pos += 13; QString color; color.sprintf(FONT_FORMAT, (msg->getFlags() & MESSAGE_RECEIVED) ? c_receive : c_send); msgText.replace(pos,6,color); pos = msgText.find("font color=\"#",pos); } } if (msgText.isEmpty()){ unsigned type = msg->type(); for (;;){ CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(type); if (cmd == NULL) break; MessageDef *def = (MessageDef*)(cmd->param); if (def->base_type){ type = def->base_type; continue; } msgText += "<p>"; msgText += i18n(def->singular, def->plural, 1); msgText += "</p>"; break; } QString text = msg->getRichText(); if (!text.isEmpty()){ msgText += "<p>"; msgText += text; msgText += "</p>"; } } Event e(EventEncodeText, &msgText); e.process(); s += parseText(msgText, false, CorePlugin::m_plugin->getUseSmiles()); } return s; }
FetchManager::FetchManager() { getContacts()->addPacketType(HTTPPacket, _HTTP, PACKET_TEXT); m_id = 0; }
void *SearchDialog::processEvent(Event *e) { switch (e->type()){ case EventClientsChanged: case EventClientChanged: fillClients(); break; case EventCommandExec:{ if (m_result != m_currentResult) return NULL; CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->menu_id == MenuSearchGroups){ Group *grp = getContacts()->group(cmd->id - CmdContactGroup); if (grp){ Contact *contact = NULL; if ((QWidget*)(cmd->param) == m_search->btnSearch){ if (m_current){ connect(this, SIGNAL(createContact(unsigned,Contact*&)), m_current, SLOT(createContact(unsigned,Contact*&))); emit createContact(CONTACT_TEMP, contact); disconnect(this, SIGNAL(createContact(unsigned,Contact*&)), m_current, SLOT(createContact(unsigned,Contact*&))); } }else{ contact = createContact(CONTACT_TEMP); } if (contact){ if ((contact->getFlags() & CONTACT_TEMP) == 0){ QString err = i18n("%1 already in contact list") .arg(contact->getName()); if ((QWidget*)(cmd->param) == m_search->btnAdd){ BalloonMsg::message(err, m_search->btnAdd); }else if ((QWidget*)(cmd->param) == m_search->btnSearch){ BalloonMsg::message(err, m_search->btnSearch); }else{ QRect rc = m_result->itemRect((QListViewItem*)(e->param())); QPoint p = m_result->viewport()->mapToGlobal(QPoint(rc.left(), rc.top())); rc = QRect(p.x(), p.y(), rc.width(), rc.height()); BalloonMsg::message(err, m_result, false, 150, &rc); } return e->param(); } contact->setFlags(contact->getFlags() & ~CONTACT_TEMP); contact->setGroup(grp->id()); Event e(EventContactChanged, contact); e.process(); } } return e->param(); } if (cmd->id == CmdSearchInfo){ Contact *contact = createContact(CONTACT_TEMP); if (contact == NULL) return e->param(); Command cmd; cmd->id = CmdInfo; cmd->menu_id = MenuContact; cmd->param = (void*)(contact->id()); CorePlugin::m_plugin->showInfo(cmd); return e->param(); } if (cmd->id == CmdSearchMsg){ Contact *contact = createContact(CONTACT_TEMP); if (contact == NULL) return e->param(); Message *m = new Message(MessageGeneric); m->setContact(contact->id()); Event e(EventOpenMessage, &m); e.process(); delete m; } break; }
FetchManager::~FetchManager() { for (list<FetchClient*>::iterator it = m_clients.begin(); it != m_clients.end(); it = m_clients.begin()) delete *it; getContacts()->removePacketType(HTTPPacket); }
ForwardPlugin::~ForwardPlugin() { Event e(EventRemovePreferences, (void*)user_data_id); e.process(); getContacts()->unregisterUserData(user_data_id); }
JabberPlugin::JabberPlugin(unsigned base) : Plugin(base) { #ifdef WIN32 qInitJpeg(); #endif JabberPacket = registerType(); getContacts()->addPacketType(JabberPacket, jabber_descr.text, true); EventAgentFound = registerType(); EventAgentInfo = registerType(); EventAgentRegister = registerType(); EventSearch = registerType(); EventSearchDone = registerType(); MenuSearchResult = registerType(); MenuGroups = registerType(); CmdSendMessage = registerType(); CmdGroups = registerType(); CmdBrowser = registerType(); BarBrowser = registerType(); CmdBack = registerType(); CmdForward = registerType(); CmdUrl = registerType(); EventDiscoItem = registerType(); CmdInfo = registerType(); CmdRegister = registerType(); CmdSearch = registerType(); IconDef icon; icon.name = "Jabber_online"; icon.xpm = jabber_online; icon.isSystem = false; Event eIcon(EventAddIcon, &icon); eIcon.process(); icon.name = "Jabber_offline"; icon.xpm = jabber_offline; eIcon.process(); icon.name = "Jabber_away"; icon.xpm = jabber_away; eIcon.process(); icon.name = "Jabber_na"; icon.xpm = jabber_na; eIcon.process(); icon.name = "Jabber_dnd"; icon.xpm = jabber_dnd; eIcon.process(); icon.name = "Jabber_ffc"; icon.xpm = jabber_ffc; eIcon.process(); icon.name = "Jabber_invisible"; icon.xpm = jabber_invisible; eIcon.process(); icon.name = "ICQ_offline"; icon.xpm = icq_offline; eIcon.process(); icon.name = "ICQ_online"; icon.xpm = icq_online; eIcon.process(); icon.name = "ICQ_away"; icon.xpm = icq_away; eIcon.process(); icon.name = "ICQ_na"; icon.xpm = icq_na; eIcon.process(); icon.name = "ICQ_dnd"; icon.xpm = icq_dnd; eIcon.process(); icon.name = "ICQ_ffc"; icon.xpm = icq_ffc; eIcon.process(); icon.name = "ICQ_invisible"; icon.xpm = icq_invisible; eIcon.process(); icon.name = "MSN_offline"; icon.xpm = msn_offline; eIcon.process(); icon.name = "MSN_online"; icon.xpm = msn_online; eIcon.process(); icon.name = "MSN_away"; icon.xpm = msn_away; eIcon.process(); icon.name = "MSN_na"; icon.xpm = msn_na; eIcon.process(); icon.name = "MSN_dnd"; icon.xpm = msn_dnd; eIcon.process(); icon.name = "MSN_invisible"; icon.xpm = msn_invisible; eIcon.process(); icon.name = "AIM_offline"; icon.xpm = aim_offline; eIcon.process(); icon.name = "AIM_online"; icon.xpm = aim_online; eIcon.process(); icon.name = "AIM_away"; icon.xpm = aim_away; eIcon.process(); icon.name = "Yahoo_offline"; icon.xpm = yahoo_offline; eIcon.process(); icon.name = "Yahoo_away"; icon.xpm = yahoo_away; eIcon.process(); icon.name = "Yahoo_na"; icon.xpm = yahoo_na; eIcon.process(); icon.name = "Yahoo_dnd"; icon.xpm = yahoo_dnd; eIcon.process(); icon.name = "Yahoo_ffc"; icon.xpm = yahoo_ffc; eIcon.process(); icon.name = "reg"; icon.xpm = reg; eIcon.process(); Event eMenuSearch(EventMenuCreate, (void*)MenuSearchResult); eMenuSearch.process(); Event eMenuGroups(EventMenuCreate, (void*)MenuGroups); eMenuGroups.process(); Event eToolbar(EventToolbarCreate, (void*)BarBrowser); eToolbar.process(); Command cmd; cmd->id = CmdSendMessage; cmd->text = I18N_NOOP("&Message"); cmd->icon = "message"; cmd->menu_id = MenuSearchResult; cmd->menu_grp = 0x1000; cmd->flags = COMMAND_DEFAULT; Event eCmd(EventCommandCreate, cmd); eCmd.process(); cmd->id = CmdInfo; cmd->text = I18N_NOOP("User &info"); cmd->icon = "info"; cmd->menu_grp = 0x1001; eCmd.process(); cmd->id = CmdGroups; cmd->text = I18N_NOOP("&Add to group"); cmd->icon = NULL; cmd->menu_grp = 0x1002; cmd->popup_id = MenuGroups; eCmd.process(); cmd->id = CmdGroups; cmd->text = "_"; cmd->menu_id = MenuGroups; cmd->flags = COMMAND_CHECK_STATE; eCmd.process(); cmd->id = CmdBrowser; cmd->text = I18N_NOOP("Jabber browser"); cmd->icon = "Jabber_online"; cmd->menu_grp = 0x20F0; cmd->menu_id = MenuMain; cmd->popup_id = NULL; cmd->flags = COMMAND_CHECK_STATE; eCmd.process(); cmd->id = CmdBrowser; cmd->text = I18N_NOOP("Jabber browser"); cmd->icon = "Jabber_online"; cmd->menu_grp = 0x20F0; cmd->menu_id = MenuContact; cmd->popup_id = NULL; cmd->flags = COMMAND_CHECK_STATE; eCmd.process(); cmd->id = CmdBack; cmd->text = I18N_NOOP("&Back"); cmd->icon = "1leftarrow"; cmd->bar_grp = 0x1000; cmd->bar_id = BarBrowser; cmd->menu_id = 0; cmd->flags = COMMAND_CHECK_STATE; eCmd.process(); cmd->id = CmdForward; cmd->text = I18N_NOOP("&Next"); cmd->icon = "1rightarrow"; cmd->bar_grp = 0x1001; eCmd.process(); cmd->id = CmdUrl; cmd->text = I18N_NOOP("JID"); cmd->icon = "run"; cmd->bar_grp = 0x2000; cmd->flags = BTN_COMBO_CHECK; eCmd.process(); cmd->id = CmdSearch; cmd->text = I18N_NOOP("&Search"); cmd->icon = "find"; cmd->bar_grp = 0x3000; cmd->flags = COMMAND_CHECK_STATE; eCmd.process(); cmd->id = CmdRegister; cmd->text = I18N_NOOP("&Register"); cmd->icon = "reg"; cmd->bar_grp = 0x3001; cmd->flags = COMMAND_CHECK_STATE; eCmd.process(); cmd->id = CmdInfo; cmd->text = I18N_NOOP("Info"); cmd->icon = "info"; cmd->bar_grp = 0x3010; cmd->flags = COMMAND_CHECK_STATE; eCmd.process(); m_protocol = new JabberProtocol(this); registerMessages(); }
void *SoundPlugin::processEvent(Event *e) { if (e->type() == EventSoundChanged){ Command cmd; cmd->id = CmdSoundDisable; SoundUserData *data = (SoundUserData*)(getContacts()->getUserData(user_data_id)); if (!data->Disable.bValue) cmd->flags |= COMMAND_CHECKED; m_bChanged = true; Event e(EventCommandChecked, cmd); e.process(); m_bChanged = false; return NULL; } if (e->type() == EventCheckState){ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdSoundDisable){ cmd->flags &= ~COMMAND_CHECKED; SoundUserData *data = (SoundUserData*)(getContacts()->getUserData(user_data_id)); if (!data->Disable.bValue) cmd->flags |= COMMAND_CHECKED; return e->param(); } return NULL; } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); if (!m_bChanged && (cmd->id == CmdSoundDisable)){ SoundUserData *data = (SoundUserData*)(getContacts()->getUserData(user_data_id)); data->Disable.bValue = !data->Disable.bValue; Event eChanged(EventSoundChanged); eChanged.process(); return e->param(); } return NULL; } if (e->type() == EventContactOnline){ Contact *contact = (Contact*)(e->param()); SoundUserData *data = (SoundUserData*)(contact->getUserData(user_data_id)); if (data && data->Alert.ptr && *data->Alert.ptr && !data->Disable.bValue){ Event eSound(EventPlaySound, data->Alert.ptr); eSound.process(); } return NULL; } if (e->type() == EventMessageSent){ Message *msg = (Message*)(e->param()); const char *err = msg->getError(); if (err && *err) return NULL; const char *sound = NULL; if (msg->type() == MessageFile){ sound = getFileDone(); }else if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ if ((msg->getFlags() & MESSAGE_MULTIPLY) && ((msg->getFlags() & MESSAGE_LAST) == 0)) return NULL; sound = getMessageSent(); } if (sound && *sound){ Event eSound(EventPlaySound, (void*)sound); eSound.process(); } return NULL; } if (e->type() == EventMessageReceived){ Message *msg = (Message*)(e->param()); if (msg->type() == MessageStatus) return NULL; if (msg->getFlags() & MESSAGE_LIST) return NULL; Contact *contact = getContacts()->contact(msg->contact()); SoundUserData *data; if (contact){ data = (SoundUserData*)(contact->getUserData(user_data_id)); }else{ data = (SoundUserData*)(getContacts()->getUserData(user_data_id)); } bool bEnable = !data->Disable.bValue; if (bEnable && data->NoSoundIfActive.bValue){ Event e(EventActiveContact); if ((unsigned)(e.process()) == contact->id()) bEnable = false; } if (bEnable){ string sound = messageSound(msg->baseType(), data); if (!sound.empty()) playSound(sound.c_str()); } return NULL; } if (e->type() == EventPlaySound){ char *name = (char*)(e->param()); playSound(name); return e->param(); } return NULL; }
void *FloatyPlugin::processEvent(Event *e) { switch (e->type()){ case EventInit:{ Contact *contact; ContactList::ContactIterator it; while ((contact = ++it) != NULL){ FloatyUserData *data = (FloatyUserData*)(contact->userData.getUserData(user_data_id, false)); if ((data == NULL) || !data->Floaty) continue; FloatyWnd *wnd = new FloatyWnd(this, contact->id()); wnd->move(data->X, data->Y); wnd->show(); } break; } case EventCheckState:{ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdFloaty){ Contact *contact = getContacts()->contact((unsigned)(cmd->param)); if (contact){ FloatyUserData *data = (FloatyUserData*)(contact->userData.getUserData(user_data_id, false)); if (data && data->Floaty){ cmd->text = I18N_NOOP("Floating off"); cmd->flags |= COMMAND_CHECKED; }else{ cmd->text = I18N_NOOP("Floating on"); cmd->flags &= ~COMMAND_CHECKED; } } return e->param(); } break; } case EventCommandExec:{ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdFloaty){ Contact *contact = getContacts()->contact((unsigned)(cmd->param)); if (contact){ FloatyUserData *data = (FloatyUserData*)(contact->userData.getUserData(user_data_id, true)); if (data->Floaty){ data->Floaty = 0; data->X = 0; data->Y = 0; FloatyWnd *wnd = findFloaty(contact->id()); if (wnd) delete wnd; }else{ data->Floaty = (unsigned)(-1); FloatyWnd *wnd = new FloatyWnd(this, (unsigned)(cmd->param)); wnd->move(0, 0); wnd->show(); } } return e->param(); } break; } case EventMessageDeleted: case EventMessageRead: case EventMessageReceived:{ Message *msg = (Message*)(e->param()); FloatyWnd *wnd = findFloaty(msg->contact()); if (wnd){ wnd->init(); wnd->repaint(); } break; } case EventContactClient: case EventContactStatus: case EventContactChanged:{ Contact *contact = (Contact*)(e->param()); FloatyWnd *wnd = findFloaty(contact->id()); if (wnd){ wnd->init(); wnd->repaint(); } break; } case EventContactDeleted:{ Contact *contact = (Contact*)(e->param()); FloatyWnd *wnd = findFloaty(contact->id()); if (wnd) delete wnd; break; } case EventRepaintView:{ QWidgetList *list = QApplication::topLevelWidgets(); QWidgetListIt it(*list); QWidget * w; while ((w = it.current()) != NULL) { if (w->inherits("FloatyWnd")){ FloatyWnd *wnd = static_cast<FloatyWnd*>(w); wnd->init(); wnd->repaint(); } ++it; } delete list; break; } } return NULL; }