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

« back to all changes in this revision

Viewing changes to RSSreader/src/applet-init.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
 
 
24
 
#include "applet-config.h"
25
 
#include "applet-notifications.h"
26
 
#include "applet-struct.h"
27
 
#include "applet-rss.h"
28
 
#include "applet-draw.h"
29
 
#include "applet-init.h"
30
 
 
31
 
CD_APPLET_DEFINE_BEGIN (N_("RSSreader"),
32
 
        2, 0, 0,
33
 
        CAIRO_DOCK_CATEGORY_APPLET_INTERNET,
34
 
        N_("This applet is an RSS/Atom feed reader.\n"
35
 
        "You can instanciate it as many times as you want.\n"
36
 
        "USAGE:\n"
37
 
        " - Left-click : display the complete feed lines in a dialog.\n"
38
 
        " - Middle-click : refresh the feed.\n"
39
 
        " - Scroll on the desklet : make the feed lines scroll.\n"
40
 
        " - Drag and drop a valid URL on the icon to use it,\n"
41
 
        "    or copy it and use \"Paste a new RSS Url\" in the menu.\n"
42
 
        "    or edit the Configuration Panel."),
43
 
        "Yann Dulieu (Nochka85)")
44
 
        CD_APPLET_DEFINE_COMMON_APPLET_INTERFACE
45
 
        CD_APPLET_ALLOW_EMPTY_TITLE
46
 
CD_APPLET_DEFINE_END
47
 
 
48
 
 
49
 
//\___________ Here is where you initiate your applet. myConfig is already set at this point, and also myIcon, myContainer, myDock, myDesklet (and myDrawContext if you're in dock mode). The macro CD_APPLET_MY_CONF_FILE and CD_APPLET_MY_KEY_FILE can give you access to the applet's conf-file and its corresponding key-file (also available during reload). If you're in desklet mode, myDrawContext is still NULL, and myIcon's buffers has not been filled, because you may not need them then (idem when reloading).
50
 
CD_APPLET_INIT_BEGIN
51
 
        
52
 
        if (myDesklet)
53
 
        {
54
 
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");  // set a desklet renderer.
55
 
                CD_APPLET_ALLOW_NO_CLICKABLE_DESKLET;
56
 
        }
57
 
        else
58
 
        {
59
 
                CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE;  // en mode dock l'image de l'icone est statique.
60
 
        }
61
 
        
62
 
        // On met un message d'attente.
63
 
        CDRssItem *pItem = g_new0 (CDRssItem, 1);  // on commence au debut de la liste (c'est le titre).
64
 
        myData.pItemList = g_list_prepend (myData.pItemList, pItem);
65
 
        pItem->cTitle = g_strdup (D_("Retrieving data..."));
66
 
        
67
 
        // on lance la tache periodique.
68
 
        cd_rssreader_launch_task (myApplet);
69
 
        
70
 
        // en mode desklet on redessine l'icone avec le message d'attente.
71
 
        if (myDesklet)
72
 
        {
73
 
                cd_applet_update_my_icon (myApplet);
74
 
        }
75
 
        
76
 
        // on s'abonne aux evenements.
77
 
        CD_APPLET_REGISTER_FOR_CLICK_EVENT;
78
 
        CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
79
 
        CD_APPLET_REGISTER_FOR_DROP_DATA_EVENT;
80
 
        CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
81
 
        CD_APPLET_REGISTER_FOR_SCROLL_EVENT;
82
 
        
83
 
CD_APPLET_INIT_END
84
 
 
85
 
 
86
 
//\___________ Here is where you stop your applet. myConfig and myData are still valid, but will be reseted to 0 at the end of the function. In the end, your applet will go back to its original state, as if it had never been activated.
87
 
CD_APPLET_STOP_BEGIN
88
 
        
89
 
        CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
90
 
        CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT;
91
 
        CD_APPLET_UNREGISTER_FOR_DROP_DATA_EVENT;
92
 
        CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
93
 
        CD_APPLET_UNREGISTER_FOR_SCROLL_EVENT;
94
 
        if (myData.iSidRedrawIdle != 0)
95
 
                g_source_remove (myData.iSidRedrawIdle);
96
 
        
97
 
CD_APPLET_STOP_END
98
 
 
99
 
 
100
 
//\___________ The reload occurs in 2 occasions : when the user changes the applet's config, and when the user reload the cairo-dock's config or modify the desklet's size. The macro CD_APPLET_MY_CONFIG_CHANGED can tell you this. myConfig has already been reloaded at this point if you're in the first case, myData is untouched. You also have the macro CD_APPLET_MY_CONTAINER_TYPE_CHANGED that can tell you if you switched from dock/desklet to desklet/dock mode.
101
 
CD_APPLET_RELOAD_BEGIN
102
 
        if (CD_APPLET_MY_CONFIG_CHANGED)
103
 
        {
104
 
                if (myDesklet && CD_APPLET_MY_CONTAINER_TYPE_CHANGED)  // we are now in a desklet, set a renderer.
105
 
                {
106
 
                        CD_APPLET_SET_DESKLET_RENDERER ("Simple");  // set a desklet renderer.
107
 
                        CD_APPLET_ALLOW_NO_CLICKABLE_DESKLET;
108
 
                }
109
 
                
110
 
                myData.fLogoSize = -1;  // pour recharger le logo.
111
 
                // on remplace le texte actuel par un message d'attente.
112
 
                myData.bUpdateIsManual = FALSE;
113
 
                myData.iFirstDisplayedItem = 0;
114
 
                if (myData.iSidRedrawIdle != 0)
115
 
                {
116
 
                        g_source_remove (myData.iSidRedrawIdle);
117
 
                        myData.iSidRedrawIdle = 0;
118
 
                }
119
 
                g_free (myData.PrevFirstTitle);
120
 
                myData.PrevFirstTitle = NULL;
121
 
                
122
 
                cd_rssreader_free_item_list (myApplet);
123
 
                CDRssItem *pItem = g_new0 (CDRssItem, 1);  // on commence au debut de la liste (c'est le titre).
124
 
                myData.pItemList = g_list_prepend (myData.pItemList, pItem);
125
 
                pItem->cTitle = g_strdup (D_("Retrieving data..."));
126
 
                myData.bInit = FALSE;
127
 
                myData.bError = FALSE;
128
 
                
129
 
                // on relance la tache periodique.
130
 
                cd_rssreader_launch_task (myApplet);
131
 
                
132
 
                // redessin.
133
 
                if (myDesklet)
134
 
                {
135
 
                        cd_applet_update_my_icon (myApplet);
136
 
                }
137
 
                else
138
 
                {
139
 
                        CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE;
140
 
                }
141
 
        }
142
 
        
143
 
        // en mode desklet on redessine l'icone aux nouvelles dimensions.
144
 
        if (myDesklet)
145
 
        {
146
 
                cd_applet_update_my_icon (myApplet);
147
 
        }
148
 
        
149
 
CD_APPLET_RELOAD_END