void TranslatorGUIClient::slotTranslateChat()
{
	if ( !m_manager->view() )
		return;

	Kopete::Message msg = m_manager->view()->currentMessage();
	QString body = msg.plainBody();
	if ( body.isEmpty() )
		return;

	QString src_lang = TranslatorPlugin::plugin()->m_myLang;
	QString dst_lang;

	QList<Kopete::Contact*> list = m_manager->members();
	Kopete::MetaContact *to = list.first()->metaContact();
	dst_lang = to->pluginData( TranslatorPlugin::plugin(), "languageKey" );
	if ( dst_lang.isEmpty() || dst_lang == "null" )
	{
		kDebug( 14308 ) << "Cannot determine dst Metacontact language (" << to->displayName() << ")";
		return;
	}

	// We search for src_dst
	TranslatorPlugin::plugin()->translateMessage( body, src_lang, dst_lang, this, SLOT(messageTranslated(QVariant)) );
}
Ejemplo n.º 2
0
QStringList KopeteIface::metacontactsForContactId( const QString & contactId )
{
    Kopete::MetaContact * mc = Kopete::ContactList::self()->findMetaContactByContactId( contactId );
    if ( mc )
        return QStringList( mc->displayName() );
    else
        return QStringList();
}
Ejemplo n.º 3
0
void KopeteIface::messageContactById( const QString &metaContactId )
{
    Kopete::MetaContact *m = Kopete::ContactList::self()->metaContact( metaContactId );
    if( m )
    {
        m->execute();
    }
}
Ejemplo n.º 4
0
void KopeteIface::setGlobalNickname( const QString &nickname )
{
    if( Kopete::Config::enableGlobalIdentity() )
    {
        Kopete::MetaContact *myselfMetaContact = Kopete::ContactList::self()->myself();
        myselfMetaContact->setDisplayNameSource( Kopete::MetaContact::SourceCustom );
        myselfMetaContact->setDisplayName( nickname );
    }
}
Ejemplo n.º 5
0
void KopeteIface::setGlobalPhoto( const KURL &photoUrl )
{
    if( Kopete::Config::enableGlobalIdentity() )
    {
        Kopete::MetaContact *myselfMetaContact = Kopete::ContactList::self()->myself();
        myselfMetaContact->setPhoto( photoUrl );
        if( myselfMetaContact->photoSource() != Kopete::MetaContact::SourceCustom )
            myselfMetaContact->setPhotoSource( Kopete::MetaContact::SourceCustom );
    }
}
Ejemplo n.º 6
0
QString KopeteIface::onlineStatus( const QString &metaContactId )
{
    Kopete::MetaContact *m = Kopete::ContactList::self()->metaContact( metaContactId );
    if( m )
    {
        Kopete::OnlineStatus status = m->status();
        return status.description();
    }

    return "Unknown Contact";
}
Ejemplo n.º 7
0
WPAccount::WPAccount(WPProtocol *parent, const QString &accountID, const char *name)
	: Kopete::Account(parent, accountID, name)
{
//	kdDebug(14170) <<  "WPAccount::WPAccount()" << endl;

	mProtocol = WPProtocol::protocol();

	// we need this before initActions
	Kopete::MetaContact *myself = Kopete::ContactList::self()->myself();
	setMyself( new WPContact(this, accountID, myself->displayName(), myself) );

//	if (excludeConnect()) connect(Kopete::OnlineStatus::Online); // ??
}
void XmlContactStorage_Test::testLoad()
{
	// TODO: Check plugin data.
	// TODO: Check more things.
	QString xmlFilename = QString( SRCDIR ) + QString("xmlcontactstorage_test_list.xml");

	Kopete::ContactListStorage *storage = new Kopete::XmlContactStorage( xmlFilename );
	storage->load();

	// Verify that the loading went well.
	QVERIFY( storage->isValid() );
	// Check that we have the correct numbers of groups and contacts.
	QCOMPARE( storage->groups().size(), 5 );
	QCOMPARE( storage->contacts().size(), 6 );

	// Verify that we parsed the correct group names.
	QStringList groupNameList = expectedGroupList();
	QStringList::ConstIterator expectedIt, expectedItEnd = groupNameList.constEnd();

	uint groupId = 1;
	Kopete::Group::List loadGroupList = storage->groups();
	Kopete::Group::List::ConstIterator it, itEnd = loadGroupList.constEnd();
	for(it = loadGroupList.constBegin(), expectedIt = groupNameList.constBegin();
		it != itEnd, expectedIt != expectedItEnd;
		++it, ++expectedIt)
	{
		Kopete::Group *group = (*it);
		QString groupName = group->displayName();
		QString expectedGroupName = (*expectedIt);
		QCOMPARE( groupName, expectedGroupName );
		QCOMPARE( group->groupId(), groupId++ );
	}

	// Verify that we parsed the correct contacts.
	QStringList contactList = expectedContactList();
	QStringList::ConstIterator contactIt, contactItEnd = contactList.constEnd();
	
	Kopete::MetaContact::List loadContactList = storage->contacts();
	Kopete::MetaContact::List::ConstIterator loadContactIt, loadContactItEnd = loadContactList.constEnd();
	for(loadContactIt = loadContactList.constBegin(), contactIt = contactList.constBegin();
		loadContactIt != loadContactItEnd, contactIt != contactItEnd;
		++loadContactIt, ++contactIt)
	{
		Kopete::MetaContact *contact = (*loadContactIt);
		QString expectedContactName = (*contactIt);

		QCOMPARE( contact->displayName(), expectedContactName );
		QCOMPARE( (int)contact->displayNameSource(), (int)Kopete::MetaContact::SourceCustom );
	}
}
Ejemplo n.º 9
0
QStringList KopeteIface::contactsForDisplayName( const QString & displayName )
{
    Kopete::MetaContact * mc = Kopete::ContactList::self()->findMetaContactByDisplayName( displayName );
    QStringList contactIds;
    if ( mc )
    {
        QPtrList<Kopete::Contact> contacts = mc->contacts();
        QPtrListIterator<Kopete::Contact> it( contacts );
        for( ; it.current(); ++it )
        {
            contactIds.append( (*it)->contactId() );
        }
    }
    return contactIds;
}
Ejemplo n.º 10
0
QString KopeteIface::messageContact( const QString &contactId, const QString &messageText )
{
    Kopete::MetaContact *mc = Kopete::ContactList::self()->findMetaContactByContactId( contactId );
    if ( !mc )
    {
        return "No such contact.";
    }

    if ( mc->isReachable() )
        Kopete::ContactList::self()->messageContact( contactId, messageText );
    else
        return "The contact is not reachable";

    //Default return value
    return QString::null;
}
JabberFileTransfer::JabberFileTransfer ( JabberAccount *account, XMPP::FileTransfer *incomingTransfer )
{
	kDebug(JABBER_DEBUG_GLOBAL) << "New incoming transfer from " << incomingTransfer->peer().full () << ", filename " << incomingTransfer->fileName () << ", size " << QString::number ( incomingTransfer->fileSize () );

	mAccount = account;
	mXMPPTransfer = incomingTransfer;

	// try to locate an exact match in our pool first
	mContact = mAccount->contactPool()->findExactMatch ( mXMPPTransfer->peer () );

	if ( !mContact )
	{
		// we have no exact match, try a broader search
		mContact = mAccount->contactPool()->findRelevantRecipient ( mXMPPTransfer->peer () );
	}

	if ( !mContact )
	{
		kDebug(JABBER_DEBUG_GLOBAL) << "No matching local contact found, creating a new one.";

		Kopete::MetaContact *metaContact = new Kopete::MetaContact ();

		metaContact->setTemporary (true);

		mContact = mAccount->contactPool()->addContact ( mXMPPTransfer->peer (), metaContact, false );

		Kopete::ContactList::self ()->addMetaContact ( metaContact );
	}

	connect ( Kopete::TransferManager::transferManager (), SIGNAL (accepted(Kopete::Transfer*,QString)),
			  this, SLOT (slotIncomingTransferAccepted(Kopete::Transfer*,QString)) );
	connect ( Kopete::TransferManager::transferManager (), SIGNAL (refused(Kopete::FileTransferInfo)),
			  this, SLOT (slotTransferRefused(Kopete::FileTransferInfo)) );

	initializeVariables ();

	if (!mXMPPTransfer->thumbnail().isNull()) {
		JT_BitsOfBinary *task = new JT_BitsOfBinary ( mAccount->client()->rootTask() );
		connect ( task, SIGNAL(finished()), this, SLOT(slotThumbnailReceived()) );
		task->get ( mXMPPTransfer->peer(), QString(mXMPPTransfer->thumbnail().data) );
		task->go ( true );
		QTimer::singleShot ( 5000, this, SLOT(askIncomingTransfer()) ); // Wait for thumbnail max 5s
	} else {
		askIncomingTransfer ();
	}
}
Ejemplo n.º 12
0
bool KABCPersistence::syncWithKABC( MetaContact * mc )
{
	kDebug(14010) ;
	bool contactAdded = false;
	// check whether the dontShowAgain was checked
		KABC::AddressBook* ab = addressBook();
		KABC::Addressee addr  = ab->findByUid( mc->kabcId() );

		if ( !addr.isEmpty() ) // if we are associated with KABC
		{
// load the set of addresses from KABC
		const QStringList customs = addr.customs();

		QStringList::ConstIterator it;
		for ( it = customs.constBegin(); it != customs.constEnd(); ++it )
		{
			QString app, name, value;
			splitField( *it, app, name, value );
			kDebug( 14010 ) << "app=" << app << " name=" << name << " value=" << value;

			if ( app.startsWith( QLatin1String( "messaging/" ) ) )
			{
				if ( name == QLatin1String( "All" ) )
				{
					kDebug( 14010 ) << " syncing \"" << app << ":" << name << " with contact list ";
					// Get the protocol name from the custom field
					// by chopping the 'messaging/' prefix from the custom field app name
					QString protocolName = app.right( app.length() - 10 );
					// munge Jabber hack
					if ( protocolName == QLatin1String( "xmpp" ) )
						protocolName = QLatin1String( "jabber" );

					// Check Kopete supports it
					Protocol * proto = dynamic_cast<Protocol*>( PluginManager::self()->loadPlugin( QLatin1String( "kopete_" ) + protocolName ) );
					if ( !proto )
					{
						KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Sorry,
																					 i18n( "<qt>\"%1\" is not supported by Kopete.</qt>", protocolName ),
																					 i18n( "Could Not Sync with KDE Address Book" )  );
						continue;
					}

					// See if we need to add each contact in this protocol
					QStringList addresses = value.split( QChar( 0xE000 ), QString::SkipEmptyParts );
					QStringList::iterator end = addresses.end();
					for ( QStringList::iterator it = addresses.begin(); it != end; ++it )
					{
						// check whether each one is present in Kopete
						// Is it in the contact list?
						// First discard anything after an 0xE120, this is used by IRC to separate nick and server group name, but
						// IRC doesn't support this properly yet, so the user will have to select an appropriate account manually
						int separatorPos = (*it).indexOf( QChar( 0xE120 ) );
						if ( separatorPos != -1 )
							*it = (*it).left( separatorPos );

						Kopete::MetaContact *otherMc = 0;
						foreach( Kopete::Account *act, Kopete::AccountManager::self()->accounts() )
						{
							if( act->protocol() != proto )
								continue;
							Kopete::Contact *c= act->contacts().value(*it);
							if(c)
							{
								otherMc=c->metaContact();
								break;
							}
						}

						if ( otherMc ) // Is it in another metacontact?
						{
							// Is it already in this metacontact? If so, we needn't do anything
							if ( otherMc == mc )
							{
								kDebug( 14010 ) << *it << " already a child of this metacontact.";
								continue;
							}
							kDebug( 14010 ) << *it << " already exists in OTHER metacontact, move here?";
							// find the Kopete::Contact and attempt to move it to this metacontact.
							otherMc->findContact( proto->pluginId(), QString(), *it )->setMetaContact( mc );
						}
						else
						{
							// if not, prompt to add it
							kDebug( 14010 ) << proto->pluginId() << "://" << *it << " was not found in the contact list.  Prompting to add...";
							if ( KMessageBox::Yes == KMessageBox::questionYesNo( Kopete::UI::Global::mainWidget(),
									 i18n( "<qt>An address was added to this contact by another application.<br />Would you like to use it in Kopete?<br /><b>Protocol:</b> %1<br /><b>Address:</b> %2</qt>", proto->displayName(), *it ), i18n( "Import Address From Address Book" ), KGuiItem( i18n("Use") ), KGuiItem( i18n("Do Not Use") ), QLatin1String( "ImportFromKABC" ) ) )
							{
								// Check the accounts for this protocol are all connected
								// Most protocols do not allow you to add contacts while offline
								// Would be better to have a virtual bool Kopete::Account::readyToAddContact()
								int accountcount=0;
								bool allAccountsConnected = true;
								Kopete::Account *chosen = 0;
								foreach( Kopete::Account *act, Kopete::AccountManager::self()->accounts() )
								{
									if( act->protocol() == proto) 
									{
										accountcount++;
										if(!act->isConnected())
										{
											allAccountsConnected=false;
											break;
										}
										chosen=act;
									}
								}

								if ( !allAccountsConnected )
								{
									KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Sorry,
											i18n( "<qt>One or more of your accounts using %1 are offline.  Most systems have to be connected to add contacts.  Please connect these accounts and try again.</qt>", protocolName ),
											i18n( "Not Connected" )  );
									continue;
								}

								// we have got a contact to add, our accounts are connected, so add it.
								// Do we need to choose an account
								if ( accountcount > 1 )
								{	// if we have >1 account in this protocol, prompt for the protocol.
									KDialog *chooser = new KDialog(0);
									chooser->setCaption( i18n("Choose Account") );
									chooser->setButtons( KDialog::Ok | KDialog::Cancel );

									AccountSelector *accSelector = new AccountSelector(proto, chooser);
									accSelector->setObjectName( QLatin1String("accSelector") );
									chooser->setMainWidget(accSelector);
									if ( chooser->exec() == QDialog::Rejected )
										continue;
									chosen = accSelector->selectedItem();

									delete chooser;
								}
								else if ( accountcount == 0 )
								{
									KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Sorry,
											i18n( "<qt>You do not have an account configured for <b>%1</b> yet.  Please create an account, connect it, and try again.</qt>", protocolName ),
											i18n( "No Account Found" )  );
									continue;
								}

								// add the contact to the chosen account
								if ( chosen )
								{
									kDebug( 14010 ) << "Adding " << *it << " to " << chosen->accountId();
									if ( chosen->addContact( *it, mc ) )
										contactAdded = true;
									else
										KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Sorry,
											i18n( "<qt>It was not possible to add the contact.</qt>" ),
											i18n( "Could Not Add Contact") ) ;
								}
							}
							else
								kDebug( 14010 ) << " user declined to add " << *it << " to contact list ";
						}
					}
					kDebug( 14010 ) << " all " << addresses.count() << " contacts in " << proto->pluginId() << " checked ";
				}
				else
Ejemplo n.º 13
0
void MeanwhileSession::syncContactsToServer()
{
    HERE;
    struct mwSametimeList *list = mwSametimeList_new();

    /* set up a fallback group for top-level contacts */
    struct mwSametimeGroup *topstgroup = mwSametimeGroup_new(list,
            mwSametimeGroup_DYNAMIC, "People");
    mwSametimeGroup_setOpen(topstgroup, true);

    const QHash<QString, Kopete::Contact *> contacts = account->contacts();
   // Q3DictIterator<Kopete::Contact> it(account->contacts());
    for(QHash<QString, Kopete::Contact *>::const_iterator it = contacts.constBegin();
            it != contacts.constEnd(); ++it ) {
        MeanwhileContact *contact = static_cast<MeanwhileContact *>(it.value());

        /* Find the group that the metacontact is in */
        Kopete::MetaContact *mc = contact->metaContact();
        if (!mc)
            continue;

        Kopete::Group *contactgroup = mc->groups().value(0);
        if (!contactgroup)
            continue;

        if (contactgroup->type() == Kopete::Group::Temporary)
            continue;

        struct mwSametimeGroup *stgroup;
        if (contactgroup->type() == Kopete::Group::TopLevel) {
            stgroup = topstgroup;
        } else  {
            /* find (or create) a matching sametime list group */
            stgroup = mwSametimeList_findGroup(list,
                        contactgroup->displayName().toUtf8().constData());
            if (!stgroup) {
                stgroup = mwSametimeGroup_new(list, mwSametimeGroup_DYNAMIC,
                        contactgroup->displayName().toUtf8().constData());
            }
            mwSametimeGroup_setOpen(stgroup, contactgroup->isExpanded());
            mwSametimeGroup_setAlias(stgroup,
                    contactgroup->pluginData(account->protocol(), "alias").toUtf8().constData());
        }

        QByteArray tmpMeanwhileId = contact->meanwhileId().toUtf8();
        /* now add the user (by IDBlock) */
        struct mwIdBlock id =
            { (gchar*)tmpMeanwhileId.constData(), 0 };
        struct mwSametimeUser *stuser = mwSametimeUser_new(stgroup,
                mwSametimeUser_NORMAL, &id);

        mwSametimeUser_setAlias(stuser, mc->displayName().toUtf8().constData());
    }

    /* store! */
    struct mwPutBuffer *buf = mwPutBuffer_new();
    struct mwStorageUnit *unit = mwStorageUnit_new(mwStore_AWARE_LIST);
    struct mwOpaque *opaque = mwStorageUnit_asOpaque(unit);

    mwSametimeList_put(buf, list);
    mwPutBuffer_finalize(opaque, buf);

    mwServiceStorage_save(storageService, unit, NULL, NULL, NULL);

    mwSametimeList_free(list);
}