mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
kio: remove unused and redundant KShellCompletion class
KCompletion has a shell-completion mode Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
96a5dce717
commit
0ac2e1f132
7 changed files with 4 additions and 397 deletions
|
@ -270,7 +270,6 @@ install(
|
|||
KSharedConfig
|
||||
KSharedPtr
|
||||
KShell
|
||||
KShellCompletion
|
||||
KShortcut
|
||||
KShortcutsDialog
|
||||
KShortcutsEditor
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#include "../kshellcompletion.h"
|
|
@ -30,12 +30,12 @@
|
|||
#ifndef KLINEEDIT_H
|
||||
#define KLINEEDIT_H
|
||||
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QLineEdit>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
|
||||
#include <kcompletion.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
class KCompletionBox;
|
||||
class KUrl;
|
||||
class KLineEditPrivate;
|
||||
|
|
|
@ -58,7 +58,6 @@ set(kiocore_STAT_SRCS
|
|||
kio/kprotocolmanager.cpp
|
||||
kio/kremoteencoding.cpp
|
||||
kio/krun.cpp
|
||||
kio/kshellcompletion.cpp
|
||||
kio/kurifilter.cpp
|
||||
kio/kurlcompletion.cpp
|
||||
kio/netaccess.cpp
|
||||
|
@ -234,7 +233,6 @@ install(
|
|||
kio/kprotocolmanager.h
|
||||
kio/kremoteencoding.h
|
||||
kio/krun.h
|
||||
kio/kshellcompletion.h
|
||||
kio/kurifilter.h
|
||||
kio/kurlcompletion.h
|
||||
kfile/kabstractfilemodule.h
|
||||
|
|
|
@ -152,7 +152,7 @@ public:
|
|||
* special one, if you used the special constructor.
|
||||
*
|
||||
* It is provided so that you can e.g. set an own completion object
|
||||
* (e.g. KShellCompletion) into it.
|
||||
* into it.
|
||||
*/
|
||||
KLineEdit * lineEdit() const;
|
||||
|
||||
|
|
|
@ -1,321 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2000 David Smith <dsmith@algonet.se>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kshellcompletion.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <kdebug.h>
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtCore/qstringlist.h>
|
||||
#include <QtCore/QRegExp>
|
||||
#include <kcompletion.h>
|
||||
|
||||
class KShellCompletionPrivate
|
||||
{
|
||||
public:
|
||||
KShellCompletionPrivate()
|
||||
: m_word_break_char(' ')
|
||||
, m_quote_char1( '\"' )
|
||||
, m_quote_char2( '\'' )
|
||||
, m_escape_char( '\\' )
|
||||
{
|
||||
}
|
||||
|
||||
void splitText(const QString &text, QString &text_start, QString &text_compl) const;
|
||||
bool quoteText(QString *text, bool force, bool skip_last) const;
|
||||
QString unquote(const QString &text) const;
|
||||
|
||||
QString m_text_start; // part of the text that was not completed
|
||||
QString m_text_compl; // part of the text that was completed (unchanged)
|
||||
|
||||
QChar m_word_break_char;
|
||||
QChar m_quote_char1;
|
||||
QChar m_quote_char2;
|
||||
QChar m_escape_char;
|
||||
};
|
||||
|
||||
KShellCompletion::KShellCompletion()
|
||||
: KUrlCompletion(),
|
||||
d( new KShellCompletionPrivate )
|
||||
{
|
||||
}
|
||||
|
||||
KShellCompletion::~KShellCompletion()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* makeCompletion()
|
||||
*
|
||||
* Entry point for file name completion
|
||||
*/
|
||||
QString KShellCompletion::makeCompletion(const QString &text)
|
||||
{
|
||||
// Split text at the last unquoted space
|
||||
//
|
||||
d->splitText(text, d->m_text_start, d->m_text_compl);
|
||||
|
||||
// Remove quotes from the text to be completed
|
||||
//
|
||||
QString tmp = d->unquote(d->m_text_compl);
|
||||
d->m_text_compl = tmp;
|
||||
|
||||
// Do exe-completion if there was no unquoted space
|
||||
//
|
||||
bool is_exe_completion = true;
|
||||
|
||||
for ( int i = 0; i < d->m_text_start.length(); i++ ) {
|
||||
if ( d->m_text_start[i] != d->m_word_break_char ) {
|
||||
is_exe_completion = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Mode mode = (is_exe_completion ? ExeCompletion : FileCompletion );
|
||||
|
||||
setMode(mode);
|
||||
|
||||
// Make completion on the last part of text
|
||||
//
|
||||
return KUrlCompletion::makeCompletion( d->m_text_compl );
|
||||
}
|
||||
|
||||
/*
|
||||
* postProcessMatch, postProcessMatches
|
||||
*
|
||||
* Called by KCompletion before emitting match() and matches()
|
||||
*
|
||||
* Add add the part of the text that was not completed
|
||||
* Add quotes when needed
|
||||
*/
|
||||
void KShellCompletion::postProcessMatch( QString *match ) const
|
||||
{
|
||||
KUrlCompletion::postProcessMatch( match );
|
||||
|
||||
if ( match->isNull() )
|
||||
return;
|
||||
|
||||
if ( match->endsWith( QLatin1Char( '/' ) ) )
|
||||
d->quoteText( match, false, true ); // don't quote the trailing '/'
|
||||
else
|
||||
d->quoteText( match, false, false ); // quote the whole text
|
||||
|
||||
match->prepend( d->m_text_start );
|
||||
}
|
||||
|
||||
void KShellCompletion::postProcessMatches( QStringList *matches ) const
|
||||
{
|
||||
KUrlCompletion::postProcessMatches( matches );
|
||||
|
||||
for ( QStringList::Iterator it = matches->begin();
|
||||
it != matches->end(); ++it )
|
||||
{
|
||||
if ( !(*it).isNull() ) {
|
||||
if ( (*it).endsWith( QLatin1Char( '/' ) ) )
|
||||
d->quoteText( &(*it), false, true ); // don't quote trailing '/'
|
||||
else
|
||||
d->quoteText( &(*it), false, false ); // quote the whole text
|
||||
|
||||
(*it).prepend( d->m_text_start );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KShellCompletion::postProcessMatches( KCompletionMatches *matches ) const
|
||||
{
|
||||
KUrlCompletion::postProcessMatches( matches );
|
||||
|
||||
for ( KCompletionMatches::Iterator it = matches->begin();
|
||||
it != matches->end(); ++it )
|
||||
{
|
||||
if ( !(*it).value().isNull() ) {
|
||||
if ( (*it).value().endsWith( QLatin1Char( '/' ) ) )
|
||||
d->quoteText( &(*it).value(), false, true ); // don't quote trailing '/'
|
||||
else
|
||||
d->quoteText( &(*it).value(), false, false ); // quote the whole text
|
||||
|
||||
(*it).value().prepend( d->m_text_start );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* splitText
|
||||
*
|
||||
* Split text at the last unquoted space
|
||||
*
|
||||
* text_start = [out] text at the left, including the space
|
||||
* text_compl = [out] text at the right
|
||||
*/
|
||||
void KShellCompletionPrivate::splitText(const QString &text, QString &text_start,
|
||||
QString &text_compl) const
|
||||
{
|
||||
bool in_quote = false;
|
||||
bool escaped = false;
|
||||
QChar p_last_quote_char;
|
||||
int last_unquoted_space = -1;
|
||||
int end_space_len = 0;
|
||||
|
||||
for (int pos = 0; pos < text.length(); pos++) {
|
||||
|
||||
end_space_len = 0;
|
||||
|
||||
if ( escaped ) {
|
||||
escaped = false;
|
||||
}
|
||||
else if ( in_quote && text[pos] == p_last_quote_char ) {
|
||||
in_quote = false;
|
||||
}
|
||||
else if ( !in_quote && text[pos] == m_quote_char1 ) {
|
||||
p_last_quote_char = m_quote_char1;
|
||||
in_quote = true;
|
||||
}
|
||||
else if ( !in_quote && text[pos] == m_quote_char2 ) {
|
||||
p_last_quote_char = m_quote_char2;
|
||||
in_quote = true;
|
||||
}
|
||||
else if ( text[pos] == m_escape_char ) {
|
||||
escaped = true;
|
||||
}
|
||||
else if ( !in_quote && text[pos] == m_word_break_char ) {
|
||||
|
||||
end_space_len = 1;
|
||||
|
||||
while ( pos+1 < text.length() && text[pos+1] == m_word_break_char ) {
|
||||
end_space_len++;
|
||||
pos++;
|
||||
}
|
||||
|
||||
if ( pos+1 == text.length() )
|
||||
break;
|
||||
|
||||
last_unquoted_space = pos;
|
||||
}
|
||||
}
|
||||
|
||||
text_start = text.left( last_unquoted_space + 1 );
|
||||
|
||||
// the last part without trailing blanks
|
||||
text_compl = text.mid( last_unquoted_space + 1 );
|
||||
}
|
||||
|
||||
/*
|
||||
* quoteText()
|
||||
*
|
||||
* Add quotations to 'text' if needed or if 'force' = true
|
||||
* Returns true if quotes were added
|
||||
*
|
||||
* skip_last => ignore the last charachter (we add a space or '/' to all filenames)
|
||||
*/
|
||||
bool KShellCompletionPrivate::quoteText(QString *text, bool force, bool skip_last) const
|
||||
{
|
||||
int pos = 0;
|
||||
|
||||
if ( !force ) {
|
||||
pos = text->indexOf( m_word_break_char );
|
||||
if ( skip_last && (pos == (int)(text->length())-1) ) pos = -1;
|
||||
}
|
||||
|
||||
if ( !force && pos == -1 ) {
|
||||
pos = text->indexOf( m_quote_char1 );
|
||||
if ( skip_last && (pos == (int)(text->length())-1) ) pos = -1;
|
||||
}
|
||||
|
||||
if ( !force && pos == -1 ) {
|
||||
pos = text->indexOf( m_quote_char2 );
|
||||
if ( skip_last && (pos == (int)(text->length())-1) ) pos = -1;
|
||||
}
|
||||
|
||||
if ( !force && pos == -1 ) {
|
||||
pos = text->indexOf( m_escape_char );
|
||||
if ( skip_last && (pos == (int)(text->length())-1) ) pos = -1;
|
||||
}
|
||||
|
||||
if ( force || (pos >= 0) ) {
|
||||
|
||||
// Escape \ in the string
|
||||
text->replace( m_escape_char,
|
||||
QString( m_escape_char ) + m_escape_char );
|
||||
|
||||
// Escape " in the string
|
||||
text->replace( m_quote_char1,
|
||||
QString( m_escape_char ) + m_quote_char1 );
|
||||
|
||||
// " at the beginning
|
||||
text->insert( 0, m_quote_char1 );
|
||||
|
||||
// " at the end
|
||||
if ( skip_last )
|
||||
text->insert( text->length()-1, m_quote_char1 );
|
||||
else
|
||||
text->insert( text->length(), m_quote_char1 );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* unquote
|
||||
*
|
||||
* Remove quotes and return the result in a new string
|
||||
*
|
||||
*/
|
||||
QString KShellCompletionPrivate::unquote(const QString &text) const
|
||||
{
|
||||
bool in_quote = false;
|
||||
bool escaped = false;
|
||||
QChar p_last_quote_char;
|
||||
QString result;
|
||||
|
||||
for (int pos = 0; pos < text.length(); pos++) {
|
||||
|
||||
if ( escaped ) {
|
||||
escaped = false;
|
||||
result.insert( result.length(), text[pos] );
|
||||
}
|
||||
else if ( in_quote && text[pos] == p_last_quote_char ) {
|
||||
in_quote = false;
|
||||
}
|
||||
else if ( !in_quote && text[pos] == m_quote_char1 ) {
|
||||
p_last_quote_char = m_quote_char1;
|
||||
in_quote = true;
|
||||
}
|
||||
else if ( !in_quote && text[pos] == m_quote_char2 ) {
|
||||
p_last_quote_char = m_quote_char2;
|
||||
in_quote = true;
|
||||
}
|
||||
else if ( text[pos] == m_escape_char ) {
|
||||
escaped = true;
|
||||
result.insert( result.length(), text[pos] );
|
||||
}
|
||||
else {
|
||||
result.insert( result.length(), text[pos] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#include "moc_kshellcompletion.cpp"
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2000 David Smith <dsmith@algonet.se>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KSHELLCOMPLETION_H
|
||||
#define KSHELLCOMPLETION_H
|
||||
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
#include "kurlcompletion.h"
|
||||
|
||||
class KShellCompletionPrivate;
|
||||
|
||||
/**
|
||||
* This class does shell-like completion of file names.
|
||||
* A string passed to makeCompletion() will be interpreted as a shell
|
||||
* command line. Completion will be done on the last argument on the line.
|
||||
* Returned matches consist of the first arguments (uncompleted) plus the
|
||||
* completed last argument.
|
||||
*
|
||||
* @short Shell-like completion of file names
|
||||
* @author David Smith <dsmith@algonet.se>
|
||||
*/
|
||||
class KIO_EXPORT KShellCompletion : public KUrlCompletion
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructs a KShellCompletion object.
|
||||
*/
|
||||
KShellCompletion();
|
||||
~KShellCompletion();
|
||||
|
||||
/**
|
||||
* Finds completions to the given text.
|
||||
* The first match is returned and emitted in the signal match().
|
||||
* @param text the text to complete
|
||||
* @return the first match, or QString() if not found
|
||||
*/
|
||||
QString makeCompletion(const QString &text);
|
||||
|
||||
protected:
|
||||
// Called by KCompletion
|
||||
void postProcessMatch( QString *match ) const;
|
||||
void postProcessMatches( QStringList *matches ) const;
|
||||
void postProcessMatches( KCompletionMatches *matches ) const;
|
||||
|
||||
private:
|
||||
KShellCompletionPrivate * const d;
|
||||
};
|
||||
|
||||
#endif // KSHELLCOMPLETION_H
|
Loading…
Add table
Reference in a new issue