~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to kicker/applets/trash/trashbutton.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-10-31 19:16:54 UTC
  • Revision ID: james.westby@ubuntu.com-20071031191654-xuof6e1jg6uxqaze
Tags: 3.95.0-0ubuntu1~gutsy1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
   Copyright (c) 2004 Kevin Ottens <ervin ipsquad net>
3
 
 
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.
8
 
 
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.
13
 
 
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.
18
 
*/
19
 
 
20
 
#include "trashbutton.h"
21
 
 
22
 
#include <QMenu>
23
 
 
24
 
 
25
 
#include <klocale.h>
26
 
#include <kmenu.h>
27
 
#include <krun.h>
28
 
#include <kstandardaction.h>
29
 
 
30
 
#include <kio/netaccess.h>
31
 
 
32
 
#include <konq_operations.h>
33
 
#include <konq_popupmenu.h>
34
 
 
35
 
TrashButton::TrashButton(QWidget *parent)
36
 
        : PanelPopupButton(parent), mActions(this),
37
 
          mFileItem()
38
 
{
39
 
        mActions.setAssociatedWidget(this);
40
 
 
41
 
        KIO::UDSEntry entry;
42
 
        KIO::NetAccess::stat(KUrl("trash:/"), entry, 0L);
43
 
        mFileItem = KFileItem(entry, KUrl("trash:/"));
44
 
 
45
 
        QAction *a = KStandardAction::paste(this, SLOT(slotPaste()), this);
46
 
        mActions.addAction("paste", a);
47
 
        a->setShortcut(0);
48
 
 
49
 
        move(0, 0);
50
 
        resize(20, 20);
51
 
 
52
 
        setTitle(i18n("Trash"));
53
 
        setIcon( "user-trash" );
54
 
 
55
 
        setAcceptDrops(true);
56
 
 
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()));
60
 
 
61
 
        setPopup(new QMenu());
62
 
}
63
 
 
64
 
TrashButton::~TrashButton()
65
 
{
66
 
}
67
 
 
68
 
void TrashButton::setItemCount(int count)
69
 
{
70
 
    if (count==0)
71
 
    {
72
 
        setIcon( "user-trash" );
73
 
        this->setToolTip( i18n("Empty"));
74
 
    }
75
 
    else
76
 
    {
77
 
        setIcon( "user-trash-full" );
78
 
        this->setToolTip( i18np("One item", "%1 items", count));
79
 
    }
80
 
}
81
 
 
82
 
void TrashButton::initPopup()
83
 
{
84
 
        QMenu *old_popup = popup();
85
 
 
86
 
        KFileItemList items;
87
 
        items.append(&mFileItem);
88
 
 
89
 
        KonqPopupMenu::KonqPopupFlags kpf =
90
 
                  KonqPopupMenu::ShowProperties
91
 
                | KonqPopupMenu::ShowNewWindow;
92
 
 
93
 
        KParts::BrowserExtension::PopupFlags bef =
94
 
                  KParts::BrowserExtension::DefaultPopupItems;
95
 
 
96
 
        KonqPopupMenu *new_popup = new KonqPopupMenu(0L, items,
97
 
                                           KUrl("trash:/"), mActions, 0L,
98
 
                                           this, kpf, bef);
99
 
//      KPopupTitle *title = new KPopupTitle(new_popup);
100
 
//      title->setTitle(i18n("Trash"));
101
 
 
102
 
//      new_popup->insertItem(title, -1, 0);
103
 
        new_popup->insertItem(i18n("Trash"), -1, 0);
104
 
 
105
 
        setPopup(new_popup);
106
 
 
107
 
        if (old_popup!=0L) delete old_popup;
108
 
}
109
 
 
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
112
 
/*
113
 
void TrashButton::slotClicked()
114
 
{
115
 
        mFileItem.run();
116
 
}
117
 
*/
118
 
 
119
 
void TrashButton::slotPaste()
120
 
{
121
 
        KonqOperations::doPaste(this, mFileItem.url());
122
 
}
123
 
 
124
 
void TrashButton::dragEnterEvent(QDragEnterEvent* e)
125
 
{
126
 
        e->setAccepted(true);
127
 
}
128
 
 
129
 
void TrashButton::dropEvent(QDropEvent *e)
130
 
{
131
 
        KonqOperations::doDrop(0L, mFileItem.url(), e, this);
132
 
}
133
 
 
134
 
QString TrashButton::tileName()
135
 
{
136
 
        return mFileItem.name();
137
 
}
138
 
 
139
 
void TrashButton::setPanelPosition(Plasma::Position position)
140
 
{
141
 
        switch(position)
142
 
        {
143
 
        case Plasma::Bottom:
144
 
                setPopupDirection(Plasma::Up);
145
 
                break;
146
 
        case Plasma::Top:
147
 
                setPopupDirection(Plasma::Down);
148
 
                break;
149
 
        case Plasma::Right:
150
 
                setPopupDirection(Plasma::Left);
151
 
                break;
152
 
        case Plasma::Left:
153
 
                setPopupDirection(Plasma::Right);
154
 
                break;
155
 
        case Plasma::Floating:
156
 
                setPopupDirection(Plasma::Floating);
157
 
                break;
158
 
        }
159
 
}
160
 
 
161
 
#include "trashbutton.moc"