• Skip to content
  • Skip to link menu
KDE 4.2 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 <QtCore/QDate>
00044 #include <QtGui/QPushButton>
00045 #include <QtGui/QRadioButton>
00046 #include <QtGui/QShortcut>
00047 
00048 #include <kwindowsystem.h>
00049 #include <klocale.h>
00050 #include <kglobal.h>
00051 #include <klineedit.h>
00052 #include <kiconloader.h>
00053 #include <kapplication.h>
00054 #include <kwindowsystem.h>
00055 #include <kvbox.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( KDialog::spacingHint() );
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 == 0 )
00156     m_onlyCookies->setChecked(true);
00157     else if(defaultButton==1)
00158     m_allCookiesDomain->setChecked(true);
00159     else if(defaultButton==2)
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 #ifndef QT_NO_WHATSTHIS
00167     setButtonToolTip(Details, i18n("See or modify the cookie information") );
00168 #endif
00169     setDefaultButton(Yes);
00170 
00171     setDetailsWidgetVisible(showDetails);
00172 }
00173 
00174 KCookieWin::~KCookieWin()
00175 {
00176 }
00177 
00178 KCookieAdvice KCookieWin::advice( KCookieJar *cookiejar, const KHttpCookie& cookie )
00179 {
00180     int result = exec();
00181 
00182     cookiejar->setShowCookieDetails ( isDetailsWidgetVisible() );
00183 
00184     KCookieAdvice advice = (result==KDialog::Yes) ? KCookieAccept : KCookieReject;
00185 
00186     int preferredPolicy=-1;
00187     if( m_onlyCookies->isChecked())
00188     preferredPolicy = 0;
00189     else if( m_allCookiesDomain->isChecked())
00190     {
00191     preferredPolicy = 1;
00192     cookiejar->setDomainAdvice( cookie, advice );
00193     }
00194     else if( m_allCookies->isChecked())
00195     {
00196     preferredPolicy = 2;
00197     cookiejar->setGlobalAdvice( advice );
00198     }
00199     cookiejar->setPreferredDefaultPolicy( preferredPolicy );
00200 
00201     return advice;
00202 }
00203 
00204 KCookieDetail::KCookieDetail( KHttpCookieList cookieList, int cookieCount,
00205                               QWidget* parent )
00206               :QGroupBox( parent )
00207 {
00208     setTitle( i18n("Cookie Details") );
00209     QGridLayout* grid = new QGridLayout( this );
00210     grid->setMargin( KDialog::marginHint() );
00211     grid->setSpacing( KDialog::spacingHint() );
00212     grid->addItem( new QSpacerItem(0, fontMetrics().lineSpacing()), 0, 0 );
00213     grid->setColumnStretch( 1, 3 );
00214 
00215     QLabel* label = new QLabel( i18n("Name:"), this );
00216     grid->addWidget( label, 1, 0 );
00217     m_name = new KLineEdit( this );
00218     m_name->setReadOnly( true );
00219     m_name->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00220     grid->addWidget( m_name, 1 ,1 );
00221 
00222     //Add the value
00223     label = new QLabel( i18n("Value:"), this );
00224     grid->addWidget( label, 2, 0 );
00225     m_value = new KLineEdit( this );
00226     m_value->setReadOnly( true );
00227     m_value->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00228     grid->addWidget( m_value, 2, 1);
00229 
00230     label = new QLabel( i18n("Expires:"), this );
00231     grid->addWidget( label, 3, 0 );
00232     m_expires = new KLineEdit( this );
00233     m_expires->setReadOnly( true );
00234     m_expires->setMaximumWidth(fontMetrics().maxWidth() * 25 );
00235     grid->addWidget( m_expires, 3, 1);
00236 
00237     label = new QLabel( i18n("Path:"), this );
00238     grid->addWidget( label, 4, 0 );
00239     m_path = new KLineEdit( this );
00240     m_path->setReadOnly( true );
00241     m_path->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00242     grid->addWidget( m_path, 4, 1);
00243 
00244     label = new QLabel( i18n("Domain:"), this );
00245     grid->addWidget( label, 5, 0 );
00246     m_domain = new KLineEdit( this );
00247     m_domain->setReadOnly( true );
00248     m_domain->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00249     grid->addWidget( m_domain, 5, 1);
00250 
00251     label = new QLabel( i18n("Exposure:"), this );
00252     grid->addWidget( label, 6, 0 );
00253     m_secure = new KLineEdit( this );
00254     m_secure->setReadOnly( true );
00255     m_secure->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00256     grid->addWidget( m_secure, 6, 1 );
00257 
00258     if ( cookieCount > 1 )
00259     {
00260         QPushButton* btnNext = new QPushButton( i18nc("Next cookie","&Next >>"), this );
00261         btnNext->setFixedSize( btnNext->sizeHint() );
00262         grid->addWidget( btnNext, 8, 0, 1, 2 );
00263         connect( btnNext, SIGNAL(clicked()), SLOT(slotNextCookie()) );
00264 #ifndef QT_NO_TOOLTIP
00265         btnNext->setToolTip(i18n("Show details of the next cookie") );
00266 #endif
00267     }
00268     m_cookieList = cookieList;
00269     m_cookieNumber = 0;
00270     slotNextCookie();
00271 }
00272 
00273 KCookieDetail::~KCookieDetail()
00274 {
00275 }
00276 
00277 void KCookieDetail::slotNextCookie()
00278 {
00279     if (m_cookieNumber == m_cookieList.count() - 1)
00280         m_cookieNumber = 0;
00281     else
00282         ++m_cookieNumber;
00283     displayCookieDetails();
00284 }
00285 
00286 void KCookieDetail::displayCookieDetails()
00287 {
00288     const KHttpCookie& cookie = m_cookieList.at(m_cookieNumber);
00289     m_name->setText(cookie.name());
00290     m_value->setText((cookie.value()));
00291     if (cookie.domain().isEmpty())
00292         m_domain->setText(i18n("Not specified"));
00293     else
00294         m_domain->setText(cookie.domain());
00295     m_path->setText(cookie.path());
00296     QDateTime cookiedate;
00297     cookiedate.setTime_t(cookie.expireDate());
00298     if (cookie.expireDate())
00299         m_expires->setText(KGlobal::locale()->formatDateTime(cookiedate));
00300     else
00301         m_expires->setText(i18n("End of Session"));
00302     QString sec;
00303     if (cookie.isSecure())
00304     {
00305         if (cookie.isHttpOnly())
00306             sec = i18n("Secure servers only");
00307         else
00308             sec = i18n("Secure servers, page scripts");
00309     }
00310     else
00311     {
00312         if (cookie.isHttpOnly())
00313             sec = i18n("Servers");
00314         else
00315             sec = i18n("Servers, page scripts");
00316     }
00317     m_secure->setText(sec);
00318 }
00319 
00320 #include "kcookiewin.moc"

KIOSlave

Skip menu "KIOSlave"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • 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
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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