]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.cpp
Create the new architecture for KCategorizedView. Now DolphinModel is created, inheri...
[dolphin.git] / src / dolphinpart.cpp
1 /* This file is part of the KDE project
2 Copyright (c) 2007 David Faure <faure@kde.org>
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 "dolphinpart.h"
21 #include "dolphinsortfilterproxymodel.h"
22 #include "dolphinview.h"
23 #include "dolphinmodel.h"
24
25 #include <kdirlister.h>
26 #include <kmessagebox.h>
27 #include <kparts/browserextension.h>
28 #include <kparts/genericfactory.h>
29
30 typedef KParts::GenericFactory<DolphinPart> DolphinPartFactory;
31 K_EXPORT_COMPONENT_FACTORY(dolphinpart, DolphinPartFactory)
32
33 class DolphinPartBrowserExtension : public KParts::BrowserExtension
34 {
35 public:
36 DolphinPartBrowserExtension( KParts::ReadOnlyPart* part )
37 : KParts::BrowserExtension( part ) {}
38 };
39
40 DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringList& args)
41 : KParts::ReadOnlyPart(parent)
42 {
43 Q_UNUSED(args)
44 setComponentData( DolphinPartFactory::componentData() );
45 m_extension = new DolphinPartBrowserExtension(this);
46
47 m_dirLister = new KDirLister;
48 m_dirLister->setAutoUpdate(true);
49 m_dirLister->setMainWindow(parentWidget->topLevelWidget());
50 m_dirLister->setDelayedMimeTypes(true);
51
52 //connect(m_dirLister, SIGNAL(started(KUrl)), this, SLOT(slotStarted()));
53 connect(m_dirLister, SIGNAL(completed(KUrl)), this, SLOT(slotCompleted(KUrl)));
54 connect(m_dirLister, SIGNAL(canceled(KUrl)), this, SLOT(slotCanceled(KUrl)));
55
56 m_dolphinModel = new DolphinModel(this);
57 m_dolphinModel->setDirLister(m_dirLister);
58
59 m_proxyModel = new DolphinSortFilterProxyModel(this);
60 m_proxyModel->setSourceModel(m_dolphinModel);
61
62 m_view = new DolphinView(parentWidget,
63 KUrl(),
64 m_dirLister,
65 m_dolphinModel,
66 m_proxyModel);
67 setWidget(m_view);
68
69 connect(m_view, SIGNAL(infoMessage(QString)),
70 this, SLOT(slotInfoMessage(QString)));
71 connect(m_view, SIGNAL(errorMessage(QString)),
72 this, SLOT(slotErrorMessage(QString)));
73 connect(m_view, SIGNAL(itemTriggered(KFileItem)),
74 this, SLOT(slotItemTriggered(KFileItem)));
75 connect(m_view, SIGNAL(requestContextMenu(KFileItem, const KUrl&)),
76 this, SLOT(slotOpenContextMenu(KFileItem, const KUrl&)));
77 connect(m_view, SIGNAL(selectionChanged(QList<KFileItem>)),
78 m_extension, SIGNAL(selectionInfo(QList<KFileItem>)));
79
80 connect(m_view, SIGNAL(requestItemInfo(KFileItem)),
81 this, SLOT(slotRequestItemInfo(KFileItem)));
82
83 // TODO connect to urlsDropped
84
85 // TODO there was a "always open a new window" (when clicking on a directory) setting in konqueror
86 // (sort of spacial navigation)
87
88 // TODO MMB-click should do something like KonqDirPart::mmbClicked
89
90 // TODO updating the paste action
91 // if (paste) emit m_extension->setActionText( "paste", actionText );
92 // emit m_extension->enableAction( "paste", paste );
93 }
94
95 DolphinPart::~DolphinPart()
96 {
97 delete m_dirLister;
98 }
99
100 KAboutData* DolphinPart::createAboutData()
101 {
102 return new KAboutData("dolphinpart", 0, ki18nc("@title", "Dolphin Part"), "0.1");
103 }
104
105 bool DolphinPart::openUrl(const KUrl& url)
106 {
107 const QString prettyUrl = url.pathOrUrl();
108 emit setWindowCaption(prettyUrl);
109 emit m_extension->setLocationBarUrl(prettyUrl);
110 const bool reload = arguments().reload();
111 if (m_view->url() == url && !reload) { // DolphinView won't do anything in that case, so don't emit started
112 return true;
113 }
114 setUrl(url); // remember it at the KParts level
115 m_view->setUrl(url);
116 if (reload)
117 m_view->reload();
118 emit started(0); // get the wheel to spin
119 return true;
120 }
121
122 void DolphinPart::slotCompleted(const KUrl& url)
123 {
124 Q_UNUSED(url)
125 emit completed();
126 }
127
128 void DolphinPart::slotCanceled(const KUrl& url)
129 {
130 slotCompleted(url);
131 }
132
133 void DolphinPart::slotInfoMessage(const QString& msg)
134 {
135 emit setStatusBarText(msg);
136 }
137
138 void DolphinPart::slotErrorMessage(const QString& msg)
139 {
140 KMessageBox::error(m_view, msg);
141 }
142
143 void DolphinPart::slotRequestItemInfo(const KFileItem& item)
144 {
145 emit m_extension->mouseOverInfo(&item);
146 }
147
148 void DolphinPart::slotItemTriggered(const KFileItem& item)
149 {
150 emit m_extension->openUrlRequest(item.url());
151 }
152
153 void DolphinPart::slotOpenContextMenu(const KFileItem& item, const KUrl&)
154 {
155 // TODO KonqKfmIconView had if ( !rootItem->isWritable() )
156 // popupFlags |= KParts::BrowserExtension::NoDeletion;
157
158 // and when clicking on the viewport:
159 // KParts::BrowserExtension::PopupFlags popupFlags = KParts::BrowserExtension::ShowNavigationItems | KParts::BrowserExtension::ShowUp;
160
161
162 KFileItem* itemCopy = new KFileItem(item); // ugly
163 KFileItemList items; items.append(itemCopy);
164 emit m_extension->popupMenu( 0, QCursor::pos(), items );
165 delete itemCopy;
166 }
167
168 #include "dolphinpart.moc"