KIO
sessiondata.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 2000 Dawit Alemayehu <adawit@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Lesser General Public 00006 License (LGPL) as published by the Free Software Foundation; 00007 either version 2 of the License, or (at your option) any 00008 later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; see the file COPYING.LIB. If not, 00017 write to the Free Software Foundation, Inc., 51 Franklin Street, 00018 Fifth Floor, Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "sessiondata.h" 00022 #include "sessiondata.moc" 00023 00024 #include <QtCore/QList> 00025 #include <QtCore/QTextCodec> 00026 00027 #include <kdebug.h> 00028 #include <kconfiggroup.h> 00029 #include <kglobal.h> 00030 #include <klocale.h> 00031 #include <kcharsets.h> 00032 #include <kprotocolmanager.h> 00033 #include <ksharedconfig.h> 00034 #include <kstandarddirs.h> 00035 00036 #include <kdesu/client.h> 00037 #include <kio/slaveconfig.h> 00038 #include <kio/http_slave_defaults.h> 00039 00040 namespace KIO { 00041 00042 /***************************** SessionData::AuthData ************************/ 00043 struct SessionData::AuthData 00044 { 00045 00046 public: 00047 AuthData() {} 00048 00049 AuthData(const QByteArray& k, const QByteArray& g, bool p) { 00050 key = k; 00051 group = g; 00052 persist = p; 00053 } 00054 00055 bool isKeyMatch( const QByteArray& val ) const { 00056 return (val==key); 00057 } 00058 00059 bool isGroupMatch( const QByteArray& val ) const { 00060 return (val==group); 00061 } 00062 00063 QByteArray key; 00064 QByteArray group; 00065 bool persist; 00066 }; 00067 00068 /********************************* SessionData ****************************/ 00069 00070 class SessionData::SessionDataPrivate 00071 { 00072 public: 00073 SessionDataPrivate() { 00074 useCookie = true; 00075 initDone = false; 00076 } 00077 00078 bool initDone; 00079 bool useCookie; 00080 QString charsets; 00081 QString language; 00082 }; 00083 00084 SessionData::SessionData() 00085 :d(new SessionDataPrivate) 00086 { 00087 // authData = 0; 00088 } 00089 00090 SessionData::~SessionData() 00091 { 00092 delete d; 00093 } 00094 00095 void SessionData::configDataFor( MetaData &configData, const QString &proto, 00096 const QString & ) 00097 { 00098 if ( (proto.startsWith(QLatin1String("http"), Qt::CaseInsensitive)) || 00099 (proto.startsWith(QLatin1String("webdav"), Qt::CaseInsensitive)) ) 00100 { 00101 if (!d->initDone) 00102 reset(); 00103 00104 // These might have already been set so check first 00105 // to make sure that we do not trumpt settings sent 00106 // by apps or end-user. 00107 if ( configData["Cookies"].isEmpty() ) 00108 configData["Cookies"] = d->useCookie ? "true" : "false"; 00109 if ( configData["Languages"].isEmpty() ) 00110 configData["Languages"] = d->language; 00111 if ( configData["Charsets"].isEmpty() ) 00112 configData["Charsets"] = d->charsets; 00113 if ( configData["CacheDir"].isEmpty() ) 00114 configData["CacheDir"] = KGlobal::dirs()->saveLocation("cache", "http"); 00115 if ( configData["UserAgent"].isEmpty() ) 00116 configData["UserAgent"] = KProtocolManager::defaultUserAgent(); 00117 } 00118 } 00119 00120 void SessionData::reset() 00121 { 00122 d->initDone = true; 00123 // Get Cookie settings... 00124 d->useCookie = KSharedConfig::openConfig("kcookiejarrc", KConfig::NoGlobals)-> 00125 group("Cookie Policy"). 00126 readEntry("Cookies", true); 00127 00128 d->language = KProtocolManager::acceptLanguagesHeader(); 00129 d->charsets = QString::fromLatin1(QTextCodec::codecForLocale()->name()).toLower(); 00130 KProtocolManager::reparseConfiguration(); 00131 } 00132 00133 }
KDE 4.6 API Reference