Example #1
0
void ChatWindowMenu::onArchiveRequestCompleted(const QString &AId)
{
	if (FSessionRequest == AId)
	{
		if (FSessionNegotiation)
		{
			IArchiveItemPrefs iprefs = FArchiver->archiveItemPrefs(streamJid(),contactJid());
			IStanzaSession session = FSessionNegotiation->findSession(streamJid(),contactJid());
			if (session.status == IStanzaSession::Active)
			{
				bool isOTRSession = isOTRStanzaSession(session);
				if (!isOTRSession && iprefs.otr==ARCHIVE_OTR_REQUIRE)
					FSessionNegotiation->initSession(streamJid(),contactJid());
				else if (!isOTRSession && iprefs.otr!=ARCHIVE_OTR_REQUIRE)
					FSessionNegotiation->initSession(streamJid(),contactJid());
			}
			else if (iprefs.otr == ARCHIVE_OTR_REQUIRE)
			{
				FSessionNegotiation->initSession(streamJid(),contactJid());
			}
		}
		FSessionRequest.clear();
		updateMenu();
	}
	else if (FSaveRequest == AId)
	{
		FSaveRequest.clear();
		updateMenu();
	}
}
Example #2
0
bool Roster::stanzaReadWrite(int AHandlerId, const Jid &AStreamJid, Stanza &AStanza, bool &AAccept)
{
	if (AHandlerId == FSHIRosterPush)
	{
		if (isOpen() && AStanza.isFromServer())
		{
			AAccept = true;
			LOG_STRM_DEBUG(streamJid(),"Roster items push received");
			processItemsElement(AStanza.firstElement("query",NS_JABBER_ROSTER),false);

			Stanza result = FStanzaProcessor->makeReplyResult(AStanza);
			FStanzaProcessor->sendStanzaOut(AStreamJid,result);
		}
		else if (!isOpen())
		{
			REPORT_ERROR("Failed to process roster items push: Roster is closed");
		}
		else if (!AStanza.isFromServer())
		{
			REPORT_ERROR("Failed to process roster items push: Invalid stanza sender");
		}
	}
	else if (AHandlerId == FSHISubscription)
	{
		Jid contactJid = AStanza.from();
		QString status = AStanza.firstElement("status").text();
		if (AStanza.type() == SUBSCRIPTION_SUBSCRIBE)
		{
			AAccept = true;
			FSubscriptionRequests += contactJid.bare();
			LOG_STRM_INFO(streamJid(),QString("Subscribe presence received from=%1, status=%2").arg(contactJid.full(),status));
			emit subscriptionReceived(AStanza.from(),IRoster::Subscribe,status);
		}
		else if (AStanza.type() == SUBSCRIPTION_SUBSCRIBED)
		{
			AAccept = true;
			LOG_STRM_INFO(streamJid(),QString("Subscribed presence received from=%1, status=%2").arg(contactJid.full(),status));
			emit subscriptionReceived(AStanza.from(),IRoster::Subscribed,status);
		}
		else if (AStanza.type() == SUBSCRIPTION_UNSUBSCRIBE)
		{
			AAccept = true;
			FSubscriptionRequests -= contactJid.bare();
			LOG_STRM_INFO(streamJid(),QString("Unsubscribe presence received from=%1, status=%2").arg(contactJid.full(),status));
			emit subscriptionReceived(AStanza.from(),IRoster::Unsubscribe,status);
		}
		else if (AStanza.type() == SUBSCRIPTION_UNSUBSCRIBED)
		{
			AAccept = true;
			LOG_STRM_INFO(streamJid(),QString("Unsubscribed presence received from=%1, status=%2").arg(contactJid.full(),status));
			emit subscriptionReceived(AStanza.from(),IRoster::Unsubscribed,status);
		}
	}
	return false;
}
void SelectProfileWidget::updateProfiles()
{
	IDiscoIdentity identity;
	identity.category = "gateway";
	identity.type = FDescriptor.type;

	QList<Jid> nativeGates;
	if (FDescriptor.id == GSID_RAMBLER)
		nativeGates.append(streamJid());

	QList<Jid> gates = FGateways->gateDescriptorServices(streamJid(),FDescriptor,FDescriptor.needLogin);
	for (QList<Jid>::iterator it=gates.begin(); it!=gates.end(); )
	{
		if (!(FGateways->serviceRestrictions(streamJid(),*it) & GSR_ADD_CONTACT))
		{
			IGateServiceDescriptor descriptor = FGateways->serviceDescriptor(streamJid(),*it);
			if (FDescriptor.id == descriptor.id)
				nativeGates.append(*it);
			it++;
		}
		else
		{
			it = gates.erase(it);
		}
	}

	Jid oldSelected = selectedProfile();
	QList<Jid> newProfiles = (gates.toSet() - FProfiles.keys().toSet()).toList();
	QList<Jid> oldProfiles = (FProfiles.keys().toSet() - gates.toSet()).toList();

	qSort(newProfiles);
	if (!FDescriptor.needGate && !FProfiles.contains(streamJid()))
		newProfiles.prepend(streamJid());
	else if (FDescriptor.needGate && FProfiles.contains(streamJid()))
		oldProfiles.prepend(streamJid());
	else
		oldProfiles.removeAll(streamJid());

	foreach(Jid serviceJid, newProfiles)
	{
		QRadioButton *button = new QRadioButton(ui.wdtProfiles);
		button->setAutoExclusive(true);
		connect(button,SIGNAL(toggled(bool)),SLOT(onProfileButtonToggled(bool)));
		FProfiles.insert(serviceJid,button);

		QLabel *label = new QLabel(ui.wdtProfiles);
		connect(label,SIGNAL(linkActivated(const QString &)),SLOT(onProfileLabelLinkActivated(const QString &)));
		FProfileLabels.insert(serviceJid,label);

		QHBoxLayout *layout = new QHBoxLayout();
		layout->setMargin(0);
		layout->setSpacing(0);
		layout->addWidget(button);
		layout->addWidget(label);
		layout->addStretch();
		qobject_cast<QVBoxLayout *>(ui.wdtProfiles->layout())->addLayout(layout);
	}
Example #4
0
void Roster::stanzaRequestResult(const Jid &AStreamJid, const Stanza &AStanza)
{
	if (AStanza.id() == FDelimRequestId)
	{
		FDelimRequestId.clear();
		QString groupDelim = ROSTER_GROUP_DELIMITER;
		if (AStanza.type() == "result")
		{
			groupDelim = AStanza.firstElement("query",NS_JABBER_PRIVATE).firstChildElement("roster").text();
			if (groupDelim.isEmpty())
			{
				groupDelim = ROSTER_GROUP_DELIMITER;
				LOG_STRM_INFO(streamJid(),QString("Saving default roster group delimiter on server, delimiter='%1'").arg(groupDelim));

				Stanza delim("iq");
				delim.setType("set").setId(FStanzaProcessor->newId());
				QDomElement elem = delim.addElement("query",NS_JABBER_PRIVATE);
				elem.appendChild(delim.createElement("roster",NS_STORAGE_GROUP_DELIMITER)).appendChild(delim.createTextNode(groupDelim));
				FStanzaProcessor->sendStanzaOut(AStreamJid,delim);
			}
			else
			{
				LOG_STRM_INFO(streamJid(),QString("Roster group delimiter loaded, delimiter='%1'").arg(groupDelim));
			}
		}
		else
		{
			LOG_STRM_WARNING(streamJid(),QString("Failed to load roster group delimiter: %1").arg(XmppStanzaError(AStanza).condition()));
		}
		setGroupDelimiter(groupDelim);
		requestRosterItems();
	}
	else if (AStanza.id() == FOpenRequestId)
	{
		FOpenRequestId.clear();
		if (AStanza.type() == "result")
		{
			LOG_STRM_INFO(streamJid(),"Roster items loaded");
			processItemsElement(AStanza.firstElement("query",NS_JABBER_ROSTER),true);
			FOpened = true;
			emit opened();
		}
		else
		{
			LOG_STRM_WARNING(streamJid(),QString("Failed to load roster items: %1").arg(XmppStanzaError(AStanza).condition()));
			FXmppStream->abort(XmppError(IERR_ROSTER_REQUEST_FAILED));
		}
	}
}
Example #5
0
CustomMailPage::CustomMailPage(IGateways *AGateways, IMessageWidgets *AMessageWidgets, IRosterIndex *AMailIndex, const Jid &AServiceJid, QWidget *AParent) : QWidget(AParent)
{
	ui.setupUi(this);
	setAttribute(Qt::WA_DeleteOnClose, true);
	setWindowTitle(tr("Write a mail"));
	StyleStorage::staticStorage(RSR_STORAGE_STYLESHEETS)->insertAutoStyle(this,STS_RAMBLERMAILNOTIFY_CUSTOMMAILPAGE);

	FGateways = AGateways;
	FMessageWidgets = AMessageWidgets;

	FMailIndex = AMailIndex;
	FServiceJid = AServiceJid;
	FDescriptor = FGateways->serviceDescriptor(streamJid(),serviceJid());

	ui.pbtContinue->setEnabled(false);
	ui.pbtContinue->addTextFlag(TF_LIGHTSHADOW);
	connect(ui.pbtContinue,SIGNAL(clicked()),SLOT(onContinueButtonClicked()));
	connect(ui.lneContactMail,SIGNAL(textChanged(const QString &)),SLOT(onContactMailChanged(const QString &)));

	connect(FGateways->instance(),SIGNAL(userJidReceived(const QString &, const Jid &)),
		SLOT(onUserJidReceived(const QString &, const Jid &)));
	connect(FGateways->instance(),SIGNAL(errorReceived(const QString &, const QString &)),
		SLOT(onErrorReceived(const QString &, const QString &)));

	connect(FMailIndex->instance(),SIGNAL(dataChanged(IRosterIndex *, int)),SLOT(onMailIndexDataChanged(IRosterIndex *, int)));

	onMailIndexDataChanged(FMailIndex,Qt::DecorationRole);
}
Example #6
0
void ChatWindowMenu::onStanzaSessionTerminated(const IStanzaSession &ASession)
{
	if (ASession.streamJid==streamJid() && ASession.contactJid==contactJid())
	{
		restoreSessionPrefs(contactJid());
		updateMenu();
	}
}
Example #7
0
void ChatWindowMenu::restoreSessionPrefs(const Jid &AContactJid)
{
	if (FRestorePrefs)
	{
		if (!FSessionPrefs.save.isEmpty() && !FSessionPrefs.otr.isEmpty())
		{
			IArchiveStreamPrefs sprefs = FArchiver->archivePrefs(streamJid());
			sprefs.itemPrefs[AContactJid] = FSessionPrefs;
			FSaveRequest = FArchiver->setArchivePrefs(streamJid(),sprefs);
		}
		else
		{
			FSaveRequest = FArchiver->removeArchiveItemPrefs(streamJid(),AContactJid);
		}
		FRestorePrefs = false;
	}
}
Example #8
0
void CustomMailPage::onContinueButtonClicked()
{
	QString contact = FGateways->normalizedContactLogin(FDescriptor,ui.lneContactMail->text().trimmed());
	FRequestId = FGateways->sendUserJidRequest(streamJid(),serviceJid(),contact);
	if (!FRequestId.isEmpty())
	{
		ui.pbtContinue->setEnabled(false);
		ui.lneContactMail->setEnabled(false);
	}
}
Example #9
0
bool Roster::xmppStanzaIn(IXmppStream *AXmppStream, Stanza &AStanza, int AOrder)
{
	if (!FVerSupported && !isOpen() && FXmppStream==AXmppStream && AOrder==XSHO_XMPP_FEATURE)
	{
		if (AStanza.element().nodeName()=="stream:features" && !AStanza.firstElement("ver",NS_FEATURE_ROSTER_VER).isNull())
		{
			FVerSupported = true;
			LOG_STRM_INFO(streamJid(),"Roster versioning is supported by server");
		}
	}
	return false;
}
Example #10
0
void ChatWindowMenu::updateMenu()
{
	if (FArchiver->isArchivePrefsEnabled(streamJid()))
	{
		IArchiveItemPrefs iprefs = FArchiver->archiveItemPrefs(streamJid(),contactJid());
		bool isOTRSession = FSessionNegotiation!=NULL ? isOTRStanzaSession(FSessionNegotiation->findSession(streamJid(),contactJid())) : false;

		FEnableArchiving->setChecked(iprefs.save != ARCHIVE_SAVE_FALSE);
		FEnableArchiving->setEnabled(FSaveRequest.isEmpty() && FSessionRequest.isEmpty() && !isOTRSession);

		FDisableArchiving->setChecked(iprefs.save == ARCHIVE_SAVE_FALSE);
		FDisableArchiving->setEnabled(FSaveRequest.isEmpty() && FSessionRequest.isEmpty() && !isOTRSession);

		if (FSessionNegotiation && FDataForms && FDiscovery)
		{
			FStartOTRSession->setEnabled(FSaveRequest.isEmpty() && FSessionRequest.isEmpty() && iprefs.otr!=ARCHIVE_OTR_FORBID);
			FStartOTRSession->setVisible(!isOTRSession && FDiscovery->discoInfo(streamJid(),contactJid()).features.contains(NS_STANZA_SESSION));

			FStopOTRSession->setEnabled(FSaveRequest.isEmpty() && FSessionRequest.isEmpty());
			FStopOTRSession->setVisible(isOTRSession);
		}
		else
		{
			FStartOTRSession->setVisible(false);
			FStopOTRSession->setVisible(false);
		}
	}
	else
	{
		FEnableArchiving->setEnabled(false);
		FEnableArchiving->setChecked(false);
		
		FDisableArchiving->setEnabled(false);
		FDisableArchiving->setChecked(false);

		FStartOTRSession->setVisible(false);
		FStopOTRSession->setVisible(false);
	}
}
Example #11
0
Presence::Presence(IXmppStream *AXmppStream, IStanzaProcessor *AStanzaProcessor) : QObject(AXmppStream->instance())
{
	FXmppStream = AXmppStream;
	FStanzaProcessor = AStanzaProcessor;

	FOpened = false;
	FShow = Offline;
	FPriority = 0;

	IStanzaHandle shandle;
	shandle.handler = this;
	shandle.order = SHO_DEFAULT;
	shandle.direction = IStanzaHandle::DirectionIn;
	shandle.streamJid = FXmppStream->streamJid();
	shandle.conditions.append(SHC_PRESENCE);
	FSHIPresence = FStanzaProcessor->insertStanzaHandle(shandle);

	connect(AXmppStream->instance(),SIGNAL(error(const QString &)),SLOT(onStreamError(const QString &)));
	connect(AXmppStream->instance(),SIGNAL(closed()),SLOT(onStreamClosed()));

	LogDetaile(QString("[Presence][%1] Presence created").arg(streamJid().bare()));
}
void SchedulerItemDialog::onAccountSelected(int AIndex)
{
	ui->cmbContact->clear();
	Jid streamJid(ui->cmbAccount->itemData(AIndex).toString());	
	IRoster *roster = FRosterManager->findRoster(streamJid);
	if (roster)
	{
		IPresence *presence = FPresenceManager->findPresence(streamJid);
		if (presence)
		{
			QHash<Jid, QString> contacts;
			QList<Jid> items = presence->itemsJid();
			for (QList<Jid>::ConstIterator it=items.constBegin(); it!=items.constEnd(); ++it)
			{
				IRosterItem rosterItem = roster->findItem(*it);
				QString name = (rosterItem.name.isEmpty()?(*it).full():QString("%1 <%2>").arg(rosterItem.name).arg((*it).full()));
				contacts.insert(*it, name);
			}

			for (QHash<Jid, QString>::ConstIterator it=contacts.constBegin(); it!=contacts.constEnd(); ++it)
				ui->cmbContact->addItem(it.value(), it.key().full());
		}
	}
}
Example #13
0
QString NormalWindow::tabPageId() const
{
	return "NormalWindow|"+streamJid().pBare()+"|"+contactJid().pBare();
}
			<div style=\"display:none\"> \
				<form method=\"post\" action=\"http://id.rambler.ru/script/auth.cgi?mode=login\" name=\"auth_form\"> \
					<input type=\"hidden\" name=\"back\" value=\"http://history.xmpp.rambler.ru/m/history/talks/%1\"> \
					<input type=\"text\" name=\"login\" value=\"%2\"> \
					<input type=\"text\" name=\"domain\" value=\"%3\"> \
					<input type=\"password\" name=\"passw\" value=\"%4\"> \
					<input type=\"text\" name=\"long_session\" value=\"0\"> \
					<input type=\"submit\" name=\"user.password\" value=\"%5\"> \
				</form> \
			</div> \
			<script>document.forms.auth_form.submit()</script> \
		</body></html>";

	QString html = HtmlTemplate.arg(
		QUrl::toPercentEncoding(contactJid().bare()).constData(),
		streamJid().bare(),
		streamJid().pDomain(),
		FRoster->xmppStream()->password(),
		QString("Enter"),
		QUrl::fromLocalFile(IconStorage::staticStorage(RSR_STORAGE_MENUICONS)->fileFullName(MNI_RAMBLERHISTORY_KRYTILKA)).toString());

	ui.wbvHistoryView->setHtml(html);

/*
	QByteArray body;
	body.append("back="+QString("http://mail.rambler.ru/m/history/talks/%1").arg(contactJid().eBare()).toUtf8().toPercentEncoding());
	body.append("&login="******"&domain="+streamJid().pDomain().toUtf8().toPercentEncoding());
	body.append("&passw="+FRoster->xmppStream()->password().toUtf8().toPercentEncoding());
	body.append("&long_session=0");
Example #15
0
QString ChatWindow::tabPageId() const
{
	return "ChatWindow|"+streamJid().pBare()+"|"+contactJid().pBare();
}
Example #16
0
QString CustomMailPage::tabPageId() const
{
	return "CustomMailPage|"+streamJid().pBare()+"|"+serviceJid().pBare();
}
Example #17
0
bool Presence::stanzaReadWrite(int AHandlerId, const Jid &AStreamJid, Stanza &AStanza, bool &AAccept)
{
	if (AHandlerId == FSHIPresence)
	{
		int show;
		int priority;
		QString status;
		QString errCond;
		if (AStanza.type().isEmpty())
		{
			QString showText = AStanza.firstElement("show").text();
			if (showText.isEmpty())
				show = Online;
			else if (showText == "chat")
				show = Chat;
			else if (showText == "away")
				show = Away;
			else if (showText == "dnd")
				show = DoNotDisturb;
			else if (showText == "xa")
				show = ExtendedAway;
			else
				show = Online;    //Костыль под кривые клиенты и транспорты

			status = AStanza.firstElement("status").text();
			priority = AStanza.firstElement("priority").text().toInt();
		}
		else if (AStanza.type() == "unavailable")
		{
			show = Offline;
			status = AStanza.firstElement("status").text();
			priority = 0;
		}
		else if (AStanza.type() == "error")
		{
			ErrorHandler err(AStanza.element());
			show = Error;
			status = err.message();
			errCond = err.condition();
			priority = 0;
		}
		else
			return false;

		if (AStreamJid != AStanza.from())
		{
			Jid fromJid = AStanza.from();

			IPresenceItem &pitem = FItems[fromJid];
			IPresenceItem before = pitem;

			pitem.isValid = true;
			pitem.itemJid = fromJid;
			pitem.show = show;
			pitem.priority = priority;
			pitem.status = status;
			pitem.errCondition = errCond;

			if (pitem != before)
				emit itemReceived(pitem, before);

			if (show == Offline)
				FItems.remove(fromJid);
		}
		else if (show!=IPresence::Offline && (FShow != show || FStatus != status || FPriority != priority))
		{
			LogDetaile(QString("[Presence][%1] Self presence changed by server, show=%2, status='%3'").arg(streamJid().bare()).arg(show).arg(status));
			FShow = show;
			FStatus = status;
			FPriority = priority;
			FErrCondition = errCond;
			emit changed(show,status,priority);
		}
		AAccept = true;
	}
	return false;
}
Example #18
0
void ChatWindowMenu::onStanzaSessionActivated(const IStanzaSession &ASession)
{
	if (ASession.streamJid==streamJid() && ASession.contactJid==contactJid())
		updateMenu();
}
Example #19
0
void ChatWindowMenu::onDiscoInfoChanged(const IDiscoInfo &ADiscoInfo)
{
	if (ADiscoInfo.streamJid==streamJid() && ADiscoInfo.contactJid==contactJid())
		updateMenu();
}
Example #20
0
void ChatWindowMenu::onArchivePrefsChanged(const Jid &AStreamJid)
{
	if (streamJid() == AStreamJid)
		updateMenu();
}
Example #21
0
void ChatWindowMenu::onActionTriggered(bool)
{
	Action *action = qobject_cast<Action *>(sender());
	if (action && FSaveRequest.isEmpty() && FSessionRequest.isEmpty())
	{
		if (action == FEnableArchiving)
		{
			IArchiveItemPrefs iprefs = FArchiver->archiveItemPrefs(streamJid(),contactJid().bare());
			if (iprefs.save == ARCHIVE_SAVE_FALSE)
			{
				IArchiveStreamPrefs sprefs = FArchiver->archivePrefs(streamJid());
				iprefs.save = sprefs.defaultPrefs.save!=ARCHIVE_SAVE_FALSE ? sprefs.defaultPrefs.save : QString(ARCHIVE_SAVE_MESSAGE);
				if (iprefs != sprefs.defaultPrefs)
				{
					sprefs.itemPrefs.insert(contactJid().bare(),iprefs);
					FSaveRequest = FArchiver->setArchivePrefs(streamJid(),sprefs);
				}
				else
				{
					FSaveRequest = FArchiver->removeArchiveItemPrefs(streamJid(),contactJid().bare());
				}
			}
		}
		else if (action == FDisableArchiving)
		{
			IArchiveItemPrefs iprefs = FArchiver->archiveItemPrefs(streamJid(),contactJid().bare());
			if (iprefs.save != ARCHIVE_SAVE_FALSE)
			{
				IArchiveStreamPrefs sprefs = FArchiver->archivePrefs(streamJid());
				iprefs.save = ARCHIVE_SAVE_FALSE;
				if (iprefs != sprefs.defaultPrefs)
				{
					sprefs.itemPrefs.insert(contactJid().bare(),iprefs);
					FSaveRequest = FArchiver->setArchivePrefs(streamJid(),sprefs);
				}
				else
				{
					FSaveRequest = FArchiver->removeArchiveItemPrefs(streamJid(),contactJid().bare());
				}
			}
		}
		else if (action == FStartOTRSession)
		{
			IArchiveItemPrefs iprefs = FArchiver->archiveItemPrefs(streamJid(),contactJid());
			if (iprefs.otr != ARCHIVE_OTR_REQUIRE)
			{
				IArchiveStreamPrefs sprefs = FArchiver->archivePrefs(streamJid());
				
				FRestorePrefs = true;
				FSessionPrefs = sprefs.itemPrefs.value(contactJid());

				iprefs.otr = ARCHIVE_OTR_REQUIRE;
				sprefs.itemPrefs.insert(contactJid(),iprefs);
				FSessionRequest = FArchiver->setArchivePrefs(streamJid(),sprefs);
			}
			else if (FSessionNegotiation)
			{
				FSessionNegotiation->initSession(streamJid(),contactJid());
			}
		}
		else if (action == FStopOTRSession)
		{
			if (FSessionNegotiation)
				FSessionNegotiation->terminateSession(streamJid(),contactJid());
		}
		updateMenu();
	}
}
Example #22
0
MultiUserChat::MultiUserChat(IMultiUserChatManager *AMultiChatManager, const Jid &AStreamJid, const Jid &ARoomJid, const QString &ANickName, const QString &APassword, QObject *AParent) : QObject(AParent)
{
	FMultiChatManager = AMultiChatManager;

	FMainUser = NULL;
	FSHIPresence = -1;
	FSHIMessage = -1;
	FConnected = false;
	FAutoPresence = false;

	FRoomJid = ARoomJid;
	FStreamJid = AStreamJid;
	FNickName = ANickName;
	FPassword = APassword;
	FShow = IPresence::Offline;
	FRoomName = FRoomJid.uBare();

	FMessageProcessor = PluginHelper::pluginInstance<IMessageProcessor>();
	if (FMessageProcessor)
	{
		FMessageProcessor->insertMessageEditor(MEO_MULTIUSERCHAT,this);
	}

	FStanzaProcessor = PluginHelper::pluginInstance<IStanzaProcessor>();
	if (FStanzaProcessor)
	{
		IStanzaHandle shandle;
		shandle.handler = this;
		shandle.order = SHO_PI_MULTIUSERCHAT;
		shandle.direction = IStanzaHandle::DirectionIn;
		shandle.streamJid = FStreamJid;
		shandle.conditions.append(SHC_PRESENCE);
		FSHIPresence = FStanzaProcessor->insertStanzaHandle(shandle);

		if (FMessageProcessor==NULL || !FMessageProcessor->isActiveStream(streamJid()))
		{
			shandle.conditions.clear();
			shandle.order = SHO_MI_MULTIUSERCHAT;
			shandle.conditions.append(SHC_MESSAGE);
			FSHIMessage = FStanzaProcessor->insertStanzaHandle(shandle);
		}
	}

	IPresenceManager *presenceManager = PluginHelper::pluginInstance<IPresenceManager>();
	FPresence = presenceManager!=NULL ? presenceManager->findPresence(FStreamJid) : NULL;
	if (FPresence)
	{
		connect(FPresence->instance(),SIGNAL(changed(int, const QString &, int)),SLOT(onPresenceChanged(int, const QString &, int)));
	}

	IXmppStreamManager *xmppStreamManager = PluginHelper::pluginInstance<IXmppStreamManager>();
	FXmppStream = xmppStreamManager!=NULL ? xmppStreamManager->findXmppStream(FStreamJid) : NULL;
	if (FXmppStream)
	{
		connect(FXmppStream->instance(),SIGNAL(closed()),SLOT(onXmppStreamClosed()));
		connect(FXmppStream->instance(),SIGNAL(jidChanged(const Jid &)),SLOT(onXmppStreamJidChanged(const Jid &)));
	}

	FDiscovery = PluginHelper::pluginInstance<IServiceDiscovery>();
	if (FDiscovery)
	{
		onDiscoveryInfoReceived(FDiscovery->discoInfo(streamJid(),roomJid()));
		connect(FDiscovery->instance(),SIGNAL(discoInfoReceived(const IDiscoInfo &)),SLOT(onDiscoveryInfoReceived(const IDiscoInfo &)));
	}

	FDataForms = PluginHelper::pluginInstance<IDataForms>();
}
Example #23
0
bool MultiUserChat::sendPresence(int AShow, const QString &AStatus)
{
	if (FStanzaProcessor)
	{
		Jid userJid(FRoomJid.node(),FRoomJid.domain(),FNickName);

		Stanza presence("presence");
		presence.setTo(userJid.full());

		QString showText;
		bool isConnecting = true;
		switch (AShow)
		{
		case IPresence::Online:
			showText = QString::null;
			break;
		case IPresence::Chat:
			showText = "chat";
			break;
		case IPresence::Away:
			showText = "away";
			break;
		case IPresence::DoNotDisturb:
			showText = "dnd";
			break;
		case IPresence::ExtendedAway:
			showText = "xa";
			break;
		default:
			isConnecting = false;
			showText = "unavailable";
		}

		if (!isConnecting)
			presence.setType("unavailable");
		else if (!showText.isEmpty())
			presence.addElement("show").appendChild(presence.createTextNode(showText));

		if (!AStatus.isEmpty())
			presence.addElement("status").appendChild(presence.createTextNode(AStatus));

		if (!isConnected() && isConnecting)
		{
			FRoomError = XmppError::null;
			emit chatAboutToConnect();

			QDomElement xelem = presence.addElement("x",NS_MUC);
			if (FHistory.empty || FHistory.maxChars>0 || FHistory.maxStanzas>0 || FHistory.seconds>0 || FHistory.since.isValid())
			{
				QDomElement histElem = xelem.appendChild(presence.createElement("history")).toElement();
				if (!FHistory.empty)
				{
					if (FHistory.maxChars > 0)
						histElem.setAttribute("maxchars",FHistory.maxChars);
					if (FHistory.maxStanzas > 0)
						histElem.setAttribute("maxstanzas",FHistory.maxStanzas);
					if (FHistory.seconds > 0)
						histElem.setAttribute("seconds",FHistory.seconds);
					if (FHistory.since.isValid())
						histElem.setAttribute("since",DateTime(FHistory.since).toX85UTC());
				}
				else
				{
					histElem.setAttribute("maxchars",0);
				}
			}
			if (!FPassword.isEmpty())
				xelem.appendChild(presence.createElement("password")).appendChild(presence.createTextNode(FPassword));
			if (FDiscovery && !FDiscovery->hasDiscoInfo(streamJid(),roomJid()))
				FDiscovery->requestDiscoInfo(streamJid(),roomJid());
		}
		else if (isConnected() && !isConnecting)
		{
			emit chatAboutToDisconnect();
		}

		if (FStanzaProcessor->sendStanzaOut(FStreamJid,presence))
		{
			LOG_STRM_INFO(FStreamJid,QString("Presence sent to conference, room=%1, show=%2").arg(FRoomJid.bare()).arg(AShow));
			FConnected = isConnecting;
			return true;
		}
		else
		{
			LOG_STRM_WARNING(FStreamJid,QString("Failed to send presence to conference, room=%1, show=%2").arg(FRoomJid.bare()).arg(AShow));
		}
	}
	else
	{
		REPORT_ERROR("Failed to send presence to conference: Required interfaces not found");
	}
	return false;
}