Fix Splitter between editor and viewer

This commit is contained in:
Aurélie Delhaie
2022-05-03 20:02:39 +02:00
parent 658f4d860c
commit e2c090b3a0
7 changed files with 88 additions and 243 deletions

View File

@@ -4,8 +4,8 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17 CONFIG += c++17
win32:VERSION = 1.1.1.0 # major.minor.patch.build win32:VERSION = 1.1.2.0 # major.minor.patch.build
else:VERSION = 1.1.1 # major.minor.patch else:VERSION = 1.1.2 # major.minor.patch
DEFINES += APP_VERSION=\"\\\"$${VERSION}\\\"\" DEFINES += APP_VERSION=\"\\\"$${VERSION}\\\"\"
DEFINES += APP_NAME=\"\\\"TaskNote\\\"\" DEFINES += APP_NAME=\"\\\"TaskNote\\\"\"
@@ -41,22 +41,14 @@ macx {
QMAKE_CXXFLAGS_RELEASE -= -O1 QMAKE_CXXFLAGS_RELEASE -= -O1
QMAKE_CXXFLAGS_RELEASE -= -O2 QMAKE_CXXFLAGS_RELEASE -= -O2
QMAKE_CXXFLAGS_RELEASE *= -O3 QMAKE_CXXFLAGS_RELEASE *= -O3
QMAKE_APPLE_DEVICE_ARCHS = x86_64 arm64
DEFINES += APP_OS=\"\\\"macOS\\\"\" DEFINES += APP_OS=\"\\\"macOS\\\"\"
DEFINES += APP_OS_VERSION=\"\\\"$$system(uname -r)\\\"\" DEFINES += APP_OS_VERSION=\"\\\"$$system(uname -r)\\\"\"
equals(QMAKE_APPLE_DEVICE_ARCHS, arm64) { DEFINES += APP_ARCH=\"\\\"universal\\\"\"
message("CPU Architecture : aarch64")
DEFINES += APP_ARCH=\"\\\"aarch64\\\"\"
QMAKE_CXXFLAGS_RELEASE += -mcpu=apple-a14
}
} }
linux-g++* { linux-g++* {
message("Build for Linux") message("Build for Linux")
#LIBS += -L/usr/lib/crypto++ -lcrypto++
#INCS += -I/usr/include/crypto++
#DEFINES += __SECURED=1
DEFINES += APP_OS=\"\\\"$$system(cat /etc/issue | cut -d\' \' -f1)\\\"\" DEFINES += APP_OS=\"\\\"$$system(cat /etc/issue | cut -d\' \' -f1)\\\"\"
DEFINES += APP_OS_VERSION=\"\\\"$$system(uname -r)\\\"\" DEFINES += APP_OS_VERSION=\"\\\"$$system(uname -r)\\\"\"
DEFINES += APP_ARCH=\"\\\"amd64\\\"\" DEFINES += APP_ARCH=\"\\\"amd64\\\"\"

View File

@@ -25,6 +25,9 @@
<property name="windowTitle"> <property name="windowTitle">
<string>About TaskNote</string> <string>About TaskNote</string>
</property> </property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0"> <item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">

View File

@@ -14,9 +14,6 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->noteList, &QListWidget::currentRowChanged, this, &MainWindow::selectionChanged); connect(ui->noteList, &QListWidget::currentRowChanged, this, &MainWindow::selectionChanged);
connect(ui->titleEdit, &QLineEdit::textChanged, this, &MainWindow::titleChanged); connect(ui->titleEdit, &QLineEdit::textChanged, this, &MainWindow::titleChanged);
connect(ui->contentEdit, &QPlainTextEdit::textChanged, this, &MainWindow::contentChanged); connect(ui->contentEdit, &QPlainTextEdit::textChanged, this, &MainWindow::contentChanged);
#ifdef __SECURED
connect(ui->actionEncrypt, &QAction::triggered, this, &MainWindow::encryptNote);
#endif
const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
ui->contentEdit->setFont(fixedFont); ui->contentEdit->setFont(fixedFont);
this->savemng = new SaveManager(); this->savemng = new SaveManager();
@@ -54,21 +51,19 @@ void MainWindow::selectionChanged(int i)
clearAndDisableFields(); clearAndDisableFields();
return; return;
} }
ui->actionRemove->setDisabled(false);
ui->contentEdit->blockSignals(true);
ui->titleEdit->blockSignals(true);
ui->titleEdit->setDisabled(false); ui->titleEdit->setDisabled(false);
ui->contentEdit->setDisabled(false); ui->contentEdit->setDisabled(false);
ui->actionRemove->setDisabled(false);
ui->titleEdit->setText(n->getTitle()); ui->titleEdit->setText(n->getTitle());
#ifdef __SECURED
if (n->isEncrypted())
{
ui->contentEdit->setPlainText(n->getEncryptedContent("azertyuiop"));
} else {
ui->contentEdit->setPlainText(n->getContent()); ui->contentEdit->setPlainText(n->getContent());
}
#else
ui->contentEdit->setPlainText(n->getContent());
#endif
ui->markdownViewer->setMarkdown(ui->contentEdit->toPlainText()); ui->markdownViewer->setMarkdown(ui->contentEdit->toPlainText());
ui->contentEdit->blockSignals(false);
ui->titleEdit->blockSignals(false);
} }
void MainWindow::removeSelected() void MainWindow::removeSelected()
@@ -113,18 +108,6 @@ void MainWindow::showAboutBox()
dialog.exec(); dialog.exec();
} }
#ifdef __SECURED
void MainWindow::encryptNote()
{
if (this->currentIndex > -1)
{
Note *n = this->savemng->getNoteByIndex(this->currentIndex);
n->encrypt("azertyuiop");
savemng->flushSave();
}
}
#endif
void MainWindow::contentChanged() void MainWindow::contentChanged()
{ {
timer->stop(); timer->stop();
@@ -149,6 +132,9 @@ void MainWindow::updateListView()
void MainWindow::clearAndDisableFields() void MainWindow::clearAndDisableFields()
{ {
ui->contentEdit->blockSignals(true);
ui->titleEdit->blockSignals(true);
this->currentIndex = -1; this->currentIndex = -1;
ui->actionRemove->setDisabled(true); ui->actionRemove->setDisabled(true);
ui->titleEdit->setDisabled(true); ui->titleEdit->setDisabled(true);
@@ -156,5 +142,8 @@ void MainWindow::clearAndDisableFields()
ui->titleEdit->clear(); ui->titleEdit->clear();
ui->contentEdit->clear(); ui->contentEdit->clear();
ui->markdownViewer->clear(); ui->markdownViewer->clear();
ui->contentEdit->blockSignals(false);
ui->titleEdit->blockSignals(false);
} }

View File

@@ -30,9 +30,6 @@ private slots:
void contentChanged(); void contentChanged();
void titleChanged(); void titleChanged();
void showAboutBox(); void showAboutBox();
#ifdef __SECURED
void encryptNote();
#endif
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;

View File

@@ -20,8 +20,8 @@
<string>TaskNote</string> <string>TaskNote</string>
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item row="0" column="0"> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QListWidget" name="noteList"> <widget class="QListWidget" name="noteList">
@@ -63,42 +63,53 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <widget class="QSplitter" name="splitter">
<item> <property name="sizePolicy">
<widget class="QLabel" name="label_3"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<property name="text"> <horstretch>0</horstretch>
<string>Markdown editor</string> <verstretch>0</verstretch>
</sizepolicy>
</property> </property>
</widget> <property name="orientation">
</item> <enum>Qt::Horizontal</enum>
<item> </property>
<widget class="QLabel" name="label_2"> <property name="childrenCollapsible">
<property name="text"> <bool>false</bool>
<string>Viewer</string>
</property> </property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPlainTextEdit" name="contentEdit"> <widget class="QPlainTextEdit" name="contentEdit">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<kerning>false</kerning>
</font>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
</widget> </widget>
</item>
<item>
<widget class="QTextEdit" name="markdownViewer"> <widget class="QTextEdit" name="markdownViewer">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="autoFormatting"> <property name="autoFormatting">
<set>QTextEdit::AutoAll</set> <set>QTextEdit::AutoAll</set>
</property> </property>
<property name="lineWrapMode"> <property name="lineWrapMode">
<enum>QTextEdit::WidgetWidth</enum> <enum>QTextEdit::NoWrap</enum>
</property> </property>
<property name="readOnly"> <property name="readOnly">
<bool>true</bool> <bool>true</bool>
@@ -110,8 +121,7 @@
<set>Qt::TextSelectableByMouse</set> <set>Qt::TextSelectableByMouse</set>
</property> </property>
</widget> </widget>
</item> </widget>
</layout>
</item> </item>
</layout> </layout>
</item> </item>
@@ -129,6 +139,9 @@
<height>96</height> <height>96</height>
</size> </size>
</property> </property>
<property name="contextMenuPolicy">
<enum>Qt::PreventContextMenu</enum>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>toolBar</string> <string>toolBar</string>
</property> </property>
@@ -138,6 +151,9 @@
<property name="toolButtonStyle"> <property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum> <enum>Qt::ToolButtonTextUnderIcon</enum>
</property> </property>
<property name="floatable">
<bool>false</bool>
</property>
<attribute name="toolBarArea"> <attribute name="toolBarArea">
<enum>TopToolBarArea</enum> <enum>TopToolBarArea</enum>
</attribute> </attribute>
@@ -149,10 +165,6 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionSave"/> <addaction name="actionSave"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionLock"/>
<addaction name="actionUnlock"/>
<addaction name="actionEncrypt"/>
<addaction name="separator"/>
<addaction name="actionAbout"/> <addaction name="actionAbout"/>
</widget> </widget>
<action name="actionAdd"> <action name="actionAdd">
@@ -197,42 +209,6 @@
<string>About</string> <string>About</string>
</property> </property>
</action> </action>
<action name="actionLock">
<property name="icon">
<iconset resource="../../icons.qrc">
<normaloff>:/icon/resources/outline_lock_black_48dp.png</normaloff>:/icon/resources/outline_lock_black_48dp.png</iconset>
</property>
<property name="text">
<string>Lock</string>
</property>
<property name="visible">
<bool>false</bool>
</property>
</action>
<action name="actionUnlock">
<property name="icon">
<iconset resource="../../icons.qrc">
<normaloff>:/icon/resources/outline_lock_open_black_48dp.png</normaloff>:/icon/resources/outline_lock_open_black_48dp.png</iconset>
</property>
<property name="text">
<string>Unlock</string>
</property>
<property name="visible">
<bool>false</bool>
</property>
</action>
<action name="actionEncrypt">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../../icons.qrc">
<normaloff>:/icon/resources/outline_shield_black_48dp.png</normaloff>:/icon/resources/outline_shield_black_48dp.png</iconset>
</property>
<property name="text">
<string>Encrypt</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="../../icons.qrc"/> <include location="../../icons.qrc"/>

View File

@@ -12,9 +12,6 @@ QJsonObject Note::toJson()
o["uuid"] = this->uuid; o["uuid"] = this->uuid;
o["title"] = this->title; o["title"] = this->title;
o["content"] = this->content; o["content"] = this->content;
#ifdef __SECURED
o["encrypted"] = this->encrypted;
#endif
return o; return o;
} }
@@ -46,43 +43,6 @@ QString Note::getContent()
} }
return ""; return "";
} }
#ifdef __SECURED
QString Note::getEncryptedContent(QString passwd)
{
if (this->encrypted)
{
using namespace CryptoPP;
std::string password = passwd.toStdString();
QString bytes = QByteArray::fromBase64(QByteArray::fromStdString(this->content.toStdString()));
std::string encoded = bytes.toStdString();
std::string iv = encoded.substr(0, TAG_SIZE);
std::string cipher = encoded.substr(TAG_SIZE + 1, encoded.length());
std::string recovered;
try {
GCM< AES >::Decryption d;
d.SetKeyWithIV((const unsigned char*)password.c_str(), sizeof(password.c_str()), (const unsigned char*)iv.c_str(), sizeof(iv.c_str()));
AuthenticatedDecryptionFilter df( d,
new StringSink(recovered),
AuthenticatedDecryptionFilter::DEFAULT_FLAGS, TAG_SIZE
);
StringSource ss2(cipher, true,
new Redirector(df)
);
return QString::fromStdString(recovered);
} catch (CryptoPP::Exception& e) {
std::cout << e.GetWhat() << "\n";
}
}
return "";
}
bool Note::isEncrypted()
{
return this->encrypted;
}
#endif
void Note::setTitle(QString value) void Note::setTitle(QString value)
{ {
this->title = value; this->title = value;
@@ -94,53 +54,3 @@ void Note::setContent(QString value)
this->content = value; this->content = value;
} }
} }
#ifdef __SECURED
// TODO encrypt avec le mot de passe
bool Note::setEncryptedContent(QString value, QString passwd)
{
if (this->encrypted) {
using namespace CryptoPP;
AutoSeededRandomPool prng;
std::string password = passwd.toStdString();
std::string pdata = value.toStdString();
std::string cipher, encoded;
SecByteBlock key(AES::MAX_KEYLENGTH + AES::BLOCKSIZE);
SecByteBlock iv(AES::BLOCKSIZE);
prng.GenerateBlock(iv, iv.size());
try
{
GCM<AES>::Encryption e;
e.SetKeyWithIV(key, sizeof(key), iv, sizeof(iv));
StringSource ss1(pdata, true,
new AuthenticatedEncryptionFilter(e,
new StringSink(cipher), false, TAG_SIZE
)
);
std::string s(reinterpret_cast< char const* >(iv.data())) ;
encoded = s + cipher;
auto bytes = QByteArray::fromStdString(encoded);
this->content = bytes.toBase64();
return true;
}
catch(CryptoPP::Exception& e)
{
std::cout << e.GetWhat() << "\n";
return false;
}
}
return false;
}
void Note::encrypt(QString password)
{
if (!this->encrypted && (password.length() >= 6)) {
this->encrypted = true;
if (!setEncryptedContent(this->content, password))
{
this->encrypted = false;
}
}
}
#endif

View File

@@ -11,18 +11,6 @@
#include <QUuid> #include <QUuid>
#include <QMessageBox> #include <QMessageBox>
#ifdef __SECURED
#include <crypto++/modes.h>
#include <crypto++/aes.h>
#include <crypto++/filters.h>
#include <crypto++/cryptlib.h>
#include <crypto++/sha.h>
#include <crypto++/hkdf.h>
#include <crypto++/osrng.h>
#include <crypto++/gcm.h>
#include <crypto++/rijndael.h>
#endif
class Note class Note
{ {
public: public:
@@ -35,18 +23,8 @@ public:
QString getTitle(); QString getTitle();
QString getContent(); QString getContent();
#ifdef __SECURED
QString getEncryptedContent(QString passwd);
bool isEncrypted();
#endif
void setTitle(QString value); void setTitle(QString value);
void setContent(QString value); void setContent(QString value);
#ifdef __SECURED
bool setEncryptedContent(QString value, QString passwd);
void encrypt(QString password);
#endif
private: private:
QString uuid; QString uuid;
QString title; QString title;