Compare commits
2 Commits
0a2b0d840b
...
b76523ec75
| Author | SHA1 | Date | |
|---|---|---|---|
| b76523ec75 | |||
| 178850e0bc |
@ -98,23 +98,6 @@ std::shared_ptr<GeneralSortFilterModel> GenericCore::getSortFilterModel() const
|
|||||||
return m_sortFilterModel;
|
return m_sortFilterModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Save items to default file (in standard location).
|
|
||||||
* @brief GenericCore::saveItems Saves item fo file.
|
|
||||||
*/
|
|
||||||
void GenericCore::saveItems() {
|
|
||||||
qDebug() << "saving items...";
|
|
||||||
|
|
||||||
const QJsonDocument doc = m_mainModel->getAllItemsAsJsonDoc();
|
|
||||||
const bool successfulSave = FileHandler::saveToFile(doc, ITEMS_FILE_NAME);
|
|
||||||
if (successfulSave) {
|
|
||||||
m_modelUndoStack->setClean();
|
|
||||||
emit displayStatusMessage(QString("Items saved."));
|
|
||||||
} else {
|
|
||||||
emit displayStatusMessage(QString("Error: Items couldn't be saved."));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GenericCore::importCSVFile(const QString& filePath) {
|
void GenericCore::importCSVFile(const QString& filePath) {
|
||||||
qInfo() << "importing items from CSV...";
|
qInfo() << "importing items from CSV...";
|
||||||
qDebug() << "filePath:" << filePath;
|
qDebug() << "filePath:" << filePath;
|
||||||
@ -158,6 +141,22 @@ bool GenericCore::isSyncServerSetup() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save items to default file (in standard location).
|
||||||
|
* @brief GenericCore::saveItems Saves item fo file.
|
||||||
|
*/
|
||||||
|
void GenericCore::saveItems() {
|
||||||
|
qDebug() << "saving items...";
|
||||||
|
|
||||||
|
const QJsonDocument doc = m_mainModel->getAllItemsAsJsonDoc();
|
||||||
|
const bool successfulSave = FileHandler::saveToFile(doc, ITEMS_FILE_NAME);
|
||||||
|
if (successfulSave) {
|
||||||
|
m_modelUndoStack->setClean();
|
||||||
|
emit displayStatusMessage(QString("Items saved."));
|
||||||
|
} else {
|
||||||
|
emit displayStatusMessage(QString("Error: Items couldn't be saved."));
|
||||||
|
}
|
||||||
|
}
|
||||||
void GenericCore::onSendItemTriggered(const QByteArray& jsonData) {
|
void GenericCore::onSendItemTriggered(const QByteArray& jsonData) {
|
||||||
m_serverCommunicator->postItems(jsonData);
|
m_serverCommunicator->postItems(jsonData);
|
||||||
}
|
}
|
||||||
@ -279,6 +278,8 @@ void GenericCore::applyServerConfiguration() {
|
|||||||
if (!urlValue.isEmpty()) {
|
if (!urlValue.isEmpty()) {
|
||||||
const QString emailValue = serverSettings.value("email").toString();
|
const QString emailValue = serverSettings.value("email").toString();
|
||||||
const QString passwordValue = serverSettings.value("password").toString();
|
const QString passwordValue = serverSettings.value("password").toString();
|
||||||
m_serverCommunicator->setServerConfiguration(urlValue, emailValue, passwordValue);
|
const QString authTokenValue = serverSettings.value("authToken").toString();
|
||||||
|
m_serverCommunicator->setServerConfiguration(urlValue, emailValue, passwordValue,
|
||||||
|
authTokenValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,21 @@ void ServerCommunicator::setUrl(const QUrl& url) {
|
|||||||
emit urlChanged();
|
emit urlChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServerCommunicator::setServerConfiguration(const QString url,
|
||||||
|
const QString email,
|
||||||
|
const QString password,
|
||||||
|
const QString authToken) {
|
||||||
|
setUrl(url);
|
||||||
|
|
||||||
|
m_email = email;
|
||||||
|
m_password = password;
|
||||||
|
m_authToken = authToken;
|
||||||
|
|
||||||
|
if (!authToken.isEmpty()) {
|
||||||
|
m_serviceApi->setBearerToken(authToken.toLatin1());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ServerCommunicator::fetchItems() {
|
void ServerCommunicator::fetchItems() {
|
||||||
/// Set up a GET request
|
/// Set up a GET request
|
||||||
m_restManager->get(m_serviceApi->createRequest(ROUTE_ITEMS), this, [this](QRestReply& reply) {
|
m_restManager->get(m_serviceApi->createRequest(ROUTE_ITEMS), this, [this](QRestReply& reply) {
|
||||||
@ -95,12 +110,3 @@ void ServerCommunicator::deleteItem(const QString& id) {
|
|||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerCommunicator::setServerConfiguration(const QString url,
|
|
||||||
const QString email,
|
|
||||||
const QString password) {
|
|
||||||
setUrl(url);
|
|
||||||
|
|
||||||
m_email = email;
|
|
||||||
m_password = password;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -16,7 +16,10 @@ class ServerCommunicator : public QObject {
|
|||||||
QUrl url() const;
|
QUrl url() const;
|
||||||
void setUrl(const QUrl& url);
|
void setUrl(const QUrl& url);
|
||||||
|
|
||||||
void setServerConfiguration(const QString url, const QString email, const QString password);
|
void setServerConfiguration(const QString url,
|
||||||
|
const QString email,
|
||||||
|
const QString password,
|
||||||
|
const QString authToken);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void fetchItems();
|
void fetchItems();
|
||||||
@ -40,7 +43,7 @@ class ServerCommunicator : public QObject {
|
|||||||
|
|
||||||
QString m_email;
|
QString m_email;
|
||||||
QString m_password;
|
QString m_password;
|
||||||
// QString m_authToken;
|
QString m_authToken;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SERVERCOMMUNICATOR_H
|
#endif // SERVERCOMMUNICATOR_H
|
||||||
|
|||||||
Reference in New Issue
Block a user