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 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.
*/
// Qt
#include <QFile>
#include <QFileInfo>
// KDE
#include <KConfig>
#include <KLocale>
#include <KStandardDirs>
// Konsole
#include "ColorScheme.h"
#include "TECommon.h"
using namespace Konsole;
const ColorEntry ColorScheme::defaultTable[TABLE_COLORS] =
// The following are almost IBM standard color codes, with some slight
// gamma correction for the dim colors to compensate for bright X screens.
// It contains the 8 ansiterm/xterm colors in 2 intensities.
{
ColorEntry( QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry(
QColor(0xFF,0xFF,0xFF), 1, 0 ), // Dfore, Dback
ColorEntry( QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry(
QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red
ColorEntry( QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry(
QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow
ColorEntry( QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry(
QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta
ColorEntry( QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry(
QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White
// intensive
ColorEntry( QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry(
QColor(0xFF,0xFF,0xFF), 1, 0 ),
ColorEntry( QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry(
QColor(0xFF,0x54,0x54), 0, 0 ),
ColorEntry( QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry(
QColor(0xFF,0xFF,0x54), 0, 0 ),
ColorEntry( QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry(
QColor(0xFF,0x54,0xFF), 0, 0 ),
ColorEntry( QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry(
QColor(0xFF,0xFF,0xFF), 0, 0 )
};
const char* ColorScheme::colorNames[TABLE_COLORS] =
{
"Foreground",
"Background",
"Color0",
"Color1",
"Color2",
"Color3",
"Color4",
"Color5",
"Color6",
"Color7",
"ForegroundIntense",
"BackgroundIntense",
"Color0Intense",
"Color1Intense",
"Color2Intense",
"Color3Intense",
"Color4Intense",
"Color5Intense",
"Color6Intense",
"Color7Intense"
};
ColorSchemeManager* ColorSchemeManager::_instance = 0;
ColorScheme::ColorScheme()
{
_table = 0;
}
ColorScheme::~ColorScheme()
{
delete[] _table;
}
void ColorScheme::setName(const QString& name) { _name = name; }
QString ColorScheme::name() const { return _name; }
void ColorScheme::setColorTableEntry(int index , const ColorEntry& entry)
{
Q_ASSERT( index >= 0 && index < TABLE_COLORS );
if ( !_table )
_table = new ColorEntry[TABLE_COLORS];
_table[index] = entry;