tdebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

konq_view.h 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. /* -*- c-basic-offset: 2 -*-
  2. * This file is part of the KDE project
  3. * Copyright (C) 1998-2005 David Faure <faure@kde.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program 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
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. **/
  19. #ifndef __konq_view_h__
  20. #define __konq_view_h__
  21. #include "konq_mainwindow.h"
  22. #include "konq_factory.h"
  23. #include <tqptrlist.h>
  24. #include <tqstring.h>
  25. #include <tqobject.h>
  26. #include <tqstringlist.h>
  27. #include <tqguardedptr.h>
  28. #include <tqcstring.h>
  29. #include <ktrader.h>
  30. class KonqRun;
  31. class KonqFrame;
  32. class KonqViewIface;
  33. class KonqBrowserInterface;
  34. namespace KParts
  35. {
  36. class BrowserExtension;
  37. class StatusBarExtension;
  38. }
  39. struct HistoryEntry
  40. {
  41. KURL url;
  42. TQString locationBarURL; // can be different from url when showing a index.html
  43. TQString title;
  44. TQByteArray buffer;
  45. TQString strServiceType;
  46. TQString strServiceName;
  47. TQByteArray postData;
  48. TQString postContentType;
  49. bool doPost;
  50. TQString pageReferrer;
  51. KonqMainWindow::PageSecurity pageSecurity;
  52. };
  53. /* This class represents a child of the main view. The main view maintains
  54. * the list of children. A KonqView contains a Browser::View and
  55. * handles it. It's more or less the backend structure for the views.
  56. * The widget handling stuff is done by the KonqFrame.
  57. */
  58. class KonqView : public TQObject
  59. {
  60. Q_OBJECT
  61. public:
  62. /**
  63. * Create a konqueror view
  64. * @param viewFactory the factory to be used to create the part
  65. * @param viewFrame the frame where to create the view
  66. * @param mainWindow is the main window :-)
  67. * @param service the service implementing the part
  68. * @param partServiceOffers list of part offers found by the factory
  69. * @param appServiceOffers list of app offers found by the factory
  70. * @param serviceType the serviceType implemented by the part
  71. * @param passiveMode whether to initially make the view passive
  72. */
  73. KonqView( KonqViewFactory &viewFactory,
  74. KonqFrame* viewFrame,
  75. KonqMainWindow * mainWindow,
  76. const KService::Ptr &service,
  77. const TDETrader::OfferList &partServiceOffers,
  78. const TDETrader::OfferList &appServiceOffers,
  79. const TQString &serviceType,
  80. bool passiveMode);
  81. ~KonqView();
  82. /**
  83. * Displays another URL, but without changing the view mode (caller has to
  84. * ensure that the call makes sense)
  85. * @param url the URL to open
  86. * @param locationBarURL the URL to set in the location bar (see @ref setLocationBarURL)
  87. * @param nameFilter e.g. *.cpp
  88. * @param tempFile whether to delete the file after use
  89. */
  90. void openURL( const KURL &url,
  91. const TQString & locationBarURL,
  92. const TQString &nameFilter = TQString::null,
  93. bool tempFile = false );
  94. /**
  95. * Change the type of view (i.e. loads a new konqueror view)
  96. * Contract: the caller should call stop() first,
  97. *
  98. * @param serviceType the service type we want to show
  99. * @param serviceName allows to enforce a particular service to be chosen,
  100. * @see KonqFactory.
  101. */
  102. bool changeViewMode( const TQString &serviceType,
  103. const TQString &serviceName = TQString::null,
  104. bool forceAutoEmbed = false );
  105. /**
  106. * Call this to prevent next openURL() call from changing history lists
  107. * Used when the same URL is reloaded (for instance with another view mode)
  108. *
  109. * Calling with lock=false is a hack reserved to the "find" feature.
  110. */
  111. void lockHistory( bool lock = true ) { m_bLockHistory = lock; }
  112. /**
  113. * @return true if view can go back
  114. */
  115. bool canGoBack()const { return m_lstHistory.at() > 0; }
  116. /**
  117. * @return true if view can go forward
  118. */
  119. bool canGoForward()const { return m_lstHistory.at() != ((int)m_lstHistory.count())-1; }
  120. /**
  121. * @return the position in the history
  122. */
  123. int historyPos() const { return m_lstHistory.at(); }
  124. uint historyLength() { return m_lstHistory.count(); }
  125. /**
  126. * Move in history. +1 is "forward", -1 is "back", you can guess the rest.
  127. */
  128. void go( int steps );
  129. /**
  130. * Helper function for go() and KonqViewManager
  131. */
  132. void restoreHistory();
  133. void setHistoryPos(int newPos) { m_lstHistory.at( newPos ); }
  134. /**
  135. * @return the history of this view
  136. */
  137. const TQPtrList<HistoryEntry> & history() { return m_lstHistory; }
  138. /**
  139. * @return the HistoryEntry at postion @p pos
  140. */
  141. const HistoryEntry* historyAt(const int pos);
  142. /**
  143. * Creates a deep copy of the @p other view's history buffers.
  144. */
  145. void copyHistory( KonqView *other );
  146. /**
  147. * Set the KonqRun instance that is running something for this view
  148. * The main window uses this to store the KonqRun for each child view.
  149. */
  150. void setRun( KonqRun * run );
  151. KonqRun *run() const { return m_pRun; }
  152. /**
  153. * Stop loading
  154. */
  155. void stop();
  156. /**
  157. * Retrieve view's URL
  158. */
  159. KURL url() const;
  160. KURL upURL() const;
  161. /**
  162. * Get view's location bar URL, i.e. the one that the view signals
  163. * It can be different from url(), for instance if we display a index.html
  164. */
  165. TQString locationBarURL() const { return m_sLocationBarURL; }
  166. /**
  167. * Get the URL that was typed to get the current URL.
  168. */
  169. TQString typedURL() const { return m_sTypedURL; }
  170. /**
  171. * Set the URL that was typed to get the current URL.
  172. */
  173. void setTypedURL( const TQString & u ) { m_sTypedURL = u; }
  174. /**
  175. * Return the security state of page in view
  176. */
  177. KonqMainWindow::PageSecurity pageSecurity() const { return m_pageSecurity; }
  178. /**
  179. * @return the part embedded into this view
  180. */
  181. KParts::ReadOnlyPart *part() const { return m_pPart; }
  182. /**
  183. * see KonqViewManager::removePart
  184. */
  185. void partDeleted() { m_pPart = 0L; }
  186. KParts::BrowserExtension *browserExtension() const;
  187. KParts::StatusBarExtension *statusBarExtension() const;
  188. /**
  189. * @return a pointer to the KonqFrame which the view lives in
  190. */
  191. KonqFrame* frame() const { return m_pKonqFrame; }
  192. /**
  193. * @return the servicetype this view is currently displaying
  194. */
  195. TQString serviceType() const { return m_serviceType; }
  196. /**
  197. * @return the servicetypes this view is capable to display
  198. */
  199. TQStringList serviceTypes() const { return m_service->serviceTypes(); }
  200. bool supportsServiceType( const TQString &serviceType ) const;
  201. // True if "Use index.html" is set (->the view doesn't necessarily show HTML!)
  202. bool allowHTML() const { return m_bAllowHTML; }
  203. void setAllowHTML( bool allow ) { m_bAllowHTML = allow; }
  204. // True if currently loading
  205. bool isLoading() const { return m_bLoading; }
  206. void setLoading( bool loading, bool hasPending = false );
  207. // True if "locked to current location" (and their view mode, in fact)
  208. bool isLockedLocation() const { return m_bLockedLocation; }
  209. void setLockedLocation( bool b );
  210. // True if can't be made active (e.g. dirtree).
  211. bool isPassiveMode() const { return m_bPassiveMode; }
  212. void setPassiveMode( bool mode );
  213. // True if is hierarchical view
  214. bool isHierarchicalView() const { return m_bHierarchicalView; }
  215. void setHierarchicalView( bool mode );
  216. // True if 'link' symbol set
  217. bool isLinkedView() const { return m_bLinkedView; }
  218. void setLinkedView( bool mode );
  219. // True if toggle view
  220. void setToggleView( bool b ) { m_bToggleView = b; }
  221. bool isToggleView() const { return m_bToggleView; }
  222. // True if it always follows the active view
  223. void setFollowActive(bool b) { m_bFollowActive = b; }
  224. bool isFollowActive() { return m_bFollowActive; }
  225. // True if locked to current view mode
  226. // Toggle views and passive views are locked to their view mode.
  227. bool isLockedViewMode() const { return m_bToggleView || m_bPassiveMode; }
  228. // True if "builtin" (see X-TDE-BrowserView-Built-Into)
  229. bool isBuiltinView() const { return m_bBuiltinView; }
  230. void setService( const KService::Ptr &s ) { m_service = s; }
  231. KService::Ptr service() { return m_service; }
  232. TQString caption() const { return m_caption; }
  233. TDETrader::OfferList partServiceOffers() { return m_partServiceOffers; }
  234. TDETrader::OfferList appServiceOffers() { return m_appServiceOffers; }
  235. KonqMainWindow *mainWindow() const { return m_pMainWindow; }
  236. // return true if the method was found, false if the execution failed
  237. bool callExtensionMethod( const char *methodName );
  238. bool callExtensionBoolMethod( const char *methodName, bool value );
  239. bool callExtensionStringMethod( const char *methodName, TQString value );
  240. bool callExtensionURLMethod( const char *methodName, const KURL& value );
  241. void setViewName( const TQString &name );
  242. TQString viewName() const;
  243. // True to enable the context popup menu
  244. void enablePopupMenu( bool b );
  245. bool isPopupMenuEnabled() const { return m_bPopupMenuEnabled; }
  246. void reparseConfiguration();
  247. void disableScrolling();
  248. TQStringList frameNames() const;
  249. KonqViewIface * dcopObject();
  250. void goHistory( int steps );
  251. // Set the TDEGlobal active instance (the one used by KBugReport)
  252. void setActiveInstance();
  253. // Called before reloading this view. Sets args.reload to true, and offers to repost form data.
  254. // Returns false in case the reload must be cancelled.
  255. bool prepareReload( KParts::URLArgs& args );
  256. // overload for the TQString version
  257. void setLocationBarURL( const KURL& locationBarURL );
  258. static TQStringList childFrameNames( KParts::ReadOnlyPart *part );
  259. static KParts::BrowserHostExtension *hostExtension( KParts::ReadOnlyPart *part, const TQString &name );
  260. signals:
  261. /**
  262. * Signal the main window that the embedded part changed (e.g. because of changeViewMode)
  263. */
  264. void sigPartChanged( KonqView *childView, KParts::ReadOnlyPart *oldPart, KParts::ReadOnlyPart *newPart );
  265. /**
  266. * Emitted in slotCompleted
  267. */
  268. void viewCompleted( KonqView * view );
  269. /**
  270. * Emitted only if the option backRightClick is activated
  271. */
  272. void backRightClick();
  273. public slots:
  274. /**
  275. * Store location-bar URL in the child view
  276. * and updates the main view if this view is the current one
  277. * May be different from url e.g. if using "allowHTML".
  278. */
  279. void setLocationBarURL( const TQString & locationBarURL );
  280. /**
  281. * get an icon for the URL from the BrowserExtension
  282. */
  283. void setIconURL( const KURL &iconURL );
  284. void setTabIcon( const KURL &url );
  285. void setCaption( const TQString & caption );
  286. void setPageSecurity( int );
  287. // connected to the KROP's TDEIO::Job
  288. // but also to KonqRun's job
  289. void slotInfoMessage( TDEIO::Job *, const TQString &msg );
  290. protected slots:
  291. // connected to the KROP's TDEIO::Job
  292. void slotStarted( TDEIO::Job * job );
  293. void slotCompleted();
  294. void slotCompleted( bool );
  295. void slotCanceled( const TQString & errMsg );
  296. void slotPercent( TDEIO::Job *, unsigned long percent );
  297. void slotSpeed( TDEIO::Job *, unsigned long bytesPerSecond );
  298. /**
  299. * Connected to the BrowserExtension
  300. */
  301. void slotSelectionInfo( const KFileItemList &items );
  302. void slotMouseOverInfo( const KFileItem* item );
  303. void slotOpenURLNotify();
  304. void slotEnableAction( const char * name, bool enabled );
  305. void slotSetActionText( const char* name, const TQString& text );
  306. void slotMoveTopLevelWidget( int x, int y );
  307. void slotResizeTopLevelWidget( int w, int h );
  308. void slotRequestFocus(KParts::ReadOnlyPart*);
  309. private:
  310. void enableBackRightClick( bool b );
  311. /**
  312. * Replace the current view with a new view, created by @p viewFactory.
  313. */
  314. void switchView( KonqViewFactory &viewFactory );
  315. /**
  316. * Connects the internal part to the main window.
  317. * Do this after creating it and before inserting it.
  318. */
  319. void connectPart();
  320. /**
  321. * Creates a new entry in the history.
  322. */
  323. void createHistoryEntry();
  324. /**
  325. * Updates the current entry in the history.
  326. * @param saveLocationBarURL whether to save the location bar URL as part of it
  327. * (not done in openURL, to be able to revert if aborting)
  328. */
  329. void updateHistoryEntry(bool saveLocationBarURL);
  330. void aboutToOpenURL( const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() );
  331. void setServiceTypeInExtension();
  332. void finishedWithCurrentURL();
  333. virtual bool eventFilter( TQObject *obj, TQEvent *e );
  334. ////////////////// private members ///////////////
  335. KParts::ReadOnlyPart *m_pPart;
  336. TQString m_sLocationBarURL;
  337. TQString m_sTypedURL;
  338. KonqMainWindow::PageSecurity m_pageSecurity;
  339. /**
  340. * The full history (back + current + forward)
  341. * The current position in the history is m_lstHistory.current()
  342. */
  343. TQPtrList<HistoryEntry> m_lstHistory;
  344. /**
  345. * The post data that _resulted_ in this page.
  346. * e.g. when submitting a form, and the result is an image, this data will be
  347. * set (and saved/restored) when the image is being viewed. Necessary for reload.
  348. */
  349. TQByteArray m_postData;
  350. TQString m_postContentType;
  351. bool m_doPost;
  352. /**
  353. * The referrer that was used to obtain this page.
  354. */
  355. TQString m_pageReferrer;
  356. KonqMainWindow *m_pMainWindow;
  357. KonqRun *m_pRun;
  358. KonqFrame *m_pKonqFrame;
  359. uint m_bAllowHTML:1;
  360. uint m_bLoading:1;
  361. uint m_bLockedLocation:1;
  362. uint m_bPassiveMode:1;
  363. uint m_bLinkedView:1;
  364. uint m_bToggleView:1;
  365. uint m_bLockHistory:1;
  366. uint m_bAborted:1;
  367. uint m_bGotIconURL:1;
  368. uint m_bPopupMenuEnabled:1;
  369. uint m_bFollowActive:1;
  370. uint m_bPendingRedirection:1;
  371. uint m_bBuiltinView:1;
  372. uint m_bURLDropHandling:1;
  373. uint m_bBackRightClick:1;
  374. uint m_bHierarchicalView:1;
  375. uint m_bDisableScrolling:1;
  376. TDETrader::OfferList m_partServiceOffers;
  377. TDETrader::OfferList m_appServiceOffers;
  378. KService::Ptr m_service;
  379. TQString m_serviceType;
  380. TQString m_caption;
  381. TQString m_tempFile;
  382. KonqViewIface * m_dcopObject;
  383. KonqBrowserInterface *m_browserIface;
  384. int m_randID;
  385. };
  386. #endif