コード例 #1
0
bool Kopete::Transfer::showHtmlMessage( QString text ) const
{
	Kopete::ChatSession *cs = chatSession();
	if (! cs)
		return false;
	
	Kopete::Message msg;
	msg.setHtmlBody( text );
	cs->appendMessage( msg );
	return true;
}
コード例 #2
0
void KopeteMessage_Test::testPrimitives()
{
	/**********************************************
	 * from(), to()
	 *********************************************/

	{
		Kopete::Message msg( m_contactFrom, m_contactTo);
		Q_ASSERT(msg.from());
		Q_ASSERT(!msg.to().isEmpty());
	}

	/**********************************************
	 * Direction
	 *********************************************/

	{
		Kopete::Message msg;
		msg.setDirection( Kopete::Message::Inbound );
		QCOMPARE(msg.direction(), Kopete::Message::Inbound);
	}
	{
		Kopete::Message msg;
		msg.setDirection( Kopete::Message::Outbound );
		QCOMPARE(msg.direction(), Kopete::Message::Outbound);
	}
	{
		Kopete::Message msg;
		msg.setDirection( Kopete::Message::Internal );
		QCOMPARE(msg.direction(), Kopete::Message::Internal);
	}

	/**********************************************
	 * Message Format
	 *********************************************/

	{
		Kopete::Message msg;
		msg.setPlainBody( QLatin1String("foobar") );
		QCOMPARE(msg.format(), Qt::PlainText);
	}
	{
		Kopete::Message msg;
		msg.setHtmlBody( QLatin1String("foobar") );
		QCOMPARE(msg.format(), Qt::RichText);
	}
	{
		QString m = "foobar";
		Kopete::Message msg;

		msg.setPlainBody(m);
		QCOMPARE(msg.format(), Qt::PlainText);

		msg.setHtmlBody(m);
		QCOMPARE(msg.format(), Qt::RichText);
	}


	/**********************************************
	 * setBody()
	 *********************************************/

	{
		QString m = "foobar";
		Kopete::Message msg;
		msg.setHtmlBody( m );

		msg.setPlainBody("NEW");
		QCOMPARE(QString("NEW"), msg.plainBody());

		msg.setPlainBody("NEW_NEW");
		QCOMPARE(msg.plainBody(), QString("NEW_NEW"));
	}
	{
		QString m = "foobar";
		Kopete::Message msg;
		msg.setPlainBody( m );

		msg.setPlainBody("NEW");
		QCOMPARE(msg.plainBody(), QString("NEW"));

		msg.setHtmlBody("NEW_NEW");
		QCOMPARE(msg.plainBody(), QString("NEW_NEW"));
	}
	{
		QString m = "<html><head></head><body foo=\"bar\">   <b>HELLO WORLD</b>   </body></html>";
		Kopete::Message msg;
		msg.setPlainBody( m );
		QCOMPARE(msg.plainBody(), m);

		msg.setPlainBody("<simple> SIMPLE");
		QCOMPARE(msg.plainBody(), QString("<simple> SIMPLE"));

		msg.setHtmlBody("<simple>SIMPLE</simple>");
		QCOMPARE(msg.plainBody(),  QString("SIMPLE") );

		QCOMPARE(Kopete::Message::unescape( QString( "<simple>SIMPLE</simple>" ) ), QString("SIMPLE") );
		QCOMPARE(Kopete::Message::unescape( QString( "Foo <img src=\"foo.png\" />" ) ), QString("Foo ") );
		QCOMPARE(Kopete::Message::unescape( QString( "Foo <img src=\"foo.png\" title=\"Bar\" />" ) ), QString("Foo Bar") );

		msg.setHtmlBody(m);

//		QCOMPARE(msg.escapedBody(),           QString(" &nbsp; <b>HELLO WORLD</b> &nbsp; "));
//		QCOMPARE(msg.plainBody(),             QString("   HELLO WORLD   "));
		QCOMPARE(msg.plainBody().trimmed(),   QString("HELLO WORLD"));
//		QCOMPARE(msg.escapedBody().trimmed(), QString("&nbsp; <b>HELLO WORLD</b> &nbsp;"));
	}

	/**********************************************
	 * Copy constructor
	 *********************************************/

	{
		Kopete::Message msg1;
		msg1.setHtmlBody( QLatin1String("foo") );
		Kopete::Message msg2(msg1);

		QCOMPARE(msg1.plainBody(), msg2.plainBody());
		QCOMPARE(msg1.escapedBody(), msg2.escapedBody());

		msg1.setPlainBody("NEW");
		QCOMPARE(msg1.plainBody(), QString("NEW"));
		QCOMPARE(msg2.plainBody(), QString("foo"));
	}

	/**********************************************
	 * operator=
	 *********************************************/

	{
		Kopete::Message msg1;
		msg1.setHtmlBody( QLatin1String("foo") );
		{
			Kopete::Message msg2;

//			QCOMPARE(msg2.plainBody(), QString());

			msg2 = msg1;

			QCOMPARE(msg1.plainBody(), msg2.plainBody());
			QCOMPARE(msg1.escapedBody(), msg2.escapedBody());

			msg1.setPlainBody("NEW");
			QCOMPARE(msg1.plainBody(), QString("NEW"));
			QCOMPARE(msg2.plainBody(), QString("foo"));
		}
		QCOMPARE(msg1.plainBody(), QString("NEW"));

		msg1 = msg1;
		QCOMPARE(msg1.plainBody(), QString("NEW"));
	}
}