static gboolean
gtk_hotkey_key_file_registry_real_store_hotkey (GtkHotkeyRegistry	*base,
											  GtkHotkeyInfo		*info,
											  GError			**error)
{
	GKeyFile					*keyfile;
	GFile						*file, *home;
	GError						*tmp_error;
	gchar						*file_path, *group;
	
	
	g_return_val_if_fail (GTK_HOTKEY_IS_INFO (info), FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
	
	/* Make sure we have our root dir */
	home = get_hotkey_home ();
	if (!g_file_query_exists(home, NULL)) {
		tmp_error = NULL;
		if (!g_file_make_directory (home, NULL, &tmp_error)) {
			g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
						 GTK_HOTKEY_REGISTRY_ERROR_IO,
						 "Failed to create hotkey configuration dir "
						HOTKEY_HOME": %s", tmp_error->message);
			g_error_free (tmp_error);
			g_object_unref (home);
			return FALSE;
		}
	}
	
	/* Now load any old contents of the keyfile */
	file = get_hotkey_file (gtk_hotkey_info_get_application_id (info));
	file_path = g_file_get_path (file);
	keyfile = g_key_file_new ();
	
	tmp_error = NULL;
	if (!g_key_file_load_from_file (keyfile, file_path, 0, &tmp_error)) {
		if (tmp_error->code == G_KEY_FILE_ERROR_PARSE) {
			g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
						 GTK_HOTKEY_REGISTRY_ERROR_MALFORMED_MEDIUM,
						 "The file %s is not in a valid key-file format: %s",
						 file_path, tmp_error->message);
			goto clean_up;
		}
		/* Ignore other errors */
		g_error_free (tmp_error);
	}
	
	/* Prepare keyfile data */
	group = g_strconcat (HOTKEY_GROUP, gtk_hotkey_info_get_key_id (info), NULL);
	
	g_key_file_set_string (keyfile, group, "Owner",
						   gtk_hotkey_info_get_application_id (info));
	g_key_file_set_string (keyfile, group, "Signature",
						   gtk_hotkey_info_get_signature (info));
	
	if (gtk_hotkey_info_get_description (info))
		g_key_file_set_string (keyfile, group, "Description",
							   gtk_hotkey_info_get_description (info));
	
	if (gtk_hotkey_info_get_app_info (info)) {
		GAppInfo *ai = gtk_hotkey_info_get_app_info (info);
		g_key_file_set_string (keyfile, group, "AppInfo",
							   g_app_info_get_id (ai));
	}
	
	gsize size;
	gchar *contents;
	tmp_error = NULL;
	contents = g_key_file_to_data (keyfile, &size, &tmp_error);
	if (tmp_error) {
		g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
					 GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN,
					 "Failed to generate keyfile contents: %s",
					 tmp_error->message);
		goto clean_up;
	}
	
	/* Write the actual data */
	g_file_set_contents (file_path, contents, size, &tmp_error);
	if (tmp_error) {
		g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
					 GTK_HOTKEY_REGISTRY_ERROR_IO,
					 "Failed to write keyfile '%s': %s",
					 file_path, tmp_error->message);
		goto clean_up;
	}
	
	clean_up:
		if (tmp_error) g_error_free (tmp_error);
		g_free (file_path);
		if (group) g_free (group);
		g_key_file_free (keyfile);
		g_object_unref (file);
		g_object_unref (home);
	
	if (*error)
		return FALSE;
	
	g_return_val_if_fail (GTK_HOTKEY_IS_INFO (info), FALSE);
	gtk_hotkey_registry_hotkey_stored (base, info);
	return TRUE;
}
Example #2
0
guint
gpc_queue_store_request (GPilotRequest req)
{
	guint num;
	guint32 handle_num;
	gchar *section = NULL;
	GKeyFile *kfile;

	set_section (req.pilot_id, req.type, &section);

	kfile = get_queue_kfile ();

	num = g_key_file_get_integer (kfile, section, NUMREQ, NULL);
	num++;
	g_key_file_set_integer (kfile, section, NUMREQ, num);
	g_free (section);

	section = NULL;
	handle_num = set_section_num (req.pilot_id, req.type, &section, num);
  
	switch (req.type) {
	case GREQ_INSTALL: 
		g_key_file_set_string (kfile, section, ENT_TYPE, "GREQ_INSTALL"); 
		g_key_file_set_string (kfile, section, ENT_FILENAME, req.parameters.install.filename);
		g_key_file_set_string (kfile, section, ENT_DESCRIPTION, req.parameters.install.description);
		break;
	case GREQ_RESTORE: 
		g_key_file_set_string (kfile, section, ENT_TYPE, "GREQ_RESTORE"); 
		g_key_file_set_string (kfile, section, ENT_DIRECTORY, req.parameters.restore.directory);
		break;
	case GREQ_CONDUIT: 
		g_message ("req.parameters.conduit.name = %s", req.parameters.conduit.name);
		g_key_file_set_string (kfile, section, ENT_TYPE, "GREQ_CONDUIT"); 
		g_key_file_set_string (kfile, section, ENT_CONDUIT, req.parameters.conduit.name);
		g_key_file_set_string (kfile, section, ENT_HOW,
				       gnome_pilot_conduit_sync_type_int_to_str (req.parameters.conduit.how));
		break;
	case GREQ_NEW_USERINFO: 
		g_key_file_set_string (kfile, section, ENT_TYPE, "GREQ_NEW_USERINFO"); 
		g_key_file_set_string (kfile, section, ENT_DEVICE, req.cradle);
		g_key_file_set_string (kfile, section, ENT_USER_ID, req.parameters.set_userinfo.user_id);
		g_key_file_set_integer (kfile, section, ENT_PILOT_ID, req.parameters.set_userinfo.pilot_id);
		break;
	case GREQ_SET_USERINFO: 
		g_key_file_set_string (kfile, section, ENT_TYPE, "GREQ_SET_USERINFO"); 
		g_key_file_set_string (kfile, section, ENT_DEVICE, req.cradle);
		g_key_file_set_string (kfile, section, ENT_PASSWORD, req.parameters.set_userinfo.password);
		g_key_file_set_string (kfile, section, ENT_USER_ID, req.parameters.set_userinfo.user_id);
		g_key_file_set_integer (kfile, section, ENT_PILOT_ID, req.parameters.set_userinfo.pilot_id);
		g_key_file_set_boolean (kfile, section, ENT_CONT_SYNC, req.parameters.set_userinfo.continue_sync);
		break;
	case GREQ_GET_USERINFO: 
		g_key_file_set_string (kfile, section, ENT_TYPE, "GREQ_GET_USERINFO"); 
		g_key_file_set_string (kfile, section, ENT_DEVICE,req.cradle);
		break;
	case GREQ_GET_SYSINFO: 
		g_key_file_set_string (kfile, section, ENT_TYPE, "GREQ_GET_SYSINFO"); 
		g_key_file_set_string (kfile, section, ENT_DEVICE, req.cradle);
		break;
	default: 
		g_assert_not_reached ();
		break;
	}
	g_key_file_set_integer (kfile, section, ENT_TIMEOUT, req.timeout);
	g_key_file_set_integer (kfile, section, ENT_HANDLE, handle_num);
	g_key_file_set_string (kfile, section, ENT_CLIENT_ID, req.client_id);
    
	g_free (section);
	save_queue_kfile (kfile);
	g_key_file_free (kfile);

	LOG (("assigned handle num %u",handle_num));
	return handle_num;
}
Example #3
0
void
plugin_themes_close(void)
{
    g_key_file_free(themes);
    themes = NULL;
}
Example #4
0
/* Called by Geany to initialize the plugin */
void plugin_init(GeanyData G_GNUC_UNUSED *data)
{
	GKeyFile *config = g_key_file_new();
	gchar *config_file_old = NULL;
	gchar *config_dir = NULL;
	gchar *config_dir_old = NULL;
	gchar *kb_label = _("Send file by mail");
	GtkWidget *menu_mail = NULL;
	GeanyKeyGroup *key_group;

	config_file = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S, "plugins", G_DIR_SEPARATOR_S,
		"sendmail", G_DIR_SEPARATOR_S, "mail.conf", NULL);

	#ifndef G_OS_WIN32
	/* We try only to move if we are on not Windows platform */
	config_file_old = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S,
		"plugins", G_DIR_SEPARATOR_S,
		"geanysendmail", G_DIR_SEPARATOR_S, "mail.conf", NULL);
	config_dir = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S,
		"plugins", G_DIR_SEPARATOR_S, "sendmail", NULL);
	config_dir_old = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S,
		"plugins", G_DIR_SEPARATOR_S, "geanysendmail", NULL);

	if (g_file_test(config_file_old, G_FILE_TEST_EXISTS))
	{
		if (dialogs_show_question(
			_("Renamed plugin detected!\n"
			  "\n"
			  "GeanySendMail has been renamed to sendmail -- you surely have "
			  "already recognised it. \n"
			  "Geany is able to migrate your old plugin configuration by "
			  "moving the old configuration file to new location.\n"
			  "Move now?")))
		{
			if (g_rename(config_dir_old, config_dir) == 0)
			{
				dialogs_show_msgbox(GTK_MESSAGE_INFO,
					_("Your configuration directory has been "
					  "successfully moved from \"%s\" to \"%s\"."),
					config_dir_old, config_dir);
			}
			else
			{
				/* If there was an error on migrating we need
				 * to load from original one.
				 * When saving new configuration it will go to
				 * new folder so migration should
				 * be implicit. */
				g_free(config_file);
				config_file = g_strdup(config_file_old);
				dialogs_show_msgbox(
					GTK_MESSAGE_WARNING,
					_("Your old configuration directory \"%s\" could "
					  "not be moved to \"%s\" (%s). "
					  "Please move manually the directory to the new location."),
					config_dir_old,
					config_dir,
					g_strerror(errno));
			}
		}
	}

	g_free(config_dir_old);
	g_free(config_dir);
	g_free(config_file_old);
	#endif

	/* Initialising options from config file */
	g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL);
	mailer = g_key_file_get_string(config, "tools", "mailer", NULL);
	address = g_key_file_get_string(config, "tools", "address", NULL);
	use_address_dialog = g_key_file_get_boolean(config, "tools", "address_usage", NULL);
	icon_in_toolbar = g_key_file_get_boolean(config, "icon", "show_icon", NULL);

	g_key_file_free(config);

	add_stock_item();
	if (icon_in_toolbar == TRUE)
	{
		show_icon();
	}

	/* Build up menu entry */
	menu_mail = gtk_menu_item_new_with_mnemonic(_("_Mail document"));
	gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), menu_mail);
	gtk_widget_set_tooltip_text(menu_mail,
		_("Sends the opened file as unzipped attachment by any mailer from your $PATH"));
	g_signal_connect(G_OBJECT(menu_mail), "activate", G_CALLBACK(send_as_attachment), NULL);

	/* setup keybindings */
	key_group = plugin_set_key_group(geany_plugin, "sendmail", COUNT_KB, NULL);
	keybindings_set_item(key_group, SENDMAIL_KB, key_send_as_attachment,
		0, 0, "send_file_as_attachment", kb_label, menu_mail);

	gtk_widget_show_all(menu_mail);
	ui_add_document_sensitive(menu_mail);
	main_menu_item = menu_mail;
}
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));
        }
    }
Example #6
0
static void
_app_info_set_from_desktop_file (OlAppInfo *info,
                                 enum OlAppInfoFlags flags)
{
  GList *path_list = _get_desktop_file_path_list ();
  gchar *filename = _find_file_in_path_list (path_list,
                                             info->binfile,
                                             ".desktop",
                                             (flags & OL_APP_INFO_WITH_PREFIX) != 0,
                                             NULL);
  if (!filename)
  {
    ol_debugf ("Cannot find desktop file for %s\n", info->binfile);
    return;
  }
  GKeyFile *keyfile = g_key_file_new ();
  GError *error = NULL;
  if (!g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, &error))
  {
    ol_errorf ("Cannot open desktop file %s: %s\n", filename, error->message);
    g_error_free (error);
  }
  else
  {
    if (flags & OL_APP_INFO_USE_DESKTOP_NAME)
    {
      gchar *name = g_key_file_get_locale_string (keyfile,
                                                  G_KEY_FILE_DESKTOP_GROUP,
                                                  G_KEY_FILE_DESKTOP_KEY_NAME,
                                                  NULL,
                                                  NULL);
      if (name != NULL)
      {
        if (info->name != NULL)
          g_free (info->name);
        info->name = name;
      }
    }
    if (flags & OL_APP_INFO_USE_DESKTOP_CMDLINE)
    {
      gchar *cmdline = g_key_file_get_locale_string (keyfile,
                                                     G_KEY_FILE_DESKTOP_GROUP,
                                                     G_KEY_FILE_DESKTOP_KEY_EXEC,
                                                     NULL,
                                                     NULL);
      if (cmdline != NULL)
      {
        if (info->cmdline != NULL)
          g_free (info->cmdline);
        info->cmdline = cmdline;
      }
    }
    if (flags & OL_APP_INFO_USE_DESKTOP_ICON)
    {
      gchar *icon_name = g_key_file_get_locale_string (keyfile,
                                                       G_KEY_FILE_DESKTOP_GROUP,
                                                       G_KEY_FILE_DESKTOP_KEY_ICON,
                                                       NULL,
                                                       NULL);
      GIcon *icon = _icon_new_from_name (icon_name);
      if (icon != NULL)
      {
        if (info->icon != NULL)
          g_object_unref (info->icon);
        info->icon = icon;
      }
    }
    info->should_show = !g_key_file_get_boolean (keyfile,
                                                 G_KEY_FILE_DESKTOP_GROUP,
                                                 G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY,
                                                 NULL);
  }
  g_free (filename);
  g_key_file_free (keyfile);
}
Example #7
0
/**
 * load the config file
 * it uses the glib config utils after 0.6.0
 * if cannot load, try the xml file before that version
 *
 * \param
 *
 * \return TRUE if ok, FALSE if not found, usually for a new opening
 * */
gboolean gsb_file_config_load_config ( void )
{
    GKeyFile *config;
    gboolean result;
    const gchar *filename;
    gchar *name;
    gint i;
    gint int_ret;
    GError* err = NULL;

    gsb_file_config_clean_config ();

    filename = gsb_dirs_get_grisbirc_filename ();

    config = g_key_file_new ();

    result = g_key_file_load_from_file ( config,
                        filename,
                        G_KEY_FILE_KEEP_COMMENTS,
                        NULL );

    if ( !result )
        return FALSE;

#if IS_DEVELOPMENT_VERSION == 1
    /* get config model */
    conf.stable_config_file_model = g_key_file_get_integer ( config,
                        "Model",
                        "Stable_config_file_model",
                        NULL );
    if ( conf.stable_config_file_model )
    {
        used_model = TRUE;
        filename = g_strconcat ( gsb_dirs_get_user_config_dir (), PACKAGE, ".conf", NULL );
        if ( !g_file_test (filename, G_FILE_TEST_EXISTS) )
        {
            g_key_file_free ( config );
            return FALSE;
        }

        g_key_file_free (config);
        config = g_key_file_new ();
        result = g_key_file_load_from_file ( config,
                        filename,
                        G_KEY_FILE_KEEP_COMMENTS,
                        NULL );
    }
#endif

    /* get the geometry */
    conf.root_x = g_key_file_get_integer ( config,
                        "Geometry",
                        "Root_x",
                        NULL );

    conf.root_y = g_key_file_get_integer ( config,
                        "Geometry",
                        "Root_y",
                        NULL );

    conf.main_width = g_key_file_get_integer ( config,
                        "Geometry",
                        "Width",
                        NULL );

    conf.main_height = g_key_file_get_integer ( config,
                        "Geometry",
                        "Height",
                        NULL );

    conf.full_screen = g_key_file_get_integer ( config,
                        "Geometry",
                        "Full_screen",
                        NULL );

    conf.maximize_screen = g_key_file_get_integer ( config,
                        "Geometry",
                        "Maximize_screen",
                        NULL );

    /* Remember size of main panel */
    int_ret = g_key_file_get_integer ( config,
                        "Geometry",
                        "Panel_width",
                        &err );
    if ( err == NULL )
        conf.panel_width = int_ret;
    else
    {
        conf.panel_width = -1;
        err = NULL;
    }

    /* preferences size */
    conf.prefs_width = g_key_file_get_integer ( config,
                        "Geometry",
                        "Prefs_width",
                        NULL );

    /* get general */
    conf.r_modifiable = g_key_file_get_integer ( config,
                        "General",
                        "Can modify R",
                        NULL );

    gsb_file_update_last_path ( g_key_file_get_string ( config,
                        "General",
                        "Path",
                        NULL ));

    conf.alerte_permission = g_key_file_get_integer ( config,
                        "General",
                        "Show permission alert",
                        NULL );

    conf.entree = g_key_file_get_integer ( config,
                        "General",
                        "Function of enter",
                        NULL );

    conf.alerte_mini = g_key_file_get_integer ( config,
                        "General",
                        "Show alert messages",
                        NULL );

    conf.utilise_fonte_listes = g_key_file_get_integer ( config,
                        "General",
                        "Use user font",
                        NULL );

    conf.font_string = g_key_file_get_string ( config, "General", "Font name", NULL );

    conf.browser_command = g_key_file_get_string ( config,
                        "General",
                        "Web",
                        NULL );

    conf.pluriel_final = g_key_file_get_integer ( config,
                        "General",
                        "Pluriel_final",
                        NULL );

    conf.metatree_action_2button_press = g_key_file_get_integer ( config,
                        "General",
                        "Metatree_action_2button_press",
                        NULL );

    /* get backup part */
    conf.make_backup = g_key_file_get_integer ( config,
                        "Backup",
                        "Make backup",
                        NULL );

    conf.make_bakup_single_file = g_key_file_get_integer ( config,
                        "Backup",
                        "Make backup single file",
                        NULL );

    conf.make_backup_every_minutes = g_key_file_get_integer ( config,
                        "Backup",
                        "Make backup every x minutes",
                        NULL );

    conf.make_backup_nb_minutes = g_key_file_get_integer ( config,
                        "Backup",
                        "Make backup nb minutes",
                        NULL );

    /* exec gsb_file_automatic_backup_start ( ) if necessary */
    if ( conf.make_backup_every_minutes
     &&
     conf.make_backup_nb_minutes )
        gsb_file_automatic_backup_start ( NULL, NULL );

    conf.compress_backup = g_key_file_get_integer ( config,
                        "Backup",
                        "Compress backup",
                        NULL );

    gsb_file_set_backup_path ( g_key_file_get_string ( config,
                        "Backup",
                        "Backup path",
                        NULL ));

    /* get input/output */
    conf.dernier_fichier_auto = g_key_file_get_integer ( config,
                        "IO",
                        "Load last file",
                        NULL );

    conf.sauvegarde_auto = g_key_file_get_integer ( config,
                        "IO",
                        "Save at closing",
                        NULL );

    conf.sauvegarde_demarrage = g_key_file_get_integer ( config,
                        "IO",
                        "Save at opening",
                        NULL );

    conf.nb_max_derniers_fichiers_ouverts = g_key_file_get_integer ( config,
                        "IO",
                        "Nb last opened files",
                        NULL );

    conf.compress_file = g_key_file_get_integer ( config,
                        "IO",
                        "Compress file",
                        NULL );

    conf.force_enregistrement = g_key_file_get_integer ( config,
                        "IO",
                        "Force saving",
                        NULL );

    tab_noms_derniers_fichiers_ouverts = g_key_file_get_string_list ( config,
                        "IO",
                        "Names last files",
                        &conf.nb_derniers_fichiers_ouverts,
                        NULL );
    if (tab_noms_derniers_fichiers_ouverts)
        nom_fichier_comptes = my_strdup (tab_noms_derniers_fichiers_ouverts [ 0 ]);
    else
        nom_fichier_comptes = NULL;

    conf.check_for_archival = g_key_file_get_integer ( config,
                        "IO",
                        "Check_archival_at_opening",
                        NULL );

    conf.max_non_archived_transactions_for_check = g_key_file_get_integer ( config,
                        "IO",
                        "Max_transactions_before_warn_archival",
                        NULL );

    /* get scheduled section */
    nb_days_before_scheduled = g_key_file_get_integer ( config,
                        "Scheduled",
                        "Days before remind",
                        NULL );

    conf.execute_scheduled_of_month = g_key_file_get_integer ( config,
                        "Scheduled",
                        "Execute scheduled of month",
                        NULL );

    int_ret = g_key_file_get_integer ( config,
                        "Scheduled",
                        "Balances with scheduled",
                        &err );
    if ( err == NULL )
        conf.balances_with_scheduled = int_ret;
    else
        err = NULL;

    conf.group_partial_balance_under_accounts = g_key_file_get_integer ( config,
                        "Scheduled",
                        "Group_partial_balance",
                        NULL );

    /* get shown section */
    conf.formulaire_toujours_affiche = g_key_file_get_integer ( config,
                        "Display",
                        "Show transaction form",
                        NULL );

    conf.show_transaction_selected_in_form = g_key_file_get_integer ( config,
                        "Display",
                        "Show selected transaction in form",
                        NULL );

    conf.show_transaction_gives_balance = g_key_file_get_integer ( config,
                        "Display",
                        "Show transaction gives balance",
                        NULL );

    conf.transactions_list_primary_sorting = g_key_file_get_integer ( config,
                        "Display",
                        "Transactions_list_primary_sorting",
                        NULL );

    conf.transactions_list_secondary_sorting = g_key_file_get_integer ( config,
                        "Display",
                        "Transactions_list_secondary_sorting",
                        NULL );

    conf.affichage_exercice_automatique = g_key_file_get_integer ( config,
                        "Display",
                        "Show automatic financial year",
                        NULL );

    int_ret = g_key_file_get_integer ( config,
                        "Display",
                        "Automatic completion payee",
                        &err );
    if ( err == NULL )
        conf.automatic_completion_payee = int_ret;
    else
        err = NULL;

    conf.limit_completion_to_current_account = g_key_file_get_integer ( config,
                        "Display",
                        "Limit payee completion",
                        NULL );

    conf.automatic_recover_splits = g_key_file_get_integer ( config,
                        "Display",
                        "Automatic_recover_splits",
                        NULL );

    conf.automatic_erase_credit_debit = g_key_file_get_integer ( config,
                        "Display",
                        "Automatic_erase_credit_debit",
                        NULL );

    conf.display_toolbar = g_key_file_get_integer ( config,
                        "Display",
                        "Display toolbar",
                        NULL );

    conf.active_scrolling_left_pane = g_key_file_get_integer ( config,
                        "Display",
                        "Active_scrolling_left_pane",
                        NULL );

    conf.show_headings_bar = g_key_file_get_integer ( config,
                        "Display",
                        "Show headings bar",
                        NULL );

    conf.show_closed_accounts = g_key_file_get_integer ( config,
                        "Display",
                        "Show closed accounts",
                        NULL );

    conf.display_grisbi_title = g_key_file_get_integer ( config,
                        "Display",
                        "Display grisbi title",
                        NULL );

    /* get messages */
    for ( i = 0; messages[i].name; i ++ )
    {
        name = g_strconcat ( messages[i].name , "-answer", NULL );
        messages[i].hidden = g_key_file_get_integer ( config, "Messages",
                        messages[i].name, NULL );
        messages[i].default_answer = g_key_file_get_integer ( config, "Messages",
                        name, NULL );
        g_free ( name );
    }

    for ( i = 0; delete_msg[i].name; i ++ )
    {
        name = g_strconcat ( delete_msg[i].name , "-answer", NULL );
        delete_msg[i].hidden = g_key_file_get_integer ( config, "Messages",
                        delete_msg[i].name, NULL );
        if ( delete_msg[i].hidden == 1 )
            delete_msg[i].default_answer = 1;
        g_free ( name );
    }

    conf.last_tip = g_key_file_get_integer ( config,
                        "Messages",
                        "Last tip",
                        NULL );

    conf.show_tip = g_key_file_get_integer ( config,
                        "Messages",
                        "Show tip",
                        NULL );

    g_key_file_free (config);
    return TRUE;
}
void 
cid_key_file_free(CidMainContainer **pCid) 
{
    g_key_file_free ((*pCid)->pKeyFile);
}
Example #9
0
static gboolean
geoclue_localnet_set_address (GeoclueLocalnet *localnet,
                              GHashTable *details,
                              GError **error)
{
	char *str, *mac;
	GKeyFile *keyfile;
	GError *int_err = NULL;
	localnet_keyfile_group *keyfile_group;
	Gateway *gw;
	
	if (!details) {
		/* TODO set error */
		return FALSE;
	}

	mac = geoclue_connectivity_get_router_mac (localnet->conn);
	if (!mac) {
		g_warning ("Couldn't get current gateway mac address");
		/* TODO set error */
		return FALSE;
	}
	/* reload keyfile just in case it's changed */
	keyfile = g_key_file_new ();
	if (!g_key_file_load_from_file (keyfile, localnet->keyfile_name, 
	                                G_KEY_FILE_NONE, &int_err)) {
		g_warning ("Could not load keyfile %s: %s", 
		         localnet->keyfile_name, int_err->message);
		g_error_free (int_err);
		int_err = NULL;
	}
	
	/* remove old group (if exists) and add new to GKeyFile */
	g_key_file_remove_group (keyfile, mac, NULL);
	
	keyfile_group = g_new0 (localnet_keyfile_group, 1);
	keyfile_group->keyfile = keyfile;
	keyfile_group->group_name = mac;
	g_hash_table_foreach (details, (GHFunc) add_address_detail_to_keyfile, keyfile_group);
	g_free (keyfile_group);
	
	/* save keyfile*/
	str = g_key_file_to_data (keyfile, NULL, &int_err);
	if (int_err) {
		g_warning ("Failed to get keyfile data as string: %s", int_err->message);
		g_error_free (int_err);
		g_key_file_free (keyfile);
		g_free (mac);
		/* TODO set error */
		return FALSE;
	}
	
	g_file_set_contents (localnet->keyfile_name, str, -1, &int_err);
	g_free (str);
	if (int_err) {
		g_warning ("Failed to save keyfile: %s", int_err->message);
		g_error_free (int_err);
		g_key_file_free (keyfile);
		g_free (mac);
		/* TODO set error */
		return FALSE;
	}
	
	/* re-parse keyfile */
	free_gateway_list (localnet->gateways);
	localnet->gateways = NULL;
	geoclue_localnet_load_gateways_from_keyfile (localnet, keyfile);
	g_key_file_free (keyfile);
	
	gw = geoclue_localnet_find_gateway (localnet, mac);
	g_free (mac);
	
	if (gw) {
		gc_iface_address_emit_address_changed (GC_IFACE_ADDRESS (localnet),
		                                       time (NULL), gw->address, gw->accuracy);
	} else {
		/* empty address -- should emit anyway? */
	}
	return TRUE;
}
Example #10
0
/**
 * fs_codec_list_from_keyfile
 * @filename: Name of the #GKeyFile to read the codecs parameters from
 * @error: location of a #GError, or NULL if no error occured
 *
 * Reads the content of a #GKeyFile of the following format into
 * a #GList of #FsCodec structures.
 *
 *
 * Example:
 * |[
 * [audio/codec1]
 * clock-rate=8000
 *
 * [audio/codec1:1]
 * clock-rate=16000
 *
 * [audio/codec2]
 * one_param=QCIF
 * another_param=WOW
 *
 * [video/codec3]
 * wierd_param=42
 * feedback:nack/pli=1
 * feedback:tfrc=
 * ]|
 *
 * Return value: (element-type FsCodec) (transfer full):
 * The #GList of #FsCodec or %NULL if the keyfile was empty or an error occured.
 */
GList *
fs_codec_list_from_keyfile (const gchar *filename, GError **error)
{
  GKeyFile *keyfile = NULL;
  GList *codecs = NULL;
  GError *gerror = NULL;
  gchar **groups = NULL;
  gsize groups_count = 0;
  int i;

  g_return_val_if_fail (filename, NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  keyfile = g_key_file_new ();

  if (!g_key_file_load_from_file (keyfile, filename,
          G_KEY_FILE_NONE, error)) {
    goto out;
  }

  groups = g_key_file_get_groups (keyfile, &groups_count);

  if (!groups)
    goto out;

  for (i=0; i < groups_count && groups[i]; i++) {
    FsCodec *codec;
    gchar **keys = NULL;
    gsize keys_count;
    int j;
    gchar *encoding_name = NULL;
    gchar *next_tok = NULL;
    FsMediaType media_type;

    keys = g_key_file_get_keys (keyfile, groups[i], &keys_count, &gerror);

    if (!keys || gerror) {
      if (gerror)
        GST_WARNING ("Unable to read parameters for %s: %s\n",
            groups[i], gerror->message);
      else
        GST_WARNING ("Unknown errors while reading parameters for %s",
            groups[i]);

      g_clear_error (&gerror);

      goto next_codec;
    }

    next_tok = strchr (groups[i], '/');
    if (!next_tok)
    {
      GST_WARNING ("Invalid codec name: %s", groups[i]);
      goto next_codec;
    }

    if ((next_tok - groups[i]) == 5 /* strlen ("audio") */ &&
        !g_ascii_strncasecmp ("audio", groups[i], 5))
    {
      media_type = FS_MEDIA_TYPE_AUDIO;
    }
    else if ((next_tok - groups[i]) == 5 /* strlen ("video") */ &&
        !g_ascii_strncasecmp ("video", groups[i], 5))
    {
      media_type = FS_MEDIA_TYPE_VIDEO;
    }
    else
    {
      GST_WARNING ("Invalid media type in codec name name %s", groups[i]);
      goto next_codec;
    }

    encoding_name = next_tok + 1;

    next_tok = strchr (encoding_name, ':');

    if (encoding_name[0] == 0 || next_tok - encoding_name == 1)
      goto next_codec;

    if (next_tok)
      encoding_name = g_strndup (encoding_name,
          next_tok - encoding_name);
    else
      encoding_name = g_strdup (encoding_name);

    codec = fs_codec_new (FS_CODEC_ID_ANY, encoding_name, media_type, 0);

    g_free (encoding_name);

    for (j = 0; j < keys_count && keys[j]; j++) {
      if (!g_ascii_strcasecmp ("clock-rate", keys[j])) {
        codec->clock_rate = g_key_file_get_integer (keyfile, groups[i], keys[j],
            &gerror);
        if (gerror) {
          codec->clock_rate = 0;
          goto keyerror;
        }

      } else if (!g_ascii_strcasecmp ("id", keys[j])) {
         codec->id = g_key_file_get_integer (keyfile, groups[i], keys[j],
            &gerror);
        if (gerror) {
          codec->id = FS_CODEC_ID_ANY;
          goto keyerror;
        }

        if (codec->id < 0)
          codec->id = FS_CODEC_ID_DISABLE;

      } else if (!g_ascii_strcasecmp ("channels", keys[j])) {
         codec->channels = g_key_file_get_integer (keyfile, groups[i], keys[j],
            &gerror);
        if (gerror) {
          codec->channels = 0;
          goto keyerror;
        }
      } else if (!g_ascii_strcasecmp ("trr-int", keys[j])) {
        codec->minimum_reporting_interval =
            g_key_file_get_integer (keyfile, groups[i], keys[j], &gerror);
        if (gerror) {
          codec->minimum_reporting_interval = G_MAXUINT;
          goto keyerror;
        }
      } else if (g_str_has_prefix (keys[j], "feedback:")) {
        gchar *type = keys[j] + strlen ("feedback:");
        gchar *subtype = strchr (type, '/');
        gchar *extra_params;

        extra_params = g_key_file_get_string (keyfile, groups[i], keys[j],
            &gerror);
        if (gerror)
          goto keyerror;

        /* Replace / with \0 and point to name (the next char) */
        if (subtype)
        {
          *subtype=0;
          subtype++;
        }
        else
        {
          subtype = "";
        }

        fs_codec_add_feedback_parameter (codec, type, subtype,
            extra_params);
        g_free (extra_params);
      } else {
        FsCodecParameter *param = g_slice_new (FsCodecParameter);

        param->name = g_strdup (keys[j]);
        param->value = g_key_file_get_string (keyfile, groups[i], keys[j],
            &gerror);
        if (gerror) {
          fs_codec_parameter_free (param);
          goto keyerror;
        }

        if (!param->name || !param->value)
          fs_codec_parameter_free (param);
        else
          codec->optional_params = g_list_append (codec->optional_params,
              param);
      }
      continue;
    keyerror:
      GST_WARNING ("Error reading key %s codec %s: %s", keys[j], groups[i],
          gerror->message);
      g_clear_error (&gerror);

    }

    codecs = g_list_append (codecs, codec);

  next_codec:
    g_strfreev (keys);
  }


 out:

  g_strfreev (groups);
  g_key_file_free (keyfile);

  return codecs;
}
static int hidp_add_connection(struct input_device *idev)
{
	struct hidp_connadd_req *req;
	sdp_record_t *rec;
	char src_addr[18], dst_addr[18];
	char filename[PATH_MAX + 1];
	GKeyFile *key_file;
	char handle[11], *str;
	GError *gerr = NULL;
	int err;

	req = g_new0(struct hidp_connadd_req, 1);
	req->ctrl_sock = g_io_channel_unix_get_fd(idev->ctrl_io);
	req->intr_sock = g_io_channel_unix_get_fd(idev->intr_io);
	req->flags     = 0;
	req->idle_to   = idle_timeout;

	ba2str(&idev->src, src_addr);
	ba2str(&idev->dst, dst_addr);

	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s", src_addr,
								dst_addr);
	filename[PATH_MAX] = '\0';
	sprintf(handle, "0x%8.8X", idev->handle);

	key_file = g_key_file_new();
	g_key_file_load_from_file(key_file, filename, 0, NULL);
	str = g_key_file_get_string(key_file, "ServiceRecords", handle, NULL);
	g_key_file_free(key_file);

	if (!str) {
		error("Rejected connection from unknown device %s", dst_addr);
		err = -EPERM;
		goto cleanup;
	}

	rec = record_from_string(str);
	g_free(str);

	err = extract_hid_record(rec, req);
	sdp_record_free(rec);
	if (err < 0) {
		error("Could not parse HID SDP record: %s (%d)", strerror(-err),
									-err);
		goto cleanup;
	}

	req->vendor = btd_device_get_vendor(idev->device);
	req->product = btd_device_get_product(idev->device);
	req->version = btd_device_get_version(idev->device);

	if (device_name_known(idev->device))
		device_get_name(idev->device, req->name, sizeof(req->name));

	/* Encryption is mandatory for keyboards */
	if (req->subclass & 0x40) {
		if (!bt_io_set(idev->intr_io, &gerr,
					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
					BT_IO_OPT_INVALID)) {
			error("btio: %s", gerr->message);
			g_error_free(gerr);
			err = -EFAULT;
			goto cleanup;
		}

		idev->req = req;
		idev->sec_watch = g_io_add_watch(idev->intr_io, G_IO_OUT,
							encrypt_notify, idev);

		return 0;
	}

	err = ioctl_connadd(req);

cleanup:
	g_free(req->rd_data);
	g_free(req);

	return err;
}
Example #12
0
/* Load theme file and all listed resources in this file */
static gboolean _xfdashboard_theme_load_resources(XfdashboardTheme *self,
													GError **outError)
{
	XfdashboardThemePrivate		*priv;
	GError						*error;
	gchar						*themeFile;
	GKeyFile					*themeKeyFile;
	gchar						**resources, **resource;
	gchar						*resourceFile;
	gint						counter;

	g_return_val_if_fail(XFDASHBOARD_IS_THEME(self), FALSE);
	g_return_val_if_fail(outError==NULL || *outError==NULL, FALSE);

	priv=self->priv;
	error=NULL;

	/* Check that theme was found */
	if(!priv->themePath)
	{
		/* Set error */
		g_set_error(outError,
					XFDASHBOARD_THEME_ERROR,
					XFDASHBOARD_THEME_ERROR_THEME_NOT_FOUND,
					_("Theme '%s' not found"),
					priv->themeName);

		/* Return FALSE to indicate error */
		return(FALSE);
	}

	/* Load theme file */
	themeFile=g_build_filename(priv->themePath, XFDASHBOARD_THEME_FILE, NULL);

	themeKeyFile=g_key_file_new();
	if(!g_key_file_load_from_file(themeKeyFile,
									themeFile,
									G_KEY_FILE_NONE,
									&error))
	{
		/* Set error */
		g_propagate_error(outError, error);

		/* Release allocated resources */
		if(themeFile) g_free(themeFile);
		if(themeKeyFile) g_key_file_free(themeKeyFile);

		/* Return FALSE to indicate error */
		return(FALSE);
	}

	g_free(themeFile);

	/* Get display name and notify about property change (regardless of success result) */
	priv->themeDisplayName=g_key_file_get_locale_string(themeKeyFile,
														XFDASHBOARD_THEME_GROUP,
														"Name",
														NULL,
														&error);
	g_object_notify_by_pspec(G_OBJECT(self), XfdashboardThemeProperties[PROP_DISPLAY_NAME]);

	if(!priv->themeDisplayName)
	{
		/* Set error */
		g_propagate_error(outError, error);

		/* Release allocated resources */
		if(themeKeyFile) g_key_file_free(themeKeyFile);

		/* Return FALSE to indicate error */
		return(FALSE);
	}

	/* Get comment and notify about property change (regardless of success result) */
	priv->themeComment=g_key_file_get_locale_string(themeKeyFile,
														XFDASHBOARD_THEME_GROUP,
														"Comment",
														NULL,
														&error);
	g_object_notify_by_pspec(G_OBJECT(self), XfdashboardThemeProperties[PROP_COMMENT]);

	if(!priv->themeComment)
	{
		/* Set error */
		g_propagate_error(outError, error);

		/* Release allocated resources */
		if(themeKeyFile) g_key_file_free(themeKeyFile);

		/* Return FALSE to indicate error */
		return(FALSE);
	}

	/* Create CSS parser and load style resources */
	resources=g_key_file_get_string_list(themeKeyFile,
											XFDASHBOARD_THEME_GROUP,
											"Style",
											NULL,
											&error);
	if(!resources)
	{
		/* Set error */
		g_propagate_error(outError, error);

		/* Release allocated resources */
		if(themeKeyFile) g_key_file_free(themeKeyFile);

		/* Return FALSE to indicate error */
		return(FALSE);
	}

	counter=0;
	resource=resources;
	while(*resource)
	{
		/* Get path and file for style resource */
		resourceFile=g_build_filename(priv->themePath, *resource, NULL);

		/* Try to load style resource */
		if(!xfdashboard_theme_css_add_file(priv->styling, resourceFile, counter, &error))
		{
			/* Set error */
			g_propagate_error(outError, error);

			/* Release allocated resources */
			if(resources) g_strfreev(resources);
			if(resourceFile) g_free(resourceFile);
			if(themeKeyFile) g_key_file_free(themeKeyFile);

			/* Return FALSE to indicate error */
			return(FALSE);
		}

		/* Release allocated resources */
		if(resourceFile) g_free(resourceFile);

		/* Continue with next entry */
		resource++;
		counter++;
	}
	g_strfreev(resources);

	/* Create XML parser and load layout resources */
	resources=g_key_file_get_string_list(themeKeyFile,
											XFDASHBOARD_THEME_GROUP,
											"Layout",
											NULL,
											&error);
	if(!resources)
	{
		/* Set error */
		g_propagate_error(outError, error);

		/* Release allocated resources */
		if(themeKeyFile) g_key_file_free(themeKeyFile);

		/* Return FALSE to indicate error */
		return(FALSE);
	}

	resource=resources;
	while(*resource)
	{
		/* Get path and file for style resource */
		resourceFile=g_build_filename(priv->themePath, *resource, NULL);

		/* Try to load style resource */
		if(!xfdashboard_theme_layout_add_file(priv->layout, resourceFile, &error))
		{
			/* Set error */
			g_propagate_error(outError, error);

			/* Release allocated resources */
			if(resources) g_strfreev(resources);
			if(resourceFile) g_free(resourceFile);
			if(themeKeyFile) g_key_file_free(themeKeyFile);

			/* Return FALSE to indicate error */
			return(FALSE);
		}

		/* Release allocated resources */
		if(resourceFile) g_free(resourceFile);

		/* Continue with next entry */
		resource++;
		counter++;
	}
	g_strfreev(resources);

	/* Create XML parser and load effect resources which are optional */
	if(g_key_file_has_key(themeKeyFile,
							XFDASHBOARD_THEME_GROUP,
							"Effects",
							NULL))
	{
		resources=g_key_file_get_string_list(themeKeyFile,
												XFDASHBOARD_THEME_GROUP,
												"Effects",
												NULL,
												&error);
		if(!resources)
		{
			/* Set error */
			g_propagate_error(outError, error);

			/* Release allocated resources */
			if(themeKeyFile) g_key_file_free(themeKeyFile);

			/* Return FALSE to indicate error */
			return(FALSE);
		}

		resource=resources;
		while(*resource)
		{
			/* Get path and file for style resource */
			resourceFile=g_build_filename(priv->themePath, *resource, NULL);

			/* Try to load style resource */
			if(!xfdashboard_theme_effects_add_file(priv->effects, resourceFile, &error))
			{
				/* Set error */
				g_propagate_error(outError, error);

				/* Release allocated resources */
				if(resources) g_strfreev(resources);
				if(resourceFile) g_free(resourceFile);
				if(themeKeyFile) g_key_file_free(themeKeyFile);

				/* Return FALSE to indicate error */
				return(FALSE);
			}

			/* Release allocated resources */
			if(resourceFile) g_free(resourceFile);

			/* Continue with next entry */
			resource++;
			counter++;
		}
		g_strfreev(resources);
	}

	/* Release allocated resources */
	if(themeKeyFile) g_key_file_free(themeKeyFile);

	/* Return TRUE to indicate success */
	return(TRUE);
}
static void
panel_menu_items_append_from_desktop (GtkWidget *menu,
				      char      *path,
				      char      *force_name)
{
	GKeyFile  *key_file;
	gboolean   loaded;
	GtkWidget *item;
	char      *path_freeme;
	char      *full_path;
	char      *uri;
	char      *icon;
	char      *name;
	char      *comment;

	path_freeme = NULL;

	key_file = g_key_file_new ();

	if (g_path_is_absolute (path)) {
		loaded = g_key_file_load_from_file (key_file, path,
						    G_KEY_FILE_NONE, NULL);
		full_path = path;
	} else {
		char *lookup_file;
		char *desktop_path;

		if (!g_str_has_suffix (path, ".desktop")) {
			desktop_path = g_strconcat (path, ".desktop", NULL);
		} else {
			desktop_path = path;
		}

		lookup_file = g_strconcat ("applications", G_DIR_SEPARATOR_S,
					   desktop_path, NULL);
		loaded = g_key_file_load_from_data_dirs (key_file, lookup_file,
							 &path_freeme,
							 G_KEY_FILE_NONE,
							 NULL);
		full_path = path_freeme;
		g_free (lookup_file);

		if (desktop_path != path)
			g_free (desktop_path);
	}

	if (!loaded) {
		g_key_file_free (key_file);
		if (path_freeme)
			g_free (path_freeme);
		return;
	}

	icon    = panel_util_key_file_get_locale_string (key_file, "Icon");
	comment = panel_util_key_file_get_locale_string (key_file, "Comment");

	if (string_empty (force_name))
		name = panel_util_key_file_get_locale_string (key_file, "Name");
	else
		name = g_strdup (force_name);

	item = gtk_image_menu_item_new ();
	setup_menu_item_with_icon (item, panel_menu_icon_get_size (),
				   icon, NULL, NULL, name);

	panel_util_set_tooltip_text (item, comment);

	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
	g_signal_connect_data (item, "activate",
			       G_CALLBACK (panel_menu_item_activate_desktop_file),
			       g_strdup (full_path),
			       (GClosureNotify) g_free, 0);
	g_signal_connect (G_OBJECT (item), "button_press_event",
			  G_CALLBACK (menu_dummy_button_press_event), NULL);

	uri = g_filename_to_uri (full_path, NULL, NULL);

	setup_uri_drag (item, uri, icon);
	g_free (uri);

	g_key_file_free (key_file);

	if (icon)
		g_free (icon);

	if (name)
		g_free (name);

	if (comment)
		g_free (comment);

	if (path_freeme)
		g_free (path_freeme);
}
static gboolean
gtk_hotkey_key_file_registry_real_delete_hotkey (GtkHotkeyRegistry	*base,
											   const gchar		*app_id,
											   const gchar		*key_id,
											   GError			**error)
{
	GtkHotkeyInfo			*info = NULL;
	GFile					*file;
	GKeyFile				*keyfile;
	GError					*tmp_error;
	gboolean				is_error = FALSE;
	gchar					*path, *group;
	
	g_return_val_if_fail (app_id != NULL, FALSE);
	g_return_val_if_fail (key_id != NULL, FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
	
	group = NULL;
	
	file = get_hotkey_file (app_id);
	g_return_val_if_fail (G_IS_FILE(file), FALSE);
	
	path = g_file_get_path (file);
	keyfile = g_key_file_new ();
	
	/* Load the old keyfile */
	tmp_error = NULL;
	g_key_file_load_from_file (keyfile, path, 0, &tmp_error);
	if (tmp_error) {
		if ((tmp_error->domain == G_FILE_ERROR &&
			 tmp_error->code == G_FILE_ERROR_NOENT) ||
			(tmp_error->domain == G_KEY_FILE_ERROR &&
			 tmp_error->code == G_KEY_FILE_ERROR_NOT_FOUND))
			g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
						 GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN_APP,
						 "No such keyfile '%s'. Application '%s' has not "
						 "registered any hotkeys",
						 path, app_id);
		else
			g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
						 GTK_HOTKEY_REGISTRY_ERROR_IO,
						 "Failed to load keyfile '%s': %s",
						 app_id, tmp_error->message);
		is_error = TRUE;
		goto clean_up;
	}
	
	/* Get a ref to the GtkHotkeyInfo so that we can emit it with the
	 * hotkey-deleted signal */
	tmp_error = NULL;
	info = get_hotkey_info_from_key_file (keyfile, app_id, key_id, error);
	if (info == NULL) {
		is_error = TRUE;
		goto clean_up;
	}
	
	/* Remove the group for key_id */
	group = g_strconcat (HOTKEY_GROUP, key_id, NULL);
	tmp_error = NULL;
	g_key_file_remove_group (keyfile, group, &tmp_error);
	if (tmp_error) {
		if (tmp_error->domain == G_KEY_FILE_ERROR &&
			 tmp_error->code == G_KEY_FILE_ERROR_GROUP_NOT_FOUND)
			g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
						 GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN_APP,
						 "Application '%s' has not registered a hotkey with"
						 "id '%s'", app_id, key_id);
		else
			g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
						 GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN,
						 "Failed to delete hotkey '%s' from application %s: %s",
						 key_id, app_id, tmp_error->message);
		is_error = TRUE;
		goto clean_up;
	}
	
	/* Check if the keyfile is empty. If it is we delete it */
	gsize count;
	GStrv groups;
	groups = g_key_file_get_groups (keyfile, &count);
	g_strfreev (groups);
	if (count == 0) {
		tmp_error = NULL;
		g_file_delete (file, NULL, &tmp_error);
		
		if (tmp_error) {
			g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
						 GTK_HOTKEY_REGISTRY_ERROR_IO,
						 "Failed to delete empty keyfile '%s': %s",
						 path, tmp_error->message);
			is_error = TRUE;
		}
		/* File deleted, we should just clean up and exit */
		goto clean_up;
	}
	
	/* Write new keyfile */
	gsize size;
	gchar *contents;
	tmp_error = NULL;
	contents = g_key_file_to_data (keyfile, &size, &tmp_error);
	if (tmp_error) {
		g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
					 GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN,
					 "Failed to generate keyfile contents: %s",
					 tmp_error->message);
		is_error = TRUE;
		goto clean_up;
	}
	
	tmp_error = NULL;
	g_file_set_contents (path, contents, size, &tmp_error);
	if (tmp_error) {
		g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
					 GTK_HOTKEY_REGISTRY_ERROR_IO,
					 "Failed to write keyfile '%s': %s",
					 path, tmp_error->message);
		is_error = TRUE;
		goto clean_up;
	}
	
	clean_up:
		if (tmp_error) g_error_free (tmp_error);
		g_object_unref (file);
		g_free (path);
		if (group) g_free (group);
		g_key_file_free (keyfile);
		
	if (is_error)
		return FALSE;
	
	gtk_hotkey_registry_hotkey_deleted (base, info);
	g_object_unref (info);
	return TRUE;
}
Example #15
0
int main(const int argc, const char* argv[]) {
    setbuf(stdout, NULL);
    setbuf(stderr, NULL);
    checkUser();
    if (chdir(etmWorkingDir) == -1) {
        perror("chdir");
        exit(EXIT_FAILURE);
    }
    umask(006);
    cleanPreviousRun();
    registerSignalHandlers();

    setupSocketServer();

    fdLock = open(LOCK_PATH, O_CREAT | O_RDWR, 0666);

    if (fdLock == -1) {
        perror("Open lock file");
        exit(EXIT_SUCCESS);
    }

    int rc = flock(fdLock, LOCK_EX | LOCK_NB);
    if (rc == 0) {
        // success
        puts("xwared: unlocked.");
        fdETMLock = open(ETM_LOCK_PATH, O_CREAT | O_RDWR, 0666);
        if (fdETMLock == -1) {
            perror("Open ETM lock file");
            exit(EXIT_SUCCESS);
        }

        // Check if ETM should run at start
        GKeyFile* configFile = g_key_file_new();
        if (g_key_file_load_from_file(configFile, CONFIG_PATH, G_KEY_FILE_NONE, NULL) == 0) {
            fprintf(stderr, "xwared: cannot load settings.ini, use default value\n");
        }
        GError* gErr = NULL;
        gboolean etmStart = g_key_file_get_boolean(configFile, "xwared", "startetm", &gErr);
        if (gErr == NULL) {
            if (etmStart == FALSE) {
                toRunETM = 0;
            }
        } else {
            fprintf(stderr, "xwared: %s, use default value\n", gErr->message);
            g_error_free(gErr);
        }
        g_key_file_free(configFile);

        while(1) {
            runETM();
        }

    } else {
        if (errno == EWOULDBLOCK) {
            puts("xwared: locked.");
            exit(EXIT_FAILURE);
        }
        perror("flock");
    }
    unload();
    exit(EXIT_SUCCESS);
}
/**
 * egg_desktop_file_new_from_key_file:
 * @key_file: a #GKeyFile representing a desktop file
 * @source: the path or URI that @key_file was loaded from, or %NULL
 * @error: error pointer
 *
 * Creates a new #EggDesktopFile for @key_file. Assumes ownership of
 * @key_file (on success or failure); you should consider @key_file to
 * be freed after calling this function.
 *
 * Return value: the new #EggDesktopFile, or %NULL on error.
 **/
EggDesktopFile *
egg_desktop_file_new_from_key_file (GKeyFile    *key_file,
				    const char  *source,
				    GError     **error)
{
  EggDesktopFile *desktop_file;
  char *version, *type;

  if (!g_key_file_has_group (key_file, EGG_DESKTOP_FILE_GROUP))
    {
      g_set_error (error, EGG_DESKTOP_FILE_ERROR,
		   EGG_DESKTOP_FILE_ERROR_INVALID,
		   _("File is not a valid .desktop file"));
      g_key_file_free (key_file);
      return NULL;
    }

  version = g_key_file_get_value (key_file, EGG_DESKTOP_FILE_GROUP,
				  EGG_DESKTOP_FILE_KEY_VERSION,
				  NULL);
  if (version)
    {
      double version_num;
      char *end;

      version_num = g_ascii_strtod (version, &end);
      if (*end)
	{
	  g_warning ("Invalid Version string '%s' in %s",
		     version, source ? source : "(unknown)");
	}
      else if (version_num > 1.0)
	{
	  g_set_error (error, EGG_DESKTOP_FILE_ERROR,
		       EGG_DESKTOP_FILE_ERROR_INVALID,
		       _("Unrecognized desktop file Version '%s'"), version);
	  g_free (version);
	  g_key_file_free (key_file);
	  return NULL;
	}
      g_free (version);
    }

  desktop_file = g_new0 (EggDesktopFile, 1);
  desktop_file->key_file = key_file;

  if (g_path_is_absolute (source))
    desktop_file->source = g_filename_to_uri (source, NULL, NULL);
  else
    desktop_file->source = g_strdup (source);

  desktop_file->name = g_key_file_get_string (key_file, EGG_DESKTOP_FILE_GROUP,
					      EGG_DESKTOP_FILE_KEY_NAME, error);
  if (!desktop_file->name)
    {
      egg_desktop_file_free (desktop_file);
      return NULL;
    }

  type = g_key_file_get_string (key_file, EGG_DESKTOP_FILE_GROUP,
				EGG_DESKTOP_FILE_KEY_TYPE, error);
  if (!type)
    {
      egg_desktop_file_free (desktop_file);
      return NULL;
    }

  if (!strcmp (type, "Application"))
    {
      char *exec, *p;

      desktop_file->type = EGG_DESKTOP_FILE_TYPE_APPLICATION;

      exec = g_key_file_get_string (key_file,
				    EGG_DESKTOP_FILE_GROUP,
				    EGG_DESKTOP_FILE_KEY_EXEC,
				    error);
      if (!exec)
	{
	  egg_desktop_file_free (desktop_file);
	  g_free (type);
	  return NULL;
	}

      /* See if it takes paths or URIs or neither */
      for (p = exec; *p; p++)
	{
	  if (*p == '%')
	    {
	      if (p[1] == '\0' || strchr ("FfUu", p[1]))
		{
		  desktop_file->document_code = p[1];
		  break;
		}
	      p++;
	    }
	}

      g_free (exec);
    }
  else if (!strcmp (type, "Link"))
    {
      char *url;

      desktop_file->type = EGG_DESKTOP_FILE_TYPE_LINK;

      url = g_key_file_get_string (key_file,
				   EGG_DESKTOP_FILE_GROUP,
				   EGG_DESKTOP_FILE_KEY_URL,
				   error);
      if (!url)
	{
	  egg_desktop_file_free (desktop_file);
	  g_free (type);
	  return NULL;
	}
      g_free (url);
    }
  else if (!strcmp (type, "Directory"))
    desktop_file->type = EGG_DESKTOP_FILE_TYPE_DIRECTORY;
  else
    desktop_file->type = EGG_DESKTOP_FILE_TYPE_UNRECOGNIZED;

  g_free (type);

  /* Check the Icon key */
  desktop_file->icon = g_key_file_get_string (key_file,
					      EGG_DESKTOP_FILE_GROUP,
					      EGG_DESKTOP_FILE_KEY_ICON,
					      NULL);
  if (desktop_file->icon && !g_path_is_absolute (desktop_file->icon))
    {
      char *ext;

      /* Lots of .desktop files still get this wrong */
      ext = strrchr (desktop_file->icon, '.');
      if (ext && (!strcmp (ext, ".png") ||
		  !strcmp (ext, ".xpm") ||
		  !strcmp (ext, ".svg")))
	{
	  g_warning ("Desktop file '%s' has malformed Icon key '%s'"
		     "(should not include extension)",
		     source ? source : "(unknown)",
		     desktop_file->icon);
	  *ext = '\0';
	}
    }

  return desktop_file;
}
Example #17
0
static gboolean
prefsFromData (PrettyPrintingOptions* ppo,
               const gchar* contents,
               gssize size,
               GError** error)
{
    GKeyFile *kf;

    g_return_val_if_fail (contents != NULL, FALSE);

    kf = g_key_file_new ();

    if (!g_key_file_load_from_data (kf, contents, size,
             G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
             error))
    {
        g_key_file_free (kf);
        return FALSE;
    }

    if (g_key_file_has_key (kf, "pretty-printer", "newLineChars", NULL))
    {
        g_free ((gpointer)ppo->newLineChars);
        ppo->newLineChars = g_key_file_get_string (kf, "pretty-printer", "newLineChars", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "indentChar", NULL))
    {
        ppo->indentChar = (char)g_key_file_get_integer (kf, "pretty-printer", "indentChar", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "indentLength", NULL))
    {
        ppo->indentLength = g_key_file_get_integer (kf, "pretty-printer", "indentLength", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "oneLineText", NULL))
    {
        ppo->oneLineText = g_key_file_get_boolean (kf, "pretty-printer", "oneLineText", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "inlineText", NULL))
    {
        ppo->inlineText = g_key_file_get_boolean (kf, "pretty-printer", "inlineText", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "oneLineComment", NULL))
    {
        ppo->oneLineComment = g_key_file_get_boolean (kf, "pretty-printer", "oneLineComment", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "inlineComment", NULL))
    {
        ppo->inlineComment = g_key_file_get_boolean (kf, "pretty-printer", "inlineComment", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "oneLineCdata", NULL))
    {
        ppo->oneLineCdata = g_key_file_get_boolean (kf, "pretty-printer", "oneLineCdata", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "inlineCdata", NULL))
    {
        ppo->inlineCdata = g_key_file_get_boolean (kf, "pretty-printer", "inlineCdata", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "emptyNodeStripping", NULL))
    {
        ppo->emptyNodeStripping = g_key_file_get_boolean (kf, "pretty-printer", "emptyNodeStripping", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "emptyNodeStrippingSpace", NULL))
    {
        ppo->emptyNodeStrippingSpace = g_key_file_get_boolean (kf, "pretty-printer", "emptyNodeStrippingSpace", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "forceEmptyNodeSplit", NULL))
    {
        ppo->forceEmptyNodeSplit = g_key_file_get_boolean (kf, "pretty-printer", "forceEmptyNodeSplit", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "trimLeadingWhites", NULL))
    {
        ppo->trimLeadingWhites = g_key_file_get_boolean (kf, "pretty-printer", "trimLeadingWhites", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "trimTrailingWhites", NULL))
    {
        ppo->trimTrailingWhites = g_key_file_get_boolean (kf, "pretty-printer", "trimTrailingWhites", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "alignComment", NULL))
    {
        ppo->alignComment = g_key_file_get_boolean (kf, "pretty-printer", "alignComment", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "alignText", NULL))
    {
        ppo->alignText = g_key_file_get_boolean (kf, "pretty-printer", "alignText", error);
    }
    if (g_key_file_has_key (kf, "pretty-printer", "alignCdata", NULL))
    {
        ppo->alignCdata = g_key_file_get_boolean (kf, "pretty-printer", "alignCdata", error);
    }

    g_key_file_free (kf);
    return TRUE;
}
Example #18
0
File: zx.c Project: mstg/zx
void zx_config(xcb_helper_struct *_s, zx *zs) {
    // Const values (Auto defined)
    _s->x = 0;
    _s->y = 0;
    _s->width = 0;

    typedef struct options {
        unsigned long long_value;
        int num_value;
        char *char_value;
    } options;

    options **_opts = malloc(sizeof(options)+sizeof(int)*5+sizeof(unsigned long)*3+1+sizeof(char*)*2+1);
    int count_def = 10;

    for (int i = 0; i < count_def; i++) {
        _opts[i] = malloc(sizeof(int)+sizeof(unsigned long));
    }

    _opts[0]->long_value = 0x2C3E50;
    _opts[1]->long_value = 0x7F8C8D;
    _opts[2]->num_value = 1;
    _opts[3]->num_value = 0;
    _opts[4]->long_value = 0xFFFFFF;
    _opts[5]->num_value = 0;
    _opts[6]->num_value = 25;
    _opts[7]->char_value = "fixed";
    _opts[8]->num_value = 1;
    _opts[9]->char_value = "xcb";

    unsigned long floating_windows_count = 0;
    char **flwin_list = NULL;

    char config_path[255];
    sprintf(config_path, "%s/.zxconfig", zs->homedir);

    GKeyFile* gkf = g_key_file_new();

    if (!g_key_file_load_from_file(gkf, config_path, G_KEY_FILE_NONE, NULL)){
        fprintf (stderr, "WARNING! Could not read config file %s! No config file present\n", config_path);
        goto set_opts;
        return;
    }

    char *opts[] = {"background", "border_color", "border", "floating", "font_color", "daemon", "height", "font", "pin_bottom", "font_type", "floating_windows"};
    char *opts_type[] = {"ul", "ul", "int", "int", "ul", "int", "int", "char", "int", "char", "list"};

    GError *err = NULL;

    for (int i = 0; i < count_def+1; i++) {
        if (strcmp(opts_type[i], "int") == 0) {
            int t = g_key_file_get_integer (gkf, "zx", opts[i], &err);
            if (!err) {
                _opts[i]->num_value = t;
            }
        } else if (strcmp(opts_type[i], "ul") == 0) {
            char *temp = g_key_file_get_value(gkf, "zx", opts[i], &err);
            if (!err) {
                unsigned long t = strtoul(temp, NULL, 0);
                _opts[i]->long_value = t;
            }
        } else if (strcmp(opts_type[i], "char") == 0) {
          char *temp = g_key_file_get_value(gkf, "zx", opts[i], &err);
          if (!err) {
              _opts[i]->char_value = temp;
          }
        } else if (strcmp(opts_type[i], "list") == 0) {
          gsize length;
          char **temp = g_key_file_get_string_list(gkf, "zx", opts[i], &length, &err);
          if (!err) {
            flwin_list = temp;
            floating_windows_count = length;
          }
        }
        err = NULL;
    }

    g_key_file_free(gkf);

set_opts:
  _s->background = _opts[0]->long_value;
  _s->rect_border = _opts[1]->long_value;
  _s->border = _opts[2]->num_value;
  zs->floating = _opts[3]->num_value;
  _s->font_color = _opts[4]->long_value;
  zs->daemon = _opts[5]->num_value;
  _s->height = _opts[6]->num_value;
  zs->font = _opts[7]->char_value;
  zs->pin_bottom = _opts[8]->num_value;
  _s->font_type = strcmp(_opts[9]->char_value, "pango") ? xcb : PANGO;
  zs->floating_windows = flwin_list;
  zs->floating_windows_length = floating_windows_count;
  free(_opts);
}
Example #19
0
static gboolean read_persistent_state(GAPersistentState *pstate,
                                      const gchar *path, gboolean frozen)
{
    GKeyFile *keyfile = NULL;
    GError *gerr = NULL;
    struct stat st;
    gboolean ret = true;

    g_assert(pstate);

    if (stat(path, &st) == -1) {
        /* it's okay if state file doesn't exist, but any other error
         * indicates a permissions issue or some other misconfiguration
         * that we likely won't be able to recover from.
         */
        if (errno != ENOENT) {
            g_critical("unable to access state file at path %s: %s",
                       path, strerror(errno));
            ret = false;
            goto out;
        }

        /* file doesn't exist. initialize state to default values and
         * attempt to save now. (we could wait till later when we have
         * modified state we need to commit, but if there's a problem,
         * such as a missing parent directory, we want to catch it now)
         *
         * there is a potential scenario where someone either managed to
         * update the agent from a version that didn't use a key store
         * while qemu-ga thought the filesystem was frozen, or
         * deleted the key store prior to issuing a fsfreeze, prior
         * to restarting the agent. in this case we go ahead and defer
         * initial creation till we actually have modified state to
         * write, otherwise fail to recover from freeze.
         */
        set_persistent_state_defaults(pstate);
        if (!frozen) {
            ret = write_persistent_state(pstate, path);
            if (!ret) {
                g_critical("unable to create state file at path %s", path);
                ret = false;
                goto out;
            }
        }
        ret = true;
        goto out;
    }

    keyfile = g_key_file_new();
    g_key_file_load_from_file(keyfile, path, 0, &gerr);
    if (gerr) {
        g_critical("error loading persistent state from path: %s, %s",
                   path, gerr->message);
        ret = false;
        goto out;
    }

    persistent_state_from_keyfile(pstate, keyfile);

out:
    if (keyfile) {
        g_key_file_free(keyfile);
    }
    if (gerr) {
        g_error_free(gerr);
    }

    return ret;
}
bool _openslide_try_hamamatsu_ndpi(openslide_t *osr, const char *filename,
				   struct _openslide_hash *quickhash1,
				   GError **err) {
  bool success = false;

  char *image_filenames = NULL;
  char *dirname = g_path_get_dirname(filename);
  image_filenames = g_new0(char, 1);
  image_filenames = g_build_filename(dirname, filename, NULL);

  FILE *f = _openslide_fopen(image_filenames, "rb", NULL);
  if (!f) {
    g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_FORMAT_NOT_SUPPORTED,
                "Can't open file");
    return false;
  }

  //dump data from NDPI file. from this function, we get all information about
  //NDPI file (number of image, size of image, offset, etc)
  GSList *dump = _openslide_tiffdump_create(f, err);
  if (!dump) {
    fclose(f);
    return false;
  }
  fclose(f);

  const char *groupname = GROUP_VMS;
  GKeyFile *key_file = g_key_file_new();

  //NDPI file dont have key file. So, I am create the key using this method
  //but, the problem is I can not show the property using :
  //openslide_get_property_names(osr)
  //are you know why?
  g_key_file_set_string(key_file, groupname, "ImageFile", image_filenames);

  //I dont get information about number of layers from NDPI file.
  //So, I set this num_layers to 1
  int num_layers = 1;
  g_key_file_set_integer(key_file, groupname, "NoLayers", num_layers);

  //create NDPI key from from dump variable
  //create key_file from this GSList.
  //We will get some of image from NDPI file with jpeg format
  //I save the count number of all jpeg image in "num_images" variable
  //some of the jpeg file dont have complete header (dont have restart marker offset)
  //"num_jpegs" is total number of jpeg with complete header
  int num_images; //the total number of jpegs images
  int num_jpegs;  //the total number of jpegs with complete header

  //I am still confused how to create index name from extracted
  //NDPI file. So, I am create a file with symbols [%].
  //please check this function
  ndpi_create_key_file(dump, key_file,
                       groupname, &num_images, &num_jpegs);

  //I dont get information about num_cols and num_rows
  //So, I set this "num_cols" variable like this
  int num_cols;
  if(num_jpegs>1)
    num_cols = 2;
  else
    num_cols = 1;

  // add properties
  if (osr) {
    add_properties(osr->properties, key_file, groupname);
  }

  //I am not yet add the macros file
  //we can get the macros file from key_file

  success = hamamatsu_ndpi_part2(osr,
            num_jpegs, image_filenames,
            num_cols, key_file,
            err);

  _openslide_tiffdump_destroy(dump);
  g_key_file_free(key_file);
  return success;
}
Example #21
0
/**
 * save the config file
 * it uses the glib config utils after 0.6.0
 * if cannot load, try the xml file before that version
 *
 * \param
 *
 * \return TRUE if ok
 * */
gboolean gsb_file_config_save_config ( void )
{
    GKeyFile *config;
    const gchar *filename;
    gchar *file_content;
    gchar *name;
    gsize length;
    FILE *conf_file;
    gint i;

    devel_debug (NULL);

    filename = gsb_dirs_get_grisbirc_filename ();
    config = g_key_file_new ();

#if IS_DEVELOPMENT_VERSION == 1
    /* set config model */
    g_key_file_set_integer ( config,
                        "Model",
                        "Stable_config_file_model",
                        conf.stable_config_file_model );
#endif

    g_key_file_set_integer ( config,
                        "Geometry",
                        "Root_x",
                        conf.root_x );

    g_key_file_set_integer ( config,
                        "Geometry",
                        "Root_y",
                        conf.root_y );

    g_key_file_set_integer ( config,
                        "Geometry",
                        "Width",
                        conf.main_width );

    g_key_file_set_integer ( config,
                        "Geometry",
                        "Height",
                        conf.main_height );

    g_key_file_set_integer ( config,
                        "Geometry",
                        "Full_screen",
                        conf.full_screen );

    g_key_file_set_integer ( config,
                        "Geometry",
                        "Maximize_screen",
                        conf.maximize_screen );

    /* Remember size of main panel */
    g_key_file_set_integer ( config,
                        "Geometry",
                        "Panel_width",
                        conf.panel_width );

    /* preferences size */
    g_key_file_set_integer ( config,
                        "Geometry",
                        "Prefs_width",
                        conf.prefs_width );

    /* save general */
    g_key_file_set_integer ( config,
                        "General",
                        "Can modify R",
                        conf.r_modifiable );

    g_key_file_set_string ( config,
                        "General",
                        "Path",
                        gsb_file_get_last_path () );

    g_key_file_set_integer ( config,
                        "General",
                        "Show permission alert",
                        conf.alerte_permission );

    g_key_file_set_integer ( config,
                        "General",
                        "Function of enter",
                        conf.entree );

    g_key_file_set_integer ( config,
                        "General",
                        "Show alert messages",
                        conf.alerte_mini );

    g_key_file_set_integer ( config,
                        "General",
                        "Use user font",
                        conf.utilise_fonte_listes );

    if ( conf.font_string )
        g_key_file_set_string ( config,
                        "General",
                        "Font name",
                        conf.font_string );

    if ( conf.browser_command )
    {
        gchar *string;

        string = my_strdelimit ( conf.browser_command, "&", "\\e" );
        if ( string )
            g_key_file_set_string ( config,
                        "General",
                        "Web",
                        string );
        g_free (string);
    }

    g_key_file_set_integer ( config,
                        "General",
                        "Pluriel_final",
                        conf.pluriel_final );

    g_key_file_set_integer ( config,
                        "General",
                        "Metatree_action_2button_press",
                        conf.metatree_action_2button_press );

     /* save backup part */
    g_key_file_set_integer ( config,
                        "Backup",
                        "Make backup",
                        conf.make_backup );

    g_key_file_set_integer ( config,
                        "Backup",
                        "Make backup single file",
                        conf.make_bakup_single_file );

    g_key_file_set_integer ( config,
                        "Backup",
                        "Make backup every x minutes",
                        conf.make_backup_every_minutes );

    g_key_file_set_integer ( config,
                        "Backup",
                        "Compress backup",
                        conf.compress_backup );

    g_key_file_set_integer ( config,
                        "Backup",
                        "Make backup nb minutes",
                        conf.make_backup_nb_minutes );

    if (gsb_file_get_backup_path ())
        g_key_file_set_string ( config,
                        "Backup",
                        "Backup path",
                        gsb_file_get_backup_path ());

    /* save input/output */
    g_key_file_set_integer ( config,
                        "IO",
                        "Load last file",
                        conf.dernier_fichier_auto );

    g_key_file_set_integer ( config,
                        "IO",
                        "Save at closing",
                        conf.sauvegarde_auto );

    g_key_file_set_integer ( config,
                        "IO",
                        "Save at opening",
                        conf.sauvegarde_demarrage );

    g_key_file_set_integer ( config,
                        "IO",
                        "Nb last opened files",
                        conf.nb_max_derniers_fichiers_ouverts );

    g_key_file_set_integer ( config,
                        "IO",
                        "Compress file",
                        conf.compress_file );

    g_key_file_set_integer ( config,
                        "IO",
                        "Force saving",
                        conf.force_enregistrement );

    if ( conf.nb_derniers_fichiers_ouverts > 0
     &&
     tab_noms_derniers_fichiers_ouverts)
        g_key_file_set_string_list ( config,
                        "IO",
                        "Names last files",
                        (const gchar **) tab_noms_derniers_fichiers_ouverts,
                        conf.nb_derniers_fichiers_ouverts);

    g_key_file_set_integer ( config,
                        "IO",
                        "Check_archival_at_opening",
                        conf.check_for_archival );

    g_key_file_set_integer ( config,
                        "IO",
                        "Max_transactions_before_warn_archival",
                        conf.max_non_archived_transactions_for_check );

    /* save scheduled section */
    g_key_file_set_integer ( config,
                        "Scheduled",
                        "Days before remind",
                        nb_days_before_scheduled );

    g_key_file_set_integer ( config,
                        "Scheduled",
                        "Execute scheduled of month",
                        conf.execute_scheduled_of_month );

    g_key_file_set_integer ( config,
                        "Scheduled",
                        "Balances with scheduled",
                        conf.balances_with_scheduled );

    g_key_file_set_integer ( config,
                        "Scheduled",
                        "Group_partial_balance",
                        conf.group_partial_balance_under_accounts );

    /* save shown section */
    g_key_file_set_integer ( config,
                        "Display",
                        "Show transaction form",
                        conf.formulaire_toujours_affiche );

    g_key_file_set_integer ( config,
                        "Display",
                        "Show selected transaction in form",
                        conf.show_transaction_selected_in_form );

    g_key_file_set_integer ( config,
                        "Display",
                        "Show transaction gives balance",
                        conf.show_transaction_gives_balance );

    g_key_file_set_integer ( config,
                        "Display",
                        "Transactions_list_primary_sorting",
                        conf.transactions_list_primary_sorting );

    g_key_file_set_integer ( config,
                        "Display",
                        "Transactions_list_secondary_sorting",
                        conf.transactions_list_secondary_sorting );

    g_key_file_set_integer ( config,
                        "Display",
                        "Show automatic financial year",
                        conf.affichage_exercice_automatique );

    g_key_file_set_integer ( config,
                        "Display",
                        "Automatic completion payee",
                        conf.automatic_completion_payee );

    g_key_file_set_integer ( config,
                        "Display",
                        "Limit payee completion",
                        conf.limit_completion_to_current_account );

    g_key_file_set_integer ( config,
                        "Display",
                        "Automatic_recover_splits",
                        conf.automatic_recover_splits );

    g_key_file_set_integer ( config,
                        "Display",
                        "Automatic_erase_credit_debit",
                        conf.automatic_erase_credit_debit );

    g_key_file_set_integer ( config,
                        "Display",
                        "Display toolbar",
                        conf.display_toolbar );

    g_key_file_set_integer ( config,
                        "Display",
                        "Active_scrolling_left_pane",
                        conf.active_scrolling_left_pane );

    g_key_file_set_integer ( config,
                        "Display",
                        "Show headings bar",
                        conf.show_headings_bar );

    g_key_file_set_integer ( config,
                        "Display",
                        "Show closed accounts",
                        conf.show_closed_accounts );

    g_key_file_set_integer ( config,
                        "Display",
                        "Display grisbi title",
                        conf.display_grisbi_title );

    /* save messages */
    for ( i = 0; messages[i].name; i ++ )
    {
        name = g_strconcat ( messages[i].name , "-answer", NULL );

        g_key_file_set_integer ( config, "Messages", messages[i].name, messages[i].hidden );
        g_key_file_set_integer ( config, "Messages", name, messages[i].default_answer );
        g_free ( name );
    }

    for ( i = 0; delete_msg[i].name; i ++ )
    {
        g_key_file_set_integer ( config, "Messages", delete_msg[i].name,
                        delete_msg[i].hidden );
    }

    g_key_file_set_integer ( config,
                        "Messages",
                        "Last tip",
                        conf.last_tip );

    g_key_file_set_integer ( config,
                        "Messages",
                        "Show tip",
                        conf.show_tip );

    /* save into a file */
    file_content = g_key_file_to_data ( config, &length, NULL );

    conf_file = fopen ( filename, "w" );

    #ifndef _WIN32
    if ( !conf_file )
    {
        utils_files_create_XDG_dir ( );
        conf_file = fopen ( filename, "w" );
    }
    #endif

    if ( !conf_file
     ||
     !fwrite ( file_content, sizeof ( gchar ), length, conf_file ) )
    {
        gchar* tmpstr = g_strdup_printf ( _("Cannot save configuration file '%s': %s"),
                        filename,
                        g_strerror ( errno ) );
        dialogue_error ( tmpstr );
        g_free ( tmpstr );
        g_free ( file_content);
        g_key_file_free (config);
        return ( FALSE );
    }

    fclose ( conf_file );
    g_free ( file_content);
    g_key_file_free (config);

    return TRUE;
}
bool _openslide_try_hamamatsu(openslide_t *osr, const char *filename,
			      struct _openslide_hash *quickhash1,
			      GError **err) {
  // initialize any variables destroyed/used in DONE
  bool success = false;

  char *dirname = g_path_get_dirname(filename);

  int num_images = 0;
  char **image_filenames = NULL;

  int num_cols = -1;
  int num_rows = -1;

  char **all_keys = NULL;

  int num_layers = -1;

  // first, see if it's a VMS/VMU file
  GKeyFile *key_file = g_key_file_new();
  if (!_openslide_read_key_file(key_file, filename, G_KEY_FILE_NONE, NULL)) {
    g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_FORMAT_NOT_SUPPORTED,
                "Can't load key file");
    goto DONE;
  }

  // select group or fail, then read dimensions
  const char *groupname;
  if (g_key_file_has_group(key_file, GROUP_VMS)) {
    groupname = GROUP_VMS;

    num_cols = g_key_file_get_integer(key_file, groupname,
				      KEY_NUM_JPEG_COLS,
				      NULL);
    num_rows = g_key_file_get_integer(key_file,
				      groupname,
				      KEY_NUM_JPEG_ROWS,
				      NULL);
  } else if (g_key_file_has_group(key_file, GROUP_VMU)) {
    groupname = GROUP_VMU;

    num_cols = 1;  // not specified in file for VMU
    num_rows = 1;
  } else {
    g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_FORMAT_NOT_SUPPORTED,
                "Not VMS or VMU file");
    goto DONE;
  }

  // validate cols/rows
  if (num_cols < 1) {
    g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_FORMAT_NOT_SUPPORTED,
                "File has no columns");
    goto DONE;
  }
  if (num_rows < 1) {
    g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_FORMAT_NOT_SUPPORTED,
                "File has no rows");
    goto DONE;
  }

  // init the image filenames
  // this format has cols*rows image files, plus the map
  num_images = (num_cols * num_rows) + 1;
  image_filenames = g_new0(char *, num_images);

  // hash in the key file
  if (!_openslide_hash_file(quickhash1, filename, err)) {
    goto DONE;
  }

  // make sure values are within known bounds
  num_layers = g_key_file_get_integer(key_file, groupname, KEY_NUM_LAYERS,
				      NULL);
  if (num_layers < 1) {
    g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_BAD_DATA,
                "Cannot handle Hamamatsu files with NoLayers < 1");
    goto DONE;
  }

  // add properties
  if (osr) {
    add_properties(osr->properties, key_file, groupname);
  }

  // extract MapFile
  char *tmp;
  tmp = g_key_file_get_string(key_file,
			      groupname,
			      KEY_MAP_FILE,
			      NULL);
  if (tmp) {
    char *map_filename = g_build_filename(dirname, tmp, NULL);
    g_free(tmp);

    image_filenames[num_images - 1] = map_filename;

    // hash in the map file
    if (!_openslide_hash_file(quickhash1, map_filename, err)) {
      goto DONE;
    }
  } else {
    g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_BAD_DATA,
                "Can't read map file");
    goto DONE;
  }

  // now each ImageFile
  all_keys = g_key_file_get_keys(key_file, groupname, NULL, NULL);
  for (char **tmp = all_keys; *tmp != NULL; tmp++) {
    char *key = *tmp;
    char *value = g_key_file_get_string(key_file, groupname, key, NULL);

    //    g_debug("%s", key);

    if (strncmp(KEY_IMAGE_FILE, key, strlen(KEY_IMAGE_FILE)) == 0) {
      // starts with ImageFile
      char *suffix = key + strlen(KEY_IMAGE_FILE);

      int layer;
      int col;
      int row;

      char **split = g_strsplit(suffix, ",", 0);
      switch (g_strv_length(split)) {
      case 0:
	// all zero
	layer = 0;
	col = 0;
	row = 0;
	break;

      case 1:
	// (z)
	// first item, skip '('
	layer = g_ascii_strtoll(split[0] + 1, NULL, 10);
	col = 0;
	row = 0;
	break;

      case 2:
	// (x,y)
	layer = 0;
	// first item, skip '('
	col = g_ascii_strtoll(split[0] + 1, NULL, 10);
	row = g_ascii_strtoll(split[1], NULL, 10);
	break;

      case 3:
        // (z,x,y)
        // first item, skip '('
        layer = g_ascii_strtoll(split[0] + 1, NULL, 10);
        col = g_ascii_strtoll(split[1], NULL, 10);
        row = g_ascii_strtoll(split[2], NULL, 10);
        break;

      default:
        // we just don't know
        g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_BAD_DATA,
                    "Unknown number of image dimensions: %d",
                    g_strv_length(split));
        g_free(value);
        g_strfreev(split);
        g_strfreev(all_keys);
        goto DONE;
      }
      g_strfreev(split);

      //g_debug("layer: %d, col: %d, row: %d", layer, col, row);

      if (layer != 0) {
        // skip non-zero layers for now
        g_free(value);
        continue;
      }

      if (col >= num_cols || row >= num_rows || col < 0 || row < 0) {
        g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_BAD_DATA,
                    "Invalid row or column in Hamamatsu file (%d,%d)",
                    col, row);
        g_free(value);
	g_strfreev(all_keys);
        goto DONE;
      }

      // compute index from x,y
      int i = row * num_cols + col;

      // init the file
      if (image_filenames[i]) {
        g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_BAD_DATA,
                    "Duplicate image for (%d,%d)", col, row);
        g_free(value);
        g_strfreev(all_keys);
        goto DONE;
      }
      image_filenames[i] = g_build_filename(dirname, value, NULL);
    }
    g_free(value);
  }
  g_strfreev(all_keys);

  // ensure all image filenames are filled
  for (int i = 0; i < num_images; i++) {
    if (!image_filenames[i]) {
      g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_BAD_DATA,
                  "Can't read image filename %d", i);
      goto DONE;
    }
  }

  // add macro image
  tmp = g_key_file_get_string(key_file,
			      groupname,
			      KEY_MACRO_IMAGE,
			      NULL);
  if (tmp) {
    char *macro_filename = g_build_filename(dirname, tmp, NULL);
    bool result = _openslide_add_jpeg_associated_image(osr ? osr->associated_images : NULL,
                                                       "macro",
                                                       macro_filename, 0, err);
    g_free(macro_filename);
    g_free(tmp);

    if (!result) {
      g_prefix_error(err, "Could not read macro image: ");
      goto DONE;
    }
  }

  // finalize depending on what format
  if (groupname == GROUP_VMS) {
    // open OptimisationFile
    FILE *optimisation_file = NULL;
    char *tmp = g_key_file_get_string(key_file,
				      GROUP_VMS,
				      KEY_OPTIMISATION_FILE,
				      NULL);
    if (tmp) {
      char *optimisation_filename = g_build_filename(dirname, tmp, NULL);
      g_free(tmp);

      optimisation_file = _openslide_fopen(optimisation_filename, "rb", NULL);

      if (optimisation_file == NULL) {
	// g_debug("Can't open optimisation file");
      }
      g_free(optimisation_filename);
    } else {
      // g_debug("Optimisation file key not present");
    }

    // do all the jpeg stuff
    success = hamamatsu_vms_part2(osr,
				  num_images, image_filenames,
				  num_cols,
				  optimisation_file,
				  err);

    // clean up
    if (optimisation_file) {
      fclose(optimisation_file);
    }
  } else if (groupname == GROUP_VMU) {
    // verify a few assumptions for VMU
    int bits_per_pixel = g_key_file_get_integer(key_file,
						GROUP_VMU,
						KEY_BITS_PER_PIXEL,
						NULL);
    char *pixel_order = g_key_file_get_string(key_file,
					      GROUP_VMU,
					      KEY_PIXEL_ORDER,
					      NULL);

    if (bits_per_pixel != 36) {
      g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_BAD_DATA,
                  "%s must be 36", KEY_BITS_PER_PIXEL);
    } else if (!pixel_order || (strcmp(pixel_order, "RGB") != 0)) {
      g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_BAD_DATA,
                  "%s must be RGB", KEY_PIXEL_ORDER);
    } else {
      // assumptions verified
      success = hamamatsu_vmu_part2(osr,
				    num_images, image_filenames,
				    err);
    }
    g_free(pixel_order);
  } else {
    g_assert_not_reached();
  }

 DONE:
  g_free(dirname);

  if (image_filenames) {
    for (int i = 0; i < num_images; i++) {
      g_free(image_filenames[i]);
    }
    g_free(image_filenames);
  }
  g_key_file_free(key_file);

  return success;
}
Example #23
0
/* Callback for sending file as attachment */
static void
send_as_attachment(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata)
{
	GeanyDocument *doc;
	gchar	*locale_filename = NULL;
	gchar	*command = NULL;
	GError	*error = NULL;
	GString	*cmd_str = NULL;
	gchar 		*data;

	doc = document_get_current();

	if (doc->file_name == NULL)
	{
		dialogs_show_save_as();
	}
	else
	{
		document_save_file(doc, FALSE);
	}

    if (doc->file_name != NULL)
	{
		if (mailer)
		{
			locale_filename = utils_get_locale_from_utf8(doc->file_name);
			cmd_str = g_string_new(mailer);
			if ((use_address_dialog == TRUE) && (g_strrstr(mailer, "%r") != NULL))
			{
				GKeyFile *config = NULL;
				gchar *config_dir = NULL;
 				gchar *input = dialogs_show_input(_("Recipient's Address"),
										GTK_WINDOW(geany->main_widgets->window),
										_("Enter the recipient's e-mail address:"),
										address);

				if (input)
				{
					config = g_key_file_new();
					g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL);

					g_free(address);
 					address = input;

 					g_key_file_set_string(config, "tools", "address", address);
 				}
 				else
 				{
					g_string_free(cmd_str, TRUE);
					g_free(locale_filename);
					return;
				}

				config_dir = g_path_get_dirname(config_file);


				if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) &&
				      utils_mkdir(config_dir, TRUE) != 0)
 				{
 					dialogs_show_msgbox(GTK_MESSAGE_ERROR,
 						_("Plugin configuration directory could not be created."));
 				}
 				else
 				{
 					/* write config to file */
 					data = g_key_file_to_data(config, NULL, NULL);
 					utils_write_file(config_file, data);
					g_free(data);
 				}
				g_key_file_free(config);
				g_free(config_dir);
 			}

			if (! utils_string_replace_all(cmd_str, "%f", locale_filename))
				ui_set_statusbar(FALSE,
				_("Filename placeholder not found. The executed command might have failed."));

			if (use_address_dialog == TRUE && address != NULL)
			{
				if (! utils_string_replace_all(cmd_str, "%r", address))
 					ui_set_statusbar(FALSE,
					_("Recipient address placeholder not found. The executed command might have failed."));
			}
			else
			{
				/* Removes %r if option was not activ but was included into command */
				utils_string_replace_all(cmd_str, "%r", "");
			}

			utils_string_replace_all(cmd_str, "%b", g_path_get_basename(locale_filename));

			command = g_string_free(cmd_str, FALSE);
			g_spawn_command_line_async(command, &error);
			if (error != NULL)
			{
				ui_set_statusbar(FALSE, _("Could not execute mailer. Please check your configuration."));
				g_error_free(error);
			}

			g_free(locale_filename);
			g_free(command);
		}
		else
		{
			ui_set_statusbar(FALSE, _("Please define a mail client first."));
		}
	}
	else
	{
		ui_set_statusbar(FALSE, _("File has to be saved before sending."));
	}
}
Example #24
0
int network_backends_save(network_backends_t *bs) {
	GKeyFile *keyfile = g_key_file_new();
	g_key_file_set_list_separator(keyfile, ',');
	GError *gerr = NULL;

	if (FALSE == g_key_file_load_from_file(keyfile, bs->default_file, G_KEY_FILE_KEEP_COMMENTS, &gerr)) {
		g_critical("%s: g_key_file_load_from_file: %s", G_STRLOC, gerr->message);
		g_error_free(gerr);
		g_key_file_free(keyfile);
		return -1;
	}

	GString *master = g_string_new(NULL);
	GString *slave  = g_string_new(NULL);
	guint i;
	GPtrArray *backends = bs->backends;

	g_mutex_lock(bs->backends_mutex);
	guint len = backends->len;
	for (i = 0; i < len; ++i) {
		network_backend_t *backend = g_ptr_array_index(backends, i);
		if (backend->type == BACKEND_TYPE_RW) {
			g_string_append_c(master, ',');
			g_string_append(master, backend->addr->name->str);
		} else if (backend->type == BACKEND_TYPE_RO) {
			g_string_append_c(slave, ',');
			g_string_append(slave, backend->addr->name->str);
		}
	}
	g_mutex_unlock(bs->backends_mutex);

	if (master->len != 0) {
		g_key_file_set_value(keyfile, "mysql-proxy", "proxy-backend-addresses", master->str+1);
	} else {
		g_key_file_set_value(keyfile, "mysql-proxy", "proxy-backend-addresses", "");
	}
	if (slave->len != 0) {
		g_key_file_set_value(keyfile, "mysql-proxy", "proxy-read-only-backend-addresses", slave->str+1);
	} else {
		g_key_file_set_value(keyfile, "mysql-proxy", "proxy-read-only-backend-addresses", "");
	}

	g_string_free(master, TRUE);
	g_string_free(slave, TRUE);

	GString *client_ips = g_string_new(NULL);
	GHashTable *ip_table = bs->ip_table[*(bs->ip_table_index)];
	g_hash_table_foreach(ip_table, append_key, client_ips);

	if (client_ips->len != 0) {
		g_key_file_set_value(keyfile, "mysql-proxy", "client-ips", client_ips->str+1);
	} else {
		g_key_file_set_value(keyfile, "mysql-proxy", "client-ips", "");
	}

	g_string_free(client_ips, TRUE);

	gsize file_size = 0;
	gchar *file_buf = g_key_file_to_data(keyfile, &file_size, NULL);
	if (FALSE == g_file_set_contents(bs->default_file, file_buf, file_size, &gerr)) {
		g_critical("%s: g_file_set_contents: %s", G_STRLOC, gerr->message);
		g_free(file_buf);
		g_error_free(gerr);
		g_key_file_free(keyfile);
		return -1;
	}

	g_message("%s: saving config file succeed", G_STRLOC);
	g_free(file_buf);
	g_key_file_free(keyfile);
	return 0;
}
Example #25
0
GPilotRequest* 
gpc_queue_load_request (guint32 pilot_id, gboolean _type, guint num)
{
	GPilotRequest *req;
	gchar *section = NULL;
	GPilotRequestType type;
	GKeyFile *kfile;

	if (_type==TRUE) {
		type = GREQ_CRADLE_EVENT; 
	} else {
		type = GREQ_PILOT_EVENT;
	}

	kfile = get_queue_kfile ();
	set_section_num (pilot_id, type, &section, num);

	req = g_new0 (GPilotRequest, sizeof (GPilotRequest));
	req->type = request_type_from_string (g_key_file_get_string (kfile, section, ENT_TYPE, NULL));
	if (req->type == GREQ_INVALID) {
		g_free (req);
		g_key_file_free (kfile);
		return NULL;
	}
  
	/* unless I store the sectionname _without_ trailing /, clean_section
	   can't delete it ? */
	g_free (section);
	section = NULL;
	req->handle = set_section_num (pilot_id, type, &section, num);
	req->queue_data.section_name = g_strdup (section);
	req->pilot_id = pilot_id;
  
	switch (req->type) {
	case GREQ_INSTALL:
		req->parameters.install.filename = g_key_file_get_string (kfile, section, ENT_FILENAME, NULL);
		req->parameters.install.description = g_key_file_get_string (kfile, section, ENT_DESCRIPTION, NULL);
		break;
	case GREQ_RESTORE:
		req->parameters.restore.directory = g_key_file_get_string (kfile, section, ENT_DIRECTORY, NULL);
		break;
	case GREQ_CONDUIT: {
		gchar *tmp;
		req->parameters.conduit.name = g_key_file_get_string (kfile, section, ENT_CONDUIT, NULL);
		tmp = g_key_file_get_string (kfile, section, ENT_HOW, NULL);
		req->parameters.conduit.how = gnome_pilot_conduit_sync_type_str_to_int (tmp);
		g_free(tmp);
	}
	break;
	case GREQ_GET_USERINFO:
		break;
	case GREQ_GET_SYSINFO:
		break;
	case GREQ_NEW_USERINFO: /* shares parameters with SET_USERINFO */
		req->parameters.set_userinfo.password = g_key_file_get_string (kfile, section, ENT_PASSWORD, NULL);
		req->parameters.set_userinfo.user_id = g_key_file_get_string (kfile, section, ENT_USER_ID, NULL);
		req->parameters.set_userinfo.pilot_id = g_key_file_get_integer (kfile, section, ENT_PILOT_ID, NULL);
		break;
	case GREQ_SET_USERINFO:
		req->parameters.set_userinfo.password = g_key_file_get_string (kfile, section, ENT_PASSWORD, NULL);
		req->parameters.set_userinfo.user_id = g_key_file_get_string (kfile, section, ENT_USER_ID, NULL);
		req->parameters.set_userinfo.pilot_id = g_key_file_get_integer (kfile, section, ENT_PILOT_ID, NULL);
		req->parameters.set_userinfo.continue_sync = g_key_file_get_boolean (kfile, section, ENT_CONT_SYNC, NULL);
		break;
	default: 
		g_assert_not_reached();
		break;
	}
	req->cradle = g_key_file_get_string (kfile, section, ENT_DEVICE, NULL);
	req->client_id = g_key_file_get_string (kfile, section, ENT_CLIENT_ID, NULL);
	req->timeout = g_key_file_get_integer (kfile, section, ENT_TIMEOUT, NULL);
	req->handle = g_key_file_get_integer (kfile, section, ENT_HANDLE, NULL);

	g_free (section);
	g_key_file_free (kfile);
	return req;
}
Example #26
0
// FIXME_pcm: error handling
static gboolean launch_program (FmArchiver *archiver, GAppLaunchContext *ctx,
                                const char *cmd, FmPathList *files, FmPath *dir)
{
    GDesktopAppInfo *app;
    char *_cmd = NULL;
    const char *dir_place_holder;
    GKeyFile *dummy;
    char *tmp;

    if (dir &&  (dir_place_holder = strstr (cmd, "%d")))
    {
        char *dir_str;
        int len;
        if (strstr (cmd, "%U") || strstr (cmd, "%u")) // supports URI
            dir_str = fm_path_to_uri (dir);
        else
        {
            GFile *gf = fm_path_to_gfile (dir);
            // FIXME_pcm: convert dir to fuse-based local path if needed.
            dir_str = g_file_get_path (gf);
            g_object_unref (gf);
        }

        // replace all % with %% so encoded URI can be handled correctly when parsing Exec key.
        tmp = fm_str_replace (dir_str, "%", "%%");
        g_free (dir_str);
        dir_str = tmp;

        // quote the path or URI
        tmp = g_shell_quote (dir_str);
        g_free (dir_str);
        dir_str = tmp;

        len = strlen (cmd) - 2 + strlen (dir_str) + 1;
        _cmd = g_malloc (len);
        len =  (dir_place_holder - cmd);
        strncpy (_cmd, cmd, len);
        strcpy (_cmd + len, dir_str);
        strcat (_cmd, dir_place_holder + 2);
        g_free (dir_str);
        cmd = _cmd;
    }

    // create a fake key file to cheat GDesktopAppInfo
    dummy = g_key_file_new ();
    g_key_file_set_string (dummy, G_KEY_FILE_DESKTOP_GROUP, "Type", "Application");
    g_key_file_set_string (dummy, G_KEY_FILE_DESKTOP_GROUP, "Name", archiver->program);

    // replace all % with %% so encoded URI can be handled correctly when parsing Exec key.
    g_key_file_set_string (dummy, G_KEY_FILE_DESKTOP_GROUP, "Exec", cmd);
    app = g_desktop_app_info_new_from_keyfile (dummy);

    g_key_file_free (dummy);
    g_debug ("cmd = %s", cmd);
    if (app)
    {
        GList *uris = NULL, *l;
        for (l = fm_list_peek_head_link (files); l; l=l->next)
        {
            FmPath *path = FM_PATH (l->data);
            uris = g_list_prepend (uris, fm_path_to_uri (path));
        }
        fm_app_info_launch_uris ((GAppInfo *) app, uris, ctx, NULL);
        g_list_foreach (uris,  (GFunc)g_free, NULL);
        g_list_free (uris);
    }
    
    g_free (_cmd);
    
    return TRUE;
}
Example #27
0
static void
gnc_state_set_base (const QofSession *session)
{
    gchar *basename, *original = NULL, *filename, *file_guid;
    gchar *sf_extension = NULL, *newstyle_filename = NULL;
    const gchar *uri;
    gchar guid_string[GUID_ENCODING_LENGTH+1];
    QofBook *book;
    const GncGUID *guid;
    GKeyFile *key_file = NULL;
    gint i;

    /* Reset filenames possibly found in a previous run */
    g_free (state_file_name);
    g_free (state_file_name_pre_241);
    state_file_name = NULL;
    state_file_name_pre_241 = NULL;

    uri = qof_session_get_url(session);
    ENTER("session %p (%s)", session, uri ? uri : "(null)");
    if (!uri)
    {
        LEAVE("no uri, nothing to do");
        return;
    }

    /* Get the book GncGUID */
    book = qof_session_get_book(session);
    guid = qof_entity_get_guid(QOF_INSTANCE(book));
    guid_to_string_buff(guid, guid_string);

    if (gnc_uri_is_file_uri (uri))
    {
        /* The book_uri is a true file, use its basename. */
        gchar *path = gnc_uri_get_path (uri);
        basename = g_path_get_basename (path);
        g_free (path);
    }
    else
    {
        /* The book_uri is composed of database connection parameters. */
        gchar* protocol = NULL;
        gchar* host = NULL;
        gchar* dbname = NULL;
        gchar* username = NULL;
        gchar* password = NULL;
        gint portnum = 0;
        gnc_uri_get_components (uri, &protocol, &host, &portnum,
                                &username, &password, &dbname);

        basename = g_strjoin ("_", protocol, host, username, dbname, NULL);
        g_free (protocol);
        g_free (host);
        g_free (username);
        g_free (password);
        g_free (dbname);
    }

    DEBUG ("Basename %s", basename);
    original = gnc_build_book_path (basename);
    g_free (basename);
    DEBUG ("Original %s", original);

    sf_extension = g_strdup (STATE_FILE_EXT);
    i = 1;
    while (1)
    {
        if (i == 1)
            filename = g_strconcat (original, sf_extension, NULL);
        else
            filename = g_strdup_printf ("%s_%d%s", original, i, sf_extension);
        DEBUG ("Trying %s", filename);
        key_file = gnc_key_file_load_from_file (filename, TRUE, FALSE, NULL);
        DEBUG ("Result %p", key_file);

        if (!key_file)
        {
            DEBUG ("No key file by that name");
            if (g_strcmp0 (sf_extension, STATE_FILE_EXT) == 0)
            {
                DEBUG ("Trying old state file names for compatibility");
                i = 1;
                g_free (sf_extension);
                sf_extension = g_strdup ("");

                /* Regardless of whether or not an old state file is found,
                 * the currently tested name should be used for the future
                 * state file.
                 */
                state_file_name = filename;
                continue;
            }

            /* No old style file found. We'll return with the new file name
             * we set earlier, and no existing key file. */
            g_free (filename);
            break;
        }

        file_guid = g_key_file_get_string (key_file,
                                           STATE_FILE_TOP, STATE_FILE_BOOK_GUID,
                                           NULL);
        DEBUG ("File GncGUID is %s", file_guid ? file_guid : "<not found>");
        if (g_strcmp0 (guid_string, file_guid) == 0)
        {
            DEBUG ("Matched !!!");
            /* Save the found file for later use. Which name to save to
             * depends on whether it was an old or new style file name
             */
            if (g_strcmp0 (sf_extension, STATE_FILE_EXT) == 0)
                state_file_name = filename;
            else
                state_file_name_pre_241 = filename;

            g_free (file_guid);
            break;
        }
        DEBUG ("Clean up this pass");
        g_free (file_guid);
        g_key_file_free (key_file);
        g_free (filename);
        i++;
    }

    DEBUG("Clean up");
    g_free(sf_extension);
    g_free(original);
    g_key_file_free (key_file);

    LEAVE ();
}
Example #28
0
int recrypt_ini_file(const char *iniPath, const char *iniPath_new,
			const char *old_iniKey)
{
	char *encrypted_key;
	GKeyFile *config = g_key_file_new();
	GError *error = NULL;
	gsize groups_count = 0;
	int i;
	char bfKey[512];
	char newbfKey[74];
	char plusOk[78];

	int re_enc = 0;

	g_key_file_load_from_file(config, iniPath, G_KEY_FILE_NONE, &error);
	if (error != NULL) {
		g_error_free(error);
		error = NULL;
		g_key_file_free(config);
		return -1;
	}

	gchar **groups = g_key_file_get_groups(config, &groups_count);

	for (i = 0; i < groups_count; i++) {

		gsize keys_count = 0;
		gchar **keys = g_key_file_get_keys(config, groups[i], &keys_count, &error);

		if (error != NULL) {
			g_error_free(error);
			error = NULL;
			continue;
		}

		int j;

		for (j = 0; j < keys_count; j++) {
			gchar *value = g_key_file_get_value(config, groups[i], keys[j], &error);

			if (error != NULL) {
				g_error_free(error);
				error = NULL;
				continue;
			}

			if (strncmp(value, "+OK ", 4) == 0) {
				re_enc = 1;

				decrypt_string(old_iniKey, value + 4, bfKey, strlen(value + 4));
				encrypt_string(iniKey, bfKey, newbfKey, strlen(bfKey));

				snprintf(plusOk, 78, "+OK %s", newbfKey);

				setIniValue(groups[i], keys[j], plusOk, iniPath_new);

				ZeroMemory(plusOk, sizeof(plusOk));
				ZeroMemory(newbfKey, sizeof(newbfKey));
			}

			g_free(value);
		}

		g_strfreev(keys);
	}

	g_strfreev(groups);
	g_key_file_free(config);

	remove(iniPath);
	rename(iniPath_new, iniPath);

	return re_enc;
}
void IconGeometrySettings::readSettings(const char* filePath)
{
    GKeyFile* keyfile = g_key_file_new();
    qint32 v = INT_MIN;
    qreal vf = 0.0;
	if (!g_key_file_load_from_file(keyfile, filePath,
								   G_KEY_FILE_NONE, NULL)) {
		goto Done;
	}

	KEY_BOOLEAN("Main","UseAbsoluteGeom",useAbsoluteGeom);
	KEYS_SIZE("Main","AbsoluteGeomSizeWidthPx",
								"AbsoluteGeomSizeHeightPx",
								absoluteGeomSizePx);

	KEY_BOOLEAN("Main","UseAbsoluteFrameGeom",useAbsoluteFrameGeom);
	KEYS_SIZE("Main",		"FrameAbsoluteGeomSizeWidthPx",
							"FrameAbsoluteGeomSizeHeightPx",
							frameBoxAbsoluteGeomSizePx);
	KEYS_SIZEF("Main",		"FrameBoxHorizontalProportionToTotalGeom",
							"FrameBoxVerticalProportionToTotalGeom",
							frameBoxProportionToGeom);

	KEY_BOOLEAN("Main","UseAbsoluteMainIconGeom",useAbsoluteMainIconGeom);
	KEYS_SIZE("Main",		"MainIconAbsoluteGeomSizeWidthPx",
							"MainIconAbsoluteGeomSizeHeightPx",
							mainIconBoxAbsoluteGeomSizePx);
	KEYS_SIZEF("Main",		"MainIconBoxHorizontalProportionToTotalGeom",
							"MainIconBoxVerticalProportionToTotalGeom",
							mainIconBoxProportionToGeom);

	KEY_BOOLEAN("Main","UseAlignmentGeom",useAlignmentGeom);
	KEYS_SIZE("Main",		"AlignmentAbsoluteGeomSizeWidthPx",
								"AlignmentAbsoluteGeomSizeHeightPx",
								alignmentGeomSizePx);

	KEY_BOOLEAN("Main","UseAbsoluteRemoveDeleteDecoratorGeom",useAbsoluteRemoveDeleteDecoratorGeom);
	KEYS_SIZE("Main",		"RemoveDeleteDecoratorBoxAbsoluteGeomWidthPx",
							"RemoveDeleteDecoratorBoxAbsoluteGeomHeightPx",
							removeDeleteDecoratorBoxAbsoluteGeomSizePx);
	KEYS_SIZEF("Main",		"RemoveDeleteDecoratorBoxHorizontalProportionToTotalGeom",
							"RemoveDeleteDecoratorBoxVerticalProportionToTotalGeom",
							removeDeleteDecoratorBoxProportionToGeom);
	KEY_BOOLEAN("Main","UseAbsoluteRemoveDeleteDecoratorOffsetFromGeomOrigin",useAbsoluteRemoveDeleteDecoratorOffsetFromGeomOrigin);
	KEYS_POINT("Main", "RemoveDeleteDecoratorHorizontalOffsetFromGeomOrigin",
					   "RemoveDeleteDecoratorVerticalOffsetFromGeomOrigin",
					   removeDeleteDecoratorOffsetFromGeomOriginPx);

	KEY_BOOLEAN("Main","UseAbsoluteInstallStatusDecoratorGeom",useAbsoluteInstallStatusDecoratorGeom);
	KEYS_SIZE("Main",		"InstallStatusDecoratorBoxAbsoluteGeomWidthPx",
							"InstallStatusDecoratorBoxAbsoluteGeomHeightPx",
							installStatusDecoratorBoxAbsoluteGeomSizePx);
	KEYS_SIZEF("Main",		"InstallStatusDecoratorBoxHorizontalProportionToTotalGeom",
							"InstallStatusDecoratorBoxVerticalProportionToTotalGeom",
							installStatusDecoratorBoxProportionToGeom);
	KEY_BOOLEAN("Main","UseAbsoluteInstallStatusDecoratorOffsetFromGeomOrigin",useAbsoluteInstallStatusDecoratorOffsetFromGeomOrigin);
	KEYS_POINT("Main", "InstallStatusDecoratorHorizontalOffsetFromGeomOrigin",
					   "InstallStatusDecoratorVerticalOffsetFromGeomOrigin",
					   installStatusDecoratorOffsetFromGeomOriginPx);

	KEY_BOOLEAN("Label",	"UseAbsoluteLabelBoxGeom",useAbsoluteLabelBoxGeom);
	KEYS_SIZE("Label",		"LabelBoxAbsoluteGeomWidthPx",
							"LabelBoxAbsoluteGeomHeightPx",
							labelBoxAbsoluteGeomSizePx);
	KEYS_SIZEF("Label",		"LabelBoxHorizontalProportionToTotalGeom",
							"LabelBoxVerticalProportionToTotalGeom",
							labelBoxProportionToGeom);

	KEY_UINTEGER("Label","LabelVerticalSpacingFromMainIcon",labelVerticalSpacingPx);

	KEY_UINTEGER("Label","FontSizePx",labelFontSizePx);
	KEY_COLOR("Label","FontColor",labelFontColor);
	KEY_BOOLEAN("Label","FontUsesBold",labelFontEmbolden);

	KEYS_SIZE("Decorators",	"EdgeOffsetHorizontalPx",
							"EdgeOffsetVerticalPx",
							decoratorEdgeOffsetPx);

	KEYS_POINT("Main","MainIconHorizontalOffsetFromGeomOriginPx",
					"MainIconVerticalOffsetFromGeomOriginPx",
					mainIconOffsetFromGeomOriginPx);

	KEYS_POINT("Main","FrameHorizontalOffsetFromGeomOriginPx",
					 "FrameVerticalOffsetFromGeomOriginPx",
					 frameOffsetFromGeomOriginPx);

Done:

	if (keyfile) {
		g_key_file_free(keyfile);
	}
}
Example #30
0
gboolean
brasero_setting_save (BraseroSetting *setting)
{
	BraseroSettingPrivate *priv;
	gchar *contents = NULL;
	gsize content_size = 0;
	GKeyFile *key_file;
	gchar *path;

	priv = BRASERO_SETTING_PRIVATE (setting);

	path = g_build_path (G_DIR_SEPARATOR_S,
	                     g_get_user_config_dir (),
	                     "brasero",
	                     "application-settings",
	                     NULL);

	key_file = g_key_file_new ();
	g_key_file_load_from_file (key_file,
	                           path,
	                           G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
	                           NULL);

	/* Don't worry if it does not work, it could be
	 * that there isn't any at the moment. */
	if (priv->search_entry_history)
		g_key_file_set_string_list (key_file,
					    "Filter",
					    "history",
					    (const gchar *const*) priv->search_entry_history,
					    g_strv_length (priv->search_entry_history));

	if (priv->layout_audio)
		g_key_file_set_string (key_file,
		                       "Display",
		                       "layout-audio",
		                       priv->layout_audio);

	if (priv->layout_video)
		g_key_file_set_string (key_file,
		                       "Display",
		                       "layout-video",
		                       priv->layout_video);

	if (priv->layout_data)
		g_key_file_set_string (key_file,
		                       "Display",
		                       "layout-data",
		                       priv->layout_data);

	g_key_file_set_boolean (key_file,
	                        "Display",
	                        "show-sidepane",
	                        priv->show_sidepane);
	g_key_file_set_boolean (key_file,
	                        "Display",
	                        "show-preview",
	                        priv->show_preview);

	g_key_file_set_integer (key_file,
	                        "Display",
	                        "main-window-width",
	                        priv->win_width);
	g_key_file_set_integer (key_file,
	                        "Display",
	                        "main-window-height",
	                        priv->win_height);
	g_key_file_set_boolean (key_file,
	                        "Display",
	                        "main-window-maximized",
	                        priv->win_maximized);
	g_key_file_set_integer (key_file,
	                        "Display",
	                        "stock-file-chooser-percent",
	                        priv->stock_file_chooser_percent);
	g_key_file_set_integer (key_file,
	                        "Display",
	                        "brasero-file-chooser-percent",
	                        priv->brasero_file_chooser_percent);
	g_key_file_set_integer (key_file,
	                        "Player",
	                        "player-volume",
	                        priv->player_volume);
	g_key_file_set_integer (key_file,
	                        "Display",
	                        "layout",
	                        priv->display_layout);
	g_key_file_set_integer (key_file,
	                        "Display",
	                        "data-disc-column",
	                        priv->data_disc_column);
	g_key_file_set_integer (key_file,
	                        "Display",
	                        "data-disc-column-order",
	                        priv->data_disc_column_order);
	g_key_file_set_integer (key_file,
	                        "Player",
	                        "image-size-width",
	                        priv->image_size_width);
	g_key_file_set_integer (key_file,
	                        "Player",
	                        "image-size-height",
	                        priv->image_size_height);
	g_key_file_set_integer (key_file,
	                        "Player",
	                        "video-size-width",
	                        priv->video_size_width);
	g_key_file_set_integer (key_file,
	                        "Player",
	                        "video-size-height",
	                        priv->video_size_height);
	g_key_file_set_integer (key_file,
	                        "Display",
	                        "pane-position",
	                        priv->display_proportion);

	contents = g_key_file_to_data (key_file, &content_size, NULL);
	g_file_set_contents (path, contents, content_size, NULL);
	g_free (contents);
	g_free (path);

	g_key_file_free (key_file);

	return TRUE;
}