File indexing completed on 2024-05-19 11:39:32
0001 /* This file is part of the KDE project 0002 * 0003 * Copyright (C) 2009 Eduardo Robles Elvira <edulix at gmail dot com> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "storepassbar.h" 0022 0023 #include "khtmlviewbar.h" 0024 #include "khtml_part.h" 0025 #include "khtmlview.h" 0026 #include <kcolorscheme.h> 0027 #include <kconfiggroup.h> 0028 #include <QPalette> 0029 0030 StorePassBar::StorePassBar(QWidget *parent) : 0031 KHTMLViewBarWidget(true, parent) 0032 { 0033 setupUi(centralWidget()); 0034 0035 m_store->setIcon(QIcon::fromTheme("document-save")); 0036 // Same as KStandardGuiItem::no() 0037 m_neverForThisSite->setIcon(QIcon::fromTheme("process-stop")); 0038 m_doNotStore->setIcon(QIcon::fromTheme("dialog-cancel")); 0039 centralWidget()->setFocusProxy(m_store); 0040 0041 QPalette pal = palette(); 0042 KColorScheme::adjustBackground(pal, KColorScheme::ActiveBackground); 0043 setPalette(pal); 0044 setBackgroundRole(QPalette::Base); 0045 setAutoFillBackground(true); 0046 0047 connect(m_store, SIGNAL(clicked()), this, SIGNAL(storeClicked())); 0048 connect(m_neverForThisSite, SIGNAL(clicked()), this, 0049 SIGNAL(neverForThisSiteClicked())); 0050 connect(m_doNotStore, SIGNAL(clicked()), this, 0051 SIGNAL(doNotStoreClicked())); 0052 0053 m_store->setFocus(); 0054 } 0055 0056 void StorePassBar::setHost(const QString &host) 0057 { 0058 if (host.isEmpty()) { 0059 m_label->setText(i18n("Do you want to store this password?")); 0060 } else { 0061 m_label->setText(i18n("Do you want to store this password for %1?", host)); 0062 } 0063 } 0064 0065 StorePass::StorePass(KHTMLPart *part) : 0066 m_part(part) 0067 { 0068 connect(&m_storePassBar, SIGNAL(storeClicked()), this, SLOT(slotStoreClicked())); 0069 connect(&m_storePassBar, SIGNAL(neverForThisSiteClicked()), this, 0070 SLOT(slotNeverForThisSiteClicked())); 0071 connect(&m_storePassBar, SIGNAL(doNotStoreClicked()), this, 0072 SLOT(slotDoNotStoreClicked())); 0073 } 0074 0075 StorePass::~StorePass() 0076 { 0077 } 0078 0079 void StorePass::saveLoginInformation(const QString &host, const QString &key, 0080 const QMap<QString, QString> &walletMap) 0081 { 0082 KConfigGroup config(KSharedConfig::openConfig(), "HTML Settings"); 0083 if (!config.readEntry("OfferToSaveWebsitePassword", true)) { 0084 return; 0085 } 0086 0087 m_host = host; 0088 m_key = key; 0089 m_walletMap = walletMap; 0090 m_storePassBar.setHost(host); 0091 0092 m_part->pTopViewBar()->addBarWidget(&m_storePassBar); 0093 m_part->pTopViewBar()->showBarWidget(&m_storePassBar); 0094 } 0095 0096 void StorePass::removeBar() 0097 { 0098 m_part->pTopViewBar()->hideCurrentBarWidget(); 0099 m_walletMap.clear(); 0100 m_host = m_key = ""; 0101 m_storePassBar.setHost(m_host); 0102 } 0103 0104 void StorePass::slotStoreClicked() 0105 { 0106 m_part->saveToWallet(m_key, m_walletMap); 0107 removeBar(); 0108 } 0109 0110 void StorePass::slotNeverForThisSiteClicked() 0111 { 0112 m_part->view()->addNonPasswordStorableSite(m_host); 0113 removeBar(); 0114 } 0115 0116 void StorePass::slotDoNotStoreClicked() 0117 { 0118 removeBar(); 0119 } 0120 0121 #include "moc_storepassbar.cpp"