• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KIOSlave

kcookiewin.cpp

Go to the documentation of this file.
00001 /*
00002 This file is part of KDE
00003 
00004   Copyright (C) 2000- Waldo Bastian <bastian@kde.org>
00005   Copyright (C) 2000- Dawit Alemayehu <adawit@kde.org>
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00020 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 */
00024 //----------------------------------------------------------------------------
00025 //
00026 // KDE File Manager -- HTTP Cookie Dialogs
00027 
00028 // The purpose of the QT_NO_TOOLTIP and QT_NO_WHATSTHIS ifdefs is because
00029 // this file is also used in Konqueror/Embedded. One of the aims of
00030 // Konqueror/Embedded is to be a small as possible to fit on embedded
00031 // devices. For this it's also useful to strip out unneeded features of
00032 // Qt, like for example QToolTip or QWhatsThis. The availability (or the
00033 // lack thereof) can be determined using these preprocessor defines.
00034 // The same applies to the QT_NO_ACCEL ifdef below. I hope it doesn't make
00035 // too much trouble... (Simon)
00036 
00037 #include "kcookiewin.h"
00038 #include "kcookiejar.h"
00039 
00040 #include <QtGui/QLabel>
00041 #include <QtGui/QLayout>
00042 #include <QtGui/QGroupBox>
00043 #include <QtGui/QPushButton>
00044 #include <QtGui/QRadioButton>
00045 #include <QtGui/QShortcut>
00046 
00047 #include <kwindowsystem.h>
00048 #include <klocale.h>
00049 #include <kglobal.h>
00050 #include <klineedit.h>
00051 #include <kiconloader.h>
00052 #include <kapplication.h>
00053 #include <kwindowsystem.h>
00054 #include <kvbox.h>
00055 #include <kdatetime.h>
00056 
00057 KCookieWin::KCookieWin( QWidget *parent, KHttpCookieList cookieList,
00058                         int defaultButton, bool showDetails )
00059            :KDialog( parent )
00060 {
00061     setModal(true);
00062     setObjectName("cookiealert");
00063     setButtons(Yes|No|Details);
00064 #ifndef Q_WS_QWS //FIXME(E): Implement for Qt Embedded
00065     setCaption( i18n("Cookie Alert") );
00066     setWindowIcon( KIcon("preferences-web-browser-cookies") );
00067     // all cookies in the list should have the same window at this time, so let's take the first
00068     if( cookieList.first().windowIds().count() > 0 )
00069     {
00070 #ifdef Q_WS_WIN
00071         KWindowSystem::setMainWindow( this, reinterpret_cast<WId>( cookieList.first().windowIds().first() ) );
00072 #else
00073         KWindowSystem::setMainWindow( this, cookieList.first().windowIds().first());
00074 #endif
00075     }
00076     else
00077     {
00078         // No window associated... make sure the user notices our dialog.
00079 #ifdef Q_WS_X11
00080         KWindowSystem::setState( winId(), NET::KeepAbove );
00081 #endif
00082         kapp->updateUserTimestamp();
00083     }
00084 #endif
00085     KVBox* vBox1 = new KVBox( this );
00086     vBox1->setSpacing( -1 );
00087     setMainWidget(vBox1);
00088     // Cookie image and message to user
00089     KHBox* hBox = new KHBox( vBox1 );
00090     QLabel* icon = new QLabel( hBox );
00091     icon->setPixmap(KIcon("dialog-warning").pixmap(IconSize(KIconLoader::Desktop)));
00092     icon->setAlignment( Qt::AlignCenter );
00093     icon->setFixedSize( 2*icon->sizeHint() );
00094 
00095     int count = cookieList.count();
00096 
00097     KVBox* vBox = new KVBox( hBox );
00098     QString txt = i18np("You received a cookie from",
00099                        "You received %1 cookies from", count);
00100     QLabel* lbl = new QLabel( txt, vBox );
00101     lbl->setAlignment( Qt::AlignCenter );
00102     const KHttpCookie& cookie = cookieList.first();
00103 
00104     QString host (cookie.host());
00105     int pos = host.indexOf(':');
00106     if ( pos > 0 )
00107     {
00108       QString portNum = host.left(pos);
00109       host.remove(0, pos+1);
00110       host += ':';
00111       host += portNum;
00112     }
00113 
00114     txt = QString("<b>%1</b>").arg( QUrl::fromAce(host.toLatin1()) );
00115     if (cookie.isCrossDomain())
00116        txt += i18n(" <b>[Cross Domain]</b>");
00117     lbl = new QLabel( txt, vBox );
00118     lbl->setAlignment( Qt::AlignCenter );
00119     lbl = new QLabel( i18n("Do you want to accept or reject?"), vBox );
00120     lbl->setAlignment( Qt::AlignCenter );
00121 
00122     // Cookie Details dialog...
00123     m_detailView = new KCookieDetail( cookieList, count, vBox1 );
00124     setDetailsWidget(m_detailView);
00125 
00126     // Cookie policy choice...
00127     QGroupBox *m_btnGrp = new QGroupBox(i18n("Apply Choice To"),vBox1);
00128     QVBoxLayout *vbox = new QVBoxLayout;
00129     txt = (count == 1)? i18n("&Only this cookie") : i18n("&Only these cookies");
00130     m_onlyCookies = new QRadioButton( txt, m_btnGrp );
00131     vbox->addWidget(m_onlyCookies);
00132 #ifndef QT_NO_WHATSTHIS
00133     m_onlyCookies->setWhatsThis(i18n("Select this option to accept/reject only this cookie. "
00134                               "You will be prompted if another cookie is received. "
00135                               "<em>(see WebBrowsing/Cookies in the Control Center)</em>." ) );
00136 #endif
00137     m_allCookiesDomain = new QRadioButton( i18n("All cookies from this do&main"), m_btnGrp );
00138     vbox->addWidget(m_allCookiesDomain);
00139 #ifndef QT_NO_WHATSTHIS
00140     m_allCookiesDomain->setWhatsThis(i18n("Select this option to accept/reject all cookies from "
00141                               "this site. Choosing this option will add a new policy for "
00142                               "the site this cookie originated from. This policy will be "
00143                               "permanent until you manually change it from the Control Center "
00144                               "<em>(see WebBrowsing/Cookies in the Control Center)</em>.") );
00145 #endif
00146     m_allCookies = new QRadioButton( i18n("All &cookies"), m_btnGrp);
00147     vbox->addWidget(m_allCookies);
00148 #ifndef QT_NO_WHATSTHIS
00149     m_allCookies->setWhatsThis(i18n("Select this option to accept/reject all cookies from "
00150                               "anywhere. Choosing this option will change the global "
00151                               "cookie policy set in the Control Center for all cookies "
00152                               "<em>(see WebBrowsing/Cookies in the Control Center)</em>.") );
00153 #endif
00154     m_btnGrp->setLayout(vbox);
00155     if (defaultButton == KCookieJar::ApplyToShownCookiesOnly )
00156     m_onlyCookies->setChecked(true);
00157     else if (defaultButton == KCookieJar::ApplyToCookiesFromDomain)
00158     m_allCookiesDomain->setChecked(true);
00159     else if (defaultButton == KCookieJar::ApplyToAllCookies)
00160     m_allCookies->setChecked(true);
00161     else
00162     m_onlyCookies->setChecked(true);
00163     setButtonText(KDialog::Yes, i18n("&Accept"));
00164     setButtonText(KDialog::No, i18n("&Reject"));
00165     //QShortcut( Qt::Key_Escape, btn, SLOT(animateClick()) );
00166     setButtonToolTip(Details, i18n("See or modify the cookie information") );
00167     setDefaultButton(Yes);
00168 
00169     setDetailsWidgetVisible(showDetails);
00170 }
00171 
00172 KCookieWin::~KCookieWin()
00173 {
00174 }
00175 
00176 KCookieAdvice KCookieWin::advice( KCookieJar *cookiejar, const KHttpCookie& cookie )
00177 {
00178     int result = exec();
00179 
00180     cookiejar->setShowCookieDetails ( isDetailsWidgetVisible() );
00181 
00182     KCookieAdvice advice = (result==KDialog::Yes) ? KCookieAccept : KCookieReject;
00183 
00184     KCookieJar::KCookieDefaultPolicy preferredPolicy = KCookieJar::ApplyToShownCookiesOnly;
00185     if (m_allCookiesDomain->isChecked()) {
00186     preferredPolicy = KCookieJar::ApplyToCookiesFromDomain;
00187     cookiejar->setDomainAdvice( cookie, advice );
00188     } else if (m_allCookies->isChecked()) {
00189     preferredPolicy = KCookieJar::ApplyToAllCookies;
00190     cookiejar->setGlobalAdvice( advice );
00191     }
00192     cookiejar->setPreferredDefaultPolicy( preferredPolicy );
00193 
00194     return advice;
00195 }
00196 
00197 KCookieDetail::KCookieDetail( KHttpCookieList cookieList, int cookieCount,
00198                               QWidget* parent )
00199               :QGroupBox( parent )
00200 {
00201     setTitle( i18n("Cookie Details") );
00202     QGridLayout* grid = new QGridLayout( this );
00203     grid->addItem( new QSpacerItem(0, fontMetrics().lineSpacing()), 0, 0 );
00204     grid->setColumnStretch( 1, 3 );
00205 
00206     QLabel* label = new QLabel( i18n("Name:"), this );
00207     grid->addWidget( label, 1, 0 );
00208     m_name = new KLineEdit( this );
00209     m_name->setReadOnly( true );
00210     m_name->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00211     grid->addWidget( m_name, 1 ,1 );
00212 
00213     //Add the value
00214     label = new QLabel( i18n("Value:"), this );
00215     grid->addWidget( label, 2, 0 );
00216     m_value = new KLineEdit( this );
00217     m_value->setReadOnly( true );
00218     m_value->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00219     grid->addWidget( m_value, 2, 1);
00220 
00221     label = new QLabel( i18n("Expires:"), this );
00222     grid->addWidget( label, 3, 0 );
00223     m_expires = new KLineEdit( this );
00224     m_expires->setReadOnly( true );
00225     m_expires->setMaximumWidth(fontMetrics().maxWidth() * 25 );
00226     grid->addWidget( m_expires, 3, 1);
00227 
00228     label = new QLabel( i18n("Path:"), this );
00229     grid->addWidget( label, 4, 0 );
00230     m_path = new KLineEdit( this );
00231     m_path->setReadOnly( true );
00232     m_path->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00233     grid->addWidget( m_path, 4, 1);
00234 
00235     label = new QLabel( i18n("Domain:"), this );
00236     grid->addWidget( label, 5, 0 );
00237     m_domain = new KLineEdit( this );
00238     m_domain->setReadOnly( true );
00239     m_domain->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00240     grid->addWidget( m_domain, 5, 1);
00241 
00242     label = new QLabel( i18n("Exposure:"), this );
00243     grid->addWidget( label, 6, 0 );
00244     m_secure = new KLineEdit( this );
00245     m_secure->setReadOnly( true );
00246     m_secure->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00247     grid->addWidget( m_secure, 6, 1 );
00248 
00249     if ( cookieCount > 1 )
00250     {
00251         QPushButton* btnNext = new QPushButton( i18nc("Next cookie","&Next >>"), this );
00252         btnNext->setFixedSize( btnNext->sizeHint() );
00253         grid->addWidget( btnNext, 8, 0, 1, 2 );
00254         connect( btnNext, SIGNAL(clicked()), SLOT(slotNextCookie()) );
00255 #ifndef QT_NO_TOOLTIP
00256         btnNext->setToolTip(i18n("Show details of the next cookie") );
00257 #endif
00258     }
00259     m_cookieList = cookieList;
00260     m_cookieNumber = 0;
00261     slotNextCookie();
00262 }
00263 
00264 KCookieDetail::~KCookieDetail()
00265 {
00266 }
00267 
00268 void KCookieDetail::slotNextCookie()
00269 {
00270     if (m_cookieNumber == m_cookieList.count() - 1)
00271         m_cookieNumber = 0;
00272     else
00273         ++m_cookieNumber;
00274     displayCookieDetails();
00275 }
00276 
00277 void KCookieDetail::displayCookieDetails()
00278 {
00279     const KHttpCookie& cookie = m_cookieList.at(m_cookieNumber);
00280     m_name->setText(cookie.name());
00281     m_value->setText((cookie.value()));
00282     if (cookie.domain().isEmpty())
00283         m_domain->setText(i18n("Not specified"));
00284     else
00285         m_domain->setText(cookie.domain());
00286     m_path->setText(cookie.path());
00287     KDateTime cookiedate;
00288     cookiedate.setTime_t(cookie.expireDate());
00289     if (cookie.expireDate())
00290         m_expires->setText(KGlobal::locale()->formatDateTime(cookiedate));
00291     else
00292         m_expires->setText(i18n("End of Session"));
00293     QString sec;
00294     if (cookie.isSecure())
00295     {
00296         if (cookie.isHttpOnly())
00297             sec = i18n("Secure servers only");
00298         else
00299             sec = i18n("Secure servers, page scripts");
00300     }
00301     else
00302     {
00303         if (cookie.isHttpOnly())
00304             sec = i18n("Servers");
00305         else
00306             sec = i18n("Servers, page scripts");
00307     }
00308     m_secure->setText(sec);
00309 }
00310 
00311 #include "kcookiewin.moc"

KIOSlave

Skip menu "KIOSlave"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal