Bug 131782 - Log on project event does not work
Summary: Log on project event does not work
Status: RESOLVED FIXED
Alias: None
Product: quanta
Classification: Miscellaneous
Component: general (show other bugs)
Version: unspecified
Platform: Debian stable Linux
: NOR normal
Target Milestone: ---
Assignee: András Manţia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-03 16:11 UTC by Yuri
Modified: 2006-09-02 20:58 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri 2006-08-03 16:11:07 UTC
Version:           3.5.2 and 3.5.3 (using KDE KDE 3.5.2)
Installed from:    Debian stable Packages

This is how to reproduce this bug:
-create a project and add some files to it
-go to project options (Shift-F7)
-click on the tab: "Event Configuration"
-click on "Add"
-choose "After Document Close" for "Event"
-choose "Log Event" for "Action"
-choose "/tmp/log.txt" for "Log file"
-choose "Full" for "Detail"
-choose "Append to Existing Log" for "Behavior"

-Open a file
Note how a warning pops up that "An internal action (log) associated with an event (after_close) will be executed."
This is strange, as we're currently only opening the file, not closing it. Anyhow:
-Click on "Execute"
-Close the file
Note how a warning pops up again
-Click on "Execute"

Note how NO file has been created under /tmp/log.txt :
"yuri@magnus-ii:~$ ls /tmp/log.txt
ls: /tmp/log.txt: Unknown file or folder"

So there are in fact two bugs as far as I can think of:
1. The warning for execution comes at the wrong time (does it do anything when I hit Execute?)
2. There is nothing being logged, rendering this option useless.

I've tried with different combinations:
- saving to a different location (my own home dir for instance)
- using a different event (on document open)
- use a different version of quanta (both 3.5.2 and 3.5.3 are broken)
But still the same results.
Comment 1 Yuri 2006-08-09 17:31:34 UTC
I really wanted to know if this works, so I finally decided to install kdevelop etc, and download the sources.
I see in utility/qpevents.cpp on line 276:
if (!logFile.startsWith("/"))

When you enter a filename starting with a / as I did, this line of code prevents the logging from happening. The only reason for this check to be there I can think of is security. You probably don't want the logging to happen over /etc/passwd etc...
It would be nice though that the user would get some feedback that the logging isn't happening because of this. I'd probably add after line 314 (in the else branch of the above mentioned 'if'):
KMessageBox::sorry(0L, i18n("Logging is only allowed in the project directory."));

Conclusion:
1. The warning for execution still comes at the wrong time
2. Logging is not allowed outside of the project directory. Unfortunately there is no warning that nothing is logged if a filename was specified outside of the project directory.
Comment 2 András Manţia 2006-09-02 16:05:37 UTC
SVN commit 580055 by amantia:

- allow logging to files outside of project directory
- don't send closing events for untitled, unmodified documents
BUG: 131782


 M  +2 -0      ChangeLog  
 M  +7 -2      src/quantaview.cpp  
 M  +46 -47    utility/qpevents.cpp  


--- branches/KDE/3.5/kdewebdev/quanta/ChangeLog #580054:580055
@@ -12,6 +12,8 @@
       - show the correct column number if tabs are used in the document [#133313]
       - only one upload dialog can be shown at any time [#132535]
       - do not show Find in Files menu if KFileReplace is not installed [#132530]
+      - allow logging to files outside of project directory [#131782]
+      - don't send closing events for untitled, unmodified documents [#131782]
 
 Version 3.5.4 (Release date: 02-08-2006; Started 24-06-2005):
  - bugfixes:
--- branches/KDE/3.5/kdewebdev/quanta/src/quantaview.cpp #580054:580055
@@ -132,6 +132,9 @@
     m_plugin->unload(false);
   } else
   {
+    bool unmodifiedUntitled = false;
+    if (m_document && m_document->isUntitled() && !m_document->isModified())
+      unmodifiedUntitled = true;
     if (m_customWidget)
         m_customWidget->reparent(0L, 0, QPoint(), false);
     if (!saveModified())
@@ -149,7 +152,8 @@
     {
       KURL url = m_document->url();
       Project::ref()->saveBookmarks(url, dynamic_cast<KTextEditor::MarkInterface*>(m_document->doc()));
-      emit eventHappened("before_close", url.url(), QString::null);
+      if (!unmodifiedUntitled)
+        emit eventHappened("before_close", url.url(), QString::null);
       m_currentViewsLayout = -1;
 //      m_document->closeTempFile();
       if (!m_document->isUntitled() && url.isLocalFile())
@@ -161,7 +165,8 @@
 
       quantaApp->menuBar()->activateItemAt(-1);
       quantaApp->guiFactory()->removeClient(m_document->view());
-      emit eventHappened("after_close", url.url(), QString::null);
+      if (!unmodifiedUntitled)
+        emit eventHappened("after_close", url.url(), QString::null);
     }
 /*      kdDebug(24000) << "Calling reparse from close " << endl;
       parser->setSAParserEnabled(true);
--- branches/KDE/3.5/kdewebdev/quanta/utility/qpevents.cpp #580054:580055
@@ -104,7 +104,7 @@
               ev.arguments << i18n("An upload was initiated");
               ev.arguments << url.path();
               handleEvent(ev);
-            } 
+            }
         }
         if (inProject && url2.isValid())
         {
@@ -266,53 +266,52 @@
     }
     if (ev.action == "log")
     {
-       QString logFile = ev.arguments[0];
-       KURL url = KURL::fromPathOrURL(logFile);
-       if (url.isValid() && !url.isLocalFile())
-       {
-          KMessageBox::sorry(0L, i18n("Logging to remote files is not supported."));
+      QString logFile = ev.arguments[0];
+      KURL url = KURL::fromPathOrURL(logFile);
+      if (url.isValid() && !url.isLocalFile())
+      {
+        KMessageBox::sorry(0L, i18n("Logging to remote files is not supported."));
+        return false;
+      }
+      if (!logFile.startsWith("/"))
+      {
+        url = Project::ref()->projectBaseURL();
+        url.addPath(logFile);
+        if (!url.isLocalFile())
+        {
+          KMessageBox::sorry(0L, i18n("Logging to files inside a remote project is not supported."));
           return false;
-       }
-       if (!logFile.startsWith("/"))
-       {
-          url = Project::ref()->projectBaseURL();
-          url.addPath(logFile);
-          if (!url.isLocalFile())
-          {
-            KMessageBox::sorry(0L, i18n("Logging to files inside a remote project is not supported."));
-            return false;
-          }
-          QFile file(url.path());
-          bool result;
-          if (ev.arguments[2] == "create_new")
-            result = file.open(IO_WriteOnly);
-          else
-            result = file.open(IO_WriteOnly | IO_Append);
-          if (result)
-          {
-            QTextStream stream(&file);
-            //Note: the log text should not be translated.
-            QString s = QDateTime::currentDateTime().toString(Qt::ISODate) + ": ";
-            s.append( "Event : " + m_eventName + " : ");
-            s.append( "Action: " + ev.action + " : ");
-            if (ev.arguments[1] == "full")
-            {
-              s.append( "Arguments: ");
-              for (uint i = 1; i < ev.arguments.count(); i++)
-                s.append(ev.arguments[i] + " | ");
-            }
-            s[s.length() - 1] = '\n';
-            stream << s;
-            file.close();
-          }
-          if (!result)
-          {
-            KMessageBox::sorry(0L, i18n("<qt>Logging failed. Check that you have write access to <i>%1</i>.").arg(url.prettyURL(KURL::StripFileProtocol)));
-            return false;
-          }
-       } else
-       {
-       }
+        }
+      }
+      QFile file(url.path());
+      bool result;
+      if (ev.arguments[2] == "create_new")
+        result = file.open(IO_WriteOnly);
+      else
+        result = file.open(IO_WriteOnly | IO_Append);
+      if (result)
+      {
+        QTextStream stream(&file);
+        stream.setEncoding(QTextStream::UnicodeUTF8);
+        //Note: the log text should not be translated.
+        QString s = QDateTime::currentDateTime().toString(Qt::ISODate) + ": ";
+        s.append( "Event : " + m_eventName + " : ");
+        s.append( "Action: " + ev.action + " : ");
+        if (ev.arguments[1] == "full")
+        {
+          s.append( "Arguments: ");
+          for (uint i = 1; i < ev.arguments.count(); i++)
+            s.append(ev.arguments[i] + " | ");
+        }
+        s[s.length() - 1] = '\n';
+        stream << s;
+        file.close();
+      }
+      if (!result)
+      {
+        KMessageBox::sorry(0L, i18n("<qt>Logging failed. Check that you have write access to <i>%1</i>.").arg(url.path()));
+        return false;
+      }
     } else
       KMessageBox::sorry(0L, i18n("<qt>Unsupported internal event action : <b>%1</b>.</qt>").arg(ev.action));
   } else
Comment 3 Yuri 2006-09-02 20:58:56 UTC
This is great Andras, thanks a lot!