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

« back to all changes in this revision

Viewing changes to weblets/src/applet-notifications.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
/******************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program, 
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Christophe Chapuis (for any bug report, please mail me to fabounet@users.berlios.de)
 
26
 
 
27
******************************************************************************/
 
28
 
 
29
#include <stdlib.h>
 
30
#include <string.h>
 
31
#include <glib/gi18n.h>
 
32
 
 
33
#include "applet-struct.h"
 
34
#include "applet-notifications.h"
 
35
#include "applet-widget.h"
 
36
 
 
37
static GList *s_pUriList = NULL;
 
38
 
 
39
 
 
40
void cd_weblet_free_uri_list (void)
 
41
{
 
42
        if (s_pUriList == NULL)
 
43
                return ;
 
44
        g_list_foreach (s_pUriList, (GFunc) g_free, NULL);
 
45
        g_list_free (s_pUriList);
 
46
        s_pUriList = NULL;
 
47
}
 
48
 
 
49
 
 
50
//\___________ Define here the action to be taken when the user left-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons.
 
51
CD_APPLET_ON_CLICK_BEGIN
 
52
        if (myDock)
 
53
        {
 
54
                if (myData.dialog == NULL)
 
55
                        weblet_build_and_show (myApplet);
 
56
                else
 
57
                        cairo_dock_unhide_dialog (myData.dialog);
 
58
        }
 
59
CD_APPLET_ON_CLICK_END
 
60
 
 
61
 
 
62
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
 
63
        if (myDock && myData.dialog != NULL)
 
64
        {
 
65
                cairo_dock_hide_dialog (myData.dialog);
 
66
        }
 
67
CD_APPLET_ON_MIDDLE_CLICK_END
 
68
 
 
69
 
 
70
static void _cd_weblets_set_current_URI (CairoDockModuleInstance *myApplet, const gchar *cURI)
 
71
{
 
72
        g_return_if_fail (cURI != NULL);
 
73
        
 
74
        // on se souvient de la derniere URL chargee.
 
75
        g_free (myConfig.cURI_to_load);
 
76
        myConfig.cURI_to_load = g_strdup (cURI);
 
77
        cairo_dock_update_conf_file (CD_APPLET_MY_CONF_FILE,
 
78
                G_TYPE_STRING,
 
79
                "Configuration",
 
80
                "weblet URI",
 
81
                myConfig.cURI_to_load,
 
82
                G_TYPE_INVALID);
 
83
 
 
84
        // on rafraichit le tout !
 
85
        cairo_dock_relaunch_task_immediately (myData.pRefreshTimer, myConfig.iReloadTimeout);
 
86
}
 
87
 
 
88
static void _cd_weblets_open_URI (GtkMenuItem *menu_item, gpointer *data)
 
89
{
 
90
        CairoDockModuleInstance *myApplet = data[0];
 
91
        gint index_URI = GPOINTER_TO_INT(data[1]);
 
92
        cd_message( "weblets: opening predefined URI %d (%s).", index_URI, myConfig.cListURI[index_URI] );
 
93
        
 
94
        _cd_weblets_set_current_URI (myApplet, myConfig.cListURI[index_URI]);
 
95
        
 
96
        cd_weblet_free_uri_list ();
 
97
}
 
98
 
 
99
static void _cd_weblets_reload_webpage (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
 
100
{
 
101
        // on rafraichit le tout !
 
102
        cairo_dock_relaunch_task_immediately (myData.pRefreshTimer, myConfig.iReloadTimeout);
 
103
}
 
104
 
 
105
//\___________ Define here the entries you want to add to the menu when the user right-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons. The menu where you can add your entries is available throught the macro CD_APPLET_MY_MENU; you can add sub-menu to it if you want.
 
106
CD_APPLET_ON_BUILD_MENU_BEGIN
 
107
        gint i = 0;
 
108
        CD_APPLET_ADD_IN_MENU("Reload webpage", _cd_weblets_reload_webpage, CD_APPLET_MY_MENU);
 
109
        GtkWidget *pSubMenu = CD_APPLET_CREATE_MY_SUB_MENU ();
 
110
        if( myConfig.cListURI != NULL )
 
111
        {
 
112
                cd_weblet_free_uri_list ();
 
113
                gpointer *data;
 
114
                while (myConfig.cListURI[i] != NULL)
 
115
                {
 
116
                        data = g_new (gpointer, 2);
 
117
                        data[0] = myApplet;
 
118
                        data[1] = GINT_TO_POINTER (i);
 
119
                        CD_APPLET_ADD_IN_MENU_WITH_DATA (myConfig.cListURI[i], _cd_weblets_open_URI, pSubMenu, data);
 
120
                        s_pUriList = g_list_prepend (s_pUriList, data);
 
121
                        i++;
 
122
                }
 
123
        }
 
124
        CD_APPLET_ADD_ABOUT_IN_MENU (pSubMenu);
 
125
CD_APPLET_ON_BUILD_MENU_END
 
126
 
 
127
 
 
128
CD_APPLET_ON_DROP_DATA_BEGIN
 
129
        _cd_weblets_set_current_URI (myApplet, CD_APPLET_RECEIVED_DATA);
 
130
CD_APPLET_ON_DROP_DATA_END