⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addressbooksub.cxx

📁 使用VOIP技术.能够无连接接通远程用户
💻 CXX
字号:
//  The contents of this file are subject to the Mozilla Public License//  Version 1.0 (the "License"); you may not use this file except in//  compliance with the License. You may obtain a copy of the License at//  http://www.mozilla.org/MPL/// //  Software distributed under the License is distributed on an "AS IS"//  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See//  the License for the specific language governing rights and limitations//  under the License.// //  The Original Code is CPhone, a cross platform voip gui.////  The Initial Developer of the Original Code is Derek Smithies.////  Copyright (C) 2002 Indranet Technologies Ltd, //                                  http://www.indranet-technologies.com//  All Rights Reserved.////  Contributor(s): _______________/* *   *  $Log: addressbookSub.cxx,v $ *  Revision 1.3  2003/04/11 01:08:35  dereksmithies *  Add speed dial support for Quicknet cards. * *  Revision 1.2  2003/04/04 04:37:49  dereksmithies *  Major upgrade. *  Ixj & microtelco support added. Fix threading issues. * *  Revision 1.1.1.1  2002/05/12 22:55:04  dereksmithies *  Initial release. * * * * */#include "addressbookSub.h"#include "keys.h"#include <ptlib.h>#include <qapplication.h>#include <qlineedit.h>#include <qlistview.h>#include <qmessagebox.h>#include <qpushbutton.h>#include <qevent.h>#define CUSTOM_EVENT_SETUP (QEvent::User + 1)PMutex           AddressBook::accessMutex;AddressBook::AddressBook()  : FormAddressBook( 0, "Address Book", FALSE, WDestructiveClose),    controlsSet(FALSE){  CPhone::Current().SetWindowId(eAddressBook, winId());  controlsSet = FALSE;  QApplication::postEvent(this, new QCustomEvent(CUSTOM_EVENT_SETUP));}/*   *  Destroys the object and frees any allocated resources */AddressBook::~AddressBook(){}void AddressBook::Setup(){  ListViewAbAllNames->clear();  ListViewAbAllNames->setColumnWidthMode(0, QListView::Maximum);  ListViewAbAllNames->setColumnText(0, "Name");  ListViewAbAllNames->setColumnWidthMode(1, QListView::Maximum);  ListViewAbAllNames->setColumnText(1, "Speed dial");  ListViewAbAllNames->setColumnWidthMode(2, QListView::Maximum);  ListViewAbAllNames->setColumnText(2, "Address");  ListViewAbAllNames->setSelectionMode(QListView::Single);  ListViewAbAllNames->setResizeMode(QListView::AllColumns);  PStringList abKeys;  PStringList addresses;  PStringList speedDials;  GetKeysSpeedsAddresses(abKeys, speedDials, addresses);  for(PINDEX i = 0; i< abKeys.GetSize(); i++) {    QListViewItem *item = new QListViewItem(ListViewAbAllNames);    item->setExpandable(TRUE);    item->setText(0, (const char *)abKeys[i]);    item->setText(1, (const char *)speedDials[i]);    item->setText(2, (const char *)addresses[i]);  }  BOOL inACall = !CPhone::GetUi().WaitingForACall();    OnConnectionEstablished(inACall);  controlsSet = TRUE;   }PString AddressBook::GetAddressForKey(PString key){   PStringList keys, speedDials, addresses;  GetKeysSpeedsAddresses(keys, speedDials, addresses);  PINDEX i = keys.GetStringsIndex(key);  if (i == P_MAX_INDEX)    return PString();  return addresses[i];}void AddressBook::GetNameAddressForSpeedDial(PString &name, PString &address, PString key){   PStringList names, speedDials, addresses;  GetKeysSpeedsAddresses(names, speedDials, addresses);    PINDEX i = speedDials.GetStringsIndex(key);  if (i == P_MAX_INDEX) {    name = PString();    address = PString();    return;  }  address = addresses[i];  name    = names[i];}void AddressBook::GetKeysSpeedsAddresses(PStringList &keys, PStringList &speedDials, PStringList &addresses){  PWaitAndSignal m(accessMutex);  PConfig *config = new PConfig(ADDRESSBOOK_CONFIG);  keys = config->GetKeys();  for (PINDEX i = 0; i< keys.GetSize(); i++) {    PString speedDialAddress=config->GetString(keys[i]);    PINDEX pos = speedDialAddress.Find('=');    if (pos == P_MAX_INDEX) {      addresses.AppendString(speedDialAddress);      speedDials.AppendString(PString());      continue;    }    speedDials.AppendString(speedDialAddress.Left(pos));    addresses.AppendString(speedDialAddress.Mid(pos + 1));  }  delete config;}void AddressBook::OnConnectionEstablished(bool isEstablished){  PushButtonAbConnect->setEnabled(!isEstablished);}void AddressBook::SaveCurrentEntries(){  PConfig     *config = new PConfig(ADDRESSBOOK_CONFIG);  PStringList abKeys = config->GetKeys();  for(PINDEX i=0; i< abKeys.GetSize(); i++)    config->DeleteKey(abKeys[i]);    QListViewItem *item = ListViewAbAllNames->firstChild();    while (item != NULL) {    PString res = PString((const char *)item->text(2));    if (!item->text(1).isEmpty())      res = PString((const char *)item->text(1)) + "=" + res;    config->SetString((const char *)item->text(0), res);    item = item->nextSibling();  }  delete config;  LineEditAbName->setText("");  LineEditAbSpeedDial->setText("");  LineEditAbAddress->setText("");}void AddressBook::AbAdd_slot(){  if (DuplicateNameCondition())    return;  if (DuplicateSpeedDialCondition())    return;  if (NullNameAddressCondition())    return;  QListViewItem *item  = new QListViewItem(ListViewAbAllNames);  item->setText(0, LineEditAbName->text());  item->setText(1, LineEditAbSpeedDial->text());   item->setText(2, LineEditAbAddress->text());   SaveCurrentEntries();}void AddressBook::AbCancelAll_slot(){  close (TRUE);}void AddressBook::AbChange_slot(){  if (NullNameAddressCondition())    return;  QListViewItem *item = ListViewAbAllNames->selectedItem();  if (item==NULL) {    QMessageBox::information(0, "Selection error",                "Please have the line to change selected before selecting \"Change\".");    return;  }  PStringList k, s, a;  ReadCurrentDisplayTable(k, s, a);    PINDEX kIndex = k.GetStringsIndex((const char *)LineEditAbName->text());  PINDEX sIndex = s.GetStringsIndex((const char *)LineEditAbSpeedDial->text());    if ((sIndex == P_MAX_INDEX) && (kIndex == P_MAX_INDEX)) /* speed dial and name not found*/    goto installAbChange_slot;  if ((sIndex != P_MAX_INDEX) && (kIndex != P_MAX_INDEX)) { /*speed dial and name both in list*/    if ((kIndex == sIndex) && (LineEditAbName->text() == item->text(0)))      goto installAbChange_slot;    goto errAbChange_slot;  }  if ((kIndex != P_MAX_INDEX) && (sIndex == P_MAX_INDEX)) {/*name found, speed dial not found */    if (LineEditAbName->text() == item->text(0))      goto installAbChange_slot;    goto errAbChange_slot;  }  if ((sIndex != P_MAX_INDEX) && (kIndex == P_MAX_INDEX)) { /*speed dial not found,  name found */    if (LineEditAbSpeedDial->text() == item->text(1))      goto installAbChange_slot;    goto errAbChange_slot;  }   installAbChange_slot:  item->setText(0, LineEditAbName->text());  item->setText(1, LineEditAbSpeedDial->text());  item->setText(2, LineEditAbAddress->text());  SaveCurrentEntries();  return; errAbChange_slot:  QString msg = "The name \n\"" + LineEditAbName->text() + "\"\n" +    "or the speed dial \"" + LineEditAbSpeedDial->text() + "\"\n" +    "is already in the addressbook.\n\n" +    "Please use a different name/speed dial";  QMessageBox::information(0, "Duplication in addressbook", msg);  return;}void AddressBook::AbDeleteItem_slot(){  QListViewItem *item = ListViewAbAllNames->selectedItem();  if (item==NULL) {    QMessageBox::information(0, "Selection error",       "Please have the line to change selected before selecting \"Delete\".");    return;  }  delete item;  SaveCurrentEntries();}void AddressBook::AbListViewSelectionChanged_slot(){  if (!controlsSet)    return;  QListViewItem *item = ListViewAbAllNames->selectedItem();  LineEditAbName->setText(item->text(0)) ;  LineEditAbSpeedDial->setText(item->text(1)) ;  LineEditAbAddress->setText(item->text(2)) ;}void AddressBook::AbSearchForItem_slot(){  QListViewItem *item = ListViewAbAllNames->firstChild();  while (item != NULL) {    if (item->text(0).compare(LineEditAbName->text() ) == 0) {      ListViewAbAllNames->setSelected(item, TRUE);      return;    }    item = item->nextSibling();  }  item = ListViewAbAllNames->firstChild();  while (item != NULL) {    if (item->text(1).compare(LineEditAbSpeedDial->text()) == 0) {      ListViewAbAllNames->setSelected(item, TRUE);      return;    }    item = item->nextSibling();  }  item = ListViewAbAllNames->firstChild();  while (item != NULL) {    if (item->text(2).compare(LineEditAbAddress->text()) == 0) {      ListViewAbAllNames->setSelected(item, TRUE);      return;    }    item = item->nextSibling();  }}bool AddressBook::DuplicateNameCondition(){  PStringList k, s, a;  ReadCurrentDisplayTable(k, s, a);  for (PINDEX i = 0; i < k.GetSize(); i++) {    if (k[i] == ((const char *)LineEditAbName->text())) {      QString msg = "The name \n\"" + LineEditAbName->text() + "\"\n" +	"is already in the addressbook.\n\n" +        "Please use a different name." ;      QMessageBox::information(0, "Duplicate name in addressbook", msg);      return TRUE;    }  }  return FALSE;}bool AddressBook::DuplicateSpeedDialCondition(){  PStringList k, s, a;  ReadCurrentDisplayTable(k, s, a);  for (PINDEX i = 0; i < k.GetSize(); i++) {    if ((s[i] == ((const char *)LineEditAbSpeedDial->text())) &&	(!s[i].IsEmpty())) {      QString msg = "The speed dial \n\"" + LineEditAbSpeedDial->text() + "\"\n" +	"is already in the addressbook.\n\n" +        "Please use a different speed dial." ;      QMessageBox::information(0, "Duplicate speed dial in addressbook", msg);      return TRUE;    }  }		   return FALSE;}void AddressBook::ReadCurrentDisplayTable(PStringList &keys, PStringList &speeds, PStringList &addresses){  QListViewItem *item = ListViewAbAllNames->firstChild();  while (item != NULL) {    keys.AppendString((const char *)item->text(0));    speeds.AppendString((const char *)item->text(1));    addresses.AppendString((const char *)item->text(2));    item = item->nextSibling();  }}bool AddressBook::NullNameAddressCondition(){  if (LineEditAbName->text().length()==0) {    QMessageBox::information(0, "Empty name", "Please enter a name");    return TRUE;  }  if (LineEditAbAddress->text().length()==0) {    QMessageBox::information(0, "Empty address", "Please enter an address");    return TRUE;  }  return FALSE;}void AddressBook::AbHelp_slot(){  cerr << "void AddressBook::AbHelp_slot()"<<endl;}void AddressBook::AbConnectToItem_slot(){  if (!CPhone::GetUi().WaitingForACall()) {    QMessageBox::warning(0, "Failed to connect", 			 "You cannot make a call while still in a call.", 0, 0);    return;  }  CPhone::GetUi().StartCall((const char *)LineEditAbAddress->text());  QCustomEvent *ce = new QCustomEvent(CUSTOM_EVENT_DIE);  QApplication::postEvent(this, ce);  //Qt will delete "ce" when done.}void AddressBook::AbDoubleClick_slot(){  AbConnectToItem_slot();}void AddressBook::closeEvent(QCloseEvent *e){ CPhone::Current().ForgetExists(eAddressBook, winId());  e->accept();}  void AddressBook::customEvent(QCustomEvent *e){  if (e->type()  == CUSTOM_EVENT_DIE)     close(TRUE);  if (e->type()  == CUSTOM_EVENT_SETUP)     Setup();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -