Part.h 6.07 KB
Newer Older
1
/*
2
    Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301  USA.
*/

#ifndef PART_H
#define PART_H

// KDE
#include <KParts/Factory>
#include <KParts/Part>
26
#include <kde_terminal_interface_v2.h>
27

28 29 30
// Konsole
#include "Profile.h"

31
class QAction;
32
class QStringList;
33
class QKeyEvent;
34 35 36

namespace Konsole
{
37
class Session;
38 39
class SessionController;
class ViewManager;
40
class ViewProperties;
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

/**
 * A factory which creates Konsole parts.
 */
class PartFactory : public KParts::Factory
{
protected:
    /** Reimplemented to create Konsole parts. */
    virtual KParts::Part* createPartObject(QWidget* parentWidget = 0,
                                           QObject* parent = 0,
                                           const char* classname = "KParts::Part",
                                           const QStringList& args = QStringList());
};

/**
 * A re-usable terminal emulator component using the KParts framework which can
 * be used to embed terminal emulators into other applications.
 */
59
class Part : public KParts::ReadOnlyPart , public TerminalInterfaceV2
60 61
{
Q_OBJECT
62
    Q_INTERFACES(TerminalInterfaceV2)
63 64
public:
    /** Constructs a new Konsole part with the specified parent. */
65
    explicit Part(QWidget* parentWidget , QObject* parent = 0);
66
    virtual ~Part();
67

68 69 70 71 72 73 74 75
    /** Reimplemented from TerminalInterface. */
    virtual void startProgram( const QString& program,
                               const QStringList& arguments );
    /** Reimplemented from TerminalInterface. */
    virtual void showShellInDir( const QString& dir );
    /** Reimplemented from TerminalInterface. */
    virtual void sendInput( const QString& text );

76 77 78 79 80 81 82 83 84
    /** Reimplemented from TerminalInterfaceV2. */
    virtual int terminalProcessId();

    /** Reimplemented from TerminalInterfaceV2. */
    virtual int foregroundProcessId();

    /** Reimplemented from TerminalInterfaceV2. */
    virtual QString foregroundProcessName();

85
public slots:
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    /**
     * Shows the dialog used to manage profiles in Konsole.  The dialog
     * will be non-modal and will delete itself when it is closed.
     *
     * This is experimental API and not guaranteed to be present in later
     * KDE 4 releases.
     *
     * @param parent The parent widget of the new dialog.
     */
    void showManageProfilesDialog(QWidget* parent);
    /**
     * Shows the dialog used to edit the profile used by the active session.  The
     * dialog will be non-modal and will delete itself when it is closed.
     *
     * This is experimental API and not guaranteed to be present in later KDE 4
     * releases.
     *
     * @param parent The parent widget of the new dialog.
     */
    void showEditCurrentProfileDialog(QWidget* parent);
    /**
     * Sends a profile change command to the active session.  This is equivalent to using
     * the konsoleprofile tool within the session to change its settings.  The @p text string
     * is a semi-colon separated list of property=value pairs, eg. "colors=Linux Colors"
     *
     * See the documentation for konsoleprofile for information on the format of @p text
     *
     * This is experimental API and not guaranteed to be present in later KDE 4 releases.
     */
    void changeSessionSettings(const QString& text);

    /**
     * Connects to an existing pseudo-teletype. See Session::openTeletype().
     * This must be called before the session is started by startProgram(),
     * or showShellInDir()
121 122
     *
     * @param ptyMasterFd The file descriptor of the pseudo-teletype (pty) master
123 124
     */
    void openTeletype(int ptyMasterFd);
125

126
signals:
127 128 129
    /**
     * Emitted when the key sequence for a shortcut, which is also a valid terminal key sequence,
     * is pressed while the terminal has focus.  By responding to this signal, the
130 131 132
     * controlling application can choose whether to execute the action associated with
     * the shortcut or ignore the shortcut and send the key
     * sequence to the terminal application.
133 134 135 136 137 138 139 140 141 142 143 144
     *
     * In the embedded terminal, shortcuts are overridden and sent to the terminal by default.
     * Set @p override to false to prevent this happening and allow the shortcut to be triggered
     * normally.
     *
     * overrideShortcut() is not called for shortcuts which are not valid terminal key sequences,
     * eg. shortcuts with two or more modifiers.
     *
     * @param event Describes the keys that were pressed.
     * @param override Set this to false to prevent the terminal display from overriding the shortcut
     */
    void overrideShortcut(QKeyEvent* event, bool& override);
145

146 147 148
protected:
    /** Reimplemented from KParts::PartBase. */
    virtual bool openFile();
149
    virtual bool openUrl(const KUrl & url);
150 151

private slots:
152
    // creates a new session using the specified profile.
Robert Knight's avatar
Robert Knight committed
153
    // call the run() method on the returned Session instance to begin the session
154
    Session* createSession(const Profile::Ptr profile = Profile::Ptr());
155
    void activeViewChanged(SessionController* controller);
156 157
    void activeViewTitleChanged(ViewProperties* properties);
    void showManageProfilesDialog();
158
    void terminalExited();
159
    void newTab();
160
    void overrideTerminalShortcut(QKeyEvent*,bool& override);
161

162
private:
163
    Session* activeSession() const;
164 165
    void setupActionsForSession(SessionController* session);
    void createGlobalActions();
166

167
private:
168 169
    ViewManager* _viewManager;
    SessionController* _pluggedController;
170
    QAction* _manageProfilesAction;
171 172
};

Stephan Binner's avatar
Stephan Binner committed
173
}
174 175

#endif // PART_H