Further Changed on the QML side to adopt the previous changes on the C++ side

This commit is contained in:
Scharel Clemens 2020-05-03 18:30:39 +02:00
parent 842ea9f699
commit fe31598042
8 changed files with 108 additions and 113 deletions

View file

@ -6,6 +6,18 @@ Dialog {
id: editDialog id: editDialog
property int id property int id
property var note
onIdChanged: note = notesModel.getNoteById(id)
onNoteChanged: {
dialogHeader.title = note["title"]
contentArea.text = note["content"]
favoriteButton.selected = note["favorite"]
categoryField.text = note["category"]
modifiedDetail.modified = note["modified"]
//parseContent()
}
property int modified property int modified
property string title property string title
property string category property string category
@ -19,16 +31,6 @@ Dialog {
notesApi.updateNote(id, { 'category': categoryField.text, 'content': contentArea.text, 'favorite': favoriteButton.selected, 'modified': new Date().valueOf() / 1000 } ) notesApi.updateNote(id, { 'category': categoryField.text, 'content': contentArea.text, 'favorite': favoriteButton.selected, 'modified': new Date().valueOf() / 1000 } )
} }
function reloadContent() {
//notesApi.getNoteFromApi(id)
/*note = notesApi.getNote(id)
dialogHeader.title = title
contentArea.text = content
favoriteButton.selected = favorite
categoryField.text = category
modifiedDetail.modified = modified*/
}
SilicaFlickable { SilicaFlickable {
anchors.fill: parent anchors.fill: parent
contentHeight: mainColumn.height + Theme.paddingLarge contentHeight: mainColumn.height + Theme.paddingLarge
@ -169,8 +171,8 @@ Dialog {
DetailItem { DetailItem {
id: modifiedDetail id: modifiedDetail
label: qsTr("Modified") label: qsTr("Modified")
property int modified//: modified property int modified
value: new Date(modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat) onModifiedChanged: value = new Date(modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
} }
} }

View file

@ -1,4 +1,4 @@
import QtQuick 2.5 import QtQuick 2.2
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import Nemo.Configuration 1.0 import Nemo.Configuration 1.0

View file

@ -1,4 +1,4 @@
import QtQuick 2.5 import QtQuick 2.2
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import "../js/showdown/dist/showdown.js" as ShowDown import "../js/showdown/dist/showdown.js" as ShowDown
@ -6,8 +6,22 @@ Dialog {
id: noteDialog id: noteDialog
property int id property int id
//property var note: notesProxyModel.getNote(notesProxyModel.index(index, 0)) property var note
property var note: notesModel.getNoteById(id)
onIdChanged: note = notesModel.getNoteById(id)
onNoteChanged: {
if (note["content"].split('\n')[0].indexOf(note["title"]) > 0) {
dialogHeader.title = ""
}
else {
dialogHeader.title = note["title"]
}
favoriteButton.selected = note["favorite"]
categoryField.text = note["category"]
modifiedDetail.modified = note["modified"]
parseContent()
}
Connections { Connections {
target: notesModel target: notesModel
onNoteUpdated: { onNoteUpdated: {
@ -17,6 +31,18 @@ Dialog {
} }
} }
acceptDestination: Qt.resolvedUrl("EditPage.qml")
onAcceptPendingChanged: {
if (acceptPending)
acceptDestinationInstance.id = id
}
onStatusChanged: {
if (status === PageStatus.Activating) {
notesModel.getNote(id)
}
}
property var showdown: ShowDown.showdown property var showdown: ShowDown.showdown
property var converter: new showdown.Converter( property var converter: new showdown.Converter(
{ simplifiedAutoLink: true, { simplifiedAutoLink: true,
@ -29,57 +55,7 @@ Dialog {
simpleLineBreaks: true, simpleLineBreaks: true,
emoji: true } ) emoji: true } )
acceptDestination: Qt.resolvedUrl("EditPage.qml")
acceptDestinationProperties: (
{ id: id,
modified: modified,
title: title,
category: category,
content: content,
favorite: favorite,
etag: etag,
error: error,
errorMessage: errorMessage
} )
onAccepted: {
//acceptDestinationInstance.note = note
acceptDestinationInstance.reloadContent()
}
onStatusChanged: {
if (status === DialogStatus.Opened) {
//notesApi.getNoteFromApi(id)
}
}
Component.onCompleted: {
parseContent()
}
Connections {
target: notesProxyModel
onDataChanged: {
console.log(topLeft, bottomRight, index)
if (notesProxyModel.index(topLeft, bottomRight) === index) {
console.log("This note changed")
}
else {
console.log("Another note changed")
}
}
}
function reloadContent() {
//notesApi.getNoteFromApi(id)
/*note = notesApi.getNote(id)
dialogHeader.title = title
favoriteButton.selected = favorite
categoryField.text = category
modifiedDetail.modified = modified
parseContent()*/
}
function parseContent() { function parseContent() {
//note = notesApi.getNoteFromApi(id, false)
var convertedText = converter.makeHtml(note["content"]) var convertedText = converter.makeHtml(note["content"])
var occurence = -1 var occurence = -1
convertedText = convertedText.replace(/^<li>(<p>)?\[ \] (.*)(<.*)$/gmi, convertedText = convertedText.replace(/^<li>(<p>)?\[ \] (.*)(<.*)$/gmi,
@ -130,6 +106,11 @@ Dialog {
enabled: !notesApi.busy enabled: !notesApi.busy
onClicked: notesApi.getNote(note["id"]) onClicked: notesApi.getNote(note["id"])
} }
/*MenuItem {
text: qsTr("Edit")
onClicked: pageStack.push(Qt.resolvedUrl("../pages/NotePage.qml"), { id: id } )
}*/
MenuLabel { MenuLabel {
visible: appSettings.currentAccount.length >= 0 visible: appSettings.currentAccount.length >= 0
text: qsTr("Last update") + ": " + ( text: qsTr("Last update") + ": " + (
@ -141,7 +122,6 @@ Dialog {
DialogHeader { DialogHeader {
id: dialogHeader id: dialogHeader
//title: noteDialog.title
acceptText: qsTr("Edit") acceptText: qsTr("Edit")
cancelText: qsTr("Notes") cancelText: qsTr("Notes")
} }
@ -157,12 +137,6 @@ Dialog {
width: parent.width width: parent.width
spacing: Theme.paddingLarge spacing: Theme.paddingLarge
/*Separator {
width: parent.width
color: Theme.primaryColor
horizontalAlignment: Qt.AlignHCenter
}*/
LinkedLabel { LinkedLabel {
id: contentLabel id: contentLabel
x: Theme.horizontalPageMargin x: Theme.horizontalPageMargin
@ -251,7 +225,7 @@ Dialog {
width: parent.width - x width: parent.width - x
IconButton { IconButton {
id: favoriteButton id: favoriteButton
property bool selected: note["favorite"] property bool selected: false
width: Theme.iconSizeMedium width: Theme.iconSizeMedium
icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") + icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
(favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor) (favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
@ -262,7 +236,6 @@ Dialog {
TextField { TextField {
id: categoryField id: categoryField
width: parent.width - favoriteButton.width width: parent.width - favoriteButton.width
text: note["category"]
placeholderText: qsTr("No category") placeholderText: qsTr("No category")
label: qsTr("Category") label: qsTr("Category")
EnterKey.iconSource: "image://theme/icon-m-enter-accept" EnterKey.iconSource: "image://theme/icon-m-enter-accept"
@ -270,7 +243,7 @@ Dialog {
categoryField.focus = false categoryField.focus = false
} }
onFocusChanged: { onFocusChanged: {
if (focus === false && text !== category) { if (focus === false && text !== note["category"]) {
notesApi.updateNote(id, {'content': content, 'category': text, 'modified': new Date().valueOf() / 1000}) // This does not seem to work without adding the content notesApi.updateNote(id, {'content': content, 'category': text, 'modified': new Date().valueOf() / 1000}) // This does not seem to work without adding the content
} }
} }
@ -280,7 +253,8 @@ Dialog {
DetailItem { DetailItem {
id: modifiedDetail id: modifiedDetail
label: qsTr("Modified") label: qsTr("Modified")
value: new Date(note["modified"] * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat) property int modified
onModifiedChanged: value = new Date(modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
} }
} }

View file

@ -106,7 +106,7 @@ Page {
id: remorse id: remorse
} }
onClicked: pageStack.push(Qt.resolvedUrl("../pages/NotePage.qml"), { id: id } ) onClicked: pageStack.push(Qt.resolvedUrl("NotePage.qml"), { id: id } )
onPressAndHold: menu.open(note) onPressAndHold: menu.open(note)
Separator { Separator {

View file

@ -130,8 +130,8 @@ void NotesModel::setAccount(const QString &account) {
mp_notesStore->setAccount(account); mp_notesStore->setAccount(account);
} }
const QJsonObject NotesModel::getNoteById(const int id) const { const QVariantMap NotesModel::getNoteById(const int id) const {
return m_notes[id]; return m_notes[id].toVariantMap();
} }
bool NotesModel::getAllNotes(const QStringList &exclude) { bool NotesModel::getAllNotes(const QStringList &exclude) {
@ -197,6 +197,12 @@ void NotesModel::insert(const int id, const QJsonObject& note) {
//emit noteInserted(id, note); //emit noteInserted(id, note);
qDebug() << "Note inserted"; qDebug() << "Note inserted";
} }
if (sender() == mp_notesApi) {
// TODO
}
if (sender() == mp_notesStore) {
// TODO
}
} }
void NotesModel::update(const int id, const QJsonObject &note) { void NotesModel::update(const int id, const QJsonObject &note) {
@ -216,6 +222,12 @@ void NotesModel::update(const int id, const QJsonObject &note) {
qDebug() << "Note changed"; qDebug() << "Note changed";
} }
} }
if (sender() == mp_notesApi) {
// TODO
}
if (sender() == mp_notesStore) {
// TODO
}
} }
void NotesModel::remove(const int id) { void NotesModel::remove(const int id) {
@ -230,6 +242,12 @@ void NotesModel::remove(const int id) {
} }
endRemoveRows(); endRemoveRows();
} }
if (sender() == mp_notesApi) {
// TODO
}
if (sender() == mp_notesStore) {
// TODO
}
} }
void NotesModel::clear() { void NotesModel::clear() {

View file

@ -72,7 +72,7 @@ public:
QString account() const; QString account() const;
void setAccount(const QString& account); void setAccount(const QString& account);
const QJsonObject getNoteById(const int id) const; Q_INVOKABLE const QVariantMap getNoteById(const int id) const;
public slots: public slots:
Q_INVOKABLE bool getAllNotes(const QStringList& exclude = QStringList()); Q_INVOKABLE bool getAllNotes(const QStringList& exclude = QStringList());

View file

@ -191,7 +191,8 @@ bool NotesStore::getNote(const int id, const QStringList& exclude) {
} }
bool NotesStore::createNote(const QJsonObject& note) { bool NotesStore::createNote(const QJsonObject& note) {
/* qDebug() << "Creating note: " << id; int id = note.value("id").toInt(-1);
qDebug() << "Creating note: " << id;
if (id < 0) { if (id < 0) {
// TODO probably crate files with an '.json.<NUMBER>.new' extension // TODO probably crate files with an '.json.<NUMBER>.new' extension
qDebug() << "Creating notes without the server API is not supported yet!"; qDebug() << "Creating notes without the server API is not supported yet!";
@ -204,7 +205,7 @@ bool NotesStore::createNote(const QJsonObject& note) {
} }
else { else {
qDebug() << "Note already exists"; qDebug() << "Note already exists";
}*/ }
return false; return false;
} }

View file

@ -84,32 +84,32 @@
<context> <context>
<name>EditPage</name> <name>EditPage</name>
<message> <message>
<location filename="../qml/pages/EditPage.qml" line="38"/> <location filename="../qml/pages/EditPage.qml" line="40"/>
<source>Reset</source> <source>Reset</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/EditPage.qml" line="42"/> <location filename="../qml/pages/EditPage.qml" line="44"/>
<source>Markdown syntax</source> <source>Markdown syntax</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/EditPage.qml" line="70"/> <location filename="../qml/pages/EditPage.qml" line="72"/>
<source>No content</source> <source>No content</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/EditPage.qml" line="155"/> <location filename="../qml/pages/EditPage.qml" line="157"/>
<source>No category</source> <source>No category</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/EditPage.qml" line="156"/> <location filename="../qml/pages/EditPage.qml" line="158"/>
<source>Category</source> <source>Category</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/EditPage.qml" line="171"/> <location filename="../qml/pages/EditPage.qml" line="173"/>
<source>Modified</source> <source>Modified</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -143,17 +143,17 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/LoginPage.qml" line="239"/> <location filename="../qml/pages/LoginPage.qml" line="240"/>
<source>Username</source> <source>Username</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/LoginPage.qml" line="250"/> <location filename="../qml/pages/LoginPage.qml" line="251"/>
<source>Password</source> <source>Password</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/LoginPage.qml" line="225"/> <location filename="../qml/pages/LoginPage.qml" line="226"/>
<source>Abort</source> <source>Abort</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -179,57 +179,57 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/LoginPage.qml" line="207"/> <location filename="../qml/pages/LoginPage.qml" line="208"/>
<source>Enforce legacy login</source> <source>Enforce legacy login</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/LoginPage.qml" line="225"/> <location filename="../qml/pages/LoginPage.qml" line="226"/>
<source>Login</source> <source>Login</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/LoginPage.qml" line="225"/> <location filename="../qml/pages/LoginPage.qml" line="226"/>
<source>Re-Login</source> <source>Re-Login</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/LoginPage.qml" line="259"/> <location filename="../qml/pages/LoginPage.qml" line="260"/>
<source>Test Login</source> <source>Test Login</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/LoginPage.qml" line="265"/> <location filename="../qml/pages/LoginPage.qml" line="266"/>
<source>Note</source> <source>Note</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/LoginPage.qml" line="273"/> <location filename="../qml/pages/LoginPage.qml" line="274"/>
<source>The &lt;a href=&quot;https://apps.nextcloud.com/apps/notes&quot;&gt;Notes&lt;/a&gt; app needs to be installed on the Nextcloud server for this app to work.</source> <source>The &lt;a href=&quot;https://apps.nextcloud.com/apps/notes&quot;&gt;Notes&lt;/a&gt; app needs to be installed on the Nextcloud server for this app to work.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/LoginPage.qml" line="277"/> <location filename="../qml/pages/LoginPage.qml" line="278"/>
<source>Security</source> <source>Security</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/LoginPage.qml" line="284"/> <location filename="../qml/pages/LoginPage.qml" line="285"/>
<source>&lt;strong&gt;CAUTION: Your password will be saved without any encryption on the device!&lt;/strong&gt;&lt;br&gt;Please consider creating a dedicated app password! Open your Nextcloud in a browser and go to &lt;i&gt;Settings&lt;/i&gt; &lt;i&gt;Security&lt;/i&gt;.</source> <source>&lt;strong&gt;CAUTION: Your password will be saved without any encryption on the device!&lt;/strong&gt;&lt;br&gt;Please consider creating a dedicated app password! Open your Nextcloud in a browser and go to &lt;i&gt;Settings&lt;/i&gt; &lt;i&gt;Security&lt;/i&gt;.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/LoginPage.qml" line="288"/> <location filename="../qml/pages/LoginPage.qml" line="289"/>
<source>Do not check certificates</source> <source>Do not check certificates</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/LoginPage.qml" line="289"/> <location filename="../qml/pages/LoginPage.qml" line="290"/>
<source>Enable this option to allow selfsigned certificates</source> <source>Enable this option to allow selfsigned certificates</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/LoginPage.qml" line="298"/> <location filename="../qml/pages/LoginPage.qml" line="299"/>
<source>Allow unencrypted connections</source> <source>Allow unencrypted connections</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -263,52 +263,52 @@
<context> <context>
<name>NotePage</name> <name>NotePage</name>
<message> <message>
<location filename="../qml/pages/NotePage.qml" line="125"/> <location filename="../qml/pages/NotePage.qml" line="96"/>
<source>Delete</source> <source>Delete</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/NotePage.qml" line="129"/> <location filename="../qml/pages/NotePage.qml" line="100"/>
<source>Reload</source> <source>Reload</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/NotePage.qml" line="129"/> <location filename="../qml/pages/NotePage.qml" line="100"/>
<source>Updating...</source> <source>Updating...</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/NotePage.qml" line="135"/> <location filename="../qml/pages/NotePage.qml" line="111"/>
<source>Last update</source> <source>Last update</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/NotePage.qml" line="138"/> <location filename="../qml/pages/NotePage.qml" line="114"/>
<source>never</source> <source>never</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/NotePage.qml" line="145"/> <location filename="../qml/pages/NotePage.qml" line="120"/>
<source>Edit</source> <source>Edit</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/NotePage.qml" line="146"/> <location filename="../qml/pages/NotePage.qml" line="121"/>
<source>Notes</source> <source>Notes</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/NotePage.qml" line="266"/> <location filename="../qml/pages/NotePage.qml" line="234"/>
<source>No category</source> <source>No category</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/NotePage.qml" line="267"/> <location filename="../qml/pages/NotePage.qml" line="235"/>
<source>Category</source> <source>Category</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/NotePage.qml" line="282"/> <location filename="../qml/pages/NotePage.qml" line="250"/>
<source>Modified</source> <source>Modified</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>