diff --git a/gtk/CMakeLists.txt b/gtk/CMakeLists.txt index 6ac8f33b1..c876697cf 100644 --- a/gtk/CMakeLists.txt +++ b/gtk/CMakeLists.txt @@ -71,6 +71,12 @@ set(SOURCE_FILES utils.c videowindow.c ) + +set(OBJC_FILES) +if (APPLE) + list(APPEND OBJC_FILES mac.m) +endif() + if(ENABLE_ASSISTANT) list(APPEND SOURCE_FILES setupwizard.c) endif() @@ -78,11 +84,14 @@ if(WIN32) list(APPEND SOURCE_FILES linphone.rc) endif() + apply_compile_flags(SOURCE_FILES "CPP" "C") +apply_compile_flags(OBJC_FILES "CPP" "OBJC") + if(WIN32) add_executable(linphone-gtk WIN32 ${SOURCE_FILES}) else() - add_executable(linphone-gtk ${SOURCE_FILES}) + add_executable(linphone-gtk ${SOURCE_FILES} ${OBJC_FILES}) endif() set_target_properties(linphone-gtk PROPERTIES OUTPUT_NAME linphone LINKER_LANGUAGE CXX) target_include_directories(linphone-gtk PUBLIC ${GTK2_INCLUDE_DIRS} ${INTL_INCLUDE_DIRS}) @@ -104,6 +113,10 @@ if(GTKMACINTEGRATION_FOUND) target_include_directories(linphone-gtk PUBLIC ${GTKMACINTEGRATION_INCLUDE_DIRS}) target_link_libraries(linphone-gtk ${GTKMACINTEGRATION_LIBRARIES}) endif() +if(APPLE) + target_link_libraries(linphone-gtk "-framework Cocoa") +endif() + install(TARGETS linphone-gtk RUNTIME DESTINATION bin diff --git a/gtk/chat.c b/gtk/chat.c index ccae62bd0..69b5466ad 100644 --- a/gtk/chat.c +++ b/gtk/chat.c @@ -341,7 +341,7 @@ void display_history_message(GtkWidget *chat_view,MSList *messages,const Linphon g_object_set_data(G_OBJECT(chat_view),"from_message",NULL); g_free(tmp); } - + linphone_gtk_free_list(messages); } } @@ -381,7 +381,7 @@ static gboolean link_event_handler(GtkTextTag *tag, GObject *text_view,GdkEvent LinphoneChatRoom *chat_room = (LinphoneChatRoom *)g_object_get_data(G_OBJECT(chat_view), "cr"); GtkWidget *main_window = linphone_gtk_get_main_window(); GtkWidget *friendlist = linphone_gtk_get_widget(main_window, "contact_list"); - + gtk_text_iter_backward_to_tag_toggle(&uri_begin, tag); gtk_text_iter_forward_to_tag_toggle(&uri_end, tag); uri = gtk_text_iter_get_slice(&uri_begin, &uri_end); @@ -393,10 +393,10 @@ static gboolean link_event_handler(GtkTextTag *tag, GObject *text_view,GdkEvent gtk_menu_popup(menu, NULL, NULL, NULL, NULL, 3, gdk_event_get_time(event)); } g_free(uri); - + linphone_chat_room_mark_as_read(chat_room); linphone_gtk_friend_list_update_button_display(GTK_TREE_VIEW(friendlist)); - + return TRUE; } return FALSE; diff --git a/gtk/linphone.h b/gtk/linphone.h index f337770fb..63b2dc362 100644 --- a/gtk/linphone.h +++ b/gtk/linphone.h @@ -360,3 +360,7 @@ LINPHONE_PUBLIC bool_t linphone_gtk_is_friend(LinphoneCore *lc, const char *cont LINPHONE_PUBLIC gboolean linphone_gtk_auto_answer_enabled(void); LINPHONE_PUBLIC void linphone_gtk_update_status_bar_icons(void); LINPHONE_PUBLIC void linphone_gtk_enable_auto_answer(GtkToggleButton *checkbox, gpointer user_data); + +#ifdef __APPLE__ +LINPHONE_PUBLIC void linphone_gtk_update_badge_count(); +#endif diff --git a/gtk/mac.m b/gtk/mac.m new file mode 100644 index 000000000..f8a7d1205 --- /dev/null +++ b/gtk/mac.m @@ -0,0 +1,46 @@ +/* +linphone, gtk-glade interface. +Copyright (C) 2008 Simon MORLAT (simon.morlat@linphone.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifdef __APPLE__ + +#import +#import "linphone.h" + +int unread_messages_count() { + LinphoneCore* lc = linphone_gtk_get_core(); + int count = 0; + const MSList *rooms = linphone_core_get_chat_rooms(lc); + const MSList *item = rooms; + while (item) { + LinphoneChatRoom *room = (LinphoneChatRoom *)item->data; + if (room) { + count += linphone_chat_room_get_unread_messages_count(room); + } + item = item->next; + } + + return count; +} + +void linphone_gtk_update_badge_count() { + ms_error("%d\n", unread_messages_count()); + [[NSApp dockTile] setBadgeLabel:[NSString stringWithFormat:@"%d", unread_messages_count()]]; +} + +#endif diff --git a/gtk/main.c b/gtk/main.c index ba91fd3b3..a1b7412db 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1555,6 +1555,9 @@ void linphone_gtk_status_icon_set_blinking(gboolean val) { if(icon) { linphone_status_icon_enable_blinking(icon, val); } +#ifdef __APPLE__ + linphone_gtk_update_badge_count(); +#endif } void linphone_gtk_options_activate(GtkWidget *item){ @@ -1945,6 +1948,12 @@ static void linphone_gtk_check_soundcards(void){ } static void linphone_gtk_quit_core(void){ +#ifdef HAVE_GTK_OSX + { + GtkosxApplication *theMacApp = gtkosx_application_get(); + gtkosx_application_set_menu_bar(theMacApp,NULL); + } +#endif linphone_gtk_unmonitor_usb(); g_source_remove_by_user_data(linphone_gtk_get_core()); #ifdef BUILD_WIZARD @@ -2022,7 +2031,7 @@ static void populate_xdg_data_dirs_envvar(void) { int i; gchar *value; gchar **paths; - + if(g_getenv("XDG_DATA_DIRS") == NULL) { value = g_strdup("/usr/share:/usr/local/share:/opt/local/share"); } else { @@ -2066,7 +2075,7 @@ int main(int argc, char *argv[]){ /*for pulseaudio:*/ g_setenv("PULSE_PROP_media.role", "phone", TRUE); #endif - + populate_xdg_data_dirs_envvar(); lang=linphone_gtk_get_lang(config_file); @@ -2198,7 +2207,7 @@ core_start: gtk_timeout_add(30,(GtkFunction)linphone_gtk_check_logs,(gpointer)linphone_gtk_get_core()); signal(SIGINT, sigint_handler); - + gtk_main(); linphone_gtk_quit(); @@ -2225,7 +2234,7 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi GtkWidget *linphone_gtk_make_tab_header(const gchar *label, const gchar *icon_name, gboolean show_quit_button, GCallback cb, gpointer user_data) { GtkWidget *tab_header=gtk_hbox_new (FALSE,0); GtkWidget *label_widget = gtk_label_new (label); - + if(icon_name) { GtkWidget *icon=gtk_image_new_from_icon_name(icon_name, GTK_ICON_SIZE_MENU); #ifdef HAVE_GTK_OSX