~ubuntu-branches/ubuntu/utopic/awn-extras-applets/utopic

« back to all changes in this revision

Viewing changes to src/webapplet/applet.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-01-13 21:50:33 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100113215033-kd9otcdjrajmiag0
Tags: 0.3.9~bzr1944-0ubuntu1
* New upstream snapshot.
 - Catch error in weather applet (LP: #359668)
* debian/patches: Refresh.
* debian/*.install: 
 - Update to new location and new applets.
 - Disable dialect applet until python-xklavier is in the archive.
 - Disable MiMenu and Pandora applets, there are unmaintained and not stable.
* debian/awn-applets-c-core: Dropped, not needed.
* debian/control:
 - Update description with new applets.
 - Remove libawn-extras and python-awnlib, all merged in python-awn-extras.
 - Replace awn-manager by awn-settings.
 - Drop build-depends on libgnome-desktop-dev, python*-dev, python2.5,
   awn-manager, libglade2-dev and libgnomeui-dev.
 - Add build-depends on libdesktop-agnostic-bin and vala-awn.
 - Bump build-depends of libawn-dev (>= 0.3.9~bzr1890), valac (>= 0.7.7) and
   debhelper (>= 7.0.50~).
 - Bump Standards-Version to 3.8.3 (no change needed).
 - Demote gconf-editor to Suggest, it's only needed for very advanced
   settings.
 - Update Recommends for python applets with new applets.
 - Suggest python-gconf for notification-area and alacarte for YAMA.
 - Add a debug package for C applets.
* debian/libawn-extras*: Removed, libawn-extras was removed upstream.
* debian/python-awnlib*: Merged with python-awn-extras.
* debian/rules:
 - Rewrite to use overrides.
* debian/copyright:
 - Update copyright and licenses.
* debian/README.source: Added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2008 Rodney Cryderman <rcryderman@gmail.com>
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2 of the License, or
7
 
 * (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
17
 
 *
18
 
 */
19
 
 
20
 
#ifdef HAVE_CONFIG_H
21
 
#include <config.h>
22
 
#endif
23
 
 
24
 
#include <libawn/awn-cairo-utils.h>
25
 
#include <libawn/awn-applet-simple.h>
26
 
#include <libawn/awn-applet-dialog.h>
27
 
#include <gtk/gtk.h>
28
 
#include <glib.h>
29
 
#include <glib/gi18n.h>
30
 
 
31
 
#include <libawn-extras/awn-extras.h>
32
 
 
33
 
#include "engine_html.h"
34
 
#include "applet.h"
35
 
#include "configuration.h"
36
 
 
37
 
 
38
 
static void
39
 
_send_dialog_response (GtkEntry *entry, GtkDialog *dialog)
40
 
{
41
 
  gtk_dialog_response (dialog, GTK_RESPONSE_OK);
42
 
}
43
 
 
44
 
static gboolean
45
 
_show_location_dialog (GtkMenuItem *menuitem,WebApplet *webapplet)
46
 
{
47
 
  static gboolean done_once = FALSE;
48
 
  static GtkWidget *location_dialog;
49
 
  static GtkWidget *entry;
50
 
  gint response;
51
 
  if (!done_once)
52
 
  {
53
 
    location_dialog = gtk_dialog_new_with_buttons (_("Open Location"),
54
 
                                                     GTK_WINDOW (webapplet->mainwindow),
55
 
                                                     GTK_DIALOG_DESTROY_WITH_PARENT,
56
 
                                                     GTK_STOCK_CANCEL,
57
 
                                                     GTK_RESPONSE_CANCEL,
58
 
                                                     GTK_STOCK_OPEN,
59
 
                                                     GTK_RESPONSE_OK,
60
 
                                                     NULL);
61
 
    GtkWidget *hbox = gtk_hbox_new (FALSE, 5);
62
 
    gtk_container_add (GTK_CONTAINER (hbox), gtk_label_new (_("URI:")));
63
 
    entry = gtk_entry_new ();
64
 
    g_signal_connect (G_OBJECT (entry), "activate",
65
 
                      G_CALLBACK (_send_dialog_response),
66
 
                      location_dialog);
67
 
    gtk_container_add (GTK_CONTAINER (hbox), entry);
68
 
    gtk_widget_show_all (hbox);
69
 
    gtk_container_add (GTK_CONTAINER (GTK_DIALOG (location_dialog)->vbox),
70
 
                       hbox);
71
 
    done_once = TRUE;
72
 
  }
73
 
  response = gtk_dialog_run (GTK_DIALOG (location_dialog));
74
 
  gtk_widget_hide (location_dialog);
75
 
  if (response == GTK_RESPONSE_OK)
76
 
  {
77
 
    html_web_view_open (webapplet->viewer,
78
 
                        gtk_entry_get_text (GTK_ENTRY (entry)));
79
 
  }
80
 
  gchar * title = g_strdup_printf("%30s",gtk_entry_get_text (GTK_ENTRY (entry)));  //FIXME put the URL or page title in here...
81
 
  awn_applet_simple_set_title(AWN_APPLET_SIMPLE(webapplet->applet),title);
82
 
  g_free(title);
83
 
  
84
 
  return TRUE;
85
 
}
86
 
 
87
 
static void
88
 
awn_html_dialog_new (WebApplet *webapplet)
89
 
{
90
 
  /* create viewer */
91
 
  webapplet->mainwindow = awn_applet_dialog_new (webapplet->applet);
92
 
  webapplet->box = gtk_vbox_new (FALSE, 1);
93
 
  gtk_widget_set_size_request (GTK_WIDGET (webapplet->box), config_get_width(webapplet),
94
 
                               config_get_height(webapplet) );
95
 
  webapplet->viewer = html_web_view_new ();
96
 
  gtk_container_add (GTK_CONTAINER (webapplet->box),webapplet->viewer);
97
 
  gtk_container_add (GTK_CONTAINER (webapplet->mainwindow), webapplet->box);
98
 
  html_web_view_open (webapplet->viewer, config_get_uri(webapplet));
99
 
}
100
 
 
101
 
 
102
 
static gboolean
103
 
_button_clicked_event (GtkWidget      *widget,
104
 
                       GdkEventButton *event,
105
 
                       WebApplet      *webapplet)
106
 
{
107
 
  static GtkWidget *menu=NULL;
108
 
  GdkEventButton *event_button;
109
 
  event_button = (GdkEventButton *)event;
110
 
  if (event->button == 1)
111
 
  {
112
 
    if (GTK_WIDGET_VISIBLE (webapplet->mainwindow))
113
 
    {
114
 
      gtk_widget_hide (webapplet->mainwindow);
115
 
    }
116
 
    else
117
 
    {
118
 
      gtk_widget_show_all (webapplet->mainwindow);
119
 
    }
120
 
  }
121
 
  else if (event->button == 3)
122
 
  {
123
 
    if (!menu)
124
 
    {
125
 
      GtkWidget *item;
126
 
      menu = awn_applet_create_default_menu (webapplet->applet);
127
 
      gtk_menu_set_screen (GTK_MENU (menu), NULL);
128
 
      if (config_get_enable_location_dialog(webapplet))
129
 
      {        
130
 
        item = gtk_image_menu_item_new_with_label (_("Open Location"));
131
 
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
132
 
                                       gtk_image_new_from_stock (GTK_STOCK_OPEN,
133
 
                                                          GTK_ICON_SIZE_MENU));
134
 
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
135
 
        gtk_widget_show_all (item);        
136
 
        g_signal_connect (G_OBJECT (item), "activate",
137
 
                          G_CALLBACK (_show_location_dialog), webapplet);                  
138
 
      }           
139
 
      item = shared_menuitem_create_applet_prefs(webapplet->uid,APPLET_NAME,APPLET_NAME);
140
 
      if (item) //generic preferences is enabled
141
 
      {
142
 
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);          
143
 
      }        
144
 
      item = shared_menuitem_about_applet_simple("2008 Rodney Cryderman <rcryderman@gmail.com>\n2008 Mark Lee <avant-wn@lazymalevolence.com>\n",
145
 
                                                 AWN_APPLET_LICENSE_GPLV2,
146
 
                                                 "WebApplet",
147
 
                                                 NULL);
148
 
      gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);                
149
 
    }
150
 
    gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
151
 
                    event_button->button, event_button->time);
152
 
  }
153
 
  return TRUE;
154
 
}
155
 
 
156
 
static gboolean
157
 
_focus_out_event(GtkWidget *widget, GdkEventButton *event, void * null)
158
 
{
159
 
//  gtk_widget_hide(webapplet->mainwindow);
160
 
  return TRUE;
161
 
}
162
 
 
163
 
 
164
 
static void
165
 
_bloody_thing_has_style (GtkWidget *widget,WebApplet *webapplet)
166
 
{
167
 
 
168
 
  gchar * title = g_strdup_printf("%30s",config_get_uri(webapplet));  //FIXME put the URL or page title in here...
169
 
  awn_applet_simple_set_title(AWN_APPLET_SIMPLE(webapplet->applet),title);
170
 
  g_free(title);
171
 
  g_signal_connect (G_OBJECT (webapplet->applet), "button-press-event",
172
 
                    G_CALLBACK (_button_clicked_event), webapplet);
173
 
  g_signal_connect (G_OBJECT (webapplet->mainwindow), "focus-out-event",
174
 
                    G_CALLBACK (_focus_out_event), webapplet);
175
 
}
176
 
 
177
 
AwnApplet *
178
 
awn_applet_factory_initp (gchar *uid, gint orient, gint height)
179
 
{
180
 
  g_on_error_stack_trace (NULL);
181
 
  html_init ();
182
 
  WebApplet *webapplet = g_malloc (sizeof (WebApplet));
183
 
  webapplet->uid=g_strdup(uid);
184
 
  init_config (webapplet, uid);
185
 
  webapplet->applet = AWN_APPLET (awn_applet_simple_new (uid, orient, height));
186
 
  gtk_widget_set_size_request (GTK_WIDGET (webapplet->applet), height, -1);
187
 
 
188
 
  webapplet->applet_icon_name = g_strdup ("apple-green");  
189
 
 
190
 
  awn_applet_simple_set_awn_icon(AWN_APPLET_SIMPLE(webapplet->applet),
191
 
                                    APPLET_NAME,
192
 
                                    webapplet->applet_icon_name)  ;
193
 
  
194
 
  gtk_widget_show_all (GTK_WIDGET (webapplet->applet));
195
 
  awn_html_dialog_new (webapplet);
196
 
  gtk_window_set_focus_on_map (GTK_WINDOW (webapplet->mainwindow), TRUE);
197
 
  g_signal_connect_after (G_OBJECT (webapplet->applet), "realize",
198
 
                          G_CALLBACK (_bloody_thing_has_style), webapplet);
199
 
  return webapplet->applet;
200
 
}
201
 
/* vim: set et ts=2 sts=2 sw=2 : */