]> sjero.net Git - linphone/commitdiff
add star icon in the uri bar to add contacts
authorSimon Morlat <simon.morlat@linphone.org>
Mon, 19 Sep 2011 07:46:17 +0000 (09:46 +0200)
committerSimon Morlat <simon.morlat@linphone.org>
Mon, 19 Sep 2011 07:46:17 +0000 (09:46 +0200)
coreapi/friend.c
gtk/conference.c [new file with mode: 0644]
gtk/friendlist.c
pixmaps/contact_starred.png [new file with mode: 0644]
pixmaps/contact_unstarred.png [new file with mode: 0644]

index 527e29bd593a4bc2e5e1e6088f3e10059f508cbd..03332d689f4b9b23008ab27c0c5c320f04f7103b 100644 (file)
@@ -438,13 +438,15 @@ static bool_t username_match(const char *u1, const char *u2){
 LinphoneFriend *linphone_core_get_friend_by_address(const LinphoneCore *lc, const char *uri){
        LinphoneAddress *puri=linphone_address_new(uri);
        const MSList *elem;
-       const char *username=linphone_address_get_username(puri);
-       const char *domain=linphone_address_get_domain(puri);
+       const char *username;
+       const char *domain;
        LinphoneFriend *lf=NULL;
                
        if (puri==NULL){
                return NULL;
        }
+       username=linphone_address_get_username(puri);
+       domain=linphone_address_get_domain(puri);
        for(elem=lc->friends;elem!=NULL;elem=ms_list_next(elem)){
                lf=(LinphoneFriend*)elem->data;
                const char *it_username=linphone_address_get_username(lf->uri);
diff --git a/gtk/conference.c b/gtk/conference.c
new file mode 100644 (file)
index 0000000..c3df395
--- /dev/null
@@ -0,0 +1,31 @@
+/***************************************************************************
+ *            gtk/conference.c
+ *
+ *  Mon Sep 12, 2011
+ *  Copyright  2011  Belledonne Communications
+ *  Author: Simon Morlat
+ *  Email simon dot morlat at linphone dot 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.
+ */
+ #include "linphone.h"
\ No newline at end of file
index d1b116272f0c749138b4076f43ee6da388988c72..1ebc9c15c783dc8821213b4b1e5250bbfa543ea6 100644 (file)
@@ -172,6 +172,70 @@ void linphone_gtk_my_presence_clicked(GtkWidget *button){
        gtk_widget_show(menu);
 }
 
+static void icon_press_handler(GtkEntry *entry){
+       const char *text=gtk_entry_get_text(entry);
+       if (text && strlen(text)>0){
+               char *uri;
+               LinphoneFriend *lf;
+               linphone_core_interpret_friend_uri(linphone_gtk_get_core(),text,&uri);
+               if (uri==NULL){
+                       return ;
+               }
+               lf=linphone_core_get_friend_by_address(linphone_gtk_get_core(),uri);
+               if (lf==NULL)
+                       lf=linphone_friend_new_with_addr(uri);
+               if (lf!=NULL){
+                       linphone_gtk_show_contact(lf);
+               }
+               ms_free(uri);
+       }
+}
+
+static void update_star(GtkEntry *entry, gboolean is_known){
+       GdkPixbuf *active,*starred,*unstarred;
+       active=gtk_entry_get_icon_pixbuf(entry,GTK_ENTRY_ICON_SECONDARY);
+       starred=g_object_get_data(G_OBJECT(entry),"starred_icon");
+       unstarred=g_object_get_data(G_OBJECT(entry),"unstarred_icon");
+       if (is_known && (active==unstarred)){
+               gtk_entry_set_icon_from_pixbuf(entry,GTK_ENTRY_ICON_SECONDARY,starred);
+       }else if ((!is_known) && (active==starred)){
+               gtk_entry_set_icon_from_pixbuf(entry,GTK_ENTRY_ICON_SECONDARY,unstarred);
+       }
+}
+
+static void check_contact(GtkEditable *editable, LinphoneCore *lc){
+       char *tmp=gtk_editable_get_chars(editable,0,-1);
+       if (tmp!=NULL){
+               if (strlen(tmp)>0){
+                       char *uri=NULL;
+                       linphone_core_interpret_friend_uri(lc,tmp,&uri);
+                       if (uri){
+                               LinphoneFriend *lf=linphone_core_get_friend_by_address(lc,uri);
+                               ms_free(uri);
+                               if (lf) {
+                                       update_star(GTK_ENTRY(editable),TRUE);
+                                       g_free(tmp);
+                                       return;
+                               }
+                       }
+               }
+               g_free(tmp);
+       }
+       update_star(GTK_ENTRY(editable),FALSE);
+}
+
+static void linphone_gtk_init_bookmark_icon(void){
+       GtkWidget *mw=linphone_gtk_get_main_window();
+       GtkWidget *entry=linphone_gtk_get_widget(mw,"uribar");
+       GdkPixbuf *pbuf=create_pixbuf("contact_unstarred.png");
+       gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(entry),GTK_ENTRY_ICON_SECONDARY,pbuf);
+       g_object_set_data_full(G_OBJECT(entry),"unstarred_icon",pbuf,g_object_unref);
+       pbuf=create_pixbuf("contact_starred.png");
+       g_object_set_data_full(G_OBJECT(entry),"starred_icon",pbuf,g_object_unref);
+       gtk_entry_set_icon_activatable(GTK_ENTRY(entry),GTK_ENTRY_ICON_SECONDARY,TRUE);
+       g_signal_connect(G_OBJECT(entry),"icon-release",(GCallback)icon_press_handler,NULL);
+       g_signal_connect(G_OBJECT(GTK_EDITABLE(entry)),"changed",(GCallback)check_contact,linphone_gtk_get_core());
+}
 
 static void linphone_gtk_friend_list_init(GtkWidget *friendlist)
 {
@@ -179,7 +243,8 @@ static void linphone_gtk_friend_list_init(GtkWidget *friendlist)
        GtkCellRenderer *renderer;
        GtkTreeViewColumn *column;
        GtkTreeSelection *select;
-       
+
+       linphone_gtk_init_bookmark_icon();
        
        store = gtk_list_store_new(FRIEND_LIST_NCOL, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING,  G_TYPE_POINTER,
                                        G_TYPE_STRING, GDK_TYPE_PIXBUF);
@@ -318,14 +383,15 @@ void linphone_gtk_show_friends(void){
                }
                if (!online_only || (linphone_friend_get_status(lf)!=LinphoneStatusOffline)){
                        BuddyInfo *bi;
+                       gboolean send_subscribe=linphone_friend_get_send_subscribe(lf);
                        if (name==NULL || name[0]=='\0') display=uri;
                        gtk_list_store_append(store,&iter);
                        gtk_list_store_set(store,&iter,FRIEND_NAME, display,
-                                       FRIEND_PRESENCE_STATUS, linphone_online_status_to_string(linphone_friend_get_status(lf)),
-                                       FRIEND_ID,lf,-1);
-                       gtk_list_store_set(store,&iter,
-                               FRIEND_PRESENCE_IMG, create_status_picture(linphone_friend_get_status(lf)),
-                               -1);
+                                       FRIEND_PRESENCE_STATUS, 
+                               send_subscribe ? linphone_online_status_to_string(linphone_friend_get_status(lf)) : "",
+                                       FRIEND_ID,lf,
+                               FRIEND_PRESENCE_IMG, send_subscribe ? create_status_picture(linphone_friend_get_status(lf)) : NULL,
+                               -1); 
                        escaped=g_markup_escape_text(uri,-1);
                        gtk_list_store_set(store,&iter,FRIEND_SIP_ADDRESS,escaped,-1);
                        g_free(escaped);
@@ -343,7 +409,7 @@ void linphone_gtk_show_friends(void){
        }
 }
 
-void linphone_gtk_add_contact(void){
+void linphone_gtk_add_contact(){
        GtkWidget *w=linphone_gtk_create_window("contact");
        int presence_enabled=linphone_gtk_get_ui_config_int("use_subscribe_notify",1);
        
diff --git a/pixmaps/contact_starred.png b/pixmaps/contact_starred.png
new file mode 100644 (file)
index 0000000..45b5d62
Binary files /dev/null and b/pixmaps/contact_starred.png differ
diff --git a/pixmaps/contact_unstarred.png b/pixmaps/contact_unstarred.png
new file mode 100644 (file)
index 0000000..ad04109
Binary files /dev/null and b/pixmaps/contact_unstarred.png differ