add more spacing
[personal-kdebase.git] / apps / konsole / src / main.cpp
blob1a126fc1ef664ad26261952fe34bc4702dd21b19
1 /*
2 Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301 USA.
20 // Own
21 #include "Application.h"
22 #include "MainWindow.h"
23 #include <KDebug>
25 // Unix
26 #include <unistd.h>
28 // X11
29 #ifdef Q_WS_X11
30 #include <X11/Xlib.h>
31 #include <X11/extensions/Xrender.h>
32 #endif
34 // KDE
35 #include <KAboutData>
36 #include <KCmdLineArgs>
37 #include <KLocale>
38 #include <KWindowSystem>
40 #define KONSOLE_VERSION "2.2"
42 using namespace Konsole;
44 #ifdef Q_WS_X11
45 void getDisplayInformation(Display*& display , Visual*& visual , Colormap& colormap);
46 #endif
48 // fills the KAboutData structure with information about contributors to
49 // Konsole
50 void fillAboutData(KAboutData& aboutData);
51 void fillCommandLineOptions(KCmdLineOptions& options);
52 bool useTransparency(); // returns true if transparency should be enabled
53 bool forceNewProcess(); // returns true if new instance should use a new
54 // process (instead of re-using an existing one)
55 void restoreSession(Application& app);
57 // ***
58 // Entry point into the Konsole terminal application.
59 // ***
60 extern "C" int KDE_EXPORT kdemain(int argc,char** argv)
62 KAboutData about( "konsole", 0,
63 ki18n("Konsole"),
64 KONSOLE_VERSION,
65 ki18n("Terminal emulator"),
66 KAboutData::License_GPL_V2
68 fillAboutData(about);
70 KCmdLineArgs::init(argc,argv,&about);
71 KCmdLineOptions options;
72 fillCommandLineOptions(options);
73 KCmdLineArgs::addCmdLineOptions(options);
74 KUniqueApplication::addCmdLineOptions();
76 KUniqueApplication::StartFlags startFlags;
77 if (forceNewProcess())
78 startFlags = KUniqueApplication::NonUniqueInstance;
80 // create a new application instance if there are no running Konsole instances,
81 // otherwise inform the existing Konsole process and exit
82 if ( !KUniqueApplication::start(startFlags) )
84 exit(0);
86 #ifdef Q_WS_X11
87 if ( useTransparency() )
89 Display* display = 0;
90 Visual* visual = 0;
91 Colormap colormap = 0;
93 getDisplayInformation(display,visual,colormap);
95 Application app(display,(Qt::HANDLE)visual,(Qt::HANDLE)colormap);
96 restoreSession(app);
97 return app.exec();
99 else
100 #endif
102 Application app;
103 restoreSession(app);
104 return app.exec();
107 bool forceNewProcess()
109 // when starting Konsole from a terminal, a new process must be used
110 // so that the current environment is propagated into the shells of the new
111 // Konsole and any debug output or warnings from Konsole are written to
112 // the current terminal
113 KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
114 return isatty(1) && !args->isSet("new-tab");
116 bool useTransparency()
118 KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
119 bool compositingAvailable = KWindowSystem::compositingActive() ||
120 args->isSet("force-transparency");
121 return compositingAvailable && args->isSet("transparency");
123 void fillCommandLineOptions(KCmdLineOptions& options)
125 options.add("profile <file>", ki18n("Name of profile to use for new Konsole instance"));
126 options.add("list-profiles", ki18n("List the available profiles"));
127 // TODO - Update this when F12 is no longer hard coded
128 options.add("background-mode", ki18n("Start Konsole in the background"
129 " and bring to the front when the F12"
130 " key is pressed"));
131 options.add("new-tab",ki18n("Create a new tab in an existing window rather than creating a new window"));
132 options.add("workdir <dir>", ki18n("Set the initial working directory of the new tab "
133 "or window to 'dir'"));
134 options.add("notransparency",ki18n("Disable transparent backgrounds, even if the system supports them."));
135 options.add("force-transparency",ki18n("Try to enable transparency, even if the system does not appear to support it."));
136 options.add("hold");
137 options.add("noclose",ki18n("Do not close the initial session automatically when it ends."));
138 // TODO - Document this option more clearly
139 options.add("p <property=value>",ki18n("Change the value of a profile property."));
140 options.add("!e <cmd>",ki18n("Command to execute"));
141 options.add("+[args]",ki18n("Arguments passed to command"));
144 void fillAboutData(KAboutData& aboutData)
146 aboutData.addAuthor(ki18n("Robert Knight"),ki18n("Maintainer"), "robertknight@gmail.com");
147 aboutData.addAuthor(ki18n("Lars Doelle"),ki18n("Author"), "lars.doelle@on-line.de");
148 aboutData.addCredit(ki18n("Kurt V. Hindenburg"),
149 ki18n("Bug fixes and general improvements"),
150 "kurt.hindenburg@gmail.com");
151 aboutData.addCredit(ki18n("Waldo Bastian"),
152 ki18n("Bug fixes and general improvements"),
153 "bastian@kde.org");
154 aboutData.addCredit(ki18n("Stephan Binner"),
155 ki18n("Bug fixes and general improvements"),
156 "binner@kde.org");
157 aboutData.addCredit(ki18n("Chris Machemer"),
158 ki18n("Bug fixes"),
159 "machey@ceinetworks.com");
160 aboutData.addCredit(ki18n("Stephan Kulow"),
161 ki18n("Solaris support and history"),
162 "coolo@kde.org");
163 aboutData.addCredit(ki18n("Alexander Neundorf"),
164 ki18n("Bug fixes and improved startup performance"),
165 "neundorf@kde.org");
166 aboutData.addCredit(ki18n("Peter Silva"),
167 ki18n("Marking improvements"),
168 "peter.silva@videotron.ca");
169 aboutData.addCredit(ki18n("Lotzi Boloni"),
170 ki18n("Embedded Konsole\n"
171 "Toolbar and session names"),
172 "boloni@cs.purdue.edu");
173 aboutData.addCredit(ki18n("David Faure"),
174 ki18n("Embedded Konsole\n"
175 "General improvements"),
176 "faure@kde.org");
177 aboutData.addCredit(ki18n("Antonio Larrosa"),
178 ki18n("Visual effects"),
179 "larrosa@kde.org");
180 aboutData.addCredit(ki18n("Matthias Ettrich"),
181 ki18n("Code from the kvt project\n"
182 "General improvements"),
183 "ettrich@kde.org");
184 aboutData.addCredit(ki18n("Warwick Allison"),
185 ki18n("Schema and text selection improvements"),
186 "warwick@troll.no");
187 aboutData.addCredit(ki18n("Dan Pilone"),
188 ki18n("SGI port"),
189 "pilone@slac.com");
190 aboutData.addCredit(ki18n("Kevin Street"),
191 ki18n("FreeBSD port"),
192 "street@iname.com");
193 aboutData.addCredit(ki18n("Sven Fischer"),
194 ki18n("Bug fixes"),
195 "herpes@kawo2.renditionwth-aachen.de");
196 aboutData.addCredit(ki18n("Dale M. Flaven"),
197 ki18n("Bug fixes"),
198 "dflaven@netport.com");
199 aboutData.addCredit(ki18n("Martin Jones"),
200 ki18n("Bug fixes"),
201 "mjones@powerup.com.au");
202 aboutData.addCredit(ki18n("Lars Knoll"),
203 ki18n("Bug fixes"),
204 "knoll@mpi-hd.mpg.de");
205 aboutData.addCredit(ki18n("Thanks to many others.\n"));
206 aboutData.setProgramIconName("utilities-terminal");
209 // code taken from the Qt 4 graphics dojo examples
210 // at http://labs.trolltech.com
211 #ifdef Q_WS_X11
212 void getDisplayInformation(Display*& display , Visual*& visual , Colormap& colormap)
214 display = XOpenDisplay(0); // open default display
215 if (!display) {
216 kWarning("Cannot connect to the X server");
217 exit(1);
220 int screen = DefaultScreen(display);
221 int eventBase, errorBase;
223 if (XRenderQueryExtension(display, &eventBase, &errorBase)) {
224 int nvi;
225 XVisualInfo templ;
226 templ.screen = screen;
227 templ.depth = 32;
228 templ.c_class = TrueColor;
229 XVisualInfo *xvi = XGetVisualInfo(display, VisualScreenMask |
230 VisualDepthMask |
231 VisualClassMask, &templ, &nvi);
233 for (int i = 0; i < nvi; ++i) {
234 XRenderPictFormat* format = XRenderFindVisualFormat(display,
235 xvi[i].visual);
236 if (format->type == PictTypeDirect && format->direct.alphaMask) {
237 visual = xvi[i].visual;
238 colormap = XCreateColormap(display, RootWindow(display, screen),
239 visual, AllocNone);
241 // found ARGB visual
242 break;
247 #endif
249 void restoreSession(Application& app)
251 if (app.isSessionRestored())
253 int n = 1;
254 while (KMainWindow::canBeRestored(n))
255 app.newMainWindow()->restore(n++);
260 Local Variables:
261 mode: c++
262 c-file-style: "stroustrup"
263 indent-tabs-mode: nil
264 tab-width: 4
265 End: