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 "dolphinsortfilterproxymodel.h"
22 #include "dolphinview.h"
24 #include <kdirlister.h>
25 #include <kdirmodel.h>
26 #include <kmessagebox.h>
27 #include <kparts/browserextension.h>
28 #include <kparts/genericfactory.h>
30 typedef KParts::GenericFactory
<DolphinPart
> DolphinPartFactory
;
31 K_EXPORT_COMPONENT_FACTORY(dolphinpart
, DolphinPartFactory
)
33 class DolphinPartBrowserExtension
: public KParts::BrowserExtension
36 DolphinPartBrowserExtension( KParts::ReadOnlyPart
* part
)
37 : KParts::BrowserExtension( part
) {}
40 DolphinPart::DolphinPart(QWidget
* parentWidget
, QObject
* parent
, const QStringList
& args
)
41 : KParts::ReadOnlyPart(parent
)
44 setComponentData( DolphinPartFactory::componentData() );
45 m_extension
= new DolphinPartBrowserExtension(this);
47 m_dirLister
= new KDirLister
;
48 m_dirLister
->setAutoUpdate(true);
49 m_dirLister
->setMainWindow(parentWidget
->topLevelWidget());
50 m_dirLister
->setDelayedMimeTypes(true);
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
)));
56 m_dirModel
= new KDirModel(this);
57 m_dirModel
->setDirLister(m_dirLister
);
59 m_proxyModel
= new DolphinSortFilterProxyModel(this);
60 m_proxyModel
->setSourceModel(m_dirModel
);
62 m_view
= new DolphinView(parentWidget
,
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 // TODO connect to urlsDropped
76 // TOOD connect to requestContextMenu
77 connect(m_view
, SIGNAL(selectionChanged(QList
<KFileItem
>)), m_extension
, SIGNAL(selectionInfo(QList
<KFileItem
>)));
79 connect(m_view
, SIGNAL(requestItemInfo(KFileItem
)), this, SLOT(slotRequestItemInfo(KFileItem
)));
81 // TODO there was a "always open a new window" (when clicking on a directory) setting in konqueror
82 // (sort of spacial navigation)
84 // TODO MMB-click should do something like KonqDirPart::mmbClicked
86 // TODO updating the paste action
87 // if (paste) emit m_extension->setActionText( "paste", actionText );
88 // emit m_extension->enableAction( "paste", paste );
91 DolphinPart::~DolphinPart()
96 KAboutData
* DolphinPart::createAboutData()
98 return new KAboutData("dolphinpart", 0, ki18nc("@title", "Dolphin Part"), "0.1");
101 bool DolphinPart::openUrl(const KUrl
& url
)
103 const QString prettyUrl
= url
.pathOrUrl();
104 setWindowCaption(prettyUrl
);
105 m_extension
->setLocationBarUrl(prettyUrl
);
107 if (arguments().reload())
109 emit
started(0); // get the wheel to spin
113 void DolphinPart::slotCompleted(const KUrl
& url
)
119 void DolphinPart::slotCanceled(const KUrl
& url
)
124 void DolphinPart::slotInfoMessage(const QString
& msg
)
126 emit
setStatusBarText(msg
);
129 void DolphinPart::slotErrorMessage(const QString
& msg
)
131 KMessageBox::error(m_view
, msg
);
134 void DolphinPart::slotRequestItemInfo(const KFileItem
& item
)
136 emit m_extension
->mouseOverInfo(&item
);
139 void DolphinPart::slotItemTriggered(const KFileItem
& item
)
141 emit m_extension
->openUrlRequest(item
.url());
144 #include "dolphinpart.moc"