int main(int argc, char **argv)
{
    BrowserApplication application(argc, argv);
    QCoreApplication::setApplicationName(QLatin1String("urllineeditexample"));
    QMainWindow w;

    QWidget *window = new QWidget;
    QComboBox *comboBox = new QComboBox(window);
    comboBox->setEditable(true);
    QLineEdit *lineEdit = new QLineEdit(window);
    LocationBar *s1 = new LocationBar(window);
    LocationBar *s2 = new LocationBar(window);
    WebView *view = new WebView(window);
    view->setUrl(QUrl("http://www.google.com"));
    s2->setWebView(view);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(comboBox);
    layout->addWidget(lineEdit);
    layout->addWidget(s1);
    layout->addWidget(s2);
    layout->addWidget(view);
    window->setLayout(layout);
    w.show();
    w.setCentralWidget(window);

    QToolBar *bar = w.addToolBar("foo");
    QSplitter *splitter = new QSplitter(window);
    splitter->addWidget(new LocationBar);
    splitter->addWidget(new QLineEdit);
    bar->addWidget(splitter);
    return application.exec();
}
void WebViewRecipe::onLoadingChanged(bb::cascades::WebLoadRequest *loadRequest)
{
    if (loadRequest->status() == WebLoadStatus::Started) {
        // Show the ProgressBar when navigation is requested.
        mLoadingIndicator->setOpacity(1.0);
    } else if (loadRequest->status() == WebLoadStatus::Succeeded) {
        // The ProgressIndicator is hidden on success or failure.
        mLoadingIndicator->setOpacity(0.0);
    } else if (loadRequest->status() == WebLoadStatus::Failed) {
        WebView *webView = dynamic_cast<WebView*>(sender());
        mLoadingIndicator->setOpacity(0.0);

        // If loading failed, fallback a local html file which will also send a java script message
        QUrl fallbackUrl("local:///assets/WebViewFallback.html");
        webView->setUrl(fallbackUrl);
    }
}
ApplicationUI::ApplicationUI(bb::cascades::Application *app) :
        QObject(app)
{
    // prepare the localization
    m_pTranslator = new QTranslator(this);
    m_pLocaleHandler = new LocaleHandler(this);

    bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()));
    // This is only available in Debug builds
    Q_ASSERT(res);
    // Since the variable is not used in the app, this is added to avoid a
    // compiler warning
    Q_UNUSED(res);

    // initial load
    onSystemLanguageChanged();

    // Create scene document from main.qml asset, the parent is set
    // to ensure the document gets destroyed properly at shut down.
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    qml->setContextProperty("app", this);

    // Create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();

    WebView* wv = root->findChild<WebView*>("oauthWebView");
    QString url = "https://www.dropbox.com/1/oauth2/authorize?";
    url.append("client_id=").append("<appkey>").append("&");
    url.append("response_type=token&");
    url.append("redirect_uri=").append("<redirect_uri>").append("&");
    url.append("state=").append("<CSRF token>");
    wv->setUrl(QUrl(url));

    // Set created root object as the application scene
    app->setScene(root);
}
WebViewRecipe::WebViewRecipe(Container *parent) :
        CustomControl(parent)
{
    bool connectResult;
    Q_UNUSED(connectResult);

    // Get the UIConfig object in order to use resolution independent sizes.
    UIConfig *ui = this->ui();

    // The recipe Container
    Container *recipeContainer = new Container();
    recipeContainer->setLayout(new DockLayout());

    WebView *webView = new WebView();
    webView->setUrl(QUrl("https://github.com/blackberry/Cascades-Samples/blob/master/cascadescookbookqml/assets/Slider.qml"));

    // We let the scroll view scroll in both x and y and enable zooming,
    // max and min content zoom property is set in the WebViews onMinContentScaleChanged
    // and onMaxContentScaleChanged signal handlers.
    mScrollView = ScrollView::create().scrollMode(ScrollMode::Both).pinchToZoomEnabled(true);
    mScrollView->setContent(webView);

    // Connect to signals to manage the progress indicator.
    connectResult = connect(webView, SIGNAL(loadingChanged(bb::cascades::WebLoadRequest *)), this,
                                     SLOT(onLoadingChanged(bb::cascades::WebLoadRequest *)));
    Q_ASSERT(connectResult);

    connectResult = connect(webView, SIGNAL(loadProgressChanged(int)), this,
                                     SLOT(onProgressChanged(int)));
    Q_ASSERT(connectResult);

    connectResult = connect(webView, SIGNAL(navigationRequested(bb::cascades::WebNavigationRequest *)), this,
                                     SLOT(onNavigationRequested(bb::cascades::WebNavigationRequest *)));
    Q_ASSERT(connectResult);

    // Connect signals to manage the web contents suggested size.
    connectResult = connect(webView, SIGNAL(maxContentScaleChanged(float)), this,
                                     SLOT(onMaxContentScaleChanged(float)));
    Q_ASSERT(connectResult);

    connectResult = connect(webView, SIGNAL(minContentScaleChanged(float)), this,
                                     SLOT(onMinContentScaleChanged(float)));
    Q_ASSERT(connectResult);

    // Connect signal to handle java script calls to navigator.cascades.postMessage()
    connectResult = connect(webView, SIGNAL(messageReceived(const QVariantMap&)), this,
                                     SLOT(onMessageReceived(const QVariantMap&)));
    Q_ASSERT(connectResult);

    WebSettings *settings = webView->settings();
    QVariantMap settingsMap;
    settingsMap["width"] = QString("device-width");
    settingsMap["initial-scale"] = 1.0;
    settings->setViewportArguments(settingsMap);

    // A progress indicator that is used to show the loading status
    Container *progressContainer = Container::create().bottom(ui->du(2));
    progressContainer->setLayout(new DockLayout());
    progressContainer->setVerticalAlignment(VerticalAlignment::Bottom);
    progressContainer->setHorizontalAlignment(HorizontalAlignment::Center);
    mLoadingIndicator = ProgressIndicator::create().opacity(0.0);
    progressContainer->add(mLoadingIndicator);

    // Add the controls and set the root Container of the Custom Control.
    recipeContainer->add(mScrollView);
    recipeContainer->add(progressContainer);
    setRoot(recipeContainer);
}