Debian Codegraph @

weblets/src/applet-widget.c

raw
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
2 /*
3 ** Login : <[email protected]>
4 ** Started on Thu Apr 03 18:21:35 2008 CHAPUIS Christophe
5 ** $Id$
6 **
7 ** Author(s):
8 ** - Christophe CHAPUIS <[email protected]>
9 **
10 ** Copyright (C) 2008 CHAPUIS Christophe
11 ** This program is free software; you can redistribute it and/or modify
12 ** it under the terms of the GNU General Public License as published by
13 ** the Free Software Foundation; either version 3 of the License, or
14 ** (at your option) any later version.
15 **
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ** GNU General Public License for more details.
20 **
21 ** You should have received a copy of the GNU General Public License
22 ** along with this program; if not, write to the Free Software
23 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26 #include "applet-struct.h"
27 #include "applet-widget.h"
28
29 #include <gtk/gtk.h>
30
31
32
33 void _cd_weblets_set_crop_position (GldiModuleInstance *myApplet)
34 {
35 GtkAdjustment *pGtkAdjustmentH = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW (myData.pGtkMozEmbed));
36 gtk_adjustment_set_value(pGtkAdjustmentH, 0);
37 gtk_adjustment_set_value(pGtkAdjustmentH, myConfig.iPosScrollX);
38 GtkAdjustment *pGtkAdjustmentV = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW (myData.pGtkMozEmbed));
39 gtk_adjustment_set_value(pGtkAdjustmentV, 0);
40 gtk_adjustment_set_value(pGtkAdjustmentV, myConfig.iPosScrollY);
41 }
42
43 // hide/show the scrollbars
44 static void show_hide_scrollbars(GldiModuleInstance *myApplet)
45 {
46 // First, set the position
47 _cd_weblets_set_crop_position (myApplet);
48
49 // Then, hide or show the scrollbars
50 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (myData.pGtkMozEmbed), myConfig.bShowScrollbars?GTK_POLICY_AUTOMATIC:GTK_POLICY_NEVER, myConfig.bShowScrollbars?GTK_POLICY_AUTOMATIC:GTK_POLICY_NEVER);
51 }
52
53
54 CairoDialog *cd_weblets_build_dialog(GldiModuleInstance *myApplet)
55 {
56 CairoDialogAttr attr;
57 memset (&attr, 0, sizeof (CairoDialogAttr));
58 attr.cText = D_ ("Weblets");
59 attr.pInteractiveWidget = myData.pGtkMozEmbed;
60 attr.pIcon = myIcon;
61 attr.pContainer = myContainer;
62 return gldi_dialog_new (&attr);
63 }
64
65 /* Will be called when loading of the page is finished*/
66 void load_finished_cb(WebKitWebView *pWebKitView, WebKitWebFrame* widget
67 , GldiModuleInstance *myApplet)
68 {
69 cd_debug ("weblets : (re)load finished\n");
70 // update scrollbars status
71 show_hide_scrollbars(myApplet);
72 }
73
74 /* Build the embedded widget */
75 void weblet_build_and_show(GldiModuleInstance *myApplet)
76 {
77 myData.pGtkMozEmbed = gtk_scrolled_window_new (NULL, NULL);
78 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (myData.pGtkMozEmbed), myConfig.bShowScrollbars?GTK_POLICY_AUTOMATIC:GTK_POLICY_NEVER, myConfig.bShowScrollbars?GTK_POLICY_AUTOMATIC:GTK_POLICY_NEVER);
79
80 myData.pWebKitView = WEBKIT_WEB_VIEW (webkit_web_view_new ());
81 gtk_container_add (GTK_CONTAINER (myData.pGtkMozEmbed), GTK_WIDGET (myData.pWebKitView));
82 g_signal_connect(G_OBJECT(myData.pWebKitView),
83 "load_finished",
84 G_CALLBACK (load_finished_cb),
85 myApplet);
86 gtk_widget_show_all (myData.pGtkMozEmbed);
87
88 if (myDock)
89 {
90 g_object_set (GTK_WIDGET (myData.pWebKitView), "width-request", 600, "height-request", 400, NULL);
91 myData.dialog = cd_weblets_build_dialog(myApplet);
92 }
93 else
94 {
95 gldi_desklet_add_interactive_widget_with_margin (myDesklet, myData.pGtkMozEmbed, myConfig.iRightMargin);
96 CD_APPLET_SET_DESKLET_RENDERER (NULL);
97 }
98 }
99
100 gboolean cd_weblets_refresh_page (GldiModuleInstance *myApplet)
101 {
102 cd_message( "weblets: refreshing page.\n" );
103
104 // load the page
105 if(myData.pGtkMozEmbed)
106 {
107 cd_message( " >> weblets: refresh !\n" );
108 if (myConfig.cURI_to_load == NULL)
109 {
110 g_free (myConfig.cURI_to_load);
111 myConfig.cURI_to_load = g_strdup ("http://www.google.com");
112 }
113 else
114 {
115 if (g_strstr_len (myConfig.cURI_to_load, -1, "://") == NULL) // pas de protocole defini, on prend http par defaut.
116 {
117 gchar *tmp = myConfig.cURI_to_load;
118 myConfig.cURI_to_load = g_strconcat ("http://", (strncmp (myConfig.cURI_to_load, "www.", 4) ? "www." : ""), myConfig.cURI_to_load, NULL);
119 g_free (tmp);
120 }
121 }
122
123 webkit_web_view_open(WEBKIT_WEB_VIEW(myData.pWebKitView), myConfig.cURI_to_load?myConfig.cURI_to_load:"http://www.google.com");
124 }
125 /* available since rev. 30985, from fev. 2008 */
126 webkit_web_view_set_transparent(myData.pWebKitView, myConfig.bIsTransparent);
127
128 return TRUE;
129 }
130