• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeioslave/http
 

tdeioslave/http

  • tdeioslave
  • http
  • kcookiejar
kcookiewin.cpp
1/*
2This file is part of KDE
3
4 Copyright (C) 2000- Waldo Bastian <bastian@kde.org>
5 Copyright (C) 2000- Dawit Alemayehu <adawit@kde.org>
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in
15all copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23*/
24//----------------------------------------------------------------------------
25//
26// KDE File Manager -- HTTP Cookie Dialogs
27// $Id$
28
29// The purpose of the TQT_NO_TOOLTIP and TQT_NO_WHATSTHIS ifdefs is because
30// this file is also used in Konqueror/Embedded. One of the aims of
31// Konqueror/Embedded is to be a small as possible to fit on embedded
32// devices. For this it's also useful to strip out unneeded features of
33// Qt, like for example TQToolTip or TQWhatsThis. The availability (or the
34// lack thereof) can be determined using these preprocessor defines.
35// The same applies to the TQT_NO_ACCEL ifdef below. I hope it doesn't make
36// too much trouble... (Simon)
37
38#include <tqhbox.h>
39#include <tqvbox.h>
40#include <tqaccel.h>
41#include <tqlabel.h>
42#include <tqwidget.h>
43#include <tqlayout.h>
44#include <tqgroupbox.h>
45#include <tqdatetime.h>
46#include <tqmessagebox.h>
47#include <tqpushbutton.h>
48#include <tqradiobutton.h>
49#include <tqvbuttongroup.h>
50
51#ifndef TQT_NO_TOOLTIP
52#include <tqtooltip.h>
53#endif
54
55#ifndef TQT_NO_WHATSTHIS
56#include <tqwhatsthis.h>
57#endif
58
59#include <kidna.h>
60#include <twin.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>
67
68#ifdef TQ_WS_X11
69#include <X11/Xlib.h>
70#endif
71
72#include "kcookiejar.h"
73#include "kcookiewin.h"
74
75KCookieWin::KCookieWin( TQWidget *parent, KHttpCookieList cookieList,
76 int defaultButton, bool showDetails )
77 :KDialog( parent, "cookiealert", true )
78{
79#ifndef TQ_WS_QWS //FIXME(E): Implement for Qt Embedded
80 setCaption( i18n("Cookie Alert") );
81 setIcon( SmallIcon("cookie") );
82 // all cookies in the list should have the same window at this time, so let's take the first
83# ifdef TQ_WS_X11
84 if( cookieList.first()->windowIds().count() > 0 )
85 {
86 XSetTransientForHint( tqt_xdisplay(), winId(), cookieList.first()->windowIds().first());
87 }
88 else
89 {
90 // No window associated... make sure the user notices our dialog.
91 KWin::setState( winId(), NET::KeepAbove );
92 tdeApp->updateUserTimestamp();
93 }
94# endif
95#endif
96 // Main widget's layout manager...
97 TQVBoxLayout* vlayout = new TQVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
98 vlayout->setResizeMode( TQLayout::Fixed );
99
100 // Cookie image and message to user
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() );
107
108 int count = cookieList.count();
109
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();
116
117 TQString host (cookie->host());
118 int pos = host.find(':');
119 if ( pos > 0 )
120 {
121 TQString portNum = host.left(pos);
122 host.remove(0, pos+1);
123 host += ':';
124 host += portNum;
125 }
126
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 );
135
136 // Cookie Details dialog...
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();
141
142 // Cookie policy choice...
143 m_btnGrp = new TQVButtonGroup( i18n("Apply Choice To"), this );
144 m_btnGrp->setRadioButtonExclusive( true );
145
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>." ) );
152#endif
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>.") );
161#endif
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>.") );
169#endif
170 m_btnGrp->insert( rb );
171 vlayout->addWidget( m_btnGrp );
172
173 if ( defaultButton > -1 && defaultButton < 3 )
174 m_btnGrp->setButton( defaultButton );
175 else
176 m_btnGrp->setButton( 1 );
177
178 // Accept/Reject buttons
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 );
184 btn->setFocus();
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 );
191#ifndef TQT_NO_ACCEL
192 TQAccel* a = new TQAccel( this );
193 a->connectItem( a->insertItem(TQt::Key_Escape), btn, TQ_SLOT(animateClick()) );
194#endif
195
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") );
202#endif
203
204
205 vlayout->addWidget( bbox );
206 setFixedSize( sizeHint() );
207}
208
209KCookieWin::~KCookieWin()
210{
211}
212
213void KCookieWin::slotCookieDetails()
214{
215 if ( m_detailView->isVisible() )
216 {
217 m_detailView->setMaximumSize( 0, 0 );
218 m_detailView->adjustSize();
219 m_detailView->hide();
220 m_button->setText( i18n( "&Details >>" ) );
221 m_showDetails = false;
222 }
223 else
224 {
225 m_detailView->setMaximumSize( 1000, 1000 );
226 m_detailView->adjustSize();
227 m_detailView->show();
228 m_button->setText( i18n( "&Details <<" ) );
229 m_showDetails = true;
230 }
231}
232
233KCookieAdvice KCookieWin::advice( KCookieJar *cookiejar, KHttpCookie* cookie )
234{
235 int result = exec();
236
237 cookiejar->setShowCookieDetails ( m_showDetails );
238
239 KCookieAdvice advice = (result==TQDialog::Accepted) ? KCookieAccept:KCookieReject;
240
241 int preferredPolicy = m_btnGrp->id( m_btnGrp->selected() );
242 cookiejar->setPreferredDefaultPolicy( preferredPolicy );
243
244 switch ( preferredPolicy )
245 {
246 case 2:
247 cookiejar->setGlobalAdvice( advice );
248 break;
249 case 1:
250 cookiejar->setDomainAdvice( cookie, advice );
251 break;
252 case 0:
253 default:
254 break;
255 }
256 return advice;
257}
258
259KCookieDetail::KCookieDetail( KHttpCookieList cookieList, int cookieCount,
260 TQWidget* parent, const char* name )
261 :TQGroupBox( parent, name )
262{
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 );
269
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 );
276
277 //Add the value
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);
284
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);
291
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);
298
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);
305
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 );
312
313 if ( cookieCount > 1 )
314 {
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") );
321#endif
322 }
323 m_cookieList = cookieList;
324 m_cookie = 0;
325 slotNextCookie();
326}
327
328KCookieDetail::~KCookieDetail()
329{
330}
331
332void KCookieDetail::slotNextCookie()
333{
334 KHttpCookiePtr cookie = m_cookieList.first();
335 if (m_cookie) while(cookie)
336 {
337 if (cookie == m_cookie)
338 {
339 cookie = m_cookieList.next();
340 break;
341 }
342 cookie = m_cookieList.next();
343 }
344 m_cookie = cookie;
345 if (!m_cookie)
346 m_cookie = m_cookieList.first();
347
348 if ( m_cookie )
349 {
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") );
354 else
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) );
361 else
362 m_expires->setText( i18n("End of Session") );
363 TQString sec;
364 if (m_cookie->isSecure())
365 {
366 if (m_cookie->isHttpOnly())
367 sec = i18n("Secure servers only");
368 else
369 sec = i18n("Secure servers, page scripts");
370 }
371 else
372 {
373 if (m_cookie->isHttpOnly())
374 sec = i18n("Servers");
375 else
376 sec = i18n("Servers, page scripts");
377 }
378 m_secure->setText( sec );
379 }
380}
381
382#include "kcookiewin.moc"

tdeioslave/http

Skip menu "tdeioslave/http"
  • Main Page
  • Alphabetical List
  • Class List
  • File List

tdeioslave/http

Skip menu "tdeioslave/http"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeioslave/http by doxygen 1.9.4
This website is maintained by Timothy Pearson.