KHtml

storepassbar.cpp
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2009 Eduardo Robles Elvira <edulix at gmail dot com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "storepassbar.h"
22 
23 #include "khtmlviewbar.h"
24 #include "khtml_part.h"
25 #include "khtmlview.h"
26 #include <kcolorscheme.h>
27 #include <kconfiggroup.h>
28 #include <QPalette>
29 
30 StorePassBar::StorePassBar(QWidget *parent) :
31  KHTMLViewBarWidget(true, parent)
32 {
33  setupUi(centralWidget());
34 
35  m_store->setIcon(QIcon::fromTheme("document-save"));
36  // Same as KStandardGuiItem::no()
37  m_neverForThisSite->setIcon(QIcon::fromTheme("process-stop"));
38  m_doNotStore->setIcon(QIcon::fromTheme("dialog-cancel"));
39  centralWidget()->setFocusProxy(m_store);
40 
41  QPalette pal = palette();
43  setPalette(pal);
44  setBackgroundRole(QPalette::Base);
45  setAutoFillBackground(true);
46 
47  connect(m_store, SIGNAL(clicked()), this, SIGNAL(storeClicked()));
48  connect(m_neverForThisSite, SIGNAL(clicked()), this,
49  SIGNAL(neverForThisSiteClicked()));
50  connect(m_doNotStore, SIGNAL(clicked()), this,
51  SIGNAL(doNotStoreClicked()));
52 
53  m_store->setFocus();
54 }
55 
56 void StorePassBar::setHost(const QString &host)
57 {
58  if (host.isEmpty()) {
59  m_label->setText(i18n("Do you want to store this password?"));
60  } else {
61  m_label->setText(i18n("Do you want to store this password for %1?", host));
62  }
63 }
64 
65 StorePass::StorePass(KHTMLPart *part) :
66  m_part(part)
67 {
68  connect(&m_storePassBar, SIGNAL(storeClicked()), this, SLOT(slotStoreClicked()));
69  connect(&m_storePassBar, SIGNAL(neverForThisSiteClicked()), this,
70  SLOT(slotNeverForThisSiteClicked()));
71  connect(&m_storePassBar, SIGNAL(doNotStoreClicked()), this,
72  SLOT(slotDoNotStoreClicked()));
73 }
74 
75 StorePass::~StorePass()
76 {
77 }
78 
79 void StorePass::saveLoginInformation(const QString &host, const QString &key,
80  const QMap<QString, QString> &walletMap)
81 {
82  KConfigGroup config(KSharedConfig::openConfig(), "HTML Settings");
83  if (!config.readEntry("OfferToSaveWebsitePassword", true)) {
84  return;
85  }
86 
87  m_host = host;
88  m_key = key;
89  m_walletMap = walletMap;
90  m_storePassBar.setHost(host);
91 
92  m_part->pTopViewBar()->addBarWidget(&m_storePassBar);
93  m_part->pTopViewBar()->showBarWidget(&m_storePassBar);
94 }
95 
96 void StorePass::removeBar()
97 {
98  m_part->pTopViewBar()->hideCurrentBarWidget();
99  m_walletMap.clear();
100  m_host = m_key = "";
101  m_storePassBar.setHost(m_host);
102 }
103 
104 void StorePass::slotStoreClicked()
105 {
106  m_part->saveToWallet(m_key, m_walletMap);
107  removeBar();
108 }
109 
110 void StorePass::slotNeverForThisSiteClicked()
111 {
112  m_part->view()->addNonPasswordStorableSite(m_host);
113  removeBar();
114 }
115 
116 void StorePass::slotDoNotStoreClicked()
117 {
118  removeBar();
119 }
This class is khtml&#39;s main class.
Definition: khtml_part.h:208
void clear()
KSharedConfigPtr config()
bool isEmpty() const const
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
QString i18n(const char *text, const TYPE &arg...)
static void adjustBackground(QPalette &, BackgroundRole newRole=NormalBackground, QPalette::ColorRole color=QPalette::Base, ColorSet set=View, KSharedConfigPtr=KSharedConfigPtr())
QIcon fromTheme(const QString &name)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:09 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.