1
/* This file is part of the KDE project
2
Copyright (c) 2004 Kevin Ottens <ervin ipsquad net>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#include "trashbutton.h"
28
#include <kstandardaction.h>
30
#include <kio/netaccess.h>
32
#include <konq_operations.h>
33
#include <konq_popupmenu.h>
35
TrashButton::TrashButton(QWidget *parent)
36
: PanelPopupButton(parent), mActions(this),
39
mActions.setAssociatedWidget(this);
42
KIO::NetAccess::stat(KUrl("trash:/"), entry, 0L);
43
mFileItem = KFileItem(entry, KUrl("trash:/"));
45
QAction *a = KStandardAction::paste(this, SLOT(slotPaste()), this);
46
mActions.addAction("paste", a);
52
setTitle(i18n("Trash"));
53
setIcon( "user-trash" );
57
// Activate this code only if we find a way to have both an
58
// action and a popup menu for the same kicker button
59
//connect(this, SIGNAL(clicked()), this, SLOT(slotClicked()));
61
setPopup(new QMenu());
64
TrashButton::~TrashButton()
68
void TrashButton::setItemCount(int count)
72
setIcon( "user-trash" );
73
this->setToolTip( i18n("Empty"));
77
setIcon( "user-trash-full" );
78
this->setToolTip( i18np("One item", "%1 items", count));
82
void TrashButton::initPopup()
84
QMenu *old_popup = popup();
87
items.append(&mFileItem);
89
KonqPopupMenu::KonqPopupFlags kpf =
90
KonqPopupMenu::ShowProperties
91
| KonqPopupMenu::ShowNewWindow;
93
KParts::BrowserExtension::PopupFlags bef =
94
KParts::BrowserExtension::DefaultPopupItems;
96
KonqPopupMenu *new_popup = new KonqPopupMenu(0L, items,
97
KUrl("trash:/"), mActions, 0L,
99
// KPopupTitle *title = new KPopupTitle(new_popup);
100
// title->setTitle(i18n("Trash"));
102
// new_popup->insertItem(title, -1, 0);
103
new_popup->insertItem(i18n("Trash"), -1, 0);
107
if (old_popup!=0L) delete old_popup;
110
// Activate this code only if we find a way to have both an
111
// action and a popup menu for the same kicker button
113
void TrashButton::slotClicked()
119
void TrashButton::slotPaste()
121
KonqOperations::doPaste(this, mFileItem.url());
124
void TrashButton::dragEnterEvent(QDragEnterEvent* e)
126
e->setAccepted(true);
129
void TrashButton::dropEvent(QDropEvent *e)
131
KonqOperations::doDrop(0L, mFileItem.url(), e, this);
134
QString TrashButton::tileName()
136
return mFileItem.name();
139
void TrashButton::setPanelPosition(Plasma::Position position)
144
setPopupDirection(Plasma::Up);
147
setPopupDirection(Plasma::Down);
150
setPopupDirection(Plasma::Left);
153
setPopupDirection(Plasma::Right);
155
case Plasma::Floating:
156
setPopupDirection(Plasma::Floating);
161
#include "trashbutton.moc"