~cairo-dock-team/cairo-dock-plug-ins/plug-ins

« back to all changes in this revision

Viewing changes to RSSreader/src/applet-notifications.c

  • Committer: Matthieu Baerts
  • Date: 2014-10-19 00:26:10 UTC
  • Revision ID: matttbe@gmail.com-20141019002610-ulf26s9b4c4rw10r
We just switched from BZR to Git.
Follow us on Github: https://github.com/Cairo-Dock

Note: we will only use Github to manage our source code and all pull requests.
Please continue to report your bugs/ideas/messages on our forum or Launchpad! 

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
 
//\________________ Add your name in the copyright file (and / or modify your name here)
21
 
 
22
 
#include <stdlib.h>
23
 
#include <string.h>
24
 
 
25
 
#include "applet-struct.h"
26
 
#include "applet-draw.h"
27
 
#include "applet-rss.h"
28
 
#include "applet-notifications.h"
29
 
 
30
 
 
31
 
static void _new_url_to_conf (GldiModuleInstance *myApplet, const gchar *cNewURL)
32
 
{
33
 
        if (g_strstr_len (cNewURL, -1, "http") != NULL)  // On verifie que l'element glisser/copier commence bien par http
34
 
        {
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,
40
 
                        G_TYPE_STRING,
41
 
                        "Configuration",
42
 
                        "url_rss_feed",
43
 
                        myConfig.cUrl,
44
 
                        G_TYPE_INVALID);  // On l'ecrit dans le fichier de config
45
 
                
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.
48
 
                
49
 
                g_free (myData.PrevFirstTitle);
50
 
                myData.PrevFirstTitle = NULL;
51
 
                cd_rssreader_free_item_list (myApplet);
52
 
                
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..."));
57
 
                myData.bInit = FALSE;
58
 
                myData.bError = FALSE;
59
 
                
60
 
                if (myDesklet)
61
 
                        cd_applet_update_my_icon (myApplet);
62
 
                
63
 
                cd_rssreader_launch_task (myApplet); // On lance l'upload pour mettre a jour notre applet
64
 
        }
65
 
        else
66
 
        {
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."),
70
 
                        myIcon,
71
 
                        myContainer,
72
 
                        3000, // Suffisant 
73
 
                        MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);                
74
 
        }
75
 
}
76
 
 
77
 
static void _paste_new_url_to_conf (GtkMenuItem *menu_item, GldiModuleInstance *myApplet)
78
 
{
79
 
        CD_APPLET_ENTER;
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);
84
 
        CD_APPLET_LEAVE ();
85
 
}
86
 
 
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
91
 
 
92
 
 
93
 
static inline void _update_feeds (GldiModuleInstance *myApplet)
94
 
{
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);
99
 
}
100
 
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
101
 
        _update_feeds (myApplet);
102
 
CD_APPLET_ON_MIDDLE_CLICK_END
103
 
 
104
 
 
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
109
 
 
110
 
 
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)
113
 
{
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);
118
 
}
119
 
static void _refresh (GtkMenuItem *menu_item, GldiModuleInstance *myApplet)
120
 
{
121
 
        _update_feeds (myApplet);
122
 
}
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);  
125
 
        
126
 
        if (myConfig.cUrl != NULL) // On ajoute une entrée dans le menu SI il y a une url seulement
127
 
        {
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);
131
 
                g_free (cLabel);
132
 
        }
133
 
CD_APPLET_ON_BUILD_MENU_END
134
 
 
135
 
 
136
 
static gboolean _redraw_desklet_idle (GldiModuleInstance *myApplet)
137
 
{
138
 
        CD_APPLET_ENTER;
139
 
        cd_applet_update_my_icon (myApplet);
140
 
        myData.iSidRedrawIdle = 0;
141
 
        CD_APPLET_LEAVE (FALSE);
142
 
        //return FALSE;
143
 
}
144
 
CD_APPLET_ON_SCROLL_BEGIN
145
 
        if (! myDesklet)
146
 
                CD_APPLET_LEAVE (GLDI_NOTIFICATION_LET_PASS);
147
 
        
148
 
        myData.iFirstDisplayedItem += (CD_APPLET_SCROLL_UP ? -1 : 1);
149
 
        if (myData.iFirstDisplayedItem < 0)  // on a scrolle trop haut.
150
 
        {
151
 
                myData.iFirstDisplayedItem = 0;
152
 
                CD_APPLET_LEAVE (GLDI_NOTIFICATION_LET_PASS);
153
 
        }
154
 
        else
155
 
        {
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.
158
 
                {
159
 
                        myData.iFirstDisplayedItem = n - 1;
160
 
                        CD_APPLET_LEAVE (GLDI_NOTIFICATION_LET_PASS);
161
 
                }
162
 
        }
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