home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / konq_popupmenu.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  7.3 KB  |  222 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 1998, 1999 David Faure <faure@kde.org>
  3.    Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>
  4.  
  5.    This library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License as published by the Free Software Foundation; either
  8.    version 2 of the License, or (at your option) any later version.
  9.  
  10.    This library is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public License
  16.    along with this library; see the file COPYING.LIB.  If not, write to
  17.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.    Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef __konqpopupmenu_h
  22. #define __konqpopupmenu_h
  23.  
  24. #include <sys/types.h>
  25.  
  26. #include <qpopupmenu.h>
  27. #include <qmap.h>
  28. #include <kaction.h>
  29.  
  30. #include <qstringlist.h>
  31.  
  32. #include <kfileitem.h>
  33. #include <kmimetype.h> // for KDEDesktopMimeType
  34. #include <libkonq_export.h>
  35.  
  36. #include <kparts/browserextension.h>
  37.  
  38. #include "konq_xmlguiclient.h"
  39.  
  40. typedef QValueList<KDEDesktopMimeType::Service> ServiceList;
  41.  
  42. class KPropertiesDialog;
  43. class KNewMenu;
  44. class KService;
  45. class KonqPopupMenuPlugin;
  46. class KBookmarkManager;
  47.  
  48. // TODO KDE4: change base class to KPopupMenu, see KAction::slotPopupActivated()
  49. /**
  50.  * This class implements the popup menu for URLs in konqueror and kdesktop
  51.  * It's usage is very simple : on right click, create the KonqPopupMenu instance
  52.  * with the correct arguments, then exec() to make it appear, then destroy it.
  53.  *
  54.  */
  55. class LIBKONQ_EXPORT KonqPopupMenu : public QPopupMenu, public KonqXMLGUIClient
  56. {
  57.   Q_OBJECT
  58. public:
  59.  
  60.   /**
  61.    * Flags set by the calling application (konqueror/kdesktop), unlike
  62.    * KParts::BrowserExtension::PopupFlags, which are set by the calling part
  63.    */
  64.   typedef uint KonqPopupFlags;
  65.   enum { NoFlags = 0,
  66.          ShowProperties = 1,  ///< whether to show the "Properties" menu item
  67.          IsLink = 2,          ///< HTML link. If set, we won't have cut/copy/paste, and we'll say "bookmark this link"
  68.          ShowNewWindow = 4 };
  69.          // WARNING: bitfield. Next item is 8
  70.  
  71.   /**
  72.    * @deprecated lacks parentWidget pointer, and
  73.    * uses bool instead of KonqPopupFlags enum,
  74.    * might do strange things with the 'new window' action.
  75.    */
  76.   KonqPopupMenu( KBookmarkManager* manager,
  77.                  const KFileItemList &items,
  78.                  KURL viewURL,
  79.                  KActionCollection & actions,
  80.                  KNewMenu * newMenu,
  81.                  bool showPropertiesAndFileType = true ) KDE_DEPRECATED;
  82.  
  83.   /**
  84.    * @deprecated uses bool instead of KonqPopupFlags enum,
  85.    * might do strange things with the 'new window' action.
  86.    */
  87.   KonqPopupMenu( KBookmarkManager* manager,
  88.                  const KFileItemList &items,
  89.                  KURL viewURL,
  90.                  KActionCollection & actions,
  91.                  KNewMenu * newMenu,
  92.          QWidget * parentWidget,
  93.          bool showPropertiesAndFileType = true ) KDE_DEPRECATED;
  94.  
  95.   /**
  96.    * Constructor
  97.    * @param manager the bookmark manager for this bookmark
  98.    * @param items the list of file items the popupmenu should be shown for
  99.    * @param viewURL the URL shown in the view, to test for RMB click on view background
  100.    * @param actions list of actions the caller wants to see in the menu
  101.    * @param newMenu "New" menu, shared with the File menu, in konqueror
  102.    * @param parentWidget the widget we're showing this popup for. Helps destroying
  103.    * the popup if the widget is destroyed before the popup.
  104.    * @param kpf flags from the KonqPopupFlags enum, set by the calling application
  105.    * @param f flags from the BrowserExtension enum, set by the calling part
  106.    *
  107.    * The actions to pass in include :
  108.    * showmenubar, back, forward, up, cut, copy, paste, pasteto, trash, rename, del
  109.    * The others items are automatically inserted.
  110.    *
  111.    * @since 3.2
  112.    *
  113.    * @todo that list is probably not be up-to-date
  114.    */
  115.   KonqPopupMenu( KBookmarkManager* manager,
  116.                  const KFileItemList &items,
  117.                  const KURL& viewURL,
  118.                  KActionCollection & actions,
  119.                  KNewMenu * newMenu,
  120.                  QWidget * parentWidget,
  121.                  KonqPopupFlags kpf,
  122.                  KParts::BrowserExtension::PopupFlags f /*= KParts::BrowserExtension::DefaultPopupItems*/);
  123.  
  124.   /**
  125.    * Don't forget to destroy the object
  126.    */
  127.   ~KonqPopupMenu();
  128.  
  129.   /**
  130.    * Set the title of the URL, when the popupmenu is opened for a single URL.
  131.    * This is used if the user chooses to add a bookmark for this URL.
  132.    */
  133.   void setURLTitle( const QString& urlTitle );
  134.  
  135.   class LIBKONQ_EXPORT ProtocolInfo {
  136.    public:
  137.     ProtocolInfo();
  138.     bool supportsReading()  const;
  139.     bool supportsWriting()  const;
  140.     bool supportsDeleting() const;
  141.     bool supportsMoving()   const;
  142.     bool trashIncluded()    const;
  143.    private:
  144.     friend class KonqPopupMenu;
  145.     bool m_Reading:1;
  146.     bool m_Writing:1;
  147.     bool m_Deleting:1;
  148.     bool m_Moving:1;
  149.     bool m_TrashIncluded:1;
  150.   };
  151.   /**
  152.    * Reimplemented for internal purpose
  153.    */
  154.   virtual KAction *action( const QDomElement &element ) const;
  155.  
  156.  
  157.   virtual KActionCollection *actionCollection() const;
  158.   QString mimeType( ) const;
  159.   KURL url( ) const;
  160.   KFileItemList fileItemList() const;
  161.   KURL::List popupURLList( ) const;
  162.   ProtocolInfo protocolInfo() const;
  163.  
  164. public slots: // KDE4: why public?
  165.   void slotPopupNewDir();
  166.   void slotPopupNewView();
  167.   void slotPopupEmptyTrashBin();
  168.   void slotPopupRestoreTrashedItems();
  169.   void slotPopupOpenWith();
  170.   void slotPopupAddToBookmark();
  171.   void slotRunService();
  172.   void slotPopupMimeType();
  173.   void slotPopupProperties();
  174.   void slotOpenShareFileDialog();
  175. protected:
  176.   KActionCollection &m_actions;
  177.   KActionCollection m_ownActions;
  178.  
  179. private:
  180.   void init (QWidget * parentWidget, KonqPopupFlags kpf, KParts::BrowserExtension::PopupFlags itemFlags);
  181.   void setup(KonqPopupFlags kpf);
  182.   void addPlugins( );
  183.   int  insertServicesSubmenus(const QMap<QString, ServiceList>& list, QDomElement& menu, bool isBuiltin);
  184.   int  insertServices(const ServiceList& list, QDomElement& menu, bool isBuiltin);
  185.   bool KIOSKAuthorizedAction(KConfig& cfg);
  186.   KPropertiesDialog* showPropertiesDialog();
  187.  
  188.   class KonqPopupMenuPrivate;
  189.   KonqPopupMenuPrivate *d;
  190.   KNewMenu *m_pMenuNew;
  191.   KURL m_sViewURL;
  192.   QString m_sMimeType;
  193.   KFileItemList m_lstItems;
  194.   KURL::List m_lstPopupURLs;
  195.   QMap<int,KService::Ptr> m_mapPopup;
  196.   QMap<int,KDEDesktopMimeType::Service> m_mapPopupServices;
  197.   bool m_bHandleEditOperations;
  198.   KXMLGUIFactory *m_factory;
  199.   KXMLGUIBuilder *m_builder;
  200.   QString attrName;
  201.   ProtocolInfo m_info;
  202.   QPtrList<KonqPopupMenuPlugin> m_pluginList;
  203.   KBookmarkManager* m_pManager;
  204. };
  205.  
  206. class LIBKONQ_EXPORT KonqPopupMenuPlugin : public QObject, public KonqXMLGUIClient {
  207.     Q_OBJECT
  208. public:
  209.   /**
  210.   * Constructor
  211.   * If you want to insert a dynamic item or menu to konqpopupmenu
  212.   * this class is the right choice.
  213.   * Create a KAction and use _popup->addAction(new KAction );
  214.   * If you want to create a submenu use _popup->addGroup( );
  215.   */
  216.   KonqPopupMenuPlugin( KonqPopupMenu *_popup, const char *name ); // this should also be the parent
  217.   virtual ~KonqPopupMenuPlugin ( );
  218. };
  219.  
  220. #endif
  221.  
  222.