mirror of
https://github.com/pbek/QOwnNotes.git
synced 2025-06-28 12:59:52 +00:00
Run Clang format script over the codebase
Column length is increased to 100 as 80 is just too short Also add a git-blame-ignore-revs file which ignores the formatting revisions while git-blaming
This commit is contained in:
parent
5a4fe8f65f
commit
1cea8a186d
151 changed files with 5828 additions and 8919 deletions
|
@ -50,7 +50,7 @@ BreakConstructorInitializersBeforeComma: false
|
|||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
ColumnLimit: 100
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
|
|
3
.git-blame-ignore-revs
Normal file
3
.git-blame-ignore-revs
Normal file
|
@ -0,0 +1,3 @@
|
|||
ee2b94b4dd6ae24077da9ed9bf54b2162f578518
|
||||
232056ddbd0d78196ea1d3091a07b94ab672a479
|
||||
18a3d6f5060b89a7217dd23e0bc2d956084bd34b
|
|
@ -132,7 +132,7 @@ bool NoteApi::removeTag(QString tagName) {
|
|||
* @param newName new file name (without file-extension)
|
||||
* @return true if the note was renamed
|
||||
*/
|
||||
bool NoteApi::renameNoteFile(const QString &newName) {
|
||||
bool NoteApi::renameNoteFile(const QString& newName) {
|
||||
Note note = Note::fetch(_id);
|
||||
|
||||
if (note.isFetched()) {
|
||||
|
@ -147,9 +147,7 @@ bool NoteApi::renameNoteFile(const QString &newName) {
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
bool NoteApi::allowDifferentFileName() {
|
||||
return Note::allowDifferentFileName();
|
||||
}
|
||||
bool NoteApi::allowDifferentFileName() { return Note::allowDifferentFileName(); }
|
||||
|
||||
/**
|
||||
* Fetches all notes
|
||||
|
@ -181,8 +179,7 @@ QQmlListProperty<NoteApi> NoteApi::fetchAll(int limit, int offset) {
|
|||
* @return
|
||||
*/
|
||||
QString NoteApi::toMarkdownHtml(bool forExport) {
|
||||
return _note.toMarkdownHtml(NoteFolder::currentLocalPath(), 980, forExport,
|
||||
true, true);
|
||||
return _note.toMarkdownHtml(NoteFolder::currentLocalPath(), 980, forExport, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,8 +192,7 @@ QString NoteApi::getFileURLFromFileName(const QString& localFileName) {
|
|||
return _note.getFileURLFromFileName(localFileName);
|
||||
}
|
||||
|
||||
void NoteApi::copy(const Note ¬e)
|
||||
{
|
||||
void NoteApi::copy(const Note& note) {
|
||||
_note = note;
|
||||
|
||||
if (_note.isFetched()) {
|
||||
|
|
|
@ -19,8 +19,7 @@ class NoteApi : public QObject, public Note {
|
|||
Q_PROPERTY(QString relativeNoteFileDirPath READ relativeNoteSubFolderPath() CONSTANT)
|
||||
Q_PROPERTY(int noteSubFolderId READ getNoteSubFolderId() CONSTANT)
|
||||
Q_PROPERTY(QString noteText READ getNoteText() WRITE setNoteText())
|
||||
Q_PROPERTY(QString decryptedNoteText READ fetchDecryptedNoteText()
|
||||
WRITE setDecryptedNoteText())
|
||||
Q_PROPERTY(QString decryptedNoteText READ fetchDecryptedNoteText() WRITE setDecryptedNoteText())
|
||||
Q_PROPERTY(QDateTime fileCreated READ getFileCreated() CONSTANT)
|
||||
Q_PROPERTY(QDateTime fileLastModified READ getFileLastModified() CONSTANT)
|
||||
Q_PROPERTY(bool hasDirtyData READ getHasDirtyData() CONSTANT)
|
||||
|
@ -40,8 +39,7 @@ class NoteApi : public QObject, public Note {
|
|||
Q_INVOKABLE bool addTag(const QString &tagName);
|
||||
Q_INVOKABLE bool removeTag(QString tagName);
|
||||
Q_INVOKABLE bool renameNoteFile(const QString &newName);
|
||||
Q_INVOKABLE QQmlListProperty<NoteApi> fetchAll(int limit = -1,
|
||||
int offset = -1);
|
||||
Q_INVOKABLE QQmlListProperty<NoteApi> fetchAll(int limit = -1, int offset = -1);
|
||||
Q_INVOKABLE QString toMarkdownHtml(bool forExport = true);
|
||||
Q_INVOKABLE QString getFileURLFromFileName(const QString &localFileName);
|
||||
Q_INVOKABLE static bool allowDifferentFileName();
|
||||
|
|
|
@ -18,7 +18,7 @@ NoteSubFolderApi *NoteSubFolderApi::fetch(int id) {
|
|||
}
|
||||
|
||||
NoteSubFolderApi *NoteSubFolderApi::fromNoteSubFolder(const NoteSubFolder ¬eSubFolder) {
|
||||
auto* noteSubFolderApi = new NoteSubFolderApi();
|
||||
auto *noteSubFolderApi = new NoteSubFolderApi();
|
||||
noteSubFolderApi->fetch(noteSubFolder.getId());
|
||||
return noteSubFolderApi;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ QQmlListProperty<NoteApi> NoteSubFolderApi::notes() {
|
|||
while (itr.hasNext()) {
|
||||
Note note = itr.next();
|
||||
|
||||
auto* noteApi = new NoteApi();
|
||||
auto *noteApi = new NoteApi();
|
||||
noteApi->fetch(note.getId());
|
||||
_notes.append(noteApi);
|
||||
}
|
||||
|
@ -54,8 +54,7 @@ QQmlListProperty<NoteApi> NoteSubFolderApi::notes() {
|
|||
* @param id int the id of the note subfolder
|
||||
* @return NoteSubFolderApi*
|
||||
*/
|
||||
NoteSubFolderApi *NoteSubFolderApi::fetchNoteSubFolderById(int id)
|
||||
{
|
||||
NoteSubFolderApi *NoteSubFolderApi::fetchNoteSubFolderById(int id) {
|
||||
auto *noteSubFolder = new NoteSubFolderApi();
|
||||
noteSubFolder->fetch(id);
|
||||
return noteSubFolder;
|
||||
|
@ -67,8 +66,7 @@ NoteSubFolderApi *NoteSubFolderApi::fetchNoteSubFolderById(int id)
|
|||
* @param parentId int the id of the parent note subfolder
|
||||
* @return QList<QObject*>
|
||||
*/
|
||||
QList<QObject*> NoteSubFolderApi::fetchNoteSubFoldersByParentId(int parentId)
|
||||
{
|
||||
QList<QObject *> NoteSubFolderApi::fetchNoteSubFoldersByParentId(int parentId) {
|
||||
QList<QObject *> noteSubFolderApis;
|
||||
|
||||
const auto noteSubFolders = NoteSubFolder::fetchAllByParentId(parentId);
|
||||
|
@ -83,10 +81,6 @@ NoteSubFolderApi *NoteSubFolderApi::activeNoteSubFolder() {
|
|||
return fetchNoteSubFolderById(NoteSubFolder::activeNoteSubFolderId());
|
||||
}
|
||||
|
||||
QString NoteSubFolderApi::relativePath() {
|
||||
return _noteSubFolder.relativePath();
|
||||
}
|
||||
QString NoteSubFolderApi::relativePath() { return _noteSubFolder.relativePath(); }
|
||||
|
||||
QString NoteSubFolderApi::fullPath() {
|
||||
return _noteSubFolder.fullPath();
|
||||
}
|
||||
QString NoteSubFolderApi::fullPath() { return _noteSubFolder.fullPath(); }
|
||||
|
|
|
@ -24,7 +24,7 @@ class NoteSubFolderApi : public QObject, public NoteSubFolder {
|
|||
|
||||
Q_INVOKABLE static NoteSubFolderApi *fetchNoteSubFolderById(int id);
|
||||
Q_INVOKABLE static NoteSubFolderApi *activeNoteSubFolder();
|
||||
Q_INVOKABLE static QList<QObject*> fetchNoteSubFoldersByParentId(int parentId);
|
||||
Q_INVOKABLE static QList<QObject *> fetchNoteSubFoldersByParentId(int parentId);
|
||||
|
||||
Q_INVOKABLE QQmlListProperty<NoteApi> notes();
|
||||
Q_INVOKABLE QString relativePath();
|
||||
|
|
|
@ -40,8 +40,7 @@ TagApi* TagApi::fromTag(const Tag& tag) {
|
|||
return tagApi;
|
||||
}
|
||||
|
||||
void TagApi::copy(const Tag &tag)
|
||||
{
|
||||
void TagApi::copy(const Tag& tag) {
|
||||
this->_id = tag.getId();
|
||||
_name = tag.getName();
|
||||
_parentId = tag.getParentId();
|
||||
|
|
|
@ -20,6 +20,6 @@ class TagApi : public QObject, public Tag {
|
|||
Q_INVOKABLE TagApi *fetchByName(const QString &name, int parentId = 0);
|
||||
Q_INVOKABLE QStringList getParentTagNames();
|
||||
Q_INVOKABLE QQmlListProperty<NoteApi> notes();
|
||||
static TagApi* fromTag(const Tag& tag);
|
||||
void copy(const Tag& t);
|
||||
static TagApi *fromTag(const Tag &tag);
|
||||
void copy(const Tag &t);
|
||||
};
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
#include "ui_aboutdialog.h"
|
||||
#include "version.h"
|
||||
|
||||
AboutDialog::AboutDialog(QWidget *parent)
|
||||
: MasterDialog(parent), ui(new Ui::AboutDialog) {
|
||||
AboutDialog::AboutDialog(QWidget *parent) : MasterDialog(parent), ui(new Ui::AboutDialog) {
|
||||
ui->setupUi(this);
|
||||
|
||||
// load the about.html
|
||||
|
@ -28,17 +27,14 @@ AboutDialog::AboutDialog(QWidget *parent)
|
|||
}
|
||||
|
||||
// fill in the variables
|
||||
html.replace(QLatin1String("QT_VERSION_STR"),
|
||||
QStringLiteral(QT_VERSION_STR));
|
||||
html.replace(QLatin1String("QT_VERSION_STR"), QStringLiteral(QT_VERSION_STR));
|
||||
html.replace(QLatin1String("BUILD_NUMBER"), QString::number(BUILD));
|
||||
html.replace(QLatin1String("BUILD_DATE"), __DATE__);
|
||||
html.replace(QLatin1String("VERSION"), QStringLiteral(VERSION));
|
||||
html.replace(QLatin1String("RELEASE"), release);
|
||||
html.replace(QLatin1String("CURRENT_YEAR"),
|
||||
QString::number(date.year()));
|
||||
html.replace(QLatin1String("CURRENT_YEAR"), QString::number(date.year()));
|
||||
|
||||
ui->textBrowser->document()->setDefaultStyleSheet(
|
||||
Utils::Misc::genericCSS());
|
||||
ui->textBrowser->document()->setDefaultStyleSheet(Utils::Misc::genericCSS());
|
||||
|
||||
// put the html to the text browser in the about dialog
|
||||
ui->textBrowser->setHtml(html);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "actiondialog.h"
|
||||
//#include <QDebug>
|
||||
// #include <QDebug>
|
||||
#include <utils/gui.h>
|
||||
|
||||
#include <QMenuBar>
|
||||
#include <QKeyEvent>
|
||||
#include <QMenuBar>
|
||||
#include <QTreeWidgetItem>
|
||||
|
||||
#include "ui_actiondialog.h"
|
||||
|
@ -27,7 +27,9 @@ void ActionDialog::refreshUi() {
|
|||
QList<QMenu *> menuList =
|
||||
_menuBar->findChildren<QMenu *>(QString(), Qt::FindDirectChildrenOnly);
|
||||
|
||||
Q_FOREACH (QMenu *menu, menuList) { buildActionTreeForMenu(menu); }
|
||||
Q_FOREACH (QMenu *menu, menuList) {
|
||||
buildActionTreeForMenu(menu);
|
||||
}
|
||||
|
||||
ui->actionTreeWidget->setRootIsDecorated(false);
|
||||
ui->actionTreeWidget->expandAll();
|
||||
|
@ -42,8 +44,7 @@ void ActionDialog::refreshUi() {
|
|||
* @param menu
|
||||
* @param parentItem
|
||||
*/
|
||||
void ActionDialog::buildActionTreeForMenu(QMenu *menu,
|
||||
QTreeWidgetItem *parentItem) {
|
||||
void ActionDialog::buildActionTreeForMenu(QMenu *menu, QTreeWidgetItem *parentItem) {
|
||||
QString menuText = menu->title().remove(QStringLiteral("&"));
|
||||
|
||||
if (menuText.isEmpty()) {
|
||||
|
@ -60,8 +61,7 @@ void ActionDialog::buildActionTreeForMenu(QMenu *menu,
|
|||
}
|
||||
|
||||
// search for sub-menus in the menu
|
||||
QList<QMenu *> menuList =
|
||||
menu->findChildren<QMenu *>(QString(), Qt::FindDirectChildrenOnly);
|
||||
QList<QMenu *> menuList = menu->findChildren<QMenu *>(QString(), Qt::FindDirectChildrenOnly);
|
||||
|
||||
// build the tree for that sub-menu
|
||||
Q_FOREACH (QMenu *subMenu, menuList) {
|
||||
|
@ -103,8 +103,7 @@ ActionDialog::~ActionDialog() { delete ui; }
|
|||
* @param item
|
||||
* @param column
|
||||
*/
|
||||
void ActionDialog::on_actionTreeWidget_itemDoubleClicked(QTreeWidgetItem *item,
|
||||
int column) {
|
||||
void ActionDialog::on_actionTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column) {
|
||||
Q_UNUSED(column);
|
||||
|
||||
if (item == nullptr) {
|
||||
|
@ -119,8 +118,7 @@ void ActionDialog::on_actionTreeWidget_itemDoubleClicked(QTreeWidgetItem *item,
|
|||
|
||||
// search for actions in the parent of the menu bar
|
||||
// for some reasons not all actions are children of the menu bar
|
||||
QList<QAction *> actionList =
|
||||
_menuBar->parent()->findChildren<QAction *>(objectName);
|
||||
QList<QAction *> actionList = _menuBar->parent()->findChildren<QAction *>(objectName);
|
||||
|
||||
// close the dialog
|
||||
close();
|
||||
|
@ -140,10 +138,9 @@ void ActionDialog::on_actionLineEdit_textChanged(const QString &arg1) {
|
|||
// search for the text
|
||||
Utils::Gui::searchForTextInTreeWidget(
|
||||
ui->actionTreeWidget, arg1,
|
||||
Utils::Gui::TreeWidgetSearchFlags(
|
||||
Utils::Gui::TreeWidgetSearchFlag::TooltipSearch |
|
||||
Utils::Gui::TreeWidgetSearchFlag::AllColumnsSearch |
|
||||
Utils::Gui::TreeWidgetSearchFlag::EveryWordSearch));
|
||||
Utils::Gui::TreeWidgetSearchFlags(Utils::Gui::TreeWidgetSearchFlag::TooltipSearch |
|
||||
Utils::Gui::TreeWidgetSearchFlag::AllColumnsSearch |
|
||||
Utils::Gui::TreeWidgetSearchFlag::EveryWordSearch));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -169,8 +166,7 @@ bool ActionDialog::eventFilter(QObject *obj, QEvent *event) {
|
|||
} else if (obj == ui->actionTreeWidget) {
|
||||
// trigger the action if return was pressed in the tree widget
|
||||
if (keyEvent->key() == Qt::Key_Return) {
|
||||
on_actionTreeWidget_itemDoubleClicked(
|
||||
ui->actionTreeWidget->currentItem(), 0);
|
||||
on_actionTreeWidget_itemDoubleClicked(ui->actionTreeWidget->currentItem(), 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,7 @@ class ActionDialog : public MasterDialog {
|
|||
void refreshUi();
|
||||
|
||||
private slots:
|
||||
void on_actionTreeWidget_itemDoubleClicked(QTreeWidgetItem *item,
|
||||
int column);
|
||||
void on_actionTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);
|
||||
|
||||
void on_actionLineEdit_textChanged(const QString &arg1);
|
||||
|
||||
|
@ -30,6 +29,5 @@ class ActionDialog : public MasterDialog {
|
|||
Ui::ActionDialog *ui;
|
||||
QMenuBar *_menuBar;
|
||||
|
||||
void buildActionTreeForMenu(QMenu *menu,
|
||||
QTreeWidgetItem *parentItem = nullptr);
|
||||
void buildActionTreeForMenu(QMenu *menu, QTreeWidgetItem *parentItem = nullptr);
|
||||
};
|
||||
|
|
|
@ -61,8 +61,7 @@ void AttachmentDialog::on_fileEdit_textChanged(const QString &arg1) {
|
|||
return;
|
||||
}
|
||||
|
||||
ui->downloadButton->setVisible(
|
||||
url.scheme().startsWith(QLatin1String("http")));
|
||||
ui->downloadButton->setVisible(url.scheme().startsWith(QLatin1String("http")));
|
||||
|
||||
if (url.scheme() == QLatin1String("file")) {
|
||||
ui->fileEdit->setText(url.toLocalFile());
|
||||
|
@ -73,9 +72,8 @@ void AttachmentDialog::on_fileEdit_textChanged(const QString &arg1) {
|
|||
QMimeDatabase db;
|
||||
QMimeType type = db.mimeTypeForFile(arg1);
|
||||
|
||||
ui->infoLabel->setText(
|
||||
Utils::Misc::toHumanReadableByteSize(fileInfo.size()) + " - " +
|
||||
type.comment());
|
||||
ui->infoLabel->setText(Utils::Misc::toHumanReadableByteSize(fileInfo.size()) + " - " +
|
||||
type.comment());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,8 +87,7 @@ void AttachmentDialog::on_downloadButton_clicked() {
|
|||
QNetworkRequest networkRequest(url);
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 9, 0)
|
||||
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute,
|
||||
true);
|
||||
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
#else
|
||||
networkRequest.setAttribute(QNetworkRequest::RedirectPolicyAttribute, true);
|
||||
#endif
|
||||
|
@ -110,13 +107,11 @@ void AttachmentDialog::on_downloadButton_clicked() {
|
|||
/**
|
||||
* Shows the download progress
|
||||
*/
|
||||
void AttachmentDialog::downloadProgress(qint64 bytesReceived,
|
||||
qint64 bytesTotal) {
|
||||
void AttachmentDialog::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
|
||||
ui->downloadProgressBar->setMaximum(static_cast<int>(bytesTotal));
|
||||
ui->downloadProgressBar->setValue(static_cast<int>(bytesReceived));
|
||||
ui->downloadSizeLabel->setText(
|
||||
Utils::Misc::toHumanReadableByteSize(bytesReceived) + " / " +
|
||||
Utils::Misc::toHumanReadableByteSize(bytesTotal));
|
||||
ui->downloadSizeLabel->setText(Utils::Misc::toHumanReadableByteSize(bytesReceived) + " / " +
|
||||
Utils::Misc::toHumanReadableByteSize(bytesTotal));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,12 +135,10 @@ void AttachmentDialog::slotReplyFinished(QNetworkReply *reply) {
|
|||
if (reply->error() != QNetworkReply::NoError &&
|
||||
reply->error() != QNetworkReply::OperationCanceledError) {
|
||||
_accept = false;
|
||||
QMessageBox::critical(
|
||||
nullptr, tr("Download error"),
|
||||
tr("Error while downloading:\n%1").arg(reply->errorString()));
|
||||
QMessageBox::critical(nullptr, tr("Download error"),
|
||||
tr("Error while downloading:\n%1").arg(reply->errorString()));
|
||||
|
||||
qWarning()
|
||||
<< QStringLiteral("Network error: %1").arg(reply->errorString());
|
||||
qWarning() << QStringLiteral("Network error: %1").arg(reply->errorString());
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -162,17 +155,16 @@ void AttachmentDialog::slotReplyFinished(QNetworkReply *reply) {
|
|||
}
|
||||
}
|
||||
|
||||
auto *tempFile =
|
||||
new QTemporaryFile(QDir::tempPath() + "/QOwnNotes-XXXXXX." + suffix);
|
||||
auto *tempFile = new QTemporaryFile(QDir::tempPath() + "/QOwnNotes-XXXXXX." + suffix);
|
||||
|
||||
// we want to keep the file to be used in the update process
|
||||
tempFile->setAutoRemove(false);
|
||||
|
||||
// get a temporary file
|
||||
if (!tempFile->open()) {
|
||||
QMessageBox::critical(nullptr, tr("File error"),
|
||||
tr("Could not open temporary file:\n%1")
|
||||
.arg(tempFile->errorString()));
|
||||
QMessageBox::critical(
|
||||
nullptr, tr("File error"),
|
||||
tr("Could not open temporary file:\n%1").arg(tempFile->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -193,9 +185,8 @@ void AttachmentDialog::slotReplyFinished(QNetworkReply *reply) {
|
|||
QFile file(filePath);
|
||||
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
QMessageBox::critical(
|
||||
nullptr, tr("File error"),
|
||||
tr("Could not store downloaded file:\n%1").arg(file.errorString()));
|
||||
QMessageBox::critical(nullptr, tr("File error"),
|
||||
tr("Could not store downloaded file:\n%1").arg(file.errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,49 +1,41 @@
|
|||
#include "commandbar.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QPainter>
|
||||
#include <QTreeView>
|
||||
#include <QLineEdit>
|
||||
#include <QKeyEvent>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QTextDocument>
|
||||
#include <QVBoxLayout>
|
||||
#include <QCoreApplication>
|
||||
#include <QMenu>
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QAction>
|
||||
#include <QCoreApplication>
|
||||
#include <QKeyEvent>
|
||||
#include <QLineEdit>
|
||||
#include <QMenu>
|
||||
#include <QPainter>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QTextDocument>
|
||||
#include <QTreeView>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "libraries/fuzzy/kfuzzymatcher.h"
|
||||
#include "models/commandmodel.h"
|
||||
#include "utils/misc.h"
|
||||
#include "libraries/fuzzy/kfuzzymatcher.h"
|
||||
|
||||
class CommandBarFilterModel : public QSortFilterProxyModel
|
||||
{
|
||||
public:
|
||||
CommandBarFilterModel(QObject *parent = nullptr)
|
||||
: QSortFilterProxyModel(parent)
|
||||
{
|
||||
}
|
||||
class CommandBarFilterModel : public QSortFilterProxyModel {
|
||||
public:
|
||||
CommandBarFilterModel(QObject *parent = nullptr) : QSortFilterProxyModel(parent) {}
|
||||
|
||||
Q_SLOT void setFilterString(const QString &string)
|
||||
{
|
||||
Q_SLOT void setFilterString(const QString &string) {
|
||||
beginResetModel();
|
||||
m_pattern = string;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
protected:
|
||||
bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override
|
||||
{
|
||||
protected:
|
||||
bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override {
|
||||
const int l = sourceLeft.data(CommandModel::Score).toInt();
|
||||
const int r = sourceRight.data(CommandModel::Score).toInt();
|
||||
return l < r;
|
||||
}
|
||||
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
|
||||
{
|
||||
if (m_pattern.isEmpty())
|
||||
return true;
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override {
|
||||
if (m_pattern.isEmpty()) return true;
|
||||
|
||||
const auto idx = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||
const QString str = idx.data().toString();
|
||||
|
@ -53,20 +45,16 @@ protected:
|
|||
return res.matched;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
QString m_pattern;
|
||||
};
|
||||
|
||||
class CommandBarStyleDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
CommandBarStyleDelegate(QObject *parent = nullptr)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
class CommandBarStyleDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
CommandBarStyleDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {}
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
|
||||
{
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override {
|
||||
QStyleOptionViewItem options = option;
|
||||
initStyleOption(&options, index);
|
||||
|
||||
|
@ -77,10 +65,14 @@ public:
|
|||
const auto strs = index.data().toString().split(QLatin1Char(':'));
|
||||
QString str = strs.at(1);
|
||||
const QString nameColor = option.palette.color(QPalette::Link).name();
|
||||
str = KFuzzyMatcher::toFuzzyMatchedDisplayString(m_filterString, str, QStringLiteral("<b style=\"color:%1;\">").arg(nameColor), QStringLiteral("</b>"));
|
||||
// fts::to_fuzzy_matched_display_string(m_filterString, str, QStringLiteral("<b style=\"color:%1;\">").arg(nameColor), QStringLiteral("</b>"));
|
||||
str = KFuzzyMatcher::toFuzzyMatchedDisplayString(
|
||||
m_filterString, str, QStringLiteral("<b style=\"color:%1;\">").arg(nameColor),
|
||||
QStringLiteral("</b>"));
|
||||
// fts::to_fuzzy_matched_display_string(m_filterString, str, QStringLiteral("<b
|
||||
// style=\"color:%1;\">").arg(nameColor), QStringLiteral("</b>"));
|
||||
|
||||
const QString component = QStringLiteral("<span style=\"color: gray;\">") + strs.at(0) + QStringLiteral(": </span>");
|
||||
const QString component = QStringLiteral("<span style=\"color: gray;\">") + strs.at(0) +
|
||||
QStringLiteral(": </span>");
|
||||
|
||||
doc.setHtml(component + str);
|
||||
doc.setDocumentMargin(2);
|
||||
|
@ -94,16 +86,18 @@ public:
|
|||
painter->fillRect(option.rect, option.palette.base());
|
||||
}
|
||||
|
||||
options.text = QString(); // clear old text
|
||||
options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter, options.widget);
|
||||
options.text = QString(); // clear old text
|
||||
options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter,
|
||||
options.widget);
|
||||
|
||||
// fix stuff for rtl
|
||||
// QTextDocument doesn't work with RTL text out of the box so we give it a hand here by increasing
|
||||
// the text width to our rect size. Icon displacement is also calculated here because 'translate()'
|
||||
// later will not work.
|
||||
// QTextDocument doesn't work with RTL text out of the box so we give it a hand here by
|
||||
// increasing the text width to our rect size. Icon displacement is also calculated here
|
||||
// because 'translate()' later will not work.
|
||||
const bool rtl = original.isRightToLeft();
|
||||
if (rtl) {
|
||||
auto r = options.widget->style()->subElementRect(QStyle::SE_ItemViewItemText, &options, options.widget);
|
||||
auto r = options.widget->style()->subElementRect(QStyle::SE_ItemViewItemText, &options,
|
||||
options.widget);
|
||||
auto hasIcon = index.data(Qt::DecorationRole).value<QIcon>().isNull();
|
||||
if (hasIcon)
|
||||
doc.setTextWidth(r.width() - 25);
|
||||
|
@ -115,8 +109,7 @@ public:
|
|||
painter->translate(option.rect.x(), option.rect.y());
|
||||
// leave space for icon
|
||||
|
||||
if (!rtl)
|
||||
painter->translate(25, 0);
|
||||
if (!rtl) painter->translate(25, 0);
|
||||
|
||||
QAbstractTextDocumentLayout::PaintContext ctx;
|
||||
ctx.palette.setColor(QPalette::Text, options.palette.text().color());
|
||||
|
@ -125,26 +118,19 @@ public:
|
|||
painter->restore();
|
||||
}
|
||||
|
||||
public Q_SLOTS:
|
||||
void setFilterString(const QString &text)
|
||||
{
|
||||
m_filterString = text;
|
||||
}
|
||||
public Q_SLOTS:
|
||||
void setFilterString(const QString &text) { m_filterString = text; }
|
||||
|
||||
private:
|
||||
private:
|
||||
QString m_filterString;
|
||||
};
|
||||
|
||||
class ShortcutStyleDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
ShortcutStyleDelegate(QObject *parent = nullptr)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
class ShortcutStyleDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
ShortcutStyleDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {}
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
|
||||
{
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override {
|
||||
QStyleOptionViewItem options = option;
|
||||
initStyleOption(&options, index);
|
||||
|
||||
|
@ -163,8 +149,9 @@ public:
|
|||
painter->fillRect(option.rect, option.palette.base());
|
||||
}
|
||||
|
||||
options.text = QString(); // clear old text
|
||||
options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter, options.widget);
|
||||
options.text = QString(); // clear old text
|
||||
options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter,
|
||||
options.widget);
|
||||
|
||||
if (!strs.isEmpty()) {
|
||||
// collect button-style pixmaps
|
||||
|
@ -185,8 +172,8 @@ public:
|
|||
int py = option.rect.y() + plusRect.height() / 2;
|
||||
int total = btnRects.size();
|
||||
int i = 0;
|
||||
painter->setRenderHint(QPainter::Antialiasing); // :)
|
||||
for (const auto& pxm : btnRects) {
|
||||
painter->setRenderHint(QPainter::Antialiasing); // :)
|
||||
for (const auto &pxm : btnRects) {
|
||||
// draw rounded rect shadown
|
||||
painter->setPen(Qt::NoPen);
|
||||
QRect r(dx, y, pxm.first.width(), pxm.first.height());
|
||||
|
@ -206,7 +193,8 @@ public:
|
|||
// draw '+'
|
||||
if (i + 1 < total) {
|
||||
dx += pxm.first.width() + 8;
|
||||
painter->drawText(QPoint(dx, py + (pxm.first.height() / 2)), QStringLiteral("+"));
|
||||
painter->drawText(QPoint(dx, py + (pxm.first.height() / 2)),
|
||||
QStringLiteral("+"));
|
||||
dx += plusRect.width() + 8;
|
||||
}
|
||||
i++;
|
||||
|
@ -217,9 +205,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
CommandBar::CommandBar(QWidget *parent)
|
||||
: QMenu(parent)
|
||||
{
|
||||
CommandBar::CommandBar(QWidget *parent) : QMenu(parent) {
|
||||
QVBoxLayout *layout = new QVBoxLayout();
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(4, 4, 4, 4);
|
||||
|
@ -237,8 +223,8 @@ CommandBar::CommandBar(QWidget *parent)
|
|||
|
||||
m_model = new CommandModel(this);
|
||||
|
||||
CommandBarStyleDelegate* delegate = new CommandBarStyleDelegate(this);
|
||||
ShortcutStyleDelegate* del = new ShortcutStyleDelegate(this);
|
||||
CommandBarStyleDelegate *delegate = new CommandBarStyleDelegate(this);
|
||||
ShortcutStyleDelegate *del = new ShortcutStyleDelegate(this);
|
||||
m_treeView->setItemDelegateForColumn(0, delegate);
|
||||
m_treeView->setItemDelegateForColumn(1, del);
|
||||
|
||||
|
@ -248,9 +234,11 @@ CommandBar::CommandBar(QWidget *parent)
|
|||
m_proxyModel->setFilterKeyColumn(0);
|
||||
|
||||
connect(m_lineEdit, &QLineEdit::returnPressed, this, &CommandBar::slotReturnPressed);
|
||||
connect(m_lineEdit, &QLineEdit::textChanged, m_proxyModel, &CommandBarFilterModel::setFilterString);
|
||||
connect(m_lineEdit, &QLineEdit::textChanged, delegate, &CommandBarStyleDelegate::setFilterString);
|
||||
connect(m_lineEdit, &QLineEdit::textChanged, this, [this](){
|
||||
connect(m_lineEdit, &QLineEdit::textChanged, m_proxyModel,
|
||||
&CommandBarFilterModel::setFilterString);
|
||||
connect(m_lineEdit, &QLineEdit::textChanged, delegate,
|
||||
&CommandBarStyleDelegate::setFilterString);
|
||||
connect(m_lineEdit, &QLineEdit::textChanged, this, [this]() {
|
||||
m_treeView->viewport()->update();
|
||||
reselectFirst();
|
||||
});
|
||||
|
@ -271,8 +259,7 @@ CommandBar::CommandBar(QWidget *parent)
|
|||
setHidden(true);
|
||||
}
|
||||
|
||||
void CommandBar::updateBar(const QVector<QPair<QString, QAction *> > &actions)
|
||||
{
|
||||
void CommandBar::updateBar(const QVector<QPair<QString, QAction *>> &actions) {
|
||||
m_model->refresh(actions);
|
||||
reselectFirst();
|
||||
|
||||
|
@ -281,13 +268,15 @@ void CommandBar::updateBar(const QVector<QPair<QString, QAction *> > &actions)
|
|||
setFocus();
|
||||
}
|
||||
|
||||
bool CommandBar::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
// catch key presses + shortcut overrides to allow to have ESC as application wide shortcut, too, see bug 409856
|
||||
bool CommandBar::eventFilter(QObject *obj, QEvent *event) {
|
||||
// catch key presses + shortcut overrides to allow to have ESC as application wide shortcut,
|
||||
// too, see bug 409856
|
||||
if (event->type() == QEvent::KeyPress || event->type() == QEvent::ShortcutOverride) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if (obj == m_lineEdit) {
|
||||
const bool forward2list = (keyEvent->key() == Qt::Key_Up) || (keyEvent->key() == Qt::Key_Down) || (keyEvent->key() == Qt::Key_PageUp) || (keyEvent->key() == Qt::Key_PageDown);
|
||||
const bool forward2list =
|
||||
(keyEvent->key() == Qt::Key_Up) || (keyEvent->key() == Qt::Key_Down) ||
|
||||
(keyEvent->key() == Qt::Key_PageUp) || (keyEvent->key() == Qt::Key_PageDown);
|
||||
if (forward2list) {
|
||||
QCoreApplication::sendEvent(m_treeView, event);
|
||||
return true;
|
||||
|
@ -300,8 +289,10 @@ bool CommandBar::eventFilter(QObject *obj, QEvent *event)
|
|||
return true;
|
||||
}
|
||||
} else {
|
||||
const bool forward2input = (keyEvent->key() != Qt::Key_Up) && (keyEvent->key() != Qt::Key_Down) && (keyEvent->key() != Qt::Key_PageUp) && (keyEvent->key() != Qt::Key_PageDown) && (keyEvent->key() != Qt::Key_Tab) &&
|
||||
(keyEvent->key() != Qt::Key_Backtab);
|
||||
const bool forward2input =
|
||||
(keyEvent->key() != Qt::Key_Up) && (keyEvent->key() != Qt::Key_Down) &&
|
||||
(keyEvent->key() != Qt::Key_PageUp) && (keyEvent->key() != Qt::Key_PageDown) &&
|
||||
(keyEvent->key() != Qt::Key_Tab) && (keyEvent->key() != Qt::Key_Backtab);
|
||||
if (forward2input) {
|
||||
QCoreApplication::sendEvent(m_lineEdit, event);
|
||||
return true;
|
||||
|
@ -310,7 +301,8 @@ bool CommandBar::eventFilter(QObject *obj, QEvent *event)
|
|||
}
|
||||
|
||||
// hide on focus out, if neither input field nor list have focus!
|
||||
else if (event->type() == QEvent::FocusOut && !(m_lineEdit->hasFocus() || m_treeView->hasFocus())) {
|
||||
else if (event->type() == QEvent::FocusOut &&
|
||||
!(m_lineEdit->hasFocus() || m_treeView->hasFocus())) {
|
||||
m_lineEdit->clear();
|
||||
hide();
|
||||
return true;
|
||||
|
@ -319,15 +311,14 @@ bool CommandBar::eventFilter(QObject *obj, QEvent *event)
|
|||
return QWidget::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void CommandBar::slotReturnPressed()
|
||||
{
|
||||
auto act = m_proxyModel->data(m_treeView->currentIndex(), Qt::UserRole).value<QAction*>();
|
||||
void CommandBar::slotReturnPressed() {
|
||||
auto act = m_proxyModel->data(m_treeView->currentIndex(), Qt::UserRole).value<QAction *>();
|
||||
if (act) {
|
||||
// if the action is a menu, we take all its actions
|
||||
// and reload our dialog with these instead.
|
||||
if (auto menu = act->menu()) {
|
||||
auto menuActions = menu->actions();
|
||||
QVector<QPair<QString, QAction*>> list;
|
||||
QVector<QPair<QString, QAction *>> list;
|
||||
list.reserve(menuActions.size());
|
||||
|
||||
// if there are no actions, trigger load actions
|
||||
|
@ -353,14 +344,12 @@ void CommandBar::slotReturnPressed()
|
|||
hide();
|
||||
}
|
||||
|
||||
void CommandBar::reselectFirst()
|
||||
{
|
||||
void CommandBar::reselectFirst() {
|
||||
QModelIndex index = m_proxyModel->index(0, 0);
|
||||
m_treeView->setCurrentIndex(index);
|
||||
}
|
||||
|
||||
void CommandBar::updateViewGeometry()
|
||||
{
|
||||
void CommandBar::updateViewGeometry() {
|
||||
m_treeView->resizeColumnToContents(0);
|
||||
m_treeView->resizeColumnToContents(1);
|
||||
|
||||
|
|
|
@ -9,28 +9,27 @@ class CommandModel;
|
|||
class CommandBarFilterModel;
|
||||
class QLineEdit;
|
||||
|
||||
class CommandBar : public QMenu
|
||||
{
|
||||
class CommandBar : public QMenu {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CommandBar(QWidget *parent = nullptr);
|
||||
public:
|
||||
explicit CommandBar(QWidget* parent = nullptr);
|
||||
|
||||
void updateBar(const QVector<QPair<QString, QAction*>>& actions);
|
||||
|
||||
void updateViewGeometry();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
protected:
|
||||
bool eventFilter(QObject* obj, QEvent* event) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
private Q_SLOTS:
|
||||
void slotReturnPressed();
|
||||
void reselectFirst();
|
||||
|
||||
private:
|
||||
private:
|
||||
QTreeView* m_treeView;
|
||||
QLineEdit* m_lineEdit;
|
||||
CommandModel* m_model;
|
||||
CommandBarFilterModel* m_proxyModel;
|
||||
};
|
||||
|
||||
#endif // COMMANDBAR_H
|
||||
#endif // COMMANDBAR_H
|
||||
|
|
|
@ -30,8 +30,7 @@ DictionaryManagerDialog::DictionaryManagerDialog(QWidget *parent)
|
|||
addDictionaryItem(tr("Amharic"), QStringLiteral("am_ET"));
|
||||
addDictionaryItem(tr("Ancient Greek"), QStringLiteral("grc_GR"));
|
||||
addDictionaryItem(tr("Arabic"), QStringLiteral("ar"));
|
||||
addDictionaryItem(tr("Aragonese"), QStringLiteral("an_ES"),
|
||||
QStringLiteral("Aragonés"));
|
||||
addDictionaryItem(tr("Aragonese"), QStringLiteral("an_ES"), QStringLiteral("Aragonés"));
|
||||
addDictionaryItem(tr("Armenian"), QStringLiteral("hy"));
|
||||
addDictionaryItem(tr("Albanian"), QStringLiteral("sq_AL"));
|
||||
addDictionaryItem(tr("Basque"), QStringLiteral("eu"));
|
||||
|
@ -47,52 +46,40 @@ DictionaryManagerDialog::DictionaryManagerDialog(QWidget *parent)
|
|||
addDictionaryItem(tr("Czech"), QStringLiteral("cs_CZ"));
|
||||
addDictionaryItem(tr("Danish"), QStringLiteral("da_DK"));
|
||||
addDictionaryItem(tr("Dutch"), QStringLiteral("nl_NL"));
|
||||
addDictionaryItem(tr("English (American)"), QStringLiteral("en"),
|
||||
QStringLiteral("en_US"));
|
||||
addDictionaryItem(tr("English (Australian)"), QStringLiteral("en"),
|
||||
QStringLiteral("en_AU"));
|
||||
addDictionaryItem(tr("English (British)"), QStringLiteral("en"),
|
||||
QStringLiteral("en_GB"));
|
||||
addDictionaryItem(tr("English (Canadian)"), QStringLiteral("en"),
|
||||
QStringLiteral("en_CA"));
|
||||
addDictionaryItem(tr("English (American)"), QStringLiteral("en"), QStringLiteral("en_US"));
|
||||
addDictionaryItem(tr("English (Australian)"), QStringLiteral("en"), QStringLiteral("en_AU"));
|
||||
addDictionaryItem(tr("English (British)"), QStringLiteral("en"), QStringLiteral("en_GB"));
|
||||
addDictionaryItem(tr("English (Canadian)"), QStringLiteral("en"), QStringLiteral("en_CA"));
|
||||
addDictionaryItem(tr("English (Medical Dictionary)"), QStringLiteral("en"),
|
||||
QStringLiteral("en-medical"));
|
||||
addDictionaryItem(tr("English (South African)"), QStringLiteral("en"),
|
||||
QStringLiteral("en_ZA"));
|
||||
addDictionaryItem(tr("English (South African)"), QStringLiteral("en"), QStringLiteral("en_ZA"));
|
||||
addDictionaryItem(tr("Esperanto"), QStringLiteral("eo"));
|
||||
addDictionaryItem(tr("Estonian"), QStringLiteral("et_EE"));
|
||||
addDictionaryItem(tr("Faroese"), QStringLiteral("fo"));
|
||||
addDictionaryItem(tr("French"), QStringLiteral("fr_FR"),
|
||||
QStringLiteral("fr"));
|
||||
addDictionaryItem(tr("French"), QStringLiteral("fr_FR"), QStringLiteral("fr"));
|
||||
addDictionaryItem(tr("Friulian"), QStringLiteral("fur_IT"));
|
||||
addDictionaryItem(tr("Gaelic"), QStringLiteral("gd_GB"));
|
||||
addDictionaryItem(tr("Galician"), QStringLiteral("gl"),
|
||||
QStringLiteral("gl_ES"));
|
||||
addDictionaryItem(tr("Galician"), QStringLiteral("gl"), QStringLiteral("gl_ES"));
|
||||
addDictionaryItem(tr("Georgian"), QStringLiteral("ka_GE"));
|
||||
addDictionaryItem(tr("German (Austrian)"), QStringLiteral("de"),
|
||||
QStringLiteral("de_AT_frami"));
|
||||
addDictionaryItem(tr("German (Austrian)"), QStringLiteral("de"), QStringLiteral("de_AT_frami"));
|
||||
addDictionaryItem(tr("German (Classical Spelling)"), QStringLiteral("de"),
|
||||
QStringLiteral("de_DE-oldspell"));
|
||||
addDictionaryItem(tr("German (German)"), QStringLiteral("de"),
|
||||
QStringLiteral("de_DE_frami"));
|
||||
addDictionaryItem(tr("German (Swiss)"), QStringLiteral("de"),
|
||||
QStringLiteral("de_CH_frami"));
|
||||
addDictionaryItem(tr("German (German)"), QStringLiteral("de"), QStringLiteral("de_DE_frami"));
|
||||
addDictionaryItem(tr("German (Swiss)"), QStringLiteral("de"), QStringLiteral("de_CH_frami"));
|
||||
addDictionaryItem(tr("German (Medical Dictionary)"), QStringLiteral("de"),
|
||||
QStringLiteral("de-medical"));
|
||||
addDictionaryItem(tr("Greek"), QStringLiteral("el_GR"));
|
||||
addDictionaryItem(tr("Modern Greek (Polytonic Greek)"),
|
||||
QStringLiteral("el_GR"), QStringLiteral("el-polyton"));
|
||||
addDictionaryItem(tr("Modern Greek (Polytonic Greek)"), QStringLiteral("el_GR"),
|
||||
QStringLiteral("el-polyton"));
|
||||
addDictionaryItem(tr("Gujarati"), QStringLiteral("gu_IN"));
|
||||
addDictionaryItem(tr("Gurani"), QStringLiteral("gug"));
|
||||
addDictionaryItem(tr("Hebrew"), QStringLiteral("he_IL"));
|
||||
addDictionaryItem(tr("Hindi"), QStringLiteral("hi_IN"));
|
||||
addDictionaryItem(tr("Hungarian"), QStringLiteral("hu_HU"));
|
||||
addDictionaryItem(tr("Icelandic"), QStringLiteral("is"));
|
||||
addDictionaryItem(tr("Indonesian"), QStringLiteral("id"),
|
||||
QStringLiteral("id_ID"));
|
||||
addDictionaryItem(tr("Indonesian"), QStringLiteral("id"), QStringLiteral("id_ID"));
|
||||
addDictionaryItem(tr("Italian"), QStringLiteral("it_IT"));
|
||||
addDictionaryItem(tr("Kaszebsczi"), QStringLiteral("csb_PL"),
|
||||
QStringLiteral("Kaszebsczi"));
|
||||
addDictionaryItem(tr("Kaszebsczi"), QStringLiteral("csb_PL"), QStringLiteral("Kaszebsczi"));
|
||||
addDictionaryItem(tr("Kazakh"), QStringLiteral("kk"));
|
||||
addDictionaryItem(tr("Khmer"), QStringLiteral("km_KH"));
|
||||
addDictionaryItem(tr("Komi (Russia)"), QStringLiteral("koi"));
|
||||
|
@ -104,24 +91,20 @@ DictionaryManagerDialog::DictionaryManagerDialog(QWidget *parent)
|
|||
addDictionaryItem(tr("Latvian"), QStringLiteral("lv_LV"));
|
||||
addDictionaryItem(tr("Lithuanian"), QStringLiteral("lt_LT"));
|
||||
addDictionaryItem(tr("Low German / Low Saxon"), QStringLiteral("nds"));
|
||||
addDictionaryItem(tr("Luxembourgish (Letzeburgesch)"),
|
||||
QStringLiteral("lb"));
|
||||
addDictionaryItem(tr("Luxembourgish (Letzeburgesch)"), QStringLiteral("lb"));
|
||||
addDictionaryItem(tr("Macedonian"), QStringLiteral("mk"));
|
||||
addDictionaryItem(tr("Malayalam"), QStringLiteral("ml_IN"));
|
||||
addDictionaryItem(tr("Mongolian"), QStringLiteral("mn"));
|
||||
addDictionaryItem(tr("Nepali"), QStringLiteral("ne_NP"));
|
||||
addDictionaryItem(tr("Norwegian (Bokmål)"), QStringLiteral("no"),
|
||||
QStringLiteral("nb_NO"));
|
||||
addDictionaryItem(tr("Norwegian (Nynorsk)"), QStringLiteral("no"),
|
||||
QStringLiteral("nn_NO"));
|
||||
addDictionaryItem(tr("Norwegian (Bokmål)"), QStringLiteral("no"), QStringLiteral("nb_NO"));
|
||||
addDictionaryItem(tr("Norwegian (Nynorsk)"), QStringLiteral("no"), QStringLiteral("nn_NO"));
|
||||
addDictionaryItem(tr("Occitan"), QStringLiteral("oc_FR"));
|
||||
addDictionaryItem(tr("Papiamentu"), QStringLiteral("pap_CW"));
|
||||
addDictionaryItem(tr("Persian"), QStringLiteral("fa_IR"));
|
||||
addDictionaryItem(tr("Polish"), QStringLiteral("pl_PL"));
|
||||
addDictionaryItem(tr("Portugese (Brazilian)"), QStringLiteral("pt_BR"));
|
||||
addDictionaryItem(tr("Portugese"), QStringLiteral("pt_PT"));
|
||||
addDictionaryItem(tr("Romanian"), QStringLiteral("ro"),
|
||||
QStringLiteral("ro_RO"));
|
||||
addDictionaryItem(tr("Romanian"), QStringLiteral("ro"), QStringLiteral("ro_RO"));
|
||||
addDictionaryItem(tr("Romansh"), QStringLiteral("rm"));
|
||||
addDictionaryItem(tr("Russian"), QStringLiteral("ru_RU"));
|
||||
addDictionaryItem(tr("Russian Medical Dictionary"), QStringLiteral("ru_RU"),
|
||||
|
@ -129,15 +112,13 @@ DictionaryManagerDialog::DictionaryManagerDialog(QWidget *parent)
|
|||
addDictionaryItem(tr("Rusyn / Ruthene (Slovakia)"), QStringLiteral("sk_SK"),
|
||||
QStringLiteral("rue_SK"));
|
||||
addDictionaryItem(tr("Serbian (Cyrillic)"), QStringLiteral("sr"));
|
||||
addDictionaryItem(tr("Serbian (Latin)"), QStringLiteral("sr"),
|
||||
QStringLiteral("sr-Latn"));
|
||||
addDictionaryItem(tr("Serbian (Latin)"), QStringLiteral("sr"), QStringLiteral("sr-Latn"));
|
||||
addDictionaryItem(tr("Shona"), QStringLiteral("sn_ZW"));
|
||||
addDictionaryItem(tr("Sindhi"), QStringLiteral("sd"));
|
||||
addDictionaryItem(tr("Sinhala"), QStringLiteral("si_LK"));
|
||||
addDictionaryItem(tr("Slovak"), QStringLiteral("sk_SK"));
|
||||
addDictionaryItem(tr("Slovenian"), QStringLiteral("sl_SI"));
|
||||
addDictionaryItem(tr("Spanish"), QStringLiteral("es"),
|
||||
QStringLiteral("es_ANY"));
|
||||
addDictionaryItem(tr("Spanish"), QStringLiteral("es"), QStringLiteral("es_ANY"));
|
||||
addDictionaryItem(tr("Swahili"), QStringLiteral("sw_TZ"));
|
||||
addDictionaryItem(tr("Swedish"), QStringLiteral("sv_SE"));
|
||||
addDictionaryItem(tr("Tagalog"), QStringLiteral("tl_PH"));
|
||||
|
@ -153,8 +134,7 @@ DictionaryManagerDialog::DictionaryManagerDialog(QWidget *parent)
|
|||
addDictionaryItem(tr("Uzbek"), QStringLiteral("uz_UZ"));
|
||||
addDictionaryItem(tr("Venda"), QStringLiteral("ve_ZA"));
|
||||
addDictionaryItem(tr("Venetian"), QStringLiteral("vec_IT"));
|
||||
addDictionaryItem(tr("Vietnamese"), QStringLiteral("vi"),
|
||||
QStringLiteral("vi_VN"));
|
||||
addDictionaryItem(tr("Vietnamese"), QStringLiteral("vi"), QStringLiteral("vi_VN"));
|
||||
addDictionaryItem(tr("Welsh"), QStringLiteral("cy_GB"));
|
||||
addDictionaryItem(tr("Xhosa"), QStringLiteral("xh_ZA"));
|
||||
addDictionaryItem(tr("Zulu"), QStringLiteral("zu_ZA"));
|
||||
|
@ -180,8 +160,7 @@ DictionaryManagerDialog::~DictionaryManagerDialog() {
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void DictionaryManagerDialog::addDictionaryItem(const QString &name,
|
||||
const QString &pathPart,
|
||||
void DictionaryManagerDialog::addDictionaryItem(const QString &name, const QString &pathPart,
|
||||
QString fileNamePart) {
|
||||
if (fileNamePart.isEmpty()) {
|
||||
fileNamePart = pathPart;
|
||||
|
@ -214,9 +193,7 @@ void DictionaryManagerDialog::setupMainSplitter() {
|
|||
// restore splitter sizes
|
||||
QSettings settings;
|
||||
QByteArray state =
|
||||
settings
|
||||
.value(QStringLiteral("DictionaryManagerDialog/mainSplitterState"))
|
||||
.toByteArray();
|
||||
settings.value(QStringLiteral("DictionaryManagerDialog/mainSplitterState")).toByteArray();
|
||||
_mainSplitter->restoreState(state);
|
||||
|
||||
ui->gridLayout->layout()->addWidget(_mainSplitter);
|
||||
|
@ -227,9 +204,8 @@ void DictionaryManagerDialog::setupMainSplitter() {
|
|||
*/
|
||||
void DictionaryManagerDialog::storeSettings() {
|
||||
QSettings settings;
|
||||
settings.setValue(
|
||||
QStringLiteral("DictionaryManagerDialog/mainSplitterState"),
|
||||
_mainSplitter->saveState());
|
||||
settings.setValue(QStringLiteral("DictionaryManagerDialog/mainSplitterState"),
|
||||
_mainSplitter->saveState());
|
||||
}
|
||||
|
||||
void DictionaryManagerDialog::on_downloadButton_clicked() {
|
||||
|
@ -245,8 +221,7 @@ void DictionaryManagerDialog::on_downloadButton_clicked() {
|
|||
return;
|
||||
}
|
||||
|
||||
QString url =
|
||||
item->data(0, Qt::UserRole).toString() + QStringLiteral(".dic");
|
||||
QString url = item->data(0, Qt::UserRole).toString() + QStringLiteral(".dic");
|
||||
downloadFile(url);
|
||||
}
|
||||
|
||||
|
@ -254,8 +229,7 @@ void DictionaryManagerDialog::downloadFile(const QString &url) {
|
|||
QNetworkRequest networkRequest(url);
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 9, 0)
|
||||
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute,
|
||||
true);
|
||||
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
#else
|
||||
networkRequest.setAttribute(QNetworkRequest::RedirectPolicyAttribute, true);
|
||||
#endif
|
||||
|
@ -292,12 +266,10 @@ void DictionaryManagerDialog::slotReplyFinished(QNetworkReply *reply) {
|
|||
|
||||
if (reply->error() != QNetworkReply::NoError &&
|
||||
reply->error() != QNetworkReply::OperationCanceledError) {
|
||||
QMessageBox::critical(
|
||||
nullptr, tr("Download error"),
|
||||
tr("Error while downloading:\n%1").arg(reply->errorString()));
|
||||
QMessageBox::critical(nullptr, tr("Download error"),
|
||||
tr("Error while downloading:\n%1").arg(reply->errorString()));
|
||||
|
||||
qWarning()
|
||||
<< QStringLiteral("Network error: %1").arg(reply->errorString());
|
||||
qWarning() << QStringLiteral("Network error: %1").arg(reply->errorString());
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -305,13 +277,11 @@ void DictionaryManagerDialog::slotReplyFinished(QNetworkReply *reply) {
|
|||
QFileInfo info(urlPath);
|
||||
QString suffix = info.completeSuffix();
|
||||
|
||||
QFile file(Utils::Misc::localDictionariesPath() + QStringLiteral("/") +
|
||||
info.fileName());
|
||||
QFile file(Utils::Misc::localDictionariesPath() + QStringLiteral("/") + info.fileName());
|
||||
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
QMessageBox::critical(
|
||||
nullptr, tr("File error"),
|
||||
tr("Could not store downloaded file:\n%1").arg(file.errorString()));
|
||||
QMessageBox::critical(nullptr, tr("File error"),
|
||||
tr("Could not store downloaded file:\n%1").arg(file.errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -324,8 +294,7 @@ void DictionaryManagerDialog::slotReplyFinished(QNetworkReply *reply) {
|
|||
auto *item = ui->remoteDictionaryTreeWidget->currentItem();
|
||||
|
||||
if (item != nullptr) {
|
||||
QString url =
|
||||
item->data(0, Qt::UserRole).toString() + QStringLiteral(".aff");
|
||||
QString url = item->data(0, Qt::UserRole).toString() + QStringLiteral(".aff");
|
||||
downloadFile(url);
|
||||
}
|
||||
} else {
|
||||
|
@ -342,14 +311,12 @@ void DictionaryManagerDialog::on_downloadCancelButton_clicked() {
|
|||
/**
|
||||
* Shows the download progress
|
||||
*/
|
||||
void DictionaryManagerDialog::downloadProgress(qint64 bytesReceived,
|
||||
qint64 bytesTotal) {
|
||||
void DictionaryManagerDialog::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
|
||||
QString text = Utils::Misc::toHumanReadableByteSize(bytesReceived);
|
||||
|
||||
// bytesTotal can be set to -1 if not available
|
||||
if (bytesTotal > -1) {
|
||||
text += QStringLiteral(" / ") +
|
||||
Utils::Misc::toHumanReadableByteSize(bytesTotal);
|
||||
text += QStringLiteral(" / ") + Utils::Misc::toHumanReadableByteSize(bytesTotal);
|
||||
} else {
|
||||
// set to 4 MB
|
||||
bytesTotal = 4194304;
|
||||
|
@ -390,8 +357,7 @@ void DictionaryManagerDialog::loadLocalDictionaries() {
|
|||
qDebug() << files;
|
||||
}
|
||||
|
||||
QString DictionaryManagerDialog::getDictionaryName(
|
||||
const QString &fileNamePart) {
|
||||
QString DictionaryManagerDialog::getDictionaryName(const QString &fileNamePart) {
|
||||
foreach (Dictionary dict, _dictionaryList) {
|
||||
if (dict.fileNamePart == fileNamePart) {
|
||||
return dict.name;
|
||||
|
@ -402,8 +368,7 @@ QString DictionaryManagerDialog::getDictionaryName(
|
|||
}
|
||||
|
||||
void DictionaryManagerDialog::on_deleteLocalDictionaryButton_clicked() {
|
||||
foreach (QTreeWidgetItem *item,
|
||||
ui->localDictionaryTreeWidget->selectedItems()) {
|
||||
foreach (QTreeWidgetItem *item, ui->localDictionaryTreeWidget->selectedItems()) {
|
||||
const QString &fileNamePart = item->data(0, Qt::UserRole).toString();
|
||||
|
||||
if (deleteLocalDictionaryFile(fileNamePart + QStringLiteral(".aff"))) {
|
||||
|
@ -415,47 +380,39 @@ void DictionaryManagerDialog::on_deleteLocalDictionaryButton_clicked() {
|
|||
qApp->setProperty("needsRestart", true);
|
||||
}
|
||||
|
||||
bool DictionaryManagerDialog::deleteLocalDictionaryFile(
|
||||
const QString &fileName) {
|
||||
QFile file(Utils::Misc::localDictionariesPath() + QStringLiteral("/") +
|
||||
fileName);
|
||||
bool DictionaryManagerDialog::deleteLocalDictionaryFile(const QString &fileName) {
|
||||
QFile file(Utils::Misc::localDictionariesPath() + QStringLiteral("/") + fileName);
|
||||
|
||||
if (!file.remove()) {
|
||||
QMessageBox::critical(
|
||||
nullptr, tr("File error"),
|
||||
tr("Could not remove dictionary file:\n%1").arg(fileName));
|
||||
QMessageBox::critical(nullptr, tr("File error"),
|
||||
tr("Could not remove dictionary file:\n%1").arg(fileName));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DictionaryManagerDialog::
|
||||
on_remoteDictionaryTreeWidget_itemSelectionChanged() {
|
||||
ui->downloadButton->setDisabled(
|
||||
ui->remoteDictionaryTreeWidget->selectedItems().count() == 0);
|
||||
void DictionaryManagerDialog::on_remoteDictionaryTreeWidget_itemSelectionChanged() {
|
||||
ui->downloadButton->setDisabled(ui->remoteDictionaryTreeWidget->selectedItems().count() == 0);
|
||||
}
|
||||
|
||||
void DictionaryManagerDialog::
|
||||
on_localDictionaryTreeWidget_itemSelectionChanged() {
|
||||
void DictionaryManagerDialog::on_localDictionaryTreeWidget_itemSelectionChanged() {
|
||||
ui->deleteLocalDictionaryButton->setDisabled(
|
||||
ui->localDictionaryTreeWidget->selectedItems().count() == 0);
|
||||
}
|
||||
|
||||
void DictionaryManagerDialog::on_searchDictionaryEdit_textChanged(
|
||||
const QString &arg1) {
|
||||
void DictionaryManagerDialog::on_searchDictionaryEdit_textChanged(const QString &arg1) {
|
||||
Utils::Gui::searchForTextInTreeWidget(ui->remoteDictionaryTreeWidget, arg1);
|
||||
}
|
||||
|
||||
void DictionaryManagerDialog::on_remoteDictionaryTreeWidget_itemDoubleClicked(
|
||||
QTreeWidgetItem *item, int column) {
|
||||
void DictionaryManagerDialog::on_remoteDictionaryTreeWidget_itemDoubleClicked(QTreeWidgetItem *item,
|
||||
int column) {
|
||||
Q_UNUSED(item)
|
||||
Q_UNUSED(column)
|
||||
on_downloadButton_clicked();
|
||||
}
|
||||
|
||||
void DictionaryManagerDialog::on_disableExternalDictionariesCheckBox_toggled(
|
||||
bool checked) {
|
||||
void DictionaryManagerDialog::on_disableExternalDictionariesCheckBox_toggled(bool checked) {
|
||||
QSettings settings;
|
||||
settings.setValue(QStringLiteral("disableExternalDictionaries"), checked);
|
||||
qApp->setProperty("needsRestart", true);
|
||||
|
|
|
@ -41,8 +41,7 @@ class DictionaryManagerDialog : public MasterDialog {
|
|||
|
||||
void on_searchDictionaryEdit_textChanged(const QString &arg1);
|
||||
|
||||
void on_remoteDictionaryTreeWidget_itemDoubleClicked(QTreeWidgetItem *item,
|
||||
int column);
|
||||
void on_remoteDictionaryTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);
|
||||
|
||||
void on_disableExternalDictionariesCheckBox_toggled(bool checked);
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
#include <QTemporaryFile>
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
#include <QXmlQuery>
|
||||
#include <QXmlResultItems>
|
||||
#include <QXmlQuery>
|
||||
#include <QXmlResultItems>
|
||||
#endif
|
||||
|
||||
#include <utility>
|
||||
|
@ -35,26 +35,18 @@ EvernoteImportDialog::EvernoteImportDialog(QWidget *parent)
|
|||
|
||||
QSettings settings;
|
||||
ui->imageImportCheckBox->setChecked(
|
||||
settings
|
||||
.value(QStringLiteral("EvernoteImport/ImageImportCheckBoxChecked"),
|
||||
true)
|
||||
.toBool());
|
||||
settings.value(QStringLiteral("EvernoteImport/ImageImportCheckBoxChecked"), true).toBool());
|
||||
ui->attachmentImportCheckBox->setChecked(
|
||||
settings
|
||||
.value(QStringLiteral(
|
||||
"EvernoteImport/AttachmentImportCheckBoxChecked"),
|
||||
true)
|
||||
settings.value(QStringLiteral("EvernoteImport/AttachmentImportCheckBoxChecked"), true)
|
||||
.toBool());
|
||||
}
|
||||
|
||||
EvernoteImportDialog::~EvernoteImportDialog() {
|
||||
QSettings settings;
|
||||
settings.setValue(
|
||||
QStringLiteral("EvernoteImport/ImageImportCheckBoxChecked"),
|
||||
ui->imageImportCheckBox->isChecked());
|
||||
settings.setValue(
|
||||
QStringLiteral("EvernoteImport/AttachmentImportCheckBoxChecked"),
|
||||
ui->attachmentImportCheckBox->isChecked());
|
||||
settings.setValue(QStringLiteral("EvernoteImport/ImageImportCheckBoxChecked"),
|
||||
ui->imageImportCheckBox->isChecked());
|
||||
settings.setValue(QStringLiteral("EvernoteImport/AttachmentImportCheckBoxChecked"),
|
||||
ui->attachmentImportCheckBox->isChecked());
|
||||
|
||||
storeMetaDataTreeWidgetItemsCheckedState();
|
||||
|
||||
|
@ -130,8 +122,7 @@ int EvernoteImportDialog::countNotes(const QString &data) {
|
|||
*
|
||||
* @param content
|
||||
*/
|
||||
QString EvernoteImportDialog::importImages(const Note ¬e, QString content,
|
||||
QXmlQuery query) {
|
||||
QString EvernoteImportDialog::importImages(const Note ¬e, QString content, QXmlQuery query) {
|
||||
query.setQuery(QStringLiteral("resource"));
|
||||
|
||||
QXmlResultItems result;
|
||||
|
@ -154,9 +145,8 @@ QString EvernoteImportDialog::importImages(const Note ¬e, QString content,
|
|||
query.setQuery(QStringLiteral("mime/text()"));
|
||||
query.evaluateTo(&mime);
|
||||
|
||||
QRegularExpression mimeExpression(
|
||||
QStringLiteral("(.+)?\\/(.+)?"),
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
QRegularExpression mimeExpression(QStringLiteral("(.+)?\\/(.+)?"),
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
QRegularExpressionMatch mimeMatch = mimeExpression.match(mime);
|
||||
|
||||
if (mimeMatch.hasMatch()) {
|
||||
|
@ -194,9 +184,8 @@ QString EvernoteImportDialog::importImages(const Note ¬e, QString content,
|
|||
|
||||
// if there is no object id set we generate the hash ourselves
|
||||
if (objectId.isEmpty()) {
|
||||
objectId = QString(QCryptographicHash::hash(
|
||||
QByteArray::fromBase64(data.toLatin1()),
|
||||
QCryptographicHash::Md5)
|
||||
objectId = QString(QCryptographicHash::hash(QByteArray::fromBase64(data.toLatin1()),
|
||||
QCryptographicHash::Md5)
|
||||
.toHex());
|
||||
}
|
||||
|
||||
|
@ -275,8 +264,7 @@ QString EvernoteImportDialog::importImages(const Note ¬e, QString content,
|
|||
*
|
||||
* @param content
|
||||
*/
|
||||
QString EvernoteImportDialog::importAttachments(const Note ¬e,
|
||||
QString content,
|
||||
QString EvernoteImportDialog::importAttachments(const Note ¬e, QString content,
|
||||
QXmlQuery query) {
|
||||
query.setQuery(QStringLiteral("resource"));
|
||||
|
||||
|
@ -299,9 +287,8 @@ QString EvernoteImportDialog::importAttachments(const Note ¬e,
|
|||
query.setQuery(QStringLiteral("mime/text()"));
|
||||
query.evaluateTo(&mime);
|
||||
|
||||
QRegularExpression mimeExpression(
|
||||
QStringLiteral("(.+)?\\/(.+)?"),
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
QRegularExpression mimeExpression(QStringLiteral("(.+)?\\/(.+)?"),
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
QRegularExpressionMatch mimeMatch = mimeExpression.match(mime);
|
||||
|
||||
if (mimeMatch.hasMatch()) {
|
||||
|
@ -338,9 +325,8 @@ QString EvernoteImportDialog::importAttachments(const Note ¬e,
|
|||
|
||||
// if there is no object id set we generate the hash ourselves
|
||||
if (objectId.isEmpty()) {
|
||||
objectId = QString(QCryptographicHash::hash(
|
||||
QByteArray::fromBase64(data.toLatin1()),
|
||||
QCryptographicHash::Md5)
|
||||
objectId = QString(QCryptographicHash::hash(QByteArray::fromBase64(data.toLatin1()),
|
||||
QCryptographicHash::Md5)
|
||||
.toHex());
|
||||
}
|
||||
|
||||
|
@ -396,8 +382,7 @@ QString EvernoteImportDialog::importAttachments(const Note ¬e,
|
|||
MediaFileData mediaFileData = mediaFileDataHash[objectId];
|
||||
|
||||
// get the Markdown code for the file data entry
|
||||
QString markdownCode =
|
||||
getMarkdownForAttachmentFileData(note, mediaFileData);
|
||||
QString markdownCode = getMarkdownForAttachmentFileData(note, mediaFileData);
|
||||
|
||||
if (!markdownCode.isEmpty()) {
|
||||
// replace media tag with Markdown code
|
||||
|
@ -417,8 +402,7 @@ QString EvernoteImportDialog::importAttachments(const Note ¬e,
|
|||
MediaFileData mediaFileData = hashIterator.value();
|
||||
|
||||
// get the Markdown code for the file data entry
|
||||
QString markdownCode =
|
||||
getMarkdownForAttachmentFileData(note, mediaFileData);
|
||||
QString markdownCode = getMarkdownForAttachmentFileData(note, mediaFileData);
|
||||
|
||||
content += "\n" + markdownCode;
|
||||
}
|
||||
|
@ -563,8 +547,7 @@ QString EvernoteImportDialog::generateMetaDataMarkdown(QXmlQuery query) {
|
|||
QString resultText;
|
||||
QString tableText;
|
||||
QList<QTreeWidgetItem *> items = ui->metaDataTreeWidget->findItems(
|
||||
QStringLiteral("*"),
|
||||
Qt::MatchWrap | Qt::MatchWildcard | Qt::MatchRecursive);
|
||||
QStringLiteral("*"), Qt::MatchWrap | Qt::MatchWildcard | Qt::MatchRecursive);
|
||||
|
||||
Q_FOREACH (QTreeWidgetItem *item, items) {
|
||||
if (item->checkState(0) != Qt::Checked) {
|
||||
|
@ -583,8 +566,7 @@ QString EvernoteImportDialog::generateMetaDataMarkdown(QXmlQuery query) {
|
|||
continue;
|
||||
}
|
||||
|
||||
tableText += QStringLiteral("| ") + name + (" | ") + attribute +
|
||||
QStringLiteral(" |\n");
|
||||
tableText += QStringLiteral("| ") + name + (" | ") + attribute + QStringLiteral(" |\n");
|
||||
}
|
||||
|
||||
if (!tableText.isEmpty()) {
|
||||
|
@ -606,9 +588,9 @@ QString EvernoteImportDialog::generateMetaDataMarkdown(QXmlQuery query) {
|
|||
* @param parentItem
|
||||
* @return
|
||||
*/
|
||||
QTreeWidgetItem *EvernoteImportDialog::addMetaDataTreeWidgetItem(
|
||||
const QString &name, const QString &attributeName,
|
||||
QTreeWidgetItem *parentItem) {
|
||||
QTreeWidgetItem *EvernoteImportDialog::addMetaDataTreeWidgetItem(const QString &name,
|
||||
const QString &attributeName,
|
||||
QTreeWidgetItem *parentItem) {
|
||||
auto *item = new QTreeWidgetItem();
|
||||
item->setText(0, name);
|
||||
|
||||
|
@ -622,12 +604,9 @@ QTreeWidgetItem *EvernoteImportDialog::addMetaDataTreeWidgetItem(
|
|||
|
||||
QSettings settings;
|
||||
auto metaDataUnCheckedList =
|
||||
settings
|
||||
.value(QStringLiteral("EvernoteImport/MetaDataUnCheckedList"))
|
||||
.toStringList();
|
||||
item->setCheckState(0, metaDataUnCheckedList.contains(attributeName)
|
||||
? Qt::Unchecked
|
||||
: Qt::Checked);
|
||||
settings.value(QStringLiteral("EvernoteImport/MetaDataUnCheckedList")).toStringList();
|
||||
item->setCheckState(
|
||||
0, metaDataUnCheckedList.contains(attributeName) ? Qt::Unchecked : Qt::Checked);
|
||||
|
||||
parentItem->addChild(item);
|
||||
}
|
||||
|
@ -639,58 +618,42 @@ QTreeWidgetItem *EvernoteImportDialog::addMetaDataTreeWidgetItem(
|
|||
* Setup the metadata tree widget items
|
||||
*/
|
||||
void EvernoteImportDialog::setupMetaDataTreeWidgetItems() {
|
||||
auto *basicAttributesItem =
|
||||
addMetaDataTreeWidgetItem(tr("Basic attributes"));
|
||||
addMetaDataTreeWidgetItem(tr("Created date"), QStringLiteral("created"),
|
||||
basicAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Updated date"), QStringLiteral("updated"),
|
||||
basicAttributesItem);
|
||||
auto *basicAttributesItem = addMetaDataTreeWidgetItem(tr("Basic attributes"));
|
||||
addMetaDataTreeWidgetItem(tr("Created date"), QStringLiteral("created"), basicAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Updated date"), QStringLiteral("updated"), basicAttributesItem);
|
||||
|
||||
auto *noteAttributesItem = addMetaDataTreeWidgetItem(tr("Note attributes"));
|
||||
addMetaDataTreeWidgetItem(tr("Subject date"),
|
||||
QStringLiteral("note-attributes/subject-date"),
|
||||
addMetaDataTreeWidgetItem(tr("Subject date"), QStringLiteral("note-attributes/subject-date"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Latitude"),
|
||||
QStringLiteral("note-attributes/latitude"),
|
||||
addMetaDataTreeWidgetItem(tr("Latitude"), QStringLiteral("note-attributes/latitude"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Longitude"),
|
||||
QStringLiteral("note-attributes/longitude"),
|
||||
addMetaDataTreeWidgetItem(tr("Longitude"), QStringLiteral("note-attributes/longitude"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Altitude"),
|
||||
QStringLiteral("note-attributes/altitude"),
|
||||
addMetaDataTreeWidgetItem(tr("Altitude"), QStringLiteral("note-attributes/altitude"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Author"),
|
||||
QStringLiteral("note-attributes/author"),
|
||||
addMetaDataTreeWidgetItem(tr("Author"), QStringLiteral("note-attributes/author"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Source"),
|
||||
QStringLiteral("note-attributes/source"),
|
||||
addMetaDataTreeWidgetItem(tr("Source"), QStringLiteral("note-attributes/source"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Source URL"),
|
||||
QStringLiteral("note-attributes/source-url"),
|
||||
addMetaDataTreeWidgetItem(tr("Source URL"), QStringLiteral("note-attributes/source-url"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Source application"),
|
||||
QStringLiteral("note-attributes/source-application"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(
|
||||
tr("Source application"),
|
||||
QStringLiteral("note-attributes/source-application"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Reminder order"),
|
||||
QStringLiteral("note-attributes/reminder-order"),
|
||||
QStringLiteral("note-attributes/reminder-order"), noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Reminder time"), QStringLiteral("note-attributes/reminder-time"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Reminder time"),
|
||||
QStringLiteral("note-attributes/reminder-time"),
|
||||
addMetaDataTreeWidgetItem(tr("Reminder done time"),
|
||||
QStringLiteral("note-attributes/reminder-done-time"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(
|
||||
tr("Reminder done time"),
|
||||
QStringLiteral("note-attributes/reminder-done-time"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Place name"),
|
||||
QStringLiteral("note-attributes/place-name"),
|
||||
addMetaDataTreeWidgetItem(tr("Place name"), QStringLiteral("note-attributes/place-name"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Content class"),
|
||||
QStringLiteral("note-attributes/content-class"),
|
||||
addMetaDataTreeWidgetItem(tr("Content class"), QStringLiteral("note-attributes/content-class"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(tr("Application data"),
|
||||
QStringLiteral("note-attributes/application-data"),
|
||||
noteAttributesItem);
|
||||
addMetaDataTreeWidgetItem(
|
||||
tr("Application data"),
|
||||
QStringLiteral("note-attributes/application-data"), noteAttributesItem);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -698,8 +661,7 @@ void EvernoteImportDialog::setupMetaDataTreeWidgetItems() {
|
|||
*/
|
||||
void EvernoteImportDialog::storeMetaDataTreeWidgetItemsCheckedState() {
|
||||
QList<QTreeWidgetItem *> items = ui->metaDataTreeWidget->findItems(
|
||||
QStringLiteral("*"),
|
||||
Qt::MatchWrap | Qt::MatchWildcard | Qt::MatchRecursive);
|
||||
QStringLiteral("*"), Qt::MatchWrap | Qt::MatchWildcard | Qt::MatchRecursive);
|
||||
QSettings settings;
|
||||
QStringList metaDataUnCheckedList;
|
||||
|
||||
|
@ -720,8 +682,7 @@ void EvernoteImportDialog::storeMetaDataTreeWidgetItemsCheckedState() {
|
|||
*/
|
||||
bool EvernoteImportDialog::isMetaDataChecked() {
|
||||
QList<QTreeWidgetItem *> items = ui->metaDataTreeWidget->findItems(
|
||||
QStringLiteral("*"),
|
||||
Qt::MatchWrap | Qt::MatchWildcard | Qt::MatchRecursive);
|
||||
QStringLiteral("*"), Qt::MatchWrap | Qt::MatchWildcard | Qt::MatchRecursive);
|
||||
|
||||
Q_FOREACH (QTreeWidgetItem *item, items) {
|
||||
if (item->checkState(0) == Qt::Checked) {
|
||||
|
@ -790,9 +751,8 @@ QString EvernoteImportDialog::getMarkdownForAttachmentFileData(
|
|||
QString fileName = mediaFileData.fileName;
|
||||
|
||||
// create a temporary file for the attachment
|
||||
auto *tempFile =
|
||||
new QTemporaryFile(QDir::tempPath() + QDir::separator() +
|
||||
QStringLiteral("media-XXXXXX.") + suffix);
|
||||
auto *tempFile = new QTemporaryFile(QDir::tempPath() + QDir::separator() +
|
||||
QStringLiteral("media-XXXXXX.") + suffix);
|
||||
|
||||
if (!tempFile->open()) {
|
||||
return QString();
|
||||
|
|
|
@ -40,19 +40,16 @@ class EvernoteImportDialog : public MasterDialog {
|
|||
|
||||
void initNoteCount(const QString &data);
|
||||
|
||||
QString getMarkdownForMediaFileData(Note note,
|
||||
const MediaFileData &mediaFileData);
|
||||
QString getMarkdownForMediaFileData(Note note, const MediaFileData &mediaFileData);
|
||||
|
||||
QString getMarkdownForAttachmentFileData(
|
||||
Note note, const MediaFileData &mediaFileData);
|
||||
QString getMarkdownForAttachmentFileData(Note note, const MediaFileData &mediaFileData);
|
||||
|
||||
QTreeWidgetItem *addMetaDataTreeWidgetItem(
|
||||
const QString &name, const QString &attributeName = QString(),
|
||||
QTreeWidgetItem *parentItem = nullptr);
|
||||
QTreeWidgetItem *addMetaDataTreeWidgetItem(const QString &name,
|
||||
const QString &attributeName = QString(),
|
||||
QTreeWidgetItem *parentItem = nullptr);
|
||||
|
||||
bool isMetaDataChecked();
|
||||
|
||||
|
||||
/** These require xml patterns **/
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
void importNotes(const QString &data);
|
||||
|
@ -63,8 +60,7 @@ class EvernoteImportDialog : public MasterDialog {
|
|||
|
||||
void tagNote(QXmlQuery &query, Note ¬e);
|
||||
|
||||
QString importAttachments(const Note ¬e, QString content,
|
||||
QXmlQuery query);
|
||||
QString importAttachments(const Note ¬e, QString content, QXmlQuery query);
|
||||
|
||||
QString generateMetaDataMarkdown(QXmlQuery query);
|
||||
#endif
|
||||
|
|
|
@ -32,10 +32,8 @@ FileDialog::FileDialog(const QString& name) {
|
|||
setDirectory(path);
|
||||
|
||||
// store the directory for the next time the dialog opens
|
||||
connect(this, SIGNAL(fileSelected(QString)), this,
|
||||
SLOT(storeDirectory(QString)));
|
||||
connect(this, SIGNAL(filesSelected(QStringList)), this,
|
||||
SLOT(storeDirectory(QStringList)));
|
||||
connect(this, SIGNAL(fileSelected(QString)), this, SLOT(storeDirectory(QString)));
|
||||
connect(this, SIGNAL(filesSelected(QStringList)), this, SLOT(storeDirectory(QStringList)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,7 @@
|
|||
#include "filedialog.h"
|
||||
#include "ui_imagedialog.h"
|
||||
|
||||
ImageDialog::ImageDialog(QWidget *parent)
|
||||
: MasterDialog(parent), ui(new Ui::ImageDialog) {
|
||||
ImageDialog::ImageDialog(QWidget *parent) : MasterDialog(parent), ui(new Ui::ImageDialog) {
|
||||
_imageFile = nullptr;
|
||||
_tempFile = nullptr;
|
||||
_rubberBand = nullptr;
|
||||
|
@ -61,15 +60,11 @@ ImageDialog::~ImageDialog() {
|
|||
delete ui;
|
||||
}
|
||||
|
||||
bool ImageDialog::isDisableCopying() {
|
||||
return ui->disableCopyingCheckBox->isChecked();
|
||||
}
|
||||
bool ImageDialog::isDisableCopying() { return ui->disableCopyingCheckBox->isChecked(); }
|
||||
|
||||
QFile *ImageDialog::getImageFile() { return _imageFile; }
|
||||
|
||||
QString ImageDialog::getFilePathOrUrl() {
|
||||
return ui->fileEdit->text().trimmed();
|
||||
}
|
||||
QString ImageDialog::getFilePathOrUrl() { return ui->fileEdit->text().trimmed(); }
|
||||
|
||||
QString ImageDialog::getImageTitle() { return ui->titleEdit->text(); }
|
||||
|
||||
|
@ -129,11 +124,10 @@ void ImageDialog::setPixmap(const QPixmap &pixmap, bool updateBase) {
|
|||
void ImageDialog::on_buttonBox_accepted() {
|
||||
// if the image was manipulated or from the clipboard we will store it into
|
||||
// a temporary file
|
||||
if (ui->fileEdit->text().trimmed().isEmpty() || _imageWasCropped ||
|
||||
_imageWasDownloaded ||
|
||||
if (ui->fileEdit->text().trimmed().isEmpty() || _imageWasCropped || _imageWasDownloaded ||
|
||||
ui->widthSpinBox->value() != _basePixmap.width()) {
|
||||
_tempFile = new QTemporaryFile(QDir::tempPath() + QDir::separator() +
|
||||
"qownnotes-media-XXXXXX.png");
|
||||
_tempFile =
|
||||
new QTemporaryFile(QDir::tempPath() + QDir::separator() + "qownnotes-media-XXXXXX.png");
|
||||
|
||||
if (_tempFile->open()) {
|
||||
// save temporary png image
|
||||
|
@ -216,8 +210,7 @@ void ImageDialog::on_fileEdit_textChanged(const QString &arg1) {
|
|||
|
||||
void ImageDialog::on_disableCopyingCheckBox_toggled(bool checked) {
|
||||
ui->scaleFrame->setDisabled(checked);
|
||||
ui->graphicsView->setDragMode(checked ? QGraphicsView::NoDrag
|
||||
: QGraphicsView::RubberBandDrag);
|
||||
ui->graphicsView->setDragMode(checked ? QGraphicsView::NoDrag : QGraphicsView::RubberBandDrag);
|
||||
|
||||
if (checked) {
|
||||
// reset scaling
|
||||
|
@ -225,8 +218,7 @@ void ImageDialog::on_disableCopyingCheckBox_toggled(bool checked) {
|
|||
}
|
||||
}
|
||||
|
||||
void ImageDialog::on_graphicsView_rubberBandChanged(QRect viewportRect,
|
||||
QPointF fromScenePoint,
|
||||
void ImageDialog::on_graphicsView_rubberBandChanged(QRect viewportRect, QPointF fromScenePoint,
|
||||
QPointF toScenePoint) {
|
||||
if (viewportRect.isEmpty()) { // dragging has stopped
|
||||
_rubberBand = new QRubberBand(QRubberBand::Rectangle, ui->graphicsView);
|
||||
|
@ -235,8 +227,8 @@ void ImageDialog::on_graphicsView_rubberBandChanged(QRect viewportRect,
|
|||
|
||||
// we need to adapt the rubberband by the content margins of the
|
||||
// graphics view
|
||||
_lastRubberBandViewportRect.adjust(margin.left(), margin.top(),
|
||||
margin.left(), margin.top());
|
||||
_lastRubberBandViewportRect.adjust(margin.left(), margin.top(), margin.left(),
|
||||
margin.top());
|
||||
|
||||
_rubberBand->setGeometry(_lastRubberBandViewportRect);
|
||||
_rubberBand->show();
|
||||
|
@ -266,8 +258,7 @@ void ImageDialog::on_graphicsView_rubberBandChanged(QRect viewportRect,
|
|||
}
|
||||
|
||||
// swap coordinates if the drag was "reversed"
|
||||
if (fromScenePointI.x() > toScenePointI.x() &&
|
||||
fromScenePointI.y() > toScenePointI.y()) {
|
||||
if (fromScenePointI.x() > toScenePointI.x() && fromScenePointI.y() > toScenePointI.y()) {
|
||||
_rubberBandSceneRect = QRect(toScenePointI, fromScenePointI);
|
||||
} else {
|
||||
_rubberBandSceneRect = QRect(fromScenePointI, toScenePointI);
|
||||
|
|
|
@ -39,8 +39,7 @@ class ImageDialog : public MasterDialog {
|
|||
|
||||
void on_disableCopyingCheckBox_toggled(bool checked);
|
||||
|
||||
void on_graphicsView_rubberBandChanged(QRect viewportRect,
|
||||
QPointF fromScenePoint,
|
||||
void on_graphicsView_rubberBandChanged(QRect viewportRect, QPointF fromScenePoint,
|
||||
QPointF toScenePoint);
|
||||
|
||||
void on_cropButton_clicked();
|
||||
|
|
|
@ -28,10 +28,10 @@ IssueAssistantDialog::IssueAssistantDialog(QWidget *parent)
|
|||
SLOT(allowIssuePageNextButton()));
|
||||
QObject::connect(ui->questionPlainTextEdit, SIGNAL(textChanged()), this,
|
||||
SLOT(allowIssuePageNextButton()));
|
||||
QObject::connect(ui->expectedBehaviourPlainTextEdit, SIGNAL(textChanged()),
|
||||
this, SLOT(allowIssuePageNextButton()));
|
||||
QObject::connect(ui->actualBehaviourPlainTextEdit, SIGNAL(textChanged()),
|
||||
this, SLOT(allowIssuePageNextButton()));
|
||||
QObject::connect(ui->expectedBehaviourPlainTextEdit, SIGNAL(textChanged()), this,
|
||||
SLOT(allowIssuePageNextButton()));
|
||||
QObject::connect(ui->actualBehaviourPlainTextEdit, SIGNAL(textChanged()), this,
|
||||
SLOT(allowIssuePageNextButton()));
|
||||
QObject::connect(ui->stepsPlainTextEdit, SIGNAL(textChanged()), this,
|
||||
SLOT(allowIssuePageNextButton()));
|
||||
QObject::connect(ui->logOutputPlainTextEdit, SIGNAL(textChanged()), this,
|
||||
|
@ -43,8 +43,7 @@ IssueAssistantDialog::IssueAssistantDialog(QWidget *parent)
|
|||
IssueAssistantDialog::~IssueAssistantDialog() { delete ui; }
|
||||
|
||||
void IssueAssistantDialog::on_nextButton_clicked() {
|
||||
MetricsService::instance()->sendVisitIfEnabled(
|
||||
QStringLiteral("issue-assistant-dialog/next"));
|
||||
MetricsService::instance()->sendVisitIfEnabled(QStringLiteral("issue-assistant-dialog/next"));
|
||||
|
||||
int index = ui->stackedWidget->currentIndex();
|
||||
int maxIndex = ui->stackedWidget->count() - 1;
|
||||
|
@ -68,13 +67,11 @@ void IssueAssistantDialog::allowIssuePageNextButton() const {
|
|||
}
|
||||
|
||||
if (ui->expectedBehaviourPlainTextEdit->isVisible()) {
|
||||
allow = allow &&
|
||||
ui->expectedBehaviourPlainTextEdit->toPlainText().length() >= 10;
|
||||
allow = allow && ui->expectedBehaviourPlainTextEdit->toPlainText().length() >= 10;
|
||||
}
|
||||
|
||||
if (ui->actualBehaviourPlainTextEdit->isVisible()) {
|
||||
allow = allow &&
|
||||
ui->actualBehaviourPlainTextEdit->toPlainText().length() >= 10;
|
||||
allow = allow && ui->actualBehaviourPlainTextEdit->toPlainText().length() >= 10;
|
||||
}
|
||||
|
||||
if (ui->stepsPlainTextEdit->isVisible()) {
|
||||
|
@ -87,9 +84,9 @@ void IssueAssistantDialog::allowIssuePageNextButton() const {
|
|||
void IssueAssistantDialog::allowLogPageNextButton() const {
|
||||
bool allow = true;
|
||||
|
||||
// if (ui->issueTypeComboBox->currentIndex() == ProblemIssueType) {
|
||||
// allow = ui->logOutputPlainTextEdit->toPlainText().length() >= 10;
|
||||
// }
|
||||
// if (ui->issueTypeComboBox->currentIndex() == ProblemIssueType) {
|
||||
// allow = ui->logOutputPlainTextEdit->toPlainText().length() >= 10;
|
||||
// }
|
||||
|
||||
ui->nextButton->setEnabled(allow);
|
||||
}
|
||||
|
@ -166,14 +163,11 @@ void IssueAssistantDialog::generateSubmitPageContent() const {
|
|||
break;
|
||||
case FeatureRequestIssueType:
|
||||
case ProblemIssueType:
|
||||
body +=
|
||||
"#### Expected behaviour\n\n" +
|
||||
ui->expectedBehaviourPlainTextEdit->toPlainText().trimmed() +
|
||||
"\n\n";
|
||||
body += "#### Expected behaviour\n\n" +
|
||||
ui->expectedBehaviourPlainTextEdit->toPlainText().trimmed() + "\n\n";
|
||||
|
||||
body += "#### Actual behaviour\n\n" +
|
||||
ui->actualBehaviourPlainTextEdit->toPlainText().trimmed() +
|
||||
"\n\n";
|
||||
ui->actualBehaviourPlainTextEdit->toPlainText().trimmed() + "\n\n";
|
||||
|
||||
body += "#### Steps to reproduce\n\n" +
|
||||
ui->stepsPlainTextEdit->toPlainText().trimmed() + "\n\n";
|
||||
|
@ -185,21 +179,18 @@ void IssueAssistantDialog::generateSubmitPageContent() const {
|
|||
body +=
|
||||
"#### Relevant log output in the Log panel\n\n"
|
||||
"<details><summary>Expand</summary>\n\n```\n" +
|
||||
ui->logOutputPlainTextEdit->toPlainText().trimmed() +
|
||||
"\n```\n</details>\n\n";
|
||||
ui->logOutputPlainTextEdit->toPlainText().trimmed() + "\n```\n</details>\n\n";
|
||||
|
||||
body +=
|
||||
"#### Information about the application, settings and "
|
||||
"environment\n\n<details><summary>Expand</summary>\n\n" +
|
||||
ui->debugOutputPlainTextEdit->toPlainText().trimmed() +
|
||||
"\n</details>\n\n";
|
||||
ui->debugOutputPlainTextEdit->toPlainText().trimmed() + "\n</details>\n\n";
|
||||
|
||||
ui->bodyPlainTextEdit->setPlainText(body);
|
||||
}
|
||||
|
||||
void IssueAssistantDialog::on_backButton_clicked() {
|
||||
MetricsService::instance()->sendVisitIfEnabled(
|
||||
QStringLiteral("issue-assistant-dialog/back"));
|
||||
MetricsService::instance()->sendVisitIfEnabled(QStringLiteral("issue-assistant-dialog/back"));
|
||||
|
||||
int index = ui->stackedWidget->currentIndex();
|
||||
|
||||
|
@ -234,15 +225,13 @@ void IssueAssistantDialog::on_issueTypeComboBox_currentIndexChanged(int index) {
|
|||
void IssueAssistantDialog::on_refreshLogButton_clicked() { refreshLogOutput(); }
|
||||
|
||||
void IssueAssistantDialog::on_postButton_clicked() {
|
||||
MetricsService::instance()->sendVisitIfEnabled(
|
||||
QStringLiteral("issue-assistant-dialog/post"));
|
||||
MetricsService::instance()->sendVisitIfEnabled(QStringLiteral("issue-assistant-dialog/post"));
|
||||
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
clipboard->setText(ui->bodyPlainTextEdit->toPlainText());
|
||||
|
||||
QUrl url("https://github.com/pbek/QOwnNotes/issues/new?title=" +
|
||||
QUrl::toPercentEncoding(ui->submitTitleLineEdit->text()) +
|
||||
"&body=" +
|
||||
QUrl::toPercentEncoding(ui->submitTitleLineEdit->text()) + "&body=" +
|
||||
QUrl::toPercentEncoding("Please paste the text from the issue "
|
||||
"assistant here. It should be already in "
|
||||
"your clipboard."));
|
||||
|
@ -264,10 +253,9 @@ void IssueAssistantDialog::on_searchIssueButton_clicked() {
|
|||
}
|
||||
|
||||
void IssueAssistantDialog::on_newIssueButton_clicked() {
|
||||
if (Utils::Gui::question(
|
||||
this, QStringLiteral("Create new issue"),
|
||||
QStringLiteral("Reset this dialog and create a new issue?"),
|
||||
QStringLiteral("issue-dialog-new-issue")) != QMessageBox::Yes) {
|
||||
if (Utils::Gui::question(this, QStringLiteral("Create new issue"),
|
||||
QStringLiteral("Reset this dialog and create a new issue?"),
|
||||
QStringLiteral("issue-dialog-new-issue")) != QMessageBox::Yes) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,12 +12,7 @@ class IssueAssistantDialog : public MasterDialog {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum IssueAssistantPages {
|
||||
IssuePage,
|
||||
LogOutputPage,
|
||||
DebugSettingsPage,
|
||||
SubmitPage
|
||||
};
|
||||
enum IssueAssistantPages { IssuePage, LogOutputPage, DebugSettingsPage, SubmitPage };
|
||||
|
||||
enum IssueTypes {
|
||||
ProblemIssueType,
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "filedialog.h"
|
||||
#include "ui_joplinimportdialog.h"
|
||||
|
||||
JoplinImportDialog::JoplinImportDialog(QWidget *parent)
|
||||
JoplinImportDialog::JoplinImportDialog(QWidget* parent)
|
||||
: MasterDialog(parent), ui(new Ui::JoplinImportDialog) {
|
||||
ui->setupUi(this);
|
||||
|
||||
|
@ -26,56 +26,39 @@ JoplinImportDialog::JoplinImportDialog(QWidget *parent)
|
|||
bool showFolders = NoteFolder::isCurrentShowSubfolders();
|
||||
|
||||
if (!showFolders) {
|
||||
ui->folderImportCheckBox->setToolTip(QObject::tr(
|
||||
"Turned on note subfolders for the current note folder to be "
|
||||
"able to import folders."));
|
||||
ui->folderImportCheckBox->setToolTip(
|
||||
QObject::tr("Turned on note subfolders for the current note folder to be "
|
||||
"able to import folders."));
|
||||
}
|
||||
|
||||
ui->folderImportCheckBox->setEnabled(showFolders);
|
||||
ui->folderImportCheckBox->setChecked(
|
||||
settings.value(
|
||||
QStringLiteral("JoplinImport/FolderImportCheckBoxChecked"), true)
|
||||
.toBool() && showFolders);
|
||||
settings.value(QStringLiteral("JoplinImport/FolderImportCheckBoxChecked"), true).toBool() &&
|
||||
showFolders);
|
||||
ui->tagImportCheckBox->setChecked(
|
||||
settings
|
||||
.value(QStringLiteral("JoplinImport/TagImportCheckBoxChecked"),
|
||||
true)
|
||||
.toBool());
|
||||
settings.value(QStringLiteral("JoplinImport/TagImportCheckBoxChecked"), true).toBool());
|
||||
ui->metadataImportCheckBox->setChecked(
|
||||
settings
|
||||
.value(QStringLiteral("JoplinImport/MetadataImportCheckBoxChecked"),
|
||||
true)
|
||||
.toBool());
|
||||
ui->imageImportCheckBox->setChecked(
|
||||
settings
|
||||
.value(QStringLiteral("JoplinImport/ImageImportCheckBoxChecked"),
|
||||
true)
|
||||
settings.value(QStringLiteral("JoplinImport/MetadataImportCheckBoxChecked"), true)
|
||||
.toBool());
|
||||
ui->imageImportCheckBox->setChecked(
|
||||
settings.value(QStringLiteral("JoplinImport/ImageImportCheckBoxChecked"), true).toBool());
|
||||
ui->attachmentImportCheckBox->setChecked(
|
||||
settings
|
||||
.value(QStringLiteral(
|
||||
"JoplinImport/AttachmentImportCheckBoxChecked"),
|
||||
true)
|
||||
settings.value(QStringLiteral("JoplinImport/AttachmentImportCheckBoxChecked"), true)
|
||||
.toBool());
|
||||
}
|
||||
|
||||
JoplinImportDialog::~JoplinImportDialog() {
|
||||
QSettings settings;
|
||||
settings.setValue(
|
||||
QStringLiteral("JoplinImport/FolderImportCheckBoxChecked"),
|
||||
ui->folderImportCheckBox->isChecked());
|
||||
settings.setValue(
|
||||
QStringLiteral("JoplinImport/TagImportCheckBoxChecked"),
|
||||
ui->tagImportCheckBox->isChecked());
|
||||
settings.setValue(
|
||||
QStringLiteral("JoplinImport/MetadataImportCheckBoxChecked"),
|
||||
ui->metadataImportCheckBox->isChecked());
|
||||
settings.setValue(
|
||||
QStringLiteral("JoplinImport/ImageImportCheckBoxChecked"),
|
||||
ui->imageImportCheckBox->isChecked());
|
||||
settings.setValue(
|
||||
QStringLiteral("JoplinImport/AttachmentImportCheckBoxChecked"),
|
||||
ui->attachmentImportCheckBox->isChecked());
|
||||
settings.setValue(QStringLiteral("JoplinImport/FolderImportCheckBoxChecked"),
|
||||
ui->folderImportCheckBox->isChecked());
|
||||
settings.setValue(QStringLiteral("JoplinImport/TagImportCheckBoxChecked"),
|
||||
ui->tagImportCheckBox->isChecked());
|
||||
settings.setValue(QStringLiteral("JoplinImport/MetadataImportCheckBoxChecked"),
|
||||
ui->metadataImportCheckBox->isChecked());
|
||||
settings.setValue(QStringLiteral("JoplinImport/ImageImportCheckBoxChecked"),
|
||||
ui->imageImportCheckBox->isChecked());
|
||||
settings.setValue(QStringLiteral("JoplinImport/AttachmentImportCheckBoxChecked"),
|
||||
ui->attachmentImportCheckBox->isChecked());
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
@ -127,7 +110,7 @@ void JoplinImportDialog::on_importButton_clicked() {
|
|||
ui->progressBar->setMaximum(files.count());
|
||||
ui->progressBar->show();
|
||||
|
||||
foreach(QString fileName, files) {
|
||||
foreach (QString fileName, files) {
|
||||
QCoreApplication::processEvents();
|
||||
QString filePath = dir.path() + "/" + fileName;
|
||||
QFile file(filePath);
|
||||
|
@ -138,51 +121,50 @@ void JoplinImportDialog::on_importButton_clicked() {
|
|||
}
|
||||
|
||||
const QString text = file.readAll();
|
||||
auto textLines = text.split(QRegularExpression(
|
||||
QStringLiteral(R"((\r\n)|(\n\r)|\r|\n)")));
|
||||
auto textLines = text.split(QRegularExpression(QStringLiteral(R"((\r\n)|(\n\r)|\r|\n)")));
|
||||
const auto id = fileName.remove(QRegularExpression("\\.md$"));
|
||||
|
||||
// check if text contains a note
|
||||
if (text.contains(QRegularExpression(
|
||||
"^type_: 1$", QRegularExpression::MultilineOption))) {
|
||||
if (text.contains(QRegularExpression("^type_: 1$", QRegularExpression::MultilineOption))) {
|
||||
_noteData[id] = text;
|
||||
|
||||
// don't increase the progress bar yet
|
||||
continue;
|
||||
}
|
||||
// check if text contains a folder
|
||||
if (text.contains(QRegularExpression(
|
||||
"^type_: 2$", QRegularExpression::MultilineOption))) {
|
||||
if (text.contains(QRegularExpression("^type_: 2$", QRegularExpression::MultilineOption))) {
|
||||
_folderData[id] = text;
|
||||
}
|
||||
// check if text contains an image or attachment
|
||||
else if (text.contains(QRegularExpression(
|
||||
"^type_: 4$", QRegularExpression::MultilineOption))) {
|
||||
if (text.contains(QRegularExpression(
|
||||
"^mime: image/", QRegularExpression::MultilineOption))) {
|
||||
else if (text.contains(
|
||||
QRegularExpression("^type_: 4$", QRegularExpression::MultilineOption))) {
|
||||
if (text.contains(
|
||||
QRegularExpression("^mime: image/", QRegularExpression::MultilineOption))) {
|
||||
_imageData[id] = text;
|
||||
} else {
|
||||
_attachmentData[id] = text;
|
||||
}
|
||||
}
|
||||
// check if text contains a tag
|
||||
else if (text.contains(QRegularExpression(
|
||||
"^type_: 5$", QRegularExpression::MultilineOption))) {
|
||||
else if (text.contains(
|
||||
QRegularExpression("^type_: 5$", QRegularExpression::MultilineOption))) {
|
||||
_tagData[id] = textLines[0];
|
||||
}
|
||||
// check if text contains a tag assignment
|
||||
else if (text.contains(QRegularExpression(
|
||||
"^type_: 6$", QRegularExpression::MultilineOption))) {
|
||||
auto noteIdMatch = QRegularExpression("^note_id: (.+)$",
|
||||
QRegularExpression::MultilineOption).match(text);
|
||||
else if (text.contains(
|
||||
QRegularExpression("^type_: 6$", QRegularExpression::MultilineOption))) {
|
||||
auto noteIdMatch =
|
||||
QRegularExpression("^note_id: (.+)$", QRegularExpression::MultilineOption)
|
||||
.match(text);
|
||||
QString noteId;
|
||||
|
||||
if (noteIdMatch.hasMatch()) {
|
||||
noteId = noteIdMatch.captured(1);
|
||||
}
|
||||
|
||||
auto tagIdMatch = QRegularExpression("^tag_id: (.+)$",
|
||||
QRegularExpression::MultilineOption).match(text);
|
||||
auto tagIdMatch =
|
||||
QRegularExpression("^tag_id: (.+)$", QRegularExpression::MultilineOption)
|
||||
.match(text);
|
||||
QString tagId;
|
||||
|
||||
if (tagIdMatch.hasMatch()) {
|
||||
|
@ -242,8 +224,8 @@ NoteSubFolder JoplinImportDialog::importFolder(const QString& id, const QString&
|
|||
}
|
||||
|
||||
auto parentSubFolder = NoteSubFolder();
|
||||
auto parentIdMatch = QRegularExpression("^parent_id: (.+)$",
|
||||
QRegularExpression::MultilineOption).match(text);
|
||||
auto parentIdMatch =
|
||||
QRegularExpression("^parent_id: (.+)$", QRegularExpression::MultilineOption).match(text);
|
||||
|
||||
// check if we need to create the parent first
|
||||
if (parentIdMatch.hasMatch()) {
|
||||
|
@ -254,8 +236,7 @@ NoteSubFolder JoplinImportDialog::importFolder(const QString& id, const QString&
|
|||
}
|
||||
}
|
||||
|
||||
auto textLines = text.split(QRegularExpression(
|
||||
QStringLiteral(R"((\r\n)|(\n\r)|\r|\n)")));
|
||||
auto textLines = text.split(QRegularExpression(QStringLiteral(R"((\r\n)|(\n\r)|\r|\n)")));
|
||||
|
||||
auto folderName = textLines.at(0).trimmed();
|
||||
|
||||
|
@ -298,16 +279,15 @@ NoteSubFolder JoplinImportDialog::importFolder(const QString& id, const QString&
|
|||
*/
|
||||
bool JoplinImportDialog::importNote(const QString& id, const QString& text,
|
||||
const QString& dirPath) {
|
||||
auto textLines = text.split(QRegularExpression(
|
||||
QStringLiteral(R"((\r\n)|(\n\r)|\r|\n)")));
|
||||
auto textLines = text.split(QRegularExpression(QStringLiteral(R"((\r\n)|(\n\r)|\r|\n)")));
|
||||
|
||||
auto title = textLines.at(0);
|
||||
title.remove(QRegularExpression("^[\\d+\\.]+"));
|
||||
auto noteText = Note::createNoteHeader(title.trimmed());
|
||||
noteText += text.trimmed();
|
||||
|
||||
auto parts = noteText.split(QRegularExpression("^id: " + id + "$",
|
||||
QRegularExpression::MultilineOption));
|
||||
auto parts =
|
||||
noteText.split(QRegularExpression("^id: " + id + "$", QRegularExpression::MultilineOption));
|
||||
|
||||
Note note = Note();
|
||||
QString newNoteText;
|
||||
|
@ -321,8 +301,9 @@ bool JoplinImportDialog::importNote(const QString& id, const QString& text,
|
|||
note.setNoteText(newNoteText);
|
||||
|
||||
if (ui->folderImportCheckBox->isChecked()) {
|
||||
auto parentIdMatch = QRegularExpression("^parent_id: (.+)$",
|
||||
QRegularExpression::MultilineOption).match(text);
|
||||
auto parentIdMatch =
|
||||
QRegularExpression("^parent_id: (.+)$", QRegularExpression::MultilineOption)
|
||||
.match(text);
|
||||
|
||||
// check if we need to create note sub-folders
|
||||
if (parentIdMatch.hasMatch()) {
|
||||
|
@ -374,7 +355,7 @@ int JoplinImportDialog::getImportCount() const { return _importCount; }
|
|||
void JoplinImportDialog::tagNote(const QString& id, const Note& note) {
|
||||
QStringList tagAssignmentData = _tagAssignmentData[id];
|
||||
|
||||
foreach(QString tagId, tagAssignmentData) {
|
||||
foreach (QString tagId, tagAssignmentData) {
|
||||
QString tagName = _tagData[tagId];
|
||||
|
||||
// create a new tag if it doesn't exist
|
||||
|
@ -399,8 +380,7 @@ void JoplinImportDialog::tagNote(const QString& id, const Note& note) {
|
|||
*/
|
||||
void JoplinImportDialog::handleImages(Note& note, const QString& dirPath) {
|
||||
QString noteText = note.getNoteText();
|
||||
auto i = QRegularExpression(R"(!\[([^\]]*)\]\(:\/([\w\d]+)\))")
|
||||
.globalMatch(noteText);
|
||||
auto i = QRegularExpression(R"(!\[([^\]]*)\]\(:\/([\w\d]+)\))").globalMatch(noteText);
|
||||
|
||||
while (i.hasNext()) {
|
||||
QRegularExpressionMatch match = i.next();
|
||||
|
@ -411,8 +391,7 @@ void JoplinImportDialog::handleImages(Note& note, const QString& dirPath) {
|
|||
importImage(note, dirPath, noteText, imageTag, imageId, imageName);
|
||||
}
|
||||
|
||||
i = QRegularExpression(R"(<img src=\":\/([\w\d]+)\"\/>)")
|
||||
.globalMatch(noteText);
|
||||
i = QRegularExpression(R"(<img src=\":\/([\w\d]+)\"\/>)").globalMatch(noteText);
|
||||
|
||||
while (i.hasNext()) {
|
||||
QRegularExpressionMatch match = i.next();
|
||||
|
@ -435,22 +414,22 @@ void JoplinImportDialog::importImage(Note& note, const QString& dirPath, QString
|
|||
// qDebug() << __func__ << " - 'imageData': " << imageData;
|
||||
|
||||
QString fileExtension;
|
||||
auto fileExtensionMatch = QRegularExpression("^file_extension: (.+)$",
|
||||
QRegularExpression::MultilineOption).match(imageData);
|
||||
auto fileExtensionMatch =
|
||||
QRegularExpression("^file_extension: (.+)$", QRegularExpression::MultilineOption)
|
||||
.match(imageData);
|
||||
|
||||
if (fileExtensionMatch.hasMatch()) {
|
||||
fileExtension = fileExtensionMatch.captured(1);
|
||||
} else {
|
||||
// if the extension wasn't set we'll try to get it from the original file
|
||||
auto imageDataLines = imageData.split(QRegularExpression(
|
||||
QStringLiteral(R"((\r\n)|(\n\r)|\r|\n)")));
|
||||
auto imageDataLines =
|
||||
imageData.split(QRegularExpression(QStringLiteral(R"((\r\n)|(\n\r)|\r|\n)")));
|
||||
auto originalFileName = imageDataLines[0];
|
||||
auto fileInfo = QFileInfo(originalFileName);
|
||||
fileExtension = fileInfo.suffix();
|
||||
}
|
||||
|
||||
auto *mediaFile = new QFile(dirPath + "/resources/" + imageId +
|
||||
"." + fileExtension);
|
||||
auto* mediaFile = new QFile(dirPath + "/resources/" + imageId + "." + fileExtension);
|
||||
|
||||
qDebug() << __func__ << " - 'mediaFile': " << mediaFile;
|
||||
|
||||
|
@ -458,8 +437,7 @@ void JoplinImportDialog::importImage(Note& note, const QString& dirPath, QString
|
|||
return;
|
||||
}
|
||||
|
||||
QString mediaMarkdown = note.getInsertMediaMarkdown(
|
||||
mediaFile, false, false, imageName);
|
||||
QString mediaMarkdown = note.getInsertMediaMarkdown(mediaFile, false, false, imageName);
|
||||
|
||||
qDebug() << __func__ << " - 'mediaMarkdown': " << mediaMarkdown;
|
||||
noteText.replace(imageTag, mediaMarkdown);
|
||||
|
@ -473,8 +451,7 @@ void JoplinImportDialog::importImage(Note& note, const QString& dirPath, QString
|
|||
*/
|
||||
void JoplinImportDialog::handleAttachments(Note& note, const QString& dirPath) {
|
||||
QString noteText = note.getNoteText();
|
||||
auto i = QRegularExpression(R"([^!](\[([^\]]*)\]\(:\/([\w\d]+)\)))")
|
||||
.globalMatch(noteText);
|
||||
auto i = QRegularExpression(R"([^!](\[([^\]]*)\]\(:\/([\w\d]+)\)))").globalMatch(noteText);
|
||||
|
||||
while (i.hasNext()) {
|
||||
QRegularExpressionMatch match = i.next();
|
||||
|
@ -487,22 +464,22 @@ void JoplinImportDialog::handleAttachments(Note& note, const QString& dirPath) {
|
|||
qDebug() << __func__ << " - 'attachmentId': " << attachmentId;
|
||||
|
||||
QString fileExtension;
|
||||
auto fileExtensionMatch = QRegularExpression("^file_extension: (.+)$",
|
||||
QRegularExpression::MultilineOption).match(attachmentData);
|
||||
auto fileExtensionMatch =
|
||||
QRegularExpression("^file_extension: (.+)$", QRegularExpression::MultilineOption)
|
||||
.match(attachmentData);
|
||||
|
||||
if (fileExtensionMatch.hasMatch()) {
|
||||
fileExtension = fileExtensionMatch.captured(1);
|
||||
} else {
|
||||
// if the extension wasn't set we'll try to get it from the original file
|
||||
auto attachmentDataLines = attachmentData.split(QRegularExpression(
|
||||
QStringLiteral(R"((\r\n)|(\n\r)|\r|\n)")));
|
||||
auto attachmentDataLines =
|
||||
attachmentData.split(QRegularExpression(QStringLiteral(R"((\r\n)|(\n\r)|\r|\n)")));
|
||||
auto originalFileName = attachmentDataLines[0];
|
||||
auto fileInfo = QFileInfo(originalFileName);
|
||||
fileExtension = fileInfo.suffix();
|
||||
}
|
||||
|
||||
auto *mediaFile = new QFile(dirPath + "/resources/" + attachmentId +
|
||||
"." + fileExtension);
|
||||
auto* mediaFile = new QFile(dirPath + "/resources/" + attachmentId + "." + fileExtension);
|
||||
|
||||
qDebug() << __func__ << " - 'mediaFile': " << mediaFile;
|
||||
|
||||
|
@ -510,8 +487,7 @@ void JoplinImportDialog::handleAttachments(Note& note, const QString& dirPath) {
|
|||
continue;
|
||||
}
|
||||
|
||||
QString mediaMarkdown = note.getInsertAttachmentMarkdown(
|
||||
mediaFile, attachmentName);
|
||||
QString mediaMarkdown = note.getInsertAttachmentMarkdown(mediaFile, attachmentName);
|
||||
|
||||
qDebug() << __func__ << " - 'mediaMarkdown': " << mediaMarkdown;
|
||||
noteText.replace(attachmentTag, mediaMarkdown);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "masterdialog.h"
|
||||
|
||||
#include <entities/notesubfolder.h>
|
||||
|
||||
#include "masterdialog.h"
|
||||
|
||||
namespace Ui {
|
||||
class JoplinImportDialog;
|
||||
}
|
||||
|
@ -22,35 +22,33 @@ class JoplinImportDialog : public MasterDialog {
|
|||
};
|
||||
|
||||
public:
|
||||
explicit JoplinImportDialog(QWidget *parent = 0);
|
||||
explicit JoplinImportDialog(QWidget* parent = 0);
|
||||
~JoplinImportDialog() override;
|
||||
|
||||
int getImportCount() const;
|
||||
private slots:
|
||||
private slots:
|
||||
void on_directoryButton_clicked();
|
||||
|
||||
void on_importButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::JoplinImportDialog *ui;
|
||||
Ui::JoplinImportDialog* ui;
|
||||
int _importCount;
|
||||
QString _dirPath;
|
||||
QHash <QString, QString> _noteData;
|
||||
QHash <QString, QString> _folderData;
|
||||
QHash <QString, QString> _tagData;
|
||||
QHash <QString, QStringList> _tagAssignmentData;
|
||||
QHash <QString, QString> _imageData;
|
||||
QHash <QString, QString> _attachmentData;
|
||||
QHash <QString, NoteSubFolder> _importedFolders;
|
||||
QHash<QString, QString> _noteData;
|
||||
QHash<QString, QString> _folderData;
|
||||
QHash<QString, QString> _tagData;
|
||||
QHash<QString, QStringList> _tagAssignmentData;
|
||||
QHash<QString, QString> _imageData;
|
||||
QHash<QString, QString> _attachmentData;
|
||||
QHash<QString, NoteSubFolder> _importedFolders;
|
||||
|
||||
bool importNote(const QString& id, const QString& text,
|
||||
const QString& dirPath);
|
||||
bool importNote(const QString& id, const QString& text, const QString& dirPath);
|
||||
void tagNote(const QString& id, const Note& note);
|
||||
void handleImages(Note& note, const QString& dirPath);
|
||||
void handleAttachments(Note& note, const QString& dirPath);
|
||||
bool importFolders();
|
||||
NoteSubFolder importFolder(const QString &id, const QString &text);
|
||||
void importImage(Note ¬e, const QString &dirPath, QString& noteText,
|
||||
const QString &imageTag, const QString &imageId,
|
||||
const QString &imageName = "");
|
||||
NoteSubFolder importFolder(const QString& id, const QString& text);
|
||||
void importImage(Note& note, const QString& dirPath, QString& noteText, const QString& imageTag,
|
||||
const QString& imageId, const QString& imageName = "");
|
||||
};
|
||||
|
|
|
@ -24,7 +24,8 @@ LinkDialog::LinkDialog(int page, const QString &dialogTitle, QWidget *parent)
|
|||
on_tabWidget_currentChanged(page);
|
||||
|
||||
// disallow ] characters, because they will break markdown links
|
||||
ui->nameLineEdit->setValidator(new QRegularExpressionValidator(QRegularExpression(R"([^\]]*)")));
|
||||
ui->nameLineEdit->setValidator(
|
||||
new QRegularExpressionValidator(QRegularExpression(R"([^\]]*)")));
|
||||
firstVisibleNoteListRow = 0;
|
||||
|
||||
if (!dialogTitle.isEmpty()) {
|
||||
|
@ -86,9 +87,8 @@ void LinkDialog::on_searchLineEdit_textChanged(const QString &arg1) {
|
|||
}
|
||||
|
||||
QString LinkDialog::getSelectedNoteName() const {
|
||||
return ui->notesListWidget->currentRow() > -1
|
||||
? ui->notesListWidget->currentItem()->text()
|
||||
: QString();
|
||||
return ui->notesListWidget->currentRow() > -1 ? ui->notesListWidget->currentItem()->text()
|
||||
: QString();
|
||||
}
|
||||
|
||||
Note LinkDialog::getSelectedNote() const {
|
||||
|
@ -96,15 +96,15 @@ Note LinkDialog::getSelectedNote() const {
|
|||
return {};
|
||||
}
|
||||
|
||||
const int noteId =
|
||||
ui->notesListWidget->currentItem()->data(Qt::UserRole).toInt();
|
||||
const int noteId = ui->notesListWidget->currentItem()->data(Qt::UserRole).toInt();
|
||||
|
||||
return Note::fetch(noteId);
|
||||
}
|
||||
|
||||
QString LinkDialog::getSelectedHeading() const {
|
||||
return ui->headingListWidget->selectedItems().isEmpty() ?
|
||||
"" : ui->headingListWidget->currentItem()->text();
|
||||
return ui->headingListWidget->selectedItems().isEmpty()
|
||||
? ""
|
||||
: ui->headingListWidget->currentItem()->text();
|
||||
}
|
||||
|
||||
QString LinkDialog::getURL() const {
|
||||
|
@ -117,17 +117,11 @@ QString LinkDialog::getURL() const {
|
|||
return url;
|
||||
}
|
||||
|
||||
QString LinkDialog::getLinkName() const {
|
||||
return ui->nameLineEdit->text().trimmed();
|
||||
}
|
||||
QString LinkDialog::getLinkName() const { return ui->nameLineEdit->text().trimmed(); }
|
||||
|
||||
void LinkDialog::setLinkName(const QString &text) {
|
||||
ui->nameLineEdit->setText(text);
|
||||
}
|
||||
void LinkDialog::setLinkName(const QString &text) { ui->nameLineEdit->setText(text); }
|
||||
|
||||
QString LinkDialog::getLinkDescription() const {
|
||||
return ui->descriptionLineEdit->text().trimmed();
|
||||
}
|
||||
QString LinkDialog::getLinkDescription() const { return ui->descriptionLineEdit->text().trimmed(); }
|
||||
|
||||
//
|
||||
// Event filters on the NoteSearchDialog
|
||||
|
@ -139,15 +133,12 @@ bool LinkDialog::eventFilter(QObject *obj, QEvent *event) {
|
|||
|
||||
// set focus to the notes list if Key_Down or Key_Tab were pressed
|
||||
// in the search line edit
|
||||
if ((keyEvent->key() == Qt::Key_Down) ||
|
||||
(keyEvent->key() == Qt::Key_Tab)) {
|
||||
if ((keyEvent->key() == Qt::Key_Down) || (keyEvent->key() == Qt::Key_Tab)) {
|
||||
// choose another selected item if current item is invisible
|
||||
auto item = ui->notesListWidget->currentItem();
|
||||
if ((item != nullptr) &&
|
||||
ui->notesListWidget->currentItem()->isHidden() &&
|
||||
if ((item != nullptr) && ui->notesListWidget->currentItem()->isHidden() &&
|
||||
(this->firstVisibleNoteListRow >= 0)) {
|
||||
ui->notesListWidget->setCurrentRow(
|
||||
this->firstVisibleNoteListRow);
|
||||
ui->notesListWidget->setCurrentRow(this->firstVisibleNoteListRow);
|
||||
}
|
||||
|
||||
// give the keyboard focus to the notes list widget
|
||||
|
@ -162,8 +153,7 @@ bool LinkDialog::eventFilter(QObject *obj, QEvent *event) {
|
|||
|
||||
// set focus to the notes list if Key_Down or Key_Tab were pressed
|
||||
// in the search line edit
|
||||
if ((keyEvent->key() == Qt::Key_Down) ||
|
||||
(keyEvent->key() == Qt::Key_Tab)) {
|
||||
if ((keyEvent->key() == Qt::Key_Down) || (keyEvent->key() == Qt::Key_Tab)) {
|
||||
// give the keyboard focus to the heading list widget
|
||||
ui->headingListWidget->setFocus();
|
||||
return true;
|
||||
|
@ -176,8 +166,7 @@ bool LinkDialog::eventFilter(QObject *obj, QEvent *event) {
|
|||
|
||||
// set focus to the note text edit if Key_Return or Key_Tab
|
||||
// were pressed in the notes list
|
||||
if ((keyEvent->key() == Qt::Key_Return) ||
|
||||
(keyEvent->key() == Qt::Key_Tab)) {
|
||||
if ((keyEvent->key() == Qt::Key_Return) || (keyEvent->key() == Qt::Key_Tab)) {
|
||||
ui->headingSearchLineEdit->setFocus();
|
||||
|
||||
return true;
|
||||
|
@ -218,11 +207,10 @@ QString LinkDialog::getTitleForUrl(const QUrl &url) {
|
|||
}
|
||||
|
||||
// parse title from webpage
|
||||
QRegularExpression regex(
|
||||
QStringLiteral(R"(<title>(.*)<\/title>)"),
|
||||
QRegularExpression::MultilineOption |
|
||||
QRegularExpression::DotMatchesEverythingOption |
|
||||
QRegularExpression::InvertedGreedinessOption);
|
||||
QRegularExpression regex(QStringLiteral(R"(<title>(.*)<\/title>)"),
|
||||
QRegularExpression::MultilineOption |
|
||||
QRegularExpression::DotMatchesEverythingOption |
|
||||
QRegularExpression::InvertedGreedinessOption);
|
||||
QRegularExpressionMatch match = regex.match(html);
|
||||
QString title = match.captured(1);
|
||||
|
||||
|
@ -249,34 +237,28 @@ QString LinkDialog::getTitleForUrl(const QUrl &url) {
|
|||
void LinkDialog::addFileUrl() {
|
||||
QSettings settings;
|
||||
// load last url
|
||||
QUrl fileUrl =
|
||||
settings.value(QStringLiteral("LinkDialog/lastSelectedFileUrl"))
|
||||
.toUrl();
|
||||
QUrl fileUrl = settings.value(QStringLiteral("LinkDialog/lastSelectedFileUrl")).toUrl();
|
||||
|
||||
if (Utils::Misc::isInPortableMode()) {
|
||||
fileUrl = QUrl(QStringLiteral("file://") +
|
||||
Utils::Misc::prependPortableDataPathIfNeeded(
|
||||
Utils::Misc::removeIfStartsWith(
|
||||
fileUrl.toLocalFile(), QStringLiteral("/"))));
|
||||
Utils::Misc::prependPortableDataPathIfNeeded(Utils::Misc::removeIfStartsWith(
|
||||
fileUrl.toLocalFile(), QStringLiteral("/"))));
|
||||
}
|
||||
|
||||
fileUrl = QFileDialog::getOpenFileUrl(this, tr("Select file to link to"),
|
||||
fileUrl);
|
||||
fileUrl = QFileDialog::getOpenFileUrl(this, tr("Select file to link to"), fileUrl);
|
||||
QString fileUrlString = fileUrl.toString(QUrl::FullyEncoded);
|
||||
|
||||
if (Utils::Misc::isInPortableMode()) {
|
||||
fileUrlString =
|
||||
QStringLiteral("file://") +
|
||||
QUrl(QStringLiteral("../") +
|
||||
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(
|
||||
fileUrl.toLocalFile()))
|
||||
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(fileUrl.toLocalFile()))
|
||||
.toString(QUrl::FullyEncoded);
|
||||
}
|
||||
|
||||
if (!fileUrlString.isEmpty()) {
|
||||
// store url for the next time
|
||||
settings.setValue(QStringLiteral("LinkDialog/lastSelectedFileUrl"),
|
||||
fileUrlString);
|
||||
settings.setValue(QStringLiteral("LinkDialog/lastSelectedFileUrl"), fileUrlString);
|
||||
|
||||
// write the file-url to the url text-edit
|
||||
ui->urlEdit->setText(fileUrlString);
|
||||
|
@ -290,27 +272,24 @@ void LinkDialog::addDirectoryUrl() {
|
|||
QSettings settings;
|
||||
// load last url
|
||||
QUrl directoryUrl =
|
||||
settings.value(QStringLiteral("LinkDialog/lastSelectedDirectoryUrl"))
|
||||
.toUrl();
|
||||
settings.value(QStringLiteral("LinkDialog/lastSelectedDirectoryUrl")).toUrl();
|
||||
|
||||
if (Utils::Misc::isInPortableMode()) {
|
||||
directoryUrl =
|
||||
QUrl(QStringLiteral("file://") +
|
||||
Utils::Misc::prependPortableDataPathIfNeeded(
|
||||
Utils::Misc::removeIfStartsWith(directoryUrl.toLocalFile(),
|
||||
QStringLiteral("/"))));
|
||||
Utils::Misc::prependPortableDataPathIfNeeded(Utils::Misc::removeIfStartsWith(
|
||||
directoryUrl.toLocalFile(), QStringLiteral("/"))));
|
||||
}
|
||||
|
||||
directoryUrl = QFileDialog::getExistingDirectoryUrl(
|
||||
this, tr("Select directory to link to"), directoryUrl);
|
||||
directoryUrl =
|
||||
QFileDialog::getExistingDirectoryUrl(this, tr("Select directory to link to"), directoryUrl);
|
||||
QString directoryUrlString = directoryUrl.toString(QUrl::FullyEncoded);
|
||||
|
||||
if (Utils::Misc::isInPortableMode()) {
|
||||
directoryUrlString =
|
||||
QStringLiteral("file://") +
|
||||
QUrl(QStringLiteral("../") +
|
||||
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(
|
||||
directoryUrl.toLocalFile()))
|
||||
QUrl(QStringLiteral("../") + Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(
|
||||
directoryUrl.toLocalFile()))
|
||||
.toString(QUrl::FullyEncoded);
|
||||
}
|
||||
|
||||
|
@ -332,8 +311,7 @@ void LinkDialog::on_urlEdit_textChanged(const QString &arg1) {
|
|||
}
|
||||
|
||||
// try to get the title of the webpage if no link name was set
|
||||
if (url.scheme().startsWith(QStringLiteral("http")) &&
|
||||
ui->nameLineEdit->text().isEmpty()) {
|
||||
if (url.scheme().startsWith(QStringLiteral("http")) && ui->nameLineEdit->text().isEmpty()) {
|
||||
const QString title = getTitleForUrl(url);
|
||||
|
||||
if (!title.isEmpty()) {
|
||||
|
@ -346,19 +324,16 @@ void LinkDialog::setupFileUrlMenu() {
|
|||
auto *addMenu = new QMenu(this);
|
||||
|
||||
QAction *addFileAction = addMenu->addAction(tr("Select file to link to"));
|
||||
addFileAction->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("document-open"),
|
||||
QIcon(QStringLiteral(
|
||||
":icons/breeze-qownnotes/16x16/document-open.svg"))));
|
||||
addFileAction->setIcon(
|
||||
QIcon::fromTheme(QStringLiteral("document-open"),
|
||||
QIcon(QStringLiteral(":icons/breeze-qownnotes/16x16/document-open.svg"))));
|
||||
connect(addFileAction, SIGNAL(triggered()), this, SLOT(addFileUrl()));
|
||||
|
||||
QAction *addDirectoryAction =
|
||||
addMenu->addAction(tr("Select directory to link to"));
|
||||
addDirectoryAction->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("folder"),
|
||||
QIcon(QStringLiteral(":icons/breeze-qownnotes/16x16/folder.svg"))));
|
||||
connect(addDirectoryAction, SIGNAL(triggered()), this,
|
||||
SLOT(addDirectoryUrl()));
|
||||
QAction *addDirectoryAction = addMenu->addAction(tr("Select directory to link to"));
|
||||
addDirectoryAction->setIcon(
|
||||
QIcon::fromTheme(QStringLiteral("folder"),
|
||||
QIcon(QStringLiteral(":icons/breeze-qownnotes/16x16/folder.svg"))));
|
||||
connect(addDirectoryAction, SIGNAL(triggered()), this, SLOT(addDirectoryUrl()));
|
||||
|
||||
ui->fileUrlButton->setMenu(addMenu);
|
||||
}
|
||||
|
|
|
@ -14,10 +14,7 @@ class LinkDialog : public MasterDialog {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum LinkDialogPages {
|
||||
TextLinkPage,
|
||||
NoteLinkPage
|
||||
};
|
||||
enum LinkDialogPages { TextLinkPage, NoteLinkPage };
|
||||
|
||||
explicit LinkDialog(int page, const QString &dialogTitle = QString(),
|
||||
QWidget *parent = nullptr);
|
||||
|
@ -42,14 +39,13 @@ class LinkDialog : public MasterDialog {
|
|||
|
||||
void on_headingSearchLineEdit_textChanged(const QString &arg1);
|
||||
|
||||
void on_notesListWidget_currentItemChanged(QListWidgetItem *current,
|
||||
QListWidgetItem *previous);
|
||||
void on_notesListWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
|
||||
|
||||
void on_headingListWidget_doubleClicked(const QModelIndex &index);
|
||||
|
||||
void on_tabWidget_currentChanged(int index);
|
||||
|
||||
private:
|
||||
private:
|
||||
Ui::LinkDialog *ui;
|
||||
int firstVisibleNoteListRow;
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
|
|
|
@ -21,8 +21,7 @@ class LocalTrashTreeWidgetItem : public QTreeWidgetItem {
|
|||
|
||||
// allow sorting for the date column
|
||||
if (column == 1) {
|
||||
return data(column, Qt::UserRole).toInt() <
|
||||
other.data(column, Qt::UserRole).toInt();
|
||||
return data(column, Qt::UserRole).toInt() < other.data(column, Qt::UserRole).toInt();
|
||||
}
|
||||
|
||||
return text(column).toLower() < other.text(column).toLower();
|
||||
|
@ -45,18 +44,16 @@ LocalTrashDialog::LocalTrashDialog(QWidget *parent)
|
|||
button->setToolTip(tr("Restore selected notes"));
|
||||
button->setProperty("ActionRole", Restore);
|
||||
button->setDefault(false);
|
||||
button->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("view-restore"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/view-restore.svg")));
|
||||
button->setIcon(QIcon::fromTheme(QStringLiteral("view-restore"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/view-restore.svg")));
|
||||
ui->buttonBox->addButton(button, QDialogButtonBox::ActionRole);
|
||||
|
||||
button = new QPushButton(tr("Remove"), this);
|
||||
button->setToolTip(tr("Remove selected notes"));
|
||||
button->setProperty("ActionRole", Remove);
|
||||
button->setDefault(false);
|
||||
button->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("edit-delete"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/edit-delete.svg")));
|
||||
button->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/edit-delete.svg")));
|
||||
ui->buttonBox->addButton(button, QDialogButtonBox::ActionRole);
|
||||
|
||||
// button = new QPushButton(tr("Cancel"));
|
||||
|
@ -92,19 +89,16 @@ void LocalTrashDialog::loadTrashedNotes() {
|
|||
item->setText(1, trashItem.getCreated().toString());
|
||||
item->setData(0, Qt::UserRole, trashItem.getId());
|
||||
// add timestamp data to allow sorting
|
||||
item->setData(1, Qt::UserRole,
|
||||
trashItem.getCreated().toMSecsSinceEpoch());
|
||||
item->setData(1, Qt::UserRole, trashItem.getCreated().toMSecsSinceEpoch());
|
||||
|
||||
QString toolTipText = tr("File will be restored to: %1")
|
||||
.arg(trashItem.restorationFilePath());
|
||||
QString toolTipText =
|
||||
tr("File will be restored to: %1").arg(trashItem.restorationFilePath());
|
||||
|
||||
// mark missing items if file is missing
|
||||
if (!trashItem.fileExists()) {
|
||||
item->setIcon(
|
||||
0,
|
||||
QIcon::fromTheme(
|
||||
QStringLiteral("edit-delete"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/edit-delete.svg")));
|
||||
0, QIcon::fromTheme(QStringLiteral("edit-delete"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/edit-delete.svg")));
|
||||
toolTipText = tr("File <strong>%1</strong> isn't readable and can't"
|
||||
" be restored!")
|
||||
.arg(trashItem.fullFilePath());
|
||||
|
@ -128,8 +122,7 @@ void LocalTrashDialog::setupMainSplitter() {
|
|||
|
||||
// restore splitter sizes
|
||||
QSettings settings;
|
||||
QByteArray state =
|
||||
settings.value(QStringLiteral("localTrashSplitterSizes")).toByteArray();
|
||||
QByteArray state = settings.value(QStringLiteral("localTrashSplitterSizes")).toByteArray();
|
||||
trashSplitter->restoreState(state);
|
||||
|
||||
ui->gridLayout->layout()->addWidget(trashSplitter);
|
||||
|
@ -139,8 +132,7 @@ void LocalTrashDialog::setupMainSplitter() {
|
|||
void LocalTrashDialog::storeSettings() {
|
||||
// store the splitter sizes
|
||||
QSettings settings;
|
||||
settings.setValue(QStringLiteral("localTrashSplitterSizes"),
|
||||
trashSplitter->saveState());
|
||||
settings.setValue(QStringLiteral("localTrashSplitterSizes"), trashSplitter->saveState());
|
||||
}
|
||||
|
||||
LocalTrashDialog::~LocalTrashDialog() { delete ui; }
|
||||
|
@ -171,8 +163,8 @@ void LocalTrashDialog::dialogButtonClicked(QAbstractButton *button) {
|
|||
* @param current
|
||||
* @param previous
|
||||
*/
|
||||
void LocalTrashDialog::on_trashTreeWidget_currentItemChanged(
|
||||
QTreeWidgetItem *current, QTreeWidgetItem *previous) {
|
||||
void LocalTrashDialog::on_trashTreeWidget_currentItemChanged(QTreeWidgetItem *current,
|
||||
QTreeWidgetItem *previous) {
|
||||
Q_UNUSED(previous);
|
||||
int trashItemId = current->data(0, Qt::UserRole).toInt();
|
||||
TrashItem trashItem = TrashItem::fetch(trashItemId);
|
||||
|
@ -191,17 +183,15 @@ void LocalTrashDialog::restoreSelectedTrashItems() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (Utils::Gui::question(this, tr("Restore selected notes"),
|
||||
tr("Restore <strong>%n</strong> selected note(s)?",
|
||||
"", selectedItemsCount),
|
||||
QStringLiteral("local-trash-restore-notes")) ==
|
||||
QMessageBox::Yes) {
|
||||
if (Utils::Gui::question(
|
||||
this, tr("Restore selected notes"),
|
||||
tr("Restore <strong>%n</strong> selected note(s)?", "", selectedItemsCount),
|
||||
QStringLiteral("local-trash-restore-notes")) == QMessageBox::Yes) {
|
||||
const QSignalBlocker blocker(ui->trashTreeWidget);
|
||||
Q_UNUSED(blocker)
|
||||
|
||||
int restoreCount = 0;
|
||||
Q_FOREACH (QTreeWidgetItem *item,
|
||||
ui->trashTreeWidget->selectedItems()) {
|
||||
Q_FOREACH (QTreeWidgetItem *item, ui->trashTreeWidget->selectedItems()) {
|
||||
int id = item->data(0, Qt::UserRole).toInt();
|
||||
TrashItem trashItem = TrashItem::fetch(id);
|
||||
bool wasRestored = trashItem.restoreFile();
|
||||
|
@ -215,10 +205,9 @@ void LocalTrashDialog::restoreSelectedTrashItems() {
|
|||
}
|
||||
}
|
||||
|
||||
Utils::Gui::information(
|
||||
this, tr("Notes restored"),
|
||||
tr("<strong>%n</strong> note(s) were restored", "", restoreCount),
|
||||
QStringLiteral("local-trash-notes-restored"));
|
||||
Utils::Gui::information(this, tr("Notes restored"),
|
||||
tr("<strong>%n</strong> note(s) were restored", "", restoreCount),
|
||||
QStringLiteral("local-trash-notes-restored"));
|
||||
|
||||
if (restoreCount > 0) {
|
||||
loadTrashedNotes();
|
||||
|
@ -236,17 +225,15 @@ void LocalTrashDialog::removeSelectedTrashItems() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (Utils::Gui::question(this, tr("Remove selected notes"),
|
||||
tr("Remove <strong>%n</strong> selected note(s)?",
|
||||
"", selectedItemsCount),
|
||||
QStringLiteral("local-trash-remove-notes")) ==
|
||||
QMessageBox::Yes) {
|
||||
if (Utils::Gui::question(
|
||||
this, tr("Remove selected notes"),
|
||||
tr("Remove <strong>%n</strong> selected note(s)?", "", selectedItemsCount),
|
||||
QStringLiteral("local-trash-remove-notes")) == QMessageBox::Yes) {
|
||||
const QSignalBlocker blocker(ui->trashTreeWidget);
|
||||
Q_UNUSED(blocker)
|
||||
|
||||
int removeCount = 0;
|
||||
Q_FOREACH (QTreeWidgetItem *item,
|
||||
ui->trashTreeWidget->selectedItems()) {
|
||||
Q_FOREACH (QTreeWidgetItem *item, ui->trashTreeWidget->selectedItems()) {
|
||||
int id = item->data(0, Qt::UserRole).toInt();
|
||||
TrashItem trashItem = TrashItem::fetch(id);
|
||||
bool wasRestored = trashItem.remove(true);
|
||||
|
@ -260,10 +247,9 @@ void LocalTrashDialog::removeSelectedTrashItems() {
|
|||
}
|
||||
}
|
||||
|
||||
Utils::Gui::information(
|
||||
this, tr("Notes removed"),
|
||||
tr("<strong>%n</strong> note(s) were removed", "", removeCount),
|
||||
QStringLiteral("local-trash-notes-removed"));
|
||||
Utils::Gui::information(this, tr("Notes removed"),
|
||||
tr("<strong>%n</strong> note(s) were removed", "", removeCount),
|
||||
QStringLiteral("local-trash-notes-removed"));
|
||||
|
||||
if (removeCount > 0) {
|
||||
loadTrashedNotes();
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "masterdialog.h"
|
||||
#include <QStringList>
|
||||
|
||||
#include "masterdialog.h"
|
||||
|
||||
namespace Ui {
|
||||
class LocalTrashDialog;
|
||||
}
|
||||
|
@ -22,8 +23,7 @@ class LocalTrashDialog : public MasterDialog {
|
|||
private slots:
|
||||
void storeSettings();
|
||||
void dialogButtonClicked(QAbstractButton *button);
|
||||
void on_trashTreeWidget_currentItemChanged(QTreeWidgetItem *current,
|
||||
QTreeWidgetItem *previous);
|
||||
void on_trashTreeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||
void on_searchLineEdit_textChanged(const QString &arg1);
|
||||
|
||||
private:
|
||||
|
|
|
@ -8,9 +8,7 @@
|
|||
|
||||
#include "services/metricsservice.h"
|
||||
|
||||
MasterDialog::MasterDialog(QWidget *parent) : QDialog(parent) {
|
||||
installEventFilter(this);
|
||||
}
|
||||
MasterDialog::MasterDialog(QWidget *parent) : QDialog(parent) { installEventFilter(this); }
|
||||
|
||||
void MasterDialog::closeEvent(QCloseEvent *event) {
|
||||
// storeGeometrySettings();
|
||||
|
@ -46,9 +44,7 @@ bool MasterDialog::eventFilter(QObject *obj, QEvent *event) {
|
|||
*
|
||||
* @return settings key
|
||||
*/
|
||||
const QString MasterDialog::getGeometrySettingKey() const {
|
||||
return objectName() + "/geometry";
|
||||
}
|
||||
const QString MasterDialog::getGeometrySettingKey() const { return objectName() + "/geometry"; }
|
||||
|
||||
void MasterDialog::show() {
|
||||
handleOpenDialog();
|
||||
|
@ -71,15 +67,13 @@ int MasterDialog::exec() {
|
|||
void MasterDialog::handleOpenDialog() {
|
||||
// restore the geometry of the dialog
|
||||
QSettings settings;
|
||||
QByteArray geometryData =
|
||||
settings.value(getGeometrySettingKey()).toByteArray();
|
||||
QByteArray geometryData = settings.value(getGeometrySettingKey()).toByteArray();
|
||||
|
||||
// restore the geometry if there is some data
|
||||
if (geometryData.length() > 0) {
|
||||
restoreGeometry(geometryData);
|
||||
} else {
|
||||
const QRect screenGeometry =
|
||||
QGuiApplication::primaryScreen()->availableGeometry();
|
||||
const QRect screenGeometry = QGuiApplication::primaryScreen()->availableGeometry();
|
||||
|
||||
// maximize the dialog window if it looks like that it doesn't fit on
|
||||
// the current screen
|
||||
|
@ -95,13 +89,11 @@ void MasterDialog::handleOpenDialog() {
|
|||
}
|
||||
}
|
||||
|
||||
void MasterDialog::setIgnoreReturnKey(bool ignore) {
|
||||
_ignoreReturnKey = ignore;
|
||||
}
|
||||
void MasterDialog::setIgnoreReturnKey(bool ignore) { _ignoreReturnKey = ignore; }
|
||||
|
||||
void MasterDialog::keyPressEvent(QKeyEvent *keyEvent) {
|
||||
if (_ignoreReturnKey && (keyEvent->key() == Qt::Key_Enter ||
|
||||
keyEvent->key() == Qt::Key_Return)) {
|
||||
if (_ignoreReturnKey &&
|
||||
(keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,19 +3,17 @@
|
|||
#include <entities/note.h>
|
||||
#include <entities/notefolder.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
#include <QSettings>
|
||||
#include <QDebug>
|
||||
|
||||
#include "ui_notedialog.h"
|
||||
|
||||
NoteDialog::NoteDialog(QWidget *parent)
|
||||
: MasterDialog(parent), ui(new Ui::NoteDialog) {
|
||||
NoteDialog::NoteDialog(QWidget *parent) : MasterDialog(parent), ui(new Ui::NoteDialog) {
|
||||
ui->setupUi(this);
|
||||
ui->textEdit->initSearchFrame(ui->searchFrame);
|
||||
ui->textEdit->setReadOnly(true);
|
||||
ui->tabWidget->setCurrentIndex(
|
||||
QSettings().value("NoteDialog/tabWidgetIndex").toInt());
|
||||
ui->tabWidget->setCurrentIndex(QSettings().value("NoteDialog/tabWidgetIndex").toInt());
|
||||
|
||||
// set the note text view font
|
||||
QFont font;
|
||||
|
@ -41,12 +39,9 @@ void NoteDialog::on_noteTextView_anchorClicked(const QUrl &url) {
|
|||
qDebug() << __func__ << " - 'url': " << url;
|
||||
const QString scheme = url.scheme();
|
||||
|
||||
if ((scheme == QStringLiteral("note") ||
|
||||
scheme == QStringLiteral("noteid") ||
|
||||
scheme == QStringLiteral("task") ||
|
||||
scheme == QStringLiteral("checkbox")) ||
|
||||
(scheme == QStringLiteral("file") &&
|
||||
Note::fileUrlIsNoteInCurrentNoteFolder(url))) {
|
||||
if ((scheme == QStringLiteral("note") || scheme == QStringLiteral("noteid") ||
|
||||
scheme == QStringLiteral("task") || scheme == QStringLiteral("checkbox")) ||
|
||||
(scheme == QStringLiteral("file") && Note::fileUrlIsNoteInCurrentNoteFolder(url))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,12 +17,12 @@ class NoteDialog : public MasterDialog {
|
|||
~NoteDialog();
|
||||
void setNote(Note ¬e);
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void on_noteTextView_anchorClicked(const QUrl &url);
|
||||
|
||||
void on_tabWidget_currentChanged(int index);
|
||||
|
||||
private:
|
||||
private:
|
||||
Ui::NoteDialog *ui;
|
||||
};
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ NoteDiffDialog::NoteDiffDialog(QWidget *parent, const QString &html)
|
|||
_notificationNoneCheckBox = new QCheckBox(this);
|
||||
_notificationNoneCheckBox->setHidden(true);
|
||||
_notificationButtonGroup->addButton(_notificationNoneCheckBox);
|
||||
connect(_notificationButtonGroup, SIGNAL(buttonPressed(QAbstractButton *)),
|
||||
this, SLOT(notificationButtonGroupPressed(QAbstractButton *)));
|
||||
connect(_notificationButtonGroup, SIGNAL(buttonPressed(QAbstractButton *)), this,
|
||||
SLOT(notificationButtonGroupPressed(QAbstractButton *)));
|
||||
|
||||
this->ui->textEdit->setHtml(html);
|
||||
|
||||
|
@ -81,15 +81,13 @@ void NoteDiffDialog::dialogButtonClicked(QAbstractButton *button) {
|
|||
// set the setting to ignore all external changes
|
||||
if (ui->ignoreAllExternalChangesCheckBox->isChecked()) {
|
||||
QSettings settings;
|
||||
settings.setValue(QStringLiteral("ignoreAllExternalModifications"),
|
||||
true);
|
||||
settings.setValue(QStringLiteral("ignoreAllExternalModifications"), true);
|
||||
}
|
||||
|
||||
// set the setting to accept all external changes
|
||||
if (ui->acceptAllExternalChangesCheckBox->isChecked()) {
|
||||
QSettings settings;
|
||||
settings.setValue(QStringLiteral("acceptAllExternalModifications"),
|
||||
true);
|
||||
settings.setValue(QStringLiteral("acceptAllExternalModifications"), true);
|
||||
}
|
||||
|
||||
this->close();
|
||||
|
|
|
@ -23,8 +23,7 @@ class NoteDiffDialog : public MasterDialog {
|
|||
Cancel
|
||||
};
|
||||
|
||||
explicit NoteDiffDialog(QWidget *parent = nullptr,
|
||||
const QString &html = QString());
|
||||
explicit NoteDiffDialog(QWidget *parent = nullptr, const QString &html = QString());
|
||||
~NoteDiffDialog();
|
||||
int resultActionRole();
|
||||
|
||||
|
|
|
@ -4,16 +4,14 @@
|
|||
|
||||
#include "ui_passworddialog.h"
|
||||
|
||||
PasswordDialog::PasswordDialog(QWidget *parent, const QString &labelText,
|
||||
bool doubleEnterPassword)
|
||||
PasswordDialog::PasswordDialog(QWidget *parent, const QString &labelText, bool doubleEnterPassword)
|
||||
: MasterDialog(parent), ui(new Ui::PasswordDialog) {
|
||||
_doubleEnterPassword = doubleEnterPassword;
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->passwordLineEdit2->setVisible(doubleEnterPassword);
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)
|
||||
->setEnabled(!doubleEnterPassword);
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!doubleEnterPassword);
|
||||
ui->errorLabel->setVisible(false);
|
||||
|
||||
if (!labelText.isEmpty()) {
|
||||
|
@ -44,8 +42,7 @@ void PasswordDialog::on_passwordLineEdit2_textChanged(const QString &arg1) {
|
|||
bool PasswordDialog::checkIfPasswordsAreEqual() {
|
||||
bool equal = ui->passwordLineEdit->text() == ui->passwordLineEdit2->text();
|
||||
|
||||
ui->errorLabel->setVisible(!equal &&
|
||||
!ui->passwordLineEdit2->text().isEmpty());
|
||||
ui->errorLabel->setVisible(!equal && !ui->passwordLineEdit2->text().isEmpty());
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(equal);
|
||||
|
||||
return equal;
|
||||
|
|
|
@ -11,8 +11,7 @@ class PasswordDialog : public MasterDialog {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PasswordDialog(QWidget *parent = nullptr,
|
||||
const QString &labelText = QString(),
|
||||
explicit PasswordDialog(QWidget *parent = nullptr, const QString &labelText = QString(),
|
||||
bool doubleEnterPassword = false);
|
||||
~PasswordDialog();
|
||||
QString password();
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
|
||||
#include "ui_scriptrepositorydialog.h"
|
||||
|
||||
ScriptRepositoryDialog::ScriptRepositoryDialog(QWidget *parent,
|
||||
bool checkForUpdates)
|
||||
ScriptRepositoryDialog::ScriptRepositoryDialog(QWidget *parent, bool checkForUpdates)
|
||||
: MasterDialog(parent), ui(new Ui::ScriptRepositoryDialog) {
|
||||
ui->setupUi(this);
|
||||
setupMainSplitter();
|
||||
|
@ -53,8 +52,7 @@ ScriptRepositoryDialog::ScriptRepositoryDialog(QWidget *parent,
|
|||
ui->overviewLabel->setText(tr("All scripts are up-to-date."));
|
||||
searchForUpdates();
|
||||
} else {
|
||||
QObject::connect(ui->scriptTreeWidget->verticalScrollBar(),
|
||||
SIGNAL(valueChanged(int)), this,
|
||||
QObject::connect(ui->scriptTreeWidget->verticalScrollBar(), SIGNAL(valueChanged(int)), this,
|
||||
SLOT(scriptTreeWidgetSliderValueChanged(int)));
|
||||
|
||||
searchScript();
|
||||
|
@ -121,8 +119,7 @@ void ScriptRepositoryDialog::searchScript(int page) {
|
|||
_page = page;
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 9, 0)
|
||||
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute,
|
||||
true);
|
||||
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
#else
|
||||
networkRequest.setAttribute(QNetworkRequest::RedirectPolicyAttribute, true);
|
||||
#endif
|
||||
|
@ -155,16 +152,14 @@ void ScriptRepositoryDialog::searchForUpdates() {
|
|||
QNetworkRequest networkRequest(url);
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 9, 0)
|
||||
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute,
|
||||
true);
|
||||
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
#else
|
||||
networkRequest.setAttribute(QNetworkRequest::RedirectPolicyAttribute, true);
|
||||
#endif
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
||||
// try to ensure the network is accessible
|
||||
_networkManager->setNetworkAccessible(
|
||||
QNetworkAccessManager::Accessible);
|
||||
_networkManager->setNetworkAccessible(QNetworkAccessManager::Accessible);
|
||||
#endif
|
||||
|
||||
_networkManager->get(networkRequest);
|
||||
|
@ -174,9 +169,7 @@ void ScriptRepositoryDialog::searchForUpdates() {
|
|||
/**
|
||||
* Does a script search
|
||||
*/
|
||||
void ScriptRepositoryDialog::on_searchScriptEdit_returnPressed() {
|
||||
searchScript();
|
||||
}
|
||||
void ScriptRepositoryDialog::on_searchScriptEdit_returnPressed() { searchScript(); }
|
||||
|
||||
/**
|
||||
* Handles all the network replies
|
||||
|
@ -228,8 +221,7 @@ void ScriptRepositoryDialog::parseCodeSearchReply(const QByteArray &arr) {
|
|||
qDebug() << __func__ << " - 'path': " << path;
|
||||
|
||||
QRegularExpressionMatch match =
|
||||
QRegularExpression(QStringLiteral("(.+)\\/info\\.json"))
|
||||
.match(path);
|
||||
QRegularExpression(QStringLiteral("(.+)\\/info\\.json")).match(path);
|
||||
|
||||
if (!match.hasMatch()) {
|
||||
continue;
|
||||
|
@ -247,16 +239,14 @@ void ScriptRepositoryDialog::parseCodeSearchReply(const QByteArray &arr) {
|
|||
QNetworkRequest networkRequest(url);
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 9, 0)
|
||||
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute,
|
||||
true);
|
||||
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
#else
|
||||
networkRequest.setAttribute(QNetworkRequest::RedirectPolicyAttribute, true);
|
||||
#endif
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
||||
// try to ensure the network is accessible
|
||||
_networkManager->setNetworkAccessible(
|
||||
QNetworkAccessManager::Accessible);
|
||||
_networkManager->setNetworkAccessible(QNetworkAccessManager::Accessible);
|
||||
#endif
|
||||
|
||||
_networkManager->get(networkRequest);
|
||||
|
@ -299,8 +289,7 @@ void ScriptRepositoryDialog::parseInfoQMLReply(const QByteArray &arr) {
|
|||
QString jsonData = QString(arr);
|
||||
|
||||
// check if script item already exists in tree widget
|
||||
if (Utils::Gui::userDataInTreeWidgetExists(ui->scriptTreeWidget,
|
||||
jsonData)) {
|
||||
if (Utils::Gui::userDataInTreeWidgetExists(ui->scriptTreeWidget, jsonData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -318,8 +307,7 @@ void ScriptRepositoryDialog::parseInfoQMLReply(const QByteArray &arr) {
|
|||
ui->scriptTreeWidget->resizeColumnToContents(0);
|
||||
|
||||
if (_page == 1) {
|
||||
ui->scriptTreeWidget->setCurrentItem(
|
||||
ui->scriptTreeWidget->topLevelItem(0));
|
||||
ui->scriptTreeWidget->setCurrentItem(ui->scriptTreeWidget->topLevelItem(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,9 +323,7 @@ void ScriptRepositoryDialog::setupMainSplitter() {
|
|||
// restore splitter sizes
|
||||
QSettings settings;
|
||||
QByteArray state =
|
||||
settings
|
||||
.value(QStringLiteral("ScriptRepositoryDialog/mainSplitterState"))
|
||||
.toByteArray();
|
||||
settings.value(QStringLiteral("ScriptRepositoryDialog/mainSplitterState")).toByteArray();
|
||||
_mainSplitter->restoreState(state);
|
||||
|
||||
ui->gridLayout->layout()->addWidget(_mainSplitter);
|
||||
|
@ -348,9 +334,8 @@ void ScriptRepositoryDialog::setupMainSplitter() {
|
|||
*/
|
||||
void ScriptRepositoryDialog::storeSettings() {
|
||||
QSettings settings;
|
||||
settings.setValue(
|
||||
QStringLiteral("ScriptRepositoryDialog/mainSplitterState"),
|
||||
_mainSplitter->saveState());
|
||||
settings.setValue(QStringLiteral("ScriptRepositoryDialog/mainSplitterState"),
|
||||
_mainSplitter->saveState());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -359,8 +344,8 @@ void ScriptRepositoryDialog::storeSettings() {
|
|||
* @param current
|
||||
* @param previous
|
||||
*/
|
||||
void ScriptRepositoryDialog::on_scriptTreeWidget_currentItemChanged(
|
||||
QTreeWidgetItem *current, QTreeWidgetItem *previous) {
|
||||
void ScriptRepositoryDialog::on_scriptTreeWidget_currentItemChanged(QTreeWidgetItem *current,
|
||||
QTreeWidgetItem *previous) {
|
||||
Q_UNUSED(current);
|
||||
Q_UNUSED(previous);
|
||||
|
||||
|
@ -387,21 +372,17 @@ void ScriptRepositoryDialog::reloadCurrentScriptInfo() {
|
|||
ui->versionLabel->setText(infoJson.version);
|
||||
ui->minAppVersionLabel->setText(infoJson.minAppVersion);
|
||||
ui->minAppVersionLabel->setHidden(infoJson.minAppVersion.isEmpty());
|
||||
ui->minAppVersionHeadlineLabel->setVisible(
|
||||
ui->minAppVersionLabel->isVisible());
|
||||
ui->minAppVersionHeadlineLabel->setVisible(ui->minAppVersionLabel->isVisible());
|
||||
ui->descriptionLabel->setText(infoJson.description);
|
||||
ui->authorLabel->setText(infoJson.richAuthorText);
|
||||
ui->authorHeadlineLabel->setText(
|
||||
(infoJson.richAuthorList.count() > 1 ? tr("Authors") : tr("Author")) +
|
||||
":");
|
||||
(infoJson.richAuthorList.count() > 1 ? tr("Authors") : tr("Author")) + ":");
|
||||
ui->platformLabel->setText(infoJson.richPlatformText);
|
||||
ui->platformHeadlineLabel->setText((infoJson.platformList.count() > 1
|
||||
? tr("Supported platforms")
|
||||
: tr("Supported platform")) +
|
||||
":");
|
||||
ui->repositoryLinkLabel->setText(
|
||||
"<a href=\"https://github.com/qownnotes/scripts/tree/master/" +
|
||||
infoJson.identifier + "\">" + tr("Open repository") + "</a>");
|
||||
ui->platformHeadlineLabel->setText(
|
||||
(infoJson.platformList.count() > 1 ? tr("Supported platforms") : tr("Supported platform")) +
|
||||
":");
|
||||
ui->repositoryLinkLabel->setText("<a href=\"https://github.com/qownnotes/scripts/tree/master/" +
|
||||
infoJson.identifier + "\">" + tr("Open repository") + "</a>");
|
||||
|
||||
Script script = Script::fetchByIdentifier(infoJson.identifier);
|
||||
if (script.isFetched()) {
|
||||
|
@ -435,8 +416,7 @@ void ScriptRepositoryDialog::reloadCurrentScriptInfo() {
|
|||
* @return
|
||||
*/
|
||||
QJsonObject ScriptRepositoryDialog::getCurrentInfoJsonObject() {
|
||||
QJsonDocument jsonResponse =
|
||||
QJsonDocument::fromJson(getCurrentInfoJsonString().toUtf8());
|
||||
QJsonDocument jsonResponse = QJsonDocument::fromJson(getCurrentInfoJsonString().toUtf8());
|
||||
QJsonObject jsonObject = jsonResponse.object();
|
||||
|
||||
return jsonObject;
|
||||
|
@ -468,8 +448,7 @@ void ScriptRepositoryDialog::on_installButton_clicked() {
|
|||
return;
|
||||
}
|
||||
|
||||
QString identifier =
|
||||
jsonObject.value(QStringLiteral("identifier")).toString();
|
||||
QString identifier = jsonObject.value(QStringLiteral("identifier")).toString();
|
||||
|
||||
if (identifier.isEmpty()) {
|
||||
return;
|
||||
|
@ -481,20 +460,18 @@ void ScriptRepositoryDialog::on_installButton_clicked() {
|
|||
|
||||
// check if platform is supported
|
||||
if (!infoJson.platformSupported &&
|
||||
QMessageBox::information(
|
||||
this, tr("Platform not supported!"),
|
||||
tr("Your platform is not supported by this script!\n"
|
||||
"Do you want to install it anyway?"),
|
||||
tr("Install"), tr("Cancel"), QString(), 0, 1) != 0) {
|
||||
QMessageBox::information(this, tr("Platform not supported!"),
|
||||
tr("Your platform is not supported by this script!\n"
|
||||
"Do you want to install it anyway?"),
|
||||
tr("Install"), tr("Cancel"), QString(), 0, 1) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// check if app version is supported
|
||||
if (!infoJson.appVersionSupported) {
|
||||
QMessageBox::information(
|
||||
this, tr("Update app"),
|
||||
tr("Please don't forget to update your installation of "
|
||||
"QOwnNotes to make this script work!"));
|
||||
QMessageBox::information(this, tr("Update app"),
|
||||
tr("Please don't forget to update your installation of "
|
||||
"QOwnNotes to make this script work!"));
|
||||
}
|
||||
|
||||
ui->installButton->setEnabled(false);
|
||||
|
@ -537,8 +514,7 @@ void ScriptRepositoryDialog::on_installButton_clicked() {
|
|||
QUrl resourceUrl = script.remoteFileUrl(resourceFileName);
|
||||
qDebug() << "Downloading: " << resourceUrl;
|
||||
|
||||
auto *file =
|
||||
new QFile(scriptRepositoryPath + "/" + resourceFileName);
|
||||
auto *file = new QFile(scriptRepositoryPath + "/" + resourceFileName);
|
||||
|
||||
if (!Utils::Misc::downloadUrlToFile(resourceUrl, file)) {
|
||||
filesWereDownloaded = false;
|
||||
|
@ -556,8 +532,7 @@ void ScriptRepositoryDialog::on_installButton_clicked() {
|
|||
|
||||
if (filesWereDownloaded) {
|
||||
script.store();
|
||||
MetricsService::instance()->sendVisitIfEnabled(
|
||||
"script-repository/install/" + identifier);
|
||||
MetricsService::instance()->sendVisitIfEnabled("script-repository/install/" + identifier);
|
||||
reloadCurrentScriptInfo();
|
||||
_lastInstalledScript = script;
|
||||
|
||||
|
@ -574,18 +549,13 @@ void ScriptRepositoryDialog::on_installButton_clicked() {
|
|||
}
|
||||
}
|
||||
|
||||
void ScriptRepositoryDialog::on_searchScriptEdit_textChanged(
|
||||
const QString &arg1) {
|
||||
void ScriptRepositoryDialog::on_searchScriptEdit_textChanged(const QString &arg1) {
|
||||
// list all scripts again if the search bar was cleared
|
||||
if (!_checkForUpdates && arg1.isEmpty()) {
|
||||
searchScript();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptRepositoryDialog::on_loadMoreScriptsButton_clicked() {
|
||||
loadMoreItems();
|
||||
}
|
||||
void ScriptRepositoryDialog::on_loadMoreScriptsButton_clicked() { loadMoreItems(); }
|
||||
|
||||
Script ScriptRepositoryDialog::getLastInstalledScript() {
|
||||
return _lastInstalledScript;
|
||||
}
|
||||
Script ScriptRepositoryDialog::getLastInstalledScript() { return _lastInstalledScript; }
|
||||
|
|
|
@ -17,8 +17,7 @@ class ScriptRepositoryDialog : public MasterDialog {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ScriptRepositoryDialog(QWidget *parent = nullptr,
|
||||
bool checkForUpdates = false);
|
||||
explicit ScriptRepositoryDialog(QWidget *parent = nullptr, bool checkForUpdates = false);
|
||||
~ScriptRepositoryDialog();
|
||||
|
||||
Script getLastInstalledScript();
|
||||
|
|
|
@ -9,8 +9,7 @@
|
|||
#include "services/websocketserverservice.h"
|
||||
#include "ui_serverbookmarksimportdialog.h"
|
||||
|
||||
ServerBookmarksImportDialog::ServerBookmarksImportDialog(
|
||||
const QJSValue &bookmarks, QWidget *parent)
|
||||
ServerBookmarksImportDialog::ServerBookmarksImportDialog(const QJSValue &bookmarks, QWidget *parent)
|
||||
: MasterDialog(parent), ui(new Ui::ServerBookmarksImportDialog) {
|
||||
ui->setupUi(this);
|
||||
ui->infoLabel->clear();
|
||||
|
@ -30,8 +29,7 @@ ServerBookmarksImportDialog::ServerBookmarksImportDialog(
|
|||
while (bookmarksIterator.hasNext()) {
|
||||
bookmarksIterator.next();
|
||||
|
||||
QJSValue property =
|
||||
bookmarksIterator.value().property(QStringLiteral("url"));
|
||||
QJSValue property = bookmarksIterator.value().property(QStringLiteral("url"));
|
||||
|
||||
if (property.isUndefined()) {
|
||||
continue;
|
||||
|
@ -43,28 +41,20 @@ ServerBookmarksImportDialog::ServerBookmarksImportDialog(
|
|||
continue;
|
||||
}
|
||||
|
||||
title = bookmarksIterator.value()
|
||||
.property(QStringLiteral("title"))
|
||||
.toString();
|
||||
title = bookmarksIterator.value().property(QStringLiteral("title")).toString();
|
||||
description = bookmarksIterator.value()
|
||||
.property(QStringLiteral("description"))
|
||||
.toString()
|
||||
.remove(QStringLiteral("#"));
|
||||
tags = bookmarksIterator.value()
|
||||
.property(QStringLiteral("tags"))
|
||||
.toVariant()
|
||||
.toStringList();
|
||||
tags =
|
||||
bookmarksIterator.value().property(QStringLiteral("tags")).toVariant().toStringList();
|
||||
|
||||
Q_FOREACH (QString tag, tags) {
|
||||
description.prepend(
|
||||
"#" + tag.replace(QLatin1String(" "), QLatin1String("-")) +
|
||||
" ");
|
||||
description.prepend("#" + tag.replace(QLatin1String(" "), QLatin1String("-")) + " ");
|
||||
}
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
|
||||
QJsonObject data{{"name", title},
|
||||
{"url", url},
|
||||
{"description", description.trimmed()}};
|
||||
QJsonObject data{{"name", title}, {"url", url}, {"description", description.trimmed()}};
|
||||
#else
|
||||
QJsonObject data;
|
||||
data.insert("name", title);
|
||||
|
@ -85,8 +75,7 @@ ServerBookmarksImportDialog::ServerBookmarksImportDialog(
|
|||
#endif
|
||||
|
||||
ui->progressBar->setMaximum(bookmarksCount);
|
||||
ui->infoLabel->setText(tr("<strong>%n bookmarks</strong> found on server",
|
||||
"", bookmarksCount));
|
||||
ui->infoLabel->setText(tr("<strong>%n bookmarks</strong> found on server", "", bookmarksCount));
|
||||
ui->importButton->setEnabled(bookmarksCount > 0);
|
||||
ui->progressBar->setEnabled(bookmarksCount > 0);
|
||||
}
|
||||
|
@ -94,7 +83,6 @@ ServerBookmarksImportDialog::ServerBookmarksImportDialog(
|
|||
ServerBookmarksImportDialog::~ServerBookmarksImportDialog() { delete ui; }
|
||||
|
||||
void ServerBookmarksImportDialog::on_importButton_clicked() {
|
||||
QJsonArray bookmarkList =
|
||||
WebSocketServerService::createBookmarks(jsonObject);
|
||||
QJsonArray bookmarkList = WebSocketServerService::createBookmarks(jsonObject);
|
||||
ui->progressBar->setValue(bookmarkList.count());
|
||||
}
|
||||
|
|
|
@ -14,8 +14,7 @@ class ServerBookmarksImportDialog : public MasterDialog {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ServerBookmarksImportDialog(const QJSValue &bookmarks,
|
||||
QWidget *parent = 0);
|
||||
explicit ServerBookmarksImportDialog(const QJSValue &bookmarks, QWidget *parent = 0);
|
||||
~ServerBookmarksImportDialog();
|
||||
|
||||
private slots:
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -66,9 +66,8 @@ class SettingsDialog : public MasterDialog {
|
|||
|
||||
~SettingsDialog();
|
||||
|
||||
void connectTestCallback(bool appIsValid, QString appVersion,
|
||||
QString serverVersion, QString notesPathExistsText,
|
||||
QString connectionErrorMessage);
|
||||
void connectTestCallback(bool appIsValid, QString appVersion, QString serverVersion,
|
||||
QString notesPathExistsText, QString connectionErrorMessage);
|
||||
|
||||
void setOKLabelData(int number, const QString &text, OKLabelStatus status);
|
||||
|
||||
|
@ -143,8 +142,8 @@ class SettingsDialog : public MasterDialog {
|
|||
|
||||
void on_noteFolderRemotePathButton_clicked();
|
||||
|
||||
void on_noteFolderRemotePathTreeWidget_currentItemChanged(
|
||||
QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||
void on_noteFolderRemotePathTreeWidget_currentItemChanged(QTreeWidgetItem *current,
|
||||
QTreeWidgetItem *previous);
|
||||
|
||||
void on_useOwnCloudPathButton_clicked();
|
||||
|
||||
|
@ -167,8 +166,7 @@ class SettingsDialog : public MasterDialog {
|
|||
|
||||
void on_removeCustomNoteFileExtensionButton_clicked();
|
||||
|
||||
void on_defaultNoteFileExtensionListWidget_itemChanged(
|
||||
QListWidgetItem *item);
|
||||
void on_defaultNoteFileExtensionListWidget_itemChanged(QListWidgetItem *item);
|
||||
|
||||
void on_darkModeCheckBox_toggled();
|
||||
|
||||
|
@ -319,7 +317,7 @@ class SettingsDialog : public MasterDialog {
|
|||
|
||||
void on_noteTextViewRefreshDebounceTimeResetButton_clicked();
|
||||
|
||||
private:
|
||||
private:
|
||||
Ui::SettingsDialog *ui;
|
||||
QStatusBar *noteFolderRemotePathTreeStatusBar;
|
||||
QFont noteTextEditFont;
|
||||
|
@ -349,11 +347,9 @@ private:
|
|||
|
||||
void outputSettings();
|
||||
|
||||
static void selectListWidgetValue(QListWidget *listWidget,
|
||||
const QString &value);
|
||||
static void selectListWidgetValue(QListWidget *listWidget, const QString &value);
|
||||
|
||||
static bool listWidgetValueExists(QListWidget *listWidget,
|
||||
const QString &value);
|
||||
static bool listWidgetValueExists(QListWidget *listWidget, const QString &value);
|
||||
|
||||
static QString getSelectedListWidgetValue(QListWidget *listWidget);
|
||||
|
||||
|
@ -363,14 +359,12 @@ private:
|
|||
|
||||
void setupNoteFolderPage();
|
||||
|
||||
QTreeWidgetItem *findNoteFolderRemotePathTreeWidgetItem(
|
||||
QTreeWidgetItem *parent, const QString &text);
|
||||
QTreeWidgetItem *findNoteFolderRemotePathTreeWidgetItem(QTreeWidgetItem *parent,
|
||||
const QString &text);
|
||||
|
||||
void addPathToNoteFolderRemotePathTreeWidget(QTreeWidgetItem *parent,
|
||||
const QString &path);
|
||||
void addPathToNoteFolderRemotePathTreeWidget(QTreeWidgetItem *parent, const QString &path);
|
||||
|
||||
QString generatePathFromCurrentNoteFolderRemotePathItem(
|
||||
QTreeWidgetItem *item);
|
||||
QString generatePathFromCurrentNoteFolderRemotePathItem(QTreeWidgetItem *item);
|
||||
|
||||
void setNoteFolderRemotePathTreeWidgetFrameVisibility(bool visi);
|
||||
|
||||
|
@ -426,8 +420,7 @@ private:
|
|||
|
||||
void initCloudConnectionComboBox(int selectedId = -1);
|
||||
|
||||
void handleDarkModeCheckBoxToggled(bool updateCheckBoxes = false,
|
||||
bool updateSchema = false);
|
||||
void handleDarkModeCheckBoxToggled(bool updateCheckBoxes = false, bool updateSchema = false);
|
||||
void resetOKLabelData();
|
||||
};
|
||||
|
||||
|
|
|
@ -36,10 +36,8 @@ void ShareDialog::updateDialog() {
|
|||
ui->linkCheckBox->setChecked(note.isShared());
|
||||
ui->linkUrlLineEdit->setVisible(note.isShared());
|
||||
ui->linkUrlLineEdit->setText(note.getShareUrl());
|
||||
ui->infoLabel1->setText(
|
||||
Utils::Misc::replaceOwnCloudText(ui->infoLabel1->text()));
|
||||
ui->linkCheckBox->setText(
|
||||
Utils::Misc::replaceOwnCloudText(ui->linkCheckBox->text()));
|
||||
ui->infoLabel1->setText(Utils::Misc::replaceOwnCloudText(ui->infoLabel1->text()));
|
||||
ui->linkCheckBox->setText(Utils::Misc::replaceOwnCloudText(ui->linkCheckBox->text()));
|
||||
ui->editCheckBox->setVisible(note.isShared());
|
||||
ui->editCheckBox->setChecked(note.isShareEditAllowed());
|
||||
}
|
||||
|
@ -62,11 +60,10 @@ void ShareDialog::on_linkCheckBox_toggled(bool checked) {
|
|||
|
||||
Utils::Gui::information(
|
||||
this, QString(),
|
||||
Utils::Misc::replaceOwnCloudText(
|
||||
tr("Keep in mind that you still have to sync your "
|
||||
"notes with your server by using the ownCloud "
|
||||
"desktop sync tool to be able to share notes with "
|
||||
"others!")),
|
||||
Utils::Misc::replaceOwnCloudText(tr("Keep in mind that you still have to sync your "
|
||||
"notes with your server by using the ownCloud "
|
||||
"desktop sync tool to be able to share notes with "
|
||||
"others!")),
|
||||
QStringLiteral("share-sync-information"));
|
||||
} else {
|
||||
// remove the share
|
||||
|
|
|
@ -41,8 +41,8 @@ void StoredAttachmentsDialog::refreshAttachmentFiles() {
|
|||
return;
|
||||
}
|
||||
|
||||
QStringList attachmentFiles = attachmentsDir.entryList(
|
||||
QStringList(QStringLiteral("*")), QDir::Files, QDir::Time);
|
||||
QStringList attachmentFiles =
|
||||
attachmentsDir.entryList(QStringList(QStringLiteral("*")), QDir::Files, QDir::Time);
|
||||
attachmentFiles.removeDuplicates();
|
||||
|
||||
QVector<Note> noteList = Note::fetchAll();
|
||||
|
@ -53,42 +53,42 @@ void StoredAttachmentsDialog::refreshAttachmentFiles() {
|
|||
ui->progressBar->show();
|
||||
|
||||
Q_FOREACH (Note note, noteList) {
|
||||
QStringList attachmentsFileList = note.getAttachmentsFileList();
|
||||
// we don't want to keep the whole note text
|
||||
note.setNoteText("");
|
||||
QStringList attachmentsFileList = note.getAttachmentsFileList();
|
||||
// we don't want to keep the whole note text
|
||||
note.setNoteText("");
|
||||
|
||||
Q_FOREACH (const QString &fileName, attachmentsFileList) {
|
||||
// remove all found attachments from the files list if _orphanedAttachmentsOnly is enabled
|
||||
if (_orphanedAttachmentsOnly) {
|
||||
attachmentFiles.removeAll(fileName);
|
||||
}
|
||||
Q_FOREACH (const QString &fileName, attachmentsFileList) {
|
||||
// remove all found attachments from the files list if _orphanedAttachmentsOnly is
|
||||
// enabled
|
||||
if (_orphanedAttachmentsOnly) {
|
||||
attachmentFiles.removeAll(fileName);
|
||||
}
|
||||
|
||||
if (!_fileNoteList[fileName].contains(note)) {
|
||||
_fileNoteList[fileName].append(note);
|
||||
}
|
||||
}
|
||||
|
||||
ui->progressBar->setValue(ui->progressBar->value() + 1);
|
||||
if (!_fileNoteList[fileName].contains(note)) {
|
||||
_fileNoteList[fileName].append(note);
|
||||
}
|
||||
}
|
||||
|
||||
ui->progressBar->setValue(ui->progressBar->value() + 1);
|
||||
}
|
||||
|
||||
ui->progressBar->hide();
|
||||
ui->fileTreeWidget->clear();
|
||||
|
||||
Q_FOREACH (QString fileName, attachmentFiles) {
|
||||
auto *item = new QTreeWidgetItem();
|
||||
item->setText(0, fileName);
|
||||
item->setData(0, Qt::UserRole, fileName);
|
||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||
auto *item = new QTreeWidgetItem();
|
||||
item->setText(0, fileName);
|
||||
item->setData(0, Qt::UserRole, fileName);
|
||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||
|
||||
QString filePath = getFilePath(item);
|
||||
QFileInfo info(filePath);
|
||||
item->setToolTip(
|
||||
0, tr("Last modified at %1").arg(info.lastModified().toString()) +
|
||||
QStringLiteral("\n") +
|
||||
Utils::Misc::toHumanReadableByteSize(info.size()));
|
||||
QString filePath = getFilePath(item);
|
||||
QFileInfo info(filePath);
|
||||
item->setToolTip(0, tr("Last modified at %1").arg(info.lastModified().toString()) +
|
||||
QStringLiteral("\n") +
|
||||
Utils::Misc::toHumanReadableByteSize(info.size()));
|
||||
|
||||
ui->fileTreeWidget->addTopLevelItem(item);
|
||||
}
|
||||
ui->fileTreeWidget->addTopLevelItem(item);
|
||||
}
|
||||
|
||||
// Re-apply search text
|
||||
on_searchLineEdit_textChanged(ui->searchLineEdit->text());
|
||||
|
@ -97,8 +97,7 @@ void StoredAttachmentsDialog::refreshAttachmentFiles() {
|
|||
|
||||
// jump to the first item
|
||||
if (attachmentFiles.count() > 0) {
|
||||
auto *event =
|
||||
new QKeyEvent(QEvent::KeyPress, Qt::Key_Home, Qt::NoModifier);
|
||||
auto *event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Home, Qt::NoModifier);
|
||||
QApplication::postEvent(ui->fileTreeWidget, event);
|
||||
}
|
||||
}
|
||||
|
@ -109,8 +108,8 @@ void StoredAttachmentsDialog::refreshAttachmentFiles() {
|
|||
* @param current
|
||||
* @param previous
|
||||
*/
|
||||
void StoredAttachmentsDialog::on_fileTreeWidget_currentItemChanged(
|
||||
QTreeWidgetItem *current, QTreeWidgetItem *previous) {
|
||||
void StoredAttachmentsDialog::on_fileTreeWidget_currentItemChanged(QTreeWidgetItem *current,
|
||||
QTreeWidgetItem *previous) {
|
||||
Q_UNUSED(current);
|
||||
Q_UNUSED(previous);
|
||||
loadCurrentFileDetails();
|
||||
|
@ -137,8 +136,7 @@ void StoredAttachmentsDialog::loadCurrentFileDetails() {
|
|||
ui->typeLabel->setText(type.comment());
|
||||
|
||||
QFileInfo fileInfo(filePath);
|
||||
QString fileSizeText =
|
||||
Utils::Misc::toHumanReadableByteSize(fileInfo.size());
|
||||
QString fileSizeText = Utils::Misc::toHumanReadableByteSize(fileInfo.size());
|
||||
ui->sizeLabel->setText(fileSizeText);
|
||||
|
||||
ui->infoFrame->setEnabled(true);
|
||||
|
@ -149,21 +147,20 @@ void StoredAttachmentsDialog::loadCurrentFileDetails() {
|
|||
auto notes = _fileNoteList[fileName];
|
||||
ui->noteTreeWidget->clear();
|
||||
|
||||
Q_FOREACH(Note note, notes) {
|
||||
auto *item = new QTreeWidgetItem();
|
||||
item->setText(0, note.getName());
|
||||
item->setData(0, Qt::UserRole, note.getId());
|
||||
Utils::Gui::setTreeWidgetItemToolTipForNote(item, note);
|
||||
Q_FOREACH (Note note, notes) {
|
||||
auto *item = new QTreeWidgetItem();
|
||||
item->setText(0, note.getName());
|
||||
item->setData(0, Qt::UserRole, note.getId());
|
||||
Utils::Gui::setTreeWidgetItemToolTipForNote(item, note);
|
||||
|
||||
NoteSubFolder noteSubFolder = note.getNoteSubFolder();
|
||||
if (noteSubFolder.isFetched()) {
|
||||
item->setToolTip(0, tr("Path: %1").arg(
|
||||
noteSubFolder.relativePath()));
|
||||
}
|
||||
|
||||
ui->noteTreeWidget->addTopLevelItem(item);
|
||||
NoteSubFolder noteSubFolder = note.getNoteSubFolder();
|
||||
if (noteSubFolder.isFetched()) {
|
||||
item->setToolTip(0, tr("Path: %1").arg(noteSubFolder.relativePath()));
|
||||
}
|
||||
|
||||
ui->noteTreeWidget->addTopLevelItem(item);
|
||||
}
|
||||
|
||||
ui->notesFrame->show();
|
||||
} else {
|
||||
ui->notesFrame->hide();
|
||||
|
@ -181,8 +178,7 @@ QString StoredAttachmentsDialog::getFilePath(QTreeWidgetItem *item) {
|
|||
return QString();
|
||||
}
|
||||
|
||||
QString fileName = NoteFolder::currentAttachmentsPath() +
|
||||
QDir::separator() +
|
||||
QString fileName = NoteFolder::currentAttachmentsPath() + QDir::separator() +
|
||||
item->data(0, Qt::UserRole).toString();
|
||||
return fileName;
|
||||
}
|
||||
|
@ -197,11 +193,10 @@ void StoredAttachmentsDialog::on_deleteButton_clicked() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (Utils::Gui::question(this, tr("Delete selected files"),
|
||||
tr("Delete <strong>%n</strong> selected file(s)?",
|
||||
"", selectedItemsCount),
|
||||
QStringLiteral("delete-attachment-files")) !=
|
||||
QMessageBox::Yes) {
|
||||
if (Utils::Gui::question(
|
||||
this, tr("Delete selected files"),
|
||||
tr("Delete <strong>%n</strong> selected file(s)?", "", selectedItemsCount),
|
||||
QStringLiteral("delete-attachment-files")) != QMessageBox::Yes) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -229,8 +224,7 @@ bool StoredAttachmentsDialog::eventFilter(QObject *obj, QEvent *event) {
|
|||
|
||||
if (obj == ui->fileTreeWidget) {
|
||||
// delete the currently selected attachments
|
||||
if ((keyEvent->key() == Qt::Key_Delete) ||
|
||||
(keyEvent->key() == Qt::Key_Backspace)) {
|
||||
if ((keyEvent->key() == Qt::Key_Delete) || (keyEvent->key() == Qt::Key_Backspace)) {
|
||||
on_deleteButton_clicked();
|
||||
return true;
|
||||
}
|
||||
|
@ -260,10 +254,8 @@ void StoredAttachmentsDialog::on_insertButton_clicked() {
|
|||
Q_FOREACH (QTreeWidgetItem *item, ui->fileTreeWidget->selectedItems()) {
|
||||
QString filePath = getFilePath(item);
|
||||
QFileInfo fileInfo(filePath);
|
||||
QString attachmentsUrlString =
|
||||
note.attachmentUrlStringForFileName(fileInfo.fileName());
|
||||
QString attachmentLink =
|
||||
"[" + fileInfo.baseName() + "](" + attachmentsUrlString + ")\n";
|
||||
QString attachmentsUrlString = note.attachmentUrlStringForFileName(fileInfo.fileName());
|
||||
QString attachmentLink = "[" + fileInfo.baseName() + "](" + attachmentsUrlString + ")\n";
|
||||
textEdit->insertPlainText(attachmentLink);
|
||||
}
|
||||
|
||||
|
@ -292,8 +284,7 @@ void StoredAttachmentsDialog::on_openFolderButton_clicked() {
|
|||
Utils::Misc::openFolderSelect(filePath);
|
||||
}
|
||||
|
||||
void StoredAttachmentsDialog::on_fileTreeWidget_customContextMenuRequested(
|
||||
const QPoint &pos) {
|
||||
void StoredAttachmentsDialog::on_fileTreeWidget_customContextMenuRequested(const QPoint &pos) {
|
||||
// don't open the most of the context menu if no tags are selected
|
||||
const bool hasSelected = ui->fileTreeWidget->selectedItems().count() > 0;
|
||||
|
||||
|
@ -336,25 +327,22 @@ void StoredAttachmentsDialog::refreshAndJumpToFileName(const QString &fileName)
|
|||
refreshAttachmentFiles();
|
||||
|
||||
// look for the item to jump back to
|
||||
auto item = Utils::Gui::getTreeWidgetItemWithUserData(
|
||||
ui->fileTreeWidget, fileName);
|
||||
auto item = Utils::Gui::getTreeWidgetItemWithUserData(ui->fileTreeWidget, fileName);
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
|
||||
// set the previous item with a timer (didn't work without timer)
|
||||
QTimer::singleShot(0, this, [this, item] () {
|
||||
ui->fileTreeWidget->setCurrentItem(item);
|
||||
});
|
||||
QTimer::singleShot(0, this, [this, item]() { ui->fileTreeWidget->setCurrentItem(item); });
|
||||
#endif
|
||||
}
|
||||
|
||||
void StoredAttachmentsDialog::on_searchLineEdit_textChanged(const QString &arg1) {
|
||||
Utils::Gui::searchForTextInTreeWidget(ui->fileTreeWidget, arg1,
|
||||
Utils::Gui::TreeWidgetSearchFlags(
|
||||
Utils::Gui::TreeWidgetSearchFlag::EveryWordSearch));
|
||||
Utils::Gui::searchForTextInTreeWidget(
|
||||
ui->fileTreeWidget, arg1,
|
||||
Utils::Gui::TreeWidgetSearchFlags(Utils::Gui::TreeWidgetSearchFlag::EveryWordSearch));
|
||||
}
|
||||
|
||||
void StoredAttachmentsDialog::on_fileTreeWidget_itemDoubleClicked(
|
||||
QTreeWidgetItem *item, int column) {
|
||||
void StoredAttachmentsDialog::on_fileTreeWidget_itemDoubleClicked(QTreeWidgetItem *item,
|
||||
int column) {
|
||||
Q_UNUSED(item)
|
||||
Q_UNUSED(column)
|
||||
on_insertButton_clicked();
|
||||
|
@ -378,8 +366,8 @@ void StoredAttachmentsDialog::openCurrentNote() {
|
|||
mainWindow->openCurrentNoteInTab();
|
||||
}
|
||||
|
||||
void StoredAttachmentsDialog::on_noteTreeWidget_itemDoubleClicked(
|
||||
QTreeWidgetItem *item, int column) {
|
||||
void StoredAttachmentsDialog::on_noteTreeWidget_itemDoubleClicked(QTreeWidgetItem *item,
|
||||
int column) {
|
||||
Q_UNUSED(item)
|
||||
Q_UNUSED(column)
|
||||
openCurrentNote();
|
||||
|
@ -390,12 +378,9 @@ void StoredAttachmentsDialog::on_checkBox_toggled(bool checked) {
|
|||
refreshAttachmentFiles();
|
||||
}
|
||||
|
||||
void StoredAttachmentsDialog::on_refreshButton_clicked() {
|
||||
refreshAttachmentFiles();
|
||||
}
|
||||
void StoredAttachmentsDialog::on_refreshButton_clicked() { refreshAttachmentFiles(); }
|
||||
|
||||
void StoredAttachmentsDialog::on_fileTreeWidget_itemChanged(
|
||||
QTreeWidgetItem *item, int column) {
|
||||
void StoredAttachmentsDialog::on_fileTreeWidget_itemChanged(QTreeWidgetItem *item, int column) {
|
||||
Q_UNUSED(column)
|
||||
|
||||
QString oldFileName = item->data(0, Qt::UserRole).toString();
|
||||
|
@ -405,20 +390,21 @@ void StoredAttachmentsDialog::on_fileTreeWidget_itemChanged(
|
|||
qDebug() << __func__ << " - 'oldFileName': " << oldFileName;
|
||||
qDebug() << __func__ << " - 'newFileName': " << newFileName;
|
||||
|
||||
const QString oldFilePath = NoteFolder::currentAttachmentsPath() +
|
||||
QDir::separator() + oldFileName;
|
||||
const QString oldFilePath =
|
||||
NoteFolder::currentAttachmentsPath() + QDir::separator() + oldFileName;
|
||||
QFile oldFile(oldFilePath);
|
||||
if (!oldFile.exists()) {
|
||||
QMessageBox::warning(this, tr("File doesn't exist"),
|
||||
tr("The file <strong>%1</strong> doesn't exist, "
|
||||
"you cannot rename it!").arg(oldFilePath));
|
||||
"you cannot rename it!")
|
||||
.arg(oldFilePath));
|
||||
item->setText(0, oldFileName);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const QString newFilePath = NoteFolder::currentAttachmentsPath() +
|
||||
QDir::separator() + newFileName;
|
||||
const QString newFilePath =
|
||||
NoteFolder::currentAttachmentsPath() + QDir::separator() + newFileName;
|
||||
QFile newFile(newFilePath);
|
||||
|
||||
if (newFile.exists()) {
|
||||
|
@ -449,11 +435,11 @@ void StoredAttachmentsDialog::on_fileTreeWidget_itemChanged(
|
|||
}
|
||||
|
||||
if (Utils::Gui::questionNoSkipOverride(
|
||||
nullptr, QObject::tr("File name changed"),
|
||||
QObject::tr("%n note(s) are using this attachment. Would you also "
|
||||
"like to rename those attachments in the note(s)?",
|
||||
"", affectedNotesCount),
|
||||
QStringLiteral("note-replace-attachments")) != QMessageBox::Yes) {
|
||||
nullptr, QObject::tr("File name changed"),
|
||||
QObject::tr("%n note(s) are using this attachment. Would you also "
|
||||
"like to rename those attachments in the note(s)?",
|
||||
"", affectedNotesCount),
|
||||
QStringLiteral("note-replace-attachments")) != QMessageBox::Yes) {
|
||||
refreshAndJumpToFileName(newFileName);
|
||||
return;
|
||||
}
|
||||
|
@ -465,8 +451,8 @@ void StoredAttachmentsDialog::on_fileTreeWidget_itemChanged(
|
|||
|
||||
QString text = note.getNoteText();
|
||||
text.replace(QRegularExpression(R"((\[.*?\])\((.*?attachments\/.*?)()" +
|
||||
QRegularExpression::escape(oldFileName) + ")\\)"),
|
||||
"\\1(\\2" + newFileName + ")");
|
||||
QRegularExpression::escape(oldFileName) + ")\\)"),
|
||||
"\\1(\\2" + newFileName + ")");
|
||||
|
||||
note.storeNewText(text);
|
||||
}
|
||||
|
@ -480,8 +466,7 @@ void StoredAttachmentsDialog::on_fileTreeWidget_itemChanged(
|
|||
}
|
||||
}
|
||||
|
||||
void StoredAttachmentsDialog::on_noteTreeWidget_customContextMenuRequested(
|
||||
const QPoint &pos) {
|
||||
void StoredAttachmentsDialog::on_noteTreeWidget_customContextMenuRequested(const QPoint &pos) {
|
||||
// don't open the most of the context menu if no tags are selected
|
||||
const bool hasSelected = ui->noteTreeWidget->selectedItems().count() > 0;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "masterdialog.h"
|
||||
#include "entities/note.h"
|
||||
#include "masterdialog.h"
|
||||
|
||||
class QTreeWidgetItem;
|
||||
class QEvent;
|
||||
|
@ -21,8 +21,7 @@ class StoredAttachmentsDialog : public MasterDialog {
|
|||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
private slots:
|
||||
void on_fileTreeWidget_currentItemChanged(QTreeWidgetItem *current,
|
||||
QTreeWidgetItem *previous);
|
||||
void on_fileTreeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||
|
||||
void on_deleteButton_clicked();
|
||||
|
||||
|
@ -48,7 +47,7 @@ class StoredAttachmentsDialog : public MasterDialog {
|
|||
|
||||
void on_noteTreeWidget_customContextMenuRequested(const QPoint &pos);
|
||||
|
||||
private:
|
||||
private:
|
||||
Ui::StoredAttachmentsDialog *ui;
|
||||
bool _orphanedAttachmentsOnly = false;
|
||||
QHash<QString, QVector<Note>> _fileNoteList;
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QMenu>
|
||||
#include <QFileInfo>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QKeyEvent>
|
||||
#include <QTreeWidgetItem>
|
||||
#include <QMenu>
|
||||
#include <QTimer>
|
||||
#include <QTreeWidgetItem>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
|
||||
#include "ui_storedimagesdialog.h"
|
||||
|
@ -38,8 +38,8 @@ void StoredImagesDialog::refreshMediaFiles() {
|
|||
return;
|
||||
}
|
||||
|
||||
QStringList mediaFiles = mediaDir.entryList(
|
||||
QStringList(QStringLiteral("*")), QDir::Files, QDir::Time);
|
||||
QStringList mediaFiles =
|
||||
mediaDir.entryList(QStringList(QStringLiteral("*")), QDir::Files, QDir::Time);
|
||||
mediaFiles.removeDuplicates();
|
||||
|
||||
QVector<Note> noteList = Note::fetchAll();
|
||||
|
@ -50,42 +50,41 @@ void StoredImagesDialog::refreshMediaFiles() {
|
|||
ui->progressBar->show();
|
||||
|
||||
Q_FOREACH (Note note, noteList) {
|
||||
QStringList mediaFileList = note.getMediaFileList();
|
||||
// we don't want to keep the whole note text
|
||||
note.setNoteText("");
|
||||
QStringList mediaFileList = note.getMediaFileList();
|
||||
// we don't want to keep the whole note text
|
||||
note.setNoteText("");
|
||||
|
||||
Q_FOREACH (QString fileName, mediaFileList) {
|
||||
// remove all found images from the files list if _orphanedImagesOnly is enabled
|
||||
if (_orphanedImagesOnly) {
|
||||
mediaFiles.removeAll(fileName);
|
||||
}
|
||||
Q_FOREACH (QString fileName, mediaFileList) {
|
||||
// remove all found images from the files list if _orphanedImagesOnly is enabled
|
||||
if (_orphanedImagesOnly) {
|
||||
mediaFiles.removeAll(fileName);
|
||||
}
|
||||
|
||||
if (!_fileNoteList[fileName].contains(note)) {
|
||||
_fileNoteList[fileName].append(note);
|
||||
}
|
||||
}
|
||||
|
||||
ui->progressBar->setValue(ui->progressBar->value() + 1);
|
||||
if (!_fileNoteList[fileName].contains(note)) {
|
||||
_fileNoteList[fileName].append(note);
|
||||
}
|
||||
}
|
||||
|
||||
ui->progressBar->setValue(ui->progressBar->value() + 1);
|
||||
}
|
||||
|
||||
ui->progressBar->hide();
|
||||
ui->fileTreeWidget->clear();
|
||||
|
||||
Q_FOREACH (QString fileName, mediaFiles) {
|
||||
auto *item = new QTreeWidgetItem();
|
||||
item->setText(0, fileName);
|
||||
item->setData(0, Qt::UserRole, fileName);
|
||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||
auto *item = new QTreeWidgetItem();
|
||||
item->setText(0, fileName);
|
||||
item->setData(0, Qt::UserRole, fileName);
|
||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||
|
||||
QString filePath = getFilePath(item);
|
||||
QFileInfo info(filePath);
|
||||
item->setToolTip(
|
||||
0, tr("Last modified at %1").arg(info.lastModified().toString()) +
|
||||
QStringLiteral("\n") +
|
||||
Utils::Misc::toHumanReadableByteSize(info.size()));
|
||||
QString filePath = getFilePath(item);
|
||||
QFileInfo info(filePath);
|
||||
item->setToolTip(0, tr("Last modified at %1").arg(info.lastModified().toString()) +
|
||||
QStringLiteral("\n") +
|
||||
Utils::Misc::toHumanReadableByteSize(info.size()));
|
||||
|
||||
ui->fileTreeWidget->addTopLevelItem(item);
|
||||
}
|
||||
ui->fileTreeWidget->addTopLevelItem(item);
|
||||
}
|
||||
|
||||
// Re-apply search text
|
||||
on_searchLineEdit_textChanged(ui->searchLineEdit->text());
|
||||
|
@ -94,8 +93,7 @@ void StoredImagesDialog::refreshMediaFiles() {
|
|||
|
||||
// jump to the first item
|
||||
if (mediaFiles.count() > 0) {
|
||||
auto *event =
|
||||
new QKeyEvent(QEvent::KeyPress, Qt::Key_Home, Qt::NoModifier);
|
||||
auto *event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Home, Qt::NoModifier);
|
||||
QApplication::postEvent(ui->fileTreeWidget, event);
|
||||
}
|
||||
}
|
||||
|
@ -106,8 +104,8 @@ void StoredImagesDialog::refreshMediaFiles() {
|
|||
* @param current
|
||||
* @param previous
|
||||
*/
|
||||
void StoredImagesDialog::on_fileTreeWidget_currentItemChanged(
|
||||
QTreeWidgetItem *current, QTreeWidgetItem *previous) {
|
||||
void StoredImagesDialog::on_fileTreeWidget_currentItemChanged(QTreeWidgetItem *current,
|
||||
QTreeWidgetItem *previous) {
|
||||
Q_UNUSED(current);
|
||||
Q_UNUSED(previous);
|
||||
loadCurrentFileDetails();
|
||||
|
@ -137,21 +135,20 @@ void StoredImagesDialog::loadCurrentFileDetails() {
|
|||
auto notes = _fileNoteList[fileName];
|
||||
ui->noteTreeWidget->clear();
|
||||
|
||||
Q_FOREACH(Note note, notes) {
|
||||
auto *item = new QTreeWidgetItem();
|
||||
item->setText(0, note.getName());
|
||||
item->setData(0, Qt::UserRole, note.getId());
|
||||
Utils::Gui::setTreeWidgetItemToolTipForNote(item, note);
|
||||
Q_FOREACH (Note note, notes) {
|
||||
auto *item = new QTreeWidgetItem();
|
||||
item->setText(0, note.getName());
|
||||
item->setData(0, Qt::UserRole, note.getId());
|
||||
Utils::Gui::setTreeWidgetItemToolTipForNote(item, note);
|
||||
|
||||
NoteSubFolder noteSubFolder = note.getNoteSubFolder();
|
||||
if (noteSubFolder.isFetched()) {
|
||||
item->setToolTip(0, tr("Path: %1").arg(
|
||||
noteSubFolder.relativePath()));
|
||||
}
|
||||
|
||||
ui->noteTreeWidget->addTopLevelItem(item);
|
||||
NoteSubFolder noteSubFolder = note.getNoteSubFolder();
|
||||
if (noteSubFolder.isFetched()) {
|
||||
item->setToolTip(0, tr("Path: %1").arg(noteSubFolder.relativePath()));
|
||||
}
|
||||
|
||||
ui->noteTreeWidget->addTopLevelItem(item);
|
||||
}
|
||||
|
||||
ui->notesFrame->show();
|
||||
} else {
|
||||
ui->notesFrame->hide();
|
||||
|
@ -169,8 +166,8 @@ QString StoredImagesDialog::getFilePath(QTreeWidgetItem *item) {
|
|||
return QString();
|
||||
}
|
||||
|
||||
QString fileName = NoteFolder::currentMediaPath() + QDir::separator() +
|
||||
item->data(0, Qt::UserRole).toString();
|
||||
QString fileName =
|
||||
NoteFolder::currentMediaPath() + QDir::separator() + item->data(0, Qt::UserRole).toString();
|
||||
return fileName;
|
||||
}
|
||||
|
||||
|
@ -184,11 +181,10 @@ void StoredImagesDialog::on_deleteButton_clicked() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (Utils::Gui::question(this, tr("Delete selected files"),
|
||||
tr("Delete <strong>%n</strong> selected file(s)?",
|
||||
"", selectedItemsCount),
|
||||
QStringLiteral("delete-image-files")) !=
|
||||
QMessageBox::Yes) {
|
||||
if (Utils::Gui::question(
|
||||
this, tr("Delete selected files"),
|
||||
tr("Delete <strong>%n</strong> selected file(s)?", "", selectedItemsCount),
|
||||
QStringLiteral("delete-image-files")) != QMessageBox::Yes) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -216,8 +212,7 @@ bool StoredImagesDialog::eventFilter(QObject *obj, QEvent *event) {
|
|||
|
||||
if (obj == ui->fileTreeWidget) {
|
||||
// delete the currently selected images
|
||||
if ((keyEvent->key() == Qt::Key_Delete) ||
|
||||
(keyEvent->key() == Qt::Key_Backspace)) {
|
||||
if ((keyEvent->key() == Qt::Key_Delete) || (keyEvent->key() == Qt::Key_Backspace)) {
|
||||
on_deleteButton_clicked();
|
||||
return true;
|
||||
}
|
||||
|
@ -248,10 +243,8 @@ void StoredImagesDialog::on_insertButton_clicked() {
|
|||
Q_FOREACH (QTreeWidgetItem *item, ui->fileTreeWidget->selectedItems()) {
|
||||
QString filePath = getFilePath(item);
|
||||
QFileInfo fileInfo(filePath);
|
||||
QString mediaUrlString =
|
||||
note.mediaUrlStringForFileName(fileInfo.fileName());
|
||||
QString imageLink =
|
||||
"\n";
|
||||
QString mediaUrlString = note.mediaUrlStringForFileName(fileInfo.fileName());
|
||||
QString imageLink = "\n";
|
||||
textEdit->insertPlainText(imageLink);
|
||||
}
|
||||
|
||||
|
@ -264,9 +257,9 @@ void StoredImagesDialog::on_checkBox_toggled(bool checked) {
|
|||
}
|
||||
|
||||
void StoredImagesDialog::on_searchLineEdit_textChanged(const QString &arg1) {
|
||||
Utils::Gui::searchForTextInTreeWidget(ui->fileTreeWidget, arg1,
|
||||
Utils::Gui::TreeWidgetSearchFlags(
|
||||
Utils::Gui::TreeWidgetSearchFlag::EveryWordSearch));
|
||||
Utils::Gui::searchForTextInTreeWidget(
|
||||
ui->fileTreeWidget, arg1,
|
||||
Utils::Gui::TreeWidgetSearchFlags(Utils::Gui::TreeWidgetSearchFlag::EveryWordSearch));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -275,8 +268,7 @@ void StoredImagesDialog::on_searchLineEdit_textChanged(const QString &arg1) {
|
|||
* @param item
|
||||
* @param column
|
||||
*/
|
||||
void StoredImagesDialog::on_fileTreeWidget_itemDoubleClicked(
|
||||
QTreeWidgetItem *item, int column) {
|
||||
void StoredImagesDialog::on_fileTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column) {
|
||||
Q_UNUSED(item)
|
||||
Q_UNUSED(column)
|
||||
on_insertButton_clicked();
|
||||
|
@ -306,19 +298,15 @@ void StoredImagesDialog::openCurrentNote() {
|
|||
* @param item
|
||||
* @param column
|
||||
*/
|
||||
void StoredImagesDialog::on_noteTreeWidget_itemDoubleClicked(
|
||||
QTreeWidgetItem *item, int column) {
|
||||
void StoredImagesDialog::on_noteTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column) {
|
||||
Q_UNUSED(item)
|
||||
Q_UNUSED(column)
|
||||
openCurrentNote();
|
||||
}
|
||||
|
||||
void StoredImagesDialog::on_refreshButton_clicked() {
|
||||
refreshMediaFiles();
|
||||
}
|
||||
void StoredImagesDialog::on_refreshButton_clicked() { refreshMediaFiles(); }
|
||||
|
||||
void StoredImagesDialog::on_fileTreeWidget_itemChanged(
|
||||
QTreeWidgetItem *item, int column) {
|
||||
void StoredImagesDialog::on_fileTreeWidget_itemChanged(QTreeWidgetItem *item, int column) {
|
||||
Q_UNUSED(column)
|
||||
|
||||
QString oldFileName = item->data(0, Qt::UserRole).toString();
|
||||
|
@ -328,20 +316,19 @@ void StoredImagesDialog::on_fileTreeWidget_itemChanged(
|
|||
qDebug() << __func__ << " - 'oldFileName': " << oldFileName;
|
||||
qDebug() << __func__ << " - 'newFileName': " << newFileName;
|
||||
|
||||
const QString oldFilePath = NoteFolder::currentMediaPath() +
|
||||
QDir::separator() + oldFileName;
|
||||
const QString oldFilePath = NoteFolder::currentMediaPath() + QDir::separator() + oldFileName;
|
||||
QFile oldFile(oldFilePath);
|
||||
if (!oldFile.exists()) {
|
||||
QMessageBox::warning(this, tr("File doesn't exist"),
|
||||
tr("The file <strong>%1</strong> doesn't exist, "
|
||||
"you cannot rename it!").arg(oldFilePath));
|
||||
"you cannot rename it!")
|
||||
.arg(oldFilePath));
|
||||
item->setText(0, oldFileName);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const QString newFilePath = NoteFolder::currentMediaPath() +
|
||||
QDir::separator() + newFileName;
|
||||
const QString newFilePath = NoteFolder::currentMediaPath() + QDir::separator() + newFileName;
|
||||
QFile newFile(newFilePath);
|
||||
|
||||
if (newFile.exists()) {
|
||||
|
@ -372,11 +359,11 @@ void StoredImagesDialog::on_fileTreeWidget_itemChanged(
|
|||
}
|
||||
|
||||
if (Utils::Gui::questionNoSkipOverride(
|
||||
nullptr, QObject::tr("File name changed"),
|
||||
QObject::tr("%n note(s) are using this image. Would you also "
|
||||
"like to rename those images in the note(s)?",
|
||||
"", affectedNotesCount),
|
||||
QStringLiteral("note-replace-images")) != QMessageBox::Yes) {
|
||||
nullptr, QObject::tr("File name changed"),
|
||||
QObject::tr("%n note(s) are using this image. Would you also "
|
||||
"like to rename those images in the note(s)?",
|
||||
"", affectedNotesCount),
|
||||
QStringLiteral("note-replace-images")) != QMessageBox::Yes) {
|
||||
refreshAndJumpToFileName(newFileName);
|
||||
return;
|
||||
}
|
||||
|
@ -388,8 +375,8 @@ void StoredImagesDialog::on_fileTreeWidget_itemChanged(
|
|||
|
||||
QString text = note.getNoteText();
|
||||
text.replace(QRegularExpression(R"((!\[.*?\])\((.*?media\/.*?)()" +
|
||||
QRegularExpression::escape(oldFileName) + ")\\)"),
|
||||
"\\1(\\2" + newFileName + ")");
|
||||
QRegularExpression::escape(oldFileName) + ")\\)"),
|
||||
"\\1(\\2" + newFileName + ")");
|
||||
|
||||
note.storeNewText(text);
|
||||
}
|
||||
|
@ -408,19 +395,15 @@ void StoredImagesDialog::refreshAndJumpToFileName(const QString &fileName) {
|
|||
refreshMediaFiles();
|
||||
|
||||
// look for the item to jump back to
|
||||
auto item = Utils::Gui::getTreeWidgetItemWithUserData(
|
||||
ui->fileTreeWidget, fileName);
|
||||
auto item = Utils::Gui::getTreeWidgetItemWithUserData(ui->fileTreeWidget, fileName);
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
|
||||
// set the previous item with a timer (didn't work without timer)
|
||||
QTimer::singleShot(0, this, [this, item] () {
|
||||
ui->fileTreeWidget->setCurrentItem(item);
|
||||
});
|
||||
QTimer::singleShot(0, this, [this, item]() { ui->fileTreeWidget->setCurrentItem(item); });
|
||||
#endif
|
||||
}
|
||||
|
||||
void StoredImagesDialog::on_fileTreeWidget_customContextMenuRequested(
|
||||
const QPoint &pos) {
|
||||
void StoredImagesDialog::on_fileTreeWidget_customContextMenuRequested(const QPoint &pos) {
|
||||
// don't open the most of the context menu if no tags are selected
|
||||
const bool hasSelected = ui->fileTreeWidget->selectedItems().count() > 0;
|
||||
|
||||
|
@ -458,8 +441,7 @@ void StoredImagesDialog::on_fileTreeWidget_customContextMenuRequested(
|
|||
}
|
||||
}
|
||||
|
||||
void StoredImagesDialog::on_noteTreeWidget_customContextMenuRequested(
|
||||
const QPoint &pos) {
|
||||
void StoredImagesDialog::on_noteTreeWidget_customContextMenuRequested(const QPoint &pos) {
|
||||
// don't open the most of the context menu if no tags are selected
|
||||
const bool hasSelected = ui->noteTreeWidget->selectedItems().count() > 0;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "masterdialog.h"
|
||||
#include "entities/note.h"
|
||||
#include "masterdialog.h"
|
||||
|
||||
class QTreeWidgetItem;
|
||||
|
||||
|
@ -20,8 +20,7 @@ class StoredImagesDialog : public MasterDialog {
|
|||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void on_fileTreeWidget_currentItemChanged(QTreeWidgetItem *current,
|
||||
QTreeWidgetItem *previous);
|
||||
void on_fileTreeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||
|
||||
void on_deleteButton_clicked();
|
||||
|
||||
|
@ -47,7 +46,7 @@ class StoredImagesDialog : public MasterDialog {
|
|||
|
||||
void on_openFolderButton_clicked();
|
||||
|
||||
private:
|
||||
private:
|
||||
Ui::StoredImagesDialog *ui;
|
||||
bool _orphanedImagesOnly = false;
|
||||
QHash<QString, QVector<Note>> _fileNoteList;
|
||||
|
|
|
@ -2,16 +2,15 @@
|
|||
|
||||
#include <mainwindow.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QClipboard>
|
||||
#include <QDebug>
|
||||
|
||||
#include "filedialog.h"
|
||||
#include "libraries/qtcsv/src/include/reader.h"
|
||||
#include "ui_tabledialog.h"
|
||||
#include "widgets/qownnotesmarkdowntextedit.h"
|
||||
|
||||
TableDialog::TableDialog(QWidget *parent)
|
||||
: MasterDialog(parent), ui(new Ui::TableDialog) {
|
||||
TableDialog::TableDialog(QWidget *parent) : MasterDialog(parent), ui(new Ui::TableDialog) {
|
||||
ui->setupUi(this);
|
||||
|
||||
// ignore the return key so we can better edit text in the table
|
||||
|
@ -40,8 +39,7 @@ void TableDialog::on_createTableWidget_itemSelectionChanged() {
|
|||
*/
|
||||
|
||||
updateMaxItems();
|
||||
const QList<QTableWidgetSelectionRange> &list =
|
||||
ui->createTableWidget->selectedRanges();
|
||||
const QList<QTableWidgetSelectionRange> &list = ui->createTableWidget->selectedRanges();
|
||||
|
||||
if (list.isEmpty()) {
|
||||
return;
|
||||
|
@ -50,8 +48,7 @@ void TableDialog::on_createTableWidget_itemSelectionChanged() {
|
|||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
|
||||
QTableWidgetSelectionRange range = list.constFirst();
|
||||
#else
|
||||
QTableWidgetSelectionRange range =
|
||||
list.first();
|
||||
QTableWidgetSelectionRange range = list.first();
|
||||
#endif
|
||||
|
||||
ui->rowSpinBox->setValue(std::max<int>(_maxRows, range.rowCount()));
|
||||
|
@ -94,8 +91,7 @@ void TableDialog::on_buttonBox_accepted() {
|
|||
* Imports the CSV file
|
||||
*/
|
||||
void TableDialog::importCSV() {
|
||||
QString filePath = _tempFile != nullptr ?
|
||||
_tempFile->fileName() : ui->fileLineEdit->text();
|
||||
QString filePath = _tempFile != nullptr ? _tempFile->fileName() : ui->fileLineEdit->text();
|
||||
|
||||
if (filePath.isEmpty()) {
|
||||
return;
|
||||
|
@ -107,9 +103,8 @@ void TableDialog::importCSV() {
|
|||
separator.replace("\\t", "\t");
|
||||
|
||||
// read data from file
|
||||
QList<QStringList> readData = QtCSV::Reader::readToList(
|
||||
filePath, separator,
|
||||
ui->textDelimiterComboBox->currentText());
|
||||
QList<QStringList> readData =
|
||||
QtCSV::Reader::readToList(filePath, separator, ui->textDelimiterComboBox->currentText());
|
||||
|
||||
// loop through all rows
|
||||
for (int row = 0; row < readData.size(); ++row) {
|
||||
|
@ -144,18 +139,15 @@ void TableDialog::createMarkdownTable() {
|
|||
QString text = QStringLiteral("\n\n");
|
||||
int colWidth = ui->columnWidthSpinBox->value();
|
||||
QString space = QStringLiteral(" ").repeated(colWidth);
|
||||
QString headline =
|
||||
QStringLiteral("-").repeated(ui->separatorColumnWidthSpinBox->value());
|
||||
QString headline = QStringLiteral("-").repeated(ui->separatorColumnWidthSpinBox->value());
|
||||
|
||||
for (int row = 0; row < ui->rowSpinBox->value(); row++) {
|
||||
// add all columns of the row
|
||||
for (int col = 0; col < ui->columnSpinBox->value(); col++) {
|
||||
auto item = ui->createTableWidget->item(row, col);
|
||||
QString itemText = item != nullptr ? item->text() : QString();
|
||||
text +=
|
||||
QStringLiteral("|") +
|
||||
(itemText.isEmpty() ? space
|
||||
: itemText.leftJustified(colWidth, ' '));
|
||||
text += QStringLiteral("|") +
|
||||
(itemText.isEmpty() ? space : itemText.leftJustified(colWidth, ' '));
|
||||
}
|
||||
|
||||
text += QStringLiteral("|\n");
|
||||
|
@ -189,8 +181,7 @@ void TableDialog::on_headlineCheckBox_toggled(bool checked) {
|
|||
*/
|
||||
void TableDialog::on_fileButton_clicked() {
|
||||
ui->csvFileTextEdit->clear();
|
||||
QStringList filters = QStringList() << tr("CSV files") + " (*.csv)"
|
||||
<< tr("All files") + " (*)";
|
||||
QStringList filters = QStringList() << tr("CSV files") + " (*.csv)" << tr("All files") + " (*)";
|
||||
FileDialog dialog(QStringLiteral("CSVTableImport"));
|
||||
dialog.setFileMode(QFileDialog::AnyFile);
|
||||
dialog.setAcceptMode(QFileDialog::AcceptOpen);
|
||||
|
@ -256,7 +247,7 @@ void TableDialog::on_clipboardButton_clicked() {
|
|||
ui->csvFileTextEdit->setPlainText(text);
|
||||
|
||||
_tempFile = new QTemporaryFile(QDir::tempPath() + QDir::separator() +
|
||||
QStringLiteral("table-XXXXXX.csv"));
|
||||
QStringLiteral("table-XXXXXX.csv"));
|
||||
|
||||
if (!_tempFile->open()) {
|
||||
_tempFile = nullptr;
|
||||
|
@ -274,15 +265,13 @@ void TableDialog::on_clipboardButton_clicked() {
|
|||
}
|
||||
}
|
||||
|
||||
void TableDialog::updateSeparator(
|
||||
const QString &text) const {
|
||||
const QStringList list = { "\t", ";", "," };
|
||||
void TableDialog::updateSeparator(const QString &text) const {
|
||||
const QStringList list = {"\t", ";", ","};
|
||||
|
||||
foreach(const QString &character, list) {
|
||||
foreach (const QString &character, list) {
|
||||
if (text.contains(character)) {
|
||||
// set separator if found
|
||||
ui->separatorComboBox->setCurrentText(
|
||||
character == "\t" ? "\\t" : character);
|
||||
ui->separatorComboBox->setCurrentText(character == "\t" ? "\\t" : character);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "masterdialog.h"
|
||||
|
||||
#include <QTemporaryFile>
|
||||
|
||||
#include "masterdialog.h"
|
||||
|
||||
namespace Ui {
|
||||
class TableDialog;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class TableDialog : public MasterDialog {
|
|||
|
||||
void on_clipboardButton_clicked();
|
||||
|
||||
private:
|
||||
private:
|
||||
enum Tab { CreateTab, ImportTab };
|
||||
|
||||
Ui::TableDialog *ui;
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
#include "ui_tagadddialog.h"
|
||||
|
||||
TagAddDialog::TagAddDialog(QWidget *parent)
|
||||
: MasterDialog(parent), ui(new Ui::TagAddDialog) {
|
||||
TagAddDialog::TagAddDialog(QWidget *parent) : MasterDialog(parent), ui(new Ui::TagAddDialog) {
|
||||
ui->setupUi(this);
|
||||
ui->nameLineEdit->setFocus();
|
||||
resize(1, 1);
|
||||
|
|
|
@ -98,40 +98,32 @@ void TodoDialog::setupUi() {
|
|||
ui->newItemEdit->setFocus();
|
||||
|
||||
// adding shortcuts, that weren't working when defined in the ui file
|
||||
auto *shortcut =
|
||||
new QShortcut(QKeySequence(QStringLiteral("Ctrl+S")), this);
|
||||
QObject::connect(shortcut, SIGNAL(activated()), this,
|
||||
SLOT(on_saveButton_clicked()));
|
||||
auto *shortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+S")), this);
|
||||
QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(on_saveButton_clicked()));
|
||||
shortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+I")), this);
|
||||
QObject::connect(shortcut, SIGNAL(activated()), this,
|
||||
SLOT(onSaveAndInsertButtonClicked()));
|
||||
QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(onSaveAndInsertButtonClicked()));
|
||||
shortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+R")), this);
|
||||
QObject::connect(shortcut, SIGNAL(activated()), this,
|
||||
SLOT(on_removeButton_clicked()));
|
||||
QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(on_removeButton_clicked()));
|
||||
|
||||
/*
|
||||
* setup the note button menu
|
||||
*/
|
||||
auto *noteMenu = new QMenu(this);
|
||||
|
||||
QAction *insertAction =
|
||||
noteMenu->addAction(tr("Save and insert into note"));
|
||||
QAction *insertAction = noteMenu->addAction(tr("Save and insert into note"));
|
||||
insertAction->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("document-save"),
|
||||
QIcon(":icons/breeze-qownnotes/16x16/document-save.svg")));
|
||||
QStringLiteral("document-save"), QIcon(":icons/breeze-qownnotes/16x16/document-save.svg")));
|
||||
insertAction->setToolTip(
|
||||
tr("Save the current todo item and insert a link"
|
||||
" to it into the current note"));
|
||||
connect(insertAction, SIGNAL(triggered()), this,
|
||||
SLOT(onSaveAndInsertButtonClicked()));
|
||||
connect(insertAction, SIGNAL(triggered()), this, SLOT(onSaveAndInsertButtonClicked()));
|
||||
|
||||
QAction *importAction = noteMenu->addAction(tr("Import as note"));
|
||||
importAction->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("document-import"),
|
||||
QIcon(":icons/breeze-qownnotes/16x16/document-import.svg")));
|
||||
importAction->setIcon(
|
||||
QIcon::fromTheme(QStringLiteral("document-import"),
|
||||
QIcon(":icons/breeze-qownnotes/16x16/document-import.svg")));
|
||||
importAction->setToolTip(tr("Import the current todo item as new note"));
|
||||
connect(importAction, SIGNAL(triggered()), this,
|
||||
SLOT(onImportAsNoteButtonClicked()));
|
||||
connect(importAction, SIGNAL(triggered()), this, SLOT(onImportAsNoteButtonClicked()));
|
||||
|
||||
ui->noteButton->setMenu(noteMenu);
|
||||
|
||||
|
@ -142,21 +134,17 @@ void TodoDialog::setupUi() {
|
|||
|
||||
QAction *reloadAction = reloadMenu->addAction(tr("Reload from server"));
|
||||
reloadAction->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("view-refresh"),
|
||||
QIcon(":icons/breeze-qownnotes/16x16/view-refresh.svg")));
|
||||
QStringLiteral("view-refresh"), QIcon(":icons/breeze-qownnotes/16x16/view-refresh.svg")));
|
||||
reloadAction->setToolTip(tr("Reload tasks from server"));
|
||||
connect(reloadAction, SIGNAL(triggered()), this, SLOT(reloadTodoList()));
|
||||
|
||||
QAction *clearCacheAction =
|
||||
reloadMenu->addAction(tr("Clear cache and reload"));
|
||||
QAction *clearCacheAction = reloadMenu->addAction(tr("Clear cache and reload"));
|
||||
clearCacheAction->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("trash-empty"),
|
||||
QIcon(":icons/breeze-qownnotes/16x16/trash-empty.svg")));
|
||||
QStringLiteral("trash-empty"), QIcon(":icons/breeze-qownnotes/16x16/trash-empty.svg")));
|
||||
clearCacheAction->setToolTip(
|
||||
tr("Clear calendar cache and reload tasks "
|
||||
"from server"));
|
||||
connect(clearCacheAction, SIGNAL(triggered()), this,
|
||||
SLOT(clearCacheAndReloadTodoList()));
|
||||
connect(clearCacheAction, SIGNAL(triggered()), this, SLOT(clearCacheAndReloadTodoList()));
|
||||
|
||||
ui->reloadTodoListButton->setMenu(reloadMenu);
|
||||
}
|
||||
|
@ -176,13 +164,11 @@ void TodoDialog::refreshUi() {
|
|||
Q_UNUSED(blocker)
|
||||
|
||||
bool showCompletedItems =
|
||||
settings.value(QStringLiteral("TodoDialog/showCompletedItems"))
|
||||
.toBool();
|
||||
settings.value(QStringLiteral("TodoDialog/showCompletedItems")).toBool();
|
||||
ui->showCompletedItemsCheckBox->setChecked(showCompletedItems);
|
||||
|
||||
bool showDueTodayItemsOnly =
|
||||
settings.value(QStringLiteral("TodoDialog/showDueTodayItemsOnly"))
|
||||
.toBool();
|
||||
settings.value(QStringLiteral("TodoDialog/showDueTodayItemsOnly")).toBool();
|
||||
ui->showDueTodayItemsOnlyCheckBox->setChecked(showDueTodayItemsOnly);
|
||||
}
|
||||
|
||||
|
@ -196,9 +182,8 @@ void TodoDialog::refreshUi() {
|
|||
ui->todoListSelector->setCurrentIndex(index);
|
||||
} else {
|
||||
// if we didn't find the index store the new current item
|
||||
settings.setValue(
|
||||
QStringLiteral("TodoDialog/todoListSelectorSelectedItem"),
|
||||
ui->todoListSelector->currentText());
|
||||
settings.setValue(QStringLiteral("TodoDialog/todoListSelectorSelectedItem"),
|
||||
ui->todoListSelector->currentText());
|
||||
}
|
||||
|
||||
// hide the reminder date time select
|
||||
|
@ -216,9 +201,7 @@ void TodoDialog::setupMainSplitter() {
|
|||
|
||||
// restore splitter sizes
|
||||
QSettings settings;
|
||||
QByteArray state =
|
||||
settings.value(QStringLiteral("TodoDialog/mainSplitterState"))
|
||||
.toByteArray();
|
||||
QByteArray state = settings.value(QStringLiteral("TodoDialog/mainSplitterState")).toByteArray();
|
||||
this->mainSplitter->restoreState(state);
|
||||
|
||||
ui->gridLayout->layout()->addWidget(this->mainSplitter);
|
||||
|
@ -234,8 +217,7 @@ void TodoDialog::loadTodoListData() {
|
|||
QSettings settings;
|
||||
ui->todoListSelector->clear();
|
||||
ui->todoListSelector->addItems(
|
||||
settings.value(QStringLiteral("ownCloud/todoCalendarEnabledList"))
|
||||
.toStringList());
|
||||
settings.value(QStringLiteral("ownCloud/todoCalendarEnabledList")).toStringList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -266,8 +248,7 @@ void TodoDialog::reloadTodoListItems() {
|
|||
int itemCount = calendarItemList.count();
|
||||
MetricsService::instance()->sendEventIfEnabled(
|
||||
QStringLiteral("todo/list/loaded"), QStringLiteral("todo"),
|
||||
QStringLiteral("todo list loaded"),
|
||||
QString::number(itemCount) + " todo items", itemCount);
|
||||
QStringLiteral("todo list loaded"), QString::number(itemCount) + " todo items", itemCount);
|
||||
|
||||
{
|
||||
const QSignalBlocker blocker(ui->todoItemTreeWidget);
|
||||
|
@ -313,13 +294,11 @@ void TodoDialog::reloadTodoListItems() {
|
|||
item->setText(0, calItem.getSummary());
|
||||
item->setData(0, Qt::UserRole, uid);
|
||||
item->setData(0, Qt::UserRole + 1, relatedUid);
|
||||
item->setCheckState(
|
||||
0, calItem.isCompleted() ? Qt::Checked : Qt::Unchecked);
|
||||
item->setCheckState(0, calItem.isCompleted() ? Qt::Checked : Qt::Unchecked);
|
||||
item->setText(1, calItem.getAlarmDate().toString());
|
||||
item->setData(1, Qt::DisplayRole, calItem.getAlarmDate());
|
||||
item->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled |
|
||||
Qt::ItemIsEnabled | Qt::ItemIsUserCheckable |
|
||||
Qt::ItemIsSelectable);
|
||||
item->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled |
|
||||
Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
|
||||
|
||||
if (relatedUid.isEmpty()) {
|
||||
ui->todoItemTreeWidget->addTopLevelItem(item);
|
||||
|
@ -345,8 +324,8 @@ void TodoDialog::reloadTodoListItems() {
|
|||
continue;
|
||||
}
|
||||
|
||||
auto parentItem = Utils::Gui::getTreeWidgetItemWithUserData(
|
||||
ui->todoItemTreeWidget, relatedUid);
|
||||
auto parentItem =
|
||||
Utils::Gui::getTreeWidgetItemWithUserData(ui->todoItemTreeWidget, relatedUid);
|
||||
|
||||
if (parentItem != nullptr) {
|
||||
parentItem->addChild(item);
|
||||
|
@ -360,7 +339,6 @@ void TodoDialog::reloadTodoListItems() {
|
|||
ui->todoItemTreeWidget->resizeColumnToContents(0);
|
||||
ui->todoItemTreeWidget->resizeColumnToContents(1);
|
||||
|
||||
|
||||
// set the current row of the task list to the first row
|
||||
jumpToTodoListItem();
|
||||
|
||||
|
@ -392,8 +370,7 @@ void TodoDialog::jumpToTodoListItem() {
|
|||
|
||||
// try to find a possible last created calendar item
|
||||
if ((item == nullptr) && lastCreatedCalendarItem.isFetched()) {
|
||||
item = findTodoItemTreeWidgetItemByUID(
|
||||
lastCreatedCalendarItem.getUid());
|
||||
item = findTodoItemTreeWidgetItemByUID(lastCreatedCalendarItem.getUid());
|
||||
|
||||
// clear the last created calendar item if we found it in the list
|
||||
if (item != nullptr) {
|
||||
|
@ -403,8 +380,7 @@ void TodoDialog::jumpToTodoListItem() {
|
|||
|
||||
if (item == nullptr) {
|
||||
// try to find the currently selected calendar item
|
||||
item =
|
||||
findTodoItemTreeWidgetItemByUID(currentCalendarItem.getUid());
|
||||
item = findTodoItemTreeWidgetItemByUID(currentCalendarItem.getUid());
|
||||
}
|
||||
|
||||
if (item != nullptr) {
|
||||
|
@ -440,10 +416,8 @@ void TodoDialog::resetEditFrameControls() {
|
|||
* @return Returns the tree widget item of the task item in the task tree,
|
||||
* returns null if not found
|
||||
*/
|
||||
QTreeWidgetItem *TodoDialog::findTodoItemTreeWidgetItemByUID(
|
||||
const QString &uid) {
|
||||
return Utils::Gui::getTreeWidgetItemWithUserData(ui->todoItemTreeWidget,
|
||||
uid);
|
||||
QTreeWidgetItem *TodoDialog::findTodoItemTreeWidgetItemByUID(const QString &uid) {
|
||||
return Utils::Gui::getTreeWidgetItemWithUserData(ui->todoItemTreeWidget, uid);
|
||||
}
|
||||
|
||||
void TodoDialog::storeSettings() {
|
||||
|
@ -474,9 +448,8 @@ void TodoDialog::updateCurrentCalendarItemWithFormData() {
|
|||
currentCalendarItem.setSummary(ui->summaryEdit->text());
|
||||
currentCalendarItem.setDescription(ui->descriptionEdit->toPlainText());
|
||||
currentCalendarItem.setModified(QDateTime::currentDateTime());
|
||||
currentCalendarItem.setAlarmDate(ui->reminderCheckBox->isChecked()
|
||||
? ui->reminderDateTimeEdit->dateTime()
|
||||
: QDateTime());
|
||||
currentCalendarItem.setAlarmDate(
|
||||
ui->reminderCheckBox->isChecked() ? ui->reminderDateTimeEdit->dateTime() : QDateTime());
|
||||
currentCalendarItem.store();
|
||||
}
|
||||
|
||||
|
@ -531,8 +504,7 @@ void TodoDialog::on_showCompletedItemsCheckBox_clicked() {
|
|||
}
|
||||
|
||||
void TodoDialog::on_saveButton_clicked() {
|
||||
MetricsService::instance()->sendVisitIfEnabled(
|
||||
QStringLiteral("todo/item/stored"));
|
||||
MetricsService::instance()->sendVisitIfEnabled(QStringLiteral("todo/item/stored"));
|
||||
|
||||
updateCurrentCalendarItemWithFormData();
|
||||
|
||||
|
@ -563,9 +535,7 @@ void TodoDialog::todoItemLoadingProgressBarIncrement() {
|
|||
ui->todoItemLoadingProgressBar->setValue(value);
|
||||
}
|
||||
|
||||
void TodoDialog::todoItemLoadingProgressBarHide() {
|
||||
ui->todoItemLoadingProgressBar->hide();
|
||||
}
|
||||
void TodoDialog::todoItemLoadingProgressBarHide() { ui->todoItemLoadingProgressBar->hide(); }
|
||||
|
||||
void TodoDialog::todoItemLoadingProgressBarSetMaximum(int value) {
|
||||
ui->todoItemLoadingProgressBar->setMaximum(value);
|
||||
|
@ -573,8 +543,7 @@ void TodoDialog::todoItemLoadingProgressBarSetMaximum(int value) {
|
|||
}
|
||||
|
||||
void TodoDialog::todoItemLoadingProgressBarHideIfOnMaximum() {
|
||||
if (ui->todoItemLoadingProgressBar->value() >=
|
||||
ui->todoItemLoadingProgressBar->maximum()) {
|
||||
if (ui->todoItemLoadingProgressBar->value() >= ui->todoItemLoadingProgressBar->maximum()) {
|
||||
ui->todoItemLoadingProgressBar->hide();
|
||||
}
|
||||
}
|
||||
|
@ -585,10 +554,9 @@ void TodoDialog::on_todoItemLoadingProgressBar_valueChanged(int value) {
|
|||
todoItemLoadingProgressBarHideIfOnMaximum();
|
||||
}
|
||||
|
||||
void TodoDialog::createNewTodoItem(const QString &name,
|
||||
const QString &relatedUid) {
|
||||
CalendarItem calItem = CalendarItem::createNewTodoItem(
|
||||
name, ui->todoListSelector->currentText(), relatedUid);
|
||||
void TodoDialog::createNewTodoItem(const QString &name, const QString &relatedUid) {
|
||||
CalendarItem calItem =
|
||||
CalendarItem::createNewTodoItem(name, ui->todoListSelector->currentText(), relatedUid);
|
||||
lastCreatedCalendarItem = calItem;
|
||||
|
||||
// set the focus to the description edit after we loaded the tasks
|
||||
|
@ -615,16 +583,14 @@ void TodoDialog::on_newItemEdit_returnPressed() {
|
|||
* @brief Removes the currently selected task from the ownCloud server
|
||||
*/
|
||||
void TodoDialog::on_removeButton_clicked() {
|
||||
if (Utils::Gui::question(
|
||||
this, tr("Remove todo item"),
|
||||
tr("Remove the selected todo item?\nThis cannot be undone!"),
|
||||
QStringLiteral("remove-todo-items")) == QMessageBox::Yes) {
|
||||
if (Utils::Gui::question(this, tr("Remove todo item"),
|
||||
tr("Remove the selected todo item?\nThis cannot be undone!"),
|
||||
QStringLiteral("remove-todo-items")) == QMessageBox::Yes) {
|
||||
CalendarItem calItem = currentCalendarItem;
|
||||
|
||||
// remove the calendar item from the list widget
|
||||
// (this will update the currentCalendarItem)
|
||||
ui->todoItemTreeWidget->removeItemWidget(
|
||||
ui->todoItemTreeWidget->currentItem(), 0);
|
||||
ui->todoItemTreeWidget->removeItemWidget(ui->todoItemTreeWidget->currentItem(), 0);
|
||||
|
||||
// remove the calendar item from the database
|
||||
calItem.remove();
|
||||
|
@ -676,13 +642,12 @@ void TodoDialog::on_newItemEdit_textChanged() {
|
|||
|
||||
// search todo item if at least 2 characters were entered
|
||||
if (arg1.count() >= 2) {
|
||||
QList<QString> uidList = CalendarItem::searchAsUidList(
|
||||
arg1, ui->todoListSelector->currentText());
|
||||
QList<QString> uidList =
|
||||
CalendarItem::searchAsUidList(arg1, ui->todoListSelector->currentText());
|
||||
|
||||
// hide all not found items
|
||||
Q_FOREACH (QTreeWidgetItem *item, allItems) {
|
||||
bool show =
|
||||
uidList.indexOf(item->data(0, Qt::UserRole).toString()) > -1;
|
||||
bool show = uidList.indexOf(item->data(0, Qt::UserRole).toString()) > -1;
|
||||
item->setHidden(!show);
|
||||
}
|
||||
|
||||
|
@ -696,7 +661,9 @@ void TodoDialog::on_newItemEdit_textChanged() {
|
|||
}
|
||||
} else {
|
||||
// show all items otherwise
|
||||
Q_FOREACH (QTreeWidgetItem *item, allItems) { item->setHidden(false); }
|
||||
Q_FOREACH (QTreeWidgetItem *item, allItems) {
|
||||
item->setHidden(false);
|
||||
}
|
||||
}
|
||||
|
||||
// let's highlight the text from the search line edit
|
||||
|
@ -742,14 +709,12 @@ bool TodoDialog::eventFilter(QObject *obj, QEvent *event) {
|
|||
if (obj == ui->newItemEdit) {
|
||||
// set focus to the task list if Key_Down or Key_Tab
|
||||
// were pressed in the new item edit
|
||||
if ((keyEvent->key() == Qt::Key_Down) ||
|
||||
(keyEvent->key() == Qt::Key_Tab)) {
|
||||
if ((keyEvent->key() == Qt::Key_Down) || (keyEvent->key() == Qt::Key_Tab)) {
|
||||
// choose another selected item if current item is invisible
|
||||
auto *item = ui->todoItemTreeWidget->currentItem();
|
||||
if ((item != nullptr) && item->isHidden() &&
|
||||
(firstVisibleTodoItemTreeItem != nullptr)) {
|
||||
ui->todoItemTreeWidget->setCurrentItem(
|
||||
firstVisibleTodoItemTreeItem);
|
||||
ui->todoItemTreeWidget->setCurrentItem(firstVisibleTodoItemTreeItem);
|
||||
}
|
||||
|
||||
// give the keyboard focus to the task list widget
|
||||
|
@ -799,9 +764,7 @@ void TodoDialog::onSaveAndInsertButtonClicked() {
|
|||
QString taskUrl = "task://" + currentCalendarItem.getUid();
|
||||
|
||||
// insert a link to the task in the current note
|
||||
QString summaryText = selectedText.isEmpty()
|
||||
? currentCalendarItem.getSummary()
|
||||
: selectedText;
|
||||
QString summaryText = selectedText.isEmpty() ? currentCalendarItem.getSummary() : selectedText;
|
||||
QString insertText = "[" + summaryText + "](" + taskUrl + ")";
|
||||
|
||||
MainWindow::instance()->activeNoteTextEdit()->textCursor().insertText(insertText);
|
||||
|
@ -818,8 +781,7 @@ void TodoDialog::onImportAsNoteButtonClicked() {
|
|||
// create a new note with the task text
|
||||
MainWindow::instance()->createNewNote(
|
||||
name, text,
|
||||
MainWindow::CreateNewNoteOptions(
|
||||
MainWindow::CreateNewNoteOption::UseNameAsHeadline));
|
||||
MainWindow::CreateNewNoteOptions(MainWindow::CreateNewNoteOption::UseNameAsHeadline));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -827,8 +789,8 @@ void TodoDialog::onImportAsNoteButtonClicked() {
|
|||
* @param current
|
||||
* @param previous
|
||||
*/
|
||||
void TodoDialog::on_todoItemTreeWidget_currentItemChanged(
|
||||
QTreeWidgetItem *current, QTreeWidgetItem *previous) {
|
||||
void TodoDialog::on_todoItemTreeWidget_currentItemChanged(QTreeWidgetItem *current,
|
||||
QTreeWidgetItem *previous) {
|
||||
Q_UNUSED(previous)
|
||||
|
||||
// in case all items were removed
|
||||
|
@ -837,8 +799,7 @@ void TodoDialog::on_todoItemTreeWidget_currentItemChanged(
|
|||
return;
|
||||
}
|
||||
|
||||
MetricsService::instance()->sendVisitIfEnabled(
|
||||
QStringLiteral("todo/item/changed"));
|
||||
MetricsService::instance()->sendVisitIfEnabled(QStringLiteral("todo/item/changed"));
|
||||
|
||||
QString uid = current->data(0, Qt::UserRole).toString();
|
||||
|
||||
|
@ -874,8 +835,7 @@ void TodoDialog::on_todoItemTreeWidget_currentItemChanged(
|
|||
* @param item
|
||||
* @param column
|
||||
*/
|
||||
void TodoDialog::on_todoItemTreeWidget_itemChanged(QTreeWidgetItem *item,
|
||||
int column) {
|
||||
void TodoDialog::on_todoItemTreeWidget_itemChanged(QTreeWidgetItem *item, int column) {
|
||||
Q_UNUSED(column)
|
||||
|
||||
QString uid = item->data(0, Qt::UserRole).toString();
|
||||
|
@ -909,9 +869,8 @@ void TodoDialog::on_todoItemTreeWidget_customContextMenuRequested(QPoint pos) {
|
|||
if (selectedItem) {
|
||||
if (selectedItem == newTaskAction) {
|
||||
bool ok;
|
||||
QString name = QInputDialog::getText(
|
||||
this, tr("Create new sub-task"), tr("Name:"), QLineEdit::Normal,
|
||||
tr("New sub-task"), &ok);
|
||||
QString name = QInputDialog::getText(this, tr("Create new sub-task"), tr("Name:"),
|
||||
QLineEdit::Normal, tr("New sub-task"), &ok);
|
||||
|
||||
if (ok) {
|
||||
createNewTodoItem(name, item->data(0, Qt::UserRole).toString());
|
||||
|
|
|
@ -18,8 +18,7 @@ class TodoDialog : public MasterDialog {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TodoDialog(const QString &taskUid = QString(),
|
||||
QWidget *parent = nullptr);
|
||||
explicit TodoDialog(const QString &taskUid = QString(), QWidget *parent = nullptr);
|
||||
~TodoDialog();
|
||||
|
||||
void reloadTodoListItems();
|
||||
|
@ -55,7 +54,7 @@ class TodoDialog : public MasterDialog {
|
|||
void on_todoItemTreeWidget_customContextMenuRequested(QPoint pos);
|
||||
void on_showDueTodayItemsOnlyCheckBox_clicked();
|
||||
|
||||
private:
|
||||
private:
|
||||
Ui::TodoDialog *ui;
|
||||
QSplitter *mainSplitter;
|
||||
CalendarItem currentCalendarItem;
|
||||
|
|
|
@ -27,17 +27,16 @@ TrashDialog::TrashDialog(const QJSValue ¬es, QWidget *parent)
|
|||
ui->buttonBox->clear();
|
||||
|
||||
button = new QPushButton(tr("&Restore selected note on server"));
|
||||
button->setToolTip(Utils::Misc::replaceOwnCloudText(
|
||||
tr("<h3>Slower, but with note versions</h3>"
|
||||
"<p>The note will be restored on your ownCloud "
|
||||
"server with all versions.</p>"
|
||||
"<p>You will have to wait until it is synced to "
|
||||
"QOwnNotes by ownCloud sync.</p>")));
|
||||
button->setToolTip(
|
||||
Utils::Misc::replaceOwnCloudText(tr("<h3>Slower, but with note versions</h3>"
|
||||
"<p>The note will be restored on your ownCloud "
|
||||
"server with all versions.</p>"
|
||||
"<p>You will have to wait until it is synced to "
|
||||
"QOwnNotes by ownCloud sync.</p>")));
|
||||
button->setProperty("ActionRole", RestoreOnServer);
|
||||
button->setDefault(false);
|
||||
button->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("view-restore"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/view-restore.svg")));
|
||||
button->setIcon(QIcon::fromTheme(QStringLiteral("view-restore"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/view-restore.svg")));
|
||||
ui->buttonBox->addButton(button, QDialogButtonBox::ActionRole);
|
||||
|
||||
button = new QPushButton(tr("&Download selected note"));
|
||||
|
@ -49,25 +48,22 @@ TrashDialog::TrashDialog(const QJSValue ¬es, QWidget *parent)
|
|||
"<p>You can always restore the note and its versions later.</p>")));
|
||||
button->setProperty("ActionRole", Download);
|
||||
button->setDefault(false);
|
||||
button->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("edit-download"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/edit-download.svg")));
|
||||
button->setIcon(QIcon::fromTheme(QStringLiteral("edit-download"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/edit-download.svg")));
|
||||
ui->buttonBox->addButton(button, QDialogButtonBox::ActionRole);
|
||||
|
||||
button = new QPushButton(tr("&Delete"));
|
||||
button->setToolTip(tr("Delete selected note on server"));
|
||||
button->setProperty("ActionRole", DeleteOnServer);
|
||||
button->setDefault(false);
|
||||
button->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("edit-delete"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/edit-delete.svg")));
|
||||
button->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/edit-delete.svg")));
|
||||
ui->buttonBox->addButton(button, QDialogButtonBox::ActionRole);
|
||||
|
||||
button = new QPushButton(tr("&Cancel"));
|
||||
button->setProperty("ActionRole", Cancel);
|
||||
button->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("dialog-cancel"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/dialog-cancel.svg")));
|
||||
button->setIcon(QIcon::fromTheme(QStringLiteral("dialog-cancel"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/dialog-cancel.svg")));
|
||||
button->setDefault(true);
|
||||
ui->buttonBox->addButton(button, QDialogButtonBox::ActionRole);
|
||||
|
||||
|
@ -90,8 +86,7 @@ TrashDialog::TrashDialog(const QJSValue ¬es, QWidget *parent)
|
|||
while (notesIterator.hasNext()) {
|
||||
notesIterator.next();
|
||||
|
||||
QJSValue property =
|
||||
notesIterator.value().property(QStringLiteral("noteName"));
|
||||
QJSValue property = notesIterator.value().property(QStringLiteral("noteName"));
|
||||
|
||||
if (property.isUndefined()) {
|
||||
continue;
|
||||
|
@ -103,16 +98,10 @@ TrashDialog::TrashDialog(const QJSValue ¬es, QWidget *parent)
|
|||
continue;
|
||||
}
|
||||
|
||||
dateString = notesIterator.value()
|
||||
.property(QStringLiteral("dateString"))
|
||||
.toString();
|
||||
data =
|
||||
notesIterator.value().property(QStringLiteral("data")).toString();
|
||||
timestamp =
|
||||
notesIterator.value().property(QStringLiteral("timestamp")).toInt();
|
||||
QString fileName = notesIterator.value()
|
||||
.property(QStringLiteral("fileName"))
|
||||
.toString();
|
||||
dateString = notesIterator.value().property(QStringLiteral("dateString")).toString();
|
||||
data = notesIterator.value().property(QStringLiteral("data")).toString();
|
||||
timestamp = notesIterator.value().property(QStringLiteral("timestamp")).toInt();
|
||||
QString fileName = notesIterator.value().property(QStringLiteral("fileName")).toString();
|
||||
|
||||
auto *item = new QListWidgetItem();
|
||||
item->setText(itemName);
|
||||
|
@ -137,8 +126,7 @@ void TrashDialog::setupMainSplitter() {
|
|||
|
||||
// restore splitter sizes
|
||||
QSettings settings;
|
||||
QByteArray state =
|
||||
settings.value(QStringLiteral("trashSplitterSizes")).toByteArray();
|
||||
QByteArray state = settings.value(QStringLiteral("trashSplitterSizes")).toByteArray();
|
||||
trashSplitter->restoreState(state);
|
||||
|
||||
ui->gridLayout->layout()->addWidget(trashSplitter);
|
||||
|
@ -148,8 +136,7 @@ void TrashDialog::setupMainSplitter() {
|
|||
void TrashDialog::storeSettings() {
|
||||
// store the splitter sizes
|
||||
QSettings settings;
|
||||
settings.setValue(QStringLiteral("trashSplitterSizes"),
|
||||
trashSplitter->saveState());
|
||||
settings.setValue(QStringLiteral("trashSplitterSizes"), trashSplitter->saveState());
|
||||
}
|
||||
|
||||
TrashDialog::~TrashDialog() { delete ui; }
|
||||
|
@ -163,20 +150,17 @@ void TrashDialog::dialogButtonClicked(QAbstractButton *button) {
|
|||
int actionRole = button->property("ActionRole").toInt();
|
||||
|
||||
QString name = ui->trashListWidget->currentItem()->text();
|
||||
QString fileName =
|
||||
ui->trashListWidget->currentItem()->data(Qt::UserRole).toString();
|
||||
QString fileName = ui->trashListWidget->currentItem()->data(Qt::UserRole).toString();
|
||||
|
||||
switch (actionRole) {
|
||||
case Download: {
|
||||
QString text =
|
||||
dataList->value(ui->trashListWidget->currentRow());
|
||||
QString text = dataList->value(ui->trashListWidget->currentRow());
|
||||
MainWindow::instance()->createNewNote(name, text);
|
||||
break;
|
||||
}
|
||||
|
||||
case RestoreOnServer: {
|
||||
int timestamp = this->timestampList->value(
|
||||
ui->trashListWidget->currentRow());
|
||||
int timestamp = this->timestampList->value(ui->trashListWidget->currentRow());
|
||||
qDebug() << name << timestamp;
|
||||
|
||||
MainWindow::instance()->restoreTrashedNoteOnServer(fileName, timestamp);
|
||||
|
@ -184,34 +168,29 @@ void TrashDialog::dialogButtonClicked(QAbstractButton *button) {
|
|||
}
|
||||
|
||||
case DeleteOnServer: {
|
||||
if (Utils::Gui::question(
|
||||
this, tr("Delete note on server"),
|
||||
tr("Delete selected trashed note on server?"),
|
||||
"trashdialog-delete",
|
||||
QMessageBox::Yes | QMessageBox::No,
|
||||
QMessageBox::No) == QMessageBox::No) {
|
||||
if (Utils::Gui::question(this, tr("Delete note on server"),
|
||||
tr("Delete selected trashed note on server?"),
|
||||
"trashdialog-delete", QMessageBox::Yes | QMessageBox::No,
|
||||
QMessageBox::No) == QMessageBox::No) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int timestamp = this->timestampList->value(
|
||||
ui->trashListWidget->currentRow());
|
||||
const int timestamp = this->timestampList->value(ui->trashListWidget->currentRow());
|
||||
auto currentItem = ui->trashListWidget->currentItem();
|
||||
OwnCloudService *ownCloud = OwnCloudService::instance();
|
||||
ui->trashListWidget->setDisabled(true);
|
||||
ui->buttonBox->setDisabled(true);
|
||||
|
||||
// delete trashed note on server
|
||||
const int statusCode = ownCloud->deleteTrashedNoteOnServer(
|
||||
fileName, timestamp);
|
||||
const int statusCode = ownCloud->deleteTrashedNoteOnServer(fileName, timestamp);
|
||||
|
||||
if (statusCode >= 200 && statusCode < 300) {
|
||||
delete currentItem;
|
||||
} else {
|
||||
Utils::Gui::warning(
|
||||
this, tr("Error while deleting note"),
|
||||
tr("Deleting trashed note failed with status code: %1").arg(
|
||||
QString::number(statusCode)),
|
||||
"trashdialog-delete-failed");
|
||||
Utils::Gui::warning(this, tr("Error while deleting note"),
|
||||
tr("Deleting trashed note failed with status code: %1")
|
||||
.arg(QString::number(statusCode)),
|
||||
"trashdialog-delete-failed");
|
||||
}
|
||||
|
||||
ui->trashListWidget->setDisabled(false);
|
||||
|
|
|
@ -18,8 +18,7 @@
|
|||
|
||||
#include "ui_updatedialog.h"
|
||||
|
||||
UpdateDialog::UpdateDialog(QWidget *parent, const QString &changesHtml,
|
||||
const QString &releaseUrl,
|
||||
UpdateDialog::UpdateDialog(QWidget *parent, const QString &changesHtml, const QString &releaseUrl,
|
||||
const QString &releaseVersionString)
|
||||
: MasterDialog(parent), ui(new Ui::UpdateDialog) {
|
||||
ui->setupUi(this);
|
||||
|
@ -33,8 +32,7 @@ UpdateDialog::UpdateDialog(QWidget *parent, const QString &changesHtml,
|
|||
"https://www.qownnotes.org/contributing/get-involved.html"));
|
||||
|
||||
// inject some generic CSS styles
|
||||
ui->changeLogEdit->document()->setDefaultStyleSheet(
|
||||
Utils::Misc::genericCSS());
|
||||
ui->changeLogEdit->document()->setDefaultStyleSheet(Utils::Misc::genericCSS());
|
||||
// ui->label_4->setText("<style>" + Utils::Misc::genericCSS() +
|
||||
// "</style>" + ui->label_4->text());
|
||||
|
||||
|
@ -51,8 +49,8 @@ UpdateDialog::UpdateDialog(QWidget *parent, const QString &changesHtml,
|
|||
_updateButton = new QPushButton(tr("&Update"));
|
||||
_updateButton->setProperty("ActionRole", Update);
|
||||
_updateButton->setDefault(true);
|
||||
_updateButton->setIcon(QIcon::fromTheme(
|
||||
"svn-update", QIcon(":/icons/breeze-qownnotes/16x16/svn-update.svg")));
|
||||
_updateButton->setIcon(
|
||||
QIcon::fromTheme("svn-update", QIcon(":/icons/breeze-qownnotes/16x16/svn-update.svg")));
|
||||
ui->buttonBox->addButton(_updateButton, QDialogButtonBox::ActionRole);
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
|
@ -66,9 +64,8 @@ UpdateDialog::UpdateDialog(QWidget *parent, const QString &changesHtml,
|
|||
}
|
||||
#endif
|
||||
|
||||
button->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("edit-download"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/edit-download.svg")));
|
||||
button->setIcon(QIcon::fromTheme(QStringLiteral("edit-download"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/edit-download.svg")));
|
||||
ui->buttonBox->addButton(button, QDialogButtonBox::ActionRole);
|
||||
|
||||
button = new QPushButton(tr("&Skip version"));
|
||||
|
@ -83,16 +80,15 @@ UpdateDialog::UpdateDialog(QWidget *parent, const QString &changesHtml,
|
|||
button->setToolTip(tr("Don't show this dialog automatically"));
|
||||
button->setProperty("ActionRole", Disable);
|
||||
button->setDefault(false);
|
||||
button->setIcon(QIcon::fromTheme(QStringLiteral("window-close"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/"
|
||||
"window-close.svg")));
|
||||
button->setIcon(
|
||||
QIcon::fromTheme(QStringLiteral("window-close"), QIcon(":/icons/breeze-qownnotes/16x16/"
|
||||
"window-close.svg")));
|
||||
ui->buttonBox->addButton(button, QDialogButtonBox::ActionRole);
|
||||
|
||||
button = new QPushButton(tr("&Cancel"), this);
|
||||
button->setProperty("ActionRole", Cancel);
|
||||
button->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("dialog-cancel"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/dialog-cancel.svg")));
|
||||
button->setIcon(QIcon::fromTheme(QStringLiteral("dialog-cancel"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/dialog-cancel.svg")));
|
||||
button->setDefault(false);
|
||||
ui->buttonBox->addButton(button, QDialogButtonBox::ActionRole);
|
||||
|
||||
|
@ -129,15 +125,13 @@ void UpdateDialog::dialogButtonClicked(QAbstractButton *button) {
|
|||
switch (actionRole) {
|
||||
case Skip: {
|
||||
QSettings settings;
|
||||
settings.setValue(QStringLiteral("skipVersion"),
|
||||
this->releaseVersionString);
|
||||
settings.setValue(QStringLiteral("skipVersion"), this->releaseVersionString);
|
||||
qDebug() << "skip version";
|
||||
break;
|
||||
}
|
||||
case Disable: {
|
||||
QSettings settings;
|
||||
settings.setValue(QStringLiteral("disableAutomaticUpdateDialog"),
|
||||
true);
|
||||
settings.setValue(QStringLiteral("disableAutomaticUpdateDialog"), true);
|
||||
qDebug() << "disable dialog";
|
||||
break;
|
||||
}
|
||||
|
@ -145,8 +139,7 @@ void UpdateDialog::dialogButtonClicked(QAbstractButton *button) {
|
|||
QString release = qApp->property("release").toString();
|
||||
// if the release was build by the CI systems download the new
|
||||
// release
|
||||
if ((release == QLatin1String("Travis CI")) ||
|
||||
(release == QLatin1String("AppVeyor"))) {
|
||||
if ((release == QLatin1String("Travis CI")) || (release == QLatin1String("AppVeyor"))) {
|
||||
// download the new release
|
||||
QDesktopServices::openUrl(QUrl(releaseUrl.toUtf8()));
|
||||
} else if ((release == QLatin1String("AppImage"))) {
|
||||
|
@ -154,8 +147,8 @@ void UpdateDialog::dialogButtonClicked(QAbstractButton *button) {
|
|||
QDesktopServices::openUrl(QUrl(releaseUrl.toUtf8()));
|
||||
} else {
|
||||
// open the installation page
|
||||
QDesktopServices::openUrl(QUrl(
|
||||
QStringLiteral("https://www.qownnotes.org/installation")));
|
||||
QDesktopServices::openUrl(
|
||||
QUrl(QStringLiteral("https://www.qownnotes.org/installation")));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -184,17 +177,14 @@ void UpdateDialog::dialogButtonClicked(QAbstractButton *button) {
|
|||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
|
||||
// we really need redirects for GitHub urls!
|
||||
networkRequest.setAttribute(
|
||||
QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
#else
|
||||
networkRequest.setAttribute(
|
||||
QNetworkRequest::RedirectPolicyAttribute, true);
|
||||
networkRequest.setAttribute(QNetworkRequest::RedirectPolicyAttribute, true);
|
||||
#endif
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
||||
// try to ensure the network is accessible
|
||||
_networkManager->setNetworkAccessible(
|
||||
QNetworkAccessManager::Accessible);
|
||||
_networkManager->setNetworkAccessible(QNetworkAccessManager::Accessible);
|
||||
#endif
|
||||
|
||||
QNetworkReply *reply = _networkManager->get(networkRequest);
|
||||
|
@ -217,8 +207,7 @@ void UpdateDialog::dialogButtonClicked(QAbstractButton *button) {
|
|||
/**
|
||||
* Shows the download progress
|
||||
*/
|
||||
void UpdateDialog::releaseDownloadProgress(qint64 bytesReceived,
|
||||
qint64 bytesTotal) {
|
||||
void UpdateDialog::releaseDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
|
||||
ui->downloadProgressBar->setMaximum(static_cast<int>(bytesTotal));
|
||||
ui->downloadProgressBar->setValue(static_cast<int>(bytesReceived));
|
||||
}
|
||||
|
@ -243,9 +232,8 @@ void UpdateDialog::slotReplyFinished(QNetworkReply *reply) {
|
|||
qDebug() << __func__ << " - 'data.size': " << data.size();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
QMessageBox::critical(
|
||||
0, tr("Download error"),
|
||||
tr("Error while downloading:\n%1").arg(reply->errorString()));
|
||||
QMessageBox::critical(0, tr("Download error"),
|
||||
tr("Error while downloading:\n%1").arg(reply->errorString()));
|
||||
|
||||
qWarning() << tr("network error: %1").arg(reply->errorString());
|
||||
_updateButton->setDisabled(false);
|
||||
|
@ -261,17 +249,16 @@ void UpdateDialog::slotReplyFinished(QNetworkReply *reply) {
|
|||
QString suffix = "download";
|
||||
#endif
|
||||
|
||||
QTemporaryFile *tempFile =
|
||||
new QTemporaryFile(QDir::tempPath() + "/QOwnNotes-XXXXXX." + suffix);
|
||||
QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/QOwnNotes-XXXXXX." + suffix);
|
||||
|
||||
// we want to keep the file to be used in the update process
|
||||
tempFile->setAutoRemove(false);
|
||||
|
||||
// get a temporary file
|
||||
if (!tempFile->open()) {
|
||||
QMessageBox::critical(0, tr("File error"),
|
||||
tr("Could not open temporary file:\n%1")
|
||||
.arg(tempFile->errorString()));
|
||||
QMessageBox::critical(
|
||||
0, tr("File error"),
|
||||
tr("Could not open temporary file:\n%1").arg(tempFile->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -289,9 +276,8 @@ void UpdateDialog::slotReplyFinished(QNetworkReply *reply) {
|
|||
QFile file(filePath);
|
||||
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
QMessageBox::critical(
|
||||
0, tr("File error"),
|
||||
tr("Could not store downloaded file:\n%1").arg(file.errorString()));
|
||||
QMessageBox::critical(0, tr("File error"),
|
||||
tr("Could not store downloaded file:\n%1").arg(file.errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -337,14 +323,13 @@ bool UpdateDialog::initializeMacOSUpdateProcess(const QString &releaseUrl) {
|
|||
QString applicationsPath = QStringLiteral("/Applications");
|
||||
|
||||
if (applicationDirPath.endsWith(appPathPart)) {
|
||||
applicationsPath = Utils::Misc::removeIfEndsWith(
|
||||
std::move(applicationDirPath), appPathPart);
|
||||
applicationsPath =
|
||||
Utils::Misc::removeIfEndsWith(std::move(applicationDirPath), appPathPart);
|
||||
}
|
||||
|
||||
if (Utils::Gui::question(this, tr("Proceed with update"),
|
||||
tr("Do you want to update and restart QOwnNotes?"),
|
||||
QStringLiteral("update-and-restart")) !=
|
||||
QMessageBox::Yes) {
|
||||
QStringLiteral("update-and-restart")) != QMessageBox::Yes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -357,9 +342,8 @@ bool UpdateDialog::initializeMacOSUpdateProcess(const QString &releaseUrl) {
|
|||
QFile f(updaterPath);
|
||||
|
||||
if (!f.exists()) {
|
||||
QMessageBox::critical(
|
||||
0, tr("Error"),
|
||||
tr("Could not find updater file:\n%1").arg(f.fileName()));
|
||||
QMessageBox::critical(0, tr("Error"),
|
||||
tr("Could not find updater file:\n%1").arg(f.fileName()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -368,25 +352,23 @@ bool UpdateDialog::initializeMacOSUpdateProcess(const QString &releaseUrl) {
|
|||
QTextStream ts(&f);
|
||||
QString scriptContent = ts.readAll();
|
||||
f.close();
|
||||
scriptContent.replace(QLatin1String("\"$QOWNNOTES_RELEASE_URL\""),
|
||||
"\"" + releaseUrl + "\"");
|
||||
scriptContent.replace(
|
||||
QLatin1String("\"$QOWNNOTES_APPLICATIONS_PATH\""),
|
||||
"\"" + QDir::toNativeSeparators(applicationsPath) + "\"");
|
||||
scriptContent.replace(QLatin1String("\"$QOWNNOTES_RELEASE_URL\""), "\"" + releaseUrl + "\"");
|
||||
scriptContent.replace(QLatin1String("\"$QOWNNOTES_APPLICATIONS_PATH\""),
|
||||
"\"" + QDir::toNativeSeparators(applicationsPath) + "\"");
|
||||
|
||||
// we need a temporary script file with hardcoded parameters because some
|
||||
// users were not able to get parameters via the system environment
|
||||
QTemporaryFile *tempFile = new QTemporaryFile(
|
||||
QDir::tempPath() + "/QOwnNotes-Updater-XXXXXX.command");
|
||||
QTemporaryFile *tempFile =
|
||||
new QTemporaryFile(QDir::tempPath() + "/QOwnNotes-Updater-XXXXXX.command");
|
||||
|
||||
// we want to keep the file to be used in the update process
|
||||
tempFile->setAutoRemove(false);
|
||||
|
||||
// get a temporary file
|
||||
if (!tempFile->open()) {
|
||||
QMessageBox::critical(0, tr("File error"),
|
||||
tr("Could not open temporary file:\n%1")
|
||||
.arg(tempFile->errorString()));
|
||||
QMessageBox::critical(
|
||||
0, tr("File error"),
|
||||
tr("Could not open temporary file:\n%1").arg(tempFile->errorString()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -394,8 +376,7 @@ bool UpdateDialog::initializeMacOSUpdateProcess(const QString &releaseUrl) {
|
|||
tempFile->write(scriptContent.toLatin1());
|
||||
|
||||
// setting executable permissions to the updater script
|
||||
tempFile->setPermissions(QFile::ExeUser | QFile::ReadUser |
|
||||
QFile::WriteUser);
|
||||
tempFile->setPermissions(QFile::ExeUser | QFile::ReadUser | QFile::WriteUser);
|
||||
|
||||
// file->fileName() only holds a value after file->open()
|
||||
QString updaterFilePath = tempFile->fileName();
|
||||
|
@ -440,9 +421,9 @@ bool UpdateDialog::initializeLinuxUpdateProcess(const QString &filePath) {
|
|||
|
||||
if (!fileInfo.isWritable()) {
|
||||
QMessageBox::critical(0, tr("Permission error"),
|
||||
tr("Your QOwnNotes executable '%1' is not writeable! It must be "
|
||||
"writeable by the current user in order to be updated.")
|
||||
.arg(appPath));
|
||||
tr("Your QOwnNotes executable '%1' is not writeable! It must be "
|
||||
"writeable by the current user in order to be updated.")
|
||||
.arg(appPath));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -452,9 +433,9 @@ bool UpdateDialog::initializeLinuxUpdateProcess(const QString &filePath) {
|
|||
// make the new AppImage executable
|
||||
if (!updateFile.setPermissions(updateFile.permissions() | QFileDevice::ExeOwner)) {
|
||||
QMessageBox::critical(0, tr("Permission error"),
|
||||
tr("The temporary file '%1' could not be made executable! "
|
||||
"You need to replace '%2' yourself.")
|
||||
.arg(filePath, appPath));
|
||||
tr("The temporary file '%1' could not be made executable! "
|
||||
"You need to replace '%2' yourself.")
|
||||
.arg(filePath, appPath));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -462,9 +443,9 @@ bool UpdateDialog::initializeLinuxUpdateProcess(const QString &filePath) {
|
|||
// remove the current binary
|
||||
if (!file.remove()) {
|
||||
QMessageBox::critical(0, tr("File error"),
|
||||
tr("Your old QOwnNotes executable '%1' could not be removed! "
|
||||
"You need to replace it yourself with '%2'.")
|
||||
.arg(appPath, filePath));
|
||||
tr("Your old QOwnNotes executable '%1' could not be removed! "
|
||||
"You need to replace it yourself with '%2'.")
|
||||
.arg(appPath, filePath));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -472,9 +453,9 @@ bool UpdateDialog::initializeLinuxUpdateProcess(const QString &filePath) {
|
|||
// rename the new AppImage to the path of the current binary
|
||||
if (!updateFile.rename(appPath)) {
|
||||
QMessageBox::critical(0, tr("File error"),
|
||||
tr("Your old QOwnNotes executable '%1' could not be replaced "
|
||||
"by the new file '%2'! You need to replace it yourself.")
|
||||
.arg(appPath, filePath));
|
||||
tr("Your old QOwnNotes executable '%1' could not be replaced "
|
||||
"by the new file '%2'! You need to replace it yourself.")
|
||||
.arg(appPath, filePath));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -513,75 +494,67 @@ bool UpdateDialog::initializeWindowsUpdateProcess(const QString &filePath) {
|
|||
QString updaterPath = pathPrefix + "-updater.bat";
|
||||
QString unzipPath = pathPrefix + "-unzip.exe";
|
||||
|
||||
QFile updaterSourceFile(QCoreApplication::applicationDirPath() +
|
||||
"/update.bat");
|
||||
QFile unzipSourceFile(QCoreApplication::applicationDirPath() +
|
||||
"/unzip.exe");
|
||||
QFile updaterSourceFile(QCoreApplication::applicationDirPath() + "/update.bat");
|
||||
QFile unzipSourceFile(QCoreApplication::applicationDirPath() + "/unzip.exe");
|
||||
|
||||
// check if updater script exists
|
||||
if (!updaterSourceFile.exists()) {
|
||||
QMessageBox::critical(0, tr("Error"),
|
||||
tr("Updater script '%1' doesn't exist!")
|
||||
.arg(updaterSourceFile.fileName()));
|
||||
QMessageBox::critical(
|
||||
0, tr("Error"),
|
||||
tr("Updater script '%1' doesn't exist!").arg(updaterSourceFile.fileName()));
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if unzip executable exists
|
||||
if (!unzipSourceFile.exists()) {
|
||||
QMessageBox::critical(0, tr("Error"),
|
||||
tr("Updater unzip executable '%1' doesn't exist!")
|
||||
.arg(unzipSourceFile.fileName()));
|
||||
QMessageBox::critical(
|
||||
0, tr("Error"),
|
||||
tr("Updater unzip executable '%1' doesn't exist!").arg(unzipSourceFile.fileName()));
|
||||
return false;
|
||||
}
|
||||
|
||||
// copy updater script
|
||||
if (!updaterSourceFile.copy(updaterPath)) {
|
||||
QMessageBox::critical(
|
||||
0, tr("Error"),
|
||||
tr("Could not copy updater script '%1' to '%2'!")
|
||||
.arg(updaterSourceFile.fileName(), unzipPath));
|
||||
QMessageBox::critical(0, tr("Error"),
|
||||
tr("Could not copy updater script '%1' to '%2'!")
|
||||
.arg(updaterSourceFile.fileName(), unzipPath));
|
||||
return false;
|
||||
}
|
||||
|
||||
// copy unzip executable script
|
||||
if (!unzipSourceFile.copy(unzipPath)) {
|
||||
QMessageBox::critical(
|
||||
0, tr("Error"),
|
||||
tr("Could not copy updater script '%1' to '%2'!")
|
||||
.arg(updaterSourceFile.fileName(), unzipPath));
|
||||
QMessageBox::critical(0, tr("Error"),
|
||||
tr("Could not copy updater script '%1' to '%2'!")
|
||||
.arg(updaterSourceFile.fileName(), unzipPath));
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if updater script exists in temporary folder
|
||||
QFile updaterFile(updaterPath);
|
||||
if (!updaterFile.exists()) {
|
||||
QMessageBox::critical(
|
||||
0, tr("Error"),
|
||||
tr("Couldn't find updater script: %1").arg(updaterPath));
|
||||
QMessageBox::critical(0, tr("Error"),
|
||||
tr("Couldn't find updater script: %1").arg(updaterPath));
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if unzip executable exists in temporary folder
|
||||
QFile unzipFile(unzipPath);
|
||||
if (!unzipFile.exists()) {
|
||||
QMessageBox::critical(
|
||||
0, tr("Error"),
|
||||
tr("Couldn't find unzip executable: %1").arg(unzipPath));
|
||||
QMessageBox::critical(0, tr("Error"),
|
||||
tr("Couldn't find unzip executable: %1").arg(unzipPath));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Utils::Gui::question(
|
||||
this, tr("Proceed with update"),
|
||||
tr("The download is now finished. Do you want to update and "
|
||||
"restart QOwnNotes?"),
|
||||
QStringLiteral("update-and-restart")) != QMessageBox::Yes) {
|
||||
if (Utils::Gui::question(this, tr("Proceed with update"),
|
||||
tr("The download is now finished. Do you want to update and "
|
||||
"restart QOwnNotes?"),
|
||||
QStringLiteral("update-and-restart")) != QMessageBox::Yes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList parameters(QStringList()
|
||||
<< QDir::toNativeSeparators(filePath)
|
||||
<< QDir::toNativeSeparators(
|
||||
QCoreApplication::applicationDirPath())
|
||||
<< QDir::toNativeSeparators(QCoreApplication::applicationDirPath())
|
||||
<< QDir::toNativeSeparators(unzipPath));
|
||||
|
||||
if (Utils::Misc::isInPortableMode()) {
|
||||
|
@ -600,9 +573,7 @@ bool UpdateDialog::initializeWindowsUpdateProcess(const QString &filePath) {
|
|||
/**
|
||||
* Checks if the update dialog is open
|
||||
*/
|
||||
bool UpdateDialog::isUpdateDialogOpen() {
|
||||
return qApp->property("isUpdateDialogOpen").toBool();
|
||||
}
|
||||
bool UpdateDialog::isUpdateDialogOpen() { return qApp->property("isUpdateDialogOpen").toBool(); }
|
||||
|
||||
/**
|
||||
* Sets if the update dialog is open
|
||||
|
|
|
@ -15,8 +15,7 @@ class UpdateDialog : public MasterDialog {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UpdateDialog(QWidget *parent = nullptr,
|
||||
const QString &changesHtml = QString(),
|
||||
explicit UpdateDialog(QWidget *parent = nullptr, const QString &changesHtml = QString(),
|
||||
const QString &releaseUrl = QString(),
|
||||
const QString &releaseVersionString = QString());
|
||||
~UpdateDialog();
|
||||
|
|
|
@ -29,16 +29,14 @@ VersionDialog::VersionDialog(const QJSValue &versions, QWidget *parent)
|
|||
button = new QPushButton(tr("&Restore selected version"));
|
||||
button->setProperty("ActionRole", Restore);
|
||||
button->setDefault(false);
|
||||
button->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("edit-download"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/edit-download.svg")));
|
||||
button->setIcon(QIcon::fromTheme(QStringLiteral("edit-download"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/edit-download.svg")));
|
||||
ui->buttonBox->addButton(button, QDialogButtonBox::ActionRole);
|
||||
|
||||
button = new QPushButton(tr("&Cancel"));
|
||||
button->setProperty("ActionRole", Cancel);
|
||||
button->setIcon(QIcon::fromTheme(
|
||||
QStringLiteral("dialog-cancel"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/dialog-cancel.svg")));
|
||||
button->setIcon(QIcon::fromTheme(QStringLiteral("dialog-cancel"),
|
||||
QIcon(":/icons/breeze-qownnotes/16x16/dialog-cancel.svg")));
|
||||
button->setDefault(true);
|
||||
ui->buttonBox->addButton(button, QDialogButtonBox::ActionRole);
|
||||
|
||||
|
@ -63,8 +61,8 @@ VersionDialog::VersionDialog(const QJSValue &versions, QWidget *parent)
|
|||
// iterate over the versions
|
||||
while (versionsIterator.hasNext()) {
|
||||
versionsIterator.next();
|
||||
QJSValue property = versionsIterator.value().property(
|
||||
QStringLiteral("humanReadableTimestamp"));
|
||||
QJSValue property =
|
||||
versionsIterator.value().property(QStringLiteral("humanReadableTimestamp"));
|
||||
|
||||
if (property.isUndefined()) {
|
||||
continue;
|
||||
|
@ -77,17 +75,13 @@ VersionDialog::VersionDialog(const QJSValue &versions, QWidget *parent)
|
|||
}
|
||||
|
||||
diffHtml = "<style>" + Utils::Misc::genericCSS() + "</style>" +
|
||||
versionsIterator.value()
|
||||
.property(QStringLiteral("diffHtml"))
|
||||
.toString();
|
||||
versionsIterator.value().property(QStringLiteral("diffHtml")).toString();
|
||||
diffHtml.replace(QLatin1String("\\n"), QLatin1String("¶<br />"));
|
||||
diffHtml.replace(QLatin1String("\n"), QLatin1String("<br />"));
|
||||
|
||||
ui->versionListWidget->addItem(itemName);
|
||||
diffList->append(diffHtml);
|
||||
dataList->append(versionsIterator.value()
|
||||
.property(QStringLiteral("data"))
|
||||
.toString());
|
||||
dataList->append(versionsIterator.value().property(QStringLiteral("data")).toString());
|
||||
}
|
||||
|
||||
ui->versionListWidget->setCurrentRow(0);
|
||||
|
@ -102,8 +96,7 @@ void VersionDialog::setupMainSplitter() {
|
|||
|
||||
// restore splitter sizes
|
||||
QSettings settings;
|
||||
QByteArray state =
|
||||
settings.value(QStringLiteral("versionSplitterSizes")).toByteArray();
|
||||
QByteArray state = settings.value(QStringLiteral("versionSplitterSizes")).toByteArray();
|
||||
versionSplitter->restoreState(state);
|
||||
|
||||
ui->gridLayout->addWidget(versionSplitter);
|
||||
|
@ -112,8 +105,7 @@ void VersionDialog::setupMainSplitter() {
|
|||
void VersionDialog::storeSettings() {
|
||||
// store the splitter sizes
|
||||
QSettings settings;
|
||||
settings.setValue(QStringLiteral("versionSplitterSizes"),
|
||||
versionSplitter->saveState());
|
||||
settings.setValue(QStringLiteral("versionSplitterSizes"), versionSplitter->saveState());
|
||||
}
|
||||
|
||||
VersionDialog::~VersionDialog() { delete ui; }
|
||||
|
|
|
@ -12,9 +12,7 @@ WebSocketTokenDialog::WebSocketTokenDialog(QWidget *parent)
|
|||
ui->setupUi(this);
|
||||
|
||||
QSettings settings;
|
||||
QString token =
|
||||
settings.value(QStringLiteral("webSocketServerService/token"))
|
||||
.toString();
|
||||
QString token = settings.value(QStringLiteral("webSocketServerService/token")).toString();
|
||||
|
||||
if (token.isEmpty()) {
|
||||
on_generateButton_clicked();
|
||||
|
@ -24,9 +22,7 @@ WebSocketTokenDialog::WebSocketTokenDialog(QWidget *parent)
|
|||
}
|
||||
}
|
||||
|
||||
QString WebSocketTokenDialog::generateToken() const {
|
||||
return Utils::Misc::generateRandomString(8);
|
||||
}
|
||||
QString WebSocketTokenDialog::generateToken() const { return Utils::Misc::generateRandomString(8); }
|
||||
|
||||
WebSocketTokenDialog::~WebSocketTokenDialog() { delete ui; }
|
||||
|
||||
|
@ -45,6 +41,5 @@ void WebSocketTokenDialog::on_generateButton_clicked() {
|
|||
|
||||
void WebSocketTokenDialog::on_buttonBox_accepted() {
|
||||
QSettings settings;
|
||||
settings.setValue(QStringLiteral("webSocketServerService/token"),
|
||||
ui->tokenLineEdit->text());
|
||||
settings.setValue(QStringLiteral("webSocketServerService/token"), ui->tokenLineEdit->text());
|
||||
}
|
||||
|
|
|
@ -12,16 +12,13 @@
|
|||
#include "settingsdialog.h"
|
||||
#include "ui_welcomedialog.h"
|
||||
|
||||
WelcomeDialog::WelcomeDialog(QWidget *parent)
|
||||
: MasterDialog(parent), ui(new Ui::WelcomeDialog) {
|
||||
WelcomeDialog::WelcomeDialog(QWidget *parent) : MasterDialog(parent), ui(new Ui::WelcomeDialog) {
|
||||
ui->setupUi(this);
|
||||
ui->layoutWidget->setManualSettingsStoring(false);
|
||||
|
||||
// replace ownCloud text
|
||||
ui->subHeadlineLabel->setText(
|
||||
Utils::Misc::replaceOwnCloudText(ui->subHeadlineLabel->text()));
|
||||
ui->groupBox_2->setTitle(
|
||||
Utils::Misc::replaceOwnCloudText(ui->groupBox_2->title()));
|
||||
ui->subHeadlineLabel->setText(Utils::Misc::replaceOwnCloudText(ui->subHeadlineLabel->text()));
|
||||
ui->groupBox_2->setTitle(Utils::Misc::replaceOwnCloudText(ui->groupBox_2->title()));
|
||||
ui->label->setText(Utils::Misc::replaceOwnCloudText(ui->label->text()));
|
||||
ui->label_4->setText(Utils::Misc::replaceOwnCloudText(ui->label_4->text()));
|
||||
ui->ownCloudSettingsButton->setText(
|
||||
|
@ -30,8 +27,7 @@ WelcomeDialog::WelcomeDialog(QWidget *parent)
|
|||
// if note layout has already been set, we can finish settings in the first
|
||||
// step
|
||||
QSettings settings;
|
||||
_allowFinishButton =
|
||||
settings.contains(QStringLiteral("workspace-initial/windowState"));
|
||||
_allowFinishButton = settings.contains(QStringLiteral("workspace-initial/windowState"));
|
||||
ui->finishButton->setEnabled(_allowFinishButton);
|
||||
|
||||
ui->backButton->setEnabled(false);
|
||||
|
@ -46,15 +42,13 @@ WelcomeDialog::WelcomeDialog(QWidget *parent)
|
|||
WelcomeDialog::~WelcomeDialog() { delete ui; }
|
||||
|
||||
void WelcomeDialog::on_cancelButton_clicked() {
|
||||
MetricsService::instance()->sendVisitIfEnabled(
|
||||
QStringLiteral("welcome-dialog/cancel"));
|
||||
MetricsService::instance()->sendVisitIfEnabled(QStringLiteral("welcome-dialog/cancel"));
|
||||
|
||||
done(QDialog::Rejected);
|
||||
}
|
||||
|
||||
void WelcomeDialog::on_nextButton_clicked() {
|
||||
MetricsService::instance()->sendVisitIfEnabled(
|
||||
QStringLiteral("welcome-dialog/next"));
|
||||
MetricsService::instance()->sendVisitIfEnabled(QStringLiteral("welcome-dialog/next"));
|
||||
|
||||
int index = ui->stackedWidget->currentIndex();
|
||||
int maxIndex = ui->stackedWidget->count() - 1;
|
||||
|
@ -96,14 +90,12 @@ bool WelcomeDialog::handleNoteFolderSetup() {
|
|||
// everything is all right, the path already exists
|
||||
_allowFinishButton = true;
|
||||
|
||||
Utils::Misc::printInfo(
|
||||
QStringLiteral("Note path '%1' exists.").arg(_notesPath));
|
||||
Utils::Misc::printInfo(QStringLiteral("Note path '%1' exists.").arg(_notesPath));
|
||||
} else {
|
||||
if (ui->createNoteFolderCheckBox->isChecked()) {
|
||||
Utils::Misc::printInfo(
|
||||
QString("Note path '%1' doesn't exist yet and will "
|
||||
"be created.")
|
||||
.arg(_notesPath));
|
||||
Utils::Misc::printInfo(QString("Note path '%1' doesn't exist yet and will "
|
||||
"be created.")
|
||||
.arg(_notesPath));
|
||||
|
||||
// mkpath should only return true if the path was created, but we
|
||||
// want to double-check because there were some troubles on Windows
|
||||
|
@ -114,16 +106,14 @@ bool WelcomeDialog::handleNoteFolderSetup() {
|
|||
_allowFinishButton = true;
|
||||
|
||||
Utils::Misc::printInfo(
|
||||
QStringLiteral("Note path '%1' was now created.")
|
||||
.arg(_notesPath));
|
||||
QStringLiteral("Note path '%1' was now created.").arg(_notesPath));
|
||||
} else {
|
||||
qWarning() << "Cannot create note path with mkpath!";
|
||||
showNoteFolderErrorMessage(
|
||||
tr("Cannot create note path! You have to create "
|
||||
"the note folder manually!"));
|
||||
MetricsService::instance()->sendVisitIfEnabled(
|
||||
QStringLiteral(
|
||||
"welcome-dialog/note-folder/cannot-create-mkpath"));
|
||||
QStringLiteral("welcome-dialog/note-folder/cannot-create-mkpath"));
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Cannot create note path!";
|
||||
|
@ -164,16 +154,14 @@ void WelcomeDialog::storeNoteFolderSettings() {
|
|||
|
||||
// make the path relative to the portable data path if we are in
|
||||
// portable mode
|
||||
settings.setValue(
|
||||
QStringLiteral("notesPath"),
|
||||
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(_notesPath));
|
||||
settings.setValue(QStringLiteral("notesPath"),
|
||||
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(_notesPath));
|
||||
settings.setValue(QStringLiteral("showNoteSubFolders"),
|
||||
ui->showNoteSubFoldersCheckBox->isChecked());
|
||||
}
|
||||
|
||||
void WelcomeDialog::on_backButton_clicked() {
|
||||
MetricsService::instance()->sendVisitIfEnabled(
|
||||
QStringLiteral("welcome-dialog/back"));
|
||||
MetricsService::instance()->sendVisitIfEnabled(QStringLiteral("welcome-dialog/back"));
|
||||
|
||||
int index = ui->stackedWidget->currentIndex();
|
||||
|
||||
|
@ -187,8 +175,7 @@ void WelcomeDialog::on_backButton_clicked() {
|
|||
}
|
||||
|
||||
void WelcomeDialog::on_finishButton_clicked() {
|
||||
MetricsService::instance()->sendVisitIfEnabled(
|
||||
QStringLiteral("welcome-dialog/finished"));
|
||||
MetricsService::instance()->sendVisitIfEnabled(QStringLiteral("welcome-dialog/finished"));
|
||||
if (ui->stackedWidget->currentIndex() == WelcomePages::NoteFolderPage) {
|
||||
if (!handleNoteFolderSetup()) return;
|
||||
} else {
|
||||
|
@ -203,9 +190,8 @@ void WelcomeDialog::on_noteFolderButton_clicked() {
|
|||
QStringLiteral("welcome-dialog/set-note-folder"));
|
||||
|
||||
QString dir = QFileDialog::getExistingDirectory(
|
||||
this,
|
||||
tr("Please select the folder where your notes will get stored to"),
|
||||
_notesPath, QFileDialog::ShowDirsOnly);
|
||||
this, tr("Please select the folder where your notes will get stored to"), _notesPath,
|
||||
QFileDialog::ShowDirsOnly);
|
||||
|
||||
QDir d = QDir(dir);
|
||||
|
||||
|
@ -213,14 +199,12 @@ void WelcomeDialog::on_noteFolderButton_clicked() {
|
|||
#ifdef Q_OS_WIN32
|
||||
// check if user chose a different drive in portable mode
|
||||
if (Utils::Misc::isInPortableMode() &&
|
||||
Utils::Misc::portableDataPath().toLower().at(0) !=
|
||||
dir.toLower().at(0)) {
|
||||
QMessageBox::information(
|
||||
this, tr("Note folder"),
|
||||
tr("Keep in mind that the note folder will be "
|
||||
"stored relative to the directory where QOwnNotes "
|
||||
"resides in portable mode! So you need to stay on the "
|
||||
"same drive."));
|
||||
Utils::Misc::portableDataPath().toLower().at(0) != dir.toLower().at(0)) {
|
||||
QMessageBox::information(this, tr("Note folder"),
|
||||
tr("Keep in mind that the note folder will be "
|
||||
"stored relative to the directory where QOwnNotes "
|
||||
"resides in portable mode! So you need to stay on the "
|
||||
"same drive."));
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -248,7 +232,6 @@ void WelcomeDialog::on_networkSettingsButton_clicked() {
|
|||
}
|
||||
|
||||
void WelcomeDialog::closeEvent(QCloseEvent *event) {
|
||||
MetricsService::instance()->sendVisitIfEnabled(
|
||||
QStringLiteral("welcome-dialog/close"));
|
||||
MetricsService::instance()->sendVisitIfEnabled(QStringLiteral("welcome-dialog/close"));
|
||||
MasterDialog::closeEvent(event);
|
||||
}
|
||||
|
|
|
@ -20,8 +20,7 @@ Bookmark::Bookmark() {
|
|||
description = QString();
|
||||
}
|
||||
|
||||
Bookmark::Bookmark(QString url, QString name, QStringList tagList,
|
||||
QString description) {
|
||||
Bookmark::Bookmark(QString url, QString name, QStringList tagList, QString description) {
|
||||
this->url = std::move(url);
|
||||
this->name = std::move(name);
|
||||
this->tags = std::move(tagList);
|
||||
|
@ -30,26 +29,20 @@ Bookmark::Bookmark(QString url, QString name, QStringList tagList,
|
|||
|
||||
QJsonObject Bookmark::jsonObject() const {
|
||||
QJsonObject bookmarkObject;
|
||||
bookmarkObject.insert(QStringLiteral("name"),
|
||||
QJsonValue::fromVariant(name));
|
||||
bookmarkObject.insert(QStringLiteral("name"), QJsonValue::fromVariant(name));
|
||||
bookmarkObject.insert(QStringLiteral("url"), QJsonValue::fromVariant(url));
|
||||
bookmarkObject.insert(QStringLiteral("tags"),
|
||||
QJsonValue::fromVariant(tags));
|
||||
bookmarkObject.insert(QStringLiteral("description"),
|
||||
QJsonValue::fromVariant(description));
|
||||
bookmarkObject.insert(QStringLiteral("tags"), QJsonValue::fromVariant(tags));
|
||||
bookmarkObject.insert(QStringLiteral("description"), QJsonValue::fromVariant(description));
|
||||
return bookmarkObject;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Bookmark &bookmark) {
|
||||
dbg.nospace() << "Bookmark: <name>" << bookmark.name << " <url>"
|
||||
<< bookmark.url << " <tags>" << bookmark.tags
|
||||
<< " <description>" << bookmark.description;
|
||||
dbg.nospace() << "Bookmark: <name>" << bookmark.name << " <url>" << bookmark.url << " <tags>"
|
||||
<< bookmark.tags << " <description>" << bookmark.description;
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
bool Bookmark::operator==(const Bookmark &bookmark) const {
|
||||
return url == bookmark.url;
|
||||
}
|
||||
bool Bookmark::operator==(const Bookmark &bookmark) const { return url == bookmark.url; }
|
||||
|
||||
/**
|
||||
* Parses bookmarks from a text
|
||||
|
@ -57,16 +50,14 @@ bool Bookmark::operator==(const Bookmark &bookmark) const {
|
|||
* @param text
|
||||
* @return
|
||||
*/
|
||||
QVector<Bookmark> Bookmark::parseBookmarks(const QString &text,
|
||||
bool withBasicUrls) {
|
||||
QVector<Bookmark> Bookmark::parseBookmarks(const QString &text, bool withBasicUrls) {
|
||||
QRegularExpressionMatchIterator i;
|
||||
QVector<Bookmark> bookmarks;
|
||||
|
||||
// parse bookmark links like `- [name](http://link) #tag1 #tag2 the
|
||||
// description text` with optional tags and description
|
||||
i = QRegularExpression(
|
||||
QStringLiteral(R"([-*]\s+\[(.+?)\]\(([\w-]+://.+?)\)(.*)$)"),
|
||||
QRegularExpression::MultilineOption)
|
||||
i = QRegularExpression(QStringLiteral(R"([-*]\s+\[(.+?)\]\(([\w-]+://.+?)\)(.*)$)"),
|
||||
QRegularExpression::MultilineOption)
|
||||
.globalMatch(text);
|
||||
|
||||
while (i.hasNext()) {
|
||||
|
@ -79,16 +70,15 @@ QVector<Bookmark> Bookmark::parseBookmarks(const QString &text,
|
|||
|
||||
if (!additionalText.isEmpty()) {
|
||||
QRegularExpressionMatchIterator addIterator =
|
||||
QRegularExpression(QStringLiteral(R"(#([^\s#]+))"))
|
||||
.globalMatch(additionalText);
|
||||
QRegularExpression(QStringLiteral(R"(#([^\s#]+))")).globalMatch(additionalText);
|
||||
while (addIterator.hasNext()) {
|
||||
QRegularExpressionMatch addMatch = addIterator.next();
|
||||
QString tag = addMatch.captured(1).trimmed();
|
||||
|
||||
if (!tags.contains(tag)) {
|
||||
tags << tag;
|
||||
additionalText.remove(QRegularExpression(
|
||||
"#" + QRegularExpression::escape(tag) + "\\b"));
|
||||
additionalText.remove(
|
||||
QRegularExpression("#" + QRegularExpression::escape(tag) + "\\b"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,22 +95,19 @@ QVector<Bookmark> Bookmark::parseBookmarks(const QString &text,
|
|||
|
||||
if (withBasicUrls) {
|
||||
// parse named links like [name](http://my.site.com)
|
||||
i = QRegularExpression(QStringLiteral(R"(\[(.+?)\]\(([\w-]+://.+?)\))"))
|
||||
.globalMatch(text);
|
||||
i = QRegularExpression(QStringLiteral(R"(\[(.+?)\]\(([\w-]+://.+?)\))")).globalMatch(text);
|
||||
|
||||
while (i.hasNext()) {
|
||||
QRegularExpressionMatch match = i.next();
|
||||
QString name = match.captured(1);
|
||||
QString url = match.captured(2);
|
||||
|
||||
auto bookmark =
|
||||
Bookmark(url, name, QStringList() << QStringLiteral("current"));
|
||||
auto bookmark = Bookmark(url, name, QStringList() << QStringLiteral("current"));
|
||||
bookmark.mergeInList(bookmarks);
|
||||
}
|
||||
|
||||
// parse links like <http://my.site.com>
|
||||
i = QRegularExpression(QStringLiteral(R"(<([\w-]+://.+?)>)"))
|
||||
.globalMatch(text);
|
||||
i = QRegularExpression(QStringLiteral(R"(<([\w-]+://.+?)>)")).globalMatch(text);
|
||||
|
||||
while (i.hasNext()) {
|
||||
QRegularExpressionMatch match = i.next();
|
||||
|
@ -139,8 +126,7 @@ QVector<Bookmark> Bookmark::parseBookmarks(const QString &text,
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
QString Bookmark::bookmarksWebServiceJsonText(
|
||||
const QVector<Bookmark> &bookmarks) {
|
||||
QString Bookmark::bookmarksWebServiceJsonText(const QVector<Bookmark> &bookmarks) {
|
||||
QJsonArray bookmarkObjectList;
|
||||
QJsonArray noteFolderObjectList;
|
||||
|
||||
|
@ -154,15 +140,12 @@ QString Bookmark::bookmarksWebServiceJsonText(
|
|||
}
|
||||
|
||||
QJsonObject bookmarkResultObject;
|
||||
bookmarkResultObject.insert(QStringLiteral("type"),
|
||||
QJsonValue::fromVariant("bookmarks"));
|
||||
bookmarkResultObject.insert(QStringLiteral("type"), QJsonValue::fromVariant("bookmarks"));
|
||||
bookmarkResultObject.insert(QStringLiteral("data"), bookmarkObjectList);
|
||||
bookmarkResultObject.insert(QStringLiteral("noteFolderName"),
|
||||
NoteFolder::currentNoteFolder().getName());
|
||||
bookmarkResultObject.insert(QStringLiteral("noteFolders"),
|
||||
noteFolderObjectList);
|
||||
bookmarkResultObject.insert(QStringLiteral("noteFolderId"),
|
||||
NoteFolder::currentNoteFolderId());
|
||||
bookmarkResultObject.insert(QStringLiteral("noteFolders"), noteFolderObjectList);
|
||||
bookmarkResultObject.insert(QStringLiteral("noteFolderId"), NoteFolder::currentNoteFolderId());
|
||||
|
||||
QJsonDocument doc(bookmarkResultObject);
|
||||
|
||||
|
@ -174,8 +157,7 @@ QString Bookmark::bookmarksWebServiceJsonText(
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
QString Bookmark::parsedBookmarksWebServiceJsonText(const QString &text,
|
||||
bool withBasicUrls) {
|
||||
QString Bookmark::parsedBookmarksWebServiceJsonText(const QString &text, bool withBasicUrls) {
|
||||
return bookmarksWebServiceJsonText(parseBookmarks(text, withBasicUrls));
|
||||
}
|
||||
|
||||
|
|
|
@ -12,17 +12,14 @@
|
|||
class Bookmark {
|
||||
public:
|
||||
Bookmark();
|
||||
explicit Bookmark(QString url, QString name = QString(),
|
||||
QStringList tagList = QStringList(),
|
||||
explicit Bookmark(QString url, QString name = QString(), QStringList tagList = QStringList(),
|
||||
QString description = QString());
|
||||
friend QDebug operator<<(QDebug dbg, const Bookmark &bookmark);
|
||||
QJsonObject jsonObject() const;
|
||||
static QVector<Bookmark> parseBookmarks(const QString &text,
|
||||
bool withBasicUrls = false);
|
||||
static QString bookmarksWebServiceJsonText(
|
||||
const QVector<Bookmark> &bookmarks);
|
||||
static QString parsedBookmarksWebServiceJsonText(
|
||||
const QString &text, bool withBasicUrls = false);
|
||||
static QVector<Bookmark> parseBookmarks(const QString &text, bool withBasicUrls = false);
|
||||
static QString bookmarksWebServiceJsonText(const QVector<Bookmark> &bookmarks);
|
||||
static QString parsedBookmarksWebServiceJsonText(const QString &text,
|
||||
bool withBasicUrls = false);
|
||||
bool operator==(const Bookmark &bookmark) const;
|
||||
static void mergeInList(QVector<Bookmark> &bookmarks, Bookmark &bookmark);
|
||||
static void mergeListInList(const QVector<Bookmark> &sourceBookmarks,
|
||||
|
|
|
@ -45,17 +45,13 @@ int CalendarItem::getPriority() { return this->priority; }
|
|||
|
||||
bool CalendarItem::getHasDirtyData() { return this->hasDirtyData; }
|
||||
|
||||
QString CalendarItem::getLastModifiedString() {
|
||||
return this->lastModifiedString;
|
||||
}
|
||||
QString CalendarItem::getLastModifiedString() { return this->lastModifiedString; }
|
||||
|
||||
QString CalendarItem::getETag() { return this->etag; }
|
||||
|
||||
QDateTime CalendarItem::getAlarmDate() { return this->alarmDate; }
|
||||
|
||||
void CalendarItem::setLastModifiedString(const QString &text) {
|
||||
this->lastModifiedString = text;
|
||||
}
|
||||
void CalendarItem::setLastModifiedString(const QString &text) { this->lastModifiedString = text; }
|
||||
|
||||
void CalendarItem::setETag(const QString &text) { this->etag = text; }
|
||||
|
||||
|
@ -65,29 +61,19 @@ void CalendarItem::setUrl(const QUrl &url) { this->url = url.toString(); }
|
|||
|
||||
void CalendarItem::setCalendar(const QString &text) { this->calendar = text; }
|
||||
|
||||
void CalendarItem::setDescription(const QString &text) {
|
||||
this->description = text;
|
||||
}
|
||||
void CalendarItem::setDescription(const QString &text) { this->description = text; }
|
||||
|
||||
void CalendarItem::setICSData(const QString &text) { this->icsData = text; }
|
||||
|
||||
void CalendarItem::setUid(const QString &text) { this->uid = text; }
|
||||
|
||||
void CalendarItem::setRelatedUid(const QString &text) {
|
||||
this->relatedUid = text;
|
||||
}
|
||||
void CalendarItem::setRelatedUid(const QString &text) { this->relatedUid = text; }
|
||||
|
||||
void CalendarItem::setCreated(const QDateTime &dateTime) {
|
||||
this->created = dateTime;
|
||||
}
|
||||
void CalendarItem::setCreated(const QDateTime &dateTime) { this->created = dateTime; }
|
||||
|
||||
void CalendarItem::setModified(const QDateTime &dateTime) {
|
||||
this->modified = dateTime;
|
||||
}
|
||||
void CalendarItem::setModified(const QDateTime &dateTime) { this->modified = dateTime; }
|
||||
|
||||
void CalendarItem::setAlarmDate(const QDateTime &dateTime) {
|
||||
this->alarmDate = dateTime;
|
||||
}
|
||||
void CalendarItem::setAlarmDate(const QDateTime &dateTime) { this->alarmDate = dateTime; }
|
||||
|
||||
void CalendarItem::setPriority(int value) { this->priority = value; }
|
||||
|
||||
|
@ -107,9 +93,9 @@ void CalendarItem::updateCompleted(bool value) {
|
|||
* translated
|
||||
* @return
|
||||
*/
|
||||
bool CalendarItem::addCalendarItemForRequest(
|
||||
const QString &calendar, const QUrl &url, const QString &etag,
|
||||
const QString &lastModifiedString) {
|
||||
bool CalendarItem::addCalendarItemForRequest(const QString &calendar, const QUrl &url,
|
||||
const QString &etag,
|
||||
const QString &lastModifiedString) {
|
||||
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("disk"));
|
||||
QSqlQuery query(db);
|
||||
|
||||
|
@ -120,8 +106,7 @@ bool CalendarItem::addCalendarItemForRequest(
|
|||
query.bindValue(QStringLiteral(":calendar"), calendar);
|
||||
query.bindValue(QStringLiteral(":url"), url);
|
||||
query.bindValue(QStringLiteral(":etag"), etag);
|
||||
query.bindValue(QStringLiteral(":last_modified_string"),
|
||||
lastModifiedString);
|
||||
query.bindValue(QStringLiteral(":last_modified_string"), lastModifiedString);
|
||||
return query.exec();
|
||||
}
|
||||
|
||||
|
@ -157,8 +142,7 @@ CalendarItem CalendarItem::fetch(int id) {
|
|||
return calendarItem;
|
||||
}
|
||||
|
||||
CalendarItem CalendarItem::fetchByUrlAndCalendar(const QString &url,
|
||||
const QString &calendar) {
|
||||
CalendarItem CalendarItem::fetchByUrlAndCalendar(const QString &url, const QString &calendar) {
|
||||
CalendarItem calendarItem;
|
||||
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("disk"));
|
||||
QSqlQuery query(db);
|
||||
|
@ -183,8 +167,7 @@ CalendarItem CalendarItem::fetchByUid(const QString &uid) {
|
|||
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("disk"));
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT * FROM calendarItem WHERE uid = :uid"));
|
||||
query.prepare(QStringLiteral("SELECT * FROM calendarItem WHERE uid = :uid"));
|
||||
query.bindValue(QStringLiteral(":uid"), uid);
|
||||
|
||||
if (!query.exec()) {
|
||||
|
@ -201,8 +184,7 @@ CalendarItem CalendarItem::fetchByUrl(const QUrl &url) {
|
|||
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("disk"));
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT * FROM calendarItem WHERE url = :url"));
|
||||
query.prepare(QStringLiteral("SELECT * FROM calendarItem WHERE url = :url"));
|
||||
query.bindValue(QStringLiteral(":url"), url);
|
||||
|
||||
if (!query.exec()) {
|
||||
|
@ -257,8 +239,7 @@ bool CalendarItem::fillFromQuery(const QSqlQuery &query) {
|
|||
this->summary = query.value(QStringLiteral("summary")).toString();
|
||||
this->url = query.value(QStringLiteral("url")).toString();
|
||||
this->description = query.value(QStringLiteral("description")).toString();
|
||||
this->hasDirtyData =
|
||||
query.value(QStringLiteral("has_dirty_data")).toInt() == 1;
|
||||
this->hasDirtyData = query.value(QStringLiteral("has_dirty_data")).toInt() == 1;
|
||||
this->completed = query.value(QStringLiteral("completed")).toInt() == 1;
|
||||
this->priority = query.value(QStringLiteral("priority")).toInt();
|
||||
this->uid = query.value(QStringLiteral("uid")).toString();
|
||||
|
@ -266,13 +247,11 @@ bool CalendarItem::fillFromQuery(const QSqlQuery &query) {
|
|||
this->calendar = query.value(QStringLiteral("calendar")).toString();
|
||||
this->icsData = query.value(QStringLiteral("ics_data")).toString();
|
||||
this->etag = query.value(QStringLiteral("etag")).toString();
|
||||
this->lastModifiedString =
|
||||
query.value(QStringLiteral("last_modified_string")).toString();
|
||||
this->lastModifiedString = query.value(QStringLiteral("last_modified_string")).toString();
|
||||
this->alarmDate = query.value(QStringLiteral("alarm_date")).toDateTime();
|
||||
this->created = query.value(QStringLiteral("created")).toDateTime();
|
||||
this->modified = query.value(QStringLiteral("modified")).toDateTime();
|
||||
this->completedDate =
|
||||
query.value(QStringLiteral("completed_date")).toDateTime();
|
||||
this->completedDate = query.value(QStringLiteral("completed_date")).toDateTime();
|
||||
this->sortPriority = query.value(QStringLiteral("sort_priority")).toInt();
|
||||
|
||||
return true;
|
||||
|
@ -391,8 +370,7 @@ QList<QUrl> CalendarItem::fetchAllUrlsByCalendar(const QString &calendar) {
|
|||
QSqlQuery query(db);
|
||||
QList<QUrl> urlList;
|
||||
|
||||
query.prepare(QStringLiteral(
|
||||
"SELECT url FROM calendarItem WHERE calendar = :calendar"));
|
||||
query.prepare(QStringLiteral("SELECT url FROM calendarItem WHERE calendar = :calendar"));
|
||||
query.bindValue(QStringLiteral(":calendar"), calendar);
|
||||
|
||||
if (!query.exec()) {
|
||||
|
@ -434,8 +412,7 @@ QList<CalendarItem> CalendarItem::search(const QString &text) {
|
|||
/**
|
||||
* Returns a list of UIDs for the search in the TodoDialog
|
||||
*/
|
||||
QList<QString> CalendarItem::searchAsUidList(const QString &text,
|
||||
const QString &calendar) {
|
||||
QList<QString> CalendarItem::searchAsUidList(const QString &text, const QString &calendar) {
|
||||
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("disk"));
|
||||
QSqlQuery query(db);
|
||||
QList<QString> resultList;
|
||||
|
@ -522,16 +499,14 @@ bool CalendarItem::store() {
|
|||
query.bindValue(QStringLiteral(":summary"), this->summary);
|
||||
query.bindValue(QStringLiteral(":url"), this->url);
|
||||
query.bindValue(QStringLiteral(":description"), this->description);
|
||||
query.bindValue(QStringLiteral(":has_dirty_data"),
|
||||
this->hasDirtyData ? 1 : 0);
|
||||
query.bindValue(QStringLiteral(":has_dirty_data"), this->hasDirtyData ? 1 : 0);
|
||||
query.bindValue(QStringLiteral(":completed"), this->completed ? 1 : 0);
|
||||
query.bindValue(QStringLiteral(":calendar"), this->calendar);
|
||||
query.bindValue(QStringLiteral(":uid"), this->uid);
|
||||
query.bindValue(QStringLiteral(":related_uid"), this->relatedUid);
|
||||
query.bindValue(QStringLiteral(":ics_data"), this->icsData);
|
||||
query.bindValue(QStringLiteral(":etag"), this->etag);
|
||||
query.bindValue(QStringLiteral(":last_modified_string"),
|
||||
this->lastModifiedString);
|
||||
query.bindValue(QStringLiteral(":last_modified_string"), this->lastModifiedString);
|
||||
query.bindValue(QStringLiteral(":alarm_date"), this->alarmDate);
|
||||
query.bindValue(QStringLiteral(":priority"), this->priority);
|
||||
query.bindValue(QStringLiteral(":created"), this->created);
|
||||
|
@ -570,18 +545,14 @@ QString CalendarItem::generateNewICSData() {
|
|||
icsDataHash[QStringLiteral("DESCRIPTION")] = description;
|
||||
icsDataHash[QStringLiteral("UID")] = uid;
|
||||
icsDataHash[QStringLiteral("PRIORITY")] = QString::number(priority);
|
||||
icsDataHash[QStringLiteral("PERCENT-COMPLETE")] =
|
||||
QString::number(completed ? 100 : 0);
|
||||
icsDataHash[QStringLiteral("STATUS")] =
|
||||
completed ? "COMPLETED" : "NEEDS-ACTION";
|
||||
icsDataHash[QStringLiteral("PERCENT-COMPLETE")] = QString::number(completed ? 100 : 0);
|
||||
icsDataHash[QStringLiteral("STATUS")] = completed ? "COMPLETED" : "NEEDS-ACTION";
|
||||
// icsDataHash["CREATED"] =
|
||||
// created.toUTC().toString(ICS_DATETIME_FORMAT);
|
||||
// icsDataHash["LAST-MODIFIED"] =
|
||||
// modified.toUTC().toString(ICS_DATETIME_FORMAT);
|
||||
icsDataHash[QStringLiteral("CREATED")] =
|
||||
created.toString(ICS_DATETIME_FORMAT);
|
||||
icsDataHash[QStringLiteral("LAST-MODIFIED")] =
|
||||
modified.toString(ICS_DATETIME_FORMAT);
|
||||
icsDataHash[QStringLiteral("CREATED")] = created.toString(ICS_DATETIME_FORMAT);
|
||||
icsDataHash[QStringLiteral("LAST-MODIFIED")] = modified.toString(ICS_DATETIME_FORMAT);
|
||||
|
||||
if (!relatedUid.isEmpty()) {
|
||||
icsDataHash[QStringLiteral("RELATED-TO")] = relatedUid;
|
||||
|
@ -590,8 +561,7 @@ QString CalendarItem::generateNewICSData() {
|
|||
if (completed) {
|
||||
// icsDataHash["COMPLETED"] =
|
||||
// completedDate.toUTC().toString(ICS_DATETIME_FORMAT);
|
||||
icsDataHash[QStringLiteral("COMPLETED")] =
|
||||
completedDate.toString(ICS_DATETIME_FORMAT);
|
||||
icsDataHash[QStringLiteral("COMPLETED")] = completedDate.toString(ICS_DATETIME_FORMAT);
|
||||
} else {
|
||||
// remove the "COMPLETED" ics data attribute if the task item is not
|
||||
// completed
|
||||
|
@ -603,8 +573,7 @@ QString CalendarItem::generateNewICSData() {
|
|||
|
||||
// set the alarm if needed
|
||||
if (alarmDate.isValid()) {
|
||||
icsDataHash[QStringLiteral("DUE")] =
|
||||
alarmDate.toString(ICS_DATETIME_FORMAT);
|
||||
icsDataHash[QStringLiteral("DUE")] = alarmDate.toString(ICS_DATETIME_FORMAT);
|
||||
|
||||
// Nextcloud seems to have problem with the VALARM block
|
||||
// addVALARMBlockToICS();
|
||||
|
@ -701,8 +670,7 @@ bool CalendarItem::deleteAllByCalendar(const QString &calendar) {
|
|||
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("disk"));
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare(
|
||||
QStringLiteral("DELETE FROM calendarItem WHERE calendar = :calendar"));
|
||||
query.prepare(QStringLiteral("DELETE FROM calendarItem WHERE calendar = :calendar"));
|
||||
query.bindValue(QStringLiteral(":calendar"), calendar);
|
||||
if (!query.exec()) {
|
||||
qWarning() << __func__ << ": " << query.lastError();
|
||||
|
@ -740,20 +708,17 @@ bool CalendarItem::updateWithICSData(const QString &icsData) {
|
|||
? icsDataHash[QStringLiteral("SUMMARY")].trimmed()
|
||||
: QString();
|
||||
completed = icsDataHash.contains(QStringLiteral("PERCENT-COMPLETE"))
|
||||
? icsDataHash[QStringLiteral("PERCENT-COMPLETE")] ==
|
||||
QLatin1String("100")
|
||||
? icsDataHash[QStringLiteral("PERCENT-COMPLETE")] == QLatin1String("100")
|
||||
: false;
|
||||
|
||||
// also take the completed status into account
|
||||
if (!completed) {
|
||||
completed =
|
||||
icsDataHash.contains(QStringLiteral("STATUS")) &&
|
||||
icsDataHash[QStringLiteral("STATUS")] == QLatin1String("COMPLETED");
|
||||
completed = icsDataHash.contains(QStringLiteral("STATUS")) &&
|
||||
icsDataHash[QStringLiteral("STATUS")] == QLatin1String("COMPLETED");
|
||||
}
|
||||
|
||||
uid = icsDataHash.contains(QStringLiteral("UID"))
|
||||
? icsDataHash[QStringLiteral("UID")]
|
||||
: QString();
|
||||
uid = icsDataHash.contains(QStringLiteral("UID")) ? icsDataHash[QStringLiteral("UID")]
|
||||
: QString();
|
||||
relatedUid = icsDataHash.contains(QStringLiteral("RELATED-TO"))
|
||||
? icsDataHash[QStringLiteral("RELATED-TO")]
|
||||
: QString();
|
||||
|
@ -764,23 +729,23 @@ bool CalendarItem::updateWithICSData(const QString &icsData) {
|
|||
? icsDataHash[QStringLiteral("PRIORITY")].toInt()
|
||||
: 0;
|
||||
created = icsDataHash.contains(QStringLiteral("CREATED"))
|
||||
? getDateTimeFromString(icsDataHash[QStringLiteral("CREATED")])
|
||||
: QDateTime::currentDateTime();
|
||||
? getDateTimeFromString(icsDataHash[QStringLiteral("CREATED")])
|
||||
: QDateTime::currentDateTime();
|
||||
modified = icsDataHash.contains(QStringLiteral("LAST-MODIFIED"))
|
||||
? getDateTimeFromString(icsDataHash[QStringLiteral("LAST-MODIFIED")])
|
||||
: QDateTime::currentDateTime();
|
||||
? getDateTimeFromString(icsDataHash[QStringLiteral("LAST-MODIFIED")])
|
||||
: QDateTime::currentDateTime();
|
||||
|
||||
// workaround to check if we have a alarm description, so that on empty
|
||||
// descriptions the alarm description isn't taken
|
||||
QString alarmDescription = getICSDataAttributeInBlock(
|
||||
QStringLiteral("VALARM"), QStringLiteral("DESCRIPTION"));
|
||||
QString alarmDescription =
|
||||
getICSDataAttributeInBlock(QStringLiteral("VALARM"), QStringLiteral("DESCRIPTION"));
|
||||
if ((!description.isEmpty()) && (!alarmDescription.isEmpty()) &&
|
||||
(description == alarmDescription)) {
|
||||
description = QString();
|
||||
}
|
||||
|
||||
QString alarmDateString = getICSDataAttributeInBlock(
|
||||
QStringLiteral("VALARM"), QStringLiteral("TRIGGER;VALUE=DATE-TIME"));
|
||||
QString alarmDateString = getICSDataAttributeInBlock(QStringLiteral("VALARM"),
|
||||
QStringLiteral("TRIGGER;VALUE=DATE-TIME"));
|
||||
|
||||
// Nextcloud seems to store the reminder date in the DUE field
|
||||
alarmDate = icsDataHash.contains(QStringLiteral("DUE"))
|
||||
|
@ -807,8 +772,7 @@ QDateTime CalendarItem::getDateTimeFromString(const QString &dateString) {
|
|||
// see: https://github.com/pbek/QOwnNotes/issues/1966
|
||||
if (!dateTime.isValid()) {
|
||||
dateTime = QDateTime::fromString(dateString, ICS_DATETIME_FORMAT_UTC);
|
||||
dateTime = QDateTime(dateTime.date(), dateTime.time(), Qt::UTC)
|
||||
.toLocalTime();
|
||||
dateTime = QDateTime(dateTime.date(), dateTime.time(), Qt::UTC).toLocalTime();
|
||||
}
|
||||
|
||||
return dateTime;
|
||||
|
@ -899,8 +863,7 @@ bool CalendarItem::addVALARMBlockToICS() {
|
|||
QString value = icsDataHash.value(key);
|
||||
|
||||
// look for the VTODO begin block
|
||||
if (key.startsWith(QLatin1String("BEGIN")) &&
|
||||
(value == QLatin1String("VTODO"))) {
|
||||
if (key.startsWith(QLatin1String("BEGIN")) && (value == QLatin1String("VTODO"))) {
|
||||
foundBegin = true;
|
||||
}
|
||||
|
||||
|
@ -916,18 +879,15 @@ bool CalendarItem::addVALARMBlockToICS() {
|
|||
icsDataHashCopy[addKey] = QLatin1String("VALARM");
|
||||
icsDataKeyListCopy.insert(i, addKey);
|
||||
|
||||
addKey =
|
||||
findFreeHashKey(&icsDataHashCopy, QStringLiteral("ACTION"));
|
||||
addKey = findFreeHashKey(&icsDataHashCopy, QStringLiteral("ACTION"));
|
||||
icsDataHashCopy[addKey] = QLatin1String("DISPLAY");
|
||||
icsDataKeyListCopy.insert(++i, addKey);
|
||||
|
||||
addKey = findFreeHashKey(&icsDataHashCopy,
|
||||
QStringLiteral("DESCRIPTION"));
|
||||
addKey = findFreeHashKey(&icsDataHashCopy, QStringLiteral("DESCRIPTION"));
|
||||
icsDataHashCopy[addKey] = QLatin1String("Reminder");
|
||||
icsDataKeyListCopy.insert(++i, addKey);
|
||||
|
||||
addKey = findFreeHashKey(&icsDataHashCopy,
|
||||
QStringLiteral("TRIGGER;VALUE=DATE-TIME"));
|
||||
addKey = findFreeHashKey(&icsDataHashCopy, QStringLiteral("TRIGGER;VALUE=DATE-TIME"));
|
||||
icsDataHashCopy[addKey] = alarmDateString;
|
||||
icsDataKeyListCopy.insert(++i, addKey);
|
||||
|
||||
|
@ -1023,8 +983,7 @@ void CalendarItem::generateICSDataHash() {
|
|||
* @param number
|
||||
* @return
|
||||
*/
|
||||
QString CalendarItem::findFreeHashKey(QHash<QString, QString> *hash,
|
||||
QString key, int number) {
|
||||
QString CalendarItem::findFreeHashKey(QHash<QString, QString> *hash, QString key, int number) {
|
||||
// give up after 1000 tries
|
||||
if (number >= 1000) {
|
||||
return key;
|
||||
|
@ -1069,16 +1028,14 @@ QString CalendarItem::decodeICSDataLine(QString line) {
|
|||
return line;
|
||||
}
|
||||
|
||||
CalendarItem CalendarItem::createNewTodoItem(const QString &summary,
|
||||
const QString &calendar,
|
||||
CalendarItem CalendarItem::createNewTodoItem(const QString &summary, const QString &calendar,
|
||||
const QString &relatedUid) {
|
||||
QString uuidString = Utils::Misc::createUuidString();
|
||||
CalendarItem calItem;
|
||||
calItem.setSummary(summary);
|
||||
calItem.setCalendar(calendar);
|
||||
calItem.setRelatedUid(relatedUid);
|
||||
calItem.setUrl(
|
||||
QUrl(getCurrentCalendarUrl() + "qownnotes-" + uuidString + ".ics"));
|
||||
calItem.setUrl(QUrl(getCurrentCalendarUrl() + "qownnotes-" + uuidString + ".ics"));
|
||||
calItem.setICSData(
|
||||
"BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:ownCloud Calendar"
|
||||
"\nCALSCALE:GREGORIAN\nBEGIN:VTODO\nEND:VTODO"
|
||||
|
@ -1093,8 +1050,7 @@ CalendarItem CalendarItem::createNewTodoItem(const QString &summary,
|
|||
|
||||
if (calItem.store()) {
|
||||
qDebug() << __func__ << " - 'calItem': " << calItem;
|
||||
qDebug() << __func__
|
||||
<< " - 'calItem.getICSData()': " << calItem.getICSData();
|
||||
qDebug() << __func__ << " - 'calItem.getICSData()': " << calItem.getICSData();
|
||||
}
|
||||
|
||||
return calItem;
|
||||
|
@ -1109,17 +1065,13 @@ int CalendarItem::getCurrentCalendarIndex() {
|
|||
QSettings settings;
|
||||
|
||||
QString todoListSelectorSelectedItem =
|
||||
settings
|
||||
.value(QStringLiteral("TodoDialog/todoListSelectorSelectedItem"))
|
||||
.toString();
|
||||
settings.value(QStringLiteral("TodoDialog/todoListSelectorSelectedItem")).toString();
|
||||
if (!todoListSelectorSelectedItem.isEmpty()) {
|
||||
QStringList todoCalendarEnabledList =
|
||||
settings.value(QStringLiteral("ownCloud/todoCalendarEnabledList"))
|
||||
.toStringList();
|
||||
settings.value(QStringLiteral("ownCloud/todoCalendarEnabledList")).toStringList();
|
||||
|
||||
// search for the text in the todoCalendarEnabledList
|
||||
int index =
|
||||
todoCalendarEnabledList.indexOf(todoListSelectorSelectedItem);
|
||||
int index = todoCalendarEnabledList.indexOf(todoListSelectorSelectedItem);
|
||||
|
||||
if (index >= 0) {
|
||||
// return the index of the task list selector if we found it
|
||||
|
@ -1141,9 +1093,7 @@ QString CalendarItem::getCurrentCalendarUrl() {
|
|||
|
||||
if (index >= 0) {
|
||||
QStringList todoCalendarEnabledUrlList =
|
||||
settings
|
||||
.value(QStringLiteral("ownCloud/todoCalendarEnabledUrlList"))
|
||||
.toStringList();
|
||||
settings.value(QStringLiteral("ownCloud/todoCalendarEnabledUrlList")).toStringList();
|
||||
return todoCalendarEnabledUrlList.at(index);
|
||||
}
|
||||
|
||||
|
@ -1163,9 +1113,8 @@ void CalendarItem::alertTodoReminders() {
|
|||
QListIterator<CalendarItem> itr(calendarItemList);
|
||||
while (itr.hasNext()) {
|
||||
CalendarItem calItem = itr.next();
|
||||
QMessageBox::information(
|
||||
nullptr, QStringLiteral("Reminder"),
|
||||
"Reminder: <strong>" + calItem.getSummary() + "</strong>");
|
||||
QMessageBox::information(nullptr, QStringLiteral("Reminder"),
|
||||
"Reminder: <strong>" + calItem.getSummary() + "</strong>");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1188,9 +1137,8 @@ int CalendarItem::countAll() {
|
|||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const CalendarItem &calendarItem) {
|
||||
dbg.nospace() << "CalendarItem: <id>" << calendarItem.id << " <summary>"
|
||||
<< calendarItem.summary << " <url>" << calendarItem.url
|
||||
<< " <relatedUid>" << calendarItem.relatedUid
|
||||
dbg.nospace() << "CalendarItem: <id>" << calendarItem.id << " <summary>" << calendarItem.summary
|
||||
<< " <url>" << calendarItem.url << " <relatedUid>" << calendarItem.relatedUid
|
||||
<< " <calendar>" << calendarItem.calendar;
|
||||
return dbg.space();
|
||||
}
|
||||
|
|
|
@ -15,8 +15,7 @@ class CalendarItem {
|
|||
|
||||
int getId();
|
||||
bool getHasDirtyData();
|
||||
static bool addCalendarItem(const QString &name, const QString &fileName,
|
||||
const QString &text);
|
||||
static bool addCalendarItem(const QString &name, const QString &fileName, const QString &text);
|
||||
static CalendarItem fetch(int id);
|
||||
static QList<CalendarItem> search(const QString &text);
|
||||
static CalendarItem calendarItemFromQuery(const QSqlQuery &query);
|
||||
|
@ -29,11 +28,9 @@ class CalendarItem {
|
|||
bool remove();
|
||||
bool isFetched();
|
||||
bool isCompleted();
|
||||
static CalendarItem fetchByUrlAndCalendar(const QString &url,
|
||||
const QString &calendar);
|
||||
static bool addCalendarItemForRequest(const QString &calendar,
|
||||
const QUrl &url, const QString &etag,
|
||||
const QString &lastModifiedString);
|
||||
static CalendarItem fetchByUrlAndCalendar(const QString &url, const QString &calendar);
|
||||
static bool addCalendarItemForRequest(const QString &calendar, const QUrl &url,
|
||||
const QString &etag, const QString &lastModifiedString);
|
||||
static QList<CalendarItem> fetchAllByCalendar(const QString &calendar);
|
||||
static bool deleteAllByCalendar(const QString &calendar);
|
||||
QString getUrl();
|
||||
|
@ -58,9 +55,8 @@ class CalendarItem {
|
|||
void setETag(const QString &text);
|
||||
static QList<QUrl> fetchAllUrlsByCalendar(const QString &calendar);
|
||||
void setCalendar(const QString &text);
|
||||
static CalendarItem createNewTodoItem(
|
||||
const QString &summary, const QString &calendar,
|
||||
const QString &relatedUid = QLatin1String(""));
|
||||
static CalendarItem createNewTodoItem(const QString &summary, const QString &calendar,
|
||||
const QString &relatedUid = QLatin1String(""));
|
||||
void setUrl(const QUrl &url);
|
||||
void setUid(const QString &text);
|
||||
void setRelatedUid(const QString &text);
|
||||
|
@ -76,8 +72,7 @@ class CalendarItem {
|
|||
void setAlarmDate(const QDateTime &dateTime);
|
||||
static QList<CalendarItem> fetchAllForReminderAlert();
|
||||
static void alertTodoReminders();
|
||||
static QList<QString> searchAsUidList(const QString &text,
|
||||
const QString &calendar);
|
||||
static QList<QString> searchAsUidList(const QString &text, const QString &calendar);
|
||||
static QList<CalendarItem> fetchAllForSystemTray(int limit = 10);
|
||||
static bool removeAll();
|
||||
static int countAll();
|
||||
|
@ -104,13 +99,11 @@ class CalendarItem {
|
|||
QHash<QString, QString> icsDataHash;
|
||||
QStringList icsDataKeyList;
|
||||
static QString decodeICSDataLine(QString line);
|
||||
static QString findFreeHashKey(QHash<QString, QString> *hash, QString key,
|
||||
int number = 0);
|
||||
static QString findFreeHashKey(QHash<QString, QString> *hash, QString key, int number = 0);
|
||||
void generateICSDataHash();
|
||||
void updateICSDataKeyListFromHash();
|
||||
void updateSortPriority();
|
||||
QString getICSDataAttributeInBlock(const QString &block,
|
||||
const QString &attributeName);
|
||||
QString getICSDataAttributeInBlock(const QString &block, const QString &attributeName);
|
||||
bool removeICSDataBlock(const QString &block);
|
||||
bool addVALARMBlockToICS();
|
||||
static QDateTime getDateTimeFromString(const QString &dateString);
|
||||
|
|
|
@ -17,10 +17,7 @@
|
|||
#include "services/databaseservice.h"
|
||||
|
||||
CloudConnection::CloudConnection()
|
||||
: name(QString()),
|
||||
serverUrl(QString()),
|
||||
username(QString()),
|
||||
password(QString()) {
|
||||
: name(QString()), serverUrl(QString()), username(QString()), password(QString()) {
|
||||
id = 0;
|
||||
priority = 0;
|
||||
}
|
||||
|
@ -31,9 +28,7 @@ QString CloudConnection::getName() { return this->name; }
|
|||
|
||||
QString CloudConnection::getServerUrl() { return this->serverUrl; }
|
||||
|
||||
QString CloudConnection::getServerUrlPath() {
|
||||
return QUrl(this->serverUrl).path();
|
||||
}
|
||||
QString CloudConnection::getServerUrlPath() { return QUrl(this->serverUrl).path(); }
|
||||
|
||||
QString CloudConnection::getServerUrlWithoutPath() {
|
||||
QString serverUrlWithoutPath = serverUrl;
|
||||
|
@ -42,8 +37,7 @@ QString CloudConnection::getServerUrlWithoutPath() {
|
|||
if (!serverUrlPath.isEmpty()) {
|
||||
// remove the path from the server url
|
||||
serverUrlWithoutPath.replace(
|
||||
QRegularExpression(QRegularExpression::escape(serverUrlPath) + "$"),
|
||||
QString());
|
||||
QRegularExpression(QRegularExpression::escape(serverUrlPath) + "$"), QString());
|
||||
}
|
||||
|
||||
return serverUrlWithoutPath;
|
||||
|
@ -64,8 +58,7 @@ CloudConnection CloudConnection::firstCloudConnection() {
|
|||
return list.count() > 0 ? list[0] : CloudConnection();
|
||||
}
|
||||
|
||||
CloudConnection CloudConnection::currentCloudConnection(
|
||||
bool ignoreTableWarning) {
|
||||
CloudConnection CloudConnection::currentCloudConnection(bool ignoreTableWarning) {
|
||||
NoteFolder noteFolder = NoteFolder::currentNoteFolder();
|
||||
const int id = noteFolder.getCloudConnectionId();
|
||||
|
||||
|
@ -74,40 +67,31 @@ CloudConnection CloudConnection::currentCloudConnection(
|
|||
|
||||
CloudConnection CloudConnection::currentTodoCalendarCloudConnection() {
|
||||
QSettings settings;
|
||||
const int id =
|
||||
settings
|
||||
.value(QStringLiteral("ownCloud/todoCalendarCloudConnectionId"),
|
||||
firstCloudConnection().getId())
|
||||
.toInt();
|
||||
const int id = settings
|
||||
.value(QStringLiteral("ownCloud/todoCalendarCloudConnectionId"),
|
||||
firstCloudConnection().getId())
|
||||
.toInt();
|
||||
|
||||
return CloudConnection::fetch(id);
|
||||
}
|
||||
|
||||
void CloudConnection::setName(const QString &text) {
|
||||
this->name = text.trimmed();
|
||||
}
|
||||
void CloudConnection::setName(const QString &text) { this->name = text.trimmed(); }
|
||||
|
||||
void CloudConnection::setServerUrl(const QString &text) {
|
||||
this->serverUrl = text.trimmed();
|
||||
}
|
||||
void CloudConnection::setServerUrl(const QString &text) { this->serverUrl = text.trimmed(); }
|
||||
|
||||
void CloudConnection::setUsername(const QString &text) {
|
||||
this->username = text.trimmed();
|
||||
}
|
||||
void CloudConnection::setUsername(const QString &text) { this->username = text.trimmed(); }
|
||||
|
||||
void CloudConnection::setAccountId(const QString &text) {
|
||||
this->accountId = text.trimmed();
|
||||
}
|
||||
void CloudConnection::setAccountId(const QString &text) { this->accountId = text.trimmed(); }
|
||||
|
||||
void CloudConnection::setPassword(const QString &text) {
|
||||
this->password = text.trimmed();
|
||||
}
|
||||
void CloudConnection::setPassword(const QString &text) { this->password = text.trimmed(); }
|
||||
|
||||
void CloudConnection::setPriority(int value) { this->priority = value; }
|
||||
void CloudConnection::setAppQOwnNotesAPIEnabled(bool value) { this->appQOwnNotesAPIEnabled = value; }
|
||||
void CloudConnection::setAppQOwnNotesAPIEnabled(bool value) {
|
||||
this->appQOwnNotesAPIEnabled = value;
|
||||
}
|
||||
|
||||
bool CloudConnection::create(const QString &name, const QString &serverUrl,
|
||||
const QString &username, const QString &password) {
|
||||
bool CloudConnection::create(const QString &name, const QString &serverUrl, const QString &username,
|
||||
const QString &password) {
|
||||
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("disk"));
|
||||
QSqlQuery query(db);
|
||||
|
||||
|
@ -130,8 +114,7 @@ CloudConnection CloudConnection::fetch(int id, bool ignoreTableWarning) {
|
|||
|
||||
CloudConnection cloudConnection;
|
||||
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT * FROM cloudConnection WHERE id = :id"));
|
||||
query.prepare(QStringLiteral("SELECT * FROM cloudConnection WHERE id = :id"));
|
||||
query.bindValue(QStringLiteral(":id"), id);
|
||||
|
||||
if (!query.exec()) {
|
||||
|
@ -149,8 +132,7 @@ int CloudConnection::countAll() {
|
|||
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("disk"));
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT COUNT(*) AS cnt FROM cloudConnection"));
|
||||
query.prepare(QStringLiteral("SELECT COUNT(*) AS cnt FROM cloudConnection"));
|
||||
|
||||
if (!query.exec()) {
|
||||
qWarning() << __func__ << ": " << query.lastError();
|
||||
|
@ -176,8 +158,7 @@ bool CloudConnection::remove() {
|
|||
}
|
||||
}
|
||||
|
||||
CloudConnection CloudConnection::cloudConnectionFromQuery(
|
||||
const QSqlQuery &query) {
|
||||
CloudConnection CloudConnection::cloudConnectionFromQuery(const QSqlQuery &query) {
|
||||
CloudConnection cloudConnection;
|
||||
cloudConnection.fillFromQuery(query);
|
||||
return cloudConnection;
|
||||
|
@ -192,16 +173,14 @@ bool CloudConnection::fillFromQuery(const QSqlQuery &query) {
|
|||
query.value(QStringLiteral("password")).toString());
|
||||
this->priority = query.value(QStringLiteral("priority")).toInt();
|
||||
|
||||
const int databaseVersion = DatabaseService::getAppData(
|
||||
QStringLiteral("database_version")).toInt();
|
||||
const int databaseVersion =
|
||||
DatabaseService::getAppData(QStringLiteral("database_version")).toInt();
|
||||
|
||||
this->accountId = databaseVersion >= 41 ?
|
||||
query.value(QStringLiteral("account_id")).toString() :
|
||||
QStringLiteral("");
|
||||
this->accountId = databaseVersion >= 41 ? query.value(QStringLiteral("account_id")).toString()
|
||||
: QStringLiteral("");
|
||||
|
||||
this->appQOwnNotesAPIEnabled = databaseVersion >= 34 ?
|
||||
query.value(QStringLiteral("qownnotesapi_enabled")).toBool() :
|
||||
true;
|
||||
this->appQOwnNotesAPIEnabled =
|
||||
databaseVersion >= 34 ? query.value(QStringLiteral("qownnotesapi_enabled")).toBool() : true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -212,8 +191,7 @@ QList<CloudConnection> CloudConnection::fetchAll() {
|
|||
|
||||
QList<CloudConnection> cloudConnectionList;
|
||||
|
||||
query.prepare(QStringLiteral(
|
||||
"SELECT * FROM cloudConnection ORDER BY priority ASC, id ASC"));
|
||||
query.prepare(QStringLiteral("SELECT * FROM cloudConnection ORDER BY priority ASC, id ASC"));
|
||||
if (!query.exec()) {
|
||||
qWarning() << __func__ << ": " << query.lastError();
|
||||
} else {
|
||||
|
@ -255,8 +233,7 @@ bool CloudConnection::store() {
|
|||
query.bindValue(QStringLiteral(":password"),
|
||||
CryptoService::instance()->encryptToString(this->password));
|
||||
query.bindValue(QStringLiteral(":priority"), this->priority);
|
||||
query.bindValue(QStringLiteral(":qownnotesapi_enabled"),
|
||||
this->appQOwnNotesAPIEnabled);
|
||||
query.bindValue(QStringLiteral(":qownnotesapi_enabled"), this->appQOwnNotesAPIEnabled);
|
||||
|
||||
if (!query.exec()) {
|
||||
// on error
|
||||
|
@ -324,9 +301,7 @@ bool CloudConnection::isFetched() { return (this->id > 0); }
|
|||
/**
|
||||
* Checks if this note folder is the current one
|
||||
*/
|
||||
bool CloudConnection::isCurrent() {
|
||||
return currentCloudConnection().getId() == id;
|
||||
}
|
||||
bool CloudConnection::isCurrent() { return currentCloudConnection().getId() == id; }
|
||||
|
||||
/**
|
||||
* Migrate the connections settings to a CloudConnection object
|
||||
|
@ -337,10 +312,8 @@ bool CloudConnection::migrateToCloudConnections() {
|
|||
}
|
||||
|
||||
QSettings settings;
|
||||
const QString serverUrl =
|
||||
settings.value(QStringLiteral("ownCloud/serverUrl")).toString();
|
||||
const QString username =
|
||||
settings.value(QStringLiteral("ownCloud/userName")).toString();
|
||||
const QString serverUrl = settings.value(QStringLiteral("ownCloud/serverUrl")).toString();
|
||||
const QString username = settings.value(QStringLiteral("ownCloud/userName")).toString();
|
||||
const QString password = CryptoService::instance()->decryptToString(
|
||||
settings.value(QStringLiteral("ownCloud/password")).toString());
|
||||
|
||||
|
@ -381,10 +354,8 @@ QList<int> CloudConnection::fetchUsedCloudConnectionsIds() {
|
|||
|
||||
QDebug operator<<(QDebug dbg, const CloudConnection &cloudConnection) {
|
||||
dbg.nospace() << "CloudConnection: <id>" << cloudConnection.id << " <name>"
|
||||
<< cloudConnection.name << " <serverUrl>"
|
||||
<< cloudConnection.serverUrl << " <username>"
|
||||
<< cloudConnection.username << " <accountId>"
|
||||
<< cloudConnection.accountId << " <priority>"
|
||||
<< cloudConnection.priority;
|
||||
<< cloudConnection.name << " <serverUrl>" << cloudConnection.serverUrl
|
||||
<< " <username>" << cloudConnection.username << " <accountId>"
|
||||
<< cloudConnection.accountId << " <priority>" << cloudConnection.priority;
|
||||
return dbg.space();
|
||||
}
|
||||
|
|
|
@ -7,14 +7,13 @@ class CloudConnection {
|
|||
explicit CloudConnection();
|
||||
|
||||
int getId();
|
||||
static bool create(const QString &name, const QString &serverUrl,
|
||||
const QString &username, const QString &password);
|
||||
static bool create(const QString &name, const QString &serverUrl, const QString &username,
|
||||
const QString &password);
|
||||
static CloudConnection fetch(int id, bool ignoreTableWarning = false);
|
||||
static CloudConnection cloudConnectionFromQuery(const QSqlQuery &query);
|
||||
bool store();
|
||||
bool storeMigratedCloudConnection();
|
||||
friend QDebug operator<<(QDebug dbg,
|
||||
const CloudConnection &CloudConnection);
|
||||
friend QDebug operator<<(QDebug dbg, const CloudConnection &CloudConnection);
|
||||
bool exists();
|
||||
bool fillFromQuery(const QSqlQuery &query);
|
||||
bool remove();
|
||||
|
@ -37,8 +36,7 @@ class CloudConnection {
|
|||
static int countAll();
|
||||
static bool migrateToCloudConnections();
|
||||
bool isCurrent();
|
||||
static CloudConnection currentCloudConnection(
|
||||
bool ignoreTableWarning = false);
|
||||
static CloudConnection currentCloudConnection(bool ignoreTableWarning = false);
|
||||
static CloudConnection firstCloudConnection();
|
||||
static CloudConnection currentTodoCalendarCloudConnection();
|
||||
QString getServerUrlPath();
|
||||
|
|
|
@ -26,16 +26,14 @@ CommandSnippet::CommandSnippet(QString command, QString description, QStringList
|
|||
QJsonObject CommandSnippet::jsonObject() const {
|
||||
QJsonObject commandSnippetObject;
|
||||
commandSnippetObject.insert(QStringLiteral("command"), QJsonValue::fromVariant(command));
|
||||
commandSnippetObject.insert(QStringLiteral("tags"),
|
||||
QJsonValue::fromVariant(tags));
|
||||
commandSnippetObject.insert(QStringLiteral("tags"), QJsonValue::fromVariant(tags));
|
||||
commandSnippetObject.insert(QStringLiteral("description"),
|
||||
QJsonValue::fromVariant(description));
|
||||
QJsonValue::fromVariant(description));
|
||||
return commandSnippetObject;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const CommandSnippet &commandSnippet) {
|
||||
dbg.nospace() << " <command>" << commandSnippet.command
|
||||
<< " <tags>" << commandSnippet.tags
|
||||
dbg.nospace() << " <command>" << commandSnippet.command << " <tags>" << commandSnippet.tags
|
||||
<< " <description>" << commandSnippet.description;
|
||||
return dbg.space();
|
||||
}
|
||||
|
@ -51,13 +49,12 @@ bool CommandSnippet::operator==(const CommandSnippet &commandSnippet) const {
|
|||
* @return
|
||||
*/
|
||||
QVector<CommandSnippet> CommandSnippet::parseCommandSnippets(const QString &text,
|
||||
bool withPrefixOnly) {
|
||||
bool withPrefixOnly) {
|
||||
QRegularExpressionMatchIterator i;
|
||||
QVector<CommandSnippet> commandSnippets;
|
||||
auto regex = QRegularExpression(
|
||||
withPrefixOnly ? QStringLiteral(R"([-*]\s+cmd:\s+`(.+?)`(.*)$)") :
|
||||
QStringLiteral(R"([-*]\s+`(.+?)`(.*)$)"),
|
||||
QRegularExpression::MultilineOption);
|
||||
auto regex = QRegularExpression(withPrefixOnly ? QStringLiteral(R"([-*]\s+cmd:\s+`(.+?)`(.*)$)")
|
||||
: QStringLiteral(R"([-*]\s+`(.+?)`(.*)$)"),
|
||||
QRegularExpression::MultilineOption);
|
||||
|
||||
// parse command snippets like "- `my-command` #tag1 #tag2 description text"
|
||||
// with optional tags and description
|
||||
|
@ -72,16 +69,15 @@ QVector<CommandSnippet> CommandSnippet::parseCommandSnippets(const QString &text
|
|||
|
||||
if (!additionalText.isEmpty()) {
|
||||
QRegularExpressionMatchIterator addIterator =
|
||||
QRegularExpression(QStringLiteral(R"(#([^\s#]+))"))
|
||||
.globalMatch(additionalText);
|
||||
QRegularExpression(QStringLiteral(R"(#([^\s#]+))")).globalMatch(additionalText);
|
||||
while (addIterator.hasNext()) {
|
||||
QRegularExpressionMatch addMatch = addIterator.next();
|
||||
QString tag = addMatch.captured(1).trimmed();
|
||||
|
||||
if (!tags.contains(tag)) {
|
||||
tags << tag;
|
||||
additionalText.remove(QRegularExpression(
|
||||
"#" + QRegularExpression::escape(tag) + "\\b"));
|
||||
additionalText.remove(
|
||||
QRegularExpression("#" + QRegularExpression::escape(tag) + "\\b"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,8 +109,7 @@ QVector<CommandSnippet> CommandSnippet::parseCommandSnippets(const QString &text
|
|||
|
||||
if (!additionalText.isEmpty()) {
|
||||
QRegularExpressionMatchIterator addIterator =
|
||||
QRegularExpression(QStringLiteral(R"(#([^\s#]+))"))
|
||||
.globalMatch(additionalText);
|
||||
QRegularExpression(QStringLiteral(R"(#([^\s#]+))")).globalMatch(additionalText);
|
||||
while (addIterator.hasNext()) {
|
||||
QRegularExpressionMatch addMatch = addIterator.next();
|
||||
QString tag = addMatch.captured(1).trimmed();
|
||||
|
@ -147,7 +142,7 @@ QString CommandSnippet::commandSnippetsWebServiceJsonText(
|
|||
|
||||
QJsonObject commandSnippetResultObject;
|
||||
commandSnippetResultObject.insert(QStringLiteral("type"),
|
||||
QJsonValue::fromVariant("commandSnippets"));
|
||||
QJsonValue::fromVariant("commandSnippets"));
|
||||
commandSnippetResultObject.insert(QStringLiteral("data"), commandSnippetObjectList);
|
||||
|
||||
QJsonDocument doc(commandSnippetResultObject);
|
||||
|
@ -161,7 +156,7 @@ QString CommandSnippet::commandSnippetsWebServiceJsonText(
|
|||
* @return
|
||||
*/
|
||||
QString CommandSnippet::parsedCommandSnippetsWebServiceJsonText(const QString &text,
|
||||
bool withPrefixOnly) {
|
||||
bool withPrefixOnly) {
|
||||
return commandSnippetsWebServiceJsonText(parseCommandSnippets(text, withPrefixOnly));
|
||||
}
|
||||
|
||||
|
@ -185,7 +180,8 @@ void CommandSnippet::mergeInList(QVector<CommandSnippet> &commandSnippets) {
|
|||
/**
|
||||
* Merges a commandSnippet into a list of commandSnippets
|
||||
*/
|
||||
void CommandSnippet::mergeInList(QVector<CommandSnippet> &commandSnippets, CommandSnippet &commandSnippet) {
|
||||
void CommandSnippet::mergeInList(QVector<CommandSnippet> &commandSnippets,
|
||||
CommandSnippet &commandSnippet) {
|
||||
commandSnippet.mergeInList(commandSnippets);
|
||||
}
|
||||
|
||||
|
@ -210,7 +206,7 @@ void CommandSnippet::merge(CommandSnippet &commandSnippet) {
|
|||
* Merges a list of commandSnippets into another
|
||||
*/
|
||||
void CommandSnippet::mergeListInList(const QVector<CommandSnippet> &sourceCommandSnippets,
|
||||
QVector<CommandSnippet> &destinationCommandSnippets) {
|
||||
QVector<CommandSnippet> &destinationCommandSnippets) {
|
||||
for (CommandSnippet commandSnippet : sourceCommandSnippets) {
|
||||
commandSnippet.mergeInList(destinationCommandSnippets);
|
||||
}
|
||||
|
|
|
@ -13,17 +13,18 @@ class CommandSnippet {
|
|||
public:
|
||||
CommandSnippet();
|
||||
explicit CommandSnippet(QString command, QString description = QString(),
|
||||
QStringList tagList = QStringList());
|
||||
QStringList tagList = QStringList());
|
||||
friend QDebug operator<<(QDebug dbg, const CommandSnippet &commandSnippet);
|
||||
QJsonObject jsonObject() const;
|
||||
static QVector<CommandSnippet> parseCommandSnippets(const QString &text,
|
||||
bool withPrefixOnly = false);
|
||||
bool withPrefixOnly = false);
|
||||
static QString commandSnippetsWebServiceJsonText(
|
||||
const QVector<CommandSnippet> &commandSnippets);
|
||||
static QString parsedCommandSnippetsWebServiceJsonText(
|
||||
const QString &text, bool withPrefixOnly = false);
|
||||
static QString parsedCommandSnippetsWebServiceJsonText(const QString &text,
|
||||
bool withPrefixOnly = false);
|
||||
bool operator==(const CommandSnippet &commandSnippet) const;
|
||||
static void mergeInList(QVector<CommandSnippet> &commandSnippets, CommandSnippet &commandSnippet);
|
||||
static void mergeInList(QVector<CommandSnippet> &commandSnippets,
|
||||
CommandSnippet &commandSnippet);
|
||||
static void mergeListInList(const QVector<CommandSnippet> &sourceCommandSnippets,
|
||||
QVector<CommandSnippet> &destinationCommandSnippets);
|
||||
void mergeInList(QVector<CommandSnippet> &commandSnippets);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -43,25 +43,20 @@ class Note {
|
|||
|
||||
void setCryptoKey(const qint64 cryptoKey);
|
||||
|
||||
static bool addNote(const QString &name, const QString &fileName,
|
||||
const QString &text);
|
||||
static bool addNote(const QString &name, const QString &fileName, const QString &text);
|
||||
|
||||
static Note fetch(int id);
|
||||
|
||||
static Note fetchByName(const QRegularExpression ®Exp,
|
||||
int noteSubFolderId = -1);
|
||||
static Note fetchByName(const QRegularExpression ®Exp, int noteSubFolderId = -1);
|
||||
|
||||
static Note fetchByFileName(const QString &fileName,
|
||||
int noteSubFolderId = -1);
|
||||
static Note fetchByFileName(const QString &fileName, int noteSubFolderId = -1);
|
||||
|
||||
static Note fetchByFileName(const QString &fileName,
|
||||
const QString ¬eSubFolderPathData);
|
||||
static Note fetchByFileName(const QString &fileName, const QString ¬eSubFolderPathData);
|
||||
|
||||
static Note fetchByName(const QString &name, int noteSubFolderId = -1);
|
||||
|
||||
static Note fetchByName(const QString &name,
|
||||
const QString ¬eSubFolderPathData,
|
||||
const QString& pathDataSeparator = QStringLiteral("\n"));
|
||||
static Note fetchByName(const QString &name, const QString ¬eSubFolderPathData,
|
||||
const QString &pathDataSeparator = QStringLiteral("\n"));
|
||||
|
||||
static int fetchNoteIdByName(const QString &name, int noteSubFolderId = -1);
|
||||
|
||||
|
@ -73,11 +68,10 @@ class Note {
|
|||
|
||||
static QVector<Note> search(const QString &text);
|
||||
|
||||
static QVector<QString> searchAsNameListInCurrentNoteSubFolder(
|
||||
const QString &text, bool searchInNameOnly = false);
|
||||
static QVector<QString> searchAsNameListInCurrentNoteSubFolder(const QString &text,
|
||||
bool searchInNameOnly = false);
|
||||
|
||||
static QVector<QString> searchAsNameList(const QString &text,
|
||||
bool searchInNameOnly = false);
|
||||
static QVector<QString> searchAsNameList(const QString &text, bool searchInNameOnly = false);
|
||||
|
||||
static QStringList fetchNoteNamesInCurrentNoteSubFolder();
|
||||
|
||||
|
@ -96,15 +90,13 @@ class Note {
|
|||
|
||||
static QString defaultNoteFileExtension();
|
||||
|
||||
static QStringList noteFileExtensionList(
|
||||
const QString &prefix = QString());
|
||||
static QStringList noteFileExtensionList(const QString &prefix = QString());
|
||||
|
||||
static QString getFullFilePathForFile(const QString &fileName);
|
||||
|
||||
QString getFilePathRelativeToNote(const Note ¬e) const;
|
||||
|
||||
static int storeDirtyNotesToDisk(Note ¤tNote,
|
||||
bool *currentNoteChanged = nullptr,
|
||||
static int storeDirtyNotesToDisk(Note ¤tNote, bool *currentNoteChanged = nullptr,
|
||||
bool *noteWasRenamed = nullptr,
|
||||
bool *currentNoteTextChanged = nullptr);
|
||||
|
||||
|
@ -114,8 +106,7 @@ class Note {
|
|||
|
||||
bool operator==(const Note ¬e) const;
|
||||
|
||||
void createFromFile(QFile &file, int noteSubFolderId = 0,
|
||||
bool withNoteNameHook = false);
|
||||
void createFromFile(QFile &file, int noteSubFolderId = 0, bool withNoteNameHook = false);
|
||||
|
||||
static bool deleteAll();
|
||||
|
||||
|
@ -138,18 +129,15 @@ class Note {
|
|||
bool remove(bool withFile = false);
|
||||
|
||||
QString toMarkdownHtml(const QString ¬esPath, int maxImageWidth = 980,
|
||||
bool forExport = false, bool decrypt = true,
|
||||
bool base64Images = false);
|
||||
bool forExport = false, bool decrypt = true, bool base64Images = false);
|
||||
|
||||
bool isFetched() const;
|
||||
|
||||
bool copyToPath(const QString &destinationPath,
|
||||
QString noteFolderPath = QString());
|
||||
bool copyToPath(const QString &destinationPath, QString noteFolderPath = QString());
|
||||
|
||||
bool exportToPath(const QString &destinationPath, bool withAttachedFiles = false);
|
||||
|
||||
bool moveToPath(const QString &destinationPath,
|
||||
const QString ¬eFolderPath = QString());
|
||||
bool moveToPath(const QString &destinationPath, const QString ¬eFolderPath = QString());
|
||||
|
||||
static QString generateTextForLink(QString text);
|
||||
|
||||
|
@ -199,15 +187,14 @@ class Note {
|
|||
|
||||
bool modifyNoteTextFileNameFromQMLHook();
|
||||
|
||||
static QVector<int> searchInNotes(QString query,
|
||||
bool ignoreNoteSubFolder = false,
|
||||
static QVector<int> searchInNotes(QString query, bool ignoreNoteSubFolder = false,
|
||||
int noteSubFolderId = -1);
|
||||
|
||||
int countSearchTextInNote(const QString &search) const;
|
||||
|
||||
static QStringList buildQueryStringList(
|
||||
QString searchString, bool escapeForRegularExpression = false,
|
||||
bool removeSearchPrefix = false);
|
||||
static QStringList buildQueryStringList(QString searchString,
|
||||
bool escapeForRegularExpression = false,
|
||||
bool removeSearchPrefix = false);
|
||||
|
||||
QString fileBaseName(bool withFullName = false);
|
||||
|
||||
|
@ -223,8 +210,7 @@ class Note {
|
|||
|
||||
static QVector<int> noteIdListFromNoteList(const QVector<Note> ¬eList);
|
||||
|
||||
static int countByNoteSubFolderId(int noteSubFolderId = 0,
|
||||
bool recursive = false);
|
||||
static int countByNoteSubFolderId(int noteSubFolderId = 0, bool recursive = false);
|
||||
|
||||
int getNoteSubFolderId() const;
|
||||
|
||||
|
@ -258,8 +244,7 @@ class Note {
|
|||
|
||||
int getFileSize() const;
|
||||
|
||||
static Note updateOrCreateFromFile(QFile &file,
|
||||
const NoteSubFolder ¬eSubFolder,
|
||||
static Note updateOrCreateFromFile(QFile &file, const NoteSubFolder ¬eSubFolder,
|
||||
bool withNoteNameHook = false);
|
||||
|
||||
static QVector<int> fetchAllIds(int limit = -1, int offset = -1);
|
||||
|
@ -270,12 +255,10 @@ class Note {
|
|||
|
||||
static QString createNoteHeader(const QString &name);
|
||||
|
||||
QString getInsertMediaMarkdown(QFile *file, bool addNewLine = true,
|
||||
bool returnUrlOnly = false,
|
||||
QString getInsertMediaMarkdown(QFile *file, bool addNewLine = true, bool returnUrlOnly = false,
|
||||
QString title = QString()) const;
|
||||
|
||||
QString getInsertAttachmentMarkdown(QFile *file,
|
||||
QString title = QString(),
|
||||
QString getInsertAttachmentMarkdown(QFile *file, QString title = QString(),
|
||||
bool returnUrlOnly = false,
|
||||
QString fileBaseName = QString()) const;
|
||||
|
||||
|
@ -283,8 +266,8 @@ class Note {
|
|||
|
||||
QString downloadUrlToMedia(const QUrl &url, bool returnUrlOnly = false);
|
||||
|
||||
QString importMediaFromBase64(
|
||||
QString &data, const QString &imageSuffix = QStringLiteral("dat"));
|
||||
QString importMediaFromBase64(QString &data,
|
||||
const QString &imageSuffix = QStringLiteral("dat"));
|
||||
|
||||
QString importMediaFromDataUrl(const QString &dataUrl);
|
||||
|
||||
|
@ -294,9 +277,8 @@ class Note {
|
|||
|
||||
void generateFileNameFromName();
|
||||
|
||||
QString textToMarkdownHtml(QString str, const QString ¬esPath,
|
||||
int maxImageWidth = 980, bool forExport = false,
|
||||
bool base64Images = false);
|
||||
QString textToMarkdownHtml(QString str, const QString ¬esPath, int maxImageWidth = 980,
|
||||
bool forExport = false, bool base64Images = false);
|
||||
|
||||
QStringList getMediaFileList();
|
||||
|
||||
|
@ -330,11 +312,10 @@ class Note {
|
|||
|
||||
void resetNoteTextHtmlConversionHash();
|
||||
|
||||
QString getFileURLFromFileName(QString fileName,
|
||||
bool urlDecodeFileName = false,
|
||||
QString getFileURLFromFileName(QString fileName, bool urlDecodeFileName = false,
|
||||
bool withFragment = false) const;
|
||||
|
||||
static QString getURLFragmentFromFileName(const QString& fileName);
|
||||
static QString getURLFragmentFromFileName(const QString &fileName);
|
||||
|
||||
static bool fileUrlIsNoteInCurrentNoteFolder(const QUrl &url);
|
||||
|
||||
|
@ -348,8 +329,7 @@ class Note {
|
|||
|
||||
static Note fetchByRelativeFilePath(const QString &relativePath);
|
||||
|
||||
QString getNoteUrlForLinkingTo(const Note ¬e,
|
||||
bool forceLegacy = false) const;
|
||||
QString getNoteUrlForLinkingTo(const Note ¬e, bool forceLegacy = false) const;
|
||||
|
||||
QString mediaUrlStringForFileName(const QString &fileName) const;
|
||||
|
||||
|
@ -379,7 +359,7 @@ class Note {
|
|||
|
||||
QStringList getHeadingList();
|
||||
|
||||
static bool applyIgnoredNotesSetting(QStringList& fileNames);
|
||||
static bool applyIgnoredNotesSetting(QStringList &fileNames);
|
||||
|
||||
protected:
|
||||
int _id;
|
||||
|
@ -402,7 +382,7 @@ class Note {
|
|||
unsigned int _sharePermissions;
|
||||
bool _hasDirtyData;
|
||||
|
||||
static QRegularExpression getEncryptedNoteTextRegularExpression() ;
|
||||
static QRegularExpression getEncryptedNoteTextRegularExpression();
|
||||
QString getEncryptedNoteText() const;
|
||||
|
||||
static const QString getNoteURL(const QString &baseName);
|
||||
|
|
|
@ -17,9 +17,7 @@
|
|||
#include "notesubfolder.h"
|
||||
|
||||
NoteFolder::NoteFolder()
|
||||
: name(QLatin1String("")),
|
||||
localPath(QLatin1String("")),
|
||||
remotePath(QLatin1String("")) {
|
||||
: name(QLatin1String("")), localPath(QLatin1String("")), remotePath(QLatin1String("")) {
|
||||
id = 0;
|
||||
cloudConnectionId = 1;
|
||||
priority = 0;
|
||||
|
@ -70,12 +68,10 @@ void NoteFolder::setActiveNoteSubFolder(const NoteSubFolder ¬eSubFolder) {
|
|||
this->activeNoteSubFolderData = noteSubFolder.pathData();
|
||||
}
|
||||
|
||||
void NoteFolder::resetActiveNoteSubFolder() {
|
||||
this->activeNoteSubFolderData.clear();
|
||||
}
|
||||
void NoteFolder::resetActiveNoteSubFolder() { this->activeNoteSubFolderData.clear(); }
|
||||
|
||||
bool NoteFolder::create(const QString &name, const QString &localPath,
|
||||
int cloudConnectionId, const QString &remotePath) {
|
||||
bool NoteFolder::create(const QString &name, const QString &localPath, int cloudConnectionId,
|
||||
const QString &remotePath) {
|
||||
const QSqlDatabase db = QSqlDatabase::database(QStringLiteral("disk"));
|
||||
QSqlQuery query(db);
|
||||
|
||||
|
@ -142,12 +138,9 @@ bool NoteFolder::remove() {
|
|||
} else {
|
||||
// remove the settings of the note folder
|
||||
QSettings settings;
|
||||
settings.remove(QStringLiteral("NoteHistory-") +
|
||||
QString::number(this->id));
|
||||
settings.remove(QStringLiteral("NoteHistoryCurrentIndex-") +
|
||||
QString::number(this->id));
|
||||
settings.remove(QStringLiteral("NoteFolder-") +
|
||||
QString::number(this->id));
|
||||
settings.remove(QStringLiteral("NoteHistory-") + QString::number(this->id));
|
||||
settings.remove(QStringLiteral("NoteHistoryCurrentIndex-") + QString::number(this->id));
|
||||
settings.remove(QStringLiteral("NoteFolder-") + QString::number(this->id));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -161,12 +154,10 @@ NoteFolder NoteFolder::noteFolderFromQuery(const QSqlQuery &query) {
|
|||
bool NoteFolder::fillFromQuery(const QSqlQuery &query) {
|
||||
this->id = query.value(QStringLiteral("id")).toInt();
|
||||
this->name = query.value(QStringLiteral("name")).toString();
|
||||
this->cloudConnectionId =
|
||||
query.value(QStringLiteral("cloud_connection_id")).toInt();
|
||||
this->cloudConnectionId = query.value(QStringLiteral("cloud_connection_id")).toInt();
|
||||
this->remotePath = query.value(QStringLiteral("remote_path")).toString();
|
||||
this->priority = query.value(QStringLiteral("priority")).toInt();
|
||||
this->showSubfolders =
|
||||
query.value(QStringLiteral("show_subfolders")).toBool();
|
||||
this->showSubfolders = query.value(QStringLiteral("show_subfolders")).toBool();
|
||||
this->useGit = query.value(QStringLiteral("use_git")).toBool();
|
||||
this->activeTagId = query.value(QStringLiteral("active_tag_id")).toInt();
|
||||
this->activeNoteSubFolderData =
|
||||
|
@ -185,8 +176,7 @@ QList<NoteFolder> NoteFolder::fetchAll() {
|
|||
|
||||
QList<NoteFolder> noteFolderList;
|
||||
|
||||
query.prepare(QStringLiteral(
|
||||
"SELECT * FROM noteFolder ORDER BY priority ASC, id ASC"));
|
||||
query.prepare(QStringLiteral("SELECT * FROM noteFolder ORDER BY priority ASC, id ASC"));
|
||||
if (!query.exec()) {
|
||||
qWarning() << __func__ << ": " << query.lastError();
|
||||
} else {
|
||||
|
@ -206,41 +196,38 @@ bool NoteFolder::store() {
|
|||
QSqlQuery query(db);
|
||||
|
||||
if (this->id > 0) {
|
||||
query.prepare(QStringLiteral(
|
||||
"UPDATE noteFolder SET name = :name, local_path = :localPath, "
|
||||
"cloud_connection_id = :cloudConnectionId, "
|
||||
"remote_path = :remotePath, priority = :priority, "
|
||||
"active_tag_id = :activeTagId, show_subfolders = "
|
||||
":showSubfolders, active_note_sub_folder_data = "
|
||||
":activeNoteSubFolderData, use_git = :useGit WHERE "
|
||||
"id = :id"));
|
||||
query.prepare(
|
||||
QStringLiteral("UPDATE noteFolder SET name = :name, local_path = :localPath, "
|
||||
"cloud_connection_id = :cloudConnectionId, "
|
||||
"remote_path = :remotePath, priority = :priority, "
|
||||
"active_tag_id = :activeTagId, show_subfolders = "
|
||||
":showSubfolders, active_note_sub_folder_data = "
|
||||
":activeNoteSubFolderData, use_git = :useGit WHERE "
|
||||
"id = :id"));
|
||||
query.bindValue(QStringLiteral(":id"), this->id);
|
||||
} else {
|
||||
query.prepare(QStringLiteral(
|
||||
"INSERT INTO noteFolder (name, local_path, cloud_connection_id, "
|
||||
"remote_path, priority, active_tag_id, "
|
||||
"show_subfolders, active_note_sub_folder_data, use_git)"
|
||||
" VALUES (:name, :localPath, :cloudConnectionId, "
|
||||
":remotePath, :priority, :activeTagId, "
|
||||
":showSubfolders, :activeNoteSubFolderData, :useGit)"));
|
||||
query.prepare(
|
||||
QStringLiteral("INSERT INTO noteFolder (name, local_path, cloud_connection_id, "
|
||||
"remote_path, priority, active_tag_id, "
|
||||
"show_subfolders, active_note_sub_folder_data, use_git)"
|
||||
" VALUES (:name, :localPath, :cloudConnectionId, "
|
||||
":remotePath, :priority, :activeTagId, "
|
||||
":showSubfolders, :activeNoteSubFolderData, :useGit)"));
|
||||
}
|
||||
|
||||
query.bindValue(QStringLiteral(":name"), this->name);
|
||||
query.bindValue(QStringLiteral(":cloudConnectionId"),
|
||||
this->cloudConnectionId);
|
||||
query.bindValue(QStringLiteral(":cloudConnectionId"), this->cloudConnectionId);
|
||||
query.bindValue(QStringLiteral(":remotePath"), this->remotePath);
|
||||
query.bindValue(QStringLiteral(":priority"), this->priority);
|
||||
query.bindValue(QStringLiteral(":activeTagId"), this->activeTagId);
|
||||
query.bindValue(QStringLiteral(":showSubfolders"), this->showSubfolders);
|
||||
query.bindValue(QStringLiteral(":useGit"), this->useGit);
|
||||
query.bindValue(QStringLiteral(":activeNoteSubFolderData"),
|
||||
this->activeNoteSubFolderData);
|
||||
query.bindValue(QStringLiteral(":activeNoteSubFolderData"), this->activeNoteSubFolderData);
|
||||
|
||||
// make the path relative to the portable data path if we are in
|
||||
// portable mode
|
||||
query.bindValue(QStringLiteral(":localPath"),
|
||||
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(
|
||||
this->localPath));
|
||||
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(this->localPath));
|
||||
|
||||
if (!query.exec()) {
|
||||
// on error
|
||||
|
@ -267,9 +254,8 @@ void NoteFolder::setAsCurrent() const {
|
|||
|
||||
// make the path relative to the portable data path if we are in
|
||||
// portable mode
|
||||
settings.setValue(
|
||||
QStringLiteral("notesPath"),
|
||||
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(localPath));
|
||||
settings.setValue(QStringLiteral("notesPath"),
|
||||
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(localPath));
|
||||
|
||||
// we need to reset the instance
|
||||
OwnCloudService::instance(true);
|
||||
|
@ -291,9 +277,7 @@ int NoteFolder::currentNoteFolderId() {
|
|||
/**
|
||||
* Returns the current note folder
|
||||
*/
|
||||
NoteFolder NoteFolder::currentNoteFolder() {
|
||||
return NoteFolder::fetch(currentNoteFolderId());
|
||||
}
|
||||
NoteFolder NoteFolder::currentNoteFolder() { return NoteFolder::fetch(currentNoteFolderId()); }
|
||||
|
||||
/**
|
||||
* Fetches the current remote path for the ownCloud service
|
||||
|
@ -307,17 +291,15 @@ QString NoteFolder::currentRemotePath(bool addTrailingSlash) {
|
|||
}
|
||||
|
||||
// add a leading "/"
|
||||
remotePath = Utils::Misc::prependIfDoesNotStartWith(std::move(remotePath),
|
||||
QStringLiteral("/"));
|
||||
remotePath = Utils::Misc::prependIfDoesNotStartWith(std::move(remotePath), QStringLiteral("/"));
|
||||
|
||||
if (addTrailingSlash) {
|
||||
// add a trailing "/"
|
||||
remotePath = Utils::Misc::appendIfDoesNotEndWith(std::move(remotePath),
|
||||
QStringLiteral("/"));
|
||||
remotePath =
|
||||
Utils::Misc::appendIfDoesNotEndWith(std::move(remotePath), QStringLiteral("/"));
|
||||
} else {
|
||||
// remove a trailing "/"
|
||||
remotePath = Utils::Misc::removeIfEndsWith(std::move(remotePath),
|
||||
QStringLiteral("/"));
|
||||
remotePath = Utils::Misc::removeIfEndsWith(std::move(remotePath), QStringLiteral("/"));
|
||||
}
|
||||
|
||||
return remotePath;
|
||||
|
@ -353,8 +335,7 @@ QString NoteFolder::currentLocalPath() {
|
|||
}
|
||||
|
||||
path = Utils::Misc::removeIfEndsWith(std::move(path), QDir::separator());
|
||||
path = Utils::Misc::removeIfEndsWith(std::move(path),
|
||||
QString{Utils::Misc::dirSeparator()});
|
||||
path = Utils::Misc::removeIfEndsWith(std::move(path), QString{Utils::Misc::dirSeparator()});
|
||||
|
||||
return path;
|
||||
}
|
||||
|
@ -365,33 +346,28 @@ QString NoteFolder::currentLocalPath() {
|
|||
*/
|
||||
QString NoteFolder::currentRootFolderName(bool fullPath) {
|
||||
QString path = currentLocalPath();
|
||||
return fullPath ? path
|
||||
: path.remove(
|
||||
0, path.lastIndexOf(Utils::Misc::dirSeparator()) + 1);
|
||||
return fullPath ? path : path.remove(0, path.lastIndexOf(Utils::Misc::dirSeparator()) + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the current trash path
|
||||
*/
|
||||
QString NoteFolder::currentTrashPath() {
|
||||
return NoteFolder::currentLocalPath() + QDir::separator() +
|
||||
QStringLiteral("trash");
|
||||
return NoteFolder::currentLocalPath() + QDir::separator() + QStringLiteral("trash");
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the current media path
|
||||
*/
|
||||
QString NoteFolder::currentMediaPath() {
|
||||
return NoteFolder::currentLocalPath() + QDir::separator() +
|
||||
QStringLiteral("media");
|
||||
return NoteFolder::currentLocalPath() + QDir::separator() + QStringLiteral("media");
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the current attachments path
|
||||
*/
|
||||
QString NoteFolder::currentAttachmentsPath() {
|
||||
return NoteFolder::currentLocalPath() + QDir::separator() +
|
||||
QStringLiteral("attachments");
|
||||
return NoteFolder::currentLocalPath() + QDir::separator() + QStringLiteral("attachments");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -441,10 +417,8 @@ QString NoteFolder::suggestRemotePath() {
|
|||
* Removes a leading or trailing slash from the remote path
|
||||
*/
|
||||
QString NoteFolder::fixRemotePath() {
|
||||
remotePath = Utils::Misc::removeIfStartsWith(std::move(remotePath),
|
||||
QStringLiteral("/"));
|
||||
remotePath = Utils::Misc::removeIfEndsWith(std::move(remotePath),
|
||||
QStringLiteral("/"));
|
||||
remotePath = Utils::Misc::removeIfStartsWith(std::move(remotePath), QStringLiteral("/"));
|
||||
remotePath = Utils::Misc::removeIfEndsWith(std::move(remotePath), QStringLiteral("/"));
|
||||
return remotePath;
|
||||
}
|
||||
|
||||
|
@ -472,8 +446,7 @@ bool NoteFolder::migrateToNoteFolders() {
|
|||
noteFolder.setCloudConnectionId(1);
|
||||
noteFolder.suggestRemotePath();
|
||||
noteFolder.setPriority(priority++);
|
||||
noteFolder.setShowSubfolders(
|
||||
settings.value(QStringLiteral("showNoteSubFolders")).toBool());
|
||||
noteFolder.setShowSubfolders(settings.value(QStringLiteral("showNoteSubFolders")).toBool());
|
||||
noteFolder.store();
|
||||
|
||||
settings.remove(QStringLiteral("showNoteSubFolders"));
|
||||
|
@ -558,16 +531,14 @@ void NoteFolder::setSettingsValue(const QString &key, const QVariant &value) {
|
|||
settings.setValue(QString("NoteFolder-%1/%2").arg(QString::number(id), key), value);
|
||||
}
|
||||
|
||||
QVariant NoteFolder::settingsValue(const QString &key,
|
||||
const QVariant &defaultValue) const {
|
||||
QVariant NoteFolder::settingsValue(const QString &key, const QVariant &defaultValue) const {
|
||||
const QSettings settings;
|
||||
return settings.value(QString("NoteFolder-%1/%2").arg(QString::number(id), key), defaultValue);
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const NoteFolder ¬eFolder) {
|
||||
dbg.nospace() << "NoteFolder: <id>" << noteFolder.id << " <name>"
|
||||
<< noteFolder.name << " <localPath>" << noteFolder.localPath
|
||||
<< " <remotePath>" << noteFolder.remotePath << " <priority>"
|
||||
<< noteFolder.priority;
|
||||
dbg.nospace() << "NoteFolder: <id>" << noteFolder.id << " <name>" << noteFolder.name
|
||||
<< " <localPath>" << noteFolder.localPath << " <remotePath>"
|
||||
<< noteFolder.remotePath << " <priority>" << noteFolder.priority;
|
||||
return dbg.space();
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ class NoteFolder {
|
|||
void setUseGit(bool value);
|
||||
QJsonObject jsonObject() const;
|
||||
|
||||
static bool create(const QString &name, const QString &localPath,
|
||||
int cloudConnectionId, const QString &remotePath);
|
||||
static bool create(const QString &name, const QString &localPath, int cloudConnectionId,
|
||||
const QString &remotePath);
|
||||
static NoteFolder fetch(int id);
|
||||
static NoteFolder noteFolderFromQuery(const QSqlQuery &query);
|
||||
static QList<NoteFolder> fetchAll();
|
||||
|
@ -67,7 +67,7 @@ class NoteFolder {
|
|||
void setSettingsValue(const QString &key, const QVariant &value);
|
||||
QVariant settingsValue(const QString &key, const QVariant &defaultValue = QVariant()) const;
|
||||
|
||||
private:
|
||||
private:
|
||||
QString name;
|
||||
QString localPath;
|
||||
QString remotePath;
|
||||
|
|
|
@ -27,15 +27,12 @@ NoteHistoryItem::NoteHistoryItem(Note *note, QPlainTextEdit *textEdit)
|
|||
|
||||
if (textEdit != nullptr) {
|
||||
_cursorPosition = textEdit->textCursor().position();
|
||||
_relativeScrollBarPosition =
|
||||
getTextEditScrollBarRelativePosition(textEdit);
|
||||
_relativeScrollBarPosition = getTextEditScrollBarRelativePosition(textEdit);
|
||||
}
|
||||
}
|
||||
|
||||
NoteHistoryItem::NoteHistoryItem(QString noteName,
|
||||
QString noteSubFolderPathData,
|
||||
int cursorPosition,
|
||||
float relativeScrollBarPosition) {
|
||||
NoteHistoryItem::NoteHistoryItem(QString noteName, QString noteSubFolderPathData,
|
||||
int cursorPosition, float relativeScrollBarPosition) {
|
||||
_noteName = std::move(noteName);
|
||||
_noteSubFolderPathData = std::move(noteSubFolderPathData);
|
||||
_cursorPosition = cursorPosition;
|
||||
|
@ -45,8 +42,7 @@ NoteHistoryItem::NoteHistoryItem(QString noteName,
|
|||
/**
|
||||
* Returns the relative note text edit scrollbar position (0..1)
|
||||
*/
|
||||
float NoteHistoryItem::getTextEditScrollBarRelativePosition(
|
||||
QPlainTextEdit *textEdit) {
|
||||
float NoteHistoryItem::getTextEditScrollBarRelativePosition(QPlainTextEdit *textEdit) {
|
||||
QScrollBar *scrollBar = textEdit->verticalScrollBar();
|
||||
int max = scrollBar->maximum();
|
||||
|
||||
|
@ -55,21 +51,16 @@ float NoteHistoryItem::getTextEditScrollBarRelativePosition(
|
|||
|
||||
QString NoteHistoryItem::getNoteName() const { return _noteName; }
|
||||
|
||||
QString NoteHistoryItem::getNoteSubFolderPathData() const {
|
||||
return _noteSubFolderPathData;
|
||||
}
|
||||
QString NoteHistoryItem::getNoteSubFolderPathData() const { return _noteSubFolderPathData; }
|
||||
|
||||
Note NoteHistoryItem::getNote() const {
|
||||
NoteSubFolder noteSubFolder =
|
||||
NoteSubFolder::fetchByPathData(_noteSubFolderPathData);
|
||||
NoteSubFolder noteSubFolder = NoteSubFolder::fetchByPathData(_noteSubFolderPathData);
|
||||
return Note::fetchByName(_noteName, noteSubFolder.getId());
|
||||
}
|
||||
|
||||
int NoteHistoryItem::getCursorPosition() const { return _cursorPosition; }
|
||||
|
||||
float NoteHistoryItem::getRelativeScrollBarPosition() const {
|
||||
return _relativeScrollBarPosition;
|
||||
}
|
||||
float NoteHistoryItem::getRelativeScrollBarPosition() const { return _relativeScrollBarPosition; }
|
||||
|
||||
/**
|
||||
* Restores the position in a text edit
|
||||
|
@ -93,9 +84,7 @@ void NoteHistoryItem::restoreTextEditPosition(QPlainTextEdit *textEdit) const {
|
|||
static_cast<int>(scrollBar->maximum() * _relativeScrollBarPosition));
|
||||
}
|
||||
|
||||
bool NoteHistoryItem::isValid() const {
|
||||
return _noteName.isEmpty();
|
||||
}
|
||||
bool NoteHistoryItem::isValid() const { return _noteName.isEmpty(); }
|
||||
|
||||
bool NoteHistoryItem::isNoteValid() const {
|
||||
Note note = getNote();
|
||||
|
@ -108,11 +97,9 @@ bool NoteHistoryItem::operator==(const NoteHistoryItem &item) const {
|
|||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const NoteHistoryItem &item) {
|
||||
dbg.nospace() << "NoteHistoryItem: <noteName>" << item._noteName
|
||||
<< " <noteSubFolderPathData>" << item._noteSubFolderPathData
|
||||
<< " <cursorPosition>" << item._cursorPosition
|
||||
<< " <relativeScrollBarPosition>"
|
||||
<< item._relativeScrollBarPosition;
|
||||
dbg.nospace() << "NoteHistoryItem: <noteName>" << item._noteName << " <noteSubFolderPathData>"
|
||||
<< item._noteSubFolderPathData << " <cursorPosition>" << item._cursorPosition
|
||||
<< " <relativeScrollBarPosition>" << item._relativeScrollBarPosition;
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
|
@ -124,8 +111,8 @@ QDebug operator<<(QDebug dbg, const NoteHistoryItem &item) {
|
|||
* @return
|
||||
*/
|
||||
QDataStream &operator<<(QDataStream &out, const NoteHistoryItem &item) {
|
||||
out << item.getNoteName() << item.getNoteSubFolderPathData()
|
||||
<< item.getCursorPosition() << item.getRelativeScrollBarPosition();
|
||||
out << item.getNoteName() << item.getNoteSubFolderPathData() << item.getCursorPosition()
|
||||
<< item.getRelativeScrollBarPosition();
|
||||
|
||||
return out;
|
||||
}
|
||||
|
@ -143,10 +130,9 @@ QDataStream &operator>>(QDataStream &in, NoteHistoryItem &item) {
|
|||
int cursorPosition;
|
||||
float relativeScrollBarPosition;
|
||||
|
||||
in >> noteName >> noteSubFolderPathData >> cursorPosition >>
|
||||
relativeScrollBarPosition;
|
||||
item = NoteHistoryItem(noteName, noteSubFolderPathData, cursorPosition,
|
||||
relativeScrollBarPosition);
|
||||
in >> noteName >> noteSubFolderPathData >> cursorPosition >> relativeScrollBarPosition;
|
||||
item =
|
||||
NoteHistoryItem(noteName, noteSubFolderPathData, cursorPosition, relativeScrollBarPosition);
|
||||
|
||||
return in;
|
||||
}
|
||||
|
@ -231,8 +217,7 @@ void NoteHistory::add(Note note, QPlainTextEdit *textEdit) {
|
|||
qDebug() << " added to history: " << item;
|
||||
}
|
||||
|
||||
void NoteHistory::updateCursorPositionOfNote(Note note,
|
||||
QPlainTextEdit *textEdit) {
|
||||
void NoteHistory::updateCursorPositionOfNote(Note note, QPlainTextEdit *textEdit) {
|
||||
if (isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
@ -314,9 +299,7 @@ bool NoteHistory::forward() {
|
|||
|
||||
int NoteHistory::lastIndex() const { return noteHistory->size() - 1; }
|
||||
|
||||
NoteHistoryItem NoteHistory::getCurrentHistoryItem() const {
|
||||
return currentHistoryItem;
|
||||
}
|
||||
NoteHistoryItem NoteHistory::getCurrentHistoryItem() const { return currentHistoryItem; }
|
||||
|
||||
bool NoteHistory::isEmpty() const { return noteHistory->empty(); }
|
||||
|
||||
|
@ -348,10 +331,8 @@ void NoteHistory::storeForCurrentNoteFolder() {
|
|||
int count = 0;
|
||||
|
||||
// store the last
|
||||
for (int i = noteHistoryItemCount - maxCount; i < noteHistoryItemCount;
|
||||
i++) {
|
||||
noteHistoryVariantItems.append(
|
||||
QVariant::fromValue(noteHistoryItems.at(i)));
|
||||
for (int i = noteHistoryItemCount - maxCount; i < noteHistoryItemCount; i++) {
|
||||
noteHistoryVariantItems.append(QVariant::fromValue(noteHistoryItems.at(i)));
|
||||
|
||||
if (i == currentIndex) {
|
||||
newCurrentIndex = count;
|
||||
|
@ -361,13 +342,12 @@ void NoteHistory::storeForCurrentNoteFolder() {
|
|||
}
|
||||
|
||||
// store the note history settings of the old note folder
|
||||
settings.setValue(
|
||||
QStringLiteral("NoteHistory-") + QString::number(currentNoteFolderId),
|
||||
noteHistoryVariantItems);
|
||||
settings.setValue(QStringLiteral("NoteHistory-") + QString::number(currentNoteFolderId),
|
||||
noteHistoryVariantItems);
|
||||
|
||||
settings.setValue(QStringLiteral("NoteHistoryCurrentIndex-") +
|
||||
QString::number(currentNoteFolderId),
|
||||
newCurrentIndex);
|
||||
settings.setValue(
|
||||
QStringLiteral("NoteHistoryCurrentIndex-") + QString::number(currentNoteFolderId),
|
||||
newCurrentIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -380,9 +360,7 @@ void NoteHistory::restoreForCurrentNoteFolder() {
|
|||
|
||||
// restore the note history of the new note folder
|
||||
const QVariantList noteHistoryVariantItems =
|
||||
settings
|
||||
.value(QStringLiteral("NoteHistory-") +
|
||||
QString::number(currentNoteFolderId))
|
||||
settings.value(QStringLiteral("NoteHistory-") + QString::number(currentNoteFolderId))
|
||||
.toList();
|
||||
|
||||
if (noteHistoryVariantItems.count() == 0) {
|
||||
|
@ -399,10 +377,8 @@ void NoteHistory::restoreForCurrentNoteFolder() {
|
|||
}
|
||||
}
|
||||
|
||||
int newCurrentIndex = settings
|
||||
.value("NoteHistoryCurrentIndex-" +
|
||||
QString::number(currentNoteFolderId))
|
||||
.toInt();
|
||||
int newCurrentIndex =
|
||||
settings.value("NoteHistoryCurrentIndex-" + QString::number(currentNoteFolderId)).toInt();
|
||||
|
||||
if (newCurrentIndex > 0 && newCurrentIndex <= maxIndex) {
|
||||
currentIndex = newCurrentIndex;
|
||||
|
@ -414,8 +390,8 @@ void NoteHistory::restoreForCurrentNoteFolder() {
|
|||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const NoteHistory &history) {
|
||||
dbg.nospace() << "NoteHistory: <index>" << history.currentIndex
|
||||
<< " <noteHistorySize>" << history.noteHistory->size();
|
||||
dbg.nospace() << "NoteHistory: <index>" << history.currentIndex << " <noteHistorySize>"
|
||||
<< history.noteHistory->size();
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
|
@ -442,9 +418,7 @@ QList<NoteHistoryItem> NoteHistory::getNoteHistoryItems() const {
|
|||
*
|
||||
* @param item
|
||||
*/
|
||||
void NoteHistory::addNoteHistoryItem(const NoteHistoryItem &item) {
|
||||
noteHistory->append(item);
|
||||
}
|
||||
void NoteHistory::addNoteHistoryItem(const NoteHistoryItem &item) { noteHistory->append(item); }
|
||||
|
||||
/**
|
||||
* Stream operator for storing the class to QSettings
|
||||
|
|
|
@ -2,18 +2,16 @@
|
|||
#define NOTEHISTORY_H
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QString>
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
|
||||
class Note;
|
||||
class QPlainTextEdit;
|
||||
|
||||
class NoteHistoryItem {
|
||||
public:
|
||||
explicit NoteHistoryItem(Note *note = nullptr,
|
||||
QPlainTextEdit *textEdit = nullptr);
|
||||
explicit NoteHistoryItem(QString noteName, QString noteSubFolderPathData,
|
||||
int cursorPosition,
|
||||
explicit NoteHistoryItem(Note *note = nullptr, QPlainTextEdit *textEdit = nullptr);
|
||||
explicit NoteHistoryItem(QString noteName, QString noteSubFolderPathData, int cursorPosition,
|
||||
float relativeScrollBarPosition);
|
||||
friend QDebug operator<<(QDebug dbg, const NoteHistoryItem &item);
|
||||
QString getNoteName() const;
|
||||
|
|
|
@ -17,22 +17,17 @@
|
|||
#include "notefolder.h"
|
||||
#include "tag.h"
|
||||
|
||||
NoteSubFolder::NoteSubFolder()
|
||||
: _id{0}, _parentId{0}, _name{QLatin1String("")} {}
|
||||
NoteSubFolder::NoteSubFolder() : _id{0}, _parentId{0}, _name{QLatin1String("")} {}
|
||||
|
||||
int NoteSubFolder::getId() const { return _id; }
|
||||
|
||||
int NoteSubFolder::getParentId() const { return _parentId; }
|
||||
|
||||
NoteSubFolder NoteSubFolder::getParent() const {
|
||||
return NoteSubFolder::fetch(_parentId);
|
||||
}
|
||||
NoteSubFolder NoteSubFolder::getParent() const { return NoteSubFolder::fetch(_parentId); }
|
||||
|
||||
QString NoteSubFolder::getName() const { return _name; }
|
||||
|
||||
QDateTime NoteSubFolder::getFileLastModified() const {
|
||||
return _fileLastModified;
|
||||
}
|
||||
QDateTime NoteSubFolder::getFileLastModified() const { return _fileLastModified; }
|
||||
|
||||
QDateTime NoteSubFolder::getModified() const { return _modified; }
|
||||
|
||||
|
@ -60,8 +55,7 @@ NoteSubFolder NoteSubFolder::fetch(int id) {
|
|||
return NoteSubFolder();
|
||||
}
|
||||
|
||||
NoteSubFolder NoteSubFolder::fetchByNameAndParentId(const QString& name,
|
||||
int parentId) {
|
||||
NoteSubFolder NoteSubFolder::fetchByNameAndParentId(const QString& name, int parentId) {
|
||||
const QSqlDatabase db = QSqlDatabase::database(QStringLiteral("memory"));
|
||||
QSqlQuery query(db);
|
||||
|
||||
|
@ -86,17 +80,15 @@ NoteSubFolder NoteSubFolder::fetchByNameAndParentId(const QString& name,
|
|||
* Gets the relative path name of the note sub folder
|
||||
*/
|
||||
QString NoteSubFolder::relativePath(char separator) const {
|
||||
return _parentId == 0
|
||||
? _name
|
||||
: getParent().relativePath(separator) + separator + _name;
|
||||
return _parentId == 0 ? _name : getParent().relativePath(separator) + separator + _name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the full path of the note sub folder
|
||||
*/
|
||||
QString NoteSubFolder::fullPath() const {
|
||||
return Utils::Misc::removeIfEndsWith(
|
||||
Note::getFullFilePathForFile(relativePath()), QStringLiteral("/"));
|
||||
return Utils::Misc::removeIfEndsWith(Note::getFullFilePathForFile(relativePath()),
|
||||
QStringLiteral("/"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,15 +100,13 @@ QDir NoteSubFolder::dir() const { return QDir(fullPath()); }
|
|||
* Gets the path data of the note sub folder
|
||||
*/
|
||||
QString NoteSubFolder::pathData() const {
|
||||
return _parentId == 0 ? _name
|
||||
: getParent().pathData() + QChar('\n') + _name;
|
||||
return _parentId == 0 ? _name : getParent().pathData() + QChar('\n') + _name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a note sub folder by its path data
|
||||
*/
|
||||
NoteSubFolder NoteSubFolder::fetchByPathData(QString pathData,
|
||||
const QString& separator) {
|
||||
NoteSubFolder NoteSubFolder::fetchByPathData(QString pathData, const QString& separator) {
|
||||
if (pathData.isEmpty()) return NoteSubFolder();
|
||||
|
||||
pathData = Utils::Misc::removeIfStartsWith(std::move(pathData), separator);
|
||||
|
@ -124,8 +114,7 @@ NoteSubFolder NoteSubFolder::fetchByPathData(QString pathData,
|
|||
NoteSubFolder noteSubFolder;
|
||||
// loop through all names to fetch the deepest note sub folder
|
||||
for (const auto& name : pathList) {
|
||||
noteSubFolder =
|
||||
NoteSubFolder::fetchByNameAndParentId(name, noteSubFolder.getId());
|
||||
noteSubFolder = NoteSubFolder::fetchByNameAndParentId(name, noteSubFolder.getId());
|
||||
if (!noteSubFolder.isFetched()) return NoteSubFolder();
|
||||
}
|
||||
return noteSubFolder;
|
||||
|
@ -181,8 +170,7 @@ bool NoteSubFolder::rename(const QString& newName) {
|
|||
const bool ret = QDir().rename(oldPath, newPath);
|
||||
|
||||
if (!ret) {
|
||||
qCritical() << "Renaming " << oldPath << " to " << newPath
|
||||
<< " failed";
|
||||
qCritical() << "Renaming " << oldPath << " to " << newPath << " failed";
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -199,8 +187,7 @@ NoteSubFolder NoteSubFolder::fillFromQuery(const QSqlQuery& query) {
|
|||
_id = query.value(QStringLiteral("id")).toInt();
|
||||
_parentId = query.value(QStringLiteral("parent_id")).toInt();
|
||||
_name = query.value(QStringLiteral("name")).toString();
|
||||
_fileLastModified =
|
||||
query.value(QStringLiteral("file_last_modified")).toDateTime();
|
||||
_fileLastModified = query.value(QStringLiteral("file_last_modified")).toDateTime();
|
||||
_created = query.value(QStringLiteral("created")).toDateTime();
|
||||
_modified = query.value(QStringLiteral("modified")).toDateTime();
|
||||
|
||||
|
@ -259,8 +246,7 @@ QVector<int> NoteSubFolder::fetchAllIds() {
|
|||
return idList;
|
||||
}
|
||||
|
||||
QVector<NoteSubFolder> NoteSubFolder::fetchAllByParentId(
|
||||
int parentId, const QString& sortBy) {
|
||||
QVector<NoteSubFolder> NoteSubFolder::fetchAllByParentId(int parentId, const QString& sortBy) {
|
||||
const QSqlDatabase db = QSqlDatabase::database(QStringLiteral("memory"));
|
||||
QSqlQuery query(db);
|
||||
|
||||
|
@ -451,9 +437,7 @@ bool NoteSubFolder::isActive() const { return activeNoteSubFolderId() == _id; }
|
|||
/**
|
||||
* Returns the id of the current note sub folder of the current note folder
|
||||
*/
|
||||
int NoteSubFolder::activeNoteSubFolderId() {
|
||||
return activeNoteSubFolder().getId();
|
||||
}
|
||||
int NoteSubFolder::activeNoteSubFolderId() { return activeNoteSubFolder().getId(); }
|
||||
|
||||
/**
|
||||
* Returns the current note sub folder of the current note folder
|
||||
|
@ -505,9 +489,7 @@ bool NoteSubFolder::treeWidgetExpandState() const {
|
|||
* Checks if noteSubfoldersPanelShowNotesRecursively is set
|
||||
*/
|
||||
bool NoteSubFolder::isNoteSubfoldersPanelShowNotesRecursively() {
|
||||
return QSettings()
|
||||
.value(QStringLiteral("noteSubfoldersPanelShowNotesRecursively"))
|
||||
.toBool();
|
||||
return QSettings().value(QStringLiteral("noteSubfoldersPanelShowNotesRecursively")).toBool();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -537,22 +519,19 @@ int NoteSubFolder::depth() const {
|
|||
return relativePath.split(QChar('\n')).count();
|
||||
}
|
||||
|
||||
bool NoteSubFolder::willFolderBeIgnored(const QString& folderName,
|
||||
bool showWarning) {
|
||||
bool NoteSubFolder::willFolderBeIgnored(const QString& folderName, bool showWarning) {
|
||||
// ignore some folders
|
||||
const QStringList ignoreFolderList{".", "..", "media", "attachments",
|
||||
"trash"};
|
||||
const QStringList ignoreFolderList{".", "..", "media", "attachments", "trash"};
|
||||
|
||||
if (ignoreFolderList.contains(folderName)) {
|
||||
#ifndef INTEGRATION_TESTS
|
||||
if (showWarning) {
|
||||
Utils::Gui::warning(
|
||||
nullptr, QObject::tr("Folder will be hidden!"),
|
||||
QObject::tr("Folder with name <b>%1</b> can't be created, "
|
||||
"because it's internally used by the "
|
||||
"application!")
|
||||
.arg(folderName),
|
||||
"note-subfolder-hidden-internal");
|
||||
Utils::Gui::warning(nullptr, QObject::tr("Folder will be hidden!"),
|
||||
QObject::tr("Folder with name <b>%1</b> can't be created, "
|
||||
"because it's internally used by the "
|
||||
"application!")
|
||||
.arg(folderName),
|
||||
"note-subfolder-hidden-internal");
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(showWarning)
|
||||
|
@ -563,9 +542,7 @@ bool NoteSubFolder::willFolderBeIgnored(const QString& folderName,
|
|||
|
||||
const QSettings settings;
|
||||
const QStringList ignoredFolderRegExpList =
|
||||
settings
|
||||
.value(QStringLiteral("ignoreNoteSubFolders"),
|
||||
IGNORED_NOTE_SUBFOLDERS_DEFAULT)
|
||||
settings.value(QStringLiteral("ignoreNoteSubFolders"), IGNORED_NOTE_SUBFOLDERS_DEFAULT)
|
||||
.toString()
|
||||
.split(QLatin1Char(';'));
|
||||
|
||||
|
@ -573,14 +550,12 @@ bool NoteSubFolder::willFolderBeIgnored(const QString& folderName,
|
|||
if (Utils::Misc::regExpInListMatches(folderName, ignoredFolderRegExpList)) {
|
||||
#ifndef INTEGRATION_TESTS
|
||||
if (showWarning) {
|
||||
Utils::Gui::warning(
|
||||
nullptr, QObject::tr("Folder will be hidden!"),
|
||||
QObject::tr(
|
||||
"Folder with name <b>%1</b> can't be created, "
|
||||
"because it's on the list of ignored subfolders! "
|
||||
"You can change that in the <i>Panels settings</i>.")
|
||||
.arg(folderName),
|
||||
"note-subfolder-hidden-settings");
|
||||
Utils::Gui::warning(nullptr, QObject::tr("Folder will be hidden!"),
|
||||
QObject::tr("Folder with name <b>%1</b> can't be created, "
|
||||
"because it's on the list of ignored subfolders! "
|
||||
"You can change that in the <i>Panels settings</i>.")
|
||||
.arg(folderName),
|
||||
"note-subfolder-hidden-settings");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -591,8 +566,7 @@ bool NoteSubFolder::willFolderBeIgnored(const QString& folderName,
|
|||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const NoteSubFolder& noteSubFolder) {
|
||||
dbg.nospace() << "NoteSubFolder: <id>" << noteSubFolder._id << " <name>"
|
||||
<< noteSubFolder._name << " <parentId>"
|
||||
<< noteSubFolder._parentId;
|
||||
dbg.nospace() << "NoteSubFolder: <id>" << noteSubFolder._id << " <name>" << noteSubFolder._name
|
||||
<< " <parentId>" << noteSubFolder._parentId;
|
||||
return dbg.space();
|
||||
}
|
||||
|
|
|
@ -56,8 +56,7 @@ class NoteSubFolder {
|
|||
NoteSubFolder getParent() const;
|
||||
|
||||
static QVector<NoteSubFolder> fetchAllByParentId(
|
||||
int parentId,
|
||||
const QString& sortBy = QStringLiteral("file_last_modified DESC"));
|
||||
int parentId, const QString& sortBy = QStringLiteral("file_last_modified DESC"));
|
||||
|
||||
static QVector<int> fetchIdsRecursivelyByParentId(int parentId);
|
||||
|
||||
|
@ -73,11 +72,10 @@ class NoteSubFolder {
|
|||
|
||||
QString pathData() const;
|
||||
|
||||
static NoteSubFolder fetchByPathData(
|
||||
QString pathData, const QString& separator = QStringLiteral("\n"));
|
||||
static NoteSubFolder fetchByPathData(QString pathData,
|
||||
const QString& separator = QStringLiteral("\n"));
|
||||
|
||||
static NoteSubFolder fetchByNameAndParentId(const QString& name,
|
||||
int parentId);
|
||||
static NoteSubFolder fetchByNameAndParentId(const QString& name, int parentId);
|
||||
|
||||
void saveTreeWidgetExpandState(bool expanded) const;
|
||||
|
||||
|
@ -99,8 +97,7 @@ class NoteSubFolder {
|
|||
|
||||
int depth() const;
|
||||
|
||||
static bool willFolderBeIgnored(const QString& folderName,
|
||||
bool showWarning = false);
|
||||
static bool willFolderBeIgnored(const QString& folderName, bool showWarning = false);
|
||||
|
||||
protected:
|
||||
int _id;
|
||||
|
|
|
@ -29,15 +29,11 @@
|
|||
#include <QSqlRecord>
|
||||
#include <QtCore/QJsonArray>
|
||||
|
||||
const QString Script::ScriptRepositoryRawContentUrlPrefix = QStringLiteral(
|
||||
"https://raw.githubusercontent.com/qownnotes/scripts/master/");
|
||||
const QString Script::ScriptRepositoryRawContentUrlPrefix =
|
||||
QStringLiteral("https://raw.githubusercontent.com/qownnotes/scripts/master/");
|
||||
|
||||
Script::Script()
|
||||
: id{0},
|
||||
name(QLatin1String("")),
|
||||
scriptPath(QLatin1String("")),
|
||||
priority{0},
|
||||
enabled{true} {}
|
||||
: id{0}, name(QLatin1String("")), scriptPath(QLatin1String("")), priority{0}, enabled{true} {}
|
||||
|
||||
int Script::getId() const { return this->id; }
|
||||
|
||||
|
@ -72,13 +68,9 @@ bool Script::isEnabled() const { return getEnabled(); }
|
|||
|
||||
void Script::setName(const QString &text) { this->name = text; }
|
||||
|
||||
void Script::setIdentifier(QString identifier) {
|
||||
this->identifier = std::move(identifier);
|
||||
}
|
||||
void Script::setIdentifier(QString identifier) { this->identifier = std::move(identifier); }
|
||||
|
||||
void Script::setInfoJson(QString infoJson) {
|
||||
this->infoJson = std::move(infoJson);
|
||||
}
|
||||
void Script::setInfoJson(QString infoJson) { this->infoJson = std::move(infoJson); }
|
||||
|
||||
void Script::setSettingsVariablesJson(QString json) {
|
||||
this->settingsVariablesJson = std::move(json);
|
||||
|
@ -107,8 +99,7 @@ bool Script::create(const QString &name, QString scriptPath) {
|
|||
// make the path relative to the portable data path if we are in
|
||||
// portable mode
|
||||
query.bindValue(QStringLiteral(":scriptPath"),
|
||||
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(
|
||||
std::move(scriptPath)));
|
||||
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(std::move(scriptPath)));
|
||||
|
||||
return query.exec();
|
||||
}
|
||||
|
@ -157,8 +148,7 @@ int Script::countEnabled() {
|
|||
QSqlDatabase db = QSqlDatabase::database(QStringLiteral("disk"));
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT COUNT(*) AS cnt FROM script WHERE enabled = 1"));
|
||||
query.prepare(QStringLiteral("SELECT COUNT(*) AS cnt FROM script WHERE enabled = 1"));
|
||||
|
||||
if (!query.exec()) {
|
||||
qWarning() << __func__ << ": " << query.lastError();
|
||||
|
@ -192,8 +182,7 @@ Script Script::fetchByIdentifier(const QString &identifier) {
|
|||
|
||||
Script script;
|
||||
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT * FROM script WHERE identifier = :identifier"));
|
||||
query.prepare(QStringLiteral("SELECT * FROM script WHERE identifier = :identifier"));
|
||||
query.bindValue(QStringLiteral(":identifier"), identifier);
|
||||
|
||||
if (!query.exec()) {
|
||||
|
@ -266,8 +255,7 @@ bool Script::fillFromQuery(const QSqlQuery &query) {
|
|||
this->name = query.value(QStringLiteral("name")).toString();
|
||||
this->identifier = query.value(QStringLiteral("identifier")).toString();
|
||||
this->infoJson = query.value(QStringLiteral("info_json")).toString();
|
||||
this->settingsVariablesJson =
|
||||
query.value(QStringLiteral("settings_variables_json")).toString();
|
||||
this->settingsVariablesJson = query.value(QStringLiteral("settings_variables_json")).toString();
|
||||
this->priority = query.value(QStringLiteral("priority")).toInt();
|
||||
this->enabled = query.value(QStringLiteral("enabled")).toBool();
|
||||
|
||||
|
@ -283,10 +271,8 @@ QList<Script> Script::fetchAll(bool enabledOnly) {
|
|||
QSqlQuery query(db);
|
||||
|
||||
QList<Script> scriptList;
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT * FROM script %1 ORDER BY priority ASC, id ASC")
|
||||
.arg(enabledOnly ? QStringLiteral("WHERE enabled = 1")
|
||||
: QLatin1String("")));
|
||||
query.prepare(QStringLiteral("SELECT * FROM script %1 ORDER BY priority ASC, id ASC")
|
||||
.arg(enabledOnly ? QStringLiteral("WHERE enabled = 1") : QLatin1String("")));
|
||||
|
||||
if (!query.exec()) {
|
||||
qWarning() << __func__ << ": " << query.lastError();
|
||||
|
@ -308,20 +294,20 @@ bool Script::store() {
|
|||
QSqlQuery query(db);
|
||||
|
||||
if (this->id > 0) {
|
||||
query.prepare(QStringLiteral(
|
||||
"UPDATE script SET name = :name, script_path = :scriptPath, "
|
||||
"priority = :priority, enabled = :enabled, "
|
||||
"identifier = :identifier, info_json = :info_json, "
|
||||
"settings_variables_json = :settings_variables_json "
|
||||
"WHERE id = :id"));
|
||||
query.prepare(
|
||||
QStringLiteral("UPDATE script SET name = :name, script_path = :scriptPath, "
|
||||
"priority = :priority, enabled = :enabled, "
|
||||
"identifier = :identifier, info_json = :info_json, "
|
||||
"settings_variables_json = :settings_variables_json "
|
||||
"WHERE id = :id"));
|
||||
query.bindValue(QStringLiteral(":id"), this->id);
|
||||
} else {
|
||||
query.prepare(QStringLiteral(
|
||||
"INSERT INTO script (name, script_path, "
|
||||
"priority, enabled, identifier, info_json,"
|
||||
"settings_variables_json) VALUES "
|
||||
"(:name, :scriptPath, :priority, :enabled, "
|
||||
":identifier, :info_json, :settings_variables_json)"));
|
||||
query.prepare(
|
||||
QStringLiteral("INSERT INTO script (name, script_path, "
|
||||
"priority, enabled, identifier, info_json,"
|
||||
"settings_variables_json) VALUES "
|
||||
"(:name, :scriptPath, :priority, :enabled, "
|
||||
":identifier, :info_json, :settings_variables_json)"));
|
||||
}
|
||||
|
||||
query.bindValue(QStringLiteral(":name"), this->name);
|
||||
|
@ -329,14 +315,12 @@ bool Script::store() {
|
|||
query.bindValue(QStringLiteral(":enabled"), this->enabled);
|
||||
query.bindValue(QStringLiteral(":identifier"), this->identifier);
|
||||
query.bindValue(QStringLiteral(":info_json"), this->infoJson);
|
||||
query.bindValue(QStringLiteral(":settings_variables_json"),
|
||||
this->settingsVariablesJson);
|
||||
query.bindValue(QStringLiteral(":settings_variables_json"), this->settingsVariablesJson);
|
||||
|
||||
// make the path relative to the portable data path if we are in
|
||||
// portable mode
|
||||
query.bindValue(QStringLiteral(":scriptPath"),
|
||||
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(
|
||||
this->scriptPath));
|
||||
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(this->scriptPath));
|
||||
|
||||
if (!query.exec()) {
|
||||
// on error
|
||||
|
@ -375,9 +359,7 @@ QJsonObject Script::getInfoJsonObject() const {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
ScriptInfoJson Script::getScriptInfoJson() const {
|
||||
return ScriptInfoJson(getInfoJsonObject());
|
||||
}
|
||||
ScriptInfoJson Script::getScriptInfoJson() const { return ScriptInfoJson(getInfoJsonObject()); }
|
||||
|
||||
/**
|
||||
* Returns the json object of the settingsVariablesJson field
|
||||
|
@ -385,8 +367,7 @@ ScriptInfoJson Script::getScriptInfoJson() const {
|
|||
* @return
|
||||
*/
|
||||
QJsonObject Script::getSettingsVariablesJsonObject() const {
|
||||
QJsonDocument jsonResponse =
|
||||
QJsonDocument::fromJson(settingsVariablesJson.toUtf8());
|
||||
QJsonDocument jsonResponse = QJsonDocument::fromJson(settingsVariablesJson.toUtf8());
|
||||
return jsonResponse.object();
|
||||
}
|
||||
|
||||
|
@ -395,9 +376,7 @@ QJsonObject Script::getSettingsVariablesJsonObject() const {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
QString Script::getSettingsVariablesJson() const {
|
||||
return settingsVariablesJson;
|
||||
}
|
||||
QString Script::getSettingsVariablesJson() const { return settingsVariablesJson; }
|
||||
|
||||
/**
|
||||
* Returns the path where the script repositories will be stored locally
|
||||
|
@ -424,8 +403,7 @@ QString Script::scriptRepositoryPath(bool removeRecursively) const {
|
|||
return QString();
|
||||
}
|
||||
|
||||
QString path =
|
||||
globalScriptRepositoryPath() + QStringLiteral("/") + identifier;
|
||||
QString path = globalScriptRepositoryPath() + QStringLiteral("/") + identifier;
|
||||
QDir dir(path);
|
||||
|
||||
// remove the old files in the script path
|
||||
|
@ -443,9 +421,7 @@ QString Script::scriptRepositoryPath(bool removeRecursively) const {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
bool Script::isScriptFromRepository() const {
|
||||
return !identifier.isEmpty() || !infoJson.isEmpty();
|
||||
}
|
||||
bool Script::isScriptFromRepository() const { return !identifier.isEmpty() || !infoJson.isEmpty(); }
|
||||
|
||||
/**
|
||||
* Returns the url of the script in the remote script repository
|
||||
|
@ -473,10 +449,8 @@ QUrl Script::remoteFileUrl(const QString &fileName) const {
|
|||
return QUrl();
|
||||
}
|
||||
|
||||
return QUrl(
|
||||
QStringLiteral(
|
||||
"https://raw.githubusercontent.com/qownnotes/scripts/master/") +
|
||||
identifier + QStringLiteral("/") + fileName);
|
||||
return QUrl(QStringLiteral("https://raw.githubusercontent.com/qownnotes/scripts/master/") +
|
||||
identifier + QStringLiteral("/") + fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -505,9 +479,9 @@ QList<QUrl> Script::remoteFileUrls() const {
|
|||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Script &script) {
|
||||
dbg.nospace() << "Script: <id>" << script.id << " <name>" << script.name
|
||||
<< " <scriptPath>" << script.scriptPath << " <enabled>"
|
||||
<< script.enabled << " <priority>" << script.priority;
|
||||
dbg.nospace() << "Script: <id>" << script.id << " <name>" << script.name << " <scriptPath>"
|
||||
<< script.scriptPath << " <enabled>" << script.enabled << " <priority>"
|
||||
<< script.priority;
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
|
@ -524,16 +498,12 @@ ScriptInfoJson::ScriptInfoJson(const QJsonObject &jsonObject) {
|
|||
name = jsonObject.value(QStringLiteral("name")).toString();
|
||||
identifier = jsonObject.value(QStringLiteral("identifier")).toString();
|
||||
version = jsonObject.value(QStringLiteral("version")).toString();
|
||||
minAppVersion =
|
||||
jsonObject.value(QStringLiteral("minAppVersion")).toString();
|
||||
minAppVersion = jsonObject.value(QStringLiteral("minAppVersion")).toString();
|
||||
description = jsonObject.value(QStringLiteral("description")).toString();
|
||||
description =
|
||||
description.replace(QStringLiteral("\n"), QStringLiteral("<br>"));
|
||||
description = description.replace(QStringLiteral("\n"), QStringLiteral("<br>"));
|
||||
script = jsonObject.value(QStringLiteral("script")).toString();
|
||||
const QJsonArray authors =
|
||||
jsonObject.value(QStringLiteral("authors")).toArray();
|
||||
const QJsonArray platforms =
|
||||
jsonObject.value(QStringLiteral("platforms")).toArray();
|
||||
const QJsonArray authors = jsonObject.value(QStringLiteral("authors")).toArray();
|
||||
const QJsonArray platforms = jsonObject.value(QStringLiteral("platforms")).toArray();
|
||||
|
||||
// generate the author list
|
||||
richAuthorList.clear();
|
||||
|
@ -579,8 +549,7 @@ ScriptInfoJson::ScriptInfoJson(const QJsonObject &jsonObject) {
|
|||
richPlatformText = richPlatformList.join(QStringLiteral(", "));
|
||||
|
||||
// get the resources file names
|
||||
const QJsonArray resourcesArray =
|
||||
jsonObject.value(QStringLiteral("resources")).toArray();
|
||||
const QJsonArray resourcesArray = jsonObject.value(QStringLiteral("resources")).toArray();
|
||||
resources.clear();
|
||||
for (const QJsonValue &value : resourcesArray) {
|
||||
const QString fileName = value.toString().trimmed();
|
||||
|
@ -591,8 +560,7 @@ ScriptInfoJson::ScriptInfoJson(const QJsonObject &jsonObject) {
|
|||
}
|
||||
|
||||
// check if app version is supported
|
||||
appVersionSupported =
|
||||
VersionNumber(VERSION) >= VersionNumber(minAppVersion);
|
||||
appVersionSupported = VersionNumber(VERSION) >= VersionNumber(minAppVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -601,6 +569,5 @@ ScriptInfoJson::ScriptInfoJson(const QJsonObject &jsonObject) {
|
|||
* @return
|
||||
*/
|
||||
QUrl Script::repositoryInfoJsonUrl() const {
|
||||
return ScriptRepositoryRawContentUrlPrefix + getIdentifier() +
|
||||
QStringLiteral("/info.json");
|
||||
return ScriptRepositoryRawContentUrlPrefix + getIdentifier() + QStringLiteral("/info.json");
|
||||
}
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
#include "notefolder.h"
|
||||
#include "notesubfolder.h"
|
||||
|
||||
Tag::Tag() noexcept
|
||||
: _parentId(0), _priority(0) {}
|
||||
Tag::Tag() noexcept : _parentId(0), _priority(0) {}
|
||||
|
||||
int Tag::getParentId() const { return _parentId; }
|
||||
|
||||
|
@ -62,10 +61,9 @@ Tag Tag::fetchByName(QString name, const bool startsWith) {
|
|||
QSqlDatabase db = DatabaseService::getNoteFolderDatabase();
|
||||
QSqlQuery query(db);
|
||||
Tag tag;
|
||||
const QString sql =
|
||||
QStringLiteral("SELECT * FROM tag WHERE name ") %
|
||||
QString(startsWith ? QStringLiteral("LIKE") : QStringLiteral("=")) %
|
||||
QStringLiteral(" :name ORDER BY name");
|
||||
const QString sql = QStringLiteral("SELECT * FROM tag WHERE name ") %
|
||||
QString(startsWith ? QStringLiteral("LIKE") : QStringLiteral("=")) %
|
||||
QStringLiteral(" :name ORDER BY name");
|
||||
query.prepare(sql);
|
||||
|
||||
if (startsWith) {
|
||||
|
@ -153,8 +151,7 @@ bool Tag::remove() const {
|
|||
QSqlQuery query2(db2);
|
||||
|
||||
// remove the note tag links
|
||||
query2.prepare(
|
||||
QStringLiteral("DELETE FROM noteTagLink WHERE tag_id = :id"));
|
||||
query2.prepare(QStringLiteral("DELETE FROM noteTagLink WHERE tag_id = :id"));
|
||||
query2.bindValue(QStringLiteral(":id"), _id);
|
||||
|
||||
if (!query2.exec()) {
|
||||
|
@ -169,9 +166,7 @@ bool Tag::remove() const {
|
|||
}
|
||||
}
|
||||
|
||||
Tag Tag::tagFromQuery(const QSqlQuery &query) {
|
||||
return Tag().fillFromQuery(query);
|
||||
}
|
||||
Tag Tag::tagFromQuery(const QSqlQuery &query) { return Tag().fillFromQuery(query); }
|
||||
|
||||
Tag Tag::fillFromQuery(const QSqlQuery &query) {
|
||||
_id = query.value(QStringLiteral("id")).toInt();
|
||||
|
@ -207,17 +202,17 @@ QVector<Tag> Tag::fetchAll() {
|
|||
* to sort the result by.
|
||||
*
|
||||
*/
|
||||
query.prepare(QStringLiteral(
|
||||
"SELECT t.id as id, t.name as name, t.priority as priority, max( "
|
||||
"CASE "
|
||||
"WHEN l.created > t.updated THEN l.created "
|
||||
"ELSE t.updated "
|
||||
"END "
|
||||
") AS created, t.parent_id as parent_id, "
|
||||
"t.color as color, t.dark_color as dark_color "
|
||||
"FROM tag t LEFT JOIN noteTagLink l ON t.id = l.tag_id "
|
||||
"GROUP BY t.name "
|
||||
"ORDER BY created DESC"));
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT t.id as id, t.name as name, t.priority as priority, max( "
|
||||
"CASE "
|
||||
"WHEN l.created > t.updated THEN l.created "
|
||||
"ELSE t.updated "
|
||||
"END "
|
||||
") AS created, t.parent_id as parent_id, "
|
||||
"t.color as color, t.dark_color as dark_color "
|
||||
"FROM tag t LEFT JOIN noteTagLink l ON t.id = l.tag_id "
|
||||
"GROUP BY t.name "
|
||||
"ORDER BY created DESC"));
|
||||
if (!query.exec()) {
|
||||
qWarning() << __func__ << ": " << query.lastError();
|
||||
} else {
|
||||
|
@ -237,11 +232,10 @@ QVector<TagHeader> Tag::fetchAllTagHeadersByParentId(const int parentId) {
|
|||
QVector<TagHeader> tagList;
|
||||
|
||||
query.prepare(
|
||||
QStringLiteral(
|
||||
"SELECT t.id as id, t.name as name "
|
||||
"FROM tag t LEFT JOIN noteTagLink l ON t.id = l.tag_id "
|
||||
"WHERE parent_id = :parentId "
|
||||
"GROUP BY t.name"));
|
||||
QStringLiteral("SELECT t.id as id, t.name as name "
|
||||
"FROM tag t LEFT JOIN noteTagLink l ON t.id = l.tag_id "
|
||||
"WHERE parent_id = :parentId "
|
||||
"GROUP BY t.name"));
|
||||
query.bindValue(QStringLiteral(":parentId"), parentId);
|
||||
|
||||
if (!query.exec()) {
|
||||
|
@ -271,18 +265,17 @@ QVector<Tag> Tag::fetchAllByParentId(const int parentId, const QString &sortBy)
|
|||
* parent_id.
|
||||
*/
|
||||
query.prepare(
|
||||
QStringLiteral(
|
||||
"SELECT t.id as id, t.name as name, t.priority as priority, max( "
|
||||
"CASE "
|
||||
"WHEN l.created > t.updated THEN l.created "
|
||||
"ELSE t.updated "
|
||||
"END "
|
||||
") AS created, t.parent_id as parent_id, "
|
||||
"t.color as color, t.dark_color as dark_color "
|
||||
"FROM tag t LEFT JOIN noteTagLink l ON t.id = l.tag_id "
|
||||
"WHERE parent_id = :parentId "
|
||||
"GROUP BY t.name "
|
||||
"ORDER BY :sortBy"));
|
||||
QStringLiteral("SELECT t.id as id, t.name as name, t.priority as priority, max( "
|
||||
"CASE "
|
||||
"WHEN l.created > t.updated THEN l.created "
|
||||
"ELSE t.updated "
|
||||
"END "
|
||||
") AS created, t.parent_id as parent_id, "
|
||||
"t.color as color, t.dark_color as dark_color "
|
||||
"FROM tag t LEFT JOIN noteTagLink l ON t.id = l.tag_id "
|
||||
"WHERE parent_id = :parentId "
|
||||
"GROUP BY t.name "
|
||||
"ORDER BY :sortBy"));
|
||||
query.bindValue(QStringLiteral(":parentId"), parentId);
|
||||
query.bindValue(QStringLiteral(":sortBy"), sortBy);
|
||||
|
||||
|
@ -299,16 +292,14 @@ QVector<Tag> Tag::fetchAllByParentId(const int parentId, const QString &sortBy)
|
|||
return tagList;
|
||||
}
|
||||
|
||||
QVector<int> Tag::fetchAllIdsByParentId(const int parentId)
|
||||
{
|
||||
QVector<int> Tag::fetchAllIdsByParentId(const int parentId) {
|
||||
QSqlDatabase db = DatabaseService::getNoteFolderDatabase();
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare(
|
||||
QStringLiteral(
|
||||
"SELECT t.id as id "
|
||||
"FROM tag t LEFT JOIN noteTagLink l ON t.id = l.tag_id "
|
||||
"WHERE parent_id = :parentId"));
|
||||
QStringLiteral("SELECT t.id as id "
|
||||
"FROM tag t LEFT JOIN noteTagLink l ON t.id = l.tag_id "
|
||||
"WHERE parent_id = :parentId"));
|
||||
|
||||
query.bindValue(QStringLiteral(":parentId"), parentId);
|
||||
|
||||
|
@ -344,9 +335,8 @@ QVector<Tag> Tag::fetchRecursivelyByParentId(const int parentId) {
|
|||
return tagList;
|
||||
}
|
||||
|
||||
QVector<int> Tag::fetchTagIdsRecursivelyByParentId(const int parentId)
|
||||
{
|
||||
QVector<int> tagIdList {parentId};
|
||||
QVector<int> Tag::fetchTagIdsRecursivelyByParentId(const int parentId) {
|
||||
QVector<int> tagIdList{parentId};
|
||||
const auto tagIds = fetchAllIdsByParentId(parentId);
|
||||
tagIdList.reserve(tagIds.size());
|
||||
|
||||
|
@ -380,9 +370,7 @@ QStringList Tag::getParentTagNames() {
|
|||
* Checks if taggingShowNotesRecursively is set
|
||||
*/
|
||||
bool Tag::isTaggingShowNotesRecursively() {
|
||||
return QSettings()
|
||||
.value(QStringLiteral("taggingShowNotesRecursively"))
|
||||
.toBool();
|
||||
return QSettings().value(QStringLiteral("taggingShowNotesRecursively")).toBool();
|
||||
}
|
||||
|
||||
int Tag::countAllParentId(const int parentId) {
|
||||
|
@ -439,14 +427,13 @@ QVector<Tag> Tag::fetchAllOfNote(const Note ¬e) {
|
|||
"l.note_sub_folder_path = :noteSubFolderPath "
|
||||
"ORDER BY t.priority ASC, t.name ASC"));
|
||||
query.bindValue(QStringLiteral(":fileName"), note.getName());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
note.getNoteSubFolder().relativePath());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"), note.getNoteSubFolder().relativePath());
|
||||
|
||||
if (!query.exec()) {
|
||||
qWarning() << __func__ << ": " << query.lastError();
|
||||
} else {
|
||||
for (int r = 0; query.next(); r++) {
|
||||
tagList.append(tagFromQuery(query));
|
||||
tagList.append(tagFromQuery(query));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -461,15 +448,14 @@ QVector<Tag> Tag::fetchAllOfNote(const Note ¬e) {
|
|||
QVector<Tag> Tag::fetchAllOfNotes(const QVector<Note> ¬es) {
|
||||
QVector<Tag> notesTagList;
|
||||
|
||||
//get all tags for the notes list
|
||||
// get all tags for the notes list
|
||||
for (const Note ¬e : notes) {
|
||||
notesTagList.append(Tag::fetchAllOfNote(note));
|
||||
}
|
||||
//sort
|
||||
std::sort (notesTagList.begin(), notesTagList.end());
|
||||
//remove duplicates
|
||||
notesTagList.erase(std::unique(notesTagList.begin(), notesTagList.end()),
|
||||
notesTagList.end());
|
||||
// sort
|
||||
std::sort(notesTagList.begin(), notesTagList.end());
|
||||
// remove duplicates
|
||||
notesTagList.erase(std::unique(notesTagList.begin(), notesTagList.end()), notesTagList.end());
|
||||
|
||||
return notesTagList;
|
||||
}
|
||||
|
@ -489,8 +475,7 @@ QStringList Tag::fetchAllNamesOfNote(const Note ¬e) {
|
|||
"l.note_sub_folder_path = :noteSubFolderPath "
|
||||
"ORDER BY t.priority ASC, t.name ASC"));
|
||||
query.bindValue(QStringLiteral(":fileName"), note.getName());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
note.getNoteSubFolder().relativePath());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"), note.getNoteSubFolder().relativePath());
|
||||
|
||||
if (!query.exec()) {
|
||||
qWarning() << __func__ << ": " << query.lastError();
|
||||
|
@ -518,8 +503,7 @@ QSet<int> Tag::fetchAllIdsByNote(const Note ¬e) {
|
|||
"WHERE note_file_name = :fileName AND "
|
||||
"note_sub_folder_path = :noteSubFolderPath"));
|
||||
query.bindValue(QStringLiteral(":fileName"), note.getName());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
note.getNoteSubFolder().relativePath());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"), note.getNoteSubFolder().relativePath());
|
||||
|
||||
if (!query.exec()) {
|
||||
qWarning() << __func__ << ": " << query.lastError();
|
||||
|
@ -578,15 +562,15 @@ Tag Tag::fetchOneOfNoteWithColor(const Note ¬e) {
|
|||
/**
|
||||
* Checks if a note has tags
|
||||
*/
|
||||
bool Tag::noteHasTags(const Note ¬e, const QString& path) {
|
||||
bool Tag::noteHasTags(const Note ¬e, const QString &path) {
|
||||
QSqlDatabase db = DatabaseService::getNoteFolderDatabase();
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT "
|
||||
"EXISTS (SELECT tag_id FROM noteTagLink "
|
||||
"WHERE note_file_name=:fileName AND "
|
||||
"note_sub_folder_path=:noteSubFolderPath) AS cnt"));
|
||||
QStringLiteral("SELECT "
|
||||
"EXISTS (SELECT tag_id FROM noteTagLink "
|
||||
"WHERE note_file_name=:fileName AND "
|
||||
"note_sub_folder_path=:noteSubFolderPath) AS cnt"));
|
||||
query.bindValue(QStringLiteral(":fileName"), note.getName());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
path.isEmpty() ? note.getNoteSubFolder().relativePath() : path);
|
||||
|
@ -618,8 +602,7 @@ bool Tag::isLinkedToNote(const Note ¬e) const {
|
|||
"note_sub_folder_path = :noteSubFolderPath "
|
||||
"AND tag_id = :tagId"));
|
||||
query.bindValue(QStringLiteral(":fileName"), note.getName());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
note.getNoteSubFolder().relativePath());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"), note.getNoteSubFolder().relativePath());
|
||||
query.bindValue(QStringLiteral(":tagId"), _id);
|
||||
|
||||
if (!query.exec()) {
|
||||
|
@ -689,9 +672,8 @@ QVector<int> Tag::fetchAllLinkedNoteIds(int tagId, const bool fromAllSubfolders,
|
|||
QStringLiteral("SELECT note_file_name, note_sub_folder_path "
|
||||
"FROM noteTagLink WHERE tag_id = :id "
|
||||
"AND note_sub_folder_path LIKE :noteSubFolderPath"));
|
||||
query.bindValue(
|
||||
QStringLiteral(":noteSubFolderPath"),
|
||||
NoteSubFolder::activeNoteSubFolder().relativePath() + "%");
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
NoteSubFolder::activeNoteSubFolder().relativePath() + "%");
|
||||
} else {
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT note_file_name, note_sub_folder_path "
|
||||
|
@ -709,13 +691,11 @@ QVector<int> Tag::fetchAllLinkedNoteIds(int tagId, const bool fromAllSubfolders,
|
|||
for (int r = 0; query.next(); r++) {
|
||||
// always keep in mind that note_file_name is no file name,
|
||||
// but the base name (so "my-note", instead of "my-note.md")
|
||||
const QString name =
|
||||
query.value(QStringLiteral("note_file_name")).toString();
|
||||
const QString name = query.value(QStringLiteral("note_file_name")).toString();
|
||||
const QString noteSubFolderPathData =
|
||||
query.value(QStringLiteral("note_sub_folder_path")).toString();
|
||||
int noteSubFolderId =
|
||||
NoteSubFolder::fetchByPathData(noteSubFolderPathData, QStringLiteral("/"))
|
||||
.getId();
|
||||
NoteSubFolder::fetchByPathData(noteSubFolderPathData, QStringLiteral("/")).getId();
|
||||
int noteId = Note::fetchNoteIdByName(name, noteSubFolderId);
|
||||
noteIdList.append(noteId);
|
||||
}
|
||||
|
@ -729,10 +709,8 @@ QVector<int> Tag::fetchAllLinkedNoteIds(int tagId, const bool fromAllSubfolders,
|
|||
/**
|
||||
* Fetches all linked note ids for a given subfolder
|
||||
*/
|
||||
QVector<int> Tag::fetchAllLinkedNoteIdsForFolder(int tagId,
|
||||
const NoteSubFolder ¬eSubFolder,
|
||||
bool fromAllSubfolders,
|
||||
const bool recursive) {
|
||||
QVector<int> Tag::fetchAllLinkedNoteIdsForFolder(int tagId, const NoteSubFolder ¬eSubFolder,
|
||||
bool fromAllSubfolders, const bool recursive) {
|
||||
QSqlDatabase db = DatabaseService::getNoteFolderDatabase();
|
||||
QSqlQuery query(db);
|
||||
QVector<int> noteIdList;
|
||||
|
@ -747,15 +725,13 @@ QVector<int> Tag::fetchAllLinkedNoteIdsForFolder(int tagId,
|
|||
QStringLiteral("SELECT note_file_name, note_sub_folder_path "
|
||||
"FROM noteTagLink WHERE tag_id = :id "
|
||||
"AND note_sub_folder_path LIKE :noteSubFolderPath"));
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
noteSubFolder.relativePath() + "%");
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"), noteSubFolder.relativePath() + "%");
|
||||
} else {
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT note_file_name, note_sub_folder_path "
|
||||
"FROM noteTagLink WHERE tag_id = :id "
|
||||
"AND note_sub_folder_path = :noteSubFolderPath"));
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
noteSubFolder.relativePath());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"), noteSubFolder.relativePath());
|
||||
}
|
||||
|
||||
query.bindValue(QStringLiteral(":id"), tagId);
|
||||
|
@ -766,13 +742,11 @@ QVector<int> Tag::fetchAllLinkedNoteIdsForFolder(int tagId,
|
|||
for (int r = 0; query.next(); r++) {
|
||||
// always keep in mind that note_file_name is no file name,
|
||||
// but the base name (so "my-note", instead of "my-note.md")
|
||||
const QString name =
|
||||
query.value(QStringLiteral("note_file_name")).toString();
|
||||
const QString name = query.value(QStringLiteral("note_file_name")).toString();
|
||||
const QString noteSubFolderPathData =
|
||||
query.value(QStringLiteral("note_sub_folder_path")).toString();
|
||||
int noteSubFolderId =
|
||||
NoteSubFolder::fetchByPathData(noteSubFolderPathData, QStringLiteral("/"))
|
||||
.getId();
|
||||
NoteSubFolder::fetchByPathData(noteSubFolderPathData, QStringLiteral("/")).getId();
|
||||
int noteId = Note::fetchNoteIdByName(name, noteSubFolderId);
|
||||
noteIdList.append(noteId);
|
||||
}
|
||||
|
@ -800,14 +774,12 @@ QVector<Note> Tag::fetchAllLinkedNotes() const {
|
|||
qWarning() << __func__ << ": " << query.lastError();
|
||||
} else {
|
||||
for (int r = 0; query.next(); r++) {
|
||||
const QString fileName =
|
||||
query.value(QStringLiteral("note_file_name")).toString();
|
||||
const QString fileName = query.value(QStringLiteral("note_file_name")).toString();
|
||||
const QString noteSubFolderPath =
|
||||
query.value(QStringLiteral("note_sub_folder_path")).toString();
|
||||
const auto noteSubFolder = NoteSubFolder::fetchByPathData(
|
||||
std::move(noteSubFolderPath), QStringLiteral("/"));
|
||||
const auto note =
|
||||
Note::fetchByName(fileName, noteSubFolder.getId());
|
||||
const auto noteSubFolder =
|
||||
NoteSubFolder::fetchByPathData(std::move(noteSubFolderPath), QStringLiteral("/"));
|
||||
const auto note = Note::fetchByName(fileName, noteSubFolder.getId());
|
||||
|
||||
noteList << note;
|
||||
}
|
||||
|
@ -864,28 +836,27 @@ QStringList Tag::fetchAllNames() {
|
|||
/**
|
||||
* Count the linked note file names for a note sub folder
|
||||
*/
|
||||
int Tag::countLinkedNoteFileNamesForNoteSubFolder(
|
||||
int tagId, const NoteSubFolder ¬eSubFolder,
|
||||
bool fromAllSubfolders, const bool recursive) {
|
||||
int Tag::countLinkedNoteFileNamesForNoteSubFolder(int tagId, const NoteSubFolder ¬eSubFolder,
|
||||
bool fromAllSubfolders, const bool recursive) {
|
||||
QSqlDatabase db = DatabaseService::getNoteFolderDatabase();
|
||||
QSqlQuery query(db);
|
||||
|
||||
if (fromAllSubfolders) {
|
||||
query.prepare(QStringLiteral(
|
||||
"SELECT COUNT(note_file_name) AS cnt FROM noteTagLink "
|
||||
"WHERE tag_id = :id"));
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT COUNT(note_file_name) AS cnt FROM noteTagLink "
|
||||
"WHERE tag_id = :id"));
|
||||
} else if (recursive) {
|
||||
query.prepare(QStringLiteral(
|
||||
"SELECT COUNT(note_file_name) AS cnt FROM noteTagLink "
|
||||
"WHERE tag_id = :id AND "
|
||||
"note_sub_folder_path LIKE :noteSubFolderPath"));
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT COUNT(note_file_name) AS cnt FROM noteTagLink "
|
||||
"WHERE tag_id = :id AND "
|
||||
"note_sub_folder_path LIKE :noteSubFolderPath"));
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
noteSubFolder.relativePath() + QLatin1Char('%'));
|
||||
} else {
|
||||
query.prepare(QStringLiteral(
|
||||
"SELECT COUNT(note_file_name) AS cnt FROM noteTagLink "
|
||||
"WHERE tag_id = :id AND "
|
||||
"note_sub_folder_path = :noteSubFolderPath"));
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT COUNT(note_file_name) AS cnt FROM noteTagLink "
|
||||
"WHERE tag_id = :id AND "
|
||||
"note_sub_folder_path = :noteSubFolderPath"));
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
noteSubFolder.relativePath() + QLatin1Char('%'));
|
||||
}
|
||||
|
@ -908,28 +879,26 @@ int Tag::countLinkedNoteFileNamesForNoteSubFolder(
|
|||
/**
|
||||
* Count the linked note file names
|
||||
*/
|
||||
int Tag::countLinkedNoteFileNames(int tagId, bool fromAllSubfolders,
|
||||
bool recursive) {
|
||||
int Tag::countLinkedNoteFileNames(int tagId, bool fromAllSubfolders, bool recursive) {
|
||||
QSqlDatabase db = DatabaseService::getNoteFolderDatabase();
|
||||
QSqlQuery query(db);
|
||||
|
||||
if (fromAllSubfolders) {
|
||||
query.prepare(QStringLiteral(
|
||||
"SELECT COUNT(note_file_name) AS cnt FROM noteTagLink "
|
||||
"WHERE tag_id = :id"));
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT COUNT(note_file_name) AS cnt FROM noteTagLink "
|
||||
"WHERE tag_id = :id"));
|
||||
} else if (recursive) {
|
||||
query.prepare(QStringLiteral(
|
||||
"SELECT COUNT(note_file_name) AS cnt FROM noteTagLink "
|
||||
"WHERE tag_id = :id AND "
|
||||
"note_sub_folder_path LIKE :noteSubFolderPath"));
|
||||
query.bindValue(
|
||||
QStringLiteral(":noteSubFolderPath"),
|
||||
NoteSubFolder::activeNoteSubFolder().relativePath() + "%");
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT COUNT(note_file_name) AS cnt FROM noteTagLink "
|
||||
"WHERE tag_id = :id AND "
|
||||
"note_sub_folder_path LIKE :noteSubFolderPath"));
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
NoteSubFolder::activeNoteSubFolder().relativePath() + "%");
|
||||
} else {
|
||||
query.prepare(QStringLiteral(
|
||||
"SELECT COUNT(note_file_name) AS cnt FROM noteTagLink "
|
||||
"WHERE tag_id = :id AND "
|
||||
"note_sub_folder_path = :noteSubFolderPath"));
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT COUNT(note_file_name) AS cnt FROM noteTagLink "
|
||||
"WHERE tag_id = :id AND "
|
||||
"note_sub_folder_path = :noteSubFolderPath"));
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
NoteSubFolder::activeNoteSubFolder().relativePath());
|
||||
}
|
||||
|
@ -959,19 +928,16 @@ bool Tag::store() {
|
|||
|
||||
const int id = _id;
|
||||
if (id > 0) {
|
||||
query.prepare(
|
||||
QStringLiteral("UPDATE tag SET name = :name, priority = :priority, "
|
||||
"parent_id = :parentId, ") %
|
||||
colorField %
|
||||
QStringLiteral(" = :color, "
|
||||
"updated = datetime('now') "
|
||||
"WHERE id = :id"));
|
||||
query.prepare(QStringLiteral("UPDATE tag SET name = :name, priority = :priority, "
|
||||
"parent_id = :parentId, ") %
|
||||
colorField %
|
||||
QStringLiteral(" = :color, "
|
||||
"updated = datetime('now') "
|
||||
"WHERE id = :id"));
|
||||
query.bindValue(QStringLiteral(":id"), id);
|
||||
} else {
|
||||
query.prepare(
|
||||
QStringLiteral("INSERT INTO tag (name, priority, parent_id, ") %
|
||||
colorField %
|
||||
QStringLiteral(") VALUES (:name, :priority, :parentId, :color)"));
|
||||
query.prepare(QStringLiteral("INSERT INTO tag (name, priority, parent_id, ") % colorField %
|
||||
QStringLiteral(") VALUES (:name, :priority, :parentId, :color)"));
|
||||
}
|
||||
|
||||
const int parentId = _parentId;
|
||||
|
@ -979,8 +945,7 @@ bool Tag::store() {
|
|||
query.bindValue(QStringLiteral(":name"), _name);
|
||||
query.bindValue(QStringLiteral(":priority"), _priority);
|
||||
query.bindValue(QStringLiteral(":parentId"), parentId);
|
||||
query.bindValue(QStringLiteral(":color"),
|
||||
_color.isValid() ? _color.name() : QLatin1String(""));
|
||||
query.bindValue(QStringLiteral(":color"), _color.isValid() ? _color.name() : QLatin1String(""));
|
||||
|
||||
if (!query.exec()) {
|
||||
// on error
|
||||
|
@ -996,8 +961,7 @@ bool Tag::store() {
|
|||
// update the parent tag for correct sorting by last use
|
||||
if (parentId > 0) {
|
||||
QSqlQuery parentQuery(db);
|
||||
parentQuery.prepare(
|
||||
QStringLiteral("SELECT * FROM tag WHERE id = :parentId"));
|
||||
parentQuery.prepare(QStringLiteral("SELECT * FROM tag WHERE id = :parentId"));
|
||||
parentQuery.bindValue(QStringLiteral(":parentId"), parentId);
|
||||
|
||||
if (!parentQuery.exec()) {
|
||||
|
@ -1022,9 +986,8 @@ bool Tag::store() {
|
|||
* @return
|
||||
*/
|
||||
QString Tag::colorFieldName() const {
|
||||
return QSettings().value(QStringLiteral("darkMode")).toBool()
|
||||
? QStringLiteral("dark_color")
|
||||
: QStringLiteral("color");
|
||||
return QSettings().value(QStringLiteral("darkMode")).toBool() ? QStringLiteral("dark_color")
|
||||
: QStringLiteral("color");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1045,8 +1008,7 @@ bool Tag::linkToNote(const Note ¬e) const {
|
|||
|
||||
query.bindValue(QStringLiteral(":tagId"), _id);
|
||||
query.bindValue(QStringLiteral(":noteFileName"), note.getName());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
note.getNoteSubFolder().relativePath());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"), note.getNoteSubFolder().relativePath());
|
||||
|
||||
if (!query.exec()) {
|
||||
// we should not show this warning, because we don't check if a
|
||||
|
@ -1061,8 +1023,7 @@ bool Tag::linkToNote(const Note ¬e) const {
|
|||
// update the parent tag for correct sorting by last use
|
||||
if (_parentId > 0) {
|
||||
QSqlQuery parentQuery(db);
|
||||
parentQuery.prepare(
|
||||
QStringLiteral("SELECT * FROM tag WHERE id = :parentId"));
|
||||
parentQuery.prepare(QStringLiteral("SELECT * FROM tag WHERE id = :parentId"));
|
||||
parentQuery.bindValue(QStringLiteral(":parentId"), _parentId);
|
||||
|
||||
if (!parentQuery.exec()) {
|
||||
|
@ -1097,8 +1058,7 @@ bool Tag::removeLinkToNote(const Note ¬e) const {
|
|||
|
||||
query.bindValue(QStringLiteral(":tagId"), _id);
|
||||
query.bindValue(QStringLiteral(":noteFileName"), note.getName());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
note.getNoteSubFolder().relativePath());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"), note.getNoteSubFolder().relativePath());
|
||||
|
||||
if (!query.exec()) {
|
||||
// on error
|
||||
|
@ -1126,8 +1086,7 @@ bool Tag::removeAllLinksToNote(const Note ¬e) {
|
|||
"note_sub_folder_path = :noteSubFolderPath"));
|
||||
|
||||
query.bindValue(QStringLiteral(":noteFileName"), note.getName());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
note.getNoteSubFolder().relativePath());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"), note.getNoteSubFolder().relativePath());
|
||||
|
||||
if (!query.exec()) {
|
||||
// on error
|
||||
|
@ -1190,13 +1149,12 @@ void Tag::removeBrokenLinks() {
|
|||
}
|
||||
|
||||
Note Tag::getNoteFromNoteTagLinkQuery(const QSqlQuery &query) {
|
||||
const QString noteFileName =
|
||||
query.value(QStringLiteral("note_file_name")).toString();
|
||||
const QString noteFileName = query.value(QStringLiteral("note_file_name")).toString();
|
||||
const QString noteSubFolderPath =
|
||||
query.value(QStringLiteral("note_sub_folder_path")).toString();
|
||||
|
||||
const NoteSubFolder noteSubFolder = NoteSubFolder::fetchByPathData(
|
||||
noteSubFolderPath, QStringLiteral("/"));
|
||||
const NoteSubFolder noteSubFolder =
|
||||
NoteSubFolder::fetchByPathData(noteSubFolderPath, QStringLiteral("/"));
|
||||
|
||||
return Note::fetchByName(noteFileName, noteSubFolder.getId());
|
||||
}
|
||||
|
@ -1234,7 +1192,8 @@ bool Tag::removeNoteLinkById(int id) {
|
|||
bool Tag::setNoteLinkByIdStale(int id) {
|
||||
QSqlDatabase db = DatabaseService::getNoteFolderDatabase();
|
||||
QSqlQuery query(db);
|
||||
query.prepare(QStringLiteral("UPDATE noteTagLink SET stale_date = :date WHERE id = :id AND stale_date IS NULL"));
|
||||
query.prepare(QStringLiteral(
|
||||
"UPDATE noteTagLink SET stale_date = :date WHERE id = :id AND stale_date IS NULL"));
|
||||
query.bindValue(QStringLiteral(":id"), id);
|
||||
query.bindValue(QStringLiteral(":date"), QDateTime::currentDateTime());
|
||||
|
||||
|
@ -1300,20 +1259,18 @@ bool Tag::removeExpiredStaleNoteLinkBy() {
|
|||
/**
|
||||
* Renames the note file name of note links
|
||||
*/
|
||||
bool Tag::renameNoteFileNamesOfLinks(const QString &oldFileName,
|
||||
const QString &newFileName,
|
||||
bool Tag::renameNoteFileNamesOfLinks(const QString &oldFileName, const QString &newFileName,
|
||||
const NoteSubFolder ¬eSubFolder) {
|
||||
QSqlDatabase db = DatabaseService::getNoteFolderDatabase();
|
||||
QSqlQuery query(db);
|
||||
query.prepare(QStringLiteral(
|
||||
"UPDATE noteTagLink SET note_file_name = :newFileName WHERE "
|
||||
"note_file_name = :oldFileName AND "
|
||||
"note_sub_folder_path = :noteSubFolderPath"));
|
||||
query.prepare(
|
||||
QStringLiteral("UPDATE noteTagLink SET note_file_name = :newFileName WHERE "
|
||||
"note_file_name = :oldFileName AND "
|
||||
"note_sub_folder_path = :noteSubFolderPath"));
|
||||
|
||||
query.bindValue(QStringLiteral(":oldFileName"), oldFileName);
|
||||
query.bindValue(QStringLiteral(":newFileName"), newFileName);
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"),
|
||||
noteSubFolder.relativePath());
|
||||
query.bindValue(QStringLiteral(":noteSubFolderPath"), noteSubFolder.relativePath());
|
||||
|
||||
if (!query.exec()) {
|
||||
// on error
|
||||
|
@ -1331,14 +1288,13 @@ bool Tag::renameNoteFileNamesOfLinks(const QString &oldFileName,
|
|||
/**
|
||||
* Renames the note sub folder paths of note links
|
||||
*/
|
||||
bool Tag::renameNoteSubFolderPathsOfLinks(const QString &oldPath,
|
||||
const QString &newPath) {
|
||||
bool Tag::renameNoteSubFolderPathsOfLinks(const QString &oldPath, const QString &newPath) {
|
||||
QSqlDatabase db = DatabaseService::getNoteFolderDatabase();
|
||||
QSqlQuery query(db);
|
||||
query.prepare(QStringLiteral(
|
||||
"UPDATE noteTagLink SET note_sub_folder_path = "
|
||||
"replace(note_sub_folder_path, :oldPath, :newPath) WHERE "
|
||||
"note_sub_folder_path LIKE :oldPathLike"));
|
||||
query.prepare(
|
||||
QStringLiteral("UPDATE noteTagLink SET note_sub_folder_path = "
|
||||
"replace(note_sub_folder_path, :oldPath, :newPath) WHERE "
|
||||
"note_sub_folder_path LIKE :oldPathLike"));
|
||||
|
||||
query.bindValue(QStringLiteral(":oldPath"), oldPath);
|
||||
query.bindValue(QStringLiteral(":oldPathLike"), oldPath + "%");
|
||||
|
@ -1426,14 +1382,11 @@ bool Tag::mergeFromDatabase(QSqlDatabase &db) {
|
|||
|
||||
const bool isSameTagTable =
|
||||
DatabaseService::generateDatabaseTableSha1Signature(db, "tag") ==
|
||||
DatabaseService::generateDatabaseTableSha1Signature(noteFolderDB,
|
||||
"tag");
|
||||
DatabaseService::generateDatabaseTableSha1Signature(noteFolderDB, "tag");
|
||||
|
||||
const bool isSameNoteTagLinkTable =
|
||||
DatabaseService::generateDatabaseTableSha1Signature(db,
|
||||
"noteTagLink") ==
|
||||
DatabaseService::generateDatabaseTableSha1Signature(noteFolderDB,
|
||||
"noteTagLink");
|
||||
DatabaseService::generateDatabaseTableSha1Signature(db, "noteTagLink") ==
|
||||
DatabaseService::generateDatabaseTableSha1Signature(noteFolderDB, "noteTagLink");
|
||||
|
||||
// if those tables are the same everything is ok
|
||||
if (isSameTagTable && isSameNoteTagLinkTable) {
|
||||
|
@ -1457,8 +1410,7 @@ bool Tag::mergeFromDatabase(QSqlDatabase &db) {
|
|||
* created
|
||||
* @return Tag object of deepest tag of the name breadcrumb list
|
||||
*/
|
||||
Tag Tag::getTagByNameBreadcrumbList(const QStringList &nameList,
|
||||
bool createMissing) {
|
||||
Tag Tag::getTagByNameBreadcrumbList(const QStringList &nameList, bool createMissing) {
|
||||
int parentId = 0;
|
||||
Tag tag;
|
||||
|
||||
|
@ -1488,7 +1440,7 @@ bool Tag::operator==(const Tag &tag) const { return _id == tag._id; }
|
|||
bool Tag::operator<(const Tag &tag) const { return _name < tag._name; }
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Tag &tag) {
|
||||
dbg.nospace() << "Tag: <id>" << tag._id << " <name>" << tag._name
|
||||
<< " <parentId>" << tag._parentId;
|
||||
dbg.nospace() << "Tag: <id>" << tag._id << " <name>" << tag._name << " <parentId>"
|
||||
<< tag._parentId;
|
||||
return dbg.space();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ class NoteSubFolder;
|
|||
|
||||
struct TagHeader {
|
||||
TagHeader() = default;
|
||||
TagHeader(int id, QString name) : _id {id}, _name{std::move(name)} {}
|
||||
TagHeader(int id, QString name) : _id{id}, _name{std::move(name)} {}
|
||||
int _id = 0;
|
||||
QString _name{QLatin1String("")};
|
||||
|
||||
|
@ -36,7 +36,7 @@ class Tag : protected TagHeader {
|
|||
|
||||
inline int getId() const { return _id; }
|
||||
|
||||
inline const QString& getName() const { return _name; }
|
||||
inline const QString &getName() const { return _name; }
|
||||
|
||||
inline void setName(QString text) { _name = text; }
|
||||
|
||||
|
@ -50,7 +50,6 @@ class Tag : protected TagHeader {
|
|||
|
||||
bool isFetched() const;
|
||||
|
||||
|
||||
int getPriority() const;
|
||||
|
||||
void setPriority(const int value);
|
||||
|
@ -63,25 +62,23 @@ class Tag : protected TagHeader {
|
|||
|
||||
bool removeLinkToNote(const Note ¬e) const;
|
||||
|
||||
static QVector<int> fetchAllLinkedNoteIds(int tagId,
|
||||
const bool fromAllSubfolders,
|
||||
const bool recursive = true);
|
||||
static QVector<int> fetchAllLinkedNoteIds(int tagId, const bool fromAllSubfolders,
|
||||
const bool recursive = true);
|
||||
|
||||
static QVector<int> fetchAllLinkedNoteIdsForFolder(
|
||||
int tagId,
|
||||
const NoteSubFolder ¬eSubFolder, bool fromAllSubfolders,
|
||||
const bool recursive = true);
|
||||
static QVector<int> fetchAllLinkedNoteIdsForFolder(int tagId,
|
||||
const NoteSubFolder ¬eSubFolder,
|
||||
bool fromAllSubfolders,
|
||||
const bool recursive = true);
|
||||
|
||||
QVector<Note> fetchAllLinkedNotes() const;
|
||||
|
||||
bool isLinkedToNote(const Note ¬e) const;
|
||||
|
||||
static int countLinkedNoteFileNames(int tagId, bool fromAllSubfolders,
|
||||
bool recursive);
|
||||
static int countLinkedNoteFileNames(int tagId, bool fromAllSubfolders, bool recursive);
|
||||
|
||||
static int countLinkedNoteFileNamesForNoteSubFolder(
|
||||
int tagId, const NoteSubFolder ¬eSubFolder,
|
||||
bool fromAllSubfolders, bool recursive);
|
||||
static int countLinkedNoteFileNamesForNoteSubFolder(int tagId,
|
||||
const NoteSubFolder ¬eSubFolder,
|
||||
bool fromAllSubfolders, bool recursive);
|
||||
|
||||
int getParentId() const;
|
||||
|
||||
|
@ -116,31 +113,27 @@ class Tag : protected TagHeader {
|
|||
|
||||
static bool removeAllLinksToNote(const Note ¬e);
|
||||
|
||||
static bool renameNoteFileNamesOfLinks(const QString &oldFileName,
|
||||
const QString &newFileName,
|
||||
static bool renameNoteFileNamesOfLinks(const QString &oldFileName, const QString &newFileName,
|
||||
const NoteSubFolder ¬eSubFolder);
|
||||
|
||||
static bool renameNoteSubFolderPathsOfLinks(const QString &oldPath,
|
||||
const QString &newPath);
|
||||
static bool renameNoteSubFolderPathsOfLinks(const QString &oldPath, const QString &newPath);
|
||||
|
||||
static Tag fetch(const int id);
|
||||
|
||||
static Tag tagFromQuery(const QSqlQuery &query);
|
||||
|
||||
static QVector<Tag> fetchAllWithLinkToNoteNames(
|
||||
const QStringList ¬eNameList);
|
||||
static QVector<Tag> fetchAllWithLinkToNoteNames(const QStringList ¬eNameList);
|
||||
|
||||
static QVector<TagHeader> fetchAllTagHeadersByParentId(const int parentId);
|
||||
|
||||
static QVector<Tag> fetchAllByParentId(
|
||||
const int parentId,
|
||||
const QString &sortBy = QStringLiteral("created DESC"));
|
||||
static QVector<Tag> fetchAllByParentId(const int parentId,
|
||||
const QString &sortBy = QStringLiteral("created DESC"));
|
||||
|
||||
static QVector<int> fetchAllIdsByParentId(const int parentId);
|
||||
|
||||
static int countAllParentId(const int parentId);
|
||||
|
||||
static bool noteHasTags(const Note ¬e, const QString& path);
|
||||
static bool noteHasTags(const Note ¬e, const QString &path);
|
||||
|
||||
static void setAsActive(const int tagId);
|
||||
|
||||
|
@ -170,10 +163,9 @@ class Tag : protected TagHeader {
|
|||
|
||||
static bool mergeFromDatabase(QSqlDatabase &db);
|
||||
|
||||
static Tag getTagByNameBreadcrumbList(const QStringList &nameList,
|
||||
bool createMissing);
|
||||
static Tag getTagByNameBreadcrumbList(const QStringList &nameList, bool createMissing);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
int _parentId;
|
||||
int _priority;
|
||||
QColor _color;
|
||||
|
|
|
@ -30,9 +30,7 @@ qint64 TrashItem::getFileSize() { return this->fileSize; }
|
|||
|
||||
QString TrashItem::getFileName() { return this->fileName; }
|
||||
|
||||
NoteSubFolder TrashItem::getNoteSubFolder() {
|
||||
return NoteSubFolder::fetch(this->noteSubFolderId);
|
||||
}
|
||||
NoteSubFolder TrashItem::getNoteSubFolder() { return NoteSubFolder::fetch(this->noteSubFolderId); }
|
||||
|
||||
void TrashItem::setNoteSubFolder(const NoteSubFolder ¬eSubFolder) {
|
||||
this->noteSubFolderPathData = noteSubFolder.pathData();
|
||||
|
@ -84,8 +82,7 @@ bool TrashItem::remove(bool withFile) {
|
|||
* Returns the full path of the trashed file
|
||||
*/
|
||||
QString TrashItem::fullFilePath() {
|
||||
return NoteFolder::currentTrashPath() + QDir::separator() +
|
||||
QString::number(getId());
|
||||
return NoteFolder::currentTrashPath() + QDir::separator() + QString::number(getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,8 +155,7 @@ bool TrashItem::doTrashing() {
|
|||
QDir destinationDir(destinationPath);
|
||||
|
||||
// created the trash folder if it doesn't exist
|
||||
if (!destinationDir.exists() &&
|
||||
!destinationDir.mkpath(destinationDir.path())) {
|
||||
if (!destinationDir.exists() && !destinationDir.mkpath(destinationDir.path())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -211,8 +207,7 @@ QString TrashItem::restorationFilePath() {
|
|||
// prepend the current timestamp if the file already exists
|
||||
if (file.exists()) {
|
||||
filePath = folderPath + QDir::separator() +
|
||||
QString::number(QDateTime::currentMSecsSinceEpoch() / 1000) +
|
||||
"_" + fileName;
|
||||
QString::number(QDateTime::currentMSecsSinceEpoch() / 1000) + "_" + fileName;
|
||||
}
|
||||
|
||||
file.setFileName(filePath);
|
||||
|
@ -224,8 +219,7 @@ QString TrashItem::restorationFilePath() {
|
|||
const quint32 number = QRandomGenerator::global()->generate();
|
||||
#endif
|
||||
|
||||
filePath = folderPath + QDir::separator() + QString::number(number) +
|
||||
"_" + fileName;
|
||||
filePath = folderPath + QDir::separator() + QString::number(number) + "_" + fileName;
|
||||
}
|
||||
|
||||
file.setFileName(filePath);
|
||||
|
@ -255,8 +249,7 @@ TrashItem TrashItem::trashItemFromQuery(const QSqlQuery &query) {
|
|||
bool TrashItem::fillFromQuery(const QSqlQuery &query) {
|
||||
id = query.value(QStringLiteral("id")).toInt();
|
||||
fileName = query.value(QStringLiteral("file_name")).toString();
|
||||
noteSubFolderPathData =
|
||||
query.value(QStringLiteral("note_sub_folder_path_data")).toString();
|
||||
noteSubFolderPathData = query.value(QStringLiteral("note_sub_folder_path_data")).toString();
|
||||
fileSize = query.value(QStringLiteral("file_size")).toLongLong();
|
||||
created = query.value(QStringLiteral("created")).toDateTime();
|
||||
|
||||
|
@ -273,8 +266,7 @@ QList<TrashItem> TrashItem::fetchAll(int limit) {
|
|||
QSqlQuery query(db);
|
||||
|
||||
QList<TrashItem> trashItemList;
|
||||
QString sql =
|
||||
QStringLiteral("SELECT * FROM trashItem ORDER BY created DESC");
|
||||
QString sql = QStringLiteral("SELECT * FROM trashItem ORDER BY created DESC");
|
||||
|
||||
if (limit >= 0) {
|
||||
sql += QLatin1String(" LIMIT :limit");
|
||||
|
@ -309,8 +301,7 @@ QList<TrashItem> TrashItem::fetchAllExpired() {
|
|||
QSqlQuery query(db);
|
||||
QSettings settings;
|
||||
QList<TrashItem> trashItemList;
|
||||
int days = settings.value(QStringLiteral("localTrash/autoCleanupDays"), 30)
|
||||
.toInt();
|
||||
int days = settings.value(QStringLiteral("localTrash/autoCleanupDays"), 30).toInt();
|
||||
QDateTime dateTime = QDateTime::currentDateTime().addDays(-1 * days);
|
||||
QString sql =
|
||||
"SELECT * FROM trashItem WHERE created < :created "
|
||||
|
@ -363,8 +354,7 @@ bool TrashItem::store() {
|
|||
|
||||
query.bindValue(QStringLiteral(":file_name"), fileName);
|
||||
query.bindValue(QStringLiteral(":file_size"), fileSize);
|
||||
query.bindValue(QStringLiteral(":note_sub_folder_path_data"),
|
||||
noteSubFolderPathData);
|
||||
query.bindValue(QStringLiteral(":note_sub_folder_path_data"), noteSubFolderPathData);
|
||||
|
||||
// on error
|
||||
if (!query.exec()) {
|
||||
|
@ -524,8 +514,7 @@ int TrashItem::countAll() {
|
|||
|
||||
bool TrashItem::isLocalTrashEnabled() {
|
||||
QSettings settings;
|
||||
return settings.value(QStringLiteral("localTrash/supportEnabled"), true)
|
||||
.toBool();
|
||||
return settings.value(QStringLiteral("localTrash/supportEnabled"), true).toBool();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -537,8 +526,7 @@ bool TrashItem::expireItems() {
|
|||
QSettings settings;
|
||||
|
||||
if (!TrashItem::isLocalTrashEnabled() ||
|
||||
!settings.value(QStringLiteral("localTrash/autoCleanupEnabled"), true)
|
||||
.toBool()) {
|
||||
!settings.value(QStringLiteral("localTrash/autoCleanupEnabled"), true).toBool()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -555,11 +543,9 @@ bool TrashItem::expireItems() {
|
|||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const TrashItem &trashItem) {
|
||||
NoteSubFolder noteSubFolder =
|
||||
NoteSubFolder::fetchByPathData(trashItem.noteSubFolderPathData);
|
||||
dbg.nospace() << "TrashItem: <id>" << trashItem.id << " <fileName>"
|
||||
<< trashItem.fileName << " <noteSubFolderId>"
|
||||
<< trashItem.noteSubFolderId << " <_fullNoteFilePath>"
|
||||
NoteSubFolder noteSubFolder = NoteSubFolder::fetchByPathData(trashItem.noteSubFolderPathData);
|
||||
dbg.nospace() << "TrashItem: <id>" << trashItem.id << " <fileName>" << trashItem.fileName
|
||||
<< " <noteSubFolderId>" << trashItem.noteSubFolderId << " <_fullNoteFilePath>"
|
||||
<< trashItem._fullNoteFilePath << " <relativePath>"
|
||||
<< noteSubFolder.relativePath();
|
||||
return dbg.space();
|
||||
|
|
|
@ -31,8 +31,7 @@ class LanguageCache : public QTextBlockUserData {
|
|||
QMapIterator<QPair<int, int>, QString> it(languages);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if (it.key().first <= pos &&
|
||||
it.key().first + it.key().second >= pos) {
|
||||
if (it.key().first <= pos && it.key().first + it.key().second >= pos) {
|
||||
return it.value();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,30 +12,24 @@ ClientProxy::ClientProxy(QObject *parent) : QObject(parent) {}
|
|||
QNetworkProxy ClientProxy::proxyFromSettings() {
|
||||
QNetworkProxy proxy;
|
||||
QSettings settings;
|
||||
QString proxyHostName =
|
||||
settings.value(QStringLiteral("networking/proxyHostName")).toString();
|
||||
QString proxyHostName = settings.value(QStringLiteral("networking/proxyHostName")).toString();
|
||||
|
||||
if (proxyHostName.isEmpty()) {
|
||||
return QNetworkProxy();
|
||||
}
|
||||
|
||||
int proxyPort =
|
||||
settings.value(QStringLiteral("networking/proxyPort")).toInt();
|
||||
int proxyNeedsAuth =
|
||||
settings.value(QStringLiteral("networking/proxyNeedsAuth")).toBool();
|
||||
int proxyPort = settings.value(QStringLiteral("networking/proxyPort")).toInt();
|
||||
int proxyNeedsAuth = settings.value(QStringLiteral("networking/proxyNeedsAuth")).toBool();
|
||||
|
||||
proxy.setHostName(proxyHostName);
|
||||
proxy.setPort(proxyPort);
|
||||
|
||||
if (proxyNeedsAuth) {
|
||||
QString proxyUser =
|
||||
settings.value(QStringLiteral("networking/proxyUser")).toString();
|
||||
QString proxyUser = settings.value(QStringLiteral("networking/proxyUser")).toString();
|
||||
QString proxyPassword =
|
||||
settings.value(QStringLiteral("networking/proxyPassword"))
|
||||
.toString();
|
||||
settings.value(QStringLiteral("networking/proxyPassword")).toString();
|
||||
proxy.setUser(proxyUser);
|
||||
proxy.setPassword(
|
||||
CryptoService::instance()->decryptToString(proxyPassword));
|
||||
proxy.setPassword(CryptoService::instance()->decryptToString(proxyPassword));
|
||||
}
|
||||
|
||||
return proxy;
|
||||
|
@ -43,26 +37,19 @@ QNetworkProxy ClientProxy::proxyFromSettings() {
|
|||
|
||||
bool ClientProxy::isUsingSystemDefault() {
|
||||
QSettings settings;
|
||||
int proxyType = settings
|
||||
.value(QStringLiteral("networking/proxyType"),
|
||||
QNetworkProxy::NoProxy)
|
||||
.toInt();
|
||||
int proxyType =
|
||||
settings.value(QStringLiteral("networking/proxyType"), QNetworkProxy::NoProxy).toInt();
|
||||
return proxyType == QNetworkProxy::DefaultProxy;
|
||||
}
|
||||
|
||||
QString printQNetworkProxy(const QNetworkProxy &proxy) {
|
||||
return QStringLiteral("%1://%2:%3")
|
||||
.arg(proxy.type())
|
||||
.arg(proxy.hostName())
|
||||
.arg(proxy.port());
|
||||
return QStringLiteral("%1://%2:%3").arg(proxy.type()).arg(proxy.hostName()).arg(proxy.port());
|
||||
}
|
||||
|
||||
void ClientProxy::setupQtProxyFromSettings() {
|
||||
QSettings settings;
|
||||
int proxyType = settings
|
||||
.value(QStringLiteral("networking/proxyType"),
|
||||
QNetworkProxy::NoProxy)
|
||||
.toInt();
|
||||
int proxyType =
|
||||
settings.value(QStringLiteral("networking/proxyType"), QNetworkProxy::NoProxy).toInt();
|
||||
QNetworkProxy proxy = proxyFromSettings();
|
||||
|
||||
switch (proxyType) {
|
||||
|
@ -77,15 +64,13 @@ void ClientProxy::setupQtProxyFromSettings() {
|
|||
break;
|
||||
case QNetworkProxy::Socks5Proxy:
|
||||
proxy.setType(QNetworkProxy::Socks5Proxy);
|
||||
qDebug() << "Set proxy configuration to SOCKS5"
|
||||
<< printQNetworkProxy(proxy);
|
||||
qDebug() << "Set proxy configuration to SOCKS5" << printQNetworkProxy(proxy);
|
||||
QNetworkProxyFactory::setUseSystemConfiguration(false);
|
||||
QNetworkProxy::setApplicationProxy(proxy);
|
||||
break;
|
||||
case QNetworkProxy::HttpProxy:
|
||||
proxy.setType(QNetworkProxy::HttpProxy);
|
||||
qDebug() << "Set proxy configuration to HTTP"
|
||||
<< printQNetworkProxy(proxy);
|
||||
qDebug() << "Set proxy configuration to HTTP" << printQNetworkProxy(proxy);
|
||||
QNetworkProxyFactory::setUseSystemConfiguration(false);
|
||||
QNetworkProxy::setApplicationProxy(proxy);
|
||||
break;
|
||||
|
@ -114,18 +99,15 @@ const char *ClientProxy::proxyTypeToCStr(QNetworkProxy::ProxyType type) {
|
|||
}
|
||||
}
|
||||
|
||||
void ClientProxy::lookupSystemProxyAsync(const QUrl &url, QObject *dst,
|
||||
const char *slot) {
|
||||
void ClientProxy::lookupSystemProxyAsync(const QUrl &url, QObject *dst, const char *slot) {
|
||||
auto *runnable = new SystemProxyRunnable(url);
|
||||
QObject::connect(runnable, SIGNAL(systemProxyLookedUp(QNetworkProxy)), dst,
|
||||
slot);
|
||||
QObject::connect(runnable, SIGNAL(systemProxyLookedUp(QNetworkProxy)), dst, slot);
|
||||
|
||||
// takes ownership and deletes
|
||||
QThreadPool::globalInstance()->start(runnable);
|
||||
}
|
||||
|
||||
SystemProxyRunnable::SystemProxyRunnable(QUrl url)
|
||||
: QObject(), QRunnable(), _url(std::move(url)) {}
|
||||
SystemProxyRunnable::SystemProxyRunnable(QUrl url) : QObject(), QRunnable(), _url(std::move(url)) {}
|
||||
|
||||
void SystemProxyRunnable::run() {
|
||||
qDebug() << Q_FUNC_INFO << "Starting system proxy lookup";
|
||||
|
|
|
@ -14,8 +14,7 @@ class ClientProxy : public QObject {
|
|||
explicit ClientProxy(QObject *parent = 0);
|
||||
|
||||
static bool isUsingSystemDefault();
|
||||
static void lookupSystemProxyAsync(const QUrl &url, QObject *dst,
|
||||
const char *slot);
|
||||
static void lookupSystemProxyAsync(const QUrl &url, QObject *dst, const char *slot);
|
||||
static QNetworkProxy proxyFromSettings();
|
||||
|
||||
public slots:
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#include "codetohtmlconverter.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QStringBuilder>
|
||||
#include <QtCore/QRegularExpression>
|
||||
#include <QDebug>
|
||||
|
||||
#include "libraries/qmarkdowntextedit/qownlanguagedata.h"
|
||||
|
||||
QHash<QString, CodeToHtmlConverter::Lang>
|
||||
CodeToHtmlConverter::_langStringToEnum;
|
||||
QHash<QString, CodeToHtmlConverter::Lang> CodeToHtmlConverter::_langStringToEnum;
|
||||
|
||||
CodeToHtmlConverter::CodeToHtmlConverter(const QString &lang) Q_DECL_NOTHROW {
|
||||
if (_langStringToEnum.isEmpty()) initCodeLangs();
|
||||
|
@ -54,10 +53,12 @@ void CodeToHtmlConverter::initCodeLangs() Q_DECL_NOTHROW {
|
|||
|
||||
QString CodeToHtmlConverter::process(const QString &input) const {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
qDebug() << "Going to highlight input:" << StringView(input).mid(0, 12) << ", with lang:" << _currentLang;
|
||||
qDebug() << "Going to highlight input:" << StringView(input).mid(0, 12)
|
||||
<< ", with lang:" << _currentLang;
|
||||
return process(StringView(input));
|
||||
#else
|
||||
qDebug() << "Going to highlight input:" << StringView(&input).mid(0, 12) << ", with lang:" << _currentLang;
|
||||
qDebug() << "Going to highlight input:" << StringView(&input).mid(0, 12)
|
||||
<< ", with lang:" << _currentLang;
|
||||
return process(StringView(&input));
|
||||
#endif
|
||||
}
|
||||
|
@ -157,14 +158,12 @@ QString CodeToHtmlConverter::process(StringView input) const {
|
|||
for (int i = 0; i < textLen; ++i) {
|
||||
if (input.at(i) == QLatin1Char(' ')) {
|
||||
output += (QLatin1Char(' '));
|
||||
} else if (input.at(i) == QLatin1Char('\'') ||
|
||||
input.at(i) == QLatin1Char('"')) {
|
||||
} else if (input.at(i) == QLatin1Char('\'') || input.at(i) == QLatin1Char('"')) {
|
||||
i = highlightStringLiterals(input, input.at(i), output, i);
|
||||
} else if (input.at(i).isDigit()) {
|
||||
i = highlightNumericLit(input, output, i);
|
||||
} else if (comment.isNull() && input.at(i) == QLatin1Char('/')) {
|
||||
if (input.at(i + 1) == QLatin1Char('/'))
|
||||
i = highlightComment(input, output, i);
|
||||
if (input.at(i + 1) == QLatin1Char('/')) i = highlightComment(input, output, i);
|
||||
// Multiline comment i.e /* */
|
||||
else if (input.at(i + 1) == QLatin1Char('*'))
|
||||
i = highlightComment(input, output, i, false);
|
||||
|
@ -172,8 +171,7 @@ QString CodeToHtmlConverter::process(StringView input) const {
|
|||
output += escape(input.at(i));
|
||||
} else if (input.at(i) == comment) {
|
||||
i = highlightComment(input, output, i);
|
||||
} else if (input.at(i) == QLatin1Char('<') ||
|
||||
input.at(i) == QLatin1Char('>') ||
|
||||
} else if (input.at(i) == QLatin1Char('<') || input.at(i) == QLatin1Char('>') ||
|
||||
input.at(i) == QLatin1Char('&')) {
|
||||
output += escape(input.at(i));
|
||||
} else if (input.at(i).isLetter()) {
|
||||
|
@ -227,8 +225,7 @@ QString CodeToHtmlConverter::process(StringView input) const {
|
|||
return output;
|
||||
}
|
||||
|
||||
int CodeToHtmlConverter::highlightNumericLit(StringView input, QString &output,
|
||||
int i) const {
|
||||
int CodeToHtmlConverter::highlightNumericLit(StringView input, QString &output, int i) const {
|
||||
bool isPreAllowed = false;
|
||||
if (i == 0)
|
||||
isPreAllowed = true;
|
||||
|
@ -274,8 +271,7 @@ int CodeToHtmlConverter::highlightNumericLit(StringView input, QString &output,
|
|||
++i;
|
||||
|
||||
// hex numbers highlighting (only if there's a preceding zero)
|
||||
if (input.at(i) == QLatin1Char('x') && input.at(i - 1) == QLatin1Char('0'))
|
||||
++i;
|
||||
if (input.at(i) == QLatin1Char('x') && input.at(i - 1) == QLatin1Char('0')) ++i;
|
||||
|
||||
// unroll till we find a non number
|
||||
while (i < input.length()) {
|
||||
|
@ -310,19 +306,15 @@ int CodeToHtmlConverter::highlightNumericLit(StringView input, QString &output,
|
|||
isPostAllowed = true;
|
||||
break;
|
||||
case 'p':
|
||||
if (_currentLang == CodeCSS &&
|
||||
input.at(i + 2) == QLatin1Char('x'))
|
||||
if ((i + 3 < input.length()) &&
|
||||
(input.at(i + 3) == QLatin1Char(';') ||
|
||||
input.at(i + 3) == QLatin1Char('\n')))
|
||||
if (_currentLang == CodeCSS && input.at(i + 2) == QLatin1Char('x'))
|
||||
if ((i + 3 < input.length()) && (input.at(i + 3) == QLatin1Char(';') ||
|
||||
input.at(i + 3) == QLatin1Char('\n')))
|
||||
isPostAllowed = true;
|
||||
break;
|
||||
case 'e':
|
||||
if (_currentLang == CodeCSS &&
|
||||
input.at(i + 2) == QLatin1Char('m'))
|
||||
if ((i + 3 < input.length()) &&
|
||||
(input.at(i + 3) == QLatin1Char(';') ||
|
||||
input.at(i + 3) == QLatin1Char('\n')))
|
||||
if (_currentLang == CodeCSS && input.at(i + 2) == QLatin1Char('m'))
|
||||
if ((i + 3 < input.length()) && (input.at(i + 3) == QLatin1Char(';') ||
|
||||
input.at(i + 3) == QLatin1Char('\n')))
|
||||
isPostAllowed = true;
|
||||
break;
|
||||
// for 100u, 1.0F
|
||||
|
@ -357,8 +349,7 @@ int CodeToHtmlConverter::highlightNumericLit(StringView input, QString &output,
|
|||
}
|
||||
}
|
||||
|
||||
int CodeToHtmlConverter::highlightStringLiterals(StringView input,
|
||||
QChar strType, QString &output,
|
||||
int CodeToHtmlConverter::highlightStringLiterals(StringView input, QChar strType, QString &output,
|
||||
int i) {
|
||||
int start = i;
|
||||
++i;
|
||||
|
@ -400,11 +391,10 @@ int CodeToHtmlConverter::highlightStringLiterals(StringView input,
|
|||
case '6':
|
||||
case '7': {
|
||||
if (i + 4 <= input.length()) {
|
||||
const bool isCurrentOctal =
|
||||
(isOctal(input.at(i + 2).toLatin1()) &&
|
||||
isOctal(input.at(i + 3).toLatin1()))
|
||||
? true
|
||||
: false;
|
||||
const bool isCurrentOctal = (isOctal(input.at(i + 2).toLatin1()) &&
|
||||
isOctal(input.at(i + 3).toLatin1()))
|
||||
? true
|
||||
: false;
|
||||
if (!isCurrentOctal) break;
|
||||
len = isCurrentOctal ? 4 : 0;
|
||||
}
|
||||
|
@ -414,8 +404,7 @@ int CodeToHtmlConverter::highlightStringLiterals(StringView input,
|
|||
case 'x': {
|
||||
if (i + 3 <= input.length()) {
|
||||
const bool isCurrentHex =
|
||||
(isHex(input.at(i + 2).toLatin1()) &&
|
||||
isHex(input.at(i + 3).toLatin1()))
|
||||
(isHex(input.at(i + 2).toLatin1()) && isHex(input.at(i + 3).toLatin1()))
|
||||
? true
|
||||
: false;
|
||||
if (!isCurrentHex) break;
|
||||
|
@ -447,7 +436,8 @@ int CodeToHtmlConverter::highlightStringLiterals(StringView input,
|
|||
++i;
|
||||
}
|
||||
|
||||
if (!input.isEmpty() && i >= input.length() && input.at(input.length() - 1) == QLatin1Char('\n')) {
|
||||
if (!input.isEmpty() && i >= input.length() &&
|
||||
input.at(input.length() - 1) == QLatin1Char('\n')) {
|
||||
// move one position backwards, we want to insert </span> so
|
||||
// that it's like </span>\n and not \n</span> i.e., new line
|
||||
// should be after
|
||||
|
@ -457,14 +447,15 @@ int CodeToHtmlConverter::highlightStringLiterals(StringView input,
|
|||
|
||||
// decrement i, this ensures that
|
||||
// - if current pos wasn't a string we are back to the string start char
|
||||
// - if it was a string, we will be at string end char thus not skipping the next character in the next loop iteration
|
||||
// - if it was a string, we will be at string end char thus not skipping the next character in
|
||||
// the next loop iteration
|
||||
--i;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
int CodeToHtmlConverter::highlightComment(StringView input, QString &output,
|
||||
int i, bool isSingleLine) {
|
||||
int CodeToHtmlConverter::highlightComment(StringView input, QString &output, int i,
|
||||
bool isSingleLine) {
|
||||
int endPos = -1;
|
||||
if (isSingleLine) {
|
||||
endPos = input.indexOf(QLatin1Char('\n'), i);
|
||||
|
@ -485,14 +476,12 @@ int CodeToHtmlConverter::highlightComment(StringView input, QString &output,
|
|||
return i;
|
||||
}
|
||||
|
||||
int CodeToHtmlConverter::highlightWord(int i, const LangData &data,
|
||||
StringView input, QString &output,
|
||||
CodeToHtmlConverter::Format f) {
|
||||
int CodeToHtmlConverter::highlightWord(int i, const LangData &data, StringView input,
|
||||
QString &output, CodeToHtmlConverter::Format f) {
|
||||
if (data.isEmpty()) return i;
|
||||
// check if we are at the beginning OR if this is the start of a word
|
||||
// AND the current char is present in the data structure
|
||||
if (i == 0 || (!input.at(i - 1).isLetterOrNumber() &&
|
||||
input.at(i - 1) != QLatin1Char('_'))) {
|
||||
if (i == 0 || (!input.at(i - 1).isLetterOrNumber() && input.at(i - 1) != QLatin1Char('_'))) {
|
||||
const auto wordList = data.values(input.at(i).toLatin1());
|
||||
for (const auto &word : wordList) {
|
||||
if (word == input.mid(i, word.size())) {
|
||||
|
@ -515,8 +504,7 @@ QString CodeToHtmlConverter::xmlHighlighter(StringView input) const {
|
|||
QString output = QLatin1String("");
|
||||
|
||||
for (int i = 0; i < textLen; ++i) {
|
||||
if (input.at(i) == QLatin1Char('<') &&
|
||||
input.at(i + 1) != QLatin1Char('!')) {
|
||||
if (input.at(i) == QLatin1Char('<') && input.at(i + 1) != QLatin1Char('!')) {
|
||||
const int found = input.indexOf(QLatin1Char('>'), i);
|
||||
if (found > 0) {
|
||||
output += escape(input.at(i));
|
||||
|
@ -539,10 +527,9 @@ QString CodeToHtmlConverter::xmlHighlighter(StringView input) const {
|
|||
output += setFormat(captured, Format::Builtin);
|
||||
} else {
|
||||
int eqPos = captured.indexOf(QLatin1Char('='));
|
||||
output +=
|
||||
setFormat(captured.left(eqPos), Format::Builtin) + "=" +
|
||||
setFormat(captured.mid(eqPos + 1, captured.length() - eqPos - 1),
|
||||
Format::String);
|
||||
output += setFormat(captured.left(eqPos), Format::Builtin) + "=" +
|
||||
setFormat(captured.mid(eqPos + 1, captured.length() - eqPos - 1),
|
||||
Format::String);
|
||||
}
|
||||
|
||||
if (matchIt.hasNext()) {
|
||||
|
@ -556,8 +543,7 @@ QString CodeToHtmlConverter::xmlHighlighter(StringView input) const {
|
|||
}
|
||||
}
|
||||
|
||||
else if (input.at(i) == QLatin1Char('\"') ||
|
||||
input.at(i) == QLatin1Char('\'')) {
|
||||
else if (input.at(i) == QLatin1Char('\"') || input.at(i) == QLatin1Char('\'')) {
|
||||
// find the next end of string
|
||||
int next = input.indexOf(input.at(i), i + 1);
|
||||
bool isEndline = false;
|
||||
|
@ -584,8 +570,7 @@ QString CodeToHtmlConverter::xmlHighlighter(StringView input) const {
|
|||
* @brief CSS highlighter
|
||||
* @return
|
||||
*/
|
||||
QString CodeToHtmlConverter::cssHighlighter(StringView input,
|
||||
const LangData &types,
|
||||
QString CodeToHtmlConverter::cssHighlighter(StringView input, const LangData &types,
|
||||
const LangData &keywords) const {
|
||||
if (input.isEmpty()) return QLatin1String("");
|
||||
const auto textLen = input.length();
|
||||
|
@ -596,8 +581,7 @@ QString CodeToHtmlConverter::cssHighlighter(StringView input,
|
|||
for (int i = 0; i < textLen; ++i) {
|
||||
if (input.at(i) == QLatin1Char(' ')) {
|
||||
output += (QLatin1Char(' '));
|
||||
} else if (input.at(i) == QLatin1Char('.') ||
|
||||
input.at(i) == QLatin1Char('#')) {
|
||||
} else if (input.at(i) == QLatin1Char('.') || input.at(i) == QLatin1Char('#')) {
|
||||
if (input.at(i + 1).isSpace() || input.at(i + 1).isNumber()) {
|
||||
output += input.at(i);
|
||||
continue;
|
||||
|
@ -609,8 +593,7 @@ QString CodeToHtmlConverter::cssHighlighter(StringView input,
|
|||
output += setFormat(input.mid(i, bracketOpen - i), Format::Keyword);
|
||||
i = bracketOpen;
|
||||
output += input.at(i);
|
||||
} else if (input.at(i) == QLatin1Char('\'') ||
|
||||
input.at(i) == QLatin1Char('"')) {
|
||||
} else if (input.at(i) == QLatin1Char('\'') || input.at(i) == QLatin1Char('"')) {
|
||||
i = highlightStringLiterals(input, input.at(i), output, i);
|
||||
// escape text at i, otherwise it gets skipped and won't be present
|
||||
// in output
|
||||
|
@ -624,8 +607,7 @@ QString CodeToHtmlConverter::cssHighlighter(StringView input,
|
|||
i = highlightComment(input, output, i, false);
|
||||
else
|
||||
output += escape(input.at(i));
|
||||
} else if (input.at(i) == QLatin1Char('<') ||
|
||||
input.at(i) == QLatin1Char('>') ||
|
||||
} else if (input.at(i) == QLatin1Char('<') || input.at(i) == QLatin1Char('>') ||
|
||||
input.at(i) == QLatin1Char('&')) {
|
||||
output += escape(input.at(i));
|
||||
} else if (input.at(i).isLetter()) {
|
||||
|
@ -674,8 +656,7 @@ QString CodeToHtmlConverter::ymlHighlighter(StringView input) const {
|
|||
|
||||
for (int i = 0; i < textLen; ++i) {
|
||||
// we found a string literal
|
||||
if (input.at(i) == QLatin1Char('"') ||
|
||||
input.at(i) == QLatin1Char('\'')) {
|
||||
if (input.at(i) == QLatin1Char('"') || input.at(i) == QLatin1Char('\'')) {
|
||||
i = highlightStringLiterals(input, input.at(i), output, i);
|
||||
} else if (input.at(i) == QLatin1Char('#')) {
|
||||
i = highlightComment(input, output, i);
|
||||
|
@ -684,8 +665,7 @@ QString CodeToHtmlConverter::ymlHighlighter(StringView input) const {
|
|||
if (colon > 0) {
|
||||
// move i to the beginning of the word
|
||||
int cursor = i;
|
||||
while (cursor < textLen && !input.at(cursor).isLetter())
|
||||
++cursor;
|
||||
while (cursor < textLen && !input.at(cursor).isLetter()) ++cursor;
|
||||
// add this to output
|
||||
output += escapeString(input.mid(i, cursor - i));
|
||||
i = cursor;
|
||||
|
@ -702,13 +682,11 @@ QString CodeToHtmlConverter::ymlHighlighter(StringView input) const {
|
|||
// advance i
|
||||
i = hashPos;
|
||||
// then add the comment
|
||||
output += setFormat(input.mid(i, endLine - i),
|
||||
Format::Comment);
|
||||
output += setFormat(input.mid(i, endLine - i), Format::Comment);
|
||||
i = endLine;
|
||||
}
|
||||
|
||||
if (i != endLine)
|
||||
output += escapeString(input.mid(i, endLine - i));
|
||||
if (i != endLine) output += escapeString(input.mid(i, endLine - i));
|
||||
i = endLine;
|
||||
}
|
||||
}
|
||||
|
@ -749,11 +727,10 @@ QString CodeToHtmlConverter::iniHighlighter(StringView input) const {
|
|||
}
|
||||
|
||||
// key-val
|
||||
else if (i == 0 || (input.at(i) == QLatin1Char('\n') &&
|
||||
i + 1 < textLen && input.at(i + 1).isLetter())) {
|
||||
else if (i == 0 || (input.at(i) == QLatin1Char('\n') && i + 1 < textLen &&
|
||||
input.at(i + 1).isLetter())) {
|
||||
int equalsPos = input.indexOf(QLatin1Char('='), i);
|
||||
if (equalsPos == -1)
|
||||
equalsPos = input.indexOf(QLatin1Char('\n'), i);
|
||||
if (equalsPos == -1) equalsPos = input.indexOf(QLatin1Char('\n'), i);
|
||||
output += setFormat(input.mid(i, equalsPos - i), Format::Keyword);
|
||||
i = equalsPos;
|
||||
output += escape(input.at(i));
|
||||
|
@ -801,37 +778,35 @@ QString CodeToHtmlConverter::escapeString(StringView s) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
QString CodeToHtmlConverter::setFormat(StringView str,
|
||||
CodeToHtmlConverter::Format format) {
|
||||
QString CodeToHtmlConverter::setFormat(StringView str, CodeToHtmlConverter::Format format) {
|
||||
switch (format) {
|
||||
case Type:
|
||||
return QStringLiteral("<span class=\"code-type\">") %
|
||||
escapeString(str) % QStringLiteral("</span>");
|
||||
return QStringLiteral("<span class=\"code-type\">") % escapeString(str) %
|
||||
QStringLiteral("</span>");
|
||||
case Keyword:
|
||||
return QStringLiteral("<span class=\"code-keyword\">") %
|
||||
escapeString(str) % QStringLiteral("</span>");
|
||||
return QStringLiteral("<span class=\"code-keyword\">") % escapeString(str) %
|
||||
QStringLiteral("</span>");
|
||||
case Literal:
|
||||
return QStringLiteral("<span class=\"code-literal\">") %
|
||||
escapeString(str) % QStringLiteral("</span>");
|
||||
return QStringLiteral("<span class=\"code-literal\">") % escapeString(str) %
|
||||
QStringLiteral("</span>");
|
||||
case String:
|
||||
return QStringLiteral("<span class=\"code-string\">") %
|
||||
escapeString(str) % QStringLiteral("</span>");
|
||||
return QStringLiteral("<span class=\"code-string\">") % escapeString(str) %
|
||||
QStringLiteral("</span>");
|
||||
case Builtin:
|
||||
return QStringLiteral("<span class=\"code-builtin\">") %
|
||||
escapeString(str) % QStringLiteral("</span>");
|
||||
return QStringLiteral("<span class=\"code-builtin\">") % escapeString(str) %
|
||||
QStringLiteral("</span>");
|
||||
case Other:
|
||||
return QStringLiteral("<span class=\"code-other\">") %
|
||||
escapeString(str) % QStringLiteral("</span>");
|
||||
return QStringLiteral("<span class=\"code-other\">") % escapeString(str) %
|
||||
QStringLiteral("</span>");
|
||||
case Comment:
|
||||
return QStringLiteral("<span class=\"code-comment\">") %
|
||||
escapeString(str) % QStringLiteral("</span>");
|
||||
return QStringLiteral("<span class=\"code-comment\">") % escapeString(str) %
|
||||
QStringLiteral("</span>");
|
||||
}
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
QString CodeToHtmlConverter::setFormat(const QString &str, CodeToHtmlConverter::Format format)
|
||||
{
|
||||
QString CodeToHtmlConverter::setFormat(const QString &str, CodeToHtmlConverter::Format format) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
return setFormat(StringView(str), format);
|
||||
#else
|
||||
|
|
|
@ -13,7 +13,7 @@ using LangData = QMultiHash<char, QLatin1String>;
|
|||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
|
||||
using StringView = QStringView;
|
||||
#else
|
||||
using StringView = const QStringRef&;
|
||||
using StringView = const QStringRef &;
|
||||
#endif
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
|
||||
|
@ -64,19 +64,15 @@ class CodeToHtmlConverter {
|
|||
Q_REQUIRED_RESULT static QString setFormat(const QString &str, Format format);
|
||||
static void initCodeLangs() Q_DECL_NOTHROW;
|
||||
|
||||
Q_REQUIRED_RESULT int highlightNumericLit(StringView input,
|
||||
QString &output, int i) const;
|
||||
Q_REQUIRED_RESULT static int highlightStringLiterals(
|
||||
StringView input, QChar strType, QString &output, int i);
|
||||
Q_REQUIRED_RESULT static int highlightComment(StringView input,
|
||||
QString &output, int i,
|
||||
Q_REQUIRED_RESULT int highlightNumericLit(StringView input, QString &output, int i) const;
|
||||
Q_REQUIRED_RESULT static int highlightStringLiterals(StringView input, QChar strType,
|
||||
QString &output, int i);
|
||||
Q_REQUIRED_RESULT static int highlightComment(StringView input, QString &output, int i,
|
||||
bool isSingleLine = true);
|
||||
Q_REQUIRED_RESULT static int highlightWord(int i, const LangData &data,
|
||||
StringView input,
|
||||
Q_REQUIRED_RESULT static int highlightWord(int i, const LangData &data, StringView input,
|
||||
QString &output, Format f);
|
||||
Q_REQUIRED_RESULT QString xmlHighlighter(StringView input) const;
|
||||
Q_REQUIRED_RESULT QString cssHighlighter(StringView input,
|
||||
const LangData &types,
|
||||
Q_REQUIRED_RESULT QString cssHighlighter(StringView input, const LangData &types,
|
||||
const LangData &keywords) const;
|
||||
Q_REQUIRED_RESULT QString ymlHighlighter(StringView input) const;
|
||||
Q_REQUIRED_RESULT QString iniHighlighter(StringView input) const;
|
||||
|
@ -84,22 +80,19 @@ class CodeToHtmlConverter {
|
|||
/**
|
||||
* @brief returns true if c is octal
|
||||
*/
|
||||
Q_REQUIRED_RESULT static inline bool isOctal(const char c) {
|
||||
return (c >= '0' && c <= '7');
|
||||
}
|
||||
Q_REQUIRED_RESULT static inline bool isOctal(const char c) { return (c >= '0' && c <= '7'); }
|
||||
|
||||
/**
|
||||
* @brief returns true if c is hex
|
||||
*/
|
||||
Q_REQUIRED_RESULT static inline bool isHex(const char c) {
|
||||
return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
|
||||
(c >= 'A' && c <= 'F'));
|
||||
return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
|
||||
}
|
||||
|
||||
static QHash<QString, Lang> _langStringToEnum;
|
||||
|
||||
/** For Test Cases Only **/
|
||||
Q_REQUIRED_RESULT QString process(const QString& input) const;
|
||||
Q_REQUIRED_RESULT QString process(const QString &input) const;
|
||||
|
||||
friend class TestNotes;
|
||||
};
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
#include <libraries/fakevim/fakevim/fakevimhandler.h>
|
||||
#include <mainwindow.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QRegularExpression>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QtCore/QTemporaryFile>
|
||||
#include <QtCore/QTextStream>
|
||||
#include <QtGui/QTextBlock>
|
||||
|
@ -11,18 +15,11 @@
|
|||
#include <QtWidgets/QMessageBox>
|
||||
#include <QtWidgets/QPlainTextEdit>
|
||||
#include <QtWidgets/QStatusBar>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QDir>
|
||||
|
||||
#include<QRegularExpression>
|
||||
|
||||
FakeVimProxy::FakeVimProxy(QWidget *widget, QObject *parent)
|
||||
: QObject(parent), m_widget(widget)
|
||||
{
|
||||
FakeVimProxy::FakeVimProxy(QWidget *widget, QObject *parent) : QObject(parent), m_widget(widget) {
|
||||
using namespace FakeVim::Internal;
|
||||
|
||||
auto *handler = static_cast<FakeVim::Internal::FakeVimHandler*>(parent);
|
||||
auto *handler = static_cast<FakeVim::Internal::FakeVimHandler *>(parent);
|
||||
|
||||
handler->installEventFilter();
|
||||
handler->setupWidget();
|
||||
|
@ -46,7 +43,6 @@ FakeVimProxy::FakeVimProxy(QWidget *widget, QObject *parent)
|
|||
fakeVimSettings()->item("ts")->setValue(Utils::Misc::indentSize());
|
||||
fakeVimSettings()->item("sw")->setValue(Utils::Misc::indentSize());
|
||||
|
||||
|
||||
{
|
||||
auto h = [this](const QString &contents, int cursorPos, int anchorPos, int msgLvl) {
|
||||
changeStatusMessage(contents, cursorPos, anchorPos, msgLvl);
|
||||
|
@ -85,7 +81,6 @@ FakeVimProxy::FakeVimProxy(QWidget *widget, QObject *parent)
|
|||
}
|
||||
|
||||
{
|
||||
|
||||
auto h = [this](bool *on) { requestHasBlockSelection(on); };
|
||||
handler->requestHasBlockSelection.connect(h);
|
||||
}
|
||||
|
@ -98,14 +93,13 @@ FakeVimProxy::FakeVimProxy(QWidget *widget, QObject *parent)
|
|||
}
|
||||
|
||||
{
|
||||
auto h = [this](bool *result, QChar c) {
|
||||
checkForElectricCharacter(result, c);
|
||||
};
|
||||
auto h = [this](bool *result, QChar c) { checkForElectricCharacter(result, c); };
|
||||
handler->checkForElectricCharacter.connect(h);
|
||||
}
|
||||
|
||||
// regular signal
|
||||
connect(this, &FakeVimProxy::handleInput, handler, [handler](const QString &text) { handler->handleInput(text); });
|
||||
connect(this, &FakeVimProxy::handleInput, handler,
|
||||
[handler](const QString &text) { handler->handleInput(text); });
|
||||
}
|
||||
|
||||
void FakeVimProxy::changeStatusData(const QString &info) {
|
||||
|
@ -156,23 +150,21 @@ void FakeVimProxy::highlightMatches(const QString &pattern) {
|
|||
updateExtraSelections();
|
||||
}
|
||||
|
||||
void FakeVimProxy::changeStatusMessage(const QString &contents, int cursorPos, int /*anchorPos*/, int /*messageLevel*/) {
|
||||
m_statusMessage =
|
||||
cursorPos == -1
|
||||
? contents
|
||||
: contents.left(cursorPos) + QChar(10073) + contents.mid(cursorPos);
|
||||
void FakeVimProxy::changeStatusMessage(const QString &contents, int cursorPos, int /*anchorPos*/,
|
||||
int /*messageLevel*/) {
|
||||
m_statusMessage = cursorPos == -1
|
||||
? contents
|
||||
: contents.left(cursorPos) + QChar(10073) + contents.mid(cursorPos);
|
||||
updateStatusBar();
|
||||
}
|
||||
|
||||
void FakeVimProxy::updateStatusBar() {
|
||||
int slack = 80 - m_statusMessage.size() - m_statusData.size();
|
||||
QString msg =
|
||||
m_statusMessage + QString(slack, QLatin1Char(' ')) + m_statusData;
|
||||
QString msg = m_statusMessage + QString(slack, QLatin1Char(' ')) + m_statusData;
|
||||
MainWindow::instance()->statusBar()->showMessage(msg);
|
||||
}
|
||||
|
||||
void FakeVimProxy::handleExCommand(bool *handled,
|
||||
const FakeVim::Internal::ExCommand &cmd) {
|
||||
void FakeVimProxy::handleExCommand(bool *handled, const FakeVim::Internal::ExCommand &cmd) {
|
||||
if (wantSaveAndQuit(cmd)) {
|
||||
// :wq
|
||||
if (save()) cancel();
|
||||
|
@ -195,8 +187,8 @@ void FakeVimProxy::requestSetBlockSelection(const QTextCursor &tc) {
|
|||
auto *ed = qobject_cast<QPlainTextEdit *>(m_widget);
|
||||
if (!ed) return;
|
||||
|
||||
QPalette pal = ed->parentWidget() != nullptr ? ed->parentWidget()->palette()
|
||||
: QApplication::palette();
|
||||
QPalette pal =
|
||||
ed->parentWidget() != nullptr ? ed->parentWidget()->palette() : QApplication::palette();
|
||||
|
||||
m_blockSelection.clear();
|
||||
m_clearSelection.clear();
|
||||
|
@ -219,17 +211,14 @@ void FakeVimProxy::requestSetBlockSelection(const QTextCursor &tc) {
|
|||
for (QTextBlock block = cur.document()->findBlock(min);
|
||||
block.isValid() && block.position() < max; block = block.next()) {
|
||||
cur.setPosition(block.position() + qMin<int>(from, block.length()));
|
||||
cur.setPosition(block.position() + qMin<int>(to, block.length()),
|
||||
QTextCursor::KeepAnchor);
|
||||
cur.setPosition(block.position() + qMin<int>(to, block.length()), QTextCursor::KeepAnchor);
|
||||
selection.cursor = cur;
|
||||
m_blockSelection.append(selection);
|
||||
}
|
||||
|
||||
disconnect(ed, &QPlainTextEdit::selectionChanged, this,
|
||||
&FakeVimProxy::updateBlockSelection);
|
||||
disconnect(ed, &QPlainTextEdit::selectionChanged, this, &FakeVimProxy::updateBlockSelection);
|
||||
ed->setTextCursor(tc);
|
||||
connect(ed, &QPlainTextEdit::selectionChanged, this,
|
||||
&FakeVimProxy::updateBlockSelection);
|
||||
connect(ed, &QPlainTextEdit::selectionChanged, this, &FakeVimProxy::updateBlockSelection);
|
||||
|
||||
QPalette pal2 = ed->palette();
|
||||
pal2.setColor(QPalette::Highlight, Qt::transparent);
|
||||
|
@ -243,16 +232,15 @@ void FakeVimProxy::requestDisableBlockSelection() {
|
|||
auto *ed = qobject_cast<QPlainTextEdit *>(m_widget);
|
||||
if (!ed) return;
|
||||
|
||||
QPalette pal = ed->parentWidget() != nullptr ? ed->parentWidget()->palette()
|
||||
: QApplication::palette();
|
||||
QPalette pal =
|
||||
ed->parentWidget() != nullptr ? ed->parentWidget()->palette() : QApplication::palette();
|
||||
|
||||
m_blockSelection.clear();
|
||||
m_clearSelection.clear();
|
||||
|
||||
ed->setPalette(pal);
|
||||
|
||||
disconnect(ed, &QPlainTextEdit::selectionChanged, this,
|
||||
&FakeVimProxy::updateBlockSelection);
|
||||
disconnect(ed, &QPlainTextEdit::selectionChanged, this, &FakeVimProxy::updateBlockSelection);
|
||||
|
||||
updateExtraSelections();
|
||||
}
|
||||
|
@ -264,9 +252,7 @@ void FakeVimProxy::updateBlockSelection() {
|
|||
requestSetBlockSelection(ed->textCursor());
|
||||
}
|
||||
|
||||
void FakeVimProxy::requestHasBlockSelection(bool *on) {
|
||||
*on = !m_blockSelection.isEmpty();
|
||||
}
|
||||
void FakeVimProxy::requestHasBlockSelection(bool *on) { *on = !m_blockSelection.isEmpty(); }
|
||||
|
||||
void FakeVimProxy::indentRegion(int beginBlock, int endBlock, QChar typedChar) {
|
||||
auto *ed = qobject_cast<QPlainTextEdit *>(m_widget);
|
||||
|
@ -290,8 +276,7 @@ void FakeVimProxy::indentRegion(int beginBlock, int endBlock, QChar typedChar) {
|
|||
while (!cursor.atBlockEnd()) cursor.deleteChar();
|
||||
} else {
|
||||
const auto previousBlock = block.previous();
|
||||
const auto previousLine =
|
||||
previousBlock.isValid() ? previousBlock.text() : QString();
|
||||
const auto previousLine = previousBlock.isValid() ? previousBlock.text() : QString();
|
||||
|
||||
qint64 indent = firstNonSpace(previousLine);
|
||||
if (typedChar == '}')
|
||||
|
@ -303,8 +288,8 @@ void FakeVimProxy::indentRegion(int beginBlock, int endBlock, QChar typedChar) {
|
|||
QTextCursor cursor(block);
|
||||
cursor.beginEditBlock();
|
||||
cursor.movePosition(QTextCursor::StartOfBlock);
|
||||
cursor.movePosition(QTextCursor::NextCharacter,
|
||||
QTextCursor::KeepAnchor, firstNonSpace(line));
|
||||
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,
|
||||
firstNonSpace(line));
|
||||
cursor.removeSelectedText();
|
||||
cursor.insertText(indentString);
|
||||
cursor.endEditBlock();
|
||||
|
@ -325,9 +310,7 @@ int FakeVimProxy::firstNonSpace(const QString &text) {
|
|||
|
||||
void FakeVimProxy::updateExtraSelections() {
|
||||
auto *ed = qobject_cast<QPlainTextEdit *>(m_widget);
|
||||
if (ed)
|
||||
ed->setExtraSelections(m_clearSelection + m_searchSelection +
|
||||
m_blockSelection);
|
||||
if (ed) ed->setExtraSelections(m_clearSelection + m_searchSelection + m_blockSelection);
|
||||
}
|
||||
|
||||
bool FakeVimProxy::wantSaveAndQuit(const FakeVim::Internal::ExCommand &cmd) {
|
||||
|
|
|
@ -26,14 +26,14 @@ class FakeVimProxy : public QObject {
|
|||
|
||||
void highlightMatches(const QString &pattern);
|
||||
|
||||
void changeStatusMessage(const QString &contents, int cursorPos, int anchorPos, int messageLevel);
|
||||
void changeStatusMessage(const QString &contents, int cursorPos, int anchorPos,
|
||||
int messageLevel);
|
||||
|
||||
void changeExtraInformation(const QString &info);
|
||||
|
||||
void updateStatusBar();
|
||||
|
||||
void handleExCommand(bool *handled,
|
||||
const FakeVim::Internal::ExCommand &cmd);
|
||||
void handleExCommand(bool *handled, const FakeVim::Internal::ExCommand &cmd);
|
||||
|
||||
void requestSetBlockSelection(const QTextCursor &tc);
|
||||
|
||||
|
|
|
@ -48,42 +48,34 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "flowlayout.h"
|
||||
|
||||
#include <QtWidgets>
|
||||
//! [1]
|
||||
FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)
|
||||
: QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
|
||||
{
|
||||
: QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing) {
|
||||
setContentsMargins(margin, margin, margin, margin);
|
||||
}
|
||||
|
||||
FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing)
|
||||
: m_hSpace(hSpacing), m_vSpace(vSpacing)
|
||||
{
|
||||
: m_hSpace(hSpacing), m_vSpace(vSpacing) {
|
||||
setContentsMargins(margin, margin, margin, margin);
|
||||
}
|
||||
//! [1]
|
||||
|
||||
//! [2]
|
||||
FlowLayout::~FlowLayout()
|
||||
{
|
||||
FlowLayout::~FlowLayout() {
|
||||
QLayoutItem *item;
|
||||
while ((item = takeAt(0)))
|
||||
delete item;
|
||||
while ((item = takeAt(0))) delete item;
|
||||
}
|
||||
//! [2]
|
||||
|
||||
//! [3]
|
||||
void FlowLayout::addItem(QLayoutItem *item)
|
||||
{
|
||||
itemList.append(item);
|
||||
}
|
||||
void FlowLayout::addItem(QLayoutItem *item) { itemList.append(item); }
|
||||
//! [3]
|
||||
|
||||
//! [4]
|
||||
int FlowLayout::horizontalSpacing() const
|
||||
{
|
||||
int FlowLayout::horizontalSpacing() const {
|
||||
if (m_hSpace >= 0) {
|
||||
return m_hSpace;
|
||||
} else {
|
||||
|
@ -91,8 +83,7 @@ int FlowLayout::horizontalSpacing() const
|
|||
}
|
||||
}
|
||||
|
||||
int FlowLayout::verticalSpacing() const
|
||||
{
|
||||
int FlowLayout::verticalSpacing() const {
|
||||
if (m_vSpace >= 0) {
|
||||
return m_vSpace;
|
||||
} else {
|
||||
|
@ -102,58 +93,38 @@ int FlowLayout::verticalSpacing() const
|
|||
//! [4]
|
||||
|
||||
//! [5]
|
||||
int FlowLayout::count() const
|
||||
{
|
||||
return itemList.size();
|
||||
}
|
||||
int FlowLayout::count() const { return itemList.size(); }
|
||||
|
||||
QLayoutItem *FlowLayout::itemAt(int index) const
|
||||
{
|
||||
return itemList.value(index);
|
||||
}
|
||||
QLayoutItem *FlowLayout::itemAt(int index) const { return itemList.value(index); }
|
||||
|
||||
QLayoutItem *FlowLayout::takeAt(int index)
|
||||
{
|
||||
if (index >= 0 && index < itemList.size())
|
||||
return itemList.takeAt(index);
|
||||
QLayoutItem *FlowLayout::takeAt(int index) {
|
||||
if (index >= 0 && index < itemList.size()) return itemList.takeAt(index);
|
||||
return nullptr;
|
||||
}
|
||||
//! [5]
|
||||
|
||||
//! [6]
|
||||
Qt::Orientations FlowLayout::expandingDirections() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
Qt::Orientations FlowLayout::expandingDirections() const { return {}; }
|
||||
//! [6]
|
||||
|
||||
//! [7]
|
||||
bool FlowLayout::hasHeightForWidth() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool FlowLayout::hasHeightForWidth() const { return true; }
|
||||
|
||||
int FlowLayout::heightForWidth(int width) const
|
||||
{
|
||||
int FlowLayout::heightForWidth(int width) const {
|
||||
int height = doLayout(QRect(0, 0, width, 0), true);
|
||||
return height;
|
||||
}
|
||||
//! [7]
|
||||
|
||||
//! [8]
|
||||
void FlowLayout::setGeometry(const QRect &rect)
|
||||
{
|
||||
void FlowLayout::setGeometry(const QRect &rect) {
|
||||
QLayout::setGeometry(rect);
|
||||
doLayout(rect, false);
|
||||
}
|
||||
|
||||
QSize FlowLayout::sizeHint() const
|
||||
{
|
||||
return minimumSize();
|
||||
}
|
||||
QSize FlowLayout::sizeHint() const { return minimumSize(); }
|
||||
|
||||
QSize FlowLayout::minimumSize() const
|
||||
{
|
||||
QSize FlowLayout::minimumSize() const {
|
||||
QSize size;
|
||||
#if QT_VERSION >= 0x050700
|
||||
for (const QLayoutItem *item : qAsConst(itemList))
|
||||
|
@ -169,8 +140,7 @@ QSize FlowLayout::minimumSize() const
|
|||
//! [8]
|
||||
|
||||
//! [9]
|
||||
int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
|
||||
{
|
||||
int FlowLayout::doLayout(const QRect &rect, bool testOnly) const {
|
||||
int left, top, right, bottom;
|
||||
getContentsMargins(&left, &top, &right, &bottom);
|
||||
QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
|
||||
|
@ -188,14 +158,14 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
|
|||
const QWidget *wid = item->widget();
|
||||
int spaceX = horizontalSpacing();
|
||||
if (spaceX == -1)
|
||||
spaceX = wid->style()->layoutSpacing(
|
||||
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
|
||||
spaceX = wid->style()->layoutSpacing(QSizePolicy::PushButton, QSizePolicy::PushButton,
|
||||
Qt::Horizontal);
|
||||
int spaceY = verticalSpacing();
|
||||
if (spaceY == -1)
|
||||
spaceY = wid->style()->layoutSpacing(
|
||||
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
|
||||
//! [10]
|
||||
//! [11]
|
||||
spaceY = wid->style()->layoutSpacing(QSizePolicy::PushButton, QSizePolicy::PushButton,
|
||||
Qt::Vertical);
|
||||
//! [10]
|
||||
//! [11]
|
||||
int nextX = x + item->sizeHint().width() + spaceX;
|
||||
if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
|
||||
x = effectiveRect.x();
|
||||
|
@ -204,8 +174,7 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
|
|||
lineHeight = 0;
|
||||
}
|
||||
|
||||
if (!testOnly)
|
||||
item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
|
||||
if (!testOnly) item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
|
||||
|
||||
x = nextX;
|
||||
lineHeight = qMax<int>(lineHeight, item->sizeHint().height());
|
||||
|
@ -214,8 +183,7 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
|
|||
}
|
||||
//! [11]
|
||||
//! [12]
|
||||
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
|
||||
{
|
||||
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const {
|
||||
QObject *parent = this->parent();
|
||||
if (!parent) {
|
||||
return -1;
|
||||
|
|
|
@ -55,9 +55,8 @@
|
|||
#include <QRect>
|
||||
#include <QStyle>
|
||||
//! [0]
|
||||
class FlowLayout : public QLayout
|
||||
{
|
||||
public:
|
||||
class FlowLayout : public QLayout {
|
||||
public:
|
||||
explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
|
||||
explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
|
||||
~FlowLayout();
|
||||
|
@ -75,7 +74,7 @@ public:
|
|||
QSize sizeHint() const override;
|
||||
QLayoutItem *takeAt(int index) override;
|
||||
|
||||
private:
|
||||
private:
|
||||
int doLayout(const QRect &rect, bool testOnly) const;
|
||||
int smartSpacing(QStyle::PixelMetric pm) const;
|
||||
|
||||
|
@ -85,4 +84,4 @@ private:
|
|||
};
|
||||
//! [0]
|
||||
|
||||
#endif // FLOWLAYOUT_H
|
||||
#endif // FLOWLAYOUT_H
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "qownnotesmarkdownhighlighter.h"
|
||||
#include "mainwindow.h"
|
||||
#include "qownspellchecker.h"
|
||||
|
||||
#include <entities/note.h>
|
||||
#include <services/scriptingservice.h>
|
||||
|
||||
|
@ -25,13 +24,14 @@
|
|||
#include <QRegularExpression>
|
||||
#include <QRegularExpressionMatch>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "qownspellchecker.h"
|
||||
|
||||
QOwnNotesMarkdownHighlighter::QOwnNotesMarkdownHighlighter(
|
||||
QTextDocument *parent, HighlightingOptions highlightingOptions)
|
||||
: MarkdownHighlighter(parent, highlightingOptions)
|
||||
{
|
||||
QOwnNotesMarkdownHighlighter::QOwnNotesMarkdownHighlighter(QTextDocument *parent,
|
||||
HighlightingOptions highlightingOptions)
|
||||
: MarkdownHighlighter(parent, highlightingOptions) {
|
||||
_defaultNoteFileExt = Note::defaultNoteFileExtension();
|
||||
connect(MainWindow::instance(), &MainWindow::settingsChanged, this, [this](){
|
||||
connect(MainWindow::instance(), &MainWindow::settingsChanged, this, [this]() {
|
||||
_defaultNoteFileExt = Note::defaultNoteFileExtension();
|
||||
updateCachedRegexes(_defaultNoteFileExt);
|
||||
});
|
||||
|
@ -60,7 +60,8 @@ void QOwnNotesMarkdownHighlighter::highlightBlock(const QString &text) {
|
|||
// do the markdown highlighting before the spellcheck highlighting
|
||||
// if we do it afterwards, it overwrites the spellcheck highlighting
|
||||
MarkdownHighlighter::highlightMarkdown(text);
|
||||
if (text.contains(QLatin1String("note://")) || text.contains(QChar('.') + _defaultNoteFileExt)) {
|
||||
if (text.contains(QLatin1String("note://")) ||
|
||||
text.contains(QChar('.') + _defaultNoteFileExt)) {
|
||||
highlightBrokenNotesLink(text);
|
||||
}
|
||||
|
||||
|
@ -104,26 +105,23 @@ void QOwnNotesMarkdownHighlighter::highlightScriptingRules(
|
|||
QTextCharFormat currentMaskedFormat = maskedFormat;
|
||||
// set the font size from the current rule's font format
|
||||
if (format.fontPointSize() > 0) {
|
||||
currentMaskedFormat.setFontPointSize(
|
||||
format.fontPointSize());
|
||||
currentMaskedFormat.setFontPointSize(format.fontPointSize());
|
||||
}
|
||||
|
||||
setFormat(match.capturedStart(maskedGroup),
|
||||
match.capturedLength(maskedGroup),
|
||||
setFormat(match.capturedStart(maskedGroup), match.capturedLength(maskedGroup),
|
||||
currentMaskedFormat);
|
||||
}
|
||||
|
||||
setFormat(match.capturedStart(capturingGroup),
|
||||
match.capturedLength(capturingGroup), format);
|
||||
setFormat(match.capturedStart(capturingGroup), match.capturedLength(capturingGroup),
|
||||
format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QOwnNotesMarkdownHighlighter::updateCachedRegexes(const QString& newExt)
|
||||
{
|
||||
void QOwnNotesMarkdownHighlighter::updateCachedRegexes(const QString &newExt) {
|
||||
_regexTagStyleLink = QRegularExpression(R"(<([^\s`][^`]*?\.)" + newExt + R"()>)");
|
||||
_regexBracketLink = QRegularExpression(R"(\[[^\[\]]+\]\((\S+\.)" + newExt + R"(|.+?\.)" + newExt + R"()(#[^\)]+)?\)\B)");
|
||||
_regexBracketLink = QRegularExpression(R"(\[[^\[\]]+\]\((\S+\.)" + newExt + R"(|.+?\.)" +
|
||||
newExt + R"()(#[^\)]+)?\)\B)");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,8 +129,7 @@ void QOwnNotesMarkdownHighlighter::updateCachedRegexes(const QString& newExt)
|
|||
*
|
||||
* @param text
|
||||
*/
|
||||
void QOwnNotesMarkdownHighlighter::highlightBrokenNotesLink(
|
||||
const QString &text) {
|
||||
void QOwnNotesMarkdownHighlighter::highlightBrokenNotesLink(const QString &text) {
|
||||
static const QRegularExpression regex(QStringLiteral(R"(note:\/\/[^\s\)>]+)"));
|
||||
QRegularExpressionMatch match = regex.match(text);
|
||||
|
||||
|
@ -164,8 +161,7 @@ void QOwnNotesMarkdownHighlighter::highlightBrokenNotesLink(
|
|||
return;
|
||||
}
|
||||
|
||||
const Note note =
|
||||
_currentNote->fetchByRelativeFileName(fileName);
|
||||
const Note note = _currentNote->fetchByRelativeFileName(fileName);
|
||||
|
||||
// if the note exists we don't need to do anything
|
||||
if (note.isFetched()) {
|
||||
|
@ -176,16 +172,14 @@ void QOwnNotesMarkdownHighlighter::highlightBrokenNotesLink(
|
|||
match = _regexBracketLink.match(text);
|
||||
|
||||
if (match.hasMatch()) {
|
||||
const QString fileName =
|
||||
Note::urlDecodeNoteUrl(match.captured(1));
|
||||
const QString fileName = Note::urlDecodeNoteUrl(match.captured(1));
|
||||
|
||||
// skip urls
|
||||
if (fileName.contains(QStringLiteral("://"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Note note =
|
||||
_currentNote->fetchByRelativeFileName(fileName);
|
||||
const Note note = _currentNote->fetchByRelativeFileName(fileName);
|
||||
|
||||
// if the note exists we don't need to do anything
|
||||
if (note.isFetched()) {
|
||||
|
@ -201,10 +195,8 @@ void QOwnNotesMarkdownHighlighter::highlightBrokenNotesLink(
|
|||
setFormat(match.capturedStart(0), match.capturedLength(0), _formats[state]);
|
||||
}
|
||||
|
||||
void QOwnNotesMarkdownHighlighter::setMisspelled(const int start,
|
||||
const int count) {
|
||||
if (MarkdownHighlighter::isPosInACodeSpan(currentBlock().blockNumber(), start))
|
||||
return;
|
||||
void QOwnNotesMarkdownHighlighter::setMisspelled(const int start, const int count) {
|
||||
if (MarkdownHighlighter::isPosInACodeSpan(currentBlock().blockNumber(), start)) return;
|
||||
|
||||
// append to the already existing text format.
|
||||
// creating a new format will destroy pre-existing format
|
||||
|
@ -230,14 +222,12 @@ void QOwnNotesMarkdownHighlighter::highlightSpellChecking(const QString &text) {
|
|||
return;
|
||||
}
|
||||
int state = currentBlockState();
|
||||
if (state == HighlighterState::HeadlineEnd ||
|
||||
state == HighlighterState::CodeBlock ||
|
||||
if (state == HighlighterState::HeadlineEnd || state == HighlighterState::CodeBlock ||
|
||||
state >= HighlighterState::CodeCpp)
|
||||
return;
|
||||
|
||||
// use our own settings, as KDE users might face issues with Autodetection
|
||||
const bool autodetectLanguage =
|
||||
QOwnSpellChecker::instance()->isAutoDetectOn();
|
||||
const bool autodetectLanguage = QOwnSpellChecker::instance()->isAutoDetectOn();
|
||||
LanguageCache *languageCache = nullptr;
|
||||
if (autodetectLanguage) {
|
||||
languageCache = dynamic_cast<LanguageCache *>(currentBlockUserData());
|
||||
|
@ -252,8 +242,7 @@ void QOwnNotesMarkdownHighlighter::highlightSpellChecking(const QString &text) {
|
|||
const Sonnet::Token sentence = languageFilter->next();
|
||||
if (autodetectLanguage) {
|
||||
QString lang;
|
||||
const QPair<int, int> spos =
|
||||
QPair<int, int>(sentence.position(), sentence.length());
|
||||
const QPair<int, int> spos = QPair<int, int>(sentence.position(), sentence.length());
|
||||
// try cache first
|
||||
if (languageCache->languages.contains(spos)) {
|
||||
lang = languageCache->languages.value(spos);
|
||||
|
@ -270,8 +259,7 @@ void QOwnNotesMarkdownHighlighter::highlightSpellChecking(const QString &text) {
|
|||
QOwnSpellChecker::instance()->setCurrentLanguage(lang);
|
||||
}
|
||||
|
||||
const auto wordTokenizer =
|
||||
QOwnSpellChecker::instance()->wordTokenizer();
|
||||
const auto wordTokenizer = QOwnSpellChecker::instance()->wordTokenizer();
|
||||
wordTokenizer->setBuffer(sentence.toString());
|
||||
const int offset = sentence.position();
|
||||
while (wordTokenizer->hasNext()) {
|
||||
|
|
|
@ -40,8 +40,7 @@ class QOwnNotesMarkdownHighlighter : public MarkdownHighlighter {
|
|||
void updateCurrentNote(Note *note);
|
||||
|
||||
struct ScriptingHighlightingRule {
|
||||
explicit ScriptingHighlightingRule(const HighlighterState state_)
|
||||
: state(state_) {}
|
||||
explicit ScriptingHighlightingRule(const HighlighterState state_) : state(state_) {}
|
||||
ScriptingHighlightingRule() = default;
|
||||
|
||||
QRegularExpression pattern;
|
||||
|
@ -61,7 +60,7 @@ class QOwnNotesMarkdownHighlighter : public MarkdownHighlighter {
|
|||
void setMisspelled(const int start, const int count);
|
||||
void highlightSpellChecking(const QString &text);
|
||||
|
||||
void updateCachedRegexes(const QString& newExt);
|
||||
void updateCachedRegexes(const QString &newExt);
|
||||
|
||||
private:
|
||||
Note *_currentNote = nullptr;
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
#include <QSettings>
|
||||
|
||||
QOwnSpellChecker::QOwnSpellChecker() : _spellchecker{new Sonnet::Speller()} {
|
||||
_languageFilter =
|
||||
new Sonnet::LanguageFilter(new Sonnet::SentenceTokenizer());
|
||||
_languageFilter = new Sonnet::LanguageFilter(new Sonnet::SentenceTokenizer());
|
||||
_wordTokenizer = new Sonnet::WordTokenizer();
|
||||
#ifdef Q_OS_MACOS
|
||||
QStringList s = _spellchecker->availableLanguages();
|
||||
|
@ -30,13 +29,9 @@ QOwnSpellChecker::QOwnSpellChecker() : _spellchecker{new Sonnet::Speller()} {
|
|||
#endif
|
||||
}
|
||||
|
||||
Sonnet::WordTokenizer *QOwnSpellChecker::wordTokenizer() const {
|
||||
return _wordTokenizer;
|
||||
}
|
||||
Sonnet::WordTokenizer *QOwnSpellChecker::wordTokenizer() const { return _wordTokenizer; }
|
||||
|
||||
Sonnet::LanguageFilter *QOwnSpellChecker::languageFilter() const {
|
||||
return _languageFilter;
|
||||
}
|
||||
Sonnet::LanguageFilter *QOwnSpellChecker::languageFilter() const { return _languageFilter; }
|
||||
|
||||
QOwnSpellChecker::~QOwnSpellChecker() {
|
||||
delete _languageFilter;
|
||||
|
@ -49,13 +44,9 @@ QOwnSpellChecker *QOwnSpellChecker::instance() {
|
|||
return &qonSpellchecker;
|
||||
}
|
||||
|
||||
QString QOwnSpellChecker::currentLanguage() const {
|
||||
return _spellchecker->language();
|
||||
}
|
||||
QString QOwnSpellChecker::currentLanguage() const { return _spellchecker->language(); }
|
||||
|
||||
void QOwnSpellChecker::setCurrentLanguage(const QString &lang) {
|
||||
_spellchecker->setLanguage(lang);
|
||||
}
|
||||
void QOwnSpellChecker::setCurrentLanguage(const QString &lang) { _spellchecker->setLanguage(lang); }
|
||||
|
||||
void QOwnSpellChecker::setActive(bool active) { _active = active; }
|
||||
|
||||
|
@ -65,9 +56,7 @@ void QOwnSpellChecker::addWordToDictionary(const QString &word) {
|
|||
_spellchecker->addToPersonal(word);
|
||||
}
|
||||
|
||||
void QOwnSpellChecker::ignoreWord(const QString &word) {
|
||||
_spellchecker->addToSession(word);
|
||||
}
|
||||
void QOwnSpellChecker::ignoreWord(const QString &word) { _spellchecker->addToSession(word); }
|
||||
|
||||
bool QOwnSpellChecker::isValid() { return _spellchecker->isValid(); }
|
||||
|
||||
|
@ -75,9 +64,7 @@ bool QOwnSpellChecker::testAttribute(Sonnet::Speller::Attribute attr) const {
|
|||
return _spellchecker->testAttribute(attr);
|
||||
}
|
||||
|
||||
void QOwnSpellChecker::setAutoDetect(bool autoDetect) {
|
||||
_autoDetect = autoDetect;
|
||||
}
|
||||
void QOwnSpellChecker::setAutoDetect(bool autoDetect) { _autoDetect = autoDetect; }
|
||||
|
||||
bool QOwnSpellChecker::isAutoDetectOn() const { return _autoDetect; }
|
||||
|
||||
|
@ -89,16 +76,13 @@ QStringList QOwnSpellChecker::suggestionsForWord(const QString &word, int max) {
|
|||
return suggestions;
|
||||
}
|
||||
|
||||
QStringList QOwnSpellChecker::suggestionsForWord(const QString &word,
|
||||
const QTextCursor &cursor,
|
||||
QStringList QOwnSpellChecker::suggestionsForWord(const QString &word, const QTextCursor &cursor,
|
||||
int max) {
|
||||
// detect the lang
|
||||
if (_autoDetect) {
|
||||
LanguageCache *cache =
|
||||
dynamic_cast<LanguageCache *>(cursor.block().userData());
|
||||
LanguageCache *cache = dynamic_cast<LanguageCache *>(cursor.block().userData());
|
||||
if (cache) {
|
||||
const QString cachedLanguage =
|
||||
cache->languageAtPos(cursor.positionInBlock());
|
||||
const QString cachedLanguage = cache->languageAtPos(cursor.positionInBlock());
|
||||
if (!cachedLanguage.isEmpty()) {
|
||||
_spellchecker->setLanguage(cachedLanguage);
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
#define QOWNSPELLCHECKER_H
|
||||
|
||||
#include <libraries/sonnet/src/core/speller.h>
|
||||
#include "libraries/sonnet/src/core/languagefilter_p.h"
|
||||
|
||||
#include "LanguageCache.h"
|
||||
#include "libraries/sonnet/src/core/languagefilter_p.h"
|
||||
|
||||
class QOwnSpellChecker {
|
||||
public:
|
||||
|
@ -47,9 +47,7 @@ class QOwnSpellChecker {
|
|||
* @param word the word to be checked
|
||||
* @return true if the given word is misspelled.
|
||||
*/
|
||||
inline bool isWordMisspelled(const QString &word) {
|
||||
return _spellchecker->isMisspelled(word);
|
||||
}
|
||||
inline bool isWordMisspelled(const QString &word) { return _spellchecker->isMisspelled(word); }
|
||||
|
||||
/**
|
||||
* Returns a list of suggested replacements for the given misspelled word.
|
||||
|
@ -76,8 +74,7 @@ class QOwnSpellChecker {
|
|||
* be returned.
|
||||
* @return a list of suggested replacements for the word
|
||||
*/
|
||||
QStringList suggestionsForWord(const QString &word,
|
||||
const QTextCursor &cursor, int max);
|
||||
QStringList suggestionsForWord(const QString &word, const QTextCursor &cursor, int max);
|
||||
|
||||
/**
|
||||
* @short Enable/Disable spell checking.
|
||||
|
|
|
@ -12,8 +12,7 @@
|
|||
|
||||
ToolbarContainer::ToolbarContainer(QToolBar *toolbar)
|
||||
: name(toolbar->objectName()), title(toolbar->windowTitle()) {
|
||||
foreach (QAction *a, toolbar->actions())
|
||||
actions.push_back(a->objectName());
|
||||
foreach (QAction *a, toolbar->actions()) actions.push_back(a->objectName());
|
||||
}
|
||||
|
||||
QToolBar *ToolbarContainer::create(QMainWindow *w) const {
|
||||
|
@ -78,25 +77,21 @@ void ToolbarContainer::updateToolbar() {
|
|||
// TODO(pbek): we will enable that again later
|
||||
if (false) {
|
||||
// if (item == "actionWorkspaceComboBox") {
|
||||
qDebug() << __func__
|
||||
<< " - 'actionWorkspaceComboBox': " << item;
|
||||
qDebug() << __func__ << " - 'actionWorkspaceComboBox': " << item;
|
||||
|
||||
// TODO(pbek): for some reason we can't find the combobox
|
||||
auto *workspaceComboBox = mainWindow->findChild<QComboBox *>(
|
||||
QStringLiteral("workspaceComboBox"));
|
||||
auto *workspaceComboBox =
|
||||
mainWindow->findChild<QComboBox *>(QStringLiteral("workspaceComboBox"));
|
||||
|
||||
qDebug() << __func__
|
||||
<< " - 'workspaceComboBox': " << workspaceComboBox;
|
||||
qDebug() << __func__ << " - 'workspaceComboBox': " << workspaceComboBox;
|
||||
|
||||
auto *widgetAction =
|
||||
mainWindow->findChild<QWidgetAction *>(item);
|
||||
auto *widgetAction = mainWindow->findChild<QWidgetAction *>(item);
|
||||
|
||||
qDebug() << __func__ << " - 'widgetAction': " << widgetAction;
|
||||
|
||||
if (widgetAction == nullptr) {
|
||||
widgetAction = new QWidgetAction(mainWindow);
|
||||
widgetAction->setObjectName(
|
||||
QStringLiteral("actionWorkspaceComboBox"));
|
||||
widgetAction->setObjectName(QStringLiteral("actionWorkspaceComboBox"));
|
||||
widgetAction->setText(QObject::tr("Workspace selector"));
|
||||
}
|
||||
|
||||
|
@ -131,9 +126,7 @@ void ToolbarContainer::updateToolbar() {
|
|||
*/
|
||||
void ToolbarContainer::updateIconSize(QToolBar *toolbar) {
|
||||
QSettings settings;
|
||||
int toolBarIconSize =
|
||||
settings.value(QStringLiteral("MainWindow/mainToolBar.iconSize"))
|
||||
.toInt();
|
||||
int toolBarIconSize = settings.value(QStringLiteral("MainWindow/mainToolBar.iconSize")).toInt();
|
||||
QSize size(toolBarIconSize, toolBarIconSize);
|
||||
toolbar->setIconSize(size);
|
||||
}
|
||||
|
|
|
@ -16,8 +16,7 @@ struct ToolbarContainer {
|
|||
QStringList actions;
|
||||
|
||||
ToolbarContainer() {}
|
||||
ToolbarContainer(const QString &name, const QString &title,
|
||||
const QStringList &actions)
|
||||
ToolbarContainer(const QString &name, const QString &title, const QStringList &actions)
|
||||
: name(name), title(title), actions(actions) {}
|
||||
ToolbarContainer(QToolBar *toolbar);
|
||||
QToolBar *create(QMainWindow *w) const;
|
||||
|
|
196
src/main.cpp
196
src/main.cpp
|
@ -30,18 +30,18 @@ void loadTranslation(QTranslator &translator, const QString &fileName,
|
|||
bool isLoaded = translator.load(fileName, directory);
|
||||
bool isInstalled = QCoreApplication::installTranslator(&translator);
|
||||
|
||||
qDebug() << "Translation " << fileName << "in" << directory << "isLoaded:"
|
||||
<< isLoaded << ", isInstalled:" << isInstalled;
|
||||
qDebug() << "Translation " << fileName << "in" << directory << "isLoaded:" << isLoaded
|
||||
<< ", isInstalled:" << isInstalled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for loading the translations
|
||||
*/
|
||||
void loadTranslations(QTranslator *translator, const QString &locale) {
|
||||
// loadTranslation(translator[0], "qt_" + QLocale::system().name(),
|
||||
// QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
// loadTranslation(translator[0], "qt_" + QLocale::system().name(),
|
||||
// QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
loadTranslation(translator[1], "qt_" + locale,
|
||||
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
QString appPath = QCoreApplication::applicationDirPath();
|
||||
loadTranslation(translator[2], "qt_" + locale, appPath + "/translations");
|
||||
loadTranslation(translator[3], appPath + "/../src/languages/QOwnNotes_" + locale);
|
||||
|
@ -50,31 +50,26 @@ void loadTranslations(QTranslator *translator, const QString &locale) {
|
|||
loadTranslation(translator[6], appPath + "/QOwnNotes_" + locale);
|
||||
loadTranslation(translator[7], "../src/languages/QOwnNotes_" + locale);
|
||||
loadTranslation(translator[8], "../share/qt5/translations/QOwnNotes_" + locale);
|
||||
loadTranslation(translator[9], appPath + "/../share/qt5/translations/QOwnNotes_" +
|
||||
locale);
|
||||
loadTranslation(translator[9], appPath + "/../share/qt5/translations/QOwnNotes_" + locale);
|
||||
loadTranslation(translator[10], "QOwnNotes_" + locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for loading the release translations
|
||||
*/
|
||||
inline void loadReleaseTranslations(QTranslator &translatorRelease,
|
||||
const QString &locale) {
|
||||
inline void loadReleaseTranslations(QTranslator &translatorRelease, const QString &locale) {
|
||||
loadTranslation(translatorRelease,
|
||||
"/usr/share/qt5/translations/"
|
||||
"QOwnNotes_" +
|
||||
locale);
|
||||
"/usr/share/qt5/translations/"
|
||||
"QOwnNotes_" +
|
||||
locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for loading the translations on OS X
|
||||
*/
|
||||
inline void loadMacTranslations(QTranslator &translatorOSX,
|
||||
QTranslator &translatorOSX2,
|
||||
QTranslator &translatorOSX3,
|
||||
QTranslator &translatorOSX4,
|
||||
const QString &appPath,
|
||||
const QString &locale) {
|
||||
inline void loadMacTranslations(QTranslator &translatorOSX, QTranslator &translatorOSX2,
|
||||
QTranslator &translatorOSX3, QTranslator &translatorOSX4,
|
||||
const QString &appPath, const QString &locale) {
|
||||
loadTranslation(translatorOSX, appPath + "/../Resources/QOwnNotes_" + locale);
|
||||
loadTranslation(translatorOSX2, "../Resources/QOwnNotes_" + locale);
|
||||
loadTranslation(translatorOSX3, appPath + "/../Resources/qtbase_" + locale);
|
||||
|
@ -90,31 +85,27 @@ bool mainStartupMisc(const QStringList &arguments) {
|
|||
parser.setApplicationDescription("QOwnNotes " + QString(VERSION));
|
||||
const QCommandLineOption helpOption = parser.addHelpOption();
|
||||
const QCommandLineOption portableOption(
|
||||
QStringLiteral("portable"),
|
||||
QCoreApplication::translate("main",
|
||||
"Runs the "
|
||||
"application in portable mode."));
|
||||
QStringLiteral("portable"), QCoreApplication::translate("main",
|
||||
"Runs the "
|
||||
"application in portable mode."));
|
||||
parser.addOption(portableOption);
|
||||
const QCommandLineOption dumpSettingsOption(
|
||||
QStringLiteral("dump-settings"),
|
||||
QCoreApplication::translate(
|
||||
"main",
|
||||
"Prints out "
|
||||
"a dump of the settings and other information about the "
|
||||
"application and environment in GitHub Markdown and exits "
|
||||
"the application."));
|
||||
QCoreApplication::translate("main",
|
||||
"Prints out "
|
||||
"a dump of the settings and other information about the "
|
||||
"application and environment in GitHub Markdown and exits "
|
||||
"the application."));
|
||||
parser.addOption(dumpSettingsOption);
|
||||
const QCommandLineOption versionOption(
|
||||
QStringLiteral("version"),
|
||||
QCoreApplication::translate(
|
||||
"main", "Prints out the version number."));
|
||||
QCoreApplication::translate("main", "Prints out the version number."));
|
||||
parser.addOption(versionOption);
|
||||
const QCommandLineOption allowMultipleInstancesOption(
|
||||
QStringLiteral("allow-multiple-instances"),
|
||||
QCoreApplication::translate(
|
||||
"main",
|
||||
"Allows multiple instances of QOwnNotes to be started "
|
||||
"even if disallowed in the settings."));
|
||||
QCoreApplication::translate("main",
|
||||
"Allows multiple instances of QOwnNotes to be started "
|
||||
"even if disallowed in the settings."));
|
||||
parser.addOption(allowMultipleInstancesOption);
|
||||
const QCommandLineOption clearSettingsOption(
|
||||
QStringLiteral("clear-settings"),
|
||||
|
@ -124,18 +115,16 @@ bool mainStartupMisc(const QStringList &arguments) {
|
|||
parser.addOption(clearSettingsOption);
|
||||
const QCommandLineOption sessionOption(
|
||||
QStringLiteral("session"),
|
||||
QCoreApplication::translate(
|
||||
"main",
|
||||
"Runs the "
|
||||
"application in a different context for settings and "
|
||||
"internal files."),
|
||||
QCoreApplication::translate("main",
|
||||
"Runs the "
|
||||
"application in a different context for settings and "
|
||||
"internal files."),
|
||||
"name");
|
||||
parser.addOption(sessionOption);
|
||||
const QCommandLineOption actionOption(
|
||||
QStringLiteral("action"),
|
||||
QCoreApplication::translate(
|
||||
"main",
|
||||
"Triggers a menu action after the application was started."),
|
||||
QCoreApplication::translate("main",
|
||||
"Triggers a menu action after the application was started."),
|
||||
"name");
|
||||
parser.addOption(actionOption);
|
||||
|
||||
|
@ -148,8 +137,7 @@ bool mainStartupMisc(const QStringList &arguments) {
|
|||
}
|
||||
|
||||
QSettings settings;
|
||||
QString interfaceStyle =
|
||||
settings.value(QStringLiteral("interfaceStyle")).toString();
|
||||
QString interfaceStyle = settings.value(QStringLiteral("interfaceStyle")).toString();
|
||||
|
||||
// restore the interface style
|
||||
if (!interfaceStyle.isEmpty()) {
|
||||
|
@ -164,12 +152,10 @@ bool mainStartupMisc(const QStringList &arguments) {
|
|||
Utils::Gui::doLinuxDarkModeCheck();
|
||||
#endif
|
||||
|
||||
bool systemIconTheme =
|
||||
settings.value(QStringLiteral("systemIconTheme")).toBool();
|
||||
bool systemIconTheme = settings.value(QStringLiteral("systemIconTheme")).toBool();
|
||||
|
||||
if (!systemIconTheme) {
|
||||
bool internalIconTheme =
|
||||
settings.value(QStringLiteral("internalIconTheme")).toBool();
|
||||
bool internalIconTheme = settings.value(QStringLiteral("internalIconTheme")).toBool();
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
||||
if (!internalIconTheme && QIcon::themeName().isEmpty()) {
|
||||
|
@ -187,30 +173,26 @@ bool mainStartupMisc(const QStringList &arguments) {
|
|||
}
|
||||
|
||||
MetricsService *metricsService = MetricsService::createInstance();
|
||||
metricsService->sendVisitIfEnabled(QStringLiteral("app/start"),
|
||||
QStringLiteral("App Start"));
|
||||
metricsService->sendVisitIfEnabled(QStringLiteral("app/start"), QStringLiteral("App Start"));
|
||||
metricsService->sendEventIfEnabled(QStringLiteral("app/qt-version-build"),
|
||||
QStringLiteral("app"), QStringLiteral("qt version build"),
|
||||
QStringLiteral(QT_VERSION_STR));
|
||||
metricsService->sendEventIfEnabled(QStringLiteral("app/qt-version-runtime"),
|
||||
QStringLiteral("app"), QStringLiteral("qt version runtime"),
|
||||
qVersion());
|
||||
metricsService->sendEventIfEnabled(QStringLiteral("app/theme"), QStringLiteral("app"),
|
||||
QStringLiteral("theme"), QIcon::themeName());
|
||||
metricsService->sendEventIfEnabled(QStringLiteral("app/release"), QStringLiteral("app"),
|
||||
QStringLiteral("release"),
|
||||
qApp->property("release").toString());
|
||||
metricsService->sendEventIfEnabled(
|
||||
QStringLiteral("app/qt-version-build"), QStringLiteral("app"),
|
||||
QStringLiteral("qt version build"), QStringLiteral(QT_VERSION_STR));
|
||||
metricsService->sendEventIfEnabled(
|
||||
QStringLiteral("app/qt-version-runtime"), QStringLiteral("app"),
|
||||
QStringLiteral("qt version runtime"), qVersion());
|
||||
metricsService->sendEventIfEnabled(
|
||||
QStringLiteral("app/theme"), QStringLiteral("app"),
|
||||
QStringLiteral("theme"), QIcon::themeName());
|
||||
metricsService->sendEventIfEnabled(
|
||||
QStringLiteral("app/release"), QStringLiteral("app"),
|
||||
QStringLiteral("release"), qApp->property("release").toString());
|
||||
metricsService->sendEventIfEnabled(
|
||||
QStringLiteral("app/portable"), QStringLiteral("app"),
|
||||
QStringLiteral("portable"),
|
||||
Utils::Misc::isInPortableMode() ? QStringLiteral("yes")
|
||||
: QStringLiteral("no"));
|
||||
QStringLiteral("app/portable"), QStringLiteral("app"), QStringLiteral("portable"),
|
||||
Utils::Misc::isInPortableMode() ? QStringLiteral("yes") : QStringLiteral("no"));
|
||||
|
||||
if (qApp->property("snap").toBool()) {
|
||||
metricsService->sendEventIfEnabled(
|
||||
QStringLiteral("app/styles"), QStringLiteral("app"),
|
||||
QStringLiteral("styles"), QStyleFactory::keys().join(QChar(' ')));
|
||||
metricsService->sendEventIfEnabled(QStringLiteral("app/styles"), QStringLiteral("app"),
|
||||
QStringLiteral("styles"),
|
||||
QStyleFactory::keys().join(QChar(' ')));
|
||||
}
|
||||
|
||||
QString productType;
|
||||
|
@ -221,9 +203,8 @@ bool mainStartupMisc(const QStringList &arguments) {
|
|||
productType += " Qt " + QString(QT_VERSION_STR);
|
||||
#endif
|
||||
|
||||
metricsService->sendEventIfEnabled(
|
||||
QStringLiteral("app/product-type"), QStringLiteral("app"),
|
||||
QStringLiteral("product-type"), productType);
|
||||
metricsService->sendEventIfEnabled(QStringLiteral("app/product-type"), QStringLiteral("app"),
|
||||
QStringLiteral("product-type"), productType);
|
||||
|
||||
QString platform = QStringLiteral("other");
|
||||
#ifdef Q_OS_LINUX
|
||||
|
@ -240,16 +221,14 @@ bool mainStartupMisc(const QStringList &arguments) {
|
|||
// self-builds if nothing is already set
|
||||
Utils::Misc::presetDisableAutomaticUpdateDialog();
|
||||
|
||||
metricsService->sendEventIfEnabled(QStringLiteral("app/platform"),
|
||||
QStringLiteral("app"),
|
||||
metricsService->sendEventIfEnabled(QStringLiteral("app/platform"), QStringLiteral("app"),
|
||||
QStringLiteral("platform"), platform);
|
||||
|
||||
// sends locale information
|
||||
metricsService->sendLocaleEvent();
|
||||
|
||||
// check legacy setting
|
||||
QString notesPath =
|
||||
settings.value(QStringLiteral("General/notesPath")).toString();
|
||||
QString notesPath = settings.value(QStringLiteral("General/notesPath")).toString();
|
||||
|
||||
// migration: remove old setting if we found one and store new one
|
||||
if (!notesPath.isEmpty()) {
|
||||
|
@ -270,17 +249,14 @@ bool mainStartupMisc(const QStringList &arguments) {
|
|||
// if this isn't the first run but the note folder doesn't exist any more
|
||||
// let the user select another one
|
||||
if (!notesPath.isEmpty() && !dir.exists()) {
|
||||
if (QMessageBox::question(
|
||||
nullptr, QObject::tr("Note folder not found!"),
|
||||
QObject::tr("Your note folder was not found any more! Do you "
|
||||
"want to select a new one?")) != QMessageBox::Yes) {
|
||||
if (QMessageBox::question(nullptr, QObject::tr("Note folder not found!"),
|
||||
QObject::tr("Your note folder was not found any more! Do you "
|
||||
"want to select a new one?")) != QMessageBox::Yes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
notesPath = QFileDialog::getExistingDirectory(
|
||||
nullptr,
|
||||
QObject::tr(
|
||||
"Please select the folder where your notes will get stored to"),
|
||||
nullptr, QObject::tr("Please select the folder where your notes will get stored to"),
|
||||
notesPath, QFileDialog::ShowDirsOnly);
|
||||
|
||||
dir = QDir(notesPath);
|
||||
|
@ -315,9 +291,7 @@ bool mainStartupMisc(const QStringList &arguments) {
|
|||
NoteFolder::migrateToNoteFolders();
|
||||
|
||||
if (parser.isSet(dumpSettingsOption)) {
|
||||
fprintf(
|
||||
stdout, "%s\n",
|
||||
Utils::Misc::generateDebugInformation().toLocal8Bit().constData());
|
||||
fprintf(stdout, "%s\n", Utils::Misc::generateDebugInformation().toLocal8Bit().constData());
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -342,12 +316,11 @@ bool mainStartupMisc(const QStringList &arguments) {
|
|||
/**
|
||||
* Temporary log output until LogWidget::logMessageOutput takes over
|
||||
*/
|
||||
void tempLogMessageOutput(QtMsgType type, const QMessageLogContext &context,
|
||||
const QString &msg) {
|
||||
void tempLogMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
|
||||
QByteArray localMsg = msg.toLocal8Bit();
|
||||
auto typeText = Utils::Misc::logMsgTypeText(type);
|
||||
auto message = QStringLiteral("%1 (%2:%3, %4)").arg(
|
||||
msg, context.file, QString::number(context.line), context.function);
|
||||
auto message = QStringLiteral("%1 (%2:%3, %4)")
|
||||
.arg(msg, context.file, QString::number(context.line), context.function);
|
||||
auto messageWithType = QStringLiteral("%1: %2\n").arg(typeText, message);
|
||||
|
||||
switch (type) {
|
||||
|
@ -370,8 +343,8 @@ void tempLogMessageOutput(QtMsgType type, const QMessageLogContext &context,
|
|||
}
|
||||
|
||||
inline void setAppProperties(QCoreApplication &app, const QString &release,
|
||||
const QStringList &arguments, bool singleApp,
|
||||
bool snap, bool portable, const QString &action) {
|
||||
const QStringList &arguments, bool singleApp, bool snap, bool portable,
|
||||
const QString &action) {
|
||||
app.setProperty("release", release);
|
||||
app.setProperty("portable", portable);
|
||||
if (singleApp) app.setProperty("singleApplication", true);
|
||||
|
@ -424,8 +397,7 @@ int main(int argc, char *argv[]) {
|
|||
portable = true;
|
||||
} else if (arg == QStringLiteral("--clear-settings")) {
|
||||
clearSettings = true;
|
||||
} else if (arg == QStringLiteral("--help") ||
|
||||
arg == QStringLiteral("--dump-settings") ||
|
||||
} else if (arg == QStringLiteral("--help") || arg == QStringLiteral("--dump-settings") ||
|
||||
arg == QStringLiteral("-h") ||
|
||||
arg == QStringLiteral("--allow-multiple-instances")) {
|
||||
allowOnlyOneAppInstance = false;
|
||||
|
@ -481,8 +453,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
QCoreApplication::setOrganizationDomain(QStringLiteral("PBE"));
|
||||
QCoreApplication::setOrganizationName(QStringLiteral("PBE"));
|
||||
QCoreApplication::setApplicationName(QStringLiteral("QOwnNotes") +
|
||||
appNameAdd);
|
||||
QCoreApplication::setApplicationName(QStringLiteral("QOwnNotes") + appNameAdd);
|
||||
|
||||
QString appVersion = QStringLiteral(VERSION);
|
||||
|
||||
|
@ -527,8 +498,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
QSettings settings;
|
||||
QString locale =
|
||||
settings.value(QStringLiteral("interfaceLanguage")).toString();
|
||||
QString locale = settings.value(QStringLiteral("interfaceLanguage")).toString();
|
||||
|
||||
if (locale.isEmpty()) {
|
||||
locale = QLocale::system().name().section('_', 0, 0);
|
||||
|
@ -554,8 +524,7 @@ int main(int argc, char *argv[]) {
|
|||
// settings
|
||||
if (allowOnlyOneAppInstance) {
|
||||
allowOnlyOneAppInstance =
|
||||
settings.value(QStringLiteral("allowOnlyOneAppInstance"), true)
|
||||
.toBool();
|
||||
settings.value(QStringLiteral("allowOnlyOneAppInstance"), true).toBool();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -571,9 +540,9 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
// if only one app instance is allowed use SingleApplication
|
||||
if (allowOnlyOneAppInstance) {
|
||||
SingleApplication app(argc, argv, true,
|
||||
SingleApplication::Mode::User |
|
||||
SingleApplication::Mode::SecondaryNotification);
|
||||
SingleApplication app(
|
||||
argc, argv, true,
|
||||
SingleApplication::Mode::User | SingleApplication::Mode::SecondaryNotification);
|
||||
|
||||
// quit app if it was already started
|
||||
if (app.isSecondary()) {
|
||||
|
@ -613,17 +582,18 @@ int main(int argc, char *argv[]) {
|
|||
w.show();
|
||||
|
||||
// receive messages from the primary app
|
||||
QObject::connect(&app, &SingleApplication::receivedMessage, [&](quint32 instanceId, QByteArray message) {
|
||||
Q_UNUSED(instanceId)
|
||||
qDebug() << __func__ << " - 'message': " << message;
|
||||
QObject::connect(&app, &SingleApplication::receivedMessage,
|
||||
[&](quint32 instanceId, QByteArray message) {
|
||||
Q_UNUSED(instanceId)
|
||||
qDebug() << __func__ << " - 'message': " << message;
|
||||
|
||||
// trigger the startup menu action
|
||||
if (message.startsWith("startupAction:")) {
|
||||
message.remove(0, 14);
|
||||
app.setProperty("startupAction", message);
|
||||
w.triggerStartupMenuAction();
|
||||
}
|
||||
});
|
||||
// trigger the startup menu action
|
||||
if (message.startsWith("startupAction:")) {
|
||||
message.remove(0, 14);
|
||||
app.setProperty("startupAction", message);
|
||||
w.triggerStartupMenuAction();
|
||||
}
|
||||
});
|
||||
|
||||
// raise the main window if app was started a 2nd time in single
|
||||
// application mode
|
||||
|
|
2424
src/mainwindow.cpp
2424
src/mainwindow.cpp
File diff suppressed because it is too large
Load diff
|
@ -81,8 +81,7 @@ class SettingsDialog;
|
|||
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Note currentNote WRITE setCurrentNote MEMBER currentNote NOTIFY
|
||||
currentNoteChanged)
|
||||
Q_PROPERTY(Note currentNote WRITE setCurrentNote MEMBER currentNote NOTIFY currentNoteChanged)
|
||||
|
||||
friend struct FileWatchDisabler;
|
||||
|
||||
|
@ -120,20 +119,17 @@ class MainWindow : public QMainWindow {
|
|||
|
||||
void setCurrentNoteText(QString text);
|
||||
|
||||
void setCurrentNote(Note note, bool updateNoteText = true,
|
||||
bool updateSelectedNote = true,
|
||||
void setCurrentNote(Note note, bool updateNoteText = true, bool updateSelectedNote = true,
|
||||
bool addPreviousNoteToHistory = true);
|
||||
|
||||
void createNewNote(QString noteName = QString(),
|
||||
bool withNameAppend = true);
|
||||
void createNewNote(QString noteName = QString(), bool withNameAppend = true);
|
||||
|
||||
void doSearchInNote(QString searchText);
|
||||
|
||||
const Note &getCurrentNote();
|
||||
|
||||
void createNewNote(
|
||||
QString name, QString text,
|
||||
CreateNewNoteOptions options = CreateNewNoteOption::None);
|
||||
void createNewNote(QString name, QString text,
|
||||
CreateNewNoteOptions options = CreateNewNoteOption::None);
|
||||
|
||||
void openSettingsDialog(int page = 0, bool openScriptRepository = false);
|
||||
|
||||
|
@ -161,12 +157,10 @@ class MainWindow : public QMainWindow {
|
|||
|
||||
void addCustomAction(const QString &identifier, const QString &menuText,
|
||||
const QString &buttonText, const QString &icon,
|
||||
bool useInNoteEditContextMenu = false,
|
||||
bool hideButtonInToolbar = false,
|
||||
bool useInNoteEditContextMenu = false, bool hideButtonInToolbar = false,
|
||||
bool useInNoteListContextMenu = false);
|
||||
|
||||
void addScriptingLabel(const QString &identifier,
|
||||
const QString &text = QString());
|
||||
void addScriptingLabel(const QString &identifier, const QString &text = QString());
|
||||
|
||||
void setScriptingLabelText(const QString &identifier, const QString &text);
|
||||
|
||||
|
@ -176,15 +170,15 @@ class MainWindow : public QMainWindow {
|
|||
|
||||
QString selectedNoteTextEditText();
|
||||
|
||||
void linkTagNameToCurrentNote(const QString &tagName,
|
||||
bool linkToSelectedNotes = false);
|
||||
void linkTagNameToCurrentNote(const QString &tagName, bool linkToSelectedNotes = false);
|
||||
|
||||
Q_INVOKABLE void reloadTagTree();
|
||||
|
||||
Q_INVOKABLE void reloadNoteSubFolderTree();
|
||||
|
||||
Q_INVOKABLE void buildNotesIndexAndLoadNoteDirectoryList(
|
||||
bool forceBuild = false, bool forceLoad = false, bool reloadTabs = true);
|
||||
Q_INVOKABLE void buildNotesIndexAndLoadNoteDirectoryList(bool forceBuild = false,
|
||||
bool forceLoad = false,
|
||||
bool reloadTabs = true);
|
||||
|
||||
QVector<Note> selectedNotes();
|
||||
|
||||
|
@ -244,8 +238,7 @@ class MainWindow : public QMainWindow {
|
|||
|
||||
void storeUpdatedNotesToDisk();
|
||||
|
||||
bool changeNoteFolder(const int noteFolderId,
|
||||
const bool forceChange = false);
|
||||
bool changeNoteFolder(const int noteFolderId, const bool forceChange = false);
|
||||
|
||||
void allowNoteEditing();
|
||||
|
||||
|
@ -253,7 +246,7 @@ class MainWindow : public QMainWindow {
|
|||
|
||||
void openSelectedNotesInTab();
|
||||
|
||||
void openNoteInTab(const Note& note);
|
||||
void openNoteInTab(const Note ¬e);
|
||||
|
||||
void openCurrentNoteInTab();
|
||||
|
||||
|
@ -429,8 +422,7 @@ class MainWindow : public QMainWindow {
|
|||
|
||||
void on_tagTreeWidget_itemChanged(QTreeWidgetItem *item, int column);
|
||||
|
||||
void on_tagTreeWidget_currentItemChanged(QTreeWidgetItem *current,
|
||||
QTreeWidgetItem *previous);
|
||||
void on_tagTreeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||
|
||||
void on_tagTreeWidget_itemSelectionChanged();
|
||||
|
||||
|
@ -478,8 +470,7 @@ class MainWindow : public QMainWindow {
|
|||
|
||||
void on_actionShow_status_bar_triggered(bool checked);
|
||||
|
||||
void on_noteTreeWidget_currentItemChanged(QTreeWidgetItem *current,
|
||||
QTreeWidgetItem *previous);
|
||||
void on_noteTreeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||
|
||||
void on_noteTreeWidget_customContextMenuRequested(const QPoint pos);
|
||||
|
||||
|
@ -689,7 +680,7 @@ class MainWindow : public QMainWindow {
|
|||
|
||||
void on_actionToggle_Always_on_top_triggered();
|
||||
|
||||
public:
|
||||
public:
|
||||
/** Settings access **/
|
||||
static bool isInDistractionFreeMode();
|
||||
void setShowNotesFromAllNoteSubFolders(bool show);
|
||||
|
@ -697,7 +688,7 @@ public:
|
|||
bool doNoteEditingCheck();
|
||||
|
||||
/** Actions **/
|
||||
public:
|
||||
public:
|
||||
QAction *newNoteAction();
|
||||
QAction *reloadNoteFolderAction();
|
||||
QAction *insertTextLinkAction();
|
||||
|
@ -705,20 +696,20 @@ public:
|
|||
QAction *pasteImageAction();
|
||||
QAction *autocompleteAction();
|
||||
QAction *splitNoteAtPosAction();
|
||||
QList<QAction*> customTextEditActions();
|
||||
QList<QAction *> customTextEditActions();
|
||||
|
||||
public:
|
||||
public:
|
||||
/** export / print **/
|
||||
void printTextDocument(QTextDocument *textDocument);
|
||||
void exportNoteAsPDF(QTextDocument *doc);
|
||||
|
||||
int getMaxImageWidth() const;
|
||||
|
||||
public:
|
||||
public:
|
||||
void clearNoteDirectoryWatcher();
|
||||
void updateNoteDirectoryWatcher();
|
||||
|
||||
private:
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QString notesPath;
|
||||
QFileSystemWatcher noteDirectoryWatcher;
|
||||
|
@ -852,8 +843,7 @@ private:
|
|||
|
||||
void loadNoteFolderListMenu();
|
||||
|
||||
void storeRecentNoteFolder(const QString &addFolderName,
|
||||
const QString &removeFolderName);
|
||||
void storeRecentNoteFolder(const QString &addFolderName, const QString &removeFolderName);
|
||||
|
||||
void storeSettings();
|
||||
|
||||
|
@ -881,8 +871,7 @@ private:
|
|||
|
||||
void updateNoteEncryptionUI();
|
||||
|
||||
void askForEncryptedNotePasswordIfNeeded(
|
||||
const QString &additionalText = QString());
|
||||
void askForEncryptedNotePasswordIfNeeded(const QString &additionalText = QString());
|
||||
|
||||
void showAppMetricsNotificationIfNeeded();
|
||||
|
||||
|
@ -934,15 +923,13 @@ private:
|
|||
|
||||
void initToolbars();
|
||||
|
||||
void buildTagTreeForParentItem(QTreeWidgetItem *parent = nullptr,
|
||||
bool topLevel = false);
|
||||
void buildTagTreeForParentItem(QTreeWidgetItem *parent = nullptr, bool topLevel = false);
|
||||
|
||||
void buildTagMoveMenuTree(QMenu *parentMenu, int parentTagId = 0);
|
||||
|
||||
void buildBulkNoteTagMenuTree(QMenu *parentMenu, int parentTagId = 0);
|
||||
|
||||
QTreeWidgetItem *addTagToTagTreeWidget(QTreeWidgetItem *parent,
|
||||
const TagHeader &tag);
|
||||
QTreeWidgetItem *addTagToTagTreeWidget(QTreeWidgetItem *parent, const TagHeader &tag);
|
||||
|
||||
bool jumpToNoteName(const QString &name);
|
||||
|
||||
|
@ -964,8 +951,7 @@ private:
|
|||
|
||||
void filterNotesByNoteSubFolders();
|
||||
|
||||
bool addNoteToNoteTreeWidget(const Note ¬e,
|
||||
QTreeWidgetItem *parent = nullptr);
|
||||
bool addNoteToNoteTreeWidget(const Note ¬e, QTreeWidgetItem *parent = nullptr);
|
||||
|
||||
QTreeWidgetItem *findNoteInNoteTreeWidget(const Note ¬e);
|
||||
|
||||
|
@ -978,9 +964,9 @@ private:
|
|||
void buildBulkNoteSubFolderMenuTree(QMenu *parentMenu, bool doCopy = true,
|
||||
int parentNoteSubFolderId = 0);
|
||||
|
||||
void buildBulkNoteFolderSubFolderMenuTree(
|
||||
QMenu *parentMenu, bool doCopy, const QString &parentNoteSubFolderPath,
|
||||
bool isRoot = true);
|
||||
void buildBulkNoteFolderSubFolderMenuTree(QMenu *parentMenu, bool doCopy,
|
||||
const QString &parentNoteSubFolderPath,
|
||||
bool isRoot = true);
|
||||
|
||||
void moveSelectedNotesToNoteSubFolder(const NoteSubFolder ¬eSubFolder);
|
||||
|
||||
|
@ -1050,17 +1036,14 @@ private:
|
|||
|
||||
void selectAllNotesInTagTreeWidget() const;
|
||||
|
||||
void handleScriptingNoteTagging(Note note, const Tag &tag,
|
||||
bool doRemove = false,
|
||||
void handleScriptingNoteTagging(Note note, const Tag &tag, bool doRemove = false,
|
||||
bool triggerPostMethods = true);
|
||||
|
||||
void handleScriptingNotesTagUpdating();
|
||||
|
||||
void handleScriptingNotesTagRenaming(const Tag &tag,
|
||||
const QString &newTagName);
|
||||
void handleScriptingNotesTagRenaming(const Tag &tag, const QString &newTagName);
|
||||
|
||||
void handleScriptingNotesTagRemoving(const Tag &tag,
|
||||
bool forBulkOperation = false);
|
||||
void handleScriptingNotesTagRemoving(const Tag &tag, bool forBulkOperation = false);
|
||||
|
||||
void directoryWatcherWorkaround(bool isNotesDirectoryWasModifiedDisabled,
|
||||
bool alsoHandleNotesWereModified = false);
|
||||
|
@ -1075,13 +1058,11 @@ private:
|
|||
|
||||
int getSelectedNotesCount() const;
|
||||
|
||||
void updateNoteTreeWidgetItem(const Note ¬e,
|
||||
QTreeWidgetItem *noteItem = nullptr);
|
||||
void updateNoteTreeWidgetItem(const Note ¬e, QTreeWidgetItem *noteItem = nullptr);
|
||||
|
||||
void initFakeVim(QOwnNotesMarkdownTextEdit *noteTextEdit);
|
||||
|
||||
void openNotesContextMenu(const QPoint globalPos,
|
||||
bool multiNoteMenuEntriesOnly = false);
|
||||
void openNotesContextMenu(const QPoint globalPos, bool multiNoteMenuEntriesOnly = false);
|
||||
|
||||
void updateCurrentNoteTextHash();
|
||||
|
||||
|
|
42
src/pch.h
42
src/pch.h
|
@ -4,36 +4,34 @@
|
|||
#if defined __cplusplus
|
||||
/* Add C++ includes here */
|
||||
|
||||
#include <QDialog>
|
||||
#include <QString>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QWidget>
|
||||
#include <QObject>
|
||||
#include <QJsonObject>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QSettings>
|
||||
#include <QMainWindow>
|
||||
#include <QList>
|
||||
#include <QVector>
|
||||
#include <QHash>
|
||||
#include <QStringList>
|
||||
#include <QRegularExpression>
|
||||
#include <QSyntaxHighlighter>
|
||||
#include <QMetaType>
|
||||
#include <QDialog>
|
||||
#include <QDir>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QHash>
|
||||
#include <QJsonObject>
|
||||
#include <QKeySequence>
|
||||
#include <QLabel>
|
||||
#include <QList>
|
||||
#include <QLoggingCategory>
|
||||
#include <QMainWindow>
|
||||
#include <QMetaType>
|
||||
#include <QObject>
|
||||
#include <QPair>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QRegularExpression>
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QSyntaxHighlighter>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QTimer>
|
||||
#include <QKeySequence>
|
||||
#include <QPair>
|
||||
#include <QLoggingCategory>
|
||||
#include <QDateTime>
|
||||
#include <QLabel>
|
||||
|
||||
#include <QVector>
|
||||
#include <QWidget>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#endif
|
||||
|
||||
#endif // QOWNNOTES_PCH_H
|
||||
#endif // QOWNNOTES_PCH_H
|
||||
|
|
|
@ -30,8 +30,7 @@ CryptoService::CryptoService(QObject *parent) : QObject(parent) {
|
|||
* The instance will be created if it doesn't exist.
|
||||
*/
|
||||
CryptoService *CryptoService::instance() {
|
||||
auto *cryptoService =
|
||||
qApp->property("cryptoService").value<CryptoService *>();
|
||||
auto *cryptoService = qApp->property("cryptoService").value<CryptoService *>();
|
||||
|
||||
if (cryptoService == nullptr) {
|
||||
cryptoService = createInstance(nullptr);
|
||||
|
@ -46,8 +45,7 @@ CryptoService *CryptoService::instance() {
|
|||
CryptoService *CryptoService::createInstance(QObject *parent) {
|
||||
auto *cryptoService = new CryptoService(parent);
|
||||
|
||||
qApp->setProperty("cryptoService",
|
||||
QVariant::fromValue<CryptoService *>(cryptoService));
|
||||
qApp->setProperty("cryptoService", QVariant::fromValue<CryptoService *>(cryptoService));
|
||||
|
||||
return cryptoService;
|
||||
}
|
||||
|
|
|
@ -28,8 +28,7 @@ DatabaseService::DatabaseService() = default;
|
|||
* @return
|
||||
*/
|
||||
QString DatabaseService::getDiskDatabasePath() {
|
||||
QString databaseFileName = Utils::Misc::appDataPath() +
|
||||
Utils::Misc::dirSeparator() +
|
||||
QString databaseFileName = Utils::Misc::appDataPath() + Utils::Misc::dirSeparator() +
|
||||
QStringLiteral("QOwnNotes.sqlite");
|
||||
qDebug() << __func__ << " - 'databaseFileName': " << databaseFileName;
|
||||
|
||||
|
@ -57,8 +56,7 @@ bool DatabaseService::removeDiskDatabase() {
|
|||
// remove the file
|
||||
bool result = file.remove();
|
||||
|
||||
QString text = result ? QStringLiteral("Removed")
|
||||
: QStringLiteral("Could not remove");
|
||||
QString text = result ? QStringLiteral("Removed") : QStringLiteral("Could not remove");
|
||||
qWarning() << text + " database file: " << file.fileName();
|
||||
return result;
|
||||
}
|
||||
|
@ -98,15 +96,14 @@ bool DatabaseService::checkDiskDatabaseIntegrity() {
|
|||
}
|
||||
|
||||
bool DatabaseService::createMemoryConnection() {
|
||||
QSqlDatabase dbMemory = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"),
|
||||
QStringLiteral("memory"));
|
||||
QSqlDatabase dbMemory =
|
||||
QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), QStringLiteral("memory"));
|
||||
dbMemory.setDatabaseName(QStringLiteral(":memory:"));
|
||||
|
||||
if (!dbMemory.open()) {
|
||||
QMessageBox::critical(
|
||||
nullptr, QWidget::tr("Cannot open memory database"),
|
||||
QWidget::tr("Unable to establish a memory database connection."),
|
||||
QMessageBox::Ok);
|
||||
QMessageBox::critical(nullptr, QWidget::tr("Cannot open memory database"),
|
||||
QWidget::tr("Unable to establish a memory database connection."),
|
||||
QMessageBox::Ok);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -114,19 +111,18 @@ bool DatabaseService::createMemoryConnection() {
|
|||
}
|
||||
|
||||
bool DatabaseService::createDiskConnection() {
|
||||
QSqlDatabase dbDisk = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"),
|
||||
QStringLiteral("disk"));
|
||||
QSqlDatabase dbDisk =
|
||||
QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), QStringLiteral("disk"));
|
||||
QString path = getDiskDatabasePath();
|
||||
dbDisk.setDatabaseName(path);
|
||||
|
||||
if (!dbDisk.open()) {
|
||||
QMessageBox::critical(
|
||||
nullptr, QWidget::tr("Cannot open disk database"),
|
||||
QWidget::tr("Unable to establish a database connection with "
|
||||
"file '%1'.\nAre the folder and the file "
|
||||
"writeable?")
|
||||
.arg(path),
|
||||
QMessageBox::Ok);
|
||||
QMessageBox::critical(nullptr, QWidget::tr("Cannot open disk database"),
|
||||
QWidget::tr("Unable to establish a database connection with "
|
||||
"file '%1'.\nAre the folder and the file "
|
||||
"writeable?")
|
||||
.arg(path),
|
||||
QMessageBox::Ok);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -137,20 +133,18 @@ bool DatabaseService::createNoteFolderConnection() {
|
|||
QSqlDatabase dbDisk =
|
||||
QSqlDatabase::contains(QStringLiteral("note_folder"))
|
||||
? QSqlDatabase::database(QStringLiteral("note_folder"))
|
||||
: QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"),
|
||||
QStringLiteral("note_folder"));
|
||||
: QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), QStringLiteral("note_folder"));
|
||||
|
||||
QString path = getNoteFolderDatabasePath();
|
||||
dbDisk.setDatabaseName(path);
|
||||
|
||||
if (!dbDisk.open()) {
|
||||
QMessageBox::critical(
|
||||
nullptr, QWidget::tr("Cannot open note folder database"),
|
||||
QWidget::tr("Unable to establish a database connection with "
|
||||
"file '%1'.\nAre the folder and the file "
|
||||
"writeable?")
|
||||
.arg(path),
|
||||
QMessageBox::Ok);
|
||||
QMessageBox::critical(nullptr, QWidget::tr("Cannot open note folder database"),
|
||||
QWidget::tr("Unable to establish a database connection with "
|
||||
"file '%1'.\nAre the folder and the file "
|
||||
"writeable?")
|
||||
.arg(path),
|
||||
QMessageBox::Ok);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -168,9 +162,8 @@ bool DatabaseService::setupNoteFolderTables() {
|
|||
QStringLiteral("CREATE TABLE IF NOT EXISTS appData ("
|
||||
"name VARCHAR(255) PRIMARY KEY, "
|
||||
"value VARCHAR(255))"));
|
||||
int version = getAppData(QStringLiteral("database_version"),
|
||||
QStringLiteral("note_folder"))
|
||||
.toInt();
|
||||
int version =
|
||||
getAppData(QStringLiteral("database_version"), QStringLiteral("note_folder")).toInt();
|
||||
int oldVersion = version;
|
||||
qDebug() << __func__ << " - 'database version': " << version;
|
||||
|
||||
|
@ -193,16 +186,15 @@ bool DatabaseService::setupNoteFolderTables() {
|
|||
"note_file_name VARCHAR(255),"
|
||||
"created DATETIME DEFAULT current_timestamp)"));
|
||||
|
||||
queryDisk.exec(QStringLiteral(
|
||||
"CREATE UNIQUE INDEX IF NOT EXISTS idxUniqueTagNoteLink"
|
||||
" ON noteTagLink (tag_id, note_file_name)"));
|
||||
queryDisk.exec(
|
||||
QStringLiteral("CREATE UNIQUE INDEX IF NOT EXISTS idxUniqueTagNoteLink"
|
||||
" ON noteTagLink (tag_id, note_file_name)"));
|
||||
|
||||
version = 1;
|
||||
}
|
||||
|
||||
if (version < 2) {
|
||||
queryDisk.exec(
|
||||
QStringLiteral("ALTER TABLE tag ADD parent_id INTEGER DEFAULT 0"));
|
||||
queryDisk.exec(QStringLiteral("ALTER TABLE tag ADD parent_id INTEGER DEFAULT 0"));
|
||||
queryDisk.exec(
|
||||
QStringLiteral("CREATE INDEX IF NOT EXISTS idxTagParent "
|
||||
"ON tag( parent_id )"));
|
||||
|
@ -218,25 +210,22 @@ bool DatabaseService::setupNoteFolderTables() {
|
|||
}
|
||||
|
||||
if (version < 4) {
|
||||
queryDisk.exec(QStringLiteral(
|
||||
"ALTER TABLE noteTagLink ADD note_sub_folder_path TEXT"));
|
||||
queryDisk.exec(QStringLiteral("ALTER TABLE noteTagLink ADD note_sub_folder_path TEXT"));
|
||||
version = 4;
|
||||
}
|
||||
|
||||
if (version < 5) {
|
||||
queryDisk.exec(QStringLiteral("DROP INDEX IF EXISTS idxUniqueTagNoteLink"));
|
||||
queryDisk.exec(
|
||||
QStringLiteral("DROP INDEX IF EXISTS idxUniqueTagNoteLink"));
|
||||
queryDisk.exec(QStringLiteral(
|
||||
"CREATE UNIQUE INDEX IF NOT EXISTS idxUniqueTagNoteLink "
|
||||
"ON noteTagLink (tag_id, note_file_name, "
|
||||
"note_sub_folder_path)"));
|
||||
QStringLiteral("CREATE UNIQUE INDEX IF NOT EXISTS idxUniqueTagNoteLink "
|
||||
"ON noteTagLink (tag_id, note_file_name, "
|
||||
"note_sub_folder_path)"));
|
||||
version = 5;
|
||||
}
|
||||
|
||||
if (version < 6) {
|
||||
// we need to add a `DEFAULT ''` to column note_sub_folder_path
|
||||
queryDisk.exec(
|
||||
QStringLiteral("ALTER TABLE noteTagLink RENAME TO _noteTagLink"));
|
||||
queryDisk.exec(QStringLiteral("ALTER TABLE noteTagLink RENAME TO _noteTagLink"));
|
||||
queryDisk.exec(
|
||||
QStringLiteral("CREATE TABLE IF NOT EXISTS noteTagLink ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
|
@ -250,12 +239,11 @@ bool DatabaseService::setupNoteFolderTables() {
|
|||
"SELECT tag_id, note_file_name, "
|
||||
"note_sub_folder_path, created "
|
||||
"FROM _noteTagLink ORDER BY id"));
|
||||
queryDisk.exec(QStringLiteral("DROP INDEX IF EXISTS idxUniqueTagNoteLink"));
|
||||
queryDisk.exec(
|
||||
QStringLiteral("DROP INDEX IF EXISTS idxUniqueTagNoteLink"));
|
||||
queryDisk.exec(QStringLiteral(
|
||||
"CREATE UNIQUE INDEX IF NOT EXISTS idxUniqueTagNoteLink "
|
||||
"ON noteTagLink (tag_id, note_file_name, "
|
||||
"note_sub_folder_path)"));
|
||||
QStringLiteral("CREATE UNIQUE INDEX IF NOT EXISTS idxUniqueTagNoteLink "
|
||||
"ON noteTagLink (tag_id, note_file_name, "
|
||||
"note_sub_folder_path)"));
|
||||
queryDisk.exec(QStringLiteral("DROP TABLE _noteTagLink"));
|
||||
queryDisk.exec(
|
||||
QStringLiteral("UPDATE noteTagLink SET note_sub_folder_path = '' "
|
||||
|
@ -276,8 +264,7 @@ bool DatabaseService::setupNoteFolderTables() {
|
|||
}
|
||||
|
||||
if (version < 9) {
|
||||
queryDisk.exec(
|
||||
QStringLiteral("ALTER TABLE tag ADD dark_color VARCHAR(20)"));
|
||||
queryDisk.exec(QStringLiteral("ALTER TABLE tag ADD dark_color VARCHAR(20)"));
|
||||
version = 9;
|
||||
}
|
||||
|
||||
|
@ -353,16 +340,16 @@ bool DatabaseService::setupNoteFolderTables() {
|
|||
if (version < 14) {
|
||||
// removing broken tag assignments from
|
||||
// https://github.com/pbek/QOwnNotes/issues/1510
|
||||
queryDisk.exec(QStringLiteral(
|
||||
"DELETE FROM noteTagLink WHERE note_sub_folder_path IS NULL"));
|
||||
queryDisk.exec(
|
||||
QStringLiteral("DELETE FROM noteTagLink WHERE note_sub_folder_path IS NULL"));
|
||||
|
||||
version = 14;
|
||||
}
|
||||
|
||||
if (version < 15) {
|
||||
// https://github.com/pbek/QOwnNotes/issues/2292
|
||||
queryDisk.exec(QStringLiteral(
|
||||
"ALTER TABLE noteTagLink ADD stale_date DATETIME DEFAULT NULL"));
|
||||
queryDisk.exec(
|
||||
QStringLiteral("ALTER TABLE noteTagLink ADD stale_date DATETIME DEFAULT NULL"));
|
||||
|
||||
version = 15;
|
||||
}
|
||||
|
@ -395,8 +382,7 @@ QSqlDatabase DatabaseService::getNoteFolderDatabase() {
|
|||
*
|
||||
* @param db
|
||||
*/
|
||||
void DatabaseService::closeDatabaseConnection(QSqlDatabase& db,
|
||||
QSqlQuery& query) {
|
||||
void DatabaseService::closeDatabaseConnection(QSqlDatabase& db, QSqlQuery& query) {
|
||||
query.finish();
|
||||
query.clear();
|
||||
|
||||
|
@ -481,8 +467,7 @@ bool DatabaseService::setupTables() {
|
|||
queryDisk.exec(
|
||||
QStringLiteral("CREATE UNIQUE INDEX IF NOT EXISTS idxUrl "
|
||||
"ON calendarItem( url )"));
|
||||
queryDisk.exec(QStringLiteral(
|
||||
"ALTER TABLE calendarItem ADD completed_date DATETIME"));
|
||||
queryDisk.exec(QStringLiteral("ALTER TABLE calendarItem ADD completed_date DATETIME"));
|
||||
queryDisk.exec(
|
||||
QStringLiteral("ALTER TABLE calendarItem "
|
||||
"ADD sort_priority INTEGER DEFAULT 0"));
|
||||
|
@ -521,8 +506,7 @@ bool DatabaseService::setupTables() {
|
|||
}
|
||||
|
||||
if (version < 7) {
|
||||
queryDisk.exec(
|
||||
QStringLiteral("ALTER TABLE noteFolder ADD active_tag_id INTEGER"));
|
||||
queryDisk.exec(QStringLiteral("ALTER TABLE noteFolder ADD active_tag_id INTEGER"));
|
||||
version = 7;
|
||||
}
|
||||
|
||||
|
@ -560,16 +544,13 @@ bool DatabaseService::setupTables() {
|
|||
}
|
||||
|
||||
if (version < 12) {
|
||||
bool darkModeColors =
|
||||
settings.value(QStringLiteral("darkModeColors")).toBool();
|
||||
bool darkModeColors = settings.value(QStringLiteral("darkModeColors")).toBool();
|
||||
|
||||
// set an initial schema key
|
||||
QString schemaKey =
|
||||
darkModeColors
|
||||
? QStringLiteral(
|
||||
"EditorColorSchema-cdbf28fc-1ddc-4d13-bb21-6a4043316a2f")
|
||||
: QStringLiteral(
|
||||
"EditorColorSchema-6033d61b-cb96-46d5-a3a8-20d5172017eb");
|
||||
? QStringLiteral("EditorColorSchema-cdbf28fc-1ddc-4d13-bb21-6a4043316a2f")
|
||||
: QStringLiteral("EditorColorSchema-6033d61b-cb96-46d5-a3a8-20d5172017eb");
|
||||
settings.setValue(QStringLiteral("Editor/CurrentSchemaKey"), schemaKey);
|
||||
|
||||
version = 12;
|
||||
|
@ -604,8 +585,7 @@ bool DatabaseService::setupTables() {
|
|||
settings.remove(QStringLiteral("dockWindowState"));
|
||||
settings.remove(QStringLiteral("verticalPreviewModeEnabled"));
|
||||
settings.remove(QStringLiteral("mainSplitterSizes"));
|
||||
settings.remove(
|
||||
QStringLiteral("DistractionFreeMode/mainSplitterSizes"));
|
||||
settings.remove(QStringLiteral("DistractionFreeMode/mainSplitterSizes"));
|
||||
settings.remove(QStringLiteral("mainSplitterState-0-0-0-0"));
|
||||
settings.remove(QStringLiteral("mainSplitterState-0-0-0-1"));
|
||||
settings.remove(QStringLiteral("mainSplitterState-0-0-1-0"));
|
||||
|
@ -632,8 +612,7 @@ bool DatabaseService::setupTables() {
|
|||
if (version < 16) {
|
||||
// remove some deprecated settings
|
||||
settings.remove(QStringLiteral("dockWindowGeometry"));
|
||||
settings.remove(
|
||||
QStringLiteral("MainWindow/showRecentNoteFolderInMainArea"));
|
||||
settings.remove(QStringLiteral("MainWindow/showRecentNoteFolderInMainArea"));
|
||||
|
||||
version = 16;
|
||||
}
|
||||
|
@ -654,8 +633,7 @@ bool DatabaseService::setupTables() {
|
|||
// set a new markdownHighlightingEnabled setting
|
||||
settings.setValue(
|
||||
QStringLiteral("markdownHighlightingEnabled"),
|
||||
settings.value(QStringLiteral("markdownHighlightingInterval"), 200)
|
||||
.toInt() > 0);
|
||||
settings.value(QStringLiteral("markdownHighlightingInterval"), 200).toInt() > 0);
|
||||
|
||||
// remove the deprecated markdownHighlightingInterval setting
|
||||
settings.remove(QStringLiteral("markdownHighlightingInterval"));
|
||||
|
@ -665,10 +643,8 @@ bool DatabaseService::setupTables() {
|
|||
|
||||
if (version < 19) {
|
||||
// set the ownCloud support enabled setting
|
||||
bool ownCloudEnabled =
|
||||
OwnCloudService::hasOwnCloudSettings(false, true);
|
||||
settings.setValue(QStringLiteral("ownCloud/supportEnabled"),
|
||||
ownCloudEnabled);
|
||||
bool ownCloudEnabled = OwnCloudService::hasOwnCloudSettings(false, true);
|
||||
settings.setValue(QStringLiteral("ownCloud/supportEnabled"), ownCloudEnabled);
|
||||
|
||||
version = 19;
|
||||
}
|
||||
|
@ -685,32 +661,27 @@ bool DatabaseService::setupTables() {
|
|||
|
||||
if (version < 21) {
|
||||
// migrate to the new Portuguese translation
|
||||
QString locale =
|
||||
settings.value(QStringLiteral("interfaceLanguage")).toString();
|
||||
QString locale = settings.value(QStringLiteral("interfaceLanguage")).toString();
|
||||
if (locale == QStringLiteral("pt")) {
|
||||
settings.setValue(QStringLiteral("interfaceLanguage"),
|
||||
QStringLiteral("pt_BR"));
|
||||
settings.setValue(QStringLiteral("interfaceLanguage"), QStringLiteral("pt_BR"));
|
||||
}
|
||||
|
||||
version = 21;
|
||||
}
|
||||
|
||||
if (version < 22) {
|
||||
queryDisk.exec(QStringLiteral(
|
||||
"ALTER TABLE noteFolder ADD use_git BOOLEAN DEFAULT 0"));
|
||||
queryDisk.exec(QStringLiteral("ALTER TABLE noteFolder ADD use_git BOOLEAN DEFAULT 0"));
|
||||
version = 22;
|
||||
}
|
||||
|
||||
if (version < 23) {
|
||||
queryDisk.exec(
|
||||
QStringLiteral("ALTER TABLE script ADD identifier VARCHAR(255)"));
|
||||
queryDisk.exec(QStringLiteral("ALTER TABLE script ADD identifier VARCHAR(255)"));
|
||||
queryDisk.exec(QStringLiteral("ALTER TABLE script ADD info_json TEXT"));
|
||||
version = 23;
|
||||
}
|
||||
|
||||
if (version < 24) {
|
||||
queryDisk.exec(QStringLiteral(
|
||||
"ALTER TABLE script ADD settings_variables_json TEXT"));
|
||||
queryDisk.exec(QStringLiteral("ALTER TABLE script ADD settings_variables_json TEXT"));
|
||||
version = 24;
|
||||
}
|
||||
|
||||
|
@ -718,17 +689,16 @@ bool DatabaseService::setupTables() {
|
|||
// migrate old sort and order settings + set defaults if unset
|
||||
// if settings.s;
|
||||
if (settings.contains(QStringLiteral("SortingModeAlphabetically"))) {
|
||||
bool sort =
|
||||
settings.value(QStringLiteral("SortingModeAlphabetically"))
|
||||
.toBool(); // read old setting
|
||||
bool sort = settings.value(QStringLiteral("SortingModeAlphabetically"))
|
||||
.toBool(); // read old setting
|
||||
settings.setValue(QStringLiteral("notesPanelSort"),
|
||||
sort ? SORT_ALPHABETICAL : SORT_BY_LAST_CHANGE);
|
||||
settings.remove(QStringLiteral("SortingModeAlphabetically"));
|
||||
}
|
||||
|
||||
if (settings.contains(QStringLiteral("NoteSortOrder"))) {
|
||||
int order = static_cast<Qt::SortOrder>(
|
||||
settings.value(QStringLiteral("NoteSortOrder")).toInt());
|
||||
int order =
|
||||
static_cast<Qt::SortOrder>(settings.value(QStringLiteral("NoteSortOrder")).toInt());
|
||||
settings.setValue(QStringLiteral("notesPanelOrder"),
|
||||
order); // see defines in MainWindow.h
|
||||
settings.remove(QStringLiteral("NoteSortOrder"));
|
||||
|
@ -736,20 +706,17 @@ bool DatabaseService::setupTables() {
|
|||
|
||||
// set defaults for now settings if not set already
|
||||
if (!settings.contains(QStringLiteral("notesPanelSort"))) {
|
||||
settings.value(QStringLiteral("notesPanelSort"),
|
||||
SORT_BY_LAST_CHANGE);
|
||||
settings.value(QStringLiteral("notesPanelSort"), SORT_BY_LAST_CHANGE);
|
||||
}
|
||||
if (!settings.contains(QStringLiteral("notesPanelOrder"))) {
|
||||
settings.value(QStringLiteral("notesPanelOrder"), ORDER_DESCENDING);
|
||||
}
|
||||
|
||||
if (!settings.contains(QStringLiteral("noteSubfoldersPanelSort"))) {
|
||||
settings.value(QStringLiteral("noteSubfoldersPanelSort"),
|
||||
SORT_BY_LAST_CHANGE);
|
||||
settings.value(QStringLiteral("noteSubfoldersPanelSort"), SORT_BY_LAST_CHANGE);
|
||||
}
|
||||
if (!settings.contains(QStringLiteral("noteSubfoldersOrder"))) {
|
||||
settings.value(QStringLiteral("noteSubfoldersOrder"),
|
||||
ORDER_ASCENDING);
|
||||
settings.value(QStringLiteral("noteSubfoldersOrder"), ORDER_ASCENDING);
|
||||
}
|
||||
|
||||
if (!settings.contains(QStringLiteral("tagsPanelSort"))) {
|
||||
|
@ -817,25 +784,23 @@ bool DatabaseService::setupTables() {
|
|||
|
||||
if (version < 31) {
|
||||
// preset cloud connections for all note folders
|
||||
queryDisk.prepare(
|
||||
QStringLiteral("UPDATE noteFolder SET cloud_connection_id = :id"));
|
||||
queryDisk.bindValue(QStringLiteral(":id"),
|
||||
CloudConnection::firstCloudConnection().getId());
|
||||
queryDisk.prepare(QStringLiteral("UPDATE noteFolder SET cloud_connection_id = :id"));
|
||||
queryDisk.bindValue(QStringLiteral(":id"), CloudConnection::firstCloudConnection().getId());
|
||||
queryDisk.exec();
|
||||
|
||||
version = 31;
|
||||
}
|
||||
|
||||
if (version < 32) {
|
||||
queryDisk.exec(QStringLiteral(
|
||||
"ALTER TABLE calendarItem ADD related_uid VARCHAR(255)"));
|
||||
queryDisk.exec(QStringLiteral("ALTER TABLE calendarItem ADD related_uid VARCHAR(255)"));
|
||||
version = 32;
|
||||
}
|
||||
|
||||
if (version < 33) {
|
||||
foreach(NoteFolder noteFolder, NoteFolder::fetchAll()) {
|
||||
noteFolder.setSettingsValue(QStringLiteral("allowDifferentNoteFileName"),
|
||||
settings.value(QStringLiteral("allowDifferentNoteFileName")));
|
||||
foreach (NoteFolder noteFolder, NoteFolder::fetchAll()) {
|
||||
noteFolder.setSettingsValue(
|
||||
QStringLiteral("allowDifferentNoteFileName"),
|
||||
settings.value(QStringLiteral("allowDifferentNoteFileName")));
|
||||
}
|
||||
|
||||
settings.remove(QStringLiteral("allowDifferentNoteFileName"));
|
||||
|
@ -845,15 +810,14 @@ bool DatabaseService::setupTables() {
|
|||
|
||||
if (version < 34) {
|
||||
queryDisk.exec(QStringLiteral(
|
||||
"ALTER TABLE cloudConnection ADD qownnotesapi_enabled BOOLEAN DEFAULT 1"));
|
||||
"ALTER TABLE cloudConnection ADD qownnotesapi_enabled BOOLEAN DEFAULT 1"));
|
||||
version = 34;
|
||||
}
|
||||
|
||||
if (version < 35) {
|
||||
// migrate setting with typo
|
||||
settings.setValue(
|
||||
QStringLiteral("Editor/removeTrailingSpaces"),
|
||||
settings.value(QStringLiteral("Editor/removeTrainingSpaces")).toBool());
|
||||
settings.setValue(QStringLiteral("Editor/removeTrailingSpaces"),
|
||||
settings.value(QStringLiteral("Editor/removeTrainingSpaces")).toBool());
|
||||
settings.remove(QStringLiteral("Editor/removeTrainingSpaces"));
|
||||
|
||||
version = 35;
|
||||
|
@ -871,13 +835,12 @@ bool DatabaseService::setupTables() {
|
|||
|
||||
if (version < 37) {
|
||||
// add "txt" and "md" to the note file extensions, so they can also be removed
|
||||
auto extensions = settings.value(
|
||||
QStringLiteral("customNoteFileExtensionList")).toStringList();
|
||||
extensions << "md" << "txt";
|
||||
auto extensions =
|
||||
settings.value(QStringLiteral("customNoteFileExtensionList")).toStringList();
|
||||
extensions << "md"
|
||||
<< "txt";
|
||||
|
||||
settings.setValue(
|
||||
QStringLiteral("customNoteFileExtensionList"),
|
||||
extensions);
|
||||
settings.setValue(QStringLiteral("customNoteFileExtensionList"), extensions);
|
||||
|
||||
version = 37;
|
||||
}
|
||||
|
@ -886,40 +849,35 @@ bool DatabaseService::setupTables() {
|
|||
|
||||
if (version < 39) {
|
||||
// migrate from customNoteFileExtensionList to noteFileExtensionList
|
||||
auto extensions = settings.value(
|
||||
QStringLiteral("customNoteFileExtensionList")).toStringList();
|
||||
auto extensions =
|
||||
settings.value(QStringLiteral("customNoteFileExtensionList")).toStringList();
|
||||
|
||||
settings.setValue(
|
||||
QStringLiteral("noteFileExtensionList"),
|
||||
extensions);
|
||||
settings.setValue(QStringLiteral("noteFileExtensionList"), extensions);
|
||||
settings.remove(QStringLiteral("customNoteFileExtensionList"));
|
||||
|
||||
version = 39;
|
||||
}
|
||||
|
||||
if (version < 40) {
|
||||
const auto bookmarksNoteName = settings.value(
|
||||
QStringLiteral("webSocketServerService/bookmarksNoteName")).toString();
|
||||
const auto bookmarksNoteName =
|
||||
settings.value(QStringLiteral("webSocketServerService/bookmarksNoteName")).toString();
|
||||
|
||||
// fix overwritten bookmarksNoteName
|
||||
if (bookmarksNoteName == QStringLiteral("Commands")) {
|
||||
settings.setValue(
|
||||
QStringLiteral("webSocketServerService/bookmarksNoteName"),
|
||||
QStringLiteral("Bookmarks"));
|
||||
settings.setValue(QStringLiteral("webSocketServerService/bookmarksNoteName"),
|
||||
QStringLiteral("Bookmarks"));
|
||||
}
|
||||
|
||||
version = 40;
|
||||
}
|
||||
|
||||
if (version < 41) {
|
||||
queryDisk.exec(QStringLiteral(
|
||||
"ALTER TABLE cloudConnection ADD account_id VARCHAR(255)"));
|
||||
queryDisk.exec(QStringLiteral("ALTER TABLE cloudConnection ADD account_id VARCHAR(255)"));
|
||||
version = 41;
|
||||
}
|
||||
|
||||
if (version != oldVersion) {
|
||||
setAppData(QStringLiteral("database_version"),
|
||||
QString::number(version));
|
||||
setAppData(QStringLiteral("database_version"), QString::number(version));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -938,13 +896,11 @@ bool DatabaseService::setAppData(const QString& name, const QString& value,
|
|||
return query.exec();
|
||||
}
|
||||
|
||||
QString DatabaseService::getAppData(const QString& name,
|
||||
const QString& connectionName) {
|
||||
QString DatabaseService::getAppData(const QString& name, const QString& connectionName) {
|
||||
QSqlDatabase db = QSqlDatabase::database(connectionName);
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare(
|
||||
QStringLiteral("SELECT value FROM appData WHERE name = :name"));
|
||||
query.prepare(QStringLiteral("SELECT value FROM appData WHERE name = :name"));
|
||||
query.bindValue(QStringLiteral(":name"), name);
|
||||
|
||||
if (!query.exec()) {
|
||||
|
@ -963,18 +919,17 @@ QString DatabaseService::getAppData(const QString& name,
|
|||
* @return
|
||||
*/
|
||||
bool DatabaseService::mergeNoteFolderDatabase(const QString& path) {
|
||||
QSqlDatabase mergeDB = QSqlDatabase::addDatabase(
|
||||
QStringLiteral("QSQLITE"), QStringLiteral("note_folder_merge"));
|
||||
QSqlDatabase mergeDB =
|
||||
QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), QStringLiteral("note_folder_merge"));
|
||||
mergeDB.setDatabaseName(path);
|
||||
|
||||
if (!mergeDB.open()) {
|
||||
QMessageBox::critical(
|
||||
nullptr, QWidget::tr("Cannot open database"),
|
||||
QWidget::tr("Unable to establish a database connection with "
|
||||
"note folder database to merge '%1'.\nAre the folder "
|
||||
"and the file writeable?")
|
||||
.arg(path),
|
||||
QMessageBox::Ok);
|
||||
QMessageBox::critical(nullptr, QWidget::tr("Cannot open database"),
|
||||
QWidget::tr("Unable to establish a database connection with "
|
||||
"note folder database to merge '%1'.\nAre the folder "
|
||||
"and the file writeable?")
|
||||
.arg(path),
|
||||
QMessageBox::Ok);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -994,8 +949,8 @@ bool DatabaseService::mergeNoteFolderDatabase(const QString& path) {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
QByteArray DatabaseService::generateDatabaseTableSha1Signature(
|
||||
QSqlDatabase& db, const QString& table) {
|
||||
QByteArray DatabaseService::generateDatabaseTableSha1Signature(QSqlDatabase& db,
|
||||
const QString& table) {
|
||||
QCryptographicHash hash(QCryptographicHash::Sha1);
|
||||
QSqlQuery query(db);
|
||||
query.prepare(QStringLiteral("SELECT * FROM ") + table);
|
||||
|
|
|
@ -10,12 +10,10 @@ class DatabaseService {
|
|||
DatabaseService();
|
||||
static bool createConnection();
|
||||
static bool setupTables();
|
||||
static QString getAppData(
|
||||
const QString& name,
|
||||
const QString& connectionName = QStringLiteral("disk"));
|
||||
static bool setAppData(
|
||||
const QString& name, const QString& value,
|
||||
const QString& connectionName = QStringLiteral("disk"));
|
||||
static QString getAppData(const QString& name,
|
||||
const QString& connectionName = QStringLiteral("disk"));
|
||||
static bool setAppData(const QString& name, const QString& value,
|
||||
const QString& connectionName = QStringLiteral("disk"));
|
||||
static bool reinitializeDiskDatabase();
|
||||
static bool removeDiskDatabase();
|
||||
static bool createNoteFolderConnection();
|
||||
|
@ -25,8 +23,7 @@ class DatabaseService {
|
|||
static void closeDatabaseConnection(QSqlDatabase& db, QSqlQuery& query);
|
||||
static QString getNoteFolderDatabasePath();
|
||||
static bool mergeNoteFolderDatabase(const QString& path);
|
||||
static QByteArray generateDatabaseTableSha1Signature(QSqlDatabase& db,
|
||||
const QString& table);
|
||||
static QByteArray generateDatabaseTableSha1Signature(QSqlDatabase& db, const QString& table);
|
||||
static bool checkDiskDatabaseIntegrity();
|
||||
|
||||
private:
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue