summaryrefslogtreecommitdiffstats
path: root/libkonq/konq_popupmenu.h
blob: 15dbcef5e2a57b970e0a198ffc0255a7f56f5c00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/* This file is part of the KDE project
   Copyright (C) 1998, 1999 David Faure <faure@kde.org>
   Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef __konqpopupmenu_h
#define __konqpopupmenu_h

#include <sys/types.h>

#include <tqpopupmenu.h>
#include <tqmap.h>
#include <kaction.h>

#include <tqstringlist.h>

#include <kfileitem.h>
#include <kmimetype.h> // for KDEDesktopMimeType
#include <libkonq_export.h>

#include <kparts/browserextension.h>

#include "konq_xmlguiclient.h"

typedef TQValueList<KDEDesktopMimeType::Service> ServiceList;

class KPropertiesDialog;
class KNewMenu;
class KService;
class KonqPopupMenuPlugin;
class KBookmarkManager;

// TODO KDE4: change base class to KPopupMenu, see KAction::slotPopupActivated()
/**
 * This class implements the popup menu for URLs in konqueror and kdesktop
 * It's usage is very simple : on right click, create the KonqPopupMenu instance
 * with the correct arguments, then exec() to make it appear, then destroy it.
 *
 */
class LIBKONQ_EXPORT KonqPopupMenu : public TQPopupMenu, public KonqXMLGUIClient
{
  Q_OBJECT
public:

  /**
   * Flags set by the calling application (konqueror/kdesktop), unlike
   * KParts::BrowserExtension::PopupFlags, which are set by the calling part
   */
  typedef uint KonqPopupFlags;
  enum { NoFlags = 0,
         ShowProperties = 1,  ///< whether to show the "Properties" menu item
         IsLink = 2,          ///< HTML link. If set, we won't have cut/copy/paste, and we'll say "bookmark this link"
         ShowNewWindow = 4 };
         // WARNING: bitfield. Next item is 8

  /**
   * @deprecated lacks tqparentWidget pointer, and
   * uses bool instead of KonqPopupFlags enum,
   * might do strange things with the 'new window' action.
   */
  KonqPopupMenu( KBookmarkManager* manager,
                 const KFileItemList &items,
                 KURL viewURL,
                 KActionCollection & actions,
                 KNewMenu * newMenu,
                 bool showPropertiesAndFileType = true ) KDE_DEPRECATED;

  /**
   * @deprecated uses bool instead of KonqPopupFlags enum,
   * might do strange things with the 'new window' action.
   */
  KonqPopupMenu( KBookmarkManager* manager,
                 const KFileItemList &items,
                 KURL viewURL,
                 KActionCollection & actions,
                 KNewMenu * newMenu,
		 TQWidget * tqparentWidget,
		 bool showPropertiesAndFileType = true ) KDE_DEPRECATED;

  /**
   * Constructor
   * @param manager the bookmark manager for this bookmark
   * @param items the list of file items the popupmenu should be shown for
   * @param viewURL the URL shown in the view, to test for RMB click on view background
   * @param actions list of actions the caller wants to see in the menu
   * @param newMenu "New" menu, shared with the File menu, in konqueror
   * @param tqparentWidget the widget we're showing this popup for. Helps destroying
   * the popup if the widget is destroyed before the popup.
   * @param kpf flags from the KonqPopupFlags enum, set by the calling application
   * @param f flags from the BrowserExtension enum, set by the calling part
   *
   * The actions to pass in include :
   * showmenubar, back, forward, up, cut, copy, paste, pasteto, trash, rename, del
   * The others items are automatically inserted.
   *
   * @since 3.2
   *
   * @todo that list is probably not be up-to-date
   */
  KonqPopupMenu( KBookmarkManager* manager,
                 const KFileItemList &items,
                 const KURL& viewURL,
                 KActionCollection & actions,
                 KNewMenu * newMenu,
                 TQWidget * tqparentWidget,
                 KonqPopupFlags kpf,
                 KParts::BrowserExtension::PopupFlags f /*= KParts::BrowserExtension::DefaultPopupItems*/);

  /**
   * Don't forget to destroy the object
   */
  ~KonqPopupMenu();

  /**
   * Set the title of the URL, when the popupmenu is opened for a single URL.
   * This is used if the user chooses to add a bookmark for this URL.
   */
  void setURLTitle( const TQString& urlTitle );

  class LIBKONQ_EXPORT ProtocolInfo {
   public:
    ProtocolInfo();
    bool supportsReading()  const;
    bool supportsWriting()  const;
    bool supportsDeleting() const;
    bool supportsMoving()   const;
    bool trashIncluded()    const;
   private:
    friend class KonqPopupMenu;
    bool m_Reading:1;
    bool m_Writing:1;
    bool m_Deleting:1;
    bool m_Moving:1;
    bool m_TrashIncluded:1;
  };
  /**
   * Reimplemented for internal purpose
   */
  virtual KAction *action( const TQDomElement &element ) const;


  virtual KActionCollection *actionCollection() const;
  TQString mimeType( ) const;
  KURL url( ) const;
  KFileItemList fileItemList() const;
  KURL::List popupURLList( ) const;
  ProtocolInfo protocolInfo() const;

public slots: // KDE4: why public?
  void slotPopupNewDir();
  void slotPopupNewView();
  void slotPopupEmptyTrashBin();
  void slotPopupRestoreTrashedItems();
  void slotPopupOpenWith();
  void slotPopupAddToBookmark();
  void slotRunService();
  void slotPopupMimeType();
  void slotPopupProperties();
  void slotOpenShareFileDialog();
protected:
  KActionCollection &m_actions;
  KActionCollection m_ownActions;

private:
  void init (TQWidget * tqparentWidget, KonqPopupFlags kpf, KParts::BrowserExtension::PopupFlags itemFlags);
  void setup(KonqPopupFlags kpf);
  void addPlugins( );
  int  insertServicesSubmenus(const TQMap<TQString, ServiceList>& list, TQDomElement& menu, bool isBuiltin);
  int  insertServices(const ServiceList& list, TQDomElement& menu, bool isBuiltin);
  bool KIOSKAuthorizedAction(KConfig& cfg);
  KPropertiesDialog* showPropertiesDialog();

  class KonqPopupMenuPrivate;
  KonqPopupMenuPrivate *d;
  KNewMenu *m_pMenuNew;
  KURL m_sViewURL;
  TQString m_sMimeType;
  KFileItemList m_lstItems;
  KURL::List m_lstPopupURLs;
  TQMap<int,KService::Ptr> m_mapPopup;
  TQMap<int,KDEDesktopMimeType::Service> m_mapPopupServices;
  bool m_bHandleEditOperations;
  KXMLGUIFactory *m_factory;
  KXMLGUIBuilder *m_builder;
  TQString attrName;
  ProtocolInfo m_info;
  TQPtrList<KonqPopupMenuPlugin> m_pluginList;
  KBookmarkManager* m_pManager;
};

class LIBKONQ_EXPORT KonqPopupMenuPlugin : public TQObject, public KonqXMLGUIClient {
	Q_OBJECT
public:
  /**
  * Constructor
  * If you want to insert a dynamic item or menu to konqpopupmenu
  * this class is the right choice.
  * Create a KAction and use _popup->tqaddAction(new KAction );
  * If you want to create a submenu use _popup->addGroup( );
  */
  KonqPopupMenuPlugin( KonqPopupMenu *_popup, const char *name ); // this should also be the parent
  virtual ~KonqPopupMenuPlugin ( );
};

#endif