Skip to content
Browse files

Work on converting to use the Graph API. At the moment logging in and…

… viewing simple newsfeed works.
  • Loading branch information...
1 parent a825d06 commit b3bec61df467da1a23f02dfe267ed1914683223e Kamilla Bremeraunet committed Feb 17, 2011
Showing with 828 additions and 98 deletions.
  1. +14 −4 facebrick.pro
  2. +17 −4 include/facebrick.h
  3. +203 −0 include/fbdialog.h
  4. +52 −0 include/fblogindialog.h
  5. +25 −14 src/facebrick.cpp
  6. +313 −0 src/fbdialog.cpp
  7. +115 −0 src/fblogindialog.cpp
  8. +11 −13 src/main.cpp
  9. +6 −3 src/mainwindow.cpp
  10. +72 −60 src/mainwindow_newsfeed.cpp
View
18 facebrick.pro
@@ -24,7 +24,10 @@ SOURCES += src/main.cpp\
src/newsfeedpostview_likedislike.cpp \
src/facebrick.cpp \
src/newsfeedpostattachment.cpp \
- src/settingsdialog.cpp
+ src/settingsdialog.cpp \
+ src/getconnection.cpp \
+ src/fblogindialog.cpp \
+ src/fbdialog.cpp
HEADERS += include/mainwindow.h \
include/newsfeedmodel.h \
@@ -34,13 +37,22 @@ HEADERS += include/mainwindow.h \
include/newsfeeddelegate.h \
include/newsfeedpostview.h \
include/facebrick.h \
- include/settingsdialog.h
+ include/settingsdialog.h \
+ include/graphapi.h \
+ include/getconnection.h \
+ include/fblogindialog.h \
+ include/fbdialog.h
FORMS += src/ui/mainwindow.ui \
src/ui/newsfeedpostview.ui \
src/ui/settingsdialog.ui
+INCLUDEPATH += ../qfacebook/src
+INCLUDEPATH += include/
+win32:LIBS += ../qfacebook/lib/libqfacebook.a
+unix:LIBS += ../qfacebook/lib/libqfacebook.so
+
INCLUDEPATH += ../libqfacebook/inc/
INCLUDEPATH += include/
win32:LIBS += ../libqfacebook/debug/libqfacebookconnect.a
@@ -57,6 +69,4 @@ maemo5:* {
icon.files += facebrick.png
}
-
-
INSTALLS += target
View
21 include/facebrick.h
@@ -19,27 +19,40 @@
#define FACEBRICK_H
#include <QObject>
+
class QNetworkAccessManager;
class FBSession;
class FBError;
+class GetConnection;
+class QFacebook;
class FaceBrick : public QObject
{
Q_OBJECT
public:
- static FaceBrick *instance(FBSession *session);
+ static FaceBrick *instance(QString client_id, QString client_secret);
static FaceBrick *instance();
+ void setToken(QString token);
+ QString getToken();
+ QString *getClientId();
+ void createConnection();
+
QNetworkAccessManager *networkManager() const;
- FBSession *session() const;
+ GetConnection *m_connection;
+ QFacebook *m_facebook;
+ QString *m_clientId;
+ QString *m_clientSecret;
+ QString m_token;
private slots:
void unableToGetStreamRead();
void errorRequestingPermission(const FBError &error);
private:
- FaceBrick(FBSession *session);
+ FaceBrick(QString client_id, QString client_secret);
QNetworkAccessManager * const m_networkAccessManager;
- FBSession * const m_session;
+ //FBSession * const m_session;
+
};
#endif // FACEBRICK_H
View
203 include/fbdialog.h
@@ -0,0 +1,203 @@
+/*
+ * 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.
+*/
+
+#ifndef FB_DIALOG_H_
+#define FB_DIALOH_H_
+
+#include <QDialog>
+#include <QWebView>
+
+#include "fbconnectglobal.h"
+
+// FORWARD DECLARATIONS
+class FBSession;
+class FBError;
+class QNetworkReply;
+
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class FBCustomNetworkAccessManagerObserver
+{
+public:
+ virtual void shouldLoadUrl ( const QUrl& aUrl ) = 0;
+};
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Used to handle fbconnect:// scheme !
+ */
+class FBCustomNetworkAccessManager : public QNetworkAccessManager
+{
+ Q_OBJECT
+public:
+ FBCustomNetworkAccessManager() : iObserver(NULL) {}
+ inline void setObserver(FBCustomNetworkAccessManagerObserver* aObserver) { iObserver = aObserver; }
+
+protected:
+ QNetworkReply * createRequest ( Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0 );
+
+ FBCustomNetworkAccessManagerObserver* iObserver;
+
+};
+
+/**
+ * Just used to get some questions answered
+ */
+class QFACEBOOKCONNECTSHARED_EXPORT FBDialogObserver
+{
+public:
+ /**
+ * called to ask the client app if the link clicked in the web page be opened in the system browser app or not.
+ * @param aUrl the url
+ * @return true if you want to open link in the external browser.
+ */
+ virtual bool shouldOpenLinkInExternalBrowser(const QUrl& aUrl) = 0;
+};
+
+/**
+ * The base Dialoggg
+ */
+class QFACEBOOKCONNECTSHARED_EXPORT FBDialog : public QDialog, public FBCustomNetworkAccessManagerObserver
+{
+ Q_OBJECT
+
+protected:
+
+ /**
+ * The session for which the login is taking place.
+ */
+ FBSession* iSession;
+ QWebView iWebView;
+ QString iLoadingUrl;
+ FBDialogObserver* iObserver;
+ bool iIgnorePageLoadCompleteEvent;
+
+signals:
+
+ /**
+ * Called when the dialog succeeds and is about to be dismissed.
+ */
+ void dialogDidSucceed ();
+
+ /**
+ * Called when the dialog is cancelled and is about to be dismissed.
+ */
+ void dialogDidCancel();
+
+ /**
+ * Called when dialog failed to load due to an error.
+ */
+ void dialogDidFailWithError ( const FBError& error );
+
+ /**
+ * Called when facebook has returned a URL with the code needed to grab access token
+ */
+ void codeFound(QUrl& aUrl);
+
+
+
+
+private slots:
+ void cancel();
+
+ /* slots for signals from QWebView.page() */
+ void linkClicked ( const QUrl & url );
+ void loadStarted ();
+ void loadFinished ( bool ok );
+
+public:
+ /**
+ * Creates the view but does not display it.
+ */
+ FBDialog(FBSession* aSession);
+ FBDialog();
+
+ /**
+ * @param aObserver, used to ask questions from client
+ */
+ void setObserver( FBDialogObserver* aObserver );
+
+
+ /**
+ * Displays the view with an animation.
+ *
+ * The view will be added to the top of the current key window.
+ */
+ void show();
+
+ /** Displays the first page of the dialog.
+ *
+ * Do not ever call this directly. It is intended to be overriden by subclasses.
+ */
+ virtual void load ();
+
+ /**
+ * Displays a URL in the dialog.
+ */
+ void loadURL(const QString& aUrl, QNetworkAccessManager::Operation aMethod, const QHash<QString, QString>& aGetParams,
+ const QHash<QString, QString>& aPostParams);
+
+
+ void dismiss(bool aAnimated);
+
+ /**
+ * Hides the view and notifies delegates of success or cancellation.
+ */
+ void dismissWithSuccess (bool aSuccess, bool aAnimated);
+
+ /**
+ * Hides the view and notifies delegates of an error.
+ */
+ void dismissWithError (const FBError& aError, bool aAnimated);
+
+ /**
+ * Subclasses may override to perform actions just prior to showing the dialog.
+ */
+ virtual void dialogWillAppear();
+
+ /**
+ * Subclasses may override to perform actions just after the dialog is hidden.
+ */
+ virtual void dialogWillDisappear();
+
+ /**
+ * Subclasses should override to process data returned from the server in a 'fbconnect' url.
+ *
+ * Implementations must call dismissWithSuccess:YES at some point to hide the dialog.
+ */
+ virtual void dialogDidSucceed(const QUrl& aUrl);
+
+ QString title() const;
+ void setTitle ( const QString& aTitle );
+
+protected:
+ /* from FBCustomNetworkAccessManagerObserver */
+ void shouldLoadUrl (const QUrl& aUrl );
+ void checkForCode(QUrl aUrl);
+
+ QString m_clientId;
+private:
+ void createControls();
+ void placeControls( const QSize & );
+
+ QString generateURL( const QString& aUrl, const QHash<QString, QString>& aParams) const;
+ QByteArray generatePostBody (const QHash<QString, QString>& aParams) const;
+
+ void postDismissCleanup();
+
+ /* called on widget resize */
+ void resizeEvent ( QResizeEvent * event ) ;
+
+ };
+#endif
View
52 include/fblogindialog.h
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+#ifndef FB_LOGIN_DIALOG_H_
+#define FB_LOGIN_DIALOG_H_
+
+#include "fbdialog.h"
+
+#include <QNetworkReply>
+
+// FORWARD DECLARATIONS
+//class FBRequest;
+
+class QFACEBOOKCONNECTSHARED_EXPORT FBLogin : public FBDialog
+{
+ Q_OBJECT
+
+private:
+
+private slots:
+ /* slots for handling signals from FBRequest iGetSessionRequest */
+ void requestDidLoad (const QVariant& aResult);
+
+ void requestFailedWithFacebookError ( const FBError& aError );
+ void requestFailedWithNetworkError( QNetworkReply::NetworkError code );
+
+public:
+ FBLogin(QString clientId);
+
+ void load();
+
+protected:
+ virtual void dialogWillDisappear();
+ virtual void dialogDidSucceed(const QUrl& aUrl);
+
+private:
+ void connectToGetSession(const QString& aToken);
+ void loadLoginPage();
+
+ };
+#endif
View
39 src/facebrick.cpp
@@ -22,14 +22,16 @@
#include "fberror.h"
#include "facebrick.h"
+#include "getconnection.h"
+#include "qfacebook.h"
static FaceBrick *sinstance = NULL;
-FaceBrick *FaceBrick::instance(FBSession *session)
+FaceBrick *FaceBrick::instance(QString client_id, QString client_secret)
{
Q_ASSERT(sinstance == NULL);
- sinstance = new FaceBrick(session);
+ sinstance = new FaceBrick(client_id, client_secret);
return sinstance;
}
@@ -40,29 +42,38 @@ FaceBrick *FaceBrick::instance()
return sinstance;
}
-FaceBrick::FaceBrick(FBSession *session)
+FaceBrick::FaceBrick(QString client_id, QString client_secret)
: QObject(0),
m_networkAccessManager(new QNetworkAccessManager(this)),
- m_session(session)
+ m_clientId(new QString(client_id)),
+ m_clientSecret(new QString(client_secret))
{
- // Request stream_read permissions (needed to show stupid newsfeed, and stupid FB API won't tell us we don't have it.)
- // TODO: it might be nice to investigate if we can check if we have this perm already to avoid showing multiple times.
- // TODO: permission dialog is leaked, see note in constructor
- FBPermissionDialog *d = new FBPermissionDialog(m_session);
- connect(d, SIGNAL(dialogDidCancel()), this, SLOT(unableToGetStreamRead()));
- connect(d, SIGNAL(dialogDidFailWithError(FBError)), this, SLOT(errorRequestingPermission(FBError)));
- d->setPermissionToRequest("read_stream");
- d->show();
}
QNetworkAccessManager *FaceBrick::networkManager() const
{
return m_networkAccessManager;
}
-FBSession *FaceBrick::session() const
+void FaceBrick::setToken(QString token)
{
- return m_session;
+ m_token = token;
+ m_facebook = new QFacebook(token, this);
+}
+
+QString FaceBrick::getToken()
+{
+ return m_token;
+}
+
+QString *FaceBrick::getClientId()
+{
+ return m_clientId;
+}
+
+void FaceBrick::createConnection()
+{
+ m_connection = new GetConnection(0, m_token);
}
void FaceBrick::errorRequestingPermission(const FBError &error)
View
313 src/fbdialog.cpp
@@ -0,0 +1,313 @@
+/*
+ * 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 <QNetworkCookie>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QWebFrame>
+#include <QFile>
+#include <QDesktopServices>
+#include <QResizeEvent>
+#include <QDebug>
+#include <QNetworkAccessManager>
+#include <QPropertyAnimation>
+
+#include "fbdialog.h"
+#include "fberror.h"
+
+static const QString kDefaultTitle = "Connect to Facebook";
+static const QString kStringBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f";
+static const QSize kDefaultDialogSize = QSize(640,320);
+
+static FBCustomNetworkAccessManager namanager;
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Used to handle fbconnect:// scheme !
+
+QNetworkReply* FBCustomNetworkAccessManager::createRequest ( Operation op, const QNetworkRequest & req, QIODevice * outgoingData )
+{
+ if (iObserver)
+ {
+ const QUrl url ( req.url() );
+ iObserver->shouldLoadUrl(url);
+ }
+
+ return QNetworkAccessManager::createRequest( op, req, outgoingData);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+FBDialog::FBDialog() : iWebView ( this ), iObserver ( NULL ), iIgnorePageLoadCompleteEvent( false )
+{
+ createControls();
+}
+
+void FBDialog::setObserver( FBDialogObserver* aObserver )
+{
+ iObserver=aObserver;
+}
+
+
+void FBDialog::createControls()
+{
+ setFixedSize(kDefaultDialogSize);
+ setWindowTitle(kDefaultTitle);
+ namanager.setObserver(this);
+ iWebView.page()->setNetworkAccessManager(&namanager);
+
+ iWebView.page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
+
+ connect( iWebView.page(), SIGNAL(linkClicked(const QUrl &)),
+ this, SLOT(linkClicked(const QUrl &)));
+
+ connect ( iWebView.page(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
+
+ connect ( iWebView.page(), SIGNAL(loadStarted()), this, SLOT ( loadStarted()));
+}
+
+void FBDialog::placeControls(const QSize& /*aSize*/)
+{
+ iWebView.setGeometry(this->rect());
+}
+
+QString FBDialog::generateURL( const QString& aUrl, const QHash<QString, QString>& aParams) const
+{
+ QString url ( aUrl );
+
+ QStringList pairs;
+ QHashIterator<QString, QString> i(aParams);
+
+ while (i.hasNext()) {
+ i.next();
+
+ QUrl url (i.value());
+ QString pair = i.key() + "=" + url.toEncoded();
+ pairs << pair.toUtf8();
+ }
+
+ if (pairs.count())
+ {
+ url = url + "?" + pairs.join("&");
+ }
+
+ return url;
+
+}
+
+QByteArray FBDialog::generatePostBody (const QHash<QString, QString>& aParams) const
+{
+ QByteArray body;
+
+ if (!aParams.count())
+ return body;
+
+
+ QString endLine = "\r\n--" + kStringBoundary + "\r\n", kStringBoundary;
+
+ QString tmp = "--" + kStringBoundary + "\r\n";
+ body.append(tmp);
+
+
+ QHashIterator<QString, QString> i(aParams);
+ while (i.hasNext()) {
+ i.next();
+
+ tmp = "Content-Disposition: form-data; name=\"" + i.key().toUtf8() + "\"\r\n\r\n" ;
+ body.append(tmp);
+ body.append(i.value().toUtf8());
+ body.append(endLine);
+ }
+
+ return body;
+}
+
+void FBDialog::postDismissCleanup()
+{
+ accept();
+ // could also be reject()?
+}
+
+void FBDialog::dismiss (bool /*aAnimated*/) {
+ dialogWillDisappear();
+ iLoadingUrl.clear();
+
+ //todo: do some animations if aAnimated == true !
+ postDismissCleanup();
+}
+
+
+void FBDialog::dismissWithSuccess( bool aSuccess, bool aAnimated)
+{
+ if (aSuccess) {
+ emit dialogDidSucceed();
+ } else {
+ emit dialogDidCancel();
+ }
+
+ dismiss(aAnimated);
+}
+
+void FBDialog::dismissWithError (const FBError& aError, bool aAnimated)
+{
+ emit dialogDidFailWithError( aError );
+ dismiss(aAnimated);
+}
+
+void FBDialog::cancel()
+{}
+
+void FBDialog::load() {}
+
+void FBDialog::show()
+{
+ load();
+ dialogWillAppear();
+
+ int result = exec();
+ qDebug() << result;
+}
+
+void FBDialog::loadURL(const QString& aUrl, QNetworkAccessManager::Operation aMethod, const QHash<QString, QString>& aGetParams, const QHash<QString, QString>& aPostParams)
+{
+ iIgnorePageLoadCompleteEvent = false;
+
+ QNetworkCookieJar* cookieJar = iWebView.page()->networkAccessManager()->cookieJar();
+ QByteArray body;
+
+ iLoadingUrl = generateURL(aUrl, aGetParams);
+
+ // This "test cookie" is required by login.php, or it complains that you need to enable JavaScript
+ QNetworkCookie testCookie ("test_cookie", "1");
+ testCookie.setDomain ( ".facebook.com" );
+ testCookie.setPath ( "/" );
+
+ QList<QNetworkCookie> cookieList;
+ cookieList.append(testCookie);
+
+ cookieJar->setCookiesFromUrl ( cookieList, QUrl(iLoadingUrl) );
+
+ QUrl url (iLoadingUrl);
+ QNetworkRequest request(url);
+
+#if QT_VERSION >= 0x040600
+ request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
+#endif
+
+ if (aMethod == QNetworkAccessManager::PostOperation)
+ {
+ const QString contentType = "multipart/form-data; boundary=" + kStringBoundary;
+ request.setHeader (QNetworkRequest::ContentTypeHeader, contentType);
+ body = generatePostBody (aPostParams);
+ }
+
+ iWebView.load ( request, aMethod, body);
+
+ qDebug() << "Loading url: " << iLoadingUrl;
+}
+
+void FBDialog::dialogWillAppear() {}
+
+void FBDialog::dialogWillDisappear() {}
+
+void FBDialog::dialogDidSucceed (const QUrl& /*aUrl*/) {
+ dismissWithSuccess(true,true);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void FBDialog::resizeEvent ( QResizeEvent * event )
+{
+ placeControls(event->size());
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+void FBDialog::linkClicked ( const QUrl & url )
+ {
+ if (iObserver && iObserver->shouldOpenLinkInExternalBrowser(url))
+ {
+ qDebug() << "Opening the link in external browser: " << url;
+ QDesktopServices::openUrl(url);
+ }
+ else
+ {
+ qDebug() << "Loading the url: " << url;
+ iWebView.load(url);
+ }
+}
+
+void FBDialog::loadStarted()
+{
+ qDebug() << "Load started: " << iWebView.url();
+
+ qDebug() << iWebView.url().hasQueryItem("code");
+ //QString code = iWebView.url().queryItemValue("code");
+ //qDebug() << code;
+}
+
+void FBDialog::loadFinished ( bool ok )
+{
+ qDebug() << "Load " << (ok ? "" : "un") << "successfull for: " << iWebView.url();
+
+ checkForCode(iWebView.url());
+
+ if (iWebView.url().hasQueryItem("code"))
+ iIgnorePageLoadCompleteEvent = true;
+
+ if (ok)
+ {
+ setWindowTitle( iWebView.page()->mainFrame()->title() );
+ }
+ else
+ {
+ if (iIgnorePageLoadCompleteEvent)
+ return;
+
+ // FBError err;
+ // dismissWithError(err, true);
+ }
+}
+
+void FBDialog::shouldLoadUrl ( const QUrl& aUrl )
+{
+ if (aUrl.hasFragment()) {
+ qDebug() << "LOL";
+ dialogDidSucceed(aUrl);
+ }
+ if (aUrl.scheme().compare("access_token") == 0)
+ {
+ const QString encodedPath ( aUrl.encodedPath());
+ if (encodedPath.compare("cancel")==0)
+ {
+ dismissWithSuccess(false, true);
+ }
+ else
+ {
+ iIgnorePageLoadCompleteEvent = true;
+ dialogDidSucceed(aUrl);
+ }
+ }
+}
+
+void FBDialog::checkForCode(QUrl aUrl)
+{
+ if (aUrl.hasQueryItem("code"))
+ {
+ qDebug() << "SUCC";
+
+ QString code = aUrl.queryItemValue("code");
+ qDebug() << code;
+
+ //emit codeFound(aUrl);
+ }
+}
View
115 src/fblogindialog.cpp
@@ -0,0 +1,115 @@
+/*
+ * 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 "fblogindialog.h"
+#include "facebrick.h"
+
+#include <QDebug>
+
+FBLogin::FBLogin(QString clientId)
+{
+ m_clientId = clientId;
+}
+
+static const QString kLoginURL = "https://www.facebook.com/dialog/oauth";
+
+void FBLogin::loadLoginPage()
+{
+ Dictionary getParams, postParams;
+
+ getParams["display"] = "touch";
+ getParams["client_id"] = m_clientId;
+ getParams["redirect_uri"] = "http://www.facebook.com/apps/application.php?id=110513258970087";
+ getParams["scope"] = "read_stream";
+ getParams["response_type"] = "token";
+
+ loadURL(kLoginURL,QNetworkAccessManager::GetOperation, getParams, postParams);
+
+}
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// FBDialog
+
+void FBLogin::load()
+{
+ loadLoginPage();
+}
+
+void FBLogin::dialogWillDisappear()
+{
+ qDebug() << "dialog gone";
+}
+
+void FBLogin::dialogDidSucceed(const QUrl& aUrl)
+{
+ const QString authToken = "access_token=";
+ const QString url ( aUrl.toString() );
+
+ int start = url.indexOf(authToken);
+ qDebug() << start;
+ if (start != -1)
+ {
+ QString token;
+ int end = url.indexOf("&", start);
+ int delta = start + authToken.size();
+ if (end != -1)
+ {
+ token = url.mid(delta, end - delta );
+ }
+ else
+ {
+ // -1 because delta assumes & character which is in this case missing
+ token = url.right(delta - 1);
+ }
+ qDebug() << token;
+
+ // TODO: needs changing
+ FaceBrick::instance()->setToken(token);
+ dismiss(true);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// slots for signals from FBRequest
+
+void FBLogin::requestDidLoad(const QVariant& aResult)
+{
+ qDebug() << "::::::::::::::::::::RESULT::::::::::::::::::::::::::";
+ qDebug() << aResult;
+ /*bool conversionError = false;
+ QVariantHash object = aResult.toHash();
+ QVariant ui = object.value("uid");
+ FBUID uid = object.value("uid").toULongLong(&conversionError);
+ QString sessionKey = object.value("session_key").toString();
+ QString sessionSecret = object.value("secret").toString();
+
+ QVariant ex = object.value("expires");
+ uint expires = object.value("expires").toUInt(&conversionError);
+ QDateTime expiration; expiration.setTime_t( expires );
+
+ iSession->beginSession(uid,sessionKey, sessionSecret,expiration);
+ iSession->resume();
+
+ dismissWithSuccess(true, true);*/
+}
+
+void FBLogin::requestFailedWithFacebookError (const FBError& aCode )
+{
+ dismissWithError(aCode, true);
+}
+
+void FBLogin::requestFailedWithNetworkError( QNetworkReply::NetworkError aCode )
+{
+ qDebug() << "error network";
+ //dismissWithError(aCode, true);
+}
View
24 src/main.cpp
@@ -1,32 +1,30 @@
#include <QtGui/QApplication>
#include <QDebug>
+#include <QTimer>
-#include "fbsession.h"
-#include "fblogindialog.h"
+#include "qfactoryinterface.h"
#include "mainwindow.h"
#include "facebrick.h"
+#include "graphapi.h"
+#include "fblogindialog.h"
+
+#include "getconnection.h"
+
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
- FBSession *session = FBSession::sessionForApplication("fd707be7594bbb68b91bf86cc1870085", QString(), QString("http://w00t.dereferenced.net/facebook/"));
-
- if (session->resume() == false)
- {
- // Never logged in, let them login!
- FBLoginDialog *m_fbLoginDialog = new FBLoginDialog();
- m_fbLoginDialog->show();
- }
- // Initialise us
- FaceBrick::instance(session);
+ QString clientId = "", clientSecret ="";
+ FaceBrick::instance(clientId, clientSecret);
+ FBLogin *m_fbLoginDialog = new FBLogin(clientId);
+ m_fbLoginDialog->show();
MainWindow w(0);
w.show();
int retval = a.exec();
delete FaceBrick::instance();
- delete session;
return retval;
}
View
9 src/mainwindow.cpp
@@ -22,7 +22,7 @@
#include "fberror.h"
#include "fblogindialog.h"
#include "fbsession.h"
-#include "fbpermissiondialog.h"
+//#include "fbpermissiondialog.h"
#include "facebrick.h"
#include "newsfeeddelegate.h"
@@ -53,6 +53,8 @@ MainWindow::MainWindow(QWidget *parent) :
// Instantiate model so it's parented to us.
FacebookAccountModel::instance(this);
+ FaceBrick::instance()->createConnection();
+
// Menu
connect(m_ui->action_Synchronise, SIGNAL(triggered()), this, SLOT(fetchNewsFeed()));
connect(m_ui->action_Logout, SIGNAL(triggered()), this, SLOT(onLogoutMenuAction()));
@@ -62,7 +64,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(m_ui->updateStatusButton, SIGNAL(clicked()), this, SLOT(sendStatusUpdate()));
// Session
- connect(FaceBrick::instance()->session(), SIGNAL(sessionDidLogout()), this, SLOT(sessionDidLogout()));
+ //connect(FaceBrick::instance()->session(), SIGNAL(sessionDidLogout()), this, SLOT(sessionDidLogout()));
// News posts
connect(m_ui->postsListView, SIGNAL(clicked(QModelIndex)), this, SLOT(newsFeedListClicked(QModelIndex)));
@@ -112,7 +114,8 @@ void MainWindow::sessionDidLogout()
void MainWindow::onLogoutMenuAction()
{
- FaceBrick::instance()->session()->logout();
+ // TODO new logout
+ //FaceBrick::instance()->session()->logout();
}
void MainWindow::onSettingsMenuAction()
View
132 src/mainwindow_newsfeed.cpp
@@ -33,6 +33,8 @@
#include "ui_mainwindow.h"
#include "newsfeedpostview.h"
+#include "getconnection.h"
+
void MainWindow::newsFeedListClicked(QModelIndex index)
{
NewsFeedPostView *nfpv = new NewsFeedPostView(this);
@@ -55,7 +57,10 @@ void MainWindow::fetchNewsFeed()
setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
#endif
- FBRequest* request = FBRequest::request();
+ connect (FaceBrick::instance()->m_connection, SIGNAL(requestDidLoad(QVariant)), this, SLOT(newsFeedLoaded(QVariant)));
+
+ FaceBrick::instance()->m_connection->load("me", "home");
+ /*FBRequest* request = FBRequest::request();
Dictionary params;
// Query to fetch news posts
@@ -75,7 +80,9 @@ void MainWindow::fetchNewsFeed()
connect (request, SIGNAL(requestDidLoad(QVariant)), this, SLOT(newsFeedLoaded(QVariant)));
connect (request, SIGNAL(requestFailedWithFacebookError(FBError)), this, SLOT(newsFeedLoadingError(FBError)));
- request->call("facebook.fql.multiquery",params);
+ request->call("facebook.fql.multiquery",params);*/
+
+
}
void MainWindow::newsFeedLoadingError(const FBError &error)
@@ -95,64 +102,70 @@ void MainWindow::newsFeedLoaded(const QVariant &container)
#endif
m_updatingNewsFeed = false;
- if (container.type() == QVariant::List) {
- QVariantList list = container.toList();
+ qDebug() << "newsfeed loaded";
- // Item #0 will be our result set on news items
- foreach (const QVariant &newsFeedPostHash, list.at(0).toHash().begin().value().toList()) {
- QHash<QString, QVariant> newsFeedPostData = newsFeedPostHash.toHash();
+ foreach (const QVariant &newsFeedPostHash, container.toMap()["data"].toList()) {
+ QMap<QString, QVariant> newsFeedPostData = newsFeedPostHash.toMap();
- // Fetch (or create) the account that made this newsfeed post
- FacebookAccount *account = FacebookAccountModel::instance()->account(newsFeedPostData["actor_id"].toLongLong());
- Q_ASSERT(account);
+ qDebug() << newsFeedPostData["from"].toMap()["name"].toString();
+
+ // Fetch (or create) the account that made this newsfeed post
+ FacebookAccount *account = FacebookAccountModel::instance()->account(newsFeedPostData["from"].toMap()["id"].toLongLong());
+ Q_ASSERT(account);
+
+ // Create a new newsfeed post
+ NewsFeedPost *np = new NewsFeedPost(m_newsFeedModel,
+ account,
+ newsFeedPostData["id"].toString(),
+ newsFeedPostData["created_time"].toLongLong(),
+ newsFeedPostData["link"].toString(),
+ newsFeedPostData["message"].toString());
+
+ account->setName(newsFeedPostData["from"].toMap()["name"].toString());
- // Create a new newsfeed post
- NewsFeedPost *np = new NewsFeedPost(m_newsFeedModel,
- account,
- newsFeedPostData["post_id"].toString(),
- newsFeedPostData["created_time"].toLongLong(),
- newsFeedPostData["permalink"].toString(),
- newsFeedPostData["message"].toString());
- Q_ASSERT(np);
-
- // Seed it into the model
- m_newsFeedModel->insertNewsItem(np);
-
- // Update our 'recent posts' block badger.
- if (np->createdTime() > m_lastUpdatedNewsFeed)
- m_lastUpdatedNewsFeed = np->createdTime();
-
- // Process like info too.
- bool iLikeThis = newsFeedPostData["likes"].toHash()["user_likes"].toString() == "1";
- np->setILikeThis(iLikeThis);
-
- // *breathe deeply* ok, and now let's try manage attachments
- QHash<QString, QVariant> attachmentHash = newsFeedPostData["attachment"].toHash();
-
- // Facebook... why not just *not* send attachment data if there isn't one?
- if (attachmentHash.count() == 1)
- continue;
-
- // Ignore "sent from my mobile" - there should be a better way to do this
- if (attachmentHash["href"].toString() == "http://www.facebook.com")
- continue;
-
- // yes, apparantly this can happen!
- if (attachmentHash["media"].toList().count() == 0)
- continue;
-
- // GOD DAMMIT I HATE THIS BOXING.
- QHash<QString, QVariant> mediaInfo = attachmentHash["media"].toList().at(0).toHash();
- qDebug() << mediaInfo;
-
- np->setHasAttachment(true);
- np->setDescription(attachmentHash["description"].toString());
- np->setAttachmentName(mediaInfo["name"].toString());
- // TODO: href?
- np->setThumbnail(mediaInfo["src"].toString());
- }
-
- foreach (const QVariant &newsFeedUserHash, list.at(1).toHash().begin().value().toList()) {
+ QUrl imageUrl = "http://graph.facebook.com/" + newsFeedPostData["from"].toMap()["id"].toString() + "/picture";
+ account->setAvatar(imageUrl);
+
+ Q_ASSERT(np);
+
+ // Seed it into the model
+ m_newsFeedModel->insertNewsItem(np);
+/*
+ // Update our 'recent posts' block badger.
+ if (np->createdTime() > m_lastUpdatedNewsFeed)
+ m_lastUpdatedNewsFeed = np->createdTime();
+
+ // Process like info too.
+ bool iLikeThis = newsFeedPostData["likes"].toHash()["user_likes"].toString() == "1";
+ np->setILikeThis(iLikeThis);
+
+ // *breathe deeply* ok, and now let's try manage attachments
+ QHash<QString, QVariant> attachmentHash = newsFeedPostData["attachment"].toHash();
+
+ // Facebook... why not just *not* send attachment data if there isn't one?
+ if (attachmentHash.count() == 1)
+ continue;
+
+ // Ignore "sent from my mobile" - there should be a better way to do this
+ if (attachmentHash["href"].toString() == "http://www.facebook.com")
+ continue;
+
+ // yes, apparantly this can happen!
+ if (attachmentHash["media"].toList().count() == 0)
+ continue;
+
+ // GOD DAMMIT I HATE THIS BOXING.
+ QHash<QString, QVariant> mediaInfo = attachmentHash["media"].toList().at(0).toHash();
+ qDebug() << mediaInfo;
+
+ np->setHasAttachment(true);
+ np->setDescription(attachmentHash["description"].toString());
+ np->setAttachmentName(mediaInfo["name"].toString());
+ // TODO: href?
+ np->setThumbnail(mediaInfo["src"].toString());*/
+ }
+
+ /*foreach (const QVariant &newsFeedUserHash, list.at(1).toHash().begin().value().toList()) {
QHash<QString, QVariant> newsFeedUserData = newsFeedUserHash.toHash();
// Get (or create - though this should have already been done above) the account
@@ -161,8 +174,7 @@ void MainWindow::newsFeedLoaded(const QVariant &container)
account->setName(newsFeedUserData["name"].toString());
account->setAvatar(newsFeedUserData["pic_square"].toString());
- }
- }
-
+ // }
+*/
sender()->deleteLater();
}

0 comments on commit b3bec61

Please sign in to comment.
Something went wrong with that request. Please try again.