[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-31 21:53:48
Message-ID: 200408312353.48410.thomas.luebking () web ! de
[Download RAW message or body]
On Tuesday 31 August 2004 22:37, Esben Mose Hansen wrote:
> P.S: Can I get your newest patch somewhere? :o)
Jupp, attached to this mail. (against plain 3.3)
- Changed dir to ~/.kde/share/apps/khtml/userCSS
- removed prepends ;)
- jumps faster out of search loop if possible (stupid bug)
- removed warnings
- !Important: decodes the domain (www.google.com -> ./com/google/www/, while
still allowing to place overrides in ./com/google to override the whole
domain)
Thomas
--
Think, think different. But essentially: Think!
["userCSS.2.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-31 23:28:17.000000000 +0200
@@ -27,6 +27,11 @@
#include <klocale.h>
#include <kdebug.h>
#include <qregexp.h>
+//userCSS stuff
+#include <kstandarddirs.h>
+#include <qfile.h>
+#include <qdir.h>
+#include <kurl.h>
/**
* @internal
@@ -94,6 +99,8 @@
PolicyMap domainPolicy;
QStringList fonts;
QStringList defaultFonts;
+ // userCSS - to avoid multiple useless calls of locateLocal
+ QString localCssDir;
};
@@ -539,6 +546,8 @@
#endif
}
}
+ // init userCSSDir
+ d->localCssDir = locateLocal("data", "khtml/userCSS/");
config->setGroup(group_save);
}
@@ -781,8 +790,94 @@
d->fonts[1] = n;
}
-QString KHTMLSettings::userStyleSheet() const
+QString KHTMLSettings::userStyleSheet(const KURL *url) const
{
+ if (url){
+ QString userCSS = d->localCssDir;
+ if (!userCSS.isNull()){
+ userCSS.append(url->protocol());
+ // check if there's demand for this protocol (e.g. avoid "file" if the \
user has no such css override) + if (QFile::exists(userCSS)){
+ QString fullPath = "";
+ if (url->hasHost()){
+ /* we'll use a reversed host, broken to dirs (so www.google.com \
will become ./com/google/www) + as my freemailer uses several \
subdomains - and has ugly font settings ;)*/ + QString host = \
url->host(); + QString section;
+ QString revHost = "";
+ if (host.contains('.')){
+ bool done = false; int i = -1;
+ while (!done){
+ section = host.section('.',i,i);
+ if (section.isEmpty()){
+ done = true;
+ }
+ else{
+ revHost.append("/");
+ revHost.append(section);
+ }
+ i--;
+ }
+ fullPath.append(revHost);
+ }
+ else{
+ fullPath.append("/");
+ fullPath.append(host);
+ }
+ }
+ fullPath.append(url->path());
+ // ok, now we have the path that should be found in \
~/.kde/share/apps/khtml/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... + while \
(!done){ + section = fullPath.section('/',i,i);
+ if (!section.isEmpty()){
+ testString.append("/");
+ testString.append(section);
+ localDir = testString;
+ if (localDir.exists()){ // we found a local dir
+ 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 + 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
+ 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
+ haveFile = true;
+ haveDir = false;
+ userCSS = testString;
+ done = true;
+ }
+ }
+ }
+ }
+ if (haveFile){
+ 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