Show
Ignore:
Timestamp:
01/18/08 21:18:10 (10 months ago)
Author:
eugene
Message:
  • Removed all password-related work from SecurityDlg?;
  • Renamed ICQ-related options in system menu to reflect this fact;
  • Removed id from OwnerEditDlg? ctor, made ppid optional and fixed some bugs;
  • Made SignalManager? invoke OwnerEditDlg? upon logoff for wrong password reason.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/qt-gui_qt4/src/dialogs/securitydlg.cpp

    r5837 r6054  
    2323#include "config.h" 
    2424 
    25 #include <climits> 
    26  
    2725#include <QCheckBox> 
    2826#include <QDialogButtonBox> 
    2927#include <QGroupBox> 
    30 #include <QLabel> 
    31 #include <QLineEdit> 
    3228#include <QPushButton> 
    3329#include <QVBoxLayout> 
     
    4844SecurityDlg::SecurityDlg(QWidget* parent) 
    4945  : QDialog(parent), 
    50     eSecurityInfo(0), 
    51     ePasswordChange(0) 
     46    title(tr("ICQ Security")), 
     47    eSecurityInfo(0) 
    5248{ 
    5349  Support::setWidgetProps(this, "SecurityDialog"); 
    5450  setAttribute(Qt::WA_DeleteOnClose, true); 
    55  
    56   title = tr("ICQ Security Options"); 
    5751  setWindowTitle(title); 
    5852 
    59   // Main dialog layout 
     53  ICQOwner* o = gUserManager.FetchOwner(LICQ_PPID, LOCK_R); 
     54  if (o == NULL) 
     55  { 
     56    InformUser(this, tr("No ICQ owner found.\nPlease create one first.")); 
     57    close(); 
     58    return; 
     59  } 
     60 
    6061  QVBoxLayout* top_lay = new QVBoxLayout(this); 
    6162 
    62   // Options box 
    6363  QGroupBox* boxOptions = new QGroupBox(tr("Options")); 
    6464  QVBoxLayout* layOptions = new QVBoxLayout(boxOptions); 
    6565 
    66 #define ADD_CHECK(var, name, tip) \ 
     66#define ADD_CHECK(var, name, tip, status) \ 
    6767  (var) = new QCheckBox((name)); \ 
     68  (var)->setChecked((status)); \ 
    6869  (var)->setToolTip((tip)); \ 
    6970  layOptions->addWidget((var)); 
     
    7172  ADD_CHECK(chkAuthorization, tr("&Authorization Required"), tr("Determines " 
    7273        "whether regular ICQ clients require\nyour authorization to add you to " 
    73         "their contact list.")); 
     74        "their contact list."), o->GetAuthorization()); 
    7475  ADD_CHECK(chkWebAware, tr("&Web Presence"), tr("Web Presence allows users to" 
    75         " see\nif you are online through your web indicator.")); 
     76        " see\nif you are online through your web indicator."), o->WebAware()); 
    7677  ADD_CHECK(chkHideIp, tr("&Hide IP"), tr("Hide IP stops users from seeing your" 
    77         " IP address.\nIt doesn't guarantee it will be hidden though.")); 
     78        " IP address.\nIt doesn't guarantee it will be hidden though."), 
     79      o->HideIp()); 
    7880#undef ADD_CHECK 
     81 
     82  gUserManager.DropOwner(); 
    7983 
    8084  top_lay->addWidget(boxOptions); 
    8185 
    82   // Password box 
    83   QGroupBox* boxPassword = new QGroupBox(tr("Password/UIN settings")); 
    84   QGridLayout* layPassword = new QGridLayout(boxPassword); 
    85  
    86   unsigned short row = 0; 
    87   QLabel* label; 
    88  
    89 #define ADD_LINE(var, name, tip) \ 
    90   label = new QLabel((name)); \ 
    91   (var) = new QLineEdit(); \ 
    92   label->setBuddy((var)); \ 
    93   (var)->setToolTip((tip)); \ 
    94   layPassword->addWidget(label, row, 0); \ 
    95   layPassword->addWidget((var), row++, 1); 
    96  
    97   ADD_LINE(edtUin, tr("&Uin:"), tr("Enter the UIN which you want to use.\n" 
    98         "Only available if \"Local changes only\" is checked.")); 
    99   ADD_LINE(edtFirst, tr("&Password:"), tr("Enter your ICQ password here.")); 
    100   ADD_LINE(edtSecond, tr("&Verify:"), tr("Verify your ICQ password here.")); 
    101 #undef ADD_LINE 
    102  
    103   chkOnlyLocal = new QCheckBox(tr("&Local changes only")); 
    104   chkOnlyLocal->setToolTip(tr("If checked, password/UIN changes will apply only" 
    105         " on your local computer.\nUseful if your password is incorrectly saved" 
    106         " in Licq.")); 
    107   connect(chkOnlyLocal, SIGNAL(toggled(bool)), SLOT(chkOnlyLocalToggled(bool))); 
    108   layPassword->addWidget(chkOnlyLocal, row++, 0, 1, 2); 
    109  
    110   // UIN 
    111   edtUin->setEnabled(false); 
    112   edtUin->setValidator(new QIntValidator(10000, INT_MAX, edtUin)); 
    113  
    114   // Owner password 
    115   edtFirst->setEchoMode(QLineEdit::Password); 
    116   edtSecond->setEchoMode(QLineEdit::Password); 
    117  
    118   ICQOwner* o = gUserManager.FetchOwner(LOCK_R); 
    119   if (o != NULL) 
    120   { 
    121     edtUin->setText(o->IdString()); 
    122     edtFirst->setText(o->Password()); 
    123     edtSecond->setText(o->Password()); 
    124   } 
    125   else 
    126   { 
    127     edtFirst->setEnabled(false); 
    128     edtSecond->setEnabled(false); 
    129   } 
    130  
    131   // do some magic ;) 
    132   // if we are offline, we enable the checkbox "Only local changes" 
    133   // this saves one click :) 
    134   if (o != NULL)  // Make sure we exist 
    135   { 
    136     chkOnlyLocal->setChecked(o->Status() == ICQ_STATUS_OFFLINE); 
    137     chkAuthorization->setChecked(o->GetAuthorization()); 
    138     chkWebAware->setChecked(o->WebAware()); 
    139     chkHideIp->setChecked(o->HideIp()); 
    140     gUserManager.DropOwner(); 
    141   } 
    142   else 
    143   { 
    144     chkOnlyLocal->setChecked(true); 
    145     chkOnlyLocal->setEnabled(false); 
    146     chkAuthorization->setChecked(false); 
    147     chkWebAware->setChecked(false); 
    148     chkHideIp->setChecked(false); 
    149   } 
    150  
    151   // remember the initial values 
    152   // later we use these to apply only what has been changed by the user 
    153   initAuthorization = chkAuthorization->isChecked(); 
    154   initWebAware      = chkWebAware->isChecked(); 
    155   initHideIp        = chkHideIp->isChecked(); 
    156   initEdtUin        = edtUin->text(); 
    157   initEdtFirst      = edtFirst->text(); 
    158   initEdtSecond     = edtSecond->text(); 
    159  
    160   top_lay->addWidget(boxPassword); 
    161  
    162   // Buttons 
    16386  QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Cancel); 
    16487 
     
    17699void SecurityDlg::ok() 
    177100{ 
    178   ICQOwner* o = gUserManager.FetchOwner(LOCK_R); 
     101  ICQOwner* o = gUserManager.FetchOwner(LICQ_PPID, LOCK_R); 
    179102 
    180103  if (o == NULL) 
    181     return; 
    182  
    183   unsigned short status = o->Status(); 
    184   gUserManager.DropOwner(); 
    185  
    186   // validate password 
    187   if ((edtFirst->text().isEmpty() && !chkOnlyLocal->isChecked()) || 
    188        edtFirst->text().length() > 8) 
    189104  { 
    190     InformUser(this, tr("Invalid password, must be between 1 and 8 characters.")); 
     105    // Even though we protected from this in constructor, 
     106    // it's never too bad to persuade 
     107    close(); 
    191108    return; 
    192109  } 
    193110 
    194   if (edtFirst->text() != edtSecond->text()) 
     111  if (o->Status() == ICQ_STATUS_OFFLINE) 
    195112  { 
    196     InformUser(this, tr("Passwords do not match, try again.")); 
     113    gUserManager.DropOwner(LICQ_PPID); 
     114    InformUser(this, tr("You need to be connected to the\n" 
     115          "ICQ Network to change the settings.")); 
    197116    return; 
    198117  } 
    199118 
    200   if (status == ICQ_STATUS_OFFLINE && !chkOnlyLocal->isChecked()) 
     119  bool auth = chkAuthorization->isChecked(); 
     120  bool web = chkWebAware->isChecked(); 
     121  bool ip = chkHideIp->isChecked(); 
     122 
     123  if (auth != o->GetAuthorization() || 
     124      web != o->WebAware() || 
     125      ip != o->HideIp()) 
    201126  { 
    202     InformUser(this, tr("You need to be connected to the\n" 
    203                         "ICQ Network to change the settings.")); 
    204     return; 
     127    gUserManager.DropOwner(LICQ_PPID); 
     128    btnUpdate->setEnabled(false); 
     129 
     130    connect(LicqGui::instance()->signalManager(), 
     131        SIGNAL(doneUserFcn(ICQEvent*)), SLOT(doneUserFcn(ICQEvent*))); 
     132 
     133    setWindowTitle(title + " [" + tr("Setting...") + "]"); 
     134 
     135    eSecurityInfo = gLicqDaemon->icqSetSecurityInfo(auth, ip, web); 
     136 
     137    return; // prevents the dialog from closing 
    205138  } 
    206139 
    207   // test if we really need to update anything 
    208   bool secUpdateNeeded = false; 
    209   bool pasUpdateNeeded = false; 
    210  
    211   if (chkAuthorization->isChecked() != initAuthorization || 
    212       chkWebAware->isChecked() != initWebAware || 
    213       chkHideIp->isChecked() != initHideIp) 
    214   { 
    215     secUpdateNeeded = true; 
    216     initAuthorization = chkAuthorization->isChecked(); 
    217     initWebAware = chkWebAware->isChecked(); 
    218     initHideIp = chkHideIp->isChecked(); 
    219   } 
    220  
    221   if (edtUin->text() != initEdtUin || 
    222       edtFirst->text() != initEdtFirst || 
    223       edtSecond->text() != initEdtSecond) 
    224   { 
    225     pasUpdateNeeded = true; 
    226     initEdtUin = edtUin->text(); 
    227     initEdtFirst = edtFirst->text(); 
    228     initEdtSecond = edtSecond->text(); 
    229   } 
    230  
    231   if (secUpdateNeeded || pasUpdateNeeded) 
    232   { 
    233     btnUpdate->setEnabled(false); 
    234  
    235     if (chkOnlyLocal->isChecked()) 
    236     { 
    237       o = gUserManager.FetchOwner(LOCK_W); 
    238       if (o == NULL) 
    239         InformUser(this, tr("Failed to change the settings.")); 
    240       else 
    241       { 
    242         o->SetId(edtUin->text().toLatin1()); 
    243         o->SetPassword(edtFirst->text().toLatin1()); 
    244         gUserManager.DropOwner(); 
    245       } 
    246     } 
    247     else 
    248     { 
    249       connect(LicqGui::instance()->signalManager(), 
    250           SIGNAL(doneUserFcn(ICQEvent*)), 
    251           SLOT(doneUserFcn(ICQEvent*))); 
    252  
    253       // eSecurityInfo and ePasswordChange contain the event numbers. 
    254       // These are used in doneUserFcn to compare if we received 
    255       // what we expected :) 
    256       if (secUpdateNeeded) 
    257         eSecurityInfo = gLicqDaemon->icqSetSecurityInfo( 
    258             chkAuthorization->isChecked(), 
    259             chkHideIp->isChecked(), 
    260             chkWebAware->isChecked()); 
    261  
    262       if (pasUpdateNeeded) 
    263         ePasswordChange = gLicqDaemon->icqSetPassword( 
    264             edtFirst->text().toLatin1()); 
    265  
    266       setWindowTitle(title + " [" + tr("Setting...") + "]"); 
    267       return; // prevents the dialog from closing 
    268     } 
    269   } 
     140  gUserManager.DropOwner(LICQ_PPID); 
    270141 
    271142  close(); 
     
    274145void SecurityDlg::doneUserFcn(ICQEvent* e) 
    275146{ 
    276   // Checking if the received events correspond to one of 
    277   // our sent events. 
    278   bool bSec  = e->Equals(eSecurityInfo); 
    279   bool bPass = e->Equals(ePasswordChange); 
    280  
    281   if (!bSec && !bPass) 
     147  if (!e->Equals(eSecurityInfo)) 
    282148    return; 
    283149 
    284   QString result; 
     150  eSecurityInfo = 0; 
     151  QString result = QString::null; 
     152  btnUpdate->setEnabled(true); 
     153 
     154  disconnect(LicqGui::instance()->signalManager(), 
     155      SIGNAL(doneUserFcn(ICQEvent*)), this, SLOT(doneUserFcn(ICQEvent*))); 
    285156 
    286157  switch (e->Result()) 
     
    288159    case EVENT_FAILED: 
    289160      result = tr("failed"); 
    290       if (bSec) 
    291         InformUser(this, tr("Setting security options failed.")); 
    292       else if (bPass) 
    293         InformUser(this, tr("Changing password failed.")); 
     161      InformUser(this, tr("Setting security options failed.")); 
    294162      break; 
    295163 
    296164    case EVENT_TIMEDOUT: 
    297165      result = tr("timed out"); 
    298       if (bSec) 
    299         InformUser(this, tr("Timeout while setting security options.")); 
    300       else if (bPass) 
    301         InformUser(this, tr("Timeout while changing password.")); 
     166      InformUser(this, tr("Timeout while setting security options.")); 
    302167      break; 
    303168 
    304169    case EVENT_ERROR: 
    305170      result = tr("error"); 
    306       if (bSec) 
    307         InformUser(this, tr("Internal error while setting security options.")); 
    308       else if (bPass) 
    309         InformUser(this, tr("Internal error while changing password.")); 
     171      InformUser(this, tr("Internal error while setting security options.")); 
    310172      break; 
    311173 
     
    314176  } 
    315177 
    316   if (bSec) 
    317     eSecurityInfo = 0; 
    318   else if (bPass) 
    319     ePasswordChange = 0; 
    320  
    321   if (eSecurityInfo == 0 && ePasswordChange == 0) 
    322     btnUpdate->setEnabled(true); 
    323  
    324   if (!result.isEmpty()) 
     178  if (result.isEmpty()) 
     179    close(); 
     180  else 
    325181    setWindowTitle(title + " [" + tr("Setting...") + " " + result + "]"); 
    326   else 
    327   { 
    328     if ((eSecurityInfo == 0) && (ePasswordChange == 0)) 
    329     { 
    330       setWindowTitle(tr("ICQ Security Options")); 
    331       close(); 
    332     } 
    333   } 
    334182} 
    335  
    336 void SecurityDlg::chkOnlyLocalToggled(bool b) 
    337 { 
    338   edtUin->setEnabled(b); 
    339   chkAuthorization->setEnabled(!b); 
    340   chkWebAware->setEnabled(!b); 
    341   chkHideIp->setEnabled(!b); 
    342 }