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
)));
85 connect(m_view
, SIGNAL(requestItemInfo(KFileItem
)),
86 this, SLOT(slotRequestItemInfo(KFileItem
)));
87 connect(m_view
, SIGNAL(urlChanged(const KUrl
&)),
88 this, SLOT(slotUrlChanged(const KUrl
&)));
93 // TODO provide these actions in the menu, merged with the existing view-mode-actions somehow
94 // [Q_PROPERTY introspection?]
96 // TODO sort_by_* actions
97 // TODO show_*_info actions
99 // TODO connect to urlsDropped
101 // TODO there was a "always open a new window" (when clicking on a directory) setting in konqueror
102 // (sort of spacial navigation)
104 // TODO MMB-click should do something like KonqDirPart::mmbClicked
106 // TODO updating the paste action
107 // if (paste) emit m_extension->setActionText( "paste", actionText );
108 // emit m_extension->enableAction( "paste", paste );
110 // TODO updating the trash and del actions too - or removing special handling of those from konq?
113 DolphinPart::~DolphinPart()
118 void DolphinPart::createActions()
120 QActionGroup
* viewModeActions
= new QActionGroup(this);
121 viewModeActions
->addAction(DolphinView::iconsModeAction(actionCollection()));
122 viewModeActions
->addAction(DolphinView::detailsModeAction(actionCollection()));
123 viewModeActions
->addAction(DolphinView::columnsModeAction(actionCollection()));
124 connect(viewModeActions
, SIGNAL(triggered(QAction
*)), this, SLOT(slotViewModeActionTriggered(QAction
*)));
127 void DolphinPart::updateViewActions()
129 QAction
* action
= actionCollection()->action(m_view
->currentViewModeActionName());
131 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
132 toggleAction
->setChecked(true);
136 KAboutData
* DolphinPart::createAboutData()
138 return new KAboutData("dolphinpart", 0, ki18nc("@title", "Dolphin Part"), "0.1");
141 bool DolphinPart::openUrl(const KUrl
& url
)
143 const bool reload
= arguments().reload();
144 if (m_view
->url() == url
&& !reload
) { // DolphinView won't do anything in that case, so don't emit started
147 setUrl(url
); // remember it at the KParts level
148 const QString prettyUrl
= url
.pathOrUrl();
149 emit
setWindowCaption(prettyUrl
);
150 emit m_extension
->setLocationBarUrl(prettyUrl
);
154 emit
started(0); // get the wheel to spin
158 void DolphinPart::slotCompleted(const KUrl
& url
)
164 void DolphinPart::slotCanceled(const KUrl
& url
)
169 void DolphinPart::slotInfoMessage(const QString
& msg
)
171 emit
setStatusBarText(msg
);
174 void DolphinPart::slotErrorMessage(const QString
& msg
)
176 KMessageBox::error(m_view
, msg
);
179 void DolphinPart::slotRequestItemInfo(const KFileItem
& item
)
181 emit m_extension
->mouseOverInfo(item
);
184 void DolphinPart::slotItemTriggered(const KFileItem
& item
)
186 qDebug() << QApplication::mouseButtons();
187 if (QApplication::mouseButtons() & Qt::MidButton
) {
188 qDebug() << "MMB!!" << item
.mimetype();
189 if (item
.mimeTypePtr()->is("inode/directory")) {
190 KParts::OpenUrlArguments args
;
191 args
.setMimeType( item
.mimetype() );
192 emit m_extension
->createNewWindow( item
.url(), args
);
198 // Left button. [Right button goes to slotOpenContextMenu before triggered can be emitted]
200 emit m_extension
->openUrlRequest(item
.url());
204 void DolphinPart::slotOpenContextMenu(const KFileItem
& _item
, const KUrl
&)
206 KParts::BrowserExtension::PopupFlags popupFlags
= KParts::BrowserExtension::DefaultPopupItems
207 | KParts::BrowserExtension::ShowProperties
208 | KParts::BrowserExtension::ShowUrlOperations
;
209 // TODO KonqKfmIconView had if ( !rootItem->isWritable() )
210 // popupFlags |= KParts::BrowserExtension::NoDeletion;
212 KFileItem
item(_item
);
214 if (item
.isNull()) { // viewport context menu
215 popupFlags
|= KParts::BrowserExtension::ShowNavigationItems
| KParts::BrowserExtension::ShowUp
;
216 // TODO get m_dirLister->rootItem if possible. or via kdirmodel?
217 // and use this as fallback:
218 item
= KFileItem( S_IFDIR
, (mode_t
)-1, url() );
221 KFileItemList items
; items
.append(item
);
222 emit m_extension
->popupMenu( QCursor::pos(), items
, KParts::OpenUrlArguments(), KParts::BrowserArguments(), popupFlags
);
225 void DolphinPart::slotViewModeActionTriggered(QAction
* action
)
227 const DolphinView::Mode mode
= action
->data().value
<DolphinView::Mode
>();
228 m_view
->setMode(mode
);
231 void DolphinPart::slotUrlChanged(const KUrl
& url
)
233 if (m_view
->url() != url
) {
234 // If the view URL is not equal to 'url', then an inner URL change has
235 // been done (e. g. by activating an existing column in the column view).
236 // From the hosts point of view this must be handled like changing the URL.
237 emit m_extension
->openUrlRequest(url
);
241 #include "dolphinpart.moc"