delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / nsplugins / viewer / viewer.cpp
blob385c95ef3f7069c6f84390eab53718a9f9addbb6
1 /*
3 This is a standalone application that executes Netscape plugins.
6 Copyright (c) 2000 Matthias Hoelzer-Kluepfel <mhk@caldera.de>
7 Stefan Schimanski <1Stein@gmx.de>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include <config-apps.h>
28 #include <kapplication.h>
29 #include "nsplugin.h"
31 #include <kcmdlineargs.h>
32 #include <kaboutdata.h>
33 #include <kconfiggroup.h>
34 #include <kdebug.h>
35 #include <kglobal.h>
36 #include <klocale.h>
37 #include <kmessagebox.h>
38 #include <QSocketNotifier>
40 #include <stdlib.h>
41 #include <sys/resource.h>
42 #include <sys/time.h>
43 #include <unistd.h>
44 #include <kdefakes.h>
46 #ifdef Bool
47 #undef Bool
48 #endif
49 #include <kconfig.h>
51 #include "xtevents.h"
52 #include "glibevents.h"
53 #include <QtDBus/QtDBus>
55 /**
56 * Use RLIMIT_DATA on systems that don't define RLIMIT_AS,
57 * such as FreeBSD 4, NetBSD and OpenBSD.
60 #ifndef RLIMIT_AS
61 #define RLIMIT_AS RLIMIT_DATA
62 #endif
65 * As the plugin viewer needs to be a motif application, I give in to
66 * the "old style" and keep lot's of global vars. :-)
69 static QString g_dbusServiceName;
71 /**
72 * parseCommandLine - get command line parameters
75 void parseCommandLine(int argc, char *argv[])
77 for (int i=0; i<argc; i++)
79 if (!strcmp(argv[i], "-dbusservice") && (i+1 < argc))
81 g_dbusServiceName = argv[i+1];
82 i++;
87 int main(int argc, char** argv)
89 // nspluginviewer is a helper app, it shouldn't do session management at all
90 setenv( "SESSION_MANAGER", "", 1 );
92 setvbuf( stderr, NULL, _IONBF, 0 );
94 kDebug(1430) << "2 - parseCommandLine";
95 parseCommandLine(argc, argv);
97 parseCommandLine(argc, argv);
99 kDebug(1430) << "3 - create KApplication";
101 // Skip the args.. This is internal, anyway.
102 KCmdLineArgs::init(1, argv, "nspluginviewer", "nsplugin", ki18n("nspluginviewer"), "");
104 KApplication app;
106 kDebug(1430) << "4 - create XtEvents and GlibEvents";
107 XtEvents xtevents;
108 #ifdef HAVE_GLIB2
109 GlibEvents glibevents;
110 #endif
112 KConfig _cfg( "kcmnspluginrc" );
113 KConfigGroup cfg(&_cfg, "Misc");
114 int v = qBound(0, cfg.readEntry("Nice Level", 0), 19);
115 if (v > 0) {
116 nice(v);
118 v = cfg.readEntry("Max Memory", 0);
119 if (v > 0) {
120 rlimit rl;
121 memset(&rl, 0, sizeof(rl));
122 if (0 == getrlimit(RLIMIT_AS, &rl)) {
123 rl.rlim_cur = qMin(v, int(rl.rlim_max));
124 setrlimit(RLIMIT_AS, &rl);
129 kDebug(1430) << "5 - dbus requestName";
130 if (!g_dbusServiceName.isEmpty()) {
131 QDBusConnectionInterface* bus = QDBusConnection::sessionBus().interface(); // already null-checked by KApplication
132 if ( bus->registerService(g_dbusServiceName, QDBusConnectionInterface::DontQueueService) == QDBusConnectionInterface::ServiceNotRegistered ) {
133 kError(101) << "Couldn't register name '" << g_dbusServiceName << "' with DBUS - another process owns it already!" << endl;
134 ::exit(126);
138 // create dcop interface
139 kDebug(1430) << "6 - new NSPluginViewer";
140 NSPluginViewer *viewer = new NSPluginViewer( 0 );
142 // start main loop
143 kDebug(1430) << "7 - app.exec()";
144 app.exec();
146 // delete viewer
147 delete viewer;