void TwitterConfigWidget::authenticateVerifyReply( const QTweetUser &user ) { qDebug() << Q_FUNC_INFO; if ( user.id() == 0 ) { QMessageBox::critical( this, tr("Tweetin' Error"), tr("The credentials could not be verified.\nYou may wish to try re-authenticating.") ); emit twitterAuthed( false ); return; } TomahawkSettings* s = TomahawkSettings::instance(); s->setTwitterScreenName( user.screenName() ); s->setTwitterCachedFriendsSinceId( 0 ); s->setTwitterCachedMentionsSinceId( 0 ); ui->twitterStatusLabel->setText( tr( "Status: Credentials saved for %1" ).arg( s->twitterScreenName() ) ); ui->twitterAuthenticateButton->setText( tr( "De-authenticate" ) ); ui->twitterInstructionsInfoLabel->setVisible( true ); ui->twitterGlobalTweetLabel->setVisible( true ); ui->twitterTweetGotTomahawkButton->setVisible( true ); ui->twitterUserTweetLineEdit->setVisible( true ); ui->twitterTweetComboBox->setVisible( true ); m_plugin->connectPlugin( false ); emit twitterAuthed( true ); }
/** * Load last 100 tweets mentions from database * @reimp */ void MentionsQmlListModel::loadTweetsFromDatabase() { QSqlQuery query; query.prepare("SELECT id, text, screenName, profileImageUrl, userId, created " "FROM status " "WHERE mention = 1 " "ORDER BY id DESC " "LIMIT 100 "); query.exec(); //remove/clear all statuses beginResetModel(); m_statuses.clear(); m_numUnreadTweets = 0; endResetModel(); QList<QTweetStatus> newStatuses; while (query.next()) { QTweetStatus st; st.setId(query.value(0).toLongLong()); st.setText(query.value(1).toString()); //Datetime is stored in UTC QDateTime tempTime = query.value(5).toDateTime(); QDateTime utcTime(tempTime.date(), tempTime.time(), Qt::UTC); st.setCreatedAt(utcTime); QTweetUser userinfo; userinfo.setScreenName(query.value(2).toString()); userinfo.setprofileImageUrl(query.value(3).toString()); userinfo.setId(query.value(4).toInt()); st.setUser(userinfo); newStatuses.append(st); } if (newStatuses.count()) { beginInsertRows(QModelIndex(), 0, newStatuses.count() - 1); m_statuses.append(newStatuses); endInsertRows(); } }
/** * Called when follow user is finished */ void UserInfo::finishedFollowUser(const QTweetUser &user) { QTweetFriendshipCreate *createFriend = qobject_cast<QTweetFriendshipCreate*>(sender()); // append followed user to friends list if (createFriend) { createFriend->deleteLater(); m_friends.append(user.id()); if (m_userinfo.id() == user.id()) { if (!m_isFriend) { m_isFriend = true; emit isFriendChanged(); } } } }
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 ); } }
/** * Called when unfollowin user is finisedh */ void UserInfo::finishedUnfollowUser(const QTweetUser &user) { QTweetFriendshipDestroy *destroyFriend = qobject_cast<QTweetFriendshipDestroy*>(sender()); if (destroyFriend) { destroyFriend->deleteLater(); //remove from friend list m_friends.removeOne(user.id()); //if it's the same user info changed the isFriend property if (m_userinfo.id() == user.id()) { if (m_isFriend) { m_isFriend = false; emit isFriendChanged(); } } } }
void TwitterPlugin::connectAuthVerifyReply( const QTweetUser &user ) { if ( user.id() == 0 ) { qDebug() << "TwitterPlugin could not authenticate to Twitter"; m_isAuthed = false; m_state = Disconnected; m_connectTimer.stop(); m_checkTimer.stop(); m_dmPollTimer.stop(); emit stateChanged( m_state ); } else { qDebug() << "TwitterPlugin successfully authenticated to Twitter as user " << user.screenName(); m_isAuthed = true; if ( !m_twitterAuth.isNull() ) { setTwitterScreenName( user.screenName() ); m_friendsTimeline = QWeakPointer<QTweetFriendsTimeline>( new QTweetFriendsTimeline( m_twitterAuth.data(), this ) ); m_mentions = QWeakPointer<QTweetMentions>( new QTweetMentions( m_twitterAuth.data(), this ) ); m_directMessages = QWeakPointer<QTweetDirectMessages>( new QTweetDirectMessages( m_twitterAuth.data(), this ) ); m_directMessageNew = QWeakPointer<QTweetDirectMessageNew>( new QTweetDirectMessageNew( m_twitterAuth.data(), this ) ); m_directMessageDestroy = QWeakPointer<QTweetDirectMessageDestroy>( new QTweetDirectMessageDestroy( m_twitterAuth.data(), this ) ); connect( m_friendsTimeline.data(), SIGNAL( parsedStatuses(const QList< QTweetStatus > &) ), SLOT( friendsTimelineStatuses(const QList<QTweetStatus> &) ) ); connect( m_mentions.data(), SIGNAL( parsedStatuses(const QList< QTweetStatus > &) ), SLOT( mentionsStatuses(const QList<QTweetStatus> &) ) ); connect( m_directMessages.data(), SIGNAL( parsedDirectMessages(const QList<QTweetDMStatus> &)), SLOT( directMessages(const QList<QTweetDMStatus> &) ) ); connect( m_directMessageNew.data(), SIGNAL( parsedDirectMessage(const QTweetDMStatus &)), SLOT( directMessagePosted(const QTweetDMStatus &) ) ); connect( m_directMessageNew.data(), SIGNAL( error(QTweetNetBase::ErrorCode, const QString &) ), SLOT( directMessagePostError(QTweetNetBase::ErrorCode, const QString &) ) ); connect( m_directMessageDestroy.data(), SIGNAL( parsedDirectMessage(const QTweetDMStatus &) ), SLOT( directMessageDestroyed(const QTweetDMStatus &) ) ); m_state = Connected; emit stateChanged( m_state ); m_connectTimer.start(); m_checkTimer.start(); m_dmPollTimer.start(); QMetaObject::invokeMethod( this, "checkTimerFired", Qt::AutoConnection ); QTimer::singleShot( 20000, this, SLOT( connectTimerFired() ) ); } else { if ( refreshTwitterAuth() )
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( ")" ) ); }
void MainWindow::verifyCredentialsFinished(const QTweetUser& userinfo) { qDebug() << "Verify Credential succesfull"; QTweetAccountVerifyCredentials *tweetVerifyCredentials = qobject_cast<QTweetAccountVerifyCredentials*>(sender()); if (tweetVerifyCredentials) { QSettings settings(QSettings::IniFormat, QSettings::UserScope, "QTwitdget", "QTwitdget"); settings.setValue("oauth_token", m_oauthTwitter->oauthToken()); settings.setValue("oauth_token_secret", m_oauthTwitter->oauthTokenSecret()); settings.setValue("user_id", userinfo.id()); settings.setValue("user_screenname", userinfo.screenName()); m_userId = userinfo.id(); m_userScreenName = userinfo.screenName(); emit userScreenNameChanged(); tweetVerifyCredentials->deleteLater(); startUp(); } }
void TwitterAccount::connectAuthVerifyReply( const QTweetUser &user ) { m_isAuthenticating = false; if ( user.id() == 0 ) { qDebug() << "TwitterAccount could not authenticate to Twitter"; deauthenticate(); } else { tDebug() << "TwitterAccount successfully authenticated to Twitter as user " << user.screenName(); QVariantHash config = configuration(); config[ "screenname" ] = user.screenName(); setConfiguration( config ); sync(); sipPlugin()->connectPlugin(); m_isAuthenticated = true; emit nowAuthenticated( m_twitterAuth, user ); } }
void TwitterInfoPlugin::connectAuthVerifyReply( const QTweetUser &user ) { if ( user.id() == 0 ) { tDebug() << "TwitterInfoPlugin could not authenticate to Twitter" << this; deleteLater(); return; } else { tDebug() << "TwitterInfoPlugin successfully authenticated to Twitter" << this; return; } }
QTweetUser QTweetConvert::jsonObjectToUser(const QJsonObject &jsonObject) { QTweetUser userInfo; userInfo.setId(static_cast<qint64>(jsonObject.value("id").toDouble())); if (jsonObject.contains("name")) { userInfo.setName(jsonObject.value("name").toString()); userInfo.setLocation(jsonObject.value("location").toString()); userInfo.setprofileImageUrl(jsonObject.value("profile_image_url").toString()); userInfo.setCreatedAt(jsonObject.value("created_at").toString()); userInfo.setFavouritesCount(static_cast<int>(jsonObject.value("favourites_count").toDouble())); userInfo.setUrl(jsonObject.value("url").toString()); userInfo.setUtcOffset(static_cast<int>(jsonObject.value("utc_offset").toDouble())); userInfo.setProtected(jsonObject.value("protected").toBool()); userInfo.setFollowersCount(static_cast<int>(jsonObject.value("followers_count").toDouble())); userInfo.setVerified(jsonObject.value("verified").toBool()); userInfo.setGeoEnabled(jsonObject.value("geo_enabled").toBool()); userInfo.setDescription(jsonObject.value("description").toString()); userInfo.setTimezone(jsonObject.value("time_zone").toString()); userInfo.setStatusesCount(static_cast<int>(jsonObject.value("statuses_count").toDouble())); userInfo.setScreenName(jsonObject.value("screen_name").toString()); userInfo.setContributorsEnabled(jsonObject.value("contributors_enabled").toBool()); userInfo.setListedCount(static_cast<int>(jsonObject.value("listed_count").toDouble())); userInfo.setLang(jsonObject.value("lang").toString()); if (jsonObject.contains("status")) { QJsonObject jsonStatusObject = jsonObject.value("status").toObject(); QTweetStatus status = jsonObjectToStatus(jsonStatusObject); userInfo.setStatus(status); } } return userInfo; }