]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/places/placespanel.cpp
5ea4b971cb9f2650c97eef49fa44c914fb910fb2
1 /***************************************************************************
2 * Copyright (C) 2008-2012 by Peter Penz <peter.penz19@gmail.com> *
4 * Based on KFilePlacesModel from kdelibs: *
5 * Copyright (C) 2007 Kevin Ottens <ervin@kde.org> *
6 * Copyright (C) 2007 David Faure <faure@kde.org> *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
22 ***************************************************************************/
24 #include "placespanel.h"
27 #include <KBookmarkGroup>
28 #include <KBookmarkManager>
29 #include <KComponentData>
32 #include <kitemviews/kitemlistcontainer.h>
33 #include <kitemviews/kitemlistcontroller.h>
34 #include <kitemviews/kstandarditem.h>
35 #include <kitemviews/kstandarditemlistview.h>
36 #include <kitemviews/kstandarditemmodel.h>
37 #include <KStandardDirs>
38 #include <views/draganddrophelper.h>
39 #include <QVBoxLayout>
42 PlacesPanel::PlacesPanel(QWidget
* parent
) :
51 PlacesPanel::~PlacesPanel()
55 bool PlacesPanel::urlChanged()
60 void PlacesPanel::showEvent(QShowEvent
* event
)
62 if (event
->spontaneous()) {
63 Panel::showEvent(event
);
68 // Postpone the creating of the controller to the first show event.
69 // This assures that no performance and memory overhead is given when the folders panel is not
70 // used at all and stays invisible.
71 const QString file
= KStandardDirs::locateLocal("data", "kfileplaces/bookmarks.xml");
72 m_bookmarkManager
= KBookmarkManager::managerForFile(file
, "kfileplaces");
73 m_model
= new KStandardItemModel(this);
76 KStandardItemListView
* view
= new KStandardItemListView();
78 m_controller
= new KItemListController(m_model
, view
, this);
79 m_controller
->setSelectionBehavior(KItemListController::SingleSelection
);
80 connect(m_controller
, SIGNAL(itemActivated(int)), this, SLOT(slotItemActivated(int)));
81 connect(m_controller
, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int)));
83 KItemListContainer
* container
= new KItemListContainer(m_controller
, this);
84 container
->setEnabledFrame(false);
86 QVBoxLayout
* layout
= new QVBoxLayout(this);
88 layout
->addWidget(container
);
91 Panel::showEvent(event
);
94 void PlacesPanel::slotItemActivated(int index
)
96 const KStandardItem
* item
= m_model
->item(index
);
98 const KUrl url
= item
->dataValue("url").value
<KUrl
>();
99 emit
placeActivated(url
);
103 void PlacesPanel::slotItemMiddleClicked(int index
)
105 const KStandardItem
* item
= m_model
->item(index
);
107 const KUrl url
= item
->dataValue("url").value
<KUrl
>();
108 emit
placeMiddleClicked(url
);
112 void PlacesPanel::slotUrlsDropped(const KUrl
& dest
, QDropEvent
* event
, QWidget
* parent
)
115 DragAndDropHelper::dropUrls(KFileItem(), dest
, event
);
118 void PlacesPanel::loadBookmarks()
120 KBookmarkGroup root
= m_bookmarkManager
->root();
121 KBookmark bookmark
= root
.first();
122 QSet
<QString
> devices
= m_availableDevices
;
124 while (!bookmark
.isNull()) {
125 const QString udi
= bookmark
.metaDataItem("UDI");
126 const QString appName
= bookmark
.metaDataItem("OnlyInApp");
127 const bool deviceAvailable
= devices
.remove(udi
);
129 const bool allowedHere
= appName
.isEmpty() || (appName
== KGlobal::mainComponent().componentName());
131 if ((udi
.isEmpty() && allowedHere
) || deviceAvailable
) {
132 KStandardItem
* item
= new KStandardItem();
133 item
->setIcon(KIcon(bookmark
.icon()));
134 item
->setText(bookmark
.text());
135 item
->setDataValue("address", bookmark
.address());
136 item
->setDataValue("url", bookmark
.url());
137 if (deviceAvailable
) {
138 item
->setDataValue("udi", udi
);
140 m_model
->appendItem(item
);
143 bookmark
= root
.next(bookmark
);
147 #include "placespanel.moc"