~ubuntu-branches/ubuntu/quantal/linphone/quantal

« back to all changes in this revision

Viewing changes to gnome/applet.c

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2004-06-30 13:58:16 UTC
  • Revision ID: james.westby@ubuntu.com-20040630135816-wwx75gdlodkqbabb
Tags: upstream-0.12.2
ImportĀ upstreamĀ versionĀ 0.12.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          applet.c  -  Applet code for linphone's gnome 
 
3
                                                                                  interface
 
4
                             -------------------
 
5
    begin                : Sat Dec 14 2002
 
6
    copyright            : (C) 2001 by Simon Morlat
 
7
    email                : simon.morlat@linphone.org
 
8
 ***************************************************************************/
 
9
 
 
10
/***************************************************************************
 
11
 *                                                                         *
 
12
 *   This program is free software; you can redistribute it and/or modify  *
 
13
 *   it under the terms of the GNU General Public License as published by  *
 
14
 *   the Free Software Foundation; either version 2 of the License, or     *
 
15
 *   (at your option) any later version.                                   *
 
16
 *                                                                         *
 
17
 ***************************************************************************/
 
18
 
 
19
 
 
20
#include "linphone.h"
 
21
#include <panel-applet.h>
 
22
 
 
23
#define get_uiobj()     (uiobj)
 
24
 
 
25
LinphoneCore core;
 
26
LinphoneGnomeUI ui;
 
27
static int show=0;
 
28
static int firstime=1;
 
29
static gulong signal_ref;
 
30
static GtkWidget *applet_button=NULL;
 
31
static GdkPixbuf *original_icon=NULL;
 
32
static GtkWidget *icon=NULL;
 
33
 
 
34
void draw_icon(GtkWidget *button, int size)
 
35
{
 
36
        GdkPixbuf *resized;
 
37
        if (original_icon==NULL){
 
38
                original_icon=gdk_pixbuf_new_from_file(PACKAGE_DATA_DIR "/pixmaps/linphone/linphone2.xpm",
 
39
                                                                                                NULL);
 
40
                g_return_if_fail( original_icon!=NULL);
 
41
        }
 
42
        if (icon!=NULL){
 
43
                gtk_container_remove(GTK_CONTAINER(button),icon);
 
44
                gtk_widget_destroy(icon);
 
45
        }
 
46
        resized=gdk_pixbuf_scale_simple(original_icon,size,size,GDK_INTERP_BILINEAR);
 
47
        g_return_if_fail(resized!=NULL);
 
48
        icon=gtk_image_new_from_pixbuf(resized);
 
49
        g_return_if_fail(icon!=NULL);
 
50
        gdk_pixbuf_unref(resized);
 
51
        gtk_container_add(GTK_CONTAINER(button),icon);
 
52
        gtk_widget_show(icon);
 
53
}
 
54
 
 
55
void linphone_applet_about_cb(gpointer p)
 
56
{
 
57
        GtkWidget *about2;
 
58
        about2 = create_about2 ();
 
59
        gtk_widget_show (about2);
 
60
}
 
61
 
 
62
 
 
63
 
 
64
static void applet_change_pixel_size(GtkWidget *applet, int size)
 
65
{
 
66
        g_return_if_fail(applet_button!=NULL);
 
67
        draw_icon(applet_button,size);
 
68
}
 
69
 
 
70
static void applet_destroy_cb(GtkWidget *widget, gpointer data)
 
71
{
 
72
        if (get_uiobj()->main_window.window!=NULL){
 
73
                gtk_widget_destroy(get_uiobj()->main_window.window);
 
74
        }
 
75
        linphone_gnome_uninit(get_uiobj());
 
76
}
 
77
 
 
78
static gboolean
 
79
gui_destroy_cb (GtkWidget *widget, gpointer data)
 
80
{
 
81
        linphone_gnome_ui_uninit(get_uiobj());
 
82
        show=0;
 
83
        return FALSE;
 
84
}
 
85
 
 
86
static gboolean button_press_cb(GtkWidget *applet, GdkEventButton* event, gpointer data)
 
87
{
 
88
        if (event->button!=1) return FALSE;
 
89
        if (show){
 
90
                g_signal_handlers_disconnect_by_func(G_OBJECT(get_uiobj()->main_window.window),
 
91
                                                G_CALLBACK(gui_destroy_cb),NULL);
 
92
                linphone_gnome_ui_hide(get_uiobj());
 
93
                
 
94
                show=0;
 
95
        }else {
 
96
                linphone_gnome_ui_show(get_uiobj());
 
97
                signal_ref=g_signal_connect(G_OBJECT(get_uiobj()->main_window.window),
 
98
                                                "destroy",
 
99
                                                G_CALLBACK(gui_destroy_cb),NULL);
 
100
                show=1;
 
101
        }
 
102
        return FALSE;
 
103
}
 
104
 
 
105
const BonoboUIVerb linphone_applet_menu_verbs [] = {
 
106
        BONOBO_UI_UNSAFE_VERB ("About",    linphone_applet_about_cb),
 
107
        BONOBO_UI_VERB_END
 
108
};
 
109
 
 
110
static gboolean
 
111
linphone_applet_fill (PanelApplet *applet)
 
112
{
 
113
        gint size=panel_applet_get_size(applet);
 
114
        GtkWidget *frame;
 
115
        
 
116
        
 
117
        applet_button=gtk_frame_new(NULL);
 
118
        gtk_container_add(GTK_CONTAINER(applet),applet_button);
 
119
        gtk_widget_show(applet_button);
 
120
 
 
121
        draw_icon(applet_button,size);
 
122
        
 
123
        g_signal_connect(G_OBJECT(applet),"button-press-event",G_CALLBACK(button_press_cb),NULL);
 
124
        
 
125
 
 
126
        g_signal_connect(G_OBJECT(applet),"change_size",
 
127
                                G_CALLBACK(applet_change_pixel_size),
 
128
                                NULL);
 
129
 
 
130
                
 
131
        g_signal_connect (G_OBJECT (applet), "destroy",
 
132
                          G_CALLBACK (applet_destroy_cb), NULL);
 
133
                                
 
134
        //sizehint = panel_applet_get_size (PANEL_APPLET (applet));
 
135
        panel_applet_setup_menu_from_file (applet,
 
136
                                           NULL,
 
137
                                           "GNOME_LinphoneApplet.xml",
 
138
                                           NULL,
 
139
                                           linphone_applet_menu_verbs,
 
140
                                           NULL);
 
141
        
 
142
        /* tracing for osip */
 
143
        TRACE_INITIALIZE(5,stdout);
 
144
        
 
145
        linphone_gnome_init(&ui,&core);
 
146
        gtk_widget_show_all (GTK_WIDGET (applet));
 
147
          
 
148
        return TRUE;
 
149
}
 
150
 
 
151
 
 
152
static gboolean
 
153
linphone_applet_factory (PanelApplet *applet,
 
154
                            const gchar *iid,
 
155
                            gpointer     data)
 
156
{
 
157
        gboolean retval;
 
158
        static int instances=0;
 
159
        GtkWidget *dialog;
 
160
        if (!strcmp (iid, "OAFIID:GNOME_LinphoneApplet")){
 
161
                if (instances>0){
 
162
                        dialog = gtk_message_dialog_new (GTK_WINDOW(applet),
 
163
                                  GTK_DIALOG_DESTROY_WITH_PARENT,
 
164
                                  GTK_MESSAGE_WARNING,
 
165
                                  GTK_BUTTONS_CLOSE,
 
166
                                  (const gchar*) _("Cannot run multiples instances of the linphone applet."));
 
167
                        /* Destroy the dialog when the user responds to it (e.g. clicks a button) */
 
168
                        g_signal_connect_swapped (G_OBJECT (dialog), "response",
 
169
                           G_CALLBACK (gtk_widget_destroy),
 
170
                           G_OBJECT (dialog));
 
171
                        gtk_widget_show(GTK_WIDGET(dialog));
 
172
                        return FALSE;
 
173
                }
 
174
                retval = linphone_applet_fill (applet); 
 
175
    }
 
176
        return retval;
 
177
}
 
178
 
 
179
#define GNOMELOCALEDIR PACKAGE_LOCALE_DIR
 
180
 
 
181
PANEL_APPLET_BONOBO_FACTORY ("OAFIID:GNOME_LinphoneApplet_Factory",
 
182
                             PANEL_TYPE_APPLET,
 
183
                             "linphone_applet",
 
184
                             "0",
 
185
                             linphone_applet_factory,
 
186
                             NULL)
 
187
 
 
188