~ubuntu-branches/debian/sid/kde-baseapps/sid

« back to all changes in this revision

Viewing changes to konqueror/settings/kio/kcookiespolicies.cpp

  • Committer: Package Import Robot
  • Author(s): Modestas Vainius, Eshat Cakar, Pino Toscano
  • Date: 2012-06-09 22:18:08 UTC
  • mfrom: (4.2.1) (6.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20120609221808-h1l0ekd5qmb8nefr
Tags: 4:4.8.4-1
* New upstream release.

[ Eshat Cakar ]
* Add watch file.
* Bump kde-sc-dev-latest build dependency to version 4:4.8.4.
* Update installed files.

[ Pino Toscano ]
* Move files of the konqueror documentation from kde-baseapps-data to
  konqueror itself.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
// Own
28
28
#include "kcookiespolicies.h"
29
29
 
 
30
// Local
 
31
#include "ksaveioconfig.h"
 
32
 
30
33
// Qt
31
34
#include <QtGui/QLayout>
32
35
#include <QtGui/QCheckBox>
44
47
#include <kurl.h>
45
48
#include <kdebug.h>
46
49
 
47
 
#include "ksaveioconfig.h"
48
50
 
49
51
// QUrl::fromAce/toAce don't accept a domain that starts with a '.', like we do here.
50
52
// So we use these wrappers.
51
 
QString tolerantFromAce(const QByteArray& _domain)
52
 
{
53
 
    QByteArray domain(_domain);
54
 
    const bool hasDot = domain.startsWith('.');
55
 
    if (hasDot)
56
 
        domain.remove(0, 1);
57
 
    QString ret = QUrl::fromAce(domain);
58
 
    if (hasDot) {
59
 
        ret.prepend('.');
60
 
    }
61
 
    return ret;
62
 
}
63
 
 
64
 
static QByteArray tolerantToAce(const QString& _domain)
65
 
{
66
 
    QString domain(_domain);
67
 
    const bool hasDot = domain.startsWith('.');
68
 
    if (hasDot)
69
 
        domain.remove(0, 1);
70
 
    QByteArray ret = QUrl::toAce(domain);
71
 
    if (hasDot) {
72
 
        ret.prepend('.');
73
 
    }
74
 
    return ret;
75
 
}
76
 
 
77
 
 
78
 
KCookiesPolicies::KCookiesPolicies(const KComponentData &componentData, QWidget *parent)
79
 
                 :KCModule(componentData, parent)
80
 
{
81
 
    QVBoxLayout *mainLayout = new QVBoxLayout(this);
82
 
    mainLayout->setMargin(0);
83
 
 
84
 
    dlg = new KCookiesPolicyDlgUI (this);
85
 
    dlg->kListViewSearchLine->setTreeWidget(dlg->lvDomainPolicy);
 
53
QString tolerantFromAce (const QByteArray& _domain)
 
54
{
 
55
    QByteArray domain (_domain);
 
56
    const bool hasDot = domain.startsWith ('.');
 
57
    if (hasDot)
 
58
        domain.remove (0, 1);
 
59
    QString ret = QUrl::fromAce (domain);
 
60
    if (hasDot) {
 
61
        ret.prepend ('.');
 
62
    }
 
63
    return ret;
 
64
}
 
65
 
 
66
static QByteArray tolerantToAce (const QString& _domain)
 
67
{
 
68
    QString domain (_domain);
 
69
    const bool hasDot = domain.startsWith ('.');
 
70
    if (hasDot)
 
71
        domain.remove (0, 1);
 
72
    QByteArray ret = QUrl::toAce (domain);
 
73
    if (hasDot) {
 
74
        ret.prepend ('.');
 
75
    }
 
76
    return ret;
 
77
}
 
78
 
 
79
 
 
80
KCookiesPolicies::KCookiesPolicies (const KComponentData& componentData, QWidget* parent)
 
81
    : KCModule (componentData, parent)
 
82
{
 
83
    mUi.setupUi (this);
 
84
    mUi.kListViewSearchLine->setTreeWidget (mUi.lvDomainPolicy);
86
85
    QList<int> columns;
87
 
    columns.append(0);
88
 
    dlg->kListViewSearchLine->setSearchColumns(columns);
89
 
 
90
 
    dlg->pbNew->setIcon(KIcon("list-add"));
91
 
    dlg->pbChange->setIcon(KIcon("edit-rename"));
92
 
    dlg->pbDelete->setIcon(KIcon("list-remove"));
93
 
    dlg->pbDeleteAll->setIcon(KIcon("edit-delete"));
94
 
 
95
 
    mainLayout->addWidget(dlg);
 
86
    columns.append (0);
 
87
    mUi.kListViewSearchLine->setSearchColumns (columns);
 
88
 
 
89
    mUi.pbNew->setIcon (KIcon ("list-add"));
 
90
    mUi.pbChange->setIcon (KIcon ("edit-rename"));
 
91
    mUi.pbDelete->setIcon (KIcon ("list-remove"));
 
92
    mUi.pbDeleteAll->setIcon (KIcon ("edit-delete"));
96
93
 
97
94
    // Connect the main swicth :) Enable/disable cookie support
98
 
    connect( dlg->cbEnableCookies, SIGNAL( toggled(bool) ),
99
 
             SLOT( cookiesEnabled(bool) ) );
100
 
    connect( dlg->cbEnableCookies, SIGNAL( toggled(bool) ),
101
 
             SLOT( configChanged() ) );
 
95
    connect (mUi.cbEnableCookies, SIGNAL (toggled (bool)),
 
96
             SLOT (cookiesEnabled (bool)));
 
97
    connect (mUi.cbEnableCookies, SIGNAL (toggled (bool)),
 
98
             SLOT (configChanged()));
102
99
 
103
100
    // Connect the preference check boxes...
104
 
    connect ( dlg->cbRejectCrossDomainCookies, SIGNAL(toggled(bool)),
105
 
              SLOT(configChanged()));
106
 
    connect ( dlg->cbAutoAcceptSessionCookies, SIGNAL(toggled(bool)),
107
 
              SLOT(configChanged()));
108
 
    connect ( dlg->cbIgnoreCookieExpirationDate, SIGNAL(toggled(bool)),
109
 
              SLOT(configChanged()));
110
 
 
111
 
    connect ( dlg->cbAutoAcceptSessionCookies, SIGNAL(toggled(bool)),
112
 
              SLOT(autoAcceptSessionCookies(bool)));
113
 
    connect ( dlg->cbIgnoreCookieExpirationDate, SIGNAL(toggled(bool)),
114
 
              SLOT(ignoreCookieExpirationDate(bool)));
115
 
 
116
 
    connect ( dlg->rbPolicyAsk, SIGNAL(toggled(bool)),
117
 
              SLOT(configChanged()));
118
 
    connect ( dlg->rbPolicyAccept, SIGNAL(toggled(bool)),
119
 
              SLOT(configChanged()));
120
 
    connect ( dlg->rbPolicyReject, SIGNAL(toggled(bool)),
121
 
              SLOT(configChanged()));
 
101
    connect (mUi.cbRejectCrossDomainCookies, SIGNAL (toggled (bool)),
 
102
             SLOT (configChanged()));
 
103
    connect (mUi.cbAutoAcceptSessionCookies, SIGNAL (toggled (bool)),
 
104
             SLOT (configChanged()));
 
105
    connect (mUi.cbIgnoreCookieExpirationDate, SIGNAL (toggled (bool)),
 
106
             SLOT (configChanged()));
 
107
 
 
108
    connect (mUi.cbAutoAcceptSessionCookies, SIGNAL (toggled (bool)),
 
109
             SLOT (autoAcceptSessionCookies (bool)));
 
110
    connect (mUi.cbIgnoreCookieExpirationDate, SIGNAL (toggled (bool)),
 
111
             SLOT (ignoreCookieExpirationDate (bool)));
 
112
 
 
113
    connect (mUi.rbPolicyAsk, SIGNAL (toggled (bool)),
 
114
             SLOT (configChanged()));
 
115
    connect (mUi.rbPolicyAccept, SIGNAL (toggled (bool)),
 
116
             SLOT (configChanged()));
 
117
    connect (mUi.rbPolicyReject, SIGNAL (toggled (bool)),
 
118
             SLOT (configChanged()));
122
119
    // Connect signals from the domain specific policy listview.
123
 
    connect( dlg->lvDomainPolicy, SIGNAL(itemSelectionChanged()),
124
 
             SLOT(selectionChanged()) );
125
 
    connect( dlg->lvDomainPolicy, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
126
 
             SLOT(changePressed() ) );
 
120
    connect (mUi.lvDomainPolicy, SIGNAL (itemSelectionChanged()),
 
121
             SLOT (selectionChanged()));
 
122
    connect (mUi.lvDomainPolicy, SIGNAL (itemDoubleClicked (QTreeWidgetItem*, int)),
 
123
             SLOT (changePressed()));
127
124
 
128
125
    // Connect the buttons...
129
 
    connect( dlg->pbNew, SIGNAL(clicked()), SLOT( addPressed() ) );
130
 
    connect( dlg->pbChange, SIGNAL( clicked() ), SLOT( changePressed() ) );
131
 
    connect( dlg->pbDelete, SIGNAL( clicked() ), SLOT( deletePressed() ) );
132
 
    connect( dlg->pbDeleteAll, SIGNAL( clicked() ), SLOT( deleteAllPressed() ) );
 
126
    connect (mUi.pbNew, SIGNAL (clicked()), SLOT (addPressed()));
 
127
    connect (mUi.pbChange, SIGNAL (clicked()), SLOT (changePressed()));
 
128
    connect (mUi.pbDelete, SIGNAL (clicked()), SLOT (deletePressed()));
 
129
    connect (mUi.pbDeleteAll, SIGNAL (clicked()), SLOT (deleteAllPressed()));
133
130
}
134
131
 
135
132
KCookiesPolicies::~KCookiesPolicies()
138
135
 
139
136
void KCookiesPolicies::configChanged ()
140
137
{
141
 
  //kDebug() << "KCookiesPolicies::configChanged...";
142
 
  emit changed(true);
143
 
}
144
 
 
145
 
void KCookiesPolicies::cookiesEnabled( bool enable )
146
 
{
147
 
  dlg->bgDefault->setEnabled( enable );
148
 
  dlg->bgPreferences->setEnabled ( enable );
149
 
  dlg->gbDomainSpecific->setEnabled( enable );
150
 
 
151
 
  if (enable)
152
 
  {
153
 
    ignoreCookieExpirationDate ( enable );
154
 
    autoAcceptSessionCookies ( enable );
155
 
  }
156
 
}
157
 
 
158
 
void KCookiesPolicies::ignoreCookieExpirationDate ( bool enable )
159
 
{
160
 
  bool isAutoAcceptChecked = dlg->cbAutoAcceptSessionCookies->isChecked();
161
 
  enable = (enable && isAutoAcceptChecked);
162
 
 
163
 
  dlg->bgDefault->setEnabled( !enable );
164
 
  dlg->gbDomainSpecific->setEnabled( !enable );
165
 
}
166
 
 
167
 
void KCookiesPolicies::autoAcceptSessionCookies ( bool enable )
168
 
{
169
 
  bool isIgnoreExpirationChecked = dlg->cbIgnoreCookieExpirationDate->isChecked();
170
 
  enable = (enable && isIgnoreExpirationChecked);
171
 
 
172
 
  dlg->bgDefault->setEnabled( !enable );
173
 
  dlg->gbDomainSpecific->setEnabled( !enable );
174
 
}
175
 
 
176
 
void KCookiesPolicies::addNewPolicy(const QString& domain)
177
 
{
178
 
  PolicyDlg pdlg (i18nc("@title:window", "New Cookie Policy"), this);
179
 
  pdlg.setEnableHostEdit (true, domain);
180
 
 
181
 
  if (dlg->rbPolicyAccept->isChecked())
182
 
    pdlg.setPolicy(KCookieAdvice::Reject);
183
 
  else
184
 
    pdlg.setPolicy(KCookieAdvice::Accept);
185
 
 
186
 
  if (pdlg.exec() && !pdlg.domain().isEmpty())
187
 
  {
188
 
    QString domain = tolerantFromAce(pdlg.domain().toLatin1());
189
 
    int advice = pdlg.advice();
190
 
 
191
 
    if ( !handleDuplicate(domain, advice) )
192
 
    {
193
 
      const char* strAdvice = KCookieAdvice::adviceToStr(advice);
194
 
      QTreeWidgetItem* item = new QTreeWidgetItem (dlg->lvDomainPolicy,
195
 
                                                   QStringList()<< domain << i18n(strAdvice));
196
 
      m_pDomainPolicy.insert (item, strAdvice);
197
 
      configChanged();
198
 
    }
199
 
  }
 
138
    //kDebug() << "KCookiesPolicies::configChanged...";
 
139
    emit changed (true);
 
140
}
 
141
 
 
142
void KCookiesPolicies::cookiesEnabled (bool enable)
 
143
{
 
144
    mUi.bgDefault->setEnabled (enable);
 
145
    mUi.bgPreferences->setEnabled (enable);
 
146
    mUi.gbDomainSpecific->setEnabled (enable);
 
147
 
 
148
    if (enable) {
 
149
        ignoreCookieExpirationDate (enable);
 
150
        autoAcceptSessionCookies (enable);
 
151
    }
 
152
}
 
153
 
 
154
void KCookiesPolicies::ignoreCookieExpirationDate (bool enable)
 
155
{
 
156
    bool isAutoAcceptChecked = mUi.cbAutoAcceptSessionCookies->isChecked();
 
157
    enable = (enable && isAutoAcceptChecked);
 
158
 
 
159
    mUi.bgDefault->setEnabled (!enable);
 
160
    mUi.gbDomainSpecific->setEnabled (!enable);
 
161
}
 
162
 
 
163
void KCookiesPolicies::autoAcceptSessionCookies (bool enable)
 
164
{
 
165
    bool isIgnoreExpirationChecked = mUi.cbIgnoreCookieExpirationDate->isChecked();
 
166
    enable = (enable && isIgnoreExpirationChecked);
 
167
 
 
168
    mUi.bgDefault->setEnabled (!enable);
 
169
    mUi.gbDomainSpecific->setEnabled (!enable);
 
170
}
 
171
 
 
172
void KCookiesPolicies::addNewPolicy (const QString& domain)
 
173
{
 
174
    KCookiesPolicySelectionDlg pdlg (this);
 
175
    pdlg.setWindowTitle (i18nc ("@title:window", "New Cookie Policy"));
 
176
    pdlg.setEnableHostEdit (true, domain);
 
177
 
 
178
    if (mUi.rbPolicyAccept->isChecked())
 
179
        pdlg.setPolicy (KCookieAdvice::Reject);
 
180
    else
 
181
        pdlg.setPolicy (KCookieAdvice::Accept);
 
182
 
 
183
    if (pdlg.exec() && !pdlg.domain().isEmpty()) {
 
184
        QString domain = tolerantFromAce (pdlg.domain().toLatin1());
 
185
        int advice = pdlg.advice();
 
186
 
 
187
        if (!handleDuplicate (domain, advice)) {
 
188
            const char* strAdvice = KCookieAdvice::adviceToStr (advice);
 
189
            QTreeWidgetItem* item = new QTreeWidgetItem (mUi.lvDomainPolicy,
 
190
                    QStringList() << domain << i18n (strAdvice));
 
191
            m_pDomainPolicy.insert (item, strAdvice);
 
192
            configChanged();
 
193
        }
 
194
    }
200
195
}
201
196
 
202
197
 
203
198
void KCookiesPolicies::addPressed()
204
199
{
205
 
  addNewPolicy (QString());
 
200
    addNewPolicy (QString());
206
201
}
207
202
 
208
203
void KCookiesPolicies::changePressed()
209
204
{
210
 
  QTreeWidgetItem* index = dlg->lvDomainPolicy->currentItem();
211
 
 
212
 
  if (!index)
213
 
    return;
214
 
 
215
 
  QString oldDomain = index->text(0);
216
 
 
217
 
  PolicyDlg pdlg (i18nc("@title:window", "Change Cookie Policy"), this);
218
 
  pdlg.setPolicy (KCookieAdvice::strToAdvice(m_pDomainPolicy[index]));
219
 
  pdlg.setEnableHostEdit (true, oldDomain);
220
 
 
221
 
  if( pdlg.exec() && !pdlg.domain().isEmpty())
222
 
  {
223
 
    QString newDomain = tolerantFromAce(pdlg.domain().toLatin1());
224
 
    int advice = pdlg.advice();
225
 
    if (newDomain == oldDomain || !handleDuplicate(newDomain, advice))
226
 
    {
227
 
      m_pDomainPolicy[index] = KCookieAdvice::adviceToStr(advice);
228
 
      index->setText(0, newDomain);
229
 
      index->setText(1, i18n(m_pDomainPolicy[index]) );
230
 
      configChanged();
 
205
    QTreeWidgetItem* index = mUi.lvDomainPolicy->currentItem();
 
206
 
 
207
    if (!index)
 
208
        return;
 
209
 
 
210
    QString oldDomain = index->text (0);
 
211
 
 
212
    KCookiesPolicySelectionDlg pdlg (this);
 
213
    pdlg.setWindowTitle (i18nc ("@title:window", "Change Cookie Policy"));
 
214
    pdlg.setPolicy (KCookieAdvice::strToAdvice (m_pDomainPolicy[index]));
 
215
    pdlg.setEnableHostEdit (true, oldDomain);
 
216
 
 
217
    if (pdlg.exec() && !pdlg.domain().isEmpty()) {
 
218
        QString newDomain = tolerantFromAce (pdlg.domain().toLatin1());
 
219
        int advice = pdlg.advice();
 
220
        if (newDomain == oldDomain || !handleDuplicate (newDomain, advice)) {
 
221
            m_pDomainPolicy[index] = KCookieAdvice::adviceToStr (advice);
 
222
            index->setText (0, newDomain);
 
223
            index->setText (1, i18n (m_pDomainPolicy[index]));
 
224
            configChanged();
 
225
        }
231
226
    }
232
 
  }
233
227
}
234
228
 
235
 
bool KCookiesPolicies::handleDuplicate( const QString& domain, int advice )
 
229
bool KCookiesPolicies::handleDuplicate (const QString& domain, int advice)
236
230
{
237
 
  QTreeWidgetItem* item = dlg->lvDomainPolicy->topLevelItem(0);
238
 
  while ( item != 0 )
239
 
  {
240
 
    if ( item->text(0) == domain )
241
 
    {
242
 
      QString msg = i18n("<qt>A policy already exists for"
243
 
                         "<center><b>%1</b></center>"
244
 
                         "Do you want to replace it?</qt>", domain);
245
 
      int res = KMessageBox::warningContinueCancel(this, msg,
246
 
                                          i18nc("@title:window", "Duplicate Policy"),
247
 
                                          KGuiItem(i18n("Replace")));
248
 
      if ( res == KMessageBox::Continue )
249
 
      {
250
 
        m_pDomainPolicy[item]= KCookieAdvice::adviceToStr(advice);
251
 
        item->setText(0, domain);
252
 
        item->setText(1, i18n(m_pDomainPolicy[item]));
253
 
        configChanged();
254
 
        return true;
255
 
      }
256
 
      else
257
 
        return true;  // User Cancelled!!
 
231
    QTreeWidgetItem* item = mUi.lvDomainPolicy->topLevelItem (0);
 
232
    while (item != 0) {
 
233
        if (item->text (0) == domain) {
 
234
            QString msg = i18n ("<qt>A policy already exists for"
 
235
                                "<center><b>%1</b></center>"
 
236
                                "Do you want to replace it?</qt>", domain);
 
237
            int res = KMessageBox::warningContinueCancel (this, msg,
 
238
                      i18nc ("@title:window", "Duplicate Policy"),
 
239
                      KGuiItem (i18n ("Replace")));
 
240
            if (res == KMessageBox::Continue) {
 
241
                m_pDomainPolicy[item] = KCookieAdvice::adviceToStr (advice);
 
242
                item->setText (0, domain);
 
243
                item->setText (1, i18n (m_pDomainPolicy[item]));
 
244
                configChanged();
 
245
                return true;
 
246
            } else
 
247
                return true;  // User Cancelled!!
 
248
        }
 
249
        item = mUi.lvDomainPolicy->itemBelow (item);
258
250
    }
259
 
    item = dlg->lvDomainPolicy->itemBelow(item);
260
 
  }
261
 
  return false;
 
251
    return false;
262
252
}
263
253
 
264
254
void KCookiesPolicies::deletePressed()
265
255
{
266
 
  QTreeWidgetItem* nextItem = 0L;
267
 
 
268
 
  Q_FOREACH(QTreeWidgetItem* item, dlg->lvDomainPolicy->selectedItems()) {
269
 
    nextItem = dlg->lvDomainPolicy->itemBelow(item);
270
 
    if (!nextItem)
271
 
      nextItem = dlg->lvDomainPolicy->itemAbove(item);
272
 
 
273
 
    m_pDomainPolicy.remove(item);
274
 
    delete item;
275
 
  }
276
 
 
277
 
  if (nextItem)
278
 
    nextItem->setSelected(true);
279
 
 
280
 
  updateButtons();
281
 
  configChanged();
 
256
    QTreeWidgetItem* nextItem = 0L;
 
257
 
 
258
    Q_FOREACH (QTreeWidgetItem * item, mUi.lvDomainPolicy->selectedItems()) {
 
259
        nextItem = mUi.lvDomainPolicy->itemBelow (item);
 
260
        if (!nextItem)
 
261
            nextItem = mUi.lvDomainPolicy->itemAbove (item);
 
262
 
 
263
        m_pDomainPolicy.remove (item);
 
264
        delete item;
 
265
    }
 
266
 
 
267
    if (nextItem)
 
268
        nextItem->setSelected (true);
 
269
 
 
270
    updateButtons();
 
271
    configChanged();
282
272
}
283
273
 
284
274
void KCookiesPolicies::deleteAllPressed()
285
275
{
286
 
  m_pDomainPolicy.clear();
287
 
  dlg->lvDomainPolicy->clear();
288
 
  updateButtons();
289
 
  configChanged();
 
276
    m_pDomainPolicy.clear();
 
277
    mUi.lvDomainPolicy->clear();
 
278
    updateButtons();
 
279
    configChanged();
290
280
}
291
281
 
292
282
void KCookiesPolicies::updateButtons()
293
283
{
294
 
  bool hasItems = dlg->lvDomainPolicy->topLevelItemCount() > 0;
 
284
    bool hasItems = mUi.lvDomainPolicy->topLevelItemCount() > 0;
295
285
 
296
 
  dlg->pbChange->setEnabled ((hasItems && d_itemsSelected == 1));
297
 
  dlg->pbDelete->setEnabled ((hasItems && d_itemsSelected > 0));
298
 
  dlg->pbDeleteAll->setEnabled ( hasItems );
 
286
    mUi.pbChange->setEnabled ( (hasItems && d_itemsSelected == 1));
 
287
    mUi.pbDelete->setEnabled ( (hasItems && d_itemsSelected > 0));
 
288
    mUi.pbDeleteAll->setEnabled (hasItems);
299
289
}
300
290
 
301
 
void KCookiesPolicies::updateDomainList(const QStringList &domainConfig)
 
291
void KCookiesPolicies::updateDomainList (const QStringList& domainConfig)
302
292
{
303
 
  dlg->lvDomainPolicy->clear();
304
 
 
305
 
  QStringList::ConstIterator it = domainConfig.begin();
306
 
  for (; it != domainConfig.end(); ++it)
307
 
  {
308
 
    QString domain;
309
 
    KCookieAdvice::Value advice = KCookieAdvice::Dunno;
310
 
 
311
 
    splitDomainAdvice(*it, domain, advice);
312
 
 
313
 
    if (!domain.isEmpty())
314
 
    {
315
 
        QTreeWidgetItem* index = new QTreeWidgetItem( dlg->lvDomainPolicy, QStringList() << tolerantFromAce(domain.toLatin1()) <<
316
 
                                                  i18n(KCookieAdvice::adviceToStr(advice)) );
317
 
        m_pDomainPolicy[index] = KCookieAdvice::adviceToStr(advice);
318
 
    }
319
 
  }
320
 
 
321
 
  dlg->lvDomainPolicy->sortItems(0, Qt::AscendingOrder);
 
293
    mUi.lvDomainPolicy->clear();
 
294
 
 
295
    QStringList::ConstIterator it = domainConfig.begin();
 
296
    for (; it != domainConfig.end(); ++it) {
 
297
        QString domain;
 
298
        KCookieAdvice::Value advice = KCookieAdvice::Dunno;
 
299
 
 
300
        splitDomainAdvice (*it, domain, advice);
 
301
 
 
302
        if (!domain.isEmpty()) {
 
303
            QTreeWidgetItem* index = new QTreeWidgetItem (mUi.lvDomainPolicy, QStringList() << tolerantFromAce (domain.toLatin1()) <<
 
304
                    i18n (KCookieAdvice::adviceToStr (advice)));
 
305
            m_pDomainPolicy[index] = KCookieAdvice::adviceToStr (advice);
 
306
        }
 
307
    }    
 
308
 
 
309
    mUi.lvDomainPolicy->sortItems(0, Qt::AscendingOrder);
322
310
}
323
311
 
324
312
void KCookiesPolicies::selectionChanged ()
325
313
{
326
 
  d_itemsSelected = dlg->lvDomainPolicy->selectedItems().count();
 
314
    d_itemsSelected = mUi.lvDomainPolicy->selectedItems().count();
327
315
 
328
 
  updateButtons ();
 
316
    updateButtons ();
329
317
}
330
318
 
331
319
void KCookiesPolicies::load()
332
320
{
333
 
  d_itemsSelected = 0;
334
 
 
335
 
  KConfig cfg ("kcookiejarrc");
336
 
  KConfigGroup group = cfg.group ("Cookie Policy");
337
 
 
338
 
  bool enableCookies = group.readEntry("Cookies", true);
339
 
  dlg->cbEnableCookies->setChecked (enableCookies);
340
 
  cookiesEnabled( enableCookies );
341
 
 
342
 
  // Warning: the default values are duplicated in kcookiejar.cpp
343
 
  KCookieAdvice::Value advice = KCookieAdvice::strToAdvice (group.readEntry(
344
 
                                               "CookieGlobalAdvice", "Accept"));
345
 
  switch (advice)
346
 
  {
 
321
    d_itemsSelected = 0;
 
322
 
 
323
    KConfig cfg ("kcookiejarrc");
 
324
    KConfigGroup group = cfg.group ("Cookie Policy");
 
325
 
 
326
    bool enableCookies = group.readEntry ("Cookies", true);
 
327
    mUi.cbEnableCookies->setChecked (enableCookies);
 
328
    cookiesEnabled (enableCookies);
 
329
 
 
330
    // Warning: the default values are duplicated in kcookiejar.cpp
 
331
    KCookieAdvice::Value advice = KCookieAdvice::strToAdvice (group.readEntry (
 
332
                                      "CookieGlobalAdvice", "Accept"));
 
333
    switch (advice) {
347
334
    case KCookieAdvice::Accept:
348
 
      dlg->rbPolicyAccept->setChecked (true);
349
 
      break;
 
335
        mUi.rbPolicyAccept->setChecked (true);
 
336
        break;
350
337
    case KCookieAdvice::Reject:
351
 
      dlg->rbPolicyReject->setChecked (true);
352
 
      break;
 
338
        mUi.rbPolicyReject->setChecked (true);
 
339
        break;
353
340
    case KCookieAdvice::Ask:
354
341
    case KCookieAdvice::Dunno:
355
342
    default:
356
 
      dlg->rbPolicyAsk->setChecked (true);
357
 
  }
358
 
 
359
 
  bool enable = group.readEntry("RejectCrossDomainCookies", true);
360
 
  dlg->cbRejectCrossDomainCookies->setChecked (enable);
361
 
 
362
 
  bool sessionCookies = group.readEntry("AcceptSessionCookies", true);
363
 
  dlg->cbAutoAcceptSessionCookies->setChecked (sessionCookies);
364
 
  bool cookieExpiration = group.readEntry("IgnoreExpirationDate", false);
365
 
  dlg->cbIgnoreCookieExpirationDate->setChecked (cookieExpiration);
366
 
  updateDomainList(group.readEntry("CookieDomainAdvice", QStringList()));
367
 
 
368
 
  if (enableCookies)
369
 
  {
370
 
    ignoreCookieExpirationDate( cookieExpiration );
371
 
    autoAcceptSessionCookies( sessionCookies );
372
 
    updateButtons();
373
 
  }
 
343
        mUi.rbPolicyAsk->setChecked (true);
 
344
    }
 
345
 
 
346
    bool enable = group.readEntry ("RejectCrossDomainCookies", true);
 
347
    mUi.cbRejectCrossDomainCookies->setChecked (enable);
 
348
 
 
349
    bool sessionCookies = group.readEntry ("AcceptSessionCookies", true);
 
350
    mUi.cbAutoAcceptSessionCookies->setChecked (sessionCookies);
 
351
    bool cookieExpiration = group.readEntry ("IgnoreExpirationDate", false);
 
352
    mUi.cbIgnoreCookieExpirationDate->setChecked (cookieExpiration);
 
353
    updateDomainList (group.readEntry ("CookieDomainAdvice", QStringList()));
 
354
 
 
355
    if (enableCookies) {
 
356
        ignoreCookieExpirationDate (cookieExpiration);
 
357
        autoAcceptSessionCookies (sessionCookies);
 
358
        updateButtons();
 
359
    }
374
360
}
375
361
 
376
362
void KCookiesPolicies::save()
377
363
{
378
 
  KConfig cfg ( "kcookiejarrc" );
379
 
  KConfigGroup group = cfg.group( "Cookie Policy" );
380
 
 
381
 
  bool state = dlg->cbEnableCookies->isChecked();
382
 
  group.writeEntry( "Cookies", state );
383
 
  state = dlg->cbRejectCrossDomainCookies->isChecked();
384
 
  group.writeEntry( "RejectCrossDomainCookies", state );
385
 
  state = dlg->cbAutoAcceptSessionCookies->isChecked();
386
 
  group.writeEntry( "AcceptSessionCookies", state );
387
 
  state = dlg->cbIgnoreCookieExpirationDate->isChecked();
388
 
  group.writeEntry( "IgnoreExpirationDate", state );
389
 
 
390
 
  QString advice;
391
 
  if (dlg->rbPolicyAccept->isChecked())
392
 
      advice = KCookieAdvice::adviceToStr(KCookieAdvice::Accept);
393
 
  else if (dlg->rbPolicyReject->isChecked())
394
 
      advice = KCookieAdvice::adviceToStr(KCookieAdvice::Reject);
395
 
  else
396
 
      advice = KCookieAdvice::adviceToStr(KCookieAdvice::Ask);
397
 
 
398
 
  group.writeEntry("CookieGlobalAdvice", advice);
399
 
 
400
 
  QStringList domainConfig;
401
 
  QMapIterator<QTreeWidgetItem*, const char*> it (m_pDomainPolicy);
402
 
  while (it.hasNext()) {
403
 
      it.next();
404
 
      QTreeWidgetItem *item = it.key();
405
 
      QString policy = tolerantToAce(item->text(0));
406
 
      policy += QLatin1Char(':');
407
 
      policy += QLatin1String(it.value());
408
 
      domainConfig << policy;
409
 
  }
410
 
 
411
 
  group.writeEntry("CookieDomainAdvice", domainConfig);
412
 
  group.sync();
413
 
 
414
 
  // Update the cookiejar...
415
 
  if (!dlg->cbEnableCookies->isChecked())
416
 
  {
417
 
      QDBusInterface kded("org.kde.kded", "/modules/kcookiejar", "org.kde.KCookieServer", QDBusConnection::sessionBus());
418
 
      kded.call( "shutdown" );
419
 
  }
420
 
  else
421
 
  {
422
 
       QDBusInterface kded("org.kde.kded", "/modules/kcookiejar", "org.kde.KCookieServer", QDBusConnection::sessionBus());
423
 
       QDBusReply<void> reply = kded.call( "reloadPolicy" );
424
 
    if (!reply.isValid())
425
 
      KMessageBox::sorry(0, i18n("Unable to communicate with the cookie handler service.\n"
426
 
                                 "Any changes you made will not take effect until the service "
427
 
                                 "is restarted."));
428
 
  }
429
 
 
430
 
  // Force running io-slave to reload configurations...
431
 
  KSaveIOConfig::updateRunningIOSlaves (this);
432
 
  emit changed( false );
 
364
    KConfig cfg ("kcookiejarrc");
 
365
    KConfigGroup group = cfg.group ("Cookie Policy");
 
366
 
 
367
    bool state = mUi.cbEnableCookies->isChecked();
 
368
    group.writeEntry ("Cookies", state);
 
369
    state = mUi.cbRejectCrossDomainCookies->isChecked();
 
370
    group.writeEntry ("RejectCrossDomainCookies", state);
 
371
    state = mUi.cbAutoAcceptSessionCookies->isChecked();
 
372
    group.writeEntry ("AcceptSessionCookies", state);
 
373
    state = mUi.cbIgnoreCookieExpirationDate->isChecked();
 
374
    group.writeEntry ("IgnoreExpirationDate", state);
 
375
 
 
376
    QString advice;
 
377
    if (mUi.rbPolicyAccept->isChecked())
 
378
        advice = KCookieAdvice::adviceToStr (KCookieAdvice::Accept);
 
379
    else if (mUi.rbPolicyReject->isChecked())
 
380
        advice = KCookieAdvice::adviceToStr (KCookieAdvice::Reject);
 
381
    else
 
382
        advice = KCookieAdvice::adviceToStr (KCookieAdvice::Ask);
 
383
 
 
384
    group.writeEntry ("CookieGlobalAdvice", advice);
 
385
 
 
386
    QStringList domainConfig;
 
387
    QMapIterator<QTreeWidgetItem*, const char*> it (m_pDomainPolicy);
 
388
    while (it.hasNext()) {
 
389
        it.next();
 
390
        QTreeWidgetItem* item = it.key();
 
391
        QString policy = tolerantToAce (item->text (0));
 
392
        policy += QLatin1Char (':');
 
393
        policy += QLatin1String (it.value());
 
394
        domainConfig << policy;
 
395
    }
 
396
 
 
397
    group.writeEntry ("CookieDomainAdvice", domainConfig);
 
398
    group.sync();
 
399
 
 
400
    // Update the cookiejar...
 
401
    if (!mUi.cbEnableCookies->isChecked()) {
 
402
        QDBusInterface kded ("org.kde.kded", "/modules/kcookiejar", "org.kde.KCookieServer", QDBusConnection::sessionBus());
 
403
        kded.call ("shutdown");
 
404
    } else {
 
405
        QDBusInterface kded ("org.kde.kded", "/modules/kcookiejar", "org.kde.KCookieServer", QDBusConnection::sessionBus());
 
406
        QDBusReply<void> reply = kded.call ("reloadPolicy");
 
407
        if (!reply.isValid())
 
408
            KMessageBox::sorry (0, i18n ("Unable to communicate with the cookie handler service.\n"
 
409
                                         "Any changes you made will not take effect until the service "
 
410
                                         "is restarted."));
 
411
    }
 
412
 
 
413
    // Force running io-slave to reload configurations...
 
414
    KSaveIOConfig::updateRunningIOSlaves (this);
 
415
    emit changed (false);
433
416
}
434
417
 
435
418
 
436
419
void KCookiesPolicies::defaults()
437
420
{
438
 
  dlg->cbEnableCookies->setChecked( true );
439
 
  dlg->rbPolicyAsk->setChecked( true );
440
 
  dlg->rbPolicyAccept->setChecked( false );
441
 
  dlg->rbPolicyReject->setChecked( false );
442
 
  dlg->cbRejectCrossDomainCookies->setChecked( true );
443
 
  dlg->cbAutoAcceptSessionCookies->setChecked( true );
444
 
  dlg->cbIgnoreCookieExpirationDate->setChecked( false );
445
 
  dlg->lvDomainPolicy->clear();
 
421
    mUi.cbEnableCookies->setChecked (true);
 
422
    mUi.rbPolicyAsk->setChecked (true);
 
423
    mUi.rbPolicyAccept->setChecked (false);
 
424
    mUi.rbPolicyReject->setChecked (false);
 
425
    mUi.cbRejectCrossDomainCookies->setChecked (true);
 
426
    mUi.cbAutoAcceptSessionCookies->setChecked (true);
 
427
    mUi.cbIgnoreCookieExpirationDate->setChecked (false);
 
428
    mUi.lvDomainPolicy->clear();
446
429
 
447
 
  cookiesEnabled( dlg->cbEnableCookies->isChecked() );
448
 
  updateButtons();
 
430
    cookiesEnabled (mUi.cbEnableCookies->isChecked());
 
431
    updateButtons();
449
432
}
450
433
 
451
 
void KCookiesPolicies::splitDomainAdvice (const QString& cfg, QString &domain,
452
 
                                          KCookieAdvice::Value &advice)
 
434
void KCookiesPolicies::splitDomainAdvice (const QString& cfg, QString& domain,
 
435
        KCookieAdvice::Value& advice)
453
436
{
454
 
  int sepPos = cfg.lastIndexOf(':');
455
 
 
456
 
  // Ignore any policy that does not contain a domain...
457
 
  if ( sepPos <= 0 )
458
 
    return;
459
 
 
460
 
  domain = cfg.left(sepPos);
461
 
  advice = KCookieAdvice::strToAdvice( cfg.mid( sepPos+1 ) );
 
437
    int sepPos = cfg.lastIndexOf (':');
 
438
 
 
439
    // Ignore any policy that does not contain a domain...
 
440
    if (sepPos <= 0)
 
441
        return;
 
442
 
 
443
    domain = cfg.left (sepPos);
 
444
    advice = KCookieAdvice::strToAdvice (cfg.mid (sepPos + 1));
462
445
}
463
446
 
464
447
QString KCookiesPolicies::quickHelp() const
465
448
{
466
 
  return i18n("<p><h1>Cookies</h1> Cookies contain information that Konqueror"
467
 
              " (or any other KDE application using the HTTP protocol) stores"
468
 
              " on your computer from a remote Internet server. This means"
469
 
              " that a web server can store information about you and your"
470
 
              " browsing activities on your machine for later use. You might"
471
 
              " consider this an invasion of privacy.</p><p>However, cookies are"
472
 
              " useful in certain situations. For example, they are often used"
473
 
              " by Internet shops, so you can 'put things into a shopping"
474
 
              " basket'. Some sites require you have a browser that supports"
475
 
              " cookies.</p><p>Because most people want a compromise between privacy"
476
 
              " and the benefits cookies offer, KDE offers you the ability to"
477
 
              " customize the way it handles cookies. You might, for example"
478
 
              " want to set KDE's default policy to ask you whenever a server"
479
 
              " wants to set a cookie or simply reject or accept everything."
480
 
              " For example, you might choose to accept all cookies from your"
481
 
              " favorite shopping web site. For this all you have to do is"
482
 
              " either browse to that particular site and when you are presented"
483
 
              " with the cookie dialog box, click on <i> This domain </i> under"
484
 
              " the 'apply to' tab and choose accept or simply specify the name"
485
 
              " of the site in the <i> Domain Specific Policy </i> tab and set"
486
 
              " it to accept. This enables you to receive cookies from trusted"
487
 
              " web sites without being asked every time KDE receives a cookie.</p>"
488
 
             );
 
449
    return i18n ("<p><h1>Cookies</h1> Cookies contain information that Konqueror"
 
450
                 " (or any other KDE application using the HTTP protocol) stores"
 
451
                 " on your computer from a remote Internet server. This means"
 
452
                 " that a web server can store information about you and your"
 
453
                 " browsing activities on your machine for later use. You might"
 
454
                 " consider this an invasion of privacy.</p><p>However, cookies are"
 
455
                 " useful in certain situations. For example, they are often used"
 
456
                 " by Internet shops, so you can 'put things into a shopping"
 
457
                 " basket'. Some sites require you have a browser that supports"
 
458
                 " cookies.</p><p>Because most people want a compromise between privacy"
 
459
                 " and the benefits cookies offer, KDE offers you the ability to"
 
460
                 " customize the way it handles cookies. You might, for example"
 
461
                 " want to set KDE's default policy to ask you whenever a server"
 
462
                 " wants to set a cookie or simply reject or accept everything."
 
463
                 " For example, you might choose to accept all cookies from your"
 
464
                 " favorite shopping web site. For this all you have to do is"
 
465
                 " either browse to that particular site and when you are presented"
 
466
                 " with the cookie dialog box, click on <i> This domain </i> under"
 
467
                 " the 'apply to' tab and choose accept or simply specify the name"
 
468
                 " of the site in the <i> Domain Specific Policy </i> tab and set"
 
469
                 " it to accept. This enables you to receive cookies from trusted"
 
470
                 " web sites without being asked every time KDE receives a cookie.</p>"
 
471
                );
489
472
}
490
473
 
491
474
#include "kcookiespolicies.moc"