Пример #1
0
void BookmarksToolBar::dropEvent(QDropEvent *event)
{
    const QMimeData *mimeData = event->mimeData();
    if (mimeData->hasUrls() && mimeData->hasText()) {
        QList<QUrl> urls = mimeData->urls();
        QAction *action = actionAt(event->pos());
        QString dropText;
        if (action)
            dropText = action->text();
        int row = -1;
        QModelIndex parentIndex = m_root;
        for (int i = 0; i < m_bookmarksModel->rowCount(m_root); ++i) {
            QModelIndex idx = m_bookmarksModel->index(i, 0, m_root);
            QString title = idx.data().toString();
            if (title == dropText) {
                row = i;
                if (m_bookmarksModel->hasChildren(idx)) {
                    parentIndex = idx;
                    row = -1;
                }
                break;
            }
        }
        BookmarkNode *bookmark = new BookmarkNode(BookmarkNode::Bookmark);
        bookmark->url = urls.at(0).toString();
        bookmark->title = mimeData->text();

        BookmarkNode *parent = m_bookmarksModel->node(parentIndex);
        BookmarksManager *bookmarksManager = m_bookmarksModel->bookmarksManager();
        bookmarksManager->addBookmark(parent, bookmark, row);
        event->acceptProposedAction();
    }
    QToolBar::dropEvent(event);
}
Пример #2
0
void WebView::loadUrl(const QUrl &url)
{
    if(url.toString() == "about:home") {

        QFile file("://home.html");
        bool isOpened = file.open(QIODevice::ReadOnly);
        Q_ASSERT(isOpened);
        Q_UNUSED(isOpened)
        page()->mainFrame()->addToJavaScriptWindowObject("js", &js);
        BookmarksManager *manager =  BrowserApplication::bookmarksManager();

        QList<QString> url;

        url = manager->bookmarksTop();

        QString html = QString(QLatin1String(file.readAll()))
                .arg((url.count() >= 1)? "<a href="+url[0]+">"+url[1]+"</a>" : "<a class='none' onclick='addDialog()'>+</a>")
                .arg((url.count() >= 3)? "<a href="+url[2]+">"+url[3]+"</a>" : "<a class='none' onclick='addDialog()'>+</a>")
                .arg((url.count() >= 5)? "<a href="+url[4]+">"+url[5]+"</a>" : "<a class='none' onclick='addDialog()'>+</a>")
                .arg((url.count() >= 7)? "<a href="+url[6]+">"+url[7]+"</a>" : "<a class='none' onclick='addDialog()'>+</a>")
                .arg((url.count() >= 9)? "<a href="+url[8]+">"+url[9]+"</a>" : "<a class='none' onclick='addDialog()'>+</a>")
                .arg((url.count() >= 11)? "<a href="+url[10]+">"+url[11]+"</a>" : "<a class='none' onclick='addDialog()'>+</a>")
                .arg((url.count() >= 13)? "<a href="+url[12]+">"+url[13]+"</a>" : "<a class='none' onclick='addDialog()'>+</a>")
                .arg((url.count() >= 15)? "<a href="+url[14]+">"+url[15]+"</a>" : "<a class='none' onclick='addDialog()'>+</a>");

        page()->mainFrame()->setHtml(html);

        m_initialUrl = "about:home";

        return;
    }

    m_initialUrl = url;
    load(url);
}
Пример #3
0
void JsAPI::addTop8(const QString &url, const QString &title)
{
    BookmarksManager *manager = BrowserApplication::bookmarksManager();
    BookmarkNode *node = new BookmarkNode(BookmarkNode::Bookmark);

    node->title = title;
    node->url = url;

    manager->addBookmark(manager->top8(), node );
    qDebug() << "Added";
}
Пример #4
0
// This will be called before each test function is executed.
void tst_AddBookmarkDialog::init()
{
    BookmarksManager *manager = BrowserApplication::bookmarksManager();
    BookmarkNode *root = manager->bookmarks();
    QList<BookmarkNode*> nodes = root->children();
    BookmarkNode *menu = nodes[0];
    BookmarkNode *toolbar = nodes[1];
    while (!menu->children().isEmpty())
        manager->removeBookmark(menu->children().first());
    while (!toolbar->children().isEmpty())
        manager->removeBookmark(toolbar->children().first());
}
Пример #5
0
QString bookmarkWriteName( const BookmarkNode * node)
{
	if (!node)
		return "";

        if (node->type() == BookmarkNode::Folder)
	{
		BookmarksManager* bm = BrowserApplication::bookmarksManager();
		if (bm && bm->menu() == node)
			return "Bookmarks Menu";
		if (bm && bm->toolbar() == node)
			return "Bookmarks Bar";
	}

	return node->title;
}
Пример #6
0
void BookmarksFolderView::createFolder()
{
    BookmarksManager * manager = BookmarksManager::bookmarksManager();
    QModelIndex index = m_model->mapToSource(currentIndex());
    if(index.isValid())
    {
        QList<QVariant> indexes = manager->indexes(index);
        bool ok;
        QString title =
                QInputDialog::getText(this, trUtf8("Create bookmarks folder"),
                                      trUtf8("Title") + ":",
                                      QLineEdit::Normal, QString(), &ok);
        if(ok && !title.isEmpty())
        {
            manager->addItem(title, QUrl(), indexes);
        }
    }
}
Пример #7
0
void tst_AddBookmarkDialog::addbookmarkdialog()
{
    QFETCH(QString, url);
    QFETCH(QString, title);
    QFETCH(QDialogButtonBox::StandardButton, button);
    QFETCH(int, menuCount);
    QFETCH(int, toolbarCount);
    QFETCH(int, select);

    BookmarksManager *manager = BrowserApplication::bookmarksManager();
    qRegisterMetaType<BookmarkNode *>("BookmarkNode *");
    QSignalSpy spy(manager, SIGNAL(entryAdded(BookmarkNode *)));
    BookmarkNode *menu = manager->menu();
    BookmarkNode *toolbar = manager->toolbar();
    QCOMPARE(menu->children().count(), 0);
    QCOMPARE(toolbar->children().count(), 0);

    SubAddBookmarkDialog dialog(0, manager);
    dialog.setUrl(url);
    dialog.setTitle(title);
    QComboBox *combobox = dialog.findChild<QComboBox*>();
    QVERIFY(combobox);
    if (select != -1) {
        combobox->setCurrentIndex(select);
        combobox->view()->setCurrentIndex(combobox->model()->index(select, 0));
    }
    QDialogButtonBox *buttonBox = dialog.findChild<QDialogButtonBox*>();
    QVERIFY(buttonBox);
    QPushButton *pushButton = buttonBox->button(button);
    pushButton->click();

    QCOMPARE(spy.count(), menuCount + toolbarCount);

    QCOMPARE(menu->children().count(), menuCount);
    QCOMPARE(toolbar->children().count(), toolbarCount);
    BookmarkNode *node = 0;
    if (menuCount == 1) node = menu->children()[0];
    if (toolbarCount == 1) node = toolbar->children()[0];
    if (node) {
        QCOMPARE(node->title, title);
        QCOMPARE(node->url, url);
    }
}
Пример #8
0
void BookmarksToolBar::dropEvent(QDropEvent *event)
{
    const QMimeData *mimeData = event->mimeData();
    if (mimeData->hasUrls() && mimeData->hasText()) {
        QList<QUrl> urls = mimeData->urls();
        QString title = mimeData->text();
        QUrl url = urls.at(0);

        if (url.isEmpty()) {
            QToolBar::dropEvent(event);
            return;
        }

        if (title.isEmpty()) {
            title = QLatin1String(url.toEncoded());
        }

        int row = -1;
        QModelIndex parentIndex = m_root;
        QToolButton *target = qobject_cast<QToolButton *>(childAt(event->pos()));

        if (target && target->menu()) {
            ModelMenu *menu = qobject_cast<ModelMenu *>(target->menu());
            if (menu)
                parentIndex = menu->rootIndex();
        }

        BookmarkNode *bookmark = new BookmarkNode(BookmarkNode::Bookmark);
        bookmark->url = QLatin1String(url.toEncoded());
        bookmark->title = title;

        BookmarkNode *parent = m_bookmarksModel->node(parentIndex);
        BookmarksManager *bookmarksManager = m_bookmarksModel->bookmarksManager();
        bookmarksManager->addBookmark(parent, bookmark, row);
        event->acceptProposedAction();
    }
    QToolBar::dropEvent(event);
}
Пример #9
0
void BookmarksToolBar::dropEvent(QDropEvent *event)
{
    const QMimeData *mimeData = event->mimeData();

    if (mimeData->hasUrls()) {
        QUrl url = mimeData->urls().at(0);
        QString title = mimeData->text();

        if (url.isEmpty()) {
            QToolBar::dropEvent(event);
            return;
        }

        if (title.isEmpty())
            title = QString::fromUtf8(url.toEncoded());

        QModelIndex parentIndex = m_root;
        QAction *action = actionAt(event->pos());
        QModelIndex index = this->index(action);

        if (action && action->menu() && index.isValid())
            parentIndex = index;

        BookmarkNode *node = new BookmarkNode(BookmarkNode::Bookmark);
        node->url = QString::fromUtf8(url.toEncoded());
        node->title = title;

        int row = m_bookmarksModel->rowCount(parentIndex);
        BookmarkNode *parent = m_bookmarksModel->node(parentIndex);
        BookmarksManager *bookmarksManager = m_bookmarksModel->bookmarksManager();
        bookmarksManager->addBookmark(parent, node, row);

        event->acceptProposedAction();
    }

    QToolBar::dropEvent(event);
}
Пример #10
0
void BrowserWindow::HandleMessage( Message * pcMsg )
{
	BrowserWebView *pcWebView = GetCurrentWebView();

	switch( pcMsg->GetCode() )
	{
		case ID_URL_CHANGED:
		{
			bool bFinal = false;
			pcMsg->FindBool( "final", &bFinal );

			if( bFinal )
			{
				String cURL = "";
				int nSelection = -1;
				if( pcMsg->FindInt32( "selection", &nSelection ) == EOK )
					cURL = m_pcUrlEdit->GetItem( nSelection );
				else
				{
					cURL = m_pcUrlEdit->GetCurrentString();
					m_pcUrlEdit->AppendItem( cURL );
				}

				OpenURL( cURL );
			}
			break;
		}
		case ID_SET_STATUS_BAR_TEXT:
		{
			String cText;
			if( pcMsg->FindString( "text", &cText ) == EOK )
				m_pcStatusBar->SetText( "text", cText );
			break;
		}
		case ID_CLEAR_STATUS_BAR_TEXT:
		{
			m_pcStatusBar->SetText( "text", "" );
			break;
		}
		case ID_CREATE_WINDOW:
		{
			BrowserWindow *pcWindow;
			String cURL;
			Rect cFrame;

			/* Use the supplied dimensions if they've been provided, otherwise
			   clone the current Window */
			if( pcMsg->FindRect( "frame", &cFrame ) != EOK )
				cFrame = GetFrame();

			pcWindow = new BrowserWindow( cFrame );

			if( pcMsg->FindString( "url", &cURL ) == EOK )
				pcWindow->OpenURL( cURL );

			pcWindow->Show();
			pcWindow->MakeFocus();

			/* Tell BrowserApp about the new window */
			Application::GetInstance()->PostMessage( ID_WINDOW_OPENED );

			if( pcMsg->IsSourceWaiting() )
			{
				WebCore::Page *pcPage;
				View *pcTab;

				/* The new window will only have one tab at this stage so it's safe to always get tab #0 */
				pcTab = pcWindow->m_pcTabView->GetTabView( 0 );
				pcPage = static_cast<BrowserWebView*>( pcTab )->GetWebCoreFrame()->page();

				Message cReply( ID_CREATE_WINDOW_REPLY );
				cReply.AddPointer( "page", pcPage );

				pcMsg->SendReply( &cReply );
			}

			break;
		}
		case ID_CREATE_TAB:
		{
			String cURL;
			if( pcMsg->FindString( "url", &cURL ) == EOK )
			{
				uint nTabIndex;

				nTabIndex = CreateTab( cURL );

				if( pcMsg->IsSourceWaiting() )
				{
					WebCore::Page *pcPage;
					View *pcTab;

					pcTab = m_pcTabView->GetTabView( nTabIndex );
					pcPage = static_cast<BrowserWebView*>( pcTab )->GetWebCoreFrame()->page();

					Message cReply( ID_CREATE_WINDOW_REPLY );
					cReply.AddPointer( "page", pcPage );

					pcMsg->SendReply( &cReply );
				}
			}

			break;
		}
		case ID_BUTTON_BACK:
		{
			pcWebView->GoBack();

			UpdateButtonState( false );
			break;
		}
		case ID_BUTTON_FORWARD:
		{
			pcWebView->GoForward();

			UpdateButtonState( false );
			break;
		}
		case ID_BUTTON_RELOAD:
		{
			pcWebView->Reload();
			break;
		}
		case ID_BUTTON_STOP:
		{
			pcWebView->Stop();

			UpdateButtonState( false );
			break;
		}
		case ID_BUTTON_HOME:
		{
			OpenURL( m_pcSettings->GetString( "homepage", "about:blank" ) );
			break;
		}
		case ID_MENU_APP_ABOUT:
		{
			Alert* pcAbout = new Alert( "About Webster",
										"Webster " WEBSTER_VERSION " (Alpha)\nA WebCore based web browser\n\n© Copyright Kristian Van Der Vliet, 2008\nArno Klenke, 2004-2007\nKurt Skauen, 2001\n"
										"\nWebster is released under the Gnu Public License (GPL)\n",
										Alert::ALERT_INFO, 0x00, "Ok", NULL );
			pcAbout->Go( NULL );

			break;
		}
		case ID_MENU_WIN_NEW_TAB:
		{
			CreateTab( "" );
			break;
		}
		case ID_MENU_WIN_CLOSE_TAB:
		{
			DestroyTab( m_pcTabView->GetSelection() );
			break;
		}
		case ID_MENU_EDIT_CUT:
		{
			pcWebView->Cut();
			break;
		}
		case ID_MENU_EDIT_COPY:
		{
			pcWebView->Copy();
			break;
		}
		case ID_MENU_EDIT_PASTE:
		{
			pcWebView->Paste();
			break;
		}
		case ID_MENU_EDIT_DELETE:
		{
			pcWebView->Delete();
			break;
		}
		case ID_MENU_SETTINGS_CONFIGURE:
		{
			Rect cSettingsFrame = m_pcGuiSettings->GetRect( "settings", m_cSettingsFrame );
			SettingsWindow *pcSettingsWindow = new SettingsWindow( cSettingsFrame, "Webster settings", this, m_pcWebSettings, m_pcSettings, m_pcGuiSettings );
			pcSettingsWindow->Show();
			pcSettingsWindow->MakeFocus();

			break;
		}
		case ID_SETTINGS_SAVE:
		{
			Settings *pcSettings;
			if( pcMsg->FindPointer( "settings", (void**)&pcSettings ) == EOK )
			{
				delete m_pcSettings;
				m_pcSettings = pcSettings;

				m_pcSettings->Save();
			}

			WebSettings *pcWebSettings;
			if( pcMsg->FindPointer( "web_settings", (void**)&pcWebSettings ) == EOK )
			{
				delete m_pcWebSettings;
				m_pcWebSettings = pcWebSettings;
			}

			break;
		}
		case ID_SETTINGS_APPLY:
		{
			Settings *pcSettings;
			if( pcMsg->FindPointer( "settings", (void**)&pcSettings ) == EOK )
			{
				delete m_pcSettings;
				m_pcSettings = pcSettings;
			}

			WebSettings *pcWebSettings;
			if( pcMsg->FindPointer( "web_settings", (void**)&pcWebSettings ) == EOK )
			{
				delete m_pcWebSettings;
				m_pcWebSettings = pcWebSettings;
			}

			break;
		}
		case ID_MENU_BOOKMARKS_ADD:
		{
			String cShortTitle, cLongTitle, cURL;

			pcWebView->GetTitle( cShortTitle, cLongTitle );
			cURL = pcWebView->GetCurrentURL();

			m_pcBookmarksManager->AddBookmark( cLongTitle, cURL );

			break;
		}
		case ID_MENU_BOOKMARKS_MANAGE:
		{
			String cPath;
			if( pcMsg->FindString( "path", &cPath ) != EOK )
				break;

			/* XXXKV: This is a really rubbish way to manage bookmarks: we should have
			   a proper in-application dialog to do it */

			/* Open a filebrowser window */
			if( fork() == 0 )
			{
				set_thread_priority( -1, 0 );
				execlp( "/system/bin/FileBrowser", "/system/bin/FileBrowser", cPath.c_str(), NULL );
			}
			break;
		}
		case ID_BOOKMARK_GO:
		{
			String cURL;

			if( pcMsg->FindString( "url", &cURL ) == EOK )
				OpenURL( cURL );

			break;
		}
		case ID_TAB_CHANGED:
		{
			ChangeTab( m_pcTabView->GetSelection() );
			break;
		}
		case ID_WEBVIEW_SET_TITLE:
		{
			String cShortTitle, cLongTitle;
			uint nTabIndex;

			if( pcMsg->FindString( "short", &cShortTitle ) == EOK &&
				pcMsg->FindString( "long", &cLongTitle ) == EOK &&
				pcMsg->FindInt32( "index", (int32*)&nTabIndex ) == EOK )
			{
				m_pcTabView->SetTabTitle( nTabIndex, cShortTitle );

				/* If this is the currently selected tab, set the Window title to the full page title */
				if( nTabIndex == m_pcTabView->GetSelection() )
					SetTitle( cLongTitle );
			}

			break;
		}
		case ID_WEBVIEW_LOAD_STARTED:
		{
			String cURL;
			uint nTabIndex;

			if( pcMsg->FindString( "url", &cURL ) == EOK &&
				pcMsg->FindInt32( "index", (int32*)&nTabIndex ) == EOK )
			{
				if( nTabIndex == m_pcTabView->GetSelection() )
				{
					m_pcUrlEdit->SetCurrentString( cURL.c_str() );
					UpdateButtonState( true );
				}
			}
			break;
		}
		case ID_WEBVIEW_LOAD_FINISHED:
		{
			uint nTabIndex;
			if( pcMsg->FindInt32( "index", (int32*)&nTabIndex ) == EOK )
				if( nTabIndex == m_pcTabView->GetSelection() )
					UpdateButtonState( false );
			break;
		}
		default:
		{
			fprintf( stderr, "Unknown message with code #%d\n", pcMsg->GetCode() );
			Window::HandleMessage( pcMsg );
			break;
		}
	}
}