123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #include "contactswidget.h"
- #include "ui_contactswidget.h"
-
- ContactsWidget::ContactsWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ContactsWidget)
- {
- ui->setupUi(this);
-
- ui->comboUserState->addItem(NetSoul::getStringFromUserState(NetSoul::Actif), NetSoul::Actif);
- ui->comboUserState->addItem(NetSoul::getStringFromUserState(NetSoul::Away), NetSoul::Away);
- ui->comboUserState->addItem(NetSoul::getStringFromUserState(NetSoul::Lock), NetSoul::Lock);
-
- connect(ui->listContacts, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contactsMenuRequested(QPoint)));
- connect(ui->listContacts, SIGNAL(userSelected(NetSoul::User)), this, SLOT(chatWithContact(NetSoul::User)));
-
- for(int i = 0; i < ui->listContacts->header()->count(); ++i)
- ui->listContacts->header()->resizeSection(i, 80);
-
- m_contactsMenu = new QMenu("Contacts");
- connect(m_contactsMenu->addAction("Chat"), SIGNAL(triggered()), this, SLOT(chat()));
- connect(m_contactsMenu->addAction("Search on intra-bocal"), SIGNAL(triggered()), this, SLOT(searchOnIntra()));
- connect(m_contactsMenu->addAction("Delete"), SIGNAL(triggered()), this, SLOT(removeFromContacts()));
- }
-
- ContactsWidget::~ContactsWidget()
- {
- delete ui;
- delete m_contactsMenu;
- }
-
- void ContactsWidget::nsStateChanged(NetSoul::State s)
- {
- if(s == NetSoul::Disconnected || s == NetSoul::NetworkError || s == NetSoul::ProtocolError)
- ui->listContacts->clear();
- }
-
- void ContactsWidget::nsUserDataChanged(NetSoul::User user)
- {
- ui->listContacts->updateUser(user);
- }
-
- void ContactsWidget::addContact(QString contact)
- {
- NetSoul::User usr;
- usr.login = contact;
- ui->listContacts->addUser(usr);
- }
-
- void ContactsWidget::addContacts(QStringList contacts)
- {
- foreach(QString contact, contacts)
- addContact(contact);
- }
-
- void ContactsWidget::removeFromContacts(QString login)
- {
- removeFromContacts(QStringList() << login);
- }
-
- void ContactsWidget::removeFromContacts(QStringList logins)
- {
- ui->listContacts->remove(logins);
- }
-
- void ContactsWidget::on_comboUserState_activated(int index)
- {
- emit userStateChanged((NetSoul::UserState)ui->comboUserState->itemData(index).toInt());
- }
-
- void ContactsWidget::contactsMenuRequested(QPoint p)
- {
- if(ui->listContacts->getSelectedUsers().isEmpty())
- return;
- m_contactsMenu->move(ui->listContacts->mapToGlobal(p) + QPoint(0, ui->listContacts->header()->height()));
- m_contactsMenu->show();
- }
-
- void ContactsWidget::chat()
- {
- emit chatRequested(ui->listContacts->getSelectedUsers());
- }
-
- void ContactsWidget::searchOnIntra()
- {
- QString exe;
- #ifdef Q_OS_WIN
- exe = "intrabocal.exe";
- #else
- #ifdef Q_OS_LINUX
- exe = "intrabocal";
- #else
- #error "OS specific"
- #endif
- #endif
- foreach(NetSoul::User usr, ui->listContacts->getSelectedUsers())
- QProcess::startDetached(exe, QStringList() << "-login" << usr.login);
- }
-
- void ContactsWidget::removeFromContacts()
- {
- QStringList logins;
- foreach(NetSoul::User usr, ui->listContacts->getSelectedUsers())
- if(!logins.contains(usr.login))
- logins.append(usr.login);
- if(!logins.isEmpty())
- emit removeFromContactsRequested(logins);
- }
-
- void ContactsWidget::chatWithContact(NetSoul::User user)
- {
- emit chatRequested(NetSoul::Users() << user);
- }
|