1 /* This file is part of the KDE project
2 Copyright (C) 1998, 1999 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.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "konqsessionmanager.h"
21 #include "konqsettingsxt.h"
22 #include "konqmainwindow.h"
23 #include "konqviewmanager.h"
26 #include <kapplication.h>
28 #include <kmessagebox.h>
29 #include <kurifilter.h>
31 #include <kstandarddirs.h>
32 #include <kwindowsystem.h>
33 #include <kprotocolmanager.h>
34 #include <kstartupinfo.h>
35 #include <kiconloader.h>
36 #include <kconfiggroup.h>
39 /**********************************************
43 **********************************************/
45 // Terminates fullscreen-mode for any full-screen window on the current desktop
46 void KonqMisc::abortFullScreenMode()
49 QList
<KonqMainWindow
*> *mainWindows
= KonqMainWindow::mainWindowList();
52 foreach ( KonqMainWindow
* window
, *mainWindows
)
54 if ( window
->fullScreenMode() )
56 KWindowInfo info
= KWindowSystem::windowInfo( window
->winId(), NET::WMDesktop
);
57 if ( info
.valid() && info
.isOnCurrentDesktop() )
58 window
->setWindowState( window
->windowState() & ~Qt::WindowFullScreen
);
65 KonqMainWindow
* KonqMisc::createSimpleWindow( const KUrl
& url
, const KParts::OpenUrlArguments
&args
,
66 const KParts::BrowserArguments
& browserArgs
,
69 abortFullScreenMode();
71 KonqOpenURLRequest req
;
73 req
.browserArgs
= browserArgs
;
74 req
.tempFile
= tempFile
;
75 KonqMainWindow
*win
= new KonqMainWindow
;
76 win
->openUrl( 0L, url
, QString(), req
);
82 KonqMainWindow
* KonqMisc::createNewWindow( const KUrl
&url
, const KParts::OpenUrlArguments
&args
,
83 const KParts::BrowserArguments
& browserArgs
,
84 bool forbidUseHTML
, const QStringList
&filesToSelect
, bool tempFile
, bool openUrl
)
86 //kDebug() << "url=" << url;
87 // For HTTP or html files, use the web browsing profile, otherwise use filemanager profile
88 const QString profileName
= url
.isEmpty() || // e.g. in window.open
89 (!(KProtocolManager::supportsListing(url
)) || // e.g. any HTTP url
90 KMimeType::findByUrl(url
)->name() == "text/html")
91 ? "webbrowsing" : "filemanagement";
93 QString profile
= KStandardDirs::locate( "data", QLatin1String("konqueror/profiles/") + profileName
);
94 return createBrowserWindowFromProfile(profile
, profileName
,
95 url
, args
, browserArgs
,
96 forbidUseHTML
, filesToSelect
, tempFile
, openUrl
);
99 KonqMainWindow
* KonqMisc::createBrowserWindowFromProfile( const QString
& _path
, const QString
&filename
, const KUrl
&url
,
100 const KParts::OpenUrlArguments
&args
,
101 const KParts::BrowserArguments
& browserArgs
,
102 bool forbidUseHTML
, const QStringList
& filesToSelect
, bool tempFile
, bool openUrl
)
105 kDebug(1202) << "path=" << path
<< ", filename=" << filename
<< ", url=" << url
;
106 Q_ASSERT(!path
.isEmpty());
107 // Well the path can be empty when misusing DBUS calls....
109 path
= defaultProfilePath();
111 abortFullScreenMode();
113 KonqOpenURLRequest req
;
115 req
.browserArgs
= browserArgs
;
116 req
.filesToSelect
= filesToSelect
;
117 req
.tempFile
= tempFile
;
119 KonqMainWindow
* mainWindow
;
120 // Ask the user to recover session if appliable
121 if(KonqSessionManager::self()->askUserToRestoreAutosavedAbandonedSessions())
123 QList
<KonqMainWindow
*> *mainWindowList
= KonqMainWindow::mainWindowList();
124 if(mainWindowList
&& !mainWindowList
->isEmpty())
125 mainWindow
= mainWindowList
->first();
126 else // This should never happen but just to be sure
127 mainWindow
= new KonqMainWindow
;
130 mainWindow
->openUrl( 0, url
, QString(), req
);
132 else if( KonqMainWindow::isPreloaded() && KonqMainWindow::preloadedWindow() != NULL
)
134 mainWindow
= KonqMainWindow::preloadedWindow();
136 KStartupInfo::setWindowStartupId( mainWindow
->winId(), kapp
->startupId());
138 KonqMainWindow::setPreloadedWindow( NULL
);
139 KonqMainWindow::setPreloadedFlag( false );
140 mainWindow
->resetWindow();
141 mainWindow
->reparseConfiguration();
142 mainWindow
->viewManager()->loadViewProfileFromFile(path
, filename
, url
, req
, true, openUrl
);
146 KSharedConfigPtr cfg
= KSharedConfig::openConfig(path
, KConfig::SimpleConfig
);
147 const KConfigGroup
profileGroup(cfg
, "Profile");
148 const QString xmluiFile
= profileGroup
.readPathEntry("XMLUIFile","konqueror.rc");
150 mainWindow
= new KonqMainWindow(KUrl(), xmluiFile
);
151 mainWindow
->viewManager()->loadViewProfileFromConfig(cfg
, path
, filename
, url
, req
, false, openUrl
);
154 mainWindow
->setShowHTML( false );
155 mainWindow
->setInitialFrameName( browserArgs
.frameName
);
160 KonqMainWindow
* KonqMisc::newWindowFromHistory( KonqView
* view
, int steps
)
162 int oldPos
= view
->historyIndex();
163 int newPos
= oldPos
+ steps
;
165 const HistoryEntry
* he
= view
->historyAt(newPos
);
169 KonqMainWindow
* mainwindow
= createNewWindow(he
->url
, KParts::OpenUrlArguments(),
170 KParts::BrowserArguments(),
171 false, QStringList(), false, /*openUrl*/false);
174 KonqView
* newView
= mainwindow
->currentView();
179 newView
->copyHistory(view
);
180 newView
->setHistoryIndex(newPos
);
181 newView
->restoreHistory();
185 QString
KonqMisc::konqFilteredURL( QWidget
* parent
, const QString
& _url
, const QString
& _path
)
187 if ( !_url
.startsWith( "about:" ) ) // Don't filter "about:" URLs
189 KUriFilterData
data(_url
);
191 if( !_path
.isEmpty() )
192 data
.setAbsolutePath(_path
);
194 // We do not want to the filter to check for executables
195 // from the location bar.
196 data
.setCheckForExecutables (false);
198 if( KUriFilter::self()->filterUri( data
) )
200 if( data
.uriType() == KUriFilterData::Error
&& !data
.errorMsg().isEmpty() )
202 KMessageBox::sorry( parent
, i18n( data
.errorMsg().toUtf8() ) );
206 return data
.uri().url();
209 else if (_url
!= "about:blank" && _url
!= "about:plugins" && !_url
.startsWith("about:konqueror")) {
212 return _url
; // return the original url if it cannot be filtered.
215 QString
KonqMisc::defaultProfileName()
217 // By default try to open in webbrowser mode. People can use "konqueror ." to get a filemanager.
218 return "webbrowsing";
221 QString
KonqMisc::defaultProfilePath()
223 return KStandardDirs::locate("data", QLatin1String("konqueror/profiles/")+ defaultProfileName());
226 QString
KonqMisc::encodeFilename(QString filename
)
228 return filename
.replace(':', '_');
231 QString
KonqMisc::decodeFilename(QString filename
)
233 return filename
.replace('_', ':');