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
00038 #include <qhbox.h>
00039 #include <qvbox.h>
00040 #include <qaccel.h>
00041 #include <qlabel.h>
00042 #include <qwidget.h>
00043 #include <qlayout.h>
00044 #include <qgroupbox.h>
00045 #include <qdatetime.h>
00046 #include <qmessagebox.h>
00047 #include <qpushbutton.h>
00048 #include <qradiobutton.h>
00049 #include <qvbuttongroup.h>
00050
00051 #ifndef QT_NO_TOOLTIP
00052 #include <qtooltip.h>
00053 #endif
00054
00055 #ifndef QT_NO_WHATSTHIS
00056 #include <qwhatsthis.h>
00057 #endif
00058
00059 #include <kidna.h>
00060 #include <kwin.h>
00061 #include <klocale.h>
00062 #include <kglobal.h>
00063 #include <kurllabel.h>
00064 #include <klineedit.h>
00065 #include <kiconloader.h>
00066 #include <kapplication.h>
00067
00068 #ifdef Q_WS_X11
00069 #include <X11/Xlib.h>
00070 #endif
00071
00072 #include "kcookiejar.h"
00073 #include "kcookiewin.h"
00074
00075 KCookieWin::KCookieWin( QWidget *parent, KHttpCookieList cookieList,
00076 int defaultButton, bool showDetails )
00077 :KDialog( parent, "cookiealert", true )
00078 {
00079 #ifndef Q_WS_QWS //FIXME(E): Implement for Qt Embedded
00080 setCaption( i18n("Cookie Alert") );
00081 setIcon( SmallIcon("cookie") );
00082
00083 # ifdef Q_WS_X11
00084 if( cookieList.first()->windowIds().count() > 0 )
00085 {
00086 XSetTransientForHint( qt_xdisplay(), winId(), cookieList.first()->windowIds().first());
00087 }
00088 else
00089 {
00090
00091 KWin::setState( winId(), NET::KeepAbove );
00092 kapp->updateUserTimestamp();
00093 }
00094 # endif
00095 #endif
00096
00097 QVBoxLayout* vlayout = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
00098 vlayout->setResizeMode( QLayout::Fixed );
00099
00100
00101 QHBox* hBox = new QHBox( this );
00102 hBox->setSpacing( KDialog::spacingHint() );
00103 QLabel* icon = new QLabel( hBox );
00104 icon->setPixmap( QMessageBox::standardIcon(QMessageBox::Warning) );
00105 icon->setAlignment( Qt::AlignCenter );
00106 icon->setFixedSize( 2*icon->sizeHint() );
00107
00108 int count = cookieList.count();
00109
00110 QVBox* vBox = new QVBox( hBox );
00111 QString txt = i18n("You received a cookie from",
00112 "You received %n cookies from", count);
00113 QLabel* lbl = new QLabel( txt, vBox );
00114 lbl->setAlignment( Qt::AlignCenter );
00115 KHttpCookiePtr cookie = cookieList.first();
00116
00117 QString host (cookie->host());
00118 int pos = host.find(':');
00119 if ( pos > 0 )
00120 {
00121 QString portNum = host.left(pos);
00122 host.remove(0, pos+1);
00123 host += ':';
00124 host += portNum;
00125 }
00126
00127 txt = QString("<b>%1</b>").arg( KIDNA::toUnicode(host) );
00128 if (cookie->isCrossDomain())
00129 txt += i18n(" <b>[Cross Domain!]</b>");
00130 lbl = new QLabel( txt, vBox );
00131 lbl->setAlignment( Qt::AlignCenter );
00132 lbl = new QLabel( i18n("Do you want to accept or reject?"), vBox );
00133 lbl->setAlignment( Qt::AlignCenter );
00134 vlayout->addWidget( hBox, 0, Qt::AlignLeft );
00135
00136
00137 m_detailView = new KCookieDetail( cookieList, count, this );
00138 vlayout->addWidget( m_detailView );
00139 m_showDetails = showDetails;
00140 m_showDetails ? m_detailView->show():m_detailView->hide();
00141
00142
00143 m_btnGrp = new QVButtonGroup( i18n("Apply Choice To"), this );
00144 m_btnGrp->setRadioButtonExclusive( true );
00145
00146 txt = (count == 1)? i18n("&Only this cookie") : i18n("&Only these cookies");
00147 QRadioButton* rb = new QRadioButton( txt, m_btnGrp );
00148 #ifndef QT_NO_WHATSTHIS
00149 QWhatsThis::add( rb, i18n("Select this option to accept/reject only this cookie. "
00150 "You will be prompted if another cookie is received. "
00151 "<em>(see WebBrowsing/Cookies in the Control Center)</em>." ) );
00152 #endif
00153 m_btnGrp->insert( rb );
00154 rb = new QRadioButton( i18n("All cookies from this do&main"), m_btnGrp );
00155 #ifndef QT_NO_WHATSTHIS
00156 QWhatsThis::add( rb, i18n("Select this option to accept/reject all cookies from "
00157 "this site. Choosing this option will add a new policy for "
00158 "the site this cookie originated from. This policy will be "
00159 "permanent until you manually change it from the Control Center "
00160 "<em>(see WebBrowsing/Cookies in the Control Center)</em>.") );
00161 #endif
00162 m_btnGrp->insert( rb );
00163 rb = new QRadioButton( i18n("All &cookies"), m_btnGrp );
00164 #ifndef QT_NO_WHATSTHIS
00165 QWhatsThis::add( rb, i18n("Select this option to accept/reject all cookies from "
00166 "anywhere. Choosing this option will change the global "
00167 "cookie policy set in the Control Center for all cookies "
00168 "<em>(see WebBrowsing/Cookies in the Control Center)</em>.") );
00169 #endif
00170 m_btnGrp->insert( rb );
00171 vlayout->addWidget( m_btnGrp );
00172
00173 if ( defaultButton > -1 && defaultButton < 3 )
00174 m_btnGrp->setButton( defaultButton );
00175 else
00176 m_btnGrp->setButton( 1 );
00177
00178
00179 QWidget* bbox = new QWidget( this );
00180 QBoxLayout* bbLay = new QHBoxLayout( bbox );
00181 bbLay->setSpacing( KDialog::spacingHint() );
00182 QPushButton* btn = new QPushButton( i18n("&Accept"), bbox );
00183 btn->setDefault( true );
00184 btn->setFocus();
00185 connect( btn, SIGNAL(clicked()), SLOT(accept()) );
00186 bbLay->addWidget( btn );
00187 btn = new QPushButton( i18n("&Reject"), bbox );
00188 connect( btn, SIGNAL(clicked()), SLOT(reject()) );
00189 bbLay->addWidget( btn );
00190 bbLay->addStretch( 1 );
00191 #ifndef QT_NO_ACCEL
00192 QAccel* a = new QAccel( this );
00193 a->connectItem( a->insertItem(Qt::Key_Escape), btn, SLOT(animateClick()) );
00194 #endif
00195
00196 m_button = new QPushButton( bbox );
00197 m_button->setText( m_showDetails ? i18n("&Details <<"):i18n("&Details >>") );
00198 connect( m_button, SIGNAL(clicked()), SLOT(slotCookieDetails()) );
00199 bbLay->addWidget( m_button );
00200 #ifndef QT_NO_WHATSTHIS
00201 QWhatsThis::add( m_button, i18n("See or modify the cookie information") );
00202 #endif
00203
00204
00205 vlayout->addWidget( bbox );
00206 setFixedSize( sizeHint() );
00207 }
00208
00209 KCookieWin::~KCookieWin()
00210 {
00211 }
00212
00213 void KCookieWin::slotCookieDetails()
00214 {
00215 if ( m_detailView->isVisible() )
00216 {
00217 m_detailView->setMaximumSize( 0, 0 );
00218 m_detailView->adjustSize();
00219 m_detailView->hide();
00220 m_button->setText( i18n( "&Details >>" ) );
00221 m_showDetails = false;
00222 }
00223 else
00224 {
00225 m_detailView->setMaximumSize( 1000, 1000 );
00226 m_detailView->adjustSize();
00227 m_detailView->show();
00228 m_button->setText( i18n( "&Details <<" ) );
00229 m_showDetails = true;
00230 }
00231 }
00232
00233 KCookieAdvice KCookieWin::advice( KCookieJar *cookiejar, KHttpCookie* cookie )
00234 {
00235 int result = exec();
00236
00237 cookiejar->setShowCookieDetails ( m_showDetails );
00238
00239 KCookieAdvice advice = (result==QDialog::Accepted) ? KCookieAccept:KCookieReject;
00240
00241 int preferredPolicy = m_btnGrp->id( m_btnGrp->selected() );
00242 cookiejar->setPreferredDefaultPolicy( preferredPolicy );
00243
00244 switch ( preferredPolicy )
00245 {
00246 case 2:
00247 cookiejar->setGlobalAdvice( advice );
00248 break;
00249 case 1:
00250 cookiejar->setDomainAdvice( cookie, advice );
00251 break;
00252 case 0:
00253 default:
00254 break;
00255 }
00256 return advice;
00257 }
00258
00259 KCookieDetail::KCookieDetail( KHttpCookieList cookieList, int cookieCount,
00260 QWidget* parent, const char* name )
00261 :QGroupBox( parent, name )
00262 {
00263 setTitle( i18n("Cookie Details") );
00264 QGridLayout* grid = new QGridLayout( this, 9, 2,
00265 KDialog::spacingHint(),
00266 KDialog::marginHint() );
00267 grid->addRowSpacing( 0, fontMetrics().lineSpacing() );
00268 grid->setColStretch( 1, 3 );
00269
00270 QLabel* label = new QLabel( i18n("Name:"), this );
00271 grid->addWidget( label, 1, 0 );
00272 m_name = new KLineEdit( this );
00273 m_name->setReadOnly( true );
00274 m_name->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00275 grid->addWidget( m_name, 1 ,1 );
00276
00277
00278 label = new QLabel( i18n("Value:"), this );
00279 grid->addWidget( label, 2, 0 );
00280 m_value = new KLineEdit( this );
00281 m_value->setReadOnly( true );
00282 m_value->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00283 grid->addWidget( m_value, 2, 1);
00284
00285 label = new QLabel( i18n("Expires:"), this );
00286 grid->addWidget( label, 3, 0 );
00287 m_expires = new KLineEdit( this );
00288 m_expires->setReadOnly( true );
00289 m_expires->setMaximumWidth(fontMetrics().maxWidth() * 25 );
00290 grid->addWidget( m_expires, 3, 1);
00291
00292 label = new QLabel( i18n("Path:"), this );
00293 grid->addWidget( label, 4, 0 );
00294 m_path = new KLineEdit( this );
00295 m_path->setReadOnly( true );
00296 m_path->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00297 grid->addWidget( m_path, 4, 1);
00298
00299 label = new QLabel( i18n("Domain:"), this );
00300 grid->addWidget( label, 5, 0 );
00301 m_domain = new KLineEdit( this );
00302 m_domain->setReadOnly( true );
00303 m_domain->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00304 grid->addWidget( m_domain, 5, 1);
00305
00306 label = new QLabel( i18n("Exposure:"), this );
00307 grid->addWidget( label, 6, 0 );
00308 m_secure = new KLineEdit( this );
00309 m_secure->setReadOnly( true );
00310 m_secure->setMaximumWidth( fontMetrics().maxWidth() * 25 );
00311 grid->addWidget( m_secure, 6, 1 );
00312
00313 if ( cookieCount > 1 )
00314 {
00315 QPushButton* btnNext = new QPushButton( i18n("Next cookie","&Next >>"), this );
00316 btnNext->setFixedSize( btnNext->sizeHint() );
00317 grid->addMultiCellWidget( btnNext, 8, 8, 0, 1 );
00318 connect( btnNext, SIGNAL(clicked()), SLOT(slotNextCookie()) );
00319 #ifndef QT_NO_TOOLTIP
00320 QToolTip::add( btnNext, i18n("Show details of the next cookie") );
00321 #endif
00322 }
00323 m_cookieList = cookieList;
00324 m_cookie = 0;
00325 slotNextCookie();
00326 }
00327
00328 KCookieDetail::~KCookieDetail()
00329 {
00330 }
00331
00332 void KCookieDetail::slotNextCookie()
00333 {
00334 KHttpCookiePtr cookie = m_cookieList.first();
00335 if (m_cookie) while(cookie)
00336 {
00337 if (cookie == m_cookie)
00338 {
00339 cookie = m_cookieList.next();
00340 break;
00341 }
00342 cookie = m_cookieList.next();
00343 }
00344 m_cookie = cookie;
00345 if (!m_cookie)
00346 m_cookie = m_cookieList.first();
00347
00348 if ( m_cookie )
00349 {
00350 m_name->setText( m_cookie->name() );
00351 m_value->setText( ( m_cookie->value() ) );
00352 if ( m_cookie->domain().isEmpty() )
00353 m_domain->setText( i18n("Not specified") );
00354 else
00355 m_domain->setText( m_cookie->domain() );
00356 m_path->setText( m_cookie->path() );
00357 QDateTime cookiedate;
00358 cookiedate.setTime_t( m_cookie->expireDate() );
00359 if ( m_cookie->expireDate() )
00360 m_expires->setText( KGlobal::locale()->formatDateTime(cookiedate) );
00361 else
00362 m_expires->setText( i18n("End of Session") );
00363 QString sec;
00364 if (m_cookie->isSecure())
00365 {
00366 if (m_cookie->isHttpOnly())
00367 sec = i18n("Secure servers only");
00368 else
00369 sec = i18n("Secure servers, page scripts");
00370 }
00371 else
00372 {
00373 if (m_cookie->isHttpOnly())
00374 sec = i18n("Servers");
00375 else
00376 sec = i18n("Servers, page scripts");
00377 }
00378 m_secure->setText( sec );
00379 }
00380 }
00381
00382 #include "kcookiewin.moc"