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

KIOSlave

  • sources
  • kde-4.12
  • kdelibs
  • 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|User1|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 
85  const int count = cookieList.count();
86  const KHttpCookie& cookie = cookieList.first();
87  QString host (cookie.host());
88  int pos = host.indexOf(':');
89  if ( pos > 0 ) {
90  QString portNum = host.left(pos);
91  host.remove(0, pos+1);
92  host += ':';
93  host += portNum;
94  }
95 
96  QString txt = QLatin1String("<html><body style=\"p {line-height: 150%}; text-align: center;\">");
97  txt += i18ncp("%2 hostname, %3 optional cross domain suffix (translated below)",
98  "<p>You received a cookie from<br/>"
99  "<b>%2%3</b><br/>"
100  "Do you want to accept or reject this cookie?</p>",
101  "<p>You received %1 cookies from<br/>"
102  "<b>%2%3</b><br/>"
103  "Do you want to accept or reject these cookies?</p>",
104  count,
105  QUrl::fromAce(host.toLatin1()),
106  cookie.isCrossDomain() ? i18nc("@item:intext cross domain cookie", " [Cross Domain]") : QString());
107  txt += QLatin1String("</body></html>");
108 
109  KVBox* vBox1 = new KVBox( this );
110  vBox1->setSpacing( -1 );
111  setMainWidget(vBox1);
112  // Cookie image and message to user
113  KHBox* hBox = new KHBox( vBox1 );
114  QLabel* icon = new QLabel( hBox );
115  icon->setPixmap(KIcon("dialog-warning").pixmap(IconSize(KIconLoader::Desktop)));
116  icon->setAlignment( Qt::AlignCenter );
117  icon->setFixedSize( 2*icon->sizeHint() );
118 
119  KVBox* vBox = new KVBox(hBox);
120  QLabel* lbl = new QLabel(txt, vBox);
121  lbl->setAlignment(Qt::AlignCenter);
122 
123  // Cookie Details dialog...
124  m_detailView = new KCookieDetail( cookieList, count, vBox1 );
125  setDetailsWidget(m_detailView);
126 
127  // Cookie policy choice...
128  QGroupBox *m_btnGrp = new QGroupBox(i18n("Apply Choice To"),vBox1);
129  QVBoxLayout *vbox = new QVBoxLayout;
130  txt = (count == 1)? i18n("&Only this cookie") : i18n("&Only these cookies");
131  m_onlyCookies = new QRadioButton( txt, m_btnGrp );
132  vbox->addWidget(m_onlyCookies);
133 #ifndef QT_NO_WHATSTHIS
134  m_onlyCookies->setWhatsThis(i18n("Select this option to only accept or reject this cookie. "
135  "You will be prompted again if you receive another cookie."));
136 #endif
137  m_allCookiesDomain = new QRadioButton( i18n("All cookies from this do&main"), m_btnGrp );
138  vbox->addWidget(m_allCookiesDomain);
139 #ifndef QT_NO_WHATSTHIS
140  m_allCookiesDomain->setWhatsThis(i18n("Select this option to accept or reject all cookies from "
141  "this site. Choosing this option will add a new policy for "
142  "the site this cookie originated from. This policy will be "
143  "permanent until you manually change it from the System Settings."));
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 for all cookies until you manually change "
151  "it from the System Settings."));
152 #endif
153  m_btnGrp->setLayout(vbox);
154 
155  switch (defaultButton) {
156  case KCookieJar::ApplyToShownCookiesOnly:
157  m_onlyCookies->setChecked(true);
158  break;
159  case KCookieJar::ApplyToCookiesFromDomain:
160  m_allCookiesDomain->setChecked(true);
161  break;
162  case KCookieJar::ApplyToAllCookies:
163  m_allCookies->setChecked(true);
164  break;
165  default:
166  m_onlyCookies->setChecked(true);
167  break;
168  }
169 
170  setButtonText(KDialog::Yes, i18n("&Accept"));
171  setButtonText(KDialog::User1, i18n("Accept for this &session"));
172  setButtonIcon(KDialog::User1, KIcon("chronometer"));
173  setButtonToolTip(KDialog::User1, i18n("Accept cookie(s) until the end of the current session"));
174  setButtonText(KDialog::No, i18n("&Reject"));
175 
176  setButtonToolTip(Details, i18n("See or modify the cookie information") );
177  setDefaultButton(Yes);
178 
179  setDetailsWidgetVisible(showDetails);
180 }
181 
182 KCookieWin::~KCookieWin()
183 {
184 }
185 
186 KCookieAdvice KCookieWin::advice( KCookieJar *cookiejar, const KHttpCookie& cookie )
187 {
188  const int result = exec();
189 
190  cookiejar->setShowCookieDetails (isDetailsWidgetVisible());
191 
192  KCookieAdvice advice;
193 
194  switch (result) {
195  case KDialog::Yes:
196  advice = KCookieAccept;
197  break;
198  case KDialog::User1:
199  advice = KCookieAcceptForSession;
200  break;
201  default:
202  advice = KCookieReject;
203  break;
204  }
205 
206  KCookieJar::KCookieDefaultPolicy preferredPolicy = KCookieJar::ApplyToShownCookiesOnly;
207  if (m_allCookiesDomain->isChecked()) {
208  preferredPolicy = KCookieJar::ApplyToCookiesFromDomain;
209  cookiejar->setDomainAdvice( cookie, advice );
210  } else if (m_allCookies->isChecked()) {
211  preferredPolicy = KCookieJar::ApplyToAllCookies;
212  cookiejar->setGlobalAdvice( advice );
213  }
214  cookiejar->setPreferredDefaultPolicy( preferredPolicy );
215 
216  return advice;
217 }
218 
219 KCookieDetail::KCookieDetail( KHttpCookieList cookieList, int cookieCount,
220  QWidget* parent )
221  :QGroupBox( parent )
222 {
223  setTitle( i18n("Cookie Details") );
224  QGridLayout* grid = new QGridLayout( this );
225  grid->addItem( new QSpacerItem(0, fontMetrics().lineSpacing()), 0, 0 );
226  grid->setColumnStretch( 1, 3 );
227 
228  QLabel* label = new QLabel( i18n("Name:"), this );
229  grid->addWidget( label, 1, 0 );
230  m_name = new KLineEdit( this );
231  m_name->setReadOnly( true );
232  m_name->setMaximumWidth( fontMetrics().maxWidth() * 25 );
233  grid->addWidget( m_name, 1 ,1 );
234 
235  //Add the value
236  label = new QLabel( i18n("Value:"), this );
237  grid->addWidget( label, 2, 0 );
238  m_value = new KLineEdit( this );
239  m_value->setReadOnly( true );
240  m_value->setMaximumWidth( fontMetrics().maxWidth() * 25 );
241  grid->addWidget( m_value, 2, 1);
242 
243  label = new QLabel( i18n("Expires:"), this );
244  grid->addWidget( label, 3, 0 );
245  m_expires = new KLineEdit( this );
246  m_expires->setReadOnly( true );
247  m_expires->setMaximumWidth(fontMetrics().maxWidth() * 25 );
248  grid->addWidget( m_expires, 3, 1);
249 
250  label = new QLabel( i18n("Path:"), this );
251  grid->addWidget( label, 4, 0 );
252  m_path = new KLineEdit( this );
253  m_path->setReadOnly( true );
254  m_path->setMaximumWidth( fontMetrics().maxWidth() * 25 );
255  grid->addWidget( m_path, 4, 1);
256 
257  label = new QLabel( i18n("Domain:"), this );
258  grid->addWidget( label, 5, 0 );
259  m_domain = new KLineEdit( this );
260  m_domain->setReadOnly( true );
261  m_domain->setMaximumWidth( fontMetrics().maxWidth() * 25 );
262  grid->addWidget( m_domain, 5, 1);
263 
264  label = new QLabel( i18n("Exposure:"), this );
265  grid->addWidget( label, 6, 0 );
266  m_secure = new KLineEdit( this );
267  m_secure->setReadOnly( true );
268  m_secure->setMaximumWidth( fontMetrics().maxWidth() * 25 );
269  grid->addWidget( m_secure, 6, 1 );
270 
271  if ( cookieCount > 1 )
272  {
273  QPushButton* btnNext = new QPushButton( i18nc("Next cookie","&Next >>"), this );
274  btnNext->setFixedSize( btnNext->sizeHint() );
275  grid->addWidget( btnNext, 8, 0, 1, 2 );
276  connect( btnNext, SIGNAL(clicked()), SLOT(slotNextCookie()) );
277 #ifndef QT_NO_TOOLTIP
278  btnNext->setToolTip(i18n("Show details of the next cookie") );
279 #endif
280  }
281  m_cookieList = cookieList;
282  m_cookieNumber = 0;
283  slotNextCookie();
284 }
285 
286 KCookieDetail::~KCookieDetail()
287 {
288 }
289 
290 void KCookieDetail::slotNextCookie()
291 {
292  if (m_cookieNumber == m_cookieList.count() - 1)
293  m_cookieNumber = 0;
294  else
295  ++m_cookieNumber;
296  displayCookieDetails();
297 }
298 
299 void KCookieDetail::displayCookieDetails()
300 {
301  const KHttpCookie& cookie = m_cookieList.at(m_cookieNumber);
302  m_name->setText(cookie.name());
303  m_value->setText((cookie.value()));
304  if (cookie.domain().isEmpty())
305  m_domain->setText(i18n("Not specified"));
306  else
307  m_domain->setText(cookie.domain());
308  m_path->setText(cookie.path());
309  KDateTime cookiedate;
310  cookiedate.setTime_t(cookie.expireDate());
311  if (cookie.expireDate())
312  m_expires->setText(KGlobal::locale()->formatDateTime(cookiedate));
313  else
314  m_expires->setText(i18n("End of Session"));
315  QString sec;
316  if (cookie.isSecure())
317  {
318  if (cookie.isHttpOnly())
319  sec = i18n("Secure servers only");
320  else
321  sec = i18n("Secure servers, page scripts");
322  }
323  else
324  {
325  if (cookie.isHttpOnly())
326  sec = i18n("Servers");
327  else
328  sec = i18n("Servers, page scripts");
329  }
330  m_secure->setText(sec);
331 }
332 
333 void KCookieWin::slotButtonClicked(int button)
334 {
335  if (button == KDialog::User1) {
336  done (KDialog::User1);
337  return;
338  }
339 
340  KDialog::slotButtonClicked(button);
341 }
342 
343 
344 #include "kcookiewin.moc"
KHttpCookie::expireDate
qint64 expireDate() const
Definition: kcookiejar.h:94
i18n
QString i18n(const char *text)
kapp
#define kapp
KCookieDetail::~KCookieDetail
~KCookieDetail()
Definition: kcookiewin.cpp:286
KVBox
IconSize
int IconSize(KIconLoader::Group group)
KCookieJar::setDomainAdvice
void setDomainAdvice(const QString &_domain, KCookieAdvice _advice)
This function sets the advice for all cookies originating from _domain.
Definition: kcookiejar.cpp:1080
KCookieJar::ApplyToCookiesFromDomain
Definition: kcookiejar.h:358
KCookieJar::setShowCookieDetails
void setShowCookieDetails(bool value)
Sets the user's preference of level of detail displayed by the cookie dialog.
Definition: kcookiejar.h:376
kdatetime.h
kapplication.h
KCookieWin::advice
KCookieAdvice advice(KCookieJar *cookiejar, const KHttpCookie &cookie)
Definition: kcookiewin.cpp:186
KHttpCookie::host
QString host() const
Definition: kcookiejar.h:86
KHttpCookie
Definition: kcookiejar.h:49
label
QString label(StandardShortcut id)
KCookieAccept
Definition: kcookiejar.h:43
QWidget
QPushButton
kiconloader.h
KDialog
QString
KCookieDetail::KCookieDetail
KCookieDetail(KHttpCookieList cookieList, int cookieCount, QWidget *parent=0)
Definition: kcookiewin.cpp:219
klocale.h
KCookieWin::~KCookieWin
~KCookieWin()
Definition: kcookiewin.cpp:182
KIconLoader::Desktop
i18nc
QString i18nc(const char *ctxt, const char *text)
KHttpCookie::value
QString value() const
Definition: kcookiejar.h:89
KCookieJar::ApplyToAllCookies
Definition: kcookiejar.h:359
No
KHttpCookie::name
QString name() const
Definition: kcookiejar.h:88
KDateTime::setTime_t
void setTime_t(qint64 seconds)
kglobal.h
KCookieReject
Definition: kcookiejar.h:45
i18ncp
QString i18ncp(const char *ctxt, const char *sing, const char *plur, const A1 &a1)
KCookieJar::setGlobalAdvice
void setGlobalAdvice(KCookieAdvice _advice)
This function sets the global advice for cookies.
Definition: kcookiejar.cpp:1126
KCookieJar::ApplyToShownCookiesOnly
Definition: kcookiejar.h:357
KIcon
QGroupBox
KCookieWin::KCookieWin
KCookieWin(QWidget *parent, KHttpCookieList cookieList, int defaultButton=0, bool showDetails=false)
Definition: kcookiewin.cpp:56
kcookiewin.h
KHttpCookieList
Definition: kcookiejar.h:113
kvbox.h
KWindowSystem::setState
static void setState(WId win, unsigned long state)
KDateTime
KCookieAdvice
KCookieAdvice
Definition: kcookiejar.h:40
KLocale::formatDateTime
QString formatDateTime(const QDateTime &dateTime, DateFormat format=ShortDate, bool includeSecs=false) const
KWindowSystem::setMainWindow
static void setMainWindow(QWidget *subwindow, WId mainwindow)
kcookiejar.h
KGlobal::locale
KLocale * locale()
KCookieWin::slotButtonClicked
virtual void slotButtonClicked(int button)
Definition: kcookiewin.cpp:333
KLineEdit
KCookieAcceptForSession
Definition: kcookiejar.h:44
KCookieJar
Definition: kcookiejar.h:129
KHttpCookie::path
QString path() const
Definition: kcookiejar.h:87
Yes
KCookieJar::KCookieDefaultPolicy
KCookieDefaultPolicy
Definition: kcookiejar.h:356
QLabel
KCookieJar::setPreferredDefaultPolicy
void setPreferredDefaultPolicy(KCookieDefaultPolicy value)
Sets the user's default preference cookie policy.
Definition: kcookiejar.h:370
KHttpCookie::isSecure
bool isSecure() const
Definition: kcookiejar.h:96
KHBox::setSpacing
void setSpacing(int space)
kwindowsystem.h
klineedit.h
KHBox
KHttpCookie::isCrossDomain
bool isCrossDomain() const
Definition: kcookiejar.h:102
KLineEdit::setReadOnly
virtual void setReadOnly(bool)
KCookieDetail
Definition: kcookiewin.h:37
KLineEdit::setText
virtual void setText(const QString &)
KHttpCookie::domain
QString domain() const
Definition: kcookiejar.h:85
KHttpCookie::isHttpOnly
bool isHttpOnly() const
Definition: kcookiejar.h:103
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:58 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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