Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit a7cb11a9 authored by Camilo Higuita's avatar Camilo Higuita

more work on links saver

parent 84720fed
<?xml version="1.0"?>
<manifest package="org.kde.buho" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
<manifest package="Buho" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="Buho">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="Buho" android:screenOrientation="unspecified" android:launchMode="singleTop">
<intent-filter>
......@@ -11,7 +11,7 @@
<!-- meta-data android:name="android.app.arguments" android:value="arg1 arg2 arg3"/ -->
<!-- Application arguments -->
<meta-data android:name="android.app.lib_name" android:value="buho"/>
<meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
<meta-data android:name="android.app.repository" android:value="default"/>
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
......
......@@ -14,7 +14,8 @@ SOURCES += \
src/db/dbactions.cpp \
src/buho.cpp \
src/documenthandler.cpp \
src/linker.cpp
src/linker.cpp \
src/utils/htmlparser.cpp
RESOURCES += \
qml.qrc
......@@ -50,7 +51,14 @@ linux:unix:!android {
DISTFILES += \
src/db/script.sql \
src/utils/owl.js
src/utils/owl.js \
android/AndroidManifest.xml \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradlew \
android/res/values/libs.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat
HEADERS += \
src/db/db.h \
......@@ -58,5 +66,9 @@ HEADERS += \
src/buho.h \
src/utils/owl.h \
src/documenthandler.h \
src/linker.h
src/linker.h \
src/utils/htmlparser.h
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
......@@ -18,7 +18,7 @@
#include "mauikit/src/mauikit.h"
#include "src/buho.h"
#include "src/documenthandler.h"
#include "src/linker.h"
int main(int argc, char *argv[])
{
......@@ -46,6 +46,9 @@ int main(int argc, char *argv[])
auto context = engine.rootContext();
context->setContextProperty("owl", &owl);
Linker linker;
context->setContextProperty("linker", &linker);
qmlRegisterType<DocumentHandler>("org.buho.editor", 1, 0, "DocumentHandler");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
......
......@@ -5,6 +5,7 @@ import org.kde.maui 1.0 as Maui
import "src/widgets"
import "src/views/notes"
import "src/views/links"
Maui.ApplicationWindow
{
......@@ -63,6 +64,8 @@ Maui.ApplicationWindow
{
if(item.mid === "note")
newNoteDialog.open()
else if(item.mid === "link")
newLinkDialog.open()
}
}
......@@ -101,6 +104,11 @@ Maui.ApplicationWindow
}
NewLinkDialog
{
id: newLinkDialog
}
/***** VIEWS *****/
SwipeView
......@@ -112,7 +120,11 @@ Maui.ApplicationWindow
{
id: notesView
onNoteClicked: setNote(note)
}
LinksView
{
id: linksView
}
}
......
......@@ -7,5 +7,6 @@
<file>src/views/notes/NotesView.qml</file>
<file>src/widgets/CardDelegate.qml</file>
<file>src/widgets/NewLinkDialog.qml</file>
<file>src/views/links/LinksView.qml</file>
</qresource>
</RCC>
#include "linker.h"
#include <QEventLoop>
#include <QWebFrame>
linker::linker(QObject *parent) : QObject(parent)
#include "utils/htmlparser.h"
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);
htmlParser parser;
parser.setHtml(data);
qDebug()<<data;
query(data, "title");
}
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();
}
void Linker::query(QByteArray &array, QString qq)
{
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);
});
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 .....";
}
......@@ -2,16 +2,33 @@
#define LINKER_H
#include <QObject>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QWebPage>
#include <QWebElementCollection>
class linker : public QObject
typedef QVariantMap LINK;
class Linker : public QObject
{
Q_OBJECT
public:
explicit linker(QObject *parent = nullptr);
explicit Linker(QObject *parent = nullptr);
Q_INVOKABLE void extract(const QString &url);
private:
QByteArray getUrl(const QString &url);
void query(QByteArray &array, QString qq);
QWebElement doc;
signals:
void previewReady(LINK data);
public slots:
void parsingWork(QString query);
};
#endif // LINKER_H
\ No newline at end of file
#endif // LINKER_H
#include "htmlparser.h"
htmlParser::htmlParser(QObject *parent) : QObject(parent)
{
}
void htmlParser::setHtml(const QByteArray &array)
{
this->html = array;
}
QString htmlParser::extractProp(const QString &tag,const QString &prop)
{
// qDebug()<<"extractProp"<<tag;
auto list = tag.split(" ");
auto result =list.filter(prop,Qt::CaseInsensitive);
// qDebug()<<result;
auto url = result.first().replace(prop,"").replace('\"',"");
// qDebug()<<url;
return url;
}
QStringList htmlParser::parseTag(const QString &tagRef, const QString &attribute)
{
QStringList results;
QStringList html(QString(this->html).split(">"));
for(auto i =0; i<html.size();i++)
{
QString tag = html.at(i);
tag+=">";
if(findTag(tag,"<"+tagRef+">") && tag.contains(attribute))
{
QString subResult;
// qDebug()<<subResult;
while(!html.at(i).contains("</"+tagRef))
{
auto subTag=html.at(i);
subTag+=">";
subResult+=subTag;
i++;
if(i>html.size()) break;
}
results<<subResult.simplified();
qDebug()<<subResult;
}
}
return results;
}
/*QStringList htmlParser::parseTag_old(const QString &tagRef)
{
QString html(this->html);
QStringList tags;
int i =0;
while(html.size()>i)
{
if(html.at(i)=="<")
{
QString tag;
while(html.at(i)!=">")
{
tag+=html.at(i);
i++;
if(i>html.size()) break;
}
tag+=">";
if(findTag(tag,tagRef))
{
tags<<tag;
qDebug()<<tag;
}
}
i++;
if(i>html.size()) break;
}
return tags;
}*/
bool htmlParser::findTag(const QString &txt, const QString &tagRef)
{
// qDebug()<<"size of tag<<"<<txt.size();
int i =0;
QString subTag;
while(i<txt.size())
{
if(txt.at(i).toLatin1()=='<')
{
while(!txt.at(i).isSpace() && txt.at(i).toLatin1()!='>')
{
subTag+=txt.at(i);
i++;
if(i>txt.size()) break;
}
subTag+=">";
}
i++;
if(i>txt.size()) break;
}
if(tagRef==subTag) return true;
else return false;
}
#ifndef HTMLPARSER_H
#define HTMLPARSER_H
#include <QObject>
#include <QStringList>
#include <QString>
#include <QDebug>
class htmlParser : public QObject
{
Q_OBJECT
public:
explicit htmlParser(QObject *parent = nullptr);
void setHtml(const QByteArray &html);
QStringList parseTag(const QString &tagRef, const QString &attribute=""); // return all tag matches with content
bool findTag(const QString &txt, const QString &tagRef);
QString extractProp(const QString &tag, const QString &prop);
private:
QByteArray html;
signals:
void finishedParsingTags(const QStringList &tags);
void finishedExtractingProp(const QString &prop);
public slots:
};
#endif // HTMLPARSER_H
import QtQuick 2.9
import "../../widgets"
import org.kde.maui 1.0 as Maui
Maui.Page
{
id: control
}
......@@ -11,9 +11,8 @@ ItemDelegate
property string noteColor : color ? color : "pink"
property int cardWidth: Kirigami.Units.devicePixelRatio*200
property int cardHeight: Kirigami.Units.devicePixelRatio*120
width: cardWidth
height: cardHeight
height: cardHeight
background: Rectangle
{
......@@ -48,6 +47,7 @@ ItemDelegate
{
anchors.fill: parent
spacing: 0
clip: true
Label
{
......@@ -59,6 +59,8 @@ ItemDelegate
Layout.rightMargin: space.medium
Layout.fillWidth: true
text: model.title
color: Qt.darker(model.color, 3)
font.weight: Font.Bold
font.bold: true
font.pointSize: fontSizes.large
......@@ -77,6 +79,8 @@ ItemDelegate
Layout.fillWidth: true
enabled: false
text: model.body
color: Qt.darker(model.color, 3)
textFormat: TextEdit.RichText
font.pointSize: fontSizes.big
......@@ -102,7 +106,7 @@ ItemDelegate
sourceSize.height: height
sourceSize.width: width
fillMode: Image.PreserveAspectCrop
source: model.preview
source: model.preview || ""
}
}
}
......
......@@ -6,7 +6,8 @@ import org.kde.maui 1.0 as Maui
GridView
{
property alias holder : holder
property int itemWidth : Kirigami.Units.devicePixelRatio * 200
readonly property int defaultSize : Kirigami.Units.devicePixelRatio * 200
property int itemWidth : !isMobile ? Kirigami.Units.devicePixelRatio * 200 : parent.width
property int itemHeight: Kirigami.Units.devicePixelRatio * 120
property int itemSpacing: space.huge
......@@ -34,11 +35,10 @@ GridView
{
currentIndex = index
itemClicked(index)
}
}
onWidthChanged: adaptGrid()
onWidthChanged: if(!isMobile) adaptGrid()
function adaptGrid()
{
......
......@@ -7,7 +7,8 @@ import org.buho.editor 1.0
Popup
{
parent: ApplicationWindow.overlay
height: parent.height * (isMobile ? 0.8 : 0.7)
height: previewReady ? parent.height * (isMobile ? 0.8 : 0.7) :
toolBarHeight
width: parent.width * (isMobile ? 0.9 : 0.7)
signal linkSaved(var note)
......@@ -21,7 +22,7 @@ Popup
Rectangle
{
id: bg
color: selectedColor
color: "transparent"
z: -1
anchors.fill: parent
}
......@@ -37,6 +38,25 @@ Popup
Layout.fillWidth: true
Layout.margins: space.medium
height: 24
placeholderText: qsTr("URL")
font.weight: Font.Bold
font.bold: true
font.pointSize: fontSizes.large
background: Rectangle
{
color: "transparent"
}
onAccepted: linker.extract(link.text)
}
TextField
{
id: title
visible: previewReady
Layout.fillWidth: true
Layout.margins: space.medium
height: 24
placeholderText: qsTr("Title")
font.weight: Font.Bold
font.bold: true
......@@ -51,7 +71,7 @@ Popup
Layout.fillHeight: true
Layout.fillWidth: true
Layout.margins: space.medium
visible: previewReady
TextArea
{
id: body
......@@ -74,43 +94,35 @@ Popup
Layout.margins: space.medium
Layout.alignment: Qt.AlignRight
spacing: space.medium
visible: previewReady
Button
{
id: save
text: qsTr("Save")
onClicked:
{
close()
noteSaved({
title: title.text,
body: body.text,
color: selectedColor,
tags: ""
})
clearNote()
linker.extract(link.text)
clear()
}
}
Button
{
id: discard
text: qsTr("Discard")
onClicked:
{
close()
clearNote()
}
onClicked: clear()
}
}
}
function clearNote()
function clear()
{
title.clear()
body.clear()
close()
}
function fill(note)
......
......@@ -32,6 +32,8 @@ Popup
Maui.ToolBar
{
position: ToolBar.Header
z: 999
Layout.fillWidth: true
leftContent: [
......@@ -167,6 +169,7 @@ Popup
placeholderText: qsTr("Title")
font.weight: Font.Bold
font.bold: true
color: Qt.darker(selectedColor, 2.5)
background: Rectangle
{
color: "transparent"
......@@ -181,9 +184,9 @@ Popup
selectionStart: body.selectionStart
selectionEnd: body.selectionEnd
// textColor: TODO
// onLoaded: {
// body.text = text
// }
// onLoaded: {
// body.text = text
// }
onError: {
body.text = message
body.visible = true
......@@ -204,6 +207,7 @@ Popup
selectByKeyboard :!isMobile
selectByMouse : !isMobile
textFormat : TextEdit.AutoText
color: Qt.darker(selectedColor, 2.5)
background: Rectangle
{
......@@ -225,15 +229,15 @@ Popup
text: qsTr("Save")
onClicked:
{
close()
noteSaved({
title: title.text,
body: body.text,
color: selectedColor,
tags: ""
})
if(body.text.length > 0)
noteSaved({
title: title.text,
body: body.text,
color: selectedColor,
tags: ""
})
clearNote()
close()
}
}
......@@ -251,6 +255,8 @@ Popup
}
}
onOpened: body.forceActiveFocus()
function clearNote()
{
......@@ -267,9 +273,4 @@ Popup
open()
}
function bold()
{
// body.sele
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment