~ubuntu-branches/ubuntu/raring/quassel/raring-proposed

« back to all changes in this revision

Viewing changes to src/uisupport/tabcompleter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2008-06-27 19:21:30 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080627192130-kjsrutd8w40x5okn
Tags: upstream-0.2.0~rc1
ImportĀ upstreamĀ versionĀ 0.2.0~rc1

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "ircchannel.h"
29
29
#include "ircuser.h"
30
30
 
 
31
#include <QRegExp>
 
32
 
31
33
TabCompleter::TabCompleter(InputLine *inputLine_)
32
34
  : QObject(inputLine_),
33
35
    inputLine(inputLine_),
38
40
}
39
41
 
40
42
void TabCompleter::buildCompletionList() {
41
 
  completionList.clear();
42
 
  nextCompletion = completionList.begin();
 
43
  completionMap.clear();
43
44
  // this is the first time tab is pressed -> build up the completion list and it's iterator
44
45
  QModelIndex currentIndex = Client::bufferModel()->currentIndex();
45
 
  if(!currentIndex.data(NetworkModel::BufferIdRole).isValid())
 
46
  if(!currentIndex.data(NetworkModel::BufferIdRole).isValid()) {
 
47
    nextCompletion = completionMap.begin();
46
48
    return;
 
49
  }
47
50
  
48
51
  NetworkId networkId = currentIndex.data(NetworkModel::NetworkIdRole).value<NetworkId>();
49
52
  QString channelName = currentIndex.sibling(currentIndex.row(), 0).data().toString();
65
68
          this, SLOT(ircUserJoinedOrParted(IrcUser *)));
66
69
  */
67
70
 
68
 
  completionList.clear();
69
71
  QString tabAbbrev = inputLine->text().left(inputLine->cursorPosition()).section(' ',-1,-1);
70
 
  completionList.clear();
 
72
  QRegExp regex(QString("^[^a-zA-Z]*").append(tabAbbrev), Qt::CaseInsensitive);
 
73
 
71
74
  foreach(IrcUser *ircUser, channel->ircUsers()) {
72
 
    if(ircUser->nick().toLower().startsWith(tabAbbrev.toLower())) {
73
 
      completionList << ircUser->nick();
 
75
    if(regex.indexIn(ircUser->nick()) > -1) {
 
76
      completionMap[ircUser->nick().toLower()] = ircUser->nick();
74
77
    }
75
78
  }
76
 
  completionList.sort();
77
 
  nextCompletion = completionList.begin();
 
79
 
 
80
  nextCompletion = completionMap.begin();
78
81
  lastCompletionLength = tabAbbrev.length();
79
82
}
80
83
 
89
92
    enabled = true;
90
93
  }
91
94
  
92
 
  if (nextCompletion != completionList.end()) {
 
95
  if (nextCompletion != completionMap.end()) {
93
96
    // clear previous completion
94
97
    for (int i = 0; i < lastCompletionLength; i++) {
95
98
      inputLine->backspace();
110
113
 
111
114
  // we're at the end of the list -> start over again
112
115
  } else {
113
 
    nextCompletion = completionList.begin();
 
116
    if(!completionMap.isEmpty()) {
 
117
      nextCompletion = completionMap.begin();
 
118
      complete();
 
119
    }
114
120
  }
115
121
  
116
122
}