SocketApi: Improve logging
authorJocelyn Turcotte <jturcotte@woboq.com>
Tue, 4 Jul 2017 14:41:40 +0000 (16:41 +0200)
committerChristian Kamm <mail@ckamm.de>
Fri, 7 Jul 2017 08:49:51 +0000 (10:49 +0200)
src/gui/guiutility.cpp
src/gui/socketapi.cpp

index 27fe54897b05224f9b1e1b0b2dde020ce54622aa..f4b31a7af235acaa1b3aa7c58d403d838e77677d 100644 (file)
 #include <QClipboard>
 #include <QApplication>
 #include <QDesktopServices>
+#include <QLoggingCategory>
 #include <QMessageBox>
 
 using namespace OCC;
 
+Q_LOGGING_CATEGORY(lcUtility, "gui.utility", QtInfoMsg)
+
 bool Utility::openBrowser(const QUrl &url, QWidget *errorWidgetParent)
 {
-    if (!QDesktopServices::openUrl(url) && errorWidgetParent) {
-        QMessageBox::warning(
-            errorWidgetParent,
-            QCoreApplication::translate("utility", "Could not open browser"),
-            QCoreApplication::translate("utility",
-                "There was an error when launching the browser to go to "
-                "URL %1. Maybe no default browser is configured?")
-                .arg(url.toString()));
+    if (!QDesktopServices::openUrl(url)) {
+        if (errorWidgetParent) {
+            QMessageBox::warning(
+                errorWidgetParent,
+                QCoreApplication::translate("utility", "Could not open browser"),
+                QCoreApplication::translate("utility",
+                    "There was an error when launching the browser to go to "
+                    "URL %1. Maybe no default browser is configured?")
+                    .arg(url.toString()));
+        }
+        qCWarning(lcUtility) << "QDesktopServices::openUrl failed for" << url;
         return false;
     }
     return true;
@@ -42,14 +48,17 @@ bool Utility::openEmailComposer(const QString &subject, const QString &body, QWi
     url.setQueryItems({ { QLatin1String("subject"), subject },
         { QLatin1String("body"), body } });
 
-    if (!QDesktopServices::openUrl(url) && errorWidgetParent) {
-        QMessageBox::warning(
-            errorWidgetParent,
-            QCoreApplication::translate("utility", "Could not open email client"),
-            QCoreApplication::translate("utility",
-                "There was an error when launching the email client to "
-                "create a new message. Maybe no default email client is "
-                "configured?"));
+    if (!QDesktopServices::openUrl(url)) {
+        if (errorWidgetParent) {
+            QMessageBox::warning(
+                errorWidgetParent,
+                QCoreApplication::translate("utility", "Could not open email client"),
+                QCoreApplication::translate("utility",
+                    "There was an error when launching the email client to "
+                    "create a new message. Maybe no default email client is "
+                    "configured?"));
+        }
+        qCWarning(lcUtility) << "QDesktopServices::openUrl failed for" << url;
         return false;
     }
     return true;
index bf4e75d3b067fd6ae6e26a1d0ef4449d35005512..ccfe5167eb4a3e564a7110e95450c715d23a335d 100644 (file)
@@ -128,7 +128,7 @@ public:
 
     void sendMessage(const QString &message, bool doWait = false) const
     {
-        qCInfo(lcSocketApi) << "Sending SocketAPI message" << message << "to" << socket;
+        qCInfo(lcSocketApi) << "Sending SocketAPI message -->" << message << "to" << socket;
         QString localMessage = message;
         if (!localMessage.endsWith(QLatin1Char('\n'))) {
             localMessage.append(QLatin1Char('\n'));
@@ -282,6 +282,7 @@ void SocketApi::slotReadSocket()
         // make sure that the path will match, especially on OS X.
         QString line = QString::fromUtf8(socket->readLine()).normalized(QString::NormalizationForm_C);
         line.chop(1); // remove the '\n'
+        qCInfo(lcSocketApi) << "Received SocketAPI message <--" << line << "from" << socket;
         QByteArray command = line.split(":").value(0).toAscii();
         QByteArray functionWithArguments = "command_" + command + "(QString,SocketListener*)";
         int indexOfMethod = staticMetaObject.indexOfMethod(functionWithArguments);
@@ -373,8 +374,6 @@ void SocketApi::command_RETRIEVE_FOLDER_STATUS(const QString &argument, SocketLi
 
 void SocketApi::command_RETRIEVE_FILE_STATUS(const QString &argument, SocketListener *listener)
 {
-    qCDebug(lcSocketApi) << argument;
-
     QString statusString;
 
     Folder *syncFolder = FolderMan::instance()->folderForPath(argument);
@@ -403,8 +402,6 @@ void SocketApi::command_RETRIEVE_FILE_STATUS(const QString &argument, SocketList
 
 void SocketApi::command_SHARE(const QString &localFile, SocketListener *listener)
 {
-    qCDebug(lcSocketApi) << localFile;
-
     auto theme = Theme::instance();
 
     Folder *shareFolder = FolderMan::instance()->folderForPath(localFile);
@@ -454,8 +451,6 @@ void SocketApi::command_VERSION(const QString &, SocketListener *listener)
 
 void SocketApi::command_SHARE_STATUS(const QString &localFile, SocketListener *listener)
 {
-    qCDebug(lcSocketApi) << localFile;
-
     Folder *shareFolder = FolderMan::instance()->folderForPath(localFile);
 
     if (!shareFolder) {