From kde-devel Tue Aug 31 21:53:48 2004 From: Thomas =?iso-8859-15?q?L=FCbking?= Date: Tue, 31 Aug 2004 21:53:48 +0000 To: kde-devel Subject: Re: kde 3.3 / konqueror / css / font parsing Message-Id: <200408312353.48410.thomas.luebking () web ! de> X-MARC-Message: https://marc.info/?l=kde-devel&m=109398912427991 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_sNPNBM8rWHIvlmM" --Boundary-00=_sNPNBM8rWHIvlmM Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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! --Boundary-00=_sNPNBM8rWHIvlmM Content-Type: text/x-diff; charset="iso-8859-15"; name="userCSS.2.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="userCSS.2.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 #include #include +//userCSS stuff +#include +#include +#include +#include /** * @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/ - 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; --Boundary-00=_sNPNBM8rWHIvlmM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe << --Boundary-00=_sNPNBM8rWHIvlmM--