delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / konqueror / src / KonquerorAdaptor.cpp
blob465a88a87e81e4553457bdc4718d44921535abef
1 /* This file is part of the KDE project
2 Copyright 1998, 1999 Simon Hausmann <hausmann@kde.org>
3 Copyright 2000, 2006 David Faure <faure@kde.org>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include "KonquerorAdaptor.h"
22 #include "konqmisc.h"
23 #include "KonqMainWindowAdaptor.h"
24 #include "konqmainwindow.h"
25 #include "konqviewmanager.h"
26 #include "konqview.h"
27 #include "konqsettingsxt.h"
28 #include "konqsettings.h"
30 #include <kapplication.h>
31 #include <kdebug.h>
32 #include <kwindowsystem.h>
34 #include <QtCore/QFile>
35 #ifdef Q_WS_X11
36 #include <QX11Info>
37 #include <X11/Xlib.h>
38 #endif
40 // these DBus calls come from outside, so any windows created by these
41 // calls would have old user timestamps (for KWin's no-focus-stealing),
42 // it's better to reset the timestamp and rely on other means
43 // of detecting the time when the user action that triggered all this
44 // happened
45 // TODO a valid timestamp should be passed in the DBus calls that
46 // are not for user scripting
48 KonquerorAdaptor::KonquerorAdaptor()
49 : QObject( kapp )
51 QDBusConnection dbus = QDBusConnection::sessionBus();
52 dbus.registerObject( KONQ_MAIN_PATH, this, QDBusConnection::ExportNonScriptableSlots );
55 KonquerorAdaptor::~KonquerorAdaptor()
59 QDBusObjectPath KonquerorAdaptor::openBrowserWindow( const QString& url, const QByteArray& startup_id )
61 kapp->setStartupId( startup_id );
62 #ifdef Q_WS_X11
63 QX11Info::setAppUserTime( 0 );
64 #endif
65 KonqMainWindow *res = KonqMisc::createSimpleWindow( KUrl(url), KParts::OpenUrlArguments() );
66 if ( !res )
67 return QDBusObjectPath("/");
68 return QDBusObjectPath( res->dbusName() );
71 QDBusObjectPath KonquerorAdaptor::createNewWindow( const QString& url, const QString& mimetype, const QByteArray& startup_id, bool tempFile )
73 kapp->setStartupId( startup_id );
74 #ifdef Q_WS_X11
75 QX11Info::setAppUserTime( 0 );
76 #endif
77 KParts::OpenUrlArguments args;
78 args.setMimeType( mimetype );
79 // Filter the URL, so that "kfmclient openURL gg:foo" works also when konq is already running
80 KUrl finalURL = KonqMisc::konqFilteredURL( 0, url );
81 KonqMainWindow *res = KonqMisc::createNewWindow( finalURL, args, KParts::BrowserArguments(), false, QStringList(), tempFile );
82 if ( !res )
83 return QDBusObjectPath("/");
84 return QDBusObjectPath( res->dbusName() );
87 QDBusObjectPath KonquerorAdaptor::createNewWindowWithSelection( const QString& url, const QStringList& filesToSelect, const QByteArray& startup_id )
89 kapp->setStartupId( startup_id );
90 #ifdef Q_WS_X11
91 QX11Info::setAppUserTime( 0 );
92 #endif
93 KonqMainWindow *res = KonqMisc::createNewWindow( KUrl(url), KParts::OpenUrlArguments(), KParts::BrowserArguments(), false, filesToSelect );
94 if ( !res )
95 return QDBusObjectPath("/");
96 return QDBusObjectPath( res->dbusName() );
99 QDBusObjectPath KonquerorAdaptor::createBrowserWindowFromProfile( const QString& path, const QString& filename, const QByteArray& startup_id )
101 kapp->setStartupId( startup_id );
102 #ifdef Q_WS_X11
103 QX11Info::setAppUserTime( 0 );
104 #endif
105 kDebug(1202) << "void KonquerorAdaptor::createBrowserWindowFromProfile( path, filename ) ";
106 kDebug(1202) << path << "," << filename;
107 KonqMainWindow *res = KonqMisc::createBrowserWindowFromProfile( path, filename );
108 if ( !res )
109 return QDBusObjectPath("/");
110 return QDBusObjectPath( res->dbusName() );
113 QDBusObjectPath KonquerorAdaptor::createBrowserWindowFromProfileAndUrl( const QString& path, const QString& filename, const QString& url, const QByteArray& startup_id )
115 kapp->setStartupId( startup_id );
116 #ifdef Q_WS_X11
117 QX11Info::setAppUserTime( 0 );
118 #endif
119 KonqMainWindow *res = KonqMisc::createBrowserWindowFromProfile( path, filename, KUrl(url) );
120 if ( !res )
121 return QDBusObjectPath("/");
122 return QDBusObjectPath( res->dbusName() );
125 QDBusObjectPath KonquerorAdaptor::createBrowserWindowFromProfileUrlAndMimeType( const QString& path, const QString& filename, const QString& url, const QString& mimetype, const QByteArray& startup_id )
127 kapp->setStartupId( startup_id );
128 #ifdef Q_WS_X11
129 QX11Info::setAppUserTime( 0 );
130 #endif
131 KParts::OpenUrlArguments args;
132 args.setMimeType( mimetype );
133 KonqMainWindow *res = KonqMisc::createBrowserWindowFromProfile( path, filename, KUrl(url), args );
134 if ( !res )
135 return QDBusObjectPath("/");
136 return QDBusObjectPath( res->dbusName() );
139 void KonquerorAdaptor::updateProfileList()
141 QList<KonqMainWindow*> *mainWindows = KonqMainWindow::mainWindowList();
142 if ( !mainWindows )
143 return;
145 foreach ( KonqMainWindow* window, *mainWindows )
146 window->viewManager()->profileListDirty( false );
149 QString KonquerorAdaptor::crashLogFile()
151 return KonqMainWindow::s_crashlog_file->objectName();
154 QList<QDBusObjectPath> KonquerorAdaptor::getWindows()
156 QList<QDBusObjectPath> lst;
157 QList<KonqMainWindow*> *mainWindows = KonqMainWindow::mainWindowList();
158 if ( mainWindows )
160 foreach ( KonqMainWindow* window, *mainWindows )
161 lst.append( QDBusObjectPath( window->dbusName() ) );
163 return lst;
166 QDBusObjectPath KonquerorAdaptor::windowForTab()
168 QList<KonqMainWindow*> *mainWindows = KonqMainWindow::mainWindowList();
169 if ( mainWindows ) {
170 foreach ( KonqMainWindow* window, *mainWindows ) {
171 #ifdef Q_WS_X11
172 KWindowInfo winfo = KWindowSystem::windowInfo( window->winId(), NET::WMDesktop );
173 if( winfo.isOnCurrentDesktop() &&
174 #else
176 #endif
177 !KonqMainWindow::isPreloaded() ) { // we want a tab in an already shown window
178 Q_ASSERT(!window->dbusName().isEmpty());
179 return QDBusObjectPath( window->dbusName() );
183 // We can't use QDBusObjectPath(), dbus type 'o' must be a valid object path.
184 // So we use "/" as an indicator for not found.
185 return QDBusObjectPath("/");
188 bool KonquerorAdaptor::processCanBeReused( int screen )
190 #ifdef Q_WS_X11
191 QX11Info info;
192 if( info.screen() != screen )
193 return false; // this instance run on different screen, and Qt apps can't migrate
194 #endif
195 if( KonqMainWindow::isPreloaded())
196 return false; // will be handled by preloading related code instead
197 QList<KonqMainWindow*>* windows = KonqMainWindow::mainWindowList();
198 if( windows == NULL )
199 return true;
200 QStringList allowed_parts = KonqSettings::safeParts();
201 bool all_parts_allowed = false;
203 if( allowed_parts.count() == 1 && allowed_parts.first() == QLatin1String( "SAFE" ))
205 allowed_parts.clear();
206 // is duplicated in client/kfmclient.cc
207 allowed_parts << QLatin1String( "dolphinpart.desktop" )
208 << QLatin1String( "konq_sidebartng.desktop" );
210 else if( allowed_parts.count() == 1 && allowed_parts.first() == QLatin1String( "ALL" ))
212 allowed_parts.clear();
213 all_parts_allowed = true;
215 if( all_parts_allowed )
216 return true;
217 foreach ( KonqMainWindow* window, *windows )
219 kDebug(1202) << "processCanBeReused: count=" << window->viewCount();
220 const KonqMainWindow::MapViews& views = window->viewMap();
221 foreach ( KonqView* view, views )
223 kDebug(1202) << "processCanBeReused: part=" << view->service()->entryPath() << ", URL=" << view->url().prettyUrl();
224 if( !allowed_parts.contains( view->service()->entryPath()))
225 return false;
228 return true;
231 void KonquerorAdaptor::terminatePreloaded()
233 if( KonqMainWindow::isPreloaded())
234 kapp->exit();
237 #include "KonquerorAdaptor.moc"