~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to weblets/src/applet-widget.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

Show diffs side-by-side

added added

removed removed

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