void RosterView::MouseDown(BPoint point) { Window()->Activate(true); uint32 buttons = 0; GetMouse(&point, &buttons); printf("buttons %i\n",buttons); if (buttons & B_SECONDARY_MOUSE_BUTTON) { RosterItem *item = CurrentItemSelection(); if (item && !item->StalePointer()) { UpdatePopUpMenu(); BPoint screen_point(point); ConvertToScreen(&screen_point); BRect r(screen_point.x - 4, screen_point.y - 20, screen_point.x + 24, screen_point.y + 4); _popup->Go(screen_point, true, true, r, false); } } BOutlineListView::MouseDown(point); }
Resource *Roster::get_resource(const QString &full_jid, bool create) { QString jid, resource; int index = full_jid.indexOf("/"); if(index == -1) { jid = full_jid; resource = "default"; } else { jid = full_jid.left(index); resource = full_jid.mid(index + 1); } //qDebug() << "jid:" << jid << "resource:" << resource; RosterItem *item = get_item(jid); if(!item) { qDebug() << "no item for jid" + jid; return 0; } Resource *n = static_cast<Resource *>(item->child(resource)); if(!n && create) { n = new Resource(resource, item); item->addChild(n); } return n; }
int32 RosterView::FindUser(UserID *compare_user) { if (compare_user == NULL) return -1; for (int i=0; i<FullListCountItems(); ++i) { RosterItem *item = dynamic_cast<RosterItem *>(FullListItemAt(i)); if (item == NULL || item->StalePointer()) continue; if (item->GetUserID() == compare_user) return i; } return -1; }
RosterItem *RosterGroup::get_item(const QString &jid) const { RosterTreeNode *c = 0; QVectorIterator<RosterTreeNode *> i(children); while(i.hasNext()) { c = i.next(); if(c->type() == RTNT_ITEM) { RosterItem *item = static_cast<RosterItem *>(c); if(item->getJID() == jid) return item; } else if(c->type() == RTNT_GROUP) { RosterItem *i = static_cast<RosterGroup *>(c)->get_item(jid); if(i) return i; } } return 0; }
void CMainFrame::handleRosterPresence( const RosterItem& item, const std::string& resource, Presence::PresenceType presence, const std::string& msg ) { if(m_pBuddyList) { CBuddyListItem* buddy= m_pBuddyList->FindBuddyItem(item.jid()); if(buddy) { bool online=buddy->IsOnline(); buddy->SetPresence(presence); buddy->SetSignature(utf8dec(msg)); if(online!=buddy->IsOnline()) { buddy->SetHeader(GetContext()->GetHeaderManager().GetHeader(item.jid(),buddy->IsOnline())); } } } }
void RosterManager::handlePresence( const Presence& presence ) { if( presence.subtype() == Presence::Error ) return; bool self = false; Roster::iterator it = m_roster.find( presence.from().bare() ); if( it != m_roster.end() || ( self = ( presence.from().bareJID() == m_self->jidJID() ) ) ) { RosterItem* ri = self ? m_self : (*it).second; const std::string& resource = presence.from().resource(); if( presence.presence() == Presence::Unavailable ) ri->removeResource( resource ); else { ri->setPresence( resource, presence.presence() ); ri->setStatus( resource, presence.status() ); ri->setPriority( resource, presence.priority() ); ri->setExtensions( resource, presence.extensions() ); } if( m_rosterListener && !self ) m_rosterListener->handleRosterPresence( *ri, resource, presence.presence(), presence.status() ); else if( m_rosterListener && self ) m_rosterListener->handleSelfPresence( *ri, resource, presence.presence(), presence.status() ); } else { if( m_rosterListener ) m_rosterListener->handleNonrosterPresence( presence ); } }
void RosterView::UpdatePopUpMenu() { RosterItem *item = CurrentItemSelection(); if (item && !item->StalePointer()) { const UserID *user = item->GetUserID(); _change_user_item->SetEnabled(true); _remove_user_item->SetEnabled(true); if (user->OnlineStatus() != UserID::CONF_STATUS) { _presence->SetEnabled(true); if (user->HaveSubscriptionTo()) { _subscribe_presence->SetEnabled(false); _unsubscribe_presence->SetEnabled(true); } else { _subscribe_presence->SetEnabled(true); _unsubscribe_presence->SetEnabled(false); } } else { _presence->SetEnabled(false); } } else { _change_user_item->SetEnabled(false); _remove_user_item->SetEnabled(false); _presence->SetEnabled(false); } }
static Roster xmlReadRoster(const QDomElement &q, bool push) { Roster r; for(QDomNode n = q.firstChild(); !n.isNull(); n = n.nextSibling()) { QDomElement i = n.toElement(); if(i.isNull()) continue; if(i.tagName() == "item") { RosterItem item; item.fromXml(i); if(push) item.setIsPush(true); r += item; } } return r; }
void Client::importRosterItem(const RosterItem &item) { QString substr; switch(item.subscription().type()) { case Subscription::Both: substr = "<-->"; break; case Subscription::From: substr = " ->"; break; case Subscription::To: substr = "<- "; break; case Subscription::Remove: substr = "xxxx"; break; case Subscription::None: default: substr = "----"; break; } QString dstr, str; str.sprintf(" %s %-32s", substr.latin1(), item.jid().full().latin1()); if(!item.name().isEmpty()) str += QString(" [") + item.name() + "]"; str += '\n'; // Remove if(item.subscription().type() == Subscription::Remove) { LiveRoster::Iterator it = d->roster.find(item.jid()); if(it != d->roster.end()) { rosterItemRemoved(*it); d->roster.remove(it); } dstr = "Client: (Removed) "; } // Add/Update else { LiveRoster::Iterator it = d->roster.find(item.jid()); if(it != d->roster.end()) { LiveRosterItem &i = *it; i.setFlagForDelete(false); i.setRosterItem(item); rosterItemUpdated(i); dstr = "Client: (Updated) "; } else { LiveRosterItem i(item); d->roster += i; // signal it rosterItemAdded(i); dstr = "Client: (Added) "; } } debug(dstr + str); }
void LiveRosterItem::setRosterItem(const RosterItem &i) { setJid(i.jid()); setName(i.name()); setGroups(i.groups()); setSubscription(i.subscription()); setAsk(i.ask()); setIsPush(i.isPush()); }
void handleRosterPresence( const RosterItem& item, const std::string& resource, Presence presence, const std::string& msg ) { jsval fval; if ( !JS_GetProperty(_cx, _obj, "onRosterPresence", &fval) || fval.isUndefined() ) return; if ( !JL_ValueIsCallable(_cx, fval) ) { JS_ReportError(_cx, "onRosterPresence is not a function."); return; } jsval fromVal, presenceVal, msgVal, tmp; JidToJsval(_cx, &JID(item.jid()), &fromVal); JL_NativeToJsval(_cx, presence, &presenceVal); JL_NativeToJsval(_cx, msg.c_str(), &msgVal); jsval argv[] = { fromVal, presenceVal, msgVal }; JS_CallFunctionValue(_cx, _obj, fval, COUNTOF(argv), argv, &tmp); // errors will be managed later by JL_IsExceptionPending(cx) }
QVariant ContactModel::data(const QModelIndex &index, int role) const { if (!index.parent().isValid()) { // Groups switch (role) { case Qt::DisplayRole: if(index.column()==0) return groups.keys().at(index.row()); } } else { // Contacts ContactGroup *group = reinterpret_cast<ContactGroup *>(index.internalPointer()); Contact contact = group->contacts.at(index.row()); MAGNORMOBOT *bot = contact.conduit.data(); switch (role) { case Qt::DisplayRole: if(index.column()==1) return bot->getNameFromJid(contact.jid); case Qt::DecorationRole: { RosterItem *item = bot->getRosterItemFromJid(contact.jid); if (!item) return QIcon(":/icons/user-offline"); if (!item->highestResource()) return QIcon(":/icons/user-offline"); switch (item->highestResource()->presence()) { case Presence::Available: case Presence::Chat: if(index.column()==1) return QIcon(":/icons/user-online"); else { return bot->getAccountIcon(); } case Presence::Away: case Presence::DND: case Presence::XA: if(index.column()==1) return QIcon(":/icons/user-away"); else { return bot->getAccountIcon(); } default: return QIcon(":/icons/user-offline"); } break; } case Qt::ToolTipRole: case ContactModel::JIDRole: return contact.jid; case ContactModel::ContactRole: return QVariant::fromValue(contact); case ContactModel::PresenceRole: { RosterItem *item = bot->getRosterItemFromJid(contact.jid); if (!item) return Presence::Unavailable; if (!item->highestResource()) return Presence::Unavailable; return item->highestResource()->presence(); } } } return QVariant(); }
void Core::handleRosterPresence(const RosterItem &item, const std::string &resource, Presence::PresenceType presence, const std::string &msg){ write_string("You have received a status update of: " + item.jid() + " (" + msg + ")"); // some bugs with item.jid(), check caracters issues update_roster_choice(); }
const UserID *RosterView::GetConference(int i) { RosterItem *item = (RosterItem*)ItemUnderAt(_conferences, true, i); if (item) return item->GetUserID(); else return NULL; }
virtual void handleRosterPresence( const RosterItem& item, const std::string& resource, Presence presence, const std::string& /*msg*/ ) { printf( "presence received: %s/%s -- %d\n", item.jid().c_str(), resource.c_str(), presence ); }
virtual void itemUnavailable( const RosterItem& item, const std::string& /*msg*/ ) { printf( "item offline: %s\n", item.jid().c_str() ); };
virtual void presenceUpdated( const RosterItem& item, int /*status*/, const std::string& /*msg*/ ) { printf( "item changed: %s\n", item.jid().c_str() ); }
void UserAccount::fromOptions(OptionsTree *o, QString base) { // WARNING: If you add any new option here, only read the option if // allSetOptions (defined below) contains the new option. If not // the code should just leave the default value from the reset() // call in place. optionsBase = base; reset(); QStringList allSetOptions = o->getChildOptionNames(base, true, true); opt_enabled = o->getOption(base + ".enabled").toBool(); opt_auto = o->getOption(base + ".auto").toBool(); opt_keepAlive = o->getOption(base + ".keep-alive").toBool(); opt_compress = o->getOption(base + ".compress").toBool(); req_mutual_auth = o->getOption(base + ".require-mutual-auth").toBool(); legacy_ssl_probe = o->getOption(base + ".legacy-ssl-probe").toBool(); opt_automatic_resource = o->getOption(base + ".automatic-resource").toBool(); opt_log = o->getOption(base + ".log").toBool(); opt_reconn = o->getOption(base + ".reconn").toBool(); opt_ignoreSSLWarnings = o->getOption(base + ".ignore-SSL-warnings").toBool(); // FIX-ME: See FS#771 if (o->getChildOptionNames().contains(base + ".connect-after-sleep")) { opt_connectAfterSleep = o->getOption(base + ".connect-after-sleep").toBool(); } else { o->setOption(base + ".connect-after-sleep", opt_connectAfterSleep); } name = o->getOption(base + ".name").toString(); jid = o->getOption(base + ".jid").toString(); customAuth = o->getOption(base + ".custom-auth.use").toBool(); authid = o->getOption(base + ".custom-auth.authid").toString(); realm = o->getOption(base + ".custom-auth.realm").toString(); // read password (we must do this after reading the jid, to decode properly) QString tmp = o->getOption(base + ".password").toString(); if(!tmp.isEmpty()) { opt_pass = true; pass = decodePassword(tmp, jid); } opt_host = o->getOption(base + ".use-host").toBool(); security_level = o->getOption(base + ".security-level").toInt(); tmp = o->getOption(base + ".ssl").toString(); if (tmp == "no") { ssl = SSL_No; } else if (tmp == "yes") { ssl = SSL_Yes; } else if (tmp == "auto") { ssl = SSL_Auto; } else if (tmp == "legacy") { ssl = SSL_Legacy; } else { ssl = SSL_Yes; } host = o->getOption(base + ".host").toString(); port = o->getOption(base + ".port").toInt(); resource = o->getOption(base + ".resource").toString(); priority = o->getOption(base + ".priority").toInt(); QString pgpSecretKeyID = o->getOption(base + ".pgp-secret-key-id").toString(); if (!pgpSecretKeyID.isEmpty()) { QCA::KeyStoreEntry e = PGPUtil::instance().getSecretKeyStoreEntry(pgpSecretKeyID); if (!e.isNull()) pgpSecretKey = e.pgpSecretKey(); } tmp = o->getOption(base + ".allow-plain").toString(); if (tmp == "never") { allow_plain = XMPP::ClientStream::NoAllowPlain; } else if (tmp == "always") { allow_plain = XMPP::ClientStream::AllowPlain; } else if (tmp == "over encryped") { allow_plain = XMPP::ClientStream::AllowPlainOverTLS; } else { allow_plain = XMPP::ClientStream::NoAllowPlain; } QStringList rosterCache = o->getChildOptionNames(base + ".roster-cache", true, true); foreach(QString rbase, rosterCache) { RosterItem ri; ri.setJid(Jid(o->getOption(rbase + ".jid").toString())); ri.setName(o->getOption(rbase + ".name").toString()); Subscription s; s.fromString(o->getOption(rbase + ".subscription").toString()); ri.setSubscription(s); ri.setAsk(o->getOption(rbase + ".ask").toString()); ri.setGroups(o->getOption(rbase + ".groups").toStringList()); roster += ri; }
void MainWindow::MessageReceived(BMessage* message) { switch (message->what) { case kSearchContact: { void* control = NULL; if (message->FindPointer("source", &control) != B_OK) return; SearchBarTextControl* searchBox = static_cast<SearchBarTextControl*>(control); if (searchBox == NULL) return; RosterMap map = fServer->RosterItems(); for (uint32 i = 0; i < map.CountItems(); i++) { ContactLinker* linker = map.ValueAt(i); RosterItem* item = linker->GetRosterItem(); // If the search filter has been deleted show all the items, // otherwise remove the item in order to show only items // that matches the search criteria if (strcmp(searchBox->Text(), "") == 0) AddItem(item); else if (linker->GetName().IFindFirst(searchBox->Text()) == B_ERROR) RemoveItem(item); else AddItem(item); UpdateListItem(item); } break; } case CAYA_SHOW_SETTINGS: { PreferencesDialog* dialog = new PreferencesDialog(); dialog->Show(); break; } case CAYA_OPEN_CHAT_WINDOW: { int index = message->FindInt32("index"); RosterItem* ritem = ItemAt(index); if (ritem != NULL) ritem->GetContactLinker()->ShowWindow(false, true); break; } case CAYA_REPLICANT_STATUS_SET: { int32 status; message->FindInt32("status", &status); AccountManager* accountManager = AccountManager::Get(); accountManager->SetStatus((CayaStatus)status); break; } case CAYA_REPLICANT_SHOW_WINDOW: { if (LockLooper()) { SetWorkspaces(B_CURRENT_WORKSPACE); if ((IsMinimized() || IsHidden()) || fWorkspaceChanged) { Minimize(false); Show(); fWorkspaceChanged = false; } else if ((!IsMinimized() || !IsHidden()) || (!fWorkspaceChanged)) { Minimize(true); } UnlockLooper(); } break; } case IM_MESSAGE: ImMessage(message); break; case IM_ERROR: ImError(message); break; case B_ABOUT_REQUESTED: be_app->PostMessage(message); break; default: BWindow::MessageReceived(message); } }
virtual void handleSelfPresence( const RosterItem& item, const std::string& resource, Presence::PresenceType presence, const std::string& /*msg*/ ) { printf( "self presence received: %s/%s -- %d\n", item.jidJID().full().c_str(), resource.c_str(), presence ); }
void MainWindow::ImMessage(BMessage* msg) { int32 im_what = msg->FindInt32("im_what"); switch (im_what) { case IM_OWN_CONTACT_INFO: fStatusView->SetName(msg->FindString("name")); break; case IM_OWN_AVATAR_SET: { entry_ref ref; if (msg->FindRef("ref", &ref) == B_OK) { BBitmap* bitmap = BTranslationUtils::GetBitmap(&ref); fStatusView->SetAvatarIcon(bitmap); } break; } case IM_STATUS_SET: { int32 status; if (msg->FindInt32("status", &status) != B_OK) return; RosterItem* rosterItem = fServer->RosterItemForId(msg->FindString("id")); if (rosterItem) { UpdateListItem(rosterItem); // Add or remove item switch (status) { /*case CAYA_OFFLINE: // By default offline contacts are hidden if (!CayaPreferences::Item()->HideOffline) break; if (HasItem(rosterItem)) RemoveItem(rosterItem); return;*/ default: // Add item because it has a non-offline status if (!HasItem(rosterItem)) AddItem(rosterItem); break; } UpdateListItem(rosterItem); // Sort list view again fListView->Sort(); // Check if the user want the notification if (!CayaPreferences::Item()->NotifyContactStatus) break; switch (status) { case CAYA_ONLINE: case CAYA_OFFLINE: // Notify when contact is online or offline if (status == CAYA_ONLINE) { BString message; message << rosterItem->GetContactLinker()->GetName(); if (status == CAYA_ONLINE) message << " is available!"; else message << " is offline!"; BNotification notification(B_INFORMATION_NOTIFICATION); notification.SetGroup(BString("Caya")); notification.SetTitle(BString("Presence")); notification.SetIcon(rosterItem->Bitmap()); notification.SetContent(message); notification.Send(); } break; default: break; } } break; } case IM_AVATAR_SET: case IM_CONTACT_INFO: case IM_EXTENDED_CONTACT_INFO: { RosterItem* rosterItem = fServer->RosterItemForId(msg->FindString("id")); if (rosterItem) UpdateListItem(rosterItem); break; } } }