Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 222: crash with 'qevercloud::EverCloudException' #233

Merged
merged 4 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions src/communication/communicationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ CommunicationManager::CommunicationManager(DatabaseConnection *db) {
if (networkAccessManager == nullptr) {
networkAccessManager = new QNetworkAccessManager(this);
}
threadException = nullptr;
hasException = false;
}


Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -790,18 +796,21 @@ bool CommunicationManager::getNoteVersion(Note &note, 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<int>(e.type()), e.what());
} catch (EDAMUserException &e) {
reportError(CommunicationError::EDAMUserException, static_cast<int>(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;
}
Expand Down Expand Up @@ -1038,7 +1047,10 @@ void CommunicationManager::processSyncChunk(SyncChunk &chunk, QString token) {
QList<Note> downloadedNotes;
downloadedNotes.clear();

const int THREAD_NUMBER = 5;
global.settings->beginGroup(INI_GROUP_SYNC);
const int THREAD_NUMBER = global.settings->value("threadNumber", 5).toInt();
global.settings->endGroup();

for (int i = 0; i < notes.size(); i += THREAD_NUMBER) {
QList<Note> tmpNotes;
tmpNotes.clear();
Expand All @@ -1048,7 +1060,7 @@ void CommunicationManager::processSyncChunk(SyncChunk &chunk, QString token) {
}
downloadedNotes.append(QtConcurrent::blockingMapped<QList<Note> >(tmpNotes,
std::bind(&CommunicationManager::downloadNote, this, std::placeholders::_1)));
if (threadException != nullptr) {
if (hasException) {
return;
}
QLOG_TRACE() << "A set of notes Retrieved";
Expand Down
2 changes: 1 addition & 1 deletion src/communication/communicationmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class CommunicationManager : public QObject
const QString &internalMessage = QString());

CommunicationError error;
EverCloudException *threadException;
bool hasException;
QMutex mutex;

public:
Expand Down
8 changes: 8 additions & 0 deletions src/dialog/preferences/syncpreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/dialog/preferences/syncpreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <QLabel>
#include <QComboBox>
#include <QLineEdit>
#include <QSpinBox>

class SyncPreferences : public QWidget
{
Expand All @@ -47,6 +48,8 @@ class SyncPreferences : public QWidget
QLineEdit *port;
QLineEdit *host;

QSpinBox *threadNumber;

int getSyncInterval();

public:
Expand Down
8 changes: 4 additions & 4 deletions themes.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down