File indexing completed on 2025-01-19 03:55:36
0001 #include <QApplication> 0002 #include <QStringList> 0003 #include <QTimer> 0004 #include <QDebug> 0005 0006 #include "fbdemo.h" 0007 0008 const char OPT_OAUTH_CODE[] = "-o"; 0009 const char OPT_VALIDATE_TOKEN[] = "-v"; 0010 0011 const char USAGE[] = "\n" 0012 "Usage: facebookdemo [OPTION]...\n" 0013 "Get OAuth2 access tokens from Facebook's OAuth service\n" 0014 "\nOptions:\n" 0015 " %1\t\tLink with Facebook OAuth2 service using Authorization Code\n" 0016 " %2\t\tValidate Access Token\n"; 0017 0018 0019 class Helper : public QObject { 0020 Q_OBJECT 0021 0022 public: 0023 Helper() : QObject(), fbdemo_(this), waitForMsg_(false), msg_(QString()) {} 0024 0025 public slots: 0026 void processArgs() { 0027 QStringList argList = qApp->arguments(); 0028 QByteArray help = QString(USAGE).arg(OPT_OAUTH_CODE, 0029 OPT_VALIDATE_TOKEN).toLatin1(); 0030 const char* helpText = help.constData(); 0031 connect(&fbdemo_, SIGNAL(linkingFailed()), this, SLOT(onLinkingFailed())); 0032 connect(&fbdemo_, SIGNAL(linkingSucceeded()), this, SLOT(onLinkingSucceeded())); 0033 if (argList.contains(OPT_OAUTH_CODE)) { 0034 // Start OAuth 0035 fbdemo_.doOAuth(O2::GrantFlowAuthorizationCode); 0036 } else if (argList.contains(OPT_VALIDATE_TOKEN)) { 0037 fbdemo_.validateToken(); 0038 } else { 0039 qDebug() << helpText; 0040 qApp->exit(1); 0041 } 0042 } 0043 0044 void onLinkingFailed() { 0045 qDebug() << "Linking failed!"; 0046 qApp->exit(1); 0047 } 0048 0049 void onLinkingSucceeded() { 0050 qDebug() << "Linking succeeded!"; 0051 if (waitForMsg_) { 0052 //postStatusUpdate(msg_); 0053 } else { 0054 qApp->quit(); 0055 } 0056 } 0057 0058 private: 0059 FBDemo fbdemo_; 0060 bool waitForMsg_; 0061 QString msg_; 0062 }; 0063 0064 int main(int argc, char *argv[]) { 0065 QApplication a(argc, argv); 0066 QCoreApplication::setOrganizationName("MySoft"); 0067 QCoreApplication::setOrganizationDomain("mysoft.com"); 0068 QCoreApplication::setApplicationName("facebookdemo"); 0069 Helper helper; 0070 QTimer::singleShot(0, &helper, SLOT(processArgs())); 0071 return a.exec(); 0072 } 0073 0074 #include "main.moc"