2006-11-21 06:02:05 +00:00
|
|
|
/***************************************************************************
|
2007-03-15 22:42:21 +00:00
|
|
|
* Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
|
2006-11-21 06:02:05 +00:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
2006-12-08 21:24:08 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
2006-11-21 06:02:05 +00:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef DOLPHINCONTEXTMENU_H
|
|
|
|
#define DOLPHINCONTEXTMENU_H
|
|
|
|
|
2007-03-15 22:42:21 +00:00
|
|
|
#include <kdedesktopmimetype.h>
|
|
|
|
#include <kfileitem.h>
|
|
|
|
#include <kservice.h>
|
|
|
|
#include <kurl.h>
|
|
|
|
|
2007-01-21 21:20:37 +00:00
|
|
|
#include <QString>
|
|
|
|
#include <QVector>
|
|
|
|
|
2006-11-22 08:12:45 +00:00
|
|
|
class KMenu;
|
2006-11-21 06:02:05 +00:00
|
|
|
class KFileItem;
|
2007-03-15 22:42:21 +00:00
|
|
|
class QAction;
|
|
|
|
class DolphinMainWindow;
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Represents the context menu which appears when doing a right
|
2007-03-15 22:42:21 +00:00
|
|
|
* click on an item or the viewport of the file manager.
|
2006-11-21 06:02:05 +00:00
|
|
|
*
|
|
|
|
* Beside static menu entries (e. g. 'Paste' or 'Properties') two
|
|
|
|
* dynamic sub menus are shown when opening a context menu above
|
|
|
|
* an item:
|
|
|
|
* - 'Open With': Contains all applications which are registered to
|
|
|
|
* open items of the given MIME type.
|
|
|
|
* - 'Actions': Contains all actions which can be applied to the
|
|
|
|
* given item.
|
|
|
|
*/
|
|
|
|
class DolphinContextMenu
|
|
|
|
{
|
|
|
|
public:
|
2007-03-16 00:24:56 +00:00
|
|
|
enum ViewType
|
|
|
|
{
|
|
|
|
ItemsView,
|
|
|
|
SidebarView
|
|
|
|
};
|
|
|
|
|
2006-11-21 06:02:05 +00:00
|
|
|
/**
|
2007-03-15 22:42:21 +00:00
|
|
|
* @parent Pointer to the main window the context menu
|
|
|
|
* belongs to.
|
|
|
|
* @fileInfo Pointer to the file item the context menu
|
|
|
|
* is applied. If 0 is passed, the context menu
|
|
|
|
* is above the viewport.
|
|
|
|
* @baseUrl Base URL of the viewport where the context menu
|
|
|
|
* should be opened.
|
2007-03-16 00:24:56 +00:00
|
|
|
* @viewType On which view type is the context menu shown.
|
2006-11-21 06:02:05 +00:00
|
|
|
*/
|
2007-03-15 22:42:21 +00:00
|
|
|
DolphinContextMenu(DolphinMainWindow* parent,
|
|
|
|
KFileItem* fileInfo,
|
|
|
|
const KUrl& baseUrl,
|
2007-03-16 00:24:56 +00:00
|
|
|
ViewType viewType = ItemsView);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
virtual ~DolphinContextMenu();
|
|
|
|
|
|
|
|
/** Opens the context menu modal. */
|
|
|
|
void open();
|
|
|
|
|
|
|
|
private:
|
2007-03-15 21:24:41 +00:00
|
|
|
void openTrashContextMenu();
|
|
|
|
void openTrashItemContextMenu();
|
2006-11-21 06:02:05 +00:00
|
|
|
void openItemContextMenu();
|
2007-03-15 21:24:41 +00:00
|
|
|
void openViewportContextMenu();
|
|
|
|
|
|
|
|
void insertDefaultItemActions(KMenu* popup);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts the 'Open With...' submenu to \a popup.
|
|
|
|
* @param popup Menu where the 'Open With...' sub menu should
|
|
|
|
* be added.
|
|
|
|
* @param openWithVector Output parameter which contains all 'Open with...'
|
|
|
|
* services.
|
|
|
|
* @return Identifier of the first 'Open With...' entry.
|
|
|
|
* All succeeding identifiers have an increased value of 1
|
|
|
|
* to the predecessor.
|
|
|
|
*/
|
2006-11-22 11:34:19 +00:00
|
|
|
QList<QAction*> insertOpenWithItems(KMenu* popup,
|
2007-01-21 21:20:37 +00:00
|
|
|
QVector<KService::Ptr>& openWithVector);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts the 'Actions...' submenu to \a popup.
|
|
|
|
* @param popup Menu where the 'Actions...' sub menu should
|
|
|
|
* be added.
|
|
|
|
* @param openWithVector Output parameter which contains all 'Actions...'
|
|
|
|
* services.
|
|
|
|
*/
|
2006-11-22 11:34:19 +00:00
|
|
|
QList<QAction*> insertActionItems(KMenu* popup,
|
2007-01-21 21:20:37 +00:00
|
|
|
QVector<KDEDesktopMimeType::Service>& actionsVector);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true, if 'menu' contains already
|
|
|
|
* an entry with the name 'entryName'.
|
|
|
|
*/
|
2006-11-22 08:12:45 +00:00
|
|
|
bool containsEntry(const KMenu* menu,
|
2006-11-21 06:02:05 +00:00
|
|
|
const QString& entryName) const;
|
|
|
|
|
2007-03-15 21:24:41 +00:00
|
|
|
private:
|
2006-11-21 06:02:05 +00:00
|
|
|
struct Entry {
|
|
|
|
int type;
|
|
|
|
QString name;
|
|
|
|
QString filePath; // empty for separator
|
|
|
|
QString templatePath; // same as filePath for template
|
|
|
|
QString icon;
|
|
|
|
QString comment;
|
|
|
|
};
|
2007-03-15 21:24:41 +00:00
|
|
|
|
|
|
|
enum ContextType {
|
|
|
|
NoContext = 0,
|
|
|
|
ItemContext = 1,
|
|
|
|
TrashContext = 2
|
|
|
|
};
|
|
|
|
|
2007-03-15 22:42:21 +00:00
|
|
|
DolphinMainWindow* m_mainWindow;
|
2007-03-15 21:24:41 +00:00
|
|
|
KFileItem* m_fileInfo;
|
2007-03-15 22:42:21 +00:00
|
|
|
KUrl m_baseUrl;
|
|
|
|
KFileItemList m_selectedItems;
|
|
|
|
KUrl::List m_selectedUrls;
|
2007-03-16 00:24:56 +00:00
|
|
|
ViewType m_viewType;
|
2007-03-15 21:24:41 +00:00
|
|
|
int m_context;
|
2006-11-21 06:02:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|