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"
23 #include "KonqMainWindowAdaptor.h"
24 #include "konqmainwindow.h"
25 #include "konqviewmanager.h"
27 #include "konqsettingsxt.h"
28 #include "konqsettings.h"
30 #include <kapplication.h>
32 #include <kwindowsystem.h>
34 #include <QtCore/QFile>
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
45 // TODO a valid timestamp should be passed in the DBus calls that
46 // are not for user scripting
48 KonquerorAdaptor::KonquerorAdaptor()
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
);
63 QX11Info::setAppUserTime( 0 );
65 KonqMainWindow
*res
= KonqMisc::createSimpleWindow( KUrl(url
), KParts::OpenUrlArguments() );
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
);
75 QX11Info::setAppUserTime( 0 );
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
);
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
);
91 QX11Info::setAppUserTime( 0 );
93 KonqMainWindow
*res
= KonqMisc::createNewWindow( KUrl(url
), KParts::OpenUrlArguments(), KParts::BrowserArguments(), false, filesToSelect
);
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
);
103 QX11Info::setAppUserTime( 0 );
105 kDebug(1202) << "void KonquerorAdaptor::createBrowserWindowFromProfile( path, filename ) ";
106 kDebug(1202) << path
<< "," << filename
;
107 KonqMainWindow
*res
= KonqMisc::createBrowserWindowFromProfile( path
, filename
);
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
);
117 QX11Info::setAppUserTime( 0 );
119 KonqMainWindow
*res
= KonqMisc::createBrowserWindowFromProfile( path
, filename
, KUrl(url
) );
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
);
129 QX11Info::setAppUserTime( 0 );
131 KParts::OpenUrlArguments args
;
132 args
.setMimeType( mimetype
);
133 KonqMainWindow
*res
= KonqMisc::createBrowserWindowFromProfile( path
, filename
, KUrl(url
), args
);
135 return QDBusObjectPath("/");
136 return QDBusObjectPath( res
->dbusName() );
139 void KonquerorAdaptor::updateProfileList()
141 QList
<KonqMainWindow
*> *mainWindows
= KonqMainWindow::mainWindowList();
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();
160 foreach ( KonqMainWindow
* window
, *mainWindows
)
161 lst
.append( QDBusObjectPath( window
->dbusName() ) );
166 QDBusObjectPath
KonquerorAdaptor::windowForTab()
168 QList
<KonqMainWindow
*> *mainWindows
= KonqMainWindow::mainWindowList();
170 foreach ( KonqMainWindow
* window
, *mainWindows
) {
172 KWindowInfo winfo
= KWindowSystem::windowInfo( window
->winId(), NET::WMDesktop
);
173 if( winfo
.isOnCurrentDesktop() &&
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
)
192 if( info
.screen() != screen
)
193 return false; // this instance run on different screen, and Qt apps can't migrate
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
)
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
)
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()))
231 void KonquerorAdaptor::terminatePreloaded()
233 if( KonqMainWindow::isPreloaded())
237 #include "KonquerorAdaptor.moc"