File: urlobserver.cpp

package info (click to toggle)
angelfish 25.04.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,740 kB
  • sloc: cpp: 2,703; xml: 611; javascript: 273; makefile: 16; sh: 11; sql: 7
file content (47 lines) | stat: -rw-r--r-- 1,071 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-FileCopyrightText: 2020 Rinigus <rinigus.git@gmail.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later

#include "urlobserver.h"
#include "browsermanager.h"

UrlObserver::UrlObserver(QObject *parent)
    : QObject(parent)
{
    connect(BrowserManager::instance(), &BrowserManager::databaseTableChanged, this, &UrlObserver::onDatabaseTableChanged);
}

QString UrlObserver::url() const
{
    return m_url;
}

void UrlObserver::setUrl(const QString &url)
{
    m_url = url;
    updateBookmarked();
    Q_EMIT urlChanged(url);
}

bool UrlObserver::bookmarked() const
{
    return m_bookmarked;
}

void UrlObserver::onDatabaseTableChanged(const QString &table)
{
    if (table != QStringView(u"bookmarks"))
        return;

    updateBookmarked();
}

QCoro::Task<> UrlObserver::updateBookmarked()
{
    if (const bool isBookmarked = co_await BrowserManager::instance()->databaseManager()->isBookmarked(m_url); isBookmarked != m_bookmarked) {
        m_bookmarked = isBookmarked;
        Q_EMIT bookmarkedChanged(m_bookmarked);
    }
}

#include "moc_urlobserver.cpp"