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.

KonquerorIface.cc 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /* This file is part of the KDE project
  2. Copyright (C) 1998, 1999 Simon Hausmann <hausmann@kde.org>
  3. Copyright (C) 2000 David Faure <faure@kde.org>
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; see the file COPYING. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include "KonquerorIface.h"
  18. #include "konq_misc.h"
  19. #include "KonqMainWindowIface.h"
  20. #include "konq_mainwindow.h"
  21. #include "konq_viewmgr.h"
  22. #include "konq_view.h"
  23. #include <konq_settings.h>
  24. #include <tdeapplication.h>
  25. #include <dcopclient.h>
  26. #include <kdebug.h>
  27. #include <tqfile.h>
  28. #include "konq_settingsxt.h"
  29. // these DCOP calls come from outside, so any windows created by these
  30. // calls would have old user timestamps (for KWin's no-focus-stealing),
  31. // it's better to reset the timestamp and rely on other means
  32. // of detecting the time when the user action that triggered all this
  33. // happened
  34. // TODO a valid timestamp should be passed in the DCOP calls that
  35. // are not for user scripting
  36. #include <X11/Xlib.h>
  37. KonquerorIface::KonquerorIface()
  38. : DCOPObject( "KonquerorIface" )
  39. {
  40. }
  41. KonquerorIface::~KonquerorIface()
  42. {
  43. }
  44. DCOPRef KonquerorIface::openBrowserWindow( const TQString &url )
  45. {
  46. SET_QT_X_USER_TIME(0);
  47. KonqMainWindow *res = KonqMisc::createSimpleWindow( KURL(url) );
  48. if ( !res )
  49. return DCOPRef();
  50. return res->dcopObject();
  51. }
  52. DCOPRef KonquerorIface::openBrowserWindowASN( const TQString &url, const TQCString& startup_id )
  53. {
  54. kapp->setStartupId( startup_id );
  55. return openBrowserWindow( url );
  56. }
  57. DCOPRef KonquerorIface::createNewWindow( const TQString &url )
  58. {
  59. return createNewWindow( url, TQString::null, false );
  60. }
  61. DCOPRef KonquerorIface::createNewWindowASN( const TQString &url, const TQCString& startup_id, bool tempFile )
  62. {
  63. kapp->setStartupId( startup_id );
  64. return createNewWindow( url, TQString::null, tempFile );
  65. }
  66. DCOPRef KonquerorIface::createNewWindowWithSelection( const TQString &url, TQStringList filesToSelect )
  67. {
  68. SET_QT_X_USER_TIME(0);
  69. KonqMainWindow *res = KonqMisc::createNewWindow( KURL(url), KParts::URLArgs(), false, filesToSelect );
  70. if ( !res )
  71. return DCOPRef();
  72. return res->dcopObject();
  73. }
  74. DCOPRef KonquerorIface::createNewWindowWithSelectionASN( const TQString &url, TQStringList filesToSelect, const TQCString &startup_id )
  75. {
  76. kapp->setStartupId( startup_id );
  77. return createNewWindowWithSelection( url, filesToSelect );
  78. }
  79. DCOPRef KonquerorIface::createNewWindow( const TQString &url, const TQString &mimetype, bool tempFile )
  80. {
  81. SET_QT_X_USER_TIME(0);
  82. KParts::URLArgs args;
  83. args.serviceType = mimetype;
  84. // Filter the URL, so that "kfmclient openURL gg:foo" works also when konq is already running
  85. KURL finalURL = KonqMisc::konqFilteredURL( 0, url );
  86. KonqMainWindow *res = KonqMisc::createNewWindow( finalURL, args, false, TQStringList(), tempFile );
  87. if ( !res )
  88. return DCOPRef();
  89. return res->dcopObject();
  90. }
  91. DCOPRef KonquerorIface::createNewWindowASN( const TQString &url, const TQString &mimetype,
  92. const TQCString& startup_id, bool tempFile )
  93. {
  94. kapp->setStartupId( startup_id );
  95. return createNewWindow( url, mimetype, tempFile );
  96. }
  97. DCOPRef KonquerorIface::createBrowserWindowFromProfile( const TQString &path )
  98. {
  99. SET_QT_X_USER_TIME(0);
  100. kdDebug(1202) << "void KonquerorIface::createBrowserWindowFromProfile( const TQString &path ) " << endl;
  101. kdDebug(1202) << path << endl;
  102. KonqMainWindow *res = KonqMisc::createBrowserWindowFromProfile( path, TQString::null );
  103. if ( !res )
  104. return DCOPRef();
  105. return res->dcopObject();
  106. }
  107. DCOPRef KonquerorIface::createBrowserWindowFromProfileASN( const TQString &path, const TQCString& startup_id )
  108. {
  109. kapp->setStartupId( startup_id );
  110. return createBrowserWindowFromProfile( path );
  111. }
  112. DCOPRef KonquerorIface::createBrowserWindowFromProfile( const TQString & path, const TQString &filename )
  113. {
  114. SET_QT_X_USER_TIME(0);
  115. kdDebug(1202) << "void KonquerorIface::createBrowserWindowFromProfile( path, filename ) " << endl;
  116. kdDebug(1202) << path << "," << filename << endl;
  117. KonqMainWindow *res = KonqMisc::createBrowserWindowFromProfile( path, filename );
  118. if ( !res )
  119. return DCOPRef();
  120. return res->dcopObject();
  121. }
  122. DCOPRef KonquerorIface::createBrowserWindowFromProfileASN( const TQString &path, const TQString &filename,
  123. const TQCString& startup_id )
  124. {
  125. kapp->setStartupId( startup_id );
  126. return createBrowserWindowFromProfile( path, filename );
  127. }
  128. DCOPRef KonquerorIface::createBrowserWindowFromProfileAndURL( const TQString & path, const TQString &filename, const TQString &url )
  129. {
  130. SET_QT_X_USER_TIME(0);
  131. KonqMainWindow *res = KonqMisc::createBrowserWindowFromProfile( path, filename, KURL(url) );
  132. if ( !res )
  133. return DCOPRef();
  134. return res->dcopObject();
  135. }
  136. DCOPRef KonquerorIface::createBrowserWindowFromProfileAndURLASN( const TQString & path, const TQString &filename, const TQString &url,
  137. const TQCString& startup_id )
  138. {
  139. kapp->setStartupId( startup_id );
  140. return createBrowserWindowFromProfileAndURL( path, filename, url );
  141. }
  142. DCOPRef KonquerorIface::createBrowserWindowFromProfileAndURL( const TQString &path, const TQString &filename, const TQString &url, const TQString &mimetype )
  143. {
  144. SET_QT_X_USER_TIME(0);
  145. KParts::URLArgs args;
  146. args.serviceType = mimetype;
  147. KonqMainWindow *res = KonqMisc::createBrowserWindowFromProfile( path, filename, KURL(url), args );
  148. if ( !res )
  149. return DCOPRef();
  150. return res->dcopObject();
  151. }
  152. DCOPRef KonquerorIface::createBrowserWindowFromProfileAndURLASN( const TQString & path, const TQString &filename, const TQString &url, const TQString &mimetype,
  153. const TQCString& startup_id )
  154. {
  155. kapp->setStartupId( startup_id );
  156. return createBrowserWindowFromProfileAndURL( path, filename, url, mimetype );
  157. }
  158. void KonquerorIface::reparseConfiguration()
  159. {
  160. TDEGlobal::config()->reparseConfiguration();
  161. KonqFMSettings::reparseConfiguration();
  162. TQPtrList<KonqMainWindow> *mainWindows = KonqMainWindow::mainWindowList();
  163. if ( mainWindows )
  164. {
  165. TQPtrListIterator<KonqMainWindow> it( *mainWindows );
  166. for (; it.current(); ++it )
  167. it.current()->reparseConfiguration();
  168. }
  169. }
  170. void KonquerorIface::updateProfileList()
  171. {
  172. TQPtrList<KonqMainWindow> *mainWindows = KonqMainWindow::mainWindowList();
  173. if ( !mainWindows )
  174. return;
  175. TQPtrListIterator<KonqMainWindow> it( *mainWindows );
  176. for (; it.current(); ++it )
  177. it.current()->viewManager()->profileListDirty( false );
  178. }
  179. TQString KonquerorIface::crashLogFile()
  180. {
  181. return KonqMainWindow::s_crashlog_file->name();
  182. }
  183. TQValueList<DCOPRef> KonquerorIface::getWindows()
  184. {
  185. TQValueList<DCOPRef> lst;
  186. TQPtrList<KonqMainWindow> *mainWindows = KonqMainWindow::mainWindowList();
  187. if ( mainWindows )
  188. {
  189. TQPtrListIterator<KonqMainWindow> it( *mainWindows );
  190. for (; it.current(); ++it )
  191. lst.append( DCOPRef( kapp->dcopClient()->appId(), it.current()->dcopObject()->objId() ) );
  192. }
  193. return lst;
  194. }
  195. void KonquerorIface::addToCombo( TQString url, TQCString objId )
  196. {
  197. KonqMainWindow::comboAction( KonqMainWindow::ComboAdd, url, objId );
  198. }
  199. void KonquerorIface::removeFromCombo( TQString url, TQCString objId )
  200. {
  201. KonqMainWindow::comboAction( KonqMainWindow::ComboRemove, url, objId );
  202. }
  203. void KonquerorIface::comboCleared( TQCString objId )
  204. {
  205. KonqMainWindow::comboAction( KonqMainWindow::ComboClear,
  206. TQString::null, objId );
  207. }
  208. bool KonquerorIface::processCanBeReused( int screen )
  209. {
  210. if( tqt_xscreen() != screen )
  211. return false; // this instance run on different screen, and Qt apps can't migrate
  212. if( KonqMainWindow::isPreloaded())
  213. return false; // will be handled by preloading related code instead
  214. TQPtrList<KonqMainWindow>* windows = KonqMainWindow::mainWindowList();
  215. if( windows == NULL )
  216. return true;
  217. TQStringList allowed_parts = KonqSettings::safeParts();
  218. bool all_parts_allowed = false;
  219. if( allowed_parts.count() == 1 && allowed_parts.first() == TQString::fromLatin1( "SAFE" ))
  220. {
  221. allowed_parts.clear();
  222. // is duplicated in client/kfmclient.cc
  223. allowed_parts << TQString::fromLatin1( "konq_iconview.desktop" )
  224. << TQString::fromLatin1( "konq_multicolumnview.desktop" )
  225. << TQString::fromLatin1( "konq_sidebartng.desktop" )
  226. << TQString::fromLatin1( "konq_infolistview.desktop" )
  227. << TQString::fromLatin1( "konq_treeview.desktop" )
  228. << TQString::fromLatin1( "konq_detailedlistview.desktop" );
  229. }
  230. else if( allowed_parts.count() == 1 && allowed_parts.first() == TQString::fromLatin1( "ALL" ))
  231. {
  232. allowed_parts.clear();
  233. all_parts_allowed = true;
  234. }
  235. if( all_parts_allowed )
  236. return true;
  237. for( TQPtrListIterator<KonqMainWindow> it1( *windows );
  238. it1 != NULL;
  239. ++it1 )
  240. {
  241. kdDebug(1202) << "processCanBeReused: count=" << (*it1)->viewCount() << endl;
  242. const KonqMainWindow::MapViews& views = (*it1)->viewMap();
  243. for( KonqMainWindow::MapViews::ConstIterator it2 = views.begin();
  244. it2 != views.end();
  245. ++it2 )
  246. {
  247. kdDebug(1202) << "processCanBeReused: part=" << (*it2)->service()->desktopEntryPath() << ", URL=" << (*it2)->url().prettyURL() << endl;
  248. if( !allowed_parts.contains( (*it2)->service()->desktopEntryPath()))
  249. return false;
  250. }
  251. }
  252. return true;
  253. }
  254. void KonquerorIface::terminatePreloaded()
  255. {
  256. if( KonqMainWindow::isPreloaded())
  257. kapp->exit();
  258. }