aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/widgets
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2021-12-02 21:35:16 +0000
committerSaturneric <[email protected]>2021-12-02 21:35:16 +0000
commit1e3f1d13a6fb1bfc8f24be83032df1e92350dbcc (patch)
tree58cabfa5c0065632b97823b6e6f068c04f1fa2e9 /src/ui/widgets
parentFix and Modified. (diff)
downloadGpgFrontend-1e3f1d13a6fb1bfc8f24be83032df1e92350dbcc.tar.gz
GpgFrontend-1e3f1d13a6fb1bfc8f24be83032df1e92350dbcc.zip
Fixed.
1. Fixed known issue in File Operations.
Diffstat (limited to 'src/ui/widgets')
-rw-r--r--src/ui/widgets/EditorPage.cpp74
-rw-r--r--src/ui/widgets/EditorPage.h10
-rw-r--r--src/ui/widgets/FilePage.cpp10
-rw-r--r--src/ui/widgets/SignersPicker.cpp7
-rw-r--r--src/ui/widgets/TextEdit.cpp3
5 files changed, 47 insertions, 57 deletions
diff --git a/src/ui/widgets/EditorPage.cpp b/src/ui/widgets/EditorPage.cpp
index 6fd72c20..eeedfaf5 100644
--- a/src/ui/widgets/EditorPage.cpp
+++ b/src/ui/widgets/EditorPage.cpp
@@ -27,6 +27,8 @@
#include <boost/filesystem.hpp>
#include <utility>
+#include "ui/function/FileReadThread.h"
+
namespace GpgFrontend::UI {
EditorPage::EditorPage(QString filePath, QWidget* parent)
@@ -106,51 +108,37 @@ void EditorPage::slotFormatGpgHeader() {
}
void EditorPage::readFile() {
- if (this->readThread != nullptr) {
- this->readThread->requestInterruption();
- this->readThread = nullptr;
- }
- LOG(INFO) << "EditorPage::readFile Started";
- this->readThread = QThread::create([&]() {
- LOG(INFO) << "EditorPage::readFile read_thread Started";
- boost::filesystem::path read_file_path(this->fullFilePath.toStdString());
- if (is_regular_file(read_file_path)) {
- LOG(INFO) << "EditorPage::readFile read_thread Read Open";
-
- auto fp = fopen(read_file_path.c_str(), "r");
- size_t read_size;
- qDebug() << "Thread Start Reading";
- // Event loop
- this->getTextPage()->setReadOnly(true);
- char buffer[8192];
- while ((read_size = fread(buffer, sizeof(char), sizeof buffer, fp)) > 0) {
- // Check isInterruptionRequested
- if (QThread::currentThread()->isInterruptionRequested()) {
- LOG(INFO)
- << "EditorPage::readFile ReadThread isInterruptionRequested ";
- fclose(fp);
- return;
- }
-
- LOG(INFO) << "EditorPage::readFile read_thread Read block size"
- << read_size;
- this->getTextPage()->insertPlainText(
- QString::fromLocal8Bit(buffer, read_size));
-
- QThread::msleep(32);
- }
- fclose(fp);
- this->getTextPage()->setReadOnly(false);
- LOG(INFO) << "Thread End Reading";
- }
+ LOG(INFO) << "Called";
+
+ auto text_page = this->getTextPage();
+ text_page->setReadOnly(true);
+ auto thread = new FileReadThread(this->fullFilePath.toStdString());
+
+ connect(thread, &FileReadThread::sendReadBlock, this,
+ &EditorPage::slotInsertText);
+
+ connect(thread, &FileReadThread::readDone, this, [=]() {
+ LOG(INFO) << "Thread read done";
+ text_page->document()->setModified(false);
+ text_page->setReadOnly(false);
});
- connect(this->readThread, SIGNAL(finished()), this->readThread,
- SLOT(deleteLater()));
- connect(this, &QWidget::destroyed, [&]() {
- LOG(INFO) << "QWidget::destroyed RequestInterruption for readThread";
- this->readThread->requestInterruption();
+
+ connect(thread, &FileReadThread::finished, this, [=]() {
+ LOG(INFO) << "Thread finished";
+ thread->deleteLater();
+ });
+
+ connect(this, &FileReadThread::destroyed, [=]() {
+ LOG(INFO) << "RequestInterruption for readThread";
+ thread->requestInterruption();
+ thread->deleteLater();
});
- this->readThread->start();
+
+ thread->start();
+}
+
+void EditorPage::slotInsertText(const QString& text) {
+ this->getTextPage()->insertPlainText(text);
}
} // namespace GpgFrontend::UI
diff --git a/src/ui/widgets/EditorPage.h b/src/ui/widgets/EditorPage.h
index 1e19a0de..1a19134c 100644
--- a/src/ui/widgets/EditorPage.h
+++ b/src/ui/widgets/EditorPage.h
@@ -30,11 +30,8 @@
QT_BEGIN_NAMESPACE
class QVBoxLayout;
-
class QHBoxLayout;
-
class QString;
-
class QLabel;
QT_END_NAMESPACE
@@ -58,7 +55,7 @@ class EditorPage : public QWidget {
/**
* @details Get the filepath of the currently activated tab.
*/
- const QString& getFilePath() const;
+ [[nodiscard]] const QString& getFilePath() const;
/**
* @details Set filepath of currently activated tab.
@@ -87,8 +84,6 @@ class EditorPage : public QWidget {
*/
void closeNoteByClass(const char* className);
- const QString uuid = QUuid::createUuid().toString();
-
void readFile();
private:
@@ -96,7 +91,6 @@ class EditorPage : public QWidget {
QVBoxLayout* mainLayout; /** The layout for the tab */
QString fullFilePath; /** The path to the file handled in the tab */
bool signMarked{}; /** true, if the signed header is marked, false if not */
- QThread* readThread = nullptr;
private slots:
@@ -104,6 +98,8 @@ class EditorPage : public QWidget {
* @details Format the gpg header in another font-style
*/
void slotFormatGpgHeader();
+
+ void slotInsertText(const QString& text);
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/widgets/FilePage.cpp b/src/ui/widgets/FilePage.cpp
index 4b88092b..bb026804 100644
--- a/src/ui/widgets/FilePage.cpp
+++ b/src/ui/widgets/FilePage.cpp
@@ -53,7 +53,7 @@ FilePage::FilePage(QWidget* parent) : QWidget(parent) {
connect(upLevelButton, SIGNAL(clicked(bool)), this, SLOT(slotUpLevel()));
QString buttonStyle =
- "QPushButton{border:none;background-color:rgba(255, 255, 255,100);}";
+ "QPushButton{border:none;background-color:rgba(255, 255, 255, 0);}";
auto upPixmap = QPixmap(":up.png");
upPixmap =
@@ -113,7 +113,7 @@ FilePage::FilePage(QWidget* parent) : QWidget(parent) {
void FilePage::fileTreeViewItemClicked(const QModelIndex& index) {
selectedPath = boost::filesystem::path(
dirModel->fileInfo(index).absoluteFilePath().toStdString());
- LOG(INFO) << "FilePage::fileTreeViewItemClicked selectedPath" << selectedPath;
+ LOG(INFO) << "selected path" << selectedPath;
}
void FilePage::slotUpLevel() {
@@ -129,7 +129,7 @@ void FilePage::slotUpLevel() {
pathEdit->setText(mPath.c_str());
slotGoPath();
}
- LOG(INFO) << "FilePage::slotUpLevel Current Root mPath" << mPath;
+ LOG(INFO) << "Current Root mPath" << mPath;
emit pathChanged(mPath.c_str());
}
}
@@ -144,7 +144,7 @@ void FilePage::fileTreeViewItemDoubleClicked(const QModelIndex& index) {
dirTreeView->setRootIndex(targetModelIndex);
pathEdit->setText(mPath.c_str());
}
- LOG(INFO) << "FilePage::fileTreeViewItemDoubleClicked Index mPath" << mPath;
+ LOG(INFO) << "Index mPath" << mPath;
emit pathChanged(mPath.c_str());
}
@@ -155,7 +155,7 @@ void FilePage::slotGoPath() {
auto fileInfo = QFileInfo(pathEdit->text());
if (fileInfo.isDir() && fileInfo.isReadable() && fileInfo.isExecutable()) {
mPath = boost::filesystem::path(fileInfo.filePath().toStdString());
- LOG(INFO) << "FilePage::slotGoPath Set Path" << mPath;
+ LOG(INFO) << "Set Path" << mPath;
dirTreeView->setRootIndex(dirModel->index(fileInfo.filePath()));
} else {
QMessageBox::critical(this, "Error",
diff --git a/src/ui/widgets/SignersPicker.cpp b/src/ui/widgets/SignersPicker.cpp
index 3131989b..3e4b3bb5 100644
--- a/src/ui/widgets/SignersPicker.cpp
+++ b/src/ui/widgets/SignersPicker.cpp
@@ -45,12 +45,17 @@ SignersPicker::SignersPicker(QWidget* parent) : QDialog(parent) {
mKeyList->slotRefresh();
auto* vbox2 = new QVBoxLayout();
- vbox2->addWidget(new QLabel("Select Signer(s): "));
+ vbox2->addWidget(new QLabel(QString(_("Select Signer(s)")) + ": "));
vbox2->addWidget(mKeyList);
+ vbox2->addWidget(new QLabel(
+ _("Selecting Nothing will eventually use default key to sign.")));
vbox2->addWidget(confirmButton);
vbox2->addStretch(0);
setLayout(vbox2);
+ this->setWindowFlags(Qt::Window | Qt::WindowTitleHint |
+ Qt::CustomizeWindowHint);
+
this->setModal(true);
this->setWindowTitle("Signers Picker");
this->setMinimumWidth(480);
diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp
index efc2abbf..528a4c88 100644
--- a/src/ui/widgets/TextEdit.cpp
+++ b/src/ui/widgets/TextEdit.cpp
@@ -74,7 +74,7 @@ void TextEdit::slotNewFileTab() const {
void TextEdit::slotOpenFile(QString& path) {
QFile file(path);
- LOG(INFO) << "TextEdit::slotOpenFile path" << path.toStdString();
+ LOG(INFO) << " path" << path.toStdString();
auto result = file.open(QIODevice::ReadOnly | QIODevice::Text);
if (result) {
auto* page = new EditorPage(path);
@@ -93,6 +93,7 @@ void TextEdit::slotOpenFile(QString& path) {
}
file.close();
+ LOG(INFO) << "done";
}
void TextEdit::slotOpen() {