Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 87b05311 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

LOG: Use the new logging API with the MainWindow

parent a67b15d3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -164,7 +164,7 @@ MainWindow::MainWindow() noexcept
void
MainWindow::closeEvent(QCloseEvent *event) noexcept
{
qDebug() << "Closing the main window!";
logDebug() << "Closing the main window!";
forEachViews<VivyDocumentView>([](VivyDocumentView *view, int) { view->closeDocument(); });
QMainWindow::closeEvent(event);
}
......@@ -191,7 +191,7 @@ MainWindow::openProperties(int index) noexcept
return;
}
qDebug().nospace() << "Tab n°" << index << " was double clicked";
logDebug() << "Tab n°" << index << " was double clicked";
AbstractDocumentView *current = getTab(index);
current->openProperties();
}
......@@ -226,7 +226,7 @@ MainWindow::saveFile() noexcept
}
catch (const std::runtime_error &e) {
qCritical() << "Failed to save current document:" << e.what();
logError() << "Failed to save current document: " << e.what();
}
}
......@@ -248,7 +248,7 @@ MainWindow::renameFile() noexcept
}
catch (const std::runtime_error &e) {
qCritical() << "Failed to save current document:" << e.what();
logError() << "Failed to save current document: " << e.what();
}
}
......@@ -270,7 +270,7 @@ MainWindow::saveFileAs() noexcept
}
catch (const std::runtime_error &e) {
qCritical() << "Failed to save current document:" << e.what();
logError() << "Failed to save current document: " << e.what();
}
}
......@@ -300,7 +300,7 @@ MainWindow::closeDocument(int index) noexcept
&MainWindow::documentViewActionsChanged);
if (documentToClose) {
qDebug() << "Delete document view" << documentToClose->getDocumentTabName();
logDebug() << "Delete document view " << documentToClose->getDocumentTabName();
documentToClose->closeDocument();
delete documentToClose;
}
......@@ -313,7 +313,7 @@ MainWindow::newDocument() noexcept
addTab(new VivyDocumentView(
vivyApp->documentStore.newDocument(VivyDocument::UntouchedByDefault), documents));
} catch (const std::runtime_error &e) {
qCritical() << "Failed to create a new empty document:" << e.what();
logError() << "Failed to create a new empty document: " << e.what();
}
}
......@@ -323,7 +323,7 @@ MainWindow::openDocument() noexcept
const QString filename = dialogOpenFileName("Select a document to open", QDir::homePath(),
Utils::getAnyTopLevelDocumentFileSuffixFilter());
if (filename.isEmpty()) {
qWarning() << "Found an empty filename, don't open a file";
logDebug() << "Found an empty filename, don't open a file";
return;
}
......@@ -331,7 +331,7 @@ MainWindow::openDocument() noexcept
Utils::DocumentType fileType;
if (!Utils::detectDocumentType(fileInfo, &fileType)) {
qWarning() << "Failed to detect file type for" << filename;
logWarning() << "Failed to detect file type for " << filename;
return;
}
......@@ -353,7 +353,7 @@ MainWindow::openDocument() noexcept
addTab(newView);
}
} catch (const std::runtime_error &e) {
qCritical() << "Failed to load document" << filename << "with error:" << e.what();
logError() << "Failed to load document " << filename << " with error: " << e.what();
}
}
......@@ -420,7 +420,7 @@ MainWindow::addTab(AbstractDocumentView *const tab)
}
});
documentViewActionsChanged();
qDebug() << "View constructed successfully";
logDebug() << "View constructed successfully";
}
int
......@@ -487,19 +487,19 @@ MainWindow::findFirstUntouchedDocument() const noexcept
void
MainWindow::documentViewActionsChanged() noexcept
{
qInfo() << "Document view action changed";
logDebug() << "Document view action changed";
viewMenu->clear();
// Change document view menu if we have a document
try {
viewMenu->addActions(getCurrentDocumentView()->getViewsActions());
} catch (const std::runtime_error &e) {
qInfo() << "No view to display:" << e.what();
logDebug() << "No view to display: " << e.what();
}
}
static inline QString
executeDialog(MainWindow *const self, QFileDialog *const dialog) noexcept
QString
MainWindow::executeDialog(MainWindow *const self, QFileDialog *const dialog) noexcept
{
bool dialogAccepted = false;
std::unique_ptr<VivyFileIconProvider> iconProvider(new VivyFileIconProvider());
......@@ -515,7 +515,7 @@ executeDialog(MainWindow *const self, QFileDialog *const dialog) noexcept
const QStringList resList = dialog->selectedFiles();
if (resList.size() != 1) {
qCritical() << "You must select only one file";
self->logError() << "You must select only one file";
return QStringLiteral("");
}
......
......@@ -4,7 +4,9 @@
#error "This is a C++ header"
#endif
#include "../VivyApplication.hh"
#include "../Lib/Utils.hh"
#include "../Lib/Log.hh"
#include "../Lib/AbstractDocument.hh"
#include "../Lib/Document/VivyDocumentStore.hh"
#include "DocumentViews/AudioVisualizer.hh"
......@@ -17,6 +19,7 @@ class AboutWindow;
class MainWindow final : public QMainWindow {
Q_OBJECT
VIVY_APP_LOGGABLE_OBJECT(MainWindow, logger)
QTabWidget *documents{ nullptr };
QMenu *viewMenu{ nullptr };
......@@ -54,6 +57,8 @@ private:
QString dialogSaveFileName(const QString &title, const QString &folder,
const QString &filter) noexcept;
QString executeDialog(MainWindow *const self, QFileDialog *const dialog) noexcept;
// Do an action with the selected filename. The 'call' variable must be
// callable like this: call(DocumentView, Document, QString)
template <typename DV, typename D>
......@@ -62,7 +67,7 @@ private:
const QString filename = dialogOpenFileName(title, QDir::homePath(), filter);
if (filename.isEmpty()) {
qWarning() << "Found an empty filename, don't open a file";
logWarning() << "Found an empty filename, don't open a file";
return;
}
......@@ -74,7 +79,7 @@ private:
call(view, doc, filename);
}
} catch (const std::runtime_error &e) {
qCritical() << "Operation failed with:" << e.what();
logError() << "Operation failed with: " << e.what();
}
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter