Commit 392ee727 authored by Alexandre Lision's avatar Alexandre Lision

Add minimal historybackend

We can now log calls in history.ini in the App package
parent b47b4c87
......@@ -32,6 +32,7 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
SET(ringclient_SRCS
main.cpp
mainwindow.cpp
minimalhistorybackend.cpp
mysearchbar.cpp)
SET(ringclient_FORMS
......@@ -41,6 +42,7 @@ QT5_WRAP_UI(ringclient_FORMS_HEADERS ${ringclient_FORMS})
SET(ringclient_HDRS
mainwindox.h
minimalhistorybackend.h
mysearchbar.h)
# Icons
......@@ -54,11 +56,25 @@ SET(myApp_ICON ${CMAKE_CURRENT_SOURCE_DIR}/data/appicon.icns)
SET_SOURCE_FILES_PROPERTIES(${myApp_ICON} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources")
SET(ring_ICONS ${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_accept.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_call.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_cancel.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_email.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_new_email.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_search.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_video.png)
SET_SOURCE_FILES_PROPERTIES(${ring_ICONS} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources")
qt5_add_resources(rcc_files ${CMAKE_CURRENT_SOURCE_DIR}/data.qrc)
ADD_EXECUTABLE(${PROJ_NAME} MACOSX_BUNDLE
${ringclient_SRCS}
${ringclient_HEADERS_MOC}
${ringclient_FORMS_HEADERS}
${myApp_ICON})
${myApp_ICON}
${ring_ICONS}
${rcc_files})
TARGET_LINK_LIBRARIES( ${PROJ_NAME}
${LIB_RING_CLIENT_LIBRARY}
......@@ -67,6 +83,7 @@ TARGET_LINK_LIBRARIES( ${PROJ_NAME}
${QT_QTGUI_LIBRARY}
)
SET_TARGET_PROPERTIES(${PROJ_NAME} PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/cmake/MacOSXBundleInfo.plist.in
MACOSX_BUNDLE_GUI_IDENTIFIER "cx.ring"
......
#include "mainwindow.h"
#include "minimalhistorybackend.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
......@@ -19,9 +18,6 @@ MainWindow::MainWindow(QWidget *parent) :
mainAccount_ = AccountModel::currentAccount();
callModel_ = CallModel::instance();
HistoryModel::instance()->addBackend(new LegacyHistoryBackend(this),
LoadOptions::FORCE_ENABLED);
ContactModel::instance()->addBackend(TransitionalContactBackend::instance(),
LoadOptions::FORCE_ENABLED);
......@@ -35,6 +31,9 @@ MainWindow::MainWindow(QWidget *parent) :
connectSlots();
ui->contact_list->setModel(ContactModel::instance());
HistoryModel::instance()->addBackend(new MinimalHistoryBackend(this),
LoadOptions::FORCE_ENABLED);
//ui->contact_list->setModel(CallModel::instance());
//ui->contact_list->setModel(HistoryModel::instance());
//ui->contact_list->setModel(ContactModel::instance());
......@@ -169,6 +168,12 @@ void MainWindow::transformAnswerBar()
void MainWindow::state_changed(Call *call, Call::State previousState)
{
qDebug() << "on state changed! " << previousState << endl;
if(call->state() == Call::State::CURRENT || call->state() == Call::State::RINGING)
transformAnswerBar();
else if(call->state() == Call::State::OVER) {
hideAnswerBar();
}
}
void MainWindow::incoming_call(Call *call)
......@@ -183,6 +188,8 @@ void MainWindow::on_call_button_clicked()
qDebug() << "ICI" << ui->search_bar->text();
mainCall_->setDialNumber(ui->search_bar->text());
mainCall_->performAction(Call::Action::ACCEPT);
showAnswerBar();
}
void MainWindow::on_hangup_button_clicked()
......
......@@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
<string>Ring</string>
</property>
<property name="styleSheet">
<string notr="true">QMainWindow#MainWindow {
......@@ -106,34 +106,12 @@ color: rgb(160, 160, 160);
</item>
<item>
<widget class="QToolButton" name="call_button">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color:transparent;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="data.qrc">
<normaloff>:/data/dark/ic_action_call.png</normaloff>
<normalon>:/data/light/ic_action_call.png</normalon>
<disabledoff>:/data/dark/ic_action_call.png</disabledoff>
<disabledon>:/data/light/ic_action_call.png</disabledon>
<activeoff>:/data/dark/ic_action_call.png</activeoff>
<activeon>:/data/light/ic_action_call.png</activeon>
<selectedoff>:/data/dark/ic_action_call.png</selectedoff>
<selectedon>:/data/light/ic_action_call.png</selectedon>:/data/dark/ic_action_call.png</iconset>
<normaloff>:/data/dark/ic_action_call.png</normaloff>:/data/dark/ic_action_call.png</iconset>
</property>
<property name="iconSize">
<size>
......@@ -144,16 +122,7 @@ color: rgb(160, 160, 160);
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_2">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color:transparent;</string>
</property>
<widget class="QToolButton" name="toolButton">
<property name="text">
<string>...</string>
</property>
......@@ -170,18 +139,9 @@ color: rgb(160, 160, 160);
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_3">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color:transparent;</string>
</property>
<widget class="QToolButton" name="toolButton_2">
<property name="text">
<string>...</string>
<string/>
</property>
<property name="icon">
<iconset resource="data.qrc">
......@@ -198,37 +158,72 @@ color: rgb(160, 160, 160);
</layout>
</item>
<item>
<widget class="QTreeView" name="contact_list">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
<enum>QTabWidget::South</enum>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgba(255,255,255, 0.0);</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<property name="currentIndex">
<number>1</number>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="iconSize">
<size>
<width>0</width>
<height>0</height>
</size>
<property name="tabsClosable">
<bool>false</bool>
</property>
<widget class="QWidget" name="tab_contacts">
<attribute name="title">
<string>Contacts</string>
</attribute>
<widget class="QTreeView" name="contact_list">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>347</width>
<height>361</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgba(255,255,255, 0.0);</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="iconSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</widget>
<widget class="QWidget" name="tab_history">
<attribute name="title">
<string>History</string>
</attribute>
</widget>
</widget>
</item>
</layout>
......
/************************************************************************************
* Copyright (C) 2014 by Savoir-Faire Linux *
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***********************************************************************************/
#include "minimalhistorybackend.h"
//Qt
#include <QtCore/QFile>
#include <QtCore/QCoreApplication>
#include <QtCore/QHash>
//SFLPhone
#include "call.h"
#include "account.h"
#include "phonenumber.h"
#include "historymodel.h"
MinimalHistoryBackend::MinimalHistoryBackend(QObject* parent) : AbstractHistoryBackend(nullptr,parent)
{
setObjectName("MinimalHistoryBackend");
}
MinimalHistoryBackend::~MinimalHistoryBackend()
{
}
QString MinimalHistoryBackend::name () const
{
return "Minimal history backend";
}
QVariant MinimalHistoryBackend::icon() const
{
return QVariant();
}
bool MinimalHistoryBackend::isEnabled() const
{
return true;
}
bool MinimalHistoryBackend::load()
{
QFile file(QCoreApplication::applicationDirPath() + "/history.ini");
if ( file.open(QIODevice::ReadOnly | QIODevice::Text) ) {
QMap<QString,QString> hc;
while (!file.atEnd()) {
QByteArray line = file.readLine().trimmed();
//The item is complete
if ((line.isEmpty() || !line.size()) && hc.size()) {
Call* pastCall = Call::buildHistoryCall(hc);
if (pastCall->peerName().isEmpty()) {
pastCall->setPeerName(tr("Unknown"));
}
pastCall->setRecordingPath(hc[ Call::HistoryMapFields::RECORDING_PATH ]);
pastCall->setBackend(this);
emit newHistoryCallAdded(pastCall);
hc.clear();
}
// Add to the current set
else {
const int idx = line.indexOf("=");
if (idx >= 0)
hc[line.left(idx)] = line.right(line.size()-idx-1);
}
}
return true;
}
else
qWarning() << "History doesn't exist or is not readable";
return false;
}
bool MinimalHistoryBackend::reload()
{
return false;
}
bool MinimalHistoryBackend::append(const Call* call)
{
if (call->backend() == this || call->id().isEmpty()) return false;
//TODO support \r and \n\r end of line
QFile file(QCoreApplication::applicationDirPath()+"/history.ini");
if ( file.open(QIODevice::Append | QIODevice::Text) ) {
const QString direction = (call->direction()==Call::Direction::INCOMING)?
Call::HistoryStateName::INCOMING : Call::HistoryStateName::OUTGOING;
QTextStream streamFileOut(&file);
const Account* a = call->account();
streamFileOut << QString("%1=%2\n").arg(Call::HistoryMapFields::CALLID ).arg(call->id() );
streamFileOut << QString("%1=%2\n").arg(Call::HistoryMapFields::TIMESTAMP_START ).arg(call->startTimeStamp() );
streamFileOut << QString("%1=%2\n").arg(Call::HistoryMapFields::TIMESTAMP_STOP ).arg(call->stopTimeStamp() );
streamFileOut << QString("%1=%2\n").arg(Call::HistoryMapFields::ACCOUNT_ID ).arg(a?a->id():"" );
streamFileOut << QString("%1=%2\n").arg(Call::HistoryMapFields::DISPLAY_NAME ).arg(call->peerName() );
streamFileOut << QString("%1=%2\n").arg(Call::HistoryMapFields::PEER_NUMBER ).arg(call->peerPhoneNumber()->uri() );
streamFileOut << QString("%1=%2\n").arg(Call::HistoryMapFields::DIRECTION ).arg(direction );
streamFileOut << QString("%1=%2\n").arg(Call::HistoryMapFields::MISSED ).arg(call->isMissed() );
streamFileOut << QString("%1=%2\n").arg(Call::HistoryMapFields::RECORDING_PATH ).arg(call->recordingPath() );
streamFileOut << QString("%1=%2\n").arg(Call::HistoryMapFields::CONTACT_USED ).arg(false );//TODO
if (call->peerPhoneNumber()->contact()) {
streamFileOut << QString("%1=%2\n").arg(Call::HistoryMapFields::CONTACT_UID ).arg(
QString(call->peerPhoneNumber()->contact()->uid())
);
}
streamFileOut << "\n";
streamFileOut.flush();
file.close();
return true;
}
else
qWarning() << "Unable to save history";
return false;
}
/** Rewrite the file from scratch
* @todo Eventually check if it is necessary, it will be faster
*/
bool MinimalHistoryBackend::save(const Call* call)
{
if (call->backend() != this)
append(call);
return false;
}
/** Rewrite the file from scratch
* @todo Eventually check if it is necessary, it will be faster
*/
bool MinimalHistoryBackend::batchSave(QList<Call*> calls)
{
Q_UNUSED(calls)
return false;
}
AbstractHistoryBackend::SupportedFeatures MinimalHistoryBackend::supportedFeatures() const
{
return (AbstractHistoryBackend::SupportedFeatures) (
AbstractHistoryBackend::SupportedFeatures::NONE |
AbstractHistoryBackend::SupportedFeatures::LOAD |
AbstractHistoryBackend::SupportedFeatures::CLEAR |
// AbstractHistoryBackend::SupportedFeatures::REMOVE|
AbstractHistoryBackend::SupportedFeatures::ADD );
}
///Edit 'item', the implementation may be a GUI or somehting else
bool MinimalHistoryBackend::edit( Call* call)
{
Q_UNUSED(call)
return false;
}
bool MinimalHistoryBackend::remove ( Call* c )
{
Q_UNUSED(c)
qDebug() << "Removing item is not yet supported";
return true;
}
///Add a new item to the backend
bool MinimalHistoryBackend::addNew( Call* call)
{
Q_UNUSED(call)
return true;
}
///Add a new phone number to an existing item
bool MinimalHistoryBackend::addPhoneNumber( Call* call , PhoneNumber* number )
{
Q_UNUSED(call)
Q_UNUSED(number)
return false;
}
bool MinimalHistoryBackend::clear()
{
//const int ret = KMessageBox::questionYesNo(static_cast<QApplication*>(QApplication::instance())->activeWindow(), i18n("Are you sure you want to clear history?"), i18n("Clear history"));
//if (ret == KMessageBox::Yes) {
QFile::remove(QCoreApplication::applicationDirPath()+"/history.ini");
return true;
//}
//return false;
}
QByteArray MinimalHistoryBackend::id() const
{
return "mhb";
}
QList<Call*> MinimalHistoryBackend::items() const
{
return QList<Call*>(); //TODO
}
/************************************************************************************
* Copyright (C) 2014 by Savoir-Faire Linux *
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***********************************************************************************/
#ifndef MINIMALHISTORYBACKEND_H
#define MINIMALHISTORYBACKEND_H
#include "abstractitembackend.h"
class LIB_EXPORT MinimalHistoryBackend : public AbstractHistoryBackend
{
public:
explicit MinimalHistoryBackend(QObject* parent = nullptr);
virtual ~MinimalHistoryBackend();
virtual bool load();
virtual bool reload();
virtual bool clear();
virtual bool save(const Call* call);
virtual bool batchSave(QList<Call*> calls);
virtual bool append(const Call* item);
virtual QString name () const;
virtual QVariant icon () const;
virtual bool isEnabled() const;
virtual QByteArray id () const;
virtual bool remove ( Call* c ) override;
virtual SupportedFeatures supportedFeatures() const;
virtual QList<Call*> items() const override;
///Edit 'item', the implementation may be a GUI or somehting else
virtual bool edit( Call* call);
///Add a new item to the backend
virtual bool addNew( Call* call);
///Add a new phone number to an existing item
virtual bool addPhoneNumber( Call* call , PhoneNumber* number );
};
#endif
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