mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-24 02:42:50 +00:00
konsole: use KApplication instead of KUniqueApplication
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
7b8efc2d0b
commit
a4a460f9b2
5 changed files with 56 additions and 148 deletions
|
@ -41,53 +41,9 @@
|
||||||
|
|
||||||
using namespace Konsole;
|
using namespace Konsole;
|
||||||
|
|
||||||
Application::Application() : KUniqueApplication()
|
Application::Application()
|
||||||
{
|
: KApplication(),
|
||||||
init();
|
_backgroundInstance(nullptr)
|
||||||
}
|
|
||||||
|
|
||||||
void Application::init()
|
|
||||||
{
|
|
||||||
_backgroundInstance = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Application::~Application()
|
|
||||||
{
|
|
||||||
SessionManager::instance()->closeAllSessions();
|
|
||||||
ProfileManager::instance()->saveSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
MainWindow* Application::newMainWindow()
|
|
||||||
{
|
|
||||||
MainWindow* window = new MainWindow();
|
|
||||||
|
|
||||||
connect(window, SIGNAL(newWindowRequest(Profile::Ptr,QString)),
|
|
||||||
this, SLOT(createWindow(Profile::Ptr,QString)));
|
|
||||||
connect(window, SIGNAL(viewDetached(Session*)),
|
|
||||||
this, SLOT(detachView(Session*)));
|
|
||||||
|
|
||||||
return window;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::createWindow(Profile::Ptr profile, const QString& directory)
|
|
||||||
{
|
|
||||||
MainWindow* window = newMainWindow();
|
|
||||||
window->createSession(profile, directory);
|
|
||||||
window->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::detachView(Session* session)
|
|
||||||
{
|
|
||||||
MainWindow* window = newMainWindow();
|
|
||||||
window->createView(session);
|
|
||||||
// Since user is dragging and dropping, move dnd window to where
|
|
||||||
// the user has the cursor (correct multiple monitor setups).
|
|
||||||
window->move(QCursor::pos());
|
|
||||||
window->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
int Application::newInstance()
|
|
||||||
{
|
{
|
||||||
static bool firstInstance = true;
|
static bool firstInstance = true;
|
||||||
|
|
||||||
|
@ -98,7 +54,7 @@ int Application::newInstance()
|
||||||
// check for arguments to print help or other information to the
|
// check for arguments to print help or other information to the
|
||||||
// terminal, quit if such an argument was found
|
// terminal, quit if such an argument was found
|
||||||
if (processHelpArgs(args))
|
if (processHelpArgs(args))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
// create a new window or use an existing one
|
// create a new window or use an existing one
|
||||||
MainWindow* window = processWindowArgs(args);
|
MainWindow* window = processWindowArgs(args);
|
||||||
|
@ -148,7 +104,41 @@ int Application::newInstance()
|
||||||
|
|
||||||
firstInstance = false;
|
firstInstance = false;
|
||||||
args->clear();
|
args->clear();
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
Application::~Application()
|
||||||
|
{
|
||||||
|
SessionManager::instance()->closeAllSessions();
|
||||||
|
ProfileManager::instance()->saveSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWindow* Application::newMainWindow()
|
||||||
|
{
|
||||||
|
MainWindow* window = new MainWindow();
|
||||||
|
|
||||||
|
connect(window, SIGNAL(newWindowRequest(Profile::Ptr,QString)),
|
||||||
|
this, SLOT(createWindow(Profile::Ptr,QString)));
|
||||||
|
connect(window, SIGNAL(viewDetached(Session*)),
|
||||||
|
this, SLOT(detachView(Session*)));
|
||||||
|
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::createWindow(Profile::Ptr profile, const QString& directory)
|
||||||
|
{
|
||||||
|
MainWindow* window = newMainWindow();
|
||||||
|
window->createSession(profile, directory);
|
||||||
|
window->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::detachView(Session* session)
|
||||||
|
{
|
||||||
|
MainWindow* window = newMainWindow();
|
||||||
|
window->createView(session);
|
||||||
|
// Since user is dragging and dropping, move dnd window to where
|
||||||
|
// the user has the cursor (correct multiple monitor setups).
|
||||||
|
window->move(QCursor::pos());
|
||||||
|
window->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Documentation for tab file:
|
/* Documentation for tab file:
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#define APPLICATION_H
|
#define APPLICATION_H
|
||||||
|
|
||||||
// KDE
|
// KDE
|
||||||
#include <KUniqueApplication>
|
#include <KApplication>
|
||||||
|
|
||||||
// Konsole
|
// Konsole
|
||||||
#include "Profile.h"
|
#include "Profile.h"
|
||||||
|
@ -45,7 +45,7 @@ class Session;
|
||||||
* The factory used to create new terminal sessions can be retrieved using
|
* The factory used to create new terminal sessions can be retrieved using
|
||||||
* the sessionManager() accessor.
|
* the sessionManager() accessor.
|
||||||
*/
|
*/
|
||||||
class Application : public KUniqueApplication
|
class Application : public KApplication
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -55,9 +55,6 @@ public:
|
||||||
|
|
||||||
virtual ~Application();
|
virtual ~Application();
|
||||||
|
|
||||||
/** Creates a new main window and opens a default terminal session */
|
|
||||||
virtual int newInstance();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new, empty main window and connects to its newSessionRequest()
|
* Creates a new, empty main window and connects to its newSessionRequest()
|
||||||
* and newWindowRequest() signals to trigger creation of new sessions or
|
* and newWindowRequest() signals to trigger creation of new sessions or
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <KAboutData>
|
#include <KAboutData>
|
||||||
#include <KCmdLineArgs>
|
#include <KCmdLineArgs>
|
||||||
#include <KLocale>
|
#include <KLocale>
|
||||||
|
#include <KDebug>
|
||||||
|
|
||||||
#define KONSOLE_VERSION "2.14.2"
|
#define KONSOLE_VERSION "2.14.2"
|
||||||
|
|
||||||
|
@ -39,10 +40,6 @@ void fillAboutData(KAboutData& aboutData);
|
||||||
// fill the KCmdLineOptions object with konsole specific options.
|
// fill the KCmdLineOptions object with konsole specific options.
|
||||||
void fillCommandLineOptions(KCmdLineOptions& options);
|
void fillCommandLineOptions(KCmdLineOptions& options);
|
||||||
|
|
||||||
// check and report whether this konsole instance should use a new konsole
|
|
||||||
// process, or re-use an existing konsole process.
|
|
||||||
bool shouldUseNewProcess();
|
|
||||||
|
|
||||||
// restore sessions saved by KDE.
|
// restore sessions saved by KDE.
|
||||||
void restoreSession(Application& app);
|
void restoreSession(Application& app);
|
||||||
|
|
||||||
|
@ -62,21 +59,11 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
KCmdLineArgs::init(argc, argv, &about);
|
KCmdLineArgs::init(argc, argv, &about);
|
||||||
KCmdLineArgs::addStdCmdLineOptions(); // Qt and KDE options
|
KCmdLineArgs::addStdCmdLineOptions(); // Qt and KDE options
|
||||||
KUniqueApplication::addCmdLineOptions(); // KUniqueApplication options
|
|
||||||
KCmdLineOptions konsoleOptions; // Konsole options
|
KCmdLineOptions konsoleOptions; // Konsole options
|
||||||
fillCommandLineOptions(konsoleOptions);
|
fillCommandLineOptions(konsoleOptions);
|
||||||
KCmdLineArgs::addCmdLineOptions(konsoleOptions);
|
KCmdLineArgs::addCmdLineOptions(konsoleOptions);
|
||||||
|
|
||||||
KUniqueApplication::StartFlags startFlags = 0;
|
// create a new application instance
|
||||||
if (shouldUseNewProcess())
|
|
||||||
startFlags = KUniqueApplication::NonUniqueInstance;
|
|
||||||
|
|
||||||
// create a new application instance if there are no running Konsole
|
|
||||||
// instances, otherwise inform the existing Konsole process and exit
|
|
||||||
if (!KUniqueApplication::start(startFlags)) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
Application app;
|
Application app;
|
||||||
|
|
||||||
// make sure the d&d popup menu provided by libkonq get translated.
|
// make sure the d&d popup menu provided by libkonq get translated.
|
||||||
|
@ -85,76 +72,6 @@ int main(int argc, char** argv)
|
||||||
restoreSession(app);
|
restoreSession(app);
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
bool shouldUseNewProcess()
|
|
||||||
{
|
|
||||||
// The "unique process" model of konsole is incompatible with some or all
|
|
||||||
// Qt/KDE options. When those incompatible options are given, konsole must
|
|
||||||
// use new process
|
|
||||||
//
|
|
||||||
// TODO: make sure the existing list is OK and add more incompatible options.
|
|
||||||
|
|
||||||
// take Qt options into consideration
|
|
||||||
const KCmdLineArgs* qtArgs = KCmdLineArgs::parsedArgs("qt");
|
|
||||||
QStringList qtProblematicOptions;
|
|
||||||
qtProblematicOptions << "session" << "name" << "reverse"
|
|
||||||
<< "stylesheet";
|
|
||||||
#if defined(Q_WS_X11)
|
|
||||||
qtProblematicOptions << "display" << "visual";
|
|
||||||
#endif
|
|
||||||
foreach(const QString& option, qtProblematicOptions) {
|
|
||||||
if ( qtArgs->isSet(option.toLocal8Bit()) ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// take KDE options into consideration
|
|
||||||
const KCmdLineArgs* kdeArgs = KCmdLineArgs::parsedArgs("kde");
|
|
||||||
QStringList kdeProblematicOptions;
|
|
||||||
kdeProblematicOptions << "config" << "style";
|
|
||||||
#if defined(Q_WS_X11)
|
|
||||||
kdeProblematicOptions << "waitforwm";
|
|
||||||
#endif
|
|
||||||
foreach(const QString& option, kdeProblematicOptions) {
|
|
||||||
if ( kdeArgs->isSet(option.toLocal8Bit()) ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const KCmdLineArgs* kUniqueAppArgs = KCmdLineArgs::parsedArgs("kuniqueapp");
|
|
||||||
|
|
||||||
// when user asks konsole to run in foreground through the --nofork option
|
|
||||||
// provided by KUniqueApplication, we must use new process. Otherwise, there
|
|
||||||
// will be no process for users to wait for finishing.
|
|
||||||
const bool shouldRunInForeground = !kUniqueAppArgs->isSet("fork");
|
|
||||||
if (shouldRunInForeground) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const KCmdLineArgs* konsoleArgs = KCmdLineArgs::parsedArgs();
|
|
||||||
|
|
||||||
// if users have explictly requested starting a new process
|
|
||||||
if (konsoleArgs->isSet("separate")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// the only way to create new tab is to reuse existing Konsole process.
|
|
||||||
if (konsoleArgs->isSet("new-tab")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// when starting Konsole from a terminal, a new process must be used
|
|
||||||
// so that the current environment is propagated into the shells of the new
|
|
||||||
// Konsole and any debug output or warnings from Konsole are written to
|
|
||||||
// the current terminal
|
|
||||||
bool hasControllingTTY = false;
|
|
||||||
const int fd = KDE_open("/dev/tty", O_RDONLY);
|
|
||||||
if (fd != -1) {
|
|
||||||
hasControllingTTY = true;
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasControllingTTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fillCommandLineOptions(KCmdLineOptions& options)
|
void fillCommandLineOptions(KCmdLineOptions& options)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,14 +21,15 @@
|
||||||
#include "DBusTest.h"
|
#include "DBusTest.h"
|
||||||
#include "../Session.h"
|
#include "../Session.h"
|
||||||
|
|
||||||
#include <QtDBus/QDBusConnectionInterface>
|
#include <QTextCodec>
|
||||||
|
#include <QDBusConnectionInterface>
|
||||||
|
|
||||||
using namespace Konsole;
|
using namespace Konsole;
|
||||||
|
|
||||||
/* Exec a new Konsole and grab its dbus */
|
/* Exec a new Konsole and grab its dbus */
|
||||||
void DBusTest::initTestCase()
|
void DBusTest::initTestCase()
|
||||||
{
|
{
|
||||||
const QString interfaceName = "org.kde.konsole";
|
const QString interfaceName = "org.kde.konsole-";
|
||||||
QDBusConnectionInterface* bus = 0;
|
QDBusConnectionInterface* bus = 0;
|
||||||
QStringList konsoleServices;
|
QStringList konsoleServices;
|
||||||
|
|
||||||
|
@ -50,15 +51,15 @@ void DBusTest::initTestCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new Konsole with a separate process id
|
// Create a new Konsole with a separate process id
|
||||||
QProcess proc;
|
_process.reset(new QProcess(this));
|
||||||
proc.start("konsole");
|
_process->start("konsole");
|
||||||
proc.waitForStarted();
|
_process->waitForStarted();
|
||||||
if (proc.exitCode() != 0) {
|
if (_process->exitCode() != 0) {
|
||||||
kFatal() << "Unable to exec a new Konsole : " << proc.exitCode();
|
kFatal() << "Unable to exec a new Konsole : " << _process->exitCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for above Konsole to finish starting
|
// Wait for above Konsole to finish starting
|
||||||
QTest::qWait(5000);
|
QTest::qWait(3000);
|
||||||
|
|
||||||
serviceReply = bus->registeredServiceNames();
|
serviceReply = bus->registeredServiceNames();
|
||||||
if (!serviceReply.isValid())
|
if (!serviceReply.isValid())
|
||||||
|
@ -101,6 +102,8 @@ void DBusTest::cleanupTestCase()
|
||||||
QDBusReply<void> instanceReply = iface.call("close");
|
QDBusReply<void> instanceReply = iface.call("close");
|
||||||
if (!instanceReply.isValid())
|
if (!instanceReply.isValid())
|
||||||
kFatal() << "Unable to close Konsole :" << instanceReply.error();
|
kFatal() << "Unable to close Konsole :" << instanceReply.error();
|
||||||
|
|
||||||
|
_process.reset(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBusTest::testSessions()
|
void DBusTest::testSessions()
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include <QtDBus/QDBusInterface>
|
#include <QtDBus/QDBusInterface>
|
||||||
#include <QtDBus/QDBusReply>
|
#include <QtDBus/QDBusReply>
|
||||||
#include <QtCore/QProcess>
|
#include <QtCore/QProcess>
|
||||||
#include <QtCore/QTextCodec>
|
#include <QtCore/QScopedPointer>
|
||||||
#include <KDebug>
|
#include <KDebug>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -47,6 +47,7 @@ protected slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString _interfaceName;
|
QString _interfaceName;
|
||||||
|
QScopedPointer<QProcess> _process;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue