auto-type and auto-type-window definitions are now fully compatible with keepass

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@151 b624d157-de02-0410-bad0-e51aec6abb33
master
sniperbeamer 17 years ago
parent 51acb50266
commit 18e99b5a41
  1. 40
      src/lib/AutoType_X11.cpp

@ -60,27 +60,25 @@ Shortcut AutoType::shortcut;
void AutoType::perform(IEntryHandle* entry, QString& err,bool hideWindow,int nr){ void AutoType::perform(IEntryHandle* entry, QString& err,bool hideWindow,int nr){
QString indexStr; QString indexStr;
if (nr==0) if (nr==0)
indexStr = "Auto-Type: "; indexStr = "Auto-Type:";
else else
indexStr = QString("Auto-Type-%1: ").arg(nr); indexStr = QString("Auto-Type-%1:").arg(nr);
QString str; QString str;
QString comment=entry->comment(); QString comment=entry->comment();
int c=comment.count(indexStr); int c=comment.count(indexStr, Qt::CaseInsensitive);
if(c>1){ if(c>1){
err=QCoreApplication::translate("AutoType","More than one 'Auto-Type:' key sequence found.\nAllowed is only one per entry."); err=QCoreApplication::translate("AutoType","More than one 'Auto-Type:' key sequence found.\nAllowed is only one per entry.");
return; return;
} }
if(c==1){ else if(c==1){
int indexLen = indexStr.length(); int start = comment.indexOf(indexStr,0,Qt::CaseInsensitive) + indexStr.length();
int start=comment.indexOf(indexStr)+indexLen; int end = comment.indexOf("\n", start);
int len; if (end == -1)
if(comment.size()==indexLen)return; end = comment.length();
for(len=0;len<comment.size();len++){
if(comment.size()==(start+len))break; str=comment.mid(start,end-start).trimmed();
if(comment.at(start+len)==QChar('\n'))break; if (str.isEmpty())
} return;
if(!len)return;
str=comment.mid(start,len);
} }
else else
str="{USERNAME}{TAB}{PASSWORD}{ENTER}"; str="{USERNAME}{TAB}{PASSWORD}{ENTER}";
@ -195,28 +193,28 @@ void AutoType::performGlobal(){
QList<IEntryHandle*> validEntries; QList<IEntryHandle*> validEntries;
QList<int> entryNumbers; QList<int> entryNumbers;
QList<IEntryHandle*> entries = MainWin->db->entries(); QList<IEntryHandle*> entries = MainWin->db->entries();
QRegExp lineMatch("^Auto-Type-Window(?:-(\\d+)|): (.+)$", Qt::CaseSensitive, QRegExp::RegExp2); QRegExp lineMatch("Auto-Type-Window(?:-(\\d+)|):([^\\n]+)", Qt::CaseInsensitive, QRegExp::RegExp2);
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
for (int i=0; i<entries.size(); i++){ for (int i=0; i<entries.size(); i++){
if (entries[i]->expire()!=Date_Never && entries[i]->expire()<now) if (entries[i]->expire()!=Date_Never && entries[i]->expire()<now)
continue; continue;
bool hasWindowEntry=false; bool hasWindowEntry=false;
QStringList lines=entries[i]->comment().split("\n", QString::SkipEmptyParts); QString comment = entries[i]->comment();
for (int j=0; j<lines.size(); j++){ int offset = 0;
QString line = lines[j].trimmed(); while ( (offset=lineMatch.indexIn(comment, offset))!=-1 ){
if (lineMatch.indexIn(line)==-1) continue;
QStringList captured = lineMatch.capturedTexts(); QStringList captured = lineMatch.capturedTexts();
offset += captured[0].length();
int nr; int nr;
QString entryWindow; QString entryWindow;
bool valid; bool valid;
if (captured.size()==2){ if (captured.size()==2){
nr = 0; nr = 0;
entryWindow = captured[1].toLower(); entryWindow = captured[1].trimmed().toLower();
} }
else{ else{
nr = captured[1].toInt(); nr = captured[1].toInt();
entryWindow = captured[2].toLower(); entryWindow = captured[2].trimmed().toLower();
} }
if (entryWindow.length()==0) continue; if (entryWindow.length()==0) continue;