24 #include <kcomponentdata.h>
26 #include <kio/netaccess.h>
28 #include <kmessagebox.h>
29 #include <kstandarddirs.h>
34 #include <QApplication>
38 #include <QDragEnterEvent>
39 #include <QMouseEvent>
46 setText(0, QString::fromLatin1(
"%1 (%2)").arg(_name).arg(_entries));
47 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled);
52 KIconLoader *loader = KIconLoader::global();
53 QPixmap pix = loader->loadIcon( _name, group, 0,
54 KIconLoader::DefaultState, QStringList(),0,
true );
56 pix = loader->loadIcon( _name.toLower(), group, 0,
57 KIconLoader::DefaultState, QStringList(),0,
true);
59 pix = loader->loadIcon( QLatin1String(
"folder-red" ), group, 0,
60 KIconLoader::DefaultState, QStringList(),0,
true);
65 const QString saveFolder =
_wallet->currentFolder();
67 setText(0, QString::fromLatin1(
"%1 (%2)").arg(_name).arg(
_wallet->entryList().count()));
73 int visibleLeafCount =0;
74 for (
int i=0; i < childCount(); i++) {
76 if (wi->childCount()) {
77 for (
int l=0; l < wi->childCount(); l++) {
84 setText(0, QString::fromLatin1(
"%1 (%2)").arg(_name).arg(visibleLeafCount));
88 for (
int i = 0; i < childCount(); ++i) {
105 for (
int i = 0; i < childCount(); ++i) {
119 return mime->provides(
"application/x-kwallet-entry") ||
120 mime->provides(
"text/uri-list");
136 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
151 for (
int i = 0; i < childCount(); ++i) {
153 if (entryItem && entryItem->
name() == key) {
165 setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
174 QTreeWidgetItem::setText(0, n);
179 QTreeWidgetItem::setText(0, m_name);
187 :
QListWidgetItem(DesktopIcon(QLatin1String(
"wallet-closed" )), walletName, parent), _open(false) {
188 setFlags(flags() | Qt::ItemIsDropEnabled);
195 if (_open != state) {
198 setIcon( DesktopIcon(QLatin1String(
"wallet-open" )) );
200 setIcon( DesktopIcon(QLatin1String(
"wallet-closed" )) );
205 static bool decodeEntry(KWallet::Wallet *_wallet, QDataStream& ds) {
209 kDebug() <<
"bad magic" ;
214 KWallet::Wallet::EntryType et;
216 if (_wallet->hasEntry(name)) {
217 int rc = KMessageBox::warningContinueCancel(0L, i18n(
"An entry by the name '%1' already exists. Would you like to continue?", name));
218 if (rc == KMessageBox::Cancel) {
224 et = KWallet::Wallet::EntryType(l);
226 _wallet->writeEntry(name, value, et);
234 kDebug() <<
"bad magic" ;
239 if (_wallet->hasFolder(folder)) {
240 int rc = KMessageBox::warningYesNoCancel(0L, i18n(
"A folder by the name '%1' already exists. What would you like to do?", folder), QString(), KStandardGuiItem::cont(), KGuiItem(i18n(
"Replace")));
241 if (rc == KMessageBox::Cancel) {
245 _wallet->removeFolder(folder);
246 _wallet->createFolder(folder);
249 _wallet->createFolder(folder);
252 _wallet->setFolder(folder);
253 while (!ds.atEnd()) {
256 KWallet::Wallet::EntryType et;
260 et = KWallet::Wallet::EntryType(l);
262 _wallet->writeEntry(name, value, et);
268 if (e->provides(
"application/x-kwallet-folder") ||
269 e->provides(
"text/uri-list")) {
271 KWallet::Wallet *_wallet = KWallet::Wallet::openWallet(text(), listWidget()->topLevelWidget()->winId());
277 const QString saveFolder = _wallet->currentFolder();
279 QDataStream *ds = 0L;
281 if (e->provides(
"application/x-kwallet-folder")) {
282 QByteArray edata = e->encodedData(
"application/x-kwallet-folder");
283 if (!edata.isEmpty()) {
284 ds =
new QDataStream(&edata, QIODevice::ReadOnly);
287 const QList<QUrl> urls = e->mimeData()->urls();
288 if (urls.isEmpty()) {
293 KUrl u(urls.first());
294 if (u.fileName().isEmpty()) {
299 if (KIO::NetAccess::download(u, tmpFile, 0L)) {
301 file.setFileName(tmpFile);
302 file.open(QIODevice::ReadOnly);
303 ds =
new QDataStream(&file);
304 KIO::NetAccess::removeTempFile(tmpFile);
306 KMessageBox::error(listWidget(), KIO::NetAccess::lastErrorString());
313 _wallet->setFolder(saveFolder);
317 Qt::MouseButtons state = QApplication::mouseButtons();
318 if (e->source() && e->source()->parent() &&
319 !strcmp(e->source()->parent()->metaObject()->className(),
"KWalletEntryList") &&
320 !(state & Qt::ControlModifier)) {
345 setObjectName( QLatin1String( name ) );
347 setHeaderLabel(i18n(
"Folders"));
348 setRootIsDecorated(
true);
349 setDragEnabled(
true);
350 setAcceptDrops(
true);
351 setDragDropMode(DragDrop);
352 setSelectionMode(SingleSelection);
369 kDebug() << e->source() << e->source()->metaObject()->className();
370 if (e->source() && !strcmp(e->source()->metaObject()->className(),
"KWalletEntryList")) {
374 KMessageBox::error(
this, i18n(
"An unexpected error occurred trying to drop the item"));
376 sel = el->currentItem();
379 if (e->provides(
"application/x-kwallet-entry")) {
381 if (sel && sel->parent()->parent() ==
382 KWalletEntryList::getItemFolder(item)) {
387 QByteArray data = e->encodedData(
"application/x-kwallet-entry");
388 if (data.isEmpty()) {
392 ds =
new QDataStream(&data, QIODevice::ReadOnly);
393 }
else if (e->provides(
"application/x-kwallet-folder")) {
400 QByteArray data = e->encodedData(
"application/x-kwallet-folder");
401 if (data.isEmpty()) {
405 ds =
new QDataStream(&data, QIODevice::ReadOnly);
406 }
else if (e->provides(
"text/uri-list")) {
407 const QList<QUrl> urls = e->mimeData()->urls();
408 if (urls.isEmpty()) {
412 KUrl u(urls.first());
413 if (u.fileName().isEmpty()) {
418 if (KIO::NetAccess::download(u, tmpFile, 0L)) {
419 file.setFileName(tmpFile);
420 file.open(QIODevice::ReadOnly);
421 ds =
new QDataStream(&file);
431 kDebug() <<
"bad magic" ;
437 ds =
new QDataStream(&file);
438 KIO::NetAccess::removeTempFile(tmpFile);
440 KMessageBox::error(
this, KIO::NetAccess::lastErrorString());
447 Qt::MouseButtons state = QApplication::mouseButtons();
456 KMessageBox::error(
this, i18n(
"An unexpected error occurred trying to drop the entry"));
461 QString saveFolder =
_wallet->currentFolder();
464 _wallet->setFolder(saveFolder);
469 if (ok && el && !(state & Qt::ControlModifier) && sel) {
470 el->
_wallet->removeEntry(sel->text(0));
479 if (ok && el && !(state & Qt::ControlModifier) && sel) {
485 KMessageBox::error(
this, i18n(
"An unexpected error occurred trying to delete the original folder, but the folder has been copied successfully"));
497 for (
int i = 0; i < topLevelItemCount(); ++i) {
502 if (name == fi->
name()) {
509 QMimeData *KWalletEntryList::itemMimeData(
const QTreeWidgetItem *i)
const {
520 sd =
new QMimeData();
522 QDataStream ds(&a, QIODevice::WriteOnly);
524 ds.setVersion(QDataStream::Qt_3_1);
529 ei->
_wallet->readEntry(i->text(0), value);
531 sd->setData(
"application/x-kwallet-entry", a);
537 sd =
new QMimeData();
539 QDataStream ds(&a, QIODevice::WriteOnly);
541 ds.setVersion(QDataStream::Qt_3_1);
545 sd->setData(
"application/x-kwallet-folder", a);
551 if (e->button() == Qt::LeftButton)
553 QTreeWidget::mousePressEvent( e );
557 if (!(e->buttons() & Qt::LeftButton))
559 if ((e->pos() -
_mousePos).manhattanLength() < QApplication::startDragDistance())
563 if (!item || !item->isSelected())
566 QMimeData *mimeData = itemMimeData(item);
568 QDrag *drag =
new QDrag(
this);
569 drag->setMimeData(mimeData);
570 drag->setHotSpot(QPoint(0,0));
588 if (e->provides(
"application/x-kwallet-entry") ||
589 e->provides(
"text/uri-list")) {
593 if ((e->provides(
"application/x-kwallet-folder") &&
594 e->source() != viewport()) ||
595 e->provides(
"text/uri-list")) {
601 for (
int i = 0; i < topLevelItemCount(); ++i) {
606 if (name == fi->
name()) {
614 switch (item->type()) {
627 QTreeWidgetItemIterator it(
this);
630 if (!item->isHidden()) {
632 if (item->childCount() ==0) {
634 setCurrentItem(item);
643 QTreeWidgetItemIterator it(
this);
653 class ReturnPressedFilter :
public QObject
656 ReturnPressedFilter(KListWidget *parent) : QObject(parent)
658 parent->installEventFilter(
this);
661 bool eventFilter(QObject * , QEvent *event)
663 if (event->type () == QEvent::KeyPress)
665 QKeyEvent *ke =
static_cast<QKeyEvent *
>(event);
666 if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return)
668 KListWidget *p =
static_cast<KListWidget*
>(parent());
669 QMetaObject::invokeMethod(p,
"executed", Q_ARG(
QListWidgetItem*, p->currentItem()));
677 #include "allyourbase.moc"
virtual ~KWalletEntryList()
KWalletItem(QListWidget *parent, const QString &walletName)
virtual bool acceptDrop(const QMimeSource *mime) const
#define KWALLETENTRYMAGIC
virtual ~KWalletEntryItem()
KWalletFolderItem * getFolder(const QString &name)
virtual void dragEnterEvent(QDragEnterEvent *e)
QPixmap getFolderIcon(KIconLoader::Group group)
KWalletContainerItem * getContainer(KWallet::Wallet::EntryType type)
QTreeWidgetItem * getItem(const QString &itemKey)
virtual void mouseMoveEvent(QMouseEvent *e)
void itemDropped(QDropEvent *e, QTreeWidgetItem *item)
virtual ~KWalletFolderItem()
KWalletEntryItem(KWallet::Wallet *w, QTreeWidgetItem *parent, const QString &ename)
static bool decodeEntry(KWallet::Wallet *_wallet, QDataStream &ds)
virtual void dropEvent(QDropEvent *e)
void setWallet(KWallet::Wallet *w)
const QString & name() const
static bool decodeFolder(KWallet::Wallet *_wallet, QDataStream &ds)
QTreeWidgetItem * getItem(const QString &itemKey)
KWalletEntryList(QWidget *parent, const char *name=0L)
KWalletContainerItem(QTreeWidgetItem *parent, const QString &name, KWallet::Wallet::EntryType entryType)
KWallet::Wallet * _wallet
virtual void dragMoveEvent(QDragMoveEvent *e)
KWallet::Wallet * _wallet
KWallet::Wallet::EntryType entryType()
virtual void mousePressEvent(QMouseEvent *e)
bool contains(const QString &itemKey)
bool contains(const QString &itemKey)
bool existsFolder(const QString &name)
void setName(const QString &n)
virtual ~KWalletContainerItem()
KWalletFolderItem(KWallet::Wallet *w, QTreeWidget *parent, const QString &name, int entries)
void selectFirstVisible()
KWallet::Wallet * _wallet
#define KWALLETFOLDERMAGIC
void processDropEvent(QDropEvent *e)