]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/places/placespanel.cpp
Reset the location to the home URL, if a place has been removed (e. g. a DVD has...
[dolphin.git] / src / panels / places / placespanel.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2010 by Christian Muehlhaeuser <muesli@gmail.com> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program 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 *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "placespanel.h"
22
23 #include "dolphin_generalsettings.h"
24 #include "draganddrophelper.h"
25 #include <kfileitem.h>
26 #include <konq_operations.h>
27 #include "settings/dolphinsettings.h"
28
29 PlacesPanel::PlacesPanel(QWidget* parent) :
30 KFilePlacesView(parent),
31 m_mouseButtons(Qt::NoButton)
32 {
33 setDropOnPlaceEnabled(true);
34 connect(this, SIGNAL(urlsDropped(const KUrl&, QDropEvent*, QWidget*)),
35 this, SLOT(slotUrlsDropped(const KUrl&, QDropEvent*, QWidget*)));
36 connect(this, SIGNAL(urlChanged(const KUrl&)),
37 this, SLOT(emitExtendedUrlChangedSignal(const KUrl&)));
38 }
39
40 PlacesPanel::~PlacesPanel()
41 {
42 }
43
44 void PlacesPanel::mousePressEvent(QMouseEvent* event)
45 {
46 m_mouseButtons = event->buttons();
47 KFilePlacesView::mousePressEvent(event);
48 }
49
50 void PlacesPanel::rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end)
51 {
52 Q_UNUSED(parent);
53
54 const QModelIndexList indexes = selectedIndexes();
55 if (!indexes.isEmpty()) {
56 const int selectedRow = indexes.first().row();
57 if ((start >= selectedRow) && (end <= selectedRow)) {
58 // The currently selected item is about to be removed, reset view to home URL
59 const KUrl homeUrl = DolphinSettings::instance().generalSettings()->homeUrl();
60 setUrl(homeUrl);
61 emit urlChanged(homeUrl, Qt::NoButton);
62 }
63 }
64 }
65
66 void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
67 {
68 DragAndDropHelper::instance().dropUrls(KFileItem(), dest, event, parent);
69 }
70
71 void PlacesPanel::emitExtendedUrlChangedSignal(const KUrl& url)
72 {
73 emit urlChanged(url, m_mouseButtons);
74 }
75
76 #include "placespanel.moc"