Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

contactswidget.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "contactswidget.h"
  2. #include "ui_contactswidget.h"
  3. ContactsWidget::ContactsWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ContactsWidget)
  4. {
  5. ui->setupUi(this);
  6. ui->comboUserState->addItem(NetSoul::getStringFromUserState(NetSoul::Actif), NetSoul::Actif);
  7. ui->comboUserState->addItem(NetSoul::getStringFromUserState(NetSoul::Away), NetSoul::Away);
  8. ui->comboUserState->addItem(NetSoul::getStringFromUserState(NetSoul::Lock), NetSoul::Lock);
  9. connect(ui->listContacts, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contactsMenuRequested(QPoint)));
  10. connect(ui->listContacts, SIGNAL(userSelected(NetSoul::User)), this, SLOT(chatWithContact(NetSoul::User)));
  11. for(int i = 0; i < ui->listContacts->header()->count(); ++i)
  12. ui->listContacts->header()->resizeSection(i, 80);
  13. m_contactsMenu = new QMenu("Contacts");
  14. connect(m_contactsMenu->addAction("Chat"), SIGNAL(triggered()), this, SLOT(chat()));
  15. connect(m_contactsMenu->addAction("Search on intra-bocal"), SIGNAL(triggered()), this, SLOT(searchOnIntra()));
  16. connect(m_contactsMenu->addAction("Delete"), SIGNAL(triggered()), this, SLOT(removeFromContacts()));
  17. }
  18. ContactsWidget::~ContactsWidget()
  19. {
  20. delete ui;
  21. delete m_contactsMenu;
  22. }
  23. void ContactsWidget::nsStateChanged(NetSoul::State s)
  24. {
  25. if(s == NetSoul::Disconnected || s == NetSoul::NetworkError || s == NetSoul::ProtocolError)
  26. ui->listContacts->clear();
  27. }
  28. void ContactsWidget::nsUserDataChanged(NetSoul::User user)
  29. {
  30. ui->listContacts->updateUser(user);
  31. }
  32. void ContactsWidget::addContact(QString contact)
  33. {
  34. NetSoul::User usr;
  35. usr.login = contact;
  36. ui->listContacts->addUser(usr);
  37. }
  38. void ContactsWidget::addContacts(QStringList contacts)
  39. {
  40. foreach(QString contact, contacts)
  41. addContact(contact);
  42. }
  43. void ContactsWidget::removeFromContacts(QString login)
  44. {
  45. removeFromContacts(QStringList() << login);
  46. }
  47. void ContactsWidget::removeFromContacts(QStringList logins)
  48. {
  49. ui->listContacts->remove(logins);
  50. }
  51. void ContactsWidget::on_comboUserState_activated(int index)
  52. {
  53. emit userStateChanged((NetSoul::UserState)ui->comboUserState->itemData(index).toInt());
  54. }
  55. void ContactsWidget::contactsMenuRequested(QPoint p)
  56. {
  57. if(ui->listContacts->getSelectedUsers().isEmpty())
  58. return;
  59. m_contactsMenu->move(ui->listContacts->mapToGlobal(p) + QPoint(0, ui->listContacts->header()->height()));
  60. m_contactsMenu->show();
  61. }
  62. void ContactsWidget::chat()
  63. {
  64. emit chatRequested(ui->listContacts->getSelectedUsers());
  65. }
  66. void ContactsWidget::searchOnIntra()
  67. {
  68. QString exe;
  69. #ifdef Q_OS_WIN
  70. exe = "intrabocal.exe";
  71. #else
  72. #error "OS specific"
  73. #endif
  74. foreach(NetSoul::User usr, ui->listContacts->getSelectedUsers())
  75. QProcess::startDetached(exe, QStringList() << "-login" << usr.login);
  76. }
  77. void ContactsWidget::removeFromContacts()
  78. {
  79. QStringList logins;
  80. foreach(NetSoul::User usr, ui->listContacts->getSelectedUsers())
  81. if(!logins.contains(usr.login))
  82. logins.append(usr.login);
  83. if(!logins.isEmpty())
  84. emit removeFromContactsRequested(logins);
  85. }
  86. void ContactsWidget::chatWithContact(NetSoul::User user)
  87. {
  88. emit chatRequested(NetSoul::Users() << user);
  89. }