예제 #1
0
void KopeteApplication::slotAllPluginsLoaded()
{
	KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

	// --noconnect not specified?
	if ( args->isSet( "connect" )  && KopetePrefs::prefs()->autoConnect() )
		Kopete::AccountManager::self()->connectAll();


	// Handle things like '--autoconnect foo,bar --autoconnect foobar'
	KStringList connectArgsC = args->getOptionList( "autoconnect" );
	QStringList connectArgs;

	for ( KStringList::ConstIterator it = connectArgsC.begin(); it != connectArgsC.end(); ++it )
	{
		QStringList split = QStringList::split( ',', QString::fromLatin1( *it ) );

		for ( QStringList::ConstIterator it2 = split.begin(); it2 != split.end(); ++it2 )
		{
			connectArgs.append( *it2 );
		}
	}
	
	for ( QStringList::ConstIterator i = connectArgs.begin(); i != connectArgs.end(); ++i )
	{
		QRegExp rx( QString::fromLatin1( "([^\\|]*)\\|\\|(.*)" ) );
		rx.search( *i );
		QString protocolId = rx.cap( 1 );
		QString accountId = rx.cap( 2 );

		if ( accountId.isEmpty() )
		{
			if ( protocolId.isEmpty() )
				accountId = *i;
			else
				continue;
		}

		QPtrListIterator<Kopete::Account> it( Kopete::AccountManager::self()->accounts() );
		Kopete::Account *account;
		while ( ( account = it.current() ) != 0 )
		{
			++it;

			if ( ( account->accountId() == accountId ) )
			{
				if ( protocolId.isEmpty() || account->protocol()->pluginId() == protocolId )
				{
					account->connect();
					break;
				}
			}
		}
	}

	// Parse any passed URLs/files
	handleURLArgs();
}
예제 #2
0
QStringList KopeteIface::accounts()
{
    QStringList list;
    QPtrList<Kopete::Account> m_accounts=Kopete::AccountManager::self()->accounts();
    QPtrListIterator<Kopete::Account> it( m_accounts );
    Kopete::Account *account;
    while ( ( account = it.current() ) != 0 )
    {
        ++it;

        list += ( account->protocol()->pluginId() +"||" + account->accountId() );
    }

    return list;

}
예제 #3
0
void KopeteIface::disconnect(const QString &protocolId, const QString &accountId )
{
    QPtrListIterator<Kopete::Account> it( Kopete::AccountManager::self()->accounts() );
    Kopete::Account *account;
    while ( ( account = it.current() ) != 0 )
    {
        ++it;

        if( ( account->accountId() == accountId) )
        {
            if( protocolId.isEmpty() || account->protocol()->pluginId() == protocolId )
            {
                account->disconnect();
                break;
            }
        }
    }
}
void KopeteAccountConfig::load()
{
	KopeteAccountLVI *lvi = 0L;

	m_view->mAccountList->clear();

	QPtrList<Kopete::Account> accounts = Kopete::AccountManager::self()->accounts();
	for ( Kopete::Account *i = accounts.first() ; i; i = accounts.next() )
	{
		// Insert the item after the previous one
		lvi = new KopeteAccountLVI( i, m_view->mAccountList );
		lvi->setText( 0, i->protocol()->displayName() );
		lvi->setPixmap( 0, i->accountIcon() );
		lvi->setText( 1, i->accountLabel() );
	}

	m_newColors.clear();
	slotItemSelected();
}
void KopeteAccountConfig::slotEditAccount()
{
	KopeteAccountLVI *lvi = static_cast<KopeteAccountLVI*>( m_view->mAccountList->selectedItem() );
	if ( !lvi || !lvi->account() )
		return;

	Kopete::Account *ident = lvi->account();
	Kopete::Protocol *proto = ident->protocol();

	KDialogBase *editDialog = new KDialogBase( this, "KopeteAccountConfig::editDialog", true,
		i18n( "Edit Account" ), KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, true );

	KopeteEditAccountWidget *m_accountWidget = proto->createEditAccountWidget( ident, editDialog );
	if ( !m_accountWidget )
		return;

	// FIXME: Why the #### is EditAccountWidget not a QWidget?!? This sideways casting
	//        is braindead and error-prone. Looking at MSN the only reason I can see is
	//        because it allows direct subclassing of designer widgets. But what is
	//        wrong with embedding the designer widget in an empty QWidget instead?
	//        Also, if this REALLY has to be a pure class and not a widget, then the
	//        class should at least be renamed to EditAccountIface instead - Martijn
	QWidget *w = dynamic_cast<QWidget *>( m_accountWidget );
	if ( !w )
		return;

	editDialog->setMainWidget( w );
	if ( editDialog->exec() == QDialog::Accepted )
	{
		if( m_accountWidget->validateData() )
			m_accountWidget->apply();
	}

	// FIXME: Why deleteLater? It shouldn't be in use anymore at this point - Martijn
	editDialog->deleteLater();
	load();
	Kopete::AccountManager::self()->save();
}
void NowListeningPlugin::slotAdvertCurrentMusic()
{
	// Do anything when statusAdvertising is off.
	if( !NowListeningConfig::self()->statusAdvertising() && !NowListeningConfig::self()->appendStatusAdvertising() )
		return; 

	// This slot is called every 5 seconds, so we check if we have a new track playing.
	if( newTrackPlaying() )
	{
		QString advert;

		QPtrList<Kopete::Account> accountsList = Kopete::AccountManager::self()->accounts();
		for( Kopete::Account* a = accountsList.first(); a; a = accountsList.next() )
		{
			/*
				NOTE:
				MSN status message(personal message) use a special tag to advert the current music playing. 
				So, we don't send the all formatted string, send a special string seperated by ";".
				
				Also, do not use MSN hack in appending mode.
			*/
			if( a->protocol()->pluginId() == "MSNProtocol" && !NowListeningConfig::self()->appendStatusAdvertising() )
			{
				QString track, artist, album, mediaList;
				bool isPlaying=false;

				if( NowListeningConfig::self()->useSpecifiedMediaPlayer() && d->m_currentMediaPlayer )
				{
					if( d->m_currentMediaPlayer->playing() )
					{
						track = d->m_currentMediaPlayer->track();
						artist = d->m_currentMediaPlayer->artist();
						album = d->m_currentMediaPlayer->album();
						mediaList = track + ";" + artist + ";" + album;
						isPlaying = true;
					}
				}
				else
				{
					for ( NLMediaPlayer* i = d->m_mediaPlayerList.first(); i; i = d->m_mediaPlayerList.next() )
					{
						if( i->playing() )
						{
							track = i->track();
							artist = i->artist();
							album = i->album();
							mediaList = track + ";" + artist + ";" + album;
							isPlaying = true;
						}
					}
				}

				// KDE4 TODO: Use the new status message framework, and remove this "hack".
				if( isPlaying )
				{
					advert = QString("[Music]%1").arg(mediaList);
				}

			}
			else
			{
				if( NowListeningConfig::self()->appendStatusAdvertising() )
				{
					// Check for the now listening message in parenthesis, 
					// include the header to not override other messages in parenthesis.
					QRegExp statusSong( QString(" \\(%1.*\\)$").arg( NowListeningConfig::header()) );
					
					// HACK: Don't keep appending the now listened song. Replace it in the status message.
					advert = a->myself()->property( Kopete::Global::Properties::self()->awayMessage() ).value().toString();
					// Remove the braces when they are no listened song.
					QString mediaAdvert = mediaPlayerAdvert(false);
					if(!mediaAdvert.isEmpty())
					{
						if(statusSong.search(advert) != -1)
						{
							advert = advert.replace(statusSong, QString(" (%1)").arg(mediaPlayerAdvert(false)) );
						}
						else
						{
							advert += QString(" (%1)").arg( mediaPlayerAdvert(false) );
						}
					}
					else
					{
						advert = advert.replace(statusSong, "");
					}
				}
				else
				{
					advert = mediaPlayerAdvert(false); // newTrackPlaying has done the update.
				}
			}

			a->setOnlineStatus(a->myself()->onlineStatus(), advert);
		}
	}
}