Added implementation of the FileInfoExtension to allow KPart plugins to obtain such information

svn path=/trunk/KDE/kdebase/apps/; revision=1191993
This commit is contained in:
Dawit Alemayehu 2010-11-01 16:56:47 +00:00
parent 3aa13c7a24
commit 0ad893ae2b
4 changed files with 114 additions and 40 deletions

View file

@ -38,6 +38,7 @@
#include <knewfilemenu.h>
#include <kmenu.h>
#include <kinputdialog.h>
#include <kprotocolinfo.h>
#include "settings/dolphinsettings.h"
#include "views/dolphinview.h"
@ -61,6 +62,7 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QVariantL
Q_UNUSED(args)
setComponentData(DolphinPartFactory::componentData(), false);
m_extension = new DolphinPartBrowserExtension(this);
new DolphinPartFileInfoExtension(this);
// make sure that other apps using this part find Dolphin's view-file-columns icons
KIconLoader::global()->addAppDir("dolphin");
@ -465,46 +467,6 @@ void DolphinPart::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
}
}
////
void DolphinPartBrowserExtension::restoreState(QDataStream &stream)
{
KParts::BrowserExtension::restoreState(stream);
m_part->view()->restoreState(stream);
}
void DolphinPartBrowserExtension::saveState(QDataStream &stream)
{
KParts::BrowserExtension::saveState(stream);
m_part->view()->saveState(stream);
}
void DolphinPartBrowserExtension::cut()
{
m_part->view()->cutSelectedItems();
}
void DolphinPartBrowserExtension::copy()
{
m_part->view()->copySelectedItems();
}
void DolphinPartBrowserExtension::paste()
{
m_part->view()->paste();
}
void DolphinPartBrowserExtension::pasteTo(const KUrl&)
{
m_part->view()->pasteIntoFolder();
}
void DolphinPartBrowserExtension::reparseConfiguration()
{
m_part->view()->refresh();
}
////
void DolphinPart::slotEditMimeType()
{
@ -630,4 +592,89 @@ void DolphinPart::setFilesToSelect(const KUrl::List& files)
m_view->markUrlsAsSelected(files);
}
////
void DolphinPartBrowserExtension::restoreState(QDataStream &stream)
{
KParts::BrowserExtension::restoreState(stream);
m_part->view()->restoreState(stream);
}
void DolphinPartBrowserExtension::saveState(QDataStream &stream)
{
KParts::BrowserExtension::saveState(stream);
m_part->view()->saveState(stream);
}
void DolphinPartBrowserExtension::cut()
{
m_part->view()->cutSelectedItems();
}
void DolphinPartBrowserExtension::copy()
{
m_part->view()->copySelectedItems();
}
void DolphinPartBrowserExtension::paste()
{
m_part->view()->paste();
}
void DolphinPartBrowserExtension::pasteTo(const KUrl&)
{
m_part->view()->pasteIntoFolder();
}
void DolphinPartBrowserExtension::reparseConfiguration()
{
m_part->view()->refresh();
}
////
DolphinPartFileInfoExtension::DolphinPartFileInfoExtension(DolphinPart* part)
: KParts::FileInfoExtension(part)
{
}
DolphinPart* DolphinPartFileInfoExtension::part() const
{
return static_cast<DolphinPart*>(parent());
}
bool DolphinPartFileInfoExtension::hasSelection() const
{
return part()->view()->hasSelection();
}
KParts::FileInfoExtension::QueryModes DolphinPartFileInfoExtension::supportedQueryModes() const
{
return (KParts::FileInfoExtension::AllItems | KParts::FileInfoExtension::SelectedItems);
}
KFileItemList DolphinPartFileInfoExtension::queryFor(KParts::FileInfoExtension::QueryMode mode) const
{
KFileItemList list;
if (mode == KParts::FileInfoExtension::None)
return list;
if (!(supportedQueryModes() & mode))
return list;
switch (mode) {
case KParts::FileInfoExtension::SelectedItems:
if (hasSelection())
return part()->view()->selectedItems();
break;
case KParts::FileInfoExtension::AllItems:
return part()->view()->allItems();
default:
break;
}
return list;
}
#include "dolphinpart.moc"

View file

@ -22,6 +22,7 @@
#include <kparts/part.h>
#include <kparts/browserextension.h>
#include <kparts/fileinfoextension.h>
#include <QItemSelectionModel>
@ -262,4 +263,20 @@ private:
DolphinPart* m_part;
};
class DolphinPartFileInfoExtension : public KParts::FileInfoExtension
{
Q_OBJECT
public:
DolphinPartFileInfoExtension(DolphinPart* part);
virtual QueryModes supportedQueryModes() const;
virtual bool hasSelection() const;
virtual KFileItemList queryFor(QueryMode mode) const;
protected:
DolphinPart* part() const;
};
#endif /* DOLPHINPART_H */

View file

@ -1458,4 +1458,9 @@ void DolphinView::restoreContentsPosition()
}
}
KFileItemList DolphinView::allItems() const
{
return m_viewAccessor.dirLister()->items();
}
#include "dolphinview.moc"

View file

@ -324,6 +324,11 @@ public:
*/
void saveState(QDataStream& stream);
/**
* Returns all the items in the current view.
*/
KFileItemList allItems() const;
public slots:
/**
* Changes the directory to \a url. If the current directory is equal to