diff options
Diffstat (limited to 'pica-client/contactlistwidget.cpp')
| -rw-r--r-- | pica-client/contactlistwidget.cpp | 284 |
1 files changed, 142 insertions, 142 deletions
diff --git a/pica-client/contactlistwidget.cpp b/pica-client/contactlistwidget.cpp index d73a3f4..9c607ac 100644 --- a/pica-client/contactlistwidget.cpp +++ b/pica-client/contactlistwidget.cpp @@ -12,202 +12,202 @@ #include <QTimer> ContactListWidget::ContactListWidget(QWidget *parent) : - QListWidget(parent) + QListWidget(parent) { - addcontactAct = new QAction(tr("&Add Contact..."), this); - addcontactAct->setStatusTip(tr("add new contact")); - connect(addcontactAct,SIGNAL(triggered()),this,SLOT(add_contact())); + addcontactAct = new QAction(tr("&Add Contact..."), this); + addcontactAct->setStatusTip(tr("add new contact")); + connect(addcontactAct, SIGNAL(triggered()), this, SLOT(add_contact())); - delcontactAct = new QAction(tr("&Delete Contact"),this); - connect(delcontactAct,SIGNAL(triggered()),this,SLOT(del_contact())); + delcontactAct = new QAction(tr("&Delete Contact"), this); + connect(delcontactAct, SIGNAL(triggered()), this, SLOT(del_contact())); - startchatAct = new QAction(tr("Start &Chat"), this); - connect(startchatAct, SIGNAL(triggered()), this, SLOT(start_chat())); + startchatAct = new QAction(tr("Start &Chat"), this); + connect(startchatAct, SIGNAL(triggered()), this, SLOT(start_chat())); - viewcertAct = new QAction(tr("&View Certificate"), this); - connect(viewcertAct, SIGNAL(triggered()), this, SLOT(view_cert())); + viewcertAct = new QAction(tr("&View Certificate"), this); + connect(viewcertAct, SIGNAL(triggered()), this, SLOT(view_cert())); - showidAct = new QAction(tr("Show Pica Pica &ID"), this); - connect(showidAct, SIGNAL(triggered()), this, SLOT(show_id())); + showidAct = new QAction(tr("Show Pica Pica &ID"), this); + connect(showidAct, SIGNAL(triggered()), this, SLOT(show_id())); - sendfileAct = new QAction(tr("Send &File"), this); - connect(sendfileAct, SIGNAL(triggered()), this, SLOT(send_file())); + sendfileAct = new QAction(tr("Send &File"), this); + connect(sendfileAct, SIGNAL(triggered()), this, SLOT(send_file())); - connect(this, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(start_chat())); + connect(this, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(start_chat())); - setContactsStorage(new Contacts(config_dbname, Accounts::GetCurrentAccount().id)); + setContactsStorage(new Contacts(config_dbname, Accounts::GetCurrentAccount().id)); } ContactListWidget::~ContactListWidget() { - delete storage; + delete storage; } void ContactListWidget::contextMenuEvent(QContextMenuEvent *event) { - QMenu menu(this); + QMenu menu(this); - if (this->itemAt(event->pos())) - menu.addAction(delcontactAct); + if (this->itemAt(event->pos())) + menu.addAction(delcontactAct); - menu.addAction(addcontactAct); + menu.addAction(addcontactAct); - if (this->itemAt(event->pos())) - { - menu.addAction(startchatAct); - menu.addAction(viewcertAct); - menu.addAction(showidAct); - menu.addAction(sendfileAct); - } - menu.exec(event->globalPos()); + if (this->itemAt(event->pos())) + { + menu.addAction(startchatAct); + menu.addAction(viewcertAct); + menu.addAction(showidAct); + menu.addAction(sendfileAct); + } + menu.exec(event->globalPos()); } void ContactListWidget::setContactsStorage(Contacts *ct) { - clear(); - // this->addItems(ct->GetContacts()); - storage=ct; - contact_records=ct->GetContacts(); - - for (int i=0;i<contact_records.size();i++) - { - addItem(QString("(%1...) %2").arg(contact_records[i].id.toBase64().left(8).constData()).arg(contact_records[i].name)); - wgitem_to_recs[this->item(i)]=&contact_records[i]; - this->item(i)->setStatusTip(contact_records[i].id.toBase64()); - this->item(i)->setToolTip(contact_records[i].id.toBase64().constData()); - } + clear(); + // this->addItems(ct->GetContacts()); + storage = ct; + contact_records = ct->GetContacts(); + + for (int i = 0; i < contact_records.size(); i++) + { + addItem(QString("(%1...) %2").arg(contact_records[i].id.toBase64().left(8).constData()).arg(contact_records[i].name)); + wgitem_to_recs[this->item(i)] = &contact_records[i]; + this->item(i)->setStatusTip(contact_records[i].id.toBase64()); + this->item(i)->setToolTip(contact_records[i].id.toBase64().constData()); + } } void ContactListWidget::add_contact() { - bool ok; - QString input=QInputDialog::getText(this,tr("Add New Contact"),tr("Pica Pica ID: "),QLineEdit::Normal,NULL,&ok); - - if (ok && !input.isEmpty()) - { - QByteArray user_id = QByteArray::fromBase64(input.toAscii()).left(PICA_ID_SIZE); - - if (user_id.size() != PICA_ID_SIZE) - { - QMessageBox mbx; - mbx.setIcon(QMessageBox::Warning); - mbx.setText(tr("Invalid user ID")); - mbx.exec(); - return; - } - - for(int i=0;i<contact_records.size();i++) - if (contact_records[i].id==user_id) - { - QMessageBox mbx; - mbx.setIcon(QMessageBox::Warning); - mbx.setText(tr("User \"(%1) %2\" already exists").arg(user_id.toBase64().constData()).arg(contact_records[i].name)); - mbx.exec(); - return; - } - - Contacts::ContactRecord r; - - r.id=user_id; - r.name=""; - - storage->Add(user_id); - - if (!storage->isOK()) - { - QMessageBox mbx; - mbx.setIcon(QMessageBox::Warning); - mbx.setText(storage->GetLastError()); - mbx.exec(); - return; - } - - addItem(QString("(%1) ").arg(user_id.toBase64().constData())); - contact_records.append(r); - wgitem_to_recs[this->item(this->count()-1)]=&contact_records.last(); - - } + bool ok; + QString input = QInputDialog::getText(this, tr("Add New Contact"), tr("Pica Pica ID: "), QLineEdit::Normal, NULL, &ok); + + if (ok && !input.isEmpty()) + { + QByteArray user_id = QByteArray::fromBase64(input.toAscii()).left(PICA_ID_SIZE); + + if (user_id.size() != PICA_ID_SIZE) + { + QMessageBox mbx; + mbx.setIcon(QMessageBox::Warning); + mbx.setText(tr("Invalid user ID")); + mbx.exec(); + return; + } + + for(int i = 0; i < contact_records.size(); i++) + if (contact_records[i].id == user_id) + { + QMessageBox mbx; + mbx.setIcon(QMessageBox::Warning); + mbx.setText(tr("User \"(%1) %2\" already exists").arg(user_id.toBase64().constData()).arg(contact_records[i].name)); + mbx.exec(); + return; + } + + Contacts::ContactRecord r; + + r.id = user_id; + r.name = ""; + + storage->Add(user_id); + + if (!storage->isOK()) + { + QMessageBox mbx; + mbx.setIcon(QMessageBox::Warning); + mbx.setText(storage->GetLastError()); + mbx.exec(); + return; + } + + addItem(QString("(%1) ").arg(user_id.toBase64().constData())); + contact_records.append(r); + wgitem_to_recs[this->item(this->count() - 1)] = &contact_records.last(); + + } } void ContactListWidget::del_contact() { -QMessageBox mbx; -mbx.setText(QString(tr("Are you sure you want to remove user \"%1\" from your contact list?")).arg(currentItem()->text())); -mbx.setIcon(QMessageBox::Question); -mbx.addButton(QMessageBox::Yes); -mbx.addButton(QMessageBox::No); -mbx.setDefaultButton(QMessageBox::No); - -if (QMessageBox::Yes==mbx.exec()) - { - QByteArray rm_id; - QListWidgetItem *rm_ptr; - - storage->Delete(rm_id = wgitem_to_recs[currentItem()]->id); - delete (rm_ptr=takeItem(currentRow())); - - for(int i=0;i<contact_records.size();i++) - { - if (contact_records[i].id==rm_id) - { - contact_records.removeAt(i); - break; - } - } - - wgitem_to_recs.remove(rm_ptr); - } + QMessageBox mbx; + mbx.setText(QString(tr("Are you sure you want to remove user \"%1\" from your contact list?")).arg(currentItem()->text())); + mbx.setIcon(QMessageBox::Question); + mbx.addButton(QMessageBox::Yes); + mbx.addButton(QMessageBox::No); + mbx.setDefaultButton(QMessageBox::No); + + if (QMessageBox::Yes == mbx.exec()) + { + QByteArray rm_id; + QListWidgetItem *rm_ptr; + + storage->Delete(rm_id = wgitem_to_recs[currentItem()]->id); + delete (rm_ptr = takeItem(currentRow())); + + for(int i = 0; i < contact_records.size(); i++) + { + if (contact_records[i].id == rm_id) + { + contact_records.removeAt(i); + break; + } + } + + wgitem_to_recs.remove(rm_ptr); + } } void ContactListWidget::start_chat() { - msguirouter->start_chat(wgitem_to_recs[currentItem()]->id); + msguirouter->start_chat(wgitem_to_recs[currentItem()]->id); } void ContactListWidget::view_cert() { - QString cert_pem = storage->GetContactCert(wgitem_to_recs[currentItem()]->id); - - if (!storage->isOK()) - { - QMessageBox mbx; - mbx.setText(storage->GetLastError()); - mbx.exec(); - } - - if (!cert_pem.isEmpty()) - { - ViewCertDialog vcd; - vcd.SetCert(cert_pem); - vcd.exec(); - } - else - { - QMessageBox mbx; - mbx.setText(tr("Certificate is not stored for this contact yet")); - mbx.exec(); - } + QString cert_pem = storage->GetContactCert(wgitem_to_recs[currentItem()]->id); + + if (!storage->isOK()) + { + QMessageBox mbx; + mbx.setText(storage->GetLastError()); + mbx.exec(); + } + + if (!cert_pem.isEmpty()) + { + ViewCertDialog vcd; + vcd.SetCert(cert_pem); + vcd.exec(); + } + else + { + QMessageBox mbx; + mbx.setText(tr("Certificate is not stored for this contact yet")); + mbx.exec(); + } } void ContactListWidget::show_id() { - ShowPicaIdDialog d(wgitem_to_recs[currentItem()]->name, - wgitem_to_recs[currentItem()]->id, - tr("Contact's ID")); - d.exec(); + ShowPicaIdDialog d(wgitem_to_recs[currentItem()]->name, + wgitem_to_recs[currentItem()]->id, + tr("Contact's ID")); + d.exec(); } void ContactListWidget::Reload() { - setContactsStorage(storage); + setContactsStorage(storage); } void ContactListWidget::send_file() { - ftctrl->send_file(wgitem_to_recs[currentItem()]->id); + ftctrl->send_file(wgitem_to_recs[currentItem()]->id); } |
