[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: kde 3.3 / konqueror / css / font parsing
From: Thomas =?iso-8859-15?q?L=FCbking?= <thomas.luebking () web ! de>
Date: 2004-08-29 19:24:11
Message-ID: 200408292124.11718.thomas.luebking () web ! de
[Download RAW message or body]
On Saturday 28 August 2004 11:40, Esben Mose Hansen wrote:
here it is - rather simple patch.
currently full of explanations and debug messages - as i'm not 100% sure if i
handled any kind of querky url.
But be carefull, it slowdowns the userStyleSheet() function from
khtml_settings.cpp - this is no problem for khtml (it's only called useless
once - when reloading the page) but i don't know if other libraries call this
function.
Furthermore it works on all protocols and i changed the local css override dir
to ~/.userCSS to allow sharing this functionality with other browsers (if
there's need for it)
Regards,
Thomas
oh, btw:
do you know how to diff directories without getting those "only in..."
messages? (couldn't get that out of the manpage)
--
Think, think different. But essentially: Think!
["userCSS.diff" (text/x-diff)]
diff --unified backup/khtml_part.cpp ./khtml_part.cpp
--- backup/khtml_part.cpp 2004-08-09 11:25:45.000000000 +0200
+++ ./khtml_part.cpp 2004-08-29 16:52:40.000000000 +0200
@@ -661,8 +661,8 @@
// 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() );
+ if ( args.reload && !settings()->userStyleSheet(&url).isEmpty() ) {
+ KURL url( settings()->userStyleSheet(&url) );
KIO::StatJob *job = KIO::stat( url, false /* don't show progress */ );
connect( job, SIGNAL( result( KIO::Job * ) ),
this, SLOT( slotUserSheetStatDone( KIO::Job * ) ) );
@@ -1716,7 +1716,7 @@
d->m_paUseStylesheet->setEnabled( false );
setAutoloadImages( KHTMLFactory::defaultHTMLSettings()->autoLoadImages() );
- QString userStyleSheet = KHTMLFactory::defaultHTMLSettings()->userStyleSheet();
+ QString userStyleSheet = \
KHTMLFactory::defaultHTMLSettings()->userStyleSheet(&url); if ( \
!userStyleSheet.isEmpty() ) setUserStyleSheet( KURL( userStyleSheet ) );
diff --unified backup/khtml_settings.cc ./khtml_settings.cc
--- backup/khtml_settings.cc 2004-06-22 19:36:38.000000000 +0200
+++ ./khtml_settings.cc 2004-08-29 20:43:59.000000000 +0200
@@ -27,6 +27,10 @@
#include <klocale.h>
#include <kdebug.h>
#include <qregexp.h>
+//userCSS stuff
+#include <qfile.h>
+#include <qdir.h>
+#include <kurl.h>
/**
* @internal
@@ -781,8 +785,87 @@
d->fonts[1] = n;
}
-QString KHTMLSettings::userStyleSheet() const
+QString KHTMLSettings::userStyleSheet(const KURL *url) const
{
+ //ok, that's it:
+ //the function takes an url, parses it left to right and tries to find a \
corresponding local css file + //unfortunately, this makes the whole function \
"slightly" slower than just returning a static value... + //so you should avoid to \
call the function several times and instead store the value you got once... + if \
(url){ + QString userCSS = url->protocol();
+ if (!userCSS.isNull()){
+ // i decided to use this path in homedir if this functionality should be \
shared among different browsers... + userCSS.prepend("/.userCSS/");
+ userCSS.prepend(QDir::homeDirPath());
+ // check if there's demand for this protocol (e.g. avoid "file" if the \
user has no such css override) + if (QFile::exists(userCSS)){
+ qWarning("have protocol: %s", userCSS.ascii());
+ QString fullPath = url->path();
+ if (url->hasHost()){
+ fullPath.prepend(url->host());
+ fullPath.prepend("/");
+ }
+ // ok, now we have the path that should be found in \
~/.userCSS/<protocol> - let's parse it :) + int i = 1; bool done = \
false; bool haveDir = false; bool haveFile = false; QString section; QDir localDir; + \
QString testString = userCSS; //this little buddy will help us to look ahead without \
loosing the found path... + qWarning("parsing path: \
%s",fullPath.ascii()); + while (!done){
+ section = fullPath.section('/',i,i);
+ qWarning("found section: %s",section.ascii());
+ if (!section.isEmpty()){
+ qWarning("found new path element");
+ testString.append("/");
+ testString.append(section);
+ localDir = testString;
+ if (localDir.exists()){ // we found a local dir
+ qWarning("found new dir: %s", testString.ascii());
+ haveDir = true;
+ userCSS = testString;
+ done = false;
+ }
+ else { // no dir found - let's see if there's a usefull file
+ testString.append(".css");
+ if (QFile::exists(testString)){ // we found a local file \
- yeeehaahh + qWarning("found individual override \
file: %s", testString.ascii()); + haveDir = false;
+ haveFile = true;
+ userCSS = testString;
+ done = true;
+ }
+ else { // didn't find anything - try fallback
+ userCSS.append("/override.css");
+ if (QFile::exists(userCSS)){ // found override css
+ qWarning("found general override file: %s", \
userCSS.ascii()); + haveFile = true;
+ haveDir = false;
+ done = true;
+ }
+ }
+ }
+ i++;
+ }
+ else { // end of url - is there an override file in the latest \
found dir? + done = true;
+ if (haveDir){
+ testString.append("/override.css");
+ if (QFile::exists(testString)){ // found override css
+ qWarning("found general override file (end of path): \
%s", testString.ascii()); + haveFile = true;
+ haveDir = false;
+ userCSS = testString;
+ done = true;
+ }
+ }
+ }
+ }
+ qWarning("...done");
+ if (haveFile){
+ qWarning("returning user CSS file: %s", userCSS.ascii());
+ return userCSS;
+ }
+ }
+ }
+ } // fallback to common css override (if any)
return d->m_userSheet;
}
diff --unified backup/khtml_settings.h ./khtml_settings.h
--- backup/khtml_settings.h 2004-06-22 19:36:38.000000000 +0200
+++ ./khtml_settings.h 2004-08-29 15:07:02.000000000 +0200
@@ -29,6 +29,7 @@
struct KPerDomainSettings;
class KHTMLSettingsPrivate;
+class KURL;
/**
* Settings for the HTML view.
@@ -184,7 +185,7 @@
QString settingsToCSS() const;
static const QString &availableFamilies();
- QString userStyleSheet() const;
+ QString userStyleSheet(const KURL *url = 0L) const;
// Form completion
bool isFormCompletionEnabled() const;
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic