1 /* This file is part of the KDE project
2 Copyright (c) 2007 David Faure <faure@kde.org>
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 "dolphinpart.h"
21 #include <kactioncollection.h>
22 #include <ktoggleaction.h>
23 #include <QActionGroup>
24 #include "dolphinsortfilterproxymodel.h"
25 #include "dolphinview.h"
26 #include "dolphinmodel.h"
28 #include <kdirlister.h>
29 #include <kmessagebox.h>
30 #include <kparts/browserextension.h>
31 #include <kparts/genericfactory.h>
32 #include <QApplication>
34 typedef KParts::GenericFactory
<DolphinPart
> DolphinPartFactory
;
35 K_EXPORT_COMPONENT_FACTORY(dolphinpart
, DolphinPartFactory
)
37 class DolphinPartBrowserExtension
: public KParts::BrowserExtension
40 DolphinPartBrowserExtension( KParts::ReadOnlyPart
* part
)
41 : KParts::BrowserExtension( part
) {}
44 DolphinPart::DolphinPart(QWidget
* parentWidget
, QObject
* parent
, const QStringList
& args
)
45 : KParts::ReadOnlyPart(parent
)
48 setComponentData( DolphinPartFactory::componentData() );
49 m_extension
= new DolphinPartBrowserExtension(this);
51 m_dirLister
= new KDirLister
;
52 m_dirLister
->setAutoUpdate(true);
53 m_dirLister
->setMainWindow(parentWidget
->topLevelWidget());
54 m_dirLister
->setDelayedMimeTypes(true);
56 //connect(m_dirLister, SIGNAL(started(KUrl)), this, SLOT(slotStarted()));
57 connect(m_dirLister
, SIGNAL(completed(KUrl
)), this, SLOT(slotCompleted(KUrl
)));
58 connect(m_dirLister
, SIGNAL(canceled(KUrl
)), this, SLOT(slotCanceled(KUrl
)));
60 m_dolphinModel
= new DolphinModel(this);
61 m_dolphinModel
->setDirLister(m_dirLister
);
63 m_proxyModel
= new DolphinSortFilterProxyModel(this);
64 m_proxyModel
->setSourceModel(m_dolphinModel
);
66 m_view
= new DolphinView(parentWidget
,
73 setXMLFile("dolphinpart.rc");
75 connect(m_view
, SIGNAL(infoMessage(QString
)),
76 this, SLOT(slotInfoMessage(QString
)));
77 connect(m_view
, SIGNAL(errorMessage(QString
)),
78 this, SLOT(slotErrorMessage(QString
)));
79 connect(m_view
, SIGNAL(itemTriggered(KFileItem
)),
80 this, SLOT(slotItemTriggered(KFileItem
)));
81 connect(m_view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&)),
82 this, SLOT(slotOpenContextMenu(KFileItem
, const KUrl
&)));
83 connect(m_view
, SIGNAL(selectionChanged(KFileItemList
)),
84 m_extension
, SIGNAL(selectionInfo(KFileItemList
)));
86 connect(m_view
, SIGNAL(requestItemInfo(KFileItem
)),
87 this, SLOT(slotRequestItemInfo(KFileItem
)));
92 // TODO provide these actions in the menu, merged with the existing view-mode-actions somehow
93 // [Q_PROPERTY introspection?]
95 // TODO connect to urlsDropped
97 // TODO there was a "always open a new window" (when clicking on a directory) setting in konqueror
98 // (sort of spacial navigation)
100 // TODO MMB-click should do something like KonqDirPart::mmbClicked
102 // TODO updating the paste action
103 // if (paste) emit m_extension->setActionText( "paste", actionText );
104 // emit m_extension->enableAction( "paste", paste );
106 // TODO updating the trash and del actions too - or removing special handling of those from konq?
109 DolphinPart::~DolphinPart()
114 void DolphinPart::createActions()
116 QActionGroup
* viewModeActions
= new QActionGroup(this);
117 viewModeActions
->addAction(DolphinView::iconsModeAction(actionCollection()));
118 viewModeActions
->addAction(DolphinView::detailsModeAction(actionCollection()));
119 viewModeActions
->addAction(DolphinView::columnsModeAction(actionCollection()));
120 connect(viewModeActions
, SIGNAL(triggered(QAction
*)), this, SLOT(slotViewModeActionTriggered(QAction
*)));
123 void DolphinPart::updateViewActions()
125 QAction
* action
= actionCollection()->action(m_view
->currentViewModeActionName());
127 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
128 toggleAction
->setChecked(true);
132 KAboutData
* DolphinPart::createAboutData()
134 return new KAboutData("dolphinpart", 0, ki18nc("@title", "Dolphin Part"), "0.1");
137 bool DolphinPart::openUrl(const KUrl
& url
)
139 const QString prettyUrl
= url
.pathOrUrl();
140 emit
setWindowCaption(prettyUrl
);
141 emit m_extension
->setLocationBarUrl(prettyUrl
);
142 const bool reload
= arguments().reload();
143 if (m_view
->url() == url
&& !reload
) { // DolphinView won't do anything in that case, so don't emit started
146 setUrl(url
); // remember it at the KParts level
150 emit
started(0); // get the wheel to spin
154 void DolphinPart::slotCompleted(const KUrl
& url
)
160 void DolphinPart::slotCanceled(const KUrl
& url
)
165 void DolphinPart::slotInfoMessage(const QString
& msg
)
167 emit
setStatusBarText(msg
);
170 void DolphinPart::slotErrorMessage(const QString
& msg
)
172 KMessageBox::error(m_view
, msg
);
175 void DolphinPart::slotRequestItemInfo(const KFileItem
& item
)
177 emit m_extension
->mouseOverInfo(item
);
180 void DolphinPart::slotItemTriggered(const KFileItem
& item
)
182 qDebug() << QApplication::mouseButtons();
183 if (QApplication::mouseButtons() & Qt::MidButton
) {
184 qDebug() << "MMB!!" << item
.mimetype();
185 if (item
.mimeTypePtr()->is("inode/directory")) {
186 KParts::OpenUrlArguments args
;
187 args
.setMimeType( item
.mimetype() );
188 emit m_extension
->createNewWindow( item
.url(), args
);
194 // Left button. [Right button goes to slotOpenContextMenu before triggered can be emitted]
196 emit m_extension
->openUrlRequest(item
.url());
200 void DolphinPart::slotOpenContextMenu(const KFileItem
& _item
, const KUrl
&)
202 KParts::BrowserExtension::PopupFlags popupFlags
= KParts::BrowserExtension::DefaultPopupItems
203 | KParts::BrowserExtension::ShowProperties
204 | KParts::BrowserExtension::ShowUrlOperations
;
205 // TODO KonqKfmIconView had if ( !rootItem->isWritable() )
206 // popupFlags |= KParts::BrowserExtension::NoDeletion;
208 KFileItem
item(_item
);
210 if (item
.isNull()) { // viewport context menu
211 popupFlags
|= KParts::BrowserExtension::ShowNavigationItems
| KParts::BrowserExtension::ShowUp
;
212 // TODO get m_dirLister->rootItem if possible. or via kdirmodel?
213 // and use this as fallback:
214 item
= KFileItem( S_IFDIR
, (mode_t
)-1, url() );
217 KFileItemList items
; items
.append(item
);
218 emit m_extension
->popupMenu( QCursor::pos(), items
, KParts::OpenUrlArguments(), KParts::BrowserArguments(), popupFlags
);
221 void DolphinPart::slotViewModeActionTriggered(QAction
* action
)
223 const DolphinView::Mode mode
= action
->data().value
<DolphinView::Mode
>();
224 m_view
->setMode(mode
);
227 #include "dolphinpart.moc"