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

kwallet

  • sources
  • kde-4.14
  • kdeutils
  • kwalletmanager
  • src
  • manager
kwalletmanagerwidget.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (C) 2013 Valentin Rusu <kde@rusu.info>
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 "kwalletmanagerwidget.h"
22 #include "kwalletmanagerwidgetitem.h"
23 #include "kwallet_interface.h"
24 
25 #include <kwallet.h>
26 #include <kurl.h>
27 #include <kglobal.h>
28 #include <kmessagebox.h>
29 #include <klocalizedstring.h>
30 #include <kio/netaccess.h>
31 #include <QDragEnterEvent>
32 
33 KWalletManagerWidget::KWalletManagerWidget(QWidget* parent, Qt::WindowFlags flags):
34  KPageWidget(parent)
35 {
36  setFaceType(Auto);
37  setAcceptDrops(true);
38 
39  connect(this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), SLOT(onCurrentPageChanged(KPageWidgetItem*,KPageWidgetItem*)));
40 }
41 
42 KWalletManagerWidget::~KWalletManagerWidget()
43 {
44 
45 }
46 
47 void KWalletManagerWidget::onCurrentPageChanged(KPageWidgetItem* current, KPageWidgetItem* before)
48 {
49 
50 }
51 
52 void KWalletManagerWidget::updateWalletDisplay(QString selectWallet /* = QString() */)
53 {
54  // NOTE: this method is called upon several kwalletd events
55  static bool alreadyUpdating = false;
56  if (alreadyUpdating)
57  return;
58 
59  alreadyUpdating = true;
60  // find out pages corresponding to deleted wallets
61  const QStringList wl = KWallet::Wallet::walletList();
62  WalletPagesHash::iterator p = _walletPages.begin();
63  while ( p != _walletPages.end() ) {
64  if ( !wl.contains(p.key()) ) {
65  // remove the page corresponding to the missing wallet
66  removePage(p.value());
67  p = _walletPages.erase(p);
68  }
69  else {
70  ++p;
71  }
72  }
73 
74  // add new wallets
75  for (QStringList::const_iterator i = wl.begin(); i != wl.end(); ++i) {
76  const QString& name = *i;
77  if ( !_walletPages.contains(name) ) {
78  KWalletManagerWidgetItem *wi = new KWalletManagerWidgetItem(this, name);
79  addPage( wi );
80  _walletPages.insert(*i, wi);
81  }
82  }
83 
84  // update existing wallets display, e.g. icon
85  WalletPagesHash::const_iterator cp = _walletPages.constBegin();
86  WalletPagesHash::const_iterator cend = _walletPages.constEnd();
87  for ( ; cp != cend; cp++ ) {
88  cp.value()->updateWalletDisplay();
89  }
90 
91  if (!selectWallet.isEmpty()) {
92  setCurrentPage(_walletPages[selectWallet]);
93  }
94  alreadyUpdating = false;
95 }
96 
97 bool KWalletManagerWidget::hasWallet(const QString& name) const
98 {
99  return _walletPages.contains(name);
100 }
101 
102 bool KWalletManagerWidget::openWalletFile(const QString& path)
103 {
104  Q_ASSERT(0);
105  // TODO: implement this method: add a new tab with an editor centered on a file
106  return false;
107 }
108 
109 bool KWalletManagerWidget::openWallet(const QString& name)
110 {
111  bool result = false;
112  if (_walletPages.contains(name)) {
113  KWalletManagerWidgetItem *wi = _walletPages[name];
114  setCurrentPage(wi);
115  result = wi->openWallet();
116  }
117  return result;
118 }
119 
120 const QString& KWalletManagerWidget::activeWalletName() const
121 {
122  return qobject_cast<KWalletManagerWidgetItem*>(currentPage())->walletName();
123 }
124 
125 void KWalletManagerWidget::dragEnterEvent(QDragEnterEvent* e)
126 {
127  if (e->provides("application/x-kwallet-wallet")) {
128  e->accept();
129  } else {
130  e->ignore();
131  }
132 }
133 
134 void KWalletManagerWidget::dragMoveEvent(QDragMoveEvent* e)
135 {
136  qDebug("KWalletManagerWidget::dragMoveEvent");
137 // KUrl dummy;
138 // QListWidgetItem *dummy2;
139 // if (shouldIgnoreDropEvent(e, &dummy, &dummy2)) {
140 // e->ignore();
141 // } else {
142 // e->accept();
143 // }
144 }
145 
146 void KWalletManagerWidget::dropEvent(QDropEvent* e)
147 {
148  qDebug("KWalletManagerWidget::dropEvent");
149 // KUrl u;
150 // QListWidgetItem *item;
151 // if (shouldIgnoreDropEvent(e, &u, &item)) {
152 // e->ignore();
153 // return;
154 // }
155 //
156 // if (!item) {
157 // // Not dropped over an item thus it is a wallet
158 // const QString dest = KGlobal::dirs()->saveLocation("kwallet") + u.fileName();
159 // if (QFile::exists(dest)) {
160 // KMessageBox::sorry(viewport(), i18n("That wallet file already exists. You cannot overwrite wallets."));
161 // e->ignore();
162 // return;
163 // }
164 //
165 // // FIXME: verify that it is a real wallet file first
166 // KIO::NetAccess::file_copy(u, KUrl(dest));
167 // e->accept();
168 // } else {
169 // // Dropped over an item thus it is a folder
170 // KWalletItem *kwi = dynamic_cast<KWalletItem *>(item);
171 // Q_ASSERT(kwi);
172 // if (kwi) {
173 // kwi->processDropEvent(e);
174 // }
175 // }
176 }
177 
178 bool KWalletManagerWidget::shouldIgnoreDropEvent(const QDropEvent* e, KUrl* u) const
179 {
180  return false;
181 // if (e->source() == viewport()) {
182 // return true;
183 // }
184 //
185 // if (!e->provides("application/x-kwallet-folder") &&
186 // !e->provides("application/x-kwallet-wallet") &&
187 // !e->provides("text/uri-list")) {
188 // return true;
189 // }
190 //
191 // // Over wallets folders, over nothing wallets
192 // *item = itemAt(e->pos());
193 // const QByteArray edata = e->encodedData(item ? "application/x-kwallet-folder" : "application/x-kwallet-wallet");
194 // *u = decodeUrl(edata);
195 // if (*u == KUrl()) {
196 // *u = decodeUrl(e->encodedData("text/uri-list"));
197 // }
198 //
199 // return *u == KUrl();
200 }
201 
202 #include "kwalletmanagerwidget.moc"
KWalletManagerWidget::openWallet
bool openWallet(const QString &name)
Definition: kwalletmanagerwidget.cpp:109
QWidget
QHash::insert
iterator insert(const Key &key, const T &value)
QDragMoveEvent
KWalletManagerWidget::~KWalletManagerWidget
virtual ~KWalletManagerWidget()
Definition: kwalletmanagerwidget.cpp:42
KWalletManagerWidget::dragEnterEvent
virtual void dragEnterEvent(QDragEnterEvent *e)
Definition: kwalletmanagerwidget.cpp:125
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QList::const_iterator
QDropEvent::provides
virtual bool provides(const char *mimeType) const
KWalletManagerWidget::KWalletManagerWidget
KWalletManagerWidget(QWidget *parent=0, Qt::WindowFlags flags=0)
Definition: kwalletmanagerwidget.cpp:33
kwalletmanagerwidgetitem.h
QHash::constEnd
const_iterator constEnd() const
QDragMoveEvent::accept
void accept()
KWalletManagerWidget::openWalletFile
bool openWalletFile(const QString &path)
Definition: kwalletmanagerwidget.cpp:102
QDropEvent
QString::isEmpty
bool isEmpty() const
QHash::begin
iterator begin()
QString
QStringList
KPageWidget
QHash::erase
iterator erase(iterator pos)
KWalletManagerWidgetItem
Definition: kwalletmanagerwidgetitem.h:26
QDragMoveEvent::ignore
void ignore()
QList::end
iterator end()
KWalletManagerWidget::hasWallet
bool hasWallet(const QString &) const
Definition: kwalletmanagerwidget.cpp:97
kwalletmanagerwidget.h
QHash::constBegin
const_iterator constBegin() const
QDragEnterEvent
KWalletManagerWidget::dropEvent
virtual void dropEvent(QDropEvent *e)
Definition: kwalletmanagerwidget.cpp:146
KPageWidgetItem
KWalletManagerWidget::dragMoveEvent
virtual void dragMoveEvent(QDragMoveEvent *e)
Definition: kwalletmanagerwidget.cpp:134
Qt::WindowFlags
typedef WindowFlags
QHash::contains
bool contains(const Key &key) const
KWalletManagerWidget::updateWalletDisplay
void updateWalletDisplay(QString selectWallet=QString())
Definition: kwalletmanagerwidget.cpp:52
QHash::end
iterator end()
KWalletManagerWidget::activeWalletName
const QString & activeWalletName() const
Definition: kwalletmanagerwidget.cpp:120
QList::begin
iterator begin()
KWalletManagerWidgetItem::openWallet
bool openWallet()
Definition: kwalletmanagerwidgetitem.cpp:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:01 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kwallet

Skip menu "kwallet"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

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