2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
20
//\________________ Add your name in the copyright file (and / or modify your name here)
25
#include "applet-struct.h"
26
#include "applet-draw.h"
27
#include "applet-rss.h"
28
#include "applet-notifications.h"
31
static void _new_url_to_conf (GldiModuleInstance *myApplet, const gchar *cNewURL)
33
if (g_strstr_len (cNewURL, -1, "http") != NULL) // On verifie que l'element glisser/copier commence bien par http
35
cd_debug ("RSSreader-debug : This seems to be a valid URL -> Let's continue...");
36
// on definit la nouvelle URL en conf.
37
g_free (myConfig.cUrl);
38
myConfig.cUrl = g_strdup (cNewURL);
39
cairo_dock_update_conf_file (CD_APPLET_MY_CONF_FILE,
44
G_TYPE_INVALID); // On l'ecrit dans le fichier de config
46
// on remet a zero les items actuels.
47
CD_APPLET_SET_NAME_FOR_MY_ICON (NULL); // pour mettre a jour le titre par la meme occasion.
49
g_free (myData.PrevFirstTitle);
50
myData.PrevFirstTitle = NULL;
51
cd_rssreader_free_item_list (myApplet);
53
// on recupere le nouveau flux.
54
CDRssItem *pItem = g_new0 (CDRssItem, 1); // on commence au debut de la liste (c'est le titre).
55
myData.pItemList = g_list_prepend (myData.pItemList, pItem);
56
pItem->cTitle = g_strdup (D_("Retrieving data..."));
58
myData.bError = FALSE;
61
cd_applet_update_my_icon (myApplet);
63
cd_rssreader_launch_task (myApplet); // On lance l'upload pour mettre a jour notre applet
67
cd_debug ("RSSreader-debug : It doesn't seem to be a valid URL.");
68
gldi_dialogs_remove_on_icon (myIcon);
69
gldi_dialog_show_temporary_with_icon (D_("It doesn't seem to be a valid URL."),
73
MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
77
static void _paste_new_url_to_conf (GtkMenuItem *menu_item, GldiModuleInstance *myApplet)
80
GtkClipboard *pClipBoardSelection = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
81
gchar *cEntry = gtk_clipboard_wait_for_text (pClipBoardSelection);
82
cd_debug ("RSSreader-debug : Paste from clipboard -> \"%s\"", cEntry);
83
_new_url_to_conf (myApplet, cEntry);
87
//\___________ 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.
88
CD_APPLET_ON_CLICK_BEGIN
89
cd_rssreader_show_dialog (myApplet);
90
CD_APPLET_ON_CLICK_END
93
static inline void _update_feeds (GldiModuleInstance *myApplet)
95
myData.bUpdateIsManual = TRUE;
96
// on ne met pas de message d'attente pour conserver les items actuels, on prefere afficher un dialogue signalant ou pas une modification.
97
if (! gldi_task_is_running (myData.pTask)) // sinon on va bloquer jusqu'a ce que la tache courante se termine, pour la relancer aussitot, ce qui n'a aucun interet.
98
cd_rssreader_launch_task (myApplet);
100
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
101
_update_feeds (myApplet);
102
CD_APPLET_ON_MIDDLE_CLICK_END
105
CD_APPLET_ON_DROP_DATA_BEGIN
106
cd_debug ("RSSreader-debug : \"%s\" was dropped", CD_APPLET_RECEIVED_DATA);
107
_new_url_to_conf (myApplet, CD_APPLET_RECEIVED_DATA);
108
CD_APPLET_ON_DROP_DATA_END
111
//\___________ 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.
112
static void _start_browser (GtkMenuItem *menu_item, GldiModuleInstance *myApplet)
114
if (myConfig.cSpecificWebBrowser != NULL) // une commande specifique est fournie.
115
cairo_dock_launch_command_printf ("%s %s", NULL, myConfig.cSpecificWebBrowser, myConfig.cUrl);
116
else // sinon on utilise la commande par defaut.
117
cairo_dock_fm_launch_uri (myConfig.cUrl);
119
static void _refresh (GtkMenuItem *menu_item, GldiModuleInstance *myApplet)
121
_update_feeds (myApplet);
123
CD_APPLET_ON_BUILD_MENU_BEGIN
124
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Paste a new RSS Url (drag and drop)"), GLDI_ICON_NAME_PASTE, _paste_new_url_to_conf, CD_APPLET_MY_MENU);
126
if (myConfig.cUrl != NULL) // On ajoute une entrée dans le menu SI il y a une url seulement
128
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Open with your web browser"), GLDI_ICON_NAME_EXECUTE, _start_browser, CD_APPLET_MY_MENU);
129
gchar *cLabel = g_strdup_printf ("%s (%s)", D_("Refresh"), D_("middle-click"));
130
CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, GLDI_ICON_NAME_REFRESH, _refresh, CD_APPLET_MY_MENU);
133
CD_APPLET_ON_BUILD_MENU_END
136
static gboolean _redraw_desklet_idle (GldiModuleInstance *myApplet)
139
cd_applet_update_my_icon (myApplet);
140
myData.iSidRedrawIdle = 0;
141
CD_APPLET_LEAVE (FALSE);
144
CD_APPLET_ON_SCROLL_BEGIN
146
CD_APPLET_LEAVE (GLDI_NOTIFICATION_LET_PASS);
148
myData.iFirstDisplayedItem += (CD_APPLET_SCROLL_UP ? -1 : 1);
149
if (myData.iFirstDisplayedItem < 0) // on a scrolle trop haut.
151
myData.iFirstDisplayedItem = 0;
152
CD_APPLET_LEAVE (GLDI_NOTIFICATION_LET_PASS);
156
int n = g_list_length (myData.pItemList) - 1; // la 1ere ligne est le titre.
157
if (myData.iFirstDisplayedItem > n - 1) // on a scrolle trop bas.
159
myData.iFirstDisplayedItem = n - 1;
160
CD_APPLET_LEAVE (GLDI_NOTIFICATION_LET_PASS);
163
if (myData.iSidRedrawIdle == 0) // on planifie un redessin pour quand la boucle principale sera accessible, de facon a éviter de la surcharger en cas de scroll rapide.
164
myData.iSidRedrawIdle = g_idle_add ((GSourceFunc)_redraw_desklet_idle, myApplet);
165
CD_APPLET_ON_SCROLL_END