aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt8
-rw-r--r--src/MainWindow.cpp340
-rw-r--r--src/gpg/GpgContext.cpp55
-rw-r--r--src/gpg/GpgFileOpera.cpp35
-rwxr-xr-xsrc/ui/QuitDialog.cpp2
-rw-r--r--src/ui/WaitingDialog.cpp19
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp327
-rw-r--r--src/ui/widgets/TextEdit.cpp856
8 files changed, 992 insertions, 650 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 97fae047..deeabadb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -121,11 +121,17 @@ IF (MINGW)
gpgfrontend-ui gpg
Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core
crypto ssl)
+elseif(APPLE)
+ message(STATUS "Link Application Static Library For macOS")
+ target_link_libraries(${AppName}
+ gpgfrontend-ui gpg
+ Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core
+ crypto ssl)
else()
message(STATUS "Link Application Static Library For UNIX")
target_link_libraries(${AppName}
gpgfrontend-ui gpg
Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core
- crypto ssl)
+ crypto ssl pthread)
endif()
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index a3d4f1e2..35890a47 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -26,173 +26,205 @@
MainWindow::MainWindow()
: appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", QSettings::IniFormat) {
-
- mCtx = new GpgME::GpgContext();
-
- /* get path were app was started */
- setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
- setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
-
- qDebug() << "Main Window" << this;
-
- edit = new TextEdit(this);
- setCentralWidget(edit);
-
- /* the list of Keys available*/
- mKeyList = new KeyList(mCtx,
- KeyListRow::SECRET_OR_PUBLIC_KEY,
- KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress |
- KeyListColumn::Usage | KeyListColumn::Validity,
- this);
- mKeyList->setFilter([](const GpgKey &key) -> bool {
- if (key.revoked || key.disabled || key.expired) return false;
- else return true;
- });
- mKeyList->slotRefresh();
-
- infoBoard = new InfoBoardWidget(this, mCtx, mKeyList);
-
- /* List of binary Attachments */
- attachmentDockCreated = false;
-
- /* Variable containing if restart is needed */
- this->slotSetRestartNeeded(false);
-
- keyMgmt = new KeyMgmt(mCtx, this);
- keyMgmt->hide();
- /* test attachmentdir for files alll 15s */
- auto *timer = new QTimer(this);
- connect(timer, SIGNAL(timeout()), this, SLOT(slotCheckAttachmentFolder()));
- timer->start(5000);
-
- createActions();
- createMenus();
- createToolBars();
- createStatusBar();
- createDockWindows();
-
- connect(edit->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotDisableTabActions(int)));
-
- mKeyList->addMenuAction(appendSelectedKeysAct);
- mKeyList->addMenuAction(copyMailAddressToClipboardAct);
- mKeyList->addMenuAction(showKeyDetailsAct);
- mKeyList->addMenuAction(refreshKeysFromKeyserverAct);
- mKeyList->addMenuAction(uploadKeyToServerAct);
-
- restoreSettings();
-
- // open filename if provided as first command line parameter
- QStringList args = qApp->arguments();
- if (args.size() > 1) {
- if (!args[1].startsWith("-")) {
- if (QFile::exists(args[1]))
- edit->loadFile(args[1]);
- }
- }
- edit->curTextPage()->setFocus();
- this->setMinimumSize(1200, 700);
- this->setWindowTitle(qApp->applicationName());
- this->show();
-
- // Show wizard, if the don't show wizard message box wasn't checked
- // and keylist doesn't contain a private key
- qDebug() << "wizard/showWizard" << settings.value("wizard/showWizard", true).toBool() ;
- qDebug() << "wizard/nextPage" << settings.value("wizard/nextPage").isNull() ;
- if (settings.value("wizard/showWizard", true).toBool() || !settings.value("wizard/nextPage").isNull()) {
- slotStartWizard();
+ settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
+ QSettings::IniFormat) {
+
+ auto waitingDialog = new WaitingDialog("Loading", this);
+
+ auto ctx_thread = QThread::create([&]() { mCtx = new GpgME::GpgContext(); });
+
+ ctx_thread->start();
+
+ while (ctx_thread->isRunning())
+ QApplication::processEvents();
+
+ waitingDialog->close();
+
+
+ if (!mCtx->isGood()) {
+ QMessageBox::critical(
+ nullptr, tr("ENV Loading Failed"),
+ tr("Gnupg is not installed correctly, please follow the ReadME "
+ "instructions to install gnupg and then open GPGFrontend."));
+ QCoreApplication::quit();
+ exit(0);
+ }
+
+ /* get path were app was started */
+ setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
+ setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
+
+ qDebug() << "Main Window" << this;
+
+ edit = new TextEdit(this);
+ setCentralWidget(edit);
+
+ /* the list of Keys available*/
+ mKeyList = new KeyList(mCtx, KeyListRow::SECRET_OR_PUBLIC_KEY,
+ KeyListColumn::TYPE | KeyListColumn::NAME |
+ KeyListColumn::EmailAddress |
+ KeyListColumn::Usage | KeyListColumn::Validity,
+ this);
+ mKeyList->setFilter([](const GpgKey &key) -> bool {
+ if (key.revoked || key.disabled || key.expired)
+ return false;
+ else
+ return true;
+ });
+ mKeyList->slotRefresh();
+
+ infoBoard = new InfoBoardWidget(this, mCtx, mKeyList);
+
+ /* List of binary Attachments */
+ attachmentDockCreated = false;
+
+ /* Variable containing if restart is needed */
+ this->slotSetRestartNeeded(false);
+
+ keyMgmt = new KeyMgmt(mCtx, this);
+ keyMgmt->hide();
+ /* test attachmentdir for files alll 15s */
+ auto *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(slotCheckAttachmentFolder()));
+ timer->start(5000);
+
+ createActions();
+ createMenus();
+ createToolBars();
+ createStatusBar();
+ createDockWindows();
+
+ connect(edit->tabWidget, SIGNAL(currentChanged(int)), this,
+ SLOT(slotDisableTabActions(int)));
+
+ mKeyList->addMenuAction(appendSelectedKeysAct);
+ mKeyList->addMenuAction(copyMailAddressToClipboardAct);
+ mKeyList->addMenuAction(showKeyDetailsAct);
+ mKeyList->addMenuAction(refreshKeysFromKeyserverAct);
+ mKeyList->addMenuAction(uploadKeyToServerAct);
+
+ restoreSettings();
+
+ // open filename if provided as first command line parameter
+ QStringList args = qApp->arguments();
+ if (args.size() > 1) {
+ if (!args[1].startsWith("-")) {
+ if (QFile::exists(args[1]))
+ edit->loadFile(args[1]);
}
+ }
+ edit->curTextPage()->setFocus();
+ this->setMinimumSize(1200, 700);
+ this->setWindowTitle(qApp->applicationName());
+ this->show();
+
+ // Show wizard, if the don't show wizard message box wasn't checked
+ // and keylist doesn't contain a private key
+ qDebug() << "wizard/showWizard"
+ << settings.value("wizard/showWizard", true).toBool();
+ qDebug() << "wizard/nextPage" << settings.value("wizard/nextPage").isNull();
+ if (settings.value("wizard/showWizard", true).toBool() ||
+ !settings.value("wizard/nextPage").isNull()) {
+ slotStartWizard();
+ }
+
}
void MainWindow::restoreSettings() {
- // state sets pos & size of dock-widgets
- this->restoreState(settings.value("window/windowState").toByteArray());
-
- // Restore window size & location
- if (settings.value("window/windowSave").toBool()) {
- QPoint pos = settings.value("window/pos", QPoint(100, 100)).toPoint();
- QSize size = settings.value("window/size", QSize(800, 450)).toSize();
- this->resize(size);
- this->move(pos);
- } else {
- this->resize(QSize(800, 450));
- this->move(QPoint(100, 100));
- }
-
- // Iconsize
- QSize iconSize = settings.value("toolbar/iconsize", QSize(24, 24)).toSize();
- this->setIconSize(iconSize);
-
- importButton->setIconSize(iconSize);
- fileEncButton->setIconSize(iconSize);
- // set list of keyserver if not defined
- QStringList *keyServerDefaultList;
- keyServerDefaultList = new QStringList("http://keys.gnupg.net");
- keyServerDefaultList->append("https://keyserver.ubuntu.com");
- keyServerDefaultList->append("http://pool.sks-keyservers.net");
-
- QStringList keyServerList = settings.value("keyserver/keyServerList", *keyServerDefaultList).toStringList();
- settings.setValue("keyserver/keyServerList", keyServerList);
-
- // set default keyserver, if it's not set
- QString defaultKeyServer = settings.value("keyserver/defaultKeyServer", QString("https://keyserver.ubuntu.com")).toString();
- settings.setValue("keyserver/defaultKeyServer", defaultKeyServer);
-
- // Iconstyle
- Qt::ToolButtonStyle buttonStyle = static_cast<Qt::ToolButtonStyle>(settings.value("toolbar/iconstyle",
- Qt::ToolButtonTextUnderIcon).toUInt());
- this->setToolButtonStyle(buttonStyle);
- importButton->setToolButtonStyle(buttonStyle);
- fileEncButton->setToolButtonStyle(buttonStyle);
-
- // Checked Keys
- if (settings.value("keys/saveKeyChecked").toBool()) {
- QStringList keyIds = settings.value("keys/savedCheckedKeyList").toStringList();
- mKeyList->setChecked(&keyIds);
- }
+ // state sets pos & size of dock-widgets
+ this->restoreState(settings.value("window/windowState").toByteArray());
+
+ // Restore window size & location
+ if (settings.value("window/windowSave").toBool()) {
+ QPoint pos = settings.value("window/pos", QPoint(100, 100)).toPoint();
+ QSize size = settings.value("window/size", QSize(800, 450)).toSize();
+ this->resize(size);
+ this->move(pos);
+ } else {
+ this->resize(QSize(800, 450));
+ this->move(QPoint(100, 100));
+ }
+
+ // Iconsize
+ QSize iconSize = settings.value("toolbar/iconsize", QSize(24, 24)).toSize();
+ this->setIconSize(iconSize);
+
+ importButton->setIconSize(iconSize);
+ fileEncButton->setIconSize(iconSize);
+ // set list of keyserver if not defined
+ QStringList *keyServerDefaultList;
+ keyServerDefaultList = new QStringList("http://keys.gnupg.net");
+ keyServerDefaultList->append("https://keyserver.ubuntu.com");
+ keyServerDefaultList->append("http://pool.sks-keyservers.net");
+
+ QStringList keyServerList =
+ settings.value("keyserver/keyServerList", *keyServerDefaultList)
+ .toStringList();
+ settings.setValue("keyserver/keyServerList", keyServerList);
+
+ // set default keyserver, if it's not set
+ QString defaultKeyServer = settings
+ .value("keyserver/defaultKeyServer",
+ QString("https://keyserver.ubuntu.com"))
+ .toString();
+ settings.setValue("keyserver/defaultKeyServer", defaultKeyServer);
+
+ // Iconstyle
+ Qt::ToolButtonStyle buttonStyle = static_cast<Qt::ToolButtonStyle>(
+ settings.value("toolbar/iconstyle", Qt::ToolButtonTextUnderIcon)
+ .toUInt());
+ this->setToolButtonStyle(buttonStyle);
+ importButton->setToolButtonStyle(buttonStyle);
+ fileEncButton->setToolButtonStyle(buttonStyle);
+
+ // Checked Keys
+ if (settings.value("keys/saveKeyChecked").toBool()) {
+ QStringList keyIds =
+ settings.value("keys/savedCheckedKeyList").toStringList();
+ mKeyList->setChecked(&keyIds);
+ }
}
void MainWindow::saveSettings() {
- // window position and size
- settings.setValue("window/windowState", saveState());
- settings.setValue("window/pos", pos());
- settings.setValue("window/size", size());
-
- // keyid-list of private checked keys
- if (settings.value("keys/saveKeyChecked").toBool()) {
- QStringList *keyIds = mKeyList->getChecked();
- if (!keyIds->isEmpty()) {
- settings.setValue("keys/savedCheckedKeyList", *keyIds);
- } else {
- settings.setValue("keys/savedCheckedKeyList", "");
- }
+ // window position and size
+ settings.setValue("window/windowState", saveState());
+ settings.setValue("window/pos", pos());
+ settings.setValue("window/size", size());
+
+ // keyid-list of private checked keys
+ if (settings.value("keys/saveKeyChecked").toBool()) {
+ QStringList *keyIds = mKeyList->getChecked();
+ if (!keyIds->isEmpty()) {
+ settings.setValue("keys/savedCheckedKeyList", *keyIds);
} else {
- settings.remove("keys/savedCheckedKeyList");
+ settings.setValue("keys/savedCheckedKeyList", "");
}
+ } else {
+ settings.remove("keys/savedCheckedKeyList");
+ }
}
void MainWindow::closeAttachmentDock() {
- if (!attachmentDockCreated) {
- return;
- }
- attachmentDock->close();
- attachmentDock->deleteLater();
- attachmentDockCreated = false;
+ if (!attachmentDockCreated) {
+ return;
+ }
+ attachmentDock->close();
+ attachmentDock->deleteLater();
+ attachmentDockCreated = false;
}
void MainWindow::closeEvent(QCloseEvent *event) {
- /*
- * ask to save changes, if there are
- * modified documents in any tab
- */
- if (edit->maybeSaveAnyTab()) {
- saveSettings();
- event->accept();
- } else {
- event->ignore();
- }
-
- // clear password from memory
- mCtx->clearPasswordCache();
+ /*
+ * ask to save changes, if there are
+ * modified documents in any tab
+ */
+ if (edit->maybeSaveAnyTab()) {
+ saveSettings();
+ event->accept();
+ } else {
+ event->ignore();
+ }
+
+ // clear password from memory
+ mCtx->clearPasswordCache();
}
-
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp
index 67bae907..028653b7 100644
--- a/src/gpg/GpgContext.cpp
+++ b/src/gpg/GpgContext.cpp
@@ -87,11 +87,10 @@ namespace GpgME {
check_pass = true;
if (!check_pass) {
- QMessageBox::critical(nullptr, tr("ENV Loading Failed"),
- tr("Gnupg is not installed correctly, please follow the ReadME instructions to install gnupg and then open GPGFrontend."));
- QCoreApplication::quit();
- exit(0);
- }
+ good = false;
+ return;
+ } else good = true;
+
/** Setting the output type must be done at the beginning */
/** think this means ascii-armor --> ? */
@@ -122,6 +121,10 @@ namespace GpgME {
mCtx = nullptr;
}
+ bool GpgContext::isGood() const {
+ return good;
+ }
+
/** Import Key from QByteArray
*
*/
@@ -656,16 +659,16 @@ namespace GpgME {
bool GpgContext::exportSecretKey(const GpgKey &key, QByteArray *outBuffer) {
qDebug() << "Export Secret Key" << key.id;
gpgme_key_t target_key[2] = {
- key.key_refer,
- nullptr
+ key.key_refer,
+ nullptr
};
gpgme_data_t dataOut;
gpgme_data_new(&dataOut);
// export private key to outBuffer
- gpgme_error_t error = gpgme_op_export_keys(mCtx, target_key,GPGME_EXPORT_MODE_SECRET, dataOut);
+ gpgme_error_t error = gpgme_op_export_keys(mCtx, target_key, GPGME_EXPORT_MODE_SECRET, dataOut);
- if(gpgme_err_code(error) != GPG_ERR_NO_ERROR) {
+ if (gpgme_err_code(error) != GPG_ERR_NO_ERROR) {
checkErr(error);
gpgme_data_release(dataOut);
return false;
@@ -731,26 +734,6 @@ namespace GpgME {
return gpgmeError;
}
- /***
- * return type should contain:
- * -> list of sigs
- * -> valid
- * -> decrypted message
- */
- //void GpgContext::decryptVerify(QByteArray in) {
-
- /* gpgme_error_t err;
- gpgme_data_t in, out;
-
- gpgme_decrypt_result_t decrypt_result;
- gpgme_verify_result_t verify_result;
-
- err = gpgme_op_decrypt_verify (mCtx, in, out);
- decrypt_result = gpgme_op_decrypt_result (mCtx);
-
- verify_result = gpgme_op_verify_result (mCtx);
- */
- //}
gpg_error_t
GpgContext::sign(const QVector<GpgKey> &keys, const QByteArray &inBuffer, QByteArray *outBuffer, bool detached,
gpgme_sign_result_t *result) {
@@ -959,8 +942,10 @@ namespace GpgME {
void GpgContext::setSigners(const QVector<GpgKey> &keys) {
gpgme_signers_clear(mCtx);
for (const auto &key : keys) {
- auto gpgmeError = gpgme_signers_add(mCtx, key.key_refer);
- checkErr(gpgmeError);
+ if (checkIfKeyCanSign(key)) {
+ auto gpgmeError = gpgme_signers_add(mCtx, key.key_refer);
+ checkErr(gpgmeError);
+ }
}
if (keys.length() != gpgme_signers_count(mCtx)) {
qDebug() << "No All Keys Added";
@@ -1174,6 +1159,10 @@ namespace GpgME {
}
}
}
+
+ if (gpgme_err_code(err) != GPG_ERR_NO_ERROR)
+ checkErr(err);
+
if (dataIn) {
gpgme_data_release(dataIn);
}
@@ -1231,11 +1220,11 @@ namespace GpgME {
return false;
}
- for (const auto& key : keys) {
+ for (const auto &key : keys) {
err = gpgme_data_new(&dataOut);
checkErr(err);
- err = gpgme_op_export(mCtx,key.id.toUtf8().constData(), 0, dataOut);
+ err = gpgme_op_export(mCtx, key.id.toUtf8().constData(), 0, dataOut);
checkErr(err);
read_bytes = gpgme_data_seek(dataOut, 0, SEEK_END);
diff --git a/src/gpg/GpgFileOpera.cpp b/src/gpg/GpgFileOpera.cpp
index f7db9d44..9395bd17 100644
--- a/src/gpg/GpgFileOpera.cpp
+++ b/src/gpg/GpgFileOpera.cpp
@@ -132,6 +132,8 @@ gpgme_error_t GpgFileOpera::signFile(GpgME::GpgContext *ctx, QVector<GpgKey> &ke
gpgme_error_t GpgFileOpera::verifyFile(GpgME::GpgContext *ctx, const QString &mPath, gpgme_verify_result_t *result) {
+ qDebug() << "Verify File Path" << mPath;
+
QFileInfo fileInfo(mPath);
if (!fileInfo.isFile() || !fileInfo.isReadable())
@@ -142,29 +144,33 @@ gpgme_error_t GpgFileOpera::verifyFile(GpgME::GpgContext *ctx, const QString &mP
if (!infile.open(QIODevice::ReadOnly))
throw std::runtime_error("cannot open file");
-
QByteArray inBuffer = infile.readAll();
- QFile signFile;
- signFile.setFileName(mPath + ".sig");
- if (!signFile.open(QIODevice::ReadOnly)) {
- throw std::runtime_error("cannot open file");
+ if(fileInfo.suffix() == "gpg") {
+ auto error = ctx->verify(&inBuffer, nullptr, result);
+ return error;
}
+ else {
+ QFile signFile;
+ signFile.setFileName(mPath + ".sig");
+ if (!signFile.open(QIODevice::ReadOnly)) {
+ throw std::runtime_error("cannot open file");
+ }
+ auto signBuffer = signFile.readAll();
+ infile.close();
-
- auto signBuffer = signFile.readAll();
- infile.close();
-
-
- auto error = ctx->verify(&inBuffer, &signBuffer, result);
-
- return error;
+ auto error = ctx->verify(&inBuffer, &signBuffer, result);
+ return error;
+ }
}
gpg_error_t GpgFileOpera::encryptSignFile(GpgME::GpgContext *ctx, QVector<GpgKey> &keys, const QString &mPath,
gpgme_encrypt_result_t *encr_res,
gpgme_sign_result_t *sign_res) {
+
+ qDebug() << "Encrypt Sign File Path" << mPath;
+
QFileInfo fileInfo(mPath);
if (!fileInfo.isFile() || !fileInfo.isReadable())
@@ -198,6 +204,9 @@ gpg_error_t GpgFileOpera::encryptSignFile(GpgME::GpgContext *ctx, QVector<GpgKey
gpg_error_t GpgFileOpera::decryptVerifyFile(GpgME::GpgContext *ctx, const QString &mPath, gpgme_decrypt_result_t *decr_res,
gpgme_verify_result_t *verify_res) {
+
+ qDebug() << "Decrypt Verify File Path" << mPath;
+
QFileInfo fileInfo(mPath);
if (!fileInfo.isFile() || !fileInfo.isReadable())
diff --git a/src/ui/QuitDialog.cpp b/src/ui/QuitDialog.cpp
index 5ebedc20..783a8a61 100755
--- a/src/ui/QuitDialog.cpp
+++ b/src/ui/QuitDialog.cpp
@@ -74,7 +74,7 @@ QuitDialog::QuitDialog(QWidget *parent, const QHash<int, QString>& unsavedDocs)
auto *warn_icon = new QLabel();
warn_icon->setPixmap(pixmap);
auto *warn_label = new QLabel(
- tr("<h3>%1 files contain unsaved information.<br/>Save the changes before closing?</h3>").arg(row));
+ tr("%1 files contain unsaved information.<br/>Save the changes before closing?").arg(row));
auto *warnBoxLayout = new QHBoxLayout();
warnBoxLayout->addWidget(warn_icon);
warnBoxLayout->addWidget(warn_label);
diff --git a/src/ui/WaitingDialog.cpp b/src/ui/WaitingDialog.cpp
new file mode 100644
index 00000000..bc21a17d
--- /dev/null
+++ b/src/ui/WaitingDialog.cpp
@@ -0,0 +1,19 @@
+#include "ui/WaitingDialog.h"
+
+WaitingDialog::WaitingDialog(const QString &title, QWidget *parent) : QDialog(parent) {
+ auto *pb = new QProgressBar();
+ pb->setRange(0, 0);
+ pb->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+
+ auto *layout = new QVBoxLayout();
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(0);
+ layout->addWidget(pb);
+ this->setLayout(layout);
+
+ this->setModal(true);
+ this->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
+ this->setWindowTitle(title);
+ this->setFixedSize(240, 42);
+ this->show();
+}
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index f820a4e6..21d0af0d 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -52,7 +52,22 @@ void MainWindow::slotEncrypt() {
auto *tmp = new QByteArray();
gpgme_encrypt_result_t result = nullptr;
- auto error = mCtx->encrypt(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, &result);
+
+ gpgme_error_t error;
+
+ auto thread = QThread::create([&]() {
+ error = mCtx->encrypt(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, &result);
+ });
+
+ thread->start();
+
+ auto *dialog = new WaitingDialog(tr("Encrypting"), this);
+
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+
+ dialog->close();
auto resultAnalyse = new EncryptResultAnalyse(error, result);
auto &reportText = resultAnalyse->getResultReport();
@@ -103,7 +118,18 @@ void MainWindow::slotSign() {
gpgme_sign_result_t result = nullptr;
- auto error = mCtx->sign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, false, &result);
+ gpgme_error_t error;
+ auto thread = QThread::create([&]() {
+ error = mCtx->sign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, false, &result);
+ });
+ thread->start();
+
+ auto *dialog = new WaitingDialog(tr("Signing"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+ dialog->close();
+
infoBoard->associateTextEdit(edit->curTextPage());
edit->slotFillTextEditWithText(QString::fromUtf8(*tmp));
@@ -133,8 +159,21 @@ void MainWindow::slotDecrypt() {
GpgME::GpgContext::preventNoDataErr(&text);
gpgme_decrypt_result_t result = nullptr;
- // try decrypt, if fail do nothing, especially don't replace text
- auto error = mCtx->decrypt(text, decrypted, &result);
+
+ gpgme_error_t error;
+ auto thread = QThread::create([&]() {
+ // try decrypt, if fail do nothing, especially don't replace text
+ error = mCtx->decrypt(text, decrypted, &result);
+ });
+ thread->start();
+
+ auto *dialog = new WaitingDialog(tr("Decrypting"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+
+ dialog->close();
+
infoBoard->associateTextEdit(edit->curTextPage());
if (gpgme_err_code(error) == GPG_ERR_NO_ERROR)
@@ -181,7 +220,17 @@ void MainWindow::slotVerify() {
gpgme_verify_result_t result;
- auto error = mCtx->verify(&text, nullptr, &result);
+ gpgme_error_t error;
+ auto thread = QThread::create([&]() {
+ error = mCtx->verify(&text, nullptr, &result);
+ });
+ thread->start();
+
+ auto *dialog = new WaitingDialog(tr("Verifying"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+ dialog->close();
auto resultAnalyse = new VerifyResultAnalyse(mCtx, error, result);
infoBoard->associateTextEdit(edit->curTextPage());
@@ -221,24 +270,61 @@ void MainWindow::slotEncryptSign() {
return;
}
+ bool can_sign = false, can_encr = false;
+
for (const auto &key : keys) {
- if (!GpgME::GpgContext::checkIfKeyCanSign(key) || !GpgME::GpgContext::checkIfKeyCanEncr(key)) {
- QMessageBox::information(nullptr,
- tr("Invalid Operation"),
- tr("The selected key cannot be used for signing and encryption at the same time.<br/>")
- + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid);
+ bool key_can_sign = GpgME::GpgContext::checkIfKeyCanSign(key);
+ bool key_can_encr = GpgME::GpgContext::checkIfKeyCanEncr(key);
+
+ if (!key_can_sign && !key_can_encr) {
+ QMessageBox::critical(nullptr,
+ tr("Invalid KeyPair"),
+ tr("The selected keypair cannot be used for signing and encryption at the same time.<br/>")
+ + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid);
return;
}
+
+ if (key_can_sign) can_sign = true;
+ if (key_can_encr) can_encr = true;
+ }
+
+ if (!can_encr) {
+ QMessageBox::critical(nullptr,
+ tr("Incomplete Operation"),
+ tr("None of the selected key pairs can provide the encryption function."));
+ return;
+ }
+
+ if (!can_sign) {
+ QMessageBox::warning(nullptr,
+ tr("Incomplete Operation"),
+ tr("None of the selected key pairs can provide the signature function."));
}
auto *tmp = new QByteArray();
gpgme_encrypt_result_t encr_result = nullptr;
gpgme_sign_result_t sign_result = nullptr;
- auto error = mCtx->encryptSign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, &encr_result,
- &sign_result);
- auto *tmp2 = new QString(*tmp);
- edit->slotFillTextEditWithText(*tmp2);
+ gpgme_decrypt_result_t result = nullptr;
+
+ gpgme_error_t error;
+ auto thread = QThread::create([&]() {
+ error = mCtx->encryptSign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, &encr_result,
+ &sign_result);
+ });
+ thread->start();
+
+ auto *dialog = new WaitingDialog(tr("Encrypting and Signing"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+
+ dialog->close();
+
+ if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) {
+ auto *tmp2 = new QString(*tmp);
+ edit->slotFillTextEditWithText(*tmp2);
+ }
auto resultAnalyseEncr = new EncryptResultAnalyse(error, encr_result);
auto resultAnalyseSign = new SignResultAnalyse(error, sign_result);
@@ -273,8 +359,20 @@ void MainWindow::slotDecryptVerify() {
gpgme_decrypt_result_t d_result = nullptr;
gpgme_verify_result_t v_result = nullptr;
- // try decrypt, if fail do nothing, especially don't replace text
- auto error = mCtx->decryptVerify(text, decrypted, &d_result, &v_result);
+
+ gpgme_error_t error;
+ auto thread = QThread::create([&]() {
+ error = mCtx->decryptVerify(text, decrypted, &d_result, &v_result);
+ });
+ thread->start();
+
+ WaitingDialog *dialog = new WaitingDialog(tr("Decrypting and Verifying"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+
+ dialog->close();
+
infoBoard->associateTextEdit(edit->curTextPage());
if (gpgme_err_code(error) == GPG_ERR_NO_ERROR)
@@ -407,10 +505,26 @@ void MainWindow::slotFileEncrypt() {
}
}
- try {
- gpgme_encrypt_result_t result;
- auto error = GpgFileOpera::encryptFile(mCtx, keys, path, &result);
+ gpgme_encrypt_result_t result;
+
+ gpgme_error_t error;
+ bool if_error = false;
+ auto thread = QThread::create([&]() {
+ try {
+ error = GpgFileOpera::encryptFile(mCtx, keys, path, &result);
+ } catch (const std::runtime_error &e) {
+ if_error = true;
+ }
+ });
+ thread->start();
+
+ auto *dialog = new WaitingDialog(tr("Encrypting"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+ dialog->close();
+ if(!if_error) {
auto resultAnalyse = new EncryptResultAnalyse(error, result);
auto &reportText = resultAnalyse->getResultReport();
infoBoard->associateTabWidget(edit->tabWidget);
@@ -426,11 +540,10 @@ void MainWindow::slotFileEncrypt() {
delete resultAnalyse;
fileTreeView->update();
-
- } catch (std::runtime_error &e) {
+ } else {
QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation."));
+ return;
}
-
}
void MainWindow::slotFileDecrypt() {
@@ -472,10 +585,27 @@ void MainWindow::slotFileDecrypt() {
return;
}
- try {
- gpgme_decrypt_result_t result;
- auto error = GpgFileOpera::decryptFile(mCtx, path, &result);
+ gpgme_decrypt_result_t result;
+ gpgme_error_t error;
+ bool if_error = false;
+
+ auto thread = QThread::create([&]() {
+ try {
+ error = GpgFileOpera::decryptFile(mCtx, path, &result);
+ } catch (const std::runtime_error &e) {
+ if_error = true;
+ }
+ });
+ thread->start();
+ auto *dialog = new WaitingDialog("Decrypting", this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+
+ dialog->close();
+
+ if(!if_error) {
auto resultAnalyse = new DecryptResultAnalyse(mCtx, error, result);
auto &reportText = resultAnalyse->getResultReport();
infoBoard->associateTabWidget(edit->tabWidget);
@@ -491,7 +621,7 @@ void MainWindow::slotFileDecrypt() {
delete resultAnalyse;
fileTreeView->update();
- } catch (std::runtime_error &e) {
+ } else {
QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation."));
return;
}
@@ -550,9 +680,27 @@ void MainWindow::slotFileSign() {
}
}
- try {
- gpgme_sign_result_t result;
- auto error = GpgFileOpera::signFile(mCtx, keys, path, &result);
+ gpgme_sign_result_t result;
+ gpgme_error_t error;
+ bool if_error = false;
+
+ auto thread = QThread::create([&]() {
+ try {
+ error = GpgFileOpera::signFile(mCtx, keys, path, &result);
+ } catch (const std::runtime_error &e) {
+ if_error = true;
+ }
+ });
+ thread->start();
+
+ auto *dialog = new WaitingDialog(tr("Signing"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+
+ dialog->close();
+
+ if(!if_error) {
auto resultAnalyse = new SignResultAnalyse(error, result);
auto &reportText = resultAnalyse->getResultReport();
@@ -570,8 +718,9 @@ void MainWindow::slotFileSign() {
fileTreeView->update();
- } catch (std::runtime_error &e) {
+ } else {
QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation."));
+ return;
}
fileTreeView->update();
@@ -587,7 +736,10 @@ void MainWindow::slotFileVerify() {
QString signFilePath, dataFilePath;
- if (fileInfo.suffix() == "sig" || fileInfo.suffix() == "gpg") {
+ if (fileInfo.suffix() == "gpg") {
+ dataFilePath = path;
+ signFilePath = path;
+ } else if (fileInfo.suffix() == "sig") {
int pos = path.lastIndexOf(QChar('.'));
dataFilePath = path.left(pos);
signFilePath = path;
@@ -612,10 +764,26 @@ void MainWindow::slotFileVerify() {
return;
}
- try {
- gpgme_verify_result_t result;
- auto error = GpgFileOpera::verifyFile(mCtx, dataFilePath, &result);
+ gpgme_verify_result_t result;
+
+ gpgme_error_t error;
+ bool if_error = false;
+ auto thread = QThread::create([&]() {
+ try {
+ error = GpgFileOpera::verifyFile(mCtx, dataFilePath, &result);
+ } catch (const std::runtime_error &e) {
+ if_error = true;
+ }
+ });
+ thread->start();
+
+ auto *dialog = new WaitingDialog(tr("Verifying"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+ dialog->close();
+ if (!if_error) {
auto resultAnalyse = new VerifyResultAnalyse(mCtx, error, result);
auto &reportText = resultAnalyse->getResultReport();
infoBoard->associateTabWidget(edit->tabWidget);
@@ -638,7 +806,7 @@ void MainWindow::slotFileVerify() {
delete resultAnalyse;
fileTreeView->update();
- } catch (std::runtime_error &e) {
+ } else {
QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation."));
return;
}
@@ -663,7 +831,7 @@ void MainWindow::slotFileEncryptSign() {
QMessageBox::critical(this, tr("Error"), tr("No permission to create file."));
return;
}
- if (QFile::exists(path + ".asc")) {
+ if (QFile::exists(path + ".gpg")) {
auto ret = QMessageBox::warning(this,
tr("Warning"),
tr("The target file already exists, do you need to overwrite it?"),
@@ -682,23 +850,59 @@ void MainWindow::slotFileEncryptSign() {
return;
}
+ bool can_sign = false, can_encr = false;
+
for (const auto &key : keys) {
- if (!GpgME::GpgContext::checkIfKeyCanEncr(key)) {
- QMessageBox::information(this,
- tr("Invalid Operation"),
- tr("The selected key contains a key that does not actually have a encrypt usage.<br/>")
- + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid);
+ bool key_can_sign = GpgME::GpgContext::checkIfKeyCanSign(key);
+ bool key_can_encr = GpgME::GpgContext::checkIfKeyCanEncr(key);
+
+ if (!key_can_sign && !key_can_encr) {
+ QMessageBox::critical(nullptr,
+ tr("Invalid KeyPair"),
+ tr("The selected keypair cannot be used for signing and encryption at the same time.<br/>")
+ + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid);
return;
-
}
+
+ if (key_can_sign) can_sign = true;
+ if (key_can_encr) can_encr = true;
}
- try {
+ if (!can_encr) {
+ QMessageBox::critical(nullptr,
+ tr("Incomplete Operation"),
+ tr("None of the selected key pairs can provide the encryption function."));
+ return;
+ }
- gpgme_encrypt_result_t encr_result = nullptr;
- gpgme_sign_result_t sign_result = nullptr;
+ if (!can_sign) {
+ QMessageBox::warning(nullptr,
+ tr("Incomplete Operation"),
+ tr("None of the selected key pairs can provide the signature function."));
+ }
+
+ gpgme_encrypt_result_t encr_result = nullptr;
+ gpgme_sign_result_t sign_result = nullptr;
- auto error = GpgFileOpera::encryptSignFile(mCtx, keys, path, &encr_result, &sign_result);
+ gpgme_error_t error;
+ bool if_error = false;
+
+ auto thread = QThread::create([&]() {
+ try {
+ error = GpgFileOpera::encryptSignFile(mCtx, keys, path, &encr_result, &sign_result);
+ } catch (const std::runtime_error &e) {
+ if_error = true;
+ }
+ });
+ thread->start();
+
+ WaitingDialog *dialog = new WaitingDialog(tr("Encrypting and Signing"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+ dialog->close();
+
+ if(!if_error) {
auto resultAnalyseEncr = new EncryptResultAnalyse(error, encr_result);
auto resultAnalyseSign = new SignResultAnalyse(error, sign_result);
@@ -719,8 +923,9 @@ void MainWindow::slotFileEncryptSign() {
fileTreeView->update();
- } catch (std::runtime_error &e) {
+ } else {
QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation."));
+ return;
}
}
@@ -752,12 +957,28 @@ void MainWindow::slotFileDecryptVerify() {
outFileName = path + ".out";
}
- try {
+ gpgme_decrypt_result_t d_result = nullptr;
+ gpgme_verify_result_t v_result = nullptr;
- gpgme_decrypt_result_t d_result = nullptr;
- gpgme_verify_result_t v_result = nullptr;
- // try decrypt, if fail do nothing, especially don't replace text
- auto error = GpgFileOpera::decryptVerifyFile(mCtx, path, &d_result, &v_result);
+ gpgme_error_t error;
+ bool if_error = false;
+
+ auto thread = QThread::create([&]() {
+ try {
+ error = GpgFileOpera::decryptVerifyFile(mCtx, path, &d_result, &v_result);
+ } catch (const std::runtime_error &e) {
+ if_error = true;
+ }
+ });
+ thread->start();
+
+ auto *dialog = new WaitingDialog(tr("Decrypting and Verifying"), this);
+ while (thread->isRunning()) {
+ QApplication::processEvents();
+ }
+ dialog->close();
+
+ if(!if_error) {
infoBoard->associateFileTreeView(edit->curFilePage());
auto resultAnalyseDecrypt = new DecryptResultAnalyse(mCtx, error, d_result);
@@ -782,7 +1003,7 @@ void MainWindow::slotFileDecryptVerify() {
delete resultAnalyseVerify;
fileTreeView->update();
- } catch (std::runtime_error &e) {
+ } else {
QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation."));
return;
}
diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp
index 643747ed..f06b3a45 100644
--- a/src/ui/widgets/TextEdit.cpp
+++ b/src/ui/widgets/TextEdit.cpp
@@ -25,221 +25,289 @@
#include "ui/widgets/TextEdit.h"
TextEdit::TextEdit(QWidget *parent) : QWidget(parent) {
- countPage = 0;
- tabWidget = new QTabWidget(this);
- tabWidget->setMovable(true);
- tabWidget->setTabsClosable(true);
- tabWidget->setDocumentMode(true);
-
- auto *layout = new QVBoxLayout;
- layout->addWidget(tabWidget);
- layout->setContentsMargins(0, 0, 0, 0);
- layout->setSpacing(0);
- setLayout(layout);
-
- // Front in same width
- this->setFont({"Courier"});
-
- connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(removeTab(int)));
- slotNewTab();
- setAcceptDrops(false);
+ countPage = 0;
+ tabWidget = new QTabWidget(this);
+ tabWidget->setMovable(true);
+ tabWidget->setTabsClosable(true);
+ tabWidget->setDocumentMode(true);
+
+ auto *layout = new QVBoxLayout;
+ layout->addWidget(tabWidget);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(0);
+ setLayout(layout);
+
+ // Front in same width
+ this->setFont({"Courier"});
+
+ connect(tabWidget, SIGNAL(tabCloseRequested(int)), this,
+ SLOT(removeTab(int)));
+ connect(this, &TextEdit::insertTargetTextPage, this,
+ &TextEdit::slotInsertTargetTextPage);
+ connect(this, &TextEdit::readTargetTextPageStart, this,
+ &TextEdit::slotReadTargetTextPageStart);
+ connect(this, &TextEdit::readTargetTextPageDone, this,
+ &TextEdit::slotReadTargetTextPageDone);
+ slotNewTab();
+ setAcceptDrops(false);
}
void TextEdit::slotNewTab() {
- QString header = tr("untitled") +
- QString::number(++countPage) + ".txt";
+ QString header = tr("untitled") + QString::number(++countPage) + ".txt";
- auto *page = new EditorPage();
- tabWidget->addTab(page, header);
- tabWidget->setCurrentIndex(tabWidget->count() - 1);
- page->getTextPage()->setFocus();
- connect(page->getTextPage()->document(), SIGNAL(modificationChanged(bool)), this, SLOT(slotShowModified()));
+ auto *page = new EditorPage();
+ tabWidget->addTab(page, header);
+ tabWidget->setCurrentIndex(tabWidget->count() - 1);
+ page->getTextPage()->setFocus();
+ connect(page->getTextPage()->document(), SIGNAL(modificationChanged(bool)),
+ this, SLOT(slotShowModified()));
}
void TextEdit::slotNewHelpTab(const QString &title, const QString &path) const {
- auto *page = new HelpPage(path);
- tabWidget->addTab(page, title);
- tabWidget->setCurrentIndex(tabWidget->count() - 1);
-
+ auto *page = new HelpPage(path);
+ tabWidget->addTab(page, title);
+ tabWidget->setCurrentIndex(tabWidget->count() - 1);
}
void TextEdit::slotNewFileTab() const {
- auto *page = new FilePage(qobject_cast<QWidget *>(parent()));
- tabWidget->addTab(page, "[File Browser]");
- tabWidget->setCurrentIndex(tabWidget->count() - 1);
- connect(page, SIGNAL(pathChanged(const QString &)), this, SLOT(slotFilePagePathChanged(const QString &)));
-
+ auto *page = new FilePage(qobject_cast<QWidget *>(parent()));
+ tabWidget->addTab(page, "[File Browser]");
+ tabWidget->setCurrentIndex(tabWidget->count() - 1);
+ connect(page, SIGNAL(pathChanged(const QString &)), this,
+ SLOT(slotFilePagePathChanged(const QString &)));
}
void TextEdit::slotOpenFile(QString &path) {
- QFile file(path);
+ QFile file(path);
+
+ if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ auto *page = new EditorPage(path);
+ pagesHashMap.insert(page->uuid, page);
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+
+ auto read_thread = QThread::create([&, page]() {
+ QFile targetFile(path);
+
+ if (targetFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ emit readTargetTextPageStart(page->uuid);
+ QTextStream in(&targetFile);
+ QString readText;
+ qDebug() << "Thread Start Reading" << path;
+ while (!((readText = in.read(8192)).isEmpty())) {
+ emit insertTargetTextPage(page->uuid, readText);
+ QThread::msleep(64);
+ }
+ targetFile.close();
+ emit readTargetTextPageDone(page->uuid);
+ qDebug() << "Thread End Reading" << path;
+ }
+ });
+
+ page->setFilePath(path);
+ QTextDocument *document = page->getTextPage()->document();
+ document->setModified(false);
+
+ tabWidget->addTab(page, strippedName(path));
+ tabWidget->setCurrentIndex(tabWidget->count() - 1);
+ QApplication::restoreOverrideCursor();
+ page->getTextPage()->setFocus();
+
+ file.close();
+ read_thread->start();
+
+ } else {
+ QMessageBox::warning(
+ this, tr("Warning"),
+ tr("Cannot read file %1:\n%2.").arg(path).arg(file.errorString()));
+ }
+}
+
+void TextEdit::slotInsertTargetTextPage(const QString &pagePtr,
+ const QString &text) {
+ auto it = pagesHashMap.find(pagePtr);
+ if (it != pagesHashMap.end()) {
+ auto *taregtTextPage = qobject_cast<EditorPage *>(it.value());
+ if (taregtTextPage != nullptr) {
+ taregtTextPage->getTextPage()->insertPlainText(text);
+ taregtTextPage->getTextPage()->document()->setModified(false);
+ }
+ }
+}
+
+void TextEdit::slotReadTargetTextPageStart(const QString &pagePtr) {
+ auto it = pagesHashMap.find(pagePtr);
+ if (it != pagesHashMap.end()) {
+ auto *taregtTextPage = qobject_cast<EditorPage *>(it.value());
+ if (taregtTextPage != nullptr) {
+ qDebug() << "Setting TextEdit At Start" << pagePtr;
+ taregtTextPage->getTextPage()->setReadOnly(true);
+ auto index = tabWidget->indexOf(taregtTextPage);
+ if (index != -1) {
+ tabWidget->setTabText(
+ index, "[Loading] " + strippedName(taregtTextPage->getFilePath()));
+ }
+ }
+ }
+}
+
+void TextEdit::slotReadTargetTextPageDone(const QString &pagePtr) {
+ auto it = pagesHashMap.find(pagePtr);
+ if (it != pagesHashMap.end()) {
+ auto *taregtTextPage = qobject_cast<EditorPage *>(it.value());
+ if (taregtTextPage != nullptr) {
+ qDebug() << "Setting TextEdit At End" << pagePtr;
+ taregtTextPage->getTextPage()->setReadOnly(false);
+ auto index = tabWidget->indexOf(taregtTextPage);
+ if (index != -1) {
+ tabWidget->setTabText(index,
+ strippedName(taregtTextPage->getFilePath()));
+ }
+ taregtTextPage->getTextPage()->document()->setModified(false);
+ connect(taregtTextPage->getTextPage()->document(),
+ SIGNAL(modificationChanged(bool)), this,
+ SLOT(slotShowModified()));
+ }
+ }
+}
+
+void TextEdit::slotOpen() {
+ QStringList fileNames =
+ QFileDialog::getOpenFileNames(this, tr("Open file"), QDir::currentPath());
+ for (const auto &fileName : fileNames) {
+ if (!fileName.isEmpty()) {
+ QFile file(fileName);
- if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- auto *page = new EditorPage(path);
+ if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ auto *page = new EditorPage(fileName);
QTextStream in(&file);
QApplication::setOverrideCursor(Qt::WaitCursor);
page->getTextPage()->setPlainText(in.readAll());
- page->setFilePath(path);
+ page->setFilePath(fileName);
QTextDocument *document = page->getTextPage()->document();
document->setModified(false);
- tabWidget->addTab(page, strippedName(path));
+ tabWidget->addTab(page, strippedName(fileName));
tabWidget->setCurrentIndex(tabWidget->count() - 1);
QApplication::restoreOverrideCursor();
page->getTextPage()->setFocus();
- connect(page->getTextPage()->document(), SIGNAL(modificationChanged(bool)), this,
+ connect(page->getTextPage()->document(),
+ SIGNAL(modificationChanged(bool)), this,
SLOT(slotShowModified()));
- //enableAction(true)
+ // enableAction(true)
file.close();
- } else {
+ } else {
QMessageBox::warning(this, tr("Warning"),
tr("Cannot read file %1:\n%2.")
- .arg(path).arg(file.errorString()));
- }
-}
-
-void TextEdit::slotOpen() {
- QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open file"),
- QDir::currentPath());
- for (const auto &fileName : fileNames) {
- if (!fileName.isEmpty()) {
- QFile file(fileName);
-
- if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- auto *page = new EditorPage(fileName);
-
- QTextStream in(&file);
- QApplication::setOverrideCursor(Qt::WaitCursor);
- page->getTextPage()->setPlainText(in.readAll());
- page->setFilePath(fileName);
- QTextDocument *document = page->getTextPage()->document();
- document->setModified(false);
-
- tabWidget->addTab(page, strippedName(fileName));
- tabWidget->setCurrentIndex(tabWidget->count() - 1);
- QApplication::restoreOverrideCursor();
- page->getTextPage()->setFocus();
- connect(page->getTextPage()->document(), SIGNAL(modificationChanged(bool)), this,
- SLOT(slotShowModified()));
- //enableAction(true)
- file.close();
- } else {
- QMessageBox::warning(this, tr("Warning"),
- tr("Cannot read file %1:\n%2.")
- .arg(fileName)
- .arg(file.errorString()));
- }
- }
+ .arg(fileName)
+ .arg(file.errorString()));
+ }
}
+ }
}
void TextEdit::slotSave() {
- if (tabWidget->count() == 0 || slotCurPageTextEdit() == 0) {
- return;
- }
+ if (tabWidget->count() == 0 || slotCurPageTextEdit() == 0) {
+ return;
+ }
- QString fileName = slotCurPageTextEdit()->getFilePath();
+ QString fileName = slotCurPageTextEdit()->getFilePath();
- if (fileName.isEmpty()) {
- //QString docname = tabWidget->tabText(tabWidget->currentIndex());
- //docname.remove(0,2);
- slotSaveAs();
- } else {
- saveFile(fileName);
- }
+ if (fileName.isEmpty()) {
+ // QString docname = tabWidget->tabText(tabWidget->currentIndex());
+ // docname.remove(0,2);
+ slotSaveAs();
+ } else {
+ saveFile(fileName);
+ }
}
bool TextEdit::saveFile(const QString &fileName) {
- if (fileName.isEmpty()) {
- return false;
- }
+ if (fileName.isEmpty()) {
+ return false;
+ }
- QFile file(fileName);
+ QFile file(fileName);
- if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
- EditorPage *page = slotCurPageTextEdit();
+ if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ EditorPage *page = slotCurPageTextEdit();
- QTextStream outputStream(&file);
- QApplication::setOverrideCursor(Qt::WaitCursor);
- outputStream << page->getTextPage()->toPlainText();
- QApplication::restoreOverrideCursor();
- QTextDocument *document = page->getTextPage()->document();
+ QTextStream outputStream(&file);
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+ outputStream << page->getTextPage()->toPlainText();
+ QApplication::restoreOverrideCursor();
+ QTextDocument *document = page->getTextPage()->document();
- document->setModified(false);
+ document->setModified(false);
- int curIndex = tabWidget->currentIndex();
- tabWidget->setTabText(curIndex, strippedName(fileName));
- page->setFilePath(fileName);
- // statusBar()->showMessage(tr("File saved"), 2000);
- file.close();
- return true;
- } else {
- QMessageBox::warning(this, tr("File"),
- tr("Cannot write file %1:\n%2.")
- .arg(fileName)
- .arg(file.errorString()));
- return false;
- }
+ int curIndex = tabWidget->currentIndex();
+ tabWidget->setTabText(curIndex, strippedName(fileName));
+ page->setFilePath(fileName);
+ // statusBar()->showMessage(tr("File saved"), 2000);
+ file.close();
+ return true;
+ } else {
+ QMessageBox::warning(
+ this, tr("File"),
+ tr("Cannot write file %1:\n%2.").arg(fileName).arg(file.errorString()));
+ return false;
+ }
}
-
bool TextEdit::slotSaveAs() {
- if (tabWidget->count() == 0 || slotCurPageTextEdit() == 0) {
- return true;
- }
+ if (tabWidget->count() == 0 || slotCurPageTextEdit() == 0) {
+ return true;
+ }
- EditorPage *page = slotCurPageTextEdit();
- QString path;
- if (page->getFilePath() != "") {
- path = page->getFilePath();
- } else {
- path = tabWidget->tabText(tabWidget->currentIndex()).remove(0, 2);
- }
+ EditorPage *page = slotCurPageTextEdit();
+ QString path;
+ if (page->getFilePath() != "") {
+ path = page->getFilePath();
+ } else {
+ path = tabWidget->tabText(tabWidget->currentIndex()).remove(0, 2);
+ }
- QString fileName = QFileDialog::getSaveFileName(this, tr("Save file"),
- path);
- return saveFile(fileName);
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Save file"), path);
+ return saveFile(fileName);
}
void TextEdit::slotCloseTab() {
- removeTab(tabWidget->currentIndex());
- if (tabWidget->count() != 0) {
- slotCurPageTextEdit()->getTextPage()->setFocus();
- }
+ removeTab(tabWidget->currentIndex());
+ if (tabWidget->count() != 0) {
+ slotCurPageTextEdit()->getTextPage()->setFocus();
+ }
}
void TextEdit::removeTab(int index) {
- // Do nothing, if no tab is opened
- if (tabWidget->count() == 0) {
- return;
- }
+ // Do nothing, if no tab is opened
+ if (tabWidget->count() == 0) {
+ return;
+ }
- // get the index of the actual current tab
- int lastIndex = tabWidget->currentIndex();
+ // get the index of the actual current tab
+ int lastIndex = tabWidget->currentIndex();
- // set the focus to argument index
- tabWidget->setCurrentIndex(index);
+ // set the focus to argument index
+ tabWidget->setCurrentIndex(index);
- if (maybeSaveCurrentTab(true)) {
- tabWidget->removeTab(index);
+ if (maybeSaveCurrentTab(true)) {
+ tabWidget->removeTab(index);
- if (index >= lastIndex) {
- tabWidget->setCurrentIndex(lastIndex);
- } else {
- tabWidget->setCurrentIndex(lastIndex - 1);
- }
+ if (index >= lastIndex) {
+ tabWidget->setCurrentIndex(lastIndex);
+ } else {
+ tabWidget->setCurrentIndex(lastIndex - 1);
}
+ }
- if (tabWidget->count() == 0) {
- // enableAction(false);
- }
+ if (tabWidget->count() == 0) {
+ // enableAction(false);
+ }
}
-
/**
* Check if current may need to be saved.
* Call this function before closing the currently active tab-
@@ -248,339 +316,337 @@ void TextEdit::removeTab(int index) {
*/
bool TextEdit::maybeSaveCurrentTab(bool askToSave) {
- EditorPage *page = slotCurPageTextEdit();
- // if this page is no textedit, there should be nothing to save
- if (page == nullptr) {
- return true;
- }
- QTextDocument *document = page->getTextPage()->document();
-
- if (document->isModified()) {
- QMessageBox::StandardButton result = QMessageBox::Cancel;
-
- // write title of tab to docname and remove the leading *
- QString docname = tabWidget->tabText(tabWidget->currentIndex());
- docname.remove(0, 2);
-
- const QString &filePath = page->getFilePath();
- if (askToSave) {
- result = QMessageBox::warning(this, tr("Unsaved document"),
- tr("<h3>The document \"%1\" has been modified.<br/>Do you want to save your changes?</h3>").arg(
- docname) +
- tr("<b>Note:</b> If you don't save these files, all changes are lost.<br/>"),
- QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
- }
- if ((result == QMessageBox::Save) || (!askToSave)) {
- if (filePath == "") {
- //QString docname = tabWidget->tabText(tabWidget->currentIndex());
- //docname.remove(0,2);
- return slotSaveAs();
- } else {
- return saveFile(filePath);
- }
- } else if (result == QMessageBox::Discard) {
- return true;
- } else {
- return false;
- }
- }
+ EditorPage *page = slotCurPageTextEdit();
+ // if this page is no textedit, there should be nothing to save
+ if (page == nullptr) {
return true;
+ }
+ QTextDocument *document = page->getTextPage()->document();
+
+ if (document->isModified()) {
+ QMessageBox::StandardButton result = QMessageBox::Cancel;
+
+ // write title of tab to docname and remove the leading *
+ QString docname = tabWidget->tabText(tabWidget->currentIndex());
+ docname.remove(0, 2);
+
+ const QString &filePath = page->getFilePath();
+ if (askToSave) {
+ result = QMessageBox::warning(
+ this, tr("Unsaved document"),
+ tr("The document \"%1\" has been modified. Do you want to "
+ "save your changes?<br/>")
+ .arg(docname) +
+ tr("<b>Note:</b> If you don't save these files, all changes are "
+ "lost.<br/>"),
+ QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
+ }
+ if ((result == QMessageBox::Save) || (!askToSave)) {
+ if (filePath == "") {
+ // QString docname = tabWidget->tabText(tabWidget->currentIndex());
+ // docname.remove(0,2);
+ return slotSaveAs();
+ } else {
+ return saveFile(filePath);
+ }
+ } else if (result == QMessageBox::Discard) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ return true;
}
bool TextEdit::maybeSaveAnyTab() {
- // get a list of all unsaved documents and their tabids
- QHash<int, QString> unsavedDocs = this->unsavedDocuments();
+ // get a list of all unsaved documents and their tabids
+ QHash<int, QString> unsavedDocs = this->unsavedDocuments();
- /*
- * no unsaved documents, so app can be closed
- */
- if (unsavedDocs.empty()) {
+ /*
+ * no unsaved documents, so app can be closed
+ */
+ if (unsavedDocs.empty()) {
+ return true;
+ }
+ /*
+ * only 1 unsaved document -> set modified tab as current
+ * and show normal unsaved doc dialog
+ */
+ if (unsavedDocs.size() == 1) {
+ int modifiedTab = unsavedDocs.keys().at(0);
+ tabWidget->setCurrentIndex(modifiedTab);
+ return maybeSaveCurrentTab(true);
+ }
+
+ /*
+ * more than one unsaved documents
+ */
+ if (unsavedDocs.size() > 1) {
+ QHashIterator<int, QString> i(unsavedDocs);
+
+ QuitDialog *dialog;
+ dialog = new QuitDialog(this, unsavedDocs);
+ int result = dialog->exec();
+
+ // if result is QDialog::Rejected, discard or cancel was clicked
+ if (result == QDialog::Rejected) {
+ // return true, if discard is clicked, so app can be closed
+ if (dialog->isDiscarded()) {
return true;
- }
- /*
- * only 1 unsaved document -> set modified tab as current
- * and show normal unsaved doc dialog
- */
- if (unsavedDocs.size() == 1) {
- int modifiedTab = unsavedDocs.keys().at(0);
- tabWidget->setCurrentIndex(modifiedTab);
- return maybeSaveCurrentTab(true);
- }
+ } else {
+ return false;
+ }
+ } else {
+ bool allsaved = true;
+ QList<int> tabIdsToSave = dialog->getTabIdsToSave();
- /*
- * more than one unsaved documents
- */
- if (unsavedDocs.size() > 1) {
- QHashIterator<int, QString> i(unsavedDocs);
-
- QuitDialog *dialog;
- dialog = new QuitDialog(this, unsavedDocs);
- int result = dialog->exec();
-
- // if result is QDialog::Rejected, discard or cancel was clicked
- if (result == QDialog::Rejected) {
- // return true, if discard is clicked, so app can be closed
- if (dialog->isDiscarded()) {
- return true;
- } else {
- return false;
- }
- } else {
- bool allsaved = true;
- QList<int> tabIdsToSave = dialog->getTabIdsToSave();
-
- foreach(int
- tabId, tabIdsToSave) {
- tabWidget->setCurrentIndex(tabId);
- if (!maybeSaveCurrentTab(false)) {
- allsaved = false;
- }
- }
- if (allsaved) {
- return true;
- } else {
- return false;
- }
+ foreach (int tabId, tabIdsToSave) {
+ tabWidget->setCurrentIndex(tabId);
+ if (!maybeSaveCurrentTab(false)) {
+ allsaved = false;
}
+ }
+ if (allsaved) {
+ return true;
+ } else {
+ return false;
+ }
}
- // code should never reach this statement
- return false;
+ }
+ // code should never reach this statement
+ return false;
}
-
QTextEdit *TextEdit::curTextPage() const {
- auto *curTextPage = qobject_cast<EditorPage *>(tabWidget->currentWidget());
- if (curTextPage != nullptr) {
- return curTextPage->getTextPage();
- } else {
- return nullptr;
- }
+ auto *curTextPage = qobject_cast<EditorPage *>(tabWidget->currentWidget());
+ if (curTextPage != nullptr) {
+ return curTextPage->getTextPage();
+ } else {
+ return nullptr;
+ }
}
-FilePage * TextEdit::curFilePage() const {
- auto *curFilePage = qobject_cast<FilePage *>(tabWidget->currentWidget());
- if (curFilePage != nullptr) {
- return curFilePage;
- } else {
- return nullptr;
- }
+FilePage *TextEdit::curFilePage() const {
+ auto *curFilePage = qobject_cast<FilePage *>(tabWidget->currentWidget());
+ if (curFilePage != nullptr) {
+ return curFilePage;
+ } else {
+ return nullptr;
+ }
}
-int TextEdit::tabCount() const {
- return tabWidget->count();
-}
+int TextEdit::tabCount() const { return tabWidget->count(); }
EditorPage *TextEdit::slotCurPageTextEdit() const {
- auto *curPage = qobject_cast<EditorPage *>(tabWidget->currentWidget());
- return curPage;
+ auto *curPage = qobject_cast<EditorPage *>(tabWidget->currentWidget());
+ return curPage;
}
FilePage *TextEdit::slotCurPageFileTreeView() const {
- auto *curPage = qobject_cast<FilePage *>(tabWidget->currentWidget());
- return curPage;
+ auto *curPage = qobject_cast<FilePage *>(tabWidget->currentWidget());
+ return curPage;
}
void TextEdit::slotQuote() const {
- if (tabWidget->count() == 0 || curTextPage() == nullptr) {
- return;
- }
+ if (tabWidget->count() == 0 || curTextPage() == nullptr) {
+ return;
+ }
- QTextCursor cursor(curTextPage()->document());
-
- // beginEditBlock and endEditBlock() let operation look like single undo/redo operation
- cursor.beginEditBlock();
- cursor.setPosition(0);
- cursor.insertText("> ");
- while (!cursor.isNull() && !cursor.atEnd()) {
- cursor.movePosition(QTextCursor::EndOfLine);
- cursor.movePosition(QTextCursor::NextCharacter);
- if (!cursor.atEnd()) {
- cursor.insertText("> ");
- }
+ QTextCursor cursor(curTextPage()->document());
+
+ // beginEditBlock and endEditBlock() let operation look like single undo/redo
+ // operation
+ cursor.beginEditBlock();
+ cursor.setPosition(0);
+ cursor.insertText("> ");
+ while (!cursor.isNull() && !cursor.atEnd()) {
+ cursor.movePosition(QTextCursor::EndOfLine);
+ cursor.movePosition(QTextCursor::NextCharacter);
+ if (!cursor.atEnd()) {
+ cursor.insertText("> ");
}
- cursor.endEditBlock();
+ }
+ cursor.endEditBlock();
}
void TextEdit::slotFillTextEditWithText(const QString &text) const {
- QTextCursor cursor(curTextPage()->document());
- cursor.beginEditBlock();
- this->curTextPage()->selectAll();
- this->curTextPage()->insertPlainText(text);
- cursor.endEditBlock();
+ QTextCursor cursor(curTextPage()->document());
+ cursor.beginEditBlock();
+ this->curTextPage()->selectAll();
+ this->curTextPage()->insertPlainText(text);
+ cursor.endEditBlock();
}
void TextEdit::loadFile(const QString &fileName) {
- QFile file(fileName);
- if (!file.open(QFile::ReadOnly | QFile::Text)) {
- QMessageBox::warning(this, tr("Application"),
- tr("Cannot read file %1:\n%2.")
- .arg(fileName)
- .arg(file.errorString()));
- return;
- }
- QTextStream in(&file);
- QApplication::setOverrideCursor(Qt::WaitCursor);
- curTextPage()->setPlainText(in.readAll());
- QApplication::restoreOverrideCursor();
- slotCurPageTextEdit()->setFilePath(fileName);
- tabWidget->setTabText(tabWidget->currentIndex(), strippedName(fileName));
- file.close();
- // statusBar()->showMessage(tr("File loaded"), 2000);
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly | QFile::Text)) {
+ QMessageBox::warning(
+ this, tr("Application"),
+ tr("Cannot read file %1:\n%2.").arg(fileName).arg(file.errorString()));
+ return;
+ }
+ QTextStream in(&file);
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+ curTextPage()->setPlainText(in.readAll());
+ QApplication::restoreOverrideCursor();
+ slotCurPageTextEdit()->setFilePath(fileName);
+ tabWidget->setTabText(tabWidget->currentIndex(), strippedName(fileName));
+ file.close();
+ // statusBar()->showMessage(tr("File loaded"), 2000);
}
QString TextEdit::strippedName(const QString &fullFileName) {
- return QFileInfo(fullFileName).fileName();
+ return QFileInfo(fullFileName).fileName();
}
void TextEdit::slotPrint() {
- if (tabWidget->count() == 0) {
- return;
- }
+ if (tabWidget->count() == 0) {
+ return;
+ }
#ifndef QT_NO_PRINTER
- QTextDocument *document;
- if (curTextPage() != nullptr) {
- document = curTextPage()->document();
- }
- QPrinter printer;
-
- auto *dlg = new QPrintDialog(&printer, this);
- if (dlg->exec() != QDialog::Accepted) {
- return;
- }
- document->print(&printer);
-
- //statusBar()->showMessage(tr("Ready"), 2000);
+ QTextDocument *document;
+ if (curTextPage() != nullptr) {
+ document = curTextPage()->document();
+ }
+ QPrinter printer;
+
+ auto *dlg = new QPrintDialog(&printer, this);
+ if (dlg->exec() != QDialog::Accepted) {
+ return;
+ }
+ document->print(&printer);
+
+ // statusBar()->showMessage(tr("Ready"), 2000);
#endif
}
void TextEdit::slotShowModified() const {
- int index = tabWidget->currentIndex();
- QString title = tabWidget->tabText(index);
- // if doc is modified now, add leading * to title,
- // otherwise remove the leading * from the title
- if (curTextPage()->document()->isModified()) {
- tabWidget->setTabText(index, title.prepend("* "));
- } else {
- tabWidget->setTabText(index, title.remove(0, 2));
- }
+ int index = tabWidget->currentIndex();
+ QString title = tabWidget->tabText(index);
+ // if doc is modified now, add leading * to title,
+ // otherwise remove the leading * from the title
+ if (curTextPage()->document()->isModified()) {
+ tabWidget->setTabText(index, title.prepend("* "));
+ } else {
+ tabWidget->setTabText(index, title.remove(0, 2));
+ }
}
void TextEdit::slotSwitchTabUp() const {
- if (tabWidget->count() > 1) {
- int newindex = (tabWidget->currentIndex() + 1) % (tabWidget->count());
- tabWidget->setCurrentIndex(newindex);
- }
+ if (tabWidget->count() > 1) {
+ int newindex = (tabWidget->currentIndex() + 1) % (tabWidget->count());
+ tabWidget->setCurrentIndex(newindex);
+ }
}
void TextEdit::slotSwitchTabDown() const {
- if (tabWidget->count() > 1) {
- int newindex = (tabWidget->currentIndex() - 1 + tabWidget->count()) % tabWidget->count();
- tabWidget->setCurrentIndex(newindex);
- }
+ if (tabWidget->count() > 1) {
+ int newindex = (tabWidget->currentIndex() - 1 + tabWidget->count()) %
+ tabWidget->count();
+ tabWidget->setCurrentIndex(newindex);
+ }
}
/*
* return a hash of tabindexes and title of unsaved tabs
*/
QHash<int, QString> TextEdit::unsavedDocuments() const {
- QHash<int, QString> unsavedDocs; // this list could be used to implement gedit like "unsaved changed"-dialog
-
- for (int i = 0; i < tabWidget->count(); i++) {
- auto *ep = qobject_cast<EditorPage *>(tabWidget->widget(i));
- if (ep != nullptr && ep->getTextPage()->document()->isModified()) {
- QString docname = tabWidget->tabText(i);
- // remove * before name of modified doc
- docname.remove(0, 2);
- unsavedDocs.insert(i, docname);
- }
+ QHash<int, QString> unsavedDocs; // this list could be used to implement gedit
+ // like "unsaved changed"-dialog
+
+ for (int i = 0; i < tabWidget->count(); i++) {
+ auto *ep = qobject_cast<EditorPage *>(tabWidget->widget(i));
+ if (ep != nullptr && ep->getTextPage()->document()->isModified()) {
+ QString docname = tabWidget->tabText(i);
+ // remove * before name of modified doc
+ docname.remove(0, 2);
+ unsavedDocs.insert(i, docname);
}
- return unsavedDocs;
+ }
+ return unsavedDocs;
}
void TextEdit::slotCut() const {
- if (tabWidget->count() == 0 || curTextPage() == nullptr) {
- return;
- }
+ if (tabWidget->count() == 0 || curTextPage() == nullptr) {
+ return;
+ }
- curTextPage()->cut();
+ curTextPage()->cut();
}
void TextEdit::slotCopy() const {
- if (tabWidget->count() == 0) {
- return;
- }
-
- if (curTextPage() != nullptr) {
- curTextPage()->copy();
- }
-
+ if (tabWidget->count() == 0) {
+ return;
+ }
+ if (curTextPage() != nullptr) {
+ curTextPage()->copy();
+ }
}
void TextEdit::slotPaste() const {
- if (tabWidget->count() == 0 || curTextPage() == nullptr) {
- return;
- }
+ if (tabWidget->count() == 0 || curTextPage() == nullptr) {
+ return;
+ }
- curTextPage()->paste();
+ curTextPage()->paste();
}
void TextEdit::slotUndo() const {
- if (tabWidget->count() == 0 || curTextPage() == nullptr) {
- return;
- }
+ if (tabWidget->count() == 0 || curTextPage() == nullptr) {
+ return;
+ }
- curTextPage()->undo();
+ curTextPage()->undo();
}
void TextEdit::slotRedo() const {
- if (tabWidget->count() == 0 || curTextPage() == nullptr) {
- return;
- }
+ if (tabWidget->count() == 0 || curTextPage() == nullptr) {
+ return;
+ }
- curTextPage()->redo();
+ curTextPage()->redo();
}
void TextEdit::slotZoomIn() const {
- if (tabWidget->count() == 0) {
- return;
- }
-
- if (curTextPage() != nullptr) {
- curTextPage()->zoomIn();
- }
+ if (tabWidget->count() == 0) {
+ return;
+ }
+ if (curTextPage() != nullptr) {
+ curTextPage()->zoomIn();
+ }
}
void TextEdit::slotZoomOut() const {
- if (tabWidget->count() == 0) {
- return;
- }
+ if (tabWidget->count() == 0) {
+ return;
+ }
- if (curTextPage() != nullptr) {
- curTextPage()->zoomOut();
- }
+ if (curTextPage() != nullptr) {
+ curTextPage()->zoomOut();
+ }
}
void TextEdit::slotSelectAll() const {
- if (tabWidget->count() == 0 || curTextPage() == nullptr) {
- return;
- }
- curTextPage()->selectAll();
+ if (tabWidget->count() == 0 || curTextPage() == nullptr) {
+ return;
+ }
+ curTextPage()->selectAll();
}
void TextEdit::slotFilePagePathChanged(const QString &path) {
- int index = tabWidget->currentIndex();
- QString mPath;
- QFileInfo fileInfo(path);
- QString tPath = fileInfo.path();
- if (path.size() > 18) {
- mPath = tPath.mid(tPath.size() - 18, 18).prepend("...");
- } else {
- mPath = tPath;
- }
- mPath.prepend("[File Browser] ");
- mPath.append("/");
- tabWidget->setTabText(index, mPath);
+ int index = tabWidget->currentIndex();
+ QString mPath;
+ QFileInfo fileInfo(path);
+ QString tPath = fileInfo.path();
+ if (path.size() > 18) {
+ mPath = tPath.mid(tPath.size() - 18, 18).prepend("...");
+ } else {
+ mPath = tPath;
+ }
+ mPath.prepend("[File Browser] ");
+ mPath.append("/");
+ tabWidget->setTabText(index, mPath);
}