• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • kde-4.14
  • applications
  • konsole
  • src
main.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
3 
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.
8 
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.
13 
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.
18 */
19 
20 // Own
21 #include "Application.h"
22 #include "MainWindow.h"
23 
24 // OS specific
25 #include <kde_file.h>
26 
27 // KDE
28 #include <KAboutData>
29 #include <KCmdLineArgs>
30 #include <KLocale>
31 
32 #define KONSOLE_VERSION "2.14.2"
33 
34 using Konsole::Application;
35 
36 // fill the KAboutData structure with information about contributors to Konsole.
37 void fillAboutData(KAboutData& aboutData);
38 
39 // fill the KCmdLineOptions object with konsole specific options.
40 void fillCommandLineOptions(KCmdLineOptions& options);
41 
42 // check and report whether this konsole instance should use a new konsole
43 // process, or re-use an existing konsole process.
44 bool shouldUseNewProcess();
45 
46 // restore sessions saved by KDE.
47 void restoreSession(Application& app);
48 
49 // ***
50 // Entry point into the Konsole terminal application.
51 // ***
52 extern "C" int KDE_EXPORT kdemain(int argc, char** argv)
53 {
54  KAboutData about("konsole",
55  0,
56  ki18nc("@title", "<application>Konsole</application>"),
57  KONSOLE_VERSION,
58  ki18nc("@title", "Terminal emulator"),
59  KAboutData::License_GPL_V2
60  );
61  fillAboutData(about);
62 
63  KCmdLineArgs::init(argc, argv, &about);
64  KCmdLineArgs::addStdCmdLineOptions(); // Qt and KDE options
65  KUniqueApplication::addCmdLineOptions(); // KUniqueApplication options
66  KCmdLineOptions konsoleOptions; // Konsole options
67  fillCommandLineOptions(konsoleOptions);
68  KCmdLineArgs::addCmdLineOptions(konsoleOptions);
69 
70  KUniqueApplication::StartFlags startFlags;
71  if (shouldUseNewProcess())
72  startFlags = KUniqueApplication::NonUniqueInstance;
73 
74  // create a new application instance if there are no running Konsole
75  // instances, otherwise inform the existing Konsole process and exit
76  if (!KUniqueApplication::start(startFlags)) {
77  exit(0);
78  }
79 
80  Application app;
81 
82  // make sure the d&d popup menu provided by libkonq get translated.
83  KGlobal::locale()->insertCatalog("libkonq");
84 
85  restoreSession(app);
86  return app.exec();
87 }
88 bool shouldUseNewProcess()
89 {
90  // The "unique process" model of konsole is incompatible with some or all
91  // Qt/KDE options. When those incompatible options are given, konsole must
92  // use new process
93  //
94  // TODO: make sure the existing list is OK and add more incompatible options.
95 
96  // take Qt options into consideration
97  const KCmdLineArgs* qtArgs = KCmdLineArgs::parsedArgs("qt");
98  QStringList qtProblematicOptions;
99  qtProblematicOptions << "session" << "name" << "reverse"
100  << "stylesheet" << "graphicssystem";
101 #if defined(Q_WS_X11)
102  qtProblematicOptions << "display" << "visual";
103 #endif
104  foreach(const QString& option, qtProblematicOptions) {
105  if ( qtArgs->isSet(option.toLocal8Bit()) ) {
106  return true;
107  }
108  }
109 
110  // take KDE options into consideration
111  const KCmdLineArgs* kdeArgs = KCmdLineArgs::parsedArgs("kde");
112  QStringList kdeProblematicOptions;
113  kdeProblematicOptions << "config" << "style";
114 #if defined(Q_WS_X11)
115  kdeProblematicOptions << "waitforwm";
116 #endif
117  foreach(const QString& option, kdeProblematicOptions) {
118  if ( kdeArgs->isSet(option.toLocal8Bit()) ) {
119  return true;
120  }
121  }
122 
123  const KCmdLineArgs* kUniqueAppArgs = KCmdLineArgs::parsedArgs("kuniqueapp");
124 
125  // when user asks konsole to run in foreground through the --nofork option
126  // provided by KUniqueApplication, we must use new process. Otherwise, there
127  // will be no process for users to wait for finishing.
128  const bool shouldRunInForeground = !kUniqueAppArgs->isSet("fork");
129  if (shouldRunInForeground) {
130  return true;
131  }
132 
133  const KCmdLineArgs* konsoleArgs = KCmdLineArgs::parsedArgs();
134 
135  // if users have explictly requested starting a new process
136  if (konsoleArgs->isSet("separate")) {
137  return true;
138  }
139 
140  // the only way to create new tab is to reuse existing Konsole process.
141  if (konsoleArgs->isSet("new-tab")) {
142  return false;
143  }
144 
145  // when starting Konsole from a terminal, a new process must be used
146  // so that the current environment is propagated into the shells of the new
147  // Konsole and any debug output or warnings from Konsole are written to
148  // the current terminal
149  bool hasControllingTTY = false;
150  const int fd = KDE_open("/dev/tty", O_RDONLY);
151  if (fd != -1) {
152  hasControllingTTY = true;
153  close(fd);
154  }
155 
156  return hasControllingTTY;
157 }
158 
159 void fillCommandLineOptions(KCmdLineOptions& options)
160 {
161  options.add("profile <name>",
162  ki18nc("@info:shell", "Name of profile to use for new Konsole instance"));
163  options.add("fallback-profile",
164  ki18nc("@info:shell", "Use the internal FALLBACK profile"));
165  options.add("workdir <dir>",
166  ki18nc("@info:shell", "Set the initial working directory of the new tab or"
167  " window to 'dir'"));
168  options.add("hold");
169  options.add("noclose",
170  ki18nc("@info:shell", "Do not close the initial session automatically when it"
171  " ends."));
172  options.add("new-tab",
173  ki18nc("@info:shell", "Create a new tab in an existing window rather than"
174  " creating a new window"));
175  options.add("tabs-from-file <file>",
176  ki18nc("@info:shell", "Create tabs as specified in given tabs configuration"
177  " file"));
178  options.add("background-mode",
179  ki18nc("@info:shell", "Start Konsole in the background and bring to the front"
180  " when Ctrl+Shift+F12 (by default) is pressed"));
181  options.add("separate", ki18n("Run in a separate process"));
182  options.add("show-menubar", ki18nc("@info:shell", "Show the menubar, overriding the default setting"));
183  options.add("hide-menubar", ki18nc("@info:shell", "Hide the menubar, overriding the default setting"));
184  options.add("show-tabbar", ki18nc("@info:shell", "Show the tabbar, overriding the default setting"));
185  options.add("hide-tabbar", ki18nc("@info:shell", "Hide the tabbar, overriding the default setting"));
186  options.add("fullscreen", ki18nc("@info:shell", "Start Konsole in fullscreen mode"));
187  options.add("notransparency",
188  ki18nc("@info:shell", "Disable transparent backgrounds, even if the system"
189  " supports them."));
190  options.add("list-profiles", ki18nc("@info:shell", "List the available profiles"));
191  options.add("list-profile-properties",
192  ki18nc("@info:shell", "List all the profile properties names and their type"
193  " (for use with -p)"));
194  options.add("p <property=value>",
195  ki18nc("@info:shell", "Change the value of a profile property."));
196  options.add("!e <cmd>",
197  ki18nc("@info:shell", "Command to execute. This option will catch all following"
198  " arguments, so use it as the last option."));
199  options.add("+[args]", ki18nc("@info:shell", "Arguments passed to command"));
200  options.add("", ki18nc("@info:shell", "Use --nofork to run in the foreground (helpful"
201  " with the -e option)."));
202 }
203 
204 void fillAboutData(KAboutData& aboutData)
205 {
206  aboutData.setProgramIconName("utilities-terminal");
207  aboutData.setHomepage("http://konsole.kde.org");
208 
209  aboutData.addAuthor(ki18nc("@info:credit", "Kurt Hindenburg"),
210  ki18nc("@info:credit", "General maintainer, bug fixes and general"
211  " improvements"),
212  "kurt.hindenburg@gmail.com");
213  aboutData.addAuthor(ki18nc("@info:credit", "Robert Knight"),
214  ki18nc("@info:credit", "Previous maintainer, ported to KDE4"),
215  "robertknight@gmail.com");
216  aboutData.addAuthor(ki18nc("@info:credit", "Lars Doelle"),
217  ki18nc("@info:credit", "Original author"),
218  "lars.doelle@on-line.de");
219  aboutData.addCredit(ki18nc("@info:credit", "Jekyll Wu"),
220  ki18nc("@info:credit", "Bug fixes and general improvements"),
221  "adaptee@gmail.com");
222  aboutData.addCredit(ki18nc("@info:credit", "Waldo Bastian"),
223  ki18nc("@info:credit", "Bug fixes and general improvements"),
224  "bastian@kde.org");
225  aboutData.addCredit(ki18nc("@info:credit", "Stephan Binner"),
226  ki18nc("@info:credit", "Bug fixes and general improvements"),
227  "binner@kde.org");
228  aboutData.addCredit(ki18nc("@info:credit", "Thomas Dreibholz"),
229  ki18nc("@info:credit", "General improvements"),
230  "dreibh@iem.uni-due.de");
231  aboutData.addCredit(ki18nc("@info:credit", "Chris Machemer"),
232  ki18nc("@info:credit", "Bug fixes"),
233  "machey@ceinetworks.com");
234  aboutData.addCredit(ki18nc("@info:credit", "Francesco Cecconi"),
235  ki18nc("@info:credit", "Bug fixes"),
236  "francesco.cecconi@gmail.com");
237  aboutData.addCredit(ki18nc("@info:credit", "Stephan Kulow"),
238  ki18nc("@info:credit", "Solaris support and history"),
239  "coolo@kde.org");
240  aboutData.addCredit(ki18nc("@info:credit", "Alexander Neundorf"),
241  ki18nc("@info:credit", "Bug fixes and improved startup performance"),
242  "neundorf@kde.org");
243  aboutData.addCredit(ki18nc("@info:credit", "Peter Silva"),
244  ki18nc("@info:credit", "Marking improvements"),
245  "Peter.A.Silva@gmail.com");
246  aboutData.addCredit(ki18nc("@info:credit", "Lotzi Boloni"),
247  ki18nc("@info:credit", "Embedded Konsole\n"
248  "Toolbar and session names"),
249  "boloni@cs.purdue.edu");
250  aboutData.addCredit(ki18nc("@info:credit", "David Faure"),
251  ki18nc("@info:credit", "Embedded Konsole\n"
252  "General improvements"),
253  "faure@kde.org");
254  aboutData.addCredit(ki18nc("@info:credit", "Antonio Larrosa"),
255  ki18nc("@info:credit", "Visual effects"),
256  "larrosa@kde.org");
257  aboutData.addCredit(ki18nc("@info:credit", "Matthias Ettrich"),
258  ki18nc("@info:credit", "Code from the kvt project\n"
259  "General improvements"),
260  "ettrich@kde.org");
261  aboutData.addCredit(ki18nc("@info:credit", "Warwick Allison"),
262  ki18nc("@info:credit", "Schema and text selection improvements"),
263  "warwick@troll.no");
264  aboutData.addCredit(ki18nc("@info:credit", "Dan Pilone"),
265  ki18nc("@info:credit", "SGI port"),
266  "pilone@slac.com");
267  aboutData.addCredit(ki18nc("@info:credit", "Kevin Street"),
268  ki18nc("@info:credit", "FreeBSD port"),
269  "street@iname.com");
270  aboutData.addCredit(ki18nc("@info:credit", "Sven Fischer"),
271  ki18nc("@info:credit", "Bug fixes"),
272  "herpes@kawo2.renditionwth-aachen.de");
273  aboutData.addCredit(ki18nc("@info:credit", "Dale M. Flaven"),
274  ki18nc("@info:credit", "Bug fixes"),
275  "dflaven@netport.com");
276  aboutData.addCredit(ki18nc("@info:credit", "Martin Jones"),
277  ki18nc("@info:credit", "Bug fixes"),
278  "mjones@powerup.com.au");
279  aboutData.addCredit(ki18nc("@info:credit", "Lars Knoll"),
280  ki18nc("@info:credit", "Bug fixes"),
281  "knoll@mpi-hd.mpg.de");
282  aboutData.addCredit(ki18nc("@info:credit", "Thanks to many others.\n"));
283 }
284 
285 void restoreSession(Application& app)
286 {
287  if (app.isSessionRestored()) {
288  int n = 1;
289  while (KMainWindow::canBeRestored(n))
290  app.newMainWindow()->restore(n++);
291  }
292 }
293 
restoreSession
void restoreSession(Application &app)
Definition: main.cpp:285
KONSOLE_VERSION
#define KONSOLE_VERSION
Definition: main.cpp:32
Application.h
MainWindow.h
fillAboutData
void fillAboutData(KAboutData &aboutData)
Definition: main.cpp:204
Konsole::Application::newMainWindow
MainWindow * newMainWindow()
Creates a new, empty main window and connects to its newSessionRequest() and newWindowRequest() signa...
Definition: Application.cpp:71
shouldUseNewProcess
bool shouldUseNewProcess()
Definition: main.cpp:88
Konsole::Application
The Konsole Application.
Definition: Application.h:48
kdemain
int KDE_EXPORT kdemain(int argc, char **argv)
Definition: main.cpp:52
QString
fillCommandLineOptions
void fillCommandLineOptions(KCmdLineOptions &options)
Definition: main.cpp:159
QStringList
QString::toLocal8Bit
QByteArray toLocal8Bit() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

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

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal