You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
223 lines
8.4 KiB
223 lines
8.4 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 1998, 1999 Simon Hausmann <hausmann@kde.org>
|
||
|
|
||
|
This program is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; see the file COPYING. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "konq_main.h"
|
||
|
#include "konq_misc.h"
|
||
|
#include "konq_factory.h"
|
||
|
#include "konq_mainwindow.h"
|
||
|
#include "konq_view.h"
|
||
|
#include "konq_settingsxt.h"
|
||
|
#include "KonquerorIface.h"
|
||
|
|
||
12 years ago
|
#include <tdetempfile.h>
|
||
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <kstandarddirs.h>
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdecmdlineargs.h>
|
||
15 years ago
|
#include <dcopclient.h>
|
||
|
#include <kimageio.h>
|
||
14 years ago
|
#include <tqfile.h>
|
||
15 years ago
|
|
||
14 years ago
|
#include <tqwidgetlist.h>
|
||
15 years ago
|
|
||
12 years ago
|
static const TDECmdLineOptions options[] =
|
||
15 years ago
|
{
|
||
|
{ "silent", I18N_NOOP("Start without a default window"), 0 },
|
||
|
{ "preload", I18N_NOOP("Preload for later use"), 0 },
|
||
|
{ "profile <profile>", I18N_NOOP("Profile to open"), 0 },
|
||
|
{ "profiles", I18N_NOOP("List available profiles"), 0 },
|
||
|
{ "mimetype <mimetype>", I18N_NOOP("Mimetype to use for this URL (e.g. text/html or inode/directory)"), 0 },
|
||
|
{ "select", I18N_NOOP("For URLs that point to files, opens the directory and selects the file, instead of opening the actual file"), 0 },
|
||
|
{ "+[URL]", I18N_NOOP("Location to open"), 0 },
|
||
12 years ago
|
TDECmdLineLastOption
|
||
15 years ago
|
};
|
||
|
|
||
|
extern "C" KDE_EXPORT int kdemain( int argc, char **argv )
|
||
|
{
|
||
12 years ago
|
TDECmdLineArgs::init( argc, argv, KonqFactory::aboutData() );
|
||
15 years ago
|
|
||
12 years ago
|
TDECmdLineArgs::addCmdLineOptions( options ); // Add our own options.
|
||
|
TDECmdLineArgs::addTempFileOption();
|
||
15 years ago
|
|
||
|
KonquerorApplication app;
|
||
|
|
||
|
app.dcopClient()->registerAs( "konqueror" );
|
||
|
|
||
|
KonquerorIface *kiface = new KonquerorIface;
|
||
|
app.dcopClient()->setDefaultObject( kiface->objId() );
|
||
|
|
||
12 years ago
|
TDEGlobal::locale()->insertCatalogue("libkonq"); // needed for apps using libkonq
|
||
15 years ago
|
KImageIO::registerFormats();
|
||
|
|
||
12 years ago
|
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
|
||
15 years ago
|
|
||
|
KTempFile crashlog_file(locateLocal("tmp", "konqueror-crash-"), ".log");
|
||
|
KonqMainWindow::s_crashlog_file = crashlog_file.file();
|
||
|
|
||
|
if ( kapp->isRestored() )
|
||
|
{
|
||
|
int n = 1;
|
||
|
while ( KonqMainWindow::canBeRestored( n ) )
|
||
|
{
|
||
12 years ago
|
TQString className = TDEMainWindow::classNameOfToplevel( n );
|
||
13 years ago
|
if( className == TQString::fromLatin1( "KonqMainWindow" ))
|
||
15 years ago
|
(new KonqMainWindow( KURL(), false ) )->restore( n );
|
||
|
else
|
||
|
kdWarning() << "Unknown class " << className << " in session saved data!" << endl;
|
||
|
n++;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (args->isSet("profiles"))
|
||
|
{
|
||
12 years ago
|
TQStringList profiles = TDEGlobal::dirs()->findAllResources("data", "konqueror/profiles/*", false, true);
|
||
15 years ago
|
profiles.sort();
|
||
14 years ago
|
for(TQStringList::ConstIterator it = profiles.begin();
|
||
15 years ago
|
it != profiles.end(); ++it)
|
||
|
{
|
||
14 years ago
|
TQString file = *it;
|
||
13 years ago
|
file = file.mid(file.findRev('/')+1);
|
||
14 years ago
|
printf("%s\n", TQFile::encodeName(file).data());
|
||
15 years ago
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
if (args->isSet("profile"))
|
||
|
{
|
||
14 years ago
|
TQString profile = TQString::fromLocal8Bit(args->getOption("profile"));
|
||
|
TQString profilePath = profile;
|
||
15 years ago
|
if (profile[0] != '/')
|
||
13 years ago
|
profilePath = locate( "data", TQString::fromLatin1("konqueror/profiles/")+profile );
|
||
14 years ago
|
TQString url;
|
||
|
TQStringList filesToSelect;
|
||
15 years ago
|
if (args->count() == 1)
|
||
14 years ago
|
url = TQString::fromLocal8Bit(args->arg(0));
|
||
15 years ago
|
KURL kurl(url);
|
||
|
KParts::URLArgs urlargs;
|
||
|
if (args->isSet("mimetype"))
|
||
14 years ago
|
urlargs.serviceType = TQString::fromLocal8Bit(args->getOption("mimetype"));
|
||
15 years ago
|
if (args->isSet("select")) {
|
||
14 years ago
|
TQString fn = kurl.fileName(false);
|
||
15 years ago
|
if( !fn.isEmpty() ){
|
||
|
filesToSelect += fn;
|
||
|
kurl.setFileName("");
|
||
|
}
|
||
|
}
|
||
|
kdDebug(1202) << "main() -> createBrowserWindowFromProfile servicetype=" << urlargs.serviceType << endl;
|
||
|
KonqMisc::createBrowserWindowFromProfile( profilePath, profile, kurl, urlargs, false, filesToSelect );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (args->count() == 0)
|
||
|
{
|
||
|
if (args->isSet("preload"))
|
||
|
{
|
||
|
if( KonqSettings::maxPreloadCount() > 0 )
|
||
|
{
|
||
|
DCOPRef ref( "kded", "konqy_preloader" );
|
||
|
if( !ref.callExt( "registerPreloadedKonqy", DCOPRef::NoEventLoop, 5000,
|
||
13 years ago
|
app.dcopClient()->appId(), tqt_xscreen()))
|
||
15 years ago
|
return 0; // too many preloaded or failed
|
||
|
KonqMainWindow* win = new KonqMainWindow( KURL(), false ); // prepare an empty window too
|
||
|
// KonqMainWindow ctor sets always the preloaded flag to false, so create the window before this
|
||
|
KonqMainWindow::setPreloadedFlag( true );
|
||
|
KonqMainWindow::setPreloadedWindow( win );
|
||
|
kdDebug(1202) << "Konqy preloaded :" << app.dcopClient()->appId() << endl;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return 0; // no preloading
|
||
|
}
|
||
|
}
|
||
|
else if (!args->isSet("silent"))
|
||
|
{
|
||
|
// By default try to open in webbrowser mode. People can use "konqueror ." to get a filemanager.
|
||
14 years ago
|
TQString profile = "webbrowsing";
|
||
13 years ago
|
TQString profilePath = locate( "data", TQString::fromLatin1("konqueror/profiles/")+profile );
|
||
15 years ago
|
if ( !profilePath.isEmpty() ) {
|
||
|
KonqMisc::createBrowserWindowFromProfile( profilePath, profile );
|
||
|
} else {
|
||
|
KonqMainWindow *mainWindow = new KonqMainWindow;
|
||
|
mainWindow->show();
|
||
|
}
|
||
|
}
|
||
|
kdDebug(1202) << "main() -> no args" << endl;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
KURL::List urlList;
|
||
|
KonqMainWindow * mainwin = 0L;
|
||
|
for ( int i = 0; i < args->count(); i++ )
|
||
|
{
|
||
|
// KonqMisc::konqFilteredURL doesn't cope with local files... A bit of hackery below
|
||
|
KURL url = args->url(i);
|
||
|
KURL urlToOpen;
|
||
14 years ago
|
TQStringList filesToSelect;
|
||
15 years ago
|
|
||
14 years ago
|
if (url.isLocalFile() && TQFile::exists(url.path())) // "konqueror index.html"
|
||
15 years ago
|
urlToOpen = url;
|
||
|
else
|
||
14 years ago
|
urlToOpen = KURL( KonqMisc::konqFilteredURL(0L, TQString::fromLocal8Bit(args->arg(i))) ); // "konqueror slashdot.org"
|
||
15 years ago
|
|
||
|
if ( !mainwin ) {
|
||
|
KParts::URLArgs urlargs;
|
||
|
if (args->isSet("mimetype"))
|
||
|
{
|
||
14 years ago
|
urlargs.serviceType = TQString::fromLocal8Bit(args->getOption("mimetype"));
|
||
15 years ago
|
kdDebug(1202) << "main() : setting serviceType to " << urlargs.serviceType << endl;
|
||
|
}
|
||
|
if (args->isSet("select"))
|
||
|
{
|
||
14 years ago
|
TQString fn = urlToOpen.fileName(false);
|
||
15 years ago
|
if( !fn.isEmpty() ){
|
||
|
filesToSelect += fn;
|
||
|
urlToOpen.setFileName("");
|
||
|
}
|
||
|
}
|
||
12 years ago
|
const bool tempFile = TDECmdLineArgs::isTempFileSet();
|
||
15 years ago
|
mainwin = KonqMisc::createNewWindow( urlToOpen, urlargs, false, filesToSelect, tempFile );
|
||
|
} else
|
||
|
urlList += urlToOpen;
|
||
|
}
|
||
|
if ( mainwin )
|
||
|
mainwin->openMultiURL( urlList );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
args->clear();
|
||
|
|
||
|
app.exec();
|
||
|
|
||
|
// Delete all KonqMainWindows, so that we don't have
|
||
|
// any parts loaded when KLibLoader::cleanUp is called.
|
||
|
// Their deletion was postponed in their event()
|
||
|
// (and Qt doesn't delete WDestructiveClose widgets on exit anyway :( )
|
||
|
while( KonqMainWindow::mainWindowList() != NULL )
|
||
|
{ // the list will be deleted by last KonqMainWindow
|
||
|
delete KonqMainWindow::mainWindowList()->first();
|
||
|
}
|
||
|
|
||
|
delete kiface;
|
||
|
|
||
|
crashlog_file.unlink();
|
||
|
|
||
|
return 0;
|
||
|
}
|