Commit d684f986 authored by philippe groarke's avatar philippe groarke

Working answer.

parent 24d0fe0d
......@@ -14,11 +14,9 @@ TEMPLATE = app
CONFIG += c++11
SOURCES += main.cpp\
mainwindow.cpp \
mylistview.cpp
mainwindow.cpp
HEADERS += mainwindow.h \
mylistview.h
HEADERS += mainwindow.h
FORMS += mainwindow.ui
......
......@@ -8,32 +8,41 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->contact_list->setModel(CallModel::instance());
ui->contact_list->setModel(HistoryModel::instance());
ui->contact_list->setModel(ContactModel::instance());
ui->contact_list->setAttribute(Qt::WA_MacShowFocusRect, false);
//setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint);
//setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
mainAccount_ = AccountModel::currentAccount();
callModel_ = CallModel::instance();
HistoryModel::instance()->addBackend(new LegacyHistoryBackend(this), LoadOptions::FORCE_ENABLED);
connectSlots();
QObject::connect(callModel_, SIGNAL(callStateChanged(Call*, Call::State)),
this, SLOT(on_state_changed(Call*, Call::State)));
connect(&pollTimer_, SIGNAL(timeout()), this, SLOT(pollEvents()));
pollTimer_.start(1000);
//ui->contact_list->setModel(CallModel::instance());
ui->contact_list->setModel(HistoryModel::instance());
// ui->contact_list->setModel(ContactModel::instance());
}
MainWindow::~MainWindow()
{
if (mainCall_ != nullptr)
if (mainCall_ != nullptr) {
mainCall_->performAction(Call::Action::REFUSE);
delete mainAccount_;
delete mainCall_;
delete mainCall_;
}
if (mainAccount_) {
delete mainAccount_;
}
if (callModel_) {
//delete callModel_;
}
delete ui;
}
//// PROTECTED ////
void MainWindow::mousePressEvent(QMouseEvent *e)
{
clickPos_ = e->pos();
......@@ -47,9 +56,36 @@ void MainWindow::mouseMoveEvent(QMouseEvent *e)
//// PRIVATE ////
void MainWindow::connectSlots()
{
QObject::connect(callModel_, SIGNAL(callStateChanged(Call*, Call::State)),
this, SLOT(state_changed(Call*, Call::State)));
QObject::connect(callModel_, SIGNAL(incomingCall(Call*)),
this, SLOT(incoming_call(Call*)));
connect(&pollTimer_, SIGNAL(timeout()), this, SLOT(pollEvents()));
pollTimer_.start(1000);
}
//// SLOTS ////
void MainWindow::state_changed(Call *call, Call::State previousState)
{
qDebug() << "on state changed! " << previousState << endl;
}
void MainWindow::incoming_call(Call *call)
{
qDebug() << "incoming call!";
mainCall_ = call;
}
void MainWindow::on_call_button_clicked()
{
mainCall_ = CallModel::instance()->dialingCall();
......@@ -63,14 +99,16 @@ void MainWindow::on_hangup_button_clicked()
mainCall_->performAction(Call::Action::REFUSE);
}
void MainWindow::on_state_changed(Call *call, Call::State previousState)
{
qDebug() << "on state changed!" << endl;
}
void MainWindow::pollEvents()
{
qDebug() << "Poll Events?";
AccountModel::currentAccount()->poll_events();
}
void MainWindow::on_answer_button_clicked()
{
if (mainCall_) {
mainCall_->performAction(Call::Action::ACCEPT);
}
}
......@@ -15,6 +15,7 @@
#include <callmodel.h>
#include <contactmodel.h>
#include <historymodel.h>
#include <legacyhistorybackend.h>
namespace Ui {
class MainWindow;
......@@ -33,19 +34,23 @@ protected:
void mouseMoveEvent(QMouseEvent *);
private:
void connectSlots();
private slots:
void state_changed(Call* call, Call::State previousState);
void incoming_call(Call* call);
void on_call_button_clicked();
void on_state_changed(Call* call, Call::State previousState);
void on_hangup_button_clicked();
void pollEvents();
void on_answer_button_clicked();
private:
Ui::MainWindow *ui;
CallModel* callModel_{nullptr};
Call* mainCall_{nullptr};
Account* mainAccount_;
LegacyHistoryBackend* backend_;
QString savedNumber_;
QTimer pollTimer_;
QPoint clickPos_{QPoint(0,0)};
......
......@@ -89,7 +89,7 @@
</layout>
</item>
<item>
<widget class="MyListView" name="contact_list">
<widget class="QTreeView" name="contact_list">
<property name="styleSheet">
<string notr="true">background-color: rgba(255,255,255, 0.0);</string>
</property>
......@@ -102,9 +102,6 @@
<property name="lineWidth">
<number>0</number>
</property>
<property name="flow">
<enum>QListView::TopToBottom</enum>
</property>
</widget>
</item>
</layout>
......@@ -184,13 +181,6 @@
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>MyListView</class>
<extends>QListView</extends>
<header>mylistview.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
......
#include "mylistview.h"
MyListView::MyListView(QWidget *parent) :
QListView(parent)
{
setAttribute(Qt::WA_MacShowFocusRect, false);
}
#ifndef MYLISTVIEW_H
#define MYLISTVIEW_H
#include <QWidget>
#include <QListView>
class MyListView : public QListView
{
Q_OBJECT
public:
explicit MyListView(QWidget *parent = 0);
signals:
public slots:
};
#endif // MYLISTVIEW_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment