• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.8.5 API Reference
  • KDE Home
  • Contact Us
 

KIOSlave

  • kioslave
  • http
  • kcookiejar
kcookiewin.cpp
Go to the documentation of this file.
1 /*
2 This 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 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24 //----------------------------------------------------------------------------
25 //
26 // KDE File Manager -- HTTP Cookie Dialogs
27 
28 // The purpose of the QT_NO_TOOLTIP and QT_NO_WHATSTHIS ifdefs is because
29 // this file is also used in Konqueror/Embedded. One of the aims of
30 // Konqueror/Embedded is to be a small as possible to fit on embedded
31 // devices. For this it's also useful to strip out unneeded features of
32 // Qt, like for example QToolTip or QWhatsThis. The availability (or the
33 // lack thereof) can be determined using these preprocessor defines.
34 // The same applies to the QT_NO_ACCEL ifdef below. I hope it doesn't make
35 // too much trouble... (Simon)
36 
37 #include "kcookiewin.h"
38 #include "kcookiejar.h"
39 
40 #include <QtGui/QLabel>
41 #include <QtGui/QLayout>
42 #include <QtGui/QGroupBox>
43 #include <QtGui/QPushButton>
44 #include <QtGui/QRadioButton>
45 #include <QtGui/QShortcut>
46 
47 #include <kwindowsystem.h>
48 #include <klocale.h>
49 #include <kglobal.h>
50 #include <klineedit.h>
51 #include <kiconloader.h>
52 #include <kapplication.h>
53 #include <kvbox.h>
54 #include <kdatetime.h>
55 
56 KCookieWin::KCookieWin( QWidget *parent, KHttpCookieList cookieList,
57  int defaultButton, bool showDetails )
58  :KDialog( parent )
59 {
60  setModal(true);
61  setObjectName("cookiealert");
62  setButtons(Yes|No|Details);
63 #ifndef Q_WS_QWS //FIXME(E): Implement for Qt Embedded
64  setCaption( i18n("Cookie Alert") );
65  setWindowIcon( KIcon("preferences-web-browser-cookies") );
66  // all cookies in the list should have the same window at this time, so let's take the first
67  if( cookieList.first().windowIds().count() > 0 )
68  {
69 #ifdef Q_WS_WIN
70  KWindowSystem::setMainWindow( this, reinterpret_cast<WId>( cookieList.first().windowIds().first() ) );
71 #else
72  KWindowSystem::setMainWindow( this, cookieList.first().windowIds().first());
73 #endif
74  }
75  else
76  {
77  // No window associated... make sure the user notices our dialog.
78 #ifdef Q_WS_X11
79  KWindowSystem::setState( winId(), NET::KeepAbove );
80 #endif
81  kapp->updateUserTimestamp();
82  }
83 #endif
84  KVBox* vBox1 = new KVBox( this );
85  vBox1->setSpacing( -1 );
86  setMainWidget(vBox1);
87  // Cookie image and message to user
88  KHBox* hBox = new KHBox( vBox1 );
89  QLabel* icon = new QLabel( hBox );
90  icon->setPixmap(KIcon("dialog-warning").pixmap(IconSize(KIconLoader::Desktop)));
91  icon->setAlignment( Qt::AlignCenter );
92  icon->setFixedSize( 2*icon->sizeHint() );
93 
94  int count = cookieList.count();
95 
96  KVBox* vBox = new KVBox( hBox );
97  QString txt = i18np("You received a cookie from",
98  "You received %1 cookies from", count);
99  QLabel* lbl = new QLabel( txt, vBox );
100  lbl->setAlignment( Qt::AlignCenter );
101  const KHttpCookie& cookie = cookieList.first();
102 
103  QString host (cookie.host());
104  int pos = host.indexOf(':');
105  if ( pos > 0 )
106  {
107  QString portNum = host.left(pos);
108  host.remove(0, pos+1);
109  host += ':';
110  host += portNum;
111  }
112 
113  txt = QString("<b>%1</b>").arg( QUrl::fromAce(host.toLatin1()) );
114  if (cookie.isCrossDomain())
115  txt += i18n(" <b>[Cross Domain]</b>");
116  lbl = new QLabel( txt, vBox );
117  lbl->setAlignment( Qt::AlignCenter );
118  lbl = new QLabel( i18n("Do you want to accept or reject?"), vBox );
119  lbl->setAlignment( Qt::AlignCenter );
120 
121  // Cookie Details dialog...
122  m_detailView = new KCookieDetail( cookieList, count, vBox1 );
123  setDetailsWidget(m_detailView);
124 
125  // Cookie policy choice...
126  QGroupBox *m_btnGrp = new QGroupBox(i18n("Apply Choice To"),vBox1);
127  QVBoxLayout *vbox = new QVBoxLayout;
128  txt = (count == 1)? i18n("&Only this cookie") : i18n("&Only these cookies");
129  m_onlyCookies = new QRadioButton( txt, m_btnGrp );
130  vbox->addWidget(m_onlyCookies);
131 #ifndef QT_NO_WHATSTHIS
132  m_onlyCookies->setWhatsThis(i18n("Select this option to accept/reject only this cookie. "
133  "You will be prompted if another cookie is received. "
134  "<em>(see WebBrowsing/Cookies in the System Settings)</em>." ) );
135 #endif
136  m_allCookiesDomain = new QRadioButton( i18n("All cookies from this do&main"), m_btnGrp );
137  vbox->addWidget(m_allCookiesDomain);
138 #ifndef QT_NO_WHATSTHIS
139  m_allCookiesDomain->setWhatsThis(i18n("Select this option to accept/reject all cookies from "
140  "this site. Choosing this option will add a new policy for "
141  "the site this cookie originated from. This policy will be "
142  "permanent until you manually change it from the System Settings "
143  "<em>(see WebBrowsing/Cookies in the System Settings)</em>.") );
144 #endif
145  m_allCookies = new QRadioButton( i18n("All &cookies"), m_btnGrp);
146  vbox->addWidget(m_allCookies);
147 #ifndef QT_NO_WHATSTHIS
148  m_allCookies->setWhatsThis(i18n("Select this option to accept/reject all cookies from "
149  "anywhere. Choosing this option will change the global "
150  "cookie policy set in the System Settings for all cookies "
151  "<em>(see WebBrowsing/Cookies in the System Settings)</em>.") );
152 #endif
153  m_btnGrp->setLayout(vbox);
154  if (defaultButton == KCookieJar::ApplyToShownCookiesOnly )
155  m_onlyCookies->setChecked(true);
156  else if (defaultButton == KCookieJar::ApplyToCookiesFromDomain)
157  m_allCookiesDomain->setChecked(true);
158  else if (defaultButton == KCookieJar::ApplyToAllCookies)
159  m_allCookies->setChecked(true);
160  else
161  m_onlyCookies->setChecked(true);
162  setButtonText(KDialog::Yes, i18n("&Accept"));
163  setButtonText(KDialog::No, i18n("&Reject"));
164  //QShortcut( Qt::Key_Escape, btn, SLOT(animateClick()) );
165  setButtonToolTip(Details, i18n("See or modify the cookie information") );
166  setDefaultButton(Yes);
167 
168  setDetailsWidgetVisible(showDetails);
169 }
170 
171 KCookieWin::~KCookieWin()
172 {
173 }
174 
175 KCookieAdvice KCookieWin::advice( KCookieJar *cookiejar, const KHttpCookie& cookie )
176 {
177  int result = exec();
178 
179  cookiejar->setShowCookieDetails ( isDetailsWidgetVisible() );
180 
181  KCookieAdvice advice = (result==KDialog::Yes) ? KCookieAccept : KCookieReject;
182 
183  KCookieJar::KCookieDefaultPolicy preferredPolicy = KCookieJar::ApplyToShownCookiesOnly;
184  if (m_allCookiesDomain->isChecked()) {
185  preferredPolicy = KCookieJar::ApplyToCookiesFromDomain;
186  cookiejar->setDomainAdvice( cookie, advice );
187  } else if (m_allCookies->isChecked()) {
188  preferredPolicy = KCookieJar::ApplyToAllCookies;
189  cookiejar->setGlobalAdvice( advice );
190  }
191  cookiejar->setPreferredDefaultPolicy( preferredPolicy );
192 
193  return advice;
194 }
195 
196 KCookieDetail::KCookieDetail( KHttpCookieList cookieList, int cookieCount,
197  QWidget* parent )
198  :QGroupBox( parent )
199 {
200  setTitle( i18n("Cookie Details") );
201  QGridLayout* grid = new QGridLayout( this );
202  grid->addItem( new QSpacerItem(0, fontMetrics().lineSpacing()), 0, 0 );
203  grid->setColumnStretch( 1, 3 );
204 
205  QLabel* label = new QLabel( i18n("Name:"), this );
206  grid->addWidget( label, 1, 0 );
207  m_name = new KLineEdit( this );
208  m_name->setReadOnly( true );
209  m_name->setMaximumWidth( fontMetrics().maxWidth() * 25 );
210  grid->addWidget( m_name, 1 ,1 );
211 
212  //Add the value
213  label = new QLabel( i18n("Value:"), this );
214  grid->addWidget( label, 2, 0 );
215  m_value = new KLineEdit( this );
216  m_value->setReadOnly( true );
217  m_value->setMaximumWidth( fontMetrics().maxWidth() * 25 );
218  grid->addWidget( m_value, 2, 1);
219 
220  label = new QLabel( i18n("Expires:"), this );
221  grid->addWidget( label, 3, 0 );
222  m_expires = new KLineEdit( this );
223  m_expires->setReadOnly( true );
224  m_expires->setMaximumWidth(fontMetrics().maxWidth() * 25 );
225  grid->addWidget( m_expires, 3, 1);
226 
227  label = new QLabel( i18n("Path:"), this );
228  grid->addWidget( label, 4, 0 );
229  m_path = new KLineEdit( this );
230  m_path->setReadOnly( true );
231  m_path->setMaximumWidth( fontMetrics().maxWidth() * 25 );
232  grid->addWidget( m_path, 4, 1);
233 
234  label = new QLabel( i18n("Domain:"), this );
235  grid->addWidget( label, 5, 0 );
236  m_domain = new KLineEdit( this );
237  m_domain->setReadOnly( true );
238  m_domain->setMaximumWidth( fontMetrics().maxWidth() * 25 );
239  grid->addWidget( m_domain, 5, 1);
240 
241  label = new QLabel( i18n("Exposure:"), this );
242  grid->addWidget( label, 6, 0 );
243  m_secure = new KLineEdit( this );
244  m_secure->setReadOnly( true );
245  m_secure->setMaximumWidth( fontMetrics().maxWidth() * 25 );
246  grid->addWidget( m_secure, 6, 1 );
247 
248  if ( cookieCount > 1 )
249  {
250  QPushButton* btnNext = new QPushButton( i18nc("Next cookie","&Next >>"), this );
251  btnNext->setFixedSize( btnNext->sizeHint() );
252  grid->addWidget( btnNext, 8, 0, 1, 2 );
253  connect( btnNext, SIGNAL(clicked()), SLOT(slotNextCookie()) );
254 #ifndef QT_NO_TOOLTIP
255  btnNext->setToolTip(i18n("Show details of the next cookie") );
256 #endif
257  }
258  m_cookieList = cookieList;
259  m_cookieNumber = 0;
260  slotNextCookie();
261 }
262 
263 KCookieDetail::~KCookieDetail()
264 {
265 }
266 
267 void KCookieDetail::slotNextCookie()
268 {
269  if (m_cookieNumber == m_cookieList.count() - 1)
270  m_cookieNumber = 0;
271  else
272  ++m_cookieNumber;
273  displayCookieDetails();
274 }
275 
276 void KCookieDetail::displayCookieDetails()
277 {
278  const KHttpCookie& cookie = m_cookieList.at(m_cookieNumber);
279  m_name->setText(cookie.name());
280  m_value->setText((cookie.value()));
281  if (cookie.domain().isEmpty())
282  m_domain->setText(i18n("Not specified"));
283  else
284  m_domain->setText(cookie.domain());
285  m_path->setText(cookie.path());
286  KDateTime cookiedate;
287  cookiedate.setTime_t(cookie.expireDate());
288  if (cookie.expireDate())
289  m_expires->setText(KGlobal::locale()->formatDateTime(cookiedate));
290  else
291  m_expires->setText(i18n("End of Session"));
292  QString sec;
293  if (cookie.isSecure())
294  {
295  if (cookie.isHttpOnly())
296  sec = i18n("Secure servers only");
297  else
298  sec = i18n("Secure servers, page scripts");
299  }
300  else
301  {
302  if (cookie.isHttpOnly())
303  sec = i18n("Servers");
304  else
305  sec = i18n("Servers, page scripts");
306  }
307  m_secure->setText(sec);
308 }
309 
310 #include "kcookiewin.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Fri Nov 16 2012 15:17:56 by doxygen 1.8.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIOSlave

Skip menu "KIOSlave"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.8.5 API Reference

Skip menu "kdelibs-4.8.5 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal