char*
get_execution_id(const char *URL, char *message)
{
    if (strlen(execution_id) > 0) {
        return execution_id;
    }

    if (!check_URL(URL) || !check_message(message)) {
        return '\0';
    }

    if (!prepare_publish(URL, message)) {
        return '\0';
    }

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, get_stream_data);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &execution_id);

    CURLcode response = curl_easy_perform(curl);
    if (response != CURLE_OK) {
        const char *error_msg = curl_easy_strerror(response);
        log_error("publish(const char*, Message) %s", error_msg);
    }

    debug("get_execution_id(const char*, char*) Execution_ID = <%s>", execution_id);

    curl_easy_reset(curl);

    return execution_id;
}
int
query(const char* query, char* received_data)
{
    int result = SEND_SUCCESS;
    struct string response_message;

    if (!check_URL(query)) {
        return 0;
    }

    if (!prepare_query(query)) {
        return 0;
    }

    init_string(&response_message);

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, response_message);

    CURLcode response = curl_easy_perform(curl);
    if (response != CURLE_OK) {
        result = SEND_FAILED;
        const char *error_msg = curl_easy_strerror(response);
        log_error("query(const char*, char*) %s", error_msg);
    }

    received_data = (char*) realloc (received_data, response_message.len);
    received_data = response_message.ptr;

    curl_easy_reset(curl);

    return result;
}
char*
publish_json(const char *URL, const char *message)
{
    if (!check_URL(URL) || !check_message(message)) {
        return 0;
    }

    if (!prepare_publish(URL, message)) {
        return 0;
    }

    char* response_message = (char *)malloc(sizeof(char) * 1024);
    memset(response_message, 0x00, 1024);

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, get_stream_data);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, response_message);

    CURLcode response = curl_easy_perform(curl);
    if (response != CURLE_OK) {
        const char *error_msg = curl_easy_strerror(response);
        log_error("publish(const char*, Message) %s", error_msg);
    }

    debug("URL %s + RESPONSE: %s", URL, response_message);
    curl_easy_reset(curl);

    return response_message;
}
MainWindow::MainWindow(QWidget *parent):
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    oauth = new OAuth();
    oauth->audioManager->show();
    //downloader = new Downloader();


    this->showStartPage();

    QObject::connect(ui->webView,SIGNAL(urlChanged(QUrl)),oauth,SLOT(check_URL(QUrl)));//изменение урла страницы сохранит токен в oauth.token
    QObject::connect(this->oauth,SIGNAL(oauthSuccess()),this,SLOT(afterSuccessOaouth()));

//    QObject::connect(oauth->audioManager,SIGNAL(sendTrackListToDownloadThread(QList<Track>)),
//            oauth->audioManager->downloadqueue->downloadthread,
//            SLOT(updateTrackList(QList<Track>)));

}