Commit 2e6e657f authored by Robert Knight's avatar Robert Knight

Add Remote Connection dialog. More explanation later. Some more Q_UINT* -> quint* porting.

svn path=/branches/work/konsole-split-view/; revision=651051
parent 83491d35
...@@ -77,6 +77,7 @@ set(konsole_KDEINIT_SRCS ...@@ -77,6 +77,7 @@ set(konsole_KDEINIT_SRCS
TerminalDisplay.cpp TerminalDisplay.cpp
Vt102Emulation.cpp Vt102Emulation.cpp
Emulation.cpp Emulation.cpp
RemoteConnectionDialog.cpp
TerminalCharacterDecoder.cpp TerminalCharacterDecoder.cpp
ViewContainer.cpp ViewContainer.cpp
ViewManager.cpp ViewManager.cpp
...@@ -89,8 +90,10 @@ set(konsole_KDEINIT_SRCS ...@@ -89,8 +90,10 @@ set(konsole_KDEINIT_SRCS
XKB.cpp XKB.cpp
) )
set_source_files_properties(${konsole_KDEINIT_SRCS} PROPERTIES COMPILE_FLAGS "-Wuninitialized")
kde4_add_ui_files(konsole_KDEINIT_SRCS
RemoteConnectionDialog.ui
)
kde4_automoc(${konsole_KDEINIT_SRCS}) kde4_automoc(${konsole_KDEINIT_SRCS})
kde4_add_kdeinit_executable( konsole ${konsole_KDEINIT_SRCS}) kde4_add_kdeinit_executable( konsole ${konsole_KDEINIT_SRCS})
......
...@@ -34,10 +34,11 @@ ...@@ -34,10 +34,11 @@
#include <KXMLGUIFactory> #include <KXMLGUIFactory>
// Konsole // Konsole
#include "IncrementalSearchBar.h"
#include "Application.h" #include "Application.h"
#include "BookmarkHandler.h" #include "BookmarkHandler.h"
#include "IncrementalSearchBar.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "RemoteConnectionDialog.h"
#include "SessionList.h" #include "SessionList.h"
#include "ViewManager.h" #include "ViewManager.h"
#include "ViewSplitter.h" #include "ViewSplitter.h"
...@@ -87,15 +88,22 @@ void MainWindow::setupActions() ...@@ -87,15 +88,22 @@ void MainWindow::setupActions()
newTabAction->setIcon( KIcon("openterm") ); newTabAction->setIcon( KIcon("openterm") );
newTabAction->setText( i18n("New &Tab") ); newTabAction->setText( i18n("New &Tab") );
newTabAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_N) ); newTabAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_N) );
connect( newTabAction , SIGNAL(triggered()) , this , SLOT(newTab()) );
QAction* newWindowAction = collection->addAction("new-window"); QAction* newWindowAction = collection->addAction("new-window");
newWindowAction->setIcon( KIcon("window-new") ); newWindowAction->setIcon( KIcon("window-new") );
newWindowAction->setText( i18n("New &Window") ); newWindowAction->setText( i18n("New &Window") );
newWindowAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_M) ); newWindowAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_M) );
connect( newTabAction , SIGNAL(triggered()) , this , SLOT(newTab()) );
connect( newWindowAction , SIGNAL(triggered()) , this , SLOT(newWindow()) ); connect( newWindowAction , SIGNAL(triggered()) , this , SLOT(newWindow()) );
QAction* remoteConnectionAction = collection->addAction("remote-connection");
remoteConnectionAction->setText( i18n("Remote Connection...") );
remoteConnectionAction->setIcon( KIcon("network") );
remoteConnectionAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_R) );
connect( remoteConnectionAction , SIGNAL(triggered()) , this , SLOT(showRemoteConnectionDialog()) );
QAction* customSessionAction = collection->addAction("custom-session");
customSessionAction->setText( i18n("Custom Session...") );
KStandardAction::quit( Application::self() , SLOT(quit()) , collection ); KStandardAction::quit( Application::self() , SLOT(quit()) , collection );
// Bookmark Menu // Bookmark Menu
...@@ -153,6 +161,13 @@ void MainWindow::showPreferencesDialog() ...@@ -153,6 +161,13 @@ void MainWindow::showPreferencesDialog()
KToolInvocation::startServiceByDesktopName("konsole",QString()); KToolInvocation::startServiceByDesktopName("konsole",QString());
} }
void MainWindow::showRemoteConnectionDialog()
{
RemoteConnectionDialog dialog(this);
if ( dialog.exec() == QDialog::Accepted )
emit requestSession(dialog.sessionKey(),_viewManager);
}
void MainWindow::mergeWindows() void MainWindow::mergeWindows()
{ {
// merges all of the open Konsole windows into this window // merges all of the open Konsole windows into this window
......
...@@ -93,6 +93,7 @@ class MainWindow : public KMainWindow ...@@ -93,6 +93,7 @@ class MainWindow : public KMainWindow
void newTab(); void newTab();
void newWindow(); void newWindow();
void showPreferencesDialog(); void showPreferencesDialog();
void showRemoteConnectionDialog();
void showShortcutsDialog(); void showShortcutsDialog();
void sessionSelected(const QString&); void sessionSelected(const QString&);
......
/*
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 <QtDebug>
// KDE
#include <KLocale>
// Konsole
#include "Application.h"
#include "SessionManager.h"
#include "ui_RemoteConnectionDialog.h"
#include "RemoteConnectionDialog.h"
using namespace Konsole;
RemoteConnectionDialog::RemoteConnectionDialog(QWidget* parent)
: KDialog(parent)
{
setCaption("New Remote Connection");
setButtons( KDialog::Ok | KDialog::Cancel );
setButtonText( KDialog::Ok , i18n("Connect") );
_ui = new Ui::RemoteConnectionDialog();
_ui->setupUi(mainWidget());
// set initial UI state
_ui->userEdit->setFocus(Qt::OtherFocusReason);
}
QString RemoteConnectionDialog::user() const
{
return _ui->userEdit->text();
}
QString RemoteConnectionDialog::host() const
{
return _ui->hostEdit->text();
}
QString RemoteConnectionDialog::service() const
{
return "ssh";
}
QString RemoteConnectionDialog::sessionKey() const
{
SessionManager* manager = Application::self()->sessionManager();
CustomCommandSessionInfo* customSession =
new CustomCommandSessionInfo(manager->defaultSessionType()->path());
customSession->setCommand( service() );
customSession->setName( i18n("%1 at %2",user(),host()) );
customSession->setArguments( QStringList() << customSession->command(true,true) <<
user() + '@' + host() );
QString key = manager->addSessionType( customSession );
qDebug() << "session key = " << key;
return key;
}
/*
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 REMOTECONNECTIONDIALOG_H
#define REMOTECONNECTIONDIALOG_H
// KDE
#include <KDialog>
namespace Ui
{
class RemoteConnectionDialog;
};
namespace Konsole
{
class RemoteConnectionDialog : public KDialog
{
public:
RemoteConnectionDialog(QWidget* parent = 0 );
QString user() const;
QString host() const;
QString service() const;
QString sessionKey() const;
private:
Ui::RemoteConnectionDialog* _ui;
};
};
#endif // REMOTECONNECTIONDIALOG_H
<ui version="4.0" >
<class>RemoteConnectionDialog</class>
<widget class="QWidget" name="RemoteConnectionDialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>610</width>
<height>160</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="windowTitle" >
<string>Remote Connection</string>
</property>
<layout class="QVBoxLayout" >
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="userLabel" >
<property name="text" >
<string>User:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="userEdit" />
</item>
<item>
<widget class="QLabel" name="hostLabel" >
<property name="text" >
<string>Host:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="hostEdit" >
<property name="minimumSize" >
<size>
<width>180</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="lookupHostButton" >
<property name="text" >
<string>Lookup...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="backgroundColorLabel" >
<property name="text" >
<string>Background color:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="selectBackgroundButton" >
<property name="text" >
<string>Select...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="saveAsCustomCheckBox" >
<property name="text" >
<string>Save as custom session</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" native="1" name="sessionWidget" >
<layout class="QHBoxLayout" >
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="sessionNameLabel" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>Name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="sessionNameEdit" >
<property name="enabled" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="sessionEditButton" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>Edit...</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="0" />
<includes/>
<resources/>
<connections>
<connection>
<sender>saveAsCustomCheckBox</sender>
<signal>toggled(bool)</signal>
<receiver>sessionNameEdit</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>252</x>
<y>76</y>
</hint>
<hint type="destinationlabel" >
<x>141</x>
<y>104</y>
</hint>
</hints>
</connection>
<connection>
<sender>saveAsCustomCheckBox</sender>
<signal>toggled(bool)</signal>
<receiver>sessionEditButton</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>252</x>
<y>76</y>
</hint>
<hint type="destinationlabel" >
<x>275</x>
<y>104</y>
</hint>
</hints>
</connection>
<connection>
<sender>saveAsCustomCheckBox</sender>
<signal>toggled(bool)</signal>
<receiver>sessionNameLabel</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>304</x>
<y>89</y>
</hint>
<hint type="destinationlabel" >
<x>28</x>
<y>128</y>
</hint>
</hints>
</connection>
</connections>
</ui>
...@@ -19,16 +19,17 @@ SessionList::SessionList(SessionManager* manager , QObject* parent) ...@@ -19,16 +19,17 @@ SessionList::SessionList(SessionManager* manager , QObject* parent)
_group = new QActionGroup(this); _group = new QActionGroup(this);
QListIterator<SessionInfo*> iter(manager->availableSessionTypes()); QListIterator<QString> iter(manager->availableSessionTypes());
while (iter.hasNext()) while (iter.hasNext())
{ {
SessionInfo* info = iter.next(); const QString& key = iter.next();
SessionInfo* info = manager->sessionType(key);
QAction* action = new QAction(_group); QAction* action = new QAction(_group);
action->setText( info->name() ); action->setText( info->name() );
action->setIcon( KIcon(info->icon()) ); action->setIcon( KIcon(info->icon()) );
action->setData( info->path() ); action->setData( key );
} }
connect( _group , SIGNAL(triggered(QAction*)) , this , SLOT(triggered(QAction*)) ); connect( _group , SIGNAL(triggered(QAction*)) , this , SLOT(triggered(QAction*)) );
......
...@@ -168,6 +168,41 @@ QString SessionInfo::defaultWorkingDirectory() const ...@@ -168,6 +168,41 @@ QString SessionInfo::defaultWorkingDirectory() const
return _config->readPathEntry("Cwd"); return _config->readPathEntry("Cwd");
} }
CustomCommandSessionInfo::CustomCommandSessionInfo(const QString& path)
: SessionInfo(path)
{
}
void CustomCommandSessionInfo::setName(const QString& name)
{
_name = name;
}
QString CustomCommandSessionInfo::name() const
{
return _name;
}
void CustomCommandSessionInfo::setCommand(const QString& command)
{
_command = command;
}
QString CustomCommandSessionInfo::command(bool,bool) const
{
return _command;
}
void CustomCommandSessionInfo::setArguments(const QStringList& arguments)
{
_arguments = arguments;
}
QStringList CustomCommandSessionInfo::arguments() const
{
return _arguments;
}
SessionManager::SessionManager() SessionManager::SessionManager()
: _defaultSessionType(0), : _defaultSessionType(0),
_colorSchemeList(0) _colorSchemeList(0)
...@@ -193,7 +228,7 @@ SessionManager::SessionManager() ...@@ -193,7 +228,7 @@ SessionManager::SessionManager()
QString configFile = fileIter.next(); QString configFile = fileIter.next();
SessionInfo* newType = new SessionInfo(configFile); SessionInfo* newType = new SessionInfo(configFile);
_types << newType; addSessionType( newType );
if ( QFileInfo(configFile).fileName() == defaultSessionFilename ) if ( QFileInfo(configFile).fileName() == defaultSessionFilename )
_defaultSessionType = newType; _defaultSessionType = newType;
...@@ -208,7 +243,7 @@ SessionManager::SessionManager() ...@@ -208,7 +243,7 @@ SessionManager::SessionManager()
SessionManager::~SessionManager() SessionManager::~SessionManager()
{ {
QListIterator<SessionInfo*> infoIter(_types); QListIterator<SessionInfo*> infoIter(_types.values());
while (infoIter.hasNext()) while (infoIter.hasNext())
delete infoIter.next(); delete infoIter.next();
...@@ -227,22 +262,18 @@ void SessionManager::pushSessionSettings( const SessionInfo* info ) ...@@ -227,22 +262,18 @@ void SessionManager::pushSessionSettings( const SessionInfo* info )
addSetting( ColorScheme , SessionConfig , info->colorScheme() ); addSetting( ColorScheme , SessionConfig , info->colorScheme() );
} }
Session* SessionManager::createSession(QString configPath ) Session* SessionManager::createSession(QString key )
{ {
Session* session = 0; Session* session = 0;
const SessionInfo* info = 0;
//select default session type if not specified if ( key.isEmpty() )
if ( configPath.isEmpty() ) info = _defaultSessionType;
configPath = _defaultSessionType->path(); else
info = _types[key];
//search for SessionInfo object built from this config path
QListIterator<SessionInfo*> iter(_types);
while (iter.hasNext())
{
const SessionInfo* const info = iter.next();
if ( info->path() == configPath ) if ( true )
{ {
//supply settings from session config //supply settings from session config
pushSessionSettings( info ); pushSessionSettings( info );
...@@ -272,9 +303,7 @@ Session* SessionManager::createSession(QString configPath ) ...@@ -272,9 +303,7 @@ Session* SessionManager::createSession(QString configPath )
//add session to active list //add session to active list
_sessions << session; _sessions << session;
break;
} }
}
Q_ASSERT( session ); Q_ASSERT( session );
...@@ -287,9 +316,17 @@ void SessionManager::sessionTerminated(Session* session) ...@@ -287,9 +316,17 @@ void SessionManager::sessionTerminated(Session* session)
session->deleteLater(); session->deleteLater();
} }
QList<SessionInfo*> SessionManager::availableSessionTypes() QList<QString> SessionManager::availableSessionTypes()
{ {
return _types; return _types.keys();
}
SessionInfo* SessionManager::sessionType(const QString& key) const
{
if ( _types.contains(key) )
return _types[key];
else
return 0;
} }
SessionInfo* SessionManager::defaultSessionType() SessionInfo* SessionManager::defaultSessionType()
...@@ -325,4 +362,22 @@ QVariant SessionManager::activeSetting( Setting setting ) const ...@@ -325,4 +362,22 @@ QVariant SessionManager::activeSetting( Setting setting ) const
return value; return value;
} }
QString SessionManager::addSessionType(SessionInfo* type)
{
QString key;
for ( int counter = 0;;counter++ )
{
if ( !_types.contains(type->path() + QString::number(counter)) )
{
key = type->path() + QString::number(counter);
break;
}
}
_types.insert(key,type);
return key;
}