#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGlobal>
#include <QDebug>
#include <QMessageBox>
#include "fbrequest.h"
#include "fberror.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow),
iLoginDialog ( NULL )
{
ui->setupUi(this);
iFBSession
= FBSession
::sessionForApplication("xxxxxxxxxxx",
"xxxxxxxxxxx",
QString());
connect (iFBSession,SIGNAL(sessionDidLogin(FBUID)), this, SLOT(sessionDidLogin(FBUID)));
connect (iFBSession, SIGNAL(sessionDidLogout()), this, SLOT(sessionDidLogout()));
}
MainWindow::~MainWindow()
{
delete iFBSession;
delete ui;
}
void MainWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::on_pushButton_clicked()
{
if (iFBSession->resume() == false)
{
iLoginDialog = new FBLoginDialog();
iLoginDialog->show();
}
}
void MainWindow::sessionDidLogin(FBUID aUid)
{
QString msg
("Logged in sucessfully, your FBUID is " + UserId
);
msgbox.setText(msg);
msgbox.exec();
if (iLoginDialog)
{
iLoginDialog->deleteLater();;
iLoginDialog = NULL;
}
}
void MainWindow::sessionDidLogout()
{
msgbox.setText("logged out");
msgbox.exec();
}
void MainWindow::on_pushButton_2_clicked()
{
FBRequest* request = FBRequest::request();
Dictionary params;
QString query
= "select name,pic_big, status,birthday_date, timezone from user where uid in (select uid2 from friend where uid1==" +UserId
+ ")";
params["query"] = query;
connect (request,
SIGNAL(requestDidLoad
(QVariant)),
this,
SLOT(requestDidLoad
(QVariant)));
connect (request, SIGNAL(requestFailedWithFacebookError(FBError)), this, SLOT(requestFailedWithFacebookError(FBError)));
request->call("facebook.fql.query",params);
}
void MainWindow::requestFailedWithFacebookError ( const FBError& aError )
{
qDebug() << "facebook error is " << aError.code() << " - " << aError.description();
}
void MainWindow::requestDidLoad(const QVariant& aContainer)
{
if (aContainer.
type() == QVariant::List) {
QVariantList list = aContainer.toList();
for (int i = 0 ; i < list.count(); i ++)
{
QVariantHash dictionary = list.at(i).toHash();
QHashIterator<QString, QVariant> iterator(dictionary);
QString name
= dictionary.
value("name").
toString();
ui->listWidget->addItem(name);
}
sender()->deleteLater();
}
}
void MainWindow::on_buttonForget_clicked()
{
iFBSession->logout();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGlobal>
#include <QDebug>
#include <QMessageBox>
#include "fbrequest.h"
#include "fberror.h"
static QString UserId;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
iLoginDialog ( NULL )
{
ui->setupUi(this);
iFBSession = FBSession::sessionForApplication("xxxxxxxxxxx","xxxxxxxxxxx", QString());
connect (iFBSession,SIGNAL(sessionDidLogin(FBUID)), this, SLOT(sessionDidLogin(FBUID)));
connect (iFBSession, SIGNAL(sessionDidLogout()), this, SLOT(sessionDidLogout()));
}
MainWindow::~MainWindow()
{
delete iFBSession;
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::on_pushButton_clicked()
{
if (iFBSession->resume() == false)
{
iLoginDialog = new FBLoginDialog();
iLoginDialog->show();
}
}
void MainWindow::sessionDidLogin(FBUID aUid)
{
QMessageBox msgbox;
UserId = QString::number(aUid,10);
QString msg ("Logged in sucessfully, your FBUID is " + UserId);
msgbox.setText(msg);
msgbox.exec();
if (iLoginDialog)
{
iLoginDialog->deleteLater();;
iLoginDialog = NULL;
}
}
void MainWindow::sessionDidLogout()
{
QMessageBox msgbox;
msgbox.setText("logged out");
msgbox.exec();
}
void MainWindow::on_pushButton_2_clicked()
{
FBRequest* request = FBRequest::request();
Dictionary params;
QString query = "select name,pic_big, status,birthday_date, timezone from user where uid in (select uid2 from friend where uid1==" +UserId+ ")";
params["query"] = query;
connect (request, SIGNAL(requestDidLoad(QVariant)), this, SLOT(requestDidLoad(QVariant)));
connect (request, SIGNAL(requestFailedWithFacebookError(FBError)), this, SLOT(requestFailedWithFacebookError(FBError)));
request->call("facebook.fql.query",params);
}
void MainWindow::requestFailedWithFacebookError ( const FBError& aError )
{
qDebug() << "facebook error is " << aError.code() << " - " << aError.description();
}
void MainWindow::requestDidLoad(const QVariant& aContainer)
{
if (aContainer.type() == QVariant::List)
{
QVariantList list = aContainer.toList();
for (int i = 0 ; i < list.count(); i ++)
{
QVariantHash dictionary = list.at(i).toHash();
QHashIterator<QString, QVariant> iterator(dictionary);
QString name = dictionary.value("name").toString();
ui->listWidget->addItem(name);
}
sender()->deleteLater();
}
}
void MainWindow::on_buttonForget_clicked()
{
iFBSession->logout();
}
To copy to clipboard, switch view to plain text mode
#-------------------------------------------------
#
# Project created by QtCreator 2009-11-20T00:54:21
#
#-------------------------------------------------
QT += network webkit xml
TARGET = sample
TEMPLATE = app
DESTDIR = ../debug
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH = ../inc/
win32:LIBS += ../debug/qfacebookconnect.lib
unix:LIBS += ../debug/libqfacebookconnect.so
symbian: {
TARGET.CAPABILITY = NetworkServices # Symbian specific, we just need network access
TARGET.UID3 = 0xA89FA522 # Symbian specific, unprotected uid3 from symbiansigned.com
INCLUDEPATH += /epoc32/include/stdapis # this seems to be a bug.
LIBS += -lqfacebookconnect
libqfacebookconnect.sources = qfacebookconnect.dll
libqfacebookconnect.path = \sys\bin
DEPLOYMENT += libqfacebookconnect
}
ICON = gfx/fb.svg
#-------------------------------------------------
#
# Project created by QtCreator 2009-11-20T00:54:21
#
#-------------------------------------------------
QT += network webkit xml
TARGET = sample
TEMPLATE = app
DESTDIR = ../debug
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH = ../inc/
win32:LIBS += ../debug/qfacebookconnect.lib
unix:LIBS += ../debug/libqfacebookconnect.so
symbian: {
TARGET.CAPABILITY = NetworkServices # Symbian specific, we just need network access
TARGET.UID3 = 0xA89FA522 # Symbian specific, unprotected uid3 from symbiansigned.com
INCLUDEPATH += /epoc32/include/stdapis # this seems to be a bug.
LIBS += -lqfacebookconnect
libqfacebookconnect.sources = qfacebookconnect.dll
libqfacebookconnect.path = \sys\bin
DEPLOYMENT += libqfacebookconnect
}
ICON = gfx/fb.svg
To copy to clipboard, switch view to plain text mode
Bookmarks