Пример #1
0
void LocationCompleter::indexShiftActivated(const QModelIndex &index)
{
    Q_ASSERT(index.isValid());

    if (index.data(LocationCompleterModel::BookmarkRole).toBool()) {
        BookmarkItem* bookmark = static_cast<BookmarkItem*>(index.data(LocationCompleterModel::BookmarkItemRole).value<void*>());
        bookmark->updateVisitCount();
    }

    const QUrl url = index.data(LocationCompleterModel::UrlRole).toUrl();
    const int tabPos = index.data(LocationCompleterModel::TabPositionTabRole).toInt();

    // Load url (instead of switching to tab) with shift activation
    if (tabPos > -1) {
        loadUrl(url);
        return;
    }

    closePopup();

    // Clear locationbar
    emit clearCompletion();

    // Open new window
    mApp->createWindow(Qz::BW_NewWindow, url);
}
bool
BookmarkModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
    int row, int column, const QModelIndex &parent)
{
    if (action == Qt::IgnoreAction)
        return true;

    if (!data->hasFormat(MIMETYPE) || column > 0)
        return false;

    QByteArray ba = data->data(MIMETYPE);
    QDataStream stream(&ba, QIODevice::ReadOnly);
    while (stream.atEnd())
        return false;

    qint32 depth;
    bool expanded;
    QString name, url;
    while (!stream.atEnd()) {
        stream >> depth >> name >> url >> expanded;
        if (insertRow(qMax(0, row), parent)) {
            const QModelIndex &current = index(qMax(0, row), 0, parent);
            if (current.isValid()) {
                BookmarkItem* item = itemFromIndex(current);
                item->setData(DataVector() << name << url << expanded);
            }
        }
    }
    return true;
}
Пример #3
0
void WebBrowser::removeBookmarkMessageButtonPressed(const Plasma::MessageButton button)
{  
    if (button == Plasma::ButtonNo){
        return;
    }
    
    const QModelIndexList list = m_bookmarkModel->match(m_bookmarkModel->index(0,0), BookmarkItem::UrlRole, m_url.prettyUrl());

    if (!list.isEmpty()) {
        const QModelIndex &index = list.first();
        BookmarkItem *item = dynamic_cast<BookmarkItem *>(m_bookmarkModel->itemFromIndex(index));
        
        if (item) {
            KBookmark bookmark = item->bookmark();
            
            bookmark.parentGroup().deleteBookmark(bookmark);
            m_bookmarkManager->save();
        }
        
        if (item && item->parent()) {
            item->parent()->removeRow(index.row());
        } else {
            m_bookmarkModel->removeRow(index.row());
        }
    }
    
    m_addBookmark->setAction(m_addBookmarkAction);
}
Пример #4
0
LoadRequest LocationCompleter::createLoadRequest(const QModelIndex &index)
{
    LoadRequest request;
    BookmarkItem *bookmark = nullptr;

    if (index.data(LocationCompleterModel::HistoryRole).toBool()) {
        request = index.data(LocationCompleterModel::UrlRole).toUrl();
    } else if (index.data(LocationCompleterModel::BookmarkRole).toBool()) {
        bookmark = static_cast<BookmarkItem*>(index.data(LocationCompleterModel::BookmarkItemRole).value<void*>());
    } else if (index.data(LocationCompleterModel::SearchSuggestionRole).toBool()) {
        const QString text = index.data(LocationCompleterModel::TitleRole).toString();
        request = mApp->searchEnginesManager()->searchResult(LocationBar::searchEngine(), text);
    } else if (index.data(LocationCompleterModel::VisitSearchItemRole).toBool()) {
        const auto action = LocationBar::loadAction(m_originalText);
        switch (action.type) {
        case LocationBar::LoadAction::Url:
        case LocationBar::LoadAction::Search:
            request = action.loadRequest;
            break;
        case LocationBar::LoadAction::Bookmark:
            bookmark = action.bookmark;
            break;
        default:
            break;
        }
    }

    if (bookmark) {
        bookmark->updateVisitCount();
        request = bookmark->url();
    }

    return request;
}
LoadRequest LocationBar::createLoadRequest() const
{
    LoadRequest req;

    // Check for Search Engine shortcut
    int firstSpacePos = text().indexOf(QLatin1Char(' '));
    if (firstSpacePos != -1) {
        const QString shortcut = text().left(firstSpacePos);
        const QString searchedString = text().mid(firstSpacePos).trimmed();

        SearchEngine en = mApp->searchEnginesManager()->engineForShortcut(shortcut);
        if (!en.name.isEmpty()) {
            req = mApp->searchEnginesManager()->searchResult(en, searchedString);
        }
    }

    // Check for Bookmark keyword
    QList<BookmarkItem*> items = mApp->bookmarks()->searchKeyword(text());
    if (!items.isEmpty()) {
        BookmarkItem* item = items.first();
        item->updateVisitCount();
        req.setUrl(item->url());
    }

    if (req.isEmpty()) {
        const QUrl guessedUrl = WebView::guessUrlFromString(text());
        if (!guessedUrl.isEmpty())
            req.setUrl(guessedUrl);
        else
            req.setUrl(QUrl::fromEncoded(text().toUtf8()));
    }

    return req;
}
Пример #6
0
void MainWindow::editBookmark()
{
    // search the model for the closest bookmark
    BookmarkItem * bookmarkItem = 0;
    QModelIndex bookmarkIndex = currentTreeItem;
    do
    {

        bookmarkItem = 0; // qobject_cast<BookmarkItem *>(static_cast<TreeItem *>(bookmarkIndex.internalPointer()));

        if (bookmarkItem)
            break; // we found one!

        // up one level
        bookmarkIndex = bookmarkIndex.parent();
    } while (bookmarkIndex.isValid());

    // we found no bookmark!
    if (!bookmarkItem)
        return;

    EditBookmarkDialog dlg(this);
    dlg.setDir(bookmarkItem->name());
    dlg.setAlias(bookmarkItem->alias());

    if (dlg.exec())
        model.updateBookmark(bookmarkIndex, dlg.dir(), dlg.alias());
}
Пример #7
0
void BookmarkEditDlg::OnItemModify(void) 
{
    if (mListCtrl.GetSelectedCount() > 0)
    {
        xpr_sint_t sIndex = mListCtrl.GetSelectionMark();
        BookmarkItem *sBookmarkItem = (BookmarkItem *)mListCtrl.GetItemData(sIndex);

        BookmarkItemEditDlg sDlg;
        sDlg.add(sBookmarkItem);
        if (sDlg.DoModal() == IDOK)
        {
            if (sDlg.mBookmark.mPath.empty() == XPR_FALSE)
            {
                sDlg.copyBookmark(sBookmarkItem);

                sBookmarkItem->newSignature();
                sBookmarkItem->destroyIcon();

                mListCtrl.SetItemData(sIndex, XPR_NULL);
                mListCtrl.DeleteItem(sIndex);
                addBookmark(sBookmarkItem, IconReqShellIcon, sIndex);

                setItemFocus(sIndex);
            }
        }
    }

    updateStatus();
}
Пример #8
0
xpr_bool_t BookmarkToolBar::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
    NMHDR *pnmhdr = (NMHDR *)lParam;

    if (pnmhdr->code == TTN_GETDISPINFO)
    {
        if (gOpt->mConfig.mBookmarkTooltip == XPR_TRUE)
        {
            LPNMTTDISPINFO sNmTtDispInfo = (LPNMTTDISPINFO)pnmhdr;

            CPoint sPoint;
            GetCursorPos(&sPoint);
            ScreenToClient(&sPoint);

            xpr_sint_t sIndex = GetToolBarCtrl().HitTest(&sPoint);

            BookmarkItem *sBookmarkItem = BookmarkMgr::instance().getBookmark(sIndex);
            if (sBookmarkItem == XPR_NULL)
                return XPR_FALSE;

            sBookmarkItem->getTooltip(mToolTipText, !gOpt->mMain.mBookmarkBarText, XPR_TRUE);

            sNmTtDispInfo->lpszText = mToolTipText;
        }
    }

    return super::OnNotify(wParam, lParam, pResult);
}
Пример #9
0
void ChromeImporter::readBookmarks(const QVariantList &list, BookmarkItem* parent)
{
    Q_ASSERT(parent);

    foreach (const QVariant &entry, list) {
        const QVariantMap map = entry.toMap();
        const QString typeString = map.value("type").toString();
        BookmarkItem::Type type;

        if (typeString == QLatin1String("url")) {
            type = BookmarkItem::Url;
        }
        else if (typeString == QLatin1String("folder")) {
            type = BookmarkItem::Folder;
        }
        else {
            continue;
        }

        BookmarkItem* item = new BookmarkItem(type, parent);
        item->setTitle(map.value("name").toString());

        if (item->isUrl()) {
            item->setUrl(QUrl::fromEncoded(map.value("url").toByteArray()));
        }

        if (map.contains("children")) {
            readBookmarks(map.value("children").toList(), item);
        }
    }
}
Пример #10
0
void BookmarksManager::addBookmark()
{
    BookmarkItem* item = new BookmarkItem(BookmarkItem::Url);
    item->setTitle(tr("New Bookmark"));
    item->setUrl(QUrl("http://"));
    addBookmark(item);
}
Пример #11
0
void BookmarkList::slotExecuted( QTreeWidgetItem * item )
{
    BookmarkItem* bmItem = dynamic_cast<BookmarkItem*>( item );
    if ( !bmItem || !bmItem->viewport().isValid() )
        return;

    goTo( bmItem );
}
Пример #12
0
int BookmarksModel::rowCount(const QModelIndex &parent) const
{
    if (parent.column() > 0) {
        return 0;
    }

    BookmarkItem* itm = item(parent);
    return itm->children().count();
}
Пример #13
0
void BookmarksManager::bookmarkEdited()
{
    Q_ASSERT(ui->tree->selectedBookmarks().count() == 1);

    BookmarkItem* item = ui->tree->selectedBookmarks().first();
    item->setTitle(ui->title->text());
    item->setUrl(QUrl::fromEncoded(ui->address->text().toUtf8()));
    item->setKeyword(ui->keyword->text());
    item->setDescription(ui->description->toPlainText());

    m_bookmarks->changeBookmark(item);
}
void BookmarksListBox::startDrag()
{
    int currentItem = QListBox::currentItem();
    if (currentItem != -1) {
        BookmarkItem* bookmark = (BookmarkItem*)item(currentItem);
	if (bookmark!=0){
            KURL::List lst;
            lst.append( bookmark->url() );
            KURLDrag *drag = new KURLDrag(lst, this);
            drag->drag();
        }
    }
}
Пример #15
0
BookmarkItem* IeImporter::importBookmarks()
{
    BookmarkItem* root = new BookmarkItem(BookmarkItem::Folder);
    root->setTitle("Internet Explorer Import");

    foreach (QFileInfo file, urls) {
        QSettings urlFile(file.absoluteFilePath(), QSettings::IniFormat, this);

        QUrl url = urlFile.value("InternetShortcut/URL").toUrl();

        BookmarkItem* b = new BookmarkItem(BookmarkItem::Url, root);
        b->setTitle(file.baseName());
        b->setUrl(url);
    }
Пример #16
0
BookmarkItem* ChromeImporter::importBookmarks()
{
    const QByteArray data = m_file.readAll();
    m_file.close();

    QJsonParseError err;
    QJsonDocument json = QJsonDocument::fromJson(data, &err);
    const QVariant res = json.toVariant();

    if (err.error != QJsonParseError::NoError || res.type() != QVariant::Map) {
        setError(BookmarksImporter::tr("Cannot parse JSON file!"));
        return 0;
    }

    QVariantMap rootMap = res.toMap().value("roots").toMap();

    BookmarkItem* root = new BookmarkItem(BookmarkItem::Folder);
    root->setTitle("Chrome Import");

    BookmarkItem* toolbar = new BookmarkItem(BookmarkItem::Folder, root);
    toolbar->setTitle(rootMap.value("bookmark_bar").toMap().value("name").toString());
    readBookmarks(rootMap.value("bookmark_bar").toMap().value("children").toList(), toolbar);

    BookmarkItem* other = new BookmarkItem(BookmarkItem::Folder, root);
    other->setTitle(rootMap.value("other").toMap().value("name").toString());
    readBookmarks(rootMap.value("other").toMap().value("children").toList(), other);

    BookmarkItem* synced = new BookmarkItem(BookmarkItem::Folder, root);
    synced->setTitle(rootMap.value("synced").toMap().value("name").toString());
    readBookmarks(rootMap.value("synced").toMap().value("synced").toList(), other);

    return root;
}
Пример #17
0
LRESULT BookmarkEditDlg::OnShellAsyncIcon(WPARAM wParam, LPARAM lParam)
{
    ShellIcon::AsyncIcon *sAsyncIcon = (ShellIcon::AsyncIcon *)wParam;
    if (sAsyncIcon == XPR_NULL)
        return 0;

    //if (sAsyncIcon->uCode == m_uCode)
    {
        xpr_sint_t sIndex = -1;
        BookmarkItem *sBookmarkItem = XPR_NULL;

        if (sAsyncIcon->mItem != -1 && sAsyncIcon->mItem >= 0)
        {
            sBookmarkItem = (BookmarkItem *)mListCtrl.GetItemData((xpr_sint_t)sAsyncIcon->mItem);
            if (sBookmarkItem != XPR_NULL && sBookmarkItem->getSignature() == sAsyncIcon->mSignature)
                sIndex = (xpr_sint_t)sAsyncIcon->mItem;
        }

        if (sIndex < 0)
        {
            sIndex = findSignature(sAsyncIcon->mSignature);
            if (sIndex >= 0)
                sBookmarkItem = (BookmarkItem *)mListCtrl.GetItemData(sIndex);
        }

        if (sIndex >= 0 && sBookmarkItem != XPR_NULL)
        {
            HICON sIcon = sAsyncIcon->mResult.mIcon;
            if (sIcon == XPR_NULL)
                sIcon = BookmarkMgr::instance().getTypeIcon(BookmarkMgr::IconTypeNot, XPR_TRUE);

            sBookmarkItem->setIcon(sIcon);

            sAsyncIcon->mResult.mIcon = XPR_NULL;

            xpr_sint_t sImage = mImgList.Add(sIcon);

            LVITEM sLvItem = {0};
            sLvItem.mask   = LVIF_IMAGE;
            sLvItem.iItem  = sIndex;
            sLvItem.iImage = sImage;
            mListCtrl.SetItem(&sLvItem);
        }
    }

    XPR_SAFE_DELETE(sAsyncIcon);

    return 0;
}
Пример #18
0
void BookmarkList::slotChanged( QTreeWidgetItem * item )
{
    BookmarkItem* bmItem = dynamic_cast<BookmarkItem*>( item );
    if ( bmItem && bmItem->viewport().isValid() )
    {
        bmItem->bookmark().setFullText( bmItem->text( 0 ) );
        m_document->bookmarkManager()->save();
    }

    FileItem* fItem = dynamic_cast<FileItem*>( item );
    if ( fItem )
    {
        const KUrl url = fItem->data( 0, UrlRole ).value< KUrl >();
        m_document->bookmarkManager()->renameBookmark( url, fItem->text( 0 ) );
        m_document->bookmarkManager()->save();
    }
}
Пример #19
0
LRESULT BookmarkEditDlg::OnBookmarkAsyncIcon(WPARAM wParam, LPARAM lParam)
{
    xpr_sint_t sBookmarkIndex = (xpr_sint_t)wParam;
    BookmarkItem *sBookmarkItem = (BookmarkItem *)lParam;

    if (sBookmarkItem == XPR_NULL)
        return 0;

    xpr_sint_t sIndex = -1;
    BookmarkItem *sBookmarkItem2 = XPR_NULL;

    xpr_sint_t sCount = mListCtrl.GetItemCount();
    if (XPR_IS_RANGE(0, sBookmarkIndex, sCount-1))
    {
        sBookmarkItem2 = (BookmarkItem *)mListCtrl.GetItemData(sBookmarkIndex);
        if (sBookmarkItem2 != XPR_NULL && sBookmarkItem2->getSignature() == sBookmarkItem->getSignature())
            sIndex = sBookmarkIndex;
    }

    if (sIndex < 0)
    {
        sIndex = findSignature(sBookmarkItem->getSignature());
        if (sIndex >= 0)
            sBookmarkItem2 = (BookmarkItem *)mListCtrl.GetItemData(sIndex);
    }

    if (sIndex >= 0 && sBookmarkItem2 != XPR_NULL)
    {
        HICON sIcon = sBookmarkItem->getIcon();
        if (sIcon != XPR_NULL)
            sIcon = ::DuplicateIcon(XPR_NULL, sIcon);

        sBookmarkItem2->setIcon(sIcon);

        xpr_sint_t sImage = mImgList.Add(sIcon);

        LVITEM sLvItem = {0};
        sLvItem.mask   = LVIF_IMAGE;
        sLvItem.iItem  = sIndex;
        sLvItem.iImage = sImage;
        mListCtrl.SetItem(&sLvItem);
    }

    return 0;
}
Пример #20
0
xpr_sint_t BookmarkEditDlg::findSignature(xpr_uint_t aSignature)
{
    xpr_sint_t i;
    xpr_sint_t sCount;
    BookmarkItem *sBookmarkItem;

    sCount = mListCtrl.GetItemCount();
    for (i = 0; i < sCount; ++i)
    {
        sBookmarkItem = (BookmarkItem *)mListCtrl.GetItemData(i);
        if (sBookmarkItem == XPR_NULL)
            continue;

        if (sBookmarkItem->getSignature() == aSignature)
            return i;
    }

    return -1;
}
Пример #21
0
LoadRequest LocationBar::createLoadRequest() const
{
    LoadRequest req;

    const QString &t = text().trimmed();

    // Check for Search Engine shortcut
    int firstSpacePos = t.indexOf(QLatin1Char(' '));
    if (firstSpacePos != -1) {
        const QString shortcut = t.left(firstSpacePos);
        const QString searchedString = t.mid(firstSpacePos).trimmed();

        SearchEngine en = mApp->searchEnginesManager()->engineForShortcut(shortcut);
        if (!en.name.isEmpty()) {
            req = mApp->searchEnginesManager()->searchResult(en, searchedString);
        }
    }

    // Check for Bookmark keyword
    QList<BookmarkItem*> items = mApp->bookmarks()->searchKeyword(t);
    if (!items.isEmpty()) {
        BookmarkItem* item = items.at(0);
        item->updateVisitCount();
        req.setUrl(item->url());
    }

    if (req.isEmpty()) {
        // One word needs special handling, because QUrl::fromUserInput
        // would convert it to QUrl("http://WORD")
        if (!t.contains(QL1C(' ')) && !t.contains(QL1C('.'))) {
            req.setUrl(QUrl(t));
        }
        else {
            const QUrl &guessed = QUrl::fromUserInput(t);
            if (!guessed.isEmpty())
                req.setUrl(guessed);
            else
                req.setUrl(QUrl::fromEncoded(t.toUtf8()));
        }
    }

    return req;
}
Пример #22
0
void WebBrowser::removeBookmark(const QModelIndex &index)
{
    BookmarkItem *item = dynamic_cast<BookmarkItem *>(m_bookmarkModel->itemFromIndex(index));

    if (item) {
        KBookmark bookmark = item->bookmark();

        const QString text(i18nc("@info", "Do you really want to remove the bookmark to %1?", bookmark.url().host()));
        showMessage(KIcon("dialog-warning"), text, Plasma::ButtonYes | Plasma::ButtonNo);
        return;
    }

    if (item && item->parent()) {
        item->parent()->removeRow(index.row());
    } else {
        m_bookmarkModel->removeRow(index.row());
    }

}
Пример #23
0
Qt::ItemFlags BookmarksModel::flags(const QModelIndex &index) const
{
    BookmarkItem* itm = item(index);

    if (!index.isValid() || !itm) {
        return Qt::NoItemFlags;
    }

    Qt::ItemFlags flags =  Qt::ItemIsEnabled | Qt::ItemIsSelectable;

    if (itm->isFolder()) {
        flags |= Qt::ItemIsDropEnabled;
    }

    if (m_bookmarks && m_bookmarks->canBeModified(itm)) {
        flags |= Qt::ItemIsDragEnabled;
    }

    return flags;
}
Пример #24
0
LRESULT BookmarkToolBar::OnBookmarkAsyncIcon(WPARAM wParam, LPARAM lParam)
{
    xpr_sint_t sIndex = (xpr_sint_t)wParam;
    BookmarkItem *sBookmarkItem = (BookmarkItem *)lParam;

    if (sBookmarkItem == XPR_NULL)
        return 0;

    if (XPR_IS_RANGE(0, sIndex, BookmarkMgr::instance().getCount()-1))
    {
        TBBUTTONINFO sTbButtonInfo = {0};
        sTbButtonInfo.cbSize = sizeof(TBBUTTONINFO);
        sTbButtonInfo.dwMask = TBIF_BYINDEX | TBIF_IMAGE;
        sTbButtonInfo.iImage = mImgList.Add(sBookmarkItem->getIcon());

        GetToolBarCtrl().SetButtonInfo(sIndex, &sTbButtonInfo);
    }

    return 0;
}
Пример #25
0
void LocationCompleter::indexCtrlActivated(const QModelIndex &index)
{
    Q_ASSERT(index.isValid());
    Q_ASSERT(m_window);

    if (index.data(LocationCompleterModel::BookmarkRole).toBool()) {
        BookmarkItem* bookmark = static_cast<BookmarkItem*>(index.data(LocationCompleterModel::BookmarkItemRole).value<void*>());
        bookmark->updateVisitCount();
    }

    const QUrl url = index.data(LocationCompleterModel::UrlRole).toUrl();
    const QString title = index.data(LocationCompleterModel::TitleRole).toString();

    closePopup();

    // Clear locationbar
    emit clearCompletion();

    // Open url in new tab
    m_window->tabWidget()->addView(url, title, Qz::NT_CleanSelectedTab);
}
Пример #26
0
BookmarkItem* FirefoxImporter::importBookmarks()
{
    BookmarkItem* root = new BookmarkItem(BookmarkItem::Folder);
    root->setTitle("Firefox Import");

    QSqlQuery query(m_db);
    query.exec("SELECT title, fk FROM moz_bookmarks WHERE title != ''");

    while (query.next()) {
        QString title = query.value(0).toString();
        int placesId = query.value(1).toInt();

        QSqlQuery query2(m_db);
        query2.exec("SELECT url FROM moz_places WHERE id=" + QString::number(placesId));

        if (!query2.next()) {
            continue;
        }

        QUrl url = query2.value(0).toUrl();

        if (title.isEmpty() || url.isEmpty() || url.scheme() == QLatin1String("place")
                || url.scheme() == QLatin1String("about")) {
            continue;
        }

        BookmarkItem* b = new BookmarkItem(BookmarkItem::Url, root);
        b->setTitle(title);
        b->setUrl(url);
    }

    if (query.lastError().isValid()) {
        setError(query.lastError().text());
    }

    m_db.close();
    QSqlDatabase::removeDatabase("firefox-import");

    return root;
}
Пример #27
0
void LocationCompleter::indexActivated(const QModelIndex &index)
{
    Q_ASSERT(index.isValid());

    const QUrl url = index.data(LocationCompleterModel::UrlRole).toUrl();
    const int tabPos = index.data(LocationCompleterModel::TabPositionTabRole).toInt();

    // Switch to tab with simple index activation
    if (tabPos > -1) {
        BrowserWindow* window = static_cast<BrowserWindow*>(index.data(LocationCompleterModel::TabPositionWindowRole).value<void*>());
        Q_ASSERT(window);
        switchToTab(window, tabPos);
        return;
    }

    if (index.data(LocationCompleterModel::BookmarkRole).toBool()) {
        BookmarkItem* bookmark = static_cast<BookmarkItem*>(index.data(LocationCompleterModel::BookmarkItemRole).value<void*>());
        bookmark->updateVisitCount();
    }

    loadUrl(url);
}
Пример #28
0
void WebBrowser::fillGroup(BookmarkItem *parentItem, const KBookmarkGroup &group)
{
    KBookmark it = group.first();

    while (!it.isNull()) {
        BookmarkItem *bookmarkItem = new BookmarkItem(it);
        bookmarkItem->setEditable(false);

        if (it.isGroup()) {
            KBookmarkGroup grp = it.toGroup();
            fillGroup( bookmarkItem, grp );

        }

        if (parentItem) {
            parentItem->appendRow(bookmarkItem);
        } else {
            m_bookmarkModel->appendRow(bookmarkItem);
        }

        it = m_bookmarkManager->root().next(it);
    }
}
Пример #29
0
void BookmarksWidget::toggleBookmark()
{
    if (m_bookmark) {
        if (m_edited) {
            // Change folder
            m_bookmarks->removeBookmark(m_bookmark);
            m_bookmarks->addBookmark(ui->folderButton->selectedFolder(), m_bookmark);
        }
        else {
            // Remove
            m_bookmarks->removeBookmark(m_bookmark);
        }
    }
    else {
        // Save bookmark
        BookmarkItem* bookmark = new BookmarkItem(BookmarkItem::Url);
        bookmark->setTitle(m_view->title());
        bookmark->setUrl(m_view->url());
        m_bookmarks->addBookmark(ui->folderButton->selectedFolder(), bookmark);
    }

    closePopup();
}
Пример #30
0
LocationBar::LoadAction LocationBar::loadAction(const QString &text)
{
    LoadAction action;

    const QString &t = text.trimmed();

    if (t.isEmpty()) {
        return action;
    }

    // Check for Search Engine shortcut
    const int firstSpacePos = t.indexOf(QLatin1Char(' '));
    if (qzSettings->searchFromAddressBar && firstSpacePos != -1) {
        const QString shortcut = t.left(firstSpacePos);
        const QString searchedString = t.mid(firstSpacePos).trimmed();

        SearchEngine en = mApp->searchEnginesManager()->engineForShortcut(shortcut);
        if (en.isValid()) {
            action.type = LoadAction::Search;
            action.searchEngine = en;
            action.loadRequest = mApp->searchEnginesManager()->searchResult(en, searchedString);
            return action;
        }
    }

    // Check for Bookmark keyword
    const QList<BookmarkItem*> items = mApp->bookmarks()->searchKeyword(t);
    if (!items.isEmpty()) {
        BookmarkItem* item = items.at(0);
        action.type = LoadAction::Bookmark;
        action.bookmark = item;
        action.loadRequest.setUrl(item->url());
        return action;
    }

    if (!qzSettings->searchFromAddressBar) {
        const QUrl &guessedUrl = QUrl::fromUserInput(t);
        if (guessedUrl.isValid()) {
            action.type = LoadAction::Url;
            action.loadRequest = guessedUrl;
        }
        return action;
    }

    // Check for one word search
    if (t != QL1S("localhost")
            && !QzTools::containsSpace(t)
            && !t.contains(QL1C('.'))
            && !t.contains(QL1C(':'))
            && !t.contains(QL1C('/'))
       ) {
        action.type = LoadAction::Search;
        action.searchEngine = searchEngine();
        action.loadRequest = mApp->searchEnginesManager()->searchResult(searchEngine(), t);
        return action;
    }

    // Otherwise load as url
    const QUrl &guessedUrl = QUrl::fromUserInput(t);
    if (guessedUrl.isValid()) {
        // Always allow javascript: to be loaded
        const bool forceLoad = guessedUrl.scheme() == QL1S("javascript");
        // Only allow spaces in query
        if (forceLoad || !QzTools::containsSpace(guessedUrl.toString(QUrl::RemoveQuery))) {
            // Only allow whitelisted schemes
            static const QSet<QString> whitelistedSchemes = {
                QSL("http"), QSL("https"), QSL("ftp"), QSL("file"),
                QSL("data"), QSL("about"), QSL("qupzilla")
            };
            if (forceLoad || whitelistedSchemes.contains(guessedUrl.scheme())) {
                action.type = LoadAction::Url;
                action.loadRequest = guessedUrl;
                return action;
            }
        }
    }

    // Search when creating url failed
    action.type = LoadAction::Search;
    action.searchEngine = searchEngine();
    action.loadRequest = mApp->searchEnginesManager()->searchResult(searchEngine(), t);
    return action;
}