Add (and install) svg for the new krunner interface.
[kdebase/uwolfer.git] / apps / konqueror / src / konqmain.cpp
blob765c65161adc5585830c4e56ea30efbf39b2388f
1 /* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Simon Hausmann <hausmann@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 "konqapplication.h"
21 #include "konqmisc.h"
22 #include "konqfactory.h"
23 #include "konqmainwindow.h"
24 #include "konqview.h"
25 #include "konqsettingsxt.h"
27 #include <ktemporaryfile.h>
28 #include <klocale.h>
29 #include <kstandarddirs.h>
30 #include <kdebug.h>
31 #include <kcmdlineargs.h>
32 #include <QtCore/QFile>
33 #include <QtGui/QApplication>
34 #include <QtGui/QWidget>
36 #ifdef Q_WS_X11
37 #include <QX11Info>
38 #endif
40 #include <QtDBus/QtDBus>
41 #include <QDir>
43 extern "C" KDE_EXPORT int kdemain( int argc, char **argv )
45 KCmdLineArgs::init( argc, argv, KonqFactory::aboutData() );
48 KCmdLineOptions options;
50 options.add("silent", ki18n("Start without a default window"));
52 options.add("preload", ki18n("Preload for later use"));
54 options.add("profile <profile>", ki18n("Profile to open"));
56 options.add("profiles", ki18n("List available profiles"));
58 options.add("mimetype <mimetype>", ki18n("Mimetype to use for this URL (e.g. text/html or inode/directory)"));
60 options.add("select", ki18n("For URLs that point to files, opens the directory and selects the file, instead of opening the actual file"));
62 options.add("+[URL]", ki18n("Location to open"));
64 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
65 KCmdLineArgs::addTempFileOption();
67 KonquerorApplication app;
68 app.setQuitOnLastWindowClosed(false);
70 KGlobal::locale()->insertCatalog("libkonq"); // needed for apps using libkonq
72 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
74 KTemporaryFile crashlog_file;
75 crashlog_file.setPrefix("konqueror-crash-");
76 crashlog_file.setSuffix(".log");
77 crashlog_file.open();
78 KonqMainWindow::s_crashlog_file = &crashlog_file;
80 if ( app.isSessionRestored() )
82 int n = 1;
83 while ( KonqMainWindow::canBeRestored( n ) )
85 QString className = KXmlGuiWindow::classNameOfToplevel( n );
86 if( className == QLatin1String( "KonqMainWindow" ))
87 (new KonqMainWindow() )->restore( n );
88 else
89 kWarning() << "Unknown class " << className << " in session saved data!" ;
90 n++;
93 else
95 if (args->isSet("profiles"))
97 QStringList profiles = KGlobal::dirs()->findAllResources("data", "konqueror/profiles/*", KStandardDirs::NoDuplicates);
98 profiles.sort();
99 for(QStringList::ConstIterator it = profiles.begin();
100 it != profiles.end(); ++it)
102 QString file = *it;
103 file = file.mid(file.lastIndexOf('/')+1);
104 printf("%s\n", QFile::encodeName(file).data());
107 return 0;
109 if (args->isSet("profile"))
111 QString profile = args->getOption("profile");
112 QString profilePath = profile;
113 if (profile[0] != '/')
114 profilePath = KStandardDirs::locate( "data", QLatin1String("konqueror/profiles/")+profile );
115 QString url;
116 QStringList filesToSelect;
117 if (args->count() == 1)
118 url = args->arg(0);
119 KUrl kurl(url);
120 KParts::OpenUrlArguments urlargs;
121 if (args->isSet("mimetype"))
122 urlargs.setMimeType( args->getOption("mimetype") );
123 if (args->isSet("select")) {
124 QString fn = kurl.fileName(KUrl::ObeyTrailingSlash);
125 if( !fn.isEmpty() ){
126 filesToSelect += fn;
127 kurl.setFileName("");
130 kDebug(1202) << "main() -> createBrowserWindowFromProfile mimeType=" << urlargs.mimeType();
131 KonqMisc::createBrowserWindowFromProfile( profilePath, profile, kurl, urlargs, KParts::BrowserArguments(), false, filesToSelect );
133 else
135 if (args->count() == 0)
137 if (args->isSet("preload"))
139 #ifdef Q_WS_X11
140 if( KonqSettings::maxPreloadCount() > 0 )
142 QDBusInterface ref( "org.kde.kded", "/modules/konqy_preloader", "org.kde.konqueror.Preloader", QDBusConnection::sessionBus() );
143 QX11Info info;
144 QDBusReply<bool> retVal = ref.call( QDBus::Block, "registerPreloadedKonqy", QDBusConnection::sessionBus().baseService(), info.screen());
145 if( !retVal )
146 return 0; // too many preloaded or failed
147 KonqMainWindow* win = new KonqMainWindow; // prepare an empty window too
148 // KonqMainWindow ctor sets always the preloaded flag to false, so create the window before this
149 KonqMainWindow::setPreloadedFlag( true );
150 KonqMainWindow::setPreloadedWindow( win );
151 kDebug(1202) << "Konqy preloaded :" << QDBusConnection::sessionBus().baseService();
153 else
155 return 0; // no preloading
157 #else
158 return 0; // no preloading
159 #endif
161 else if (!args->isSet("silent"))
163 // By default try to open in webbrowser mode. People can use "konqueror ." to get a filemanager.
164 QString profile = "webbrowsing";
165 QString profilePath = KStandardDirs::locate( "data", QLatin1String("konqueror/profiles/")+profile );
166 if ( !profilePath.isEmpty() ) {
167 KonqMisc::createBrowserWindowFromProfile( profilePath, profile );
168 } else {
169 KonqMainWindow *mainWindow = new KonqMainWindow( KUrl( QDir::homePath() ) );
170 mainWindow->show();
173 kDebug(1202) << "main() -> no args";
175 else
177 KUrl::List urlList;
178 KonqMainWindow * mainwin = 0L;
179 for ( int i = 0; i < args->count(); i++ )
181 // KonqMisc::konqFilteredURL doesn't cope with local files... A bit of hackery below
182 KUrl url = args->url(i);
183 KUrl urlToOpen;
184 QStringList filesToSelect;
186 if (url.isLocalFile() && QFile::exists(url.path())) // "konqueror index.html"
187 urlToOpen = url;
188 else
189 urlToOpen = KUrl( KonqMisc::konqFilteredURL(0L, args->arg(i)) ); // "konqueror slashdot.org"
191 if ( !mainwin ) {
192 KParts::OpenUrlArguments urlargs;
193 if (args->isSet("mimetype"))
195 urlargs.setMimeType( args->getOption("mimetype") );
196 kDebug(1202) << "main() : setting mimeType to " << urlargs.mimeType();
198 if (args->isSet("select"))
200 QString fn = urlToOpen.fileName(KUrl::ObeyTrailingSlash);
201 if( !fn.isEmpty() ){
202 filesToSelect += fn;
203 urlToOpen.setFileName("");
206 const bool tempFile = KCmdLineArgs::isTempFileSet();
207 mainwin = KonqMisc::createNewWindow( urlToOpen, urlargs, KParts::BrowserArguments(), false, filesToSelect, tempFile );
208 } else
209 urlList += urlToOpen;
211 if ( mainwin )
212 mainwin->openMultiURL( urlList );
216 args->clear();
218 app.exec();
220 // Delete all KonqMainWindows, so that we don't have
221 // any parts loaded when KLibLoader::cleanUp is called.
222 // Their deletion was postponed in their event()
223 // (and Qt doesn't delete WDestructiveClose widgets on exit anyway :( )
224 while( KonqMainWindow::mainWindowList() != NULL )
225 { // the list will be deleted by last KonqMainWindow
226 delete KonqMainWindow::mainWindowList()->first();
229 return 0;