Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modules: add comm-telepathy #4

Merged
merged 3 commits into from Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions CMakeLists.txt
Expand Up @@ -23,8 +23,10 @@ pkg_search_module(GMODULE REQUIRED gmodule-2.0)
pkg_search_module(DBUS REQUIRED dbus-glib-1)
pkg_search_module(SQL REQUIRED sqlite3)

find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets DBus)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets DBus)
find_package(TelepathyQt5 0.9.7)

pkg_search_module(GSTREAMER gstreamer-1.0)
pkg_search_module(PULSE libpulse)
pkg_search_module(LIBHILDON hildon-1)
Expand Down Expand Up @@ -150,6 +152,13 @@ else()
message("libnotify support disabled")
endif(DEFINED NOTIFY_LIBRARIES)

if(DEFINED TELEPATHY_QT5_LIBRARIES)
message("Qt Telepathy support enabled")
else()
message("Telepathy support disabled")
endif(DEFINED TELEPATHY_QT5_LIBRARIES)


add_subdirectory(src)
add_subdirectory(src/modules)
add_subdirectory(desktop)
Expand Down
4 changes: 2 additions & 2 deletions src/modapi/types.h
Expand Up @@ -55,7 +55,7 @@ typedef enum {
SPHONE_CALL_DIALING,
SPHONE_CALL_ALERTING,
SPHONE_CALL_INCOMING,
SPHONE_CALL_WATING,
SPHONE_CALL_WAITING,
SPHONE_CALL_DISCONNECTED,
} sphone_call_state_t;

Expand Down Expand Up @@ -85,7 +85,7 @@ typedef struct _CallProperties{
time_t start_time;
time_t end_time;
bool emergency;
bool awnserd;
bool answered;
bool needs_route;
bool outbound;
} CallProperties;
Expand Down
3 changes: 3 additions & 0 deletions src/modules/CMakeLists.txt
@@ -1,3 +1,4 @@
find_package(PkgConfig)
set(MODULE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../modapi)

add_library(test SHARED test.c)
Expand All @@ -17,6 +18,7 @@ if(DEFINED Qt${QT_VERSION_MAJOR}_FOUND)
target_link_libraries(qtloop ${COMMON_LIBRARIES} Qt${QT_VERSION_MAJOR}::Widgets)
target_include_directories(qtloop SYSTEM PRIVATE ${COMMON_INCLUDE_DIRS})
target_include_directories(qtloop PRIVATE ${MODULE_INCLUDE_DIRS})

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm?

install(TARGETS qtloop DESTINATION ${SPHONE_MODULE_DIR})
endif(DEFINED Qt${QT_VERSION_MAJOR}_FOUND)

Expand Down Expand Up @@ -124,3 +126,4 @@ if(DEFINED NOTIFY_LIBRARIES)
endif(DEFINED NOTIFY_LIBRARIES)

add_subdirectory(gui)
add_subdirectory(voicecallmanager)
4 changes: 2 additions & 2 deletions src/modules/comm-ofono.c
Expand Up @@ -258,7 +258,7 @@ static sphone_call_state_t ofono_string_to_call_state(const gchar *state)
else if(g_strcmp0(state, "incoming") == 0)
return SPHONE_CALL_INCOMING;
else if(g_strcmp0(state, "waiting") == 0)
return SPHONE_CALL_WATING;
return SPHONE_CALL_WAITING;
else if(g_strcmp0(state, "disconnected") == 0)
return SPHONE_CALL_DISCONNECTED;
sphone_module_log(LL_WARN, "Got invalid call state %s", state);
Expand Down Expand Up @@ -449,7 +449,7 @@ static void call_accept_trigger(gconstpointer data, gpointer user_data)
OFONO_VOICECALL_IFACE, "Answer", NULL, NULL,
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &gerror);

call->awnserd = true;
call->answered = true;

g_variant_unref(result);

Expand Down
6 changes: 3 additions & 3 deletions src/modules/commtest.c
Expand Up @@ -64,7 +64,7 @@ static gboolean call_remote_accept(void *data)
return true;
} else if(call->state == SPHONE_CALL_ALERTING) {
call->state = SPHONE_CALL_ACTIVE;
call->awnserd = true;
call->answered = true;
call->start_time = time(NULL);
execute_datapipe(&call_properties_changed_pipe, call);
sphone_module_log(LL_DEBUG, "set state active on %s", call->line_identifier);
Expand Down Expand Up @@ -121,7 +121,7 @@ static void call_accept_trigger(const void *data, void *user_data)
if(icall->backend == id && icall->state == SPHONE_CALL_INCOMING) {
CallProperties *call = find_call(icall);
if(call) {
call->awnserd = true;
call->answered = true;
call->state = SPHONE_CALL_ACTIVE;
call->start_time = time(NULL);
execute_datapipe(&call_properties_changed_pipe, call);
Expand Down Expand Up @@ -149,7 +149,7 @@ static void call_hangup_trigger(const void *data, void *user_data)
call->end_time = time(NULL);
execute_datapipe(&call_properties_changed_pipe, call);

if(call->awnserd) {
if(call->answered) {
char *line_id = g_strdup(call->line_identifier);
sphone_module_log(LL_DEBUG, "%s will call back in 10s", line_id);
g_timeout_add_seconds(10, mock_incomeing_call, line_id);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/external-exec.c
Expand Up @@ -64,7 +64,7 @@ static void call_properties_changed_trigger(gconstpointer data, gpointer user_da
command = sphone_conf_get_string("ExternalExec", "OutgoingCall", NULL, NULL);
else if(call->state == SPHONE_CALL_ACTIVE)
command = sphone_conf_get_string("ExternalExec", "CallAnswered", NULL, NULL);
else if(call->state == SPHONE_CALL_DISCONNECTED && !call->awnserd)
else if(call->state == SPHONE_CALL_DISCONNECTED && !call->answered)
command = sphone_conf_get_string("ExternalExec", "CallMissed", NULL, NULL);

if(command) {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/gui/gtk2/ui-calls-manager-gtk.c
Expand Up @@ -208,7 +208,7 @@ static void gui_calls_select_callback(void)
gtk_widget_hide(g_calls_manager.answer_waiting_button);
gtk_widget_show(g_calls_manager.answer_button);
gtk_widget_show(g_calls_manager.hangup_button);
} else if(call->state == SPHONE_CALL_WATING) {
} else if(call->state == SPHONE_CALL_WAITING) {
gtk_widget_hide(g_calls_manager.activate_button);
gtk_widget_show(g_calls_manager.answer_waiting_button);
gtk_widget_hide(g_calls_manager.answer_button);
Expand Down Expand Up @@ -356,7 +356,7 @@ static void gui_calls_answer_callback(void)
gtk_tree_path_free(path);
gtk_tree_model_get_value(GTK_TREE_MODEL(g_calls_manager.dials_store),&iter, GUI_CALLS_COLUMN_CALL, &value);
CallProperties *call = (CallProperties*)g_value_get_pointer(&value);
call->awnserd = TRUE;
call->answered = TRUE;

execute_datapipe(&call_accept_pipe, call);

Expand Down
4 changes: 2 additions & 2 deletions src/modules/notify-libnotify.c
Expand Up @@ -109,9 +109,9 @@ static void call_properties_changed_trigger(const void *data, void *user_data)
(void)user_data;
const CallProperties *call = data;

sphone_module_log(LL_DEBUG, "%s, %i %i %i", __func__, call->state != SPHONE_CALL_DISCONNECTED, call->outbound, call->awnserd);
sphone_module_log(LL_DEBUG, "%s, %i %i %i", __func__, call->state != SPHONE_CALL_DISCONNECTED, call->outbound, call->answered);

if(call->state != SPHONE_CALL_DISCONNECTED || call->outbound || call->awnserd)
if(call->state != SPHONE_CALL_DISCONNECTED || call->outbound || call->answered)
return;

CallProperties *call_copy = call_properties_copy(call);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/store-rtcom.c
Expand Up @@ -77,7 +77,7 @@ static void call_properties_changed_trigger(const void *data, void *user_data)

RTCOM_EL_EVENT_SET_FIELD(ev, service, g_strdup("RTCOM_EL_SERVICE_CALL"));

if(!call->awnserd && !call->outbound) {
if(!call->answered && !call->outbound) {
RTCOM_EL_EVENT_SET_FIELD(ev, event_type, g_strdup("RTCOM_EL_EVENTTYPE_CALL_MISSED"));
} else {
RTCOM_EL_EVENT_SET_FIELD(ev, event_type, g_strdup("RTCOM_EL_EVENTTYPE_CALL"));
Expand Down Expand Up @@ -333,7 +333,7 @@ static GList *get_calls_for_contact(Contact *contact, unsigned int limit)
}
sphone_module_log(LL_DEBUG, "got line: %s", line_identifier ?: "NULL");
call->line_identifier = g_strdup(line_identifier);
call->awnserd = type != rtcom_el_get_eventtype_id(evlog, "RTCOM_EL_EVENTTYPE_CALL_MISSED");
call->answered = type != rtcom_el_get_eventtype_id(evlog, "RTCOM_EL_EVENTTYPE_CALL_MISSED");
call->outbound = outbound;
call->state = SPHONE_CALL_DISCONNECTED;

Expand Down
32 changes: 32 additions & 0 deletions src/modules/voicecallmanager/CMakeLists.txt
@@ -0,0 +1,32 @@
find_package(PkgConfig)

pkg_check_modules(QTVOICECALL qtvoicecall)

if(DEFINED QTVOICECALL_FOUND)
add_library(comm-voicecallmanager SHARED
comm-voicecallmanager.cpp
comm-voicecallmanager.h
comm-voicecallmanager-maemomanager.h
comm-voicecallmanager-maemoprovider.h
comm-voicecallmanager-maemomanager.cpp
comm-voicecallmanager-maemoprovider.cpp
comm-voicecallmanager-maemocallhandler.h
comm-voicecallmanager-maemocallhandler.cpp
)
target_link_libraries(comm-voicecallmanager ${COMMON_LIBRARIES} Qt${QT_VERSION_MAJOR}::Widgets ${TELEPATHY_QT5_LIBRARIES})

target_link_libraries(comm-voicecallmanager ${QTVOICECALL_LIBRARIES})
target_include_directories(comm-voicecallmanager PUBLIC ${QTVOICECALL_INCLUDE_DIRS})
target_compile_options(comm-voicecallmanager PUBLIC ${QTVOICECALL_CFLAGS_OTHER})

target_compile_definitions(comm-voicecallmanager PUBLIC ${Qt5DBus_DEFINITIONS})

target_include_directories(comm-voicecallmanager SYSTEM PRIVATE ${COMMON_INCLUDE_DIRS})
target_include_directories(comm-voicecallmanager PRIVATE ${MODULE_INCLUDE_DIRS})
target_include_directories(comm-voicecallmanager PRIVATE ${TELEPATHY_QT5_INCLUDE_DIR})
target_include_directories(comm-voicecallmanager PRIVATE ${Qt5DBus_INCLUDE_DIRS})

set_property(TARGET comm-voicecallmanager PROPERTY AUTOMOC ON)

install(TARGETS comm-voicecallmanager DESTINATION ${SPHONE_MODULE_DIR})
endif(DEFINED QTVOICECALL_FOUND)
@@ -0,0 +1,127 @@
#include <time.h>

#include "comm-voicecallmanager-maemocallhandler.h"

#include "moc_comm-voicecallmanager-maemocallhandler.cpp"

MaemoCallHandler::MaemoCallHandler(MaemoManager* mgr_, VoiceCallHandler* handler_)
{
this->mgr = mgr_;
this->voicecall_handler = handler_;
this->backend = NULL;
this->call_properties = NULL;
this->call_status = VoiceCallHandler::STATUS_NULL;

// Setup signals here, we could add more like line id changes, duration
// changes (I suppose hold might influence the duration)
connect(voicecall_handler, &VoiceCallHandler::statusChanged, this, &MaemoCallHandler::statusChanged);
}

MaemoCallHandler::~MaemoCallHandler()
{
disconnect(voicecall_handler);
call_properties_free(call_properties);
}

void MaemoCallHandler::setupProvider()
{
if (backend != NULL)
return;

sphone_module_log(LL_DEBUG, "setupProvider");

QString provider_id = voicecall_handler->providerId();
if (provider_id == "")
return;

backend = mgr->maemo_providers[provider_id];
}

void MaemoCallHandler::statusChanged()
{
// Since it's not setup upon creation, let's check here first
setupProvider();

int current_status = voicecall_handler->status();

qDebug() << "statusChanged status:" << current_status << "old status:" << call_status;
sphone_module_log(LL_DEBUG, "statusChanged status: %d old status: %d",
current_status, call_status);

if (call_status == VoiceCallHandler::STATUS_NULL) {
sphone_module_log(LL_DEBUG, "Creating call");
call_properties = (CallProperties*)g_malloc0(sizeof(*call_properties));

call_properties->backend = backend->sphone_backend_id;
call_properties->needs_route = backend->type == "tel";
call_properties->outbound = !voicecall_handler->isIncoming();

if (current_status == VoiceCallHandler::STATUS_INCOMING)
call_properties->state = SPHONE_CALL_INCOMING;
else if (current_status == VoiceCallHandler::STATUS_DIALING)
call_properties->state = SPHONE_CALL_DIALING;
else if (current_status == VoiceCallHandler::STATUS_ALERTING)
call_properties->state = SPHONE_CALL_ALERTING;
else
sphone_module_log(LL_DEBUG, "Not sure what initial state to assign to call!!!");

call_properties->start_time = time(NULL);

call_properties->emergency = voicecall_handler->isEmergency();
call_properties->line_identifier = g_strdup(voicecall_handler->lineId().toStdString().c_str());
call_properties->backend_data = g_strdup(voicecall_handler->handlerId().toStdString().c_str());

execute_datapipe(&call_new_pipe, call_properties);
} else if (current_status == VoiceCallHandler::STATUS_ACTIVE) {
#if 0
// Is this the right place?
if (call_properties->outbound)
call_properties->answered = true;
#endif
call_properties->answered = true;

call_properties->state = SPHONE_CALL_ACTIVE;
execute_datapipe(&call_properties_changed_pipe, call_properties);
} else if (current_status == VoiceCallHandler::STATUS_DIALING) {
call_properties->state = SPHONE_CALL_DIALING;
execute_datapipe(&call_properties_changed_pipe, call_properties);
} else if (current_status == VoiceCallHandler::STATUS_ALERTING) {
call_properties->state = SPHONE_CALL_ALERTING;
execute_datapipe(&call_properties_changed_pipe, call_properties);
} else if (current_status == VoiceCallHandler::STATUS_HELD) {
call_properties->state = SPHONE_CALL_HELD;
execute_datapipe(&call_properties_changed_pipe, call_properties);
} else if (current_status == VoiceCallHandler::STATUS_WAITING) {
call_properties->state = SPHONE_CALL_WAITING;
execute_datapipe(&call_properties_changed_pipe, call_properties);
} else if (current_status == VoiceCallHandler::STATUS_DISCONNECTED) {
sphone_module_log(LL_DEBUG, "call status: disconnected");
call_properties->state = SPHONE_CALL_DISCONNECTED;
call_properties->end_time = time(NULL);

execute_datapipe(&call_properties_changed_pipe, call_properties);
}

call_status = current_status;
}

void MaemoCallHandler::answer()
{
sphone_module_log(LL_DEBUG, "accept()");
voicecall_handler->answer();
}

void MaemoCallHandler::hold(bool hold)
{
sphone_module_log(LL_DEBUG, "hold()");
voicecall_handler->hold(hold);
}

void MaemoCallHandler::hangup()
{
sphone_module_log(LL_DEBUG, "hangup()");
voicecall_handler->hangup();
call_properties->state = SPHONE_CALL_DISCONNECTED;
call_properties->end_time = time(NULL);
execute_datapipe(&call_properties_changed_pipe, call_properties);
}