Ejemplo n.º 1
0
/**
 * Starts authentication by opening the browser
 */
void Authorize::doOAuth()
{
    QUrl url(QString::fromLatin1("https://accounts.google.com/o/oauth2/auth"));
    QUrlQuery urlQuery;
    urlQuery.addQueryItem(QString::fromLatin1("scope"),         m_scope);
    urlQuery.addQueryItem(QString::fromLatin1("redirect_uri"),  m_redirect_uri);
    urlQuery.addQueryItem(QString::fromLatin1("response_type"), m_response_type);
    urlQuery.addQueryItem(QString::fromLatin1("client_id"),     m_client_id);
    urlQuery.addQueryItem(QString::fromLatin1("access_type"),   QString::fromLatin1("offline"));
    url.setQuery(urlQuery);
    qCDebug(KIPIPLUGINS_LOG) << "OAuth URL: " << url;
    QDesktopServices::openUrl(url);

    emit signalBusy(false);

    m_window = new QDialog(QApplication::activeWindow(),0);
    m_window->setModal(true);
    m_window->setWindowTitle(i18n("Google Drive Authorization"));

    QDialogButtonBox* const buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
    QPushButton* const okButton       = buttonBox->button(QDialogButtonBox::Ok);
    okButton->setDefault(true);

    m_window->connect(buttonBox, SIGNAL(accepted()),
                      this, SLOT(slotAccept()));

    m_window->connect(buttonBox, SIGNAL(rejected()),
                      this, SLOT(slotReject()));

    QLineEdit* const textbox      = new QLineEdit();
    QPlainTextEdit* const infobox = new QPlainTextEdit(i18n("Please follow the instructions in the browser. "
                                                            "After logging in and authorizing the application, "
                                                            "copy the code from the browser, paste it in the "
                                                            "textbox below, and click OK."));
    QVBoxLayout* const layout = new QVBoxLayout;
    m_window->setLayout(layout);
    infobox->setReadOnly(true);
    layout->addWidget(infobox);
    layout->addWidget(textbox);
    layout->addWidget(buttonBox);

    m_window->exec();

    if (m_window->result() == QDialog::Accepted && !(textbox->text().isEmpty()))
    {
        qCDebug(KIPIPLUGINS_LOG) << "1";
        m_code = textbox->text();
    }

    if (textbox->text().isEmpty())
    {
        qCDebug(KIPIPLUGINS_LOG) << "3";
        emit signalTextBoxEmpty();
    }

    if (m_code != QString::fromLatin1("0"))
    {
        getAccessToken();
    }
}
Ejemplo n.º 2
0
/** Starts authentication by opening the browser
 */
void Authorize::doOAuth()
{
    KUrl url("https://accounts.google.com/o/oauth2/auth");
    url.addQueryItem("scope",m_scope);
    url.addQueryItem("redirect_uri",m_redirect_uri);
    url.addQueryItem("response_type",m_response_type);
    url.addQueryItem("client_id",m_client_id);
    url.addQueryItem("access_type","offline");
    kDebug() << "OAuth URL: " << url;
    KToolInvocation::invokeBrowser(url.url());

    emit signalBusy(false);

    KDialog* const window         = new KDialog(kapp->activeWindow(),0);
    window->setModal(true);
    window->setWindowTitle(i18n("Google Drive Authorization"));
    window->setButtons(KDialog::Ok | KDialog::Cancel);
    QWidget* const main           = new QWidget(window,0);
    QLineEdit* const textbox      = new QLineEdit();
    QPlainTextEdit* const infobox = new QPlainTextEdit(i18n("Please follow the instructions in the browser. "
                                                            "After logging in and authorizing the application, "
                                                            "copy the code from the browser, paste it in the "
                                                            "textbox below, and click OK."));
    infobox->setReadOnly(true);
    QVBoxLayout* const layout = new QVBoxLayout;
    layout->addWidget(infobox);
    layout->addWidget(textbox);
    main->setLayout(layout);
    window->setMainWidget(main);

    if(window->exec() == QDialog::Accepted && !(textbox->text().isEmpty()))
    {
        kDebug() << "1";
        m_code = textbox->text();
    }

    if(textbox->text().isEmpty())
    {
        kDebug() << "3";
        emit signalTextBoxEmpty();
    }

    if(m_code != "0")
    {
        getAccessToken();
    }
}