1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
/* 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"
#include <ktempfile.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kdebug.h>
#include <tdecmdlineargs.h>
#include <dcopclient.h>
#include <kimageio.h>
#include <tqfile.h>
#include <tqwidgetlist.h>
static const TDECmdLineOptions options[] =
{
{ "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 },
TDECmdLineLastOption
};
extern "C" KDE_EXPORT int kdemain( int argc, char **argv )
{
TDECmdLineArgs::init( argc, argv, KonqFactory::aboutData() );
TDECmdLineArgs::addCmdLineOptions( options ); // Add our own options.
TDECmdLineArgs::addTempFileOption();
KonquerorApplication app;
app.dcopClient()->registerAs( "konqueror" );
KonquerorIface *kiface = new KonquerorIface;
app.dcopClient()->setDefaultObject( kiface->objId() );
TDEGlobal::locale()->insertCatalogue("libkonq"); // needed for apps using libkonq
KImageIO::registerFormats();
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
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 ) )
{
TQString className = TDEMainWindow::classNameOfToplevel( n );
if( className == TQString::fromLatin1( "KonqMainWindow" ))
(new KonqMainWindow( KURL(), false ) )->restore( n );
else
kdWarning() << "Unknown class " << className << " in session saved data!" << endl;
n++;
}
}
else
{
if (args->isSet("profiles"))
{
TQStringList profiles = TDEGlobal::dirs()->findAllResources("data", "konqueror/profiles/*", false, true);
profiles.sort();
for(TQStringList::ConstIterator it = profiles.begin();
it != profiles.end(); ++it)
{
TQString file = *it;
file = file.mid(file.findRev('/')+1);
printf("%s\n", TQFile::encodeName(file).data());
}
return 0;
}
if (args->isSet("profile"))
{
TQString profile = TQString::fromLocal8Bit(args->getOption("profile"));
TQString profilePath = profile;
if (profile[0] != '/')
profilePath = locate( "data", TQString::fromLatin1("konqueror/profiles/")+profile );
TQString url;
TQStringList filesToSelect;
if (args->count() == 1)
url = TQString::fromLocal8Bit(args->arg(0));
KURL kurl(url);
KParts::URLArgs urlargs;
if (args->isSet("mimetype"))
urlargs.serviceType = TQString::fromLocal8Bit(args->getOption("mimetype"));
if (args->isSet("select")) {
TQString fn = kurl.fileName(false);
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,
app.dcopClient()->appId(), tqt_xscreen()))
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.
TQString profile = "webbrowsing";
TQString profilePath = locate( "data", TQString::fromLatin1("konqueror/profiles/")+profile );
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;
TQStringList filesToSelect;
if (url.isLocalFile() && TQFile::exists(url.path())) // "konqueror index.html"
urlToOpen = url;
else
urlToOpen = KURL( KonqMisc::konqFilteredURL(0L, TQString::fromLocal8Bit(args->arg(i))) ); // "konqueror slashdot.org"
if ( !mainwin ) {
KParts::URLArgs urlargs;
if (args->isSet("mimetype"))
{
urlargs.serviceType = TQString::fromLocal8Bit(args->getOption("mimetype"));
kdDebug(1202) << "main() : setting serviceType to " << urlargs.serviceType << endl;
}
if (args->isSet("select"))
{
TQString fn = urlToOpen.fileName(false);
if( !fn.isEmpty() ){
filesToSelect += fn;
urlToOpen.setFileName("");
}
}
const bool tempFile = TDECmdLineArgs::isTempFileSet();
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;
}
|