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.cc 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  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. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; see the file COPYING. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include "konq_view.h"
  18. #include "tdeapplication.h"
  19. #include "KonqViewIface.h"
  20. #include "konq_settingsxt.h"
  21. #include "konq_frame.h"
  22. #include "konq_run.h"
  23. #include "konq_events.h"
  24. #include "konq_viewmgr.h"
  25. #include "konq_tabs.h"
  26. #include "konq_browseriface.h"
  27. #include <tdeparts/statusbarextension.h>
  28. #include <tdeparts/browserextension.h>
  29. #include <konq_historymgr.h>
  30. #include <konq_pixmapprovider.h>
  31. #include <assert.h>
  32. #include <kdebug.h>
  33. #include <kcursor.h>
  34. #include <kurldrag.h>
  35. #include <tqscrollview.h>
  36. #include <tqapplication.h>
  37. #include <tqmetaobject.h>
  38. #include <tqobjectlist.h>
  39. #include <config.h>
  40. #include <tqucomextra_p.h>
  41. #include <tdemessagebox.h>
  42. #include <tdelocale.h>
  43. #include <fixx11h.h>
  44. //#define DEBUG_HISTORY
  45. template class TQPtrList<HistoryEntry>;
  46. KonqView::KonqView( KonqViewFactory &viewFactory,
  47. KonqFrame* viewFrame,
  48. KonqMainWindow *mainWindow,
  49. const KService::Ptr &service,
  50. const TDETrader::OfferList &partServiceOffers,
  51. const TDETrader::OfferList &appServiceOffers,
  52. const TQString &serviceType,
  53. bool passiveMode
  54. )
  55. {
  56. m_pKonqFrame = viewFrame;
  57. m_pKonqFrame->setView( this );
  58. m_sLocationBarURL = "";
  59. m_pageSecurity = KonqMainWindow::NotCrypted;
  60. m_bLockHistory = false;
  61. m_doPost = false;
  62. m_pMainWindow = mainWindow;
  63. m_pRun = 0L;
  64. m_pPart = 0L;
  65. m_dcopObject = 0L;
  66. m_randID = TDEApplication::random();
  67. m_service = service;
  68. m_partServiceOffers = partServiceOffers;
  69. m_appServiceOffers = appServiceOffers;
  70. m_serviceType = serviceType;
  71. m_bAllowHTML = m_pMainWindow->isHTMLAllowed();
  72. m_lstHistory.setAutoDelete( true );
  73. m_bLoading = false;
  74. m_bPendingRedirection = false;
  75. m_bPassiveMode = passiveMode;
  76. m_bLockedLocation = false;
  77. m_bLinkedView = false;
  78. m_bAborted = false;
  79. m_bToggleView = false;
  80. m_bHierarchicalView = false;
  81. m_bDisableScrolling = false;
  82. m_bGotIconURL = false;
  83. m_bPopupMenuEnabled = true;
  84. m_browserIface = new KonqBrowserInterface( this, "browseriface" );
  85. m_bBackRightClick = KonqSettings::backRightClick();
  86. m_bFollowActive = false;
  87. m_bBuiltinView = false;
  88. m_bURLDropHandling = false;
  89. switchView( viewFactory );
  90. }
  91. KonqView::~KonqView()
  92. {
  93. //kdDebug(1202) << "KonqView::~KonqView : part = " << m_pPart << endl;
  94. if (KonqMainWindow::s_crashlog_file) {
  95. TQString part_url;
  96. if (m_pPart)
  97. part_url = m_pPart->url().url();
  98. if (part_url.isNull())
  99. part_url = "";
  100. TQCString line;
  101. line = ( TQString("close(%1):%2\n").arg(m_randID,0,16).arg(part_url) ).utf8();
  102. KonqMainWindow::s_crashlog_file->writeBlock(line, line.length());
  103. KonqMainWindow::s_crashlog_file->flush();
  104. }
  105. // We did so ourselves for passive views
  106. if (m_pPart != 0L)
  107. {
  108. finishedWithCurrentURL();
  109. if ( isPassiveMode() )
  110. disconnect( m_pPart, TQT_SIGNAL( destroyed() ), m_pMainWindow->viewManager(), TQT_SLOT( slotObjectDestroyed() ) );
  111. delete m_pPart;
  112. }
  113. setRun( 0L );
  114. //kdDebug(1202) << "KonqView::~KonqView " << this << " done" << endl;
  115. }
  116. void KonqView::openURL( const KURL &url, const TQString & locationBarURL,
  117. const TQString & nameFilter, bool tempFile )
  118. {
  119. kdDebug(1202) << "KonqView::openURL url=" << url << " locationBarURL=" << locationBarURL << endl;
  120. setServiceTypeInExtension();
  121. if (KonqMainWindow::s_crashlog_file) {
  122. TQString part_url;
  123. if (m_pPart)
  124. part_url = m_pPart->url().url();
  125. if (part_url.isNull())
  126. part_url = "";
  127. TQString url_url = url.url();
  128. if (url_url.isNull())
  129. url_url = TQString("");
  130. TQCString line;
  131. line = ( TQString("closed(%1):%2\n").arg(m_randID,0,16).arg(part_url) ).utf8();
  132. KonqMainWindow::s_crashlog_file->writeBlock(line,line.length());
  133. line = ( TQString("opened(%3):%4\n").arg(m_randID,0,16).arg(url_url) ).utf8();
  134. KonqMainWindow::s_crashlog_file->writeBlock(line,line.length());
  135. KonqMainWindow::s_crashlog_file->flush();
  136. }
  137. KParts::BrowserExtension *ext = browserExtension();
  138. KParts::URLArgs args;
  139. if ( ext )
  140. args = ext->urlArgs();
  141. // Typing "Enter" again after the URL of an aborted view, triggers a reload.
  142. if ( m_bAborted && m_pPart && m_pPart->url() == url && !args.doPost())
  143. {
  144. if ( !prepareReload( args ) )
  145. return;
  146. if ( ext )
  147. ext->setURLArgs( args );
  148. }
  149. #ifdef DEBUG_HISTORY
  150. kdDebug(1202) << "m_bLockedLocation=" << m_bLockedLocation << " args.lockHistory()=" << args.lockHistory() << endl;
  151. #endif
  152. if ( args.lockHistory() )
  153. lockHistory();
  154. if ( !m_bLockHistory )
  155. {
  156. // Store this new URL in the history, removing any existing forward history.
  157. // We do this first so that everything is ready if a part calls completed().
  158. createHistoryEntry();
  159. } else
  160. m_bLockHistory = false;
  161. callExtensionStringMethod( "setNameFilter(const TQString&)", nameFilter );
  162. if ( m_bDisableScrolling )
  163. callExtensionMethod( "disableScrolling()" );
  164. setLocationBarURL( locationBarURL );
  165. setPageSecurity(KonqMainWindow::NotCrypted);
  166. if ( !args.reload )
  167. {
  168. // Save the POST data that is necessary to open this URL
  169. // (so that reload can re-post it)
  170. m_doPost = args.doPost();
  171. m_postContentType = args.contentType();
  172. m_postData = args.postData;
  173. // Save the referrer
  174. m_pageReferrer = args.metaData()["referrer"];
  175. }
  176. if ( tempFile ) {
  177. // Store the path to the tempfile. Yes, we could store a bool only,
  178. // but this would be more dangerous. If anything goes wrong in the code,
  179. // we might end up deleting a real file.
  180. if ( url.isLocalFile() )
  181. m_tempFile = url.path();
  182. else
  183. kdWarning(1202) << "Tempfile option is set, but URL is remote: " << url << endl;
  184. }
  185. aboutToOpenURL( url, args );
  186. m_pPart->openURL( url );
  187. updateHistoryEntry(false /* don't save location bar URL yet */);
  188. // add pending history entry
  189. KonqHistoryManager::kself()->addPending( url, locationBarURL, TQString::null);
  190. #ifdef DEBUG_HISTORY
  191. kdDebug(1202) << "Current position : " << m_lstHistory.at() << endl;
  192. #endif
  193. }
  194. void KonqView::switchView( KonqViewFactory &viewFactory )
  195. {
  196. kdDebug(1202) << "KonqView::switchView" << endl;
  197. if ( m_pPart )
  198. m_pPart->widget()->hide();
  199. KParts::ReadOnlyPart *oldPart = m_pPart;
  200. m_pPart = m_pKonqFrame->attach( viewFactory ); // creates the part
  201. // Set the statusbar in the BE asap to avoid a TDEMainWindow statusbar being created.
  202. KParts::StatusBarExtension* sbext = statusBarExtension();
  203. if ( sbext )
  204. sbext->setStatusBar( frame()->statusbar() );
  205. // Activate the new part
  206. if ( oldPart )
  207. {
  208. m_pPart->setName( oldPart->name() );
  209. emit sigPartChanged( this, oldPart, m_pPart );
  210. delete oldPart;
  211. }
  212. connectPart();
  213. TQVariant prop;
  214. prop = m_service->property( "X-TDE-BrowserView-FollowActive");
  215. if (prop.isValid() && prop.toBool())
  216. {
  217. //kdDebug(1202) << "KonqView::switchView X-TDE-BrowserView-FollowActive -> setFollowActive" <<endl;
  218. setFollowActive(true);
  219. }
  220. prop = m_service->property( "X-TDE-BrowserView-Built-Into" );
  221. m_bBuiltinView = (prop.isValid() && prop.toString() == "konqueror");
  222. if ( !m_pMainWindow->viewManager()->isLoadingProfile() )
  223. {
  224. // Honour "non-removeable passive mode" (like the dirtree)
  225. prop = m_service->property( "X-TDE-BrowserView-PassiveMode");
  226. if ( prop.isValid() && prop.toBool() )
  227. {
  228. kdDebug(1202) << "KonqView::switchView X-TDE-BrowserView-PassiveMode -> setPassiveMode" << endl;
  229. setPassiveMode( true ); // set as passive
  230. }
  231. // Honour "linked view"
  232. prop = m_service->property( "X-TDE-BrowserView-LinkedView");
  233. if ( prop.isValid() && prop.toBool() )
  234. {
  235. setLinkedView( true ); // set as linked
  236. // Two views : link both
  237. if (m_pMainWindow->viewCount() <= 2) // '1' can happen if this view is not yet in the map
  238. {
  239. KonqView * otherView = m_pMainWindow->otherView( this );
  240. if (otherView)
  241. otherView->setLinkedView( true );
  242. }
  243. }
  244. }
  245. prop = m_service->property( "X-TDE-BrowserView-HierarchicalView");
  246. if ( prop.isValid() && prop.toBool() )
  247. {
  248. kdDebug() << "KonqView::switchView X-TDE-BrowserView-HierarchicalView -> setHierarchicalView" << endl;
  249. setHierarchicalView( true ); // set as hierarchial
  250. }
  251. else
  252. {
  253. setHierarchicalView( false );
  254. }
  255. }
  256. bool KonqView::changeViewMode( const TQString &serviceType,
  257. const TQString &serviceName,
  258. bool forceAutoEmbed )
  259. {
  260. // Caller should call stop first.
  261. assert ( !m_bLoading );
  262. kdDebug(1202) << "changeViewMode: serviceType is " << serviceType
  263. << " serviceName is " << serviceName
  264. << " current service name is " << m_service->desktopEntryName() << endl;
  265. if ( KMimeType::mimeType(serviceType)->is(m_serviceType) && (serviceName.isEmpty() || serviceName == m_service->desktopEntryName()) )
  266. return true;
  267. if ( isLockedViewMode() )
  268. {
  269. //kdDebug(1202) << "This view's mode is locked - can't change" << endl;
  270. return false; // we can't do that if our view mode is locked
  271. }
  272. kdDebug(1202) << "Switching view modes..." << endl;
  273. TDETrader::OfferList partServiceOffers, appServiceOffers;
  274. KService::Ptr service = 0L;
  275. KonqViewFactory viewFactory = KonqFactory::createView( serviceType, serviceName, &service, &partServiceOffers, &appServiceOffers, forceAutoEmbed );
  276. if ( viewFactory.isNull() )
  277. {
  278. // Revert location bar's URL to the working one
  279. if(history().current())
  280. setLocationBarURL( history().current()->locationBarURL );
  281. return false;
  282. }
  283. m_serviceType = serviceType;
  284. m_partServiceOffers = partServiceOffers;
  285. m_appServiceOffers = appServiceOffers;
  286. // Check if that's already the kind of part we have -> no need to recreate it
  287. // Note: we should have an operator= for KService...
  288. if ( m_service && m_service->desktopEntryPath() == service->desktopEntryPath() )
  289. {
  290. kdDebug( 1202 ) << "KonqView::changeViewMode. Reusing service. Service type set to " << m_serviceType << endl;
  291. if ( m_pMainWindow->currentView() == this )
  292. m_pMainWindow->updateViewModeActions();
  293. }
  294. else
  295. {
  296. m_service = service;
  297. switchView( viewFactory );
  298. }
  299. if ( m_pMainWindow->viewManager()->activePart() != m_pPart )
  300. {
  301. // Make the new part active. Note that we don't do it each time we
  302. // open a URL (becomes awful in view-follows-view mode), but we do
  303. // each time we change the view mode.
  304. // We don't do it in switchView either because it's called from the constructor too,
  305. // where the location bar url isn't set yet.
  306. //kdDebug(1202) << "Giving focus to new part " << m_pPart << endl;
  307. m_pMainWindow->viewManager()->setActivePart( m_pPart );
  308. }
  309. return true;
  310. }
  311. void KonqView::connectPart( )
  312. {
  313. //kdDebug(1202) << "KonqView::connectPart" << endl;
  314. connect( m_pPart, TQT_SIGNAL( started( TDEIO::Job * ) ),
  315. this, TQT_SLOT( slotStarted( TDEIO::Job * ) ) );
  316. connect( m_pPart, TQT_SIGNAL( completed() ),
  317. this, TQT_SLOT( slotCompleted() ) );
  318. connect( m_pPart, TQT_SIGNAL( completed(bool) ),
  319. this, TQT_SLOT( slotCompleted(bool) ) );
  320. connect( m_pPart, TQT_SIGNAL( canceled( const TQString & ) ),
  321. this, TQT_SLOT( slotCanceled( const TQString & ) ) );
  322. connect( m_pPart, TQT_SIGNAL( setWindowCaption( const TQString & ) ),
  323. this, TQT_SLOT( setCaption( const TQString & ) ) );
  324. KParts::BrowserExtension *ext = browserExtension();
  325. if ( ext )
  326. {
  327. ext->setBrowserInterface( m_browserIface );
  328. connect( ext, TQT_SIGNAL( openURLRequestDelayed( const KURL &, const KParts::URLArgs &) ),
  329. m_pMainWindow, TQT_SLOT( slotOpenURLRequest( const KURL &, const KParts::URLArgs & ) ) );
  330. if ( m_bPopupMenuEnabled )
  331. {
  332. m_bPopupMenuEnabled = false; // force
  333. enablePopupMenu( true );
  334. }
  335. connect( ext, TQT_SIGNAL( setLocationBarURL( const TQString & ) ),
  336. this, TQT_SLOT( setLocationBarURL( const TQString & ) ) );
  337. connect( ext, TQT_SIGNAL( setIconURL( const KURL & ) ),
  338. this, TQT_SLOT( setIconURL( const KURL & ) ) );
  339. connect( ext, TQT_SIGNAL( setPageSecurity( int ) ),
  340. this, TQT_SLOT( setPageSecurity( int ) ) );
  341. connect( ext, TQT_SIGNAL( createNewWindow( const KURL &, const KParts::URLArgs & ) ),
  342. m_pMainWindow, TQT_SLOT( slotCreateNewWindow( const KURL &, const KParts::URLArgs & ) ) );
  343. connect( ext, TQT_SIGNAL( createNewWindow( const KURL &, const KParts::URLArgs &, const KParts::WindowArgs &, KParts::ReadOnlyPart *& ) ),
  344. m_pMainWindow, TQT_SLOT( slotCreateNewWindow( const KURL &, const KParts::URLArgs &, const KParts::WindowArgs &, KParts::ReadOnlyPart *& ) ) );
  345. connect( ext, TQT_SIGNAL( loadingProgress( int ) ),
  346. m_pKonqFrame->statusbar(), TQT_SLOT( slotLoadingProgress( int ) ) );
  347. connect( ext, TQT_SIGNAL( speedProgress( int ) ),
  348. m_pKonqFrame->statusbar(), TQT_SLOT( slotSpeedProgress( int ) ) );
  349. connect( ext, TQT_SIGNAL( selectionInfo( const KFileItemList & ) ),
  350. this, TQT_SLOT( slotSelectionInfo( const KFileItemList & ) ) );
  351. connect( ext, TQT_SIGNAL( mouseOverInfo( const KFileItem * ) ),
  352. this, TQT_SLOT( slotMouseOverInfo( const KFileItem * ) ) );
  353. connect( ext, TQT_SIGNAL( openURLNotify() ),
  354. this, TQT_SLOT( slotOpenURLNotify() ) );
  355. connect( ext, TQT_SIGNAL( enableAction( const char *, bool ) ),
  356. this, TQT_SLOT( slotEnableAction( const char *, bool ) ) );
  357. connect( ext, TQT_SIGNAL( setActionText( const char *, const TQString& ) ),
  358. this, TQT_SLOT( slotSetActionText( const char *, const TQString& ) ) );
  359. connect( ext, TQT_SIGNAL( moveTopLevelWidget( int, int ) ),
  360. this, TQT_SLOT( slotMoveTopLevelWidget( int, int ) ) );
  361. connect( ext, TQT_SIGNAL( resizeTopLevelWidget( int, int ) ),
  362. this, TQT_SLOT( slotResizeTopLevelWidget( int, int ) ) );
  363. connect( ext, TQT_SIGNAL( requestFocus(KParts::ReadOnlyPart *) ),
  364. this, TQT_SLOT( slotRequestFocus(KParts::ReadOnlyPart *) ) );
  365. if (service()->desktopEntryName() != "konq_sidebartng") {
  366. connect( ext, TQT_SIGNAL( infoMessage( const TQString & ) ),
  367. m_pKonqFrame->statusbar(), TQT_SLOT( message( const TQString & ) ) );
  368. connect( ext,
  369. TQT_SIGNAL( addWebSideBar(const KURL&, const TQString&) ),
  370. m_pMainWindow,
  371. TQT_SLOT( slotAddWebSideBar(const KURL&, const TQString&) ) );
  372. }
  373. callExtensionBoolMethod( "setSaveViewPropertiesLocally(bool)", m_pMainWindow->saveViewPropertiesLocally() );
  374. }
  375. TQVariant urlDropHandling;
  376. if ( ext )
  377. urlDropHandling = ext->property( "urlDropHandling" );
  378. else
  379. urlDropHandling = TQVariant( true, 0 );
  380. // Handle url drops if
  381. // a) either the property says "ok"
  382. // or
  383. // b) the part is a plain krop (no BE)
  384. m_bURLDropHandling = ( urlDropHandling.type() == TQVariant::Bool &&
  385. urlDropHandling.toBool() );
  386. m_pPart->widget()->installEventFilter( this );
  387. if (m_bBackRightClick && m_pPart->widget()->inherits(TQSCROLLVIEW_OBJECT_NAME_STRING) )
  388. {
  389. (static_cast<TQScrollView *>(m_pPart->widget()))->viewport()->installEventFilter( this );
  390. }
  391. // KonqDirPart signal
  392. if ( m_pPart->inherits("KonqDirPart") )
  393. {
  394. connect( m_pPart, TQT_SIGNAL( findOpen( KonqDirPart * ) ),
  395. m_pMainWindow, TQT_SLOT( slotFindOpen( KonqDirPart * ) ) );
  396. }
  397. }
  398. void KonqView::slotEnableAction( const char * name, bool enabled )
  399. {
  400. if ( m_pMainWindow->currentView() == this )
  401. m_pMainWindow->enableAction( name, enabled );
  402. // Otherwise, we don't have to do anything, the state of the action is
  403. // stored inside the browser-extension.
  404. }
  405. void KonqView::slotSetActionText( const char* name, const TQString& text )
  406. {
  407. if ( m_pMainWindow->currentView() == this )
  408. m_pMainWindow->setActionText( name, text );
  409. // Otherwise, we don't have to do anything, the state of the action is
  410. // stored inside the browser-extension.
  411. }
  412. void KonqView::slotMoveTopLevelWidget( int x, int y )
  413. {
  414. KonqFrameContainerBase* container = frame()->parentContainer();
  415. // If tabs are shown, only accept to move the whole window if there's only one tab.
  416. if ( container->frameType() != "Tabs" || static_cast<KonqFrameTabs*>(container)->count() == 1 )
  417. m_pMainWindow->move( x, y );
  418. }
  419. void KonqView::slotResizeTopLevelWidget( int w, int h )
  420. {
  421. KonqFrameContainerBase* container = frame()->parentContainer();
  422. // If tabs are shown, only accept to resize the whole window if there's only one tab.
  423. // ### Maybe we could store the size requested by each tab and resize the window to the biggest one.
  424. if ( container->frameType() != "Tabs" || static_cast<KonqFrameTabs*>(container)->count() == 1 )
  425. m_pMainWindow->resize( w, h );
  426. }
  427. void KonqView::slotStarted( TDEIO::Job * job )
  428. {
  429. //kdDebug(1202) << "KonqView::slotStarted" << job << endl;
  430. setLoading( true );
  431. if (job)
  432. {
  433. // Manage passwords properly...
  434. if (m_pMainWindow)
  435. {
  436. kdDebug(7035) << "slotStarted: Window ID = " << m_pMainWindow->topLevelWidget()->winId() << endl;
  437. job->setWindow (m_pMainWindow->topLevelWidget ());
  438. }
  439. connect( job, TQT_SIGNAL( percent( TDEIO::Job *, unsigned long ) ), this, TQT_SLOT( slotPercent( TDEIO::Job *, unsigned long ) ) );
  440. connect( job, TQT_SIGNAL( speed( TDEIO::Job *, unsigned long ) ), this, TQT_SLOT( slotSpeed( TDEIO::Job *, unsigned long ) ) );
  441. connect( job, TQT_SIGNAL( infoMessage( TDEIO::Job *, const TQString & ) ), this, TQT_SLOT( slotInfoMessage( TDEIO::Job *, const TQString & ) ) );
  442. }
  443. }
  444. void KonqView::slotRequestFocus( KParts::ReadOnlyPart * )
  445. {
  446. m_pMainWindow->viewManager()->showTab(this);
  447. }
  448. void KonqView::setLoading( bool loading, bool hasPending /*= false*/)
  449. {
  450. //kdDebug(1202) << "KonqView::setLoading loading=" << loading << " hasPending=" << hasPending << endl;
  451. m_bLoading = loading;
  452. m_bPendingRedirection = hasPending;
  453. if ( m_pMainWindow->currentView() == this )
  454. m_pMainWindow->updateToolBarActions( hasPending );
  455. m_pMainWindow->viewManager()->setLoading( this, loading || hasPending );
  456. }
  457. void KonqView::slotPercent( TDEIO::Job *, unsigned long percent )
  458. {
  459. m_pKonqFrame->statusbar()->slotLoadingProgress( percent );
  460. }
  461. void KonqView::slotSpeed( TDEIO::Job *, unsigned long bytesPerSecond )
  462. {
  463. m_pKonqFrame->statusbar()->slotSpeedProgress( bytesPerSecond );
  464. }
  465. void KonqView::slotInfoMessage( TDEIO::Job *, const TQString &msg )
  466. {
  467. m_pKonqFrame->statusbar()->message( msg );
  468. }
  469. void KonqView::slotCompleted()
  470. {
  471. slotCompleted( false );
  472. }
  473. void KonqView::slotCompleted( bool hasPending )
  474. {
  475. //kdDebug(1202) << "KonqView::slotCompleted hasPending=" << hasPending << endl;
  476. m_pKonqFrame->statusbar()->slotLoadingProgress( -1 );
  477. if ( ! m_bLockHistory )
  478. {
  479. // Success... update history entry, including location bar URL
  480. updateHistoryEntry( true );
  481. if ( m_bAborted ) // remove the pending entry on error
  482. KonqHistoryManager::kself()->removePending( url() );
  483. else if ( m_lstHistory.current() ) // register as proper history entry
  484. KonqHistoryManager::kself()->confirmPending(url(), typedURL(),
  485. m_lstHistory.current()->title);
  486. emit viewCompleted( this );
  487. }
  488. setLoading( false, hasPending );
  489. if (!m_bGotIconURL && !m_bAborted)
  490. {
  491. if ( KonqSettings::enableFavicon() == true )
  492. {
  493. // Try to get /favicon.ico
  494. if ( supportsServiceType( "text/html" ) && url().protocol().startsWith( "http" ) )
  495. KonqPixmapProvider::downloadHostIcon( url() );
  496. }
  497. }
  498. }
  499. void KonqView::slotCanceled( const TQString & errorMsg )
  500. {
  501. kdDebug(1202) << "KonqView::slotCanceled" << endl;
  502. // The errorMsg comes from the ReadOnlyPart's job.
  503. // It should probably be used in a KMessageBox
  504. // Let's use the statusbar for now
  505. m_pKonqFrame->statusbar()->message( errorMsg );
  506. m_bAborted = true;
  507. slotCompleted();
  508. }
  509. void KonqView::slotSelectionInfo( const KFileItemList &items )
  510. {
  511. KonqFileSelectionEvent ev( items, m_pPart );
  512. TQApplication::sendEvent( m_pMainWindow, &ev );
  513. }
  514. void KonqView::slotMouseOverInfo( const KFileItem *item )
  515. {
  516. KonqFileMouseOverEvent ev( item, m_pPart );
  517. TQApplication::sendEvent( m_pMainWindow, &ev );
  518. }
  519. void KonqView::setLocationBarURL( const KURL& locationBarURL )
  520. {
  521. setLocationBarURL( locationBarURL.pathOrURL() );
  522. }
  523. void KonqView::setLocationBarURL( const TQString & locationBarURL )
  524. {
  525. //kdDebug(1202) << "KonqView::setLocationBarURL " << locationBarURL << " this=" << this << endl;
  526. m_sLocationBarURL = locationBarURL;
  527. if ( m_pMainWindow->currentView() == this )
  528. {
  529. //kdDebug(1202) << "is current view " << this << endl;
  530. m_pMainWindow->setLocationBarURL( m_sLocationBarURL );
  531. m_pMainWindow->setPageSecurity( m_pageSecurity );
  532. }
  533. if (!m_bPassiveMode) setTabIcon( KURL::fromPathOrURL( m_sLocationBarURL ) );
  534. }
  535. void KonqView::setIconURL( const KURL & iconURL )
  536. // This function sets the favIcon in konqui's window if enabled,
  537. // thus it is responsible for the icon in the taskbar.
  538. // It does not set the tab's favIcon.
  539. {
  540. kdDebug(1202) << "entering KonqView::setIconURL" << endl;
  541. if ( KonqSettings::enableFavicon() )
  542. {
  543. KonqPixmapProvider::setIconForURL( KURL( m_sLocationBarURL ), iconURL );
  544. m_bGotIconURL = true;
  545. }
  546. }
  547. void KonqView::setPageSecurity( int pageSecurity )
  548. {
  549. m_pageSecurity = (KonqMainWindow::PageSecurity)pageSecurity;
  550. if ( m_pMainWindow->currentView() == this )
  551. m_pMainWindow->setPageSecurity( m_pageSecurity );
  552. }
  553. void KonqView::setTabIcon( const KURL &url )
  554. {
  555. if (!m_bPassiveMode) frame()->setTabIcon( url, 0L );
  556. }
  557. void KonqView::setCaption( const TQString & caption )
  558. {
  559. if (caption.isEmpty()) return;
  560. TQString adjustedCaption = caption;
  561. // For local URLs we prefer to use only the directory name
  562. if (url().isLocalFile())
  563. {
  564. // Is the caption a URL? If so, is it local? If so, only display the filename!
  565. KURL url = KURL::fromPathOrURL(caption);
  566. if (url.isValid() && url.isLocalFile() && url.fileName() == this->url().fileName())
  567. adjustedCaption = url.fileName();
  568. }
  569. m_caption = adjustedCaption;
  570. if (!m_bPassiveMode) frame()->setTitle( adjustedCaption , 0L );
  571. }
  572. void KonqView::slotOpenURLNotify()
  573. {
  574. #ifdef DEBUG_HISTORY
  575. kdDebug(1202) << "KonqView::slotOpenURLNotify" << endl;
  576. #endif
  577. updateHistoryEntry(true);
  578. createHistoryEntry();
  579. if ( m_pMainWindow->currentView() == this )
  580. m_pMainWindow->updateToolBarActions();
  581. }
  582. void KonqView::createHistoryEntry()
  583. {
  584. // First, remove any forward history
  585. HistoryEntry * current = m_lstHistory.current();
  586. if (current)
  587. {
  588. #ifdef DEBUG_HISTORY
  589. kdDebug(1202) << "Truncating history" << endl;
  590. #endif
  591. m_lstHistory.at( m_lstHistory.count() - 1 ); // go to last one
  592. for ( ; m_lstHistory.current() != current ; )
  593. {
  594. if ( !m_lstHistory.removeLast() ) // and remove from the end (faster and easier)
  595. assert(0);
  596. // go to last one. The documentation says that removeLast()
  597. // makes current() null if it's the last item. however in qt2
  598. // the behaviour was different than the documentation. this is
  599. // changed in qt3 to behave as documented ;-) (Simon)
  600. m_lstHistory.at( m_lstHistory.count() - 1 );
  601. }
  602. // Now current is the current again.
  603. }
  604. // Append a new entry
  605. #ifdef DEBUG_HISTORY
  606. kdDebug(1202) << "Append a new entry" << endl;
  607. #endif
  608. m_lstHistory.append( new HistoryEntry ); // made current
  609. #ifdef DEBUG_HISTORY
  610. kdDebug(1202) << "at=" << m_lstHistory.at() << " count=" << m_lstHistory.count() << endl;
  611. #endif
  612. assert( m_lstHistory.at() == (int) m_lstHistory.count() - 1 );
  613. }
  614. void KonqView::updateHistoryEntry( bool saveLocationBarURL )
  615. {
  616. Q_ASSERT( !m_bLockHistory ); // should never happen
  617. HistoryEntry * current = m_lstHistory.current();
  618. if ( !current )
  619. return;
  620. if ( browserExtension() )
  621. {
  622. current->buffer = TQByteArray(); // Start with empty buffer.
  623. TQDataStream stream( current->buffer, IO_WriteOnly );
  624. browserExtension()->saveState( stream );
  625. }
  626. #ifdef DEBUG_HISTORY
  627. kdDebug(1202) << "Saving part URL : " << m_pPart->url() << " in history position " << m_lstHistory.at() << endl;
  628. #endif
  629. current->url = m_pPart->url();
  630. if (saveLocationBarURL)
  631. {
  632. #ifdef DEBUG_HISTORY
  633. kdDebug(1202) << "Saving location bar URL : " << m_sLocationBarURL << " in history position " << m_lstHistory.at() << endl;
  634. #endif
  635. current->locationBarURL = m_sLocationBarURL;
  636. current->pageSecurity = m_pageSecurity;
  637. }
  638. #ifdef DEBUG_HISTORY
  639. kdDebug(1202) << "Saving title : " << m_caption << " in history position " << m_lstHistory.at() << endl;
  640. #endif
  641. current->title = m_caption;
  642. current->strServiceType = m_serviceType;
  643. current->strServiceName = m_service->desktopEntryName();
  644. current->doPost = m_doPost;
  645. current->postData = m_doPost ? m_postData : TQByteArray();
  646. current->postContentType = m_doPost ? m_postContentType : TQString::null;
  647. current->pageReferrer = m_pageReferrer;
  648. }
  649. void KonqView::goHistory( int steps )
  650. {
  651. // This is called by KonqBrowserInterface
  652. if ( m_pMainWindow->currentView() == this )
  653. m_pMainWindow->viewManager()->setActivePart( part() );
  654. // Delay the go() call (we need to return to the caller first)
  655. m_pMainWindow->slotGoHistoryActivated( steps );
  656. }
  657. void KonqView::go( int steps )
  658. {
  659. if ( !steps ) // [WildFox] i bet there are sites on the net with stupid devs who do that :)
  660. {
  661. #ifdef DEBUG_HISTORY
  662. kdDebug(1202) << "KonqView::go(0)" << endl;
  663. #endif
  664. // [David] and you're right. And they expect that it reloads, apparently.
  665. // [George] I'm going to make nspluginviewer rely on this too. :-)
  666. m_pMainWindow->slotReload();
  667. return;
  668. }
  669. int newPos = m_lstHistory.at() + steps;
  670. #ifdef DEBUG_HISTORY
  671. kdDebug(1202) << "go : steps=" << steps
  672. << " newPos=" << newPos
  673. << " m_lstHistory.count()=" << m_lstHistory.count()
  674. << endl;
  675. #endif
  676. if( newPos < 0 || (uint)newPos >= m_lstHistory.count() )
  677. return;
  678. stop();
  679. // Yay, we can move there without a loop !
  680. HistoryEntry *currentHistoryEntry = m_lstHistory.at( newPos ); // sets current item
  681. assert( currentHistoryEntry );
  682. assert( newPos == m_lstHistory.at() ); // check we moved (i.e. if I understood the docu)
  683. assert( currentHistoryEntry == m_lstHistory.current() );
  684. #ifdef DEBUG_HISTORY
  685. kdDebug(1202) << "New position " << m_lstHistory.at() << endl;
  686. #endif
  687. restoreHistory();
  688. }
  689. void KonqView::restoreHistory()
  690. {
  691. HistoryEntry h( *(m_lstHistory.current()) ); // make a copy of the current history entry, as the data
  692. // the pointer points to will change with the following calls
  693. #ifdef DEBUG_HISTORY
  694. kdDebug(1202) << "Restoring servicetype/name, and location bar URL from history : " << h.locationBarURL << endl;
  695. #endif
  696. setLocationBarURL( h.locationBarURL );
  697. setPageSecurity( h.pageSecurity );
  698. m_sTypedURL = TQString::null;
  699. if ( ! changeViewMode( h.strServiceType, h.strServiceName ) )
  700. {
  701. kdWarning(1202) << "Couldn't change view mode to " << h.strServiceType
  702. << " " << h.strServiceName << endl;
  703. return /*false*/;
  704. }
  705. setServiceTypeInExtension();
  706. aboutToOpenURL( h.url );
  707. if ( browserExtension() )
  708. {
  709. //kdDebug(1202) << "Restoring view from stream" << endl;
  710. TQDataStream stream( h.buffer, IO_ReadOnly );
  711. browserExtension()->restoreState( stream );
  712. m_doPost = h.doPost;
  713. m_postContentType = h.postContentType;
  714. m_postData = h.postData;
  715. m_pageReferrer = h.pageReferrer;
  716. }
  717. else
  718. m_pPart->openURL( h.url );
  719. if ( m_pMainWindow->currentView() == this )
  720. m_pMainWindow->updateToolBarActions();
  721. #ifdef DEBUG_HISTORY
  722. kdDebug(1202) << "New position (2) " << m_lstHistory.at() << endl;
  723. #endif
  724. }
  725. const HistoryEntry * KonqView::historyAt(const int pos)
  726. {
  727. if(pos<0 || pos>=(int)m_lstHistory.count())
  728. return 0L;
  729. int oldpos = m_lstHistory.at();
  730. const HistoryEntry* h = m_lstHistory.at(pos);
  731. m_lstHistory.at( oldpos );
  732. return h;
  733. }
  734. void KonqView::copyHistory( KonqView *other )
  735. {
  736. m_lstHistory.clear();
  737. TQPtrListIterator<HistoryEntry> it( other->m_lstHistory );
  738. for (; it.current(); ++it )
  739. m_lstHistory.append( new HistoryEntry( *it.current() ) );
  740. m_lstHistory.at(other->m_lstHistory.at());
  741. }
  742. KURL KonqView::url() const
  743. {
  744. assert( m_pPart );
  745. return m_pPart->url();
  746. }
  747. KURL KonqView::upURL() const
  748. {
  749. KURL currentURL;
  750. if ( m_pRun )
  751. currentURL = m_pRun->url();
  752. else
  753. currentURL = KURL::fromPathOrURL( m_sLocationBarURL );
  754. return currentURL.upURL();
  755. }
  756. void KonqView::setRun( KonqRun * run )
  757. {
  758. if ( m_pRun )
  759. {
  760. // Tell the KonqRun to abort, but don't delete it ourselves.
  761. // It could be showing a message box right now. It will delete itself anyway.
  762. m_pRun->abort();
  763. // finish() will be emitted later (when back to event loop)
  764. // and we don't want it to call slotRunFinished (which stops the animation and stop button).
  765. m_pRun->disconnect( m_pMainWindow );
  766. if ( !run )
  767. frame()->unsetCursor();
  768. }
  769. else if ( run )
  770. frame()->setCursor( KCursor::workingCursor() );
  771. m_pRun = run;
  772. }
  773. void KonqView::stop()
  774. {
  775. //kdDebug(1202) << "KonqView::stop()" << endl;
  776. m_bAborted = false;
  777. finishedWithCurrentURL();
  778. if ( m_bLoading || m_bPendingRedirection )
  779. {
  780. // aborted -> confirm the pending url. We might as well remove it, but
  781. // we decided to keep it :)
  782. KonqHistoryManager::kself()->confirmPending( url(), m_sTypedURL );
  783. //kdDebug(1202) << "m_pPart->closeURL()" << endl;
  784. m_pPart->closeURL();
  785. m_bAborted = true;
  786. m_pKonqFrame->statusbar()->slotLoadingProgress( -1 );
  787. setLoading( false, false );
  788. }
  789. if ( m_pRun )
  790. {
  791. // Revert to working URL - unless the URL was typed manually
  792. // This is duplicated with KonqMainWindow::slotRunFinished, but we can't call it
  793. // since it relies on sender()...
  794. if ( history().current() && m_pRun->typedURL().isEmpty() ) { // not typed
  795. setLocationBarURL( history().current()->locationBarURL );
  796. setPageSecurity( history().current()->pageSecurity );
  797. }
  798. setRun( 0L );
  799. m_pKonqFrame->statusbar()->slotLoadingProgress( -1 );
  800. }
  801. if ( !m_bLockHistory && m_lstHistory.count() > 0 )
  802. updateHistoryEntry(true);
  803. }
  804. void KonqView::finishedWithCurrentURL()
  805. {
  806. if ( !m_tempFile.isEmpty() )
  807. {
  808. kdDebug(1202) << "######### Deleting tempfile after use:" << m_tempFile << endl;
  809. TQFile::remove( m_tempFile );
  810. m_tempFile = TQString::null;
  811. }
  812. }
  813. void KonqView::setPassiveMode( bool mode )
  814. {
  815. // In theory, if m_bPassiveMode is true and mode is false,
  816. // the part should be removed from the part manager,
  817. // and if the other way round, it should be readded to the part manager...
  818. m_bPassiveMode = mode;
  819. if ( mode && m_pMainWindow->viewCount() > 1 && m_pMainWindow->currentView() == this )
  820. {
  821. KParts::Part * part = m_pMainWindow->viewManager()->chooseNextView( this )->part(); // switch active part
  822. m_pMainWindow->viewManager()->setActivePart( part );
  823. }
  824. // Update statusbar stuff
  825. m_pMainWindow->viewManager()->viewCountChanged();
  826. }
  827. void KonqView::setHierarchicalView( bool mode )
  828. {
  829. m_bHierarchicalView=mode;
  830. }
  831. void KonqView::setLinkedView( bool mode )
  832. {
  833. m_bLinkedView = mode;
  834. if ( m_pMainWindow->currentView() == this )
  835. m_pMainWindow->linkViewAction()->setChecked( mode );
  836. frame()->statusbar()->setLinkedView( mode );
  837. }
  838. void KonqView::setLockedLocation( bool b )
  839. {
  840. m_bLockedLocation = b;
  841. }
  842. void KonqView::aboutToOpenURL( const KURL &url, const KParts::URLArgs &args )
  843. {
  844. KParts::OpenURLEvent ev( m_pPart, url, args );
  845. TQApplication::sendEvent( m_pMainWindow, &ev );
  846. m_bGotIconURL = false;
  847. m_bAborted = false;
  848. }
  849. void KonqView::setServiceTypeInExtension()
  850. {
  851. KParts::BrowserExtension *ext = browserExtension();
  852. if ( !ext )
  853. return;
  854. KParts::URLArgs args( ext->urlArgs() );
  855. args.serviceType = m_serviceType;
  856. ext->setURLArgs( args );
  857. }
  858. TQStringList KonqView::frameNames() const
  859. {
  860. return childFrameNames( m_pPart );
  861. }
  862. TQStringList KonqView::childFrameNames( KParts::ReadOnlyPart *part )
  863. {
  864. TQStringList res;
  865. KParts::BrowserHostExtension *hostExtension = KParts::BrowserHostExtension::childObject( part );
  866. if ( !hostExtension )
  867. return res;
  868. res += hostExtension->frameNames();
  869. const TQPtrList<KParts::ReadOnlyPart> children = hostExtension->frames();
  870. TQPtrListIterator<KParts::ReadOnlyPart> it( children );
  871. for (; it.current(); ++it )
  872. res += childFrameNames( it.current() );
  873. return res;
  874. }
  875. KParts::BrowserHostExtension* KonqView::hostExtension( KParts::ReadOnlyPart *part, const TQString &name )
  876. {
  877. KParts::BrowserHostExtension *ext = KParts::BrowserHostExtension::childObject( part );
  878. if ( !ext )
  879. return 0;
  880. if ( ext->frameNames().contains( name ) )
  881. return ext;
  882. const TQPtrList<KParts::ReadOnlyPart> children = ext->frames();
  883. TQPtrListIterator<KParts::ReadOnlyPart> it( children );
  884. for (; it.current(); ++it )
  885. {
  886. KParts::BrowserHostExtension *childHost = hostExtension( it.current(), name );
  887. if ( childHost )
  888. return childHost;
  889. }
  890. return 0;
  891. }
  892. bool KonqView::callExtensionMethod( const char *methodName )
  893. {
  894. TQObject *obj = KParts::BrowserExtension::childObject( m_pPart );
  895. if ( !obj ) // not all views have a browser extension !
  896. return false;
  897. int id = obj->metaObject()->findSlot( methodName );
  898. if ( id == -1 )
  899. return false;
  900. TQUObject o[ 1 ];
  901. obj->tqt_invoke( id, o );
  902. return true;
  903. }
  904. bool KonqView::callExtensionBoolMethod( const char *methodName, bool value )
  905. {
  906. TQObject *obj = KParts::BrowserExtension::childObject( m_pPart );
  907. if ( !obj ) // not all views have a browser extension !
  908. return false;
  909. int id = obj->metaObject()->findSlot( methodName );
  910. if ( id == -1 )
  911. return false;
  912. TQUObject o[ 2 ];
  913. static_TQUType_bool.set( o + 1, value );
  914. obj->tqt_invoke( id, o );
  915. return true;
  916. }
  917. bool KonqView::callExtensionStringMethod( const char *methodName, TQString value )
  918. {
  919. TQObject *obj = KParts::BrowserExtension::childObject( m_pPart );
  920. if ( !obj ) // not all views have a browser extension !
  921. return false;
  922. int id = obj->metaObject()->findSlot( methodName );
  923. if ( id == -1 )
  924. return false;
  925. TQUObject o[ 2 ];
  926. static_TQUType_TQString.set( o + 1, value );
  927. obj->tqt_invoke( id, o );
  928. return true;
  929. }
  930. bool KonqView::callExtensionURLMethod( const char *methodName, const KURL& value )
  931. {
  932. TQObject *obj = KParts::BrowserExtension::childObject( m_pPart );
  933. if ( !obj ) // not all views have a browser extension !
  934. return false;
  935. int id = obj->metaObject()->findSlot( methodName );
  936. if ( id == -1 )
  937. return false;
  938. TQUObject o[ 2 ];
  939. static_TQUType_ptr.set( o + 1, &value );
  940. obj->tqt_invoke( id, o );
  941. return true;
  942. }
  943. void KonqView::setViewName( const TQString &name )
  944. {
  945. //kdDebug() << "KonqView::setViewName this=" << this << " name=" << name << endl;
  946. if ( m_pPart )
  947. m_pPart->setName( name.local8Bit().data() );
  948. }
  949. TQString KonqView::viewName() const
  950. {
  951. return m_pPart ? TQString::fromLocal8Bit( m_pPart->name() ) : TQString();
  952. }
  953. void KonqView::enablePopupMenu( bool b )
  954. {
  955. Q_ASSERT( m_pMainWindow );
  956. KParts::BrowserExtension *ext = browserExtension();
  957. if ( !ext )
  958. return;
  959. if ( m_bPopupMenuEnabled == b )
  960. return;
  961. // enable context popup
  962. if ( b ) {
  963. m_bPopupMenuEnabled = true;
  964. connect( ext, TQT_SIGNAL( popupMenu( const TQPoint &, const KFileItemList & ) ),
  965. m_pMainWindow, TQT_SLOT( slotPopupMenu( const TQPoint &, const KFileItemList & ) ) );
  966. connect( ext, TQT_SIGNAL( popupMenu( const TQPoint &, const KURL &, const TQString &, mode_t ) ),
  967. m_pMainWindow, TQT_SLOT( slotPopupMenu( const TQPoint &, const KURL &, const TQString &, mode_t ) ) );
  968. connect( ext, TQT_SIGNAL( popupMenu( KXMLGUIClient *, const TQPoint &, const KFileItemList & ) ),
  969. m_pMainWindow, TQT_SLOT( slotPopupMenu( KXMLGUIClient *, const TQPoint &, const KFileItemList & ) ) );
  970. connect( ext, TQT_SIGNAL( popupMenu( KXMLGUIClient *, const TQPoint &, const KFileItemList &, const KParts::URLArgs &, KParts::BrowserExtension::PopupFlags ) ),
  971. m_pMainWindow, TQT_SLOT( slotPopupMenu( KXMLGUIClient *, const TQPoint &, const KFileItemList &, const KParts::URLArgs &, KParts::BrowserExtension::PopupFlags ) ) );
  972. connect( ext, TQT_SIGNAL( popupMenu( KXMLGUIClient *, const TQPoint &, const KURL &, const TQString &, mode_t ) ),
  973. m_pMainWindow, TQT_SLOT( slotPopupMenu( KXMLGUIClient *, const TQPoint &, const KURL &, const TQString &, mode_t ) ) );
  974. connect( ext, TQT_SIGNAL( popupMenu( KXMLGUIClient *, const TQPoint &, const KURL &, const KParts::URLArgs &, KParts::BrowserExtension::PopupFlags, mode_t ) ),
  975. m_pMainWindow, TQT_SLOT( slotPopupMenu( KXMLGUIClient *, const TQPoint &, const KURL &, const KParts::URLArgs &, KParts::BrowserExtension::PopupFlags, mode_t ) ) );
  976. }
  977. else // disable context popup
  978. {
  979. m_bPopupMenuEnabled = false;
  980. disconnect( ext, TQT_SIGNAL( popupMenu( const TQPoint &, const KFileItemList & ) ),
  981. m_pMainWindow, TQT_SLOT( slotPopupMenu( const TQPoint &, const KFileItemList & ) ) );
  982. disconnect( ext, TQT_SIGNAL( popupMenu( const TQPoint &, const KURL &, const TQString &, mode_t ) ),
  983. m_pMainWindow, TQT_SLOT( slotPopupMenu( const TQPoint &, const KURL &, const TQString &, mode_t ) ) );
  984. disconnect( ext, TQT_SIGNAL( popupMenu( KXMLGUIClient *, const TQPoint &, const KFileItemList & ) ),
  985. m_pMainWindow, TQT_SLOT( slotPopupMenu( KXMLGUIClient *, const TQPoint &, const KFileItemList & ) ) );
  986. disconnect( ext, TQT_SIGNAL( popupMenu( KXMLGUIClient *, const TQPoint &, const KURL &, const TQString &, mode_t ) ),
  987. m_pMainWindow, TQT_SLOT( slotPopupMenu( KXMLGUIClient *, const TQPoint &, const KURL &, const TQString &, mode_t ) ) );
  988. }
  989. enableBackRightClick( m_bBackRightClick );
  990. }
  991. // caller should ensure that this is called only when b changed, or for new parts
  992. void KonqView::enableBackRightClick( bool b )
  993. {
  994. m_bBackRightClick = b;
  995. if ( b )
  996. connect( this, TQT_SIGNAL( backRightClick() ),
  997. m_pMainWindow, TQT_SLOT( slotBack() ) );
  998. else
  999. disconnect( this, TQT_SIGNAL( backRightClick() ),
  1000. m_pMainWindow, TQT_SLOT( slotBack() ) );
  1001. }
  1002. void KonqView::reparseConfiguration()
  1003. {
  1004. callExtensionMethod( "reparseConfiguration()" );
  1005. bool b = KonqSettings::backRightClick();
  1006. if ( m_bBackRightClick != b )
  1007. {
  1008. if (m_bBackRightClick && m_pPart->widget()->inherits(TQSCROLLVIEW_OBJECT_NAME_STRING) )
  1009. {
  1010. (static_cast<TQScrollView *>(m_pPart->widget()))->viewport()->installEventFilter( this );
  1011. }
  1012. enableBackRightClick( b );
  1013. }
  1014. }
  1015. void KonqView::disableScrolling()
  1016. {
  1017. m_bDisableScrolling = true;
  1018. callExtensionMethod( "disableScrolling()" );
  1019. }
  1020. KonqViewIface * KonqView::dcopObject()
  1021. {
  1022. if ( !m_dcopObject ) {
  1023. TQCString dcopName = name();
  1024. if ( dcopName.isEmpty() || dcopName == "unnamed" )
  1025. dcopName = viewName().utf8();
  1026. if ( dcopName.isEmpty() || dcopName == "unnamed" ) {
  1027. TQVariant dcopProperty = part()->property( "dcopObjectId" );
  1028. if ( dcopProperty.type() == TQVariant::CString )
  1029. dcopName = dcopProperty.toCString();
  1030. }
  1031. dcopName += "-view"; // to avoid having the same name as the part
  1032. m_dcopObject = new KonqViewIface( this, dcopName );
  1033. }
  1034. return m_dcopObject;
  1035. }
  1036. bool KonqView::eventFilter( TQObject *obj, TQEvent *e )
  1037. {
  1038. if ( !m_pPart )
  1039. return false;
  1040. // kdDebug() << "--" << obj->className() << "--" << e->type() << "--" << endl;
  1041. if ( e->type() == TQEvent::DragEnter && m_bURLDropHandling && TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(m_pPart->widget()) )
  1042. {
  1043. TQDragEnterEvent *ev = static_cast<TQDragEnterEvent *>( e );
  1044. if ( KURLDrag::canDecode( ev ) )
  1045. {
  1046. KURL::List lstDragURLs;
  1047. bool ok = KURLDrag::decode( ev, lstDragURLs );
  1048. TQObjectList *children = m_pPart->widget()->queryList( TQWIDGET_OBJECT_NAME_STRING );
  1049. if ( ok &&
  1050. !lstDragURLs.first().url().contains( "javascript:", false ) && // ### this looks like a hack to me
  1051. ev->source() != m_pPart->widget() &&
  1052. children &&
  1053. children->findRef( TQT_TQOBJECT(ev->source()) ) == -1 )
  1054. ev->acceptAction();
  1055. delete children;
  1056. }
  1057. }
  1058. else if ( e->type() == TQEvent::Drop && m_bURLDropHandling && TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(m_pPart->widget()) )
  1059. {
  1060. TQDropEvent *ev = static_cast<TQDropEvent *>( e );
  1061. KURL::List lstDragURLs;
  1062. bool ok = KURLDrag::decode( ev, lstDragURLs );
  1063. KParts::BrowserExtension *ext = browserExtension();
  1064. if ( ok && ext && lstDragURLs.first().isValid() )
  1065. emit ext->openURLRequest( lstDragURLs.first() ); // this will call m_pMainWindow::slotOpenURLRequest delayed
  1066. }
  1067. if ( m_bBackRightClick )
  1068. {
  1069. if ( e->type() == TQEvent::ContextMenu )
  1070. {
  1071. TQContextMenuEvent *ev = TQT_TQCONTEXTMENUEVENT( e );
  1072. if ( ev->reason() == TQContextMenuEvent::Mouse )
  1073. {
  1074. return true;
  1075. }
  1076. }
  1077. else if ( e->type() == TQEvent::MouseButtonPress )
  1078. {
  1079. TQMouseEvent *ev = TQT_TQMOUSEEVENT( e );
  1080. if ( ev->button() == Qt::RightButton )
  1081. {
  1082. return true;
  1083. }
  1084. }
  1085. else if ( e->type() == TQEvent::MouseButtonRelease )
  1086. {
  1087. TQMouseEvent *ev = TQT_TQMOUSEEVENT( e );
  1088. if ( ev->button() == Qt::RightButton )
  1089. {
  1090. emit backRightClick();
  1091. return true;
  1092. }
  1093. }
  1094. else if ( e->type() == TQEvent::MouseMove )
  1095. {
  1096. TQMouseEvent *ev = TQT_TQMOUSEEVENT( e );
  1097. if ( ev->state() == Qt::RightButton )
  1098. {
  1099. obj->removeEventFilter( this );
  1100. TQMouseEvent me( TQEvent::MouseButtonPress, ev->pos(), 2, 2 );
  1101. TQApplication::sendEvent( obj, &me );
  1102. TQContextMenuEvent ce( TQContextMenuEvent::Mouse, ev->pos(), 2 );
  1103. TQApplication::sendEvent( obj, &ce );
  1104. obj->installEventFilter( this );
  1105. return true;
  1106. }
  1107. }
  1108. }
  1109. if ( e->type() == TQEvent::FocusIn )
  1110. {
  1111. setActiveInstance();
  1112. }
  1113. return false;
  1114. }
  1115. void KonqView::setActiveInstance()
  1116. {
  1117. if ( m_bBuiltinView || !m_pPart->instance() /*never!*/)
  1118. TDEGlobal::_activeInstance = TDEGlobal::instance();
  1119. else
  1120. TDEGlobal::_activeInstance = m_pPart->instance();
  1121. }
  1122. bool KonqView::prepareReload( KParts::URLArgs& args )
  1123. {
  1124. args.reload = true;
  1125. // Repost form data if this URL is the result of a POST HTML form.
  1126. if ( m_doPost && !args.redirectedRequest() )
  1127. {
  1128. if ( KMessageBox::warningContinueCancel( 0, i18n(
  1129. "The page you are trying to view is the result of posted form data. "
  1130. "If you resend the data, any action the form carried out (such as search or online purchase) will be repeated. "),
  1131. i18n( "Warning" ), i18n( "Resend" ) ) == KMessageBox::Continue )
  1132. {
  1133. args.setDoPost( true );
  1134. args.setContentType( m_postContentType );
  1135. args.postData = m_postData;
  1136. }
  1137. else
  1138. return false;
  1139. }
  1140. // Re-set referrer
  1141. args.metaData()["referrer"] = m_pageReferrer;
  1142. return true;
  1143. }
  1144. KParts::BrowserExtension * KonqView::browserExtension() const
  1145. {
  1146. return KParts::BrowserExtension::childObject( m_pPart );
  1147. }
  1148. KParts::StatusBarExtension * KonqView::statusBarExtension() const
  1149. {
  1150. return KParts::StatusBarExtension::childObject( m_pPart );
  1151. }
  1152. bool KonqView::supportsServiceType( const TQString &serviceType ) const
  1153. {
  1154. const TQStringList lst = serviceTypes();
  1155. for( TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
  1156. if ( *it == serviceType )
  1157. return true;
  1158. // Maybe we should keep around a list of KServiceType::Ptr?
  1159. KMimeType::Ptr mime = KMimeType::mimeType( *it );
  1160. if ( mime && mime->is( serviceType ) ) // respect inheritance
  1161. return true;
  1162. }
  1163. return false;
  1164. }
  1165. #include "konq_view.moc"