Bug 39962 - user defined stylesheet updates ignored
Summary: user defined stylesheet updates ignored
Status: RESOLVED FIXED
Alias: None
Product: konqueror
Classification: Applications
Component: khtml (show other bugs)
Version: unspecified
Platform: Compiled Sources Other
: NOR minor
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-03-31 13:03 UTC by Daniel Naber
Modified: 2004-02-22 16:44 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Proposed patch to implement this (3.10 KB, patch)
2004-02-22 03:59 UTC, Frerich Raabe
Details
Proposed patch to implement this (3.15 KB, patch)
2004-02-22 12:30 UTC, Frerich Raabe
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Naber 2002-03-31 12:49:31 UTC
(*** This bug was imported into bugs.kde.org ***)

Package:           khtml
Version:           KDE 3.0.5 CVS/CVSup/Snapshot
Severity:          wishlist
Installed from:    Compiled sources
Compiler:          Not Specified
OS:                Not Specified
OS/Compiler notes: Not Specified

Developing user defined stylesheets is not as easy as it should be beaause changes in the stylesheet file don't take effect unless konqueror gets restarted. I suggest to reload the user stylsheet whenever the user explicitly reloads the current html page.


(Submitted via bugs.kde.org)
Comment 1 Jim Dabell 2002-11-14 19:07:50 UTC
There are a number of options: 
 
1.  Detect when the file has changed and rerender all documents. 
 
2.  Detect when the file has changed, and apply the new one for all subsequent 
document renderings. 
 
3.  Check the user stylesheet for changes on each document rendering (similar to 2). 
 
4.  Provide DCOP interface to provide notification of changes to user stylesheet. 
 
 
I'd prefer 2 & 4. 
Comment 2 Frerich Raabe 2004-02-22 03:59:29 UTC
Created attachment 4831 [details]
Proposed patch to implement this

This patch attempts to make KHTML check whether the user-defined stylesheet was
changed since the last URL was opened and reload it if necessary. This only
happens when the "Reload" button in Konqueror is pressed though, to avoid
calling stat too often.

The patch seems to work quite well with today's khtml CVS version, even though
I had some occasional crashes a few days ago. I can't reproduce the crashes at
all anymore, but I cannot tell whether they were fixed and what fixed them.
Hence, this patch is to be taken with a pinch of salt.
Comment 3 Frerich Raabe 2004-02-22 12:30:09 UTC
Created attachment 4835 [details]
Proposed patch to implement this

This is patch supersedes the previous one (ID 4831); the "slotStatDone" slot
was renamed to "slotUserSheetStatDone". Also, slotUserSheetStatDone now checks
for whether there was an error with the job (if so, call showError and bail
out). Finally, if slotUserSheetStatDone failed to retrieve the modification
time from the job's UDS entry, it'll always reload the stylesheet.
Comment 4 Frerich Raabe 2004-02-22 16:44:15 UTC
CVS commit by raabe: 

- In case the openURL call is a reload, do a stat on the user-defined
  stylesheet and reload it in case it changed in the meanwhile.
CCMAIL:39962-done@bugs.kde.org


  M +9 -0      ChangeLog   1.213
  M +40 -0     khtml_part.cpp   1.975
  M +6 -1      khtml_part.h   1.250
  M +2 -0      khtmlpart_p.h   1.52


--- kdelibs/khtml/ChangeLog  #1.212:1.213
@@ -1,2 +1,11 @@
+2004-02-22  Frerich Raabe  <raabe@kde.org>
+
+        * khtml_part.cpp/.h (openURL): In case the call is a reload, do a stat
+        on the user-defined stylesheet and reload it in case it changed in
+        the meanwhile (#39962).
+        * khtmlpart_p.h (class KHTMLPartPrivate): Added
+        m_userStyleSheetLastModified variable which keeps track of the
+        mtime of the user-defined sheet.
+
 2004-02-20  Germain Garand  <germain@ebooksfrance.org>
 

--- kdelibs/khtml/khtml_part.cpp  #1.974:1.975
@@ -633,4 +633,13 @@ bool KHTMLPart::openURL( const KURL &url
 
   d->m_jobspeed = 0;
+
+  // If this was an explicit reload and the user style sheet should be used,
+  // do a stat to see whether the stylesheet was changed in the meanwhile.
+  if ( args.reload && !settings()->userStyleSheet().isEmpty() ) {
+    KURL url( settings()->userStyleSheet() );
+    KIO::StatJob *job = KIO::stat( url, false /* don't show progress */ );
+    connect( job, SIGNAL( result( KIO::Job * ) ),
+             this, SLOT( slotUserSheetStatDone( KIO::Job * ) ) );
+  }
   emit started( 0L );
 
@@ -1872,4 +1881,35 @@ void KHTMLPart::slotJobDone( KIO::Job* /
 }
 
+void KHTMLPart::slotUserSheetStatDone( KIO::Job *_job )
+{
+  using namespace KIO;
+
+  if ( _job->error() ) {
+    showError( _job );
+    return;
+  }
+
+  const UDSEntry entry = dynamic_cast<KIO::StatJob *>( _job )->statResult();
+  UDSEntry::ConstIterator it = entry.begin();
+  UDSEntry::ConstIterator end = entry.end();
+  for ( ; it != end; ++it ) {
+    if ( ( *it ).m_uds == UDS_MODIFICATION_TIME ) {
+     break;
+    }
+  }
+
+  // If the filesystem supports modification times, only reload the
+  // user-defined stylesheet if necessary - otherwise always reload.
+  if ( it != end ) {
+    const time_t lastModified = static_cast<time_t>( ( *it ).m_long );
+    if ( d->m_userStyleSheetLastModified >= lastModified ) {
+      return;
+    }
+    d->m_userStyleSheetLastModified = lastModified;
+  }
+
+  setUserStyleSheet( KURL( settings()->userStyleSheet() ) );
+}
+
 void KHTMLPart::checkCompleted()
 {

--- kdelibs/khtml/khtml_part.h  #1.249:1.250
@@ -1303,4 +1303,9 @@ private slots:
    * @internal
    */
+  void slotUserSheetStatDone( KIO::Job* );
+
+  /*
+   * @internal
+   */
   void slotJobSpeed( KIO::Job*, unsigned long );
 

--- kdelibs/khtml/khtmlpart_p.h  #1.51:1.52
@@ -207,4 +207,5 @@ public:
     m_statusBarWalletLabel = 0L;
     m_statusBarJSErrorLabel = 0L;
+    m_userStyleSheetLastModified = 0;
   }
   ~KHTMLPartPrivate()
@@ -466,4 +467,5 @@ public:
   }
 
+  time_t m_userStyleSheetLastModified;
 };