<commit_before>/*
 * Copyright 2013 KanMemo Project.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "tweetdialog.h"
#include "ui_tweetdialog.h"

#include <QtCore/QDebug>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QInputDialog>
#include <QtTwitterAPI/oauth.h>
#include <QtTwitterAPI/status.h>

#include "../KanmusuMemoryTwitter/twitterinfo.h"

class TweetDialog::Private
{
public:
    Private(TweetDialog *parent);

private:
    TweetDialog *q;
    Ui::TweetDialog ui;

public:
    OAuth oauth;
    QString imagePath;
};

TweetDialog::Private::Private(TweetDialog *parent)
    : q(parent)
{
    ui.setupUi(q);

    //表示画像を変更
    connect(q, &TweetDialog::imagePathChanged, ui.screenshot, &QLabel::setPixmap);

    //Ctrl+Enterで送信
    ui.tweetTextEdit->addAction(ui.actionTweet);
    connect(ui.actionTweet, &QAction::triggered, ui.tweetButton, &QPushButton::animateClick);

    connect(ui.reauthButton, &QPushButton::clicked, [this]() {
        //認証開始
        oauth.unauthorize();
        oauth.request_token();
    });

    connect(ui.tweetTextEdit, &QPlainTextEdit::textChanged, [this]() {
        //つぶやきの入力内容が変化した
        int len = ui.tweetTextEdit->toPlainText().length();
        ui.charCountLabel->setText(QString("%1").arg(117 - len));
        ui.tweetButton->setEnabled(len > 0);
    });
    ui.tweetTextEdit->setPlainText(tr(" #kancolle"));

    connect(ui.tweetButton, &QPushButton::clicked, [this]() {
        //認証済みか確認
        if (oauth.state() != OAuth::Authorized) return;

        //画像が指定されてるか
        if(!QFile::exists(imagePath)) return;

        Status status;
//        connect(&status, &Status::loadingChanged, [this](bool loading) {
//            qDebug() << "loadingChanged " << loading;
//            if (loading) {
//                q->setEnabled(false);
//            } else {
//                //消す
//                q->close();
//            }
//        });
        QVariantMap map;
        map.insert("status", ui.tweetTextEdit->toPlainText());
        map.insert("media", QStringList() << imagePath);
        status.statusesUpdate(map);
        //消す（仮）
        q->close();
    });

    //OAuth
    connect(&oauth, &OAuth::stateChanged, [this](OAuth::State state) {
        switch (state) {
        case OAuth::RequestTokenReceived: {
    //        qDebug() << "RequestTokenReceived:";
    //        qDebug() << "   token:" << m_oauth.token();
    //        qDebug() << "   tokenSecret:" << m_oauth.tokenSecret();

            //PINを取得しにブラウザを開く
            oauth.authorize();<commit_msg>wait until sending a tweet complated<commit_after>/*
 * Copyright 2013 KanMemo Project.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "tweetdialog.h"
#include "ui_tweetdialog.h"

#include <QtCore/QDebug>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QInputDialog>
#include <QtTwitterAPI/oauth.h>
#include <QtTwitterAPI/status.h>

#include "../KanmusuMemoryTwitter/twitterinfo.h"

class TweetDialog::Private
{
public:
    Private(TweetDialog *parent);

private:
    TweetDialog *q;
    Ui::TweetDialog ui;

public:
    OAuth oauth;
    QString imagePath;
};

TweetDialog::Private::Private(TweetDialog *parent)
    : q(parent)
{
    ui.setupUi(q);

    //表示画像を変更
    connect(q, &TweetDialog::imagePathChanged, ui.screenshot, &QLabel::setPixmap);

    //Ctrl+Enterで送信
    ui.tweetTextEdit->addAction(ui.actionTweet);
    connect(ui.actionTweet, &QAction::triggered, ui.tweetButton, &QPushButton::animateClick);

    connect(ui.reauthButton, &QPushButton::clicked, [this]() {
        //認証開始
        oauth.unauthorize();
        oauth.request_token();
    });

    connect(ui.tweetTextEdit, &QPlainTextEdit::textChanged, [this]() {
        //つぶやきの入力内容が変化した
        int len = ui.tweetTextEdit->toPlainText().length();
        ui.charCountLabel->setText(QString("%1").arg(117 - len));
        ui.tweetButton->setEnabled(len > 0);
    });
    ui.tweetTextEdit->setPlainText(tr(" #kancolle"));

    connect(ui.tweetButton, &QPushButton::clicked, [this]() {
        //認証済みか確認
        if (oauth.state() != OAuth::Authorized) return;

        //画像が指定されてるか
        if(!QFile::exists(imagePath)) return;

        Status *status = new Status(q);
        connect(status, &Status::loadingChanged, [this](bool loading) {
            if (loading) {
                q->setEnabled(false);
            } else {
                //消す
                q->accept();
            }
        });
        QVariantMap map;
        map.insert("status", ui.tweetTextEdit->toPlainText());
        map.insert("media", QStringList() << imagePath);
        status->statusesUpdate(map);
    });

    //OAuth
    connect(&oauth, &OAuth::stateChanged, [this](OAuth::State state) {
        switch (state) {
        case OAuth::RequestTokenReceived: {
    //        qDebug() << "RequestTokenReceived:";
    //        qDebug() << "   token:" << m_oauth.token();
    //        qDebug() << "   tokenSecret:" << m_oauth.tokenSecret();

            //PINを取得しにブラウザを開く
            oauth.authorize();
{'fraction_non_alphanumeric': 0.14231215790346657, 'fraction_numerical': 0.004312489633438381, 'mean_word_length': 2.8261421319796955, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7611033', 'n_tokens_mistral': 1992, 'n_tokens_neox': 1948, 'n_words': 407}