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_tabs.cc 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /* This file is part of the KDE project
  2. Copyright (C) 2002-2003 Konqueror Developers
  3. 2002-2003 Douglas Hanley <douglash@caltech.edu>
  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,
  15. MA 02110-1301, USA.
  16. */
  17. #include "konq_tabs.h"
  18. #include <tqapplication.h>
  19. #include <tqclipboard.h>
  20. #include <tqptrlist.h>
  21. #include <tqpopupmenu.h>
  22. #include <tqtoolbutton.h>
  23. #include <tqtooltip.h>
  24. #include <kdebug.h>
  25. #include <kiconloader.h>
  26. #include <tdelocale.h>
  27. #include <kurldrag.h>
  28. #include <kstringhandler.h>
  29. #include "konq_frame.h"
  30. #include "konq_view.h"
  31. #include "konq_viewmgr.h"
  32. #include "konq_misc.h"
  33. #include "konq_settingsxt.h"
  34. #include <tdeaccelmanager.h>
  35. #include <konq_pixmapprovider.h>
  36. #include <tdestdaccel.h>
  37. #include <tqtabbar.h>
  38. #include <tqwhatsthis.h>
  39. #include <tqstyle.h>
  40. #define DUPLICATE_ID 3
  41. #define RELOAD_ID 4
  42. #define BREAKOFF_ID 5
  43. #define CLOSETAB_ID 6
  44. #define OTHERTABS_ID 7
  45. #define MOVE_LEFT_ID 8
  46. #define MOVE_RIGHT_ID 9
  47. //###################################################################
  48. KonqFrameTabs::KonqFrameTabs(TQWidget* parent, KonqFrameContainerBase* parentContainer,
  49. KonqViewManager* viewManager, const char * name)
  50. : KTabWidget(parent, name), m_rightWidget(0), m_leftWidget(0), m_alwaysTabBar(false),
  51. m_closeOtherTabsId(0)
  52. {
  53. TDEAcceleratorManager::setNoAccel(this);
  54. TQWhatsThis::add( tabBar(), i18n( "This bar contains the list of currently open tabs. Click on a tab to make it "
  55. "active. The option to show a close button instead of the website icon in the left "
  56. "corner of the tab is configurable. You can also use keyboard shortcuts to "
  57. "navigate through tabs. The text on the tab is the title of the website "
  58. "currently open in it, put your mouse over the tab too see the full title in "
  59. "case it was truncated to fit the tab size." ) );
  60. //kdDebug(1202) << "KonqFrameTabs::KonqFrameTabs()" << endl;
  61. m_pParentContainer = parentContainer;
  62. m_pChildFrameList = new TQPtrList<KonqFrameBase>;
  63. m_pChildFrameList->setAutoDelete(false);
  64. m_pActiveChild = 0L;
  65. m_pViewManager = viewManager;
  66. connect( this, TQT_SIGNAL( currentChanged ( TQWidget * ) ),
  67. this, TQT_SLOT( slotCurrentChanged( TQWidget* ) ) );
  68. m_pPopupMenu = new TQPopupMenu( this );
  69. m_pPopupMenu->insertItem( SmallIcon( "tab_new" ),
  70. i18n("&New Tab"),
  71. m_pViewManager->mainWindow(),
  72. TQT_SLOT( slotAddTab() ),
  73. m_pViewManager->mainWindow()->action("newtab")->shortcut() );
  74. m_pPopupMenu->insertItem( SmallIconSet( "reload" ),
  75. i18n( "&Reload Tab" ),
  76. m_pViewManager->mainWindow(),
  77. TQT_SLOT( slotReloadPopup() ),
  78. m_pViewManager->mainWindow()->action("reload")->shortcut(), RELOAD_ID );
  79. m_pPopupMenu->insertItem( SmallIconSet( "tab_duplicate" ),
  80. i18n("&Duplicate Tab"),
  81. m_pViewManager->mainWindow(),
  82. TQT_SLOT( slotDuplicateTabPopup() ),
  83. m_pViewManager->mainWindow()->action("duplicatecurrenttab")->shortcut(),
  84. DUPLICATE_ID );
  85. m_pPopupMenu->insertItem( SmallIconSet( "tab_breakoff" ),
  86. i18n("D&etach Tab"),
  87. m_pViewManager->mainWindow(),
  88. TQT_SLOT( slotBreakOffTabPopup() ),
  89. m_pViewManager->mainWindow()->action("breakoffcurrenttab")->shortcut(),
  90. BREAKOFF_ID );
  91. m_pPopupMenu->insertSeparator();
  92. m_pPopupMenu->insertItem( SmallIconSet( "tab_move_left" ),
  93. i18n("Move Tab &Left"),
  94. m_pViewManager->mainWindow(),
  95. TQT_SLOT( slotMoveTabLeft() ),
  96. m_pViewManager->mainWindow()->action("tab_move_left")->shortcut(),
  97. MOVE_LEFT_ID );
  98. m_pPopupMenu->insertItem( SmallIconSet( "tab_move_right" ),
  99. i18n("Move Tab &Right"),
  100. m_pViewManager->mainWindow(),
  101. TQT_SLOT( slotMoveTabRight() ),
  102. m_pViewManager->mainWindow()->action("tab_move_right")->shortcut(),
  103. MOVE_RIGHT_ID );
  104. m_pPopupMenu->insertSeparator();
  105. m_pSubPopupMenuTab = new TQPopupMenu( this );
  106. m_pPopupMenu->insertItem( i18n("Other Tabs" ), m_pSubPopupMenuTab, OTHERTABS_ID );
  107. connect( m_pSubPopupMenuTab, TQT_SIGNAL( activated ( int ) ),
  108. this, TQT_SLOT( slotSubPopupMenuTabActivated( int ) ) );
  109. m_pPopupMenu->insertSeparator();
  110. m_pPopupMenu->insertItem( SmallIconSet( "tab_remove" ),
  111. i18n("&Close Tab"),
  112. m_pViewManager->mainWindow(),
  113. TQT_SLOT( slotRemoveTabPopup() ),
  114. m_pViewManager->mainWindow()->action("removecurrenttab")->shortcut(),
  115. CLOSETAB_ID );
  116. connect( this, TQT_SIGNAL( contextMenu( TQWidget *, const TQPoint & ) ),
  117. TQT_SLOT(slotContextMenu( TQWidget *, const TQPoint & ) ) );
  118. connect( this, TQT_SIGNAL( contextMenu( const TQPoint & ) ),
  119. TQT_SLOT(slotContextMenu( const TQPoint & ) ) );
  120. m_MouseMiddleClickClosesTab = KonqSettings::mouseMiddleClickClosesTab();
  121. m_permanentCloseButtons = KonqSettings::permanentCloseButton();
  122. if (m_permanentCloseButtons) {
  123. setHoverCloseButton( true );
  124. setHoverCloseButtonDelayed( false );
  125. }
  126. else
  127. setHoverCloseButton( KonqSettings::hoverCloseButton() );
  128. setTabCloseActivatePrevious( KonqSettings::tabCloseActivatePrevious() );
  129. if (KonqSettings::tabPosition()=="Bottom")
  130. setTabPosition(TQTabWidget::Bottom);
  131. connect( this, TQT_SIGNAL( closeRequest( TQWidget * )), TQT_SLOT(slotCloseRequest( TQWidget * )));
  132. connect( this, TQT_SIGNAL( removeTabPopup() ),
  133. m_pViewManager->mainWindow(), TQT_SLOT( slotRemoveTabPopup() ) );
  134. if ( KonqSettings::addTabButton() ) {
  135. m_leftWidget = new TQToolButton( this );
  136. connect( m_leftWidget, TQT_SIGNAL( clicked() ),
  137. m_pViewManager->mainWindow(), TQT_SLOT( slotAddTab() ) );
  138. m_leftWidget->setIconSet( SmallIcon( "tab_new" ) );
  139. m_leftWidget->adjustSize();
  140. TQToolTip::add(m_leftWidget, i18n("Open a new tab"));
  141. setCornerWidget( m_leftWidget, TopLeft );
  142. }
  143. if ( KonqSettings::closeTabButton() ) {
  144. m_rightWidget = new TQToolButton( this );
  145. connect( m_rightWidget, TQT_SIGNAL( clicked() ),
  146. m_pViewManager->mainWindow(), TQT_SLOT( slotRemoveTab() ) );
  147. m_rightWidget->setIconSet( SmallIconSet( "tab_remove" ) );
  148. m_rightWidget->adjustSize();
  149. TQToolTip::add(m_rightWidget, i18n("Close the current tab"));
  150. setCornerWidget( m_rightWidget, TopRight );
  151. }
  152. setAutomaticResizeTabs( true );
  153. setTabReorderingEnabled( true );
  154. connect( this, TQT_SIGNAL( movedTab( int, int ) ),
  155. TQT_SLOT( slotMovedTab( int, int ) ) );
  156. connect( this, TQT_SIGNAL( mouseMiddleClick() ),
  157. TQT_SLOT( slotMouseMiddleClick() ) );
  158. connect( this, TQT_SIGNAL( mouseMiddleClick( TQWidget * ) ),
  159. TQT_SLOT( slotMouseMiddleClick( TQWidget * ) ) );
  160. connect( this, TQT_SIGNAL( mouseDoubleClick() ),
  161. m_pViewManager->mainWindow(), TQT_SLOT( slotAddTab() ) );
  162. connect( this, TQT_SIGNAL( testCanDecode(const TQDragMoveEvent *, bool & )),
  163. TQT_SLOT( slotTestCanDecode(const TQDragMoveEvent *, bool & ) ) );
  164. connect( this, TQT_SIGNAL( receivedDropEvent( TQDropEvent * )),
  165. TQT_SLOT( slotReceivedDropEvent( TQDropEvent * ) ) );
  166. connect( this, TQT_SIGNAL( receivedDropEvent( TQWidget *, TQDropEvent * )),
  167. TQT_SLOT( slotReceivedDropEvent( TQWidget *, TQDropEvent * ) ) );
  168. connect( this, TQT_SIGNAL( initiateDrag( TQWidget * )),
  169. TQT_SLOT( slotInitiateDrag( TQWidget * ) ) );
  170. setMouseWheelScroll(KonqSettings::tabsCycleWheel());
  171. }
  172. KonqFrameTabs::~KonqFrameTabs()
  173. {
  174. //kdDebug(1202) << "KonqFrameTabs::~KonqFrameTabs() " << this << " - " << className() << endl;
  175. m_pChildFrameList->setAutoDelete(true);
  176. delete m_pChildFrameList;
  177. }
  178. void KonqFrameTabs::listViews( ChildViewList *viewList ) {
  179. for( TQPtrListIterator<KonqFrameBase> it( *m_pChildFrameList ); *it; ++it )
  180. it.current()->listViews(viewList);
  181. }
  182. void KonqFrameTabs::saveConfig( TDEConfig* config, const TQString &prefix, bool saveURLs,
  183. KonqFrameBase* docContainer, int id, int depth )
  184. {
  185. //write children
  186. TQStringList strlst;
  187. int i = 0;
  188. TQString newPrefix;
  189. for (KonqFrameBase* it = m_pChildFrameList->first(); it; it = m_pChildFrameList->next())
  190. {
  191. newPrefix = TQString::fromLatin1( it->frameType() ) + "T" + TQString::number(i);
  192. strlst.append( newPrefix );
  193. newPrefix.append( '_' );
  194. it->saveConfig( config, newPrefix, saveURLs, docContainer, id, depth + i );
  195. i++;
  196. }
  197. config->writeEntry( TQString::fromLatin1( "Children" ).prepend( prefix ), strlst );
  198. config->writeEntry( TQString::fromLatin1( "activeChildIndex" ).prepend( prefix ),
  199. currentPageIndex() );
  200. }
  201. void KonqFrameTabs::copyHistory( KonqFrameBase *other )
  202. {
  203. if( other->frameType() != "Tabs" ) {
  204. kdDebug(1202) << "Frame types are not the same" << endl;
  205. return;
  206. }
  207. for (uint i = 0; i < m_pChildFrameList->count(); i++ )
  208. {
  209. m_pChildFrameList->at(i)->copyHistory( static_cast<KonqFrameTabs *>( other )->m_pChildFrameList->at(i) );
  210. }
  211. }
  212. void KonqFrameTabs::printFrameInfo( const TQString& spaces )
  213. {
  214. kdDebug(1202) << spaces << "KonqFrameTabs " << this << " visible="
  215. << TQString("%1").arg(isVisible()) << " activeChild="
  216. << m_pActiveChild << endl;
  217. if (!m_pActiveChild)
  218. kdDebug(1202) << "WARNING: " << this << " has a null active child!" << endl;
  219. KonqFrameBase* child;
  220. int childFrameCount = m_pChildFrameList->count();
  221. for (int i = 0 ; i < childFrameCount ; i++) {
  222. child = m_pChildFrameList->at(i);
  223. if (child != 0L)
  224. child->printFrameInfo(spaces + " ");
  225. else
  226. kdDebug(1202) << spaces << " Null child" << endl;
  227. }
  228. }
  229. void KonqFrameTabs::reparentFrame( TQWidget* parent, const TQPoint & p, bool showIt )
  230. {
  231. TQWidget::reparent( parent, p, showIt );
  232. }
  233. void KonqFrameTabs::setTitle( const TQString &title , TQWidget* sender)
  234. {
  235. // kdDebug(1202) << "KonqFrameTabs::setTitle( " << title << " , " << sender << " )" << endl;
  236. setTabLabel( sender,title );
  237. }
  238. void KonqFrameTabs::setTabIcon( const KURL &url, TQWidget* sender )
  239. {
  240. //kdDebug(1202) << "KonqFrameTabs::setTabIcon( " << url << " , " << sender << " )" << endl;
  241. TQIconSet iconSet;
  242. if (m_permanentCloseButtons)
  243. iconSet = SmallIcon( "window-close" );
  244. else
  245. iconSet = SmallIconSet( KonqPixmapProvider::self()->iconNameFor( url.url() ) );
  246. if (tabIconSet( sender ).pixmap().serialNumber() != iconSet.pixmap().serialNumber())
  247. setTabIconSet( sender, iconSet );
  248. }
  249. void KonqFrameTabs::activateChild()
  250. {
  251. if (m_pActiveChild)
  252. {
  253. showPage( m_pActiveChild->widget() );
  254. m_pActiveChild->activateChild();
  255. }
  256. }
  257. void KonqFrameTabs::insertChildFrame( KonqFrameBase* frame, int index )
  258. {
  259. //kdDebug(1202) << "KonqFrameTabs " << this << ": insertChildFrame " << frame << endl;
  260. if (frame)
  261. {
  262. //kdDebug(1202) << "Adding frame" << endl;
  263. bool showTabBar = (count() == 1);
  264. insertTab(frame->widget(),"", index);
  265. frame->setParentContainer(this);
  266. if (index == -1) m_pChildFrameList->append(frame);
  267. else m_pChildFrameList->insert(index, frame);
  268. if (m_rightWidget)
  269. m_rightWidget->setEnabled( m_pChildFrameList->count()>1 );
  270. KonqView* activeChildView = frame->activeChildView();
  271. if (activeChildView != 0L) {
  272. activeChildView->setCaption( activeChildView->caption() );
  273. activeChildView->setTabIcon( activeChildView->url() );
  274. }
  275. if (showTabBar)
  276. setTabBarHidden(false);
  277. else if ( count() == 1 )
  278. this->hideTabBar();//the first frame inserted (initialization)
  279. }
  280. else
  281. kdWarning(1202) << "KonqFrameTabs " << this << ": insertChildFrame(0L) !" << endl;
  282. }
  283. void KonqFrameTabs::removeChildFrame( KonqFrameBase * frame )
  284. {
  285. //kdDebug(1202) << "KonqFrameTabs::RemoveChildFrame " << this << ". Child " << frame << " removed" << endl;
  286. if (frame) {
  287. removePage(frame->widget());
  288. m_pChildFrameList->remove(frame);
  289. if (m_rightWidget)
  290. m_rightWidget->setEnabled( m_pChildFrameList->count()>1 );
  291. if (count() == 1)
  292. hideTabBar();
  293. }
  294. else
  295. kdWarning(1202) << "KonqFrameTabs " << this << ": removeChildFrame(0L) !" << endl;
  296. //kdDebug(1202) << "KonqFrameTabs::RemoveChildFrame finished" << endl;
  297. }
  298. void KonqFrameTabs::slotCurrentChanged( TQWidget* newPage )
  299. {
  300. setTabColor( newPage, TDEGlobalSettings::textColor() );
  301. KonqFrameBase* currentFrame = tqt_dynamic_cast<KonqFrameBase*>(newPage);
  302. if (currentFrame && !m_pViewManager->isLoadingProfile()) {
  303. m_pActiveChild = currentFrame;
  304. currentFrame->activateChild();
  305. }
  306. }
  307. void KonqFrameTabs::moveTabBackward( int index )
  308. {
  309. if ( index == 0 )
  310. return;
  311. moveTab( index, index-1 );
  312. }
  313. void KonqFrameTabs::moveTabForward( int index )
  314. {
  315. if ( index == count()-1 )
  316. return;
  317. moveTab( index, index+1 );
  318. }
  319. void KonqFrameTabs::slotMovedTab( int from, int to )
  320. {
  321. KonqFrameBase* fromFrame = m_pChildFrameList->at( from );
  322. m_pChildFrameList->remove( fromFrame );
  323. m_pChildFrameList->insert( to, fromFrame );
  324. KonqFrameBase* currentFrame = tqt_dynamic_cast<KonqFrameBase*>( currentPage() );
  325. if ( currentFrame && !m_pViewManager->isLoadingProfile() ) {
  326. m_pActiveChild = currentFrame;
  327. currentFrame->activateChild();
  328. }
  329. }
  330. void KonqFrameTabs::slotContextMenu( const TQPoint &p )
  331. {
  332. refreshSubPopupMenuTab();
  333. m_pPopupMenu->setItemEnabled( RELOAD_ID, false );
  334. m_pPopupMenu->setItemEnabled( DUPLICATE_ID, false );
  335. m_pPopupMenu->setItemEnabled( BREAKOFF_ID, false );
  336. uint tabCount = m_pChildFrameList->count();
  337. KonqView *kview = m_pViewManager->mainWindow()->currentView();
  338. if (tabCount>1 && kview)
  339. {
  340. // Move tab left
  341. bool left_enable = false, right_enable = false;
  342. if (TQApplication::reverseLayout())
  343. {
  344. left_enable = (kview->frame() != m_pChildFrameList->last());
  345. right_enable= (kview->frame() != m_pChildFrameList->first());
  346. }
  347. else
  348. {
  349. left_enable = (kview->frame() != m_pChildFrameList->first());
  350. right_enable= (kview->frame() != m_pChildFrameList->last());
  351. }
  352. m_pPopupMenu->setItemEnabled( MOVE_LEFT_ID, left_enable);
  353. m_pPopupMenu->setItemEnabled( MOVE_RIGHT_ID, right_enable);
  354. }
  355. else
  356. {
  357. m_pPopupMenu->setItemEnabled(MOVE_LEFT_ID, false);
  358. m_pPopupMenu->setItemEnabled(MOVE_RIGHT_ID, false);
  359. }
  360. m_pPopupMenu->setItemEnabled( CLOSETAB_ID, false );
  361. m_pPopupMenu->setItemEnabled( OTHERTABS_ID, true );
  362. m_pSubPopupMenuTab->setItemEnabled( m_closeOtherTabsId, false );
  363. m_pPopupMenu->exec( p );
  364. }
  365. void KonqFrameTabs::slotContextMenu( TQWidget *w, const TQPoint &p )
  366. {
  367. refreshSubPopupMenuTab();
  368. uint tabCount = m_pChildFrameList->count();
  369. m_pPopupMenu->setItemEnabled( RELOAD_ID, true );
  370. m_pPopupMenu->setItemEnabled( DUPLICATE_ID, true );
  371. m_pPopupMenu->setItemEnabled( BREAKOFF_ID, tabCount>1 );
  372. KonqView *kview = m_pViewManager->mainWindow()->currentView();
  373. if (tabCount>1 && kview)
  374. {
  375. // Move tab left
  376. bool left_enable = false, right_enable = false;
  377. if (TQApplication::reverseLayout())
  378. {
  379. left_enable = (kview->frame() != m_pChildFrameList->last());
  380. right_enable= (kview->frame() != m_pChildFrameList->first());
  381. }
  382. else
  383. {
  384. left_enable = (kview->frame() != m_pChildFrameList->first());
  385. right_enable= (kview->frame() != m_pChildFrameList->last());
  386. }
  387. m_pPopupMenu->setItemEnabled( MOVE_LEFT_ID, left_enable);
  388. m_pPopupMenu->setItemEnabled( MOVE_RIGHT_ID, right_enable);
  389. }
  390. else
  391. {
  392. m_pPopupMenu->setItemEnabled(MOVE_LEFT_ID, false);
  393. m_pPopupMenu->setItemEnabled(MOVE_RIGHT_ID, false);
  394. }
  395. m_pPopupMenu->setItemEnabled( CLOSETAB_ID, tabCount>1 );
  396. m_pPopupMenu->setItemEnabled( OTHERTABS_ID, tabCount>1 );
  397. m_pSubPopupMenuTab->setItemEnabled( m_closeOtherTabsId, true );
  398. // Yes, I know this is an unchecked tqt_dynamic_cast - I'm casting sideways in a
  399. // class hierarchy and it could crash one day, but I haven't checked
  400. // setWorkingTab so I don't know if it can handle nulls.
  401. m_pViewManager->mainWindow()->setWorkingTab( tqt_dynamic_cast<KonqFrameBase*>(w) );
  402. m_pPopupMenu->exec( p );
  403. }
  404. void KonqFrameTabs::refreshSubPopupMenuTab()
  405. {
  406. m_pSubPopupMenuTab->clear();
  407. int i=0;
  408. m_pSubPopupMenuTab->insertItem( SmallIcon( "reload_all_tabs" ),
  409. i18n( "&Reload All Tabs" ),
  410. m_pViewManager->mainWindow(),
  411. TQT_SLOT( slotReloadAllTabs() ),
  412. m_pViewManager->mainWindow()->action("reload_all_tabs")->shortcut() );
  413. m_pSubPopupMenuTab->insertSeparator();
  414. for (KonqFrameBase* it = m_pChildFrameList->first(); it; it = m_pChildFrameList->next())
  415. {
  416. KonqFrame* frame = dynamic_cast<KonqFrame *>(it);
  417. if ( frame && frame->activeChildView() )
  418. {
  419. TQString title = frame->title().stripWhiteSpace();
  420. if ( title.isEmpty() )
  421. title = frame->activeChildView()->url().url();
  422. title = KStringHandler::csqueeze( title, 50 );
  423. m_pSubPopupMenuTab->insertItem( TQIconSet( KonqPixmapProvider::self()->pixmapFor( frame->activeChildView()->url().url() ) ), title, i );
  424. }
  425. i++;
  426. }
  427. m_pSubPopupMenuTab->insertSeparator();
  428. m_closeOtherTabsId =
  429. m_pSubPopupMenuTab->insertItem( SmallIconSet( "tab_remove_other" ),
  430. i18n( "Close &Other Tabs" ),
  431. m_pViewManager->mainWindow(),
  432. TQT_SLOT( slotRemoveOtherTabsPopup() ),
  433. m_pViewManager->mainWindow()->action("removeothertabs")->shortcut() );
  434. }
  435. void KonqFrameTabs::slotCloseRequest( TQWidget *w )
  436. {
  437. if ( m_pChildFrameList->count() > 1 ) {
  438. // Yes, I know this is an unchecked tqt_dynamic_cast - I'm casting sideways in a class hierarchy and it could crash one day, but I haven't checked setWorkingTab so I don't know if it can handle nulls.
  439. m_pViewManager->mainWindow()->setWorkingTab( tqt_dynamic_cast<KonqFrameBase*>(w) );
  440. emit ( removeTabPopup() );
  441. }
  442. }
  443. void KonqFrameTabs::slotSubPopupMenuTabActivated( int _id)
  444. {
  445. setCurrentPage( _id );
  446. }
  447. void KonqFrameTabs::slotMouseMiddleClick()
  448. {
  449. TQApplication::clipboard()->setSelectionMode( TQClipboard::Selection );
  450. KURL filteredURL ( KonqMisc::konqFilteredURL( this, TQApplication::clipboard()->text() ) );
  451. if ( !filteredURL.isEmpty() ) {
  452. KonqView* newView = m_pViewManager->addTab(TQString::null, TQString::null, false, false);
  453. if (newView == 0L) return;
  454. m_pViewManager->mainWindow()->openURL( newView, filteredURL, TQString::null );
  455. m_pViewManager->showTab( newView );
  456. m_pViewManager->mainWindow()->focusLocationBar();
  457. }
  458. }
  459. void KonqFrameTabs::slotMouseMiddleClick( TQWidget *w )
  460. {
  461. if ( m_MouseMiddleClickClosesTab ) {
  462. if ( m_pChildFrameList->count() > 1 ) {
  463. // Yes, I know this is an unchecked tqt_dynamic_cast - I'm casting sideways in a class hierarchy and it could crash one day, but I haven't checked setWorkingTab so I don't know if it can handle nulls.
  464. m_pViewManager->mainWindow()->setWorkingTab( tqt_dynamic_cast<KonqFrameBase*>(w) );
  465. emit ( removeTabPopup() );
  466. }
  467. }
  468. else {
  469. TQApplication::clipboard()->setSelectionMode( TQClipboard::Selection );
  470. KURL filteredURL ( KonqMisc::konqFilteredURL( this, TQApplication::clipboard()->text() ) );
  471. if ( !filteredURL.isEmpty() ) {
  472. KonqFrameBase* frame = tqt_dynamic_cast<KonqFrameBase*>(w);
  473. if (frame) {
  474. m_pViewManager->mainWindow()->openURL( frame->activeChildView(), filteredURL );
  475. }
  476. }
  477. }
  478. }
  479. void KonqFrameTabs::slotTestCanDecode(const TQDragMoveEvent *e, bool &accept /* result */)
  480. {
  481. accept = KURLDrag::canDecode( e );
  482. }
  483. void KonqFrameTabs::slotReceivedDropEvent( TQDropEvent *e )
  484. {
  485. KURL::List lstDragURLs;
  486. bool ok = KURLDrag::decode( e, lstDragURLs );
  487. if ( ok && lstDragURLs.first().isValid() ) {
  488. KonqView* newView = m_pViewManager->addTab(TQString::null, TQString::null, false, false);
  489. if (newView == 0L) return;
  490. m_pViewManager->mainWindow()->openURL( newView, lstDragURLs.first(), TQString::null );
  491. m_pViewManager->showTab( newView );
  492. m_pViewManager->mainWindow()->focusLocationBar();
  493. }
  494. }
  495. void KonqFrameTabs::slotReceivedDropEvent( TQWidget *w, TQDropEvent *e )
  496. {
  497. KURL::List lstDragURLs;
  498. bool ok = KURLDrag::decode( e, lstDragURLs );
  499. KonqFrameBase* frame = tqt_dynamic_cast<KonqFrameBase*>(w);
  500. if ( ok && lstDragURLs.first().isValid() && frame ) {
  501. KURL lstDragURL = lstDragURLs.first();
  502. if ( lstDragURL != frame->activeChildView()->url() )
  503. m_pViewManager->mainWindow()->openURL( frame->activeChildView(), lstDragURL );
  504. }
  505. }
  506. void KonqFrameTabs::slotInitiateDrag( TQWidget *w )
  507. {
  508. KonqFrameBase* frame = tqt_dynamic_cast<KonqFrameBase*>( w );
  509. if (frame) {
  510. KURL::List lst;
  511. lst.append( frame->activeChildView()->url() );
  512. KURLDrag *d = new KURLDrag( lst, this );
  513. d->setPixmap( KMimeType::pixmapForURL( lst.first(), 0, TDEIcon::Small ) );
  514. d->dragCopy();
  515. }
  516. }
  517. void KonqFrameTabs::hideTabBar()
  518. {
  519. if ( !m_alwaysTabBar ) {
  520. setTabBarHidden(true);
  521. }
  522. m_pPopupMenu->setItemEnabled( BREAKOFF_ID, false );
  523. m_pPopupMenu->setItemEnabled( MOVE_LEFT_ID, false );
  524. m_pPopupMenu->setItemEnabled( MOVE_RIGHT_ID, false );
  525. m_pPopupMenu->setItemEnabled( CLOSETAB_ID, false );
  526. }
  527. void KonqFrameTabs::setAlwaysTabbedMode( bool enable )
  528. {
  529. bool update = ( enable != m_alwaysTabBar );
  530. m_alwaysTabBar = enable;
  531. if ( update ) {
  532. if ( m_alwaysTabBar )
  533. setTabBarHidden(false);
  534. else
  535. hideTabBar();
  536. }
  537. }
  538. #include "konq_tabs.moc"