• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Konsole

main.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301  USA.
00018 */
00019 
00020 // Own
00021 #include "Application.h"
00022 #include "MainWindow.h"
00023 #include <KDebug>
00024 
00025 // Unix
00026 #include <unistd.h>
00027 
00028 // X11
00029 #ifdef Q_WS_X11
00030 #include <X11/Xlib.h>
00031 #include <X11/extensions/Xrender.h>
00032 #endif
00033 
00034 // KDE
00035 #include <KAboutData>
00036 #include <KCmdLineArgs>
00037 #include <KLocale>
00038 #include <KWindowSystem>
00039 
00040 #define KONSOLE_VERSION "2.2"
00041 
00042 using namespace Konsole;
00043 
00044 #ifdef Q_WS_X11
00045 void getDisplayInformation(Display*& display , Visual*& visual , Colormap& colormap);
00046 #endif
00047 
00048 // fills the KAboutData structure with information about contributors to 
00049 // Konsole
00050 void fillAboutData(KAboutData& aboutData);
00051 void fillCommandLineOptions(KCmdLineOptions& options);
00052 bool useTransparency();     // returns true if transparency should be enabled
00053 bool forceNewProcess();     // returns true if new instance should use a new
00054                             // process (instead of re-using an existing one)
00055 void restoreSession(Application& app);
00056 
00057 // ***
00058 // Entry point into the Konsole terminal application.  
00059 // ***
00060 extern "C" int KDE_EXPORT kdemain(int argc,char** argv)
00061 {
00062     KAboutData about(   "konsole", 0,
00063                         ki18n("Konsole"),
00064                         KONSOLE_VERSION,
00065                         ki18n("Terminal emulator"),
00066                         KAboutData::License_GPL_V2
00067                     );
00068     fillAboutData(about);
00069 
00070     KCmdLineArgs::init(argc,argv,&about);
00071     KCmdLineOptions options;
00072     fillCommandLineOptions(options);
00073     KCmdLineArgs::addCmdLineOptions(options);
00074     KUniqueApplication::addCmdLineOptions();
00075 
00076     KUniqueApplication::StartFlags startFlags;
00077     if (forceNewProcess())
00078         startFlags = KUniqueApplication::NonUniqueInstance;
00079 
00080     // create a new application instance if there are no running Konsole instances,
00081     // otherwise inform the existing Konsole process and exit
00082     if ( !KUniqueApplication::start(startFlags) )
00083     {
00084         exit(0);
00085     }
00086 #ifdef Q_WS_X11 
00087     if ( useTransparency() ) 
00088     {
00089         Display* display = 0;
00090         Visual* visual = 0;
00091         Colormap colormap = 0;
00092 
00093         getDisplayInformation(display,visual,colormap);
00094 
00095         Application app(display,(Qt::HANDLE)visual,(Qt::HANDLE)colormap);
00096         restoreSession(app);
00097         return app.exec();
00098     }
00099     else
00100 #endif 
00101     {
00102         Application app;
00103         restoreSession(app);
00104         return app.exec();
00105     }   
00106 }
00107 bool forceNewProcess()
00108 {
00109     // when starting Konsole from a terminal, a new process must be used 
00110     // so that the current environment is propagated into the shells of the new
00111     // Konsole and any debug output or warnings from Konsole are written to
00112     // the current terminal
00113     KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
00114     return isatty(1) && !args->isSet("new-tab");
00115 }
00116 bool useTransparency()
00117 {
00118     KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
00119     bool compositingAvailable = KWindowSystem::compositingActive() ||
00120                                 args->isSet("force-transparency");
00121     return compositingAvailable && args->isSet("transparency");
00122 }
00123 void fillCommandLineOptions(KCmdLineOptions& options)
00124 {
00125     options.add("profile <file>", ki18n("Name of profile to use for new Konsole instance"));
00126     options.add("list-profiles", ki18n("List the available profiles"));
00127     // TODO - Update this when F12 is no longer hard coded
00128     options.add("background-mode", ki18n("Start Konsole in the background"
00129                                     " and bring to the front when the F12"
00130                                     " key is pressed"));
00131     options.add("new-tab",ki18n("Create a new tab in an existing window rather than creating a new window"));
00132     options.add("workdir <dir>",   ki18n("Set the initial working directory of the new tab "
00133                                            "or window to 'dir'"));
00134     options.add("notransparency",ki18n("Disable transparent backgrounds, even if the system supports them."));
00135     options.add("force-transparency",ki18n("Try to enable transparency, even if the system does not appear to support it."));
00136     options.add("hold");
00137     options.add("noclose",ki18n("Do not close the initial session automatically when it ends."));
00138     // TODO - Document this option more clearly
00139     options.add("p <property=value>",ki18n("Change the value of a profile property."));
00140     options.add("!e <cmd>",ki18n("Command to execute"));
00141     options.add("+[args]",ki18n("Arguments passed to command"));
00142 }
00143 
00144 void fillAboutData(KAboutData& aboutData)
00145 {
00146   aboutData.addAuthor(ki18n("Robert Knight"),ki18n("Maintainer"), "robertknight@gmail.com");
00147   aboutData.addAuthor(ki18n("Lars Doelle"),ki18n("Author"), "lars.doelle@on-line.de");
00148   aboutData.addCredit(ki18n("Kurt V. Hindenburg"),
00149     ki18n("Bug fixes and general improvements"), 
00150     "kurt.hindenburg@gmail.com");
00151   aboutData.addCredit(ki18n("Waldo Bastian"),
00152     ki18n("Bug fixes and general improvements"),
00153     "bastian@kde.org");
00154   aboutData.addCredit(ki18n("Stephan Binner"),
00155     ki18n("Bug fixes and general improvements"),
00156     "binner@kde.org");
00157   aboutData.addCredit(ki18n("Chris Machemer"),
00158     ki18n("Bug fixes"),
00159     "machey@ceinetworks.com");
00160   aboutData.addCredit(ki18n("Stephan Kulow"),
00161     ki18n("Solaris support and history"),
00162     "coolo@kde.org");
00163   aboutData.addCredit(ki18n("Alexander Neundorf"),
00164     ki18n("Bug fixes and improved startup performance"),
00165     "neundorf@kde.org");
00166   aboutData.addCredit(ki18n("Peter Silva"),
00167     ki18n("Marking improvements"),
00168     "peter.silva@videotron.ca");
00169   aboutData.addCredit(ki18n("Lotzi Boloni"),
00170     ki18n("Embedded Konsole\n"
00171     "Toolbar and session names"),
00172     "boloni@cs.purdue.edu");
00173   aboutData.addCredit(ki18n("David Faure"),
00174     ki18n("Embedded Konsole\n"
00175     "General improvements"),
00176     "faure@kde.org");
00177   aboutData.addCredit(ki18n("Antonio Larrosa"),
00178     ki18n("Visual effects"),
00179     "larrosa@kde.org");
00180   aboutData.addCredit(ki18n("Matthias Ettrich"),
00181     ki18n("Code from the kvt project\n"
00182     "General improvements"),
00183     "ettrich@kde.org");
00184   aboutData.addCredit(ki18n("Warwick Allison"),
00185     ki18n("Schema and text selection improvements"),
00186     "warwick@troll.no");
00187   aboutData.addCredit(ki18n("Dan Pilone"),
00188     ki18n("SGI port"),
00189     "pilone@slac.com");
00190   aboutData.addCredit(ki18n("Kevin Street"),
00191     ki18n("FreeBSD port"),
00192     "street@iname.com");
00193   aboutData.addCredit(ki18n("Sven Fischer"),
00194     ki18n("Bug fixes"),
00195     "herpes@kawo2.renditionwth-aachen.de");
00196   aboutData.addCredit(ki18n("Dale M. Flaven"),
00197     ki18n("Bug fixes"),
00198     "dflaven@netport.com");
00199   aboutData.addCredit(ki18n("Martin Jones"),
00200     ki18n("Bug fixes"),
00201     "mjones@powerup.com.au");
00202   aboutData.addCredit(ki18n("Lars Knoll"),
00203     ki18n("Bug fixes"),
00204     "knoll@mpi-hd.mpg.de");
00205   aboutData.addCredit(ki18n("Thanks to many others.\n"));
00206   aboutData.setProgramIconName("utilities-terminal");
00207 }
00208 
00209 // code taken from the Qt 4 graphics dojo examples
00210 // at http://labs.trolltech.com 
00211 #ifdef Q_WS_X11
00212 void getDisplayInformation(Display*& display , Visual*& visual , Colormap& colormap)
00213 {
00214     display = XOpenDisplay(0); // open default display
00215     if (!display) {
00216         kWarning("Cannot connect to the X server");
00217         exit(1);
00218     }
00219 
00220     int screen = DefaultScreen(display);
00221     int eventBase, errorBase;
00222 
00223     if (XRenderQueryExtension(display, &eventBase, &errorBase)) {
00224         int nvi;
00225         XVisualInfo templ;
00226         templ.screen  = screen;
00227         templ.depth = 32;
00228         templ.c_class = TrueColor;
00229         XVisualInfo *xvi = XGetVisualInfo(display, VisualScreenMask |
00230                                           VisualDepthMask |
00231                                           VisualClassMask, &templ, &nvi);
00232     
00233         for (int i = 0; i < nvi; ++i) {
00234             XRenderPictFormat* format = XRenderFindVisualFormat(display,
00235                                                                 xvi[i].visual);
00236             if (format->type == PictTypeDirect && format->direct.alphaMask) {
00237                 visual = xvi[i].visual;
00238                 colormap = XCreateColormap(display, RootWindow(display, screen),
00239                                            visual, AllocNone);
00240 
00241                 // found ARGB visual
00242                 break;
00243             }
00244         }
00245     }
00246 }
00247 #endif
00248 
00249 void restoreSession(Application& app)
00250 {
00251     if (app.isSessionRestored())
00252     {
00253         int n = 1;
00254         while (KMainWindow::canBeRestored(n))
00255             app.newMainWindow()->restore(n++);
00256     }
00257 }
00258 
00259 /*
00260   Local Variables:
00261   mode: c++
00262   c-file-style: "stroustrup"
00263   indent-tabs-mode: nil
00264   tab-width: 4
00265   End:
00266 */

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal