void cairo_dock_set_icon_name (cairo_t *pSourceContext, const gchar *cIconName, Icon *pIcon, CairoContainer *pContainer) // fonction proposee par Necropotame. { g_return_if_fail (pIcon != NULL && pContainer != NULL); // le contexte sera verifie plus loin. gchar *cUniqueName = NULL; if (pIcon->pSubDock != NULL) { cUniqueName = cairo_dock_get_unique_dock_name (cIconName); cIconName = cUniqueName; cairo_dock_rename_dock (pIcon->acName, pIcon->pSubDock, cUniqueName); } if (pIcon->acName != cIconName) { g_free (pIcon->acName); pIcon->acName = g_strdup (cIconName); } g_free (cUniqueName); cairo_dock_fill_one_text_buffer( pIcon, pSourceContext, &myLabels.iconTextDescription); }
static GKeyFile* reload_object (GldiObject *obj, gboolean bReloadConf, GKeyFile *pKeyFile) { Icon *icon = (Icon*)obj; if (bReloadConf) g_return_val_if_fail (pKeyFile != NULL, NULL); // get additional parameters g_free (icon->cFileName); icon->cFileName = g_key_file_get_string (pKeyFile, "Desktop Entry", "Icon", NULL); if (icon->cFileName != NULL && *icon->cFileName == '\0') { g_free (icon->cFileName); icon->cFileName = NULL; } gchar *cName = icon->cName; icon->cName = cairo_dock_get_locale_string_from_conf_file (pKeyFile, "Desktop Entry", "Name", NULL); if (icon->cName == NULL || *icon->cName == '\0') // no name defined, we need one. { g_free (icon->cName); if (cName != NULL) icon->cName = g_strdup (cName); else icon->cName = cairo_dock_get_unique_dock_name ("sub-dock"); g_key_file_set_string (pKeyFile, "Desktop Entry", "Name", icon->cName); gchar *cDesktopFilePath = g_strdup_printf ("%s/%s", g_cCurrentLaunchersPath, icon->cDesktopFileName); cairo_dock_write_keys_to_file (pKeyFile, cDesktopFilePath); g_free (cDesktopFilePath); } // if it has changed, ensure its unicity, and rename the sub-dock to be able to link with it again. if (g_strcmp0 (icon->cName, cName) != 0) // name has changed -> rename the sub-dock. { // ensure unicity gchar *cUniqueName = cairo_dock_get_unique_dock_name (icon->cName); if (strcmp (icon->cName, cUniqueName) != 0) { g_free (icon->cName); icon->cName = cUniqueName; cUniqueName = NULL; g_key_file_set_string (pKeyFile, "Desktop Entry", "Name", icon->cName); gchar *cDesktopFilePath = g_strdup_printf ("%s/%s", g_cCurrentLaunchersPath, icon->cDesktopFileName); cairo_dock_write_keys_to_file (pKeyFile, cDesktopFilePath); g_free (cDesktopFilePath); } g_free (cUniqueName); // rename sub-dock cd_debug ("on renomme a l'avance le sous-dock en %s", icon->cName); if (icon->pSubDock != NULL) gldi_dock_rename (icon->pSubDock, icon->cName); // also updates sub-icon's container name } icon->iSubdockViewType = g_key_file_get_integer (pKeyFile, "Desktop Entry", "render", NULL); // on a besoin d'un entier dans le panneau de conf pour pouvoir degriser des options selon le rendu choisi. De plus c'est utile aussi pour Animated Icons... gchar *cSubDockRendererName = g_key_file_get_string (pKeyFile, "Desktop Entry", "Renderer", NULL); //\_____________ reload icon // redraw icon cairo_dock_load_icon_image (icon, icon->pContainer); // reload label if (g_strcmp0 (cName, icon->cName) != 0) cairo_dock_load_icon_text (icon); // set sub-dock renderer if (icon->pSubDock != NULL) { if (g_strcmp0 (cSubDockRendererName, icon->pSubDock->cRendererName) != 0) { cairo_dock_set_renderer (icon->pSubDock, cSubDockRendererName); cairo_dock_update_dock_size (icon->pSubDock); } } g_free (cSubDockRendererName); g_free (cName); return pKeyFile; }
static void init_object (GldiObject *obj, gpointer attr) { Icon *icon = (Icon*)obj; GldiUserIconAttr *pAttributes = (GldiUserIconAttr*)attr; g_return_if_fail (pAttributes->pKeyFile != NULL); icon->iface.load_image = _load_image; // get additional parameters GKeyFile *pKeyFile = pAttributes->pKeyFile; gboolean bNeedUpdate = FALSE; icon->cFileName = g_key_file_get_string (pKeyFile, "Desktop Entry", "Icon", NULL); if (icon->cFileName != NULL && *icon->cFileName == '\0') { g_free (icon->cFileName); icon->cFileName = NULL; } icon->cName = cairo_dock_get_locale_string_from_conf_file (pKeyFile, "Desktop Entry", "Name", NULL); if (icon->cName != NULL && *icon->cName == '\0') { g_free (icon->cName); icon->cName = NULL; } if (g_strcmp0 (icon->cName, icon->cParentDockName) == 0) // it shouldn't happen, but if ever it does, be sure to forbid an icon pointing on itself. { cd_warning ("It seems we have a sub-dock in itself! => its parent dock is now the main dock"); g_key_file_set_string (pKeyFile, "Desktop Entry", "Container", CAIRO_DOCK_MAIN_DOCK_NAME); // => to the main dock bNeedUpdate = TRUE; g_free (icon->cParentDockName); icon->cParentDockName = g_strdup (CAIRO_DOCK_MAIN_DOCK_NAME); } g_return_if_fail (icon->cName != NULL); icon->iSubdockViewType = g_key_file_get_integer (pKeyFile, "Desktop Entry", "render", NULL); // on a besoin d'un entier dans le panneau de conf pour pouvoir degriser des options selon le rendu choisi. De plus c'est utile aussi pour Animated Icons... // create its sub-dock gchar *cSubDockRendererName = g_key_file_get_string (pKeyFile, "Desktop Entry", "Renderer", NULL); if (icon->cName != NULL) { CairoDock *pChildDock = gldi_dock_get (icon->cName); // the dock might already exists (if an icon inside has been created beforehand), in this case it's still a root dock if (pChildDock && (pChildDock->iRefCount > 0 || pChildDock->bIsMainDock)) // if ever a sub-dock with this name already exists, change the icon's name to avoid the conflict { gchar *cUniqueDockName = cairo_dock_get_unique_dock_name (icon->cName); cd_warning ("A sub-dock with the same name (%s) already exists, we'll change it to %s", icon->cName, cUniqueDockName); gchar *cDesktopFilePath = g_strdup_printf ("%s/%s", g_cCurrentLaunchersPath, icon->cDesktopFileName); cairo_dock_update_conf_file (cDesktopFilePath, G_TYPE_STRING, "Desktop Entry", "Name", cUniqueDockName, G_TYPE_INVALID); g_free (cDesktopFilePath); g_free (icon->cName); icon->cName = cUniqueDockName; pChildDock = NULL; } CairoDock *pParentDock = gldi_dock_get (icon->cParentDockName); // the icon is not yet inserted, but its dock has been created by the parent class. if (pChildDock == NULL) { cd_message ("The child dock (%s) doesn't exist, we create it with this view: %s", icon->cName, cSubDockRendererName); pChildDock = gldi_subdock_new (icon->cName, cSubDockRendererName, pParentDock, NULL); } else { cd_message ("The dock is now a 'child-dock' (%d, %d)", pChildDock->container.bIsHorizontal, pChildDock->container.bDirectionUp); gldi_dock_make_subdock (pChildDock, pParentDock, cSubDockRendererName); } icon->pSubDock = pChildDock; } g_free (cSubDockRendererName); if (! bNeedUpdate) bNeedUpdate = cairo_dock_conf_file_needs_update (pKeyFile, GLDI_VERSION); if (bNeedUpdate) { gchar *cDesktopFilePath = g_strdup_printf ("%s/%s", g_cCurrentLaunchersPath, pAttributes->cConfFileName); const gchar *cTemplateFile = GLDI_SHARE_DATA_DIR"/"CAIRO_DOCK_CONTAINER_CONF_FILE; cairo_dock_upgrade_conf_file (cDesktopFilePath, pKeyFile, cTemplateFile); // update keys g_free (cDesktopFilePath); } }