TDE base libraries and programs
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_viewmgr.cc 63KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843
  1. // -*- mode: c++; c-basic-offset: 2 -*-
  2. /* This file is part of the KDE project
  3. Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (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
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. */
  16. #include "konq_viewmgr.h"
  17. #include "konq_view.h"
  18. #include "konq_frame.h"
  19. #include "konq_tabs.h"
  20. #include "konq_profiledlg.h"
  21. #include "konq_events.h"
  22. #include "konq_settingsxt.h"
  23. #include <tqfileinfo.h>
  24. #include <tqptrlist.h>
  25. #include <tdeaccelgen.h>
  26. #include <kstandarddirs.h>
  27. #include <kdebug.h>
  28. #include <tdeapplication.h>
  29. #include <tdeglobalsettings.h>
  30. #include <tdetempfile.h>
  31. #include <dcopclient.h>
  32. #include <tdelocale.h>
  33. #include <tdemessagebox.h>
  34. #include <assert.h>
  35. #include <tdepopupmenu.h>
  36. // #define DEBUG_VIEWMGR
  37. template class TQPtrList<KonqView>;
  38. KonqViewManager::KonqViewManager( KonqMainWindow *mainWindow )
  39. : KParts::PartManager( mainWindow )
  40. {
  41. m_pMainWindow = mainWindow;
  42. m_pDocContainer = 0L;
  43. m_pamProfiles = 0L;
  44. m_bProfileListDirty = true;
  45. m_bLoadingProfile = false;
  46. m_activePartChangedTimer = new TQTimer(this);
  47. connect(m_activePartChangedTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(emitActivePartChanged()));
  48. connect( this, TQT_SIGNAL( activePartChanged ( KParts::Part * ) ), this, TQT_SLOT( slotActivePartChanged ( KParts::Part * ) ) );
  49. }
  50. KonqView* KonqViewManager::Initialize( const TQString &serviceType, const TQString &serviceName )
  51. {
  52. //kdDebug(1202) << "KonqViewManager::Initialize()" << endl;
  53. KService::Ptr service;
  54. TDETrader::OfferList partServiceOffers, appServiceOffers;
  55. KonqViewFactory newViewFactory = createView( serviceType, serviceName, service, partServiceOffers, appServiceOffers, true /*forceAutoEmbed*/ );
  56. if ( newViewFactory.isNull() )
  57. {
  58. kdDebug(1202) << "KonqViewManager::Initialize() No suitable factory found." << endl;
  59. return 0;
  60. }
  61. KonqView* childView = setupView( m_pMainWindow, newViewFactory, service, partServiceOffers, appServiceOffers, serviceType, false );
  62. setActivePart( childView->part() );
  63. m_pDocContainer = childView->frame();
  64. convertDocContainer();
  65. static_cast<KonqFrameTabs*>( m_pDocContainer )->setAlwaysTabbedMode(KonqSettings::alwaysTabbedMode());
  66. static_cast<KonqFrameTabs*>( m_pDocContainer )->setMouseWheelScroll(KonqSettings::tabsCycleWheel());
  67. m_pDocContainer->widget()->show();
  68. return childView;
  69. }
  70. KonqViewManager::~KonqViewManager()
  71. {
  72. //kdDebug(1202) << "KonqViewManager::~KonqViewManager()" << endl;
  73. clear();
  74. }
  75. KonqView* KonqViewManager::splitView ( Qt::Orientation orientation,
  76. const TQString &serviceType,
  77. const TQString &serviceName,
  78. bool newOneFirst, bool forceAutoEmbed )
  79. {
  80. #ifdef DEBUG_VIEWMGR
  81. kdDebug(1202) << "KonqViewManager::splitView(ServiceType)" << endl;
  82. m_pMainWindow->dumpViewList();
  83. printFullHierarchy( m_pMainWindow );
  84. #endif
  85. KonqFrame* splitFrame = m_pMainWindow->currentView()->frame();
  86. KService::Ptr service;
  87. TDETrader::OfferList partServiceOffers, appServiceOffers;
  88. KonqViewFactory newViewFactory = createView( serviceType, serviceName, service, partServiceOffers, appServiceOffers, forceAutoEmbed );
  89. if( newViewFactory.isNull() )
  90. return 0L; //do not split at all if we can't create the new view
  91. assert( splitFrame );
  92. KonqFrameContainerBase* parentContainer = splitFrame->parentContainer();
  93. bool moveNewContainer = false;
  94. TQValueList<int> splitterSizes;
  95. int index= -1;
  96. if (parentContainer->frameType()=="Container") {
  97. moveNewContainer = (static_cast<KonqFrameContainer*>(parentContainer)->idAfter( splitFrame->widget() ) != 0);
  98. splitterSizes = static_cast<KonqFrameContainer*>(parentContainer)->sizes();
  99. }
  100. else if (parentContainer->frameType()=="Tabs")
  101. index = static_cast<KonqFrameTabs*>(parentContainer)->indexOf( splitFrame->widget() );
  102. #ifndef NDEBUG
  103. //printSizeInfo( splitFrame, parentContainer, "before split");
  104. #endif
  105. parentContainer->widget()->setUpdatesEnabled( false );
  106. //kdDebug(1202) << "Move out child" << endl;
  107. TQPoint pos = splitFrame->widget()->pos();
  108. parentContainer->removeChildFrame( splitFrame );
  109. splitFrame->widget()->reparent( m_pMainWindow, pos );
  110. //kdDebug(1202) << "Create new Container" << endl;
  111. KonqFrameContainer *newContainer = new KonqFrameContainer( orientation, parentContainer->widget(), parentContainer );
  112. connect(newContainer,TQT_SIGNAL(ctrlTabPressed()),m_pMainWindow,TQT_SLOT(slotCtrlTabPressed()));
  113. parentContainer->insertChildFrame( newContainer, index );
  114. if ( moveNewContainer ) {
  115. static_cast<KonqFrameContainer*>(parentContainer)->moveToFirst( newContainer );
  116. static_cast<KonqFrameContainer*>(parentContainer)->swapChildren();
  117. }
  118. //kdDebug(1202) << "Move in child" << endl;
  119. splitFrame->widget()->reparent( newContainer, pos );
  120. newContainer->insertChildFrame( splitFrame );
  121. #ifndef NDEBUG
  122. //printSizeInfo( splitFrame, parentContainer, "after reparent" );
  123. #endif
  124. //kdDebug(1202) << "Create new child" << endl;
  125. KonqView *newView = setupView( newContainer, newViewFactory, service, partServiceOffers, appServiceOffers, serviceType, false );
  126. #ifndef DEBUG
  127. //printSizeInfo( splitFrame, parentContainer, "after child insert" );
  128. #endif
  129. if ( newOneFirst )
  130. {
  131. newContainer->moveToLast( splitFrame->widget() );
  132. newContainer->swapChildren();
  133. }
  134. TQValueList<int> newSplitterSizes;
  135. newSplitterSizes << 50 << 50;
  136. newContainer->setSizes( newSplitterSizes );
  137. if (parentContainer->frameType()=="Container") {
  138. static_cast<KonqFrameContainer*>(parentContainer)->setSizes( splitterSizes );
  139. }
  140. else if (parentContainer->frameType()=="Tabs")
  141. static_cast<KonqFrameTabs*>(parentContainer)->showPage( newContainer );
  142. splitFrame->show();
  143. //newView->frame()->show();
  144. newContainer->show();
  145. parentContainer->widget()->setUpdatesEnabled( true );
  146. if (m_pDocContainer == splitFrame) m_pDocContainer = newContainer;
  147. assert( newView->frame() );
  148. assert( newView->part() );
  149. newContainer->setActiveChild( newView->frame() );
  150. setActivePart( newView->part(), false );
  151. #ifdef DEBUG_VIEWMGR
  152. m_pMainWindow->dumpViewList();
  153. printFullHierarchy( m_pMainWindow );
  154. kdDebug(1202) << "KonqViewManager::splitView(ServiceType) done" << endl;
  155. #endif
  156. return newView;
  157. }
  158. KonqView* KonqViewManager::splitWindow( Qt::Orientation orientation,
  159. const TQString &serviceType,
  160. const TQString &serviceName,
  161. bool newOneFirst )
  162. {
  163. kdDebug(1202) << "KonqViewManager::splitWindow(default)" << endl;
  164. // Don't crash when doing things too quickly.
  165. if (!m_pMainWindow || !m_pMainWindow->currentView())
  166. return 0L;
  167. KURL url = m_pMainWindow->currentView()->url();
  168. TQString locationBarURL = m_pMainWindow->currentView()->locationBarURL();
  169. KService::Ptr service;
  170. TDETrader::OfferList partServiceOffers, appServiceOffers;
  171. KonqViewFactory newViewFactory = createView( serviceType, serviceName, service, partServiceOffers, appServiceOffers );
  172. if( newViewFactory.isNull() )
  173. return 0L; //do not split at all if we can't create the new view
  174. KonqFrameBase* mainFrame = m_pMainWindow->childFrame();
  175. mainFrame->widget()->setUpdatesEnabled( false );
  176. //kdDebug(1202) << "Move out child" << endl;
  177. TQPoint pos = mainFrame->widget()->pos();
  178. m_pMainWindow->removeChildFrame( mainFrame );
  179. KonqFrameContainer *newContainer = new KonqFrameContainer( orientation, m_pMainWindow, 0L);
  180. connect(newContainer,TQT_SIGNAL(ctrlTabPressed()),m_pMainWindow,TQT_SLOT(slotCtrlTabPressed()));
  181. m_pMainWindow->insertChildFrame( newContainer );
  182. newContainer->insertChildFrame( mainFrame );
  183. mainFrame->widget()->reparent( newContainer, pos );
  184. KonqView* childView = setupView( newContainer, newViewFactory, service, partServiceOffers, appServiceOffers, serviceType, true );
  185. if( newOneFirst ) {
  186. static_cast<KonqFrameContainer*>(newContainer)->moveToFirst( childView->frame() );
  187. static_cast<KonqFrameContainer*>(newContainer)->swapChildren();
  188. }
  189. newContainer->show();
  190. mainFrame->widget()->setUpdatesEnabled( true );
  191. if( childView )
  192. childView->openURL( url, locationBarURL );
  193. newContainer->setActiveChild( mainFrame );
  194. #ifdef DEBUG_VIEWMGR
  195. m_pMainWindow->dumpViewList();
  196. printFullHierarchy( m_pMainWindow );
  197. kdDebug(1202) << "KonqViewManager::splitWindow(default) done" << endl;
  198. #endif
  199. return childView;
  200. }
  201. void KonqViewManager::convertDocContainer()
  202. {
  203. // Must create a tab container since one is not present,
  204. // then insert the existing frame as a tab
  205. KonqFrameContainerBase* parentContainer = m_pDocContainer->parentContainer();
  206. bool moveNewContainer = false;
  207. TQValueList<int> splitterSizes;
  208. if (parentContainer->frameType()=="Container") {
  209. moveNewContainer = (static_cast<KonqFrameContainer*>(parentContainer)->idAfter( m_pDocContainer->widget() ) != 0);
  210. splitterSizes = static_cast<KonqFrameContainer*>(parentContainer)->sizes();
  211. }
  212. parentContainer->widget()->setUpdatesEnabled( false );
  213. //kdDebug(1202) << "Move out child" << endl;
  214. TQPoint pos = m_pDocContainer->widget()->pos();
  215. parentContainer->removeChildFrame( m_pDocContainer );
  216. m_pDocContainer->widget()->reparent( m_pMainWindow, pos );
  217. KonqFrameTabs* newContainer = new KonqFrameTabs( parentContainer->widget() , parentContainer, this);
  218. parentContainer->insertChildFrame( newContainer );
  219. connect( newContainer, TQT_SIGNAL(ctrlTabPressed()), m_pMainWindow, TQT_SLOT(slotCtrlTabPressed()) );
  220. m_pDocContainer->widget()->reparent( newContainer, pos );
  221. newContainer->insertChildFrame( m_pDocContainer );
  222. if ( moveNewContainer ) {
  223. static_cast<KonqFrameContainer*>(parentContainer)->moveToFirst( newContainer );
  224. static_cast<KonqFrameContainer*>(parentContainer)->swapChildren();
  225. }
  226. if (parentContainer->frameType()=="Container")
  227. static_cast<KonqFrameContainer*>(parentContainer)->setSizes( splitterSizes );
  228. newContainer->show();
  229. parentContainer->widget()->setUpdatesEnabled( true );
  230. m_pDocContainer = newContainer;
  231. }
  232. KonqView* KonqViewManager::addTab(const TQString &serviceType, const TQString &serviceName, bool passiveMode, bool openAfterCurrentPage )
  233. {
  234. #ifdef DEBUG_VIEWMGR
  235. kdDebug(1202) << "------------- KonqViewManager::addTab starting -------------" << endl;
  236. m_pMainWindow->dumpViewList();
  237. printFullHierarchy( m_pMainWindow );
  238. #endif
  239. if (m_pDocContainer == 0L)
  240. {
  241. if (m_pMainWindow &&
  242. m_pMainWindow->currentView() &&
  243. m_pMainWindow->currentView()->frame()) {
  244. m_pDocContainer = m_pMainWindow->currentView()->frame();
  245. } else {
  246. kdDebug(1202) << "This view profile does not support tabs." << endl;
  247. return 0L;
  248. }
  249. }
  250. KService::Ptr service;
  251. TDETrader::OfferList partServiceOffers, appServiceOffers;
  252. KonqViewFactory newViewFactory = createView( serviceType, serviceName, service, partServiceOffers, appServiceOffers, true /*forceAutoEmbed*/ );
  253. if( newViewFactory.isNull() )
  254. return 0L; //do not split at all if we can't create the new view
  255. if (m_pDocContainer->frameType() != "Tabs") convertDocContainer();
  256. KonqView* childView = setupView( static_cast<KonqFrameTabs*>(m_pDocContainer), newViewFactory, service, partServiceOffers, appServiceOffers, serviceType, passiveMode, openAfterCurrentPage );
  257. #ifdef DEBUG_VIEWMGR
  258. m_pMainWindow->dumpViewList();
  259. printFullHierarchy( m_pMainWindow );
  260. kdDebug(1202) << "------------- KonqViewManager::addTab done -------------" << endl;
  261. #endif
  262. return childView;
  263. }
  264. KonqView* KonqViewManager::addTabFromHistory( int steps, bool openAfterCurrentPage )
  265. {
  266. if (m_pDocContainer == 0L)
  267. {
  268. if (m_pMainWindow &&
  269. m_pMainWindow->currentView() &&
  270. m_pMainWindow->currentView()->frame()) {
  271. m_pDocContainer = m_pMainWindow->currentView()->frame();
  272. } else {
  273. kdDebug(1202) << "This view profile does not support tabs." << endl;
  274. return 0L;
  275. }
  276. }
  277. if (m_pDocContainer->frameType() != "Tabs") convertDocContainer();
  278. int oldPos = m_pMainWindow->currentView()->historyPos();
  279. int newPos = oldPos + steps;
  280. const HistoryEntry * he = m_pMainWindow->currentView()->historyAt(newPos);
  281. if(!he)
  282. return 0L;
  283. KonqView* newView = 0L;
  284. newView = addTab( he->strServiceType, he->strServiceName, false, openAfterCurrentPage );
  285. if(!newView)
  286. return 0L;
  287. newView->copyHistory(m_pMainWindow->currentView());
  288. newView->setHistoryPos(newPos);
  289. newView->restoreHistory();
  290. return newView;
  291. }
  292. void KonqViewManager::duplicateTab( KonqFrameBase* tab, bool openAfterCurrentPage )
  293. {
  294. #ifdef DEBUG_VIEWMGR
  295. kdDebug(1202) << "---------------- KonqViewManager::duplicateTab( " << tab << " ) --------------" << endl;
  296. m_pMainWindow->dumpViewList();
  297. printFullHierarchy( m_pMainWindow );
  298. #endif
  299. if (m_pDocContainer == 0L)
  300. {
  301. if (m_pMainWindow &&
  302. m_pMainWindow->currentView() &&
  303. m_pMainWindow->currentView()->frame()) {
  304. m_pDocContainer = m_pMainWindow->currentView()->frame();
  305. } else {
  306. kdDebug(1202) << "This view profile does not support tabs." << endl;
  307. return;
  308. }
  309. }
  310. if (m_pDocContainer->frameType() != "Tabs") convertDocContainer();
  311. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(m_pDocContainer);
  312. KonqFrameBase* currentFrame;
  313. if ( tab == 0L )
  314. currentFrame = tqt_dynamic_cast<KonqFrameBase*>(tabContainer->currentPage());
  315. else
  316. currentFrame = tab;
  317. if (!currentFrame) {
  318. return;
  319. }
  320. KTempFile tempFile;
  321. tempFile.setAutoDelete( true );
  322. TDEConfig config( tempFile.name() );
  323. config.setGroup( "View Profile" );
  324. TQString prefix = TQString::fromLatin1( currentFrame->frameType() ) + TQString::number(0);
  325. config.writeEntry( "RootItem", prefix );
  326. prefix.append( '_' );
  327. currentFrame->saveConfig( &config, prefix, true, 0L, 0, 1);
  328. TQString rootItem = config.readEntry( "RootItem", "empty" );
  329. if (rootItem.isNull() || rootItem == "empty") return;
  330. // This flag is used by KonqView, to distinguish manual view creation
  331. // from profile loading (e.g. in switchView)
  332. m_bLoadingProfile = true;
  333. loadItem( config, tabContainer, rootItem, KURL(""), true, openAfterCurrentPage );
  334. m_bLoadingProfile = false;
  335. m_pMainWindow->enableAllActions(true);
  336. // This flag disables calls to viewCountChanged while creating the views,
  337. // so we do it once at the end :
  338. m_pMainWindow->viewCountChanged();
  339. if (openAfterCurrentPage)
  340. tabContainer->setCurrentPage( tabContainer->currentPageIndex () + 1 );
  341. else
  342. tabContainer->setCurrentPage( tabContainer->count() - 1 );
  343. KonqFrameBase* duplicatedFrame = tqt_dynamic_cast<KonqFrameBase*>(tabContainer->currentPage());
  344. if (duplicatedFrame)
  345. duplicatedFrame->copyHistory( currentFrame );
  346. #ifdef DEBUG_VIEWMGR
  347. m_pMainWindow->dumpViewList();
  348. printFullHierarchy( m_pMainWindow );
  349. kdDebug(1202) << "------------- KonqViewManager::duplicateTab done --------------" << endl;
  350. #endif
  351. }
  352. void KonqViewManager::breakOffTab( KonqFrameBase* tab )
  353. {
  354. #ifdef DEBUG_VIEWMGR
  355. kdDebug(1202) << "---------------- KonqViewManager::breakOffTab( " << tab << " ) --------------" << endl;
  356. m_pMainWindow->dumpViewList();
  357. printFullHierarchy( m_pMainWindow );
  358. #endif
  359. if (m_pDocContainer == 0L) return;
  360. if (m_pDocContainer->frameType() != "Tabs") return;
  361. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(m_pDocContainer);
  362. int width = m_pMainWindow->width();
  363. int height = m_pMainWindow->height();
  364. KonqFrameBase* currentFrame;
  365. if ( tab == 0L )
  366. currentFrame = tqt_dynamic_cast<KonqFrameBase*>(tabContainer->currentPage());
  367. else
  368. currentFrame = tab;
  369. if (!currentFrame) {
  370. return;
  371. }
  372. KTempFile tempFile;
  373. tempFile.setAutoDelete( true );
  374. TDEConfig config( tempFile.name() );
  375. config.setGroup( "View Profile" );
  376. TQString prefix = TQString::fromLatin1( currentFrame->frameType() ) + TQString::number(0);
  377. config.writeEntry( "RootItem", prefix );
  378. prefix.append( '_' );
  379. config.writeEntry( TQString::fromLatin1( "docContainer" ).prepend( prefix ), true );
  380. currentFrame->saveConfig( &config, prefix, true, 0L, 0, 1);
  381. KonqMainWindow *mainWindow = new KonqMainWindow( KURL(), false );
  382. if (mainWindow == 0L) return;
  383. mainWindow->viewManager()->loadViewProfile( config, "" );
  384. KonqFrameBase * newDocContainer = mainWindow->viewManager()->docContainer();
  385. if( newDocContainer && newDocContainer->frameType() == "Tabs")
  386. {
  387. KonqFrameTabs *kft = static_cast<KonqFrameTabs *>(newDocContainer);
  388. KonqFrameBase *newFrame = tqt_dynamic_cast<KonqFrameBase*>(kft->currentPage());
  389. if(newFrame)
  390. newFrame->copyHistory( currentFrame );
  391. }
  392. removeTab( currentFrame );
  393. mainWindow->enableAllActions( true );
  394. mainWindow->resize( width, height );
  395. mainWindow->activateChild();
  396. mainWindow->show();
  397. #ifdef DEBUG_VIEWMGR
  398. m_pMainWindow->dumpViewList();
  399. printFullHierarchy( m_pMainWindow );
  400. mainWindow->dumpViewList();
  401. mainWindow->viewManager()->printFullHierarchy( mainWindow );
  402. kdDebug(1202) << "------------- KonqViewManager::breakOffTab done --------------" << endl;
  403. #endif
  404. }
  405. void KonqViewManager::removeTab( KonqFrameBase* tab )
  406. {
  407. #ifdef DEBUG_VIEWMGR
  408. kdDebug(1202) << "---------------- KonqViewManager::removeTab( " << tab << " ) --------------" << endl;
  409. m_pMainWindow->dumpViewList();
  410. printFullHierarchy( m_pMainWindow );
  411. #endif
  412. if (m_pDocContainer == 0L)
  413. return;
  414. if (m_pDocContainer->frameType() != "Tabs" )
  415. return;
  416. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(m_pDocContainer);
  417. KonqFrameBase* currentFrame;
  418. if ( tab != 0L ) {
  419. currentFrame = tab;
  420. } else {
  421. currentFrame = tqt_dynamic_cast<KonqFrameBase*>(tabContainer->currentPage());
  422. if (!currentFrame) {
  423. return;
  424. }
  425. }
  426. if ( tabContainer->count() == 1 )
  427. return;
  428. if (currentFrame->widget() == tabContainer->currentPage())
  429. setActivePart( 0L, true );
  430. tabContainer->removeChildFrame(currentFrame);
  431. TQPtrList<KonqView> viewList;
  432. TQPtrListIterator<KonqView> it( viewList );
  433. currentFrame->listViews( &viewList );
  434. for ( it.toFirst(); it != 0L; ++it )
  435. {
  436. if (it.current() == m_pMainWindow->currentView())
  437. setActivePart( 0L, true );
  438. m_pMainWindow->removeChildView( it.current() );
  439. delete it.current();
  440. }
  441. delete currentFrame;
  442. tabContainer->slotCurrentChanged(tabContainer->currentPage());
  443. #ifdef DEBUG_VIEWMGR
  444. m_pMainWindow->dumpViewList();
  445. printFullHierarchy( m_pMainWindow );
  446. kdDebug(1202) << "------------- KonqViewManager::removeTab done --------------" << endl;
  447. #endif
  448. }
  449. void KonqViewManager::reloadAllTabs( )
  450. {
  451. if (m_pDocContainer == 0L) return;
  452. if (m_pDocContainer->frameType() != "Tabs") return;
  453. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(m_pDocContainer);
  454. TQPtrList<KonqFrameBase> frameList = *tabContainer->childFrameList();
  455. TQPtrListIterator<KonqFrameBase> it( frameList );
  456. for ( it.toFirst(); it != 0L; ++it )
  457. {
  458. if ( it.current()->activeChildView())
  459. {
  460. if( !it.current()->activeChildView()->locationBarURL().isEmpty())
  461. it.current()->activeChildView()->openURL( it.current()->activeChildView()->url(),it.current()->activeChildView()->locationBarURL());
  462. }
  463. }
  464. }
  465. void KonqViewManager::removeOtherTabs( KonqFrameBase* tab )
  466. {
  467. if (m_pDocContainer == 0L) return;
  468. if (m_pDocContainer->frameType() != "Tabs") return;
  469. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(m_pDocContainer);
  470. KonqFrameBase *currentFrame;
  471. if ( tab == 0L )
  472. currentFrame = tqt_dynamic_cast<KonqFrameBase*>(tabContainer->currentPage());
  473. else
  474. currentFrame = tab;
  475. if (!currentFrame) {
  476. return;
  477. }
  478. TQPtrList<KonqFrameBase> frameList = *tabContainer->childFrameList();
  479. TQPtrListIterator<KonqFrameBase> it( frameList );
  480. for ( it.toFirst(); it != 0L; ++it )
  481. {
  482. if( it.current() != currentFrame )
  483. removeTab(it.current());
  484. }
  485. }
  486. void KonqViewManager::moveTabBackward()
  487. {
  488. if (m_pDocContainer == 0L) return;
  489. if (m_pDocContainer->frameType() != "Tabs") return;
  490. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(m_pDocContainer);
  491. if( tabContainer->count() == 1 ) return;
  492. int iTab = tabContainer->currentPageIndex();
  493. kdDebug()<<" tabContainer->currentPageIndex(); :"<<iTab<<endl;
  494. tabContainer->moveTabBackward(iTab);
  495. }
  496. void KonqViewManager::moveTabForward()
  497. {
  498. if (m_pDocContainer == 0L) return;
  499. if (m_pDocContainer->frameType() != "Tabs") return;
  500. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(m_pDocContainer);
  501. if( tabContainer->count() == 1 ) return;
  502. int iTab = tabContainer->currentPageIndex();
  503. tabContainer->moveTabForward(iTab);
  504. }
  505. void KonqViewManager::activateNextTab()
  506. {
  507. if (m_pDocContainer == 0L) return;
  508. if (m_pDocContainer->frameType() != "Tabs") return;
  509. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(m_pDocContainer);
  510. if( tabContainer->count() == 1 ) return;
  511. int iTab = tabContainer->currentPageIndex();
  512. iTab++;
  513. if( iTab == tabContainer->count() )
  514. iTab = 0;
  515. tabContainer->setCurrentPage( iTab );
  516. }
  517. void KonqViewManager::activatePrevTab()
  518. {
  519. if (m_pDocContainer == 0L) return;
  520. if (m_pDocContainer->frameType() != "Tabs") return;
  521. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(m_pDocContainer);
  522. if( tabContainer->count() == 1 ) return;
  523. int iTab = tabContainer->currentPageIndex();
  524. iTab--;
  525. if( iTab == -1 )
  526. iTab = tabContainer->count() - 1;
  527. tabContainer->setCurrentPage( iTab );
  528. }
  529. void KonqViewManager::activateTab(int position)
  530. {
  531. if (m_pDocContainer == 0L) return;
  532. if (m_pDocContainer->frameType() != "Tabs") return;
  533. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(m_pDocContainer);
  534. if (position<0 || tabContainer->count() == 1 || position>=tabContainer->count()) return;
  535. tabContainer->setCurrentPage( position );
  536. }
  537. void KonqViewManager::showTab( KonqView *view )
  538. {
  539. KonqFrameTabs *tabContainer = static_cast<KonqFrameTabs*>( docContainer() );
  540. if (tabContainer->currentPage() != view->frame())
  541. {
  542. tabContainer->showPage( view->frame() );
  543. emitActivePartChanged();
  544. }
  545. }
  546. void KonqViewManager::updatePixmaps()
  547. {
  548. if (m_pDocContainer == 0L) return;
  549. if (m_pDocContainer->frameType() != "Tabs") return;
  550. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(m_pDocContainer);
  551. TQPtrList<KonqView> viewList;
  552. TQPtrListIterator<KonqView> it( viewList );
  553. tabContainer->listViews( &viewList );
  554. for ( it.toFirst(); it != 0L; ++it )
  555. it.current()->setTabIcon( KURL::fromPathOrURL( it.current()->locationBarURL() ) );
  556. }
  557. void KonqViewManager::removeView( KonqView *view )
  558. {
  559. #ifdef DEBUG_VIEWMGR
  560. kdDebug(1202) << "---------------- removeView --------------" << view << endl;
  561. m_pMainWindow->dumpViewList();
  562. printFullHierarchy( m_pMainWindow );
  563. #endif
  564. if (!view)
  565. return;
  566. KonqFrame* frame = view->frame();
  567. KonqFrameContainerBase* parentContainer = frame->parentContainer();
  568. kdDebug(1202) << "view=" << view << " frame=" << frame << " parentContainer=" << parentContainer << endl;
  569. if (parentContainer->frameType()=="Container")
  570. {
  571. kdDebug(1202) << "parentContainer is a KonqFrameContainer" << endl;
  572. KonqFrameContainerBase* grandParentContainer = parentContainer->parentContainer();
  573. kdDebug(1202) << "grandParentContainer=" << grandParentContainer << endl;
  574. setActivePart( 0L, true );
  575. int index = -1;
  576. TQValueList<int> splitterSizes;
  577. bool moveOtherChild = false;
  578. if (grandParentContainer->frameType()=="Tabs")
  579. index = static_cast<KonqFrameTabs*>(grandParentContainer)->indexOf( parentContainer->widget() );
  580. else if (grandParentContainer->frameType()=="Container")
  581. {
  582. moveOtherChild = (static_cast<KonqFrameContainer*>(grandParentContainer)->idAfter( parentContainer->widget() ) != 0);
  583. splitterSizes = static_cast<KonqFrameContainer*>(grandParentContainer)->sizes();
  584. }
  585. KonqFrameBase* otherFrame = static_cast<KonqFrameContainer*>(parentContainer)->otherChild( frame );
  586. kdDebug(1202) << "otherFrame=" << otherFrame << endl;
  587. if( otherFrame == 0L )
  588. {
  589. kdWarning(1202) << "KonqViewManager::removeView: This shouldn't happen!" << endl;
  590. return;
  591. }
  592. if (m_pDocContainer == parentContainer) m_pDocContainer = otherFrame;
  593. grandParentContainer->widget()->setUpdatesEnabled( false );
  594. static_cast<KonqFrameContainer*>(parentContainer)->setAboutToBeDeleted();
  595. //kdDebug(1202) << "--- Reparenting otherFrame to m_pMainWindow " << m_pMainWindow << endl;
  596. TQPoint pos = otherFrame->widget()->pos();
  597. otherFrame->reparentFrame( m_pMainWindow, pos );
  598. //kdDebug(1202) << "--- Removing otherFrame from parentContainer" << endl;
  599. parentContainer->removeChildFrame( otherFrame );
  600. //kdDebug(1202) << "--- Removing parentContainer from grandParentContainer" << endl;
  601. grandParentContainer->removeChildFrame( parentContainer );
  602. //kdDebug(1202) << "--- Removing view from view list" << endl;
  603. m_pMainWindow->removeChildView(view);
  604. //kdDebug(1202) << "--- Deleting view " << view << endl;
  605. delete view; // This deletes the view, which deletes the part, which deletes its widget
  606. //kdDebug(1202) << "--- Deleting parentContainer " << parentContainer
  607. // << ". Its parent is " << parentContainer->widget()->parent() << endl;
  608. delete parentContainer;
  609. //kdDebug(1202) << "--- Reparenting otherFrame to grandParentContainer" << grandParentContainer << endl;
  610. otherFrame->reparentFrame( grandParentContainer->widget(), pos );
  611. //kdDebug(1202) << "--- Inserting otherFrame into grandParentContainer" << grandParentContainer << endl;
  612. grandParentContainer->insertChildFrame( otherFrame, index );
  613. if( moveOtherChild )
  614. {
  615. static_cast<KonqFrameContainer*>(grandParentContainer)->moveToFirst( otherFrame->widget() );
  616. static_cast<KonqFrameContainer*>(grandParentContainer)->swapChildren();
  617. }
  618. if (grandParentContainer->frameType()=="Container")
  619. static_cast<KonqFrameContainer*>(grandParentContainer)->setSizes( splitterSizes );
  620. otherFrame->widget()->show();
  621. grandParentContainer->setActiveChild( otherFrame );
  622. grandParentContainer->activateChild();
  623. grandParentContainer->widget()->setUpdatesEnabled( true );
  624. }
  625. else if (parentContainer->frameType()=="Tabs") {
  626. kdDebug(1202) << "parentContainer " << parentContainer << " is a KonqFrameTabs" << endl;
  627. removeTab( frame );
  628. }
  629. else if (parentContainer->frameType()=="MainWindow")
  630. kdDebug(1202) << "parentContainer is a KonqMainWindow. This shouldn't be removeable, not removing." << endl;
  631. else
  632. kdDebug(1202) << "Unrecognized frame type, not removing." << endl;
  633. #ifdef DEBUG_VIEWMGR
  634. printFullHierarchy( m_pMainWindow );
  635. m_pMainWindow->dumpViewList();
  636. kdDebug(1202) << "------------- removeView done --------------" << view << endl;
  637. #endif
  638. }
  639. // reimplemented from PartManager
  640. void KonqViewManager::removePart( KParts::Part * part )
  641. {
  642. kdDebug(1202) << "KonqViewManager::removePart ( " << part << " )" << endl;
  643. // This is called when a part auto-deletes itself (case 1), or when
  644. // the "delete view" above deletes, in turn, the part (case 2)
  645. kdDebug(1202) << "Calling KParts::PartManager::removePart " << part << endl;
  646. KParts::PartManager::removePart( part );
  647. // If we were called by PartManager::slotObjectDestroyed, then the inheritance has
  648. // been deleted already... Can't use inherits().
  649. KonqView * view = m_pMainWindow->childView( static_cast<KParts::ReadOnlyPart *>(part) );
  650. if ( view ) // the child view still exists, so we are in case 1
  651. {
  652. kdDebug(1202) << "Found a child view" << endl;
  653. view->partDeleted(); // tell the child view that the part auto-deletes itself
  654. if (m_pMainWindow->mainViewsCount() == 1)
  655. {
  656. kdDebug(1202) << "Deleting last view -> closing the window" << endl;
  657. clear();
  658. kdDebug(1202) << "Closing m_pMainWindow " << m_pMainWindow << endl;
  659. m_pMainWindow->close(); // will delete it
  660. return;
  661. } else { // normal case
  662. removeView( view );
  663. }
  664. }
  665. kdDebug(1202) << "KonqViewManager::removePart ( " << part << " ) done" << endl;
  666. }
  667. void KonqViewManager::slotPassiveModePartDeleted()
  668. {
  669. // Passive mode parts aren't registered to the part manager,
  670. // so we have to handle suicidal ones ourselves
  671. KParts::ReadOnlyPart * part = const_cast<KParts::ReadOnlyPart *>( static_cast<const KParts::ReadOnlyPart *>( sender() ) );
  672. disconnect( part, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotPassiveModePartDeleted() ) );
  673. kdDebug(1202) << "KonqViewManager::slotPassiveModePartDeleted part=" << part << endl;
  674. KonqView * view = m_pMainWindow->childView( part );
  675. kdDebug(1202) << "view=" << view << endl;
  676. if ( view != 0L) // the child view still exists, so the part suicided
  677. {
  678. view->partDeleted(); // tell the child view that the part deleted itself
  679. removeView( view );
  680. }
  681. }
  682. void KonqViewManager::viewCountChanged()
  683. {
  684. bool bShowActiveViewIndicator = ( m_pMainWindow->viewCount() > 1 );
  685. bool bShowLinkedViewIndicator = ( m_pMainWindow->linkableViewsCount() > 1 );
  686. KonqMainWindow::MapViews mapViews = m_pMainWindow->viewMap();
  687. KonqMainWindow::MapViews::Iterator it = mapViews.begin();
  688. KonqMainWindow::MapViews::Iterator end = mapViews.end();
  689. for ( ; it != end ; ++it )
  690. {
  691. KonqFrameStatusBar* sb = it.data()->frame()->statusbar();
  692. sb->showActiveViewIndicator( bShowActiveViewIndicator && !it.data()->isPassiveMode() );
  693. sb->showLinkedViewIndicator( bShowLinkedViewIndicator && !it.data()->isFollowActive() );
  694. }
  695. }
  696. void KonqViewManager::clear()
  697. {
  698. kdDebug(1202) << "KonqViewManager::clear" << endl;
  699. setActivePart( 0L, true /* immediate */ );
  700. if (m_pMainWindow->childFrame() == 0L) return;
  701. TQPtrList<KonqView> viewList;
  702. m_pMainWindow->listViews( &viewList );
  703. kdDebug(1202) << viewList.count() << " items" << endl;
  704. TQPtrListIterator<KonqView> it( viewList );
  705. for ( it.toFirst(); it.current(); ++it ) {
  706. m_pMainWindow->removeChildView( it.current() );
  707. kdDebug(1202) << "Deleting " << it.current() << endl;
  708. delete it.current();
  709. }
  710. kdDebug(1202) << "deleting mainFrame " << endl;
  711. KonqFrameBase* frame = m_pMainWindow->childFrame();
  712. m_pMainWindow->removeChildFrame( frame ); // will set childFrame() to NULL
  713. delete frame;
  714. m_pDocContainer = 0L;
  715. }
  716. KonqView *KonqViewManager::chooseNextView( KonqView *view )
  717. {
  718. //kdDebug(1202) << "KonqViewManager(" << this << ")::chooseNextView(" << view << ")" << endl;
  719. KonqMainWindow::MapViews mapViews = m_pMainWindow->viewMap();
  720. KonqMainWindow::MapViews::Iterator it = mapViews.begin();
  721. KonqMainWindow::MapViews::Iterator end = mapViews.end();
  722. if ( view ) // find it in the map - can't use the key since view->part() might be 0L
  723. while ( it != end && it.data() != view )
  724. ++it;
  725. // the view should always be in the list
  726. if ( it == end ) {
  727. if ( view )
  728. kdWarning() << "View " << view << " is not in list !" << endl;
  729. it = mapViews.begin();
  730. if ( it == end )
  731. return 0L; // We have no view at all - this used to happen with totally-empty-profiles
  732. }
  733. KonqMainWindow::MapViews::Iterator startIt = it;
  734. //kdDebug(1202) << "KonqViewManager::chooseNextView: count=" << mapViews.count() << endl;
  735. while ( true )
  736. {
  737. //kdDebug(1202) << "*KonqViewManager::chooseNextView going next" << endl;
  738. if ( ++it == end ) // move to next
  739. it = mapViews.begin(); // rewind on end
  740. if ( it == startIt && view )
  741. break; // no next view found
  742. KonqView *nextView = it.data();
  743. if ( nextView && !nextView->isPassiveMode() )
  744. return nextView;
  745. //kdDebug(1202) << "KonqViewManager::chooseNextView nextView=" << nextView << " passive=" << nextView->isPassiveMode() << endl;
  746. }
  747. //kdDebug(1202) << "KonqViewManager::chooseNextView: returning 0L" << endl;
  748. return 0L; // no next view found
  749. }
  750. KonqViewFactory KonqViewManager::createView( const TQString &serviceType,
  751. const TQString &serviceName,
  752. KService::Ptr &service,
  753. TDETrader::OfferList &partServiceOffers,
  754. TDETrader::OfferList &appServiceOffers,
  755. bool forceAutoEmbed )
  756. {
  757. kdDebug(1202) << "KonqViewManager::createView" << endl;
  758. KonqViewFactory viewFactory;
  759. if( serviceType.isEmpty() && m_pMainWindow->currentView() ) {
  760. //clone current view
  761. KonqView *cv = m_pMainWindow->currentView();
  762. TQString _serviceType, _serviceName;
  763. if ( cv->service()->desktopEntryName() == "konq_sidebartng" ) {
  764. _serviceType = "text/html";
  765. }
  766. else {
  767. _serviceType = cv->serviceType();
  768. _serviceName = cv->service()->desktopEntryName();
  769. }
  770. viewFactory = KonqFactory::createView( _serviceType, _serviceName,
  771. &service, &partServiceOffers, &appServiceOffers, forceAutoEmbed );
  772. }
  773. else {
  774. //create view with the given servicetype
  775. viewFactory = KonqFactory::createView( serviceType, serviceName,
  776. &service, &partServiceOffers, &appServiceOffers, forceAutoEmbed );
  777. }
  778. return viewFactory;
  779. }
  780. KonqView *KonqViewManager::setupView( KonqFrameContainerBase *parentContainer,
  781. KonqViewFactory &viewFactory,
  782. const KService::Ptr &service,
  783. const TDETrader::OfferList &partServiceOffers,
  784. const TDETrader::OfferList &appServiceOffers,
  785. const TQString &serviceType,
  786. bool passiveMode,
  787. bool openAfterCurrentPage )
  788. {
  789. kdDebug(1202) << "KonqViewManager::setupView passiveMode=" << passiveMode << endl;
  790. TQString sType = serviceType;
  791. if ( sType.isEmpty() )
  792. sType = m_pMainWindow->currentView()->serviceType();
  793. //kdDebug(1202) << "KonqViewManager::setupView creating KonqFrame with parent=" << parentContainer << endl;
  794. KonqFrame* newViewFrame = new KonqFrame( parentContainer->widget(), parentContainer, "KonqFrame" );
  795. newViewFrame->setGeometry( 0, 0, m_pMainWindow->width(), m_pMainWindow->height() );
  796. //kdDebug(1202) << "Creating KonqView" << endl;
  797. KonqView *v = new KonqView( viewFactory, newViewFrame,
  798. m_pMainWindow, service, partServiceOffers, appServiceOffers, sType, passiveMode );
  799. //kdDebug(1202) << "KonqView created - v=" << v << " v->part()=" << v->part() << endl;
  800. TQObject::connect( v, TQT_SIGNAL( sigPartChanged( KonqView *, KParts::ReadOnlyPart *, KParts::ReadOnlyPart * ) ),
  801. m_pMainWindow, TQT_SLOT( slotPartChanged( KonqView *, KParts::ReadOnlyPart *, KParts::ReadOnlyPart * ) ) );
  802. m_pMainWindow->insertChildView( v );
  803. int index = -1;
  804. if (m_pDocContainer && m_pDocContainer->frameType() == "Tabs")
  805. {
  806. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(m_pDocContainer);
  807. if ( openAfterCurrentPage )
  808. index = tabContainer->currentPageIndex() +1 ;
  809. }
  810. parentContainer->insertChildFrame( newViewFrame, index );
  811. if (parentContainer->frameType() != "Tabs") newViewFrame->show();
  812. // Don't register passive views to the part manager
  813. if ( !v->isPassiveMode() ) // note that KonqView's constructor could set this to true even if passiveMode is false
  814. addPart( v->part(), false );
  815. else
  816. {
  817. // Passive views aren't registered, but we still want to detect the suicidal ones
  818. connect( v->part(), TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotPassiveModePartDeleted() ) );
  819. }
  820. //kdDebug(1202) << "KonqViewManager::setupView done" << endl;
  821. return v;
  822. }
  823. ///////////////// Profile stuff ////////////////
  824. void KonqViewManager::saveViewProfile( const TQString & fileName, const TQString & profileName, bool saveURLs, bool saveWindowSize )
  825. {
  826. TQString path = locateLocal( "data", TQString::fromLatin1( "konqueror/profiles/" ) +
  827. fileName, TDEGlobal::instance() );
  828. if ( TQFile::exists( path ) )
  829. TQFile::remove( path );
  830. KSimpleConfig cfg( path );
  831. cfg.setGroup( "Profile" );
  832. if ( !profileName.isEmpty() )
  833. cfg.writePathEntry( "Name", profileName );
  834. saveViewProfile( cfg, saveURLs, saveWindowSize );
  835. }
  836. void KonqViewManager::saveViewProfile( TDEConfig & cfg, bool saveURLs, bool saveWindowSize )
  837. {
  838. //kdDebug(1202) << "KonqViewManager::saveViewProfile" << endl;
  839. if( m_pMainWindow->childFrame() != 0L ) {
  840. TQString prefix = TQString::fromLatin1( m_pMainWindow->childFrame()->frameType() )
  841. + TQString::number(0);
  842. cfg.writeEntry( "RootItem", prefix );
  843. prefix.append( '_' );
  844. m_pMainWindow->saveConfig( &cfg, prefix, saveURLs, m_pDocContainer, 0, 1);
  845. }
  846. cfg.writeEntry( "FullScreen", m_pMainWindow->fullScreenMode());
  847. cfg.writeEntry("XMLUIFile", m_pMainWindow->xmlFile());
  848. if ( saveWindowSize )
  849. {
  850. cfg.writeEntry( "Width", m_pMainWindow->width() );
  851. cfg.writeEntry( "Height", m_pMainWindow->height() );
  852. }
  853. // Save menu/toolbar settings in profile. Relys on konq_mainwindow calling
  854. // setAutoSaveSetting( "KongMainWindow", false ). The false is important,
  855. // we do not want this call save size settings in the profile, because we
  856. // do it ourselves. Save in a separate group than the rest of the profile.
  857. TQString savedGroup = cfg.group();
  858. m_pMainWindow->saveMainWindowSettings( &cfg, "Main Window Settings" );
  859. cfg.setGroup( savedGroup );
  860. cfg.sync();
  861. }
  862. void KonqViewManager::loadViewProfile( const TQString & path, const TQString & filename,
  863. const KURL & forcedURL, const KonqOpenURLRequest &req,
  864. bool resetWindow, bool openURL )
  865. {
  866. TDEConfig cfg( path, true );
  867. cfg.setDollarExpansion( true );
  868. cfg.setGroup( "Profile" );
  869. loadViewProfile( cfg, filename, forcedURL, req, resetWindow, openURL );
  870. }
  871. void KonqViewManager::loadViewProfile( TDEConfig &cfg, const TQString & filename,
  872. const KURL & forcedURL, const KonqOpenURLRequest &req,
  873. bool resetWindow, bool openURL )
  874. {
  875. if ( docContainer() && docContainer()->frameType()=="Tabs" )
  876. {
  877. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(docContainer());
  878. if ( tabContainer->count() > 1 )
  879. {
  880. if ( KMessageBox::warningContinueCancel( 0,
  881. i18n("You have multiple tabs open in this window.\n"
  882. "Loading a view profile will close them."),
  883. i18n("Confirmation"),
  884. i18n("Load View Profile"),
  885. "LoadProfileTabsConfirm" ) == KMessageBox::Cancel )
  886. return;
  887. }
  888. KonqView *originalView = m_pMainWindow->currentView();
  889. TQPtrList<KonqFrameBase> frameList = *tabContainer->childFrameList();
  890. TQPtrListIterator<KonqFrameBase> it( frameList );
  891. for ( it.toFirst(); it != 0L; ++it )
  892. {
  893. KonqView *view = it.current()->activeChildView();
  894. if (view && view->part() && (view->part()->metaObject()->findProperty("modified") != -1)) {
  895. TQVariant prop = view->part()->property("modified");
  896. if (prop.isValid() && prop.toBool()) {
  897. showTab( view );
  898. if ( KMessageBox::warningContinueCancel( 0,
  899. i18n("This tab contains changes that have not been submitted.\nLoading a profile will discard these changes."),
  900. i18n("Discard Changes?"), i18n("&Discard Changes"), "discardchangesloadprofile") != KMessageBox::Continue )
  901. {
  902. showTab( originalView );
  903. return;
  904. }
  905. }
  906. }
  907. }
  908. showTab( originalView );
  909. }
  910. else
  911. {
  912. KonqView *view = m_pMainWindow->currentView();
  913. if (view && view->part() && (view->part()->metaObject()->findProperty("modified") != -1)) {
  914. TQVariant prop = view->part()->property("modified");
  915. if (prop.isValid() && prop.toBool())
  916. if ( KMessageBox::warningContinueCancel( 0,
  917. i18n("This page contains changes that have not been submitted.\nLoading a profile will discard these changes."),
  918. i18n("Discard Changes?"), i18n("&Discard Changes"), "discardchangesloadprofile") != KMessageBox::Continue )
  919. return;
  920. }
  921. }
  922. bool alwaysTabbedMode = KonqSettings::alwaysTabbedMode();
  923. m_currentProfile = filename;
  924. m_currentProfileText = cfg.readPathEntry("Name",filename);
  925. m_profileHomeURL = cfg.readEntry("HomeURL", TQString::null);
  926. m_pMainWindow->currentProfileChanged();
  927. KURL defaultURL;
  928. if ( m_pMainWindow->currentView() )
  929. defaultURL = m_pMainWindow->currentView()->url();
  930. clear();
  931. TQString rootItem = cfg.readEntry( "RootItem", "empty" );
  932. //kdDebug(1202) << "KonqViewManager::loadViewProfile : loading RootItem " << rootItem <<
  933. //" forcedURL " << forcedURL.url() << endl;
  934. if ( forcedURL.url() != "about:blank" )
  935. {
  936. // This flag is used by KonqView, to distinguish manual view creation
  937. // from profile loading (e.g. in switchView)
  938. m_bLoadingProfile = true;
  939. loadItem( cfg, m_pMainWindow, rootItem, defaultURL, openURL && forcedURL.isEmpty() );
  940. m_bLoadingProfile = false;
  941. m_pMainWindow->enableAllActions(true);
  942. // This flag disables calls to viewCountChanged while creating the views,
  943. // so we do it once at the end :
  944. m_pMainWindow->viewCountChanged();
  945. }
  946. else
  947. {
  948. m_pMainWindow->disableActionsNoView();
  949. m_pMainWindow->action( "clear_location" )->activate();
  950. }
  951. //kdDebug(1202) << "KonqViewManager::loadViewProfile : after loadItem " << endl;
  952. if (m_pDocContainer == 0L)
  953. {
  954. if (m_pMainWindow &&
  955. m_pMainWindow->currentView() &&
  956. m_pMainWindow->currentView()->frame()) {
  957. m_pDocContainer = m_pMainWindow->currentView()->frame();
  958. } else {
  959. kdDebug(1202) << "This view profile does not support tabs." << endl;
  960. return;
  961. }
  962. }
  963. if ( m_pDocContainer->frameType() != "Tabs")
  964. convertDocContainer();
  965. static_cast<KonqFrameTabs*>( m_pDocContainer )->setAlwaysTabbedMode( alwaysTabbedMode );
  966. static_cast<KonqFrameTabs*>( m_pDocContainer )->setMouseWheelScroll(KonqSettings::tabsCycleWheel());
  967. // Set an active part first so that we open the URL in the current view
  968. // (to set the location bar correctly and asap)
  969. KonqView *nextChildView = 0L;
  970. nextChildView = m_pMainWindow->activeChildView();
  971. if (nextChildView == 0L) nextChildView = chooseNextView( 0L );
  972. setActivePart( nextChildView ? nextChildView->part() : 0L, true /* immediate */);
  973. // #71164
  974. if ( !req.args.frameName.isEmpty() && nextChildView ) {
  975. nextChildView->setViewName( req.args.frameName );
  976. }
  977. if ( openURL && !forcedURL.isEmpty())
  978. {
  979. KonqOpenURLRequest _req(req);
  980. _req.openAfterCurrentPage = KonqSettings::openAfterCurrentPage();
  981. _req.forceAutoEmbed = true; // it's a new window, let's use it
  982. m_pMainWindow->openURL( nextChildView /* can be 0 for an empty profile */,
  983. forcedURL, _req.args.serviceType, _req, _req.args.trustedSource );
  984. // TODO choose a linked view if any (instead of just the first one),
  985. // then open the same URL in any non-linked one
  986. }
  987. else
  988. {
  989. if ( m_pMainWindow->locationBarURL().isEmpty() ) // No URL -> the user will want to type one
  990. m_pMainWindow->focusLocationBar();
  991. }
  992. // Window size
  993. if ( !m_pMainWindow->initialGeometrySet() )
  994. {
  995. if (cfg.readBoolEntry( "FullScreen" ))
  996. {
  997. // Full screen on
  998. m_pMainWindow->showFullScreen();
  999. }
  1000. else
  1001. {
  1002. // Full screen off
  1003. if( m_pMainWindow->isFullScreen())
  1004. m_pMainWindow->showNormal();
  1005. TQSize size = readConfigSize( cfg, m_pMainWindow );
  1006. if ( size.isValid() )
  1007. m_pMainWindow->resize( size );
  1008. else // no size in the profile; use last known size
  1009. m_pMainWindow->restoreWindowSize();
  1010. }
  1011. }
  1012. if( resetWindow )
  1013. { // force default settings for the GUI
  1014. m_pMainWindow->applyMainWindowSettings( TDEGlobal::config(), "KonqMainWindow", true );
  1015. }
  1016. // Apply menu/toolbar settings saved in profile. Read from a separate group
  1017. // so that the window doesn't try to change the size stored in the Profile group.
  1018. // (If applyMainWindowSettings finds a "Width" or "Height" entry, it
  1019. // sets them to 0,0)
  1020. TQString savedGroup = cfg.group();
  1021. m_pMainWindow->applyMainWindowSettings( &cfg, "Main Window Settings" );
  1022. cfg.setGroup( savedGroup );
  1023. #ifdef DEBUG_VIEWMGR
  1024. printFullHierarchy( m_pMainWindow );
  1025. #endif
  1026. //kdDebug(1202) << "KonqViewManager::loadViewProfile done" << endl;
  1027. }
  1028. void KonqViewManager::setActivePart( KParts::Part *part, TQWidget * )
  1029. {
  1030. setActivePart( part, false );
  1031. }
  1032. void KonqViewManager::setActivePart( KParts::Part *part, bool immediate )
  1033. {
  1034. //kdDebug(1202) << "KonqViewManager::setActivePart " << part << endl;
  1035. //if ( part )
  1036. // kdDebug(1202) << " " << part->className() << " " << part->name() << endl;
  1037. // Due to the single-shot timer below, we need to also make sure that
  1038. // the mainwindow also has the right part active already
  1039. KParts::Part* mainWindowActivePart = (m_pMainWindow && m_pMainWindow->currentView())
  1040. ? m_pMainWindow->currentView()->part() : 0;
  1041. if (part == activePart() && (!immediate || mainWindowActivePart == part))
  1042. {
  1043. if ( part )
  1044. kdDebug(1202) << "Part is already active!" << endl;
  1045. return;
  1046. }
  1047. // Don't activate when part changed in non-active tab
  1048. KonqView* partView = m_pMainWindow->childView((KParts::ReadOnlyPart*)part);
  1049. if (partView)
  1050. {
  1051. KonqFrameContainerBase* parentContainer = partView->frame()->parentContainer();
  1052. if (parentContainer->frameType()=="Tabs")
  1053. {
  1054. KonqFrameTabs* parentFrameTabs = static_cast<KonqFrameTabs*>(parentContainer);
  1055. if (partView->frame() != parentFrameTabs->currentPage())
  1056. return;
  1057. }
  1058. }
  1059. if (m_pMainWindow && m_pMainWindow->currentView())
  1060. m_pMainWindow->currentView()->setLocationBarURL(m_pMainWindow->locationBarURL());
  1061. KParts::PartManager::setActivePart( part );
  1062. if (part && part->widget())
  1063. part->widget()->setFocus();
  1064. if (!immediate && reason() != ReasonRightClick) {
  1065. // We use a 0s single shot timer so that when left-clicking on a part,
  1066. // we process the mouse event before rebuilding the GUI.
  1067. // Otherwise, when e.g. dragging icons, the mouse pointer can already
  1068. // be very far from where it was...
  1069. m_activePartChangedTimer->start( 0, true );
  1070. // This is not done with right-clicking so that the part is activated before the
  1071. // popup appears (#75201)
  1072. } else {
  1073. emitActivePartChanged();
  1074. }
  1075. }
  1076. void KonqViewManager::slotActivePartChanged ( KParts::Part *newPart )
  1077. {
  1078. //kdDebug(1202) << "KonqViewManager::slotActivePartChanged " << newPart << endl;
  1079. if (newPart == 0L) {
  1080. //kdDebug(1202) << "newPart = 0L , returning" << endl;
  1081. return;
  1082. }
  1083. KonqView * view = m_pMainWindow->childView( static_cast<KParts::ReadOnlyPart *>(newPart) );
  1084. if (view == 0L) {
  1085. kdDebug(1202) << k_funcinfo << "No view associated with this part" << endl;
  1086. return;
  1087. }
  1088. if (view->frame()->parentContainer() == 0L) return;
  1089. if (!m_bLoadingProfile) {
  1090. view->frame()->statusbar()->updateActiveStatus();
  1091. view->frame()->parentContainer()->setActiveChild( view->frame() );
  1092. }
  1093. //kdDebug(1202) << "KonqViewManager::slotActivePartChanged done" << endl;
  1094. }
  1095. void KonqViewManager::emitActivePartChanged()
  1096. {
  1097. // prevent unnecessary multiple calls to slotPartActivated:
  1098. m_activePartChangedTimer->stop();
  1099. m_pMainWindow->slotPartActivated( activePart() );
  1100. }
  1101. TQSize KonqViewManager::readConfigSize( TDEConfig &cfg, TQWidget *widget )
  1102. {
  1103. bool ok;
  1104. TQString widthStr = cfg.readEntry( "Width" );
  1105. TQString heightStr = cfg.readEntry( "Height" );
  1106. int width = -1;
  1107. int height = -1;
  1108. TQRect geom = TDEGlobalSettings::desktopGeometry(widget);
  1109. if ( widthStr.contains( '%' ) == 1 )
  1110. {
  1111. widthStr.truncate( widthStr.length() - 1 );
  1112. int relativeWidth = widthStr.toInt( &ok );
  1113. if ( ok ) {
  1114. width = relativeWidth * geom.width() / 100;
  1115. }
  1116. }
  1117. else
  1118. {
  1119. width = widthStr.toInt( &ok );
  1120. if ( !ok )
  1121. width = -1;
  1122. }
  1123. if ( heightStr.contains( '%' ) == 1 )
  1124. {
  1125. heightStr.truncate( heightStr.length() - 1 );
  1126. int relativeHeight = heightStr.toInt( &ok );
  1127. if ( ok ) {
  1128. height = relativeHeight * geom.height() / 100;
  1129. }
  1130. }
  1131. else
  1132. {
  1133. height = heightStr.toInt( &ok );
  1134. if ( !ok )
  1135. height = -1;
  1136. }
  1137. return TQSize( width, height );
  1138. }
  1139. void KonqViewManager::loadItem( TDEConfig &cfg, KonqFrameContainerBase *parent,
  1140. const TQString &name, const KURL & defaultURL, bool openURL, bool openAfterCurrentPage )
  1141. {
  1142. TQString prefix;
  1143. if( name != "InitialView" )
  1144. prefix = name + '_';
  1145. //kdDebug(1202) << "KonqViewManager::loadItem: begin name " << name << " openURL " << openURL << endl;
  1146. if( name.startsWith("View") || name == "empty" ) {
  1147. //load view config
  1148. TQString serviceType;
  1149. TQString serviceName;
  1150. if ( name == "empty" ) {
  1151. // An empty profile is an empty TDEHTML part. Makes all TDEHTML actions available, avoids crashes,
  1152. // makes it easy to DND a URL onto it, and makes it fast to load a website from there.
  1153. serviceType = "text/html";
  1154. serviceName = "html";
  1155. } else {
  1156. serviceType = cfg.readEntry( TQString::fromLatin1( "ServiceType" ).prepend( prefix ), "inode/directory");
  1157. serviceName = cfg.readEntry( TQString::fromLatin1( "ServiceName" ).prepend( prefix ) );
  1158. }
  1159. //kdDebug(1202) << "KonqViewManager::loadItem: ServiceType " << serviceType << " " << serviceName << endl;
  1160. KService::Ptr service;
  1161. TDETrader::OfferList partServiceOffers, appServiceOffers;
  1162. KonqViewFactory viewFactory = KonqFactory::createView( serviceType, serviceName, &service, &partServiceOffers, &appServiceOffers, true /*forceAutoEmbed*/ );
  1163. if ( viewFactory.isNull() )
  1164. {
  1165. kdWarning(1202) << "Profile Loading Error: View creation failed" << endl;
  1166. return; //ugh..
  1167. }
  1168. bool passiveMode = cfg.readBoolEntry( TQString::fromLatin1( "PassiveMode" ).prepend( prefix ), false );
  1169. //kdDebug(1202) << "KonqViewManager::loadItem: Creating View Stuff" << endl;
  1170. KonqView *childView = setupView( parent, viewFactory, service, partServiceOffers, appServiceOffers, serviceType, passiveMode, openAfterCurrentPage );
  1171. if (!childView->isFollowActive()) childView->setLinkedView( cfg.readBoolEntry( TQString::fromLatin1( "LinkedView" ).prepend( prefix ), false ) );
  1172. childView->setToggleView( cfg.readBoolEntry( TQString::fromLatin1( "ToggleView" ).prepend( prefix ), false ) );
  1173. if( !cfg.readBoolEntry( TQString::fromLatin1( "ShowStatusBar" ).prepend( prefix ), true ) )
  1174. childView->frame()->statusbar()->hide();
  1175. if (cfg.readBoolEntry( TQString::fromLatin1( "docContainer" ).prepend( prefix ), false ))
  1176. m_pDocContainer = childView->frame();
  1177. if (!m_pDocContainer)
  1178. {
  1179. if (parent->frameType() == "MainWindow")
  1180. m_pDocContainer = childView->frame(); // Child view of mainWindow
  1181. else if (parent->frameType() == "Container")
  1182. {
  1183. KonqFrameContainer* parentContainer = static_cast<KonqFrameContainer*>(parent);
  1184. KonqFrameBase* otherFrame = parentContainer->otherChild( childView->frame() );
  1185. if (otherFrame)
  1186. {
  1187. if (childView->isPassiveMode())
  1188. {
  1189. if (otherFrame->frameType() == "View")
  1190. {
  1191. KonqFrame* viewFrame = static_cast<KonqFrame*>(otherFrame);
  1192. if (viewFrame->childView()->isPassiveMode())
  1193. m_pDocContainer = parentContainer; // Both views are passive, shouldn't happen
  1194. else
  1195. m_pDocContainer = viewFrame; // This one is passive, the other is active
  1196. }
  1197. }
  1198. else
  1199. {
  1200. if (otherFrame->frameType() == "View")
  1201. {
  1202. KonqFrame* viewFrame = static_cast<KonqFrame*>(otherFrame);
  1203. if (viewFrame->childView()->isPassiveMode())
  1204. m_pDocContainer = childView->frame(); // This one is active, the other is passive
  1205. else
  1206. m_pDocContainer = parentContainer; // Both views are active
  1207. }
  1208. else
  1209. m_pDocContainer = parentContainer; // This one is active, the other is a Container
  1210. }
  1211. }
  1212. }
  1213. }
  1214. KonqConfigEvent ev( &cfg, prefix+"_", false/*load*/);
  1215. TQApplication::sendEvent( childView->part(), &ev );
  1216. childView->frame()->show();
  1217. TQString key = TQString::fromLatin1( "URL" ).prepend( prefix );
  1218. if ( openURL )
  1219. {
  1220. KURL url;
  1221. //kdDebug(1202) << "KonqViewManager::loadItem: key " << key << endl;
  1222. if ( cfg.hasKey( key ) )
  1223. {
  1224. TQString u = cfg.readPathEntry( key );
  1225. if ( u.isEmpty() )
  1226. u = TQString::fromLatin1("about:blank");
  1227. url = u;
  1228. }
  1229. else if(key == "empty_URL")
  1230. url = TQString::fromLatin1("about:blank");
  1231. else
  1232. url = defaultURL;
  1233. if ( !url.isEmpty() )
  1234. {
  1235. //kdDebug(1202) << "KonqViewManager::loadItem: calling openURL " << url.prettyURL() << endl;
  1236. //childView->openURL( url, url.prettyURL() );
  1237. // We need view-follows-view (for the dirtree, for instance)
  1238. KonqOpenURLRequest req;
  1239. if (url.protocol() != "about")
  1240. req.typedURL = url.prettyURL();
  1241. m_pMainWindow->openView( serviceType, url, childView, req );
  1242. }
  1243. //else kdDebug(1202) << "KonqViewManager::loadItem: url is empty" << endl;
  1244. }
  1245. // Do this after opening the URL, so that it's actually possible to open it :)
  1246. childView->setLockedLocation( cfg.readBoolEntry( TQString::fromLatin1( "LockedLocation" ).prepend( prefix ), false ) );
  1247. }
  1248. else if( name.startsWith("Container") ) {
  1249. //kdDebug(1202) << "KonqViewManager::loadItem Item is Container" << endl;
  1250. //load container config
  1251. TQString ostr = cfg.readEntry( TQString::fromLatin1( "Orientation" ).prepend( prefix ) );
  1252. //kdDebug(1202) << "Orientation: " << ostr << endl;
  1253. Qt::Orientation o;
  1254. if( ostr == "Vertical" )
  1255. o = Qt::Vertical;
  1256. else if( ostr == "Horizontal" )
  1257. o = Qt::Horizontal;
  1258. else {
  1259. kdWarning() << "Profile Loading Error: No orientation specified in " << name << endl;
  1260. o = Qt::Horizontal;
  1261. }
  1262. TQValueList<int> sizes =
  1263. cfg.readIntListEntry( TQString::fromLatin1( "SplitterSizes" ).prepend( prefix ));
  1264. int index = cfg.readNumEntry( TQString::fromLatin1( "activeChildIndex" ).prepend(prefix), -1 );
  1265. TQStrList childList;
  1266. if( cfg.readListEntry( TQString::fromLatin1( "Children" ).prepend( prefix ), childList ) < 2 )
  1267. {
  1268. kdWarning() << "Profile Loading Error: Less than two children in " << name << endl;
  1269. // fallback to defaults
  1270. loadItem( cfg, parent, "InitialView", defaultURL, openURL );
  1271. }
  1272. else
  1273. {
  1274. KonqFrameContainer *newContainer = new KonqFrameContainer( o, parent->widget(), parent );
  1275. connect(newContainer,TQT_SIGNAL(ctrlTabPressed()),m_pMainWindow,TQT_SLOT(slotCtrlTabPressed()));
  1276. int tabindex = -1;
  1277. if(openAfterCurrentPage && parent->frameType() == "Tabs") // Need to honor it, if possible
  1278. tabindex = static_cast<KonqFrameTabs*>(parent)->currentPageIndex() + 1;
  1279. parent->insertChildFrame( newContainer, tabindex );
  1280. if (cfg.readBoolEntry( TQString::fromLatin1( "docContainer" ).prepend( prefix ), false ))
  1281. m_pDocContainer = newContainer;
  1282. loadItem( cfg, newContainer, childList.at(0), defaultURL, openURL );
  1283. loadItem( cfg, newContainer, childList.at(1), defaultURL, openURL );
  1284. newContainer->setSizes( sizes );
  1285. if (index == 1)
  1286. newContainer->setActiveChild( newContainer->secondChild() );
  1287. else if (index == 0)
  1288. newContainer->setActiveChild( newContainer->firstChild() );
  1289. newContainer->show();
  1290. }
  1291. }
  1292. else if( name.startsWith("Tabs") )
  1293. {
  1294. //kdDebug(1202) << "KonqViewManager::loadItem: Item is a Tabs" << endl;
  1295. KonqFrameTabs *newContainer = new KonqFrameTabs( parent->widget(), parent, this );
  1296. connect(newContainer,TQT_SIGNAL(ctrlTabPressed()),m_pMainWindow,TQT_SLOT(slotCtrlTabPressed()));
  1297. parent->insertChildFrame( newContainer );
  1298. m_pDocContainer = newContainer;
  1299. int index = cfg.readNumEntry( TQString::fromLatin1( "activeChildIndex" ).prepend(prefix), 0 );
  1300. TQStringList childList = cfg.readListEntry( TQString::fromLatin1( "Children" ).prepend( prefix ) );
  1301. for ( TQStringList::Iterator it = childList.begin(); it != childList.end(); ++it )
  1302. {
  1303. loadItem( cfg, newContainer, *it, defaultURL, openURL );
  1304. TQWidget* currentPage = newContainer->currentPage();
  1305. if (currentPage != 0L) {
  1306. KonqView* activeChildView = tqt_dynamic_cast<KonqFrameBase*>(currentPage)->activeChildView();
  1307. if (activeChildView != 0L) {
  1308. activeChildView->setCaption( activeChildView->caption() );
  1309. activeChildView->setTabIcon( activeChildView->url() );
  1310. }
  1311. }
  1312. }
  1313. newContainer->setActiveChild( tqt_dynamic_cast<KonqFrameBase*>(newContainer->page(index)) );
  1314. newContainer->setCurrentPage( index );
  1315. newContainer->show();
  1316. }
  1317. else
  1318. kdWarning() << "Profile Loading Error: Unknown item " << name;
  1319. //kdDebug(1202) << "KonqViewManager::loadItem: end" << name << endl;
  1320. }
  1321. void KonqViewManager::setProfiles( TDEActionMenu *profiles )
  1322. {
  1323. m_pamProfiles = profiles;
  1324. if ( m_pamProfiles )
  1325. {
  1326. connect( m_pamProfiles->popupMenu(), TQT_SIGNAL( activated( int ) ),
  1327. this, TQT_SLOT( slotProfileActivated( int ) ) );
  1328. connect( m_pamProfiles->popupMenu(), TQT_SIGNAL( aboutToShow() ),
  1329. this, TQT_SLOT( slotProfileListAboutToShow() ) );
  1330. }
  1331. //KonqMainWindow::enableAllActions will call it anyway
  1332. //profileListDirty();
  1333. }
  1334. void KonqViewManager::showProfileDlg( const TQString & preselectProfile )
  1335. {
  1336. KonqProfileDlg dlg( this, preselectProfile, m_pMainWindow );
  1337. dlg.exec();
  1338. profileListDirty();
  1339. }
  1340. void KonqViewManager::slotProfileDlg()
  1341. {
  1342. showProfileDlg( TQString::null );
  1343. }
  1344. void KonqViewManager::profileListDirty( bool broadcast )
  1345. {
  1346. //kdDebug(1202) << "KonqViewManager::profileListDirty()" << endl;
  1347. if ( !broadcast )
  1348. {
  1349. m_bProfileListDirty = true;
  1350. // #if 0 causes problems with TDevelop syntax highlighting. Converted to comments
  1351. // #if 0
  1352. // There's always one profile at least, now...
  1353. //TQStringList profiles = KonqFactory::instance()->dirs()->findAllResources( "data", "konqueror/profiles/*", false, true );
  1354. //if ( m_pamProfiles )
  1355. // m_pamProfiles->setEnabled( profiles.count() > 0 );
  1356. // #endif
  1357. return;
  1358. }
  1359. kapp->dcopClient()->send( "konqueror*", "KonquerorIface", "updateProfileList()", TQByteArray() );
  1360. }
  1361. void KonqViewManager::slotProfileActivated( int id )
  1362. {
  1363. TQMap<TQString, TQString>::ConstIterator iter = m_mapProfileNames.begin();
  1364. TQMap<TQString, TQString>::ConstIterator end = m_mapProfileNames.end();
  1365. for(int i=0; iter != end; ++iter, ++i) {
  1366. if( i == id ) {
  1367. KURL u;
  1368. u.setPath( *iter );
  1369. loadViewProfile( *iter, u.fileName() );
  1370. break;
  1371. }
  1372. }
  1373. }
  1374. void KonqViewManager::slotProfileListAboutToShow()
  1375. {
  1376. if ( !m_pamProfiles || !m_bProfileListDirty )
  1377. return;
  1378. TQPopupMenu *popup = m_pamProfiles->popupMenu();
  1379. popup->clear();
  1380. // Fetch profiles
  1381. m_mapProfileNames = KonqProfileDlg::readAllProfiles();
  1382. // Generate accelerators
  1383. TQStringList accel_strings;
  1384. TDEAccelGen::generateFromKeys(m_mapProfileNames, accel_strings);
  1385. // Store menu items
  1386. TQValueListIterator<TQString> iter = accel_strings.begin();
  1387. for( int id = 0;
  1388. iter != accel_strings.end();
  1389. ++iter, ++id ) {
  1390. popup->insertItem( *iter, id );
  1391. }
  1392. m_bProfileListDirty = false;
  1393. }
  1394. void KonqViewManager::setLoading( KonqView *view, bool loading )
  1395. {
  1396. KonqFrameContainerBase* parentContainer = view->frame()->parentContainer();
  1397. if ( parentContainer->frameType() == "Tabs" ) {
  1398. TQColor color;
  1399. KonqFrameTabs* konqframetabs = static_cast<KonqFrameTabs*>( parentContainer );
  1400. if ( loading )
  1401. color = TQColor( (TDEGlobalSettings::linkColor().red() + TDEGlobalSettings::inactiveTextColor().red())/2,
  1402. (TDEGlobalSettings::linkColor().green()+ TDEGlobalSettings::inactiveTextColor().green())/2,
  1403. (TDEGlobalSettings::linkColor().blue() + TDEGlobalSettings::inactiveTextColor().blue())/2 );
  1404. else
  1405. {
  1406. if ( konqframetabs->currentPage() != view->frame() )
  1407. color = TDEGlobalSettings::linkColor();
  1408. else
  1409. color = TDEGlobalSettings::textColor();
  1410. }
  1411. konqframetabs->setTabColor( view->frame(), color );
  1412. }
  1413. }
  1414. void KonqViewManager::showHTML(bool b)
  1415. {
  1416. if (m_pDocContainer == 0L) return;
  1417. if (m_pDocContainer->frameType() != "Tabs") return;
  1418. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(m_pDocContainer);
  1419. TQPtrList<KonqFrameBase> frameList = *tabContainer->childFrameList();
  1420. TQPtrListIterator<KonqFrameBase> it( frameList );
  1421. for ( it.toFirst(); it != 0L; ++it )
  1422. {
  1423. if ( it.current()->activeChildView() && it.current()->activeChildView() !=m_pMainWindow->currentView())
  1424. {
  1425. it.current()->activeChildView()->setAllowHTML( b );
  1426. if( !it.current()->activeChildView()->locationBarURL().isEmpty())
  1427. {
  1428. m_pMainWindow->showHTML( it.current()->activeChildView(), b, false );
  1429. }
  1430. }
  1431. }
  1432. }
  1433. void KonqViewManager::reparseConfiguration()
  1434. {
  1435. KonqFrameTabs *frameTabs=static_cast<KonqFrameTabs*>(m_pDocContainer);
  1436. if (frameTabs)
  1437. {
  1438. frameTabs->setAlwaysTabbedMode(KonqSettings::alwaysTabbedMode());
  1439. frameTabs->setMouseWheelScroll(KonqSettings::tabsCycleWheel());
  1440. }
  1441. }
  1442. ///////////////// Debug stuff ////////////////
  1443. #ifndef NDEBUG
  1444. void KonqViewManager::printSizeInfo( KonqFrameBase* frame,
  1445. KonqFrameContainerBase* parent,
  1446. const char* msg )
  1447. {
  1448. TQRect r;
  1449. r = frame->widget()->geometry();
  1450. tqDebug("Child size %s : x: %d, y: %d, w: %d, h: %d", msg, r.x(),r.y(),r.width(),r.height() );
  1451. if ( parent->frameType() == "Container" )
  1452. {
  1453. TQValueList<int> sizes;
  1454. sizes = static_cast<KonqFrameContainer*>(parent)->sizes();
  1455. printf( "Parent sizes %s :", msg );
  1456. TQValueList<int>::ConstIterator it;
  1457. for( it = sizes.begin(); it != sizes.end(); ++it )
  1458. printf( " %d", (*it) );
  1459. printf("\n");
  1460. }
  1461. }
  1462. void KonqViewManager::printFullHierarchy( KonqFrameContainerBase * container )
  1463. {
  1464. kdDebug(1202) << "currentView=" << m_pMainWindow->currentView() << endl;
  1465. kdDebug(1202) << "docContainer=" << m_pDocContainer << endl;
  1466. if (container) container->printFrameInfo(TQString::null);
  1467. else m_pMainWindow->printFrameInfo(TQString::null);
  1468. }
  1469. #endif
  1470. #include "konq_viewmgr.moc"