Skip to content

Instantly share code, notes, and snippets.

@dio
Created May 2, 2011 00:02
Show Gist options
  • Select an option

  • Save dio/951010 to your computer and use it in GitHub Desktop.

Select an option

Save dio/951010 to your computer and use it in GitHub Desktop.
// checksum 0xa193 version 0x30001
/*
This file was generated by the Mobile Qt Application wizard of Qt Creator.
MainWindow is a convenience class containing mobile device specific code
such as screen orientation handling.
It is recommended not to modify this file, since newer versions of Qt Creator
may offer an updated version of it.
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtCore/QCoreApplication>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
nam = new QNetworkAccessManager(this);
connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
connect(nam,SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::setOrientation(ScreenOrientation orientation)
{
#if defined(Q_OS_SYMBIAN)
// If the version of Qt on the device is < 4.7.2, that attribute won't work
if (orientation != ScreenOrientationAuto) {
const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
return;
}
}
#endif // Q_OS_SYMBIAN
Qt::WidgetAttribute attribute;
switch (orientation) {
#if QT_VERSION < 0x040702
// Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
case ScreenOrientationLockPortrait:
attribute = static_cast<Qt::WidgetAttribute>(128);
break;
case ScreenOrientationLockLandscape:
attribute = static_cast<Qt::WidgetAttribute>(129);
break;
default:
case ScreenOrientationAuto:
attribute = static_cast<Qt::WidgetAttribute>(130);
break;
#else // QT_VERSION < 0x040702
case ScreenOrientationLockPortrait:
attribute = Qt::WA_LockPortraitOrientation;
break;
case ScreenOrientationLockLandscape:
attribute = Qt::WA_LockLandscapeOrientation;
break;
default:
case ScreenOrientationAuto:
attribute = Qt::WA_AutoOrientation;
break;
#endif // QT_VERSION < 0x040702
};
setAttribute(attribute, true);
}
void MainWindow::showExpanded()
{
#ifdef Q_OS_SYMBIAN
showFullScreen();
#elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
showMaximized();
#else
show();
#endif
}
void MainWindow::on_pushButton_clicked()
{
QNetworkRequest request;
request.setUrl(QUrl("https://api.sajiansedap.com/recipes/list/category/Kue/limit/10/offset/0/lang/id"));
QString concatenated = "ss_client:s4jIeN--zeD4Ap";
QByteArray data = concatenated.toLocal8Bit().toBase64();
QString headerData = "Basic " + data;
request.setRawHeader("Authorization", headerData.toLocal8Bit());
nam->get(request);
qDebug() << "get request";
iTime.restart();
}
void MainWindow::finished(QNetworkReply *reply)
{
qDebug() << "finished";
qDebug() << reply->readAll();
qDebug() << "s: " << iTime.elapsed() * 1.0/1000 << "seconds";
}
void MainWindow::sslErrors(QNetworkReply * r, QList<QSslError> l)
{
qDebug() << "ssl error";
r->ignoreSslErrors();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment