44 #include <tqgroupbox.h>
45 #include <tqdatetime.h>
46 #include <tqmessagebox.h>
47 #include <tqpushbutton.h>
48 #include <tqradiobutton.h>
49 #include <tqvbuttongroup.h>
51 #ifndef TQT_NO_TOOLTIP
52 #include <tqtooltip.h>
55 #ifndef TQT_NO_WHATSTHIS
56 #include <tqwhatsthis.h>
61 #include <tdelocale.h>
62 #include <tdeglobal.h>
63 #include <kurllabel.h>
64 #include <klineedit.h>
65 #include <kiconloader.h>
66 #include <tdeapplication.h>
72 #include "kcookiejar.h"
73 #include "kcookiewin.h"
75 KCookieWin::KCookieWin( TQWidget *parent, KHttpCookieList cookieList,
76 int defaultButton,
bool showDetails )
77 :KDialog( parent,
"cookiealert", true )
80 setCaption( i18n(
"Cookie Alert") );
81 setIcon( SmallIcon(
"cookie") );
84 if( cookieList.first()->windowIds().count() > 0 )
86 XSetTransientForHint( tqt_xdisplay(), winId(), cookieList.first()->windowIds().first());
91 KWin::setState( winId(), NET::KeepAbove );
92 kapp->updateUserTimestamp();
97 TQVBoxLayout* vlayout =
new TQVBoxLayout(
this, KDialog::marginHint(), KDialog::spacingHint() );
98 vlayout->setResizeMode( TQLayout::Fixed );
101 TQHBox* hBox =
new TQHBox(
this );
102 hBox->setSpacing( KDialog::spacingHint() );
103 TQLabel* icon =
new TQLabel( hBox );
104 icon->setPixmap( TQMessageBox::standardIcon(TQMessageBox::Warning) );
105 icon->setAlignment( TQt::AlignCenter );
106 icon->setFixedSize( 2*icon->sizeHint() );
108 int count = cookieList.count();
110 TQVBox* vBox =
new TQVBox( hBox );
111 TQString txt = i18n(
"You received a cookie from",
112 "You received %n cookies from", count);
113 TQLabel* lbl =
new TQLabel( txt, vBox );
114 lbl->setAlignment( TQt::AlignCenter );
115 KHttpCookiePtr cookie = cookieList.first();
117 TQString host (cookie->host());
118 int pos = host.find(
':');
121 TQString portNum = host.left(pos);
122 host.remove(0, pos+1);
127 txt = TQString(
"<b>%1</b>").arg( KIDNA::toUnicode(host) );
128 if (cookie->isCrossDomain())
129 txt += i18n(
" <b>[Cross Domain!]</b>");
130 lbl =
new TQLabel( txt, vBox );
131 lbl->setAlignment( TQt::AlignCenter );
132 lbl =
new TQLabel( i18n(
"Do you want to accept or reject?"), vBox );
133 lbl->setAlignment( TQt::AlignCenter );
134 vlayout->addWidget( hBox, 0, TQt::AlignLeft );
137 m_detailView =
new KCookieDetail( cookieList, count,
this );
138 vlayout->addWidget( m_detailView );
139 m_showDetails = showDetails;
140 m_showDetails ? m_detailView->show():m_detailView->hide();
143 m_btnGrp =
new TQVButtonGroup( i18n(
"Apply Choice To"),
this );
144 m_btnGrp->setRadioButtonExclusive(
true );
146 txt = (count == 1)? i18n(
"&Only this cookie") : i18n(
"&Only these cookies");
147 TQRadioButton* rb =
new TQRadioButton( txt, m_btnGrp );
148 #ifndef TQT_NO_WHATSTHIS
149 TQWhatsThis::add( rb, i18n(
"Select this option to accept/reject only this cookie. "
150 "You will be prompted if another cookie is received. "
151 "<em>(see WebBrowsing/Cookies in the Control Center)</em>." ) );
153 m_btnGrp->insert( rb );
154 rb =
new TQRadioButton( i18n(
"All cookies from this do&main"), m_btnGrp );
155 #ifndef TQT_NO_WHATSTHIS
156 TQWhatsThis::add( rb, i18n(
"Select this option to accept/reject all cookies from "
157 "this site. Choosing this option will add a new policy for "
158 "the site this cookie originated from. This policy will be "
159 "permanent until you manually change it from the Control Center "
160 "<em>(see WebBrowsing/Cookies in the Control Center)</em>.") );
162 m_btnGrp->insert( rb );
163 rb =
new TQRadioButton( i18n(
"All &cookies"), m_btnGrp );
164 #ifndef TQT_NO_WHATSTHIS
165 TQWhatsThis::add( rb, i18n(
"Select this option to accept/reject all cookies from "
166 "anywhere. Choosing this option will change the global "
167 "cookie policy set in the Control Center for all cookies "
168 "<em>(see WebBrowsing/Cookies in the Control Center)</em>.") );
170 m_btnGrp->insert( rb );
171 vlayout->addWidget( m_btnGrp );
173 if ( defaultButton > -1 && defaultButton < 3 )
174 m_btnGrp->setButton( defaultButton );
176 m_btnGrp->setButton( 1 );
179 TQWidget* bbox =
new TQWidget(
this );
180 TQBoxLayout* bbLay =
new TQHBoxLayout( bbox );
181 bbLay->setSpacing( KDialog::spacingHint() );
182 TQPushButton* btn =
new TQPushButton( i18n(
"&Accept"), bbox );
183 btn->setDefault(
true );
185 connect( btn, TQ_SIGNAL(clicked()), TQ_SLOT(accept()) );
186 bbLay->addWidget( btn );
187 btn =
new TQPushButton( i18n(
"&Reject"), bbox );
188 connect( btn, TQ_SIGNAL(clicked()), TQ_SLOT(reject()) );
189 bbLay->addWidget( btn );
190 bbLay->addStretch( 1 );
192 TQAccel* a =
new TQAccel(
this );
193 a->connectItem( a->insertItem(TQt::Key_Escape), btn, TQ_SLOT(animateClick()) );
196 m_button =
new TQPushButton( bbox );
197 m_button->setText( m_showDetails ? i18n(
"&Details <<"):i18n(
"&Details >>") );
198 connect( m_button, TQ_SIGNAL(clicked()), TQ_SLOT(slotCookieDetails()) );
199 bbLay->addWidget( m_button );
200 #ifndef TQT_NO_WHATSTHIS
201 TQWhatsThis::add( m_button, i18n(
"See or modify the cookie information") );
205 vlayout->addWidget( bbox );
206 setFixedSize( sizeHint() );
209 KCookieWin::~KCookieWin()
213 void KCookieWin::slotCookieDetails()
215 if ( m_detailView->isVisible() )
217 m_detailView->setMaximumSize( 0, 0 );
218 m_detailView->adjustSize();
219 m_detailView->hide();
220 m_button->setText( i18n(
"&Details >>" ) );
221 m_showDetails =
false;
225 m_detailView->setMaximumSize( 1000, 1000 );
226 m_detailView->adjustSize();
227 m_detailView->show();
228 m_button->setText( i18n(
"&Details <<" ) );
229 m_showDetails =
true;
233 KCookieAdvice KCookieWin::advice( KCookieJar *cookiejar, KHttpCookie* cookie )
237 cookiejar->setShowCookieDetails ( m_showDetails );
239 KCookieAdvice advice = (result==TQDialog::Accepted) ? KCookieAccept:KCookieReject;
241 int preferredPolicy = m_btnGrp->id( m_btnGrp->selected() );
242 cookiejar->setPreferredDefaultPolicy( preferredPolicy );
244 switch ( preferredPolicy )
247 cookiejar->setGlobalAdvice( advice );
250 cookiejar->setDomainAdvice( cookie, advice );
259 KCookieDetail::KCookieDetail( KHttpCookieList cookieList,
int cookieCount,
260 TQWidget* parent,
const char* name )
261 :TQGroupBox( parent, name )
263 setTitle( i18n(
"Cookie Details") );
264 TQGridLayout* grid =
new TQGridLayout(
this, 9, 2,
265 KDialog::spacingHint(),
266 KDialog::marginHint() );
267 grid->addRowSpacing( 0, fontMetrics().lineSpacing() );
268 grid->setColStretch( 1, 3 );
270 TQLabel* label =
new TQLabel( i18n(
"Name:"),
this );
271 grid->addWidget( label, 1, 0 );
272 m_name =
new KLineEdit(
this );
273 m_name->setReadOnly(
true );
274 m_name->setMaximumWidth( fontMetrics().maxWidth() * 25 );
275 grid->addWidget( m_name, 1 ,1 );
278 label =
new TQLabel( i18n(
"Value:"),
this );
279 grid->addWidget( label, 2, 0 );
280 m_value =
new KLineEdit(
this );
281 m_value->setReadOnly(
true );
282 m_value->setMaximumWidth( fontMetrics().maxWidth() * 25 );
283 grid->addWidget( m_value, 2, 1);
285 label =
new TQLabel( i18n(
"Expires:"),
this );
286 grid->addWidget( label, 3, 0 );
287 m_expires =
new KLineEdit(
this );
288 m_expires->setReadOnly(
true );
289 m_expires->setMaximumWidth(fontMetrics().maxWidth() * 25 );
290 grid->addWidget( m_expires, 3, 1);
292 label =
new TQLabel( i18n(
"Path:"),
this );
293 grid->addWidget( label, 4, 0 );
294 m_path =
new KLineEdit(
this );
295 m_path->setReadOnly(
true );
296 m_path->setMaximumWidth( fontMetrics().maxWidth() * 25 );
297 grid->addWidget( m_path, 4, 1);
299 label =
new TQLabel( i18n(
"Domain:"),
this );
300 grid->addWidget( label, 5, 0 );
301 m_domain =
new KLineEdit(
this );
302 m_domain->setReadOnly(
true );
303 m_domain->setMaximumWidth( fontMetrics().maxWidth() * 25 );
304 grid->addWidget( m_domain, 5, 1);
306 label =
new TQLabel( i18n(
"Exposure:"),
this );
307 grid->addWidget( label, 6, 0 );
308 m_secure =
new KLineEdit(
this );
309 m_secure->setReadOnly(
true );
310 m_secure->setMaximumWidth( fontMetrics().maxWidth() * 25 );
311 grid->addWidget( m_secure, 6, 1 );
313 if ( cookieCount > 1 )
315 TQPushButton* btnNext =
new TQPushButton( i18n(
"Next cookie",
"&Next >>"),
this );
316 btnNext->setFixedSize( btnNext->sizeHint() );
317 grid->addMultiCellWidget( btnNext, 8, 8, 0, 1 );
318 connect( btnNext, TQ_SIGNAL(clicked()), TQ_SLOT(slotNextCookie()) );
319 #ifndef TQT_NO_TOOLTIP
320 TQToolTip::add( btnNext, i18n(
"Show details of the next cookie") );
323 m_cookieList = cookieList;
328 KCookieDetail::~KCookieDetail()
332 void KCookieDetail::slotNextCookie()
334 KHttpCookiePtr cookie = m_cookieList.first();
335 if (m_cookie)
while(cookie)
337 if (cookie == m_cookie)
339 cookie = m_cookieList.next();
342 cookie = m_cookieList.next();
346 m_cookie = m_cookieList.first();
350 m_name->setText( m_cookie->name() );
351 m_value->setText( ( m_cookie->value() ) );
352 if ( m_cookie->domain().isEmpty() )
353 m_domain->setText( i18n(
"Not specified") );
355 m_domain->setText( m_cookie->domain() );
356 m_path->setText( m_cookie->path() );
357 TQDateTime cookiedate;
358 cookiedate.setTime_t( m_cookie->expireDate() );
359 if ( m_cookie->expireDate() )
360 m_expires->setText( TDEGlobal::locale()->formatDateTime(cookiedate) );
362 m_expires->setText( i18n(
"End of Session") );
364 if (m_cookie->isSecure())
366 if (m_cookie->isHttpOnly())
367 sec = i18n(
"Secure servers only");
369 sec = i18n(
"Secure servers, page scripts");
373 if (m_cookie->isHttpOnly())
374 sec = i18n(
"Servers");
376 sec = i18n(
"Servers, page scripts");
378 m_secure->setText( sec );
382 #include "kcookiewin.moc"