From 8bd22618813553f31cdca77b4e77a81f00ed28ac Mon Sep 17 00:00:00 2001 From: Boo Yee Date: Sat, 21 Sep 2024 20:22:12 +0800 Subject: [PATCH 1/4] Catch exceptions in downloadNote(). --- src/communication/communicationmanager.cpp | 31 ++++++++++++++-------- src/communication/communicationmanager.h | 2 +- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/communication/communicationmanager.cpp b/src/communication/communicationmanager.cpp index 1264fe38..5b1a34f2 100644 --- a/src/communication/communicationmanager.cpp +++ b/src/communication/communicationmanager.cpp @@ -85,7 +85,7 @@ CommunicationManager::CommunicationManager(DatabaseConnection *db) { if (networkAccessManager == nullptr) { networkAccessManager = new QNetworkAccessManager(this); } - threadException = nullptr; + hasException = false; } @@ -301,7 +301,8 @@ CommunicationManager::getSyncChunk(SyncChunk &chunk, int start, int chunkSize, i try { chunk = myNoteStore->getFilteredSyncChunk(start, chunkSize, filter, newRequestContext(token, requestTimeout)); processSyncChunk(chunk, token); - if (threadException != nullptr) { + if (hasException) { + hasException = false; return false; } } catch (ThriftException &e) { @@ -558,9 +559,13 @@ void CommunicationManager::reportError( backtrace_symbols_fd(array, size, 2); #endif // End windows check + QMutexLocker locker(&mutex); + error.resetTo(errorType, code, message, internalMessage); global.setMessage(tr("Error in sync: ") + error.getMessage(), 0); + + hasException = true; } void CommunicationManager::resetError() { @@ -712,7 +717,8 @@ bool CommunicationManager::getLinkedNotebookSyncChunk(SyncChunk &chunk, LinkedNo try { chunk = linkedNoteStore->getLinkedNotebookSyncChunk(book, start, chunkSize, fullSync, newRequestContext(authToken, requestTimeout)); processSyncChunk(chunk, linkedAuthToken); - if (threadException != nullptr) { + if (hasException) { + hasException = false; return false; } } catch (ThriftException &e) { @@ -790,18 +796,21 @@ bool CommunicationManager::getNoteVersion(Note ¬e, QString guid, qint32 usn, } } - Note CommunicationManager::downloadNote(const Note &n) { QLOG_DEBUG() << "downloadNote guid=" << n.guid; Note tmp = n; try { this->getNote(tmp, n.guid, true, true, true); - } catch (const EverCloudException &e) { - QMutexLocker locker(&mutex); - if (threadException == nullptr) { - threadException = new EverCloudException(e); - reportError(CommunicationError::StdException, 16, e.what()); - } + } catch (ThriftException &e) { + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); + } catch (EDAMUserException &e) { + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); + } catch (EDAMSystemException &e) { + handleEDAMSystemException(e); + } catch (EDAMNotFoundException &e) { + handleEDAMNotFoundException(e); + } catch (std::exception &e) { // connection closed by the server + reportError(CommunicationError::StdException, 16, e.what()); } return tmp; } @@ -1048,7 +1057,7 @@ void CommunicationManager::processSyncChunk(SyncChunk &chunk, QString token) { } downloadedNotes.append(QtConcurrent::blockingMapped >(tmpNotes, std::bind(&CommunicationManager::downloadNote, this, std::placeholders::_1))); - if (threadException != nullptr) { + if (hasException) { return; } QLOG_TRACE() << "A set of notes Retrieved"; diff --git a/src/communication/communicationmanager.h b/src/communication/communicationmanager.h index c7107387..bf19ac88 100644 --- a/src/communication/communicationmanager.h +++ b/src/communication/communicationmanager.h @@ -104,7 +104,7 @@ class CommunicationManager : public QObject const QString &internalMessage = QString()); CommunicationError error; - EverCloudException *threadException; + bool hasException; QMutex mutex; public: From 348c565ba737855a7df4ddff5edef3aacabef0f0 Mon Sep 17 00:00:00 2001 From: Boo Yee Date: Sun, 22 Sep 2024 13:27:42 +0800 Subject: [PATCH 2/4] Add the setting of downloading thread number. --- src/communication/communicationmanager.cpp | 5 ++++- src/dialog/preferences/syncpreferences.cpp | 8 ++++++++ src/dialog/preferences/syncpreferences.h | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/communication/communicationmanager.cpp b/src/communication/communicationmanager.cpp index 5b1a34f2..f275fc53 100644 --- a/src/communication/communicationmanager.cpp +++ b/src/communication/communicationmanager.cpp @@ -1047,7 +1047,10 @@ void CommunicationManager::processSyncChunk(SyncChunk &chunk, QString token) { QList downloadedNotes; downloadedNotes.clear(); - const int THREAD_NUMBER = 5; + global.settings->beginGroup(INI_GROUP_SYNC); + const int THREAD_NUMBER = global.settings->value("threadNumber").toInt(); + global.settings->endGroup(); + for (int i = 0; i < notes.size(); i += THREAD_NUMBER) { QList tmpNotes; tmpNotes.clear(); diff --git a/src/dialog/preferences/syncpreferences.cpp b/src/dialog/preferences/syncpreferences.cpp index 0ef76199..cc32b94d 100644 --- a/src/dialog/preferences/syncpreferences.cpp +++ b/src/dialog/preferences/syncpreferences.cpp @@ -48,6 +48,10 @@ SyncPreferences::SyncPreferences(QWidget *parent) : showGoodSyncMessagesInTray = new QCheckBox(tr("Show successful syncs"), this); apiRateRestart = new QCheckBox(tr("Restart sync on API limit (experimental)"), this); connectionClosedRestart = new QCheckBox(tr("Restart sync on connection closed (experimental)"), this); + QLabel *threadNumberLabel = new QLabel(tr("The number of downloading threads(1~50)"), this); + threadNumber = new QSpinBox(this); + threadNumber->setMinimum(1); + threadNumber->setMaximum(50); enableProxy = new QCheckBox(tr("Enable Proxy*"), this); enableSocks5 = new QCheckBox(tr("Enable Socks5"),this); @@ -95,6 +99,8 @@ SyncPreferences::SyncPreferences(QWidget *parent) : mainLayout->addWidget(passwordLabel,9,0); mainLayout->addWidget(password,9,1); mainLayout->addWidget(restartLabel,10,0); + mainLayout->addWidget(threadNumberLabel, 11,0); + mainLayout->addWidget(threadNumber, 11,1); mainLayout->setAlignment(Qt::AlignTop); global.settings->beginGroup(INI_GROUP_SYNC); @@ -108,6 +114,7 @@ SyncPreferences::SyncPreferences(QWidget *parent) : showGoodSyncMessagesInTray->setChecked(global.showGoodSyncMessagesInTray); apiRateRestart->setChecked(global.settings->value("apiRateLimitAutoRestart", true).toBool()); connectionClosedRestart->setChecked(global.settings->value("connectionClosedAutoRestart", false).toBool()); + threadNumber->setValue(global.settings->value("threadNumber", 5).toInt()); global.settings->endGroup(); global.showGoodSyncMessagesInTray = showGoodSyncMessagesInTray->isChecked(); @@ -164,6 +171,7 @@ void SyncPreferences::saveValues() { global.settings->setValue("showGoodSyncMessagesInTray", showGoodSyncMessagesInTray ->isChecked()); global.settings->setValue("apiRateLimitAutoRestart", apiRateRestart ->isChecked()); global.settings->setValue("connectionClosedAutoRestart", connectionClosedRestart->isChecked()); + global.settings->setValue("threadNumber", threadNumber->value()); global.settings->endGroup(); global.showGoodSyncMessagesInTray = showGoodSyncMessagesInTray->isChecked(); diff --git a/src/dialog/preferences/syncpreferences.h b/src/dialog/preferences/syncpreferences.h index 8b851af2..f33e8f2d 100644 --- a/src/dialog/preferences/syncpreferences.h +++ b/src/dialog/preferences/syncpreferences.h @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include #include +#include class SyncPreferences : public QWidget { @@ -47,6 +48,8 @@ class SyncPreferences : public QWidget QLineEdit *port; QLineEdit *host; + QSpinBox *threadNumber; + int getSyncInterval(); public: From 71ef00f53d25e23317c5d156891211455d94697c Mon Sep 17 00:00:00 2001 From: Boo Yee Date: Sun, 22 Sep 2024 20:01:36 +0800 Subject: [PATCH 3/4] Add a default value for thread number in CommunicationManager::processSyncChunk(). --- src/communication/communicationmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/communication/communicationmanager.cpp b/src/communication/communicationmanager.cpp index f275fc53..a5996717 100644 --- a/src/communication/communicationmanager.cpp +++ b/src/communication/communicationmanager.cpp @@ -1048,7 +1048,7 @@ void CommunicationManager::processSyncChunk(SyncChunk &chunk, QString token) { downloadedNotes.clear(); global.settings->beginGroup(INI_GROUP_SYNC); - const int THREAD_NUMBER = global.settings->value("threadNumber").toInt(); + const int THREAD_NUMBER = global.settings->value("threadNumber", 5).toInt(); global.settings->endGroup(); for (int i = 0; i < notes.size(); i += THREAD_NUMBER) { From 0bb6e01d0c2a35f8ed41460826c3804dac28f96a Mon Sep 17 00:00:00 2001 From: Boo Yee Date: Sat, 14 Dec 2024 21:42:24 +0800 Subject: [PATCH 4/4] Fix some css styles of the dark theme. --- themes.ini | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/themes.ini b/themes.ini index 25e2f10f..bf14dcb3 100644 --- a/themes.ini +++ b/themes.ini @@ -300,20 +300,20 @@ stackIcon =purple-theme/stack-purple.png windowIcon=purple-theme/windowIcon5.png -# global dark theme -[Dark Blue] +# global dark theme - you can modify it, but don't remove +[global dark] editorCss=body { color: white; background-color: #272a34;} # Note title editor style when inactive noteTitleEditorInactiveCss=background-color: #23252e; color: white; QLineEdit {background-color: transparent; border-radius: 0px;} QLineEdit:hover {border: 1px solid #808080; background-color: white; border-radius: 4px;} # Note title editor when it has user focus. -noteTitleEditorActiveCss=QLineEdit {border: 1px solid #808080; background-color: white; border-radius: 4px;} +noteTitleEditorActiveCss=QLineEdit {border: 1px solid #808080; background-color: #abacb0; color: black; border-radius: 4px;} # searchInputCss= background-color: #272a34; QLineEdit { padding-right: 1px; } ## Search across notes text input field mainWindowCss=background-color: #23252e; color: white; ## Default window -menuCss=QMenu {background-color: #23252e; color: white;} ## Window menu +menuCss=QMenu {background-color: #23252e; color: white;} QMenu::item::selected { background:#abacb0; } QMenuBar::item {background: transparent; } QMenuBar::item::selected { background: #abacb0; } ## Window menu mainToolbarCss= background-color: #23252e; ## Main toolbar #noteAuthorInactiveCss=background-color: transparent; border-radius: 0px; ## Color when author field doesn't have focus #noteAuthorActiveCss=border: 1px solid #808080; background-color: white; border-radius: 4px; ## color when author field has focus