summaryrefslogtreecommitdiffstats
path: root/kdesktop/minicli.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kdesktop/minicli.cpp')
-rw-r--r--kdesktop/minicli.cpp139
1 files changed, 132 insertions, 7 deletions
diff --git a/kdesktop/minicli.cpp b/kdesktop/minicli.cpp
index 096b293d0..2cf225bcc 100644
--- a/kdesktop/minicli.cpp
+++ b/kdesktop/minicli.cpp
@@ -1,5 +1,8 @@
/* This file is part of the KDE project
+ Autocompletion code:
+ Copyright (C) 2009 Timothy Pearson <kb9vqf@pearsoncomputing.net>
+
Copyright (C) 1999-2002,2003 Dawit Alemayehu <adawit@kde.org>
Copyright (C) 2000 Malte Starostik <starosti@zedat.fu-berlin.de>
Copyright (C) 2003 Sven Leiber <s.leiber@web.de>
@@ -76,6 +79,8 @@ Minicli::Minicli( QWidget *parent, const char *name)
:KDialog( parent, name, false, WType_TopLevel ),
m_autoCheckedRunInTerm(false)
{
+ m_pURLCompletion = 0L;
+
setPlainCaption( i18n("Run Command") );
KWin::setIcons( winId(), DesktopIcon("run"), SmallIcon("run") );
@@ -121,6 +126,13 @@ Minicli::Minicli( QWidget *parent, const char *name)
m_dlg->leUsername->setText("root");
+ // Autocomplete system
+ m_filesystemAutocomplete = 0;
+ m_histfilesystemAutocomplete = 0;
+ m_pURLCompletion = new KURLCompletion();
+ //m_pURLCompletion->setCompletionMode( KGlobalSettings::completionMode() );
+ connect( m_pURLCompletion, SIGNAL( match(const QString&) ), SLOT( slotMatch(const QString&) ));
+
// Main widget buttons...
connect( m_dlg->pbRun, SIGNAL(clicked()), this, SLOT(accept()) );
connect( m_dlg->pbCancel, SIGNAL(clicked()), this, SLOT(reject()) );
@@ -137,6 +149,8 @@ Minicli::Minicli( QWidget *parent, const char *name)
connect(m_dlg->cbPriority, SIGNAL(toggled(bool)), SLOT(slotChangeScheduler(bool)));
connect(m_dlg->slPriority, SIGNAL(valueChanged(int)), SLOT(slotPriority(int)));
connect(m_dlg->cbRealtime, SIGNAL(toggled(bool)), SLOT(slotRealtime(bool)));
+ connect(m_dlg->cbAutocomplete, SIGNAL(toggled(bool)), SLOT(slotAutocompleteToggled(bool)));
+ connect(m_dlg->cbAutohistory, SIGNAL(toggled(bool)), SLOT(slotAutohistoryToggled(bool)));
connect(m_dlg->cbRunAsOther, SIGNAL(toggled(bool)), SLOT(slotChangeUid(bool)));
connect(m_dlg->leUsername, SIGNAL(lostFocus()), SLOT(updateAuthLabel()));
connect(m_dlg->cbRunInTerminal, SIGNAL(toggled(bool)), SLOT(slotTerminal(bool)));
@@ -149,6 +163,7 @@ Minicli::Minicli( QWidget *parent, const char *name)
Minicli::~Minicli()
{
delete m_filterData;
+ delete m_pURLCompletion;
}
void Minicli::setCommand(const QString& command)
@@ -198,6 +213,19 @@ void Minicli::loadConfig()
m_dlg->cbCommand->setHistoryItems( histList );
m_dlg->cbCommand->blockSignals( block );
+ m_dlg->cbAutocomplete->setChecked( KDesktopSettings::miniCLIFilesystemAutoComplete() );
+ m_dlg->cbAutohistory->setChecked( KDesktopSettings::miniCLIHistoryAndFilesystemAutoComplete() );
+
+ m_filesystemAutocomplete = KDesktopSettings::miniCLIFilesystemAutoComplete();
+ m_histfilesystemAutocomplete = KDesktopSettings::miniCLIHistoryAndFilesystemAutoComplete();
+
+ if (m_histfilesystemAutocomplete == true) {
+ m_dlg->cbAutocomplete->setDisabled( true );
+ }
+ else {
+ m_dlg->cbAutocomplete->setDisabled( false );
+ }
+
QStringList compList = KDesktopSettings::completionItems();
if( compList.isEmpty() )
m_dlg->cbCommand->completionObject()->setItems( histList );
@@ -241,8 +269,10 @@ void Minicli::saveConfig()
{
KDesktopSettings::setHistory( m_dlg->cbCommand->historyItems() );
KDesktopSettings::setTerminalApps( m_terminalAppList );
- KDesktopSettings::setCompletionItems( m_dlg->cbCommand->completionObject()->items() );
+ //KDesktopSettings::setCompletionItems( m_dlg->cbCommand->completionObject()->items() );
KDesktopSettings::setCompletionMode( m_dlg->cbCommand->completionMode() );
+ KDesktopSettings::setMiniCLIFilesystemAutoComplete( m_filesystemAutocomplete );
+ KDesktopSettings::setMiniCLIHistoryAndFilesystemAutoComplete( m_histfilesystemAutocomplete );
KDesktopSettings::writeConfig();
}
@@ -369,6 +399,17 @@ int Minicli::runCommand()
cmd = uri.path();
else
cmd = uri.url();
+
+ QCString asn;
+ if( qApp->desktop()->isVirtualDesktop())
+ {
+ asn = KStartupInfo::createNewStartupId();
+ KStartupInfoId id;
+ id.initId( asn );
+ KStartupInfoData data;
+ data.setXinerama( qApp->desktop()->screenNumber( this ));
+ KStartupInfo::sendChange( id, data );
+ }
// Determine whether the application should be run through
// the command line (terminal) interface...
@@ -504,7 +545,7 @@ int Minicli::runCommand()
case KURIFilterData::HELP:
{
// No need for kfmclient, KRun does it all (David)
- (void) new KRun( m_filterData->uri(), parentWidget());
+ (void) new KRun( m_filterData->uri(), parentWidget(), asn );
return 0;
}
case KURIFilterData::EXECUTABLE:
@@ -516,7 +557,7 @@ int Minicli::runCommand()
if (service && service->isValid() && service->type() == "Application")
{
notifyServiceStarted(service);
- KRun::run(*service, KURL::List());
+ KRun::run(*service, KURL::List(), parentWidget(), asn );
return 0;
}
}
@@ -551,7 +592,7 @@ int Minicli::runCommand()
if (service && service->isValid() && service->type() == "Application")
{
notifyServiceStarted(service);
- KRun::run(*service, KURL::List(), this);
+ KRun::run(*service, KURL::List(), parentWidget(), asn );
return 0;
}
@@ -559,7 +600,7 @@ int Minicli::runCommand()
if (service && service->isValid() && service->type() == "Application")
{
notifyServiceStarted(service);
- KRun::run(*service, KURL::List(), this);
+ KRun::run(*service, KURL::List(), parentWidget(), asn );
return 0;
}
@@ -571,7 +612,7 @@ int Minicli::runCommand()
}
}
- if ( KRun::runCommand( cmd, exec, m_iconName ) )
+ if ( KRun::runCommand( cmd, exec, m_iconName, parentWidget(), asn ) )
return 0;
else
{
@@ -615,10 +656,58 @@ void Minicli::slotCmdChanged(const QString& text)
return;
}
+ else if ((m_filesystemAutocomplete == true) && ( m_pURLCompletion )) {
+ // Attempt to autocomplete the entered URL if it starts with the / character, meaning I am looking for something on the filesystem
+ // Also use autocompletion if it appears that I am using some kind of ioslave, except the http:// ioslave
+ m_urlCompletionStarted = true; // flag for slotMatch()
+
+ if ((text.startsWith( "/" ) || text.startsWith( "~" ) || (text.contains("://", false) != 0)) && (text.contains("http://", false) == 0)) {
+ QString completion = m_pURLCompletion->makeCompletion( text );
+ }
+ }
m_parseTimer->start(250, true);
}
+// Handle match() from m_pURLCompletion
+void Minicli::slotMatch( const QString &match )
+{
+ QString current_text;
+ QStringList histList = KDesktopSettings::history();
+ int maxHistory = KDesktopSettings::historyLength();
+ int maxAutocompletion = KDesktopSettings::miniCLIAutocompletionLength();
+
+ if ( match.isEmpty() ) // this case is handled directly
+ return;
+
+ // Check flag to avoid match() raised by rotation
+ if ( m_urlCompletionStarted ) {
+ m_urlCompletionStarted = false;
+
+ if (m_filesystemAutocomplete == true) {
+ bool block = m_dlg->cbCommand->signalsBlocked();
+ m_dlg->cbCommand->blockSignals( true );
+ QStringList items = m_pURLCompletion->allMatches();
+ items.sort();
+ if (m_histfilesystemAutocomplete == true) {
+ // Add the history to the list
+ histList += items;
+ maxHistory += maxAutocompletion;
+ }
+ else {
+ histList = items;
+ maxHistory = maxAutocompletion;
+ }
+ current_text = m_dlg->cbCommand->currentText();
+ //histList.prepend ( current_text ); // Add the current text to the autocompletion list
+ m_dlg->cbCommand->setMaxCount( maxHistory );
+ m_dlg->cbCommand->completionObject()->setItems( histList );
+ m_dlg->cbCommand->setCurrentText( current_text );
+ m_dlg->cbCommand->blockSignals( block );
+ }
+ }
+}
+
void Minicli::slotAdvanced()
{
if (m_dlg->gbAdvanced->isHidden())
@@ -722,7 +811,7 @@ void Minicli::setIcon ()
void Minicli::updateAuthLabel()
{
- if (m_dlg->cbPriority->isChecked() && (m_iPriority > 50) ||
+ if ((m_dlg->cbPriority->isChecked() && (m_iPriority > 50)) ||
(m_iScheduler != StubProcess::SchedNormal))
{
if (!m_prevCached && !m_dlg->leUsername->text().isEmpty())
@@ -843,6 +932,42 @@ void Minicli::slotRealtime(bool enabled)
updateAuthLabel();
}
+void Minicli::slotAutocompleteToggled(bool enabled)
+{
+ if (enabled)
+ {
+ // Enable filesystem autocompletion
+ m_filesystemAutocomplete = true;
+ }
+ else {
+ // Enable history only autocompletion
+ m_filesystemAutocomplete = false;
+ }
+
+ QString current_text = m_dlg->cbCommand->currentText();
+ m_dlg->cbCommand->setCurrentText( current_text ); // Force an update of the autocompletion list
+}
+
+void Minicli::slotAutohistoryToggled(bool enabled)
+{
+ if (enabled)
+ {
+ // Enable history and filesystem autocompletion
+ m_histfilesystemAutocomplete = true;
+ m_filesystemAutocomplete = true;
+ m_dlg->cbAutocomplete->setChecked( true );
+ m_dlg->cbAutocomplete->setDisabled ( true );
+ }
+ else {
+ // Disable history and filesystem autocompletion
+ m_histfilesystemAutocomplete = false;
+ m_dlg->cbAutocomplete->setDisabled ( false );
+ }
+
+ QString current_text = m_dlg->cbCommand->currentText();
+ m_dlg->cbCommand->setCurrentText( current_text ); // Force an update of the autocompletion list
+}
+
void Minicli::slotPriority(int priority)
{
// Provide a way to easily return to the default priority