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"
22 #include "konqfactory.h"
23 #include "konqmainwindow.h"
25 #include "konqsettingsxt.h"
27 #include <ktemporaryfile.h>
29 #include <kstandarddirs.h>
31 #include <kcmdlineargs.h>
32 #include <QtCore/QFile>
33 #include <QtGui/QApplication>
34 #include <QtGui/QWidget>
40 #include <QtDBus/QtDBus>
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");
78 KonqMainWindow::s_crashlog_file
= &crashlog_file
;
80 if ( app
.isSessionRestored() )
83 while ( KonqMainWindow::canBeRestored( n
) )
85 QString className
= KXmlGuiWindow::classNameOfToplevel( n
);
86 if( className
== QLatin1String( "KonqMainWindow" ))
87 (new KonqMainWindow() )->restore( n
);
89 kWarning() << "Unknown class " << className
<< " in session saved data!" ;
95 if (args
->isSet("profiles"))
97 QStringList profiles
= KGlobal::dirs()->findAllResources("data", "konqueror/profiles/*", KStandardDirs::NoDuplicates
);
99 for(QStringList::ConstIterator it
= profiles
.begin();
100 it
!= profiles
.end(); ++it
)
103 file
= file
.mid(file
.lastIndexOf('/')+1);
104 printf("%s\n", QFile::encodeName(file
).data());
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
);
116 QStringList filesToSelect
;
117 if (args
->count() == 1)
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
);
127 kurl
.setFileName("");
130 kDebug(1202) << "main() -> createBrowserWindowFromProfile mimeType=" << urlargs
.mimeType();
131 KonqMisc::createBrowserWindowFromProfile( profilePath
, profile
, kurl
, urlargs
, KParts::BrowserArguments(), false, filesToSelect
);
135 if (args
->count() == 0)
137 if (args
->isSet("preload"))
140 if( KonqSettings::maxPreloadCount() > 0 )
142 QDBusInterface
ref( "org.kde.kded", "/modules/konqy_preloader", "org.kde.konqueror.Preloader", QDBusConnection::sessionBus() );
144 QDBusReply
<bool> retVal
= ref
.call( QDBus::Block
, "registerPreloadedKonqy", QDBusConnection::sessionBus().baseService(), info
.screen());
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();
155 return 0; // no preloading
158 return 0; // no preloading
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
);
169 KonqMainWindow
*mainWindow
= new KonqMainWindow( KUrl( QDir::homePath() ) );
173 kDebug(1202) << "main() -> no args";
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
);
184 QStringList filesToSelect
;
186 if (url
.isLocalFile() && QFile::exists(url
.path())) // "konqueror index.html"
189 urlToOpen
= KUrl( KonqMisc::konqFilteredURL(0L, args
->arg(i
)) ); // "konqueror slashdot.org"
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
);
203 urlToOpen
.setFileName("");
206 const bool tempFile
= KCmdLineArgs::isTempFileSet();
207 mainwin
= KonqMisc::createNewWindow( urlToOpen
, urlargs
, KParts::BrowserArguments(), false, filesToSelect
, tempFile
);
209 urlList
+= urlToOpen
;
212 mainwin
->openMultiURL( urlList
);
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();