beautified it all, added file renaming

master
Tibor 2 years ago
parent 7025e7f4ce
commit 84f34fb987
  1. 4
      DirectoryDialog.qml
  2. 12
      NoteTreeView.qml
  3. 12
      log.h
  4. 59
      main.qml
  5. 28
      notehandler.cpp
  6. 8
      notehandler.h

@ -2,7 +2,7 @@ import QtQuick 2.0
import QtQuick.Controls 2.12
Dialog {
title: qsTr("Directory chooser")
title: qsTr("Change your Nextcloud directory here")
width: 400
height: 160
@ -17,7 +17,7 @@ Dialog {
id: textField
width: parent.width
placeholderText: "/home/myuser/Nextcloud"
placeholderText: "(e.g. /home/myuser/Nextcloud or C:\\Users\\myuser\\Nextcloud)"
onTextChanged: {
dirPath = text

@ -1,7 +1,7 @@
import QtQuick 2.0
import QtQuick.Controls 2.12
import QtQuick 2.15
import QtQuick.Controls 2.15
import Qt.labs.folderlistmodel 2.2
import Qt.labs.folderlistmodel 2.15
Rectangle {
property var currentIndex: view.currentIndex
@ -40,14 +40,14 @@ Rectangle {
Text {
id: fileNameText
text: noteHandler ? noteHandler.fileName(index) : null
text: noteHandler ? noteHandler.filename(index) : null
width: parent.width
height: parent.height
elide: Text.ElideMiddle
wrapMode: Text.Wrap
padding: 5
}
MouseArea {

12
log.h

@ -67,22 +67,22 @@ public:
switch (lv) {
case Level::DEBUG:
log_level = "DEBUG";
log_level = "DEBUG\t";
break;
case Level::INFO:
log_level = "INFO";
log_level = "INFO\t";
break;
case Level::WARNING:
log_level = "WARNING";
log_level = "WARNING\t";
break;
case Level::ERROR:
log_level = "ERROR";
log_level = "ERROR\t";
break;
case Level::FATAL:
log_level = "FATAL";
log_level = "FATAL\t";
break;
default:
log_level = "UNKNOWN";
log_level = "UNKNOWN\t";
break;
}

@ -21,7 +21,7 @@ ApplicationWindow {
Menu {
title: "File"
Action {
text: qsTr("&Open...")
text: qsTr("&Change Nextcloud folder...")
onTriggered: dirDialog.open()
}
@ -36,8 +36,6 @@ ApplicationWindow {
}
}
// TODO die Idee ist, 2 Spalten zu haben, links eine mit einer Zeile
// und rechts eine mit zwei Zeilen (oben: TextArea für Titel und unten: TextEdit für Notiz)
Grid {
width: parent.width
height: parent.height
@ -45,33 +43,54 @@ ApplicationWindow {
columns: 2
spacing: 2
Grid {
NoteTreeView {
id: treeView
width: parent.width * .25
height: parent.height
model: noteHandler ? noteHandler.entryList() : null
onCurrentIndexChanged: {
noteEdit.text = noteHandler ? noteHandler.fileContents(currentIndex) : null
noteName.text = noteHandler ? noteHandler.filename(currentIndex) : null
}
}
/*
width: parent.width
Grid {
width: parent.width * .75
height: parent.height
*/
rows: 2
spacing: 2
NoteTreeView {
id: treeView
width: parent.width * .25
height: parent.height
TextInput {
id: noteName
width: noteEdit.width
height: 50
model: noteHandler ? noteHandler.entryList() : null
text: noteHandler ? noteHandler.filename(treeView.currentIndex) : null
font.capitalization: Font.SmallCaps
font.bold: true
font.pointSize: 14
onCurrentIndexChanged: {
noteEdit.text = noteHandler ? noteHandler.fileContents(
currentIndex) : null
function enterPressed() {
noteHandler.setFilename(treeView.currentIndex, text);
// TODO save index to not zero it everytime enter is pressed
// reload the entry list
treeView.model = noteHandler.entryList();
// TODO insert 1-sec animation (bg change to green or similar)
}
}
TextArea {
id: noteName
width: noteEdit.width
height: 50
Keys.onReturnPressed: {
enterPressed();
}
Keys.onEnterPressed: {
enterPressed();
}
}
TextEdit {

@ -7,6 +7,8 @@ NoteHandler::NoteHandler(QString const& dirPath, std::shared_ptr<tai::config> co
{
// get notes folder entries
_notesDir.setPath(dirPath);
// QObject::connect(this, &NoteHandler::filesChanged, this, );
}
/**
@ -14,13 +16,13 @@ NoteHandler::NoteHandler(QString const& dirPath, std::shared_ptr<tai::config> co
* @param index
* @return the file name
*/
QString NoteHandler::fileName(int index)
QString NoteHandler::filename(int index)
{
if (index < 0) {
return {};
}
return entryList().at(index);
return entryList().at(index).split(".txt").first();
}
/**
@ -49,7 +51,7 @@ QString NoteHandler::fileContents(int index)
*/
QStringList NoteHandler::entryList()
{
return _notesDir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot);
return _notesDir.entryList(QDir::Files);
}
/**
@ -59,6 +61,11 @@ QStringList NoteHandler::entryList()
*/
void NoteHandler::setDirPath(QString const& newDirPath)
{
if (newDirPath.isEmpty()) {
LOG_WRN("No path provided, path is empty.");
return;
}
QDir const& path { QDir(newDirPath) };
std::string const& newPathStd { newDirPath.toStdString() };
@ -78,4 +85,19 @@ void NoteHandler::setDirPath(QString const& newDirPath)
_config->insert({}, "path", newDirPath);
}
void NoteHandler::setFilename(int index, QString const& newFilename)
{
QString oldFilename { _notesDir.entryList(QDir::Files).at(index) };
QString extension { oldFilename.split(".").last() };
QString filePath { _notesDir.path() + QDir::separator() };
QFile file { filePath + oldFilename };
if (!file.rename(filePath + newFilename + "." + extension)) {
LOG_ERR("Unable to rename file " + file.fileName().toStdString() + " to " + newFilename.toStdString() + ": " + file.errorString().toStdString());
}
emit filesChanged();
}
}

@ -6,6 +6,7 @@
#include <QDebug>
#include <QDir>
#include <QFile>
// project includes
#include "config.h"
@ -18,12 +19,17 @@ public:
explicit NoteHandler(QString const& dirPath, std::shared_ptr<tai::config> conf);
public slots:
QString fileName(int index);
QString filename(int index);
QString fileContents(int index);
QStringList entryList();
void setDirPath(QString const& newDirPath);
void setFilename(int index, QString const& filename);
signals:
void filesChanged();
private:
QDir _notesDir {};

Loading…
Cancel
Save