TDE base libraries and programs
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

konq_guiclients.cc 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /* This file is part of the KDE project
  2. Copyright (C) 1998, 1999 Simon Hausmann <hausmann@kde.org>
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; see the file COPYING. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #include <kdebug.h>
  17. #include <tdelocale.h>
  18. #include <tdemenubar.h>
  19. #include "konq_view.h"
  20. #include "konq_settingsxt.h"
  21. #include "konq_frame.h"
  22. #include "konq_guiclients.h"
  23. #include "konq_viewmgr.h"
  24. #include <kiconloader.h>
  25. PopupMenuGUIClient::PopupMenuGUIClient( KonqMainWindow *mainWindow,
  26. const TDETrader::OfferList &embeddingServices,
  27. bool showEmbeddingServices, bool doTabHandling )
  28. {
  29. //giving a name to each guiclient: just for debugging
  30. // (needs delete instance() in the dtor if enabled for good)
  31. //setInstance( new TDEInstance( "PopupMenuGUIClient" ) );
  32. m_mainWindow = mainWindow;
  33. m_doc = TQDomDocument( "kpartgui" );
  34. TQDomElement root = m_doc.createElement( "kpartgui" );
  35. root.setAttribute( "name", "konqueror" );
  36. m_doc.appendChild( root );
  37. TQDomElement menu = m_doc.createElement( "Menu" );
  38. root.appendChild( menu );
  39. menu.setAttribute( "name", "popupmenu" );
  40. if ( !mainWindow->menuBar()->isVisible() )
  41. {
  42. TQDomElement showMenuBarElement = m_doc.createElement( "action" );
  43. showMenuBarElement.setAttribute( "name", "options_show_menubar" );
  44. menu.appendChild( showMenuBarElement );
  45. menu.appendChild( m_doc.createElement( "separator" ) );
  46. }
  47. if ( mainWindow->fullScreenMode() )
  48. {
  49. TQDomElement stopFullScreenElement = m_doc.createElement( "action" );
  50. stopFullScreenElement.setAttribute( "name", "fullscreen" );
  51. menu.appendChild( stopFullScreenElement );
  52. menu.appendChild( m_doc.createElement( "separator" ) );
  53. }
  54. if ( showEmbeddingServices )
  55. {
  56. TDETrader::OfferList::ConstIterator it = embeddingServices.begin();
  57. TDETrader::OfferList::ConstIterator end = embeddingServices.end();
  58. if ( embeddingServices.count() == 1 )
  59. {
  60. KService::Ptr service = *embeddingServices.begin();
  61. addEmbeddingService( menu, 0, i18n( "Preview in %1" ).arg( service->name() ), service );
  62. }
  63. else if ( embeddingServices.count() > 1 )
  64. {
  65. int idx = 0;
  66. TQDomElement subMenu = m_doc.createElement( "menu" );
  67. menu.appendChild( subMenu );
  68. TQDomElement text = m_doc.createElement( "text" );
  69. subMenu.appendChild( text );
  70. text.appendChild( m_doc.createTextNode( i18n( "Preview In" ) ) );
  71. subMenu.setAttribute( "group", "preview" );
  72. subMenu.setAttribute( "name", "preview submenu" );
  73. bool inserted = false;
  74. for (; it != end; ++it, ++idx )
  75. {
  76. addEmbeddingService( subMenu, idx, (*it)->name(), *it );
  77. inserted = true;
  78. }
  79. if ( !inserted ) // oops, if empty then remove the menu :-]
  80. menu.removeChild( menu.namedItem( "menu" ) );
  81. }
  82. }
  83. if ( doTabHandling )
  84. {
  85. TQDomElement openInSameWindow = m_doc.createElement( "action" );
  86. openInSameWindow.setAttribute( "name", "sameview" );
  87. openInSameWindow.setAttribute( "group", "tabhandling" );
  88. menu.appendChild( openInSameWindow );
  89. TQDomElement openInWindow = m_doc.createElement( "action" );
  90. openInWindow.setAttribute( "name", "newview" );
  91. openInWindow.setAttribute( "group", "tabhandling" );
  92. menu.appendChild( openInWindow );
  93. TQDomElement openInTabElement = m_doc.createElement( "action" );
  94. openInTabElement.setAttribute( "name", "openintab" );
  95. openInTabElement.setAttribute( "group", "tabhandling" );
  96. menu.appendChild( openInTabElement );
  97. TQDomElement openInTabFrontElement = m_doc.createElement( "action" );
  98. openInTabFrontElement.setAttribute( "name", "openintabfront" );
  99. openInTabFrontElement.setAttribute( "group", "tabhandling" );
  100. menu.appendChild( openInTabFrontElement );
  101. TQDomElement separatorElement = m_doc.createElement( "separator" );
  102. separatorElement.setAttribute( "group", "tabhandling" );
  103. menu.appendChild( separatorElement );
  104. }
  105. //kdDebug() << k_funcinfo << m_doc.toString() << endl;
  106. setDOMDocument( m_doc );
  107. }
  108. PopupMenuGUIClient::~PopupMenuGUIClient()
  109. {
  110. }
  111. TDEAction *PopupMenuGUIClient::action( const TQDomElement &element ) const
  112. {
  113. TDEAction *res = KXMLGUIClient::action( element );
  114. if ( !res )
  115. res = m_mainWindow->action( element );
  116. return res;
  117. }
  118. void PopupMenuGUIClient::addEmbeddingService( TQDomElement &menu, int idx, const TQString &name, const KService::Ptr &service )
  119. {
  120. TQDomElement action = m_doc.createElement( "action" );
  121. menu.appendChild( action );
  122. TQCString actName;
  123. actName.setNum( idx );
  124. action.setAttribute( "name", TQString::number( idx ) );
  125. action.setAttribute( "group", "preview" );
  126. (void)new TDEAction( name, service->pixmap( TDEIcon::Small ), 0,
  127. TQT_TQOBJECT(m_mainWindow), TQT_SLOT( slotOpenEmbedded() ), actionCollection(), actName );
  128. }
  129. ToggleViewGUIClient::ToggleViewGUIClient( KonqMainWindow *mainWindow )
  130. : TQObject( mainWindow )
  131. {
  132. m_mainWindow = mainWindow;
  133. m_actions.setAutoDelete( true );
  134. TDETrader::OfferList offers = TDETrader::self()->query( "Browser/View" );
  135. TDETrader::OfferList::Iterator it = offers.begin();
  136. while ( it != offers.end() )
  137. {
  138. TQVariant prop = (*it)->property( "X-TDE-BrowserView-Toggable" );
  139. TQVariant orientation = (*it)->property( "X-TDE-BrowserView-ToggableView-Orientation" );
  140. if ( !prop.isValid() || !prop.toBool() ||
  141. !orientation.isValid() || orientation.toString().isEmpty() )
  142. {
  143. offers.remove( it );
  144. it = offers.begin();
  145. }
  146. else
  147. ++it;
  148. }
  149. m_empty = ( offers.count() == 0 );
  150. if ( m_empty )
  151. return;
  152. TDETrader::OfferList::ConstIterator cIt = offers.begin();
  153. TDETrader::OfferList::ConstIterator cEnd = offers.end();
  154. for (; cIt != cEnd; ++cIt )
  155. {
  156. TQString description = i18n( "Show %1" ).arg( (*cIt)->name() );
  157. TQString name = (*cIt)->desktopEntryName();
  158. //kdDebug(1202) << "ToggleViewGUIClient: name=" << name << endl;
  159. TDEToggleAction *action = new TDEToggleAction( description, 0, mainWindow->actionCollection(), name.latin1() );
  160. action->setCheckedState( i18n( "Hide %1" ).arg( (*cIt)->name() ) );
  161. // HACK
  162. if ( (*cIt)->icon() != "unknown" )
  163. action->setIcon( (*cIt)->icon() );
  164. connect( action, TQT_SIGNAL( toggled( bool ) ),
  165. this, TQT_SLOT( slotToggleView( bool ) ) );
  166. m_actions.insert( name, action );
  167. TQVariant orientation = (*cIt)->property( "X-TDE-BrowserView-ToggableView-Orientation" );
  168. bool horizontal = orientation.toString().lower() == "horizontal";
  169. m_mapOrientation.insert( name, horizontal );
  170. }
  171. connect( m_mainWindow, TQT_SIGNAL( viewAdded( KonqView * ) ),
  172. this, TQT_SLOT( slotViewAdded( KonqView * ) ) );
  173. connect( m_mainWindow, TQT_SIGNAL( viewRemoved( KonqView * ) ),
  174. this, TQT_SLOT( slotViewRemoved( KonqView * ) ) );
  175. }
  176. ToggleViewGUIClient::~ToggleViewGUIClient()
  177. {
  178. }
  179. TQPtrList<TDEAction> ToggleViewGUIClient::actions() const
  180. {
  181. TQPtrList<TDEAction> res;
  182. TQDictIterator<TDEAction> it( m_actions );
  183. for (; it.current(); ++it )
  184. res.append( it.current() );
  185. return res;
  186. }
  187. void ToggleViewGUIClient::slotToggleView( bool toggle )
  188. {
  189. TQString serviceName = TQString::fromLatin1( TQT_TQOBJECT_CONST(sender())->name() );
  190. bool horizontal = m_mapOrientation[ serviceName ];
  191. KonqViewManager *viewManager = m_mainWindow->viewManager();
  192. if ( toggle )
  193. {
  194. KonqView *childView = viewManager->splitWindow( horizontal ? Qt::Vertical : Qt::Horizontal,
  195. TQString::fromLatin1( "Browser/View" ),
  196. serviceName,
  197. !horizontal /* vertical = make it first */);
  198. TQValueList<int> newSplitterSizes;
  199. if ( horizontal )
  200. newSplitterSizes << 100 << 30;
  201. else
  202. newSplitterSizes << 30 << 100;
  203. if (!childView || !childView->frame())
  204. return;
  205. // Toggleviews don't need their statusbar
  206. childView->frame()->statusbar()->hide();
  207. KonqFrameContainerBase *newContainer = childView->frame()->parentContainer();
  208. if (newContainer->frameType()=="Container")
  209. static_cast<KonqFrameContainer*>(newContainer)->setSizes( newSplitterSizes );
  210. #if 0 // already done by splitWindow
  211. if ( m_mainWindow->currentView() )
  212. {
  213. TQString locBarURL = m_mainWindow->currentView()->url().prettyURL(); // default one in case it doesn't set it
  214. childView->openURL( m_mainWindow->currentView()->url(), locBarURL );
  215. }
  216. #endif
  217. // If not passive, set as active :)
  218. if (!childView->isPassiveMode())
  219. viewManager->setActivePart( childView->part() );
  220. kdDebug() << "ToggleViewGUIClient::slotToggleView setToggleView(true) on " << childView << endl;
  221. childView->setToggleView( true );
  222. m_mainWindow->viewCountChanged();
  223. }
  224. else
  225. {
  226. TQPtrList<KonqView> viewList;
  227. m_mainWindow->listViews( &viewList );
  228. TQPtrListIterator<KonqView> it( viewList );
  229. for (; it.current(); ++it )
  230. if ( it.current()->service()->desktopEntryName() == serviceName )
  231. // takes care of choosing the new active view, and also calls slotViewRemoved
  232. viewManager->removeView( it.current() );
  233. }
  234. }
  235. void ToggleViewGUIClient::saveConfig( bool add, const TQString &serviceName )
  236. {
  237. // This is used on konqueror's startup....... so it's never used, since
  238. // the TDE menu only contains calls to kfmclient......
  239. // Well, it could be useful again in the future.
  240. // Currently, the profiles save this info.
  241. TQStringList toggableViewsShown = KonqSettings::toggableViewsShown();
  242. if (add)
  243. {
  244. if ( !toggableViewsShown.contains( serviceName ) )
  245. toggableViewsShown.append(serviceName);
  246. }
  247. else
  248. toggableViewsShown.remove(serviceName);
  249. KonqSettings::setToggableViewsShown( toggableViewsShown );
  250. }
  251. void ToggleViewGUIClient::slotViewAdded( KonqView *view )
  252. {
  253. TQString name = view->service()->desktopEntryName();
  254. TDEAction *action = m_actions[ name ];
  255. if ( action )
  256. {
  257. static_cast<TDEToggleAction *>( action )->setChecked( true );
  258. saveConfig( true, name );
  259. // KonqView::isToggleView() is not set yet.. so just check for the orientation
  260. #if 0
  261. TQVariant vert = view->service()->property( "X-TDE-BrowserView-ToggableView-Orientation");
  262. bool vertical = vert.toString().lower() == "vertical";
  263. TQVariant nohead = view->service()->property( "X-TDE-BrowserView-ToggableView-NoHeader");
  264. bool noheader = nohead.isValid() ? nohead.toBool() : false;
  265. // if it is a vertical toggle part, turn on the header.
  266. // this works even when konq loads the view from a profile.
  267. if ( vertical && (!noheader))
  268. {
  269. view->frame()->header()->setText(view->service()->name());
  270. view->frame()->header()->setAction(action);
  271. }
  272. #endif
  273. }
  274. }
  275. void ToggleViewGUIClient::slotViewRemoved( KonqView *view )
  276. {
  277. TQString name = view->service()->desktopEntryName();
  278. TDEAction *action = m_actions[ name ];
  279. if ( action )
  280. {
  281. static_cast<TDEToggleAction *>( action )->setChecked( false );
  282. saveConfig( false, name );
  283. }
  284. }
  285. #include "konq_guiclients.moc"