| 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 |
#include <stdlib.h> |
| 21 |
#include <string.h> |
| 22 |
#include <glib/gi18n.h> |
| 23 |
|
| 24 |
#include "applet-struct.h" |
| 25 |
#include "applet-notifications.h" |
| 26 |
#include "applet-widget.h" |
| 27 |
|
| 28 |
static GList *s_pUriList = NULL; |
| 29 |
|
| 30 |
|
| 31 |
void cd_weblet_free_uri_list (void) |
| 32 |
{ |
| 33 |
if (s_pUriList == NULL) |
| 34 |
return ; |
| 35 |
g_list_foreach (s_pUriList, (GFunc) g_free, NULL); |
| 36 |
g_list_free (s_pUriList); |
| 37 |
s_pUriList = NULL; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
//\___________ 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. |
| 42 |
CD_APPLET_ON_CLICK_BEGIN |
| 43 |
if (myDock) |
| 44 |
{ |
| 45 |
if (myData.dialog == NULL) |
| 46 |
weblet_build_and_show (myApplet); |
| 47 |
else |
| 48 |
gldi_dialog_unhide (myData.dialog); |
| 49 |
} |
| 50 |
CD_APPLET_ON_CLICK_END |
| 51 |
|
| 52 |
|
| 53 |
CD_APPLET_ON_MIDDLE_CLICK_BEGIN |
| 54 |
if (myDock && myData.dialog != NULL) |
| 55 |
{ |
| 56 |
gldi_dialog_hide (myData.dialog); |
| 57 |
} |
| 58 |
CD_APPLET_ON_MIDDLE_CLICK_END |
| 59 |
|
| 60 |
|
| 61 |
static void _cd_weblets_set_current_URI (GldiModuleInstance *myApplet, const gchar *cURI) |
| 62 |
{ |
| 63 |
g_return_if_fail (cURI != NULL); |
| 64 |
|
| 65 |
// on se souvient de la derniere URL chargee. |
| 66 |
g_free (myConfig.cURI_to_load); |
| 67 |
myConfig.cURI_to_load = g_strdup (cURI); |
| 68 |
cairo_dock_update_conf_file (CD_APPLET_MY_CONF_FILE, |
| 69 |
G_TYPE_STRING, |
| 70 |
"Configuration", |
| 71 |
"weblet URI", |
| 72 |
myConfig.cURI_to_load, |
| 73 |
G_TYPE_INVALID); |
| 74 |
|
| 75 |
// on rafraichit le tout ! |
| 76 |
gldi_task_change_frequency_and_relaunch (myData.pRefreshTimer, myConfig.iReloadTimeout); |
| 77 |
} |
| 78 |
|
| 79 |
static void _cd_weblets_open_URI (GtkMenuItem *menu_item, gpointer *data) |
| 80 |
{ |
| 81 |
GldiModuleInstance *myApplet = data[0]; |
| 82 |
gint index_URI = GPOINTER_TO_INT(data[1]); |
| 83 |
cd_message( "weblets: opening predefined URI %d (%s).", index_URI, myConfig.cListURI[index_URI] ); |
| 84 |
|
| 85 |
_cd_weblets_set_current_URI (myApplet, myConfig.cListURI[index_URI]); |
| 86 |
|
| 87 |
cd_weblet_free_uri_list (); |
| 88 |
} |
| 89 |
|
| 90 |
static void _cd_weblets_reload_webpage (GtkMenuItem *menu_item, GldiModuleInstance *myApplet) |
| 91 |
{ |
| 92 |
// on rafraichit le tout ! |
| 93 |
gldi_task_change_frequency_and_relaunch (myData.pRefreshTimer, myConfig.iReloadTimeout); |
| 94 |
} |
| 95 |
|
| 96 |
//\___________ 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. |
| 97 |
CD_APPLET_ON_BUILD_MENU_BEGIN |
| 98 |
gint i = 0; |
| 99 |
CD_APPLET_ADD_IN_MENU_WITH_STOCK ("Reload webpage", GLDI_ICON_NAME_REFRESH, _cd_weblets_reload_webpage, CD_APPLET_MY_MENU); |
| 100 |
|
| 101 |
if( myConfig.cListURI != NULL ) |
| 102 |
{ |
| 103 |
cd_weblet_free_uri_list (); |
| 104 |
gpointer *data; |
| 105 |
while (myConfig.cListURI[i] != NULL) |
| 106 |
{ |
| 107 |
data = g_new (gpointer, 2); |
| 108 |
data[0] = myApplet; |
| 109 |
data[1] = GINT_TO_POINTER (i); |
| 110 |
CD_APPLET_ADD_IN_MENU_WITH_DATA (myConfig.cListURI[i], _cd_weblets_open_URI, CD_APPLET_MY_MENU, data); |
| 111 |
s_pUriList = g_list_prepend (s_pUriList, data); |
| 112 |
i++; |
| 113 |
} |
| 114 |
} |
| 115 |
CD_APPLET_ON_BUILD_MENU_END |
| 116 |
|
| 117 |
|
| 118 |
CD_APPLET_ON_DROP_DATA_BEGIN |
| 119 |
_cd_weblets_set_current_URI (myApplet, CD_APPLET_RECEIVED_DATA); |
| 120 |
CD_APPLET_ON_DROP_DATA_END |