Esempio n. 1
0
void test_setcomment()
{
	GKeyFile *keyfile;
	gchar *comment;

	const gchar *data = 
	    "[1]\n"
	    "key1=123\n"
	    "key2=456\n";
	
	keyfile = load_data (data, 0);
	
	g_key_file_set_comment(keyfile,"1","key1","comment1",NULL);
	
	comment = g_key_file_get_comment(keyfile,"1","key1",NULL);
	
	g_assert(!strcmp(comment,"comment1\n"));
	
	g_key_file_remove_comment(keyfile,"1","key1",NULL);
	
	g_free(comment);
	
	comment = g_key_file_get_comment(keyfile,"1","key1",NULL);
	
	g_assert(comment == NULL);
	
}
Esempio n. 2
0
/* copies all keys and comments from one group to another, deleting the old
 * group. */
static gboolean
gst_preset_default_rename_preset (GstPreset * preset, const gchar * old_name,
    const gchar * new_name)
{
  GKeyFile *presets;
  gchar *str;
  gchar **keys;
  gsize i, num_keys;

  /* get the presets from the type */
  if (!(presets = preset_get_keyfile (preset)))
    goto no_presets;

  if (!g_key_file_has_group (presets, old_name))
    goto no_group;

  /* copy group comment if there is any */
  if ((str = g_key_file_get_comment (presets, old_name, NULL, NULL))) {
    g_key_file_set_comment (presets, new_name, NULL, str, NULL);
    g_free (str);
  }

  /* get all keys from the old group and copy them in the new group */
  keys = g_key_file_get_keys (presets, old_name, &num_keys, NULL);
  for (i = 0; i < num_keys; i++) {
    /* copy key comment if there is any */
    if ((str = g_key_file_get_comment (presets, old_name, keys[i], NULL))) {
      g_key_file_set_comment (presets, new_name, keys[i], str, NULL);
      g_free (str);
    }
    /* copy key value */
    str = g_key_file_get_value (presets, old_name, keys[i], NULL);
    g_key_file_set_value (presets, new_name, keys[i], str);
    g_free (str);
  }
  g_strfreev (keys);

  /* remove old group */
  g_key_file_remove_group (presets, old_name, NULL);

  /* save updated version */
  return gst_preset_default_save_presets_file (preset);

  /* ERRORS */
no_presets:
  {
    GST_WARNING_OBJECT (preset, "no presets");
    return FALSE;
  }
no_group:
  {
    GST_WARNING_OBJECT (preset, "no preset named %s", old_name);
    return FALSE;
  }
}
Esempio n. 3
0
static void
preset_merge (GKeyFile * system, GKeyFile * user)
{
  gchar *str;
  gchar **groups, **keys;
  gsize i, j, num_groups, num_keys;

  /* copy file comment if there is any */
  if ((str = g_key_file_get_comment (user, NULL, NULL, NULL))) {
    g_key_file_set_comment (system, NULL, NULL, str, NULL);
    g_free (str);
  }

  /* get groups in user and copy into system */
  groups = g_key_file_get_groups (user, &num_groups);
  for (i = 0; i < num_groups; i++) {
    /* copy group comment if there is any */
    if ((str = g_key_file_get_comment (user, groups[i], NULL, NULL))) {
      g_key_file_set_comment (system, groups[i], NULL, str, NULL);
      g_free (str);
    }

    /* ignore private groups */
    if (groups[i][0] == '_')
      continue;

    /* if group already exists in system, remove and re-add keys from user */
    if (g_key_file_has_group (system, groups[i])) {
      g_key_file_remove_group (system, groups[i], NULL);
    }

    keys = g_key_file_get_keys (user, groups[i], &num_keys, NULL);
    for (j = 0; j < num_keys; j++) {
      /* copy key comment if there is any */
      if ((str = g_key_file_get_comment (user, groups[i], keys[j], NULL))) {
        g_key_file_set_comment (system, groups[i], keys[j], str, NULL);
        g_free (str);
      }
      str = g_key_file_get_value (user, groups[i], keys[j], NULL);
      g_key_file_set_value (system, groups[i], keys[j], str);
      g_free (str);
    }
    g_strfreev (keys);
  }
  g_strfreev (groups);
}
gboolean
dfu_key_file_rename_group (GKeyFile   *keyfile,
                           const char *oldgroup,
                           const char *newgroup)
{
  char         **keys;
  char          *value;
  unsigned int   i;

  g_return_val_if_fail (keyfile != NULL, FALSE);

  if (!g_key_file_has_group (keyfile, oldgroup))
    return TRUE;

  keys = g_key_file_get_keys (keyfile, oldgroup, NULL, NULL);
  for (i = 0; keys[i] != NULL; i++) {
    value = g_key_file_get_value (keyfile, oldgroup, keys[i], NULL);
    g_key_file_set_value (keyfile, newgroup, keys[i], value);
    g_free (value);

    value = g_key_file_get_comment (keyfile, oldgroup, keys[i], NULL);
    if (value) {
      g_key_file_set_comment (keyfile, newgroup, keys[i], value, NULL);
      g_free (value);
    }
  }
  g_strfreev (keys);

  value = g_key_file_get_comment (keyfile, oldgroup, NULL, NULL);
  if (value) {
    g_key_file_set_comment (keyfile, newgroup, NULL, value, NULL);
    g_free (value);
  }

  g_key_file_remove_group (keyfile, oldgroup, NULL);

  return TRUE;
}
void cairo_dock_get_conf_file_version (GKeyFile *pKeyFile, gchar **cConfFileVersion)
{
	*cConfFileVersion = NULL;
	
	gchar *cFirstComment =  g_key_file_get_comment (pKeyFile, NULL, NULL, NULL);
	
	if (cFirstComment != NULL && *cFirstComment != '\0')
	{
		gchar *str = strchr (cFirstComment, '\n');
		if (str != NULL)
			*str = '\0';
		
		str = strchr (cFirstComment, ';');  // le 1er est pour la langue (obsolete).
		if (str != NULL)
		{
			*cConfFileVersion = g_strdup (str+1);
		}
		else
		{
			*cConfFileVersion = g_strdup (cFirstComment + (*cFirstComment == '!'));  // le '!' est obsolete.
		}
	}
	g_free (cFirstComment);
}
void cairo_dock_apply_filter_on_group_list (gchar **pKeyWords, gboolean bAllWords, gboolean bSearchInToolTip, gboolean bHighLightText, gboolean bHideOther, GList *pGroupDescriptionList)
{
    //g_print ("%s ()\n", __func__);
    if (sBuffer == NULL)
        sBuffer = g_string_new ("");
    CairoDockGroupDescription *pGroupDescription, *pInternalGroupDescription;
    gchar *cKeyWord, *str = NULL, *cModifiedText = NULL, *cDescription, *cToolTip = NULL;
    gboolean bFound, bFrameVisible;
    GtkWidget *pGroupBox, *pLabel, *pCategoryFrame, *pCurrentCategoryFrame = NULL;
    GKeyFile *pKeyFile;
    GKeyFile *pMainKeyFile = cairo_dock_open_key_file (g_cConfFile);

    int i;
    GList *gd;
    const gchar *cGettextDomain;
    for (gd = pGroupDescriptionList; gd != NULL; gd = gd->next)
    {
        pGroupDescription = gd->data;
        pGroupDescription->bMatchFilter = FALSE;
    }
    for (gd = pGroupDescriptionList; gd != NULL; gd = gd->next)
    {
        //g_print ("pGroupDescription:%x\n", gd->data);
        //\_______________ On recupere le group description.
        pGroupDescription = gd->data;

        if (pGroupDescription->cInternalModule)
        {
            g_print ("%s : bouton emprunte a %s\n", pGroupDescription->cGroupName, pGroupDescription->cInternalModule);
            pInternalGroupDescription = cairo_dock_find_module_description (pGroupDescription->cInternalModule);
            if (pInternalGroupDescription != NULL)
                pGroupBox = gtk_widget_get_parent (pInternalGroupDescription->pActivateButton);
            else
                continue;
            pLabel = pInternalGroupDescription->pLabel;
            g_print ("ok, found pGroupBox\n");
        }
        else
        {
            pGroupBox = gtk_widget_get_parent (pGroupDescription->pActivateButton);
            pLabel = pGroupDescription->pLabel;
        }
        //g_print ("  %x\n", pGroupDescription->pActivateButton);
        pCategoryFrame = gtk_widget_get_parent (pGroupBox);
        cGettextDomain = pGroupDescription->cGettextDomain;
        bFound = FALSE;

        cDescription = dgettext (cGettextDomain, pGroupDescription->cGroupName);
        if (bSearchInToolTip)
            cToolTip = dgettext (cGettextDomain, pGroupDescription->cDescription);
        //g_print ("cDescription : %s (%s)(%x,%x)\n", cDescription, cToolTip, cModifiedText, str);

        //\_______________ On change de frame.
        if (pCategoryFrame != pCurrentCategoryFrame)  // on a change de frame.
        {
            if (pCurrentCategoryFrame)
            {
                if (! bFrameVisible && bHideOther)
                {
                    //g_print (" on cache cette categorie\n");
                    gtk_widget_hide (pCurrentCategoryFrame);
                }
                else
                    gtk_widget_show (pCurrentCategoryFrame);
            }
            pCurrentCategoryFrame = pCategoryFrame;
            //g_print (" pCurrentCategoryFrame <- %x\n", pCurrentCategoryFrame);
        }

        //\_______________ On cherche chaque mot dans la description du module.
        for (i = 0; pKeyWords[i] != NULL; i ++)
        {
            cKeyWord = pKeyWords[i];
            _copy_string_to_buffer (cDescription);
            if (bHighLightText)
                cModifiedText = cairo_dock_highlight_key_word (cDescription, cKeyWord, TRUE);
            else
                str = _search_in_buffer (cKeyWord);
            if (cModifiedText == NULL && str == NULL)
            {
                if (cToolTip != NULL)
                {
                    _copy_string_to_buffer (cToolTip);
                    str = _search_in_buffer (cKeyWord);
                }
            }

            if (cModifiedText != NULL || str != NULL)
            {
                //g_print (">>> on a trouve direct %s\n", cKeyWord);
                bFound = TRUE;
                if (cModifiedText != NULL)
                {
                    gtk_label_set_use_markup (GTK_LABEL (pLabel), TRUE);
                    gtk_label_set_markup (GTK_LABEL (pLabel), cModifiedText);
                    g_free (cModifiedText);
                    cModifiedText = NULL;
                }
                else
                {
                    gtk_label_set_text (GTK_LABEL (pLabel), cDescription);
                    str = NULL;
                }
                if (! bAllWords)
                    break ;
            }
            else if (bAllWords)
            {
                bFound = FALSE;
                break ;
            }
        }

        //\_______________ On cherche chaque mot a l'interieur du module.
        if (! bFound && pGroupDescription->cOriginalConfFilePath != NULL)
        {
            //\_______________ On recupere les groupes du module.
            //g_print ("* on cherche dans le fichier de conf %s ...\n", pGroupDescription->cOriginalConfFilePath);
            gchar **pGroupList = NULL;
            CairoDockModule *pModule = cairo_dock_find_module_from_name (pGroupDescription->cGroupName);
            if (pModule != NULL)
            {
                pKeyFile = cairo_dock_open_key_file (pModule->cConfFilePath);
                if (pKeyFile != NULL)
                {
                    gsize length = 0;
                    pGroupList = g_key_file_get_groups (pKeyFile, &length);
                }
            }
            else  // groupe interne, le fichier de conf n'est ouvert qu'une seule fois.
            {
                pKeyFile = pMainKeyFile;
                pGroupList = g_new0 (gchar *, 2);
                pGroupList[0] = g_strdup (pGroupDescription->cGroupName);
            }

            //\_______________ Pour chaque groupe on parcourt toutes les cles.
            if (pGroupList != NULL)
            {
                int iNbWords;
                for (iNbWords = 0; pKeyWords[iNbWords] != NULL; iNbWords ++);
                gboolean *bFoundWords = g_new0 (gboolean , iNbWords);

                gchar *cUsefulComment;
                gchar iElementType;
                int iNbElements;
                gchar **pAuthorizedValuesList;
                gchar *cTipString;
                gboolean bIsAligned;
                gchar **pKeyList;
                gchar *cGroupName, *cKeyName, *cKeyComment;
                int j, k;
                for (k = 0; pGroupList[k] != NULL; k ++)
                {
                    cGroupName = pGroupList[k];
                    pKeyList = g_key_file_get_keys (pKeyFile, cGroupName, NULL, NULL);
                    for (j = 0; pKeyList[j] != NULL; j ++)
                    {
                        cKeyName = pKeyList[j];
                        //\_______________ On recupere la description + bulle d'aide de la cle.
                        cKeyComment =  g_key_file_get_comment (pKeyFile, cGroupName, cKeyName, NULL);
                        cUsefulComment = cairo_dock_parse_key_comment (cKeyComment, &iElementType, &iNbElements, &pAuthorizedValuesList, &bIsAligned, &cTipString);
                        if (cUsefulComment == NULL)
                        {
                            g_free (cKeyComment);
                            continue;
                        }

                        cUsefulComment = dgettext (cGettextDomain, cUsefulComment);
                        if (cTipString != NULL)
                        {
                            if (bSearchInToolTip)
                                cTipString = dgettext (cGettextDomain, cTipString);
                            else
                                cTipString = NULL;
                        }
                        //\_______________ On y cherche les mots-cles.
                        for (i = 0; pKeyWords[i] != NULL; i ++)
                        {
                            if (bFoundWords[i])
                                continue;
                            cKeyWord = pKeyWords[i];
                            str = NULL;
                            if (cUsefulComment)
                            {
                                _copy_string_to_buffer (cUsefulComment);
                                str = _search_in_buffer (cKeyWord);
                            }
                            if (! str && cTipString)
                            {
                                _copy_string_to_buffer (cTipString);
                                str = _search_in_buffer (cKeyWord);
                            }
                            if (! str && pAuthorizedValuesList)
                            {
                                int l;
                                for (l = 0; pAuthorizedValuesList[l] != NULL; l ++)
                                {
                                    _copy_string_to_buffer (dgettext (cGettextDomain, pAuthorizedValuesList[l]));
                                    str = _search_in_buffer (cKeyWord);
                                    if (str != NULL)
                                        break ;
                                }
                            }

                            if (str != NULL)
                            {
                                //g_print (">>>on a trouve %s\n", pKeyWords[i]);
                                bFound = TRUE;
                                str = NULL;
                                if (! bAllWords)
                                {
                                    break ;
                                }
                                bFoundWords[i] = TRUE;
                            }
                        }

                        g_free (cKeyComment);
                        if (! bAllWords && bFound)
                            break ;
                    }  // fin de parcours du groupe.
                    g_strfreev (pKeyList);
                    if (! bAllWords && bFound)
                        break ;
                }  // fin de parcours des groupes.
                g_strfreev (pGroupList);

                if (bAllWords && bFound)
                {
                    for (i = 0; i < iNbWords; i ++)
                    {
                        if (! bFoundWords[i])
                        {
                            //g_print ("par contre il manque %s, dommage\n", pKeyWords[i]);
                            bFound = FALSE;
                            break;
                        }
                    }
                }
                g_free (bFoundWords);
            }  // fin du cas ou on avait des groupes a etudier.
            if (pKeyFile != pMainKeyFile)
                g_key_file_free (pKeyFile);
            //g_print ("bFound : %d\n", bFound);

            if (bHighLightText && bFound)  // on passe le label du groupe en bleu + gras.
            {
                cModifiedText = g_strdup_printf ("<b><span color=\"blue\">%s</span></b>", cDescription);
                //g_print ("cModifiedText : %s\n", cModifiedText);
                gtk_label_set_markup (GTK_LABEL (pLabel), dgettext (cGettextDomain, cModifiedText));
                g_free (cModifiedText);
                cModifiedText = NULL;
            }
        }  // fin du cas ou on devait chercher dans le groupe.

        if (pGroupDescription->cInternalModule)
        {
            pInternalGroupDescription = cairo_dock_find_module_description (pGroupDescription->cInternalModule);
            if (pInternalGroupDescription != NULL)
            {
                pInternalGroupDescription->bMatchFilter |= bFound;
                bFound = pInternalGroupDescription->bMatchFilter;
            }
        }
        else
        {
            pGroupDescription->bMatchFilter |= bFound;
            bFound = pGroupDescription->bMatchFilter;
        }
        if (bFound)
        {
            //g_print ("on montre ce groupe\n");
            gtk_widget_show (pGroupBox);
            if (pCurrentCategoryFrame != NULL)
                bFrameVisible = TRUE;
        }
        else if (bHideOther)
        {
            //g_print ("on cache ce groupe (%s)\n", pGroupDescription->cGroupName);
            gtk_widget_hide (pGroupBox);
        }
        else
            gtk_widget_show (pGroupBox);
        if (! bHighLightText || ! bFound)
        {
            gtk_label_set_markup (GTK_LABEL (pLabel), dgettext (cGettextDomain, cDescription));
        }
    }
Esempio n. 7
0
/* check handling of comments
 */
void
test_comments (void)
{
  gchar **names;
  gsize len;
  GError *error = NULL;
  gchar *comment;

  const gchar *data = 
    "# top comment\n"
    "# top comment, continued\n"
    "[group1]\n"
    "key1 = value1\n"
    "# key comment\n"
    "# key comment, continued\n"
    "key2 = value2\n"
    "# line end check\r\n"
    "key3 = value3\n"
    "key4 = value4\n"
    "# group comment\n"
    "# group comment, continued\n"
    "[group2]\n";

  const gchar *top_comment= " top comment\n top comment, continued\n";
  const gchar *group_comment= " group comment\n group comment, continued\n";
  const gchar *key_comment= " key comment\n key comment, continued\n";
  
  cut_assert (g_key_file_load_from_data (keyfile, data, -1, 0, NULL));

  check_string_value (keyfile, "group1", "key1", "value1");
  check_string_value (keyfile, "group1", "key2", "value2");
  check_string_value (keyfile, "group1", "key3", "value3");
  check_string_value (keyfile, "group1", "key4", "value4");

  names = g_key_file_get_keys (keyfile, "group1", &len, &error);
  check_no_error (error);

  check_length ("keys", g_strv_length (names), len, 4);
  check_name ("key", names[0], "key1", 0);
  check_name ("key", names[1], "key2", 1);
  check_name ("key", names[2], "key3", 2);
  check_name ("key", names[3], "key4", 3);

  g_strfreev (names);

  g_key_file_free (keyfile);

  keyfile = g_key_file_new ();
  cut_assert (g_key_file_load_from_data (keyfile, data, -1, G_KEY_FILE_KEEP_COMMENTS, NULL));

  names = g_key_file_get_keys (keyfile, "group1", &len, &error);
  check_no_error (error);

  check_length ("keys", g_strv_length (names), len, 4);
  check_name ("key", names[0], "key1", 0);
  check_name ("key", names[1], "key2", 1);
  check_name ("key", names[2], "key3", 2);
  check_name ("key", names[3], "key4", 3);

  g_strfreev (names);

  comment = g_key_file_get_comment (keyfile, NULL, NULL, &error);
  check_no_error (error);
  check_name ("top comment", comment, top_comment, 0);
  g_free (comment);

  comment = g_key_file_get_comment (keyfile, "group1", "key2", &error);
  check_no_error (error);
  check_name ("key comment", comment, key_comment, 0);
  g_free (comment);

  comment = g_key_file_get_comment (keyfile, "group2", NULL, &error);
  check_no_error (error);
  check_name ("group comment", comment, group_comment, 0);
  g_free (comment);

  comment = g_key_file_get_comment (keyfile, "group3", NULL, &error);
  check_error (&error, 
	       G_KEY_FILE_ERROR,
	       G_KEY_FILE_ERROR_GROUP_NOT_FOUND);
  cut_assert_null (comment);
}
int
main (int argc, char** argv)
{
	if (argc < 2)
		g_error ("il manque le chemin du fichier !\n");
	gchar *cConfFilePath = argv[1];
	
	GKeyFile *pKeyFile = g_key_file_new ();
	
	GError *erreur = NULL;
	g_key_file_load_from_file (pKeyFile, cConfFilePath, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &erreur);
	if (erreur != NULL)
		g_error ("%s\n", erreur->message);
	
	int iNbBuffers = 0;
	gsize length = 0;
	gchar **pKeyList;
	gchar **pGroupList = g_key_file_get_groups (pKeyFile, &length);
	
	gchar *cGroupName, *cKeyName, *cKeyComment, *cUsefulComment, *cAuthorizedValuesChain, *pTipString, **pAuthorizedValuesList;
	int i, j, k, iNbElements;
	char iElementType;
	gboolean bIsAligned;
	gboolean bValue, *bValueList;
	int iValue, iMinValue, iMaxValue, *iValueList;
	double fValue, fMinValue, fMaxValue, *fValueList;
	gchar *cValue, **cValueList;
	
	gchar *cDirPath = g_path_get_dirname (cConfFilePath);
	gchar *cMessagesFilePath = g_strconcat (cDirPath, "/messages", NULL);
	FILE *f = fopen (cMessagesFilePath, "a");
	if (!f)
		g_error ("impossible d'ouvrir %s", cMessagesFilePath);
	
	i = 0;
	cGroupName = pGroupList[0];
	if (cGroupName != NULL && strcmp (cGroupName, "ChangeLog") == 0)
	{
		pKeyList = g_key_file_get_keys (pKeyFile, cGroupName, NULL, NULL);
		j = 0;
		while (pKeyList[j] != NULL)
		{
			cKeyName = pKeyList[j];
			cValue = g_key_file_get_string (pKeyFile, cGroupName, cKeyName, NULL);
			write_message (cValue);
			g_free (cValue);
			j ++;
		}
		g_strfreev (pKeyList);
	}
	else
	while (pGroupList[i] != NULL)
	{
		cGroupName = pGroupList[i];
		write_message (cGroupName);
		
		pKeyList = g_key_file_get_keys (pKeyFile, cGroupName, NULL, NULL);
		
		j = 0;
		while (pKeyList[j] != NULL)
		{
			cKeyName = pKeyList[j];

			cKeyComment =  g_key_file_get_comment (pKeyFile, cGroupName, cKeyName, NULL);
			//g_print ("%s -> %s\n", cKeyName, cKeyComment);
			if (cKeyComment != NULL && strcmp (cKeyComment, "") != 0)
			{
				cUsefulComment = cKeyComment;
				while (*cUsefulComment == '#' || *cUsefulComment == ' ')  // on saute les # et les espaces.
					cUsefulComment ++;

				iElementType = *cUsefulComment;
				cUsefulComment ++;

				if (! g_ascii_isdigit (*cUsefulComment) && *cUsefulComment != '[')
				{
					cUsefulComment ++;
				}
				
				if (g_ascii_isdigit (*cUsefulComment))
				{
					iNbElements = atoi (cUsefulComment);
					g_return_val_if_fail (iNbElements > 0, 1);
					while (g_ascii_isdigit (*cUsefulComment))
						cUsefulComment ++;
				}
				else
				{
					iNbElements = 1;
				}
				//g_print ("%d element(s)\n", iNbElements);

				while (*cUsefulComment == ' ')  // on saute les espaces.
					cUsefulComment ++;

				if (*cUsefulComment == '[')
				{
					cUsefulComment ++;
					cAuthorizedValuesChain = cUsefulComment;

					while (*cUsefulComment != '\0' && *cUsefulComment != ']')
						cUsefulComment ++;
					g_return_val_if_fail (*cUsefulComment != '\0', 1);
					*cUsefulComment = '\0';
					cUsefulComment ++;
					while (*cUsefulComment == ' ')  // on saute les espaces.
						cUsefulComment ++;

					pAuthorizedValuesList = g_strsplit (cAuthorizedValuesChain, ";", 0);
				}
				else
				{
					pAuthorizedValuesList = NULL;
				}
				if (cUsefulComment[strlen (cUsefulComment) - 1] == '\n')
					cUsefulComment[strlen (cUsefulComment) - 1] = '\0';
				if (cUsefulComment[strlen (cUsefulComment) - 1] == '/')
				{
					bIsAligned = FALSE;
					cUsefulComment[strlen (cUsefulComment) - 1] = '\0';
				}
				else
				{
					bIsAligned = TRUE;
				}
				//g_print ("cUsefulComment : %s\n", cUsefulComment);

				pTipString = strchr (cUsefulComment, '{');
				if (pTipString != NULL)
				{
					if (*(pTipString-1) == '\n')
						*(pTipString-1) ='\0';
					else
						*pTipString = '\0';

					pTipString ++;

					gchar *pTipEnd = strrchr (pTipString, '}');
					if (pTipEnd != NULL)
						*pTipEnd = '\0';
				}

				if (pTipString != NULL)
				{
					//g_print ("pTipString : '%s'\n", pTipString);
					write_message (pTipString);
				}

				if (*cUsefulComment != '\0' && strcmp (cUsefulComment, "...") != 0 && iElementType != 'F' && iElementType != 'X')
				{
					write_message (cUsefulComment);
				}
				
				switch (iElementType)
				{
					case CAIRO_DOCK_WIDGET_CHECK_BUTTON :
					
					case CAIRO_DOCK_WIDGET_SPIN_INTEGER :  
					case CAIRO_DOCK_WIDGET_HSCALE_INTEGER :
					case CAIRO_DOCK_WIDGET_SIZE_INTEGER :  
					
					case CAIRO_DOCK_WIDGET_SPIN_DOUBLE :
					case CAIRO_DOCK_WIDGET_COLOR_SELECTOR_RGB : 
					case CAIRO_DOCK_WIDGET_COLOR_SELECTOR_RGBA :
					case CAIRO_DOCK_WIDGET_HSCALE_DOUBLE :
					
					case CAIRO_DOCK_WIDGET_STRING_ENTRY :
					case CAIRO_DOCK_WIDGET_PASSWORD_ENTRY :
					case CAIRO_DOCK_WIDGET_FILE_SELECTOR :
					case CAIRO_DOCK_WIDGET_FOLDER_SELECTOR :  
					case CAIRO_DOCK_WIDGET_SOUND_SELECTOR :
					case CAIRO_DOCK_WIDGET_FONT_SELECTOR :
					case CAIRO_DOCK_WIDGET_SHORTKEY_SELECTOR :
					
					case CAIRO_DOCK_WIDGET_TREE_VIEW_SORT_AND_MODIFY :  // rien a faire car les choix sont modifiables.
					
					case CAIRO_DOCK_WIDGET_VIEW_LIST :
					case CAIRO_DOCK_WIDGET_THEME_LIST :
					case CAIRO_DOCK_WIDGET_THEME_LIST_ENTRY :
					case CAIRO_DOCK_WIDGET_USER_THEME_SELECTOR :
					case CAIRO_DOCK_WIDGET_THEME_SELECTOR :
					case CAIRO_DOCK_WIDGET_ANIMATION_LIST :
					case CAIRO_DOCK_WIDGET_DIALOG_DECORATOR_LIST :
					case CAIRO_DOCK_WIDGET_DESKLET_DECORATION_LIST :
					case CAIRO_DOCK_WIDGET_DESKLET_DECORATION_LIST_WITH_DEFAULT :
					case CAIRO_DOCK_WIDGET_GAUGE_LIST :
					case CAIRO_DOCK_WIDGET_DOCK_LIST :
					case CAIRO_DOCK_WIDGET_JUMP_TO_MODULE :
					case CAIRO_DOCK_WIDGET_JUMP_TO_MODULE_IF_EXISTS :
					
					case CAIRO_DOCK_WIDGET_EMPTY_WIDGET :
					case CAIRO_DOCK_WIDGET_TEXT_LABEL :
					case CAIRO_DOCK_WIDGET_SEPARATOR :
					break;
					
					case CAIRO_DOCK_WIDGET_LIST :
					case CAIRO_DOCK_WIDGET_NUMBERED_LIST :  
					case CAIRO_DOCK_WIDGET_LIST_WITH_ENTRY :
					case CAIRO_DOCK_WIDGET_TREE_VIEW_SORT :
					case CAIRO_DOCK_WIDGET_TREE_VIEW_MULTI_CHOICE :
						if (pAuthorizedValuesList != NULL)
						{
							for (k = 0; pAuthorizedValuesList[k] != NULL; k ++)
							{
								write_message (pAuthorizedValuesList[k]);
							}
						}
					break;
					
					case CAIRO_DOCK_WIDGET_FRAME :
					case CAIRO_DOCK_WIDGET_EXPANDER :
						if (pAuthorizedValuesList != NULL)
						{
							if (pAuthorizedValuesList[0] == NULL || *pAuthorizedValuesList[0] == '\0')
								cValue = g_key_file_get_string (pKeyFile, cGroupName, cKeyName, NULL);
							else
								cValue = pAuthorizedValuesList[0];
							write_message (cValue);
						}
					break;
					
					default :
						g_print ("this conf file seems to be incorrect ! (type : %c)\n", iElementType);
					break ;
				}
				g_strfreev (pAuthorizedValuesList);
				g_free (cKeyComment);
			}

			j ++;
		}
		g_strfreev (pKeyList);

		i ++;
	}
	
	g_strfreev (pGroupList);
	fclose (f);
	return 0;
}
Esempio n. 9
0
void
img_load_slideshow( img_window_struct *img,
					const gchar       *input )
{
	GdkPixbuf *thumb;
	slide_struct *slide_info;
	GtkTreeIter iter;
	GKeyFile *img_key_file;
	gchar *dummy, *slide_filename, *time;
	GtkWidget *dialog;
	gint number,i,transition_id, duration, no_points, previous_nr_of_slides;
	guint speed;
	GtkTreeModel *model;
	void (*render);
	GHashTable *table;
	gchar      *spath, *conf;
	gdouble    *color, *font_color, *font_bgcolor;
	gboolean    old_file = FALSE;
	gboolean    first_slide = TRUE;
    gchar      *video_config_name, *aspect_ratio, *fps;
    gint        old_video_size, bitrate;

	/* Cretate new key file */
	img_key_file = g_key_file_new();
	if( ! g_key_file_load_from_file( img_key_file, input,
									 G_KEY_FILE_KEEP_COMMENTS, NULL ) )
	{
		g_key_file_free( img_key_file );
		return;
	}

	/* Are we able to load this project? */
	dummy = g_key_file_get_comment( img_key_file, NULL, NULL, NULL);

	if( strncmp( dummy, comment_string, strlen( comment_string ) ) != 0 )
	{
		/* Enable loading of old projects too */
		if( strncmp( dummy, old_comment_string,
					 strlen( old_comment_string ) ) != 0 )
		{
			dialog = gtk_message_dialog_new(
						GTK_WINDOW( img->imagination_window ), GTK_DIALOG_MODAL,
						GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
						_("This is not an Imagination project file!") );
			gtk_window_set_title( GTK_WINDOW( dialog ), "Imagination" );
			gtk_dialog_run( GTK_DIALOG( dialog ) );
			gtk_widget_destroy( GTK_WIDGET( dialog ) );
			g_free( dummy );
			return;
		}
		old_file = TRUE;
	}
	g_free( dummy );

	/* Create hash table for efficient searching */
	table = g_hash_table_new_full( g_direct_hash, g_direct_equal,
								   NULL, g_free );
	model = gtk_combo_box_get_model( GTK_COMBO_BOX( img->transition_type ) );
	gtk_tree_model_foreach( model,
							(GtkTreeModelForeachFunc)img_populate_hash_table,
							&table );

	/* Set the slideshow options */
    /* Video Format, first check if we have a buggy, old file format (imagination <= 3.0) */
    old_video_size = g_key_file_get_integer(img_key_file, "slideshow settings", "video format", NULL);
    if (old_video_size != 0)
    {
        img_message(img, FALSE, "Old imagination project file, guessing format as VOB");
        img->video_format_index = 0; /* index for VOB format*/

        for (i = 0;
             video_format_list[0].sizelist[i].name != NULL
             && video_format_list[0].sizelist[i].y != old_video_size;
             i++);
        if (video_format_list[0].sizelist[i].name != NULL)
        {
            img->video_size[0] = video_format_list[0].sizelist[i].x;
            img->video_size[1] = old_video_size;
        }
        else /* we could not find the appropriate format, so we guess 4:3 format */
        {
            img->video_size[0] = old_video_size * 4 / 3;
            img->video_size[1] = old_video_size;
        }

        /* Guess fps from video size */
        if (img->video_size[1] == 576)
            img->fps_index = 1; /* NTSC */
        else
            img->fps_index = 0; /* PAL */
        img->export_fps = video_format_list[img->video_format_index].fps_list[img->fps_index].value;

        /* set other parameters to defaults, as they can't be checked */
        img->aspect_ratio_index = 0;    /* 4:3 */
        img->bitrate_index = 0;         /* Not used in vob */

    }
    else
    {
        /* Video Codec */
        video_config_name = g_key_file_get_string(img_key_file, "slideshow settings",
                                "video codec", NULL);
        i = 0;
        while (video_config_name != NULL
                && video_format_list[i].name != NULL
                && strcmp (video_format_list[i].config_name, video_config_name) != 0)
            i++;
        if (video_config_name == NULL || video_format_list[i].name == NULL)
        {
            img_message(img, FALSE, "Could not find a video format, guessing VOB\n");
            img->video_format_index = 0; /* index for VOB format*/
        }
        else
            img->video_format_index = i;

        /* Video Size */
        img->video_size[0] = g_key_file_get_integer(img_key_file, "slideshow settings",
                                "video width", NULL);
        img->video_size[1] = g_key_file_get_integer(img_key_file, "slideshow settings",
                                "video height", NULL);

        /* fps */
        fps = g_key_file_get_string(img_key_file, "slideshow settings", "fps", NULL);
        i = 0;
        while (fps != NULL
                && strcmp (video_format_list[img->video_format_index].fps_list[i].name, fps) != 0)
            i++;

        if (fps == NULL
            || video_format_list[img->video_format_index].fps_list[i].name == NULL)
        {
            img_message(img, FALSE, "Could not find a fps, set to default\n");
            img->fps_index = 0; /* index for VOB format*/
        }
        else
            img->fps_index = i;
        img->export_fps = video_format_list[img->video_format_index].fps_list[img->fps_index].value;

        /* Aspect ratio */
        if (NULL != video_format_list[img->video_format_index].aspect_ratio_list)
        {
            aspect_ratio = g_key_file_get_string(img_key_file, "slideshow settings",
                                    "aspect ratio", NULL);
            i = 0;
            while (aspect_ratio != NULL
                   && video_format_list[img->video_format_index].aspect_ratio_list[i].name != NULL
                   && strcmp (video_format_list[img->video_format_index].aspect_ratio_list[i].name, aspect_ratio) != 0)
                i++;

            if (aspect_ratio == NULL
                || video_format_list[img->video_format_index].aspect_ratio_list[i].name == NULL)
                {
                    img_message(img, FALSE, "Could not find an aspect ratio, set to default\n");
                    img->aspect_ratio_index = 0; /* index for VOB format*/
                }
                else
                    img->aspect_ratio_index = i;
        }
        
        /* Bitrate */
        if (NULL != video_format_list[img->video_format_index].bitratelist)
        {
            bitrate = g_key_file_get_integer(img_key_file, "slideshow settings",
                                    "bitrate", NULL);
            i = 0;
            while (video_format_list[img->video_format_index].bitratelist[i].name != NULL
                   && video_format_list[img->video_format_index].bitratelist[i].value != bitrate)
                i++;

            if (video_format_list[img->video_format_index].bitratelist[i].name == NULL)
                {
                    img_message(img, FALSE, "Could not find a bitrate, set to default\n");
                    img->bitrate_index = 0; /* index for VOB format*/
                }
                else
                    img->bitrate_index = i;
        }

    }

    img_zoom_fit(NULL, img);

	/* Make loading more efficient by removing model from icon view */
	g_object_ref( G_OBJECT( img->thumbnail_model ) );
	gtk_icon_view_set_model( GTK_ICON_VIEW( img->thumbnail_iconview ), NULL );
	gtk_icon_view_set_model( GTK_ICON_VIEW( img->over_icon ), NULL );

	/* Enable loading of old projects too */
	if( old_file )
	{
		guint32 tmp;
		dummy = g_key_file_get_string( img_key_file, "slideshow settings",
									   "background color", NULL );
		tmp = (guint32)strtoul( dummy, NULL, 16 );
		img->background_color[0] = (gdouble)( ( tmp >> 24 ) & 0xff ) / 0xff;
		img->background_color[1] = (gdouble)( ( tmp >> 16 ) & 0xff ) / 0xff;
		img->background_color[2] = (gdouble)( ( tmp >>  8 ) & 0xff ) / 0xff;

		/* Loads the thumbnails and set the slides info */
		number = g_key_file_get_integer(img_key_file,"images","number", NULL);

		/* Store the previous number of slides and set img->slides_nr so to have the correct number of slides displayed on the status bar */
		previous_nr_of_slides = img->slides_nr;
		img->slides_nr = number;
		gtk_widget_show(img->progress_bar);
		for (i = 1; i <= number; i++)
		{
			dummy = g_strdup_printf("image_%d",i);
			slide_filename = g_key_file_get_string(img_key_file,"images",dummy, NULL);

			if( img_scale_image( slide_filename, img->video_ratio, 88, 0,
								 img->distort_images, img->background_color,
								 &thumb, NULL ) )
			{
				GdkPixbuf *pix;

				speed 	=		g_key_file_get_integer(img_key_file, "transition speed",	dummy, NULL);
				duration= 		g_key_file_get_integer(img_key_file, "slide duration",		dummy, NULL);
				transition_id = g_key_file_get_integer(img_key_file, "transition type",		dummy, NULL);

				/* Get the mem address of the transition */
				spath = (gchar *)g_hash_table_lookup( table, GINT_TO_POINTER( transition_id ) );
				if (spath)
				{
					gtk_tree_model_get_iter_from_string( model, &iter, spath );
					gtk_tree_model_get( model, &iter, 2, &render, 0, &pix, -1 );
				}
				slide_info = img_create_new_slide();
				if( slide_info )
				{
					img_set_slide_file_info( slide_info, slide_filename );
					gtk_list_store_append( img->thumbnail_model, &iter );
					gtk_list_store_set( img->thumbnail_model, &iter, 0, thumb, 1, slide_info, -1 );
					g_object_unref( G_OBJECT( thumb ) );

					/* Set non-default data */
					img_set_slide_still_info( slide_info, duration, img );
					img_set_slide_transition_info( slide_info,
												   img->thumbnail_model, &iter,
												   pix, spath, transition_id,
												   render, speed, img );
					g_object_unref( G_OBJECT( pix ) );

					/* Increment slide counter */
					img->slides_nr++;

					/* If we're loading the first slide, apply some of it's
				 	 * data to final pseudo-slide */
					if( first_slide )
					{
						first_slide = FALSE;
						img->final_transition.speed  = slide_info->speed;
						img->final_transition.render = slide_info->render;
					}
				}
			}

			img_increase_progressbar(img, i);
			g_free(slide_filename);
			g_free(dummy);
		}
	}
	else
	{
void cairo_dock_replace_key_values (GKeyFile *pOriginalKeyFile, GKeyFile *pReplacementKeyFile, gboolean bUseOriginalKeys, gchar iIdentifier)
{
	g_print ("%s (%d, %d)\n", __func__, iIdentifier, bUseOriginalKeys);
	GError *erreur = NULL;
	gsize length = 0;
	gchar **pKeyList;
	gchar **pGroupList = g_key_file_get_groups ((bUseOriginalKeys ? pOriginalKeyFile : pReplacementKeyFile), &length);
	g_return_if_fail (pGroupList != NULL);
	gchar *cGroupName, *cKeyName, *cKeyValue, *cComment;
	int i, j;

	i = 0;
	while (pGroupList[i] != NULL)
	{
		cGroupName = pGroupList[i];

		length = 0;
		pKeyList = g_key_file_get_keys ((bUseOriginalKeys ? pOriginalKeyFile : pReplacementKeyFile), cGroupName, NULL, NULL);
		g_return_if_fail (pKeyList != NULL);
		
		j = 0;
		while (pKeyList[j] != NULL)
		{
			cKeyName = pKeyList[j];
			//g_print ("%s\n  %s", cKeyName, g_key_file_get_comment (pOriginalKeyFile, cGroupName, cKeyName, NULL));

			if (iIdentifier != 0)
			{
				cComment = g_key_file_get_comment (bUseOriginalKeys ? pOriginalKeyFile : pReplacementKeyFile, cGroupName, cKeyName, NULL);
				//g_print ("%s\n  %s", cKeyName, cComment);
				if (cComment == NULL || strlen (cComment) < 2 || cComment[1] != iIdentifier)
				{
					//g_print ("  on saute %s;%s (%s)\n", cGroupName, cKeyName, cComment);
					g_free (cComment);
					j ++;
					continue ;
				}
				g_free (cComment);
			}

			cKeyValue =  g_key_file_get_string (pReplacementKeyFile, cGroupName, cKeyName, &erreur);
			if (erreur != NULL)
			{
				cd_warning (erreur->message);
				g_error_free (erreur);
				erreur = NULL;
			}
			else
			{
				//g_print (" -> %s\n", cKeyValue);
				if (cKeyValue[strlen(cKeyValue) - 1] == '\n')
					cKeyValue[strlen(cKeyValue) - 1] = '\0';
				g_key_file_set_string (pOriginalKeyFile, cGroupName, cKeyName, (cKeyValue != NULL ? cKeyValue : ""));
			}
			g_free (cKeyValue);
			j ++;
		}

		g_strfreev (pKeyList);
		i ++;
	}
	g_strfreev (pGroupList);
	
	if (bUseOriginalKeys)
	{
		pGroupList = g_key_file_get_groups (pReplacementKeyFile, &length);
		i = 0;
		while (pGroupList[i] != NULL)
		{
			cGroupName = pGroupList[i];

			length = 0;
			pKeyList = g_key_file_get_keys (pReplacementKeyFile, cGroupName, NULL, NULL);

			j = 0;
			while (pKeyList[j] != NULL)
			{
				cKeyName = pKeyList[j];
				//g_print ("%s\n  %s", cKeyName, g_key_file_get_comment (pOriginalKeyFile, cGroupName, cKeyName, NULL));

				cComment = g_key_file_get_comment (pReplacementKeyFile, cGroupName, cKeyName, NULL);
				if (cComment == NULL || strlen (cComment) < 3 || (cComment[1] != '0' && cComment[2] != '0'))
				{
					g_free (cComment);
					j ++;
					continue ;
				}
				if (iIdentifier != 0)
				{
					if (cComment == NULL || strlen (cComment) < 2 || cComment[1] != iIdentifier)
					{
						//g_print ("  on saute %s;%s (%s)\n", cGroupName, cKeyName, cComment);
						g_free (cComment);
						j ++;
						continue ;
					}
				}

				cKeyValue =  g_key_file_get_string (pReplacementKeyFile, cGroupName, cKeyName, &erreur);
				if (erreur != NULL)
				{
					cd_warning (erreur->message);
					g_error_free (erreur);
					erreur = NULL;
				}
				else
				{
					//g_print (" -> %s\n", cKeyValue);
					if (cKeyValue[strlen(cKeyValue) - 1] == '\n')
						cKeyValue[strlen(cKeyValue) - 1] = '\0';
					g_key_file_set_string (pOriginalKeyFile, cGroupName, cKeyName, (cKeyValue != NULL ? cKeyValue : ""));
					if (cComment != NULL)
					{
						g_key_file_set_comment (pOriginalKeyFile, cGroupName, cKeyName, cComment, &erreur);
						if (erreur != NULL)
						{
							cd_warning (erreur->message);
							g_error_free (erreur);
							erreur = NULL;
						}
					}
				}
				g_free (cKeyValue);
				g_free (cComment);
				j ++;
			}

			g_strfreev (pKeyList);
			i ++;
		}
		g_strfreev (pGroupList);
	}
}