Commit 95f053e3 authored by Robert Knight's avatar Robert Knight

* Use kdelibs facilities to check for compositing support

* Initial draft of dialogs to manage sessions
    - SessionTypeDialog lists available session types and allows the
      user to trigger creation, editing or removal of a type.
    - EditSessionDialog allows the user to edit an individual session
      type.
* Remove access to the old KDE 3 preferences dialog
* Began a re-write of the Konsole part, the intention is to avoid
  the duplication of code between the part and the main application
  which occurred in KDE 3 and also to make more of the functionality
  from the main application available to the part's clients.
* Implement the history size dialog
* Implement SSH bookmarks
* Implement Bookmark Tabs as Folders
* Allow the user to choose which sessions are shown in the 'File' menu
* Implement 'background mode'.  When Konsole is started in this mode
  (by running "konsole --background-mode") it creates a new session in the 
  background which can be displayed or hidden at any time by pressing F12.
  Idea taken from Yakuake. 
* Use tab bar rather than a tab widget for the view container by default,
  removes the frame around the terminal display, this does not look correct
  if you are using the ported-from-3.5 KDE "Plastik" style in KDE 4.  
  Qt's very-similar-looking Platique style produces the desired results. 
* Fixed two spectacular memory leaks.
* Add option to split the view left/right ( in addition to top/bottom ) and
  allow more than two views open at once.  Dividing the view into a grid
  ( aka. "recursive splitting" ) is not yet supported.  
* Add menu options to Close Active View and Close Others ( which closes 
  all views except the active one )

// Behind the scenes stuff

* Rewrote color scheme code
    ColorSchema -> ColorScheme
    ColorSchemaList -> replaced with global ColorSchemeManager
    KDE 4 INI-format color schemes are used if available with fallback to the KDE 3
    .schema files otherwise.
    * Some more Qt 3 -> 4 porting:
    Q3TextEdit -> QTextEdit
    Q3IntDict<V> -> QHash<int,V>
    Q3PtrList<T> -> QList<T*>
* Various adjustments to resource loading so that the various
  *Manager classes can find their resources when being used in
  an application other than Konsole ( eg. when being used in a part )
* Change access to singleton managers, the *Manager classes
  now have an instance() method to access the global instance and
  a setInstance() method which is called by the Application or KPart
  constructor to create the manager initially.
* Remove all references to MainWindow from the ViewManager and move 
  the relevant code to the MainWindow class itself.  

svn path=/branches/work/konsole-split-view/; revision=654402
parent 2e6e657f
......@@ -5,6 +5,8 @@
<Menu name="file"><text>File</text>
<Action name="new-tab" />
<Action name="new-window" />
<Action name="remote-connection" />
<Action name="custom-session" />
<Separator/>
<ActionList name="new-session-types"/>
<Separator/>
......@@ -20,7 +22,11 @@
<Menu name="view"><text>View</text>
<DefineGroup name="session-view-operations"/>
<Separator/>
<Action name="split-view"/>
<Action name="split-view-left-right"/>
<Action name="split-view-top-bottom"/>
<Action name="close-active-view"/>
<Action name="close-other-views"/>
<Separator/>
<Action name="detach-view"/>
<Action name="merge-windows"/>
<Separator/>
......@@ -32,7 +38,6 @@
<Separator/>
<Action name="configure-notifications"/>
<Action name="configure-shortcuts"/>
<Action name="configure-application"/>
</Menu>
<Menu name="help"><text>Help</text>
......
......@@ -36,6 +36,9 @@
<Action name="paste"/>
<Action name="clear-history-and-reset"/>
<Separator/>
<Action name="show-menubar"/>
<Action name="edit-current-session" />
<Separator/>
<Action name="close-session"/>
</Menu>
</kpartgui>
......@@ -19,28 +19,43 @@
#include "kdebug.h"
// KDE
#include <KAction>
#include <KCmdLineArgs>
#include <KWM>
// Konsole
#include "ColorScheme.h"
#include "SessionList.h"
#include "SessionManager.h"
#include "KeyTrans.h"
#include "KeyboardTranslator.h"
#include "Application.h"
#include "MainWindow.h"
#include "Session.h"
#include "TerminalDisplay.h"
#include "ViewManager.h"
using namespace Konsole;
// global variable to determine whether or not true transparency should be used
// this should be made into a static class variable of Application
int true_transparency = true;
Application::Application()
: _sessionList(0)
, _backgroundInstance(0)
{
// create session manager
_sessionManager = new SessionManager();
SessionManager::setInstance( new SessionManager() );
// create color scheme manager
ColorSchemeManager::setInstance( new ColorSchemeManager() );
// load keyboard layouts
// new keyboard translator manager
KeyboardTranslatorManager::setInstance( new KeyboardTranslatorManager() );
// old keyboard translator manager
KeyTrans::loadAll();
// check for compositing functionality
TerminalDisplay::setTransparencyEnabled( KWM::compositingActive() );
};
Application* Application::self()
......@@ -51,7 +66,7 @@ Application* Application::self()
MainWindow* Application::newMainWindow()
{
MainWindow* window = new MainWindow();
window->setSessionList( new SessionList(sessionManager(),window) );
window->setSessionList( new SessionList(window) );
connect( window , SIGNAL(requestSession(const QString&,ViewManager*)),
this , SLOT(createSession(const QString&,ViewManager*)));
......@@ -62,22 +77,64 @@ MainWindow* Application::newMainWindow()
int Application::newInstance()
{
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
// create a new window and session to run in it
MainWindow* window = newMainWindow();
createSession( QString() , window->viewManager() );
window->show();
// if the background-mode argument is supplied, start the background session
// ( or bring to the front if it already exists )
if ( args->isSet("background-mode") )
{
if ( _backgroundInstance )
{
return 0;
}
KAction* action = new KAction(window);
KShortcut shortcut = action->shortcut();
action->setObjectName("Konsole Background Mode");
//TODO - Customisable key sequence for this
action->setGlobalShortcut( KShortcut(QKeySequence(Qt::Key_F12)) );
_backgroundInstance = window;
connect( action , SIGNAL(triggered()) , this , SLOT(toggleBackgroundInstance()) );
}
else
{
window->show();
}
return 0;
}
SessionManager* Application::sessionManager()
void Application::toggleBackgroundInstance()
{
return _sessionManager;
Q_ASSERT( _backgroundInstance );
if ( !_backgroundInstance->isVisible() )
{
_backgroundInstance->show();
// ensure that the active terminal display has the focus.
// without this, an odd problem occurred where the focus widgetwould change
// each time the background instance was shown
_backgroundInstance->viewManager()->activeView()->setFocus();
}
else
{
_backgroundInstance->hide();
}
}
Application::~Application()
{
delete _sessionManager;
delete SessionManager::instance();
delete ColorSchemeManager::instance();
SessionManager::setInstance(0);
ColorSchemeManager::setInstance(0);
}
void Application::detachView(Session* session)
......@@ -89,7 +146,7 @@ void Application::detachView(Session* session)
void Application::createSession(const QString& key , ViewManager* view)
{
Session* session = _sessionManager->createSession(key);
Session* session = SessionManager::instance()->createSession(key);
session->setListenToKeyPress(true);
//session->setConnect(true);
......
......@@ -27,7 +27,7 @@ class KCmdLineArgs;
namespace Konsole
{
class ColorSchemeManager;
class SessionList;
class SessionManager;
class ViewManager;
......@@ -71,17 +71,17 @@ public:
/** Returns the Application instance */
static Application* self();
/** Returns the session manager */
SessionManager* sessionManager();
private slots:
void createSession(const QString& key, ViewManager* view);
void detachView(Session* session);
void toggleBackgroundInstance();
private:
KCmdLineArgs* _arguments;
SessionManager* _sessionManager;
SessionList* _sessionList;
MainWindow* _backgroundInstance;
};
};
......
......@@ -36,32 +36,24 @@
// Konsole
#include "BookmarkHandler.h"
#include "SessionController.h"
#include "ViewProperties.h"
using namespace Konsole;
BookmarkHandler::BookmarkHandler( KActionCollection* collection, KMenu* menu, bool toplevel )
: QObject( collection ),
BookmarkHandler::BookmarkHandler( KActionCollection* collection,
KMenu* menu,
bool toplevel ,
QObject* parent )
: QObject( parent ),
KBookmarkOwner(),
m_toplevel(toplevel),
m_controller( 0 )
m_activeView(0)
{
setObjectName( "BookmarkHandler" );
m_menu = menu;
// KDE3.5 - Konsole's bookmarks are now in konsole/bookmarks.xml
// TODO: Consider removing for KDE4
QString new_bm_file = KStandardDirs::locateLocal( "data", "konsole/bookmarks.xml" );
if ( !QFile::exists( new_bm_file ) ) {
QString old_bm_file = KStandardDirs::locateLocal( "data", "kfile/bookmarks.xml" );
if ( QFile::exists( old_bm_file ) )
// We want sync here...
if ( !KIO::NetAccess::file_copy( KUrl( old_bm_file ),
KUrl ( new_bm_file ), 0 ) ) {
kWarning()<<KIO::NetAccess::lastErrorString()<<endl;
}
}
m_file = KStandardDirs::locate( "data", "konsole/bookmarks.xml" );
if ( m_file.isEmpty() )
......@@ -102,9 +94,14 @@ bool BookmarkHandler::editBookmarkEntry() const
QString BookmarkHandler::currentUrl() const
{
if ( m_controller )
return urlForView(m_activeView);
}
QString BookmarkHandler::urlForView(ViewProperties* view) const
{
if ( view )
{
return m_controller->url().prettyUrl();
return view->url().prettyUrl();
}
else
{
......@@ -114,7 +111,12 @@ QString BookmarkHandler::currentUrl() const
QString BookmarkHandler::currentTitle() const
{
const KUrl &u = m_controller ? m_controller->url() : KUrl();
return titleForView(m_activeView);
}
QString BookmarkHandler::titleForView(ViewProperties* view) const
{
const KUrl &u = view ? view->url() : KUrl();
if (u.isLocalFile())
{
QString path = u.path();
......@@ -124,13 +126,42 @@ QString BookmarkHandler::currentTitle() const
return u.prettyUrl();
}
void BookmarkHandler::setController( SessionController* controller )
bool BookmarkHandler::supportsTabs() const
{
return true;
}
QList<QPair<QString,QString> > BookmarkHandler::currentBookmarkList() const
{
QList<QPair<QString,QString> > list;
QListIterator<ViewProperties*> iter( m_views );
while ( iter.hasNext() )
{
ViewProperties* next = iter.next();
list << QPair<QString,QString>(titleForView(next) , urlForView(next));
}
return list;
}
void BookmarkHandler::setViews(const QList<ViewProperties*>& views)
{
qDebug() << "BookmarkHandler - View list changed.";
m_views = views;
}
QList<ViewProperties*> BookmarkHandler::views() const
{
return m_views;
}
void BookmarkHandler::setActiveView( ViewProperties* view )
{
m_controller = controller;
m_activeView = view;
}
SessionController* BookmarkHandler::controller() const
ViewProperties* BookmarkHandler::activeView() const
{
return m_controller;
return m_activeView;
}
#include "BookmarkHandler.moc"
......@@ -32,7 +32,7 @@ class KActionCollection;
namespace Konsole
{
class SessionController;
class ViewProperties;
/**
* This class handles the communication between the bookmark menu and the active session,
......@@ -58,7 +58,7 @@ public:
* @param menu The menu which the bookmark actions should be added to
* @param toplevel TODO: Document me
*/
BookmarkHandler( KActionCollection* collection , KMenu* menu, bool toplevel );
BookmarkHandler( KActionCollection* collection , KMenu* menu, bool toplevel , QObject* parent );
~BookmarkHandler();
QMenu * popupMenu();
......@@ -67,24 +67,28 @@ public:
virtual QString currentTitle() const;
virtual bool addBookmarkEntry() const;
virtual bool editBookmarkEntry() const;
virtual bool supportsTabs() const;
virtual QList<QPair<QString,QString> > currentBookmarkList() const;
/**
* Returns the menu which this bookmark handler inserts its actions into.
*/
KMenu *menu() const { return m_menu; }
QList<ViewProperties*> views() const;
ViewProperties* activeView() const;
public slots:
/**
* Sets the controller used to retrieve the current session URL when
* the "Add Bookmark" menu item is selected.
*/
void setController( SessionController* controller );
/**
* Returns the controller used to retrieve the current session URL when
* the "Add Bookmark" menu item is selected.
*
*/
SessionController* controller() const;
void setViews( const QList<ViewProperties*>& views );
void setActiveView( ViewProperties* view );
Q_SIGNALS:
signals:
/**
* Emitted when the user selects a bookmark from the bookmark menu.
*
......@@ -93,15 +97,20 @@ Q_SIGNALS:
*/
void openUrl( const KUrl& url );
private Q_SLOTS:
void openBookmark( const KBookmark & bm, Qt::MouseButtons, Qt::KeyboardModifiers );
private:
QString titleForView( ViewProperties* view ) const;
QString urlForView( ViewProperties* view ) const;
KMenu* m_menu;
KBookmarkMenu* m_bookmarkMenu;
QString m_file;
bool m_toplevel;
SessionController* m_controller;
ViewProperties* m_activeView;
QList<ViewProperties*> m_views;
};
};
......
......@@ -56,6 +56,8 @@ endif(KONSOLE_GENERATE_LINEFONT)
set(konsole_KDEINIT_SRCS
${sessionadaptors_SRCS}
BlockArray.cpp
ColorScheme.cpp
EditSessionDialog.cpp
Filter.cpp
HistorySizeDialog.cpp
IncrementalSearchBar.cpp
......@@ -70,6 +72,7 @@ set(konsole_KDEINIT_SRCS
SessionList.cpp
SessionListWidget.cpp
SessionManager.cpp
SessionTypeDialog.cpp
History.cpp
Pty.cpp
Screen.cpp
......@@ -85,13 +88,14 @@ set(konsole_KDEINIT_SRCS
ViewSplitter.cpp
ZModemDialog.cpp
konsole_wcwidth.cpp
schema.cpp
start.cpp
XKB.cpp
)
kde4_add_ui_files(konsole_KDEINIT_SRCS
EditSessionDialog.ui
SessionTypeDialog.ui
RemoteConnectionDialog.ui
)
kde4_automoc(${konsole_KDEINIT_SRCS})
......@@ -119,35 +123,49 @@ install(TARGETS konsole DESTINATION ${BIN_INSTALL_DIR})
set(konsolepart_PART_SRCS
#${sessionadaptors_SRCS}
Pty.cpp
BlockArray.cpp
konsole_part.cpp
schema.cpp
Session.cpp
ZModemDialog.cpp
TerminalDisplay.cpp
Vt102Emulation.cpp
Screen.cpp
konsole_wcwidth.cpp
BlockArray.cpp
BookmarkHandler.cpp
ColorScheme.cpp
EditSessionDialog.cpp
Emulation.cpp
History.cpp
Filter.cpp
History.cpp
HistorySizeDialog.cpp
IncrementalSearchBar.cpp
KeyTrans.cpp
TerminalCharacterDecoder.cpp
SessionManager.cpp
MainWindow.cpp
Part.cpp
ProcessInfo.cpp
Pty.cpp
RemoteConnectionDialog.cpp
Screen.cpp
ScreenWindow.cpp
Filter.cpp
Session.cpp
SessionController.cpp
SessionList.cpp
SessionListWidget.cpp
SessionManager.cpp
SessionTypeDialog.cpp
TerminalCharacterDecoder.cpp
TerminalDisplay.cpp
ViewContainer.cpp
ViewManager.cpp
ViewProperties.cpp
ViewSplitter.cpp
Vt102Emulation.cpp
XKB.cpp
ZModemDialog.cpp
konsole_wcwidth.cpp
)
set_source_files_properties(${konsolepart_PART_SRCS} PROPERTIES COMPILE_FLAGS -Wuninitialized)
kde4_automoc(${konsolepart_PART_SRCS})
kde4_add_plugin(konsolepart WITH_PREFIX ${konsolepart_PART_SRCS})
set_target_properties(konsolepart PROPERTIES DEFINE_SYMBOL KONSOLE_PART)
target_link_libraries(konsolepart ${KDE4_KDE3SUPPORT_LIBS} )
target_link_libraries(konsolepart ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS} )
if(X11_XTest_LIB)
target_link_libraries(konsolepart ${X11_XTest_LIB} )
endif(X11_XTest_LIB)
......
This diff is collapsed.
/*
This source file is part of Konsole, a terminal emulator.
Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>
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 COLORSCHEME_H
#define COLORSCHEME_H
// Qt
#include <QHash>
#include <QList>
#include <QMetaType>
#include <QIODevice>
// Konsole
#include "TECommon.h"
class QIODevice;
class KConfig;
namespace Konsole
{
/**
* Represents a color scheme for a terminal display.
*
* The color scheme includes the palette of colors used to draw the text and character backgrounds
* in the display and the opacity level of the display background.
*/
class ColorScheme
{
public:
/**
* Constructs a new color scheme which is initialised to the default color set
* for Konsole.
*/
ColorScheme();
~ColorScheme();
/** Sets the name of the color scheme */
void setName(const QString& name);
/** Returns the name of the color scheme */
QString name() const;
/** Reads the color scheme from the specified configuration source */
void read(KConfig& config);
/** Writes the color scheme to the specified configuration source */
void write(KConfig& config) const;
/** Sets a single entry within the color palette. */
void setColorTableEntry(int index , const ColorEntry& entry);
/**
* Returns a pointer to an array of color entries which form the palette
* for this color scheme.
* The array has TABLE_COLORS entries
*
* TODO: More documentation
*/
const ColorEntry* colorTable() const;
/**
* Convenience method. Returns the foreground color for this scheme, this
* is the primary color used to draw the text in this scheme.
*/
QColor foregroundColor() const;
/**
* Convenience method. Returns the background color for this scheme, this
* is the primary color used to draw the terminal background in this scheme.
*/
QColor backgroundColor() const;
/**
* Sets the opacity level of the display background. A value of
* 0 represents a completely transparent background, up to a value of 1
* representing a completely opaque background.
*
* Defaults to 1.
*
* TODO: More documentation
*/
void setOpacity(qreal opacity);
/**
* Returns the opacity level for this color scheme, see setOpacity()
* TODO: More documentation
*/
qreal opacity() const;
//void setCursorColor(const QColor& color);
//QColor cursorColor() const;
//void setCursorShape(int shape);
//int cursorShape() const;
private:
// reads a single colour entry from a KConfig source
ColorEntry readColorEntry(KConfig& config , const QString& colorName);
// writes a single colour entry to a KConfig source
void writeColorEntry(KConfig& config , const QString& colorName, const ColorEntry& entry) const;
QString _name;
qreal _opacity;
ColorEntry* _table; // pointer to custom color table or 0 if the default
// color scheme is being used
static QString colorNameForIndex(int index);
static const char* colorNames[TABLE_COLORS];
static const ColorEntry defaultTable[]; // table of default color entries
};
/**
* Reads a color scheme stored in the .schema format used in the KDE 3 incarnation
* of Konsole
*
* Only the basic essentials ( title and color palette entries ) are currently
* supported. Additional options such as background image and background
* blend colors are ignored.
*/
class KDE3ColorSchemeReader
{
public:
/**
* Constructs a new reader which reads from the specified device.
* The device should be open in read-only mode.
*/
KDE3ColorSchemeReader( QIODevice* device );
/**
* Reads and parses the contents of the .schema file from the input
* device and returns the ColorScheme defined within it.
*
* Returns a null pointer if an error occurs whilst parsing
* the contents of the file.
*/
ColorScheme* read();
private:
// reads a line from the file specifying a colour palette entry
// format is: color [index] [red] [green] [blue] [transparent] [bold]
void readColorLine(const QString& line , ColorScheme* scheme);
void readTitleLine(const QString& line , ColorScheme* scheme);
QIODevice* _device;
};
/**
* Manages the color schemes available for use by terminal displays.
* See ColorScheme
*/
class ColorSchemeManager
{
public:
/**
* Constructs a new ColorSchemeManager and loads the list
* of available color schemes.
*
* The color schemes themselves are not loaded until they are first
* requested via a call to findColorScheme()
*/
ColorSchemeManager();
~ColorSchemeManager();
/**
* Returns the default color scheme for Konsole
*/
const ColorScheme* defaultColorScheme() const;
/**