Exemplo n.º 1
0
void MainWindow::updateButtonClicked(const QString &id, const QString &text, const QString& screenName)
{
    bool ok;

    //if screenName is not empty, then it's direct message
    if (!screenName.isEmpty()) {
        qDebug() << "Sending DM to " << screenName;

        QTweetDirectMessageNew *dm = new QTweetDirectMessageNew;
        dm->setOAuthTwitter(m_oauthTwitter);
        dm->post(screenName, text);

        connect(dm, SIGNAL(parsedDirectMessage(QTweetDMStatus)),
                this, SLOT(directMessageNewFinished(QTweetDMStatus)));

        return;
    }

    qint64 tweetid = id.toLongLong(&ok);

    QString updateText = text.left(140);

    if (updateText.isEmpty()) {
        qDebug() << "MainWindow::updateButtonClicked: empty update text";
        return;
    }

    QTweetStatusUpdate *statusUpdate = new QTweetStatusUpdate;
    statusUpdate->setOAuthTwitter(m_oauthTwitter);
    statusUpdate->post(text, tweetid);
    connect(statusUpdate, SIGNAL(postedStatus(QTweetStatus)),
            this, SLOT(statusUpdateFinished(QTweetStatus)));
}
Exemplo n.º 2
0
void
TwitterInfoPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )
{
    tDebug() << Q_FUNC_INFO;
    if ( !isValid() )
    {
        tDebug() << Q_FUNC_INFO << "Plugin not valid, deleting and returning";
        deleteLater();
        return;
    }

    Tomahawk::InfoSystem::PushInfoPair pushInfoPair = pushData.infoPair;
    
    if ( !pushInfoPair.second.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
    {
        tDebug() << Q_FUNC_INFO << "Cannot convert input into an info string hash";
        return;
    }

    Tomahawk::InfoSystem::InfoStringHash info = pushInfoPair.second.value< Tomahawk::InfoSystem::InfoStringHash >();

    QString msg = tr( "Listening to \"%1\" by %2 and loving it! %3" )
                        .arg( info[ "title" ] )
                        .arg( info[ "artist" ] )
                        .arg( pushInfoPair.first.contains( "shorturl" ) ?
                                pushInfoPair.first[ "shorturl" ].toUrl().toString() :
                                GlobalActionManager::instance()->openLink( info[ "title" ], info[ "artist" ], info[ "album" ] ).toString() );

    QTweetStatusUpdate *statUpdate = new QTweetStatusUpdate( m_twitterAuth.data(), this );
    connect( statUpdate, SIGNAL( postedStatus(const QTweetStatus &) ), SLOT( postLovedStatusUpdateReply(const QTweetStatus &) ) );
    connect( statUpdate, SIGNAL( error(QTweetNetBase::ErrorCode, const QString&) ), SLOT( postLovedStatusUpdateError(QTweetNetBase::ErrorCode, const QString &) ) );
    tDebug() << Q_FUNC_INFO << "Posting message: " << msg;
    statUpdate->post( msg );
}
Exemplo n.º 3
0
void MainWindow::statusUpdateFinished(const QTweetStatus &status)
{
    QTweetStatusUpdate *statusUpdate = qobject_cast<QTweetStatusUpdate*>(sender());
    if (statusUpdate) {
        qDebug() << "Sended status with id: " << status.id();

        statusUpdate->deleteLater();
    }
}
Exemplo n.º 4
0
void
TwitterConfigWidget::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user )
{
    if ( user.id() == 0 )
    {
        QMessageBox::critical( this, tr("Tweetin' Error"), tr("Your saved credentials could not be verified.\nYou may wish to try re-authenticating.") );
        emit twitterAuthed( false );
        return;
    }
    TomahawkSettings* s = TomahawkSettings::instance();
    s->setTwitterScreenName( user.screenName() );
    TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this );
    twitAuth->setNetworkAccessManager( TomahawkUtils::nam() );
    twitAuth->setOAuthToken( s->twitterOAuthToken().toLatin1() );
    twitAuth->setOAuthTokenSecret( s->twitterOAuthTokenSecret().toLatin1() );
    if ( m_postGTtype != "Direct Message" )
    {
        QTweetStatusUpdate *statUpdate = new QTweetStatusUpdate( twitAuth, this );
        connect( statUpdate, SIGNAL( postedStatus(const QTweetStatus &) ), SLOT( postGotTomahawkStatusUpdateReply(const QTweetStatus &) ) );
        connect( statUpdate, SIGNAL( error(QTweetNetBase::ErrorCode, const QString&) ), SLOT( postGotTomahawkStatusUpdateError(QTweetNetBase::ErrorCode, const QString &) ) );
        QString uuid = QUuid::createUuid();
        QString message = QString( "Got Tomahawk? {" ) + Database::instance()->dbid() + QString( "} (" ) + uuid.mid( 1, 8 ) + QString( ")" ) + QString( " http://gettomahawk.com" );
        if ( m_postGTtype == "@Mention" )
        {
            QString user = ui->twitterUserTweetLineEdit->text();
            if ( user.startsWith( "@" ) )
                user.remove( 0, 1 );
            message = QString( "@" ) + user + QString( " " ) + message;
        }
        statUpdate->post( message );
    }
    else
    {
        QTweetDirectMessageNew *statUpdate = new QTweetDirectMessageNew( twitAuth, this );
        connect( statUpdate, SIGNAL( parsedDirectMessage(const QTweetDMStatus &)), SLOT( postGotTomahawkDirectMessageReply(const QTweetDMStatus &) ) );
        connect( statUpdate, SIGNAL( error(QTweetNetBase::ErrorCode, const QString&) ), SLOT( postGotTomahawkStatusUpdateError(QTweetNetBase::ErrorCode, const QString &) ) );
        QString uuid = QUuid::createUuid();
        QString message = QString( "Got Tomahawk? {" ) + Database::instance()->dbid() + QString( "} (" ) + uuid.mid( 1, 8 ) + QString( ")" ) + QString( " http://gettomahawk.com" );
        QString user = ui->twitterUserTweetLineEdit->text();
        if ( user.startsWith( "@" ) )
            user.remove( 0, 1 );
        statUpdate->post( user, message );
    }
}
Exemplo n.º 5
0
void
TwitterConfigWidget::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user )
{
    if ( user.id() == 0 )
    {
        QMessageBox::critical( 0, QString("Tweetin' Error"), QString("Your saved credentials could not be verified.\nYou may wish to try re-authenticating.") );
        return;
    }
    TomahawkSettings* s = TomahawkSettings::instance();
    s->setTwitterScreenName( user.screenName() );
    TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this );
    twitAuth->setNetworkAccessManager( TomahawkUtils::nam() );
    twitAuth->setOAuthToken( s->twitterOAuthToken().toLatin1() );
    twitAuth->setOAuthTokenSecret( s->twitterOAuthTokenSecret().toLatin1() );
    QTweetStatusUpdate *statUpdate = new QTweetStatusUpdate( twitAuth, this );
    connect( statUpdate, SIGNAL( postedStatus(const QTweetStatus &) ), SLOT( postGotTomahawkStatusUpdateReply(const QTweetStatus &) ) );
    connect( statUpdate, SIGNAL( error(QTweetNetBase::ErrorCode, const QString&) ), SLOT( postGotTomahawkStatusUpdateError(QTweetNetBase::ErrorCode, const QString &) ) );
    QString uuid = QUuid::createUuid();
    statUpdate->post( QString( "Got Tomahawk? {" ) + Database::instance()->dbid() + QString( "} (" ) + uuid.mid( 1, 8 ) + QString( ")" ) );
}
Exemplo n.º 6
0
void
TwitterInfoPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )
{
    tDebug() << Q_FUNC_INFO;
    if ( !isValid() )
    {
        tDebug() << Q_FUNC_INFO << "Plugin not valid, deleting and returning";
        deleteLater();
        return;
    }

    Tomahawk::InfoSystem::PushInfoPair pushInfoPair = pushData.infoPair;

    if ( !pushInfoPair.second.canConvert< QVariantMap >() )
    {
        tLog() << Q_FUNC_INFO << "Failed to find QVariantMap!";
        return;
    }

    QVariantMap map = pushInfoPair.second.toMap();

    if ( !map.contains( "accountlist" ) || !map[ "accountlist" ].canConvert< QStringList >() )
    {
        tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Cowardly failing to send out a message without an account list present";
        return;
    }

    const QStringList accountList = map[ "accountlist" ].toStringList();
    if ( !accountList.contains( "all" ) && !accountList.contains( m_account->accountId() ) )
    {
        tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Our account not in the list, not tweeting out";
        return;
    }

    if ( !map.contains( "message" ) && ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) )
    {
        tLog() << Q_FUNC_INFO << "Failed to find message or trackinfo";
        return;
    }

    Tomahawk::InfoSystem::InfoStringHash info;
    QString msg;
    if ( !map.contains( "message" ) )
    {
        info = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >();
        msg = tr( "Listening to \"%1\" by %2 and loving it! %3" )
                .arg( info[ "title" ] )
                .arg( info[ "artist" ] )
                .arg( pushInfoPair.first.contains( "shorturl" ) ?
                        pushInfoPair.first[ "shorturl" ].toUrl().toString() :
                        GlobalActionManager::instance()->openLink( info[ "title" ], info[ "artist" ], info[ "album" ] ).toString() );
    }
    else
        msg = map[ "message" ].toString();

    QTweetStatusUpdate *statUpdate = new QTweetStatusUpdate( m_twitterAuth.data(), this );
    connect( statUpdate, SIGNAL( postedStatus(const QTweetStatus &) ), SLOT( postLovedStatusUpdateReply(const QTweetStatus &) ) );
    connect( statUpdate, SIGNAL( error(QTweetNetBase::ErrorCode, const QString&) ), SLOT( postLovedStatusUpdateError(QTweetNetBase::ErrorCode, const QString &) ) );
    tDebug() << Q_FUNC_INFO << "Posting message:" << msg;
    statUpdate->post( msg );
}