示例#1
0
void BookmarksModel::removeBookmark(const QList<int> list)
{
    QSqlDatabase db = QSqlDatabase::database();
    db.transaction();

    foreach(int id, list) {
        QSqlQuery query;
        query.prepare("SELECT url, title, folder FROM bookmarks WHERE id = ?");
        query.bindValue(0, id);
        query.exec();
        if (!query.next()) {
            continue;
        }

        Bookmark bookmark;
        bookmark.id = id;
        bookmark.url = query.value(0).toUrl();
        bookmark.title = query.value(1).toString();
        bookmark.folder = query.value(2).toString();
        bookmark.image = QImage::fromData(query.value(3).toByteArray());
        bookmark.inSubfolder = isSubfolder(bookmark.folder);

        if (!query.exec("DELETE FROM bookmarks WHERE id = " + QString::number(id))) {
            continue;
        }

        emit bookmarkDeleted(bookmark);
    }
示例#2
0
bool BookmarksModel::removeBookmark(int id)
{
    QSqlQuery query;
    query.prepare("SELECT url, title, folder FROM bookmarks WHERE id = ?");
    query.bindValue(0, id);
    query.exec();
    if (!query.next()) {
        return false;
    }

    Bookmark bookmark;
    bookmark.id = id;
    bookmark.url = query.value(0).toUrl();
    bookmark.title = query.value(1).toString();
    bookmark.folder = query.value(2).toString();
    bookmark.image = QImage::fromData(query.value(3).toByteArray());
    bookmark.inSubfolder = isSubfolder(bookmark.folder);

    if (!query.exec("DELETE FROM bookmarks WHERE id = " + QString::number(id))) {
        return false;
    }

    emit bookmarkDeleted(bookmark);
    mApp->sendMessages(Qz::AM_BookmarksChanged, true);
    return true;
}
示例#3
0
bool BookmarksModel::editBookmark(int id, const QString &title, const QUrl &url, const QString &folder)
{
    if (title.isEmpty() && url.isEmpty() && folder.isEmpty()) {
        return false;
    }
    QSqlQuery query;
    if (!query.exec("SELECT title, url, folder, icon FROM bookmarks WHERE id = " + QString::number(id))) {
        return false;
    }

    query.next();

    Bookmark before;
    before.id = id;
    before.title = query.value(0).toString();
    before.url = query.value(1).toUrl();
    before.folder = query.value(2).toString();
    before.image = QImage::fromData(query.value(3).toByteArray());
    before.inSubfolder = isSubfolder(before.folder);

    Bookmark after;
    after.id = id;
    after.title = title.isEmpty() ? before.title : title;
    after.url = url.isEmpty() ? before.url : url;
    after.folder = folder.isEmpty() ? before.folder : folder;
    after.image = before.image;
    after.inSubfolder = isSubfolder(after.folder);

    query.prepare("UPDATE bookmarks SET title=?, url=?, folder=? WHERE id = ?");
    query.bindValue(0, after.title);
    query.bindValue(1, after.url.toString());
    query.bindValue(2, after.folder);
    query.bindValue(3, id);

    if (!query.exec()) {
        return false;
    }

    emit bookmarkEdited(before, after);
    mApp->sendMessages(Qz::AM_BookmarksChanged, true);
    return true;
}
示例#4
0
BookmarksModel::Bookmark BookmarksModel::getBookmark(int id)
{
    Bookmark bookmark;
    QSqlQuery query;
    query.prepare("SELECT url, title, folder, icon FROM bookmarks WHERE id=?");
    query.bindValue(0, id);
    query.exec();
    if (query.next()) {
        bookmark.id = id;
        bookmark.url = query.value(0).toUrl();
        bookmark.title = query.value(1).toString();
        bookmark.folder = query.value(2).toString();
        bookmark.image = QImage::fromData(query.value(3).toByteArray());
        bookmark.inSubfolder = isSubfolder(bookmark.folder);
    }
    return bookmark;
}
示例#5
0
bool BookmarksModel::saveBookmark(const QUrl &url, const QString &title, const QIcon &icon, const QString &folder)
{
    if (url.isEmpty() || title.isEmpty() || folder.isEmpty()) {
        return false;
    }

    QImage image = icon.pixmap(16, 16).toImage();
    if (image.isNull()) {
        image = IconProvider::emptyWebImage();
    }

    if (!isFolder(folder)) {
        createFolder(folder);
    }

    QSqlQuery query;
    query.prepare("INSERT INTO bookmarks (url, title, folder, icon) VALUES (?,?,?,?)");
    query.bindValue(0, url.toString());
    query.bindValue(1, title);
    query.bindValue(2, folder);
    QByteArray ba;
    QBuffer buffer(&ba);
    buffer.open(QIODevice::WriteOnly);
    image.save(&buffer, "PNG");
    query.bindValue(3, buffer.data());
    query.exec();

    Bookmark bookmark;
    bookmark.id = query.lastInsertId().toInt();
    bookmark.url = url;
    bookmark.title = title;
    bookmark.folder = folder;
    bookmark.image = image;
    bookmark.inSubfolder = isSubfolder(bookmark.folder);

    setLastFolder(folder);

    emit bookmarkAdded(bookmark);
    mApp->sendMessages(Qz::AM_BookmarksChanged, true);
    return true;
}
示例#6
0
QList<Bookmark> BookmarksModel::folderBookmarks(const QString &name)
{
    QList<Bookmark> list;

    QSqlQuery query;
    query.prepare("SELECT id, url, title, folder, icon FROM bookmarks WHERE folder=?");
    query.addBindValue(name);
    query.exec();
    while (query.next()) {
        Bookmark bookmark;
        bookmark.id = query.value(0).toInt();
        bookmark.url = query.value(1).toUrl();
        bookmark.title = query.value(2).toString();
        bookmark.folder = query.value(3).toString();
        bookmark.image = QImage::fromData(query.value(4).toByteArray());
        bookmark.inSubfolder = isSubfolder(bookmark.folder);

        list.append(bookmark);
    }

    return list;
}