00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
00055 #ifdef Q_WS_X11
00056 #include <QX11Info>
00057 #include <X11/Xlib.h>
00058 #endif
00059
00060 #include <kvbox.h>
00061
00062 KCookieWin::KCookieWin( QWidget *parent, KHttpCookieList cookieList,
00063 int defaultButton, bool showDetails )
00064 :KDialog( parent )
00065 {
00066 setModal(true);
00067 setObjectName("cookiealert");
00068 setButtons(Yes|No|Details);
00069 #ifndef Q_WS_QWS //FIXME(E): Implement for Qt Embedded
00070 setCaption( i18n("Cookie Alert") );
00071 setWindowIcon( KIcon("preferences-web-browser-cookies") );
00072
00073 # ifdef Q_WS_X11
00074 if( cookieList.first().windowIds().count() > 0 )
00075 {
00076 XSetTransientForHint( QX11Info::display(), winId(), cookieList.first().windowIds().first());
00077 }
00078 else
00079 {
00080
00081 KWindowSystem::setState( winId(), NET::KeepAbove );
00082 kapp->updateUserTimestamp();
00083 }
00084 # endif
00085 #endif
00086 KVBox* vBox1 = new KVBox( this );
00087 vBox1->setSpacing( KDialog::spacingHint() );
00088 setMainWidget(vBox1);
00089
00090 KHBox* hBox = new KHBox( vBox1 );
00091 QLabel* icon = new QLabel( hBox );
00092 icon->setPixmap(KIcon("dialog-warning").pixmap(IconSize(KIconLoader::Desktop)));
00093 icon->setAlignment( Qt::AlignCenter );
00094 icon->setFixedSize( 2*icon->sizeHint() );
00095
00096 int count = cookieList.count();
00097
00098 KVBox* vBox = new KVBox( hBox );
00099 QString txt = i18np("You received a cookie from",
00100 "You received %1 cookies from", count);
00101 QLabel* lbl = new QLabel( txt, vBox );
00102 lbl->setAlignment( Qt::AlignCenter );
00103 const KHttpCookie& cookie = cookieList.first();
00104
00105 QString host (cookie.host());
00106 int pos = host.indexOf(':');
00107 if ( pos > 0 )
00108 {
00109 QString portNum = host.left(pos);
00110 host.remove(0, pos+1);
00111 host += ':';
00112 host += portNum;
00113 }
00114
00115 txt = QString("<b>%1</b>").arg( QUrl::fromAce(host.toLatin1()) );
00116 if (cookie.isCrossDomain())
00117 txt += i18n(" <b>[Cross Domain]</b>");
00118 lbl = new QLabel( txt, vBox );
00119 lbl->setAlignment( Qt::AlignCenter );
00120 lbl = new QLabel( i18n("Do you want to accept or reject?"), vBox );
00121 lbl->setAlignment( Qt::AlignCenter );
00122
00123
00124 m_detailView = new KCookieDetail( cookieList, count, vBox1 );
00125 setDetailsWidget(m_detailView);
00126
00127
00128 QGroupBox *m_btnGrp = new QGroupBox(i18n("Apply Choice To"),vBox1);
00129 QVBoxLayout *vbox = new QVBoxLayout;
00130 txt = (count == 1)? i18n("&Only this cookie") : i18n("&Only these cookies");
00131 m_onlyCookies = new QRadioButton( txt, m_btnGrp );
00132 vbox->addWidget(m_onlyCookies);
00133 #ifndef QT_NO_WHATSTHIS
00134 m_onlyCookies->setWhatsThis(i18n("Select this option to accept/reject only this cookie. "
00135 "You will be prompted if another cookie is received. "
00136 "<em>(see WebBrowsing/Cookies in the Control Center)</em>." ) );
00137 #endif
00138 m_allCookiesDomain = new QRadioButton( i18n("All cookies from this do&main"), m_btnGrp );
00139 vbox->addWidget(m_allCookiesDomain);
00140 #ifndef QT_NO_WHATSTHIS
00141 m_allCookiesDomain->setWhatsThis(i18n("Select this option to accept/reject all cookies from "
00142 "this site. Choosing this option will add a new policy for "
00143 "the site this cookie originated from. This policy will be "
00144 "permanent until you manually change it from the Control Center "
00145 "<em>(see WebBrowsing/Cookies in the Control Center)</em>.") );
00146 #endif
00147 m_allCookies = new QRadioButton( i18n("All &cookies"), m_btnGrp);
00148 vbox->addWidget(m_allCookies);
00149 #ifndef QT_NO_WHATSTHIS
00150 m_allCookies->setWhatsThis(i18n("Select this option to accept/reject all cookies from "
00151 "anywhere. Choosing this option will change the global "
00152 "cookie policy set in the Control Center for all cookies "
00153 "<em>(see WebBrowsing/Cookies in the Control Center)</em>.") );
00154 #endif
00155 m_btnGrp->setLayout(vbox);
00156 if (defaultButton == 0 )
00157 m_onlyCookies->setChecked(true);
00158 else if(defaultButton==1)
00159 m_allCookiesDomain->setChecked(true);
00160 else if(defaultButton==2)
00161 m_allCookies->setChecked(true);
00162 else
00163 m_onlyCookies->setChecked(true);
00164 setButtonText(KDialog::Yes, i18n("&Accept"));
00165 setButtonText(KDialog::No, i18n("&Reject"));
00166
00167 #ifndef QT_NO_WHATSTHIS
00168 setButtonToolTip(Details, i18n("See or modify the cookie information") );
00169 #endif
00170 setDefaultButton(Yes);
00171
00172 setDetailsWidgetVisible(showDetails);
00173 }
00174
00175 KCookieWin::~KCookieWin()
00176 {
00177 }
00178
00179 KCookieAdvice KCookieWin::advice( KCookieJar *cookiejar, const KHttpCookie& cookie )
00180 {
00181 int result = exec();
00182
00183 cookiejar->setShowCookieDetails ( isDetailsWidgetVisible() );
00184
00185 KCookieAdvice advice = (result==KDialog::Yes) ? KCookieAccept : KCookieReject;
00186
00187 int preferredPolicy=-1;
00188 if( m_onlyCookies->isChecked())
00189 preferredPolicy = 0;
00190 else if( m_allCookiesDomain->isChecked())
00191 {
00192 preferredPolicy = 1;
00193 cookiejar->setDomainAdvice( cookie, advice );
00194 }
00195 else if( m_allCookies->isChecked())
00196 {
00197 preferredPolicy = 2;
00198 cookiejar->setGlobalAdvice( advice );
00199 }
00200 cookiejar->setPreferredDefaultPolicy( preferredPolicy );
00201
00202 return advice;
00203 }
00204
00205 KCookieDetail::KCookieDetail( KHttpCookieList cookieList, int cookieCount,
00206 QWidget* parent )
00207 :QGroupBox( parent )
00208 {
00209 setTitle( i18n("Cookie Details") );
00210 QGridLayout* grid = new QGridLayout( this );
00211 grid->setMargin( KDialog::marginHint() );
00212 grid->setSpacing( KDialog::spacingHint() );
00213 grid->addItem( new QSpacerItem(0, fontMetrics().lineSpacing()), 0, 0 );
00214 grid->setColumnStretch( 1, 3 );
00215
00216 QLabel* label = new QLabel( i18n("Name:"), this );
00217 grid->addWidget( label, 1, 0 );
00218 m_name = new KLineEdit( this );
00219 m_name->setReadOnly( true );
00220 m_name->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00221 grid->addWidget( m_name, 1 ,1 );
00222
00223
00224 label = new QLabel( i18n("Value:"), this );
00225 grid->addWidget( label, 2, 0 );
00226 m_value = new KLineEdit( this );
00227 m_value->setReadOnly( true );
00228 m_value->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00229 grid->addWidget( m_value, 2, 1);
00230
00231 label = new QLabel( i18n("Expires:"), this );
00232 grid->addWidget( label, 3, 0 );
00233 m_expires = new KLineEdit( this );
00234 m_expires->setReadOnly( true );
00235 m_expires->setMaximumWidth(fontMetrics().maxWidth() * 25 );
00236 grid->addWidget( m_expires, 3, 1);
00237
00238 label = new QLabel( i18n("Path:"), this );
00239 grid->addWidget( label, 4, 0 );
00240 m_path = new KLineEdit( this );
00241 m_path->setReadOnly( true );
00242 m_path->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00243 grid->addWidget( m_path, 4, 1);
00244
00245 label = new QLabel( i18n("Domain:"), this );
00246 grid->addWidget( label, 5, 0 );
00247 m_domain = new KLineEdit( this );
00248 m_domain->setReadOnly( true );
00249 m_domain->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00250 grid->addWidget( m_domain, 5, 1);
00251
00252 label = new QLabel( i18n("Exposure:"), this );
00253 grid->addWidget( label, 6, 0 );
00254 m_secure = new KLineEdit( this );
00255 m_secure->setReadOnly( true );
00256 m_secure->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00257 grid->addWidget( m_secure, 6, 1 );
00258
00259 if ( cookieCount > 1 )
00260 {
00261 QPushButton* btnNext = new QPushButton( i18nc("Next cookie","&Next >>"), this );
00262 btnNext->setFixedSize( btnNext->sizeHint() );
00263 grid->addWidget( btnNext, 8, 0, 1, 2 );
00264 connect( btnNext, SIGNAL(clicked()), SLOT(slotNextCookie()) );
00265 #ifndef QT_NO_TOOLTIP
00266 btnNext->setToolTip(i18n("Show details of the next cookie") );
00267 #endif
00268 }
00269 m_cookieList = cookieList;
00270 m_cookieNumber = 0;
00271 slotNextCookie();
00272 }
00273
00274 KCookieDetail::~KCookieDetail()
00275 {
00276 }
00277
00278 void KCookieDetail::slotNextCookie()
00279 {
00280 if (m_cookieNumber == m_cookieList.count() - 1)
00281 m_cookieNumber = 0;
00282 else
00283 ++m_cookieNumber;
00284 displayCookieDetails();
00285 }
00286
00287 void KCookieDetail::displayCookieDetails()
00288 {
00289 const KHttpCookie& cookie = m_cookieList.at(m_cookieNumber);
00290 m_name->setText(cookie.name());
00291 m_value->setText((cookie.value()));
00292 if (cookie.domain().isEmpty())
00293 m_domain->setText(i18n("Not specified"));
00294 else
00295 m_domain->setText(cookie.domain());
00296 m_path->setText(cookie.path());
00297 QDateTime cookiedate;
00298 cookiedate.setTime_t(cookie.expireDate());
00299 if (cookie.expireDate())
00300 m_expires->setText(KGlobal::locale()->formatDateTime(cookiedate));
00301 else
00302 m_expires->setText(i18n("End of Session"));
00303 QString sec;
00304 if (cookie.isSecure())
00305 {
00306 if (cookie.isHttpOnly())
00307 sec = i18n("Secure servers only");
00308 else
00309 sec = i18n("Secure servers, page scripts");
00310 }
00311 else
00312 {
00313 if (cookie.isHttpOnly())
00314 sec = i18n("Servers");
00315 else
00316 sec = i18n("Servers, page scripts");
00317 }
00318 m_secure->setText(sec);
00319 }
00320
00321 #include "kcookiewin.moc"