~ubuntu-branches/ubuntu/quantal/cairo-dock-plug-ins/quantal-201208191523

« back to all changes in this revision

Viewing changes to stack/src/applet-stack.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2011-04-20 20:46:51 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20110420204651-ftnpzesj6uc7qeul
Tags: 2.3.0~1-0ubuntu1
* New Upstream Version (LP: #723995)
* Upstream short ChangeLog (since 2.3.0~0rc1):
 - Updated translations
 - Updated the integration of the new versions of kwin and compiz
    (Switcher, ShowDesktop, etc.)
 - Removed a lot of useless g_print
 - Updated a few plug-ins to fit with the new version of the API (gldit)
 - Fixed a few bugs
 - Updated MeMenu, MessagingMenu and Status-Notifier to works
    with the latest version of dbusmenu, etc.
* Switch to dpkg-source 3.0 (quilt) format
* debian/cairo-dock-plug-ins.install:
 - Added new files (interfaces for python, ruby, vala and mono)
* debian/control:
 - Added new dependences for new applets (sensors and zeitgeist)
    and new interfaces (python, valac, ruby and mono)
 - Updated the version of cairo-dock build-dependences
* debian/rules:
 - Added a new CMake flag to install python interface in debian/tmp
* Updated debian/watch

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
        }
61
61
}
62
62
 
63
 
void cd_stack_clear_stack (CairoDockModuleInstance *myApplet) {
 
63
void cd_stack_clear_stack (CairoDockModuleInstance *myApplet)
 
64
{
64
65
        gchar *cCommand = g_strdup_printf("rm -rf \"%s\"/*", myConfig.cStackDir);
65
66
        cd_debug("Stack: will use '%s'", cCommand);
66
67
        int r = system (cCommand);
67
68
        g_free(cCommand);
68
69
        
69
70
        CD_APPLET_DELETE_MY_ICONS_LIST;
 
71
        if (myDock)  // on ne veut pas d'un sous-dock vide, meme si on va probablement y rajouter des items aussitot.
 
72
        {
 
73
                cairo_dock_destroy_dock (myIcon->pSubDock, myIcon->cName);
 
74
                myIcon->pSubDock = NULL;
 
75
        }
70
76
}
71
77
 
72
78
 
81
87
}
82
88
 
83
89
 
 
90
static void _get_html_page (CDHtmlLink *pHtmlLink)
 
91
{
 
92
        CairoDockModuleInstance *myApplet = pHtmlLink->pApplet;
 
93
        // get the HTML page content
 
94
        gchar *cPageContent = cairo_dock_get_url_data (pHtmlLink->cURL, NULL);
 
95
        if (cPageContent == NULL)
 
96
        {
 
97
                cd_warning ("Stack: couldn't get the html page '%s'\n -> can't get the title and favicon", pHtmlLink->cURL);
 
98
                return;  // we could still draw the emblem in case it's already local, but not the title; so it wouldn't be really better.
 
99
        }
 
100
        
 
101
        // get the title
 
102
        gchar *str = strstr (cPageContent, "<title>");
 
103
        if (!str)
 
104
                str = strstr (cPageContent, "<TITLE>");
 
105
        if (str)
 
106
        {
 
107
                str += 7;
 
108
                gchar *str2 = strstr (str, "</title>");
 
109
                if (!str2)
 
110
                        str2 = strstr (str, "</TITLE>");
 
111
                if (str2)
 
112
                {
 
113
                        pHtmlLink->cTitle = g_strndup (str, str2 - str);
 
114
                        // remove carriage returns.
 
115
                        gchar *str = pHtmlLink->cTitle;
 
116
                        while (str = strchr (str, '\n'))
 
117
                        {
 
118
                                *str = ' ';  // replace the carriage returns with a space.
 
119
                                str ++;  // begining of the new line.
 
120
                                str2 = str;
 
121
                                while (*str2 == ' ')
 
122
                                        str2 ++;
 
123
                                if (str2 != str)  // remove spaces at the begining of the new line.
 
124
                                        strcpy (str, str2);
 
125
                        }
 
126
                }
 
127
                cd_debug ("cTitle: '%s'", pHtmlLink->cTitle);
 
128
        }
 
129
        
 
130
        // get the domain name.
 
131
        gchar *cDomainName = NULL;
 
132
        str = strstr (pHtmlLink->cURL, "://");
 
133
        if (str)
 
134
        {
 
135
                str += 3;
 
136
                gchar *str2 = strchr (str, '/');
 
137
                if (str2)
 
138
                        cDomainName = g_strndup (str, str2 - str);
 
139
        }
 
140
        cd_debug ("cDomainName: %s", cDomainName);
 
141
        
 
142
        // get the favicon or use the existing one.
 
143
        gchar *cLocalFaviconPath = NULL;
 
144
        if (cDomainName != NULL)
 
145
        {
 
146
                // check the favicons folder.
 
147
                gchar *cFaviconDir = g_strdup_printf ("%s/favicons", g_cCairoDockDataDir);
 
148
                if (! g_file_test (cFaviconDir, G_FILE_TEST_EXISTS))
 
149
                {
 
150
                        g_mkdir (cFaviconDir, 7*8*8+7*8+5);
 
151
                }
 
152
                cLocalFaviconPath = g_strdup_printf ("%s/%s", cFaviconDir, cDomainName);
 
153
                g_free (cFaviconDir);
 
154
                
 
155
                // if favicon is not already on hard-disk, download it.
 
156
                if (! g_file_test (cLocalFaviconPath, G_FILE_TEST_EXISTS))
 
157
                {
 
158
                        gboolean bGotFavIcon = FALSE;
 
159
                        
 
160
                        // try to get the favicon path specified in the html page.
 
161
                        gchar *cRelPath = NULL;
 
162
                        str = strstr (cPageContent, "<link rel=\"shortcut icon\"");
 
163
                        if (!str)
 
164
                                str = strstr (cPageContent, "<link rel=\"SHORTCUT ICON\"");
 
165
                        if (str)  // found.
 
166
                        {
 
167
                                str += 25;
 
168
                                // get its remote relative path.
 
169
                                gchar *str2 = strstr (str, "href=\"");
 
170
                                if (str2)
 
171
                                {
 
172
                                        str2 += 6;
 
173
                                        gchar *str3 = strchr (str2, '"');
 
174
                                        if (str3)
 
175
                                        {
 
176
                                                cRelPath = g_strndup (str2, str3 - str2);
 
177
                                                cd_debug ("favicon: '%s'", cRelPath);
 
178
                                        }
 
179
                                }
 
180
                        }
 
181
                        else  // no standard favicon, get the default one in the remote root dir.
 
182
                        {
 
183
                                cd_debug ("no favicon defined, looking for a default favicon.ico...");
 
184
                                cRelPath = g_strdup ("favicon.ico");
 
185
                        }
 
186
                        
 
187
                        // now download it.
 
188
                        if (cRelPath != NULL)
 
189
                        {
 
190
                                gchar *cFaviconURL = NULL;
 
191
                                if (*cRelPath == '/' && *(cRelPath+1) == '/')
 
192
                                {
 
193
                                        cFaviconURL = g_strdup_printf ("http:%s", cRelPath);
 
194
                                }
 
195
                                else if (strstr (cRelPath, "://") != NULL)
 
196
                                {
 
197
                                        cFaviconURL = cRelPath;
 
198
                                        cRelPath = NULL;
 
199
                                }
 
200
                                else
 
201
                                {
 
202
                                        cFaviconURL = g_strdup_printf ("%s/%s", cDomainName, cRelPath);
 
203
                                }
 
204
                                cd_debug ("cFaviconURL: %s", cFaviconURL);
 
205
                                
 
206
                                gchar *cTmpFavIconPath = cairo_dock_download_file (NULL, NULL, cFaviconURL, NULL, NULL);
 
207
                                if (cTmpFavIconPath != NULL)
 
208
                                {
 
209
                                        gchar *cCommand = g_strdup_printf ("mv \"%s\" \"%s\"", cTmpFavIconPath, cLocalFaviconPath);
 
210
                                        cd_debug ("%s", cCommand);
 
211
                                        int r = system (cCommand);
 
212
                                        g_free (cCommand);
 
213
                                        g_free (cTmpFavIconPath);
 
214
                                        bGotFavIcon = TRUE;
 
215
                                }
 
216
                                g_free (cFaviconURL);
 
217
                                g_free (cRelPath);
 
218
                        }
 
219
                        
 
220
                        if (! bGotFavIcon)  // couldn't get the favicon -> no favicon defined.
 
221
                        {
 
222
                                g_free (cLocalFaviconPath);
 
223
                                cLocalFaviconPath = NULL;
 
224
                        }
 
225
                }
 
226
        }
 
227
        pHtmlLink->cFaviconPath = cLocalFaviconPath;
 
228
}
 
229
 
 
230
static gboolean _update_html_link (CDHtmlLink *pHtmlLink)
 
231
{
 
232
        CairoDockModuleInstance *myApplet = pHtmlLink->pApplet;
 
233
        CD_APPLET_ENTER;
 
234
        
 
235
        // store in the conf file.
 
236
        cairo_dock_update_conf_file (pHtmlLink->cConfFilePath,
 
237
                G_TYPE_STRING, "Desktop Entry", "Favicon", pHtmlLink->cFaviconPath,
 
238
                G_TYPE_STRING, "Desktop Entry", "Name", pHtmlLink->cTitle,
 
239
                G_TYPE_INVALID);        
 
240
        
 
241
        // update the icon.
 
242
        gchar *cDesktopFileName = g_path_get_basename (pHtmlLink->cConfFilePath);
 
243
        if (cDesktopFileName)
 
244
        {
 
245
                Icon *pIcon = NULL;
 
246
                GList *pIconsList = CD_APPLET_MY_ICONS_LIST;
 
247
                GList *ic;
 
248
                for (ic = pIconsList; ic != NULL; ic = ic->next)
 
249
                {
 
250
                        pIcon = ic->data;
 
251
                        if (pIcon->cDesktopFileName && strcmp (pIcon->cDesktopFileName, cDesktopFileName) == 0)
 
252
                        {
 
253
                                CairoContainer *pContainer = CD_APPLET_MY_ICONS_LIST_CONTAINER;
 
254
                                
 
255
                                cairo_dock_set_icon_name (pHtmlLink->cTitle, pIcon, pContainer);
 
256
                                
 
257
                                cd_debug ("draw emblem on %s", pIcon->cName);
 
258
                                CairoEmblem *pEmblem = cairo_dock_make_emblem (pHtmlLink->cFaviconPath, pIcon, pContainer);
 
259
                                cairo_dock_set_emblem_position (pEmblem, CAIRO_DOCK_EMBLEM_LOWER_RIGHT);
 
260
                                cairo_dock_draw_emblem_on_icon (pEmblem, pIcon, pContainer);
 
261
                                cairo_dock_free_emblem (pEmblem);
 
262
                                cairo_dock_redraw_icon (pIcon, pContainer);
 
263
                                break;
 
264
                        }
 
265
                }
 
266
                g_free (cDesktopFileName);
 
267
        }
 
268
        
 
269
        cairo_dock_discard_task (pHtmlLink->pTask);
 
270
        myData.pGetPageTaskList = g_list_remove (myData.pGetPageTaskList, pHtmlLink->pTask);
 
271
        
 
272
        CD_APPLET_LEAVE (TRUE);
 
273
}
 
274
 
 
275
static void _free_html_link (CDHtmlLink *pHtmlLink)
 
276
{
 
277
        g_free (pHtmlLink->cURL);
 
278
        g_free (pHtmlLink->cTitle);
 
279
        g_free (pHtmlLink->cFaviconPath);
 
280
        g_free (pHtmlLink->cConfFilePath);
 
281
        g_free (pHtmlLink);
 
282
}
 
283
 
84
284
static void _set_icon_order (Icon *pIcon, CairoDockModuleInstance *myApplet, GCompareFunc comp)
85
285
{
86
286
        GList *pIconsList = CD_APPLET_MY_ICONS_LIST;
108
308
        gchar *cName;
109
309
        double fOrder = 0;
110
310
        int iDate;
 
311
        CDHtmlLink *pHtmlLink = NULL;
111
312
        
 
313
        cd_debug ("Stack: got '%s'", cContent);
112
314
        //\_______________________ On lui trouve un petit nom.
113
315
        if (cairo_dock_string_is_adress (cContent) || *cContent == '/')
114
316
        {
115
317
                if (strncmp (cContent, "http://", 7) == 0 || strncmp (cContent, "www", 3) == 0 || strncmp (cContent, "https://", 8) == 0)
116
318
                {
 
319
                        cd_debug (" -> html page");
 
320
                        pHtmlLink = g_new0 (CDHtmlLink, 1);
 
321
                        pHtmlLink->pApplet = myApplet;
 
322
                        pHtmlLink->cURL = g_strdup (cContent);
 
323
                        pHtmlLink->pTask = cairo_dock_new_task_full (0,
 
324
                                (CairoDockGetDataAsyncFunc)_get_html_page,
 
325
                                (CairoDockUpdateSyncFunc)_update_html_link,
 
326
                                (GFreeFunc)_free_html_link,
 
327
                                pHtmlLink);
 
328
                        myData.pGetPageTaskList = g_list_prepend (myData.pGetPageTaskList, pHtmlLink->pTask);
 
329
                        cairo_dock_launch_task (pHtmlLink->pTask);
 
330
                        
117
331
                        gchar *buf = g_strdup (cContent);
118
332
                        gchar *str = strchr (buf, '?');
119
333
                        if (str != NULL)
186
400
        } while (g_file_test (sConfFilePath->str, G_FILE_TEST_EXISTS));
187
401
        
188
402
        cairo_dock_write_keys_to_file (pKeyFile, sConfFilePath->str);
 
403
        if (pHtmlLink)
 
404
                pHtmlLink->cConfFilePath = g_strdup (sConfFilePath->str);
189
405
        
190
406
        //\_______________________ On cree une icone a partir du fichier de cle precedemment remplit.
191
407
        Icon *pIcon = cd_stack_build_one_icon (myApplet, pKeyFile);