Changeset 406:435b224550e5

Show
Ignore:
Timestamp:
02/01/2010 12:47:19 PM (2 years ago)
Author:
Sidgyck <sidgyck@…>
Branch:
default
Message:

[FIX]: !net currency is work again. Some additional logic added.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/plugins/net/currencyrequest.cpp

    r362 r406  
    4343void CurrencyRequest::exec() 
    4444{ 
    45  
    4645        if ( myDest.endsWith("list") ) 
    4746        { 
     
    5857        QString to       = myDest.section(' ', 2, 2); 
    5958 
    60         if (myDest.isEmpty() && amount.isEmpty() && from.isEmpty() && to.isEmpty()) 
     59        if( from.toUpper() == "RUB" && to.isEmpty() ) { 
     60                to = "USD"; 
     61        } else if( to.isEmpty() ) { 
     62                to = "RUB"; 
     63        }  
     64         
     65        if (myDest.isEmpty() || amount.isEmpty() || from.isEmpty()) 
    6166        { 
    6267                plugin()->reply(stanza(),"Usage: net currency <amount> <from> <to>"); 
     
    6469                return; 
    6570        } 
    66  
    67         int pn=(nres-1)/10; 
    68         nres=(nres-1)%10+1; 
    6971 
    7072        QString url=QString("http://www.xe.com/ucc/convert.cgi?Amount=%1&From=%2&To=%3").arg(amount).arg(from.toUpper()).arg(to.toUpper()); 
     
    7981        if (err || http->lastResponse().statusCode()!=200) 
    8082        { 
    81                 plugin()->reply(stanza(),"Failed to fetch XE.com: "+http->lastResponse().reasonPhrase()); 
     83                plugin()->reply(stanza(),"Failed to fetch from XE.com: "+http->lastResponse().reasonPhrase()); 
    8284                deleteLater(); 
    8385                return; 
    8486        } 
    8587        QString buf=http->readAll(); 
    86         QRegExp exp("<h2 class=\"XE\">(.*)<!--"); 
    87         exp.setMinimal(TRUE); 
    88         QString str; 
    89         int ps=0; 
    9088 
    91         QString from = removeHtml(getValue(buf,"align=\"right\" class=\"XEenlarge\"><h2 class=\"XE\">(.*)<!--")).trimmed(); 
    92         QString to   = removeHtml(getValue(buf,"align=\"left\" class=\"XEenlarge\"><h2 class=\"XE\">(.*)<!--")).trimmed(); 
     89        QString from = removeHtml(getValue(buf,"align=\"right\" class=\"XEenlarge\"><h2 class=\"XE\" style=\"color:#333\">(.*)<!--")).trimmed(); 
     90        QString to   = removeHtml(getValue(buf,"align=\"left\" class=\"XEenlarge\"><h2 class=\"XE\" style=\"color:#333\">(.*)<!--")).trimmed(); 
     91         
     92        QString curr1 = myDest.section(' ', 1, 1); 
     93        QString curr2 = myDest.section(' ', 2, 2); 
     94        QString msg   = "unknown currency: %1"; 
    9395 
    94         if( to.isEmpty() || from.isEmpty() ) { 
    95                 plugin()->reply( stanza(), 
    96                                         QString("no such currency: %1 or %2") 
    97                                         .arg( myDest.section(' ', 1, 1).toUpper()) 
    98                                         .arg( myDest.section(' ', 2, 2).toUpper()) ); 
     96        if( from.isEmpty() || to.isEmpty() ) { 
     97                if( !curr2.isEmpty() && from == to) { 
     98                         msg.append(" or ").append(curr2); 
     99                } 
     100                plugin()->reply( stanza(), msg.arg(curr1)); 
    99101        } else { 
    100                 plugin()->reply(stanza(), QString("%1 = %2").arg(from).arg(to).simplified().replace(",", " ")); 
     102                plugin()->reply( stanza(), QString("%1 = %2").arg(from).arg(to).simplified().replace(",", " ")); 
    101103        } 
     104 
    102105        deleteLater(); 
    103106} 
     
    106109{ 
    107110        if (err || http->lastResponse().statusCode()!=200) { 
    108                 plugin()->reply(stanza(),"Failed to fetch list XE.com: "+http->lastResponse().reasonPhrase()); 
     111                plugin()->reply(stanza(),"Failed to fetch list from XE.com: "+http->lastResponse().reasonPhrase()); 
    109112                deleteLater(); 
    110113                return;