Exemplo n.º 1
0
Arquivo: o2gft.cpp Projeto: Sky/o2
void O2Gft::onTokenReplyFinished()
{
    qDebug() << "O2Gft::onTokenReplyFinished";

    QNetworkReply *tokenReply = qobject_cast<QNetworkReply *>(sender());
    if (tokenReply->error() == QNetworkReply::NoError) {
        QByteArray replyData = tokenReply->readAll();
        QScriptEngine engine;
        QScriptValueIterator it(engine.evaluate("(" + QString(replyData) + ")"));
        QVariantMap tokens;

        while (it.hasNext()) {
            it.next();
            tokens.insert(it.name(), it.value().toVariant());
        }

        // Check for mandatory tokens
        if (tokens.contains(O2_OAUTH2_ACCESS_TOKEN)) {
            setToken(tokens.take(O2_OAUTH2_ACCESS_TOKEN).toString());

            //
            setIdToken(tokens.take(O2_OAUTH2_ID_TOKEN).toString());

            //
            bool ok = false;
            int expiresIn = tokens.take(O2_OAUTH2_EXPIRES_IN).toInt(&ok);
            if (ok) {
                qDebug() << "Token expires in" << expiresIn << "seconds";
                setExpires(QDateTime::currentMSecsSinceEpoch() / 1000 + expiresIn);
            }
            setRefreshToken(tokens.take(O2_OAUTH2_REFRESH_TOKEN).toString());
            // Set extra tokens if any
            if (!tokens.isEmpty()) {
                setExtraTokens(tokens);
            }
            timedReplies_.remove(tokenReply);
            emit linkedChanged();
            emit tokenChanged();
            emit linkingSucceeded();
        } else {
            qWarning() << "O2::onTokenReplyFinished: oauth_token missing from response" << replyData;
            emit linkedChanged();
            emit tokenChanged();
            emit linkingFailed();
        }
    }
    tokenReply->deleteLater();
}
Exemplo n.º 2
0
YoutubeController::YoutubeController(QObject *parent): QObject(parent),
    commentsTimerId_(0),
    updateMessagesIntervalMs_(DEFAULT_YOUTUBE_UPDATE_MESSAGES_INTERVAL_MS),
    liveChatId_("")
{
    o2youtube_ = new O2Youtube(this);

    o2youtube_->setClientId("463300085238-11h8th4cbl9uoi4rd8pcl0e19sspn1s8.apps.googleusercontent.com");
    o2youtube_->setClientSecret("PZE0m3Ym4lZRKWDWk6KQ9c7T");

    
    connect(o2youtube_, SIGNAL(linkedChanged()), this, SLOT(onLinkedChanged()));
    connect(o2youtube_, SIGNAL(linkingFailed()), this, SLOT(onLinkingFailed()));
    connect(o2youtube_, SIGNAL(linkingSucceeded()), this, SLOT(onLinkingSucceeded()));
    connect(o2youtube_, SIGNAL(openBrowser(QUrl)), this, SLOT(onOpenBrowser(QUrl)));
    connect(o2youtube_, SIGNAL(closeBrowser()), this, SLOT(onCloseBrowser()));

    api_ = new YoutubeApi(this);
    connect(api_, SIGNAL(broadcastModelChanged()),this, SLOT(broadcastModelChanged()));
    connect(api_, SIGNAL(commentModelChanged()),this, SLOT(commentModelChanged()));
}
Exemplo n.º 3
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    //set up ui
    ui->setupUi(this);

    listModel= new QStandardItemModel(ui->listView);
    ui->listView->setModel(listModel);

    treeModel = new QStandardItemModel(ui->treeView);
    ui->treeView->setModel(treeModel);

    listMenu = new QMenu(this);
    treeMenu = new QMenu("TreeMenu",this);

    setting = new QSettings("my","feeder",this);
    subDialog = new SubscribeDialog(this);

    markArticleAsRead = new QAction("Mark As Read",this);
    markArticleAsUnread = new QAction("Mark As Unread",this);
    markFeedAllAsRead = new QAction("Mark All As Read",this);
    markCategoryAllAsRead = new QAction("Mark All As Read",this);
    //set up oauth2
    o2 = new O2(this);
    nam = new QNetworkAccessManager(this);
    o2req = new O2Requestor(nam,o2,this);
    o2->setClientId(CLIENT_ID);
    o2->setClientSecret(CLIENT_SECRET);
    o2->setRequestUrl(REQUEST_URL);
    o2->setTokenUrl(TOKEN_URL);
    o2->setScope(SCOPE);
    o2->setLocalPort(8080);
    o2->setRefreshTokenUrl(REFRESH_TOKEN_URL);

    store = new O2SettingsStore(setting,"myfeederkey",this);
    store->setGroupKey("OAuth");
    o2->setStore(store);

    //If we've already logged in, we can get userId and plan from
    //the local setting storage
    userId = store->value("id");
    plan = store->value("plan");
    qDebug() << userId<< plan;

    //We do the linking to log in. If we've already logged in,
    //it won't hurt any way.
    o2->link();

    //connect
    connect(o2, SIGNAL(linkedChanged()), this, SLOT(onLinkedChanged()));
    connect(o2, SIGNAL(linkingFailed()), this, SLOT(onLinkingFailed()));
    connect(o2, SIGNAL(linkingSucceeded()), this, SLOT(onLinkingSucceeded()));
    connect(o2, SIGNAL(openBrowser(QUrl)), this, SLOT(onOpenBrowser(QUrl)));
    connect(o2,SIGNAL(tokenChanged()),this,SLOT(onTokenChanged()));
    connect(ui->treeView,SIGNAL(clicked(QModelIndex)),this,SLOT(on_treeView_clicked(QModelIndex)));
    connect(o2req,SIGNAL(finished(int,QNetworkReply::NetworkError,QByteArray)),this,SLOT(onReqFinished(int,QNetworkReply::NetworkError,QByteArray)));
    connect(ui->listView,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(on_listView_customContextMenuRequested(QPoint)));
    connect(subDialog,SIGNAL(accepted()),this,SLOT(on_subscibe()));
    connect(listMenu,SIGNAL(triggered(QAction*)),this,SLOT(on_listView_menu_triggered(QAction*)));
    connect(treeMenu,SIGNAL(triggered(QAction*)),this,SLOT(on_treeView_menu_triggered(QAction*)));
    reqCategories();
}