diff --git a/src/db/dbactions.h b/src/db/dbactions.h index f7bb913..e56a960 100644 --- a/src/db/dbactions.h +++ b/src/db/dbactions.h @@ -1,51 +1,53 @@ /*** Buho Copyright (C) 2018 Camilo Higuita This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ***/ #ifndef DBACTIONS_H #define DBACTIONS_H #include #include "db.h" class DBActions : public DB { Q_OBJECT public: explicit DBActions(QObject *parent = nullptr); ~DBActions(); Q_INVOKABLE QVariantList get(const QString &queryTxt); /*main actions*/ Q_INVOKABLE bool insertNote(const QString &title, const QString &body, const QString &color = QString(), const QString &tags = QString()); Q_INVOKABLE bool updateNote(const QString &id, const QString &title, const QString &body, const QString &color = QString(), const QString &tags = QString()); Q_INVOKABLE QVariantList getNotes(); + Q_INVOKABLE bool insertLink(const QString &link, const QString &title, const QString &preview, const QString &color = QString(), const QString &tags = QString()); + protected: OWL::DB_LIST getDBData(const QString &queryTxt); bool execQuery(const QString &queryTxt); signals: void noteInserted(QVariantMap note); }; #endif // DBACTIONS_H diff --git a/src/db/script.sql b/src/db/script.sql index 4c651d1..3a521f4 100644 --- a/src/db/script.sql +++ b/src/db/script.sql @@ -1,24 +1,25 @@ CREATE TABLE IF NOT EXISTS NOTES ( id TEXT PRIMARY KEY, title TEXT, body TEXT, color TEXT, addDate DATE, updated DATE ); CREATE TABLE IF NOT EXISTS BOOKS ( url TEXT PRIMARY KEY, title TEXT NOT NULL, fav INTEGER NOT NULL, addDate DATE ); CREATE TABLE IF NOT EXISTS LINKS ( -url TEXT PRIMARY KEY, +link TEXT PRIMARY KEY, +url TEXT, title TEXT, body TEXT, preview TEXT, addDate DATE ); diff --git a/src/linker.cpp b/src/linker.cpp index 26fa99b..779a309 100644 --- a/src/linker.cpp +++ b/src/linker.cpp @@ -1,133 +1,92 @@ #include "linker.h" #include -<<<<<<< Updated upstream #include "owl.h" -======= -//#include ->>>>>>> Stashed changes - Linker::Linker(QObject *parent) : QObject(parent) { } /* extract needs to extract from a url the title, the body and a preview image*/ void Linker::extract(const QString &url) { auto data = this->getUrl(url); auto titles = query(data, HtmlTag::TITLE); QStringList imgs ; for(auto img : query(data, HtmlTag::IMG, "src")) { if(imgs.contains(img) || img.isEmpty()) continue; if(url.at(url.length()-1) == "/") { if(img.startsWith("http")) imgs << img; else imgs << url+img; }else { if(img.startsWith("http")) imgs << img; else imgs << url+"/"+img; } } LINK link_data {{OWL::KEYMAP[OWL::KEY::TITLE], titles}, {OWL::KEYMAP[OWL::KEY::BODY], data}, {OWL::KEYMAP[OWL::KEY::IMAGE], imgs}}; emit previewReady(link_data); } QByteArray Linker::getUrl(const QString &url) { QUrl mURL(url); QNetworkAccessManager manager; QNetworkRequest request (mURL); QNetworkReply *reply = manager.get(request); QEventLoop loop; connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), &loop, SLOT(quit())); loop.exec(); if(reply->error()) { qDebug() << reply->error(); return QByteArray(); } if(reply->bytesAvailable()) { auto data = reply->readAll(); reply->deleteLater(); return data; } return QByteArray(); } QStringList Linker::query(const QByteArray &array, const HtmlTag &tag, const QString &attribute) { -<<<<<<< Updated upstream QStringList res; auto doc = QGumboDocument::parse(array); auto root = doc.rootNode(); -======= -// auto frame = new QWebPage(this); - -// QWebSettings::setObjectCacheCapacities(0,0,0); -// frame->settings()->setAttribute(QWebSettings::LocalContentCanAccessFileUrls,false); -// frame->settings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls,false); - -// connect(frame->mainFrame(), &QWebFrame::loadFinished, [qq, this](bool ok) -// { -// this->parsingWork(qq); -// }); ->>>>>>> Stashed changes auto node = root.getElementsByTagName(tag); -<<<<<<< Updated upstream - for(const auto &i : node) { if(attribute.isEmpty()) res << i.innerText(); else res << i.getAttribute(attribute); } return res; -======= -// qDebug() << "Count Chars :: " << array.count(); -// frame->mainFrame()->setHtml(array); - -// doc = frame->mainFrame()->documentElement(); - } -void Linker::parsingWork(QString query) -{ -// qDebug() << "Start parsing content ....."; - -// QWebElementCollection linkCollection = doc.findAll(query); -// qDebug() << "Found " << linkCollection.count() << " links"; - -// foreach (QWebElement link, linkCollection) -// { -// qDebug() << "found link " << link.toPlainText(); -// } - -// qDebug() << "stop parsing content ....."; ->>>>>>> Stashed changes -} diff --git a/src/linker.cpp.autosave b/src/linker.cpp.autosave deleted file mode 100644 index 37dab2b..0000000 --- a/src/linker.cpp.autosave +++ /dev/null @@ -1,97 +0,0 @@ -#include "linker.h" -#include -<<<<<<< Updated upstream -#include "owl.h" -======= -//#include ->>>>>>> Stashed changes - - -Linker::Linker(QObject *parent) : QObject(parent) -{ - -} - -/* extract needs to extract from a url the title, the body and a preview image*/ -void Linker::extract(const QString &url) -{ - auto data = this->getUrl(url); - - auto titles = query(data, HtmlTag::TITLE); - QStringList imgs ; - - for(auto img : query(data, HtmlTag::IMG, "src")) - { - if(imgs.contains(img) || img.isEmpty()) continue; - - - if(url.at(url.length()-1) == "/") - { - if(img.startsWith("http")) - imgs << img; - else - imgs << url+img; - }else - { - if(img.startsWith("http")) - imgs << img; - else - imgs << url+"/"+img; - } - } - LINK link_data {{OWL::KEYMAP[OWL::KEY::TITLE], titles}, - {OWL::KEYMAP[OWL::KEY::BODY], data}, - {OWL::KEYMAP[OWL::KEY::IMAGE], imgs}}; - emit previewReady(link_data); -} - -QByteArray Linker::getUrl(const QString &url) -{ - QUrl mURL(url); - QNetworkAccessManager manager; - QNetworkRequest request (mURL); - - QNetworkReply *reply = manager.get(request); - QEventLoop loop; - connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); - - connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), &loop, - SLOT(quit())); - - loop.exec(); - - if(reply->error()) - { - qDebug() << reply->error(); - return QByteArray(); - } - - if(reply->bytesAvailable()) - { - auto data = reply->readAll(); - reply->deleteLater(); - - return data; - } - - return QByteArray(); -} - -QStringList Linker::query(const QByteArray &array, const HtmlTag &tag, const QString &attribute) -{ - QStringList res; - auto doc = QGumboDocument::parse(array); - auto root = doc.rootNode(); - - auto node = root.getElementsByTagName(tag); - - for(const auto &i : node) - { - if(attribute.isEmpty()) - res << i.innerText(); - else res << i.getAttribute(attribute); - } - - return res; -} -